/[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.12 by raeburn, Mon Jul 15 00:00:36 2002 UTC revision 1.13 by akochoi, Sat Aug 3 22:21:09 2002 UTC
# Line 58  Boston, MA 02111-1307, USA.  */ Line 58  Boston, MA 02111-1307, USA.  */
58  #define max(a, b) ((a) > (b) ? (a) : (b))  #define max(a, b) ((a) > (b) ? (a) : (b))
59  #undef init_process  #undef init_process
60  #define init_process emacs_init_process  #define init_process emacs_init_process
61    /* USE_CARBON_EVENTS determines if the Carbon Event Manager is used to
62       obtain events from the event queue.  If set to 0, WaitNextEvent is
63       used instead.  */
64    #define USE_CARBON_EVENTS 1
65  #else /* not MAC_OSX */  #else /* not MAC_OSX */
66  #include <Quickdraw.h>  #include <Quickdraw.h>
67  #include <ToolUtils.h>  #include <ToolUtils.h>
# Line 106  Boston, MA 02111-1307, USA.  */ Line 110  Boston, MA 02111-1307, USA.  */
110    
111  #define BETWEEN(X, LOWER, UPPER)  ((X) >= (LOWER) && (X) < (UPPER))  #define BETWEEN(X, LOWER, UPPER)  ((X) >= (LOWER) && (X) < (UPPER))
112    
113    /* Set of macros that handle mapping of Mac modifier keys to emacs.  */
114    #define macCtrlKey     (NILP (Vmac_reverse_ctrl_meta) ? controlKey :    \
115                            (NILP (Vmac_command_key_is_meta) ? optionKey : cmdKey))
116    #define macShiftKey    (shiftKey)
117    #define macMetaKey     (NILP (Vmac_reverse_ctrl_meta) ?                 \
118                            (NILP (Vmac_command_key_is_meta) ? optionKey : cmdKey) \
119                            : controlKey)
120    #define macAltKey      (NILP (Vmac_command_key_is_meta) ? cmdKey : optionKey)
121    
122    
123  /* Fringe bitmaps.  */  /* Fringe bitmaps.  */
124    
# Line 10092  void Line 10105  void
10105  x_iconify_frame (f)  x_iconify_frame (f)
10106       struct frame *f;       struct frame *f;
10107  {  {
 #if 0 /* MAC_TODO: really no iconify on Mac */  
   int result;  
   Lisp_Object type;  
   
10108    /* Don't keep the highlight on an invisible frame.  */    /* Don't keep the highlight on an invisible frame.  */
10109    if (FRAME_X_DISPLAY_INFO (f)->x_highlight_frame == f)    if (FRAME_MAC_DISPLAY_INFO (f)->x_highlight_frame == f)
10110      FRAME_X_DISPLAY_INFO (f)->x_highlight_frame = 0;      FRAME_MAC_DISPLAY_INFO (f)->x_highlight_frame = 0;
10111    
10112    #if 0
10113      /* Review:  Since window is still visible in dock, still allow updates? */
10114    if (f->async_iconified)    if (f->async_iconified)
10115      return;      return;
10116    #endif
10117    
10118    BLOCK_INPUT;    BLOCK_INPUT;
10119    
10120    FRAME_SAMPLE_VISIBILITY (f);    CollapseWindow (FRAME_MAC_WINDOW (f), true);
10121      
   type = x_icon_type (f);  
   if (!NILP (type))  
     x_bitmap_icon (f, type);  
   
 #ifdef USE_X_TOOLKIT  
   
   if (! FRAME_VISIBLE_P (f))  
     {  
       if (! EQ (Vx_no_window_manager, Qt))  
         x_wm_set_window_state (f, IconicState);  
       /* This was XtPopup, but that did nothing for an iconified frame.  */  
       XtMapWidget (f->output_data.x->widget);  
       /* The server won't give us any event to indicate  
          that an invisible frame was changed to an icon,  
          so we have to record it here.  */  
       f->iconified = 1;  
       f->visible = 1;  
       f->async_iconified = 1;  
       f->async_visible = 0;  
       UNBLOCK_INPUT;  
       return;  
     }  
   
   result = XIconifyWindow (FRAME_X_DISPLAY (f),  
                            XtWindow (f->output_data.x->widget),  
                            DefaultScreen (FRAME_X_DISPLAY (f)));  
   UNBLOCK_INPUT;  
   
   if (!result)  
     error ("Can't notify window manager of iconification");  
   
   f->async_iconified = 1;  
   f->async_visible = 0;  
   
   
   BLOCK_INPUT;  
   XFlush (FRAME_X_DISPLAY (f));  
   UNBLOCK_INPUT;  
 #else /* not USE_X_TOOLKIT */  
   
   /* Make sure the X server knows where the window should be positioned,  
      in case the user deiconifies with the window manager.  */  
   if (! FRAME_VISIBLE_P (f) && !FRAME_ICONIFIED_P (f))  
     x_set_offset (f, f->output_data.x->left_pos, f->output_data.x->top_pos, 0);  
   
   /* Since we don't know which revision of X we're running, we'll use both  
      the X11R3 and X11R4 techniques.  I don't know if this is a good idea.  */  
   
   /* X11R4: send a ClientMessage to the window manager using the  
      WM_CHANGE_STATE type.  */  
   {  
     XEvent message;  
   
     message.xclient.window = FRAME_X_WINDOW (f);  
     message.xclient.type = ClientMessage;  
     message.xclient.message_type = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_change_state;  
     message.xclient.format = 32;  
     message.xclient.data.l[0] = IconicState;  
   
     if (! XSendEvent (FRAME_X_DISPLAY (f),  
                       DefaultRootWindow (FRAME_X_DISPLAY (f)),  
                       False,  
                       SubstructureRedirectMask | SubstructureNotifyMask,  
                       &message))  
       {  
         UNBLOCK_INPUT_RESIGNAL;  
         error ("Can't notify window manager of iconification");  
       }  
   }  
   
   /* X11R3: set the initial_state field of the window manager hints to  
      IconicState.  */  
   x_wm_set_window_state (f, IconicState);  
   
   if (!FRAME_VISIBLE_P (f))  
     {  
       /* If the frame was withdrawn, before, we must map it.  */  
       XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));  
     }  
   
   f->async_iconified = 1;  
   f->async_visible = 0;  
   
   XFlush (FRAME_X_DISPLAY (f));  
10122    UNBLOCK_INPUT;    UNBLOCK_INPUT;
 #endif /* not USE_X_TOOLKIT */  
 #endif /* MAC_TODO */  
10123  }  }
10124    
10125    
# Line 11560  static long app_sleep_time = WNE_SLEEP_A Line 11486  static long app_sleep_time = WNE_SLEEP_A
11486    
11487  Boolean terminate_flag = false;  Boolean terminate_flag = false;
11488    
11489  /* true if using command key as meta key */  /* True if using command key as meta key.  */
11490  Lisp_Object Vmac_command_key_is_meta;  Lisp_Object Vmac_command_key_is_meta;
11491    
11492    /* True if the ctrl and meta keys should be reversed.  */
11493    Lisp_Object Vmac_reverse_ctrl_meta;
11494    
11495    #if USE_CARBON_EVENTS
11496    /* True if the mouse wheel button (i.e. button 4) should map to
11497       mouse-2, instead of mouse-3.  */
11498    Lisp_Object Vmac_wheel_button_is_mouse_2;
11499    #endif
11500    
11501  /* convert input from Mac keyboard (assumed to be in Mac Roman coding)  /* convert input from Mac keyboard (assumed to be in Mac Roman coding)
11502     to this text encoding */     to this text encoding */
11503  int mac_keyboard_text_encoding;  int mac_keyboard_text_encoding;
# Line 11577  Lisp_Object drag_and_drop_file_list; Line 11512  Lisp_Object drag_and_drop_file_list;
11512  Point saved_menu_event_location;  Point saved_menu_event_location;
11513    
11514  /* Apple Events */  /* Apple Events */
11515  static void init_required_apple_events(void);  static void init_required_apple_events (void);
11516  static pascal OSErr  static pascal OSErr
11517  do_ae_open_application(const AppleEvent *, AppleEvent *, long);  do_ae_open_application (const AppleEvent *, AppleEvent *, long);
11518  static pascal OSErr  static pascal OSErr
11519  do_ae_print_documents(const AppleEvent *, AppleEvent *, long);  do_ae_print_documents (const AppleEvent *, AppleEvent *, long);
11520  static pascal OSErr do_ae_open_documents(AppleEvent *, AppleEvent *, long);  static pascal OSErr do_ae_open_documents (AppleEvent *, AppleEvent *, long);
11521  static pascal OSErr do_ae_quit_application(AppleEvent *, AppleEvent *, long);  static pascal OSErr do_ae_quit_application (AppleEvent *, AppleEvent *, long);
11522    
11523    /* Drag and Drop */
11524    static OSErr init_mac_drag_n_drop ();
11525    static pascal OSErr mac_do_receive_drag (WindowPtr, void*, DragReference);
11526    
11527    #if USE_CARBON_EVENTS
11528    /* Preliminary Support for the OSX Services Menu */
11529    static OSStatus mac_handle_service_event (EventHandlerCallRef,EventRef,void*);
11530    static void init_service_handler ();
11531    #endif
11532    
11533  extern void init_emacs_passwd_dir ();  extern void init_emacs_passwd_dir ();
11534  extern int emacs_main (int, char **, char **);  extern int emacs_main (int, char **, char **);
# Line 11592  extern void check_alarm (); Line 11537  extern void check_alarm ();
11537  extern void initialize_applescript();  extern void initialize_applescript();
11538  extern void terminate_applescript();  extern void terminate_applescript();
11539    
11540    static unsigned int
11541    #if USE_CARBON_EVENTS
11542    mac_to_emacs_modifiers (UInt32 mods)
11543    #else
11544    mac_to_emacs_modifiers (EventModifiers mods)
11545    #endif
11546    {
11547      unsigned int result = 0;
11548      if (mods & macShiftKey)
11549        result |= shift_modifier;
11550      if (mods & macCtrlKey)
11551        result |= ctrl_modifier;
11552      if (mods & macMetaKey)
11553        result |= meta_modifier;
11554      if (NILP (Vmac_command_key_is_meta) && (mods & macAltKey))
11555        result |= alt_modifier;
11556      return result;
11557    }
11558    
11559    #if USE_CARBON_EVENTS
11560    /* Obtains the event modifiers from the event ref and then calls
11561       mac_to_emacs_modifiers.  */
11562    static int
11563    mac_event_to_emacs_modifiers (EventRef eventRef)
11564    {
11565      UInt32 mods = 0;
11566      GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL,
11567                        sizeof (UInt32), NULL, &mods);
11568      return mac_to_emacs_modifiers (mods);
11569    }
11570    
11571    /* Given an event ref, return the code to use for the mouse button
11572       code in the emacs input_event.  */
11573    static int
11574    mac_get_mouse_btn (EventRef ref)
11575    {
11576      EventMouseButton result = kEventMouseButtonPrimary;
11577      GetEventParameter (ref, kEventParamMouseButton, typeMouseButton, NULL,
11578                        sizeof (EventMouseButton), NULL, &result);
11579      switch (result)
11580        {
11581        case kEventMouseButtonPrimary:
11582          return 0;
11583        case kEventMouseButtonSecondary:
11584          return NILP (Vmac_wheel_button_is_mouse_2) ? 2 : 1;
11585        case kEventMouseButtonTertiary:
11586        case 4:  /* 4 is the number for the mouse wheel button */
11587          return NILP (Vmac_wheel_button_is_mouse_2) ? 1 : 2;
11588        default:
11589          return 0;
11590        }
11591    }
11592    
11593    /* Normally, ConvertEventRefToEventRecord will correctly handle all
11594       events.  However the click of the mouse wheel is not converted to a
11595       mouseDown or mouseUp event.  This calls ConvertEventRef, but then
11596       checks to see if it is a mouse up or down carbon event that has not
11597       been converted, and if so, converts it by hand (to be picked up in
11598       the XTread_socket loop).  */
11599    static Boolean mac_convert_event_ref (EventRef eventRef, EventRecord *eventRec)
11600    {
11601      Boolean result = ConvertEventRefToEventRecord (eventRef, eventRec);
11602      /* Do special case for mouse wheel button.  */
11603      if (!result && GetEventClass (eventRef) == kEventClassMouse)
11604        {
11605          UInt32 kind = GetEventKind (eventRef);
11606          if (kind == kEventMouseDown && !(eventRec->what == mouseDown))
11607            {
11608              eventRec->what = mouseDown;
11609              result=1;
11610            }
11611          if (kind == kEventMouseUp && !(eventRec->what == mouseUp))
11612            {
11613              eventRec->what = mouseUp;
11614              result=1;
11615            }
11616          if (result)
11617            {
11618              /* Need where and when.  */
11619              UInt32 mods;
11620              GetEventParameter (eventRef, kEventParamMouseLocation,
11621                                 typeQDPoint, NULL, sizeof (Point),
11622                                 NULL, &eventRec->where);
11623              /* Use two step process because new event modifiers are
11624                 32-bit and old are 16-bit.  Currently, only loss is
11625                 NumLock & Fn. */
11626              GetEventParameter (eventRef, kEventParamKeyModifiers,
11627                                 typeUInt32, NULL, sizeof (UInt32),
11628                                 NULL, &mods);
11629              eventRec->modifiers = mods;
11630              
11631              eventRec->when = EventTimeToTicks (GetEventTime (eventRef));
11632            }
11633        }
11634      return result;
11635    }
11636    
11637    #endif
11638    
11639  static void  static void
11640  do_get_menus (void)  do_get_menus (void)
# Line 12019  do_zoom_window (WindowPtr w, int zoom_in Line 12062  do_zoom_window (WindowPtr w, int zoom_in
12062    SetPort (save_port);    SetPort (save_port);
12063  }  }
12064    
12065    /* Initialize Drag And Drop to allow files to be dropped onto emacs frames */
12066    static OSErr
12067    init_mac_drag_n_drop ()
12068    {
12069      OSErr result = InstallReceiveHandler (mac_do_receive_drag, 0L, NULL);
12070      return result;
12071    }
12072    
12073  /* Intialize AppleEvent dispatcher table for the required events.  */  /* Intialize AppleEvent dispatcher table for the required events.  */
12074  void  void
# Line 12092  init_required_apple_events () Line 12142  init_required_apple_events ()
12142      abort ();      abort ();
12143  }  }
12144    
12145    #if USE_CARBON_EVENTS
12146    
12147    void init_service_handler()
12148    {
12149      EventTypeSpec specs[] = {{kEventClassService, kEventServiceGetTypes},
12150                               {kEventClassService, kEventServiceCopy},
12151                               {kEventClassService, kEventServicePaste}};
12152      InstallApplicationEventHandler (NewEventHandlerUPP (mac_handle_service_event),
12153                                      3, specs, NULL, NULL);
12154    }
12155    
12156    /*
12157       MAC_TODO: Check to see if this is called by AEProcessDesc...
12158     */
12159    OSStatus mac_handle_service_event (EventHandlerCallRef callRef,
12160                                       EventRef event, void *data)
12161    {
12162      OSStatus err = noErr;
12163      switch (GetEventKind (event))
12164        {
12165        case kEventServiceGetTypes:
12166          {
12167            CFMutableArrayRef copyTypes, pasteTypes;
12168            CFStringRef type;
12169            Boolean selection = true;
12170            /*
12171              GetEventParameter(event, kEventParamServicePasteTypes,
12172              typeCFMutableArrayRef, NULL,
12173              sizeof (CFMutableArrayRef), NULL, &pasteTypes);
12174            */
12175            GetEventParameter(event, kEventParamServiceCopyTypes,
12176                              typeCFMutableArrayRef, NULL,
12177                              sizeof (CFMutableArrayRef), NULL, &copyTypes);
12178            type = CreateTypeStringWithOSType (kScrapFlavorTypeText);
12179            if (type) {
12180              CFArrayAppendValue (copyTypes, type);
12181              //CFArrayAppendValue (pasteTypes, type);
12182              CFRelease (type);
12183            }
12184          }
12185        case kEventServiceCopy:
12186          {
12187            ScrapRef currentScrap, specificScrap;
12188            char * buf = "";
12189            Size byteCount = 0;
12190    
12191            GetCurrentScrap (&currentScrap);
12192    
12193            err = GetScrapFlavorSize (currentScrap, kScrapFlavorTypeText, &byteCount);
12194            if (err == noErr)
12195              {
12196                void *buffer = xmalloc (byteCount);
12197                if (buffer != NULL)
12198                  {
12199                    GetEventParameter (event, kEventParamScrapRef, typeScrapRef, NULL,
12200                                       sizeof (ScrapRef), NULL, &specificScrap);
12201                  
12202                    err = GetScrapFlavorData (currentScrap, kScrapFlavorTypeText,
12203                                              &byteCount, buffer);
12204                    if (err == noErr)
12205                      PutScrapFlavor (specificScrap, kScrapFlavorTypeText,
12206                                      kScrapFlavorMaskNone, byteCount, buffer);
12207                    xfree (buffer);
12208                  }
12209              }
12210            err = noErr;
12211          }
12212        case kEventServicePaste:
12213          {
12214            /*
12215            // Get the current location
12216            Size     byteCount;
12217            ScrapRef specificScrap;
12218            GetEventParameter(event, kEventParamScrapRef, typeScrapRef, NULL,
12219                              sizeof(ScrapRef), NULL, &specificScrap);
12220            err = GetScrapFlavorSize(specificScrap, kScrapFlavorTypeText, &byteCount);
12221            if (err == noErr) {
12222              void * buffer = xmalloc(byteCount);
12223              if (buffer != NULL ) {
12224                err = GetScrapFlavorData(specificScrap, kScrapFlavorTypeText,
12225                                         &byteCount, buffer);
12226                if (err == noErr) {
12227                  // Actually place in the buffer
12228                  BLOCK_INPUT;
12229                  // Get the current "selection" string here
12230                  UNBLOCK_INPUT;
12231                }
12232              }
12233              xfree(buffer);
12234            }
12235            */
12236          }  
12237        }
12238      return err;
12239    }
12240    #endif
12241    
12242  /* Open Application Apple Event */  /* Open Application Apple Event */
12243  static pascal OSErr  static pascal OSErr
# Line 12187  descriptor_error_exit: Line 12333  descriptor_error_exit:
12333  }  }
12334    
12335    
12336    static pascal OSErr mac_do_receive_drag (WindowPtr window, void *handlerRefCon,
12337                                             DragReference theDrag)
12338    {
12339      short items;
12340      short index;
12341      FlavorFlags theFlags;
12342      Point mouse;
12343      OSErr result;
12344      ItemReference theItem;
12345      HFSFlavor data;
12346      FSRef fref;
12347      Size size = sizeof (HFSFlavor);
12348    
12349      drag_and_drop_file_list = Qnil;
12350      GetDragMouse (theDrag, &mouse, 0L);
12351      CountDragItems (theDrag, &items);
12352      for (index = 1; index <= items; index++)
12353        {
12354          /* Only handle file references.  */
12355          GetDragItemReferenceNumber (theDrag, index, &theItem);
12356          result = GetFlavorFlags (theDrag, theItem, flavorTypeHFS, &theFlags);
12357          if (result == noErr)
12358            {
12359    #ifdef MAC_OSX
12360              FSRef frref;
12361    #else
12362              Str255 path_name;
12363    #endif
12364              Str255 unix_path_name;
12365              GetFlavorData (theDrag, theItem, flavorTypeHFS, &data, &size, 0L);
12366    #ifdef MAC_OSX
12367              /* Use Carbon routines, otherwise it converts the file name
12368                 to /Macintosh HD/..., which is not correct. */
12369              FSpMakeFSRef (&data.fileSpec, &fref);
12370              if (! FSRefMakePath (&fref, unix_path_name, sizeof (unix_path_name)));
12371    #else
12372              if (path_from_vol_dir_name (path_name, 255, data.fileSpec.vRefNum,
12373                                          data.fileSpec.parID, data.fileSpec.name) &&
12374                  mac_to_posix_pathname (path_name, unix_path_name, 255))
12375    #endif
12376                drag_and_drop_file_list = Fcons (build_string (unix_path_name),
12377                                                 drag_and_drop_file_list);
12378            }
12379          else
12380            return;
12381        }
12382      /* If there are items in the list, construct an event and post it to
12383         the queue like an interrupt using kbd_buffer_store_event.  */
12384      if (!NILP (drag_and_drop_file_list))
12385        {
12386          struct input_event event;
12387          Lisp_Object frame;
12388          struct frame *f = ((mac_output *) GetWRefCon(window))->mFP;
12389          SetPort (GetWindowPort (window));
12390          GlobalToLocal (&mouse);
12391    
12392          event.kind = DRAG_N_DROP_EVENT;
12393          event.code = 0;
12394          event.modifiers = 0;
12395          event.timestamp = TickCount () * (1000 / 60);
12396          XSETINT (event.x, mouse.h);
12397          XSETINT (event.y, mouse.v);
12398          XSETFRAME (frame, f);
12399          event.frame_or_window = Fcons (frame, drag_and_drop_file_list);
12400          event.arg = Qnil;
12401          /* Post to the interrupt queue */
12402          kbd_buffer_store_event (&event);
12403          /* MAC_TODO: Mimic behavior of windows by switching contexts to Emacs */
12404          {
12405            ProcessSerialNumber psn;
12406            GetCurrentProcess (&psn);
12407            SetFrontProcess (&psn);
12408          }
12409        }
12410    }
12411    
12412    
12413  /* Print Document Apple Event */  /* Print Document Apple Event */
12414  static pascal OSErr  static pascal OSErr
12415  do_ae_print_documents (const AppleEvent *pAE, AppleEvent *reply, long refcon)  do_ae_print_documents (const AppleEvent *pAE, AppleEvent *reply, long refcon)
# Line 12334  keycode_to_xkeysym (int keyCode, int *xK Line 12557  keycode_to_xkeysym (int keyCode, int *xK
12557  int  int
12558  XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)  XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
12559  {  {
12560    int count = 0;    int count = 0;
12561    #if USE_CARBON_EVENTS
12562      OSStatus rneResult;
12563      EventRef eventRef;
12564      EventMouseButton mouseBtn;
12565    #endif
12566    EventRecord er;    EventRecord er;
12567    int the_modifiers;    int the_modifiers;
12568    EventMask event_mask;    EventMask event_mask;
# Line 12380  XTread_socket (int sd, struct input_even Line 12608  XTread_socket (int sd, struct input_even
12608    if (NILP (Fboundp (Qmac_ready_for_drag_n_drop)))    if (NILP (Fboundp (Qmac_ready_for_drag_n_drop)))
12609      event_mask -= highLevelEventMask;      event_mask -= highLevelEventMask;
12610    
12611    #if USE_CARBON_EVENTS
12612      rneResult = ReceiveNextEvent (0, NULL,
12613                                    expected ? TicksToEventTime(app_sleep_time) : 0,
12614                                    true, &eventRef);
12615      if (!rneResult)
12616        {
12617          /* Handle new events */
12618          if (!mac_convert_event_ref (eventRef, &er))
12619            switch (GetEventClass (eventRef))
12620              {
12621              case kEventClassMouse:
12622                if (GetEventKind (eventRef) == kEventMouseWheelMoved)
12623                  {
12624                    SInt32 delta;
12625                    Point point;
12626                    WindowPtr window_ptr = FrontWindow ();
12627                    struct mac_output *mwp = (mac_output *) GetWRefCon (window_ptr);
12628                    GetEventParameter(eventRef, kEventParamMouseWheelDelta,
12629                                      typeSInt32, NULL, sizeof (SInt32),
12630                                      NULL, &delta);
12631                    GetEventParameter(eventRef, kEventParamMouseLocation,
12632                                      typeQDPoint, NULL, sizeof (Point),
12633                                      NULL, &point);
12634                    bufp->kind = MOUSE_WHEEL_EVENT;
12635                    bufp->code = delta;
12636                    bufp->modifiers = mac_event_to_emacs_modifiers(eventRef);
12637                    SetPort (GetWindowPort (window_ptr));
12638                    GlobalToLocal (&point);
12639                    XSETINT (bufp->x, point.h);
12640                    XSETINT (bufp->y, point.v);
12641                    XSETFRAME (bufp->frame_or_window, mwp->mFP);
12642                    bufp->timestamp = EventTimeToTicks (GetEventTime (eventRef))*(1000/60);
12643                    count++;
12644                  }
12645                else
12646                  SendEventToEventTarget (eventRef, GetEventDispatcherTarget ());
12647    
12648                break;
12649              default:
12650                /* Send the event to the appropriate receiver.  */
12651                SendEventToEventTarget (eventRef, GetEventDispatcherTarget ());
12652              }
12653          else
12654    #else
12655    if (WaitNextEvent (event_mask, &er, (expected ? app_sleep_time : 0L), NULL))    if (WaitNextEvent (event_mask, &er, (expected ? app_sleep_time : 0L), NULL))
12656    #endif /* USE_CARBON_EVENTS */
12657      switch (er.what)      switch (er.what)
12658        {        {
12659        case mouseDown:        case mouseDown:
# Line 12389  XTread_socket (int sd, struct input_even Line 12662  XTread_socket (int sd, struct input_even
12662            WindowPtr window_ptr = FrontWindow ();            WindowPtr window_ptr = FrontWindow ();
12663            SInt16 part_code;            SInt16 part_code;
12664    
12665    #if USE_CARBON_EVENTS
12666              /* This is needed to correctly */
12667              SendEventToEventTarget (eventRef, GetEventDispatcherTarget ());
12668    #endif
12669    
12670            if (mouse_tracking_in_progress == mouse_tracking_scroll_bar            if (mouse_tracking_in_progress == mouse_tracking_scroll_bar
12671                && er.what == mouseUp)                && er.what == mouseUp)
12672              {              {
# Line 12404  XTread_socket (int sd, struct input_even Line 12682  XTread_socket (int sd, struct input_even
12682    
12683                GlobalToLocal (&mouse_loc);                GlobalToLocal (&mouse_loc);
12684                                        
12685    #if USE_CARBON_EVENTS
12686                  bufp->code = mac_get_mouse_btn (eventRef);
12687    #else
12688                bufp->code = 0;  /* only one mouse button */                bufp->code = 0;  /* only one mouse button */
12689    #endif
12690                bufp->kind = SCROLL_BAR_CLICK_EVENT;                bufp->kind = SCROLL_BAR_CLICK_EVENT;
12691                bufp->frame_or_window = tracked_scroll_bar->window;                bufp->frame_or_window = tracked_scroll_bar->window;
12692                bufp->part = scroll_bar_handle;                bufp->part = scroll_bar_handle;
12693                bufp->modifiers = up_modifier;  #if USE_CARBON_EVENTS
12694                  bufp->modifiers = mac_event_to_emacs_modifiers (eventRef);
12695    #else
12696                  bufp->modifiers = mac_to_emacs_modifiers (er.modifiers);
12697    #endif
12698                  bufp->modifiers |= up_modifier;
12699                bufp->timestamp = er.when * (1000 / 60);                bufp->timestamp = er.when * (1000 / 60);
12700                  /* ticks to milliseconds */                  /* ticks to milliseconds */
12701    
# Line 12461  XTread_socket (int sd, struct input_even Line 12748  XTread_socket (int sd, struct input_even
12748  #else  #else
12749                    control_part_code = FindControl (mouse_loc, window_ptr, &ch);                    control_part_code = FindControl (mouse_loc, window_ptr, &ch);
12750  #endif              #endif            
12751    
12752    #if USE_CARBON_EVENTS
12753                      bufp->code = mac_get_mouse_btn (eventRef);
12754    #else            
12755                    bufp->code = 0;  /* only one mouse button */                    bufp->code = 0;  /* only one mouse button */
12756    #endif
12757                    XSETINT (bufp->x, mouse_loc.h);                    XSETINT (bufp->x, mouse_loc.h);
12758                    XSETINT (bufp->y, mouse_loc.v);                    XSETINT (bufp->y, mouse_loc.v);
12759                    bufp->timestamp = er.when * (1000 / 60);                    bufp->timestamp = er.when * (1000 / 60);
# Line 12501  XTread_socket (int sd, struct input_even Line 12793  XTread_socket (int sd, struct input_even
12793                          mouse_tracking_in_progress = mouse_tracking_none;                          mouse_tracking_in_progress = mouse_tracking_none;
12794                      }                      }
12795                                                                    
12796    #if USE_CARBON_EVENTS
12797                      bufp->modifiers = mac_event_to_emacs_modifiers (eventRef);
12798    #else
12799                      bufp->modifiers = mac_to_emacs_modifiers (er.modifiers);
12800    #endif
12801    
12802                    switch (er.what)                    switch (er.what)
12803                      {                      {
12804                      case mouseDown:                      case mouseDown:
12805                        bufp->modifiers = down_modifier;                        bufp->modifiers |= down_modifier;
12806                        break;                        break;
12807                      case mouseUp:                      case mouseUp:
12808                        bufp->modifiers = up_modifier;                        bufp->modifiers |= up_modifier;
12809                        break;                        break;
12810                      }                      }
12811                                                                                                                                    
# Line 12559  XTread_socket (int sd, struct input_even Line 12857  XTread_socket (int sd, struct input_even
12857        case updateEvt:        case updateEvt:
12858        case osEvt:        case osEvt:
12859        case activateEvt:        case activateEvt:
12860    #if USE_CARBON_EVENTS
12861            SendEventToEventTarget (eventRef, GetEventDispatcherTarget ());
12862    #endif  
12863          do_events (&er);          do_events (&er);
12864          break;          break;
12865                    
# Line 12579  XTread_socket (int sd, struct input_even Line 12880  XTread_socket (int sd, struct input_even
12880              {              {
12881                bufp->code = 0xff00 | xkeysym;                bufp->code = 0xff00 | xkeysym;
12882                bufp->kind = NON_ASCII_KEYSTROKE_EVENT;                bufp->kind = NON_ASCII_KEYSTROKE_EVENT;
12883              }                      }      
12884              else if (!NILP (Vmac_reverse_ctrl_meta) && (er.modifiers & controlKey))
12885                {
12886                  /* This is a special case to deal with converting from
12887                     a control character to non-control character */
12888                  int new_modifiers = er.modifiers & ~controlKey;
12889                  int new_keycode = keycode | new_modifiers;              
12890                  Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
12891                  unsigned long some_state = 0;
12892                  bufp->code = KeyTranslate (kchr_ptr, new_keycode, &some_state) & 0xff;
12893                  bufp->kind = ASCII_KEYSTROKE_EVENT;
12894                }
12895            else            else
12896              {              {
12897                if (er.modifiers                if (er.modifiers & macMetaKey)
                   & (NILP (Vmac_command_key_is_meta) ? optionKey : cmdKey))  
12898                  {                  {
12899                    /* This code comes from Keyboard Resource, Appendix                    /* This code comes from Keyboard Resource, Appendix
12900                       C of IM - Text.  This is necessary since shift is                       C of IM - Text.  This is necessary since shift is
# Line 12597  XTread_socket (int sd, struct input_even Line 12908  XTread_socket (int sd, struct input_even
12908                    bufp->code = KeyTranslate (kchr_ptr, new_keycode,                    bufp->code = KeyTranslate (kchr_ptr, new_keycode,
12909                                               &some_state) & 0xff;                                               &some_state) & 0xff;
12910                  }                  }
12911    #if USE_CARBON_EVENTS
12912                  else if (er.modifiers & cmdKey &&
12913                           (NILP (Vmac_command_key_is_meta)))
12914                    {
12915                      /* If this is a command key (and we are not overriding it),
12916                         send back to the operating system  */
12917                      SendEventToEventTarget (eventRef, GetEventDispatcherTarget ());
12918                      break;
12919                    }
12920    #endif
12921                else                else
12922                  bufp->code = er.message & charCodeMask;                  bufp->code = er.message & charCodeMask;
12923                bufp->kind = ASCII_KEYSTROKE_EVENT;                bufp->kind = ASCII_KEYSTROKE_EVENT;
# Line 12654  XTread_socket (int sd, struct input_even Line 12975  XTread_socket (int sd, struct input_even
12975                }                }
12976            }            }
12977    
12978          the_modifiers = 0;  #if USE_CARBON_EVENTS
12979          if (er.modifiers & shiftKey)          bufp->modifiers = mac_event_to_emacs_modifiers (eventRef);
12980            the_modifiers |= shift_modifier;  #else
12981          if (er.modifiers & controlKey)          bufp->modifiers = mac_to_emacs_modifiers (er.modifiers);
12982            the_modifiers |= ctrl_modifier;  #endif
12983          /* Use option or command key as meta depending on value of          
            mac-command-key-is-meta.  */  
         if (er.modifiers  
             & (NILP (Vmac_command_key_is_meta) ? optionKey : cmdKey))  
           the_modifiers |= meta_modifier;  
   
         /* If the Mac option key is meta, then make Emacs recognize  
            the Mac command key as alt.  */  
         if (NILP (Vmac_command_key_is_meta) && (er.modifiers & cmdKey))  
           the_modifiers |= alt_modifier;  
   
         bufp->modifiers = the_modifiers;  
                                   
12984          {          {
12985            mac_output *mwp            mac_output *mwp
12986              = (mac_output *) GetWRefCon (FrontNonFloatingWindow ());              = (mac_output *) GetWRefCon (FrontNonFloatingWindow ());
# Line 12706  XTread_socket (int sd, struct input_even Line 13015  XTread_socket (int sd, struct input_even
13015              bufp->code = 0;              bufp->code = 0;
13016              bufp->timestamp = er.when * (1000 / 60);              bufp->timestamp = er.when * (1000 / 60);
13017                /* ticks to milliseconds */                /* ticks to milliseconds */
13018              bufp->modifiers = 0;  #if USE_CARBON_EVENTS
13019                bufp->modifiers = mac_event_to_emacs_modifiers (eventRef);
13020    #else
13021                bufp->modifiers = mac_to_emacs_modifiers (er.modifiers);
13022    #endif
13023    
13024              XSETINT (bufp->x, 0);              XSETINT (bufp->x, 0);
13025              XSETINT (bufp->y, 0);              XSETINT (bufp->y, 0);
# Line 12732  XTread_socket (int sd, struct input_even Line 13045  XTread_socket (int sd, struct input_even
13045                            
13046              count++;              count++;
13047            }            }
           
13048        default:        default:
13049          break;          break;
13050        }        }
13051    #if USE_CARBON_EVENTS
13052          ReleaseEvent (eventRef);
13053        }
13054    #endif
13055    
13056    /* If the focus was just given to an autoraising frame,    /* If the focus was just given to an autoraising frame,
13057       raise it now.  */       raise it now.  */
# Line 12847  NewMacWindow (FRAME_PTR fp) Line 13163  NewMacWindow (FRAME_PTR fp)
13163      if (!(mwp->mWP = GetNewCWindow (WINDOW_RESOURCE, NULL, (WindowPtr) -1)))      if (!(mwp->mWP = GetNewCWindow (WINDOW_RESOURCE, NULL, (WindowPtr) -1)))
13164        abort ();        abort ();
13165        
   
13166    SetWRefCon (mwp->mWP, (long) mwp);    SetWRefCon (mwp->mWP, (long) mwp);
13167      /* so that update events can find this mac_output struct */      /* so that update events can find this mac_output struct */
13168    mwp->mFP = fp;  /* point back to emacs frame */    mwp->mFP = fp;  /* point back to emacs frame */
# Line 13183  mac_initialize () Line 13498  mac_initialize ()
13498  #if TARGET_API_MAC_CARBON  #if TARGET_API_MAC_CARBON
13499    init_required_apple_events ();    init_required_apple_events ();
13500    
13501      init_mac_drag_n_drop ();
13502    
13503    #if USE_CARBON_EVENTS
13504      init_service_handler ();
13505    #endif
13506    
13507    DisableMenuCommand (NULL, kHICommandQuit);    DisableMenuCommand (NULL, kHICommandQuit);
13508  #endif  #endif
13509  }  }
# Line 13253  to 4.1, set this to nil.  */); Line 13574  to 4.1, set this to nil.  */);
13574  Otherwise the option key is used.  */);  Otherwise the option key is used.  */);
13575    Vmac_command_key_is_meta = Qt;    Vmac_command_key_is_meta = Qt;
13576    
13577      DEFVAR_LISP ("mac-reverse-ctrl-meta", &Vmac_reverse_ctrl_meta,
13578        doc: /* Non-nil means that the control and meta keys are reversed.  This is
13579                useful for non-standard keyboard layouts.  */);
13580      Vmac_reverse_ctrl_meta = Qnil;
13581    
13582    #if USE_CARBON_EVENTS
13583      DEFVAR_LISP ("mac-wheel-button-is-mouse-2", &Vmac_wheel_button_is_mouse_2,
13584       doc: /* Non-nil means that the wheel button will be treated as mouse-2 and
13585    the right click will be mouse-3.
13586    Otherwise, the right click will be mouse-2 and the wheel button mouse-3.*/);
13587      Vmac_wheel_button_is_mouse_2 = Qt;
13588    #endif
13589    
13590    DEFVAR_INT ("mac-keyboard-text-encoding", &mac_keyboard_text_encoding,    DEFVAR_INT ("mac-keyboard-text-encoding", &mac_keyboard_text_encoding,
13591      doc: /* One of the Text Encoding Base constant values defined in the      doc: /* One of the Text Encoding Base constant values defined in the
13592  Basic Text Constants section of Inside Macintosh - Text Encoding  Basic Text Constants section of Inside Macintosh - Text Encoding

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

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