aboutsummaryrefslogtreecommitdiffstats
path: root/src/macterm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/macterm.c')
-rw-r--r--src/macterm.c653
1 files changed, 345 insertions, 308 deletions
diff --git a/src/macterm.c b/src/macterm.c
index 45bc533893c..8af067e086b 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -4097,6 +4097,11 @@ x_new_focus_frame (dpyinfo, frame)
4097 pending_autoraise_frame = dpyinfo->x_focus_frame; 4097 pending_autoraise_frame = dpyinfo->x_focus_frame;
4098 else 4098 else
4099 pending_autoraise_frame = 0; 4099 pending_autoraise_frame = 0;
4100
4101#if USE_MAC_FONT_PANEL
4102 if (frame)
4103 mac_set_font_info_for_selection (frame);
4104#endif
4100 } 4105 }
4101 4106
4102 x_frame_rehighlight (dpyinfo); 4107 x_frame_rehighlight (dpyinfo);
@@ -4454,35 +4459,11 @@ scroll_bar_timer_callback (timer, data)
4454 EventLoopTimerRef timer; 4459 EventLoopTimerRef timer;
4455 void *data; 4460 void *data;
4456{ 4461{
4457 EventRef event = NULL; 4462 OSStatus err;
4458 OSErr err;
4459
4460 err = CreateEvent (NULL, kEventClassMouse, kEventMouseMoved, 0,
4461 kEventAttributeNone, &event);
4462 if (err == noErr)
4463 {
4464 Point mouse_pos;
4465
4466 GetMouse (&mouse_pos);
4467 LocalToGlobal (&mouse_pos);
4468 err = SetEventParameter (event, kEventParamMouseLocation, typeQDPoint,
4469 sizeof (Point), &mouse_pos);
4470 }
4471 if (err == noErr)
4472 {
4473 UInt32 modifiers = GetCurrentKeyModifiers ();
4474 4463
4475 err = SetEventParameter (event, kEventParamKeyModifiers, typeUInt32, 4464 err = mac_post_mouse_moved_event ();
4476 sizeof (UInt32), &modifiers);
4477 }
4478 if (err == noErr)
4479 err = PostEventToQueue (GetCurrentEventQueue (), event,
4480 kEventPriorityStandard);
4481 if (err == noErr) 4465 if (err == noErr)
4482 scroll_bar_timer_event_posted_p = 1; 4466 scroll_bar_timer_event_posted_p = 1;
4483
4484 if (event)
4485 ReleaseEvent (event);
4486} 4467}
4487 4468
4488static OSStatus 4469static OSStatus
@@ -6723,10 +6704,6 @@ xlfdpat_create (pattern)
6723 } 6704 }
6724 6705
6725 return pat; 6706 return pat;
6726
6727 error:
6728 xlfdpat_destroy (pat);
6729 return NULL;
6730} 6707}
6731 6708
6732static INLINE int 6709static INLINE int
@@ -6895,6 +6872,8 @@ static Lisp_Object fm_font_family_alist;
6895#if USE_ATSUI 6872#if USE_ATSUI
6896/* Hash table linking font family names to ATSU font IDs. */ 6873/* Hash table linking font family names to ATSU font IDs. */
6897static Lisp_Object atsu_font_id_hash; 6874static Lisp_Object atsu_font_id_hash;
6875static Lisp_Object Vmac_atsu_font_table;
6876extern Lisp_Object QCfamily, QCweight, QCslant, Qnormal, Qbold, Qitalic;
6898#endif 6877#endif
6899 6878
6900/* Alist linking character set strings to Mac text encoding and Emacs 6879/* Alist linking character set strings to Mac text encoding and Emacs
@@ -7190,8 +7169,21 @@ init_font_name_table ()
7190 NULL, NULL); 7169 NULL, NULL);
7191 if (err == noErr) 7170 if (err == noErr)
7192 { 7171 {
7172 FMFontFamily ff;
7173 FMFontStyle style = normal;
7174
7193 decode_mac_font_name (name, name_len + 1, Qnil); 7175 decode_mac_font_name (name, name_len + 1, Qnil);
7194 family = make_unibyte_string (name, name_len); 7176 family = make_unibyte_string (name, name_len);
7177 FMGetFontFamilyInstanceFromFont (font_ids[i], &ff, &style);
7178 Fputhash (make_unibyte_string ((char *)(font_ids + i),
7179 sizeof (ATSUFontID)),
7180 Fcons (QCfamily,
7181 list5 (family,
7182 QCweight,
7183 style & bold ? Qbold : Qnormal,
7184 QCslant,
7185 style & italic ? Qitalic : Qnormal)),
7186 Vmac_atsu_font_table);
7195 if (*name != '.' 7187 if (*name != '.'
7196 && hash_lookup (h, family, &hash_code) < 0) 7188 && hash_lookup (h, family, &hash_code) < 0)
7197 { 7189 {
@@ -7737,6 +7729,7 @@ XLoadQueryFont (Display *dpy, char *fontname)
7737 ATSUFontFeatureSelector selectors[] = {kAllTypeFeaturesOffSelector, 7729 ATSUFontFeatureSelector selectors[] = {kAllTypeFeaturesOffSelector,
7738 kDecomposeDiacriticsSelector}; 7730 kDecomposeDiacriticsSelector};
7739 Lisp_Object font_id_cons; 7731 Lisp_Object font_id_cons;
7732 FMFontStyle style;
7740 7733
7741 font_id_cons = Fgethash (make_unibyte_string (family, strlen (family)), 7734 font_id_cons = Fgethash (make_unibyte_string (family, strlen (family)),
7742 atsu_font_id_hash, Qnil); 7735 atsu_font_id_hash, Qnil);
@@ -7755,7 +7748,11 @@ XLoadQueryFont (Display *dpy, char *fontname)
7755 return NULL; 7748 return NULL;
7756 err = ATSUSetAttributes (mac_style, sizeof (tags) / sizeof (tags[0]), 7749 err = ATSUSetAttributes (mac_style, sizeof (tags) / sizeof (tags[0]),
7757 tags, sizes, values); 7750 tags, sizes, values);
7758 fontnum = -1; 7751 if (err != noErr)
7752 return NULL;
7753 err = FMGetFontFamilyInstanceFromFont (font_id, &fontnum, &style);
7754 if (err != noErr)
7755 fontnum = -1;
7759 scriptcode = kTextEncodingMacUnicode; 7756 scriptcode = kTextEncodingMacUnicode;
7760 } 7757 }
7761 else 7758 else
@@ -7815,22 +7812,20 @@ XLoadQueryFont (Display *dpy, char *fontname)
7815 pcm_init (font->bounds.rows[0], 0x100); 7812 pcm_init (font->bounds.rows[0], 0x100);
7816 7813
7817#if USE_CG_TEXT_DRAWING 7814#if USE_CG_TEXT_DRAWING
7818 { 7815 if (fontnum != -1)
7819 FMFontFamily font_family; 7816 {
7820 FMFontStyle style; 7817 FMFontStyle style;
7821 ATSFontRef ats_font; 7818 ATSFontRef ats_font;
7822 7819
7823 err = FMGetFontFamilyInstanceFromFont (font_id, &font_family, &style); 7820 err = FMGetFontFromFontFamilyInstance (fontnum, fontface,
7824 if (err == noErr)
7825 err = FMGetFontFromFontFamilyInstance (font_family, fontface,
7826 &font_id, &style); 7821 &font_id, &style);
7827 /* Use CG text drawing if italic/bold is not synthesized. */ 7822 /* Use CG text drawing if italic/bold is not synthesized. */
7828 if (err == noErr && style == fontface) 7823 if (err == noErr && style == fontface)
7829 { 7824 {
7830 ats_font = FMGetATSFontRefFromFont (font_id); 7825 ats_font = FMGetATSFontRefFromFont (font_id);
7831 font->cg_font = CGFontCreateWithPlatformFont (&ats_font); 7826 font->cg_font = CGFontCreateWithPlatformFont (&ats_font);
7832 } 7827 }
7833 } 7828 }
7834 7829
7835 if (font->cg_font) 7830 if (font->cg_font)
7836 { 7831 {
@@ -8319,6 +8314,42 @@ x_find_ccl_program (fontp)
8319 } 8314 }
8320} 8315}
8321 8316
8317#if USE_MAC_FONT_PANEL
8318OSStatus
8319mac_set_font_info_for_selection (f)
8320 struct frame *f;
8321{
8322 OSStatus err;
8323
8324 if (f == NULL)
8325 err = SetFontInfoForSelection (kFontSelectionATSUIType, 0, NULL, NULL);
8326 else
8327 {
8328 struct face *default_face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
8329 XFontStruct *ascii_font = default_face->ascii_face->font;
8330 EventTargetRef target = GetWindowEventTarget (FRAME_MAC_WINDOW (f));
8331
8332 if (ascii_font->mac_fontnum != -1)
8333 {
8334 FontSelectionQDStyle qd_style;
8335
8336 qd_style.version = kFontSelectionQDStyleVersionZero;
8337 qd_style.instance.fontFamily = ascii_font->mac_fontnum;
8338 qd_style.instance.fontStyle = ascii_font->mac_fontface;
8339 qd_style.size = ascii_font->mac_fontsize;
8340 qd_style.hasColor = false;
8341
8342 err = SetFontInfoForSelection (kFontSelectionQDType,
8343 1, &qd_style, target);
8344 }
8345 else
8346 err = SetFontInfoForSelection (kFontSelectionATSUIType,
8347 1, &ascii_font->mac_style, target);
8348 }
8349
8350 return err;
8351}
8352#endif
8322 8353
8323 8354
8324/* The Mac Event loop code */ 8355/* The Mac Event loop code */
@@ -8406,6 +8437,14 @@ Point saved_menu_event_location;
8406/* Apple Events */ 8437/* Apple Events */
8407#if USE_CARBON_EVENTS 8438#if USE_CARBON_EVENTS
8408static Lisp_Object Qhicommand; 8439static Lisp_Object Qhicommand;
8440#ifdef MAC_OSX
8441extern Lisp_Object Qwindow;
8442static Lisp_Object Qtoolbar_switch_mode;
8443#endif
8444#if USE_MAC_FONT_PANEL
8445extern Lisp_Object Qfont;
8446static Lisp_Object Qpanel_closed, Qselection;
8447#endif
8409#endif 8448#endif
8410extern int mac_ready_for_apple_events; 8449extern int mac_ready_for_apple_events;
8411extern Lisp_Object Qundefined; 8450extern Lisp_Object Qundefined;
@@ -8415,13 +8454,9 @@ extern void mac_find_apple_event_spec P_ ((AEEventClass, AEEventID,
8415 Lisp_Object *)); 8454 Lisp_Object *));
8416extern OSErr init_coercion_handler P_ ((void)); 8455extern OSErr init_coercion_handler P_ ((void));
8417 8456
8418#if TARGET_API_MAC_CARBON
8419/* Drag and Drop */ 8457/* Drag and Drop */
8420static pascal OSErr mac_do_track_drag (DragTrackingMessage, WindowPtr, void*, DragReference); 8458OSErr install_drag_handler P_ ((WindowRef));
8421static pascal OSErr mac_do_receive_drag (WindowPtr, void*, DragReference); 8459void remove_drag_handler P_ ((WindowRef));
8422static DragTrackingHandlerUPP mac_do_track_dragUPP = NULL;
8423static DragReceiveHandlerUPP mac_do_receive_dragUPP = NULL;
8424#endif
8425 8460
8426#if USE_CARBON_EVENTS 8461#if USE_CARBON_EVENTS
8427#ifdef MAC_OSX 8462#ifdef MAC_OSX
@@ -8977,47 +9012,84 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
8977 x_real_positions (f, &f->left_pos, &f->top_pos); 9012 x_real_positions (f, &f->left_pos, &f->top_pos);
8978} 9013}
8979 9014
8980OSErr 9015void
8981mac_store_apple_event (class, id, desc) 9016mac_store_apple_event (class, id, desc)
8982 Lisp_Object class, id; 9017 Lisp_Object class, id;
8983 const AEDesc *desc; 9018 const AEDesc *desc;
8984{ 9019{
8985 OSErr err;
8986 struct input_event buf; 9020 struct input_event buf;
8987 AEDesc *desc_copy;
8988 9021
8989 desc_copy = xmalloc (sizeof (AEDesc)); 9022 EVENT_INIT (buf);
8990 err = AEDuplicateDesc (desc, desc_copy); 9023
8991 if (err == noErr) 9024 buf.kind = MAC_APPLE_EVENT;
8992 { 9025 buf.x = class;
8993 EVENT_INIT (buf); 9026 buf.y = id;
9027 XSETFRAME (buf.frame_or_window,
9028 mac_focus_frame (&one_mac_display_info));
9029 /* Now that Lisp object allocations are protected by BLOCK_INPUT, it
9030 is safe to use them during read_socket_hook. */
9031 buf.arg = mac_aedesc_to_lisp (desc);
9032 kbd_buffer_store_event (&buf);
9033}
9034
9035#if TARGET_API_MAC_CARBON
9036static OSStatus
9037mac_store_event_ref_as_apple_event (class, id, class_key, id_key,
9038 event, num_params, names, types)
9039 AEEventClass class;
9040 AEEventID id;
9041 Lisp_Object class_key, id_key;
9042 EventRef event;
9043 UInt32 num_params;
9044 EventParamName *names;
9045 EventParamType *types;
9046{
9047 OSStatus err = eventNotHandledErr;
9048 Lisp_Object binding;
8994 9049
8995 buf.kind = MAC_APPLE_EVENT; 9050 mac_find_apple_event_spec (class, id, &class_key, &id_key, &binding);
8996 buf.x = class; 9051 if (!NILP (binding) && !EQ (binding, Qundefined))
8997 buf.y = id; 9052 {
8998 buf.code = (int)desc_copy; 9053 if (INTEGERP (binding))
8999 XSETFRAME (buf.frame_or_window, 9054 err = XINT (binding);
9000 mac_focus_frame (&one_mac_display_info)); 9055 else
9001 buf.arg = Qnil; 9056 {
9002 kbd_buffer_store_event (&buf); 9057 AppleEvent apple_event;
9058 err = create_apple_event_from_event_ref (event, num_params,
9059 names, types,
9060 &apple_event);
9061 if (err == noErr)
9062 {
9063 mac_store_apple_event (class_key, id_key, &apple_event);
9064 AEDisposeDesc (&apple_event);
9065 }
9066 }
9003 } 9067 }
9004 9068
9005 return err; 9069 return err;
9006} 9070}
9007 9071
9008Lisp_Object 9072void
9009mac_make_lispy_event_code (code) 9073mac_store_drag_event (window, mouse_pos, modifiers, desc)
9010 int code; 9074 WindowRef window;
9075 Point mouse_pos;
9076 SInt16 modifiers;
9077 const AEDesc *desc;
9011{ 9078{
9012 AEDesc *desc = (AEDesc *)code; 9079 struct input_event buf;
9013 Lisp_Object obj;
9014 9080
9015 obj = mac_aedesc_to_lisp (desc); 9081 EVENT_INIT (buf);
9016 AEDisposeDesc (desc);
9017 xfree (desc);
9018 9082
9019 return obj; 9083 buf.kind = DRAG_N_DROP_EVENT;
9084 buf.modifiers = mac_to_emacs_modifiers (modifiers);
9085 buf.timestamp = TickCount () * (1000 / 60);
9086 XSETINT (buf.x, mouse_pos.h);
9087 XSETINT (buf.y, mouse_pos.v);
9088 XSETFRAME (buf.frame_or_window, mac_window_to_frame (window));
9089 buf.arg = mac_aedesc_to_lisp (desc);
9090 kbd_buffer_store_event (&buf);
9020} 9091}
9092#endif
9021 9093
9022#if USE_CARBON_EVENTS 9094#if USE_CARBON_EVENTS
9023static pascal OSStatus 9095static pascal OSStatus
@@ -9028,7 +9100,11 @@ mac_handle_command_event (next_handler, event, data)
9028{ 9100{
9029 OSStatus result, err; 9101 OSStatus result, err;
9030 HICommand command; 9102 HICommand command;
9031 Lisp_Object class_key, id_key, binding; 9103 static EventParamName names[] = {kEventParamDirectObject,
9104 kEventParamKeyModifiers};
9105 static EventParamType types[] = {typeHICommand,
9106 typeUInt32};
9107 int num_params = sizeof (names) / sizeof (names[0]);
9032 9108
9033 result = CallNextEventHandler (next_handler, event); 9109 result = CallNextEventHandler (next_handler, event);
9034 if (result != eventNotHandledErr) 9110 if (result != eventNotHandledErr)
@@ -9042,33 +9118,10 @@ mac_handle_command_event (next_handler, event, data)
9042 9118
9043 /* A HICommand event is mapped to an Apple event whose event class 9119 /* A HICommand event is mapped to an Apple event whose event class
9044 symbol is `hicommand' and event ID is its command ID. */ 9120 symbol is `hicommand' and event ID is its command ID. */
9045 class_key = Qhicommand; 9121 err = mac_store_event_ref_as_apple_event (0, command.commandID,
9046 mac_find_apple_event_spec (0, command.commandID, 9122 Qhicommand, Qnil,
9047 &class_key, &id_key, &binding); 9123 event, num_params, names, types);
9048 if (!NILP (binding) && !EQ (binding, Qundefined)) 9124 return err == noErr ? noErr : eventNotHandledErr;
9049 {
9050 if (INTEGERP (binding))
9051 return XINT (binding);
9052 else
9053 {
9054 AppleEvent apple_event;
9055 static EventParamName names[] = {kEventParamDirectObject,
9056 kEventParamKeyModifiers};
9057 static EventParamType types[] = {typeHICommand,
9058 typeUInt32};
9059 err = create_apple_event_from_event_ref (event, 2, names, types,
9060 &apple_event);
9061 if (err == noErr)
9062 {
9063 err = mac_store_apple_event (class_key, id_key, &apple_event);
9064 AEDisposeDesc (&apple_event);
9065 }
9066 if (err == noErr)
9067 return noErr;
9068 }
9069 }
9070
9071 return eventNotHandledErr;
9072} 9125}
9073 9126
9074static OSErr 9127static OSErr
@@ -9171,6 +9224,33 @@ mac_handle_window_event (next_handler, event, data)
9171 return noErr; 9224 return noErr;
9172 9225
9173 break; 9226 break;
9227
9228#ifdef MAC_OSX
9229 case kEventWindowToolbarSwitchMode:
9230 result = CallNextEventHandler (next_handler, event);
9231 {
9232 static EventParamName names[] = {kEventParamDirectObject,
9233 kEventParamWindowMouseLocation,
9234 kEventParamKeyModifiers,
9235 kEventParamMouseButton,
9236 kEventParamClickCount,
9237 kEventParamMouseChord};
9238 static EventParamType types[] = {typeWindowRef,
9239 typeQDPoint,
9240 typeUInt32,
9241 typeMouseButton,
9242 typeUInt32,
9243 typeUInt32};
9244 int num_params = sizeof (names) / sizeof (names[0]);
9245
9246 err = mac_store_event_ref_as_apple_event (0, 0,
9247 Qwindow,
9248 Qtoolbar_switch_mode,
9249 event, num_params,
9250 names, types);
9251 }
9252 return err == noErr ? noErr : result;
9253#endif
9174 } 9254 }
9175 9255
9176 return eventNotHandledErr; 9256 return eventNotHandledErr;
@@ -9245,45 +9325,96 @@ mac_handle_mouse_event (next_handler, event, data)
9245 return eventNotHandledErr; 9325 return eventNotHandledErr;
9246} 9326}
9247 9327
9328#if USE_MAC_FONT_PANEL
9329static pascal OSStatus
9330mac_handle_font_event (next_handler, event, data)
9331 EventHandlerCallRef next_handler;
9332 EventRef event;
9333 void *data;
9334{
9335 OSStatus result, err;
9336 Lisp_Object id_key;
9337 int num_params;
9338 EventParamName *names;
9339 EventParamType *types;
9340 static EventParamName names_sel[] = {kEventParamATSUFontID,
9341 kEventParamATSUFontSize,
9342 kEventParamFMFontFamily,
9343 kEventParamFMFontSize,
9344 kEventParamFontColor};
9345 static EventParamType types_sel[] = {typeATSUFontID,
9346 typeATSUSize,
9347 typeFMFontFamily,
9348 typeFMFontSize,
9349 typeFontColor};
9350
9351 result = CallNextEventHandler (next_handler, event);
9352 if (result != eventNotHandledErr)
9353 return result;
9354
9355 switch (GetEventKind (event))
9356 {
9357 case kEventFontPanelClosed:
9358 id_key = Qpanel_closed;
9359 num_params = 0;
9360 names = NULL;
9361 types = NULL;
9362 break;
9363
9364 case kEventFontSelection:
9365 id_key = Qselection;
9366 num_params = sizeof (names_sel) / sizeof (names_sel[0]);
9367 names = names_sel;
9368 types = types_sel;
9369 break;
9370 }
9371
9372 err = mac_store_event_ref_as_apple_event (0, 0, Qfont, id_key,
9373 event, num_params,
9374 names, types);
9375
9376 return err == noErr ? noErr : eventNotHandledErr;
9377}
9378#endif
9379
9248#ifdef MAC_OSX 9380#ifdef MAC_OSX
9249OSErr 9381OSStatus
9250mac_store_services_event (event) 9382mac_store_services_event (event)
9251 EventRef event; 9383 EventRef event;
9252{ 9384{
9253 OSErr err; 9385 OSStatus err;
9254 AppleEvent apple_event;
9255 Lisp_Object id_key; 9386 Lisp_Object id_key;
9387 int num_params;
9388 EventParamName *names;
9389 EventParamType *types;
9390 static EventParamName names_pfm[] = {kEventParamServiceMessageName,
9391 kEventParamServiceUserData};
9392 static EventParamType types_pfm[] = {typeCFStringRef,
9393 typeCFStringRef};
9256 9394
9257 switch (GetEventKind (event)) 9395 switch (GetEventKind (event))
9258 { 9396 {
9259 case kEventServicePaste: 9397 case kEventServicePaste:
9260 id_key = Qpaste; 9398 id_key = Qpaste;
9261 err = create_apple_event_from_event_ref (event, 0, NULL, NULL, 9399 num_params = 0;
9262 &apple_event); 9400 names = NULL;
9401 types = NULL;
9263 break; 9402 break;
9264 9403
9265 case kEventServicePerform: 9404 case kEventServicePerform:
9266 { 9405 id_key = Qperform;
9267 static EventParamName names[] = {kEventParamServiceMessageName, 9406 num_params = sizeof (names_pfm) / sizeof (names_pfm[0]);
9268 kEventParamServiceUserData}; 9407 names = names_pfm;
9269 static EventParamType types[] = {typeCFStringRef, 9408 types = types_pfm;
9270 typeCFStringRef};
9271
9272 id_key = Qperform;
9273 err = create_apple_event_from_event_ref (event, 2, names, types,
9274 &apple_event);
9275 }
9276 break; 9409 break;
9277 9410
9278 default: 9411 default:
9279 abort (); 9412 abort ();
9280 } 9413 }
9281 9414
9282 if (err == noErr) 9415 err = mac_store_event_ref_as_apple_event (0, 0, Qservices, id_key,
9283 { 9416 event, num_params,
9284 err = mac_store_apple_event (Qservices, id_key, &apple_event); 9417 names, types);
9285 AEDisposeDesc (&apple_event);
9286 }
9287 9418
9288 return err; 9419 return err;
9289} 9420}
@@ -9303,15 +9434,28 @@ install_window_handler (window)
9303 {kEventClassWindow, kEventWindowShown}, 9434 {kEventClassWindow, kEventWindowShown},
9304 {kEventClassWindow, kEventWindowHidden}, 9435 {kEventClassWindow, kEventWindowHidden},
9305 {kEventClassWindow, kEventWindowExpanded}, 9436 {kEventClassWindow, kEventWindowExpanded},
9306 {kEventClassWindow, kEventWindowCollapsed}}; 9437 {kEventClassWindow, kEventWindowCollapsed},
9438#ifdef MAC_OSX
9439 {kEventClassWindow, kEventWindowToolbarSwitchMode},
9440#endif
9441 };
9307 EventTypeSpec specs_mouse[] = {{kEventClassMouse, kEventMouseWheelMoved}}; 9442 EventTypeSpec specs_mouse[] = {{kEventClassMouse, kEventMouseWheelMoved}};
9308 static EventHandlerUPP handle_window_eventUPP = NULL; 9443 static EventHandlerUPP handle_window_eventUPP = NULL;
9309 static EventHandlerUPP handle_mouse_eventUPP = NULL; 9444 static EventHandlerUPP handle_mouse_eventUPP = NULL;
9445#if USE_MAC_FONT_PANEL
9446 EventTypeSpec specs_font[] = {{kEventClassFont, kEventFontPanelClosed},
9447 {kEventClassFont, kEventFontSelection}};
9448 static EventHandlerUPP handle_font_eventUPP = NULL;
9449#endif
9310 9450
9311 if (handle_window_eventUPP == NULL) 9451 if (handle_window_eventUPP == NULL)
9312 handle_window_eventUPP = NewEventHandlerUPP (mac_handle_window_event); 9452 handle_window_eventUPP = NewEventHandlerUPP (mac_handle_window_event);
9313 if (handle_mouse_eventUPP == NULL) 9453 if (handle_mouse_eventUPP == NULL)
9314 handle_mouse_eventUPP = NewEventHandlerUPP (mac_handle_mouse_event); 9454 handle_mouse_eventUPP = NewEventHandlerUPP (mac_handle_mouse_event);
9455#if USE_MAC_FONT_PANEL
9456 if (handle_font_eventUPP == NULL)
9457 handle_font_eventUPP = NewEventHandlerUPP (mac_handle_font_event);
9458#endif
9315 err = InstallWindowEventHandler (window, handle_window_eventUPP, 9459 err = InstallWindowEventHandler (window, handle_window_eventUPP,
9316 GetEventTypeCount (specs_window), 9460 GetEventTypeCount (specs_window),
9317 specs_window, NULL, NULL); 9461 specs_window, NULL, NULL);
@@ -9319,18 +9463,16 @@ install_window_handler (window)
9319 err = InstallWindowEventHandler (window, handle_mouse_eventUPP, 9463 err = InstallWindowEventHandler (window, handle_mouse_eventUPP,
9320 GetEventTypeCount (specs_mouse), 9464 GetEventTypeCount (specs_mouse),
9321 specs_mouse, NULL, NULL); 9465 specs_mouse, NULL, NULL);
9322#endif 9466#if USE_MAC_FONT_PANEL
9323#if TARGET_API_MAC_CARBON
9324 if (mac_do_track_dragUPP == NULL)
9325 mac_do_track_dragUPP = NewDragTrackingHandlerUPP (mac_do_track_drag);
9326 if (mac_do_receive_dragUPP == NULL)
9327 mac_do_receive_dragUPP = NewDragReceiveHandlerUPP (mac_do_receive_drag);
9328
9329 if (err == noErr)
9330 err = InstallTrackingHandler (mac_do_track_dragUPP, window, NULL);
9331 if (err == noErr) 9467 if (err == noErr)
9332 err = InstallReceiveHandler (mac_do_receive_dragUPP, window, NULL); 9468 err = InstallWindowEventHandler (window, handle_font_eventUPP,
9469 GetEventTypeCount (specs_font),
9470 specs_font, NULL, NULL);
9333#endif 9471#endif
9472#endif
9473 if (err == noErr)
9474 err = install_drag_handler (window);
9475
9334 return err; 9476 return err;
9335} 9477}
9336 9478
@@ -9338,167 +9480,9 @@ void
9338remove_window_handler (window) 9480remove_window_handler (window)
9339 WindowPtr window; 9481 WindowPtr window;
9340{ 9482{
9341#if TARGET_API_MAC_CARBON 9483 remove_drag_handler (window);
9342 if (mac_do_track_dragUPP)
9343 RemoveTrackingHandler (mac_do_track_dragUPP, window);
9344 if (mac_do_receive_dragUPP)
9345 RemoveReceiveHandler (mac_do_receive_dragUPP, window);
9346#endif
9347}
9348
9349#if TARGET_API_MAC_CARBON
9350static pascal OSErr
9351mac_do_track_drag (DragTrackingMessage message, WindowPtr window,
9352 void *handlerRefCon, DragReference theDrag)
9353{
9354 static int can_accept;
9355 short items;
9356 short index;
9357 ItemReference theItem;
9358 FlavorFlags theFlags;
9359 OSErr result;
9360
9361 if (GetFrontWindowOfClass (kMovableModalWindowClass, false))
9362 return dragNotAcceptedErr;
9363
9364 switch (message)
9365 {
9366 case kDragTrackingEnterHandler:
9367 CountDragItems (theDrag, &items);
9368 can_accept = 0;
9369 for (index = 1; index <= items; index++)
9370 {
9371 GetDragItemReferenceNumber (theDrag, index, &theItem);
9372 result = GetFlavorFlags (theDrag, theItem, flavorTypeHFS, &theFlags);
9373 if (result == noErr)
9374 {
9375 can_accept = 1;
9376 break;
9377 }
9378 }
9379 break;
9380
9381 case kDragTrackingEnterWindow:
9382 if (can_accept)
9383 {
9384 RgnHandle hilite_rgn = NewRgn ();
9385 Rect r;
9386 struct frame *f = mac_window_to_frame (window);
9387
9388 GetWindowPortBounds (window, &r);
9389 OffsetRect (&r, -r.left, -r.top);
9390 RectRgn (hilite_rgn, &r);
9391 ShowDragHilite (theDrag, hilite_rgn, true);
9392 DisposeRgn (hilite_rgn);
9393 SetThemeCursor (kThemeCopyArrowCursor);
9394 }
9395 break;
9396
9397 case kDragTrackingInWindow:
9398 break;
9399
9400 case kDragTrackingLeaveWindow:
9401 if (can_accept)
9402 {
9403 struct frame *f = mac_window_to_frame (window);
9404
9405 HideDragHilite (theDrag);
9406 SetThemeCursor (kThemeArrowCursor);
9407 }
9408 break;
9409
9410 case kDragTrackingLeaveHandler:
9411 break;
9412 }
9413
9414 return noErr;
9415} 9484}
9416 9485
9417static pascal OSErr
9418mac_do_receive_drag (WindowPtr window, void *handlerRefCon,
9419 DragReference theDrag)
9420{
9421 short items;
9422 short index;
9423 FlavorFlags theFlags;
9424 Point mouse;
9425 OSErr result;
9426 ItemReference theItem;
9427 HFSFlavor data;
9428 Size size = sizeof (HFSFlavor);
9429 Lisp_Object file_list;
9430
9431 if (GetFrontWindowOfClass (kMovableModalWindowClass, false))
9432 return dragNotAcceptedErr;
9433
9434 file_list = Qnil;
9435 GetDragMouse (theDrag, &mouse, 0L);
9436 CountDragItems (theDrag, &items);
9437 for (index = 1; index <= items; index++)
9438 {
9439 /* Only handle file references. */
9440 GetDragItemReferenceNumber (theDrag, index, &theItem);
9441 result = GetFlavorFlags (theDrag, theItem, flavorTypeHFS, &theFlags);
9442 if (result == noErr)
9443 {
9444 OSErr err;
9445 AEDesc desc;
9446
9447 err = GetFlavorData (theDrag, theItem, flavorTypeHFS,
9448 &data, &size, 0L);
9449 if (err == noErr)
9450 err = AECoercePtr (typeFSS, &data.fileSpec, sizeof (FSSpec),
9451 TYPE_FILE_NAME, &desc);
9452 if (err == noErr)
9453 {
9454 Lisp_Object file;
9455
9456 /* x-dnd functions expect undecoded filenames. */
9457 file = make_uninit_string (AEGetDescDataSize (&desc));
9458 err = AEGetDescData (&desc, SDATA (file), SBYTES (file));
9459 if (err == noErr)
9460 file_list = Fcons (file, file_list);
9461 AEDisposeDesc (&desc);
9462 }
9463 }
9464 }
9465 /* If there are items in the list, construct an event and post it to
9466 the queue like an interrupt using kbd_buffer_store_event. */
9467 if (!NILP (file_list))
9468 {
9469 struct input_event event;
9470 Lisp_Object frame;
9471 struct frame *f = mac_window_to_frame (window);
9472 SInt16 modifiers;
9473
9474 GlobalToLocal (&mouse);
9475 GetDragModifiers (theDrag, NULL, NULL, &modifiers);
9476
9477 event.kind = DRAG_N_DROP_EVENT;
9478 event.code = 0;
9479 event.modifiers = mac_to_emacs_modifiers (modifiers);
9480 event.timestamp = TickCount () * (1000 / 60);
9481 XSETINT (event.x, mouse.h);
9482 XSETINT (event.y, mouse.v);
9483 XSETFRAME (frame, f);
9484 event.frame_or_window = frame;
9485 event.arg = file_list;
9486 /* Post to the interrupt queue */
9487 kbd_buffer_store_event (&event);
9488 /* MAC_TODO: Mimic behavior of windows by switching contexts to Emacs */
9489 {
9490 ProcessSerialNumber psn;
9491 GetCurrentProcess (&psn);
9492 SetFrontProcess (&psn);
9493 }
9494
9495 return noErr;
9496 }
9497 else
9498 return dragNotAcceptedErr;
9499}
9500#endif
9501
9502 9486
9503#if __profile__ 9487#if __profile__
9504void 9488void
@@ -9784,6 +9768,41 @@ mac_wait_next_event (er, sleep_time, dequeue)
9784} 9768}
9785#endif /* not USE_CARBON_EVENTS */ 9769#endif /* not USE_CARBON_EVENTS */
9786 9770
9771#if TARGET_API_MAC_CARBON
9772OSStatus
9773mac_post_mouse_moved_event ()
9774{
9775 EventRef event = NULL;
9776 OSStatus err;
9777
9778 err = CreateEvent (NULL, kEventClassMouse, kEventMouseMoved, 0,
9779 kEventAttributeNone, &event);
9780 if (err == noErr)
9781 {
9782 Point mouse_pos;
9783
9784 GetMouse (&mouse_pos);
9785 LocalToGlobal (&mouse_pos);
9786 err = SetEventParameter (event, kEventParamMouseLocation, typeQDPoint,
9787 sizeof (Point), &mouse_pos);
9788 }
9789 if (err == noErr)
9790 {
9791 UInt32 modifiers = GetCurrentKeyModifiers ();
9792
9793 err = SetEventParameter (event, kEventParamKeyModifiers, typeUInt32,
9794 sizeof (UInt32), &modifiers);
9795 }
9796 if (err == noErr)
9797 err = PostEventToQueue (GetCurrentEventQueue (), event,
9798 kEventPriorityStandard);
9799 if (event)
9800 ReleaseEvent (event);
9801
9802 return err;
9803}
9804#endif
9805
9787/* Emacs calls this whenever it wants to read an input event from the 9806/* Emacs calls this whenever it wants to read an input event from the
9788 user. */ 9807 user. */
9789int 9808int
@@ -9911,7 +9930,8 @@ XTread_socket (sd, expected, hold_quit)
9911 break; 9930 break;
9912 9931
9913 case inContent: 9932 case inContent:
9914 if (window_ptr != FRAME_MAC_WINDOW (mac_focus_frame (dpyinfo))) 9933 if (dpyinfo->x_focus_frame == NULL
9934 || window_ptr != FRAME_MAC_WINDOW (dpyinfo->x_focus_frame))
9915 SelectWindow (window_ptr); 9935 SelectWindow (window_ptr);
9916 else 9936 else
9917 { 9937 {
@@ -10058,20 +10078,18 @@ XTread_socket (sd, expected, hold_quit)
10058 } 10078 }
10059 break; 10079 break;
10060 10080
10061#if TARGET_API_MAC_CARBON
10062 case inProxyIcon:
10063 if (TrackWindowProxyDrag (window_ptr, er.where)
10064 != errUserWantsToDragWindow)
10065 break;
10066 /* fall through */
10067#endif
10068 case inDrag: 10081 case inDrag:
10069#if TARGET_API_MAC_CARBON 10082#if TARGET_API_MAC_CARBON
10083 case inProxyIcon:
10070 if (IsWindowPathSelectClick (window_ptr, &er)) 10084 if (IsWindowPathSelectClick (window_ptr, &er))
10071 { 10085 {
10072 WindowPathSelect (window_ptr, NULL, NULL); 10086 WindowPathSelect (window_ptr, NULL, NULL);
10073 break; 10087 break;
10074 } 10088 }
10089 if (part_code == inProxyIcon
10090 && (TrackWindowProxyDrag (window_ptr, er.where)
10091 != errUserWantsToDragWindow))
10092 break;
10075 DragWindow (window_ptr, er.where, NULL); 10093 DragWindow (window_ptr, er.where, NULL);
10076#else /* not TARGET_API_MAC_CARBON */ 10094#else /* not TARGET_API_MAC_CARBON */
10077 DragWindow (window_ptr, er.where, &qd.screenBits.bounds); 10095 DragWindow (window_ptr, er.where, &qd.screenBits.bounds);
@@ -11010,6 +11028,13 @@ syms_of_macterm ()
11010#if USE_CARBON_EVENTS 11028#if USE_CARBON_EVENTS
11011 Qhicommand = intern ("hicommand"); staticpro (&Qhicommand); 11029 Qhicommand = intern ("hicommand"); staticpro (&Qhicommand);
11012#ifdef MAC_OSX 11030#ifdef MAC_OSX
11031 Qtoolbar_switch_mode = intern ("toolbar-switch-mode");
11032 staticpro (&Qtoolbar_switch_mode);
11033#if USE_MAC_FONT_PANEL
11034 Qpanel_closed = intern ("panel-closed"); staticpro (&Qpanel_closed);
11035 Qselection = intern ("selection"); staticpro (&Qselection);
11036#endif
11037
11013 Qservices = intern ("services"); staticpro (&Qservices); 11038 Qservices = intern ("services"); staticpro (&Qservices);
11014 Qpaste = intern ("paste"); staticpro (&Qpaste); 11039 Qpaste = intern ("paste"); staticpro (&Qpaste);
11015 Qperform = intern ("perform"); staticpro (&Qperform); 11040 Qperform = intern ("perform"); staticpro (&Qperform);
@@ -11050,7 +11075,7 @@ NOTE: Not supported on Mac yet. */);
11050 x_use_underline_position_properties = 0; 11075 x_use_underline_position_properties = 0;
11051 11076
11052 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars, 11077 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars,
11053 doc: /* If not nil, Emacs uses toolkit scroll bars. */); 11078 doc: /* If not nil, Emacs uses toolkit scroll bars. */);
11054#ifdef USE_TOOLKIT_SCROLL_BARS 11079#ifdef USE_TOOLKIT_SCROLL_BARS
11055 Vx_toolkit_scroll_bars = Qt; 11080 Vx_toolkit_scroll_bars = Qt;
11056#else 11081#else
@@ -11104,23 +11129,23 @@ mouse-3 and the command-key will register for mouse-2. */);
11104 11129
11105#if USE_CARBON_EVENTS 11130#if USE_CARBON_EVENTS
11106 DEFVAR_BOOL ("mac-wheel-button-is-mouse-2", &mac_wheel_button_is_mouse_2, 11131 DEFVAR_BOOL ("mac-wheel-button-is-mouse-2", &mac_wheel_button_is_mouse_2,
11107 doc: /* *Non-nil if the wheel button is mouse-2 and the right click mouse-3. 11132 doc: /* *Non-nil if the wheel button is mouse-2 and the right click mouse-3.
11108Otherwise, the right click will be treated as mouse-2 and the wheel 11133Otherwise, the right click will be treated as mouse-2 and the wheel
11109button will be mouse-3. */); 11134button will be mouse-3. */);
11110 mac_wheel_button_is_mouse_2 = 1; 11135 mac_wheel_button_is_mouse_2 = 1;
11111 11136
11112 DEFVAR_BOOL ("mac-pass-command-to-system", &mac_pass_command_to_system, 11137 DEFVAR_BOOL ("mac-pass-command-to-system", &mac_pass_command_to_system,
11113 doc: /* *Non-nil if command key presses are passed on to the Mac Toolbox. */); 11138 doc: /* *Non-nil if command key presses are passed on to the Mac Toolbox. */);
11114 mac_pass_command_to_system = 1; 11139 mac_pass_command_to_system = 1;
11115 11140
11116 DEFVAR_BOOL ("mac-pass-control-to-system", &mac_pass_control_to_system, 11141 DEFVAR_BOOL ("mac-pass-control-to-system", &mac_pass_control_to_system,
11117 doc: /* *Non-nil if control key presses are passed on to the Mac Toolbox. */); 11142 doc: /* *Non-nil if control key presses are passed on to the Mac Toolbox. */);
11118 mac_pass_control_to_system = 1; 11143 mac_pass_control_to_system = 1;
11119 11144
11120#endif 11145#endif
11121 11146
11122 DEFVAR_BOOL ("mac-allow-anti-aliasing", &mac_use_core_graphics, 11147 DEFVAR_BOOL ("mac-allow-anti-aliasing", &mac_use_core_graphics,
11123 doc: /* *If non-nil, allow anti-aliasing. 11148 doc: /* *If non-nil, allow anti-aliasing.
11124The text will be rendered using Core Graphics text rendering which 11149The text will be rendered using Core Graphics text rendering which
11125may anti-alias the text. */); 11150may anti-alias the text. */);
11126#if USE_CG_DRAWING 11151#if USE_CG_DRAWING
@@ -11133,7 +11158,7 @@ may anti-alias the text. */);
11133 creating the terminal frame on Mac OS 9 before loading 11158 creating the terminal frame on Mac OS 9 before loading
11134 term/mac-win.elc. */ 11159 term/mac-win.elc. */
11135 DEFVAR_LISP ("mac-charset-info-alist", &Vmac_charset_info_alist, 11160 DEFVAR_LISP ("mac-charset-info-alist", &Vmac_charset_info_alist,
11136 doc: /* Alist of Emacs character sets vs text encodings and coding systems. 11161 doc: /* Alist of Emacs character sets vs text encodings and coding systems.
11137Each entry should be of the form: 11162Each entry should be of the form:
11138 11163
11139 (CHARSET-NAME TEXT-ENCODING CODING-SYSTEM) 11164 (CHARSET-NAME TEXT-ENCODING CODING-SYSTEM)
@@ -11144,6 +11169,18 @@ CODING_SYSTEM is a coding system corresponding to TEXT-ENCODING. */);
11144 Vmac_charset_info_alist = 11169 Vmac_charset_info_alist =
11145 Fcons (list3 (build_string ("mac-roman"), 11170 Fcons (list3 (build_string ("mac-roman"),
11146 make_number (smRoman), Qnil), Qnil); 11171 make_number (smRoman), Qnil), Qnil);
11172
11173#if USE_ATSUI
11174 DEFVAR_LISP ("mac-atsu-font-table", &Vmac_atsu_font_table,
11175 doc: /* Hash table of ATSU font IDs vs plist of attributes and values.
11176Each font ID is represented as a four-byte string in native byte
11177order. */);
11178 Vmac_atsu_font_table =
11179 make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE),
11180 make_float (DEFAULT_REHASH_SIZE),
11181 make_float (DEFAULT_REHASH_THRESHOLD),
11182 Qnil, Qnil, Qnil);
11183#endif
11147} 11184}
11148 11185
11149/* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b 11186/* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b