]> code.delx.au - gnu-emacs/blobdiff - src/macterm.c
* macterm.c (syms_of_macterm): Provide the feature "mac-carbon" to
[gnu-emacs] / src / macterm.c
index 705b3ec537c6f0129eb387df2ec73631e26cea03..cae4172854e6a3c2683eb7e638a706b7fb890073 100644 (file)
@@ -7330,7 +7330,8 @@ note_mouse_highlight (f, x, y)
 
              dpyinfo->mouse_face_face_id
                = face_at_buffer_position (w, pos, 0, 0,
-                                          &ignore, pos + 1, 1);
+                                          &ignore, pos + 1,
+                                          !dpyinfo->mouse_face_hidden);
 
              /* Display it as active.  */
              show_mouse_face (dpyinfo, DRAW_MOUSE_FACE);
@@ -7372,7 +7373,8 @@ note_mouse_highlight (f, x, y)
              if (BUFFERP (object))
                dpyinfo->mouse_face_face_id
                  = face_at_buffer_position (w, pos, 0, 0,
-                                            &ignore, pos + 1, 1);
+                                            &ignore, pos + 1,
+                                            !dpyinfo->mouse_face_hidden);
 
              /* Display it as active.  */
              show_mouse_face (dpyinfo, DRAW_MOUSE_FACE);
@@ -7451,7 +7453,8 @@ note_mouse_highlight (f, x, y)
                  dpyinfo->mouse_face_window = window;
                  dpyinfo->mouse_face_face_id
                    = face_at_buffer_position (w, pos, 0, 0,
-                                              &ignore, pos + 1, 1);
+                                              &ignore, pos + 1,
+                                              !dpyinfo->mouse_face_hidden);
 
                  /* Display it as active.  */
                  show_mouse_face (dpyinfo, DRAW_MOUSE_FACE);
@@ -9298,6 +9301,7 @@ x_display_and_set_cursor (w, on, hpos, vpos, x, y)
   struct frame *f = XFRAME (w->frame);
   int new_cursor_type;
   int new_cursor_width;
+  int active_cursor;
   struct glyph_matrix *current_glyphs;
   struct glyph_row *glyph_row;
   struct glyph *glyph;
@@ -9331,7 +9335,7 @@ x_display_and_set_cursor (w, on, hpos, vpos, x, y)
   xassert (interrupt_input_blocked);
 
   /* Set new_cursor_type to the cursor we want to be displayed.  */
-  new_cursor_type = get_window_cursor_type (w, &new_cursor_width);
+  new_cursor_type = get_window_cursor_type (w, &new_cursor_width, &active_cursor);
 
 
   /* If cursor is currently being shown and we don't want it to be or
@@ -11586,10 +11590,10 @@ mac_get_mouse_btn (EventRef ref)
     case kEventMouseButtonPrimary:
       return 0;
     case kEventMouseButtonSecondary:
-      return NILP (Vmac_wheel_button_is_mouse_2) ? 2 : 1
+      return NILP (Vmac_wheel_button_is_mouse_2) ? 1 : 2
     case kEventMouseButtonTertiary:
     case 4:  /* 4 is the number for the mouse wheel button */
-      return NILP (Vmac_wheel_button_is_mouse_2) ? 1 : 2
+      return NILP (Vmac_wheel_button_is_mouse_2) ? 2 : 1
     default:
       return 0;
     }
@@ -12534,7 +12538,7 @@ static unsigned char keycode_to_xkeysym_table[] = {
 /* 0x00 - 0x3f */
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, '\x0d', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 /* 0x40 */
   0, '\xae' /* kp. */, 0, '\xaa' /* kp* */, 
@@ -12626,7 +12630,7 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
                                expected
                                ? TicksToEventTime (app_sleep_time)
                                : 0,
-                               true, &eventRef);
+                               kEventRemoveFromQueue, &eventRef);
   if (!rneResult)
     {
       /* Handle new events */
@@ -12657,7 +12661,7 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
                bufp->timestamp = EventTimeToTicks (GetEventTime (eventRef))*(1000/60);
                count++;
              }
-           else
+           else             
              SendEventToEventTarget (eventRef, GetEventDispatcherTarget ());
 
            break;
@@ -12907,16 +12911,16 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
                break;
            }
 #endif
-
+         
          if (!IsValidWindowPtr (FrontNonFloatingWindow ()))
            {
              SysBeep (1);
              UNBLOCK_INPUT;
              return 0;
            }
-
+         
          ObscureCursor ();
-
+         
          if (keycode == 0x33)  /* delete key (charCode translated to 0x8) */
            {
              bufp->code = 0x7f;
@@ -12927,90 +12931,83 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
              bufp->code = 0xff00 | xkeysym;
              bufp->kind = NON_ASCII_KEYSTROKE_EVENT;
            }      
-         else if (!NILP (Vmac_reverse_ctrl_meta) && (er.modifiers & controlKey))
-           {
-             /* This is a special case to deal with converting from
-                a control character to non-control character */
-             int new_modifiers = er.modifiers & ~controlKey;
-             int new_keycode = keycode | new_modifiers;              
-             Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
-             unsigned long some_state = 0;
-             bufp->code = KeyTranslate (kchr_ptr, new_keycode, &some_state) & 0xff;
-             bufp->kind = ASCII_KEYSTROKE_EVENT;
-           }
          else
            {
-             if (er.modifiers & macMetaKey)
-               {
-                 /* This code comes from Keyboard Resource, Appendix
+             if (er.modifiers & (controlKey | 
+                                 (NILP (Vmac_command_key_is_meta) ? optionKey 
+                                  : cmdKey)))
+               {
+                 /* This code comes from Keyboard Resource, Appendix
                     C of IM - Text.  This is necessary since shift is
                     ignored in KCHR table translation when option or
-                    command is pressed. */
-                 int new_modifiers = er.modifiers & 0xf600;
-                   /* mask off option and command */
-                 int new_keycode = keycode | new_modifiers;
-                 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
-                 unsigned long some_state = 0;
-                 bufp->code = KeyTranslate (kchr_ptr, new_keycode,
+                    command is pressed.  It also does not translate 
+                    correctly control-shift chars like C-% so mask off
+                    shift here also */
+                 int new_modifiers = er.modifiers & 0xe600;
+                 /* mask off option and command */
+                 int new_keycode = keycode | new_modifiers;
+                 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
+                 unsigned long some_state = 0;
+                 bufp->code = KeyTranslate (kchr_ptr, new_keycode,
                                             &some_state) & 0xff;
-               }
+               }
              else
-               bufp->code = er.message & charCodeMask;
+               bufp->code = er.message & charCodeMask;
              bufp->kind = ASCII_KEYSTROKE_EVENT;
            }
        }
-
-        /* If variable mac-convert-keyboard-input-to-latin-1 is non-nil,
-           convert non-ASCII characters typed at the Mac keyboard
-           (presumed to be in the Mac Roman encoding) to iso-latin-1
-           encoding before they are passed to Emacs.  This enables the
-           Mac keyboard to be used to enter non-ASCII iso-latin-1
-           characters directly.  */
-        if (mac_keyboard_text_encoding != kTextEncodingMacRoman
+       
+       /* If variable mac-convert-keyboard-input-to-latin-1 is non-nil,
+          convert non-ASCII characters typed at the Mac keyboard
+          (presumed to be in the Mac Roman encoding) to iso-latin-1
+          encoding before they are passed to Emacs.  This enables the
+          Mac keyboard to be used to enter non-ASCII iso-latin-1
+          characters directly.  */
+       if (mac_keyboard_text_encoding != kTextEncodingMacRoman
            && bufp->kind == ASCII_KEYSTROKE_EVENT && bufp->code >= 128)
          {
-            static TECObjectRef converter = NULL;
-            OSStatus the_err = noErr;
-            OSStatus convert_status = noErr;
-
-            if (converter ==  NULL)
-              {
-                the_err = TECCreateConverter (&converter,
+           static TECObjectRef converter = NULL;
+           OSStatus the_err = noErr;
+           OSStatus convert_status = noErr;
+           
+           if (converter ==  NULL)
+             {
+               the_err = TECCreateConverter (&converter,
                                              kTextEncodingMacRoman,
                                              mac_keyboard_text_encoding);
-                current_mac_keyboard_text_encoding
+               current_mac_keyboard_text_encoding
                  = mac_keyboard_text_encoding;
-              }
-            else if (mac_keyboard_text_encoding
+             }
+           else if (mac_keyboard_text_encoding
                     != current_mac_keyboard_text_encoding)
-              {
-                /* Free the converter for the current encoding before
-                   creating a new one.  */
-                TECDisposeConverter (converter);
-                the_err = TECCreateConverter (&converter,
+             {
+               /* Free the converter for the current encoding before
+                  creating a new one.  */
+               TECDisposeConverter (converter);
+               the_err = TECCreateConverter (&converter,
                                              kTextEncodingMacRoman,
                                              mac_keyboard_text_encoding);
-                current_mac_keyboard_text_encoding
+               current_mac_keyboard_text_encoding
                  = mac_keyboard_text_encoding;
-              
-              
-            if (the_err == noErr)
-              {
-                unsigned char ch = bufp->code;
-                ByteCount actual_input_length, actual_output_length;
-                unsigned char outch;
-                  
-                convert_status = TECConvertText (converter, &ch, 1,
+             } 
+           
+           if (the_err == noErr)
+             {
+               unsigned char ch = bufp->code;
+               ByteCount actual_input_length, actual_output_length;
+               unsigned char outch;
+               
+               convert_status = TECConvertText (converter, &ch, 1,
                                                 &actual_input_length,
-                                                 &outch, 1,
+                                                &outch, 1,
                                                 &actual_output_length);
-                if (convert_status == noErr
+               if (convert_status == noErr
                    && actual_input_length == 1
                    && actual_output_length == 1)
-                  bufp->code = outch;
-              }
+                 bufp->code = outch;
+             }
          }
-
+       
 #if USE_CARBON_EVENTS
        bufp->modifiers = mac_event_to_emacs_modifiers (eventRef);
 #else
@@ -13022,7 +13019,7 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
            = (mac_output *) GetWRefCon (FrontNonFloatingWindow ());
          XSETFRAME (bufp->frame_or_window, mwp->mFP);
        }
-
+       
        bufp->timestamp = er.when * (1000 / 60);  /* ticks to milliseconds */
 
        count++;
@@ -13042,6 +13039,14 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
             Lisp_Object frame;
 
             wp = FrontNonFloatingWindow ();
+           
+           if (!wp)
+             {
+               struct frame *f = XFRAME (XCAR (Vframe_list));
+               CollapseWindow (FRAME_MAC_WINDOW (f), false);
+               wp = FrontNonFloatingWindow ();
+             }
+
             if (wp && is_emacs_window(wp))
                f = ((mac_output *) GetWRefCon (wp))->mFP;            
 
@@ -13433,6 +13438,36 @@ mac_term_init (display_name, xrm_option, resource_name)
 }
 \f
 #ifdef MAC_OSX
+void
+mac_check_bundle()
+{
+  extern int inhibit_window_system;
+  extern int noninteractive;
+  CFBundleRef appsBundle;
+  pid_t child;
+
+  /* No need to test if already -nw*/
+  if (inhibit_window_system || noninteractive)
+    return;
+
+  appsBundle = CFBundleGetMainBundle();
+  if (appsBundle != NULL)
+    {
+      CFStringRef cfBI = CFSTR("CFBundleIdentifier");
+      CFTypeRef res = CFBundleGetValueForInfoDictionaryKey(appsBundle, cfBI);
+      /* We found the bundle identifier, now we know we are valid. */
+      if (res != NULL)
+       {
+         CFRelease(res);
+         return;
+       }
+    }
+  /* MAC_TODO:  Have this start the bundled executable */
+
+  /* For now, prevent the fatal error by bringing it up in the terminal */
+  inhibit_window_system = 1;
+}
+
 void
 MakeMeTheFrontProcess ()
 {
@@ -13443,6 +13478,93 @@ MakeMeTheFrontProcess ()
   if (err == noErr)
     (void) SetFrontProcess (&psn);
 }
+
+/***** Code to handle C-g testing  *****/
+
+/* Contains the Mac modifier formed from quit_char */
+static mac_quit_char_modifiers = 0;
+static mac_quit_char_keycode;
+extern int quit_char;
+
+static void
+mac_determine_quit_char_modifiers()
+{
+  /* Todo: Determine modifiers from quit_char. */
+  UInt32 qc_modifiers = ctrl_modifier;
+
+  /* Map modifiers */
+  mac_quit_char_modifiers = 0;
+  if (qc_modifiers & ctrl_modifier)  mac_quit_char_modifiers |= macCtrlKey;
+  if (qc_modifiers & shift_modifier) mac_quit_char_modifiers |= macShiftKey;
+  if (qc_modifiers & meta_modifier)  mac_quit_char_modifiers |= macMetaKey;
+  if (qc_modifiers & alt_modifier)   mac_quit_char_modifiers |= macAltKey;
+}
+
+static void
+init_quit_char_handler ()
+{
+  /* TODO: Let this support keys other the 'g' */
+  mac_quit_char_keycode = 5;
+  /* Look at <architecture/adb_kb_map.h> for details */
+  /* http://gemma.apple.com/techpubs/mac/Toolbox/Toolbox-40.html#MARKER-9-184*/
+  
+  mac_determine_quit_char_modifiers();
+}
+
+static Boolean
+quit_char_comp (EventRef inEvent, void *inCompData)
+{
+  if (GetEventClass(inEvent) != kEventClassKeyboard)
+    return false;
+  if (GetEventKind(inEvent) != kEventRawKeyDown)
+    return false;
+  {
+    UInt32 keyCode;
+    UInt32 keyModifiers;
+    GetEventParameter(inEvent, kEventParamKeyCode, 
+                     typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode);
+    if (keyCode != mac_quit_char_keycode)
+      return false;
+    GetEventParameter(inEvent, kEventParamKeyModifiers, 
+                     typeUInt32, NULL, sizeof(UInt32), NULL, &keyModifiers);
+    if (keyModifiers != mac_quit_char_modifiers)
+      return false;
+  }
+  return true;
+}
+
+void
+mac_check_for_quit_char()
+{
+  EventRef event;
+  /* If windows are not initialized, return immediately (keep it bouncin')*/
+  if (!mac_quit_char_modifiers)
+    return;
+
+  /* Redetermine modifiers because they are based on lisp variables */
+  mac_determine_quit_char_modifiers();
+
+  /* Fill the queue with events */
+  ReceiveNextEvent (0, NULL, kEventDurationNoWait, false, &event);
+  event = FindSpecificEventInQueue (GetMainEventQueue(), quit_char_comp, NULL);
+  if (event) 
+    {
+      struct input_event e;
+      struct mac_output *mwp = (mac_output*) GetWRefCon (FrontNonFloatingWindow ());
+      /* Use an input_event to emulate what the interrupt handler does. */
+      e.kind = ASCII_KEYSTROKE_EVENT;
+      e.code = quit_char;
+      e.arg = NULL;
+      e.modifiers = NULL;
+      e.timestamp = EventTimeToTicks(GetEventTime(event))*(1000/60);
+      XSETFRAME(e.frame_or_window, mwp->mFP);
+      /* Remove event from queue to prevent looping. */
+      RemoveEventFromQueue(GetMainEventQueue(), event);
+      ReleaseEvent(event);
+      kbd_buffer_store_event(&e);
+    }
+}
+
 #endif /* MAC_OSX */
 
 /* Set up use of X before we make the first connection.  */
@@ -13551,6 +13673,8 @@ mac_initialize ()
 
 #if USE_CARBON_EVENTS
   init_service_handler ();
+
+  init_quit_char_handler ();
 #endif
 
   DisableMenuCommand (NULL, kHICommandQuit);
@@ -13569,6 +13693,8 @@ syms_of_macterm ()
   x_error_message_string = Qnil;
 #endif
 
+  Fprovide (intern ("mac-carbon"), Qnil);
+
   staticpro (&x_display_name_list);
   x_display_name_list = Qnil;