diff options
| author | YAMAMOTO Mitsuharu | 2008-03-29 00:46:51 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2008-03-29 00:46:51 +0000 |
| commit | 660425fa9e4e519db602df1100ca8946155c151e (patch) | |
| tree | 40470ba62ae68667807abb76dab7974e4109b0dd | |
| parent | c04e33a638db06b14497e6f6a667b1d49860a5ce (diff) | |
| download | emacs-660425fa9e4e519db602df1100ca8946155c151e.tar.gz emacs-660425fa9e4e519db602df1100ca8946155c151e.zip | |
Replace MenuHandle and GetMenuHandle with MenuRef and
GetMenuRef, respectively. Replace WindowPtr with WindowRef.
Replace ControlHandle with ControlRef.
(USE_CARBON_EVENTS): Remove. Use TARGET_API_MAC_CARBON instead.
[MAC_OS8] (do_get_menus): Rename variable `menu_handle' to `menu'.
(mac_begin_cg_clip): New arg F. Call SetPortWindowPort. All callers
changed so as not to call SetPortWindowPort.
(mac_begin_cg_clip) [USE_CG_DRAWING]: Call mac_prepare_for_quickdraw.
(mac_draw_image_string_atsui) [USE_ATSUI]: New function created from
mac_draw_string_common.
(mac_draw_image_string_qd): Likewise.
(mac_draw_string_common): Use them. Add INLINE.
(XTmouse_position, x_scroll_bar_report_motion) [TARGET_API_MAC_CARBON]:
Use FRAME_OUTER_TO_INNER_DIFF_X, FRAME_OUTER_TO_INNER_DIFF_Y, and
GetGlobalMouse.
(x_set_mouse_pixel_position) [MAC_OSX]: Use FRAME_OUTER_TO_INNER_DIFF_X
and FRAME_OUTER_TO_INNER_DIFF_Y.
[TARGET_API_MAC_CARBON] (mac_handle_mouse_event): Likewise.
[USE_MAC_TSM] (mac_handle_text_input_event): Likewise.
(x_make_frame_visible) [TARGET_API_MAC_CARBON]: Move code for
repositioning window to mac_handle_window_event.
(x_make_frame_invisible) [TARGET_API_MAC_CARBON]: Move code for
saving window location to mac_handle_window_event
[USE_MAC_FONT_PANEL] (mac_show_hide_font_panel): Install handler here.
(install_menu_target_item_handler): Remove argument in extern.
[TARGET_API_MAC_CARBON] (mac_event_to_emacs_modifiers):
Also accept command events.
(do_keystroke): New function created from XTread_socket.
(init_command_handler): Remove functions.
[TARGET_API_MAC_CARBON] (mac_handle_window_event): Reposition window
and save window location by kEventWindowShowing and kEventWindowHiding
handlers here. Don't call next handler for window state change and
focus events.
(mac_handle_keyboard_event) [TARGET_API_MAC_CARBON]: New function.
(install_window_handler) [TARGET_API_MAC_CARBON]: Register handlers for
kEventWindowShowing and kEventWindowHiding events. Move installation
of mouse, font, text input and menu target item handlers to
install_application_handler.
(install_application_handler) [TARGET_API_MAC_CARBON]: New function.
(mac_handle_cg_display_reconfig) [MAC_OS_X_VERSION_MAX_ALLOWED >= 1030]:
New function.
(init_dm_notification_handler) [MAC_OS_X_VERSION_MAX_ALLOWED >= 1030]:
Register it.
(XTread_socket) [TARGET_API_MAC_CARBON]:
Consolidate SendEventToEventTarget calls.
Use FRAME_OUTER_TO_INNER_DIFF_X and FRAME_OUTER_TO_INNER_DIFF_Y.
Move keyboard handler to mac_handle_keyboard_event.
(XTread_socket) [!TARGET_API_MAC_CARBON]: Use do_keystroke.
(mac_initialize) [TARGET_API_MAC_CARBON]: Don't call
init_command_handler. Call install_application_handler.
(x_draw_fringe_bitmap) [MAC_OSX]: Extend fringe background to scroll
bar gap.
(x_scroll_bar_create) [MAC_OSX]: Set bar->fringe_extended_p.
(XTset_vertical_scroll_bar) [MAC_OSX]: Put leftmost/rightmost
scroll bars on frame edge. Check fringe background extension.
Don't clear extended fringe background area.
(TOOLBAR_IDENTIFIER, TOOLBAR_ICON_ITEM_IDENTIFIER)
(TOOLBAR_ITEM_COMMAND_ID_OFFSET, TOOLBAR_ITEM_COMMAND_ID_P)
(TOOLBAR_ITEM_COMMAND_ID_VALUE, TOOLBAR_ITEM_MAKE_COMMAND_ID):
[USE_MAC_TOOLBAR]: New macros.
(mac_move_window_with_gravity, mac_get_window_origin_with_gravity)
(mac_handle_toolbar_event, mac_image_spec_to_cg_image)
(mac_create_frame_tool_bar, update_frame_tool_bar, free_frame_tool_bar)
(mac_tool_bar_note_mouse_movement, mac_handle_toolbar_command_event)
[USE_MAC_TOOLBAR]: New functions.
(mac_handle_window_event) [USE_MAC_TOOLBAR]: Reposition window
manually if previous repositioning has failed.
(mac_handle_keyboard_event): Use precomputed event kind.
(XTread_socket) [USE_MAC_TOOLBAR]: Handle click in structure region
as tool bar item click. Handle mouse movement over tool bar items.
(frame_highlight, frame_unhighlight): Don't call
ActivateControl/DeactivateControl here.
[USE_MAC_TOOLBAR] (free_frame_tool_bar): Suppress animation when
frame-notice-user-settings is non-nil.
[USE_MAC_FONT_PANEL] (mac_handle_font_event): Also record parameter
for kEventParamFMFontStyle.
[TARGET_API_MAC_CARBON] (mac_handle_keyboard_event): Don't check
mac_pass_command_to_system and mac_pass_control_to_system here.
(XTread_socket): Call ActivateControl/DeactivateControl here.
(XTread_socket) [TARGET_API_MAC_CARBON]:
Check mac_pass_command_to_system and mac_pass_control_to_system here.
[TARGET_API_MAC_CARBON] (mac_handle_window_event): Don't use invisible
frame as parent window for repositioning.
| -rw-r--r-- | src/macterm.c | 2825 |
1 files changed, 1838 insertions, 987 deletions
diff --git a/src/macterm.c b/src/macterm.c index b3e163029c6..9e5753ec3cc 100644 --- a/src/macterm.c +++ b/src/macterm.c | |||
| @@ -35,12 +35,7 @@ Boston, MA 02110-1301, USA. */ | |||
| 35 | #include <alloca.h> | 35 | #include <alloca.h> |
| 36 | #endif | 36 | #endif |
| 37 | 37 | ||
| 38 | #if TARGET_API_MAC_CARBON | 38 | #if !TARGET_API_MAC_CARBON |
| 39 | /* USE_CARBON_EVENTS determines if the Carbon Event Manager is used to | ||
| 40 | obtain events from the event queue. If set to 0, WaitNextEvent is | ||
| 41 | used instead. */ | ||
| 42 | #define USE_CARBON_EVENTS 1 | ||
| 43 | #else /* not TARGET_API_MAC_CARBON */ | ||
| 44 | #include <Quickdraw.h> | 39 | #include <Quickdraw.h> |
| 45 | #include <ToolUtils.h> | 40 | #include <ToolUtils.h> |
| 46 | #include <Sound.h> | 41 | #include <Sound.h> |
| @@ -263,7 +258,7 @@ static void x_scroll_bar_report_motion P_ ((struct frame **, Lisp_Object *, | |||
| 263 | Lisp_Object *, Lisp_Object *, | 258 | Lisp_Object *, Lisp_Object *, |
| 264 | unsigned long *)); | 259 | unsigned long *)); |
| 265 | 260 | ||
| 266 | static int is_emacs_window P_ ((WindowPtr)); | 261 | static int is_emacs_window P_ ((WindowRef)); |
| 267 | static XCharStruct *mac_per_char_metric P_ ((XFontStruct *, XChar2b *, int)); | 262 | static XCharStruct *mac_per_char_metric P_ ((XFontStruct *, XChar2b *, int)); |
| 268 | static void XSetFont P_ ((Display *, GC, XFontStruct *)); | 263 | static void XSetFont P_ ((Display *, GC, XFontStruct *)); |
| 269 | 264 | ||
| @@ -416,7 +411,8 @@ mac_prepare_for_quickdraw (f) | |||
| 416 | static RgnHandle saved_port_clip_region = NULL; | 411 | static RgnHandle saved_port_clip_region = NULL; |
| 417 | 412 | ||
| 418 | static void | 413 | static void |
| 419 | mac_begin_clip (gc) | 414 | mac_begin_clip (f, gc) |
| 415 | struct frame *f; | ||
| 420 | GC gc; | 416 | GC gc; |
| 421 | { | 417 | { |
| 422 | static RgnHandle new_region = NULL; | 418 | static RgnHandle new_region = NULL; |
| @@ -426,6 +422,11 @@ mac_begin_clip (gc) | |||
| 426 | if (new_region == NULL) | 422 | if (new_region == NULL) |
| 427 | new_region = NewRgn (); | 423 | new_region = NewRgn (); |
| 428 | 424 | ||
| 425 | #if USE_CG_DRAWING | ||
| 426 | mac_prepare_for_quickdraw (f); | ||
| 427 | #endif | ||
| 428 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | ||
| 429 | |||
| 429 | if (gc->n_clip_rects) | 430 | if (gc->n_clip_rects) |
| 430 | { | 431 | { |
| 431 | GetClip (saved_port_clip_region); | 432 | GetClip (saved_port_clip_region); |
| @@ -445,15 +446,6 @@ mac_end_clip (gc) | |||
| 445 | 446 | ||
| 446 | /* X display function emulation */ | 447 | /* X display function emulation */ |
| 447 | 448 | ||
| 448 | void | ||
| 449 | XFreePixmap (display, pixmap) | ||
| 450 | Display *display; /* not used */ | ||
| 451 | Pixmap pixmap; | ||
| 452 | { | ||
| 453 | DisposeGWorld (pixmap); | ||
| 454 | } | ||
| 455 | |||
| 456 | |||
| 457 | /* Mac version of XDrawLine. */ | 449 | /* Mac version of XDrawLine. */ |
| 458 | 450 | ||
| 459 | static void | 451 | static void |
| @@ -495,11 +487,8 @@ mac_draw_line (f, gc, x1, y1, x2, y2) | |||
| 495 | x2--; | 487 | x2--; |
| 496 | } | 488 | } |
| 497 | 489 | ||
| 498 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 490 | mac_begin_clip (f, gc); |
| 499 | |||
| 500 | RGBForeColor (GC_FORE_COLOR (gc)); | 491 | RGBForeColor (GC_FORE_COLOR (gc)); |
| 501 | |||
| 502 | mac_begin_clip (gc); | ||
| 503 | MoveTo (x1, y1); | 492 | MoveTo (x1, y1); |
| 504 | LineTo (x2, y2); | 493 | LineTo (x2, y2); |
| 505 | mac_end_clip (gc); | 494 | mac_end_clip (gc); |
| @@ -555,25 +544,25 @@ mac_erase_rectangle (f, gc, x, y, width, height) | |||
| 555 | unsigned int width, height; | 544 | unsigned int width, height; |
| 556 | { | 545 | { |
| 557 | #if USE_CG_DRAWING | 546 | #if USE_CG_DRAWING |
| 558 | CGContextRef context; | 547 | { |
| 548 | CGContextRef context; | ||
| 559 | 549 | ||
| 560 | context = mac_begin_cg_clip (f, gc); | 550 | context = mac_begin_cg_clip (f, gc); |
| 561 | CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc); | 551 | CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc); |
| 562 | CGContextFillRect (context, CGRectMake (x, y, width, height)); | 552 | CGContextFillRect (context, CGRectMake (x, y, width, height)); |
| 563 | mac_end_cg_clip (f); | 553 | mac_end_cg_clip (f); |
| 554 | } | ||
| 564 | #else | 555 | #else |
| 565 | Rect r; | 556 | { |
| 566 | 557 | Rect r; | |
| 567 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | ||
| 568 | |||
| 569 | RGBBackColor (GC_BACK_COLOR (gc)); | ||
| 570 | SetRect (&r, x, y, x + width, y + height); | ||
| 571 | |||
| 572 | mac_begin_clip (gc); | ||
| 573 | EraseRect (&r); | ||
| 574 | mac_end_clip (gc); | ||
| 575 | 558 | ||
| 576 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 559 | mac_begin_clip (f, gc); |
| 560 | RGBBackColor (GC_BACK_COLOR (gc)); | ||
| 561 | SetRect (&r, x, y, x + width, y + height); | ||
| 562 | EraseRect (&r); | ||
| 563 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | ||
| 564 | mac_end_clip (gc); | ||
| 565 | } | ||
| 577 | #endif | 566 | #endif |
| 578 | } | 567 | } |
| 579 | 568 | ||
| @@ -596,15 +585,17 @@ mac_clear_window (f) | |||
| 596 | struct frame *f; | 585 | struct frame *f; |
| 597 | { | 586 | { |
| 598 | #if USE_CG_DRAWING | 587 | #if USE_CG_DRAWING |
| 599 | CGContextRef context; | 588 | { |
| 600 | GC gc = FRAME_NORMAL_GC (f); | 589 | CGContextRef context; |
| 601 | 590 | GC gc = FRAME_NORMAL_GC (f); | |
| 602 | context = mac_begin_cg_clip (f, NULL); | 591 | |
| 603 | CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc); | 592 | context = mac_begin_cg_clip (f, NULL); |
| 604 | CGContextFillRect (context, CGRectMake (0, 0, FRAME_PIXEL_WIDTH (f), | 593 | CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc); |
| 605 | FRAME_PIXEL_HEIGHT (f))); | 594 | CGContextFillRect (context, CGRectMake (0, 0, FRAME_PIXEL_WIDTH (f), |
| 606 | mac_end_cg_clip (f); | 595 | FRAME_PIXEL_HEIGHT (f))); |
| 607 | #else | 596 | mac_end_cg_clip (f); |
| 597 | } | ||
| 598 | #else /* !USE_CG_DRAWING */ | ||
| 608 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 599 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); |
| 609 | 600 | ||
| 610 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 601 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| @@ -678,13 +669,10 @@ mac_draw_bitmap (f, gc, x, y, width, height, bits, overlay_p) | |||
| 678 | bitmap.baseAddr = (char *)bits; | 669 | bitmap.baseAddr = (char *)bits; |
| 679 | SetRect (&(bitmap.bounds), 0, 0, width, height); | 670 | SetRect (&(bitmap.bounds), 0, 0, width, height); |
| 680 | 671 | ||
| 681 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 672 | mac_begin_clip (f, gc); |
| 682 | |||
| 683 | RGBForeColor (GC_FORE_COLOR (gc)); | 673 | RGBForeColor (GC_FORE_COLOR (gc)); |
| 684 | RGBBackColor (GC_BACK_COLOR (gc)); | 674 | RGBBackColor (GC_BACK_COLOR (gc)); |
| 685 | SetRect (&r, x, y, x + width, y + height); | 675 | SetRect (&r, x, y, x + width, y + height); |
| 686 | |||
| 687 | mac_begin_clip (gc); | ||
| 688 | #if TARGET_API_MAC_CARBON | 676 | #if TARGET_API_MAC_CARBON |
| 689 | { | 677 | { |
| 690 | CGrafPtr port; | 678 | CGrafPtr port; |
| @@ -699,9 +687,8 @@ mac_draw_bitmap (f, gc, x, y, width, height, bits, overlay_p) | |||
| 699 | CopyBits (&bitmap, &(FRAME_MAC_WINDOW (f)->portBits), &(bitmap.bounds), &r, | 687 | CopyBits (&bitmap, &(FRAME_MAC_WINDOW (f)->portBits), &(bitmap.bounds), &r, |
| 700 | overlay_p ? srcOr : srcCopy, 0); | 688 | overlay_p ? srcOr : srcCopy, 0); |
| 701 | #endif /* not TARGET_API_MAC_CARBON */ | 689 | #endif /* not TARGET_API_MAC_CARBON */ |
| 702 | mac_end_clip (gc); | ||
| 703 | |||
| 704 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 690 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 691 | mac_end_clip (gc); | ||
| 705 | } | 692 | } |
| 706 | #endif /* !USE_CG_DRAWING */ | 693 | #endif /* !USE_CG_DRAWING */ |
| 707 | 694 | ||
| @@ -752,8 +739,8 @@ mac_free_bitmap (bitmap) | |||
| 752 | 739 | ||
| 753 | Pixmap | 740 | Pixmap |
| 754 | XCreatePixmap (display, w, width, height, depth) | 741 | XCreatePixmap (display, w, width, height, depth) |
| 755 | Display *display; /* not used */ | 742 | Display *display; |
| 756 | WindowPtr w; | 743 | WindowRef w; |
| 757 | unsigned int width, height; | 744 | unsigned int width, height; |
| 758 | unsigned int depth; | 745 | unsigned int depth; |
| 759 | { | 746 | { |
| @@ -781,8 +768,8 @@ XCreatePixmap (display, w, width, height, depth) | |||
| 781 | 768 | ||
| 782 | Pixmap | 769 | Pixmap |
| 783 | XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth) | 770 | XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth) |
| 784 | Display *display; /* not used */ | 771 | Display *display; |
| 785 | WindowPtr w; | 772 | WindowRef w; |
| 786 | char *data; | 773 | char *data; |
| 787 | unsigned int width, height; | 774 | unsigned int width, height; |
| 788 | unsigned long fg, bg; | 775 | unsigned long fg, bg; |
| @@ -792,7 +779,7 @@ XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth) | |||
| 792 | BitMap bitmap; | 779 | BitMap bitmap; |
| 793 | CGrafPtr old_port; | 780 | CGrafPtr old_port; |
| 794 | GDHandle old_gdh; | 781 | GDHandle old_gdh; |
| 795 | static GC gc = NULL; /* not reentrant */ | 782 | static GC gc = NULL; |
| 796 | 783 | ||
| 797 | if (gc == NULL) | 784 | if (gc == NULL) |
| 798 | gc = XCreateGC (display, w, 0, NULL); | 785 | gc = XCreateGC (display, w, 0, NULL); |
| @@ -824,6 +811,15 @@ XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth) | |||
| 824 | } | 811 | } |
| 825 | 812 | ||
| 826 | 813 | ||
| 814 | void | ||
| 815 | XFreePixmap (display, pixmap) | ||
| 816 | Display *display; | ||
| 817 | Pixmap pixmap; | ||
| 818 | { | ||
| 819 | DisposeGWorld (pixmap); | ||
| 820 | } | ||
| 821 | |||
| 822 | |||
| 827 | /* Mac replacement for XFillRectangle. */ | 823 | /* Mac replacement for XFillRectangle. */ |
| 828 | 824 | ||
| 829 | static void | 825 | static void |
| @@ -843,12 +839,9 @@ mac_fill_rectangle (f, gc, x, y, width, height) | |||
| 843 | #else | 839 | #else |
| 844 | Rect r; | 840 | Rect r; |
| 845 | 841 | ||
| 846 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 842 | mac_begin_clip (f, gc); |
| 847 | |||
| 848 | RGBForeColor (GC_FORE_COLOR (gc)); | 843 | RGBForeColor (GC_FORE_COLOR (gc)); |
| 849 | SetRect (&r, x, y, x + width, y + height); | 844 | SetRect (&r, x, y, x + width, y + height); |
| 850 | |||
| 851 | mac_begin_clip (gc); | ||
| 852 | PaintRect (&r); /* using foreground color of gc */ | 845 | PaintRect (&r); /* using foreground color of gc */ |
| 853 | mac_end_clip (gc); | 846 | mac_end_clip (gc); |
| 854 | #endif | 847 | #endif |
| @@ -875,18 +868,34 @@ mac_draw_rectangle (f, gc, x, y, width, height) | |||
| 875 | #else | 868 | #else |
| 876 | Rect r; | 869 | Rect r; |
| 877 | 870 | ||
| 878 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 871 | mac_begin_clip (f, gc); |
| 879 | |||
| 880 | RGBForeColor (GC_FORE_COLOR (gc)); | 872 | RGBForeColor (GC_FORE_COLOR (gc)); |
| 881 | SetRect (&r, x, y, x + width + 1, y + height + 1); | 873 | SetRect (&r, x, y, x + width + 1, y + height + 1); |
| 882 | |||
| 883 | mac_begin_clip (gc); | ||
| 884 | FrameRect (&r); /* using foreground color of gc */ | 874 | FrameRect (&r); /* using foreground color of gc */ |
| 885 | mac_end_clip (gc); | 875 | mac_end_clip (gc); |
| 886 | #endif | 876 | #endif |
| 887 | } | 877 | } |
| 888 | 878 | ||
| 889 | 879 | ||
| 880 | static void | ||
| 881 | mac_invert_rectangle (f, x, y, width, height) | ||
| 882 | struct frame *f; | ||
| 883 | int x, y; | ||
| 884 | unsigned int width, height; | ||
| 885 | { | ||
| 886 | Rect r; | ||
| 887 | |||
| 888 | #if USE_CG_DRAWING | ||
| 889 | mac_prepare_for_quickdraw (f); | ||
| 890 | #endif | ||
| 891 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | ||
| 892 | |||
| 893 | SetRect (&r, x, y, x + width, y + height); | ||
| 894 | |||
| 895 | InvertRect (&r); | ||
| 896 | } | ||
| 897 | |||
| 898 | |||
| 890 | #if USE_ATSUI | 899 | #if USE_ATSUI |
| 891 | static OSStatus | 900 | static OSStatus |
| 892 | atsu_get_text_layout_with_text_ptr (text, text_length, style, text_layout) | 901 | atsu_get_text_layout_with_text_ptr (text, text_length, style, text_layout) |
| @@ -896,7 +905,7 @@ atsu_get_text_layout_with_text_ptr (text, text_length, style, text_layout) | |||
| 896 | ATSUTextLayout *text_layout; | 905 | ATSUTextLayout *text_layout; |
| 897 | { | 906 | { |
| 898 | OSStatus err; | 907 | OSStatus err; |
| 899 | static ATSUTextLayout saved_text_layout = NULL; /* not reentrant */ | 908 | static ATSUTextLayout saved_text_layout = NULL; |
| 900 | 909 | ||
| 901 | if (saved_text_layout == NULL) | 910 | if (saved_text_layout == NULL) |
| 902 | { | 911 | { |
| @@ -923,7 +932,6 @@ atsu_get_text_layout_with_text_ptr (text, text_length, style, text_layout) | |||
| 923 | err = ATSUSetLayoutControls (saved_text_layout, | 932 | err = ATSUSetLayoutControls (saved_text_layout, |
| 924 | sizeof (tags) / sizeof (tags[0]), | 933 | sizeof (tags) / sizeof (tags[0]), |
| 925 | tags, sizes, values); | 934 | tags, sizes, values); |
| 926 | /* XXX: Should we do this? */ | ||
| 927 | if (err == noErr) | 935 | if (err == noErr) |
| 928 | err = ATSUSetTransientFontMatching (saved_text_layout, true); | 936 | err = ATSUSetTransientFontMatching (saved_text_layout, true); |
| 929 | } | 937 | } |
| @@ -942,224 +950,224 @@ atsu_get_text_layout_with_text_ptr (text, text_length, style, text_layout) | |||
| 942 | *text_layout = saved_text_layout; | 950 | *text_layout = saved_text_layout; |
| 943 | return err; | 951 | return err; |
| 944 | } | 952 | } |
| 945 | #endif | ||
| 946 | |||
| 947 | |||
| 948 | static void | ||
| 949 | mac_invert_rectangle (f, x, y, width, height) | ||
| 950 | struct frame *f; | ||
| 951 | int x, y; | ||
| 952 | unsigned int width, height; | ||
| 953 | { | ||
| 954 | Rect r; | ||
| 955 | |||
| 956 | #if USE_CG_DRAWING | ||
| 957 | mac_prepare_for_quickdraw (f); | ||
| 958 | #endif | ||
| 959 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | ||
| 960 | |||
| 961 | SetRect (&r, x, y, x + width, y + height); | ||
| 962 | |||
| 963 | InvertRect (&r); | ||
| 964 | } | ||
| 965 | 953 | ||
| 966 | 954 | ||
| 967 | static void | 955 | static void |
| 968 | mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width, | 956 | mac_draw_image_string_atsui (f, gc, x, y, buf, nchars, bg_width, |
| 969 | overstrike_p, bytes_per_char) | 957 | overstrike_p, bytes_per_char) |
| 970 | struct frame *f; | 958 | struct frame *f; |
| 971 | GC gc; | 959 | GC gc; |
| 972 | int x, y; | 960 | int x, y; |
| 973 | char *buf; | 961 | char *buf; |
| 974 | int nchars, bg_width, overstrike_p, bytes_per_char; | 962 | int nchars, bg_width, overstrike_p, bytes_per_char; |
| 975 | { | 963 | { |
| 976 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 964 | OSStatus err; |
| 977 | 965 | ATSUTextLayout text_layout; | |
| 978 | #if USE_ATSUI | ||
| 979 | if (GC_FONT (gc)->mac_style) | ||
| 980 | { | ||
| 981 | OSStatus err; | ||
| 982 | ATSUTextLayout text_layout; | ||
| 983 | 966 | ||
| 984 | xassert (bytes_per_char == 2); | 967 | xassert (bytes_per_char == 2); |
| 985 | 968 | ||
| 986 | #ifndef WORDS_BIG_ENDIAN | 969 | #ifndef WORDS_BIG_ENDIAN |
| 987 | { | 970 | { |
| 988 | int i; | 971 | int i; |
| 989 | UniChar *text = (UniChar *)buf; | 972 | UniChar *text = (UniChar *)buf; |
| 990 | 973 | ||
| 991 | for (i = 0; i < nchars; i++) | 974 | for (i = 0; i < nchars; i++) |
| 992 | text[i] = EndianU16_BtoN (text[i]); | 975 | text[i] = EndianU16_BtoN (text[i]); |
| 993 | } | 976 | } |
| 994 | #endif | 977 | #endif |
| 995 | err = atsu_get_text_layout_with_text_ptr ((ConstUniCharArrayPtr)buf, | 978 | err = atsu_get_text_layout_with_text_ptr ((ConstUniCharArrayPtr)buf, |
| 996 | nchars, | 979 | nchars, |
| 997 | GC_FONT (gc)->mac_style, | 980 | GC_FONT (gc)->mac_style, |
| 998 | &text_layout); | 981 | &text_layout); |
| 999 | if (err != noErr) | 982 | if (err != noErr) |
| 1000 | return; | 983 | return; |
| 1001 | #ifdef MAC_OSX | 984 | #ifdef MAC_OSX |
| 1002 | if (!mac_use_core_graphics) | 985 | if (!mac_use_core_graphics) |
| 1003 | { | 986 | { |
| 1004 | #endif | ||
| 1005 | #if USE_CG_DRAWING | ||
| 1006 | mac_prepare_for_quickdraw (f); | ||
| 1007 | #endif | 987 | #endif |
| 1008 | mac_begin_clip (gc); | 988 | mac_begin_clip (f, gc); |
| 1009 | RGBForeColor (GC_FORE_COLOR (gc)); | 989 | RGBForeColor (GC_FORE_COLOR (gc)); |
| 1010 | if (bg_width) | 990 | if (bg_width) |
| 1011 | { | 991 | { |
| 1012 | Rect r; | 992 | Rect r; |
| 1013 | 993 | ||
| 1014 | SetRect (&r, x, y - FONT_BASE (GC_FONT (gc)), | 994 | SetRect (&r, x, y - FONT_BASE (GC_FONT (gc)), |
| 1015 | x + bg_width, y + FONT_DESCENT (GC_FONT (gc))); | 995 | x + bg_width, y + FONT_DESCENT (GC_FONT (gc))); |
| 1016 | RGBBackColor (GC_BACK_COLOR (gc)); | 996 | RGBBackColor (GC_BACK_COLOR (gc)); |
| 1017 | EraseRect (&r); | 997 | EraseRect (&r); |
| 1018 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 998 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 1019 | } | 999 | } |
| 1020 | MoveTo (x, y); | 1000 | MoveTo (x, y); |
| 1001 | ATSUDrawText (text_layout, | ||
| 1002 | kATSUFromTextBeginning, kATSUToTextEnd, | ||
| 1003 | kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); | ||
| 1004 | if (overstrike_p) | ||
| 1005 | { | ||
| 1006 | MoveTo (x + 1, y); | ||
| 1021 | ATSUDrawText (text_layout, | 1007 | ATSUDrawText (text_layout, |
| 1022 | kATSUFromTextBeginning, kATSUToTextEnd, | 1008 | kATSUFromTextBeginning, kATSUToTextEnd, |
| 1023 | kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); | 1009 | kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); |
| 1024 | if (overstrike_p) | ||
| 1025 | { | ||
| 1026 | MoveTo (x + 1, y); | ||
| 1027 | ATSUDrawText (text_layout, | ||
| 1028 | kATSUFromTextBeginning, kATSUToTextEnd, | ||
| 1029 | kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); | ||
| 1030 | } | ||
| 1031 | mac_end_clip (gc); | ||
| 1032 | #ifdef MAC_OSX | ||
| 1033 | } | 1010 | } |
| 1034 | else | 1011 | mac_end_clip (gc); |
| 1035 | { | 1012 | #ifdef MAC_OSX |
| 1036 | CGrafPtr port; | 1013 | } |
| 1037 | static CGContextRef context; | 1014 | else |
| 1038 | float port_height = FRAME_PIXEL_HEIGHT (f); | 1015 | { |
| 1039 | static const ATSUAttributeTag tags[] = {kATSUCGContextTag}; | 1016 | static CGContextRef context; |
| 1040 | static const ByteCount sizes[] = {sizeof (CGContextRef)}; | 1017 | float port_height = FRAME_PIXEL_HEIGHT (f); |
| 1041 | static const ATSUAttributeValuePtr values[] = {&context}; | 1018 | static const ATSUAttributeTag tags[] = {kATSUCGContextTag}; |
| 1019 | static const ByteCount sizes[] = {sizeof (CGContextRef)}; | ||
| 1020 | static const ATSUAttributeValuePtr values[] = {&context}; | ||
| 1042 | 1021 | ||
| 1043 | #if USE_CG_DRAWING | 1022 | #if USE_CG_DRAWING |
| 1044 | context = mac_begin_cg_clip (f, gc); | 1023 | context = mac_begin_cg_clip (f, gc); |
| 1045 | #else | 1024 | #else |
| 1046 | GetPort (&port); | 1025 | CGrafPtr port; |
| 1047 | QDBeginCGContext (port, &context); | 1026 | |
| 1048 | if (gc->n_clip_rects || bg_width) | 1027 | GetPort (&port); |
| 1049 | { | 1028 | QDBeginCGContext (port, &context); |
| 1050 | CGContextTranslateCTM (context, 0, port_height); | 1029 | if (gc->n_clip_rects || bg_width) |
| 1051 | CGContextScaleCTM (context, 1, -1); | 1030 | { |
| 1052 | if (gc->n_clip_rects) | 1031 | CGContextTranslateCTM (context, 0, port_height); |
| 1053 | CGContextClipToRects (context, gc->clip_rects, | 1032 | CGContextScaleCTM (context, 1, -1); |
| 1054 | gc->n_clip_rects); | 1033 | if (gc->n_clip_rects) |
| 1055 | #endif | 1034 | CGContextClipToRects (context, gc->clip_rects, |
| 1056 | if (bg_width) | 1035 | gc->n_clip_rects); |
| 1057 | { | ||
| 1058 | CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc); | ||
| 1059 | CGContextFillRect | ||
| 1060 | (context, | ||
| 1061 | CGRectMake (x, y - FONT_BASE (GC_FONT (gc)), | ||
| 1062 | bg_width, FONT_HEIGHT (GC_FONT (gc)))); | ||
| 1063 | } | ||
| 1064 | CGContextScaleCTM (context, 1, -1); | ||
| 1065 | CGContextTranslateCTM (context, 0, -port_height); | ||
| 1066 | #if !USE_CG_DRAWING | ||
| 1067 | } | ||
| 1068 | #endif | 1036 | #endif |
| 1069 | CG_SET_FILL_COLOR_WITH_GC_FOREGROUND (context, gc); | 1037 | if (bg_width) |
| 1070 | err = ATSUSetLayoutControls (text_layout, | ||
| 1071 | sizeof (tags) / sizeof (tags[0]), | ||
| 1072 | tags, sizes, values); | ||
| 1073 | if (err == noErr) | ||
| 1074 | { | 1038 | { |
| 1075 | ATSUDrawText (text_layout, | 1039 | CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc); |
| 1076 | kATSUFromTextBeginning, kATSUToTextEnd, | 1040 | CGContextFillRect (context, |
| 1077 | Long2Fix (x), Long2Fix (port_height - y)); | 1041 | CGRectMake (x, y - FONT_BASE (GC_FONT (gc)), |
| 1078 | if (overstrike_p) | 1042 | bg_width, |
| 1079 | ATSUDrawText (text_layout, | 1043 | FONT_HEIGHT (GC_FONT (gc)))); |
| 1080 | kATSUFromTextBeginning, kATSUToTextEnd, | ||
| 1081 | Long2Fix (x + 1), Long2Fix (port_height - y)); | ||
| 1082 | } | 1044 | } |
| 1045 | CGContextScaleCTM (context, 1, -1); | ||
| 1046 | CGContextTranslateCTM (context, 0, -port_height); | ||
| 1047 | #if !USE_CG_DRAWING | ||
| 1048 | } | ||
| 1049 | #endif | ||
| 1050 | CG_SET_FILL_COLOR_WITH_GC_FOREGROUND (context, gc); | ||
| 1051 | err = ATSUSetLayoutControls (text_layout, | ||
| 1052 | sizeof (tags) / sizeof (tags[0]), | ||
| 1053 | tags, sizes, values); | ||
| 1054 | if (err == noErr) | ||
| 1055 | { | ||
| 1056 | ATSUDrawText (text_layout, | ||
| 1057 | kATSUFromTextBeginning, kATSUToTextEnd, | ||
| 1058 | Long2Fix (x), Long2Fix (port_height - y)); | ||
| 1059 | if (overstrike_p) | ||
| 1060 | ATSUDrawText (text_layout, | ||
| 1061 | kATSUFromTextBeginning, kATSUToTextEnd, | ||
| 1062 | Long2Fix (x + 1), Long2Fix (port_height - y)); | ||
| 1063 | } | ||
| 1083 | #if USE_CG_DRAWING | 1064 | #if USE_CG_DRAWING |
| 1084 | mac_end_cg_clip (f); | 1065 | mac_end_cg_clip (f); |
| 1085 | context = NULL; | 1066 | context = NULL; |
| 1086 | #else | 1067 | #else |
| 1087 | CGContextSynchronize (context); | 1068 | CGContextSynchronize (context); |
| 1088 | QDEndCGContext (port, &context); | 1069 | QDEndCGContext (port, &context); |
| 1089 | #endif | 1070 | #endif |
| 1090 | #if 0 | 1071 | #if 0 |
| 1091 | /* This doesn't work on Mac OS X 10.1. */ | 1072 | /* This doesn't work on Mac OS X 10.1. */ |
| 1092 | ATSUClearLayoutControls (text_layout, | 1073 | ATSUClearLayoutControls (text_layout, |
| 1093 | sizeof (tags) / sizeof (tags[0]), tags); | 1074 | sizeof (tags) / sizeof (tags[0]), tags); |
| 1094 | #else | 1075 | #else |
| 1095 | ATSUSetLayoutControls (text_layout, | 1076 | ATSUSetLayoutControls (text_layout, |
| 1096 | sizeof (tags) / sizeof (tags[0]), | 1077 | sizeof (tags) / sizeof (tags[0]), |
| 1097 | tags, sizes, values); | 1078 | tags, sizes, values); |
| 1098 | #endif | 1079 | #endif |
| 1099 | } | ||
| 1100 | #endif /* MAC_OSX */ | ||
| 1101 | } | 1080 | } |
| 1102 | else | 1081 | #endif /* MAC_OSX */ |
| 1082 | } | ||
| 1103 | #endif /* USE_ATSUI */ | 1083 | #endif /* USE_ATSUI */ |
| 1104 | { | ||
| 1105 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | ||
| 1106 | UInt32 savedFlags; | ||
| 1107 | 1084 | ||
| 1108 | if (mac_use_core_graphics) | 1085 | |
| 1109 | savedFlags = SwapQDTextFlags (kQDUseCGTextRendering); | 1086 | static void |
| 1087 | mac_draw_image_string_qd (f, gc, x, y, buf, nchars, bg_width, | ||
| 1088 | overstrike_p, bytes_per_char) | ||
| 1089 | struct frame *f; | ||
| 1090 | GC gc; | ||
| 1091 | int x, y; | ||
| 1092 | char *buf; | ||
| 1093 | int nchars, bg_width, overstrike_p, bytes_per_char; | ||
| 1094 | { | ||
| 1095 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | ||
| 1096 | UInt32 savedFlags; | ||
| 1110 | #endif | 1097 | #endif |
| 1111 | #if USE_CG_DRAWING | 1098 | |
| 1112 | mac_prepare_for_quickdraw (f); | 1099 | mac_begin_clip (f, gc); |
| 1100 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | ||
| 1101 | if (mac_use_core_graphics) | ||
| 1102 | savedFlags = SwapQDTextFlags (kQDUseCGTextRendering); | ||
| 1113 | #endif | 1103 | #endif |
| 1114 | mac_begin_clip (gc); | 1104 | RGBForeColor (GC_FORE_COLOR (gc)); |
| 1115 | RGBForeColor (GC_FORE_COLOR (gc)); | ||
| 1116 | #ifdef MAC_OS8 | 1105 | #ifdef MAC_OS8 |
| 1117 | if (bg_width) | 1106 | if (bg_width) |
| 1118 | { | 1107 | { |
| 1119 | RGBBackColor (GC_BACK_COLOR (gc)); | 1108 | RGBBackColor (GC_BACK_COLOR (gc)); |
| 1120 | TextMode (srcCopy); | 1109 | TextMode (srcCopy); |
| 1121 | } | 1110 | } |
| 1122 | else | 1111 | else |
| 1123 | TextMode (srcOr); | 1112 | TextMode (srcOr); |
| 1124 | #else | 1113 | #else |
| 1125 | /* We prefer not to use srcCopy text transfer mode on Mac OS X | 1114 | /* We prefer not to use srcCopy text transfer mode on Mac OS X |
| 1126 | because: | 1115 | because: |
| 1127 | - Screen is double-buffered. (In srcCopy mode, a text is | 1116 | - Screen is double-buffered. (In srcCopy mode, a text is drawn |
| 1128 | drawn into an offscreen graphics world first. So | 1117 | into an offscreen graphics world first. So performance gain |
| 1129 | performance gain cannot be expected.) | 1118 | cannot be expected.) |
| 1130 | - It lowers rendering quality. | 1119 | - It lowers rendering quality. |
| 1131 | - Some fonts leave garbage on cursor movement. */ | 1120 | - Some fonts leave garbage on cursor movement. */ |
| 1132 | if (bg_width) | 1121 | if (bg_width) |
| 1133 | { | 1122 | { |
| 1134 | Rect r; | 1123 | Rect r; |
| 1135 | 1124 | ||
| 1136 | RGBBackColor (GC_BACK_COLOR (gc)); | 1125 | RGBBackColor (GC_BACK_COLOR (gc)); |
| 1137 | SetRect (&r, x, y - FONT_BASE (GC_FONT (gc)), | 1126 | SetRect (&r, x, y - FONT_BASE (GC_FONT (gc)), |
| 1138 | x + bg_width, y + FONT_DESCENT (GC_FONT (gc))); | 1127 | x + bg_width, y + FONT_DESCENT (GC_FONT (gc))); |
| 1139 | EraseRect (&r); | 1128 | EraseRect (&r); |
| 1140 | } | 1129 | } |
| 1141 | TextMode (srcOr); | 1130 | TextMode (srcOr); |
| 1142 | #endif | 1131 | #endif |
| 1143 | TextFont (GC_FONT (gc)->mac_fontnum); | 1132 | TextFont (GC_FONT (gc)->mac_fontnum); |
| 1144 | TextSize (GC_FONT (gc)->mac_fontsize); | 1133 | TextSize (GC_FONT (gc)->mac_fontsize); |
| 1145 | TextFace (GC_FONT (gc)->mac_fontface); | 1134 | TextFace (GC_FONT (gc)->mac_fontface); |
| 1146 | MoveTo (x, y); | 1135 | MoveTo (x, y); |
| 1136 | DrawText (buf, 0, nchars * bytes_per_char); | ||
| 1137 | if (overstrike_p) | ||
| 1138 | { | ||
| 1139 | TextMode (srcOr); | ||
| 1140 | MoveTo (x + 1, y); | ||
| 1147 | DrawText (buf, 0, nchars * bytes_per_char); | 1141 | DrawText (buf, 0, nchars * bytes_per_char); |
| 1148 | if (overstrike_p) | 1142 | } |
| 1149 | { | 1143 | if (bg_width) |
| 1150 | TextMode (srcOr); | 1144 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 1151 | MoveTo (x + 1, y); | 1145 | mac_end_clip (gc); |
| 1152 | DrawText (buf, 0, nchars * bytes_per_char); | ||
| 1153 | } | ||
| 1154 | if (bg_width) | ||
| 1155 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | ||
| 1156 | mac_end_clip (gc); | ||
| 1157 | 1146 | ||
| 1158 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | 1147 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 |
| 1159 | if (mac_use_core_graphics) | 1148 | if (mac_use_core_graphics) |
| 1160 | SwapQDTextFlags(savedFlags); | 1149 | SwapQDTextFlags(savedFlags); |
| 1161 | #endif | 1150 | #endif |
| 1162 | } | 1151 | } |
| 1152 | |||
| 1153 | |||
| 1154 | static INLINE void | ||
| 1155 | mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width, | ||
| 1156 | overstrike_p, bytes_per_char) | ||
| 1157 | struct frame *f; | ||
| 1158 | GC gc; | ||
| 1159 | int x, y; | ||
| 1160 | char *buf; | ||
| 1161 | int nchars, bg_width, overstrike_p, bytes_per_char; | ||
| 1162 | { | ||
| 1163 | #if USE_ATSUI | ||
| 1164 | if (GC_FONT (gc)->mac_style) | ||
| 1165 | mac_draw_image_string_atsui (f, gc, x, y, buf, nchars, bg_width, | ||
| 1166 | overstrike_p, bytes_per_char); | ||
| 1167 | else | ||
| 1168 | #endif /* USE_ATSUI */ | ||
| 1169 | mac_draw_image_string_qd (f, gc, x, y, buf, nchars, bg_width, | ||
| 1170 | overstrike_p, bytes_per_char); | ||
| 1163 | } | 1171 | } |
| 1164 | 1172 | ||
| 1165 | 1173 | ||
| @@ -1376,7 +1384,6 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p) | |||
| 1376 | XChar2b *buf; | 1384 | XChar2b *buf; |
| 1377 | int nchars, bg_width, overstrike_p; | 1385 | int nchars, bg_width, overstrike_p; |
| 1378 | { | 1386 | { |
| 1379 | CGrafPtr port; | ||
| 1380 | float port_height, gx, gy; | 1387 | float port_height, gx, gy; |
| 1381 | int i; | 1388 | int i; |
| 1382 | CGContextRef context; | 1389 | CGContextRef context; |
| @@ -1386,7 +1393,6 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p) | |||
| 1386 | if (!mac_use_core_graphics || GC_FONT (gc)->cg_font == NULL) | 1393 | if (!mac_use_core_graphics || GC_FONT (gc)->cg_font == NULL) |
| 1387 | return 0; | 1394 | return 0; |
| 1388 | 1395 | ||
| 1389 | port = GetWindowPort (FRAME_MAC_WINDOW (f)); | ||
| 1390 | port_height = FRAME_PIXEL_HEIGHT (f); | 1396 | port_height = FRAME_PIXEL_HEIGHT (f); |
| 1391 | gx = x; | 1397 | gx = x; |
| 1392 | gy = port_height - y; | 1398 | gy = port_height - y; |
| @@ -1407,7 +1413,7 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p) | |||
| 1407 | #if USE_CG_DRAWING | 1413 | #if USE_CG_DRAWING |
| 1408 | context = mac_begin_cg_clip (f, gc); | 1414 | context = mac_begin_cg_clip (f, gc); |
| 1409 | #else | 1415 | #else |
| 1410 | QDBeginCGContext (port, &context); | 1416 | QDBeginCGContext (GetWindowPort (FRAME_MAC_WINDOW (f)), &context); |
| 1411 | if (gc->n_clip_rects || bg_width) | 1417 | if (gc->n_clip_rects || bg_width) |
| 1412 | { | 1418 | { |
| 1413 | CGContextTranslateCTM (context, 0, port_height); | 1419 | CGContextTranslateCTM (context, 0, port_height); |
| @@ -1447,7 +1453,7 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p) | |||
| 1447 | } | 1453 | } |
| 1448 | } | 1454 | } |
| 1449 | #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020 | 1455 | #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020 |
| 1450 | else | 1456 | else /* CGContextShowGlyphsWithAdvances == NULL */ |
| 1451 | #endif | 1457 | #endif |
| 1452 | #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */ | 1458 | #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */ |
| 1453 | #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020 | 1459 | #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020 |
| @@ -1465,7 +1471,7 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p) | |||
| 1465 | mac_end_cg_clip (f); | 1471 | mac_end_cg_clip (f); |
| 1466 | #else | 1472 | #else |
| 1467 | CGContextSynchronize (context); | 1473 | CGContextSynchronize (context); |
| 1468 | QDEndCGContext (port, &context); | 1474 | QDEndCGContext (GetWindowPort (FRAME_MAC_WINDOW (f)), &context); |
| 1469 | #endif | 1475 | #endif |
| 1470 | 1476 | ||
| 1471 | return 1; | 1477 | return 1; |
| @@ -1487,7 +1493,7 @@ mac_copy_area (src, f, gc, src_x, src_y, width, height, dest_x, dest_y) | |||
| 1487 | { | 1493 | { |
| 1488 | Rect src_r, dest_r; | 1494 | Rect src_r, dest_r; |
| 1489 | 1495 | ||
| 1490 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 1496 | mac_begin_clip (f, gc); |
| 1491 | 1497 | ||
| 1492 | SetRect (&src_r, src_x, src_y, src_x + width, src_y + height); | 1498 | SetRect (&src_r, src_x, src_y, src_x + width, src_y + height); |
| 1493 | SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height); | 1499 | SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height); |
| @@ -1495,7 +1501,6 @@ mac_copy_area (src, f, gc, src_x, src_y, width, height, dest_x, dest_y) | |||
| 1495 | ForeColor (blackColor); | 1501 | ForeColor (blackColor); |
| 1496 | BackColor (whiteColor); | 1502 | BackColor (whiteColor); |
| 1497 | 1503 | ||
| 1498 | mac_begin_clip (gc); | ||
| 1499 | LockPixels (GetGWorldPixMap (src)); | 1504 | LockPixels (GetGWorldPixMap (src)); |
| 1500 | #if TARGET_API_MAC_CARBON | 1505 | #if TARGET_API_MAC_CARBON |
| 1501 | { | 1506 | { |
| @@ -1513,9 +1518,10 @@ mac_copy_area (src, f, gc, src_x, src_y, width, height, dest_x, dest_y) | |||
| 1513 | &src_r, &dest_r, srcCopy, 0); | 1518 | &src_r, &dest_r, srcCopy, 0); |
| 1514 | #endif /* not TARGET_API_MAC_CARBON */ | 1519 | #endif /* not TARGET_API_MAC_CARBON */ |
| 1515 | UnlockPixels (GetGWorldPixMap (src)); | 1520 | UnlockPixels (GetGWorldPixMap (src)); |
| 1516 | mac_end_clip (gc); | ||
| 1517 | 1521 | ||
| 1518 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 1522 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 1523 | |||
| 1524 | mac_end_clip (gc); | ||
| 1519 | } | 1525 | } |
| 1520 | 1526 | ||
| 1521 | 1527 | ||
| @@ -1531,7 +1537,7 @@ mac_copy_area_with_mask (src, mask, f, gc, src_x, src_y, | |||
| 1531 | { | 1537 | { |
| 1532 | Rect src_r, dest_r; | 1538 | Rect src_r, dest_r; |
| 1533 | 1539 | ||
| 1534 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 1540 | mac_begin_clip (f, gc); |
| 1535 | 1541 | ||
| 1536 | SetRect (&src_r, src_x, src_y, src_x + width, src_y + height); | 1542 | SetRect (&src_r, src_x, src_y, src_x + width, src_y + height); |
| 1537 | SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height); | 1543 | SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height); |
| @@ -1539,7 +1545,6 @@ mac_copy_area_with_mask (src, mask, f, gc, src_x, src_y, | |||
| 1539 | ForeColor (blackColor); | 1545 | ForeColor (blackColor); |
| 1540 | BackColor (whiteColor); | 1546 | BackColor (whiteColor); |
| 1541 | 1547 | ||
| 1542 | mac_begin_clip (gc); | ||
| 1543 | LockPixels (GetGWorldPixMap (src)); | 1548 | LockPixels (GetGWorldPixMap (src)); |
| 1544 | LockPixels (GetGWorldPixMap (mask)); | 1549 | LockPixels (GetGWorldPixMap (mask)); |
| 1545 | #if TARGET_API_MAC_CARBON | 1550 | #if TARGET_API_MAC_CARBON |
| @@ -1559,9 +1564,10 @@ mac_copy_area_with_mask (src, mask, f, gc, src_x, src_y, | |||
| 1559 | #endif /* not TARGET_API_MAC_CARBON */ | 1564 | #endif /* not TARGET_API_MAC_CARBON */ |
| 1560 | UnlockPixels (GetGWorldPixMap (mask)); | 1565 | UnlockPixels (GetGWorldPixMap (mask)); |
| 1561 | UnlockPixels (GetGWorldPixMap (src)); | 1566 | UnlockPixels (GetGWorldPixMap (src)); |
| 1562 | mac_end_clip (gc); | ||
| 1563 | 1567 | ||
| 1564 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 1568 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 1569 | |||
| 1570 | mac_end_clip (gc); | ||
| 1565 | } | 1571 | } |
| 1566 | #endif /* !USE_CG_DRAWING */ | 1572 | #endif /* !USE_CG_DRAWING */ |
| 1567 | 1573 | ||
| @@ -1590,9 +1596,9 @@ mac_scroll_area (f, gc, src_x, src_y, width, height, dest_x, dest_y) | |||
| 1590 | DisposeRgn (dummy); | 1596 | DisposeRgn (dummy); |
| 1591 | #else /* not TARGET_API_MAC_CARBON */ | 1597 | #else /* not TARGET_API_MAC_CARBON */ |
| 1592 | Rect src_r, dest_r; | 1598 | Rect src_r, dest_r; |
| 1593 | WindowPtr w = FRAME_MAC_WINDOW (f); | 1599 | WindowRef w = FRAME_MAC_WINDOW (f); |
| 1594 | 1600 | ||
| 1595 | SetPort (w); | 1601 | mac_begin_clip (f, gc); |
| 1596 | 1602 | ||
| 1597 | SetRect (&src_r, src_x, src_y, src_x + width, src_y + height); | 1603 | SetRect (&src_r, src_x, src_y, src_x + width, src_y + height); |
| 1598 | SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height); | 1604 | SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height); |
| @@ -1601,11 +1607,11 @@ mac_scroll_area (f, gc, src_x, src_y, width, height, dest_x, dest_y) | |||
| 1601 | color mapping in CopyBits. Otherwise, it will be slow. */ | 1607 | color mapping in CopyBits. Otherwise, it will be slow. */ |
| 1602 | ForeColor (blackColor); | 1608 | ForeColor (blackColor); |
| 1603 | BackColor (whiteColor); | 1609 | BackColor (whiteColor); |
| 1604 | mac_begin_clip (gc); | ||
| 1605 | CopyBits (&(w->portBits), &(w->portBits), &src_r, &dest_r, srcCopy, 0); | 1610 | CopyBits (&(w->portBits), &(w->portBits), &src_r, &dest_r, srcCopy, 0); |
| 1606 | mac_end_clip (gc); | ||
| 1607 | 1611 | ||
| 1608 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 1612 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 1613 | |||
| 1614 | mac_end_clip (gc); | ||
| 1609 | #endif /* not TARGET_API_MAC_CARBON */ | 1615 | #endif /* not TARGET_API_MAC_CARBON */ |
| 1610 | } | 1616 | } |
| 1611 | 1617 | ||
| @@ -1850,7 +1856,7 @@ mac_reset_clip_rectangles (display, gc) | |||
| 1850 | void | 1856 | void |
| 1851 | XSetWindowBackground (display, w, color) | 1857 | XSetWindowBackground (display, w, color) |
| 1852 | Display *display; | 1858 | Display *display; |
| 1853 | WindowPtr w; | 1859 | WindowRef w; |
| 1854 | unsigned long color; | 1860 | unsigned long color; |
| 1855 | { | 1861 | { |
| 1856 | #if !TARGET_API_MAC_CARBON | 1862 | #if !TARGET_API_MAC_CARBON |
| @@ -2188,6 +2194,81 @@ x_draw_fringe_bitmap (w, row, p) | |||
| 2188 | Display *display = FRAME_MAC_DISPLAY (f); | 2194 | Display *display = FRAME_MAC_DISPLAY (f); |
| 2189 | struct face *face = p->face; | 2195 | struct face *face = p->face; |
| 2190 | int rowY; | 2196 | int rowY; |
| 2197 | int overlay_p = p->overlay_p; | ||
| 2198 | |||
| 2199 | #ifdef MAC_OSX | ||
| 2200 | if (!overlay_p) | ||
| 2201 | { | ||
| 2202 | int bx = p->bx, by = p->by, nx = p->nx, ny = p->ny; | ||
| 2203 | |||
| 2204 | #if 0 /* MAC_TODO: stipple */ | ||
| 2205 | /* In case the same realized face is used for fringes and | ||
| 2206 | for something displayed in the text (e.g. face `region' on | ||
| 2207 | mono-displays, the fill style may have been changed to | ||
| 2208 | FillSolid in x_draw_glyph_string_background. */ | ||
| 2209 | if (face->stipple) | ||
| 2210 | XSetFillStyle (FRAME_X_DISPLAY (f), face->gc, FillOpaqueStippled); | ||
| 2211 | else | ||
| 2212 | XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->background); | ||
| 2213 | #endif | ||
| 2214 | |||
| 2215 | /* If the fringe is adjacent to the left (right) scroll bar of a | ||
| 2216 | leftmost (rightmost, respectively) window, then extend its | ||
| 2217 | background to the gap between the fringe and the bar. */ | ||
| 2218 | if ((WINDOW_LEFTMOST_P (w) | ||
| 2219 | && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)) | ||
| 2220 | || (WINDOW_RIGHTMOST_P (w) | ||
| 2221 | && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w))) | ||
| 2222 | { | ||
| 2223 | int sb_width = WINDOW_CONFIG_SCROLL_BAR_WIDTH (w); | ||
| 2224 | |||
| 2225 | if (sb_width > 0) | ||
| 2226 | { | ||
| 2227 | int left = WINDOW_SCROLL_BAR_AREA_X (w); | ||
| 2228 | int width = (WINDOW_CONFIG_SCROLL_BAR_COLS (w) | ||
| 2229 | * FRAME_COLUMN_WIDTH (f)); | ||
| 2230 | |||
| 2231 | if (bx < 0 | ||
| 2232 | && (left + width == p->x | ||
| 2233 | || p->x + p->wd == left)) | ||
| 2234 | { | ||
| 2235 | /* Bitmap fills the fringe and we need background | ||
| 2236 | extension. */ | ||
| 2237 | int header_line_height = WINDOW_HEADER_LINE_HEIGHT (w); | ||
| 2238 | |||
| 2239 | bx = p->x; | ||
| 2240 | nx = p->wd; | ||
| 2241 | by = WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, | ||
| 2242 | row->y)); | ||
| 2243 | ny = row->visible_height; | ||
| 2244 | } | ||
| 2245 | |||
| 2246 | if (bx >= 0) | ||
| 2247 | { | ||
| 2248 | if (left + width == bx) | ||
| 2249 | { | ||
| 2250 | bx = left + sb_width; | ||
| 2251 | nx += width - sb_width; | ||
| 2252 | } | ||
| 2253 | else if (bx + nx == left) | ||
| 2254 | nx += width - sb_width; | ||
| 2255 | } | ||
| 2256 | } | ||
| 2257 | } | ||
| 2258 | |||
| 2259 | if (bx >= 0) | ||
| 2260 | { | ||
| 2261 | mac_erase_rectangle (f, face->gc, bx, by, nx, ny); | ||
| 2262 | /* The fringe background has already been filled. */ | ||
| 2263 | overlay_p = 1; | ||
| 2264 | } | ||
| 2265 | |||
| 2266 | #if 0 /* MAC_TODO: stipple */ | ||
| 2267 | if (!face->stipple) | ||
| 2268 | XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->foreground); | ||
| 2269 | #endif | ||
| 2270 | } | ||
| 2271 | #endif /* MAC_OSX */ | ||
| 2191 | 2272 | ||
| 2192 | /* Must clip because of partially visible lines. */ | 2273 | /* Must clip because of partially visible lines. */ |
| 2193 | rowY = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | 2274 | rowY = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); |
| @@ -2206,6 +2287,7 @@ x_draw_fringe_bitmap (w, row, p) | |||
| 2206 | else | 2287 | else |
| 2207 | x_clip_to_row (w, row, -1, face->gc); | 2288 | x_clip_to_row (w, row, -1, face->gc); |
| 2208 | 2289 | ||
| 2290 | #ifndef MAC_OSX | ||
| 2209 | if (p->bx >= 0 && !p->overlay_p) | 2291 | if (p->bx >= 0 && !p->overlay_p) |
| 2210 | { | 2292 | { |
| 2211 | #if 0 /* MAC_TODO: stipple */ | 2293 | #if 0 /* MAC_TODO: stipple */ |
| @@ -2226,6 +2308,7 @@ x_draw_fringe_bitmap (w, row, p) | |||
| 2226 | XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->foreground); | 2308 | XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->foreground); |
| 2227 | #endif | 2309 | #endif |
| 2228 | } | 2310 | } |
| 2311 | #endif /* !MAC_OSX */ | ||
| 2229 | 2312 | ||
| 2230 | if (p->which | 2313 | if (p->which |
| 2231 | #if USE_CG_DRAWING | 2314 | #if USE_CG_DRAWING |
| @@ -2243,10 +2326,10 @@ x_draw_fringe_bitmap (w, row, p) | |||
| 2243 | : face->foreground)); | 2326 | : face->foreground)); |
| 2244 | #if USE_CG_DRAWING | 2327 | #if USE_CG_DRAWING |
| 2245 | mac_draw_cg_image (fringe_bmp[p->which], f, face->gc, 0, p->dh, | 2328 | mac_draw_cg_image (fringe_bmp[p->which], f, face->gc, 0, p->dh, |
| 2246 | p->wd, p->h, p->x, p->y, p->overlay_p); | 2329 | p->wd, p->h, p->x, p->y, overlay_p); |
| 2247 | #else | 2330 | #else |
| 2248 | mac_draw_bitmap (f, face->gc, p->x, p->y, | 2331 | mac_draw_bitmap (f, face->gc, p->x, p->y, |
| 2249 | p->wd, p->h, p->bits + p->dh, p->overlay_p); | 2332 | p->wd, p->h, p->bits + p->dh, overlay_p); |
| 2250 | #endif | 2333 | #endif |
| 2251 | XSetForeground (display, face->gc, gcv.foreground); | 2334 | XSetForeground (display, face->gc, gcv.foreground); |
| 2252 | } | 2335 | } |
| @@ -4266,14 +4349,6 @@ static void | |||
| 4266 | frame_highlight (f) | 4349 | frame_highlight (f) |
| 4267 | struct frame *f; | 4350 | struct frame *f; |
| 4268 | { | 4351 | { |
| 4269 | OSErr err; | ||
| 4270 | ControlRef root_control; | ||
| 4271 | |||
| 4272 | BLOCK_INPUT; | ||
| 4273 | err = GetRootControl (FRAME_MAC_WINDOW (f), &root_control); | ||
| 4274 | if (err == noErr) | ||
| 4275 | ActivateControl (root_control); | ||
| 4276 | UNBLOCK_INPUT; | ||
| 4277 | x_update_cursor (f, 1); | 4352 | x_update_cursor (f, 1); |
| 4278 | } | 4353 | } |
| 4279 | 4354 | ||
| @@ -4281,14 +4356,6 @@ static void | |||
| 4281 | frame_unhighlight (f) | 4356 | frame_unhighlight (f) |
| 4282 | struct frame *f; | 4357 | struct frame *f; |
| 4283 | { | 4358 | { |
| 4284 | OSErr err; | ||
| 4285 | ControlRef root_control; | ||
| 4286 | |||
| 4287 | BLOCK_INPUT; | ||
| 4288 | err = GetRootControl (FRAME_MAC_WINDOW (f), &root_control); | ||
| 4289 | if (err == noErr) | ||
| 4290 | DeactivateControl (root_control); | ||
| 4291 | UNBLOCK_INPUT; | ||
| 4292 | x_update_cursor (f, 1); | 4359 | x_update_cursor (f, 1); |
| 4293 | } | 4360 | } |
| 4294 | 4361 | ||
| @@ -4388,7 +4455,7 @@ x_detect_focus_change (dpyinfo, event, bufp) | |||
| 4388 | { | 4455 | { |
| 4389 | struct frame *frame; | 4456 | struct frame *frame; |
| 4390 | 4457 | ||
| 4391 | frame = mac_window_to_frame ((WindowPtr) event->message); | 4458 | frame = mac_window_to_frame ((WindowRef) event->message); |
| 4392 | if (! frame) | 4459 | if (! frame) |
| 4393 | return; | 4460 | return; |
| 4394 | 4461 | ||
| @@ -4628,8 +4695,14 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time) | |||
| 4628 | the frame are divided into. */ | 4695 | the frame are divided into. */ |
| 4629 | Point mouse_pos; | 4696 | Point mouse_pos; |
| 4630 | 4697 | ||
| 4698 | #if TARGET_API_MAC_CARBON | ||
| 4699 | GetGlobalMouse (&mouse_pos); | ||
| 4700 | mouse_pos.h -= f1->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f1); | ||
| 4701 | mouse_pos.v -= f1->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f1); | ||
| 4702 | #else | ||
| 4631 | SetPortWindowPort (FRAME_MAC_WINDOW (f1)); | 4703 | SetPortWindowPort (FRAME_MAC_WINDOW (f1)); |
| 4632 | GetMouse (&mouse_pos); | 4704 | GetMouse (&mouse_pos); |
| 4705 | #endif | ||
| 4633 | remember_mouse_glyph (f1, mouse_pos.h, mouse_pos.v, | 4706 | remember_mouse_glyph (f1, mouse_pos.h, mouse_pos.v, |
| 4634 | &last_mouse_glyph); | 4707 | &last_mouse_glyph); |
| 4635 | last_mouse_glyph_frame = f1; | 4708 | last_mouse_glyph_frame = f1; |
| @@ -4659,14 +4732,14 @@ static OSStatus set_scroll_bar_timer P_ ((EventTimerInterval)); | |||
| 4659 | static int control_part_code_to_scroll_bar_part P_ ((ControlPartCode)); | 4732 | static int control_part_code_to_scroll_bar_part P_ ((ControlPartCode)); |
| 4660 | static void construct_scroll_bar_click P_ ((struct scroll_bar *, int, | 4733 | static void construct_scroll_bar_click P_ ((struct scroll_bar *, int, |
| 4661 | struct input_event *)); | 4734 | struct input_event *)); |
| 4662 | static OSStatus get_control_part_bounds P_ ((ControlHandle, ControlPartCode, | 4735 | static OSStatus get_control_part_bounds P_ ((ControlRef, ControlPartCode, |
| 4663 | Rect *)); | 4736 | Rect *)); |
| 4664 | static void x_scroll_bar_handle_press P_ ((struct scroll_bar *, | 4737 | static void x_scroll_bar_handle_press P_ ((struct scroll_bar *, |
| 4665 | ControlPartCode, Point, | 4738 | ControlPartCode, Point, |
| 4666 | struct input_event *)); | 4739 | struct input_event *)); |
| 4667 | static void x_scroll_bar_handle_release P_ ((struct scroll_bar *, | 4740 | static void x_scroll_bar_handle_release P_ ((struct scroll_bar *, |
| 4668 | struct input_event *)); | 4741 | struct input_event *)); |
| 4669 | static void x_scroll_bar_handle_drag P_ ((WindowPtr, struct scroll_bar *, | 4742 | static void x_scroll_bar_handle_drag P_ ((WindowRef, struct scroll_bar *, |
| 4670 | Point, struct input_event *)); | 4743 | Point, struct input_event *)); |
| 4671 | static void x_set_toolkit_scroll_bar_thumb P_ ((struct scroll_bar *, | 4744 | static void x_set_toolkit_scroll_bar_thumb P_ ((struct scroll_bar *, |
| 4672 | int, int, int)); | 4745 | int, int, int)); |
| @@ -4759,7 +4832,7 @@ construct_scroll_bar_click (bar, part, bufp) | |||
| 4759 | 4832 | ||
| 4760 | static OSStatus | 4833 | static OSStatus |
| 4761 | get_control_part_bounds (ch, part_code, rect) | 4834 | get_control_part_bounds (ch, part_code, rect) |
| 4762 | ControlHandle ch; | 4835 | ControlRef ch; |
| 4763 | ControlPartCode part_code; | 4836 | ControlPartCode part_code; |
| 4764 | Rect *rect; | 4837 | Rect *rect; |
| 4765 | { | 4838 | { |
| @@ -4789,7 +4862,7 @@ x_scroll_bar_handle_press (bar, part_code, mouse_pos, bufp) | |||
| 4789 | if (part != scroll_bar_handle) | 4862 | if (part != scroll_bar_handle) |
| 4790 | { | 4863 | { |
| 4791 | construct_scroll_bar_click (bar, part, bufp); | 4864 | construct_scroll_bar_click (bar, part, bufp); |
| 4792 | HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar), part_code); | 4865 | HiliteControl (SCROLL_BAR_CONTROL_REF (bar), part_code); |
| 4793 | set_scroll_bar_timer (SCROLL_BAR_FIRST_DELAY); | 4866 | set_scroll_bar_timer (SCROLL_BAR_FIRST_DELAY); |
| 4794 | bar->dragging = Qnil; | 4867 | bar->dragging = Qnil; |
| 4795 | } | 4868 | } |
| @@ -4797,7 +4870,7 @@ x_scroll_bar_handle_press (bar, part_code, mouse_pos, bufp) | |||
| 4797 | { | 4870 | { |
| 4798 | Rect r; | 4871 | Rect r; |
| 4799 | 4872 | ||
| 4800 | get_control_part_bounds (SCROLL_BAR_CONTROL_HANDLE (bar), | 4873 | get_control_part_bounds (SCROLL_BAR_CONTROL_REF (bar), |
| 4801 | kControlIndicatorPart, &r); | 4874 | kControlIndicatorPart, &r); |
| 4802 | XSETINT (bar->dragging, - (mouse_pos.v - r.top) - 1); | 4875 | XSETINT (bar->dragging, - (mouse_pos.v - r.top) - 1); |
| 4803 | } | 4876 | } |
| @@ -4815,7 +4888,7 @@ x_scroll_bar_handle_release (bar, bufp) | |||
| 4815 | || (INTEGERP (bar->dragging) && XINT (bar->dragging) >= 0)) | 4888 | || (INTEGERP (bar->dragging) && XINT (bar->dragging) >= 0)) |
| 4816 | construct_scroll_bar_click (bar, scroll_bar_end_scroll, bufp); | 4889 | construct_scroll_bar_click (bar, scroll_bar_end_scroll, bufp); |
| 4817 | 4890 | ||
| 4818 | HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar), 0); | 4891 | HiliteControl (SCROLL_BAR_CONTROL_REF (bar), 0); |
| 4819 | set_scroll_bar_timer (kEventDurationForever); | 4892 | set_scroll_bar_timer (kEventDurationForever); |
| 4820 | 4893 | ||
| 4821 | last_scroll_bar_part = -1; | 4894 | last_scroll_bar_part = -1; |
| @@ -4825,19 +4898,19 @@ x_scroll_bar_handle_release (bar, bufp) | |||
| 4825 | 4898 | ||
| 4826 | static void | 4899 | static void |
| 4827 | x_scroll_bar_handle_drag (win, bar, mouse_pos, bufp) | 4900 | x_scroll_bar_handle_drag (win, bar, mouse_pos, bufp) |
| 4828 | WindowPtr win; | 4901 | WindowRef win; |
| 4829 | struct scroll_bar *bar; | 4902 | struct scroll_bar *bar; |
| 4830 | Point mouse_pos; | 4903 | Point mouse_pos; |
| 4831 | struct input_event *bufp; | 4904 | struct input_event *bufp; |
| 4832 | { | 4905 | { |
| 4833 | ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar); | 4906 | ControlRef ch = SCROLL_BAR_CONTROL_REF (bar); |
| 4834 | 4907 | ||
| 4835 | if (last_scroll_bar_part == scroll_bar_handle) | 4908 | if (last_scroll_bar_part == scroll_bar_handle) |
| 4836 | { | 4909 | { |
| 4837 | int top, top_range; | 4910 | int top, top_range; |
| 4838 | Rect r; | 4911 | Rect r; |
| 4839 | 4912 | ||
| 4840 | get_control_part_bounds (SCROLL_BAR_CONTROL_HANDLE (bar), | 4913 | get_control_part_bounds (SCROLL_BAR_CONTROL_REF (bar), |
| 4841 | kControlIndicatorPart, &r); | 4914 | kControlIndicatorPart, &r); |
| 4842 | 4915 | ||
| 4843 | if (INTEGERP (bar->dragging) && XINT (bar->dragging) < 0) | 4916 | if (INTEGERP (bar->dragging) && XINT (bar->dragging) < 0) |
| @@ -4885,13 +4958,13 @@ x_scroll_bar_handle_drag (win, bar, mouse_pos, bufp) | |||
| 4885 | } | 4958 | } |
| 4886 | 4959 | ||
| 4887 | if (unhilite_p) | 4960 | if (unhilite_p) |
| 4888 | HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar), 0); | 4961 | HiliteControl (SCROLL_BAR_CONTROL_REF (bar), 0); |
| 4889 | else if (part != last_scroll_bar_part | 4962 | else if (part != last_scroll_bar_part |
| 4890 | || scroll_bar_timer_event_posted_p) | 4963 | || scroll_bar_timer_event_posted_p) |
| 4891 | { | 4964 | { |
| 4892 | construct_scroll_bar_click (bar, part, bufp); | 4965 | construct_scroll_bar_click (bar, part, bufp); |
| 4893 | last_scroll_bar_part = part; | 4966 | last_scroll_bar_part = part; |
| 4894 | HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar), part_code); | 4967 | HiliteControl (SCROLL_BAR_CONTROL_REF (bar), part_code); |
| 4895 | set_scroll_bar_timer (SCROLL_BAR_CONTINUOUS_DELAY); | 4968 | set_scroll_bar_timer (SCROLL_BAR_CONTINUOUS_DELAY); |
| 4896 | } | 4969 | } |
| 4897 | } | 4970 | } |
| @@ -4905,7 +4978,7 @@ x_set_toolkit_scroll_bar_thumb (bar, portion, position, whole) | |||
| 4905 | struct scroll_bar *bar; | 4978 | struct scroll_bar *bar; |
| 4906 | int portion, position, whole; | 4979 | int portion, position, whole; |
| 4907 | { | 4980 | { |
| 4908 | ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar); | 4981 | ControlRef ch = SCROLL_BAR_CONTROL_REF (bar); |
| 4909 | int value, viewsize, maximum; | 4982 | int value, viewsize, maximum; |
| 4910 | 4983 | ||
| 4911 | if (XINT (bar->track_height) == 0) | 4984 | if (XINT (bar->track_height) == 0) |
| @@ -4964,7 +5037,7 @@ x_scroll_bar_create (w, top, left, width, height, disp_top, disp_height) | |||
| 4964 | struct scroll_bar *bar | 5037 | struct scroll_bar *bar |
| 4965 | = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil)); | 5038 | = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil)); |
| 4966 | Rect r; | 5039 | Rect r; |
| 4967 | ControlHandle ch; | 5040 | ControlRef ch; |
| 4968 | 5041 | ||
| 4969 | BLOCK_INPUT; | 5042 | BLOCK_INPUT; |
| 4970 | 5043 | ||
| @@ -4988,7 +5061,7 @@ x_scroll_bar_create (w, top, left, width, height, disp_top, disp_height) | |||
| 4988 | ch = NewControl (FRAME_MAC_WINDOW (f), &r, "\p", width < disp_height, | 5061 | ch = NewControl (FRAME_MAC_WINDOW (f), &r, "\p", width < disp_height, |
| 4989 | 0, 0, 0, scrollBarProc, (long) bar); | 5062 | 0, 0, 0, scrollBarProc, (long) bar); |
| 4990 | #endif | 5063 | #endif |
| 4991 | SET_SCROLL_BAR_CONTROL_HANDLE (bar, ch); | 5064 | SET_SCROLL_BAR_CONTROL_REF (bar, ch); |
| 4992 | 5065 | ||
| 4993 | XSETWINDOW (bar->window, w); | 5066 | XSETWINDOW (bar->window, w); |
| 4994 | XSETINT (bar->top, top); | 5067 | XSETINT (bar->top, top); |
| @@ -4998,6 +5071,9 @@ x_scroll_bar_create (w, top, left, width, height, disp_top, disp_height) | |||
| 4998 | XSETINT (bar->start, 0); | 5071 | XSETINT (bar->start, 0); |
| 4999 | XSETINT (bar->end, 0); | 5072 | XSETINT (bar->end, 0); |
| 5000 | bar->dragging = Qnil; | 5073 | bar->dragging = Qnil; |
| 5074 | #ifdef MAC_OSX | ||
| 5075 | bar->fringe_extended_p = Qnil; | ||
| 5076 | #endif | ||
| 5001 | bar->redraw_needed_p = Qnil; | 5077 | bar->redraw_needed_p = Qnil; |
| 5002 | #ifdef USE_TOOLKIT_SCROLL_BARS | 5078 | #ifdef USE_TOOLKIT_SCROLL_BARS |
| 5003 | bar->track_top = Qnil; | 5079 | bar->track_top = Qnil; |
| @@ -5039,7 +5115,7 @@ x_scroll_bar_set_handle (bar, start, end, rebuild) | |||
| 5039 | int rebuild; | 5115 | int rebuild; |
| 5040 | { | 5116 | { |
| 5041 | int dragging = ! NILP (bar->dragging); | 5117 | int dragging = ! NILP (bar->dragging); |
| 5042 | ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar); | 5118 | ControlRef ch = SCROLL_BAR_CONTROL_REF (bar); |
| 5043 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | 5119 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); |
| 5044 | int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); | 5120 | int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); |
| 5045 | int length = end - start; | 5121 | int length = end - start; |
| @@ -5108,7 +5184,7 @@ x_scroll_bar_remove (bar) | |||
| 5108 | mac_prepare_for_quickdraw (f); | 5184 | mac_prepare_for_quickdraw (f); |
| 5109 | #endif | 5185 | #endif |
| 5110 | /* Destroy the Mac scroll bar control */ | 5186 | /* Destroy the Mac scroll bar control */ |
| 5111 | DisposeControl (SCROLL_BAR_CONTROL_HANDLE (bar)); | 5187 | DisposeControl (SCROLL_BAR_CONTROL_REF (bar)); |
| 5112 | 5188 | ||
| 5113 | /* Disassociate this scroll bar from its window. */ | 5189 | /* Disassociate this scroll bar from its window. */ |
| 5114 | XWINDOW (bar->window)->vertical_scroll_bar = Qnil; | 5190 | XWINDOW (bar->window)->vertical_scroll_bar = Qnil; |
| @@ -5131,6 +5207,9 @@ XTset_vertical_scroll_bar (w, portion, whole, position) | |||
| 5131 | struct scroll_bar *bar; | 5207 | struct scroll_bar *bar; |
| 5132 | int top, height, left, sb_left, width, sb_width, disp_top, disp_height; | 5208 | int top, height, left, sb_left, width, sb_width, disp_top, disp_height; |
| 5133 | int window_y, window_height; | 5209 | int window_y, window_height; |
| 5210 | #ifdef MAC_OSX | ||
| 5211 | int fringe_extended_p; | ||
| 5212 | #endif | ||
| 5134 | 5213 | ||
| 5135 | /* Get window dimensions. */ | 5214 | /* Get window dimensions. */ |
| 5136 | window_box (w, -1, 0, &window_y, 0, &window_height); | 5215 | window_box (w, -1, 0, &window_y, 0, &window_height); |
| @@ -5150,9 +5229,9 @@ XTset_vertical_scroll_bar (w, portion, whole, position) | |||
| 5150 | 5229 | ||
| 5151 | /* Compute the left edge of the scroll bar. */ | 5230 | /* Compute the left edge of the scroll bar. */ |
| 5152 | if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w)) | 5231 | if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w)) |
| 5153 | sb_left = left; | 5232 | sb_left = left + (WINDOW_RIGHTMOST_P (w) ? width - sb_width : 0); |
| 5154 | else | 5233 | else |
| 5155 | sb_left = left + width - sb_width; | 5234 | sb_left = left + (WINDOW_LEFTMOST_P (w) ? 0 : width - sb_width); |
| 5156 | 5235 | ||
| 5157 | /* Adjustments according to Inside Macintosh to make it look nice */ | 5236 | /* Adjustments according to Inside Macintosh to make it look nice */ |
| 5158 | disp_top = top; | 5237 | disp_top = top; |
| @@ -5173,11 +5252,29 @@ XTset_vertical_scroll_bar (w, portion, whole, position) | |||
| 5173 | sb_left++; | 5252 | sb_left++; |
| 5174 | #endif | 5253 | #endif |
| 5175 | 5254 | ||
| 5255 | #ifdef MAC_OSX | ||
| 5256 | if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)) | ||
| 5257 | fringe_extended_p = (WINDOW_LEFTMOST_P (w) | ||
| 5258 | && WINDOW_LEFT_FRINGE_WIDTH (w) | ||
| 5259 | && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) | ||
| 5260 | || WINDOW_LEFT_MARGIN_COLS (w) == 0)); | ||
| 5261 | else | ||
| 5262 | fringe_extended_p = (WINDOW_RIGHTMOST_P (w) | ||
| 5263 | && WINDOW_RIGHT_FRINGE_WIDTH (w) | ||
| 5264 | && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) | ||
| 5265 | || WINDOW_RIGHT_MARGIN_COLS (w) == 0)); | ||
| 5266 | #endif | ||
| 5267 | |||
| 5176 | /* Does the scroll bar exist yet? */ | 5268 | /* Does the scroll bar exist yet? */ |
| 5177 | if (NILP (w->vertical_scroll_bar)) | 5269 | if (NILP (w->vertical_scroll_bar)) |
| 5178 | { | 5270 | { |
| 5179 | BLOCK_INPUT; | 5271 | BLOCK_INPUT; |
| 5180 | mac_clear_area (f, left, top, width, height); | 5272 | #ifdef MAC_OSX |
| 5273 | if (fringe_extended_p) | ||
| 5274 | mac_clear_area (f, sb_left, top, sb_width, height); | ||
| 5275 | else | ||
| 5276 | #endif | ||
| 5277 | mac_clear_area (f, left, top, width, height); | ||
| 5181 | UNBLOCK_INPUT; | 5278 | UNBLOCK_INPUT; |
| 5182 | bar = x_scroll_bar_create (w, top, sb_left, sb_width, height, disp_top, | 5279 | bar = x_scroll_bar_create (w, top, sb_left, sb_width, height, disp_top, |
| 5183 | disp_height); | 5280 | disp_height); |
| @@ -5186,10 +5283,10 @@ XTset_vertical_scroll_bar (w, portion, whole, position) | |||
| 5186 | else | 5283 | else |
| 5187 | { | 5284 | { |
| 5188 | /* It may just need to be moved and resized. */ | 5285 | /* It may just need to be moved and resized. */ |
| 5189 | ControlHandle ch; | 5286 | ControlRef ch; |
| 5190 | 5287 | ||
| 5191 | bar = XSCROLL_BAR (w->vertical_scroll_bar); | 5288 | bar = XSCROLL_BAR (w->vertical_scroll_bar); |
| 5192 | ch = SCROLL_BAR_CONTROL_HANDLE (bar); | 5289 | ch = SCROLL_BAR_CONTROL_REF (bar); |
| 5193 | 5290 | ||
| 5194 | BLOCK_INPUT; | 5291 | BLOCK_INPUT; |
| 5195 | 5292 | ||
| @@ -5197,21 +5294,30 @@ XTset_vertical_scroll_bar (w, portion, whole, position) | |||
| 5197 | if (XINT (bar->left) == sb_left | 5294 | if (XINT (bar->left) == sb_left |
| 5198 | && XINT (bar->top) == top | 5295 | && XINT (bar->top) == top |
| 5199 | && XINT (bar->width) == sb_width | 5296 | && XINT (bar->width) == sb_width |
| 5200 | && XINT (bar->height) == height) | 5297 | && XINT (bar->height) == height |
| 5298 | #ifdef MAC_OSX | ||
| 5299 | && !NILP (bar->fringe_extended_p) == fringe_extended_p | ||
| 5300 | #endif | ||
| 5301 | ) | ||
| 5201 | { | 5302 | { |
| 5202 | if (!NILP (bar->redraw_needed_p)) | 5303 | if (!NILP (bar->redraw_needed_p)) |
| 5203 | { | 5304 | { |
| 5204 | #if USE_CG_DRAWING | 5305 | #if USE_CG_DRAWING |
| 5205 | mac_prepare_for_quickdraw (f); | 5306 | mac_prepare_for_quickdraw (f); |
| 5206 | #endif | 5307 | #endif |
| 5207 | Draw1Control (SCROLL_BAR_CONTROL_HANDLE (bar)); | 5308 | Draw1Control (SCROLL_BAR_CONTROL_REF (bar)); |
| 5208 | } | 5309 | } |
| 5209 | } | 5310 | } |
| 5210 | else | 5311 | else |
| 5211 | { | 5312 | { |
| 5212 | /* Since toolkit scroll bars are smaller than the space reserved | 5313 | /* Since toolkit scroll bars are smaller than the space reserved |
| 5213 | for them on the frame, we have to clear "under" them. */ | 5314 | for them on the frame, we have to clear "under" them. */ |
| 5214 | mac_clear_area (f, left, top, width, height); | 5315 | #ifdef MAC_OSX |
| 5316 | if (fringe_extended_p) | ||
| 5317 | mac_clear_area (f, sb_left, top, sb_width, height); | ||
| 5318 | else | ||
| 5319 | #endif | ||
| 5320 | mac_clear_area (f, left, top, width, height); | ||
| 5215 | 5321 | ||
| 5216 | #if USE_CG_DRAWING | 5322 | #if USE_CG_DRAWING |
| 5217 | mac_prepare_for_quickdraw (f); | 5323 | mac_prepare_for_quickdraw (f); |
| @@ -5240,6 +5346,9 @@ XTset_vertical_scroll_bar (w, portion, whole, position) | |||
| 5240 | UNBLOCK_INPUT; | 5346 | UNBLOCK_INPUT; |
| 5241 | } | 5347 | } |
| 5242 | 5348 | ||
| 5349 | #ifdef MAC_OSX | ||
| 5350 | bar->fringe_extended_p = fringe_extended_p ? Qt : Qnil; | ||
| 5351 | #endif | ||
| 5243 | bar->redraw_needed_p = Qnil; | 5352 | bar->redraw_needed_p = Qnil; |
| 5244 | 5353 | ||
| 5245 | #ifdef USE_TOOLKIT_SCROLL_BARS | 5354 | #ifdef USE_TOOLKIT_SCROLL_BARS |
| @@ -5257,7 +5366,7 @@ XTset_vertical_scroll_bar (w, portion, whole, position) | |||
| 5257 | } | 5366 | } |
| 5258 | else | 5367 | else |
| 5259 | { | 5368 | { |
| 5260 | ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar); | 5369 | ControlRef ch = SCROLL_BAR_CONTROL_REF (bar); |
| 5261 | Rect r0, r1; | 5370 | Rect r0, r1; |
| 5262 | 5371 | ||
| 5263 | BLOCK_INPUT; | 5372 | BLOCK_INPUT; |
| @@ -5534,19 +5643,24 @@ x_scroll_bar_report_motion (fp, bar_window, part, x, y, time) | |||
| 5534 | unsigned long *time; | 5643 | unsigned long *time; |
| 5535 | { | 5644 | { |
| 5536 | struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); | 5645 | struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); |
| 5537 | ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar); | 5646 | ControlRef ch = SCROLL_BAR_CONTROL_REF (bar); |
| 5538 | #if TARGET_API_MAC_CARBON | 5647 | #if TARGET_API_MAC_CARBON |
| 5539 | WindowPtr wp = GetControlOwner (ch); | 5648 | WindowRef wp = GetControlOwner (ch); |
| 5540 | #else | 5649 | #else |
| 5541 | WindowPtr wp = (*ch)->contrlOwner; | 5650 | WindowRef wp = (*ch)->contrlOwner; |
| 5542 | #endif | 5651 | #endif |
| 5543 | Point mouse_pos; | 5652 | Point mouse_pos; |
| 5544 | struct frame *f = mac_window_to_frame (wp); | 5653 | struct frame *f = mac_window_to_frame (wp); |
| 5545 | int win_y, top_range; | 5654 | int win_y, top_range; |
| 5546 | 5655 | ||
| 5656 | #if TARGET_API_MAC_CARBON | ||
| 5657 | GetGlobalMouse (&mouse_pos); | ||
| 5658 | mouse_pos.h -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); | ||
| 5659 | mouse_pos.v -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); | ||
| 5660 | #else | ||
| 5547 | SetPortWindowPort (wp); | 5661 | SetPortWindowPort (wp); |
| 5548 | |||
| 5549 | GetMouse (&mouse_pos); | 5662 | GetMouse (&mouse_pos); |
| 5663 | #endif | ||
| 5550 | 5664 | ||
| 5551 | win_y = mouse_pos.v - XINT (bar->top); | 5665 | win_y = mouse_pos.v - XINT (bar->top); |
| 5552 | top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); | 5666 | top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); |
| @@ -5607,6 +5721,553 @@ x_scroll_bar_clear (f) | |||
| 5607 | 5721 | ||
| 5608 | 5722 | ||
| 5609 | /*********************************************************************** | 5723 | /*********************************************************************** |
| 5724 | Tool-bars | ||
| 5725 | ***********************************************************************/ | ||
| 5726 | #if USE_MAC_TOOLBAR | ||
| 5727 | |||
| 5728 | /* In identifiers such as function/variable names, Emacs tool bar is | ||
| 5729 | referred to as `tool_bar', and Carbon HIToolbar as `toolbar'. */ | ||
| 5730 | |||
| 5731 | #define TOOLBAR_IDENTIFIER (CFSTR ("org.gnu.Emacs.toolbar")) | ||
| 5732 | #define TOOLBAR_ICON_ITEM_IDENTIFIER (CFSTR ("org.gnu.Emacs.toolbar.icon")) | ||
| 5733 | |||
| 5734 | #define TOOLBAR_ITEM_COMMAND_ID_OFFSET 'Tb\0\0' | ||
| 5735 | #define TOOLBAR_ITEM_COMMAND_ID_P(id) \ | ||
| 5736 | (((id) & ~0xffff) == TOOLBAR_ITEM_COMMAND_ID_OFFSET) | ||
| 5737 | #define TOOLBAR_ITEM_COMMAND_ID_VALUE(id) \ | ||
| 5738 | ((id) - TOOLBAR_ITEM_COMMAND_ID_OFFSET) | ||
| 5739 | #define TOOLBAR_ITEM_MAKE_COMMAND_ID(value) \ | ||
| 5740 | ((value) + TOOLBAR_ITEM_COMMAND_ID_OFFSET) | ||
| 5741 | |||
| 5742 | static int mac_event_to_emacs_modifiers P_ ((EventRef)); | ||
| 5743 | static void mac_handle_origin_change P_ ((struct frame *)); | ||
| 5744 | static OSStatus mac_handle_toolbar_command_event P_ ((EventHandlerCallRef, | ||
| 5745 | EventRef, void *)); | ||
| 5746 | |||
| 5747 | static void | ||
| 5748 | mac_move_window_with_gravity (f, win_gravity, left, top) | ||
| 5749 | struct frame *f; | ||
| 5750 | int win_gravity; | ||
| 5751 | short left, top; | ||
| 5752 | { | ||
| 5753 | Rect inner, outer; | ||
| 5754 | |||
| 5755 | mac_get_window_bounds (f, &inner, &outer); | ||
| 5756 | |||
| 5757 | switch (win_gravity) | ||
| 5758 | { | ||
| 5759 | case NorthWestGravity: | ||
| 5760 | case WestGravity: | ||
| 5761 | case SouthWestGravity: | ||
| 5762 | left += inner.left - outer.left; | ||
| 5763 | break; | ||
| 5764 | |||
| 5765 | case NorthGravity: | ||
| 5766 | case CenterGravity: | ||
| 5767 | case SouthGravity: | ||
| 5768 | left += ((inner.left - outer.left) + (inner.right - outer.right)) / 2; | ||
| 5769 | break; | ||
| 5770 | |||
| 5771 | case NorthEastGravity: | ||
| 5772 | case EastGravity: | ||
| 5773 | case SouthEastGravity: | ||
| 5774 | left += inner.right - outer.right; | ||
| 5775 | break; | ||
| 5776 | } | ||
| 5777 | |||
| 5778 | switch (win_gravity) | ||
| 5779 | { | ||
| 5780 | case NorthWestGravity: | ||
| 5781 | case NorthGravity: | ||
| 5782 | case NorthEastGravity: | ||
| 5783 | top += inner.top - outer.top; | ||
| 5784 | break; | ||
| 5785 | |||
| 5786 | case WestGravity: | ||
| 5787 | case CenterGravity: | ||
| 5788 | case EastGravity: | ||
| 5789 | top += ((inner.top - outer.top) + (inner.bottom - outer.bottom)) / 2; | ||
| 5790 | break; | ||
| 5791 | |||
| 5792 | case SouthWestGravity: | ||
| 5793 | case SouthGravity: | ||
| 5794 | case SouthEastGravity: | ||
| 5795 | top += inner.bottom - outer.bottom; | ||
| 5796 | break; | ||
| 5797 | } | ||
| 5798 | |||
| 5799 | MoveWindow (FRAME_MAC_WINDOW (f), left, top, false); | ||
| 5800 | } | ||
| 5801 | |||
| 5802 | static void | ||
| 5803 | mac_get_window_origin_with_gravity (f, win_gravity, left, top) | ||
| 5804 | struct frame *f; | ||
| 5805 | int win_gravity; | ||
| 5806 | short *left, *top; | ||
| 5807 | { | ||
| 5808 | Rect inner, outer; | ||
| 5809 | |||
| 5810 | mac_get_window_bounds (f, &inner, &outer); | ||
| 5811 | |||
| 5812 | switch (win_gravity) | ||
| 5813 | { | ||
| 5814 | case NorthWestGravity: | ||
| 5815 | case WestGravity: | ||
| 5816 | case SouthWestGravity: | ||
| 5817 | *left = outer.left; | ||
| 5818 | break; | ||
| 5819 | |||
| 5820 | case NorthGravity: | ||
| 5821 | case CenterGravity: | ||
| 5822 | case SouthGravity: | ||
| 5823 | *left = outer.left + ((outer.right - outer.left) | ||
| 5824 | - (inner.right - inner.left)) / 2; | ||
| 5825 | break; | ||
| 5826 | |||
| 5827 | case NorthEastGravity: | ||
| 5828 | case EastGravity: | ||
| 5829 | case SouthEastGravity: | ||
| 5830 | *left = outer.right - (inner.right - inner.left); | ||
| 5831 | break; | ||
| 5832 | } | ||
| 5833 | |||
| 5834 | switch (win_gravity) | ||
| 5835 | { | ||
| 5836 | case NorthWestGravity: | ||
| 5837 | case NorthGravity: | ||
| 5838 | case NorthEastGravity: | ||
| 5839 | *top = outer.top; | ||
| 5840 | break; | ||
| 5841 | |||
| 5842 | case WestGravity: | ||
| 5843 | case CenterGravity: | ||
| 5844 | case EastGravity: | ||
| 5845 | *top = outer.top + ((outer.bottom - outer.top) | ||
| 5846 | - (inner.bottom - inner.top)) / 2; | ||
| 5847 | break; | ||
| 5848 | |||
| 5849 | case SouthWestGravity: | ||
| 5850 | case SouthGravity: | ||
| 5851 | case SouthEastGravity: | ||
| 5852 | *top = outer.bottom - (inner.bottom - inner.top); | ||
| 5853 | break; | ||
| 5854 | } | ||
| 5855 | } | ||
| 5856 | |||
| 5857 | static OSStatus | ||
| 5858 | mac_handle_toolbar_event (next_handler, event, data) | ||
| 5859 | EventHandlerCallRef next_handler; | ||
| 5860 | EventRef event; | ||
| 5861 | void *data; | ||
| 5862 | { | ||
| 5863 | OSStatus err, result = eventNotHandledErr; | ||
| 5864 | |||
| 5865 | switch (GetEventKind (event)) | ||
| 5866 | { | ||
| 5867 | case kEventToolbarGetDefaultIdentifiers: | ||
| 5868 | result = noErr; | ||
| 5869 | break; | ||
| 5870 | |||
| 5871 | case kEventToolbarGetAllowedIdentifiers: | ||
| 5872 | { | ||
| 5873 | CFMutableArrayRef array; | ||
| 5874 | |||
| 5875 | GetEventParameter (event, kEventParamMutableArray, | ||
| 5876 | typeCFMutableArrayRef, NULL, | ||
| 5877 | sizeof (CFMutableArrayRef), NULL, &array); | ||
| 5878 | CFArrayAppendValue (array, TOOLBAR_ICON_ITEM_IDENTIFIER); | ||
| 5879 | result = noErr; | ||
| 5880 | } | ||
| 5881 | break; | ||
| 5882 | |||
| 5883 | case kEventToolbarCreateItemWithIdentifier: | ||
| 5884 | { | ||
| 5885 | CFStringRef identifier; | ||
| 5886 | HIToolbarItemRef item = NULL; | ||
| 5887 | |||
| 5888 | GetEventParameter (event, kEventParamToolbarItemIdentifier, | ||
| 5889 | typeCFStringRef, NULL, | ||
| 5890 | sizeof (CFStringRef), NULL, &identifier); | ||
| 5891 | |||
| 5892 | if (CFStringCompare (identifier, TOOLBAR_ICON_ITEM_IDENTIFIER, 0) | ||
| 5893 | == kCFCompareEqualTo) | ||
| 5894 | HIToolbarItemCreate (identifier, | ||
| 5895 | kHIToolbarItemAllowDuplicates | ||
| 5896 | | kHIToolbarItemCantBeRemoved, &item); | ||
| 5897 | |||
| 5898 | if (item) | ||
| 5899 | { | ||
| 5900 | SetEventParameter (event, kEventParamToolbarItem, | ||
| 5901 | typeHIToolbarItemRef, | ||
| 5902 | sizeof (HIToolbarItemRef), &item); | ||
| 5903 | result = noErr; | ||
| 5904 | } | ||
| 5905 | } | ||
| 5906 | break; | ||
| 5907 | |||
| 5908 | default: | ||
| 5909 | abort (); | ||
| 5910 | } | ||
| 5911 | |||
| 5912 | return result; | ||
| 5913 | } | ||
| 5914 | |||
| 5915 | static CGImageRef | ||
| 5916 | mac_image_spec_to_cg_image (f, image) | ||
| 5917 | struct frame *f; | ||
| 5918 | Lisp_Object image; | ||
| 5919 | { | ||
| 5920 | if (!valid_image_p (image)) | ||
| 5921 | return NULL; | ||
| 5922 | else | ||
| 5923 | { | ||
| 5924 | int img_id = lookup_image (f, image); | ||
| 5925 | struct image *img = IMAGE_FROM_ID (f, img_id); | ||
| 5926 | |||
| 5927 | prepare_image_for_display (f, img); | ||
| 5928 | |||
| 5929 | return img->data.ptr_val; | ||
| 5930 | } | ||
| 5931 | } | ||
| 5932 | |||
| 5933 | /* Create a tool bar for frame F. */ | ||
| 5934 | |||
| 5935 | static OSStatus | ||
| 5936 | mac_create_frame_tool_bar (f) | ||
| 5937 | FRAME_PTR f; | ||
| 5938 | { | ||
| 5939 | OSStatus err; | ||
| 5940 | HIToolbarRef toolbar; | ||
| 5941 | |||
| 5942 | err = HIToolbarCreate (TOOLBAR_IDENTIFIER, kHIToolbarNoAttributes, | ||
| 5943 | &toolbar); | ||
| 5944 | if (err == noErr) | ||
| 5945 | { | ||
| 5946 | static const EventTypeSpec specs[] = | ||
| 5947 | {{kEventClassToolbar, kEventToolbarGetDefaultIdentifiers}, | ||
| 5948 | {kEventClassToolbar, kEventToolbarGetAllowedIdentifiers}, | ||
| 5949 | {kEventClassToolbar, kEventToolbarCreateItemWithIdentifier}}; | ||
| 5950 | |||
| 5951 | err = InstallEventHandler (HIObjectGetEventTarget (toolbar), | ||
| 5952 | mac_handle_toolbar_event, | ||
| 5953 | GetEventTypeCount (specs), specs, | ||
| 5954 | f, NULL); | ||
| 5955 | } | ||
| 5956 | |||
| 5957 | if (err == noErr) | ||
| 5958 | err = HIToolbarSetDisplayMode (toolbar, kHIToolbarDisplayModeIconOnly); | ||
| 5959 | if (err == noErr) | ||
| 5960 | { | ||
| 5961 | static const EventTypeSpec specs[] = | ||
| 5962 | {{kEventClassCommand, kEventCommandProcess}}; | ||
| 5963 | |||
| 5964 | err = InstallWindowEventHandler (FRAME_MAC_WINDOW (f), | ||
| 5965 | mac_handle_toolbar_command_event, | ||
| 5966 | GetEventTypeCount (specs), | ||
| 5967 | specs, f, NULL); | ||
| 5968 | } | ||
| 5969 | if (err == noErr) | ||
| 5970 | err = SetWindowToolbar (FRAME_MAC_WINDOW (f), toolbar); | ||
| 5971 | |||
| 5972 | if (toolbar) | ||
| 5973 | CFRelease (toolbar); | ||
| 5974 | |||
| 5975 | return err; | ||
| 5976 | } | ||
| 5977 | |||
| 5978 | /* Update the tool bar for frame F. Add new buttons and remove old. */ | ||
| 5979 | |||
| 5980 | void | ||
| 5981 | update_frame_tool_bar (f) | ||
| 5982 | FRAME_PTR f; | ||
| 5983 | { | ||
| 5984 | HIToolbarRef toolbar = NULL; | ||
| 5985 | short left, top; | ||
| 5986 | CFArrayRef old_items = NULL; | ||
| 5987 | CFIndex old_count; | ||
| 5988 | int i, pos, win_gravity = f->output_data.mac->toolbar_win_gravity; | ||
| 5989 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); | ||
| 5990 | |||
| 5991 | BLOCK_INPUT; | ||
| 5992 | |||
| 5993 | GetWindowToolbar (FRAME_MAC_WINDOW (f), &toolbar); | ||
| 5994 | if (toolbar == NULL) | ||
| 5995 | { | ||
| 5996 | mac_create_frame_tool_bar (f); | ||
| 5997 | GetWindowToolbar (FRAME_MAC_WINDOW (f), &toolbar); | ||
| 5998 | if (toolbar == NULL) | ||
| 5999 | goto out; | ||
| 6000 | if (win_gravity >= NorthWestGravity && win_gravity <= SouthEastGravity) | ||
| 6001 | mac_get_window_origin_with_gravity (f, win_gravity, &left, &top); | ||
| 6002 | } | ||
| 6003 | |||
| 6004 | HIToolbarCopyItems (toolbar, &old_items); | ||
| 6005 | if (old_items == NULL) | ||
| 6006 | goto out; | ||
| 6007 | |||
| 6008 | old_count = CFArrayGetCount (old_items); | ||
| 6009 | pos = 0; | ||
| 6010 | for (i = 0; i < f->n_tool_bar_items; ++i) | ||
| 6011 | { | ||
| 6012 | #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX)) | ||
| 6013 | |||
| 6014 | int enabled_p = !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P)); | ||
| 6015 | int selected_p = !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P)); | ||
| 6016 | int idx; | ||
| 6017 | Lisp_Object image; | ||
| 6018 | CGImageRef cg_image; | ||
| 6019 | CFStringRef label; | ||
| 6020 | HIToolbarItemRef item; | ||
| 6021 | |||
| 6022 | /* If image is a vector, choose the image according to the | ||
| 6023 | button state. */ | ||
| 6024 | image = PROP (TOOL_BAR_ITEM_IMAGES); | ||
| 6025 | if (VECTORP (image)) | ||
| 6026 | { | ||
| 6027 | if (enabled_p) | ||
| 6028 | idx = (selected_p | ||
| 6029 | ? TOOL_BAR_IMAGE_ENABLED_SELECTED | ||
| 6030 | : TOOL_BAR_IMAGE_ENABLED_DESELECTED); | ||
| 6031 | else | ||
| 6032 | idx = (selected_p | ||
| 6033 | ? TOOL_BAR_IMAGE_DISABLED_SELECTED | ||
| 6034 | : TOOL_BAR_IMAGE_DISABLED_DESELECTED); | ||
| 6035 | |||
| 6036 | xassert (ASIZE (image) >= idx); | ||
| 6037 | image = AREF (image, idx); | ||
| 6038 | } | ||
| 6039 | else | ||
| 6040 | idx = -1; | ||
| 6041 | |||
| 6042 | cg_image = mac_image_spec_to_cg_image (f, image); | ||
| 6043 | /* Ignore invalid image specifications. */ | ||
| 6044 | if (cg_image == NULL) | ||
| 6045 | continue; | ||
| 6046 | |||
| 6047 | label = cfstring_create_with_string (PROP (TOOL_BAR_ITEM_CAPTION)); | ||
| 6048 | if (label == NULL) | ||
| 6049 | label = CFSTR (""); | ||
| 6050 | |||
| 6051 | if (pos < old_count) | ||
| 6052 | { | ||
| 6053 | CGImageRef old_cg_image = NULL; | ||
| 6054 | CFStringRef old_label = NULL; | ||
| 6055 | Boolean old_enabled_p; | ||
| 6056 | |||
| 6057 | item = (HIToolbarItemRef) CFArrayGetValueAtIndex (old_items, pos); | ||
| 6058 | |||
| 6059 | HIToolbarItemCopyImage (item, &old_cg_image); | ||
| 6060 | if (cg_image != old_cg_image) | ||
| 6061 | HIToolbarItemSetImage (item, cg_image); | ||
| 6062 | CGImageRelease (old_cg_image); | ||
| 6063 | |||
| 6064 | HIToolbarItemCopyLabel (item, &old_label); | ||
| 6065 | if (CFStringCompare (label, old_label, 0) != kCFCompareEqualTo) | ||
| 6066 | HIToolbarItemSetLabel (item, label); | ||
| 6067 | CFRelease (old_label); | ||
| 6068 | |||
| 6069 | old_enabled_p = HIToolbarItemIsEnabled (item); | ||
| 6070 | if ((enabled_p || idx >= 0) != old_enabled_p) | ||
| 6071 | HIToolbarItemSetEnabled (item, (enabled_p || idx >= 0)); | ||
| 6072 | } | ||
| 6073 | else | ||
| 6074 | { | ||
| 6075 | item = NULL; | ||
| 6076 | HIToolbarCreateItemWithIdentifier (toolbar, | ||
| 6077 | TOOLBAR_ICON_ITEM_IDENTIFIER, | ||
| 6078 | NULL, &item); | ||
| 6079 | if (item) | ||
| 6080 | { | ||
| 6081 | HIToolbarItemSetImage (item, cg_image); | ||
| 6082 | HIToolbarItemSetLabel (item, label); | ||
| 6083 | HIToolbarItemSetEnabled (item, (enabled_p || idx >= 0)); | ||
| 6084 | HIToolbarAppendItem (toolbar, item); | ||
| 6085 | CFRelease (item); | ||
| 6086 | } | ||
| 6087 | } | ||
| 6088 | |||
| 6089 | CFRelease (label); | ||
| 6090 | if (item) | ||
| 6091 | { | ||
| 6092 | HIToolbarItemSetCommandID (item, TOOLBAR_ITEM_MAKE_COMMAND_ID (i)); | ||
| 6093 | pos++; | ||
| 6094 | } | ||
| 6095 | } | ||
| 6096 | |||
| 6097 | CFRelease (old_items); | ||
| 6098 | |||
| 6099 | while (pos < old_count) | ||
| 6100 | HIToolbarRemoveItemAtIndex (toolbar, --old_count); | ||
| 6101 | |||
| 6102 | ShowHideWindowToolbar (FRAME_MAC_WINDOW (f), true, | ||
| 6103 | !win_gravity && f == mac_focus_frame (dpyinfo)); | ||
| 6104 | /* Mac OS X 10.3 does not issue kEventWindowBoundsChanged events on | ||
| 6105 | toolbar visibility change. */ | ||
| 6106 | mac_handle_origin_change (f); | ||
| 6107 | if (win_gravity >= NorthWestGravity && win_gravity <= SouthEastGravity) | ||
| 6108 | { | ||
| 6109 | mac_move_window_with_gravity (f, win_gravity, left, top); | ||
| 6110 | /* If the title bar is completely outside the screen, adjust the | ||
| 6111 | position. */ | ||
| 6112 | ConstrainWindowToScreen (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn, | ||
| 6113 | kWindowConstrainMoveRegardlessOfFit | ||
| 6114 | | kWindowConstrainAllowPartial, NULL, NULL); | ||
| 6115 | f->output_data.mac->toolbar_win_gravity = 0; | ||
| 6116 | } | ||
| 6117 | |||
| 6118 | out: | ||
| 6119 | UNBLOCK_INPUT; | ||
| 6120 | } | ||
| 6121 | |||
| 6122 | /* Hide the tool bar on frame F. Unlike the counterpart on GTK+, it | ||
| 6123 | doesn't deallocate the resources. */ | ||
| 6124 | |||
| 6125 | void | ||
| 6126 | free_frame_tool_bar (f) | ||
| 6127 | FRAME_PTR f; | ||
| 6128 | { | ||
| 6129 | if (IsWindowToolbarVisible (FRAME_MAC_WINDOW (f))) | ||
| 6130 | { | ||
| 6131 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); | ||
| 6132 | |||
| 6133 | BLOCK_INPUT; | ||
| 6134 | ShowHideWindowToolbar (FRAME_MAC_WINDOW (f), false, | ||
| 6135 | (NILP (find_symbol_value | ||
| 6136 | (intern ("frame-notice-user-settings"))) | ||
| 6137 | && f == mac_focus_frame (dpyinfo))); | ||
| 6138 | /* Mac OS X 10.3 does not issue kEventWindowBoundsChanged events | ||
| 6139 | on toolbar visibility change. */ | ||
| 6140 | mac_handle_origin_change (f); | ||
| 6141 | UNBLOCK_INPUT; | ||
| 6142 | } | ||
| 6143 | } | ||
| 6144 | |||
| 6145 | static void | ||
| 6146 | mac_tool_bar_note_mouse_movement (f, event) | ||
| 6147 | struct frame *f; | ||
| 6148 | EventRef event; | ||
| 6149 | { | ||
| 6150 | OSStatus err; | ||
| 6151 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); | ||
| 6152 | int mouse_down_p; | ||
| 6153 | WindowRef window; | ||
| 6154 | WindowPartCode part_code; | ||
| 6155 | HIViewRef item_view; | ||
| 6156 | UInt32 command_id; | ||
| 6157 | |||
| 6158 | mouse_down_p = (dpyinfo->grabbed | ||
| 6159 | && f == last_mouse_frame | ||
| 6160 | && FRAME_LIVE_P (f)); | ||
| 6161 | if (mouse_down_p) | ||
| 6162 | return; | ||
| 6163 | |||
| 6164 | err = GetEventParameter (event, kEventParamWindowRef, typeWindowRef, NULL, | ||
| 6165 | sizeof (WindowRef), NULL, &window); | ||
| 6166 | if (err != noErr || window != FRAME_MAC_WINDOW (f)) | ||
| 6167 | return; | ||
| 6168 | |||
| 6169 | err = GetEventParameter (event, kEventParamWindowPartCode, | ||
| 6170 | typeWindowPartCode, NULL, | ||
| 6171 | sizeof (WindowPartCode), NULL, &part_code); | ||
| 6172 | if (err != noErr || part_code != inStructure) | ||
| 6173 | return; | ||
| 6174 | |||
| 6175 | err = HIViewGetViewForMouseEvent (HIViewGetRoot (window), event, &item_view); | ||
| 6176 | /* This doesn't work on Mac OS X 10.2. On Mac OS X 10.3 and 10.4, a | ||
| 6177 | toolbar item view seems to have the same command ID with that of | ||
| 6178 | the toolbar item. */ | ||
| 6179 | if (err == noErr) | ||
| 6180 | err = GetControlCommandID (item_view, &command_id); | ||
| 6181 | if (err == noErr && TOOLBAR_ITEM_COMMAND_ID_P (command_id)) | ||
| 6182 | { | ||
| 6183 | int i = TOOLBAR_ITEM_COMMAND_ID_VALUE (command_id); | ||
| 6184 | |||
| 6185 | if (i < f->n_tool_bar_items) | ||
| 6186 | { | ||
| 6187 | HIRect bounds; | ||
| 6188 | HIViewRef content_view; | ||
| 6189 | |||
| 6190 | err = HIViewGetBounds (item_view, &bounds); | ||
| 6191 | if (err == noErr) | ||
| 6192 | err = HIViewFindByID (HIViewGetRoot (window), | ||
| 6193 | kHIViewWindowContentID, &content_view); | ||
| 6194 | if (err == noErr) | ||
| 6195 | err = HIViewConvertRect (&bounds, item_view, content_view); | ||
| 6196 | if (err == noErr) | ||
| 6197 | SetRect (&last_mouse_glyph, | ||
| 6198 | CGRectGetMinX (bounds), CGRectGetMinY (bounds), | ||
| 6199 | CGRectGetMaxX (bounds), CGRectGetMaxY (bounds)); | ||
| 6200 | |||
| 6201 | help_echo_object = help_echo_window = Qnil; | ||
| 6202 | help_echo_pos = -1; | ||
| 6203 | help_echo_string = PROP (TOOL_BAR_ITEM_HELP); | ||
| 6204 | if (NILP (help_echo_string)) | ||
| 6205 | help_echo_string = PROP (TOOL_BAR_ITEM_CAPTION); | ||
| 6206 | } | ||
| 6207 | } | ||
| 6208 | } | ||
| 6209 | |||
| 6210 | static OSStatus | ||
| 6211 | mac_handle_toolbar_command_event (next_handler, event, data) | ||
| 6212 | EventHandlerCallRef next_handler; | ||
| 6213 | EventRef event; | ||
| 6214 | void *data; | ||
| 6215 | { | ||
| 6216 | OSStatus err, result = eventNotHandledErr; | ||
| 6217 | struct frame *f = (struct frame *) data; | ||
| 6218 | HICommand command; | ||
| 6219 | |||
| 6220 | err = GetEventParameter (event, kEventParamDirectObject, | ||
| 6221 | typeHICommand, NULL, | ||
| 6222 | sizeof (HICommand), NULL, &command); | ||
| 6223 | if (err != noErr) | ||
| 6224 | return result; | ||
| 6225 | |||
| 6226 | switch (GetEventKind (event)) | ||
| 6227 | { | ||
| 6228 | case kEventCommandProcess: | ||
| 6229 | if (!TOOLBAR_ITEM_COMMAND_ID_P (command.commandID)) | ||
| 6230 | result = CallNextEventHandler (next_handler, event); | ||
| 6231 | else | ||
| 6232 | { | ||
| 6233 | int i = TOOLBAR_ITEM_COMMAND_ID_VALUE (command.commandID); | ||
| 6234 | |||
| 6235 | if (i < f->n_tool_bar_items | ||
| 6236 | && !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P))) | ||
| 6237 | { | ||
| 6238 | Lisp_Object frame; | ||
| 6239 | struct input_event buf; | ||
| 6240 | |||
| 6241 | EVENT_INIT (buf); | ||
| 6242 | |||
| 6243 | XSETFRAME (frame, f); | ||
| 6244 | buf.kind = TOOL_BAR_EVENT; | ||
| 6245 | buf.frame_or_window = frame; | ||
| 6246 | buf.arg = frame; | ||
| 6247 | kbd_buffer_store_event (&buf); | ||
| 6248 | |||
| 6249 | buf.kind = TOOL_BAR_EVENT; | ||
| 6250 | buf.frame_or_window = frame; | ||
| 6251 | buf.arg = PROP (TOOL_BAR_ITEM_KEY); | ||
| 6252 | buf.modifiers = mac_event_to_emacs_modifiers (event); | ||
| 6253 | kbd_buffer_store_event (&buf); | ||
| 6254 | |||
| 6255 | result = noErr; | ||
| 6256 | } | ||
| 6257 | } | ||
| 6258 | break; | ||
| 6259 | |||
| 6260 | default: | ||
| 6261 | abort (); | ||
| 6262 | } | ||
| 6263 | #undef PROP | ||
| 6264 | |||
| 6265 | return result; | ||
| 6266 | } | ||
| 6267 | #endif /* USE_MAC_TOOLBAR */ | ||
| 6268 | |||
| 6269 | |||
| 6270 | /*********************************************************************** | ||
| 5610 | Text Cursor | 6271 | Text Cursor |
| 5611 | ***********************************************************************/ | 6272 | ***********************************************************************/ |
| 5612 | 6273 | ||
| @@ -6181,9 +6842,7 @@ x_set_offset (f, xoff, yoff, change_gravity) | |||
| 6181 | ConstrainWindowToScreen (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn, | 6842 | ConstrainWindowToScreen (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn, |
| 6182 | kWindowConstrainMoveRegardlessOfFit | 6843 | kWindowConstrainMoveRegardlessOfFit |
| 6183 | | kWindowConstrainAllowPartial, NULL, NULL); | 6844 | | kWindowConstrainAllowPartial, NULL, NULL); |
| 6184 | #if USE_CARBON_EVENTS | ||
| 6185 | if (!NILP (tip_frame) && XFRAME (tip_frame) == f) | 6845 | if (!NILP (tip_frame) && XFRAME (tip_frame) == f) |
| 6186 | #endif | ||
| 6187 | mac_handle_origin_change (f); | 6846 | mac_handle_origin_change (f); |
| 6188 | #else | 6847 | #else |
| 6189 | { | 6848 | { |
| @@ -6259,7 +6918,7 @@ x_set_window_size (f, change_gravity, cols, rows) | |||
| 6259 | 6918 | ||
| 6260 | SizeWindow (FRAME_MAC_WINDOW (f), pixelwidth, pixelheight, 0); | 6919 | SizeWindow (FRAME_MAC_WINDOW (f), pixelwidth, pixelheight, 0); |
| 6261 | 6920 | ||
| 6262 | #if USE_CARBON_EVENTS | 6921 | #if TARGET_API_MAC_CARBON |
| 6263 | if (!NILP (tip_frame) && f == XFRAME (tip_frame)) | 6922 | if (!NILP (tip_frame) && f == XFRAME (tip_frame)) |
| 6264 | #endif | 6923 | #endif |
| 6265 | mac_handle_size_change (f, pixelwidth, pixelheight); | 6924 | mac_handle_size_change (f, pixelwidth, pixelheight); |
| @@ -6306,17 +6965,11 @@ x_set_mouse_pixel_position (f, pix_x, pix_y) | |||
| 6306 | int pix_x, pix_y; | 6965 | int pix_x, pix_y; |
| 6307 | { | 6966 | { |
| 6308 | #ifdef MAC_OSX | 6967 | #ifdef MAC_OSX |
| 6309 | Point p; | 6968 | pix_x += f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); |
| 6310 | CGPoint point; | 6969 | pix_y += f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); |
| 6311 | 6970 | ||
| 6312 | BLOCK_INPUT; | 6971 | BLOCK_INPUT; |
| 6313 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 6972 | CGWarpMouseCursorPosition (CGPointMake (pix_x, pix_y)); |
| 6314 | p.h = pix_x; | ||
| 6315 | p.v = pix_y; | ||
| 6316 | LocalToGlobal (&p); | ||
| 6317 | point.x = p.h; | ||
| 6318 | point.y = p.v; | ||
| 6319 | CGWarpMouseCursorPosition (point); | ||
| 6320 | UNBLOCK_INPUT; | 6973 | UNBLOCK_INPUT; |
| 6321 | #else | 6974 | #else |
| 6322 | #if 0 /* MAC_TODO: LMSetMouseLocation and CursorDeviceMoveTo are non-Carbon */ | 6975 | #if 0 /* MAC_TODO: LMSetMouseLocation and CursorDeviceMoveTo are non-Carbon */ |
| @@ -6398,7 +7051,7 @@ static void | |||
| 6398 | mac_handle_visibility_change (f) | 7051 | mac_handle_visibility_change (f) |
| 6399 | struct frame *f; | 7052 | struct frame *f; |
| 6400 | { | 7053 | { |
| 6401 | WindowPtr wp = FRAME_MAC_WINDOW (f); | 7054 | WindowRef wp = FRAME_MAC_WINDOW (f); |
| 6402 | int visible = 0, iconified = 0; | 7055 | int visible = 0, iconified = 0; |
| 6403 | struct input_event buf; | 7056 | struct input_event buf; |
| 6404 | 7057 | ||
| @@ -6466,32 +7119,7 @@ x_make_frame_visible (f) | |||
| 6466 | before the window gets really visible. */ | 7119 | before the window gets really visible. */ |
| 6467 | if (! FRAME_ICONIFIED_P (f) | 7120 | if (! FRAME_ICONIFIED_P (f) |
| 6468 | && ! f->output_data.mac->asked_for_visible) | 7121 | && ! f->output_data.mac->asked_for_visible) |
| 6469 | { | 7122 | x_set_offset (f, f->left_pos, f->top_pos, 0); |
| 6470 | #if TARGET_API_MAC_CARBON | ||
| 6471 | if (!(FRAME_SIZE_HINTS (f)->flags & (USPosition | PPosition))) | ||
| 6472 | { | ||
| 6473 | struct frame *sf = SELECTED_FRAME (); | ||
| 6474 | if (!FRAME_MAC_P (sf)) | ||
| 6475 | RepositionWindow (FRAME_MAC_WINDOW (f), NULL, | ||
| 6476 | kWindowCenterOnMainScreen); | ||
| 6477 | else | ||
| 6478 | RepositionWindow (FRAME_MAC_WINDOW (f), | ||
| 6479 | FRAME_MAC_WINDOW (sf), | ||
| 6480 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | ||
| 6481 | kWindowCascadeStartAtParentWindowScreen | ||
| 6482 | #else | ||
| 6483 | kWindowCascadeOnParentWindowScreen | ||
| 6484 | #endif | ||
| 6485 | ); | ||
| 6486 | #if USE_CARBON_EVENTS | ||
| 6487 | if (!NILP (tip_frame) && f == XFRAME (tip_frame)) | ||
| 6488 | #endif | ||
| 6489 | mac_handle_origin_change (f); | ||
| 6490 | } | ||
| 6491 | else | ||
| 6492 | #endif | ||
| 6493 | x_set_offset (f, f->left_pos, f->top_pos, 0); | ||
| 6494 | } | ||
| 6495 | 7123 | ||
| 6496 | f->output_data.mac->asked_for_visible = 1; | 7124 | f->output_data.mac->asked_for_visible = 1; |
| 6497 | 7125 | ||
| @@ -6565,18 +7193,20 @@ x_make_frame_invisible (f) | |||
| 6565 | 7193 | ||
| 6566 | BLOCK_INPUT; | 7194 | BLOCK_INPUT; |
| 6567 | 7195 | ||
| 7196 | #if !TARGET_API_MAC_CARBON | ||
| 6568 | /* Before unmapping the window, update the WM_SIZE_HINTS property to claim | 7197 | /* Before unmapping the window, update the WM_SIZE_HINTS property to claim |
| 6569 | that the current position of the window is user-specified, rather than | 7198 | that the current position of the window is user-specified, rather than |
| 6570 | program-specified, so that when the window is mapped again, it will be | 7199 | program-specified, so that when the window is mapped again, it will be |
| 6571 | placed at the same location, without forcing the user to position it | 7200 | placed at the same location, without forcing the user to position it |
| 6572 | by hand again (they have already done that once for this window.) */ | 7201 | by hand again (they have already done that once for this window.) */ |
| 6573 | x_wm_set_size_hint (f, (long) 0, 1); | 7202 | x_wm_set_size_hint (f, (long) 0, 1); |
| 7203 | #endif | ||
| 6574 | 7204 | ||
| 6575 | HideWindow (FRAME_MAC_WINDOW (f)); | 7205 | HideWindow (FRAME_MAC_WINDOW (f)); |
| 6576 | 7206 | ||
| 6577 | UNBLOCK_INPUT; | 7207 | UNBLOCK_INPUT; |
| 6578 | 7208 | ||
| 6579 | #if !USE_CARBON_EVENTS | 7209 | #if !TARGET_API_MAC_CARBON |
| 6580 | mac_handle_visibility_change (f); | 7210 | mac_handle_visibility_change (f); |
| 6581 | #endif | 7211 | #endif |
| 6582 | } | 7212 | } |
| @@ -6615,7 +7245,7 @@ x_iconify_frame (f) | |||
| 6615 | if (err != noErr) | 7245 | if (err != noErr) |
| 6616 | error ("Can't notify window manager of iconification"); | 7246 | error ("Can't notify window manager of iconification"); |
| 6617 | 7247 | ||
| 6618 | #if !USE_CARBON_EVENTS | 7248 | #if !TARGET_API_MAC_CARBON |
| 6619 | mac_handle_visibility_change (f); | 7249 | mac_handle_visibility_change (f); |
| 6620 | #endif | 7250 | #endif |
| 6621 | } | 7251 | } |
| @@ -6628,7 +7258,7 @@ x_free_frame_resources (f) | |||
| 6628 | struct frame *f; | 7258 | struct frame *f; |
| 6629 | { | 7259 | { |
| 6630 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); | 7260 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); |
| 6631 | WindowPtr wp = FRAME_MAC_WINDOW (f); | 7261 | WindowRef wp = FRAME_MAC_WINDOW (f); |
| 6632 | 7262 | ||
| 6633 | BLOCK_INPUT; | 7263 | BLOCK_INPUT; |
| 6634 | 7264 | ||
| @@ -8763,16 +9393,95 @@ x_find_ccl_program (fontp) | |||
| 8763 | possible. */ | 9393 | possible. */ |
| 8764 | static int font_panel_shown_p = 0; | 9394 | static int font_panel_shown_p = 0; |
| 8765 | 9395 | ||
| 9396 | extern Lisp_Object Qfont; | ||
| 9397 | static Lisp_Object Qpanel_closed, Qselection; | ||
| 9398 | |||
| 9399 | static OSStatus mac_store_event_ref_as_apple_event P_ ((AEEventClass, AEEventID, | ||
| 9400 | Lisp_Object, | ||
| 9401 | Lisp_Object, | ||
| 9402 | EventRef, UInt32, | ||
| 9403 | const EventParamName *, | ||
| 9404 | const EventParamType *)); | ||
| 9405 | |||
| 8766 | int | 9406 | int |
| 8767 | mac_font_panel_visible_p () | 9407 | mac_font_panel_visible_p () |
| 8768 | { | 9408 | { |
| 8769 | return font_panel_shown_p && FPIsFontPanelVisible (); | 9409 | return font_panel_shown_p && FPIsFontPanelVisible (); |
| 8770 | } | 9410 | } |
| 8771 | 9411 | ||
| 9412 | static pascal OSStatus | ||
| 9413 | mac_handle_font_event (next_handler, event, data) | ||
| 9414 | EventHandlerCallRef next_handler; | ||
| 9415 | EventRef event; | ||
| 9416 | void *data; | ||
| 9417 | { | ||
| 9418 | OSStatus result, err; | ||
| 9419 | Lisp_Object id_key; | ||
| 9420 | int num_params; | ||
| 9421 | const EventParamName *names; | ||
| 9422 | const EventParamType *types; | ||
| 9423 | static const EventParamName names_sel[] = {kEventParamATSUFontID, | ||
| 9424 | kEventParamATSUFontSize, | ||
| 9425 | kEventParamFMFontFamily, | ||
| 9426 | kEventParamFMFontStyle, | ||
| 9427 | kEventParamFMFontSize, | ||
| 9428 | kEventParamFontColor}; | ||
| 9429 | static const EventParamType types_sel[] = {typeATSUFontID, | ||
| 9430 | typeATSUSize, | ||
| 9431 | typeFMFontFamily, | ||
| 9432 | typeFMFontStyle, | ||
| 9433 | typeFMFontSize, | ||
| 9434 | typeFontColor}; | ||
| 9435 | |||
| 9436 | result = CallNextEventHandler (next_handler, event); | ||
| 9437 | if (result != eventNotHandledErr) | ||
| 9438 | return result; | ||
| 9439 | |||
| 9440 | switch (GetEventKind (event)) | ||
| 9441 | { | ||
| 9442 | case kEventFontPanelClosed: | ||
| 9443 | id_key = Qpanel_closed; | ||
| 9444 | num_params = 0; | ||
| 9445 | names = NULL; | ||
| 9446 | types = NULL; | ||
| 9447 | break; | ||
| 9448 | |||
| 9449 | case kEventFontSelection: | ||
| 9450 | id_key = Qselection; | ||
| 9451 | num_params = sizeof (names_sel) / sizeof (names_sel[0]); | ||
| 9452 | names = names_sel; | ||
| 9453 | types = types_sel; | ||
| 9454 | break; | ||
| 9455 | } | ||
| 9456 | |||
| 9457 | err = mac_store_event_ref_as_apple_event (0, 0, Qfont, id_key, | ||
| 9458 | event, num_params, | ||
| 9459 | names, types); | ||
| 9460 | if (err == noErr) | ||
| 9461 | result = noErr; | ||
| 9462 | |||
| 9463 | return result; | ||
| 9464 | } | ||
| 9465 | |||
| 8772 | OSStatus | 9466 | OSStatus |
| 8773 | mac_show_hide_font_panel () | 9467 | mac_show_hide_font_panel () |
| 8774 | { | 9468 | { |
| 8775 | font_panel_shown_p = 1; | 9469 | if (!font_panel_shown_p) |
| 9470 | { | ||
| 9471 | OSStatus err; | ||
| 9472 | |||
| 9473 | static const EventTypeSpec specs[] = | ||
| 9474 | {{kEventClassFont, kEventFontPanelClosed}, | ||
| 9475 | {kEventClassFont, kEventFontSelection}}; | ||
| 9476 | |||
| 9477 | err = InstallApplicationEventHandler (mac_handle_font_event, | ||
| 9478 | GetEventTypeCount (specs), | ||
| 9479 | specs, NULL, NULL); | ||
| 9480 | if (err != noErr) | ||
| 9481 | return err; | ||
| 9482 | |||
| 9483 | font_panel_shown_p = 1; | ||
| 9484 | } | ||
| 8776 | 9485 | ||
| 8777 | return FPShowHideFontPanel (); | 9486 | return FPShowHideFontPanel (); |
| 8778 | } | 9487 | } |
| @@ -8888,7 +9597,7 @@ Lisp_Object Vmac_function_modifier; | |||
| 8888 | a three button mouse */ | 9597 | a three button mouse */ |
| 8889 | Lisp_Object Vmac_emulate_three_button_mouse; | 9598 | Lisp_Object Vmac_emulate_three_button_mouse; |
| 8890 | 9599 | ||
| 8891 | #if USE_CARBON_EVENTS | 9600 | #if TARGET_API_MAC_CARBON |
| 8892 | /* Non-zero if the mouse wheel button (i.e. button 4) should map to | 9601 | /* Non-zero if the mouse wheel button (i.e. button 4) should map to |
| 8893 | mouse-2, instead of mouse-3. */ | 9602 | mouse-2, instead of mouse-3. */ |
| 8894 | int mac_wheel_button_is_mouse_2; | 9603 | int mac_wheel_button_is_mouse_2; |
| @@ -8913,16 +9622,12 @@ static int mac_screen_config_changed = 0; | |||
| 8913 | Point saved_menu_event_location; | 9622 | Point saved_menu_event_location; |
| 8914 | 9623 | ||
| 8915 | /* Apple Events */ | 9624 | /* Apple Events */ |
| 8916 | #if USE_CARBON_EVENTS | 9625 | #if TARGET_API_MAC_CARBON |
| 8917 | static Lisp_Object Qhi_command; | 9626 | static Lisp_Object Qhi_command; |
| 8918 | #ifdef MAC_OSX | 9627 | #ifdef MAC_OSX |
| 8919 | extern Lisp_Object Qwindow; | 9628 | extern Lisp_Object Qwindow; |
| 8920 | static Lisp_Object Qtoolbar_switch_mode; | 9629 | static Lisp_Object Qtoolbar_switch_mode; |
| 8921 | #endif | 9630 | #endif |
| 8922 | #if USE_MAC_FONT_PANEL | ||
| 8923 | extern Lisp_Object Qfont; | ||
| 8924 | static Lisp_Object Qpanel_closed, Qselection; | ||
| 8925 | #endif | ||
| 8926 | #if USE_MAC_TSM | 9631 | #if USE_MAC_TSM |
| 8927 | static TSMDocumentID tsm_document_id; | 9632 | static TSMDocumentID tsm_document_id; |
| 8928 | static Lisp_Object Qtext_input; | 9633 | static Lisp_Object Qtext_input; |
| @@ -8934,7 +9639,7 @@ static Lisp_Object saved_ts_script_language_on_focus; | |||
| 8934 | static ScriptLanguageRecord saved_ts_language; | 9639 | static ScriptLanguageRecord saved_ts_language; |
| 8935 | static Component saved_ts_component; | 9640 | static Component saved_ts_component; |
| 8936 | #endif | 9641 | #endif |
| 8937 | #endif | 9642 | #endif /* TARGET_API_MAC_CARBON */ |
| 8938 | extern int mac_ready_for_apple_events; | 9643 | extern int mac_ready_for_apple_events; |
| 8939 | extern Lisp_Object Qundefined; | 9644 | extern Lisp_Object Qundefined; |
| 8940 | extern void init_apple_event_handler P_ ((void)); | 9645 | extern void init_apple_event_handler P_ ((void)); |
| @@ -8947,20 +9652,15 @@ extern OSErr init_coercion_handler P_ ((void)); | |||
| 8947 | extern OSErr install_drag_handler P_ ((WindowRef)); | 9652 | extern OSErr install_drag_handler P_ ((WindowRef)); |
| 8948 | extern void remove_drag_handler P_ ((WindowRef)); | 9653 | extern void remove_drag_handler P_ ((WindowRef)); |
| 8949 | 9654 | ||
| 9655 | #if TARGET_API_MAC_CARBON | ||
| 8950 | /* Showing help echo string during menu tracking */ | 9656 | /* Showing help echo string during menu tracking */ |
| 8951 | extern OSStatus install_menu_target_item_handler P_ ((WindowPtr)); | 9657 | extern OSStatus install_menu_target_item_handler P_ ((void)); |
| 8952 | 9658 | ||
| 8953 | #if USE_CARBON_EVENTS | ||
| 8954 | #ifdef MAC_OSX | 9659 | #ifdef MAC_OSX |
| 8955 | extern void init_service_handler (); | 9660 | extern OSStatus install_service_handler (); |
| 8956 | static Lisp_Object Qservice, Qpaste, Qperform; | 9661 | static Lisp_Object Qservice, Qpaste, Qperform; |
| 8957 | #endif | 9662 | #endif |
| 8958 | |||
| 8959 | /* Window Event Handler */ | ||
| 8960 | static pascal OSStatus mac_handle_window_event (EventHandlerCallRef, | ||
| 8961 | EventRef, void *); | ||
| 8962 | #endif | 9663 | #endif |
| 8963 | OSStatus install_window_handler (WindowPtr); | ||
| 8964 | 9664 | ||
| 8965 | extern void init_emacs_passwd_dir (); | 9665 | extern void init_emacs_passwd_dir (); |
| 8966 | extern int emacs_main (int, char **, char **); | 9666 | extern int emacs_main (int, char **, char **); |
| @@ -9044,7 +9744,7 @@ static const unsigned char fn_keycode_to_keycode_table[] = { | |||
| 9044 | #endif /* MAC_OSX */ | 9744 | #endif /* MAC_OSX */ |
| 9045 | 9745 | ||
| 9046 | static int | 9746 | static int |
| 9047 | #if USE_CARBON_EVENTS | 9747 | #if TARGET_API_MAC_CARBON |
| 9048 | mac_to_emacs_modifiers (UInt32 mods, UInt32 unmapped_mods) | 9748 | mac_to_emacs_modifiers (UInt32 mods, UInt32 unmapped_mods) |
| 9049 | #else | 9749 | #else |
| 9050 | mac_to_emacs_modifiers (EventModifiers mods, EventModifiers unmapped_mods) | 9750 | mac_to_emacs_modifiers (EventModifiers mods, EventModifiers unmapped_mods) |
| @@ -9165,17 +9865,19 @@ mac_quit_char_key_p (modifiers, key_code) | |||
| 9165 | } | 9865 | } |
| 9166 | #endif | 9866 | #endif |
| 9167 | 9867 | ||
| 9168 | #if USE_CARBON_EVENTS | 9868 | #if TARGET_API_MAC_CARBON |
| 9169 | /* Obtains the event modifiers from the event ref and then calls | 9869 | /* Obtains the event modifiers from the event ref and then calls |
| 9170 | mac_to_emacs_modifiers. */ | 9870 | mac_to_emacs_modifiers. */ |
| 9171 | static int | 9871 | static int |
| 9172 | mac_event_to_emacs_modifiers (EventRef eventRef) | 9872 | mac_event_to_emacs_modifiers (EventRef eventRef) |
| 9173 | { | 9873 | { |
| 9174 | UInt32 mods = 0; | 9874 | UInt32 mods = 0, class; |
| 9875 | |||
| 9175 | GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL, | 9876 | GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL, |
| 9176 | sizeof (UInt32), NULL, &mods); | 9877 | sizeof (UInt32), NULL, &mods); |
| 9878 | class = GetEventClass (eventRef); | ||
| 9177 | if (!NILP (Vmac_emulate_three_button_mouse) && | 9879 | if (!NILP (Vmac_emulate_three_button_mouse) && |
| 9178 | GetEventClass(eventRef) == kEventClassMouse) | 9880 | (class == kEventClassMouse || class == kEventClassCommand)) |
| 9179 | { | 9881 | { |
| 9180 | mods &= ~(optionKey | cmdKey); | 9882 | mods &= ~(optionKey | cmdKey); |
| 9181 | } | 9883 | } |
| @@ -9314,7 +10016,7 @@ static void | |||
| 9314 | do_get_menus (void) | 10016 | do_get_menus (void) |
| 9315 | { | 10017 | { |
| 9316 | Handle menubar_handle; | 10018 | Handle menubar_handle; |
| 9317 | MenuHandle menu_handle; | 10019 | MenuRef menu; |
| 9318 | 10020 | ||
| 9319 | menubar_handle = GetNewMBar (128); | 10021 | menubar_handle = GetNewMBar (128); |
| 9320 | if(menubar_handle == NULL) | 10022 | if(menubar_handle == NULL) |
| @@ -9323,9 +10025,9 @@ do_get_menus (void) | |||
| 9323 | DrawMenuBar (); | 10025 | DrawMenuBar (); |
| 9324 | 10026 | ||
| 9325 | #if !TARGET_API_MAC_CARBON | 10027 | #if !TARGET_API_MAC_CARBON |
| 9326 | menu_handle = GetMenuHandle (M_APPLE); | 10028 | menu = GetMenuRef (M_APPLE); |
| 9327 | if(menu_handle != NULL) | 10029 | if (menu != NULL) |
| 9328 | AppendResMenu (menu_handle,'DRVR'); | 10030 | AppendResMenu (menu, 'DRVR'); |
| 9329 | else | 10031 | else |
| 9330 | abort (); | 10032 | abort (); |
| 9331 | #endif | 10033 | #endif |
| @@ -9374,7 +10076,7 @@ do_check_ram_size (void) | |||
| 9374 | #endif /* MAC_OS8 */ | 10076 | #endif /* MAC_OS8 */ |
| 9375 | 10077 | ||
| 9376 | static void | 10078 | static void |
| 9377 | do_window_update (WindowPtr win) | 10079 | do_window_update (WindowRef win) |
| 9378 | { | 10080 | { |
| 9379 | struct frame *f = mac_window_to_frame (win); | 10081 | struct frame *f = mac_window_to_frame (win); |
| 9380 | 10082 | ||
| @@ -9419,7 +10121,7 @@ do_window_update (WindowPtr win) | |||
| 9419 | } | 10121 | } |
| 9420 | 10122 | ||
| 9421 | static int | 10123 | static int |
| 9422 | is_emacs_window (WindowPtr win) | 10124 | is_emacs_window (WindowRef win) |
| 9423 | { | 10125 | { |
| 9424 | Lisp_Object tail, frame; | 10126 | Lisp_Object tail, frame; |
| 9425 | 10127 | ||
| @@ -9532,7 +10234,7 @@ do_apple_menu (SInt16 menu_item) | |||
| 9532 | NoteAlert (ABOUT_ALERT_ID, NULL); | 10234 | NoteAlert (ABOUT_ALERT_ID, NULL); |
| 9533 | else | 10235 | else |
| 9534 | { | 10236 | { |
| 9535 | GetMenuItemText (GetMenuHandle (M_APPLE), menu_item, item_name); | 10237 | GetMenuItemText (GetMenuRef (M_APPLE), menu_item, item_name); |
| 9536 | da_driver_refnum = OpenDeskAcc (item_name); | 10238 | da_driver_refnum = OpenDeskAcc (item_name); |
| 9537 | } | 10239 | } |
| 9538 | } | 10240 | } |
| @@ -9543,7 +10245,7 @@ do_apple_menu (SInt16 menu_item) | |||
| 9543 | 10245 | ||
| 9544 | static void | 10246 | static void |
| 9545 | do_grow_window (w, e) | 10247 | do_grow_window (w, e) |
| 9546 | WindowPtr w; | 10248 | WindowRef w; |
| 9547 | const EventRecord *e; | 10249 | const EventRecord *e; |
| 9548 | { | 10250 | { |
| 9549 | Rect limit_rect; | 10251 | Rect limit_rect; |
| @@ -9595,7 +10297,7 @@ mac_get_ideal_size (f) | |||
| 9595 | struct frame *f; | 10297 | struct frame *f; |
| 9596 | { | 10298 | { |
| 9597 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); | 10299 | struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); |
| 9598 | WindowPtr w = FRAME_MAC_WINDOW (f); | 10300 | WindowRef w = FRAME_MAC_WINDOW (f); |
| 9599 | Point ideal_size; | 10301 | Point ideal_size; |
| 9600 | Rect standard_rect; | 10302 | Rect standard_rect; |
| 9601 | int height, width, columns, rows; | 10303 | int height, width, columns, rows; |
| @@ -9621,7 +10323,7 @@ mac_get_ideal_size (f) | |||
| 9621 | wide (DEFAULT_NUM_COLS) and as tall as will fit on the screen. */ | 10323 | wide (DEFAULT_NUM_COLS) and as tall as will fit on the screen. */ |
| 9622 | 10324 | ||
| 9623 | static void | 10325 | static void |
| 9624 | do_zoom_window (WindowPtr w, int zoom_in_or_out) | 10326 | do_zoom_window (WindowRef w, int zoom_in_or_out) |
| 9625 | { | 10327 | { |
| 9626 | Rect zoom_rect, port_rect; | 10328 | Rect zoom_rect, port_rect; |
| 9627 | int width, height; | 10329 | int width, height; |
| @@ -9684,13 +10386,9 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out) | |||
| 9684 | SetPort (save_port); | 10386 | SetPort (save_port); |
| 9685 | #endif /* not TARGET_API_MAC_CARBON */ | 10387 | #endif /* not TARGET_API_MAC_CARBON */ |
| 9686 | 10388 | ||
| 9687 | #if !USE_CARBON_EVENTS | 10389 | #if !TARGET_API_MAC_CARBON |
| 9688 | /* retrieve window size and update application values */ | 10390 | /* retrieve window size and update application values */ |
| 9689 | #if TARGET_API_MAC_CARBON | ||
| 9690 | GetWindowPortBounds (w, &port_rect); | ||
| 9691 | #else | ||
| 9692 | port_rect = w->portRect; | 10391 | port_rect = w->portRect; |
| 9693 | #endif | ||
| 9694 | height = port_rect.bottom - port_rect.top; | 10392 | height = port_rect.bottom - port_rect.top; |
| 9695 | width = port_rect.right - port_rect.left; | 10393 | width = port_rect.right - port_rect.left; |
| 9696 | 10394 | ||
| @@ -9699,6 +10397,204 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out) | |||
| 9699 | #endif | 10397 | #endif |
| 9700 | } | 10398 | } |
| 9701 | 10399 | ||
| 10400 | static void | ||
| 10401 | mac_set_unicode_keystroke_event (code, buf) | ||
| 10402 | UniChar code; | ||
| 10403 | struct input_event *buf; | ||
| 10404 | { | ||
| 10405 | int charset_id, c1, c2; | ||
| 10406 | |||
| 10407 | if (code < 0x80) | ||
| 10408 | { | ||
| 10409 | buf->kind = ASCII_KEYSTROKE_EVENT; | ||
| 10410 | buf->code = code; | ||
| 10411 | } | ||
| 10412 | else if (code < 0x100) | ||
| 10413 | { | ||
| 10414 | if (code < 0xA0) | ||
| 10415 | charset_id = CHARSET_8_BIT_CONTROL; | ||
| 10416 | else | ||
| 10417 | charset_id = charset_latin_iso8859_1; | ||
| 10418 | buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT; | ||
| 10419 | buf->code = MAKE_CHAR (charset_id, code, 0); | ||
| 10420 | } | ||
| 10421 | else | ||
| 10422 | { | ||
| 10423 | if (code < 0x2500) | ||
| 10424 | charset_id = charset_mule_unicode_0100_24ff, | ||
| 10425 | code -= 0x100; | ||
| 10426 | else if (code < 0x33FF) | ||
| 10427 | charset_id = charset_mule_unicode_2500_33ff, | ||
| 10428 | code -= 0x2500; | ||
| 10429 | else if (code >= 0xE000) | ||
| 10430 | charset_id = charset_mule_unicode_e000_ffff, | ||
| 10431 | code -= 0xE000; | ||
| 10432 | c1 = (code / 96) + 32, c2 = (code % 96) + 32; | ||
| 10433 | buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT; | ||
| 10434 | buf->code = MAKE_CHAR (charset_id, c1, c2); | ||
| 10435 | } | ||
| 10436 | } | ||
| 10437 | |||
| 10438 | static void | ||
| 10439 | do_keystroke (action, char_code, key_code, modifiers, timestamp, buf) | ||
| 10440 | EventKind action; | ||
| 10441 | unsigned char char_code; | ||
| 10442 | UInt32 key_code, modifiers; | ||
| 10443 | unsigned long timestamp; | ||
| 10444 | struct input_event *buf; | ||
| 10445 | { | ||
| 10446 | static SInt16 last_key_script = -1; | ||
| 10447 | SInt16 current_key_script = GetScriptManagerVariable (smKeyScript); | ||
| 10448 | UInt32 mapped_modifiers = mac_mapped_modifiers (modifiers, key_code); | ||
| 10449 | |||
| 10450 | #ifdef MAC_OSX | ||
| 10451 | if (mapped_modifiers & kEventKeyModifierFnMask | ||
| 10452 | && key_code <= 0x7f | ||
| 10453 | && fn_keycode_to_keycode_table[key_code]) | ||
| 10454 | key_code = fn_keycode_to_keycode_table[key_code]; | ||
| 10455 | #endif | ||
| 10456 | |||
| 10457 | if (key_code <= 0x7f && keycode_to_xkeysym_table[key_code]) | ||
| 10458 | { | ||
| 10459 | buf->kind = NON_ASCII_KEYSTROKE_EVENT; | ||
| 10460 | buf->code = 0xff00 | keycode_to_xkeysym_table[key_code]; | ||
| 10461 | } | ||
| 10462 | else if (mapped_modifiers) | ||
| 10463 | { | ||
| 10464 | /* translate the keycode back to determine the original key */ | ||
| 10465 | #ifdef MAC_OSX | ||
| 10466 | UCKeyboardLayout *uchr_ptr = NULL; | ||
| 10467 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | ||
| 10468 | OSStatus err; | ||
| 10469 | KeyboardLayoutRef layout; | ||
| 10470 | |||
| 10471 | err = KLGetCurrentKeyboardLayout (&layout); | ||
| 10472 | if (err == noErr) | ||
| 10473 | err = KLGetKeyboardLayoutProperty (layout, kKLuchrData, | ||
| 10474 | (const void **) &uchr_ptr); | ||
| 10475 | #else | ||
| 10476 | static SInt16 last_key_layout_id = 0; | ||
| 10477 | static Handle uchr_handle = (Handle)-1; | ||
| 10478 | SInt16 current_key_layout_id = | ||
| 10479 | GetScriptVariable (current_key_script, smScriptKeys); | ||
| 10480 | |||
| 10481 | if (uchr_handle == (Handle)-1 | ||
| 10482 | || last_key_layout_id != current_key_layout_id) | ||
| 10483 | { | ||
| 10484 | uchr_handle = GetResource ('uchr', current_key_layout_id); | ||
| 10485 | last_key_layout_id = current_key_layout_id; | ||
| 10486 | } | ||
| 10487 | if (uchr_handle) | ||
| 10488 | uchr_ptr = (UCKeyboardLayout *)*uchr_handle; | ||
| 10489 | #endif | ||
| 10490 | |||
| 10491 | if (uchr_ptr) | ||
| 10492 | { | ||
| 10493 | OSStatus status; | ||
| 10494 | UInt16 key_action = action - keyDown; | ||
| 10495 | UInt32 modifier_key_state = (modifiers & ~mapped_modifiers) >> 8; | ||
| 10496 | UInt32 keyboard_type = LMGetKbdType (); | ||
| 10497 | SInt32 dead_key_state = 0; | ||
| 10498 | UniChar code; | ||
| 10499 | UniCharCount actual_length; | ||
| 10500 | |||
| 10501 | status = UCKeyTranslate (uchr_ptr, key_code, key_action, | ||
| 10502 | modifier_key_state, keyboard_type, | ||
| 10503 | kUCKeyTranslateNoDeadKeysMask, | ||
| 10504 | &dead_key_state, | ||
| 10505 | 1, &actual_length, &code); | ||
| 10506 | if (status == noErr && actual_length == 1) | ||
| 10507 | mac_set_unicode_keystroke_event (code, buf); | ||
| 10508 | } | ||
| 10509 | #endif /* MAC_OSX */ | ||
| 10510 | |||
| 10511 | if (buf->kind == NO_EVENT) | ||
| 10512 | { | ||
| 10513 | /* This code comes from Keyboard Resource, Appendix C of IM | ||
| 10514 | - Text. This is necessary since shift is ignored in KCHR | ||
| 10515 | table translation when option or command is pressed. It | ||
| 10516 | also does not translate correctly control-shift chars | ||
| 10517 | like C-% so mask off shift here also. */ | ||
| 10518 | /* Mask off modifier keys that are mapped to some Emacs | ||
| 10519 | modifiers. */ | ||
| 10520 | int new_modifiers = modifiers & ~mapped_modifiers; | ||
| 10521 | /* set high byte of keycode to modifier high byte*/ | ||
| 10522 | int new_key_code = key_code | new_modifiers; | ||
| 10523 | Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache); | ||
| 10524 | unsigned long some_state = 0; | ||
| 10525 | UInt32 new_char_code; | ||
| 10526 | |||
| 10527 | new_char_code = KeyTranslate (kchr_ptr, new_key_code, &some_state); | ||
| 10528 | if (new_char_code == 0) | ||
| 10529 | /* Seems like a dead key. Append up-stroke. */ | ||
| 10530 | new_char_code = KeyTranslate (kchr_ptr, new_key_code | 0x80, | ||
| 10531 | &some_state); | ||
| 10532 | if (new_char_code) | ||
| 10533 | { | ||
| 10534 | buf->kind = ASCII_KEYSTROKE_EVENT; | ||
| 10535 | buf->code = new_char_code & 0xff; | ||
| 10536 | } | ||
| 10537 | } | ||
| 10538 | } | ||
| 10539 | |||
| 10540 | if (buf->kind == NO_EVENT) | ||
| 10541 | { | ||
| 10542 | buf->kind = ASCII_KEYSTROKE_EVENT; | ||
| 10543 | buf->code = char_code; | ||
| 10544 | } | ||
| 10545 | |||
| 10546 | buf->modifiers = mac_to_emacs_modifiers (mapped_modifiers, modifiers); | ||
| 10547 | buf->modifiers |= (extra_keyboard_modifiers | ||
| 10548 | & (meta_modifier | alt_modifier | ||
| 10549 | | hyper_modifier | super_modifier)); | ||
| 10550 | |||
| 10551 | #if TARGET_API_MAC_CARBON | ||
| 10552 | if (buf->kind == ASCII_KEYSTROKE_EVENT | ||
| 10553 | && buf->code >= 0x80 && buf->modifiers) | ||
| 10554 | { | ||
| 10555 | OSStatus err; | ||
| 10556 | TextEncoding encoding = kTextEncodingMacRoman; | ||
| 10557 | TextToUnicodeInfo ttu_info; | ||
| 10558 | |||
| 10559 | UpgradeScriptInfoToTextEncoding (current_key_script, | ||
| 10560 | kTextLanguageDontCare, | ||
| 10561 | kTextRegionDontCare, | ||
| 10562 | NULL, &encoding); | ||
| 10563 | err = CreateTextToUnicodeInfoByEncoding (encoding, &ttu_info); | ||
| 10564 | if (err == noErr) | ||
| 10565 | { | ||
| 10566 | UniChar code; | ||
| 10567 | Str255 pstr; | ||
| 10568 | ByteCount unicode_len; | ||
| 10569 | |||
| 10570 | pstr[0] = 1; | ||
| 10571 | pstr[1] = buf->code; | ||
| 10572 | err = ConvertFromPStringToUnicode (ttu_info, pstr, | ||
| 10573 | sizeof (UniChar), | ||
| 10574 | &unicode_len, &code); | ||
| 10575 | if (err == noErr && unicode_len == sizeof (UniChar)) | ||
| 10576 | mac_set_unicode_keystroke_event (code, buf); | ||
| 10577 | DisposeTextToUnicodeInfo (&ttu_info); | ||
| 10578 | } | ||
| 10579 | } | ||
| 10580 | #endif | ||
| 10581 | |||
| 10582 | if (buf->kind == ASCII_KEYSTROKE_EVENT | ||
| 10583 | && buf->code >= 0x80 | ||
| 10584 | && last_key_script != current_key_script) | ||
| 10585 | { | ||
| 10586 | struct input_event event; | ||
| 10587 | |||
| 10588 | EVENT_INIT (event); | ||
| 10589 | event.kind = LANGUAGE_CHANGE_EVENT; | ||
| 10590 | event.arg = Qnil; | ||
| 10591 | event.code = current_key_script; | ||
| 10592 | event.timestamp = timestamp; | ||
| 10593 | kbd_buffer_store_event (&event); | ||
| 10594 | last_key_script = current_key_script; | ||
| 10595 | } | ||
| 10596 | } | ||
| 10597 | |||
| 9702 | void | 10598 | void |
| 9703 | mac_store_apple_event (class, id, desc) | 10599 | mac_store_apple_event (class, id, desc) |
| 9704 | Lisp_Object class, id; | 10600 | Lisp_Object class, id; |
| @@ -9777,54 +10673,49 @@ mac_store_drag_event (window, mouse_pos, modifiers, desc) | |||
| 9777 | buf.arg = mac_aedesc_to_lisp (desc); | 10673 | buf.arg = mac_aedesc_to_lisp (desc); |
| 9778 | kbd_buffer_store_event (&buf); | 10674 | kbd_buffer_store_event (&buf); |
| 9779 | } | 10675 | } |
| 9780 | #endif | ||
| 9781 | 10676 | ||
| 9782 | #if USE_CARBON_EVENTS | 10677 | #ifdef MAC_OSX |
| 9783 | static pascal OSStatus | 10678 | OSStatus |
| 9784 | mac_handle_command_event (next_handler, event, data) | 10679 | mac_store_service_event (event) |
| 9785 | EventHandlerCallRef next_handler; | ||
| 9786 | EventRef event; | 10680 | EventRef event; |
| 9787 | void *data; | ||
| 9788 | { | 10681 | { |
| 9789 | OSStatus result, err; | 10682 | OSStatus err; |
| 9790 | HICommand command; | 10683 | Lisp_Object id_key; |
| 9791 | static const EventParamName names[] = | 10684 | int num_params; |
| 9792 | {kEventParamDirectObject, kEventParamKeyModifiers}; | 10685 | const EventParamName *names; |
| 9793 | static const EventParamType types[] = | 10686 | const EventParamType *types; |
| 9794 | {typeHICommand, typeUInt32}; | 10687 | static const EventParamName names_pfm[] = |
| 9795 | int num_params = sizeof (names) / sizeof (names[0]); | 10688 | {kEventParamServiceMessageName, kEventParamServiceUserData}; |
| 9796 | 10689 | static const EventParamType types_pfm[] = | |
| 9797 | result = CallNextEventHandler (next_handler, event); | 10690 | {typeCFStringRef, typeCFStringRef}; |
| 9798 | if (result != eventNotHandledErr) | ||
| 9799 | return result; | ||
| 9800 | 10691 | ||
| 9801 | err = GetEventParameter (event, kEventParamDirectObject, typeHICommand, | 10692 | switch (GetEventKind (event)) |
| 9802 | NULL, sizeof (HICommand), NULL, &command); | 10693 | { |
| 10694 | case kEventServicePaste: | ||
| 10695 | id_key = Qpaste; | ||
| 10696 | num_params = 0; | ||
| 10697 | names = NULL; | ||
| 10698 | types = NULL; | ||
| 10699 | break; | ||
| 9803 | 10700 | ||
| 9804 | if (err != noErr || command.commandID == 0) | 10701 | case kEventServicePerform: |
| 9805 | return eventNotHandledErr; | 10702 | id_key = Qperform; |
| 10703 | num_params = sizeof (names_pfm) / sizeof (names_pfm[0]); | ||
| 10704 | names = names_pfm; | ||
| 10705 | types = types_pfm; | ||
| 10706 | break; | ||
| 9806 | 10707 | ||
| 9807 | /* A HI command event is mapped to an Apple event whose event class | 10708 | default: |
| 9808 | symbol is `hi-command' and event ID is its command ID. */ | 10709 | abort (); |
| 9809 | err = mac_store_event_ref_as_apple_event (0, command.commandID, | 10710 | } |
| 9810 | Qhi_command, Qnil, | ||
| 9811 | event, num_params, names, types); | ||
| 9812 | return err == noErr ? noErr : eventNotHandledErr; | ||
| 9813 | } | ||
| 9814 | 10711 | ||
| 9815 | static OSStatus | 10712 | err = mac_store_event_ref_as_apple_event (0, 0, Qservice, id_key, |
| 9816 | init_command_handler () | 10713 | event, num_params, |
| 9817 | { | 10714 | names, types); |
| 9818 | static const EventTypeSpec specs[] = | ||
| 9819 | {{kEventClassCommand, kEventCommandProcess}}; | ||
| 9820 | static EventHandlerUPP handle_command_eventUPP = NULL; | ||
| 9821 | 10715 | ||
| 9822 | if (handle_command_eventUPP == NULL) | 10716 | return err; |
| 9823 | handle_command_eventUPP = NewEventHandlerUPP (mac_handle_command_event); | ||
| 9824 | return InstallApplicationEventHandler (handle_command_eventUPP, | ||
| 9825 | GetEventTypeCount (specs), specs, | ||
| 9826 | NULL, NULL); | ||
| 9827 | } | 10717 | } |
| 10718 | #endif /* MAC_OSX */ | ||
| 9828 | 10719 | ||
| 9829 | static pascal OSStatus | 10720 | static pascal OSStatus |
| 9830 | mac_handle_window_event (next_handler, event, data) | 10721 | mac_handle_window_event (next_handler, event, data) |
| @@ -9832,47 +10723,88 @@ mac_handle_window_event (next_handler, event, data) | |||
| 9832 | EventRef event; | 10723 | EventRef event; |
| 9833 | void *data; | 10724 | void *data; |
| 9834 | { | 10725 | { |
| 9835 | WindowPtr wp; | 10726 | WindowRef wp; |
| 9836 | OSStatus result, err; | 10727 | OSStatus err, result = eventNotHandledErr; |
| 9837 | struct frame *f; | 10728 | struct frame *f; |
| 9838 | UInt32 attributes; | 10729 | UInt32 attributes; |
| 9839 | XSizeHints *size_hints; | 10730 | XSizeHints *size_hints; |
| 9840 | 10731 | ||
| 9841 | err = GetEventParameter (event, kEventParamDirectObject, typeWindowRef, | 10732 | err = GetEventParameter (event, kEventParamDirectObject, typeWindowRef, |
| 9842 | NULL, sizeof (WindowPtr), NULL, &wp); | 10733 | NULL, sizeof (WindowRef), NULL, &wp); |
| 9843 | if (err != noErr) | 10734 | if (err != noErr) |
| 9844 | return eventNotHandledErr; | 10735 | return eventNotHandledErr; |
| 9845 | 10736 | ||
| 9846 | f = mac_window_to_frame (wp); | 10737 | f = mac_window_to_frame (wp); |
| 9847 | switch (GetEventKind (event)) | 10738 | switch (GetEventKind (event)) |
| 9848 | { | 10739 | { |
| 10740 | /* -- window refresh events -- */ | ||
| 10741 | |||
| 9849 | case kEventWindowUpdate: | 10742 | case kEventWindowUpdate: |
| 9850 | result = CallNextEventHandler (next_handler, event); | 10743 | result = CallNextEventHandler (next_handler, event); |
| 9851 | if (result != eventNotHandledErr) | 10744 | if (result != eventNotHandledErr) |
| 9852 | return result; | 10745 | break; |
| 9853 | 10746 | ||
| 9854 | do_window_update (wp); | 10747 | do_window_update (wp); |
| 9855 | return noErr; | 10748 | result = noErr; |
| 10749 | break; | ||
| 9856 | 10750 | ||
| 9857 | case kEventWindowGetIdealSize: | 10751 | /* -- window state change events -- */ |
| 9858 | result = CallNextEventHandler (next_handler, event); | ||
| 9859 | if (result != eventNotHandledErr) | ||
| 9860 | return result; | ||
| 9861 | 10752 | ||
| 9862 | { | 10753 | case kEventWindowShowing: |
| 9863 | Point ideal_size = mac_get_ideal_size (f); | 10754 | size_hints = FRAME_SIZE_HINTS (f); |
| 10755 | if (!(size_hints->flags & (USPosition | PPosition))) | ||
| 10756 | { | ||
| 10757 | struct frame *sf = SELECTED_FRAME (); | ||
| 9864 | 10758 | ||
| 9865 | err = SetEventParameter (event, kEventParamDimensions, | 10759 | if (!(FRAME_MAC_P (sf) && sf->async_visible)) |
| 9866 | typeQDPoint, sizeof (Point), &ideal_size); | 10760 | RepositionWindow (wp, NULL, kWindowCenterOnMainScreen); |
| 9867 | if (err == noErr) | 10761 | else |
| 9868 | return noErr; | 10762 | { |
| 9869 | } | 10763 | RepositionWindow (wp, FRAME_MAC_WINDOW (sf), |
| 10764 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | ||
| 10765 | kWindowCascadeStartAtParentWindowScreen | ||
| 10766 | #else | ||
| 10767 | kWindowCascadeOnParentWindowScreen | ||
| 10768 | #endif | ||
| 10769 | ); | ||
| 10770 | #if USE_MAC_TOOLBAR | ||
| 10771 | /* This is a workaround. RepositionWindow fails to put | ||
| 10772 | a window at the cascading position when its parent | ||
| 10773 | window has a Carbon HIToolbar. */ | ||
| 10774 | if ((f->left_pos == sf->left_pos | ||
| 10775 | && f->top_pos == sf->top_pos) | ||
| 10776 | || (f->left_pos == sf->left_pos + 10 * 2 | ||
| 10777 | && f->top_pos == sf->top_pos + 32 * 2)) | ||
| 10778 | MoveWindowStructure (wp, sf->left_pos + 10, sf->top_pos + 32); | ||
| 10779 | #endif | ||
| 10780 | } | ||
| 10781 | result = noErr; | ||
| 10782 | } | ||
| 10783 | break; | ||
| 10784 | |||
| 10785 | case kEventWindowHiding: | ||
| 10786 | /* Before unmapping the window, update the WM_SIZE_HINTS | ||
| 10787 | property to claim that the current position of the window is | ||
| 10788 | user-specified, rather than program-specified, so that when | ||
| 10789 | the window is mapped again, it will be placed at the same | ||
| 10790 | location, without forcing the user to position it by hand | ||
| 10791 | again (they have already done that once for this window.) */ | ||
| 10792 | x_wm_set_size_hint (f, (long) 0, 1); | ||
| 10793 | result = noErr; | ||
| 10794 | break; | ||
| 10795 | |||
| 10796 | case kEventWindowShown: | ||
| 10797 | case kEventWindowHidden: | ||
| 10798 | case kEventWindowCollapsed: | ||
| 10799 | case kEventWindowExpanded: | ||
| 10800 | mac_handle_visibility_change (f); | ||
| 10801 | result = noErr; | ||
| 9870 | break; | 10802 | break; |
| 9871 | 10803 | ||
| 9872 | case kEventWindowBoundsChanging: | 10804 | case kEventWindowBoundsChanging: |
| 9873 | result = CallNextEventHandler (next_handler, event); | 10805 | result = CallNextEventHandler (next_handler, event); |
| 9874 | if (result != eventNotHandledErr) | 10806 | if (result != eventNotHandledErr) |
| 9875 | return result; | 10807 | break; |
| 9876 | 10808 | ||
| 9877 | err = GetEventParameter (event, kEventParamAttributes, typeUInt32, | 10809 | err = GetEventParameter (event, kEventParamAttributes, typeUInt32, |
| 9878 | NULL, sizeof (UInt32), NULL, &attributes); | 10810 | NULL, sizeof (UInt32), NULL, &attributes); |
| @@ -9916,7 +10848,7 @@ mac_handle_window_event (next_handler, event, data) | |||
| 9916 | bounds.bottom = bounds.top + height; | 10848 | bounds.bottom = bounds.top + height; |
| 9917 | SetEventParameter (event, kEventParamCurrentBounds, | 10849 | SetEventParameter (event, kEventParamCurrentBounds, |
| 9918 | typeQDRectangle, sizeof (Rect), &bounds); | 10850 | typeQDRectangle, sizeof (Rect), &bounds); |
| 9919 | return noErr; | 10851 | result = noErr; |
| 9920 | } | 10852 | } |
| 9921 | break; | 10853 | break; |
| 9922 | 10854 | ||
| @@ -9947,21 +10879,12 @@ mac_handle_window_event (next_handler, event, data) | |||
| 9947 | if (attributes & kWindowBoundsChangeOriginChanged) | 10879 | if (attributes & kWindowBoundsChangeOriginChanged) |
| 9948 | mac_handle_origin_change (f); | 10880 | mac_handle_origin_change (f); |
| 9949 | 10881 | ||
| 9950 | return noErr; | 10882 | result = noErr; |
| 9951 | |||
| 9952 | case kEventWindowShown: | ||
| 9953 | case kEventWindowHidden: | ||
| 9954 | case kEventWindowExpanded: | ||
| 9955 | case kEventWindowCollapsed: | ||
| 9956 | result = CallNextEventHandler (next_handler, event); | ||
| 9957 | |||
| 9958 | mac_handle_visibility_change (f); | ||
| 9959 | return noErr; | ||
| 9960 | |||
| 9961 | break; | 10883 | break; |
| 9962 | 10884 | ||
| 10885 | /* -- window action events -- */ | ||
| 10886 | |||
| 9963 | case kEventWindowClose: | 10887 | case kEventWindowClose: |
| 9964 | result = CallNextEventHandler (next_handler, event); | ||
| 9965 | { | 10888 | { |
| 9966 | struct input_event buf; | 10889 | struct input_event buf; |
| 9967 | 10890 | ||
| @@ -9971,11 +10894,26 @@ mac_handle_window_event (next_handler, event, data) | |||
| 9971 | buf.arg = Qnil; | 10894 | buf.arg = Qnil; |
| 9972 | kbd_buffer_store_event (&buf); | 10895 | kbd_buffer_store_event (&buf); |
| 9973 | } | 10896 | } |
| 9974 | return noErr; | 10897 | result = noErr; |
| 10898 | break; | ||
| 10899 | |||
| 10900 | case kEventWindowGetIdealSize: | ||
| 10901 | result = CallNextEventHandler (next_handler, event); | ||
| 10902 | if (result != eventNotHandledErr) | ||
| 10903 | break; | ||
| 10904 | |||
| 10905 | { | ||
| 10906 | Point ideal_size = mac_get_ideal_size (f); | ||
| 10907 | |||
| 10908 | err = SetEventParameter (event, kEventParamDimensions, | ||
| 10909 | typeQDPoint, sizeof (Point), &ideal_size); | ||
| 10910 | if (err == noErr) | ||
| 10911 | result = noErr; | ||
| 10912 | } | ||
| 10913 | break; | ||
| 9975 | 10914 | ||
| 9976 | #ifdef MAC_OSX | 10915 | #ifdef MAC_OSX |
| 9977 | case kEventWindowToolbarSwitchMode: | 10916 | case kEventWindowToolbarSwitchMode: |
| 9978 | result = CallNextEventHandler (next_handler, event); | ||
| 9979 | { | 10917 | { |
| 9980 | static const EventParamName names[] = {kEventParamDirectObject, | 10918 | static const EventParamName names[] = {kEventParamDirectObject, |
| 9981 | kEventParamWindowMouseLocation, | 10919 | kEventParamWindowMouseLocation, |
| @@ -9997,23 +10935,154 @@ mac_handle_window_event (next_handler, event, data) | |||
| 9997 | event, num_params, | 10935 | event, num_params, |
| 9998 | names, types); | 10936 | names, types); |
| 9999 | } | 10937 | } |
| 10000 | return err == noErr ? noErr : result; | 10938 | if (err == noErr) |
| 10939 | result = noErr; | ||
| 10940 | break; | ||
| 10001 | #endif | 10941 | #endif |
| 10002 | 10942 | ||
| 10003 | #if USE_MAC_TSM | 10943 | #if USE_MAC_TSM |
| 10944 | /* -- window focus events -- */ | ||
| 10945 | |||
| 10004 | case kEventWindowFocusAcquired: | 10946 | case kEventWindowFocusAcquired: |
| 10005 | result = CallNextEventHandler (next_handler, event); | ||
| 10006 | err = mac_tsm_resume (); | 10947 | err = mac_tsm_resume (); |
| 10007 | return err == noErr ? noErr : result; | 10948 | if (err == noErr) |
| 10949 | result = noErr; | ||
| 10950 | break; | ||
| 10008 | 10951 | ||
| 10009 | case kEventWindowFocusRelinquish: | 10952 | case kEventWindowFocusRelinquish: |
| 10010 | result = CallNextEventHandler (next_handler, event); | ||
| 10011 | err = mac_tsm_suspend (); | 10953 | err = mac_tsm_suspend (); |
| 10012 | return err == noErr ? noErr : result; | 10954 | if (err == noErr) |
| 10955 | result = noErr; | ||
| 10956 | break; | ||
| 10013 | #endif | 10957 | #endif |
| 10958 | |||
| 10959 | default: | ||
| 10960 | abort (); | ||
| 10014 | } | 10961 | } |
| 10015 | 10962 | ||
| 10016 | return eventNotHandledErr; | 10963 | return result; |
| 10964 | } | ||
| 10965 | |||
| 10966 | static pascal OSStatus | ||
| 10967 | mac_handle_keyboard_event (next_handler, event, data) | ||
| 10968 | EventHandlerCallRef next_handler; | ||
| 10969 | EventRef event; | ||
| 10970 | void *data; | ||
| 10971 | { | ||
| 10972 | OSStatus err, result = eventNotHandledErr; | ||
| 10973 | UInt32 event_kind, key_code, modifiers; | ||
| 10974 | unsigned char char_code; | ||
| 10975 | |||
| 10976 | event_kind = GetEventKind (event); | ||
| 10977 | switch (event_kind) | ||
| 10978 | { | ||
| 10979 | case kEventRawKeyDown: | ||
| 10980 | case kEventRawKeyRepeat: | ||
| 10981 | case kEventRawKeyUp: | ||
| 10982 | /* When using Carbon Events, we need to pass raw keyboard events | ||
| 10983 | to the TSM ourselves. If TSM handles it, it will pass back | ||
| 10984 | noErr, otherwise it will pass back "eventNotHandledErr" and | ||
| 10985 | we can process it normally. */ | ||
| 10986 | result = CallNextEventHandler (next_handler, event); | ||
| 10987 | if (result != eventNotHandledErr) | ||
| 10988 | break; | ||
| 10989 | |||
| 10990 | if (read_socket_inev == NULL) | ||
| 10991 | break; | ||
| 10992 | |||
| 10993 | #if USE_MAC_TSM | ||
| 10994 | if (read_socket_inev->kind != NO_EVENT) | ||
| 10995 | { | ||
| 10996 | result = noErr; | ||
| 10997 | break; | ||
| 10998 | } | ||
| 10999 | #endif | ||
| 11000 | |||
| 11001 | if (event_kind == kEventRawKeyUp) | ||
| 11002 | break; | ||
| 11003 | |||
| 11004 | err = GetEventParameter (event, kEventParamKeyMacCharCodes, | ||
| 11005 | typeChar, NULL, | ||
| 11006 | sizeof (char), NULL, &char_code); | ||
| 11007 | if (err != noErr) | ||
| 11008 | break; | ||
| 11009 | |||
| 11010 | err = GetEventParameter (event, kEventParamKeyCode, | ||
| 11011 | typeUInt32, NULL, | ||
| 11012 | sizeof (UInt32), NULL, &key_code); | ||
| 11013 | if (err != noErr) | ||
| 11014 | break; | ||
| 11015 | |||
| 11016 | err = GetEventParameter (event, kEventParamKeyModifiers, | ||
| 11017 | typeUInt32, NULL, | ||
| 11018 | sizeof (UInt32), NULL, &modifiers); | ||
| 11019 | if (err != noErr) | ||
| 11020 | break; | ||
| 11021 | |||
| 11022 | do_keystroke ((event_kind == kEventRawKeyDown ? keyDown : autoKey), | ||
| 11023 | char_code, key_code, modifiers, | ||
| 11024 | ((unsigned long) | ||
| 11025 | (GetEventTime (event) / kEventDurationMillisecond)), | ||
| 11026 | read_socket_inev); | ||
| 11027 | result = noErr; | ||
| 11028 | break; | ||
| 11029 | |||
| 11030 | default: | ||
| 11031 | abort (); | ||
| 11032 | } | ||
| 11033 | |||
| 11034 | return result; | ||
| 11035 | } | ||
| 11036 | |||
| 11037 | static pascal OSStatus | ||
| 11038 | mac_handle_command_event (next_handler, event, data) | ||
| 11039 | EventHandlerCallRef next_handler; | ||
| 11040 | EventRef event; | ||
| 11041 | void *data; | ||
| 11042 | { | ||
| 11043 | OSStatus err, result = eventNotHandledErr; | ||
| 11044 | HICommand command; | ||
| 11045 | static const EventParamName names[] = | ||
| 11046 | {kEventParamDirectObject, kEventParamKeyModifiers}; | ||
| 11047 | static const EventParamType types[] = | ||
| 11048 | {typeHICommand, typeUInt32}; | ||
| 11049 | int num_params = sizeof (names) / sizeof (names[0]); | ||
| 11050 | |||
| 11051 | err = GetEventParameter (event, kEventParamDirectObject, typeHICommand, | ||
| 11052 | NULL, sizeof (HICommand), NULL, &command); | ||
| 11053 | if (err != noErr) | ||
| 11054 | return eventNotHandledErr; | ||
| 11055 | |||
| 11056 | switch (GetEventKind (event)) | ||
| 11057 | { | ||
| 11058 | case kEventCommandProcess: | ||
| 11059 | result = CallNextEventHandler (next_handler, event); | ||
| 11060 | if (result != eventNotHandledErr) | ||
| 11061 | break; | ||
| 11062 | |||
| 11063 | err = GetEventParameter (event, kEventParamDirectObject, | ||
| 11064 | typeHICommand, NULL, | ||
| 11065 | sizeof (HICommand), NULL, &command); | ||
| 11066 | |||
| 11067 | if (err != noErr || command.commandID == 0) | ||
| 11068 | break; | ||
| 11069 | |||
| 11070 | /* A HI command event is mapped to an Apple event whose event | ||
| 11071 | class symbol is `hi-command' and event ID is its command | ||
| 11072 | ID. */ | ||
| 11073 | err = mac_store_event_ref_as_apple_event (0, command.commandID, | ||
| 11074 | Qhi_command, Qnil, | ||
| 11075 | event, num_params, | ||
| 11076 | names, types); | ||
| 11077 | if (err == noErr) | ||
| 11078 | result = noErr; | ||
| 11079 | break; | ||
| 11080 | |||
| 11081 | default: | ||
| 11082 | abort (); | ||
| 11083 | } | ||
| 11084 | |||
| 11085 | return result; | ||
| 10017 | } | 11086 | } |
| 10018 | 11087 | ||
| 10019 | static pascal OSStatus | 11088 | static pascal OSStatus |
| @@ -10022,13 +11091,13 @@ mac_handle_mouse_event (next_handler, event, data) | |||
| 10022 | EventRef event; | 11091 | EventRef event; |
| 10023 | void *data; | 11092 | void *data; |
| 10024 | { | 11093 | { |
| 10025 | OSStatus result, err; | 11094 | OSStatus err, result = eventNotHandledErr; |
| 10026 | 11095 | ||
| 10027 | switch (GetEventKind (event)) | 11096 | switch (GetEventKind (event)) |
| 10028 | { | 11097 | { |
| 10029 | case kEventMouseWheelMoved: | 11098 | case kEventMouseWheelMoved: |
| 10030 | { | 11099 | { |
| 10031 | WindowPtr wp; | 11100 | WindowRef wp; |
| 10032 | struct frame *f; | 11101 | struct frame *f; |
| 10033 | EventMouseWheelAxis axis; | 11102 | EventMouseWheelAxis axis; |
| 10034 | SInt32 delta; | 11103 | SInt32 delta; |
| @@ -10036,15 +11105,14 @@ mac_handle_mouse_event (next_handler, event, data) | |||
| 10036 | 11105 | ||
| 10037 | result = CallNextEventHandler (next_handler, event); | 11106 | result = CallNextEventHandler (next_handler, event); |
| 10038 | if (result != eventNotHandledErr || read_socket_inev == NULL) | 11107 | if (result != eventNotHandledErr || read_socket_inev == NULL) |
| 10039 | return result; | 11108 | break; |
| 11109 | |||
| 11110 | f = mac_focus_frame (&one_mac_display_info); | ||
| 10040 | 11111 | ||
| 10041 | err = GetEventParameter (event, kEventParamWindowRef, typeWindowRef, | 11112 | err = GetEventParameter (event, kEventParamWindowRef, typeWindowRef, |
| 10042 | NULL, sizeof (WindowRef), NULL, &wp); | 11113 | NULL, sizeof (WindowRef), NULL, &wp); |
| 10043 | if (err != noErr) | 11114 | if (err != noErr |
| 10044 | break; | 11115 | || wp != FRAME_MAC_WINDOW (f)) |
| 10045 | |||
| 10046 | f = mac_window_to_frame (wp); | ||
| 10047 | if (f != mac_focus_frame (&one_mac_display_info)) | ||
| 10048 | break; | 11116 | break; |
| 10049 | 11117 | ||
| 10050 | err = GetEventParameter (event, kEventParamMouseWheelAxis, | 11118 | err = GetEventParameter (event, kEventParamMouseWheelAxis, |
| @@ -10059,8 +11127,8 @@ mac_handle_mouse_event (next_handler, event, data) | |||
| 10059 | if (err != noErr) | 11127 | if (err != noErr) |
| 10060 | break; | 11128 | break; |
| 10061 | 11129 | ||
| 10062 | SetPortWindowPort (wp); | 11130 | point.h -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); |
| 10063 | GlobalToLocal (&point); | 11131 | point.v -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); |
| 10064 | if (point.h < 0 || point.v < 0 | 11132 | if (point.h < 0 || point.v < 0 |
| 10065 | || EQ (window_from_coordinates (f, point.h, point.v, 0, 0, 0, 1), | 11133 | || EQ (window_from_coordinates (f, point.h, point.v, 0, 0, 0, 1), |
| 10066 | f->tool_bar_window)) | 11134 | f->tool_bar_window)) |
| @@ -10081,68 +11149,16 @@ mac_handle_mouse_event (next_handler, event, data) | |||
| 10081 | XSETINT (read_socket_inev->y, point.v); | 11149 | XSETINT (read_socket_inev->y, point.v); |
| 10082 | XSETFRAME (read_socket_inev->frame_or_window, f); | 11150 | XSETFRAME (read_socket_inev->frame_or_window, f); |
| 10083 | 11151 | ||
| 10084 | return noErr; | 11152 | result = noErr; |
| 10085 | } | 11153 | } |
| 10086 | break; | 11154 | break; |
| 10087 | 11155 | ||
| 10088 | default: | 11156 | default: |
| 10089 | break; | 11157 | abort (); |
| 10090 | } | ||
| 10091 | |||
| 10092 | return eventNotHandledErr; | ||
| 10093 | } | ||
| 10094 | |||
| 10095 | #if USE_MAC_FONT_PANEL | ||
| 10096 | static pascal OSStatus | ||
| 10097 | mac_handle_font_event (next_handler, event, data) | ||
| 10098 | EventHandlerCallRef next_handler; | ||
| 10099 | EventRef event; | ||
| 10100 | void *data; | ||
| 10101 | { | ||
| 10102 | OSStatus result, err; | ||
| 10103 | Lisp_Object id_key; | ||
| 10104 | int num_params; | ||
| 10105 | const EventParamName *names; | ||
| 10106 | const EventParamType *types; | ||
| 10107 | static const EventParamName names_sel[] = {kEventParamATSUFontID, | ||
| 10108 | kEventParamATSUFontSize, | ||
| 10109 | kEventParamFMFontFamily, | ||
| 10110 | kEventParamFMFontSize, | ||
| 10111 | kEventParamFontColor}; | ||
| 10112 | static const EventParamType types_sel[] = {typeATSUFontID, | ||
| 10113 | typeATSUSize, | ||
| 10114 | typeFMFontFamily, | ||
| 10115 | typeFMFontSize, | ||
| 10116 | typeFontColor}; | ||
| 10117 | |||
| 10118 | result = CallNextEventHandler (next_handler, event); | ||
| 10119 | if (result != eventNotHandledErr) | ||
| 10120 | return result; | ||
| 10121 | |||
| 10122 | switch (GetEventKind (event)) | ||
| 10123 | { | ||
| 10124 | case kEventFontPanelClosed: | ||
| 10125 | id_key = Qpanel_closed; | ||
| 10126 | num_params = 0; | ||
| 10127 | names = NULL; | ||
| 10128 | types = NULL; | ||
| 10129 | break; | ||
| 10130 | |||
| 10131 | case kEventFontSelection: | ||
| 10132 | id_key = Qselection; | ||
| 10133 | num_params = sizeof (names_sel) / sizeof (names_sel[0]); | ||
| 10134 | names = names_sel; | ||
| 10135 | types = types_sel; | ||
| 10136 | break; | ||
| 10137 | } | 11158 | } |
| 10138 | 11159 | ||
| 10139 | err = mac_store_event_ref_as_apple_event (0, 0, Qfont, id_key, | 11160 | return result; |
| 10140 | event, num_params, | ||
| 10141 | names, types); | ||
| 10142 | |||
| 10143 | return err == noErr ? noErr : eventNotHandledErr; | ||
| 10144 | } | 11161 | } |
| 10145 | #endif | ||
| 10146 | 11162 | ||
| 10147 | #if USE_MAC_TSM | 11163 | #if USE_MAC_TSM |
| 10148 | static pascal OSStatus | 11164 | static pascal OSStatus |
| @@ -10151,7 +11167,7 @@ mac_handle_text_input_event (next_handler, event, data) | |||
| 10151 | EventRef event; | 11167 | EventRef event; |
| 10152 | void *data; | 11168 | void *data; |
| 10153 | { | 11169 | { |
| 10154 | OSStatus result, err = noErr; | 11170 | OSStatus err, result; |
| 10155 | Lisp_Object id_key = Qnil; | 11171 | Lisp_Object id_key = Qnil; |
| 10156 | int num_params; | 11172 | int num_params; |
| 10157 | const EventParamName *names; | 11173 | const EventParamName *names; |
| @@ -10199,6 +11215,8 @@ mac_handle_text_input_event (next_handler, event, data) | |||
| 10199 | typeUnicodeText}; | 11215 | typeUnicodeText}; |
| 10200 | 11216 | ||
| 10201 | result = CallNextEventHandler (next_handler, event); | 11217 | result = CallNextEventHandler (next_handler, event); |
| 11218 | if (result != eventNotHandledErr) | ||
| 11219 | return result; | ||
| 10202 | 11220 | ||
| 10203 | switch (GetEventKind (event)) | 11221 | switch (GetEventKind (event)) |
| 10204 | { | 11222 | { |
| @@ -10210,6 +11228,7 @@ mac_handle_text_input_event (next_handler, event, data) | |||
| 10210 | SetEventParameter (event, EVENT_PARAM_TEXT_INPUT_SEQUENCE_NUMBER, | 11228 | SetEventParameter (event, EVENT_PARAM_TEXT_INPUT_SEQUENCE_NUMBER, |
| 10211 | typeUInt32, sizeof (UInt32), &seqno_uaia); | 11229 | typeUInt32, sizeof (UInt32), &seqno_uaia); |
| 10212 | seqno_uaia++; | 11230 | seqno_uaia++; |
| 11231 | result = noErr; | ||
| 10213 | break; | 11232 | break; |
| 10214 | 11233 | ||
| 10215 | case kEventTextInputUnicodeForKeyEvent: | 11234 | case kEventTextInputUnicodeForKeyEvent: |
| @@ -10230,8 +11249,8 @@ mac_handle_text_input_event (next_handler, event, data) | |||
| 10230 | NULL, &key_code); | 11249 | NULL, &key_code); |
| 10231 | if (err == noErr && mac_mapped_modifiers (modifiers, key_code)) | 11250 | if (err == noErr && mac_mapped_modifiers (modifiers, key_code)) |
| 10232 | /* There're mapped modifier keys. Process it in | 11251 | /* There're mapped modifier keys. Process it in |
| 10233 | XTread_socket. */ | 11252 | do_keystroke. */ |
| 10234 | return eventNotHandledErr; | 11253 | break; |
| 10235 | if (err == noErr) | 11254 | if (err == noErr) |
| 10236 | err = GetEventParameter (kbd_event, kEventParamKeyUnicodes, | 11255 | err = GetEventParameter (kbd_event, kEventParamKeyUnicodes, |
| 10237 | typeUnicodeText, NULL, 0, &actual_size, | 11256 | typeUnicodeText, NULL, 0, &actual_size, |
| @@ -10245,7 +11264,7 @@ mac_handle_text_input_event (next_handler, event, data) | |||
| 10245 | sizeof (UniChar), NULL, &code); | 11264 | sizeof (UniChar), NULL, &code); |
| 10246 | if (err == noErr && code < 0x80) | 11265 | if (err == noErr && code < 0x80) |
| 10247 | { | 11266 | { |
| 10248 | /* ASCII character. Process it in XTread_socket. */ | 11267 | /* ASCII character. Process it in do_keystroke. */ |
| 10249 | if (read_socket_inev && code >= 0x20 && code <= 0x7e | 11268 | if (read_socket_inev && code >= 0x20 && code <= 0x7e |
| 10250 | && !(key_code <= 0x7f | 11269 | && !(key_code <= 0x7f |
| 10251 | && keycode_to_xkeysym_table [key_code])) | 11270 | && keycode_to_xkeysym_table [key_code])) |
| @@ -10262,16 +11281,20 @@ mac_handle_text_input_event (next_handler, event, data) | |||
| 10262 | | hyper_modifier | super_modifier)); | 11281 | | hyper_modifier | super_modifier)); |
| 10263 | XSETFRAME (read_socket_inev->frame_or_window, f); | 11282 | XSETFRAME (read_socket_inev->frame_or_window, f); |
| 10264 | } | 11283 | } |
| 10265 | return eventNotHandledErr; | 11284 | break; |
| 10266 | } | 11285 | } |
| 10267 | } | 11286 | } |
| 11287 | if (err == noErr) | ||
| 11288 | { | ||
| 11289 | /* Non-ASCII keystrokes without mapped modifiers are | ||
| 11290 | processed at the Lisp level. */ | ||
| 11291 | id_key = Qunicode_for_key_event; | ||
| 11292 | num_params = sizeof (names_ufke) / sizeof (names_ufke[0]); | ||
| 11293 | names = names_ufke; | ||
| 11294 | types = types_ufke; | ||
| 11295 | result = noErr; | ||
| 11296 | } | ||
| 10268 | } | 11297 | } |
| 10269 | /* Non-ASCII keystrokes without mapped modifiers are processed | ||
| 10270 | at the Lisp level. */ | ||
| 10271 | id_key = Qunicode_for_key_event; | ||
| 10272 | num_params = sizeof (names_ufke) / sizeof (names_ufke[0]); | ||
| 10273 | names = names_ufke; | ||
| 10274 | types = types_ufke; | ||
| 10275 | break; | 11298 | break; |
| 10276 | 11299 | ||
| 10277 | case kEventTextInputOffsetToPos: | 11300 | case kEventTextInputOffsetToPos: |
| @@ -10281,34 +11304,35 @@ mac_handle_text_input_event (next_handler, event, data) | |||
| 10281 | Point p; | 11304 | Point p; |
| 10282 | 11305 | ||
| 10283 | if (!OVERLAYP (Vmac_ts_active_input_overlay)) | 11306 | if (!OVERLAYP (Vmac_ts_active_input_overlay)) |
| 10284 | return eventNotHandledErr; | 11307 | break; |
| 10285 | 11308 | ||
| 10286 | /* Strictly speaking, this is not always correct because | 11309 | /* Strictly speaking, this is not always correct because |
| 10287 | previous events may change some states about display. */ | 11310 | previous events may change some states about display. */ |
| 10288 | if (NILP (Foverlay_get (Vmac_ts_active_input_overlay, Qbefore_string))) | 11311 | if (!NILP (Foverlay_get (Vmac_ts_active_input_overlay, Qbefore_string))) |
| 11312 | { | ||
| 11313 | /* Active input area is displayed around the current point. */ | ||
| 11314 | f = SELECTED_FRAME (); | ||
| 11315 | w = XWINDOW (f->selected_window); | ||
| 11316 | } | ||
| 11317 | else if (WINDOWP (echo_area_window)) | ||
| 10289 | { | 11318 | { |
| 10290 | if (!WINDOWP (echo_area_window)) | ||
| 10291 | return eventNotHandledErr; | ||
| 10292 | |||
| 10293 | /* Active input area is displayed in the echo area. */ | 11319 | /* Active input area is displayed in the echo area. */ |
| 10294 | w = XWINDOW (echo_area_window); | 11320 | w = XWINDOW (echo_area_window); |
| 10295 | f = WINDOW_XFRAME (w); | 11321 | f = WINDOW_XFRAME (w); |
| 10296 | } | 11322 | } |
| 10297 | else | 11323 | else |
| 10298 | { | 11324 | break; |
| 10299 | /* Active input area is displayed around the current point. */ | ||
| 10300 | f = SELECTED_FRAME (); | ||
| 10301 | w = XWINDOW (f->selected_window); | ||
| 10302 | } | ||
| 10303 | 11325 | ||
| 10304 | p.h = (WINDOW_TO_FRAME_PIXEL_X (w, w->cursor.x) | 11326 | p.h = (WINDOW_TO_FRAME_PIXEL_X (w, w->cursor.x) |
| 10305 | + WINDOW_LEFT_FRINGE_WIDTH (w)); | 11327 | + WINDOW_LEFT_FRINGE_WIDTH (w) |
| 11328 | + f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f)); | ||
| 10306 | p.v = (WINDOW_TO_FRAME_PIXEL_Y (w, w->cursor.y) | 11329 | p.v = (WINDOW_TO_FRAME_PIXEL_Y (w, w->cursor.y) |
| 10307 | + FONT_BASE (FRAME_FONT (f))); | 11330 | + FONT_BASE (FRAME_FONT (f)) |
| 10308 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 11331 | + f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f)); |
| 10309 | LocalToGlobal (&p); | ||
| 10310 | err = SetEventParameter (event, kEventParamTextInputReplyPoint, | 11332 | err = SetEventParameter (event, kEventParamTextInputReplyPoint, |
| 10311 | typeQDPoint, sizeof (typeQDPoint), &p); | 11333 | typeQDPoint, sizeof (typeQDPoint), &p); |
| 11334 | if (err == noErr) | ||
| 11335 | result = noErr; | ||
| 10312 | } | 11336 | } |
| 10313 | break; | 11337 | break; |
| 10314 | 11338 | ||
| @@ -10320,146 +11344,137 @@ mac_handle_text_input_event (next_handler, event, data) | |||
| 10320 | err = mac_store_event_ref_as_apple_event (0, 0, Qtext_input, id_key, | 11344 | err = mac_store_event_ref_as_apple_event (0, 0, Qtext_input, id_key, |
| 10321 | event, num_params, | 11345 | event, num_params, |
| 10322 | names, types); | 11346 | names, types); |
| 10323 | 11347 | return result; | |
| 10324 | return err == noErr ? noErr : result; | ||
| 10325 | } | 11348 | } |
| 10326 | #endif | 11349 | #endif |
| 11350 | #endif /* TARGET_API_MAC_CARBON */ | ||
| 11351 | |||
| 10327 | 11352 | ||
| 10328 | #ifdef MAC_OSX | ||
| 10329 | OSStatus | 11353 | OSStatus |
| 10330 | mac_store_service_event (event) | 11354 | install_window_handler (window) |
| 10331 | EventRef event; | 11355 | WindowRef window; |
| 10332 | { | 11356 | { |
| 10333 | OSStatus err; | 11357 | OSStatus err = noErr; |
| 10334 | Lisp_Object id_key; | ||
| 10335 | int num_params; | ||
| 10336 | const EventParamName *names; | ||
| 10337 | const EventParamType *types; | ||
| 10338 | static const EventParamName names_pfm[] = | ||
| 10339 | {kEventParamServiceMessageName, kEventParamServiceUserData}; | ||
| 10340 | static const EventParamType types_pfm[] = | ||
| 10341 | {typeCFStringRef, typeCFStringRef}; | ||
| 10342 | 11358 | ||
| 10343 | switch (GetEventKind (event)) | 11359 | #if TARGET_API_MAC_CARBON |
| 11360 | if (err == noErr) | ||
| 10344 | { | 11361 | { |
| 10345 | case kEventServicePaste: | 11362 | static const EventTypeSpec specs[] = |
| 10346 | id_key = Qpaste; | 11363 | { |
| 10347 | num_params = 0; | 11364 | /* -- window refresh events -- */ |
| 10348 | names = NULL; | 11365 | {kEventClassWindow, kEventWindowUpdate}, |
| 10349 | types = NULL; | 11366 | /* -- window state change events -- */ |
| 10350 | break; | 11367 | {kEventClassWindow, kEventWindowShowing}, |
| 11368 | {kEventClassWindow, kEventWindowHiding}, | ||
| 11369 | {kEventClassWindow, kEventWindowShown}, | ||
| 11370 | {kEventClassWindow, kEventWindowHidden}, | ||
| 11371 | {kEventClassWindow, kEventWindowCollapsed}, | ||
| 11372 | {kEventClassWindow, kEventWindowExpanded}, | ||
| 11373 | {kEventClassWindow, kEventWindowBoundsChanging}, | ||
| 11374 | {kEventClassWindow, kEventWindowBoundsChanged}, | ||
| 11375 | /* -- window action events -- */ | ||
| 11376 | {kEventClassWindow, kEventWindowClose}, | ||
| 11377 | {kEventClassWindow, kEventWindowGetIdealSize}, | ||
| 11378 | #ifdef MAC_OSX | ||
| 11379 | {kEventClassWindow, kEventWindowToolbarSwitchMode}, | ||
| 11380 | #endif | ||
| 11381 | #if USE_MAC_TSM | ||
| 11382 | /* -- window focus events -- */ | ||
| 11383 | {kEventClassWindow, kEventWindowFocusAcquired}, | ||
| 11384 | {kEventClassWindow, kEventWindowFocusRelinquish}, | ||
| 11385 | #endif | ||
| 11386 | }; | ||
| 11387 | static EventHandlerUPP handle_window_eventUPP = NULL; | ||
| 10351 | 11388 | ||
| 10352 | case kEventServicePerform: | 11389 | if (handle_window_eventUPP == NULL) |
| 10353 | id_key = Qperform; | 11390 | handle_window_eventUPP = NewEventHandlerUPP (mac_handle_window_event); |
| 10354 | num_params = sizeof (names_pfm) / sizeof (names_pfm[0]); | ||
| 10355 | names = names_pfm; | ||
| 10356 | types = types_pfm; | ||
| 10357 | break; | ||
| 10358 | 11391 | ||
| 10359 | default: | 11392 | err = InstallWindowEventHandler (window, handle_window_eventUPP, |
| 10360 | abort (); | 11393 | GetEventTypeCount (specs), |
| 11394 | specs, NULL, NULL); | ||
| 10361 | } | 11395 | } |
| 11396 | #endif | ||
| 10362 | 11397 | ||
| 10363 | err = mac_store_event_ref_as_apple_event (0, 0, Qservice, id_key, | 11398 | if (err == noErr) |
| 10364 | event, num_params, | 11399 | err = install_drag_handler (window); |
| 10365 | names, types); | ||
| 10366 | 11400 | ||
| 10367 | return err; | 11401 | return err; |
| 10368 | } | 11402 | } |
| 10369 | #endif /* MAC_OSX */ | ||
| 10370 | #endif /* USE_CARBON_EVENTS */ | ||
| 10371 | 11403 | ||
| 11404 | void | ||
| 11405 | remove_window_handler (window) | ||
| 11406 | WindowRef window; | ||
| 11407 | { | ||
| 11408 | remove_drag_handler (window); | ||
| 11409 | } | ||
| 10372 | 11410 | ||
| 10373 | OSStatus | 11411 | #if TARGET_API_MAC_CARBON |
| 10374 | install_window_handler (window) | 11412 | static OSStatus |
| 10375 | WindowPtr window; | 11413 | install_application_handler () |
| 10376 | { | 11414 | { |
| 10377 | OSStatus err = noErr; | 11415 | OSStatus err = noErr; |
| 10378 | #if USE_CARBON_EVENTS | ||
| 10379 | static const EventTypeSpec specs_window[] = | ||
| 10380 | {{kEventClassWindow, kEventWindowUpdate}, | ||
| 10381 | {kEventClassWindow, kEventWindowGetIdealSize}, | ||
| 10382 | {kEventClassWindow, kEventWindowBoundsChanging}, | ||
| 10383 | {kEventClassWindow, kEventWindowBoundsChanged}, | ||
| 10384 | {kEventClassWindow, kEventWindowShown}, | ||
| 10385 | {kEventClassWindow, kEventWindowHidden}, | ||
| 10386 | {kEventClassWindow, kEventWindowExpanded}, | ||
| 10387 | {kEventClassWindow, kEventWindowCollapsed}, | ||
| 10388 | {kEventClassWindow, kEventWindowClose}, | ||
| 10389 | #ifdef MAC_OSX | ||
| 10390 | {kEventClassWindow, kEventWindowToolbarSwitchMode}, | ||
| 10391 | #endif | ||
| 10392 | #if USE_MAC_TSM | ||
| 10393 | {kEventClassWindow, kEventWindowFocusAcquired}, | ||
| 10394 | {kEventClassWindow, kEventWindowFocusRelinquish}, | ||
| 10395 | #endif | ||
| 10396 | }; | ||
| 10397 | static const EventTypeSpec specs_mouse[] = | ||
| 10398 | {{kEventClassMouse, kEventMouseWheelMoved}}; | ||
| 10399 | static EventHandlerUPP handle_window_eventUPP = NULL; | ||
| 10400 | static EventHandlerUPP handle_mouse_eventUPP = NULL; | ||
| 10401 | #if USE_MAC_FONT_PANEL | ||
| 10402 | static const EventTypeSpec specs_font[] = | ||
| 10403 | {{kEventClassFont, kEventFontPanelClosed}, | ||
| 10404 | {kEventClassFont, kEventFontSelection}}; | ||
| 10405 | static EventHandlerUPP handle_font_eventUPP = NULL; | ||
| 10406 | #endif | ||
| 10407 | #if USE_MAC_TSM | ||
| 10408 | static const EventTypeSpec specs_text_input[] = | ||
| 10409 | {{kEventClassTextInput, kEventTextInputUpdateActiveInputArea}, | ||
| 10410 | {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent}, | ||
| 10411 | {kEventClassTextInput, kEventTextInputOffsetToPos}}; | ||
| 10412 | static EventHandlerUPP handle_text_input_eventUPP = NULL; | ||
| 10413 | #endif | ||
| 10414 | 11416 | ||
| 10415 | if (handle_window_eventUPP == NULL) | ||
| 10416 | handle_window_eventUPP = NewEventHandlerUPP (mac_handle_window_event); | ||
| 10417 | if (handle_mouse_eventUPP == NULL) | ||
| 10418 | handle_mouse_eventUPP = NewEventHandlerUPP (mac_handle_mouse_event); | ||
| 10419 | #if USE_MAC_FONT_PANEL | ||
| 10420 | if (handle_font_eventUPP == NULL) | ||
| 10421 | handle_font_eventUPP = NewEventHandlerUPP (mac_handle_font_event); | ||
| 10422 | #endif | ||
| 10423 | #if USE_MAC_TSM | ||
| 10424 | if (handle_text_input_eventUPP == NULL) | ||
| 10425 | handle_text_input_eventUPP = | ||
| 10426 | NewEventHandlerUPP (mac_handle_text_input_event); | ||
| 10427 | #endif | ||
| 10428 | err = InstallWindowEventHandler (window, handle_window_eventUPP, | ||
| 10429 | GetEventTypeCount (specs_window), | ||
| 10430 | specs_window, NULL, NULL); | ||
| 10431 | if (err == noErr) | 11417 | if (err == noErr) |
| 10432 | err = InstallWindowEventHandler (window, handle_mouse_eventUPP, | 11418 | { |
| 10433 | GetEventTypeCount (specs_mouse), | 11419 | static const EventTypeSpec specs[] = |
| 10434 | specs_mouse, NULL, NULL); | 11420 | {{kEventClassKeyboard, kEventRawKeyDown}, |
| 10435 | #if USE_MAC_FONT_PANEL | 11421 | {kEventClassKeyboard, kEventRawKeyRepeat}, |
| 11422 | {kEventClassKeyboard, kEventRawKeyUp}}; | ||
| 11423 | |||
| 11424 | err = InstallApplicationEventHandler (NewEventHandlerUPP | ||
| 11425 | (mac_handle_keyboard_event), | ||
| 11426 | GetEventTypeCount (specs), | ||
| 11427 | specs, NULL, NULL); | ||
| 11428 | } | ||
| 11429 | |||
| 10436 | if (err == noErr) | 11430 | if (err == noErr) |
| 10437 | err = InstallWindowEventHandler (window, handle_font_eventUPP, | 11431 | { |
| 10438 | GetEventTypeCount (specs_font), | 11432 | static const EventTypeSpec specs[] = |
| 10439 | specs_font, NULL, NULL); | 11433 | {{kEventClassCommand, kEventCommandProcess}}; |
| 10440 | #endif | 11434 | |
| 11435 | err = InstallApplicationEventHandler (NewEventHandlerUPP | ||
| 11436 | (mac_handle_command_event), | ||
| 11437 | GetEventTypeCount (specs), | ||
| 11438 | specs, NULL, NULL); | ||
| 11439 | } | ||
| 11440 | |||
| 11441 | if (err == noErr) | ||
| 11442 | { | ||
| 11443 | static const EventTypeSpec specs[] = | ||
| 11444 | {{kEventClassMouse, kEventMouseWheelMoved}}; | ||
| 11445 | |||
| 11446 | err = InstallApplicationEventHandler (NewEventHandlerUPP | ||
| 11447 | (mac_handle_mouse_event), | ||
| 11448 | GetEventTypeCount (specs), | ||
| 11449 | specs, NULL, NULL); | ||
| 11450 | } | ||
| 11451 | |||
| 10441 | #if USE_MAC_TSM | 11452 | #if USE_MAC_TSM |
| 10442 | if (err == noErr) | 11453 | if (err == noErr) |
| 10443 | err = InstallWindowEventHandler (window, handle_text_input_eventUPP, | 11454 | { |
| 10444 | GetEventTypeCount (specs_text_input), | 11455 | static const EventTypeSpec spec[] = |
| 10445 | specs_text_input, window, NULL); | 11456 | {{kEventClassTextInput, kEventTextInputUpdateActiveInputArea}, |
| 10446 | #endif | 11457 | {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent}, |
| 11458 | {kEventClassTextInput, kEventTextInputOffsetToPos}}; | ||
| 11459 | |||
| 11460 | err = InstallApplicationEventHandler (NewEventHandlerUPP | ||
| 11461 | (mac_handle_text_input_event), | ||
| 11462 | GetEventTypeCount (spec), | ||
| 11463 | spec, NULL, NULL); | ||
| 11464 | } | ||
| 10447 | #endif | 11465 | #endif |
| 11466 | |||
| 10448 | if (err == noErr) | 11467 | if (err == noErr) |
| 10449 | err = install_drag_handler (window); | 11468 | err = install_menu_target_item_handler (); |
| 11469 | |||
| 11470 | #ifdef MAC_OSX | ||
| 10450 | if (err == noErr) | 11471 | if (err == noErr) |
| 10451 | err = install_menu_target_item_handler (window); | 11472 | err = install_service_handler (); |
| 11473 | #endif | ||
| 10452 | 11474 | ||
| 10453 | return err; | 11475 | return err; |
| 10454 | } | 11476 | } |
| 10455 | 11477 | #endif | |
| 10456 | void | ||
| 10457 | remove_window_handler (window) | ||
| 10458 | WindowPtr window; | ||
| 10459 | { | ||
| 10460 | remove_drag_handler (window); | ||
| 10461 | } | ||
| 10462 | |||
| 10463 | 11478 | ||
| 10464 | static pascal void | 11479 | static pascal void |
| 10465 | mac_handle_dm_notification (event) | 11480 | mac_handle_dm_notification (event) |
| @@ -10468,20 +11483,48 @@ mac_handle_dm_notification (event) | |||
| 10468 | mac_screen_config_changed = 1; | 11483 | mac_screen_config_changed = 1; |
| 10469 | } | 11484 | } |
| 10470 | 11485 | ||
| 11486 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 | ||
| 11487 | static void | ||
| 11488 | mac_handle_cg_display_reconfig (display, flags, user_info) | ||
| 11489 | CGDirectDisplayID display; | ||
| 11490 | CGDisplayChangeSummaryFlags flags; | ||
| 11491 | void *user_info; | ||
| 11492 | { | ||
| 11493 | mac_screen_config_changed = 1; | ||
| 11494 | } | ||
| 11495 | #endif | ||
| 11496 | |||
| 10471 | static OSErr | 11497 | static OSErr |
| 10472 | init_dm_notification_handler () | 11498 | init_dm_notification_handler () |
| 10473 | { | 11499 | { |
| 10474 | OSErr err; | 11500 | OSErr err = noErr; |
| 10475 | static DMNotificationUPP handle_dm_notificationUPP = NULL; | 11501 | |
| 10476 | ProcessSerialNumber psn; | 11502 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 |
| 11503 | #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020 | ||
| 11504 | if (CGDisplayRegisterReconfigurationCallback != NULL) | ||
| 11505 | #endif | ||
| 11506 | { | ||
| 11507 | CGDisplayRegisterReconfigurationCallback (mac_handle_cg_display_reconfig, | ||
| 11508 | NULL); | ||
| 11509 | } | ||
| 11510 | #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020 | ||
| 11511 | else /* CGDisplayRegisterReconfigurationCallback == NULL */ | ||
| 11512 | #endif | ||
| 11513 | #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */ | ||
| 11514 | #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020 | ||
| 11515 | { | ||
| 11516 | static DMNotificationUPP handle_dm_notificationUPP = NULL; | ||
| 11517 | ProcessSerialNumber psn; | ||
| 10477 | 11518 | ||
| 10478 | if (handle_dm_notificationUPP == NULL) | 11519 | if (handle_dm_notificationUPP == NULL) |
| 10479 | handle_dm_notificationUPP = | 11520 | handle_dm_notificationUPP = |
| 10480 | NewDMNotificationUPP (mac_handle_dm_notification); | 11521 | NewDMNotificationUPP (mac_handle_dm_notification); |
| 10481 | 11522 | ||
| 10482 | err = GetCurrentProcess (&psn); | 11523 | err = GetCurrentProcess (&psn); |
| 10483 | if (err == noErr) | 11524 | if (err == noErr) |
| 10484 | err = DMRegisterNotifyProc (handle_dm_notificationUPP, &psn); | 11525 | err = DMRegisterNotifyProc (handle_dm_notificationUPP, &psn); |
| 11526 | } | ||
| 11527 | #endif | ||
| 10485 | 11528 | ||
| 10486 | return err; | 11529 | return err; |
| 10487 | } | 11530 | } |
| @@ -10626,7 +11669,7 @@ main (void) | |||
| 10626 | } | 11669 | } |
| 10627 | #endif | 11670 | #endif |
| 10628 | 11671 | ||
| 10629 | #if !USE_CARBON_EVENTS | 11672 | #if !TARGET_API_MAC_CARBON |
| 10630 | static RgnHandle mouse_region = NULL; | 11673 | static RgnHandle mouse_region = NULL; |
| 10631 | 11674 | ||
| 10632 | Boolean | 11675 | Boolean |
| @@ -10663,7 +11706,7 @@ mac_wait_next_event (er, sleep_time, dequeue) | |||
| 10663 | er_buf.what = nullEvent; | 11706 | er_buf.what = nullEvent; |
| 10664 | return true; | 11707 | return true; |
| 10665 | } | 11708 | } |
| 10666 | #endif /* not USE_CARBON_EVENTS */ | 11709 | #endif /* not TARGET_API_MAC_CARBON */ |
| 10667 | 11710 | ||
| 10668 | #if TARGET_API_MAC_CARBON | 11711 | #if TARGET_API_MAC_CARBON |
| 10669 | OSStatus | 11712 | OSStatus |
| @@ -10697,44 +11740,6 @@ mac_post_mouse_moved_event () | |||
| 10697 | 11740 | ||
| 10698 | return err; | 11741 | return err; |
| 10699 | } | 11742 | } |
| 10700 | |||
| 10701 | static void | ||
| 10702 | mac_set_unicode_keystroke_event (code, buf) | ||
| 10703 | UniChar code; | ||
| 10704 | struct input_event *buf; | ||
| 10705 | { | ||
| 10706 | int charset_id, c1, c2; | ||
| 10707 | |||
| 10708 | if (code < 0x80) | ||
| 10709 | { | ||
| 10710 | buf->kind = ASCII_KEYSTROKE_EVENT; | ||
| 10711 | buf->code = code; | ||
| 10712 | } | ||
| 10713 | else if (code < 0x100) | ||
| 10714 | { | ||
| 10715 | if (code < 0xA0) | ||
| 10716 | charset_id = CHARSET_8_BIT_CONTROL; | ||
| 10717 | else | ||
| 10718 | charset_id = charset_latin_iso8859_1; | ||
| 10719 | buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT; | ||
| 10720 | buf->code = MAKE_CHAR (charset_id, code, 0); | ||
| 10721 | } | ||
| 10722 | else | ||
| 10723 | { | ||
| 10724 | if (code < 0x2500) | ||
| 10725 | charset_id = charset_mule_unicode_0100_24ff, | ||
| 10726 | code -= 0x100; | ||
| 10727 | else if (code < 0x33FF) | ||
| 10728 | charset_id = charset_mule_unicode_2500_33ff, | ||
| 10729 | code -= 0x2500; | ||
| 10730 | else if (code >= 0xE000) | ||
| 10731 | charset_id = charset_mule_unicode_e000_ffff, | ||
| 10732 | code -= 0xE000; | ||
| 10733 | c1 = (code / 96) + 32, c2 = (code % 96) + 32; | ||
| 10734 | buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT; | ||
| 10735 | buf->code = MAKE_CHAR (charset_id, c1, c2); | ||
| 10736 | } | ||
| 10737 | } | ||
| 10738 | #endif | 11743 | #endif |
| 10739 | 11744 | ||
| 10740 | /* Emacs calls this whenever it wants to read an input event from the | 11745 | /* Emacs calls this whenever it wants to read an input event from the |
| @@ -10746,7 +11751,7 @@ XTread_socket (sd, expected, hold_quit) | |||
| 10746 | { | 11751 | { |
| 10747 | struct input_event inev; | 11752 | struct input_event inev; |
| 10748 | int count = 0; | 11753 | int count = 0; |
| 10749 | #if USE_CARBON_EVENTS | 11754 | #if TARGET_API_MAC_CARBON |
| 10750 | EventRef eventRef; | 11755 | EventRef eventRef; |
| 10751 | EventTargetRef toolbox_dispatcher; | 11756 | EventTargetRef toolbox_dispatcher; |
| 10752 | #endif | 11757 | #endif |
| @@ -10767,7 +11772,7 @@ XTread_socket (sd, expected, hold_quit) | |||
| 10767 | 11772 | ||
| 10768 | ++handling_signal; | 11773 | ++handling_signal; |
| 10769 | 11774 | ||
| 10770 | #if USE_CARBON_EVENTS | 11775 | #if TARGET_API_MAC_CARBON |
| 10771 | toolbox_dispatcher = GetEventDispatcherTarget (); | 11776 | toolbox_dispatcher = GetEventDispatcherTarget (); |
| 10772 | 11777 | ||
| 10773 | while ( | 11778 | while ( |
| @@ -10776,9 +11781,9 @@ XTread_socket (sd, expected, hold_quit) | |||
| 10776 | #endif | 11781 | #endif |
| 10777 | !ReceiveNextEvent (0, NULL, kEventDurationNoWait, | 11782 | !ReceiveNextEvent (0, NULL, kEventDurationNoWait, |
| 10778 | kEventRemoveFromQueue, &eventRef)) | 11783 | kEventRemoveFromQueue, &eventRef)) |
| 10779 | #else /* !USE_CARBON_EVENTS */ | 11784 | #else /* !TARGET_API_MAC_CARBON */ |
| 10780 | while (mac_wait_next_event (&er, 0, true)) | 11785 | while (mac_wait_next_event (&er, 0, true)) |
| 10781 | #endif /* !USE_CARBON_EVENTS */ | 11786 | #endif /* !TARGET_API_MAC_CARBON */ |
| 10782 | { | 11787 | { |
| 10783 | int do_help = 0; | 11788 | int do_help = 0; |
| 10784 | struct frame *f; | 11789 | struct frame *f; |
| @@ -10788,44 +11793,33 @@ XTread_socket (sd, expected, hold_quit) | |||
| 10788 | inev.kind = NO_EVENT; | 11793 | inev.kind = NO_EVENT; |
| 10789 | inev.arg = Qnil; | 11794 | inev.arg = Qnil; |
| 10790 | 11795 | ||
| 10791 | #if USE_CARBON_EVENTS | 11796 | #if TARGET_API_MAC_CARBON |
| 10792 | timestamp = GetEventTime (eventRef) / kEventDurationMillisecond; | 11797 | timestamp = GetEventTime (eventRef) / kEventDurationMillisecond; |
| 10793 | #else | ||
| 10794 | timestamp = er.when * (1000 / 60); /* ticks to milliseconds */ | ||
| 10795 | #endif | ||
| 10796 | 11798 | ||
| 10797 | #if USE_CARBON_EVENTS | ||
| 10798 | /* Handle new events */ | ||
| 10799 | if (!mac_convert_event_ref (eventRef, &er)) | 11799 | if (!mac_convert_event_ref (eventRef, &er)) |
| 10800 | { | 11800 | goto OTHER; |
| 10801 | /* There used to be a handler for the kEventMouseWheelMoved | 11801 | #else /* !TARGET_API_MAC_CARBON */ |
| 10802 | event here. But as of Mac OS X 10.4, this kind of event | 11802 | timestamp = er.when * (1000 / 60); /* ticks to milliseconds */ |
| 10803 | is not directly posted to the main event queue by | 11803 | #endif /* !TARGET_API_MAC_CARBON */ |
| 10804 | two-finger scrolling on the trackpad. Instead, some | 11804 | |
| 10805 | private event is posted and it is converted to a wheel | ||
| 10806 | event by the default handler for the application target. | ||
| 10807 | The converted one can be received by a Carbon event | ||
| 10808 | handler installed on a window target. */ | ||
| 10809 | read_socket_inev = &inev; | ||
| 10810 | SendEventToEventTarget (eventRef, toolbox_dispatcher); | ||
| 10811 | read_socket_inev = NULL; | ||
| 10812 | } | ||
| 10813 | else | ||
| 10814 | #endif /* USE_CARBON_EVENTS */ | ||
| 10815 | switch (er.what) | 11805 | switch (er.what) |
| 10816 | { | 11806 | { |
| 10817 | case mouseDown: | 11807 | case mouseDown: |
| 10818 | case mouseUp: | 11808 | case mouseUp: |
| 10819 | { | 11809 | { |
| 10820 | WindowPtr window_ptr; | 11810 | WindowRef window_ptr; |
| 10821 | ControlPartCode part_code; | 11811 | ControlPartCode part_code; |
| 10822 | int tool_bar_p = 0; | 11812 | int tool_bar_p = 0; |
| 10823 | 11813 | ||
| 10824 | #if USE_CARBON_EVENTS | 11814 | #if TARGET_API_MAC_CARBON |
| 11815 | OSStatus err; | ||
| 11816 | |||
| 10825 | /* This is needed to send mouse events like aqua window | 11817 | /* This is needed to send mouse events like aqua window |
| 10826 | buttons to the correct handler. */ | 11818 | buttons to the correct handler. */ |
| 10827 | if (SendEventToEventTarget (eventRef, toolbox_dispatcher) | 11819 | read_socket_inev = &inev; |
| 10828 | != eventNotHandledErr) | 11820 | err = SendEventToEventTarget (eventRef, toolbox_dispatcher); |
| 11821 | read_socket_inev = NULL; | ||
| 11822 | if (err != eventNotHandledErr) | ||
| 10829 | break; | 11823 | break; |
| 10830 | #endif | 11824 | #endif |
| 10831 | last_mouse_glyph_frame = 0; | 11825 | last_mouse_glyph_frame = 0; |
| @@ -10873,17 +11867,20 @@ XTread_socket (sd, expected, hold_quit) | |||
| 10873 | else | 11867 | else |
| 10874 | { | 11868 | { |
| 10875 | ControlPartCode control_part_code; | 11869 | ControlPartCode control_part_code; |
| 10876 | ControlHandle ch; | 11870 | ControlRef ch; |
| 10877 | Point mouse_loc = er.where; | 11871 | Point mouse_loc; |
| 10878 | #ifdef MAC_OSX | 11872 | #ifdef MAC_OSX |
| 10879 | ControlKind control_kind; | 11873 | ControlKind control_kind; |
| 10880 | #endif | 11874 | #endif |
| 10881 | 11875 | ||
| 10882 | f = mac_window_to_frame (window_ptr); | 11876 | f = mac_window_to_frame (window_ptr); |
| 10883 | /* convert to local coordinates of new window */ | 11877 | /* convert to local coordinates of new window */ |
| 10884 | SetPortWindowPort (window_ptr); | 11878 | mouse_loc.h = (er.where.h |
| 10885 | 11879 | - (f->left_pos | |
| 10886 | GlobalToLocal (&mouse_loc); | 11880 | + FRAME_OUTER_TO_INNER_DIFF_X (f))); |
| 11881 | mouse_loc.v = (er.where.v | ||
| 11882 | - (f->top_pos | ||
| 11883 | + FRAME_OUTER_TO_INNER_DIFF_Y (f))); | ||
| 10887 | #if TARGET_API_MAC_CARBON | 11884 | #if TARGET_API_MAC_CARBON |
| 10888 | ch = FindControlUnderMouse (mouse_loc, window_ptr, | 11885 | ch = FindControlUnderMouse (mouse_loc, window_ptr, |
| 10889 | &control_part_code); | 11886 | &control_part_code); |
| @@ -10896,7 +11893,7 @@ XTread_socket (sd, expected, hold_quit) | |||
| 10896 | &ch); | 11893 | &ch); |
| 10897 | #endif | 11894 | #endif |
| 10898 | 11895 | ||
| 10899 | #if USE_CARBON_EVENTS | 11896 | #if TARGET_API_MAC_CARBON |
| 10900 | inev.code = mac_get_mouse_btn (eventRef); | 11897 | inev.code = mac_get_mouse_btn (eventRef); |
| 10901 | inev.modifiers = mac_event_to_emacs_modifiers (eventRef); | 11898 | inev.modifiers = mac_event_to_emacs_modifiers (eventRef); |
| 10902 | #else | 11899 | #else |
| @@ -11032,16 +12029,14 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11032 | DragWindow (window_ptr, er.where, NULL); | 12029 | DragWindow (window_ptr, er.where, NULL); |
| 11033 | #else /* not TARGET_API_MAC_CARBON */ | 12030 | #else /* not TARGET_API_MAC_CARBON */ |
| 11034 | DragWindow (window_ptr, er.where, &qd.screenBits.bounds); | 12031 | DragWindow (window_ptr, er.where, &qd.screenBits.bounds); |
| 11035 | #endif /* not TARGET_API_MAC_CARBON */ | ||
| 11036 | /* Update the frame parameters. */ | 12032 | /* Update the frame parameters. */ |
| 11037 | #if !USE_CARBON_EVENTS | ||
| 11038 | { | 12033 | { |
| 11039 | struct frame *f = mac_window_to_frame (window_ptr); | 12034 | struct frame *f = mac_window_to_frame (window_ptr); |
| 11040 | 12035 | ||
| 11041 | if (f && !f->async_iconified) | 12036 | if (f && !f->async_iconified) |
| 11042 | mac_handle_origin_change (f); | 12037 | mac_handle_origin_change (f); |
| 11043 | } | 12038 | } |
| 11044 | #endif | 12039 | #endif /* not TARGET_API_MAC_CARBON */ |
| 11045 | break; | 12040 | break; |
| 11046 | 12041 | ||
| 11047 | case inGoAway: | 12042 | case inGoAway: |
| @@ -11065,41 +12060,52 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11065 | do_zoom_window (window_ptr, part_code); | 12060 | do_zoom_window (window_ptr, part_code); |
| 11066 | break; | 12061 | break; |
| 11067 | 12062 | ||
| 12063 | #if USE_MAC_TOOLBAR | ||
| 12064 | case inStructure: | ||
| 12065 | { | ||
| 12066 | OSStatus err; | ||
| 12067 | HIViewRef ch; | ||
| 12068 | |||
| 12069 | err = HIViewGetViewForMouseEvent (HIViewGetRoot (window_ptr), | ||
| 12070 | eventRef, &ch); | ||
| 12071 | /* This doesn't work on Mac OS X 10.2. */ | ||
| 12072 | if (err == noErr) | ||
| 12073 | HIViewClick (ch, eventRef); | ||
| 12074 | } | ||
| 12075 | break; | ||
| 12076 | #endif /* USE_MAC_TOOLBAR */ | ||
| 12077 | |||
| 11068 | default: | 12078 | default: |
| 11069 | break; | 12079 | break; |
| 11070 | } | 12080 | } |
| 11071 | } | 12081 | } |
| 11072 | break; | 12082 | break; |
| 11073 | 12083 | ||
| 12084 | #if !TARGET_API_MAC_CARBON | ||
| 11074 | case updateEvt: | 12085 | case updateEvt: |
| 11075 | #if USE_CARBON_EVENTS | 12086 | do_window_update ((WindowRef) er.message); |
| 11076 | if (SendEventToEventTarget (eventRef, toolbox_dispatcher) | ||
| 11077 | != eventNotHandledErr) | ||
| 11078 | break; | ||
| 11079 | #else | ||
| 11080 | do_window_update ((WindowPtr) er.message); | ||
| 11081 | #endif | ||
| 11082 | break; | 12087 | break; |
| 12088 | #endif | ||
| 11083 | 12089 | ||
| 11084 | case osEvt: | 12090 | case osEvt: |
| 11085 | #if USE_CARBON_EVENTS | 12091 | #if TARGET_API_MAC_CARBON |
| 11086 | if (SendEventToEventTarget (eventRef, toolbox_dispatcher) | 12092 | if (SendEventToEventTarget (eventRef, toolbox_dispatcher) |
| 11087 | != eventNotHandledErr) | 12093 | != eventNotHandledErr) |
| 11088 | break; | 12094 | break; |
| 11089 | #endif | 12095 | #endif |
| 11090 | switch ((er.message >> 24) & 0x000000FF) | 12096 | switch ((er.message >> 24) & 0x000000FF) |
| 11091 | { | 12097 | { |
| 11092 | case suspendResumeMessage: | ||
| 11093 | #if USE_MAC_TSM | 12098 | #if USE_MAC_TSM |
| 12099 | case suspendResumeMessage: | ||
| 11094 | if (er.message & resumeFlag) | 12100 | if (er.message & resumeFlag) |
| 11095 | mac_tsm_resume (); | 12101 | mac_tsm_resume (); |
| 11096 | else | 12102 | else |
| 11097 | mac_tsm_suspend (); | 12103 | mac_tsm_suspend (); |
| 11098 | #endif | ||
| 11099 | break; | 12104 | break; |
| 12105 | #endif | ||
| 11100 | 12106 | ||
| 11101 | case mouseMovedMessage: | 12107 | case mouseMovedMessage: |
| 11102 | #if !USE_CARBON_EVENTS | 12108 | #if !TARGET_API_MAC_CARBON |
| 11103 | SetRectRgn (mouse_region, er.where.h, er.where.v, | 12109 | SetRectRgn (mouse_region, er.where.h, er.where.v, |
| 11104 | er.where.h + 1, er.where.v + 1); | 12110 | er.where.h + 1, er.where.v + 1); |
| 11105 | #endif | 12111 | #endif |
| @@ -11120,13 +12126,15 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11120 | 12126 | ||
| 11121 | if (f) | 12127 | if (f) |
| 11122 | { | 12128 | { |
| 11123 | WindowPtr wp = FRAME_MAC_WINDOW (f); | 12129 | WindowRef wp = FRAME_MAC_WINDOW (f); |
| 11124 | Point mouse_pos = er.where; | 12130 | Point mouse_pos; |
| 11125 | 12131 | ||
| 11126 | SetPortWindowPort (wp); | 12132 | mouse_pos.h = (er.where.h |
| 11127 | 12133 | - (f->left_pos | |
| 11128 | GlobalToLocal (&mouse_pos); | 12134 | + FRAME_OUTER_TO_INNER_DIFF_X (f))); |
| 11129 | 12135 | mouse_pos.v = (er.where.v | |
| 12136 | - (f->top_pos | ||
| 12137 | + FRAME_OUTER_TO_INNER_DIFF_Y (f))); | ||
| 11130 | if (dpyinfo->grabbed && tracked_scroll_bar) | 12138 | if (dpyinfo->grabbed && tracked_scroll_bar) |
| 11131 | #ifdef USE_TOOLKIT_SCROLL_BARS | 12139 | #ifdef USE_TOOLKIT_SCROLL_BARS |
| 11132 | x_scroll_bar_handle_drag (wp, tracked_scroll_bar, | 12140 | x_scroll_bar_handle_drag (wp, tracked_scroll_bar, |
| @@ -11171,6 +12179,10 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11171 | } | 12179 | } |
| 11172 | if (!note_mouse_movement (f, &mouse_pos)) | 12180 | if (!note_mouse_movement (f, &mouse_pos)) |
| 11173 | help_echo_string = previous_help_echo_string; | 12181 | help_echo_string = previous_help_echo_string; |
| 12182 | #if USE_MAC_TOOLBAR | ||
| 12183 | else | ||
| 12184 | mac_tool_bar_note_mouse_movement (f, eventRef); | ||
| 12185 | #endif | ||
| 11174 | } | 12186 | } |
| 11175 | } | 12187 | } |
| 11176 | 12188 | ||
| @@ -11185,13 +12197,10 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11185 | 12197 | ||
| 11186 | case activateEvt: | 12198 | case activateEvt: |
| 11187 | { | 12199 | { |
| 11188 | WindowPtr window_ptr = (WindowPtr) er.message; | 12200 | WindowRef window_ptr = (WindowRef) er.message; |
| 12201 | OSErr err; | ||
| 12202 | ControlRef root_control; | ||
| 11189 | 12203 | ||
| 11190 | #if USE_CARBON_EVENTS | ||
| 11191 | if (SendEventToEventTarget (eventRef, toolbox_dispatcher) | ||
| 11192 | != eventNotHandledErr) | ||
| 11193 | break; | ||
| 11194 | #endif | ||
| 11195 | if (window_ptr == tip_window) | 12204 | if (window_ptr == tip_window) |
| 11196 | { | 12205 | { |
| 11197 | HideWindow (tip_window); | 12206 | HideWindow (tip_window); |
| @@ -11199,25 +12208,38 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11199 | } | 12208 | } |
| 11200 | 12209 | ||
| 11201 | if (!is_emacs_window (window_ptr)) | 12210 | if (!is_emacs_window (window_ptr)) |
| 11202 | break; | 12211 | goto OTHER; |
| 12212 | |||
| 12213 | f = mac_window_to_frame (window_ptr); | ||
| 11203 | 12214 | ||
| 11204 | if ((er.modifiers & activeFlag) != 0) | 12215 | if ((er.modifiers & activeFlag) != 0) |
| 11205 | { | 12216 | { |
| 11206 | /* A window has been activated */ | 12217 | /* A window has been activated */ |
| 11207 | Point mouse_loc = er.where; | 12218 | Point mouse_loc; |
| 12219 | |||
| 12220 | err = GetRootControl (FRAME_MAC_WINDOW (f), &root_control); | ||
| 12221 | if (err == noErr) | ||
| 12222 | ActivateControl (root_control); | ||
| 11208 | 12223 | ||
| 11209 | x_detect_focus_change (dpyinfo, &er, &inev); | 12224 | x_detect_focus_change (dpyinfo, &er, &inev); |
| 11210 | 12225 | ||
| 11211 | SetPortWindowPort (window_ptr); | 12226 | mouse_loc.h = (er.where.h |
| 11212 | GlobalToLocal (&mouse_loc); | 12227 | - (f->left_pos |
| 12228 | + FRAME_OUTER_TO_INNER_DIFF_X (f))); | ||
| 12229 | mouse_loc.v = (er.where.v | ||
| 12230 | - (f->top_pos | ||
| 12231 | + FRAME_OUTER_TO_INNER_DIFF_Y (f))); | ||
| 11213 | /* Window-activated event counts as mouse movement, | 12232 | /* Window-activated event counts as mouse movement, |
| 11214 | so update things that depend on mouse position. */ | 12233 | so update things that depend on mouse position. */ |
| 11215 | note_mouse_movement (mac_window_to_frame (window_ptr), | 12234 | note_mouse_movement (f, &mouse_loc); |
| 11216 | &mouse_loc); | ||
| 11217 | } | 12235 | } |
| 11218 | else | 12236 | else |
| 11219 | { | 12237 | { |
| 11220 | /* A window has been deactivated */ | 12238 | /* A window has been deactivated */ |
| 12239 | err = GetRootControl (FRAME_MAC_WINDOW (f), &root_control); | ||
| 12240 | if (err == noErr) | ||
| 12241 | DeactivateControl (root_control); | ||
| 12242 | |||
| 11221 | #ifdef USE_TOOLKIT_SCROLL_BARS | 12243 | #ifdef USE_TOOLKIT_SCROLL_BARS |
| 11222 | if (dpyinfo->grabbed && tracked_scroll_bar) | 12244 | if (dpyinfo->grabbed && tracked_scroll_bar) |
| 11223 | { | 12245 | { |
| @@ -11238,7 +12260,6 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11238 | 12260 | ||
| 11239 | x_detect_focus_change (dpyinfo, &er, &inev); | 12261 | x_detect_focus_change (dpyinfo, &er, &inev); |
| 11240 | 12262 | ||
| 11241 | f = mac_window_to_frame (window_ptr); | ||
| 11242 | if (f == dpyinfo->mouse_face_mouse_frame) | 12263 | if (f == dpyinfo->mouse_face_mouse_frame) |
| 11243 | { | 12264 | { |
| 11244 | /* If we move outside the frame, then we're | 12265 | /* If we move outside the frame, then we're |
| @@ -11261,212 +12282,41 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11261 | case keyDown: | 12282 | case keyDown: |
| 11262 | case keyUp: | 12283 | case keyUp: |
| 11263 | case autoKey: | 12284 | case autoKey: |
| 12285 | ObscureCursor (); | ||
| 12286 | |||
| 12287 | f = mac_focus_frame (dpyinfo); | ||
| 12288 | XSETFRAME (inev.frame_or_window, f); | ||
| 12289 | |||
| 12290 | /* If mouse-highlight is an integer, input clears out mouse | ||
| 12291 | highlighting. */ | ||
| 12292 | if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight) | ||
| 12293 | && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window)) | ||
| 12294 | { | ||
| 12295 | clear_mouse_face (dpyinfo); | ||
| 12296 | dpyinfo->mouse_face_hidden = 1; | ||
| 12297 | } | ||
| 12298 | |||
| 11264 | { | 12299 | { |
| 11265 | int keycode = (er.message & keyCodeMask) >> 8; | ||
| 11266 | static SInt16 last_key_script = -1; | ||
| 11267 | SInt16 current_key_script; | ||
| 11268 | UInt32 modifiers = er.modifiers, mapped_modifiers; | 12300 | UInt32 modifiers = er.modifiers, mapped_modifiers; |
| 12301 | UInt32 key_code = (er.message & keyCodeMask) >> 8; | ||
| 11269 | 12302 | ||
| 11270 | #if USE_CARBON_EVENTS && defined (MAC_OSX) | 12303 | #ifdef MAC_OSX |
| 11271 | GetEventParameter (eventRef, kEventParamKeyModifiers, | 12304 | GetEventParameter (eventRef, kEventParamKeyModifiers, |
| 11272 | typeUInt32, NULL, | 12305 | typeUInt32, NULL, |
| 11273 | sizeof (UInt32), NULL, &modifiers); | 12306 | sizeof (UInt32), NULL, &modifiers); |
| 11274 | #endif | 12307 | #endif |
| 11275 | mapped_modifiers = mac_mapped_modifiers (modifiers, keycode); | 12308 | mapped_modifiers = mac_mapped_modifiers (modifiers, key_code); |
| 11276 | 12309 | ||
| 11277 | #if USE_CARBON_EVENTS && (defined (MAC_OSX) || USE_MAC_TSM) | 12310 | #if TARGET_API_MAC_CARBON |
| 11278 | /* When using Carbon Events, we need to pass raw keyboard | ||
| 11279 | events to the TSM ourselves. If TSM handles it, it | ||
| 11280 | will pass back noErr, otherwise it will pass back | ||
| 11281 | "eventNotHandledErr" and we can process it | ||
| 11282 | normally. */ | ||
| 11283 | if (!(mapped_modifiers | 12311 | if (!(mapped_modifiers |
| 11284 | & ~(mac_pass_command_to_system ? cmdKey : 0) | 12312 | & ~(mac_pass_command_to_system ? cmdKey : 0) |
| 11285 | & ~(mac_pass_control_to_system ? controlKey : 0))) | 12313 | & ~(mac_pass_control_to_system ? controlKey : 0))) |
| 11286 | { | 12314 | goto OTHER; |
| 11287 | OSStatus err; | 12315 | else |
| 11288 | |||
| 11289 | read_socket_inev = &inev; | ||
| 11290 | err = SendEventToEventTarget (eventRef, toolbox_dispatcher); | ||
| 11291 | read_socket_inev = NULL; | ||
| 11292 | if (err != eventNotHandledErr) | ||
| 11293 | break; | ||
| 11294 | } | ||
| 11295 | #endif | ||
| 11296 | if (er.what == keyUp) | ||
| 11297 | break; | ||
| 11298 | |||
| 11299 | ObscureCursor (); | ||
| 11300 | |||
| 11301 | f = mac_focus_frame (dpyinfo); | ||
| 11302 | |||
| 11303 | if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight) | ||
| 11304 | && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window)) | ||
| 11305 | { | ||
| 11306 | clear_mouse_face (dpyinfo); | ||
| 11307 | dpyinfo->mouse_face_hidden = 1; | ||
| 11308 | } | ||
| 11309 | |||
| 11310 | current_key_script = GetScriptManagerVariable (smKeyScript); | ||
| 11311 | if (last_key_script != current_key_script) | ||
| 11312 | { | ||
| 11313 | struct input_event event; | ||
| 11314 | |||
| 11315 | EVENT_INIT (event); | ||
| 11316 | event.kind = LANGUAGE_CHANGE_EVENT; | ||
| 11317 | event.arg = Qnil; | ||
| 11318 | event.code = current_key_script; | ||
| 11319 | event.timestamp = timestamp; | ||
| 11320 | kbd_buffer_store_event (&event); | ||
| 11321 | count++; | ||
| 11322 | last_key_script = current_key_script; | ||
| 11323 | } | ||
| 11324 | |||
| 11325 | #if USE_MAC_TSM | ||
| 11326 | if (inev.kind != NO_EVENT) | ||
| 11327 | break; | ||
| 11328 | #endif | ||
| 11329 | |||
| 11330 | #ifdef MAC_OSX | ||
| 11331 | if (mapped_modifiers & kEventKeyModifierFnMask | ||
| 11332 | && keycode <= 0x7f | ||
| 11333 | && fn_keycode_to_keycode_table[keycode]) | ||
| 11334 | keycode = fn_keycode_to_keycode_table[keycode]; | ||
| 11335 | #endif | ||
| 11336 | if (keycode <= 0x7f && keycode_to_xkeysym_table [keycode]) | ||
| 11337 | { | ||
| 11338 | inev.kind = NON_ASCII_KEYSTROKE_EVENT; | ||
| 11339 | inev.code = 0xff00 | keycode_to_xkeysym_table [keycode]; | ||
| 11340 | } | ||
| 11341 | else if (mapped_modifiers) | ||
| 11342 | { | ||
| 11343 | /* translate the keycode back to determine the | ||
| 11344 | original key */ | ||
| 11345 | #ifdef MAC_OSX | ||
| 11346 | UCKeyboardLayout *uchr_ptr = NULL; | ||
| 11347 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | ||
| 11348 | OSStatus err; | ||
| 11349 | KeyboardLayoutRef layout; | ||
| 11350 | |||
| 11351 | err = KLGetCurrentKeyboardLayout (&layout); | ||
| 11352 | if (err == noErr) | ||
| 11353 | KLGetKeyboardLayoutProperty (layout, kKLuchrData, | ||
| 11354 | (const void **) &uchr_ptr); | ||
| 11355 | #else | ||
| 11356 | static SInt16 last_key_layout_id = 0; | ||
| 11357 | static Handle uchr_handle = (Handle)-1; | ||
| 11358 | SInt16 current_key_layout_id = | ||
| 11359 | GetScriptVariable (current_key_script, smScriptKeys); | ||
| 11360 | |||
| 11361 | if (uchr_handle == (Handle)-1 | ||
| 11362 | || last_key_layout_id != current_key_layout_id) | ||
| 11363 | { | ||
| 11364 | uchr_handle = GetResource ('uchr', current_key_layout_id); | ||
| 11365 | last_key_layout_id = current_key_layout_id; | ||
| 11366 | } | ||
| 11367 | if (uchr_handle) | ||
| 11368 | uchr_ptr = (UCKeyboardLayout *)*uchr_handle; | ||
| 11369 | #endif | ||
| 11370 | |||
| 11371 | if (uchr_ptr) | ||
| 11372 | { | ||
| 11373 | OSStatus status; | ||
| 11374 | UInt16 key_action = er.what - keyDown; | ||
| 11375 | UInt32 modifier_key_state = | ||
| 11376 | (modifiers & ~mapped_modifiers) >> 8; | ||
| 11377 | UInt32 keyboard_type = LMGetKbdType (); | ||
| 11378 | SInt32 dead_key_state = 0; | ||
| 11379 | UniChar code; | ||
| 11380 | UniCharCount actual_length; | ||
| 11381 | |||
| 11382 | status = UCKeyTranslate (uchr_ptr, | ||
| 11383 | keycode, key_action, | ||
| 11384 | modifier_key_state, | ||
| 11385 | keyboard_type, | ||
| 11386 | kUCKeyTranslateNoDeadKeysMask, | ||
| 11387 | &dead_key_state, | ||
| 11388 | 1, &actual_length, &code); | ||
| 11389 | if (status == noErr && actual_length == 1) | ||
| 11390 | mac_set_unicode_keystroke_event (code, &inev); | ||
| 11391 | } | ||
| 11392 | #endif /* MAC_OSX */ | ||
| 11393 | |||
| 11394 | if (inev.kind == NO_EVENT) | ||
| 11395 | { | ||
| 11396 | /* This code comes from Keyboard Resource, | ||
| 11397 | Appendix C of IM - Text. This is necessary | ||
| 11398 | since shift is ignored in KCHR table | ||
| 11399 | translation when option or command is pressed. | ||
| 11400 | It also does not translate correctly | ||
| 11401 | control-shift chars like C-% so mask off shift | ||
| 11402 | here also. */ | ||
| 11403 | /* Mask off modifier keys that are mapped to some | ||
| 11404 | Emacs modifiers. */ | ||
| 11405 | int new_modifiers = er.modifiers & ~mapped_modifiers; | ||
| 11406 | /* set high byte of keycode to modifier high byte*/ | ||
| 11407 | int new_keycode = keycode | new_modifiers; | ||
| 11408 | Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache); | ||
| 11409 | unsigned long some_state = 0; | ||
| 11410 | UInt32 new_char_code; | ||
| 11411 | |||
| 11412 | new_char_code = KeyTranslate (kchr_ptr, new_keycode, | ||
| 11413 | &some_state); | ||
| 11414 | if (new_char_code == 0) | ||
| 11415 | /* Seems like a dead key. Append up-stroke. */ | ||
| 11416 | new_char_code = KeyTranslate (kchr_ptr, | ||
| 11417 | new_keycode | 0x80, | ||
| 11418 | &some_state); | ||
| 11419 | if (new_char_code) | ||
| 11420 | { | ||
| 11421 | inev.kind = ASCII_KEYSTROKE_EVENT; | ||
| 11422 | inev.code = new_char_code & 0xff; | ||
| 11423 | } | ||
| 11424 | } | ||
| 11425 | } | ||
| 11426 | |||
| 11427 | if (inev.kind == NO_EVENT) | ||
| 11428 | { | ||
| 11429 | inev.kind = ASCII_KEYSTROKE_EVENT; | ||
| 11430 | inev.code = er.message & charCodeMask; | ||
| 11431 | } | ||
| 11432 | |||
| 11433 | inev.modifiers = mac_to_emacs_modifiers (mapped_modifiers, | ||
| 11434 | modifiers); | ||
| 11435 | inev.modifiers |= (extra_keyboard_modifiers | ||
| 11436 | & (meta_modifier | alt_modifier | ||
| 11437 | | hyper_modifier | super_modifier)); | ||
| 11438 | XSETFRAME (inev.frame_or_window, f); | ||
| 11439 | |||
| 11440 | #if TARGET_API_MAC_CARBON | ||
| 11441 | if (inev.kind == ASCII_KEYSTROKE_EVENT | ||
| 11442 | && inev.code >= 0x80 && inev.modifiers) | ||
| 11443 | { | ||
| 11444 | OSStatus err; | ||
| 11445 | TextEncoding encoding = kTextEncodingMacRoman; | ||
| 11446 | TextToUnicodeInfo ttu_info; | ||
| 11447 | |||
| 11448 | UpgradeScriptInfoToTextEncoding (current_key_script, | ||
| 11449 | kTextLanguageDontCare, | ||
| 11450 | kTextRegionDontCare, | ||
| 11451 | NULL, &encoding); | ||
| 11452 | err = CreateTextToUnicodeInfoByEncoding (encoding, &ttu_info); | ||
| 11453 | if (err == noErr) | ||
| 11454 | { | ||
| 11455 | UniChar code; | ||
| 11456 | Str255 pstr; | ||
| 11457 | ByteCount unicode_len; | ||
| 11458 | |||
| 11459 | pstr[0] = 1; | ||
| 11460 | pstr[1] = inev.code; | ||
| 11461 | err = ConvertFromPStringToUnicode (ttu_info, pstr, | ||
| 11462 | sizeof (UniChar), | ||
| 11463 | &unicode_len, &code); | ||
| 11464 | if (err == noErr && unicode_len == sizeof (UniChar)) | ||
| 11465 | mac_set_unicode_keystroke_event (code, &inev); | ||
| 11466 | DisposeTextToUnicodeInfo (&ttu_info); | ||
| 11467 | } | ||
| 11468 | } | ||
| 11469 | #endif | 12316 | #endif |
| 12317 | if (er.what != keyUp) | ||
| 12318 | do_keystroke (er.what, er.message & charCodeMask, | ||
| 12319 | key_code, modifiers, timestamp, &inev); | ||
| 11470 | } | 12320 | } |
| 11471 | break; | 12321 | break; |
| 11472 | 12322 | ||
| @@ -11475,9 +12325,19 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11475 | break; | 12325 | break; |
| 11476 | 12326 | ||
| 11477 | default: | 12327 | default: |
| 12328 | OTHER: | ||
| 12329 | #if TARGET_API_MAC_CARBON | ||
| 12330 | { | ||
| 12331 | OSStatus err; | ||
| 12332 | |||
| 12333 | read_socket_inev = &inev; | ||
| 12334 | err = SendEventToEventTarget (eventRef, toolbox_dispatcher); | ||
| 12335 | read_socket_inev = NULL; | ||
| 12336 | } | ||
| 12337 | #endif | ||
| 11478 | break; | 12338 | break; |
| 11479 | } | 12339 | } |
| 11480 | #if USE_CARBON_EVENTS | 12340 | #if TARGET_API_MAC_CARBON |
| 11481 | ReleaseEvent (eventRef); | 12341 | ReleaseEvent (eventRef); |
| 11482 | #endif | 12342 | #endif |
| 11483 | 12343 | ||
| @@ -11511,7 +12371,6 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11511 | } | 12371 | } |
| 11512 | count++; | 12372 | count++; |
| 11513 | } | 12373 | } |
| 11514 | |||
| 11515 | } | 12374 | } |
| 11516 | 12375 | ||
| 11517 | /* If the focus was just given to an autoraising frame, | 12376 | /* If the focus was just given to an autoraising frame, |
| @@ -11529,7 +12388,7 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11529 | mac_screen_config_changed = 0; | 12388 | mac_screen_config_changed = 0; |
| 11530 | } | 12389 | } |
| 11531 | 12390 | ||
| 11532 | #if !USE_CARBON_EVENTS | 12391 | #if !TARGET_API_MAC_CARBON |
| 11533 | /* Check which frames are still visible. We do this here because | 12392 | /* Check which frames are still visible. We do this here because |
| 11534 | there doesn't seem to be any direct notification from the Window | 12393 | there doesn't seem to be any direct notification from the Window |
| 11535 | Manager that the visibility of a window has changed (at least, | 12394 | Manager that the visibility of a window has changed (at least, |
| @@ -11634,7 +12493,7 @@ make_mac_terminal_frame (struct frame *f) | |||
| 11634 | 12493 | ||
| 11635 | if (!(FRAME_MAC_WINDOW (f) = | 12494 | if (!(FRAME_MAC_WINDOW (f) = |
| 11636 | NewCWindow (NULL, &r, "\p", true, dBoxProc, | 12495 | NewCWindow (NULL, &r, "\p", true, dBoxProc, |
| 11637 | (WindowPtr) -1, 1, (long) f->output_data.mac))) | 12496 | (WindowRef) -1, 1, (long) f->output_data.mac))) |
| 11638 | abort (); | 12497 | abort (); |
| 11639 | /* so that update events can find this mac_output struct */ | 12498 | /* so that update events can find this mac_output struct */ |
| 11640 | f->output_data.mac->mFP = f; /* point back to emacs frame */ | 12499 | f->output_data.mac->mFP = f; /* point back to emacs frame */ |
| @@ -11824,7 +12683,6 @@ init_menu_bar () | |||
| 11824 | &menu, &menu_index); | 12683 | &menu, &menu_index); |
| 11825 | if (err == noErr) | 12684 | if (err == noErr) |
| 11826 | SetMenuItemCommandKey (menu, menu_index, false, 0); | 12685 | SetMenuItemCommandKey (menu, menu_index, false, 0); |
| 11827 | #if USE_CARBON_EVENTS | ||
| 11828 | EnableMenuCommand (NULL, kHICommandPreferences); | 12686 | EnableMenuCommand (NULL, kHICommandPreferences); |
| 11829 | err = GetIndMenuItemWithCommandID (NULL, kHICommandPreferences, 1, | 12687 | err = GetIndMenuItemWithCommandID (NULL, kHICommandPreferences, 1, |
| 11830 | &menu, &menu_index); | 12688 | &menu, &menu_index); |
| @@ -11836,10 +12694,9 @@ init_menu_bar () | |||
| 11836 | InsertMenuItemTextWithCFString (menu, CFSTR ("About Emacs"), | 12694 | InsertMenuItemTextWithCFString (menu, CFSTR ("About Emacs"), |
| 11837 | 0, 0, kHICommandAbout); | 12695 | 0, 0, kHICommandAbout); |
| 11838 | } | 12696 | } |
| 11839 | #endif /* USE_CARBON_EVENTS */ | ||
| 11840 | #else /* !MAC_OSX */ | 12697 | #else /* !MAC_OSX */ |
| 11841 | #if USE_CARBON_EVENTS | 12698 | #if TARGET_API_MAC_CARBON |
| 11842 | SetMenuItemCommandID (GetMenuHandle (M_APPLE), I_ABOUT, kHICommandAbout); | 12699 | SetMenuItemCommandID (GetMenuRef (M_APPLE), I_ABOUT, kHICommandAbout); |
| 11843 | #endif | 12700 | #endif |
| 11844 | #endif | 12701 | #endif |
| 11845 | } | 12702 | } |
| @@ -11946,19 +12803,13 @@ mac_initialize () | |||
| 11946 | 12803 | ||
| 11947 | #if TARGET_API_MAC_CARBON | 12804 | #if TARGET_API_MAC_CARBON |
| 11948 | 12805 | ||
| 11949 | #if USE_CARBON_EVENTS | 12806 | install_application_handler (); |
| 11950 | #ifdef MAC_OSX | ||
| 11951 | init_service_handler (); | ||
| 11952 | #endif /* MAC_OSX */ | ||
| 11953 | |||
| 11954 | init_command_handler (); | ||
| 11955 | 12807 | ||
| 11956 | init_menu_bar (); | 12808 | init_menu_bar (); |
| 11957 | 12809 | ||
| 11958 | #if USE_MAC_TSM | 12810 | #if USE_MAC_TSM |
| 11959 | init_tsm (); | 12811 | init_tsm (); |
| 11960 | #endif | 12812 | #endif |
| 11961 | #endif /* USE_CARBON_EVENTS */ | ||
| 11962 | 12813 | ||
| 11963 | #ifdef MAC_OSX | 12814 | #ifdef MAC_OSX |
| 11964 | init_coercion_handler (); | 12815 | init_coercion_handler (); |
| @@ -12008,7 +12859,7 @@ syms_of_macterm () | |||
| 12008 | Fput (Qhyper, Qmodifier_value, make_number (hyper_modifier)); | 12859 | Fput (Qhyper, Qmodifier_value, make_number (hyper_modifier)); |
| 12009 | Fput (Qsuper, Qmodifier_value, make_number (super_modifier)); | 12860 | Fput (Qsuper, Qmodifier_value, make_number (super_modifier)); |
| 12010 | 12861 | ||
| 12011 | #if USE_CARBON_EVENTS | 12862 | #if TARGET_API_MAC_CARBON |
| 12012 | Qhi_command = intern ("hi-command"); staticpro (&Qhi_command); | 12863 | Qhi_command = intern ("hi-command"); staticpro (&Qhi_command); |
| 12013 | #ifdef MAC_OSX | 12864 | #ifdef MAC_OSX |
| 12014 | Qtoolbar_switch_mode = intern ("toolbar-switch-mode"); | 12865 | Qtoolbar_switch_mode = intern ("toolbar-switch-mode"); |
| @@ -12133,7 +12984,7 @@ The symbol `reverse' means that the option-key will register for | |||
| 12133 | mouse-3 and the command-key will register for mouse-2. */); | 12984 | mouse-3 and the command-key will register for mouse-2. */); |
| 12134 | Vmac_emulate_three_button_mouse = Qnil; | 12985 | Vmac_emulate_three_button_mouse = Qnil; |
| 12135 | 12986 | ||
| 12136 | #if USE_CARBON_EVENTS | 12987 | #if TARGET_API_MAC_CARBON |
| 12137 | DEFVAR_BOOL ("mac-wheel-button-is-mouse-2", &mac_wheel_button_is_mouse_2, | 12988 | DEFVAR_BOOL ("mac-wheel-button-is-mouse-2", &mac_wheel_button_is_mouse_2, |
| 12138 | doc: /* *Non-nil if the wheel button is mouse-2 and the right click mouse-3. | 12989 | doc: /* *Non-nil if the wheel button is mouse-2 and the right click mouse-3. |
| 12139 | Otherwise, the right click will be treated as mouse-2 and the wheel | 12990 | Otherwise, the right click will be treated as mouse-2 and the wheel |