/[emacs]/emacs/src/macterm.c
ViewVC logotype

Diff of /emacs/src/macterm.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.117 by jhd, Mon Jun 6 20:23:56 2005 UTC revision 1.118 by mituharu, Wed Jun 15 02:29:29 2005 UTC
# Line 1996  static void Line 1996  static void
1996  mac_compute_glyph_string_overhangs (s)  mac_compute_glyph_string_overhangs (s)
1997       struct glyph_string *s;       struct glyph_string *s;
1998  {  {
1999    Rect r;    if (s->cmp == NULL
2000    MacFontStruct *font = s->font;        && s->first_glyph->type == CHAR_GLYPH)
   
   TextFont (font->mac_fontnum);  
   TextSize (font->mac_fontsize);  
   TextFace (font->mac_fontface);  
   
   if (s->two_byte_p)  
     QDTextBounds (s->nchars * 2, (char *)s->char2b, &r);  
   else  
2001      {      {
2002        int i;        Rect r;
2003        char *buf = xmalloc (s->nchars);        MacFontStruct *font = s->font;
2004    
2005        if (buf == NULL)        TextFont (font->mac_fontnum);
2006          SetRect (&r, 0, 0, 0, 0);        TextSize (font->mac_fontsize);
2007          TextFace (font->mac_fontface);
2008    
2009          if (s->two_byte_p)
2010            QDTextBounds (s->nchars * 2, (char *)s->char2b, &r);
2011        else        else
2012          {          {
2013            for (i = 0; i < s->nchars; ++i)            int i;
2014              buf[i] = s->char2b[i].byte2;            char *buf = xmalloc (s->nchars);
2015            QDTextBounds (s->nchars, buf, &r);  
2016            xfree (buf);            if (buf == NULL)
2017                SetRect (&r, 0, 0, 0, 0);
2018              else
2019                {
2020                  for (i = 0; i < s->nchars; ++i)
2021                    buf[i] = s->char2b[i].byte2;
2022                  QDTextBounds (s->nchars, buf, &r);
2023                  xfree (buf);
2024                }
2025          }          }
     }  
2026    
2027    s->right_overhang = r.right > s->width ? r.right - s->width : 0;        s->right_overhang = r.right > s->width ? r.right - s->width : 0;
2028    s->left_overhang = r.left < 0 ? -r.left : 0;        s->left_overhang = r.left < 0 ? -r.left : 0;
2029        }
2030  }  }
2031    
2032    
# Line 7469  Lisp_Object Vmac_pass_command_to_system; Line 7473  Lisp_Object Vmac_pass_command_to_system;
7473  /* If Non-nil, the Mac "Control" key is passed on to the Mac Toolbox  /* If Non-nil, the Mac "Control" key is passed on to the Mac Toolbox
7474     for processing before Emacs sees it.  */     for processing before Emacs sees it.  */
7475  Lisp_Object Vmac_pass_control_to_system;  Lisp_Object Vmac_pass_control_to_system;
7476    
7477    /* Points to the variable `inev' in the function XTread_socket.  It is
7478       used for passing an input event to the function back from a Carbon
7479       event handler.  */
7480    static struct input_event *read_socket_inev = NULL;
7481  #endif  #endif
7482    
7483  /* Set in term/mac-win.el to indicate that event loop can now generate  /* Set in term/mac-win.el to indicate that event loop can now generate
# Line 7601  mac_get_mouse_btn (EventRef ref) Line 7610  mac_get_mouse_btn (EventRef ref)
7610    
7611  /* Normally, ConvertEventRefToEventRecord will correctly handle all  /* Normally, ConvertEventRefToEventRecord will correctly handle all
7612     events.  However the click of the mouse wheel is not converted to a     events.  However the click of the mouse wheel is not converted to a
7613     mouseDown or mouseUp event.  This calls ConvertEventRef, but then     mouseDown or mouseUp event.  Likewise for dead key down events.
7614     checks to see if it is a mouse up or down carbon event that has not     This calls ConvertEventRef, but then checks to see if it is a mouse
7615     been converted, and if so, converts it by hand (to be picked up in     up/down, or a dead key down carbon event that has not been
7616     the XTread_socket loop).  */     converted, and if so, converts it by hand (to be picked up in the
7617       XTread_socket loop).  */
7618  static Boolean mac_convert_event_ref (EventRef eventRef, EventRecord *eventRec)  static Boolean mac_convert_event_ref (EventRef eventRef, EventRecord *eventRec)
7619  {  {
7620    Boolean result = ConvertEventRefToEventRecord (eventRef, eventRec);    Boolean result = ConvertEventRefToEventRecord (eventRef, eventRec);
7621    /* Do special case for mouse wheel button.  */  
7622    if (!result && GetEventClass (eventRef) == kEventClassMouse)    if (result)
7623        return result;
7624    
7625      switch (GetEventClass (eventRef))
7626      {      {
7627        UInt32 kind = GetEventKind (eventRef);      case kEventClassMouse:
7628        if (kind == kEventMouseDown && !(eventRec->what == mouseDown))        switch (GetEventKind (eventRef))
7629          {          {
7630            case kEventMouseDown:
7631            eventRec->what = mouseDown;            eventRec->what = mouseDown;
7632            result=1;            result = 1;
7633          }            break;
7634        if (kind == kEventMouseUp && !(eventRec->what == mouseUp))  
7635          {          case kEventMouseUp:
7636            eventRec->what = mouseUp;            eventRec->what = mouseUp;
7637            result=1;            result = 1;
7638              break;
7639    
7640            default:
7641              break;
7642          }          }
7643        if (result)  
7644        case kEventClassKeyboard:
7645          switch (GetEventKind (eventRef))
7646          {          {
7647            /* Need where and when.  */          case kEventRawKeyDown:
7648            UInt32 mods;            {
7649            GetEventParameter (eventRef, kEventParamMouseLocation,              unsigned char char_codes;
7650                               typeQDPoint, NULL, sizeof (Point),              UInt32 key_code;
7651                               NULL, &eventRec->where);  
7652            /* Use two step process because new event modifiers are              eventRec->what = keyDown;
7653               32-bit and old are 16-bit.  Currently, only loss is              GetEventParameter (eventRef, kEventParamKeyMacCharCodes, typeChar,
7654               NumLock & Fn. */                                 NULL, sizeof (char), NULL, &char_codes);
7655            GetEventParameter (eventRef, kEventParamKeyModifiers,              GetEventParameter (eventRef, kEventParamKeyCode, typeUInt32,
7656                               typeUInt32, NULL, sizeof (UInt32),                                 NULL, sizeof (UInt32), NULL, &key_code);
7657                               NULL, &mods);              eventRec->message = char_codes | ((key_code & 0xff) << 8);
7658            eventRec->modifiers = mods;              result = 1;
7659              }
7660              break;
7661    
7662            eventRec->when = EventTimeToTicks (GetEventTime (eventRef));          default:
7663              break;
7664          }          }
7665    
7666        default:
7667          break;
7668      }      }
7669    
7670      if (result)
7671        {
7672          /* Need where and when.  */
7673          UInt32 mods;
7674    
7675          GetEventParameter (eventRef, kEventParamMouseLocation, typeQDPoint,
7676                             NULL, sizeof (Point), NULL, &eventRec->where);
7677          /* Use two step process because new event modifiers are 32-bit
7678             and old are 16-bit.  Currently, only loss is NumLock & Fn. */
7679          GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32,
7680                             NULL, sizeof (UInt32), NULL, &mods);
7681          eventRec->modifiers = mods;
7682    
7683          eventRec->when = EventTimeToTicks (GetEventTime (eventRef));
7684        }
7685    
7686    return result;    return result;
7687  }  }
7688    
# Line 8209  mac_handle_command_event (next_handler, Line 8252  mac_handle_command_event (next_handler,
8252  }  }
8253    
8254  static OSErr  static OSErr
8255  init_command_handler (window)  init_command_handler ()
      WindowPtr window;  
8256  {  {
8257    OSErr err = noErr;    OSErr err = noErr;
8258    EventTypeSpec specs[] = {{kEventClassCommand, kEventCommandProcess}};    EventTypeSpec specs[] = {{kEventClassCommand, kEventCommandProcess}};
# Line 8295  mac_handle_window_event (next_handler, e Line 8337  mac_handle_window_event (next_handler, e
8337    
8338    return eventNotHandledErr;    return eventNotHandledErr;
8339  }  }
8340    
8341    static pascal OSStatus
8342    mac_handle_mouse_event (next_handler, event, data)
8343         EventHandlerCallRef next_handler;
8344         EventRef event;
8345         void *data;
8346    {
8347      OSStatus result;
8348    
8349      switch (GetEventKind (event))
8350        {
8351        case kEventMouseWheelMoved:
8352          {
8353            WindowPtr wp;
8354            struct frame *f;
8355            EventMouseWheelAxis axis;
8356            SInt32 delta;
8357            Point point;
8358    
8359            result = CallNextEventHandler (next_handler, event);
8360            if (result != eventNotHandledErr || read_socket_inev == NULL)
8361              return result;
8362    
8363            GetEventParameter (event, kEventParamWindowRef, typeWindowRef,
8364                               NULL, sizeof (WindowRef), NULL, &wp);
8365            f = mac_window_to_frame (wp);
8366            if (f != mac_focus_frame (&one_mac_display_info))
8367              break;
8368    
8369            GetEventParameter (event, kEventParamMouseWheelAxis,
8370                               typeMouseWheelAxis, NULL,
8371                               sizeof (EventMouseWheelAxis), NULL, &axis);
8372            if (axis != kEventMouseWheelAxisY)
8373              break;
8374    
8375            GetEventParameter (event, kEventParamMouseWheelDelta, typeSInt32,
8376                               NULL, sizeof (SInt32), NULL, &delta);
8377            GetEventParameter (event, kEventParamMouseLocation, typeQDPoint,
8378                               NULL, sizeof (Point), NULL, &point);
8379            read_socket_inev->kind = WHEEL_EVENT;
8380            read_socket_inev->code = 0;
8381            read_socket_inev->modifiers =
8382              (mac_event_to_emacs_modifiers (event)
8383               | ((delta < 0) ? down_modifier : up_modifier));
8384            SetPortWindowPort (wp);
8385            GlobalToLocal (&point);
8386            XSETINT (read_socket_inev->x, point.h);
8387            XSETINT (read_socket_inev->y, point.v);
8388            XSETFRAME (read_socket_inev->frame_or_window, f);
8389            read_socket_inev->timestamp =
8390              EventTimeToTicks (GetEventTime (event)) * (1000/60);
8391    
8392            return noErr;
8393          }
8394          break;
8395    
8396        default:
8397          break;
8398        }
8399    
8400      return eventNotHandledErr;
8401    }
8402  #endif  /* USE_CARBON_EVENTS */  #endif  /* USE_CARBON_EVENTS */
8403    
8404    
# Line 8304  install_window_handler (window) Line 8408  install_window_handler (window)
8408  {  {
8409    OSErr err = noErr;    OSErr err = noErr;
8410  #if USE_CARBON_EVENTS  #if USE_CARBON_EVENTS
8411    EventTypeSpec specs[] = {{kEventClassWindow, kEventWindowUpdate},    EventTypeSpec specs_window[] =
8412                             {kEventClassWindow, kEventWindowBoundsChanging}};      {{kEventClassWindow, kEventWindowUpdate},
8413    static EventHandlerUPP handle_window_event_UPP = NULL;       {kEventClassWindow, kEventWindowBoundsChanging}};
8414      EventTypeSpec specs_mouse[] = {{kEventClassMouse, kEventMouseWheelMoved}};
8415    if (handle_window_event_UPP == NULL)    static EventHandlerUPP handle_window_eventUPP = NULL;
8416      handle_window_event_UPP = NewEventHandlerUPP (mac_handle_window_event);    static EventHandlerUPP handle_mouse_eventUPP = NULL;
8417    
8418    err = InstallWindowEventHandler (window, handle_window_event_UPP,    if (handle_window_eventUPP == NULL)
8419                                     GetEventTypeCount (specs), specs,      handle_window_eventUPP = NewEventHandlerUPP (mac_handle_window_event);
8420                                     NULL, NULL);    if (handle_mouse_eventUPP == NULL)
8421        handle_mouse_eventUPP = NewEventHandlerUPP (mac_handle_mouse_event);
8422      err = InstallWindowEventHandler (window, handle_window_eventUPP,
8423                                       GetEventTypeCount (specs_window),
8424                                       specs_window, NULL, NULL);
8425      if (err == noErr)
8426        err = InstallWindowEventHandler (window, handle_mouse_eventUPP,
8427                                         GetEventTypeCount (specs_mouse),
8428                                         specs_mouse, NULL, NULL);
8429  #endif  #endif
8430  #if TARGET_API_MAC_CARBON  #if TARGET_API_MAC_CARBON
8431    if (mac_do_track_dragUPP == NULL)    if (mac_do_track_dragUPP == NULL)
# Line 8865  XTread_socket (sd, expected, hold_quit) Line 8977  XTread_socket (sd, expected, hold_quit)
8977  #if USE_CARBON_EVENTS  #if USE_CARBON_EVENTS
8978        /* Handle new events */        /* Handle new events */
8979        if (!mac_convert_event_ref (eventRef, &er))        if (!mac_convert_event_ref (eventRef, &er))
8980          switch (GetEventClass (eventRef))          {
8981            {            /* There used to be a handler for the kEventMouseWheelMoved
8982            case kEventClassWindow:               event here.  But as of Mac OS X 10.4, this kind of event
8983              if (GetEventKind (eventRef) == kEventWindowBoundsChanged)               is not directly posted to the main event queue by
8984                {               two-finger scrolling on the trackpad.  Instead, some
8985                  WindowPtr window_ptr;               private event is posted and it is converted to a wheel
8986                  GetEventParameter(eventRef, kEventParamDirectObject,               event by the default handler for the application target.
8987                                    typeWindowRef, NULL, sizeof(WindowPtr),               The converted one can be received by a Carbon event
8988                                    NULL, &window_ptr);               handler installed on a window target.  */
8989                  f = mac_window_to_frame (window_ptr);            read_socket_inev = &inev;
8990                  if (f && !f->async_iconified)            SendEventToEventTarget (eventRef, toolbox_dispatcher);
8991                    x_real_positions (f, &f->left_pos, &f->top_pos);            read_socket_inev = NULL;
8992                  SendEventToEventTarget (eventRef, toolbox_dispatcher);          }
               }  
             break;  
           case kEventClassMouse:  
             if (GetEventKind (eventRef) == kEventMouseWheelMoved)  
               {  
                 SInt32 delta;  
                 Point point;  
                 struct frame *f = mac_focus_frame (dpyinfo);  
                 WindowPtr window_ptr;  
   
 #if 0  
                 if (dpyinfo->x_focus_frame == NULL)  
                   {  
                     /* Beep if wheel move occurs when all the frames  
                        are invisible.  */  
                     SysBeep(1);  
                     break;  
                   }  
 #endif  
   
                 GetEventParameter(eventRef, kEventParamMouseWheelDelta,  
                                   typeSInt32, NULL, sizeof (SInt32),  
                                   NULL, &delta);  
                 GetEventParameter(eventRef, kEventParamMouseLocation,  
                                   typeQDPoint, NULL, sizeof (Point),  
                                   NULL, &point);  
                 inev.kind = WHEEL_EVENT;  
                 inev.code = 0;  
                 inev.modifiers = (mac_event_to_emacs_modifiers (eventRef)  
                                   | ((delta < 0) ? down_modifier  
                                      : up_modifier));  
                 window_ptr = FRAME_MAC_WINDOW (f);  
                 SetPortWindowPort (window_ptr);  
                 GlobalToLocal (&point);  
                 XSETINT (inev.x, point.h);  
                 XSETINT (inev.y, point.v);  
                 XSETFRAME (inev.frame_or_window,  
                            mac_window_to_frame (window_ptr));  
                 inev.timestamp = EventTimeToTicks (GetEventTime (eventRef))*(1000/60);  
               }  
             else  
               SendEventToEventTarget (eventRef, toolbox_dispatcher);  
   
             break;  
   
           default:  
             /* Send the event to the appropriate receiver.  */  
             SendEventToEventTarget (eventRef, toolbox_dispatcher);  
           }  
8993        else        else
8994  #endif /* USE_CARBON_EVENTS */  #endif /* USE_CARBON_EVENTS */
8995        switch (er.what)        switch (er.what)
# Line 9362  XTread_socket (sd, expected, hold_quit) Line 9425  XTread_socket (sd, expected, hold_quit)
9425              if ((!NILP (Vmac_pass_command_to_system)              if ((!NILP (Vmac_pass_command_to_system)
9426                   || !(er.modifiers & cmdKey))                   || !(er.modifiers & cmdKey))
9427                  && (!NILP (Vmac_pass_control_to_system)                  && (!NILP (Vmac_pass_control_to_system)
9428                      || !(er.modifiers & controlKey)))                      || !(er.modifiers & controlKey))
9429                    && (!NILP (Vmac_command_key_is_meta)
9430                        && NILP (Vmac_option_modifier)
9431                        || !(er.modifiers & optionKey)))
9432                if (SendEventToEventTarget (eventRef, toolbox_dispatcher)                if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
9433                    != eventNotHandledErr)                    != eventNotHandledErr)
9434                  break;                  break;

Legend:
Removed from v.1.117  
changed lines
  Added in v.1.118

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26