]> code.delx.au - gnu-emacs/blobdiff - src/macterm.c
(w32_init_fringe, mac_init_fringe): Add rif argument.
[gnu-emacs] / src / macterm.c
index 906f946388c713bf23e6d2a60f9e1cc91f47579b..8b3cee42f5c1422fe9aef1449a9fb47e01d1c4fd 100644 (file)
@@ -6,7 +6,7 @@ This file is part of GNU Emacs.
 
 GNU Emacs is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -226,14 +226,14 @@ void x_raise_frame P_ ((struct frame *));
 void x_set_window_size P_ ((struct frame *, int, int, int));
 void x_wm_set_window_state P_ ((struct frame *, int));
 void x_wm_set_icon_pixmap P_ ((struct frame *, int));
-void mac_initialize P_ ((void));
+static void mac_initialize P_ ((void));
 static void x_font_min_bounds P_ ((XFontStruct *, int *, int *));
 static int x_compute_min_glyph_bounds P_ ((struct frame *));
 static void x_update_end P_ ((struct frame *));
 static void XTframe_up_to_date P_ ((struct frame *));
-static void XTset_terminal_modes P_ ((void));
-static void XTreset_terminal_modes P_ ((void));
-static void x_clear_frame P_ ((void));
+static void XTset_terminal_modes P_ ((struct terminal *));
+static void XTreset_terminal_modes P_ ((struct terminal *));
+static void x_clear_frame P_ ((struct frame *));
 static void frame_highlight P_ ((struct frame *));
 static void frame_unhighlight P_ ((struct frame *));
 static void x_new_focus_frame P_ ((struct x_display_info *, struct frame *));
@@ -261,6 +261,8 @@ static void x_scroll_bar_report_motion P_ ((struct frame **, Lisp_Object *,
 static int is_emacs_window P_ ((WindowRef));
 static XCharStruct *mac_per_char_metric P_ ((XFontStruct *, XChar2b *, int));
 static void XSetFont P_ ((Display *, GC, XFontStruct *));
+static struct terminal *mac_create_terminal P_ ((struct mac_display_info *dpyinfo));
+
 
 #define GC_FORE_COLOR(gc)      (&(gc)->fore_color)
 #define GC_BACK_COLOR(gc)      (&(gc)->back_color)
@@ -2389,7 +2391,7 @@ mac_destroy_fringe_bitmap (which)
    rarely happens).  */
 
 static void
-XTset_terminal_modes ()
+XTset_terminal_modes (struct terminal *t)
 {
 }
 
@@ -2397,7 +2399,7 @@ XTset_terminal_modes ()
    the windows go away, and suspending requires no action.  */
 
 static void
-XTreset_terminal_modes ()
+XTreset_terminal_modes (struct terminal *t)
 {
 }
 
@@ -3056,10 +3058,17 @@ x_draw_composite_glyph_string_foreground (s)
   else
     {
       for (i = 0; i < s->nchars; i++, ++s->gidx)
-       mac_draw_image_string_16 (s->f, s->gc,
-                                 x + s->cmp->offsets[s->gidx * 2],
-                                 s->ybase - s->cmp->offsets[s->gidx * 2 + 1],
-                                 s->char2b + i, 1, 0, s->face->overstrike);
+       if (mac_per_char_metric (GC_FONT (s->gc), s->char2b + i, 0) == NULL)
+         /* This is a nonexistent or zero-width glyph such as a
+            combining diacritic.  Draw a rectangle.  */
+         mac_draw_rectangle (s->f, s->gc,
+                             x + s->cmp->offsets[s->gidx * 2], s->y,
+                             FONT_WIDTH (GC_FONT (s->gc)) - 1, s->height - 1);
+       else
+         mac_draw_image_string_16 (s->f, s->gc,
+                                   x + s->cmp->offsets[s->gidx * 2],
+                                   s->ybase - s->cmp->offsets[s->gidx * 2 + 1],
+                                   s->char2b + i, 1, 0, s->face->overstrike);
     }
 }
 
@@ -4040,15 +4049,8 @@ x_delete_glyphs (n)
    frame.  Otherwise clear the selected frame.  */
 
 static void
-x_clear_frame ()
+x_clear_frame (struct frame *f)
 {
-  struct frame *f;
-
-  if (updating_frame)
-    f = updating_frame;
-  else
-    f = SELECTED_FRAME ();
-
   /* Clearing the frame will erase any cursor, so mark them all as no
      longer visible.  */
   mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f)));
@@ -4334,14 +4336,6 @@ static void
 frame_highlight (f)
      struct frame *f;
 {
-  OSErr err;
-  ControlRef root_control;
-
-  BLOCK_INPUT;
-  err = GetRootControl (FRAME_MAC_WINDOW (f), &root_control);
-  if (err == noErr)
-    ActivateControl (root_control);
-  UNBLOCK_INPUT;
   x_update_cursor (f, 1);
 }
 
@@ -4349,14 +4343,6 @@ static void
 frame_unhighlight (f)
      struct frame *f;
 {
-  OSErr err;
-  ControlRef root_control;
-
-  BLOCK_INPUT;
-  err = GetRootControl (FRAME_MAC_WINDOW (f), &root_control);
-  if (err == noErr)
-    DeactivateControl (root_control);
-  UNBLOCK_INPUT;
   x_update_cursor (f, 1);
 }
 
@@ -4582,7 +4568,7 @@ note_mouse_movement (frame, pos)
       clear_mouse_face (dpyinfo);
       dpyinfo->mouse_face_mouse_frame = 0;
       if (!dpyinfo->grabbed)
-       rif->define_frame_cursor (frame,
+       FRAME_RIF (frame)->define_frame_cursor (frame,
                                  frame->output_data.mac->nontext_cursor);
     }
 
@@ -6114,7 +6100,9 @@ free_frame_tool_bar (f)
 
       BLOCK_INPUT;
       ShowHideWindowToolbar (FRAME_MAC_WINDOW (f), false,
-                            f == mac_focus_frame (dpyinfo));
+                            (NILP (Fsymbol_value
+                                   (intern ("frame-notice-user-settings")))
+                             && f == mac_focus_frame (dpyinfo)));
       /* Mac OS X 10.3 does not issue kEventWindowBoundsChanged events
         on toolbar visibility change.  */
       mac_handle_origin_change (f);
@@ -9391,11 +9379,13 @@ mac_handle_font_event (next_handler, event, data)
   static const EventParamName names_sel[] = {kEventParamATSUFontID,
                                             kEventParamATSUFontSize,
                                             kEventParamFMFontFamily,
+                                            kEventParamFMFontStyle,
                                             kEventParamFMFontSize,
                                             kEventParamFontColor};
   static const EventParamType types_sel[] = {typeATSUFontID,
                                             typeATSUSize,
                                             typeFMFontFamily,
+                                            typeFMFontStyle,
                                             typeFMFontSize,
                                             typeFontColor};
 
@@ -10716,7 +10706,7 @@ mac_handle_window_event (next_handler, event, data)
        {
          struct frame *sf = SELECTED_FRAME ();
 
-         if (!(FRAME_MAC_P (sf)))
+         if (!(FRAME_MAC_P (sf) && sf->async_visible))
            RepositionWindow (wp, NULL, kWindowCenterOnMainScreen);
          else
            {
@@ -10731,8 +10721,11 @@ mac_handle_window_event (next_handler, event, data)
              /* This is a workaround.  RepositionWindow fails to put
                 a window at the cascading position when its parent
                 window has a Carbon HIToolbar.  */
-             if (f->top_pos == sf->top_pos && f->left_pos == sf->left_pos)
-               MoveWindowStructure (wp,  f->left_pos + 10, f->top_pos + 32);
+             if ((f->left_pos == sf->left_pos
+                  && f->top_pos == sf->top_pos)
+                 || (f->left_pos == sf->left_pos + 10 * 2
+                     && f->top_pos == sf->top_pos + 32 * 2))
+               MoveWindowStructure (wp, sf->left_pos + 10, sf->top_pos + 32);
 #endif
            }
          result = noErr;
@@ -10957,7 +10950,7 @@ mac_handle_keyboard_event (next_handler, event, data)
      void *data;
 {
   OSStatus err, result = eventNotHandledErr;
-  UInt32 event_kind, key_code, modifiers, mapped_modifiers;
+  UInt32 event_kind, key_code, modifiers;
   unsigned char char_code;
 
   event_kind = GetEventKind (event);
@@ -10966,32 +10959,16 @@ mac_handle_keyboard_event (next_handler, event, data)
     case kEventRawKeyDown:
     case kEventRawKeyRepeat:
     case kEventRawKeyUp:
-      if (read_socket_inev == NULL)
-       {
-         result = CallNextEventHandler (next_handler, event);
-         break;
-       }
-
-      err = GetEventParameter (event, kEventParamKeyModifiers,
-                              typeUInt32, NULL,
-                              sizeof (UInt32), NULL, &modifiers);
-      if (err != noErr)
-       break;
-
-      mapped_modifiers = mac_mapped_modifiers (modifiers);
-
       /* When using Carbon Events, we need to pass raw keyboard events
         to the TSM ourselves.  If TSM handles it, it will pass back
         noErr, otherwise it will pass back "eventNotHandledErr" and
         we can process it normally.  */
-      if (!(mapped_modifiers
-           & ~(mac_pass_command_to_system ? cmdKey : 0)
-           & ~(mac_pass_control_to_system ? controlKey : 0)))
-       {
-         result = CallNextEventHandler (next_handler, event);
-         if (result != eventNotHandledErr)
-           break;
-       }
+      result = CallNextEventHandler (next_handler, event);
+      if (result != eventNotHandledErr)
+       break;
+
+      if (read_socket_inev == NULL)
+       break;
 
 #if USE_MAC_TSM
       if (read_socket_inev->kind != NO_EVENT)
@@ -11016,6 +10993,12 @@ mac_handle_keyboard_event (next_handler, event, data)
       if (err != noErr)
        break;
 
+      err = GetEventParameter (event, kEventParamKeyModifiers,
+                              typeUInt32, NULL,
+                              sizeof (UInt32), NULL, &modifiers);
+      if (err != noErr)
+       break;
+
       do_keystroke ((event_kind == kEventRawKeyDown ? keyDown : autoKey),
                    char_code, key_code, modifiers,
                    ((unsigned long)
@@ -12162,7 +12145,7 @@ XTread_socket (sd, expected, hold_quit)
                          /* Window will be selected only when it is
                             not selected now and last mouse movement
                             event was not in it.  Minibuffer window
-                            will be selected iff it is active.  */
+                            will be selected only when it is active.  */
                          if (WINDOWP (window)
                              && !EQ (window, last_window)
                              && !EQ (window, selected_window))
@@ -12197,6 +12180,8 @@ XTread_socket (sd, expected, hold_quit)
        case activateEvt:
          {
            WindowRef window_ptr = (WindowRef) er.message;
+           OSErr err;
+           ControlRef root_control;
 
            if (window_ptr == tip_window)
              {
@@ -12214,6 +12199,10 @@ XTread_socket (sd, expected, hold_quit)
                /* A window has been activated */
                Point mouse_loc;
 
+               err = GetRootControl (FRAME_MAC_WINDOW (f), &root_control);
+               if (err == noErr)
+                 ActivateControl (root_control);
+
                x_detect_focus_change (dpyinfo, &er, &inev);
 
                mouse_loc.h = (er.where.h
@@ -12229,6 +12218,10 @@ XTread_socket (sd, expected, hold_quit)
            else
              {
                /* A window has been deactivated */
+               err = GetRootControl (FRAME_MAC_WINDOW (f), &root_control);
+               if (err == noErr)
+                 DeactivateControl (root_control);
+
 #ifdef USE_TOOLKIT_SCROLL_BARS
                if (dpyinfo->grabbed && tracked_scroll_bar)
                  {
@@ -12284,13 +12277,29 @@ XTread_socket (sd, expected, hold_quit)
              clear_mouse_face (dpyinfo);
              dpyinfo->mouse_face_hidden = 1;
            }
+
+         {
+           UInt32 modifiers = er.modifiers, mapped_modifiers;
+
+#ifdef MAC_OSX
+           GetEventParameter (eventRef, kEventParamKeyModifiers,
+                              typeUInt32, NULL,
+                              sizeof (UInt32), NULL, &modifiers);
+#endif
+           mapped_modifiers = mac_mapped_modifiers (modifiers);
+
 #if TARGET_API_MAC_CARBON
-         goto OTHER;
-#else
-         do_keystroke (er.what, er.message & charCodeMask,
-                       (er.message & keyCodeMask) >> 8,
-                       er.modifiers, timestamp, &inev);
+           if (!(mapped_modifiers
+                 & ~(mac_pass_command_to_system ? cmdKey : 0)
+                 & ~(mac_pass_control_to_system ? controlKey : 0)))
+             goto OTHER;
+           else
 #endif
+             if (er.what != keyUp)
+               do_keystroke (er.what, er.message & charCodeMask,
+                             (er.message & keyCodeMask) >> 8,
+                             modifiers, timestamp, &inev);
+         }
          break;
 
        case kHighLevelEvent:
@@ -12344,7 +12353,6 @@ XTread_socket (sd, expected, hold_quit)
            }
          count++;
        }
-
     }
 
   /* If the focus was just given to an autoraising frame,
@@ -12518,6 +12526,7 @@ mac_term_init (display_name, xrm_option, resource_name)
      char *resource_name;
 {
   struct mac_display_info *dpyinfo;
+  struct terminal *terminal;
 
   BLOCK_INPUT;
 
@@ -12533,6 +12542,13 @@ mac_term_init (display_name, xrm_option, resource_name)
   dpyinfo = &one_mac_display_info;
   bzero (dpyinfo, sizeof (*dpyinfo));
 
+  terminal = mac_create_terminal (dpyinfo);
+
+  /* Set the name of the terminal. */
+  terminal->name = (char *) xmalloc (SBYTES (display_name) + 1);
+  strncpy (terminal->name, SDATA (display_name), SBYTES (display_name));
+  terminal->name[SBYTES (display_name)] = 0;
+
 #ifdef MAC_OSX
   dpyinfo->mac_id_name
     = (char *) xmalloc (SCHARS (Vinvocation_name)
@@ -12734,44 +12750,71 @@ static struct redisplay_interface x_redisplay_interface =
   mac_shift_glyphs_for_insert
 };
 
-void
+static struct terminal *
+mac_create_terminal (struct mac_display_info *dpyinfo)
+{
+  struct terminal *terminal;
+  
+  terminal = create_terminal ();
+
+  terminal->type = output_mac;
+  terminal->display_info.mac = dpyinfo;
+  dpyinfo->terminal = terminal;
+
+  terminal->clear_frame_hook = x_clear_frame;
+  terminal->ins_del_lines_hook = x_ins_del_lines;
+  terminal->delete_glyphs_hook = x_delete_glyphs;
+  terminal->ring_bell_hook = XTring_bell;
+  terminal->reset_terminal_modes_hook = XTreset_terminal_modes;
+  terminal->set_terminal_modes_hook = XTset_terminal_modes;
+  terminal->update_begin_hook = x_update_begin;
+  terminal->update_end_hook = x_update_end;
+  terminal->set_terminal_window_hook = XTset_terminal_window;
+  terminal->read_socket_hook = XTread_socket;
+  terminal->frame_up_to_date_hook = XTframe_up_to_date;
+  terminal->mouse_position_hook = XTmouse_position;
+  terminal->frame_rehighlight_hook = XTframe_rehighlight;
+  terminal->frame_raise_lower_hook = XTframe_raise_lower;
+  /* terminal->fullscreen_hook = XTfullscreen_hook; */
+  terminal->set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar;
+  terminal->condemn_scroll_bars_hook = XTcondemn_scroll_bars;
+  terminal->redeem_scroll_bar_hook = XTredeem_scroll_bar;
+  terminal->judge_scroll_bars_hook = XTjudge_scroll_bars;
+  terminal->delete_frame_hook = x_destroy_window;
+  /* terminal->delete_terminal_hook = x_delete_terminal; */
+
+  terminal->rif = &x_redisplay_interface;
+#if 0
+  TTY_SCROLL_REGION_OK (CURTTY ()) = 1; /* we'll scroll partial frames */
+  TTY_CHAR_INS_DEL_OK (CURTTY ()) = 1;
+  TTY_LINE_INS_DEL_OK (CURTTY ()) = 1; /* we'll just blt 'em */
+  TTY_FAST_CLEAR_END_OF_LINE (CURTTY ()) = 1; /* X does this well */
+  TTY_MEMORY_BELOW_FRAME (CURTTY ()) = 0; /* we don't remember what
+                                                         scrolls off the
+                                                         bottom */
+#else
+  terminal->scroll_region_ok = 1;    /* We'll scroll partial frames. */
+  terminal->char_ins_del_ok = 1;
+  terminal->line_ins_del_ok = 1;         /* We'll just blt 'em. */
+  terminal->fast_clear_end_of_line = 1;  /* X does this well. */
+  terminal->memory_below_frame = 0;   /* We don't remember what scrolls
+                                        off the bottom. */
+
+#endif
+  return terminal;
+}
+
+static void
 mac_initialize ()
 {
-  rif = &x_redisplay_interface;
-
-  clear_frame_hook = x_clear_frame;
-  ins_del_lines_hook = x_ins_del_lines;
-  delete_glyphs_hook = x_delete_glyphs;
-  ring_bell_hook = XTring_bell;
-  reset_terminal_modes_hook = XTreset_terminal_modes;
-  set_terminal_modes_hook = XTset_terminal_modes;
-  update_begin_hook = x_update_begin;
-  update_end_hook = x_update_end;
-  set_terminal_window_hook = XTset_terminal_window;
-  read_socket_hook = XTread_socket;
-  frame_up_to_date_hook = XTframe_up_to_date;
-  mouse_position_hook = XTmouse_position;
-  frame_rehighlight_hook = XTframe_rehighlight;
-  frame_raise_lower_hook = XTframe_raise_lower;
-
-  set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar;
-  condemn_scroll_bars_hook = XTcondemn_scroll_bars;
-  redeem_scroll_bar_hook = XTredeem_scroll_bar;
-  judge_scroll_bars_hook = XTjudge_scroll_bars;
-
-  scroll_region_ok = 1;         /* we'll scroll partial frames */
-  char_ins_del_ok = 1;
-  line_ins_del_ok = 1;          /* we'll just blt 'em */
-  fast_clear_end_of_line = 1;   /* X does this well */
-  memory_below_frame = 0;       /* we don't remember what scrolls
-                                  off the bottom */
+
   baud_rate = 19200;
 
   last_tool_bar_item = -1;
   any_help_event_p = 0;
 
   /* Try to use interrupt input; if we can't, then start polling.  */
-  Fset_input_mode (Qt, Qnil, Qt, Qnil);
+  Fset_input_interrupt_mode (Qt);
 
   BLOCK_INPUT;
 
@@ -12808,6 +12851,7 @@ mac_initialize ()
 #endif
 
   UNBLOCK_INPUT;
+
 }