aboutsummaryrefslogtreecommitdiffstats
path: root/src/macterm.c
diff options
context:
space:
mode:
authorAndrew Choi2002-08-03 22:21:09 +0000
committerAndrew Choi2002-08-03 22:21:09 +0000
commit742fbed75b4cd5c2c2e7a8d4c0f4add9957e7f9a (patch)
tree2d119dccd908ef943fd9343fbaa646808dc3e0e4 /src/macterm.c
parent365417014078a0f260fd24d41845aeb274b876c8 (diff)
downloademacs-742fbed75b4cd5c2c2e7a8d4c0f4add9957e7f9a.tar.gz
emacs-742fbed75b4cd5c2c2e7a8d4c0f4add9957e7f9a.zip
In src:
2002-08-03 Andrew Choi <akochoi@shaw.ca> * macterm.c (USE_CARBON_EVENTS): New macro. (macCtrlKey, macShiftKey, macMetaKey, macAltKey): New macros. (x_iconify_frame): Call CollapseWindow. (Vmac_reverse_ctrl_meta): New variable. (Vmac_wheel_button_is_mouse_2): New variable. (init_mac_drag_n_drop): New function. (mac_do_receive_drag): New function. (mac_handle_service_event): New function. (init_service_handler): New function. (mac_to_emacs_modifiers): New function. (mac_event_to_emacs_modifiers): New function. (mac_get_mouse_btn): New function. (mac_convert_event_ref): New function. (XTread_socket) [USE_CARBON_EVENTS]: Call ReceiveNextEvent, SendEventToEventTarget, mac_event_to_emacs_modifiers, and mac_get_mouse_btn. (mac_initialize): Call init_mac_drag_n_drop and init_service_handler. * keyboard.c: Define Qmouse_wheel, mouse_wheel_syms, and lispy_mouse_wheel_names for MAC_OSX as well as for WINDOWS_NT. (kbd_buffer_get_event): Set used_mouse_menu for MENU_BAR_EVENT and TOOL_BAR_EVENT for MAC_OS as well. (make_lispy_event): Handle MOUSE_WHEEL_EVENT for MAC_OSX as well as for WINDOWS_NT. (syms_of_keyboard): Initialize Qmouse_wheel for MAC_OSX. * termhooks.h (event_kind): Define MOUSE_WHEEL_EVENT also for MAC_OSX. In lisp: 2002-08-03 Andrew Choi <akochoi@shaw.ca> * term/mac-win.el: Set keys to enable mouse wheel support.
Diffstat (limited to 'src/macterm.c')
-rw-r--r--src/macterm.c590
1 files changed, 462 insertions, 128 deletions
diff --git a/src/macterm.c b/src/macterm.c
index c471ba4bf35..c00c288001c 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -58,6 +58,10 @@ Boston, MA 02111-1307, USA. */
58#define max(a, b) ((a) > (b) ? (a) : (b)) 58#define max(a, b) ((a) > (b) ? (a) : (b))
59#undef init_process 59#undef init_process
60#define init_process emacs_init_process 60#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
61#else /* not MAC_OSX */ 65#else /* not MAC_OSX */
62#include <Quickdraw.h> 66#include <Quickdraw.h>
63#include <ToolUtils.h> 67#include <ToolUtils.h>
@@ -106,6 +110,15 @@ Boston, MA 02111-1307, USA. */
106 110
107#define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER)) 111#define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
108 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
109 122
110/* Fringe bitmaps. */ 123/* Fringe bitmaps. */
111 124
@@ -10092,108 +10105,21 @@ void
10092x_iconify_frame (f) 10105x_iconify_frame (f)
10093 struct frame *f; 10106 struct frame *f;
10094{ 10107{
10095#if 0 /* MAC_TODO: really no iconify on Mac */
10096 int result;
10097 Lisp_Object type;
10098
10099 /* Don't keep the highlight on an invisible frame. */ 10108 /* Don't keep the highlight on an invisible frame. */
10100 if (FRAME_X_DISPLAY_INFO (f)->x_highlight_frame == f) 10109 if (FRAME_MAC_DISPLAY_INFO (f)->x_highlight_frame == f)
10101 FRAME_X_DISPLAY_INFO (f)->x_highlight_frame = 0; 10110 FRAME_MAC_DISPLAY_INFO (f)->x_highlight_frame = 0;
10102 10111
10112#if 0
10113 /* Review: Since window is still visible in dock, still allow updates? */
10103 if (f->async_iconified) 10114 if (f->async_iconified)
10104 return; 10115 return;
10116#endif
10105 10117
10106 BLOCK_INPUT; 10118 BLOCK_INPUT;
10107 10119
10108 FRAME_SAMPLE_VISIBILITY (f); 10120 CollapseWindow (FRAME_MAC_WINDOW (f), true);
10109 10121
10110 type = x_icon_type (f);
10111 if (!NILP (type))
10112 x_bitmap_icon (f, type);
10113
10114#ifdef USE_X_TOOLKIT
10115
10116 if (! FRAME_VISIBLE_P (f))
10117 {
10118 if (! EQ (Vx_no_window_manager, Qt))
10119 x_wm_set_window_state (f, IconicState);
10120 /* This was XtPopup, but that did nothing for an iconified frame. */
10121 XtMapWidget (f->output_data.x->widget);
10122 /* The server won't give us any event to indicate
10123 that an invisible frame was changed to an icon,
10124 so we have to record it here. */
10125 f->iconified = 1;
10126 f->visible = 1;
10127 f->async_iconified = 1;
10128 f->async_visible = 0;
10129 UNBLOCK_INPUT;
10130 return;
10131 }
10132
10133 result = XIconifyWindow (FRAME_X_DISPLAY (f),
10134 XtWindow (f->output_data.x->widget),
10135 DefaultScreen (FRAME_X_DISPLAY (f)));
10136 UNBLOCK_INPUT;
10137
10138 if (!result)
10139 error ("Can't notify window manager of iconification");
10140
10141 f->async_iconified = 1;
10142 f->async_visible = 0;
10143
10144
10145 BLOCK_INPUT;
10146 XFlush (FRAME_X_DISPLAY (f));
10147 UNBLOCK_INPUT;
10148#else /* not USE_X_TOOLKIT */
10149
10150 /* Make sure the X server knows where the window should be positioned,
10151 in case the user deiconifies with the window manager. */
10152 if (! FRAME_VISIBLE_P (f) && !FRAME_ICONIFIED_P (f))
10153 x_set_offset (f, f->output_data.x->left_pos, f->output_data.x->top_pos, 0);
10154
10155 /* Since we don't know which revision of X we're running, we'll use both
10156 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
10157
10158 /* X11R4: send a ClientMessage to the window manager using the
10159 WM_CHANGE_STATE type. */
10160 {
10161 XEvent message;
10162
10163 message.xclient.window = FRAME_X_WINDOW (f);
10164 message.xclient.type = ClientMessage;
10165 message.xclient.message_type = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_change_state;
10166 message.xclient.format = 32;
10167 message.xclient.data.l[0] = IconicState;
10168
10169 if (! XSendEvent (FRAME_X_DISPLAY (f),
10170 DefaultRootWindow (FRAME_X_DISPLAY (f)),
10171 False,
10172 SubstructureRedirectMask | SubstructureNotifyMask,
10173 &message))
10174 {
10175 UNBLOCK_INPUT_RESIGNAL;
10176 error ("Can't notify window manager of iconification");
10177 }
10178 }
10179
10180 /* X11R3: set the initial_state field of the window manager hints to
10181 IconicState. */
10182 x_wm_set_window_state (f, IconicState);
10183
10184 if (!FRAME_VISIBLE_P (f))
10185 {
10186 /* If the frame was withdrawn, before, we must map it. */
10187 XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
10188 }
10189
10190 f->async_iconified = 1;
10191 f->async_visible = 0;
10192
10193 XFlush (FRAME_X_DISPLAY (f));
10194 UNBLOCK_INPUT; 10122 UNBLOCK_INPUT;
10195#endif /* not USE_X_TOOLKIT */
10196#endif /* MAC_TODO */
10197} 10123}
10198 10124
10199 10125
@@ -11560,9 +11486,18 @@ static long app_sleep_time = WNE_SLEEP_AT_RESUME;
11560 11486
11561Boolean terminate_flag = false; 11487Boolean terminate_flag = false;
11562 11488
11563/* true if using command key as meta key */ 11489/* True if using command key as meta key. */
11564Lisp_Object Vmac_command_key_is_meta; 11490Lisp_Object Vmac_command_key_is_meta;
11565 11491
11492/* True if the ctrl and meta keys should be reversed. */
11493Lisp_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. */
11498Lisp_Object Vmac_wheel_button_is_mouse_2;
11499#endif
11500
11566/* convert input from Mac keyboard (assumed to be in Mac Roman coding) 11501/* convert input from Mac keyboard (assumed to be in Mac Roman coding)
11567 to this text encoding */ 11502 to this text encoding */
11568int mac_keyboard_text_encoding; 11503int mac_keyboard_text_encoding;
@@ -11577,13 +11512,23 @@ Lisp_Object drag_and_drop_file_list;
11577Point saved_menu_event_location; 11512Point saved_menu_event_location;
11578 11513
11579/* Apple Events */ 11514/* Apple Events */
11580static void init_required_apple_events(void); 11515static void init_required_apple_events (void);
11581static pascal OSErr 11516static pascal OSErr
11582do_ae_open_application(const AppleEvent *, AppleEvent *, long); 11517do_ae_open_application (const AppleEvent *, AppleEvent *, long);
11583static pascal OSErr 11518static pascal OSErr
11584do_ae_print_documents(const AppleEvent *, AppleEvent *, long); 11519do_ae_print_documents (const AppleEvent *, AppleEvent *, long);
11585static pascal OSErr do_ae_open_documents(AppleEvent *, AppleEvent *, long); 11520static pascal OSErr do_ae_open_documents (AppleEvent *, AppleEvent *, long);
11586static pascal OSErr do_ae_quit_application(AppleEvent *, AppleEvent *, long); 11521static pascal OSErr do_ae_quit_application (AppleEvent *, AppleEvent *, long);
11522
11523/* Drag and Drop */
11524static OSErr init_mac_drag_n_drop ();
11525static pascal OSErr mac_do_receive_drag (WindowPtr, void*, DragReference);
11526
11527#if USE_CARBON_EVENTS
11528/* Preliminary Support for the OSX Services Menu */
11529static OSStatus mac_handle_service_event (EventHandlerCallRef,EventRef,void*);
11530static void init_service_handler ();
11531#endif
11587 11532
11588extern void init_emacs_passwd_dir (); 11533extern void init_emacs_passwd_dir ();
11589extern int emacs_main (int, char **, char **); 11534extern int emacs_main (int, char **, char **);
@@ -11592,6 +11537,104 @@ extern void check_alarm ();
11592extern void initialize_applescript(); 11537extern void initialize_applescript();
11593extern void terminate_applescript(); 11538extern void terminate_applescript();
11594 11539
11540static unsigned int
11541#if USE_CARBON_EVENTS
11542mac_to_emacs_modifiers (UInt32 mods)
11543#else
11544mac_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. */
11562static int
11563mac_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. */
11573static int
11574mac_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). */
11599static 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
11595 11638
11596static void 11639static void
11597do_get_menus (void) 11640do_get_menus (void)
@@ -12019,6 +12062,13 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
12019 SetPort (save_port); 12062 SetPort (save_port);
12020} 12063}
12021 12064
12065/* Initialize Drag And Drop to allow files to be dropped onto emacs frames */
12066static OSErr
12067init_mac_drag_n_drop ()
12068{
12069 OSErr result = InstallReceiveHandler (mac_do_receive_drag, 0L, NULL);
12070 return result;
12071}
12022 12072
12023/* Intialize AppleEvent dispatcher table for the required events. */ 12073/* Intialize AppleEvent dispatcher table for the required events. */
12024void 12074void
@@ -12092,6 +12142,102 @@ init_required_apple_events ()
12092 abort (); 12142 abort ();
12093} 12143}
12094 12144
12145#if USE_CARBON_EVENTS
12146
12147void 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 */
12159OSStatus 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
12095 12241
12096/* Open Application Apple Event */ 12242/* Open Application Apple Event */
12097static pascal OSErr 12243static pascal OSErr
@@ -12187,6 +12333,83 @@ descriptor_error_exit:
12187} 12333}
12188 12334
12189 12335
12336static 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
12190/* Print Document Apple Event */ 12413/* Print Document Apple Event */
12191static pascal OSErr 12414static pascal OSErr
12192do_ae_print_documents (const AppleEvent *pAE, AppleEvent *reply, long refcon) 12415do_ae_print_documents (const AppleEvent *pAE, AppleEvent *reply, long refcon)
@@ -12334,7 +12557,12 @@ keycode_to_xkeysym (int keyCode, int *xKeySym)
12334int 12557int
12335XTread_socket (int sd, struct input_event *bufp, int numchars, int expected) 12558XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
12336{ 12559{
12337 int count = 0; 12560 int count = 0;
12561#if USE_CARBON_EVENTS
12562 OSStatus rneResult;
12563 EventRef eventRef;
12564 EventMouseButton mouseBtn;
12565#endif
12338 EventRecord er; 12566 EventRecord er;
12339 int the_modifiers; 12567 int the_modifiers;
12340 EventMask event_mask; 12568 EventMask event_mask;
@@ -12380,7 +12608,52 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
12380 if (NILP (Fboundp (Qmac_ready_for_drag_n_drop))) 12608 if (NILP (Fboundp (Qmac_ready_for_drag_n_drop)))
12381 event_mask -= highLevelEventMask; 12609 event_mask -= highLevelEventMask;
12382 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
12383 if (WaitNextEvent (event_mask, &er, (expected ? app_sleep_time : 0L), NULL)) 12655 if (WaitNextEvent (event_mask, &er, (expected ? app_sleep_time : 0L), NULL))
12656#endif /* USE_CARBON_EVENTS */
12384 switch (er.what) 12657 switch (er.what)
12385 { 12658 {
12386 case mouseDown: 12659 case mouseDown:
@@ -12389,6 +12662,11 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
12389 WindowPtr window_ptr = FrontWindow (); 12662 WindowPtr window_ptr = FrontWindow ();
12390 SInt16 part_code; 12663 SInt16 part_code;
12391 12664
12665#if USE_CARBON_EVENTS
12666 /* This is needed to correctly */
12667 SendEventToEventTarget (eventRef, GetEventDispatcherTarget ());
12668#endif
12669
12392 if (mouse_tracking_in_progress == mouse_tracking_scroll_bar 12670 if (mouse_tracking_in_progress == mouse_tracking_scroll_bar
12393 && er.what == mouseUp) 12671 && er.what == mouseUp)
12394 { 12672 {
@@ -12404,11 +12682,20 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
12404 12682
12405 GlobalToLocal (&mouse_loc); 12683 GlobalToLocal (&mouse_loc);
12406 12684
12685#if USE_CARBON_EVENTS
12686 bufp->code = mac_get_mouse_btn (eventRef);
12687#else
12407 bufp->code = 0; /* only one mouse button */ 12688 bufp->code = 0; /* only one mouse button */
12689#endif
12408 bufp->kind = SCROLL_BAR_CLICK_EVENT; 12690 bufp->kind = SCROLL_BAR_CLICK_EVENT;
12409 bufp->frame_or_window = tracked_scroll_bar->window; 12691 bufp->frame_or_window = tracked_scroll_bar->window;
12410 bufp->part = scroll_bar_handle; 12692 bufp->part = scroll_bar_handle;
12411 bufp->modifiers = up_modifier; 12693#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;
12412 bufp->timestamp = er.when * (1000 / 60); 12699 bufp->timestamp = er.when * (1000 / 60);
12413 /* ticks to milliseconds */ 12700 /* ticks to milliseconds */
12414 12701
@@ -12461,7 +12748,12 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
12461#else 12748#else
12462 control_part_code = FindControl (mouse_loc, window_ptr, &ch); 12749 control_part_code = FindControl (mouse_loc, window_ptr, &ch);
12463#endif 12750#endif
12751
12752#if USE_CARBON_EVENTS
12753 bufp->code = mac_get_mouse_btn (eventRef);
12754#else
12464 bufp->code = 0; /* only one mouse button */ 12755 bufp->code = 0; /* only one mouse button */
12756#endif
12465 XSETINT (bufp->x, mouse_loc.h); 12757 XSETINT (bufp->x, mouse_loc.h);
12466 XSETINT (bufp->y, mouse_loc.v); 12758 XSETINT (bufp->y, mouse_loc.v);
12467 bufp->timestamp = er.when * (1000 / 60); 12759 bufp->timestamp = er.when * (1000 / 60);
@@ -12501,13 +12793,19 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
12501 mouse_tracking_in_progress = mouse_tracking_none; 12793 mouse_tracking_in_progress = mouse_tracking_none;
12502 } 12794 }
12503 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
12504 switch (er.what) 12802 switch (er.what)
12505 { 12803 {
12506 case mouseDown: 12804 case mouseDown:
12507 bufp->modifiers = down_modifier; 12805 bufp->modifiers |= down_modifier;
12508 break; 12806 break;
12509 case mouseUp: 12807 case mouseUp:
12510 bufp->modifiers = up_modifier; 12808 bufp->modifiers |= up_modifier;
12511 break; 12809 break;
12512 } 12810 }
12513 12811
@@ -12559,6 +12857,9 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
12559 case updateEvt: 12857 case updateEvt:
12560 case osEvt: 12858 case osEvt:
12561 case activateEvt: 12859 case activateEvt:
12860#if USE_CARBON_EVENTS
12861 SendEventToEventTarget (eventRef, GetEventDispatcherTarget ());
12862#endif
12562 do_events (&er); 12863 do_events (&er);
12563 break; 12864 break;
12564 12865
@@ -12579,11 +12880,21 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
12579 { 12880 {
12580 bufp->code = 0xff00 | xkeysym; 12881 bufp->code = 0xff00 | xkeysym;
12581 bufp->kind = NON_ASCII_KEYSTROKE_EVENT; 12882 bufp->kind = NON_ASCII_KEYSTROKE_EVENT;
12582 } 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 }
12583 else 12895 else
12584 { 12896 {
12585 if (er.modifiers 12897 if (er.modifiers & macMetaKey)
12586 & (NILP (Vmac_command_key_is_meta) ? optionKey : cmdKey))
12587 { 12898 {
12588 /* This code comes from Keyboard Resource, Appendix 12899 /* This code comes from Keyboard Resource, Appendix
12589 C of IM - Text. This is necessary since shift is 12900 C of IM - Text. This is necessary since shift is
@@ -12597,6 +12908,16 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
12597 bufp->code = KeyTranslate (kchr_ptr, new_keycode, 12908 bufp->code = KeyTranslate (kchr_ptr, new_keycode,
12598 &some_state) & 0xff; 12909 &some_state) & 0xff;
12599 } 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
12600 else 12921 else
12601 bufp->code = er.message & charCodeMask; 12922 bufp->code = er.message & charCodeMask;
12602 bufp->kind = ASCII_KEYSTROKE_EVENT; 12923 bufp->kind = ASCII_KEYSTROKE_EVENT;
@@ -12654,24 +12975,12 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
12654 } 12975 }
12655 } 12976 }
12656 12977
12657 the_modifiers = 0; 12978#if USE_CARBON_EVENTS
12658 if (er.modifiers & shiftKey) 12979 bufp->modifiers = mac_event_to_emacs_modifiers (eventRef);
12659 the_modifiers |= shift_modifier; 12980#else
12660 if (er.modifiers & controlKey) 12981 bufp->modifiers = mac_to_emacs_modifiers (er.modifiers);
12661 the_modifiers |= ctrl_modifier; 12982#endif
12662 /* Use option or command key as meta depending on value of 12983
12663 mac-command-key-is-meta. */
12664 if (er.modifiers
12665 & (NILP (Vmac_command_key_is_meta) ? optionKey : cmdKey))
12666 the_modifiers |= meta_modifier;
12667
12668 /* If the Mac option key is meta, then make Emacs recognize
12669 the Mac command key as alt. */
12670 if (NILP (Vmac_command_key_is_meta) && (er.modifiers & cmdKey))
12671 the_modifiers |= alt_modifier;
12672
12673 bufp->modifiers = the_modifiers;
12674
12675 { 12984 {
12676 mac_output *mwp 12985 mac_output *mwp
12677 = (mac_output *) GetWRefCon (FrontNonFloatingWindow ()); 12986 = (mac_output *) GetWRefCon (FrontNonFloatingWindow ());
@@ -12706,7 +13015,11 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
12706 bufp->code = 0; 13015 bufp->code = 0;
12707 bufp->timestamp = er.when * (1000 / 60); 13016 bufp->timestamp = er.when * (1000 / 60);
12708 /* ticks to milliseconds */ 13017 /* ticks to milliseconds */
12709 bufp->modifiers = 0; 13018#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
12710 13023
12711 XSETINT (bufp->x, 0); 13024 XSETINT (bufp->x, 0);
12712 XSETINT (bufp->y, 0); 13025 XSETINT (bufp->y, 0);
@@ -12732,10 +13045,13 @@ XTread_socket (int sd, struct input_event *bufp, int numchars, int expected)
12732 13045
12733 count++; 13046 count++;
12734 } 13047 }
12735
12736 default: 13048 default:
12737 break; 13049 break;
12738 } 13050 }
13051#if USE_CARBON_EVENTS
13052 ReleaseEvent (eventRef);
13053 }
13054#endif
12739 13055
12740 /* If the focus was just given to an autoraising frame, 13056 /* If the focus was just given to an autoraising frame,
12741 raise it now. */ 13057 raise it now. */
@@ -12847,7 +13163,6 @@ NewMacWindow (FRAME_PTR fp)
12847 if (!(mwp->mWP = GetNewCWindow (WINDOW_RESOURCE, NULL, (WindowPtr) -1))) 13163 if (!(mwp->mWP = GetNewCWindow (WINDOW_RESOURCE, NULL, (WindowPtr) -1)))
12848 abort (); 13164 abort ();
12849 13165
12850
12851 SetWRefCon (mwp->mWP, (long) mwp); 13166 SetWRefCon (mwp->mWP, (long) mwp);
12852 /* so that update events can find this mac_output struct */ 13167 /* so that update events can find this mac_output struct */
12853 mwp->mFP = fp; /* point back to emacs frame */ 13168 mwp->mFP = fp; /* point back to emacs frame */
@@ -13183,6 +13498,12 @@ mac_initialize ()
13183#if TARGET_API_MAC_CARBON 13498#if TARGET_API_MAC_CARBON
13184 init_required_apple_events (); 13499 init_required_apple_events ();
13185 13500
13501 init_mac_drag_n_drop ();
13502
13503#if USE_CARBON_EVENTS
13504 init_service_handler ();
13505#endif
13506
13186 DisableMenuCommand (NULL, kHICommandQuit); 13507 DisableMenuCommand (NULL, kHICommandQuit);
13187#endif 13508#endif
13188} 13509}
@@ -13253,6 +13574,19 @@ to 4.1, set this to nil. */);
13253Otherwise the option key is used. */); 13574Otherwise the option key is used. */);
13254 Vmac_command_key_is_meta = Qt; 13575 Vmac_command_key_is_meta = Qt;
13255 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
13585the right click will be mouse-3.
13586Otherwise, the right click will be mouse-2 and the wheel button mouse-3.*/);
13587 Vmac_wheel_button_is_mouse_2 = Qt;
13588#endif
13589
13256 DEFVAR_INT ("mac-keyboard-text-encoding", &mac_keyboard_text_encoding, 13590 DEFVAR_INT ("mac-keyboard-text-encoding", &mac_keyboard_text_encoding,
13257 doc: /* One of the Text Encoding Base constant values defined in the 13591 doc: /* One of the Text Encoding Base constant values defined in the
13258Basic Text Constants section of Inside Macintosh - Text Encoding 13592Basic Text Constants section of Inside Macintosh - Text Encoding