Mercurial > emacs
comparison src/macterm.c @ 70384:a5899b40fd69
(XTread_socket) [TARGET_API_MAC_CARBON]: Try window
path select also for proxy icon click.
[TARGET_API_MAC_CARBON] (mac_post_mouse_moved_event): New function.
[USE_TOOLKIT_SCROLL_BARS] (scroll_bar_timer_callback): Use it.
(xlfdpat_create): Remove unused label `error' and trailing sentences.
(mac_do_track_drag, mac_do_receive_drag): Move functions to macselect.c.
(mac_do_track_dragUPP, mac_do_receive_dragUPP): Move variables to
macselect.c.
(install_drag_handler, remove_drag_handler): Add extern.
(mac_store_apple_event): Change return type to void. All uses changed.
Create Lisp object from Apple event and store it into input event.
(mac_make_lispy_event_code): Remove function.
[TARGET_API_MAC_CARBON] (mac_store_drag_event): New function.
(install_window_handler): Call install_drag_handler.
(remove_window_handler): Call remove_drag_handler.
author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> |
---|---|
date | Fri, 05 May 2006 06:44:45 +0000 |
parents | 085795461ed0 |
children | 8b2250961fcc |
comparison
equal
deleted
inserted
replaced
70383:84a220b0dd72 | 70384:a5899b40fd69 |
---|---|
4452 static pascal void | 4452 static pascal void |
4453 scroll_bar_timer_callback (timer, data) | 4453 scroll_bar_timer_callback (timer, data) |
4454 EventLoopTimerRef timer; | 4454 EventLoopTimerRef timer; |
4455 void *data; | 4455 void *data; |
4456 { | 4456 { |
4457 EventRef event = NULL; | 4457 OSStatus err; |
4458 OSErr err; | 4458 |
4459 | 4459 err = mac_post_mouse_moved_event (); |
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 | |
4475 err = SetEventParameter (event, kEventParamKeyModifiers, typeUInt32, | |
4476 sizeof (UInt32), &modifiers); | |
4477 } | |
4478 if (err == noErr) | |
4479 err = PostEventToQueue (GetCurrentEventQueue (), event, | |
4480 kEventPriorityStandard); | |
4481 if (err == noErr) | 4460 if (err == noErr) |
4482 scroll_bar_timer_event_posted_p = 1; | 4461 scroll_bar_timer_event_posted_p = 1; |
4483 | |
4484 if (event) | |
4485 ReleaseEvent (event); | |
4486 } | 4462 } |
4487 | 4463 |
4488 static OSStatus | 4464 static OSStatus |
4489 install_scroll_bar_timer () | 4465 install_scroll_bar_timer () |
4490 { | 4466 { |
6721 | 6697 |
6722 blk->last_char_skip = blk->skip[blk->last_char]; | 6698 blk->last_char_skip = blk->skip[blk->last_char]; |
6723 } | 6699 } |
6724 | 6700 |
6725 return pat; | 6701 return pat; |
6726 | |
6727 error: | |
6728 xlfdpat_destroy (pat); | |
6729 return NULL; | |
6730 } | 6702 } |
6731 | 6703 |
6732 static INLINE int | 6704 static INLINE int |
6733 xlfdpat_exact_p (pat) | 6705 xlfdpat_exact_p (pat) |
6734 struct xlfdpat *pat; | 6706 struct xlfdpat *pat; |
8413 extern void mac_find_apple_event_spec P_ ((AEEventClass, AEEventID, | 8385 extern void mac_find_apple_event_spec P_ ((AEEventClass, AEEventID, |
8414 Lisp_Object *, Lisp_Object *, | 8386 Lisp_Object *, Lisp_Object *, |
8415 Lisp_Object *)); | 8387 Lisp_Object *)); |
8416 extern OSErr init_coercion_handler P_ ((void)); | 8388 extern OSErr init_coercion_handler P_ ((void)); |
8417 | 8389 |
8418 #if TARGET_API_MAC_CARBON | |
8419 /* Drag and Drop */ | 8390 /* Drag and Drop */ |
8420 static pascal OSErr mac_do_track_drag (DragTrackingMessage, WindowPtr, void*, DragReference); | 8391 OSErr install_drag_handler P_ ((WindowRef)); |
8421 static pascal OSErr mac_do_receive_drag (WindowPtr, void*, DragReference); | 8392 void remove_drag_handler P_ ((WindowRef)); |
8422 static DragTrackingHandlerUPP mac_do_track_dragUPP = NULL; | |
8423 static DragReceiveHandlerUPP mac_do_receive_dragUPP = NULL; | |
8424 #endif | |
8425 | 8393 |
8426 #if USE_CARBON_EVENTS | 8394 #if USE_CARBON_EVENTS |
8427 #ifdef MAC_OSX | 8395 #ifdef MAC_OSX |
8428 extern void init_service_handler (); | 8396 extern void init_service_handler (); |
8429 static Lisp_Object Qservices, Qpaste, Qperform; | 8397 static Lisp_Object Qservices, Qpaste, Qperform; |
8975 FRAME_PIXEL_HEIGHT (f) = height; | 8943 FRAME_PIXEL_HEIGHT (f) = height; |
8976 } | 8944 } |
8977 x_real_positions (f, &f->left_pos, &f->top_pos); | 8945 x_real_positions (f, &f->left_pos, &f->top_pos); |
8978 } | 8946 } |
8979 | 8947 |
8980 OSErr | 8948 void |
8981 mac_store_apple_event (class, id, desc) | 8949 mac_store_apple_event (class, id, desc) |
8982 Lisp_Object class, id; | 8950 Lisp_Object class, id; |
8983 const AEDesc *desc; | 8951 const AEDesc *desc; |
8984 { | 8952 { |
8985 OSErr err; | |
8986 struct input_event buf; | 8953 struct input_event buf; |
8987 AEDesc *desc_copy; | 8954 |
8988 | 8955 EVENT_INIT (buf); |
8989 desc_copy = xmalloc (sizeof (AEDesc)); | 8956 |
8990 err = AEDuplicateDesc (desc, desc_copy); | 8957 buf.kind = MAC_APPLE_EVENT; |
8991 if (err == noErr) | 8958 buf.x = class; |
8992 { | 8959 buf.y = id; |
8993 EVENT_INIT (buf); | 8960 XSETFRAME (buf.frame_or_window, |
8994 | 8961 mac_focus_frame (&one_mac_display_info)); |
8995 buf.kind = MAC_APPLE_EVENT; | 8962 /* Now that Lisp object allocations are protected by BLOCK_INPUT, it |
8996 buf.x = class; | 8963 is safe to use them during read_socket_hook. */ |
8997 buf.y = id; | 8964 buf.arg = mac_aedesc_to_lisp (desc); |
8998 buf.code = (int)desc_copy; | 8965 kbd_buffer_store_event (&buf); |
8999 XSETFRAME (buf.frame_or_window, | 8966 } |
9000 mac_focus_frame (&one_mac_display_info)); | 8967 |
9001 buf.arg = Qnil; | 8968 #if TARGET_API_MAC_CARBON |
9002 kbd_buffer_store_event (&buf); | 8969 void |
9003 } | 8970 mac_store_drag_event (window, mouse_pos, modifiers, desc) |
9004 | 8971 WindowRef window; |
9005 return err; | 8972 Point mouse_pos; |
9006 } | 8973 SInt16 modifiers; |
9007 | 8974 const AEDesc *desc; |
9008 Lisp_Object | 8975 { |
9009 mac_make_lispy_event_code (code) | 8976 struct input_event buf; |
9010 int code; | 8977 |
9011 { | 8978 EVENT_INIT (buf); |
9012 AEDesc *desc = (AEDesc *)code; | 8979 |
9013 Lisp_Object obj; | 8980 buf.kind = DRAG_N_DROP_EVENT; |
9014 | 8981 buf.modifiers = mac_to_emacs_modifiers (modifiers); |
9015 obj = mac_aedesc_to_lisp (desc); | 8982 buf.timestamp = TickCount () * (1000 / 60); |
9016 AEDisposeDesc (desc); | 8983 XSETINT (buf.x, mouse_pos.h); |
9017 xfree (desc); | 8984 XSETINT (buf.y, mouse_pos.v); |
9018 | 8985 XSETFRAME (buf.frame_or_window, mac_window_to_frame (window)); |
9019 return obj; | 8986 buf.arg = mac_aedesc_to_lisp (desc); |
9020 } | 8987 kbd_buffer_store_event (&buf); |
8988 } | |
8989 #endif | |
9021 | 8990 |
9022 #if USE_CARBON_EVENTS | 8991 #if USE_CARBON_EVENTS |
9023 static pascal OSStatus | 8992 static pascal OSStatus |
9024 mac_handle_command_event (next_handler, event, data) | 8993 mac_handle_command_event (next_handler, event, data) |
9025 EventHandlerCallRef next_handler; | 8994 EventHandlerCallRef next_handler; |
9058 typeUInt32}; | 9027 typeUInt32}; |
9059 err = create_apple_event_from_event_ref (event, 2, names, types, | 9028 err = create_apple_event_from_event_ref (event, 2, names, types, |
9060 &apple_event); | 9029 &apple_event); |
9061 if (err == noErr) | 9030 if (err == noErr) |
9062 { | 9031 { |
9063 err = mac_store_apple_event (class_key, id_key, &apple_event); | 9032 mac_store_apple_event (class_key, id_key, &apple_event); |
9064 AEDisposeDesc (&apple_event); | 9033 AEDisposeDesc (&apple_event); |
9034 return noErr; | |
9065 } | 9035 } |
9066 if (err == noErr) | |
9067 return noErr; | |
9068 } | 9036 } |
9069 } | 9037 } |
9070 | 9038 |
9071 return eventNotHandledErr; | 9039 return eventNotHandledErr; |
9072 } | 9040 } |
9279 abort (); | 9247 abort (); |
9280 } | 9248 } |
9281 | 9249 |
9282 if (err == noErr) | 9250 if (err == noErr) |
9283 { | 9251 { |
9284 err = mac_store_apple_event (Qservices, id_key, &apple_event); | 9252 mac_store_apple_event (Qservices, id_key, &apple_event); |
9285 AEDisposeDesc (&apple_event); | 9253 AEDisposeDesc (&apple_event); |
9286 } | 9254 } |
9287 | 9255 |
9288 return err; | 9256 return err; |
9289 } | 9257 } |
9318 if (err == noErr) | 9286 if (err == noErr) |
9319 err = InstallWindowEventHandler (window, handle_mouse_eventUPP, | 9287 err = InstallWindowEventHandler (window, handle_mouse_eventUPP, |
9320 GetEventTypeCount (specs_mouse), | 9288 GetEventTypeCount (specs_mouse), |
9321 specs_mouse, NULL, NULL); | 9289 specs_mouse, NULL, NULL); |
9322 #endif | 9290 #endif |
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) | 9291 if (err == noErr) |
9330 err = InstallTrackingHandler (mac_do_track_dragUPP, window, NULL); | 9292 err = install_drag_handler (window); |
9331 if (err == noErr) | 9293 |
9332 err = InstallReceiveHandler (mac_do_receive_dragUPP, window, NULL); | |
9333 #endif | |
9334 return err; | 9294 return err; |
9335 } | 9295 } |
9336 | 9296 |
9337 void | 9297 void |
9338 remove_window_handler (window) | 9298 remove_window_handler (window) |
9339 WindowPtr window; | 9299 WindowPtr window; |
9340 { | 9300 { |
9341 #if TARGET_API_MAC_CARBON | 9301 remove_drag_handler (window); |
9342 if (mac_do_track_dragUPP) | 9302 } |
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 | |
9350 static pascal OSErr | |
9351 mac_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 } | |
9416 | |
9417 static pascal OSErr | |
9418 mac_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 | 9303 |
9502 | 9304 |
9503 #if __profile__ | 9305 #if __profile__ |
9504 void | 9306 void |
9505 profiler_exit_proc () | 9307 profiler_exit_proc () |
9781 if (dequeue) | 9583 if (dequeue) |
9782 er_buf.what = nullEvent; | 9584 er_buf.what = nullEvent; |
9783 return true; | 9585 return true; |
9784 } | 9586 } |
9785 #endif /* not USE_CARBON_EVENTS */ | 9587 #endif /* not USE_CARBON_EVENTS */ |
9588 | |
9589 #if TARGET_API_MAC_CARBON | |
9590 OSStatus | |
9591 mac_post_mouse_moved_event () | |
9592 { | |
9593 EventRef event = NULL; | |
9594 OSStatus err; | |
9595 | |
9596 err = CreateEvent (NULL, kEventClassMouse, kEventMouseMoved, 0, | |
9597 kEventAttributeNone, &event); | |
9598 if (err == noErr) | |
9599 { | |
9600 Point mouse_pos; | |
9601 | |
9602 GetMouse (&mouse_pos); | |
9603 LocalToGlobal (&mouse_pos); | |
9604 err = SetEventParameter (event, kEventParamMouseLocation, typeQDPoint, | |
9605 sizeof (Point), &mouse_pos); | |
9606 } | |
9607 if (err == noErr) | |
9608 { | |
9609 UInt32 modifiers = GetCurrentKeyModifiers (); | |
9610 | |
9611 err = SetEventParameter (event, kEventParamKeyModifiers, typeUInt32, | |
9612 sizeof (UInt32), &modifiers); | |
9613 } | |
9614 if (err == noErr) | |
9615 err = PostEventToQueue (GetCurrentEventQueue (), event, | |
9616 kEventPriorityStandard); | |
9617 if (event) | |
9618 ReleaseEvent (event); | |
9619 | |
9620 return err; | |
9621 } | |
9622 #endif | |
9786 | 9623 |
9787 /* Emacs calls this whenever it wants to read an input event from the | 9624 /* Emacs calls this whenever it wants to read an input event from the |
9788 user. */ | 9625 user. */ |
9789 int | 9626 int |
9790 XTread_socket (sd, expected, hold_quit) | 9627 XTread_socket (sd, expected, hold_quit) |
10056 break; | 9893 break; |
10057 } | 9894 } |
10058 } | 9895 } |
10059 break; | 9896 break; |
10060 | 9897 |
9898 case inDrag: | |
10061 #if TARGET_API_MAC_CARBON | 9899 #if TARGET_API_MAC_CARBON |
10062 case inProxyIcon: | 9900 case inProxyIcon: |
10063 if (TrackWindowProxyDrag (window_ptr, er.where) | |
10064 != errUserWantsToDragWindow) | |
10065 break; | |
10066 /* fall through */ | |
10067 #endif | |
10068 case inDrag: | |
10069 #if TARGET_API_MAC_CARBON | |
10070 if (IsWindowPathSelectClick (window_ptr, &er)) | 9901 if (IsWindowPathSelectClick (window_ptr, &er)) |
10071 { | 9902 { |
10072 WindowPathSelect (window_ptr, NULL, NULL); | 9903 WindowPathSelect (window_ptr, NULL, NULL); |
10073 break; | 9904 break; |
10074 } | 9905 } |
9906 if (part_code == inProxyIcon | |
9907 && (TrackWindowProxyDrag (window_ptr, er.where) | |
9908 != errUserWantsToDragWindow)) | |
9909 break; | |
10075 DragWindow (window_ptr, er.where, NULL); | 9910 DragWindow (window_ptr, er.where, NULL); |
10076 #else /* not TARGET_API_MAC_CARBON */ | 9911 #else /* not TARGET_API_MAC_CARBON */ |
10077 DragWindow (window_ptr, er.where, &qd.screenBits.bounds); | 9912 DragWindow (window_ptr, er.where, &qd.screenBits.bounds); |
10078 #endif /* not TARGET_API_MAC_CARBON */ | 9913 #endif /* not TARGET_API_MAC_CARBON */ |
10079 /* Update the frame parameters. */ | 9914 /* Update the frame parameters. */ |