diff options
| author | YAMAMOTO Mitsuharu | 2007-06-07 08:45:00 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2007-06-07 08:45:00 +0000 |
| commit | 7adf314352a9fcd258183153d9068f73ef1d048c (patch) | |
| tree | fa16699a47a9dfffe8b7fa5098b2e56b3e9caa13 | |
| parent | 343bd7942699f1a9e8ba83363468a7ef1c173c19 (diff) | |
| download | emacs-7adf314352a9fcd258183153d9068f73ef1d048c.tar.gz emacs-7adf314352a9fcd258183153d9068f73ef1d048c.zip | |
(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_application_event, mac_handle_keyboard_event)
[TARGET_API_MAC_CARBON]: New functions.
(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 application activation handler
to mac_handle_application_event. 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.
| -rw-r--r-- | src/macterm.c | 1953 |
1 files changed, 1084 insertions, 869 deletions
diff --git a/src/macterm.c b/src/macterm.c index a4030a18ecb..bdeedfb9ab6 100644 --- a/src/macterm.c +++ b/src/macterm.c | |||
| @@ -411,7 +411,8 @@ mac_prepare_for_quickdraw (f) | |||
| 411 | static RgnHandle saved_port_clip_region = NULL; | 411 | static RgnHandle saved_port_clip_region = NULL; |
| 412 | 412 | ||
| 413 | static void | 413 | static void |
| 414 | mac_begin_clip (gc) | 414 | mac_begin_clip (f, gc) |
| 415 | struct frame *f; | ||
| 415 | GC gc; | 416 | GC gc; |
| 416 | { | 417 | { |
| 417 | static RgnHandle new_region = NULL; | 418 | static RgnHandle new_region = NULL; |
| @@ -421,6 +422,11 @@ mac_begin_clip (gc) | |||
| 421 | if (new_region == NULL) | 422 | if (new_region == NULL) |
| 422 | new_region = NewRgn (); | 423 | new_region = NewRgn (); |
| 423 | 424 | ||
| 425 | #if USE_CG_DRAWING | ||
| 426 | mac_prepare_for_quickdraw (f); | ||
| 427 | #endif | ||
| 428 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | ||
| 429 | |||
| 424 | if (gc->n_clip_rects) | 430 | if (gc->n_clip_rects) |
| 425 | { | 431 | { |
| 426 | GetClip (saved_port_clip_region); | 432 | GetClip (saved_port_clip_region); |
| @@ -440,15 +446,6 @@ mac_end_clip (gc) | |||
| 440 | 446 | ||
| 441 | /* X display function emulation */ | 447 | /* X display function emulation */ |
| 442 | 448 | ||
| 443 | void | ||
| 444 | XFreePixmap (display, pixmap) | ||
| 445 | Display *display; /* not used */ | ||
| 446 | Pixmap pixmap; | ||
| 447 | { | ||
| 448 | DisposeGWorld (pixmap); | ||
| 449 | } | ||
| 450 | |||
| 451 | |||
| 452 | /* Mac version of XDrawLine. */ | 449 | /* Mac version of XDrawLine. */ |
| 453 | 450 | ||
| 454 | static void | 451 | static void |
| @@ -490,11 +487,8 @@ mac_draw_line (f, gc, x1, y1, x2, y2) | |||
| 490 | x2--; | 487 | x2--; |
| 491 | } | 488 | } |
| 492 | 489 | ||
| 493 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 490 | mac_begin_clip (f, gc); |
| 494 | |||
| 495 | RGBForeColor (GC_FORE_COLOR (gc)); | 491 | RGBForeColor (GC_FORE_COLOR (gc)); |
| 496 | |||
| 497 | mac_begin_clip (gc); | ||
| 498 | MoveTo (x1, y1); | 492 | MoveTo (x1, y1); |
| 499 | LineTo (x2, y2); | 493 | LineTo (x2, y2); |
| 500 | mac_end_clip (gc); | 494 | mac_end_clip (gc); |
| @@ -550,25 +544,25 @@ mac_erase_rectangle (f, gc, x, y, width, height) | |||
| 550 | unsigned int width, height; | 544 | unsigned int width, height; |
| 551 | { | 545 | { |
| 552 | #if USE_CG_DRAWING | 546 | #if USE_CG_DRAWING |
| 553 | CGContextRef context; | 547 | { |
| 548 | CGContextRef context; | ||
| 554 | 549 | ||
| 555 | context = mac_begin_cg_clip (f, gc); | 550 | context = mac_begin_cg_clip (f, gc); |
| 556 | CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc); | 551 | CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc); |
| 557 | CGContextFillRect (context, CGRectMake (x, y, width, height)); | 552 | CGContextFillRect (context, CGRectMake (x, y, width, height)); |
| 558 | mac_end_cg_clip (f); | 553 | mac_end_cg_clip (f); |
| 554 | } | ||
| 559 | #else | 555 | #else |
| 560 | Rect r; | 556 | { |
| 561 | 557 | Rect r; | |
| 562 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | ||
| 563 | |||
| 564 | RGBBackColor (GC_BACK_COLOR (gc)); | ||
| 565 | SetRect (&r, x, y, x + width, y + height); | ||
| 566 | |||
| 567 | mac_begin_clip (gc); | ||
| 568 | EraseRect (&r); | ||
| 569 | mac_end_clip (gc); | ||
| 570 | 558 | ||
| 571 | 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 | } | ||
| 572 | #endif | 566 | #endif |
| 573 | } | 567 | } |
| 574 | 568 | ||
| @@ -591,15 +585,17 @@ mac_clear_window (f) | |||
| 591 | struct frame *f; | 585 | struct frame *f; |
| 592 | { | 586 | { |
| 593 | #if USE_CG_DRAWING | 587 | #if USE_CG_DRAWING |
| 594 | CGContextRef context; | 588 | { |
| 595 | GC gc = FRAME_NORMAL_GC (f); | 589 | CGContextRef context; |
| 596 | 590 | GC gc = FRAME_NORMAL_GC (f); | |
| 597 | context = mac_begin_cg_clip (f, NULL); | 591 | |
| 598 | CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc); | 592 | context = mac_begin_cg_clip (f, NULL); |
| 599 | CGContextFillRect (context, CGRectMake (0, 0, FRAME_PIXEL_WIDTH (f), | 593 | CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc); |
| 600 | FRAME_PIXEL_HEIGHT (f))); | 594 | CGContextFillRect (context, CGRectMake (0, 0, FRAME_PIXEL_WIDTH (f), |
| 601 | mac_end_cg_clip (f); | 595 | FRAME_PIXEL_HEIGHT (f))); |
| 602 | #else | 596 | mac_end_cg_clip (f); |
| 597 | } | ||
| 598 | #else /* !USE_CG_DRAWING */ | ||
| 603 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 599 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); |
| 604 | 600 | ||
| 605 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 601 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| @@ -673,13 +669,10 @@ mac_draw_bitmap (f, gc, x, y, width, height, bits, overlay_p) | |||
| 673 | bitmap.baseAddr = (char *)bits; | 669 | bitmap.baseAddr = (char *)bits; |
| 674 | SetRect (&(bitmap.bounds), 0, 0, width, height); | 670 | SetRect (&(bitmap.bounds), 0, 0, width, height); |
| 675 | 671 | ||
| 676 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 672 | mac_begin_clip (f, gc); |
| 677 | |||
| 678 | RGBForeColor (GC_FORE_COLOR (gc)); | 673 | RGBForeColor (GC_FORE_COLOR (gc)); |
| 679 | RGBBackColor (GC_BACK_COLOR (gc)); | 674 | RGBBackColor (GC_BACK_COLOR (gc)); |
| 680 | SetRect (&r, x, y, x + width, y + height); | 675 | SetRect (&r, x, y, x + width, y + height); |
| 681 | |||
| 682 | mac_begin_clip (gc); | ||
| 683 | #if TARGET_API_MAC_CARBON | 676 | #if TARGET_API_MAC_CARBON |
| 684 | { | 677 | { |
| 685 | CGrafPtr port; | 678 | CGrafPtr port; |
| @@ -694,9 +687,8 @@ mac_draw_bitmap (f, gc, x, y, width, height, bits, overlay_p) | |||
| 694 | CopyBits (&bitmap, &(FRAME_MAC_WINDOW (f)->portBits), &(bitmap.bounds), &r, | 687 | CopyBits (&bitmap, &(FRAME_MAC_WINDOW (f)->portBits), &(bitmap.bounds), &r, |
| 695 | overlay_p ? srcOr : srcCopy, 0); | 688 | overlay_p ? srcOr : srcCopy, 0); |
| 696 | #endif /* not TARGET_API_MAC_CARBON */ | 689 | #endif /* not TARGET_API_MAC_CARBON */ |
| 697 | mac_end_clip (gc); | ||
| 698 | |||
| 699 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 690 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 691 | mac_end_clip (gc); | ||
| 700 | } | 692 | } |
| 701 | #endif /* !USE_CG_DRAWING */ | 693 | #endif /* !USE_CG_DRAWING */ |
| 702 | 694 | ||
| @@ -747,7 +739,7 @@ mac_free_bitmap (bitmap) | |||
| 747 | 739 | ||
| 748 | Pixmap | 740 | Pixmap |
| 749 | XCreatePixmap (display, w, width, height, depth) | 741 | XCreatePixmap (display, w, width, height, depth) |
| 750 | Display *display; /* not used */ | 742 | Display *display; |
| 751 | WindowRef w; | 743 | WindowRef w; |
| 752 | unsigned int width, height; | 744 | unsigned int width, height; |
| 753 | unsigned int depth; | 745 | unsigned int depth; |
| @@ -776,7 +768,7 @@ XCreatePixmap (display, w, width, height, depth) | |||
| 776 | 768 | ||
| 777 | Pixmap | 769 | Pixmap |
| 778 | XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth) | 770 | XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth) |
| 779 | Display *display; /* not used */ | 771 | Display *display; |
| 780 | WindowRef w; | 772 | WindowRef w; |
| 781 | char *data; | 773 | char *data; |
| 782 | unsigned int width, height; | 774 | unsigned int width, height; |
| @@ -787,7 +779,7 @@ XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth) | |||
| 787 | BitMap bitmap; | 779 | BitMap bitmap; |
| 788 | CGrafPtr old_port; | 780 | CGrafPtr old_port; |
| 789 | GDHandle old_gdh; | 781 | GDHandle old_gdh; |
| 790 | static GC gc = NULL; /* not reentrant */ | 782 | static GC gc = NULL; |
| 791 | 783 | ||
| 792 | if (gc == NULL) | 784 | if (gc == NULL) |
| 793 | gc = XCreateGC (display, w, 0, NULL); | 785 | gc = XCreateGC (display, w, 0, NULL); |
| @@ -819,6 +811,15 @@ XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth) | |||
| 819 | } | 811 | } |
| 820 | 812 | ||
| 821 | 813 | ||
| 814 | void | ||
| 815 | XFreePixmap (display, pixmap) | ||
| 816 | Display *display; | ||
| 817 | Pixmap pixmap; | ||
| 818 | { | ||
| 819 | DisposeGWorld (pixmap); | ||
| 820 | } | ||
| 821 | |||
| 822 | |||
| 822 | /* Mac replacement for XFillRectangle. */ | 823 | /* Mac replacement for XFillRectangle. */ |
| 823 | 824 | ||
| 824 | static void | 825 | static void |
| @@ -838,12 +839,9 @@ mac_fill_rectangle (f, gc, x, y, width, height) | |||
| 838 | #else | 839 | #else |
| 839 | Rect r; | 840 | Rect r; |
| 840 | 841 | ||
| 841 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 842 | mac_begin_clip (f, gc); |
| 842 | |||
| 843 | RGBForeColor (GC_FORE_COLOR (gc)); | 843 | RGBForeColor (GC_FORE_COLOR (gc)); |
| 844 | SetRect (&r, x, y, x + width, y + height); | 844 | SetRect (&r, x, y, x + width, y + height); |
| 845 | |||
| 846 | mac_begin_clip (gc); | ||
| 847 | PaintRect (&r); /* using foreground color of gc */ | 845 | PaintRect (&r); /* using foreground color of gc */ |
| 848 | mac_end_clip (gc); | 846 | mac_end_clip (gc); |
| 849 | #endif | 847 | #endif |
| @@ -870,18 +868,34 @@ mac_draw_rectangle (f, gc, x, y, width, height) | |||
| 870 | #else | 868 | #else |
| 871 | Rect r; | 869 | Rect r; |
| 872 | 870 | ||
| 873 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 871 | mac_begin_clip (f, gc); |
| 874 | |||
| 875 | RGBForeColor (GC_FORE_COLOR (gc)); | 872 | RGBForeColor (GC_FORE_COLOR (gc)); |
| 876 | SetRect (&r, x, y, x + width + 1, y + height + 1); | 873 | SetRect (&r, x, y, x + width + 1, y + height + 1); |
| 877 | |||
| 878 | mac_begin_clip (gc); | ||
| 879 | FrameRect (&r); /* using foreground color of gc */ | 874 | FrameRect (&r); /* using foreground color of gc */ |
| 880 | mac_end_clip (gc); | 875 | mac_end_clip (gc); |
| 881 | #endif | 876 | #endif |
| 882 | } | 877 | } |
| 883 | 878 | ||
| 884 | 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 | |||
| 885 | #if USE_ATSUI | 899 | #if USE_ATSUI |
| 886 | static OSStatus | 900 | static OSStatus |
| 887 | 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) |
| @@ -891,7 +905,7 @@ atsu_get_text_layout_with_text_ptr (text, text_length, style, text_layout) | |||
| 891 | ATSUTextLayout *text_layout; | 905 | ATSUTextLayout *text_layout; |
| 892 | { | 906 | { |
| 893 | OSStatus err; | 907 | OSStatus err; |
| 894 | static ATSUTextLayout saved_text_layout = NULL; /* not reentrant */ | 908 | static ATSUTextLayout saved_text_layout = NULL; |
| 895 | 909 | ||
| 896 | if (saved_text_layout == NULL) | 910 | if (saved_text_layout == NULL) |
| 897 | { | 911 | { |
| @@ -918,7 +932,6 @@ atsu_get_text_layout_with_text_ptr (text, text_length, style, text_layout) | |||
| 918 | err = ATSUSetLayoutControls (saved_text_layout, | 932 | err = ATSUSetLayoutControls (saved_text_layout, |
| 919 | sizeof (tags) / sizeof (tags[0]), | 933 | sizeof (tags) / sizeof (tags[0]), |
| 920 | tags, sizes, values); | 934 | tags, sizes, values); |
| 921 | /* XXX: Should we do this? */ | ||
| 922 | if (err == noErr) | 935 | if (err == noErr) |
| 923 | err = ATSUSetTransientFontMatching (saved_text_layout, true); | 936 | err = ATSUSetTransientFontMatching (saved_text_layout, true); |
| 924 | } | 937 | } |
| @@ -937,224 +950,224 @@ atsu_get_text_layout_with_text_ptr (text, text_length, style, text_layout) | |||
| 937 | *text_layout = saved_text_layout; | 950 | *text_layout = saved_text_layout; |
| 938 | return err; | 951 | return err; |
| 939 | } | 952 | } |
| 940 | #endif | ||
| 941 | 953 | ||
| 942 | 954 | ||
| 943 | static void | 955 | static void |
| 944 | mac_invert_rectangle (f, x, y, width, height) | 956 | mac_draw_image_string_atsui (f, gc, x, y, buf, nchars, bg_width, |
| 945 | struct frame *f; | 957 | overstrike_p, bytes_per_char) |
| 946 | int x, y; | ||
| 947 | unsigned int width, height; | ||
| 948 | { | ||
| 949 | Rect r; | ||
| 950 | |||
| 951 | #if USE_CG_DRAWING | ||
| 952 | mac_prepare_for_quickdraw (f); | ||
| 953 | #endif | ||
| 954 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | ||
| 955 | |||
| 956 | SetRect (&r, x, y, x + width, y + height); | ||
| 957 | |||
| 958 | InvertRect (&r); | ||
| 959 | } | ||
| 960 | |||
| 961 | |||
| 962 | static void | ||
| 963 | mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width, | ||
| 964 | overstrike_p, bytes_per_char) | ||
| 965 | struct frame *f; | 958 | struct frame *f; |
| 966 | GC gc; | 959 | GC gc; |
| 967 | int x, y; | 960 | int x, y; |
| 968 | char *buf; | 961 | char *buf; |
| 969 | int nchars, bg_width, overstrike_p, bytes_per_char; | 962 | int nchars, bg_width, overstrike_p, bytes_per_char; |
| 970 | { | 963 | { |
| 971 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 964 | OSStatus err; |
| 972 | 965 | ATSUTextLayout text_layout; | |
| 973 | #if USE_ATSUI | ||
| 974 | if (GC_FONT (gc)->mac_style) | ||
| 975 | { | ||
| 976 | OSStatus err; | ||
| 977 | ATSUTextLayout text_layout; | ||
| 978 | 966 | ||
| 979 | xassert (bytes_per_char == 2); | 967 | xassert (bytes_per_char == 2); |
| 980 | 968 | ||
| 981 | #ifndef WORDS_BIG_ENDIAN | 969 | #ifndef WORDS_BIG_ENDIAN |
| 982 | { | 970 | { |
| 983 | int i; | 971 | int i; |
| 984 | UniChar *text = (UniChar *)buf; | 972 | UniChar *text = (UniChar *)buf; |
| 985 | 973 | ||
| 986 | for (i = 0; i < nchars; i++) | 974 | for (i = 0; i < nchars; i++) |
| 987 | text[i] = EndianU16_BtoN (text[i]); | 975 | text[i] = EndianU16_BtoN (text[i]); |
| 988 | } | 976 | } |
| 989 | #endif | 977 | #endif |
| 990 | err = atsu_get_text_layout_with_text_ptr ((ConstUniCharArrayPtr)buf, | 978 | err = atsu_get_text_layout_with_text_ptr ((ConstUniCharArrayPtr)buf, |
| 991 | nchars, | 979 | nchars, |
| 992 | GC_FONT (gc)->mac_style, | 980 | GC_FONT (gc)->mac_style, |
| 993 | &text_layout); | 981 | &text_layout); |
| 994 | if (err != noErr) | 982 | if (err != noErr) |
| 995 | return; | 983 | return; |
| 996 | #ifdef MAC_OSX | 984 | #ifdef MAC_OSX |
| 997 | if (!mac_use_core_graphics) | 985 | if (!mac_use_core_graphics) |
| 998 | { | 986 | { |
| 999 | #endif | ||
| 1000 | #if USE_CG_DRAWING | ||
| 1001 | mac_prepare_for_quickdraw (f); | ||
| 1002 | #endif | 987 | #endif |
| 1003 | mac_begin_clip (gc); | 988 | mac_begin_clip (f, gc); |
| 1004 | RGBForeColor (GC_FORE_COLOR (gc)); | 989 | RGBForeColor (GC_FORE_COLOR (gc)); |
| 1005 | if (bg_width) | 990 | if (bg_width) |
| 1006 | { | 991 | { |
| 1007 | Rect r; | 992 | Rect r; |
| 1008 | 993 | ||
| 1009 | SetRect (&r, x, y - FONT_BASE (GC_FONT (gc)), | 994 | SetRect (&r, x, y - FONT_BASE (GC_FONT (gc)), |
| 1010 | x + bg_width, y + FONT_DESCENT (GC_FONT (gc))); | 995 | x + bg_width, y + FONT_DESCENT (GC_FONT (gc))); |
| 1011 | RGBBackColor (GC_BACK_COLOR (gc)); | 996 | RGBBackColor (GC_BACK_COLOR (gc)); |
| 1012 | EraseRect (&r); | 997 | EraseRect (&r); |
| 1013 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 998 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 1014 | } | 999 | } |
| 1015 | 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); | ||
| 1016 | ATSUDrawText (text_layout, | 1007 | ATSUDrawText (text_layout, |
| 1017 | kATSUFromTextBeginning, kATSUToTextEnd, | 1008 | kATSUFromTextBeginning, kATSUToTextEnd, |
| 1018 | kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); | 1009 | kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); |
| 1019 | if (overstrike_p) | ||
| 1020 | { | ||
| 1021 | MoveTo (x + 1, y); | ||
| 1022 | ATSUDrawText (text_layout, | ||
| 1023 | kATSUFromTextBeginning, kATSUToTextEnd, | ||
| 1024 | kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); | ||
| 1025 | } | ||
| 1026 | mac_end_clip (gc); | ||
| 1027 | #ifdef MAC_OSX | ||
| 1028 | } | 1010 | } |
| 1029 | else | 1011 | mac_end_clip (gc); |
| 1030 | { | 1012 | #ifdef MAC_OSX |
| 1031 | CGrafPtr port; | 1013 | } |
| 1032 | static CGContextRef context; | 1014 | else |
| 1033 | float port_height = FRAME_PIXEL_HEIGHT (f); | 1015 | { |
| 1034 | static const ATSUAttributeTag tags[] = {kATSUCGContextTag}; | 1016 | static CGContextRef context; |
| 1035 | static const ByteCount sizes[] = {sizeof (CGContextRef)}; | 1017 | float port_height = FRAME_PIXEL_HEIGHT (f); |
| 1036 | static const ATSUAttributeValuePtr values[] = {&context}; | 1018 | static const ATSUAttributeTag tags[] = {kATSUCGContextTag}; |
| 1019 | static const ByteCount sizes[] = {sizeof (CGContextRef)}; | ||
| 1020 | static const ATSUAttributeValuePtr values[] = {&context}; | ||
| 1037 | 1021 | ||
| 1038 | #if USE_CG_DRAWING | 1022 | #if USE_CG_DRAWING |
| 1039 | context = mac_begin_cg_clip (f, gc); | 1023 | context = mac_begin_cg_clip (f, gc); |
| 1040 | #else | 1024 | #else |
| 1041 | GetPort (&port); | 1025 | CGrafPtr port; |
| 1042 | QDBeginCGContext (port, &context); | 1026 | |
| 1043 | if (gc->n_clip_rects || bg_width) | 1027 | GetPort (&port); |
| 1044 | { | 1028 | QDBeginCGContext (port, &context); |
| 1045 | CGContextTranslateCTM (context, 0, port_height); | 1029 | if (gc->n_clip_rects || bg_width) |
| 1046 | CGContextScaleCTM (context, 1, -1); | 1030 | { |
| 1047 | if (gc->n_clip_rects) | 1031 | CGContextTranslateCTM (context, 0, port_height); |
| 1048 | CGContextClipToRects (context, gc->clip_rects, | 1032 | CGContextScaleCTM (context, 1, -1); |
| 1049 | gc->n_clip_rects); | 1033 | if (gc->n_clip_rects) |
| 1050 | #endif | 1034 | CGContextClipToRects (context, gc->clip_rects, |
| 1051 | if (bg_width) | 1035 | gc->n_clip_rects); |
| 1052 | { | ||
| 1053 | CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc); | ||
| 1054 | CGContextFillRect | ||
| 1055 | (context, | ||
| 1056 | CGRectMake (x, y - FONT_BASE (GC_FONT (gc)), | ||
| 1057 | bg_width, FONT_HEIGHT (GC_FONT (gc)))); | ||
| 1058 | } | ||
| 1059 | CGContextScaleCTM (context, 1, -1); | ||
| 1060 | CGContextTranslateCTM (context, 0, -port_height); | ||
| 1061 | #if !USE_CG_DRAWING | ||
| 1062 | } | ||
| 1063 | #endif | 1036 | #endif |
| 1064 | CG_SET_FILL_COLOR_WITH_GC_FOREGROUND (context, gc); | 1037 | if (bg_width) |
| 1065 | err = ATSUSetLayoutControls (text_layout, | ||
| 1066 | sizeof (tags) / sizeof (tags[0]), | ||
| 1067 | tags, sizes, values); | ||
| 1068 | if (err == noErr) | ||
| 1069 | { | 1038 | { |
| 1070 | ATSUDrawText (text_layout, | 1039 | CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc); |
| 1071 | kATSUFromTextBeginning, kATSUToTextEnd, | 1040 | CGContextFillRect (context, |
| 1072 | Long2Fix (x), Long2Fix (port_height - y)); | 1041 | CGRectMake (x, y - FONT_BASE (GC_FONT (gc)), |
| 1073 | if (overstrike_p) | 1042 | bg_width, |
| 1074 | ATSUDrawText (text_layout, | 1043 | FONT_HEIGHT (GC_FONT (gc)))); |
| 1075 | kATSUFromTextBeginning, kATSUToTextEnd, | ||
| 1076 | Long2Fix (x + 1), Long2Fix (port_height - y)); | ||
| 1077 | } | 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 | } | ||
| 1078 | #if USE_CG_DRAWING | 1064 | #if USE_CG_DRAWING |
| 1079 | mac_end_cg_clip (f); | 1065 | mac_end_cg_clip (f); |
| 1080 | context = NULL; | 1066 | context = NULL; |
| 1081 | #else | 1067 | #else |
| 1082 | CGContextSynchronize (context); | 1068 | CGContextSynchronize (context); |
| 1083 | QDEndCGContext (port, &context); | 1069 | QDEndCGContext (port, &context); |
| 1084 | #endif | 1070 | #endif |
| 1085 | #if 0 | 1071 | #if 0 |
| 1086 | /* This doesn't work on Mac OS X 10.1. */ | 1072 | /* This doesn't work on Mac OS X 10.1. */ |
| 1087 | ATSUClearLayoutControls (text_layout, | 1073 | ATSUClearLayoutControls (text_layout, |
| 1088 | sizeof (tags) / sizeof (tags[0]), tags); | 1074 | sizeof (tags) / sizeof (tags[0]), tags); |
| 1089 | #else | 1075 | #else |
| 1090 | ATSUSetLayoutControls (text_layout, | 1076 | ATSUSetLayoutControls (text_layout, |
| 1091 | sizeof (tags) / sizeof (tags[0]), | 1077 | sizeof (tags) / sizeof (tags[0]), |
| 1092 | tags, sizes, values); | 1078 | tags, sizes, values); |
| 1093 | #endif | 1079 | #endif |
| 1094 | } | ||
| 1095 | #endif /* MAC_OSX */ | ||
| 1096 | } | 1080 | } |
| 1097 | else | 1081 | #endif /* MAC_OSX */ |
| 1082 | } | ||
| 1098 | #endif /* USE_ATSUI */ | 1083 | #endif /* USE_ATSUI */ |
| 1099 | { | ||
| 1100 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | ||
| 1101 | UInt32 savedFlags; | ||
| 1102 | 1084 | ||
| 1103 | if (mac_use_core_graphics) | 1085 | |
| 1104 | 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; | ||
| 1105 | #endif | 1097 | #endif |
| 1106 | #if USE_CG_DRAWING | 1098 | |
| 1107 | 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); | ||
| 1108 | #endif | 1103 | #endif |
| 1109 | mac_begin_clip (gc); | 1104 | RGBForeColor (GC_FORE_COLOR (gc)); |
| 1110 | RGBForeColor (GC_FORE_COLOR (gc)); | ||
| 1111 | #ifdef MAC_OS8 | 1105 | #ifdef MAC_OS8 |
| 1112 | if (bg_width) | 1106 | if (bg_width) |
| 1113 | { | 1107 | { |
| 1114 | RGBBackColor (GC_BACK_COLOR (gc)); | 1108 | RGBBackColor (GC_BACK_COLOR (gc)); |
| 1115 | TextMode (srcCopy); | 1109 | TextMode (srcCopy); |
| 1116 | } | 1110 | } |
| 1117 | else | 1111 | else |
| 1118 | TextMode (srcOr); | 1112 | TextMode (srcOr); |
| 1119 | #else | 1113 | #else |
| 1120 | /* 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 |
| 1121 | because: | 1115 | because: |
| 1122 | - Screen is double-buffered. (In srcCopy mode, a text is | 1116 | - Screen is double-buffered. (In srcCopy mode, a text is drawn |
| 1123 | drawn into an offscreen graphics world first. So | 1117 | into an offscreen graphics world first. So performance gain |
| 1124 | performance gain cannot be expected.) | 1118 | cannot be expected.) |
| 1125 | - It lowers rendering quality. | 1119 | - It lowers rendering quality. |
| 1126 | - Some fonts leave garbage on cursor movement. */ | 1120 | - Some fonts leave garbage on cursor movement. */ |
| 1127 | if (bg_width) | 1121 | if (bg_width) |
| 1128 | { | 1122 | { |
| 1129 | Rect r; | 1123 | Rect r; |
| 1130 | 1124 | ||
| 1131 | RGBBackColor (GC_BACK_COLOR (gc)); | 1125 | RGBBackColor (GC_BACK_COLOR (gc)); |
| 1132 | SetRect (&r, x, y - FONT_BASE (GC_FONT (gc)), | 1126 | SetRect (&r, x, y - FONT_BASE (GC_FONT (gc)), |
| 1133 | x + bg_width, y + FONT_DESCENT (GC_FONT (gc))); | 1127 | x + bg_width, y + FONT_DESCENT (GC_FONT (gc))); |
| 1134 | EraseRect (&r); | 1128 | EraseRect (&r); |
| 1135 | } | 1129 | } |
| 1136 | TextMode (srcOr); | 1130 | TextMode (srcOr); |
| 1137 | #endif | 1131 | #endif |
| 1138 | TextFont (GC_FONT (gc)->mac_fontnum); | 1132 | TextFont (GC_FONT (gc)->mac_fontnum); |
| 1139 | TextSize (GC_FONT (gc)->mac_fontsize); | 1133 | TextSize (GC_FONT (gc)->mac_fontsize); |
| 1140 | TextFace (GC_FONT (gc)->mac_fontface); | 1134 | TextFace (GC_FONT (gc)->mac_fontface); |
| 1141 | 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); | ||
| 1142 | DrawText (buf, 0, nchars * bytes_per_char); | 1141 | DrawText (buf, 0, nchars * bytes_per_char); |
| 1143 | if (overstrike_p) | 1142 | } |
| 1144 | { | 1143 | if (bg_width) |
| 1145 | TextMode (srcOr); | 1144 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 1146 | MoveTo (x + 1, y); | 1145 | mac_end_clip (gc); |
| 1147 | DrawText (buf, 0, nchars * bytes_per_char); | ||
| 1148 | } | ||
| 1149 | if (bg_width) | ||
| 1150 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | ||
| 1151 | mac_end_clip (gc); | ||
| 1152 | 1146 | ||
| 1153 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | 1147 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 |
| 1154 | if (mac_use_core_graphics) | 1148 | if (mac_use_core_graphics) |
| 1155 | SwapQDTextFlags(savedFlags); | 1149 | SwapQDTextFlags(savedFlags); |
| 1156 | #endif | 1150 | #endif |
| 1157 | } | 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); | ||
| 1158 | } | 1171 | } |
| 1159 | 1172 | ||
| 1160 | 1173 | ||
| @@ -1371,7 +1384,6 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p) | |||
| 1371 | XChar2b *buf; | 1384 | XChar2b *buf; |
| 1372 | int nchars, bg_width, overstrike_p; | 1385 | int nchars, bg_width, overstrike_p; |
| 1373 | { | 1386 | { |
| 1374 | CGrafPtr port; | ||
| 1375 | float port_height, gx, gy; | 1387 | float port_height, gx, gy; |
| 1376 | int i; | 1388 | int i; |
| 1377 | CGContextRef context; | 1389 | CGContextRef context; |
| @@ -1381,7 +1393,6 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p) | |||
| 1381 | if (!mac_use_core_graphics || GC_FONT (gc)->cg_font == NULL) | 1393 | if (!mac_use_core_graphics || GC_FONT (gc)->cg_font == NULL) |
| 1382 | return 0; | 1394 | return 0; |
| 1383 | 1395 | ||
| 1384 | port = GetWindowPort (FRAME_MAC_WINDOW (f)); | ||
| 1385 | port_height = FRAME_PIXEL_HEIGHT (f); | 1396 | port_height = FRAME_PIXEL_HEIGHT (f); |
| 1386 | gx = x; | 1397 | gx = x; |
| 1387 | gy = port_height - y; | 1398 | gy = port_height - y; |
| @@ -1402,7 +1413,7 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p) | |||
| 1402 | #if USE_CG_DRAWING | 1413 | #if USE_CG_DRAWING |
| 1403 | context = mac_begin_cg_clip (f, gc); | 1414 | context = mac_begin_cg_clip (f, gc); |
| 1404 | #else | 1415 | #else |
| 1405 | QDBeginCGContext (port, &context); | 1416 | QDBeginCGContext (GetWindowPort (FRAME_MAC_WINDOW (f)), &context); |
| 1406 | if (gc->n_clip_rects || bg_width) | 1417 | if (gc->n_clip_rects || bg_width) |
| 1407 | { | 1418 | { |
| 1408 | CGContextTranslateCTM (context, 0, port_height); | 1419 | CGContextTranslateCTM (context, 0, port_height); |
| @@ -1442,7 +1453,7 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p) | |||
| 1442 | } | 1453 | } |
| 1443 | } | 1454 | } |
| 1444 | #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020 | 1455 | #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020 |
| 1445 | else | 1456 | else /* CGContextShowGlyphsWithAdvances == NULL */ |
| 1446 | #endif | 1457 | #endif |
| 1447 | #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */ | 1458 | #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */ |
| 1448 | #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 |
| @@ -1460,7 +1471,7 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p) | |||
| 1460 | mac_end_cg_clip (f); | 1471 | mac_end_cg_clip (f); |
| 1461 | #else | 1472 | #else |
| 1462 | CGContextSynchronize (context); | 1473 | CGContextSynchronize (context); |
| 1463 | QDEndCGContext (port, &context); | 1474 | QDEndCGContext (GetWindowPort (FRAME_MAC_WINDOW (f)), &context); |
| 1464 | #endif | 1475 | #endif |
| 1465 | 1476 | ||
| 1466 | return 1; | 1477 | return 1; |
| @@ -1482,7 +1493,7 @@ mac_copy_area (src, f, gc, src_x, src_y, width, height, dest_x, dest_y) | |||
| 1482 | { | 1493 | { |
| 1483 | Rect src_r, dest_r; | 1494 | Rect src_r, dest_r; |
| 1484 | 1495 | ||
| 1485 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 1496 | mac_begin_clip (f, gc); |
| 1486 | 1497 | ||
| 1487 | 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); |
| 1488 | 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); |
| @@ -1490,7 +1501,6 @@ mac_copy_area (src, f, gc, src_x, src_y, width, height, dest_x, dest_y) | |||
| 1490 | ForeColor (blackColor); | 1501 | ForeColor (blackColor); |
| 1491 | BackColor (whiteColor); | 1502 | BackColor (whiteColor); |
| 1492 | 1503 | ||
| 1493 | mac_begin_clip (gc); | ||
| 1494 | LockPixels (GetGWorldPixMap (src)); | 1504 | LockPixels (GetGWorldPixMap (src)); |
| 1495 | #if TARGET_API_MAC_CARBON | 1505 | #if TARGET_API_MAC_CARBON |
| 1496 | { | 1506 | { |
| @@ -1508,9 +1518,10 @@ mac_copy_area (src, f, gc, src_x, src_y, width, height, dest_x, dest_y) | |||
| 1508 | &src_r, &dest_r, srcCopy, 0); | 1518 | &src_r, &dest_r, srcCopy, 0); |
| 1509 | #endif /* not TARGET_API_MAC_CARBON */ | 1519 | #endif /* not TARGET_API_MAC_CARBON */ |
| 1510 | UnlockPixels (GetGWorldPixMap (src)); | 1520 | UnlockPixels (GetGWorldPixMap (src)); |
| 1511 | mac_end_clip (gc); | ||
| 1512 | 1521 | ||
| 1513 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 1522 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 1523 | |||
| 1524 | mac_end_clip (gc); | ||
| 1514 | } | 1525 | } |
| 1515 | 1526 | ||
| 1516 | 1527 | ||
| @@ -1526,7 +1537,7 @@ mac_copy_area_with_mask (src, mask, f, gc, src_x, src_y, | |||
| 1526 | { | 1537 | { |
| 1527 | Rect src_r, dest_r; | 1538 | Rect src_r, dest_r; |
| 1528 | 1539 | ||
| 1529 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 1540 | mac_begin_clip (f, gc); |
| 1530 | 1541 | ||
| 1531 | 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); |
| 1532 | 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); |
| @@ -1534,7 +1545,6 @@ mac_copy_area_with_mask (src, mask, f, gc, src_x, src_y, | |||
| 1534 | ForeColor (blackColor); | 1545 | ForeColor (blackColor); |
| 1535 | BackColor (whiteColor); | 1546 | BackColor (whiteColor); |
| 1536 | 1547 | ||
| 1537 | mac_begin_clip (gc); | ||
| 1538 | LockPixels (GetGWorldPixMap (src)); | 1548 | LockPixels (GetGWorldPixMap (src)); |
| 1539 | LockPixels (GetGWorldPixMap (mask)); | 1549 | LockPixels (GetGWorldPixMap (mask)); |
| 1540 | #if TARGET_API_MAC_CARBON | 1550 | #if TARGET_API_MAC_CARBON |
| @@ -1554,9 +1564,10 @@ mac_copy_area_with_mask (src, mask, f, gc, src_x, src_y, | |||
| 1554 | #endif /* not TARGET_API_MAC_CARBON */ | 1564 | #endif /* not TARGET_API_MAC_CARBON */ |
| 1555 | UnlockPixels (GetGWorldPixMap (mask)); | 1565 | UnlockPixels (GetGWorldPixMap (mask)); |
| 1556 | UnlockPixels (GetGWorldPixMap (src)); | 1566 | UnlockPixels (GetGWorldPixMap (src)); |
| 1557 | mac_end_clip (gc); | ||
| 1558 | 1567 | ||
| 1559 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 1568 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 1569 | |||
| 1570 | mac_end_clip (gc); | ||
| 1560 | } | 1571 | } |
| 1561 | #endif /* !USE_CG_DRAWING */ | 1572 | #endif /* !USE_CG_DRAWING */ |
| 1562 | 1573 | ||
| @@ -1587,7 +1598,7 @@ mac_scroll_area (f, gc, src_x, src_y, width, height, dest_x, dest_y) | |||
| 1587 | Rect src_r, dest_r; | 1598 | Rect src_r, dest_r; |
| 1588 | WindowRef w = FRAME_MAC_WINDOW (f); | 1599 | WindowRef w = FRAME_MAC_WINDOW (f); |
| 1589 | 1600 | ||
| 1590 | SetPort (w); | 1601 | mac_begin_clip (f, gc); |
| 1591 | 1602 | ||
| 1592 | 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); |
| 1593 | 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); |
| @@ -1596,11 +1607,11 @@ mac_scroll_area (f, gc, src_x, src_y, width, height, dest_x, dest_y) | |||
| 1596 | color mapping in CopyBits. Otherwise, it will be slow. */ | 1607 | color mapping in CopyBits. Otherwise, it will be slow. */ |
| 1597 | ForeColor (blackColor); | 1608 | ForeColor (blackColor); |
| 1598 | BackColor (whiteColor); | 1609 | BackColor (whiteColor); |
| 1599 | mac_begin_clip (gc); | ||
| 1600 | CopyBits (&(w->portBits), &(w->portBits), &src_r, &dest_r, srcCopy, 0); | 1610 | CopyBits (&(w->portBits), &(w->portBits), &src_r, &dest_r, srcCopy, 0); |
| 1601 | mac_end_clip (gc); | ||
| 1602 | 1611 | ||
| 1603 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); | 1612 | RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); |
| 1613 | |||
| 1614 | mac_end_clip (gc); | ||
| 1604 | #endif /* not TARGET_API_MAC_CARBON */ | 1615 | #endif /* not TARGET_API_MAC_CARBON */ |
| 1605 | } | 1616 | } |
| 1606 | 1617 | ||
| @@ -4608,8 +4619,14 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time) | |||
| 4608 | the frame are divided into. */ | 4619 | the frame are divided into. */ |
| 4609 | Point mouse_pos; | 4620 | Point mouse_pos; |
| 4610 | 4621 | ||
| 4622 | #if TARGET_API_MAC_CARBON | ||
| 4623 | GetGlobalMouse (&mouse_pos); | ||
| 4624 | mouse_pos.h -= f1->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f1); | ||
| 4625 | mouse_pos.v -= f1->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f1); | ||
| 4626 | #else | ||
| 4611 | SetPortWindowPort (FRAME_MAC_WINDOW (f1)); | 4627 | SetPortWindowPort (FRAME_MAC_WINDOW (f1)); |
| 4612 | GetMouse (&mouse_pos); | 4628 | GetMouse (&mouse_pos); |
| 4629 | #endif | ||
| 4613 | remember_mouse_glyph (f1, mouse_pos.h, mouse_pos.v, | 4630 | remember_mouse_glyph (f1, mouse_pos.h, mouse_pos.v, |
| 4614 | &last_mouse_glyph); | 4631 | &last_mouse_glyph); |
| 4615 | last_mouse_glyph_frame = f1; | 4632 | last_mouse_glyph_frame = f1; |
| @@ -5511,9 +5528,14 @@ x_scroll_bar_report_motion (fp, bar_window, part, x, y, time) | |||
| 5511 | struct frame *f = mac_window_to_frame (wp); | 5528 | struct frame *f = mac_window_to_frame (wp); |
| 5512 | int win_y, top_range; | 5529 | int win_y, top_range; |
| 5513 | 5530 | ||
| 5531 | #if TARGET_API_MAC_CARBON | ||
| 5532 | GetGlobalMouse (&mouse_pos); | ||
| 5533 | mouse_pos.h -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); | ||
| 5534 | mouse_pos.v -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); | ||
| 5535 | #else | ||
| 5514 | SetPortWindowPort (wp); | 5536 | SetPortWindowPort (wp); |
| 5515 | |||
| 5516 | GetMouse (&mouse_pos); | 5537 | GetMouse (&mouse_pos); |
| 5538 | #endif | ||
| 5517 | 5539 | ||
| 5518 | win_y = mouse_pos.v - XINT (bar->top); | 5540 | win_y = mouse_pos.v - XINT (bar->top); |
| 5519 | top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); | 5541 | top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); |
| @@ -6264,17 +6286,11 @@ x_set_mouse_pixel_position (f, pix_x, pix_y) | |||
| 6264 | int pix_x, pix_y; | 6286 | int pix_x, pix_y; |
| 6265 | { | 6287 | { |
| 6266 | #ifdef MAC_OSX | 6288 | #ifdef MAC_OSX |
| 6267 | Point p; | 6289 | pix_x += f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); |
| 6268 | CGPoint point; | 6290 | pix_y += f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); |
| 6269 | 6291 | ||
| 6270 | BLOCK_INPUT; | 6292 | BLOCK_INPUT; |
| 6271 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 6293 | CGWarpMouseCursorPosition (CGPointMake (pix_x, pix_y)); |
| 6272 | p.h = pix_x; | ||
| 6273 | p.v = pix_y; | ||
| 6274 | LocalToGlobal (&p); | ||
| 6275 | point.x = p.h; | ||
| 6276 | point.y = p.v; | ||
| 6277 | CGWarpMouseCursorPosition (point); | ||
| 6278 | UNBLOCK_INPUT; | 6294 | UNBLOCK_INPUT; |
| 6279 | #else | 6295 | #else |
| 6280 | #if 0 /* MAC_TODO: LMSetMouseLocation and CursorDeviceMoveTo are non-Carbon */ | 6296 | #if 0 /* MAC_TODO: LMSetMouseLocation and CursorDeviceMoveTo are non-Carbon */ |
| @@ -6424,30 +6440,7 @@ x_make_frame_visible (f) | |||
| 6424 | before the window gets really visible. */ | 6440 | before the window gets really visible. */ |
| 6425 | if (! FRAME_ICONIFIED_P (f) | 6441 | if (! FRAME_ICONIFIED_P (f) |
| 6426 | && ! f->output_data.mac->asked_for_visible) | 6442 | && ! f->output_data.mac->asked_for_visible) |
| 6427 | { | 6443 | x_set_offset (f, f->left_pos, f->top_pos, 0); |
| 6428 | #if TARGET_API_MAC_CARBON | ||
| 6429 | if (!(FRAME_SIZE_HINTS (f)->flags & (USPosition | PPosition))) | ||
| 6430 | { | ||
| 6431 | struct frame *sf = SELECTED_FRAME (); | ||
| 6432 | if (!FRAME_MAC_P (sf)) | ||
| 6433 | RepositionWindow (FRAME_MAC_WINDOW (f), NULL, | ||
| 6434 | kWindowCenterOnMainScreen); | ||
| 6435 | else | ||
| 6436 | RepositionWindow (FRAME_MAC_WINDOW (f), | ||
| 6437 | FRAME_MAC_WINDOW (sf), | ||
| 6438 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | ||
| 6439 | kWindowCascadeStartAtParentWindowScreen | ||
| 6440 | #else | ||
| 6441 | kWindowCascadeOnParentWindowScreen | ||
| 6442 | #endif | ||
| 6443 | ); | ||
| 6444 | if (!NILP (tip_frame) && f == XFRAME (tip_frame)) | ||
| 6445 | mac_handle_origin_change (f); | ||
| 6446 | } | ||
| 6447 | else | ||
| 6448 | #endif | ||
| 6449 | x_set_offset (f, f->left_pos, f->top_pos, 0); | ||
| 6450 | } | ||
| 6451 | 6444 | ||
| 6452 | f->output_data.mac->asked_for_visible = 1; | 6445 | f->output_data.mac->asked_for_visible = 1; |
| 6453 | 6446 | ||
| @@ -6521,12 +6514,14 @@ x_make_frame_invisible (f) | |||
| 6521 | 6514 | ||
| 6522 | BLOCK_INPUT; | 6515 | BLOCK_INPUT; |
| 6523 | 6516 | ||
| 6517 | #if !TARGET_API_MAC_CARBON | ||
| 6524 | /* Before unmapping the window, update the WM_SIZE_HINTS property to claim | 6518 | /* Before unmapping the window, update the WM_SIZE_HINTS property to claim |
| 6525 | that the current position of the window is user-specified, rather than | 6519 | that the current position of the window is user-specified, rather than |
| 6526 | program-specified, so that when the window is mapped again, it will be | 6520 | program-specified, so that when the window is mapped again, it will be |
| 6527 | placed at the same location, without forcing the user to position it | 6521 | placed at the same location, without forcing the user to position it |
| 6528 | by hand again (they have already done that once for this window.) */ | 6522 | by hand again (they have already done that once for this window.) */ |
| 6529 | x_wm_set_size_hint (f, (long) 0, 1); | 6523 | x_wm_set_size_hint (f, (long) 0, 1); |
| 6524 | #endif | ||
| 6530 | 6525 | ||
| 6531 | HideWindow (FRAME_MAC_WINDOW (f)); | 6526 | HideWindow (FRAME_MAC_WINDOW (f)); |
| 6532 | 6527 | ||
| @@ -8719,16 +8714,93 @@ x_find_ccl_program (fontp) | |||
| 8719 | possible. */ | 8714 | possible. */ |
| 8720 | static int font_panel_shown_p = 0; | 8715 | static int font_panel_shown_p = 0; |
| 8721 | 8716 | ||
| 8717 | extern Lisp_Object Qfont; | ||
| 8718 | static Lisp_Object Qpanel_closed, Qselection; | ||
| 8719 | |||
| 8720 | static OSStatus mac_store_event_ref_as_apple_event P_ ((AEEventClass, AEEventID, | ||
| 8721 | Lisp_Object, | ||
| 8722 | Lisp_Object, | ||
| 8723 | EventRef, UInt32, | ||
| 8724 | const EventParamName *, | ||
| 8725 | const EventParamType *)); | ||
| 8726 | |||
| 8722 | int | 8727 | int |
| 8723 | mac_font_panel_visible_p () | 8728 | mac_font_panel_visible_p () |
| 8724 | { | 8729 | { |
| 8725 | return font_panel_shown_p && FPIsFontPanelVisible (); | 8730 | return font_panel_shown_p && FPIsFontPanelVisible (); |
| 8726 | } | 8731 | } |
| 8727 | 8732 | ||
| 8733 | static pascal OSStatus | ||
| 8734 | mac_handle_font_event (next_handler, event, data) | ||
| 8735 | EventHandlerCallRef next_handler; | ||
| 8736 | EventRef event; | ||
| 8737 | void *data; | ||
| 8738 | { | ||
| 8739 | OSStatus result, err; | ||
| 8740 | Lisp_Object id_key; | ||
| 8741 | int num_params; | ||
| 8742 | const EventParamName *names; | ||
| 8743 | const EventParamType *types; | ||
| 8744 | static const EventParamName names_sel[] = {kEventParamATSUFontID, | ||
| 8745 | kEventParamATSUFontSize, | ||
| 8746 | kEventParamFMFontFamily, | ||
| 8747 | kEventParamFMFontSize, | ||
| 8748 | kEventParamFontColor}; | ||
| 8749 | static const EventParamType types_sel[] = {typeATSUFontID, | ||
| 8750 | typeATSUSize, | ||
| 8751 | typeFMFontFamily, | ||
| 8752 | typeFMFontSize, | ||
| 8753 | typeFontColor}; | ||
| 8754 | |||
| 8755 | result = CallNextEventHandler (next_handler, event); | ||
| 8756 | if (result != eventNotHandledErr) | ||
| 8757 | return result; | ||
| 8758 | |||
| 8759 | switch (GetEventKind (event)) | ||
| 8760 | { | ||
| 8761 | case kEventFontPanelClosed: | ||
| 8762 | id_key = Qpanel_closed; | ||
| 8763 | num_params = 0; | ||
| 8764 | names = NULL; | ||
| 8765 | types = NULL; | ||
| 8766 | break; | ||
| 8767 | |||
| 8768 | case kEventFontSelection: | ||
| 8769 | id_key = Qselection; | ||
| 8770 | num_params = sizeof (names_sel) / sizeof (names_sel[0]); | ||
| 8771 | names = names_sel; | ||
| 8772 | types = types_sel; | ||
| 8773 | break; | ||
| 8774 | } | ||
| 8775 | |||
| 8776 | err = mac_store_event_ref_as_apple_event (0, 0, Qfont, id_key, | ||
| 8777 | event, num_params, | ||
| 8778 | names, types); | ||
| 8779 | if (err == noErr) | ||
| 8780 | result = noErr; | ||
| 8781 | |||
| 8782 | return result; | ||
| 8783 | } | ||
| 8784 | |||
| 8728 | OSStatus | 8785 | OSStatus |
| 8729 | mac_show_hide_font_panel () | 8786 | mac_show_hide_font_panel () |
| 8730 | { | 8787 | { |
| 8731 | font_panel_shown_p = 1; | 8788 | if (!font_panel_shown_p) |
| 8789 | { | ||
| 8790 | OSStatus err; | ||
| 8791 | |||
| 8792 | static const EventTypeSpec specs[] = | ||
| 8793 | {{kEventClassFont, kEventFontPanelClosed}, | ||
| 8794 | {kEventClassFont, kEventFontSelection}}; | ||
| 8795 | |||
| 8796 | err = InstallApplicationEventHandler (mac_handle_font_event, | ||
| 8797 | GetEventTypeCount (specs), | ||
| 8798 | specs, NULL, NULL); | ||
| 8799 | if (err != noErr) | ||
| 8800 | return err; | ||
| 8801 | |||
| 8802 | font_panel_shown_p = 1; | ||
| 8803 | } | ||
| 8732 | 8804 | ||
| 8733 | return FPShowHideFontPanel (); | 8805 | return FPShowHideFontPanel (); |
| 8734 | } | 8806 | } |
| @@ -8875,10 +8947,6 @@ static Lisp_Object Qhi_command; | |||
| 8875 | extern Lisp_Object Qwindow; | 8947 | extern Lisp_Object Qwindow; |
| 8876 | static Lisp_Object Qtoolbar_switch_mode; | 8948 | static Lisp_Object Qtoolbar_switch_mode; |
| 8877 | #endif | 8949 | #endif |
| 8878 | #if USE_MAC_FONT_PANEL | ||
| 8879 | extern Lisp_Object Qfont; | ||
| 8880 | static Lisp_Object Qpanel_closed, Qselection; | ||
| 8881 | #endif | ||
| 8882 | #if USE_MAC_TSM | 8950 | #if USE_MAC_TSM |
| 8883 | static TSMDocumentID tsm_document_id; | 8951 | static TSMDocumentID tsm_document_id; |
| 8884 | static Lisp_Object Qtext_input; | 8952 | static Lisp_Object Qtext_input; |
| @@ -8890,7 +8958,7 @@ static Lisp_Object saved_ts_script_language_on_focus; | |||
| 8890 | static ScriptLanguageRecord saved_ts_language; | 8958 | static ScriptLanguageRecord saved_ts_language; |
| 8891 | static Component saved_ts_component; | 8959 | static Component saved_ts_component; |
| 8892 | #endif | 8960 | #endif |
| 8893 | #endif | 8961 | #endif /* TARGET_API_MAC_CARBON */ |
| 8894 | extern int mac_ready_for_apple_events; | 8962 | extern int mac_ready_for_apple_events; |
| 8895 | extern Lisp_Object Qundefined; | 8963 | extern Lisp_Object Qundefined; |
| 8896 | extern void init_apple_event_handler P_ ((void)); | 8964 | extern void init_apple_event_handler P_ ((void)); |
| @@ -8903,20 +8971,15 @@ extern OSErr init_coercion_handler P_ ((void)); | |||
| 8903 | extern OSErr install_drag_handler P_ ((WindowRef)); | 8971 | extern OSErr install_drag_handler P_ ((WindowRef)); |
| 8904 | extern void remove_drag_handler P_ ((WindowRef)); | 8972 | extern void remove_drag_handler P_ ((WindowRef)); |
| 8905 | 8973 | ||
| 8974 | #if TARGET_API_MAC_CARBON | ||
| 8906 | /* Showing help echo string during menu tracking */ | 8975 | /* Showing help echo string during menu tracking */ |
| 8907 | extern OSStatus install_menu_target_item_handler P_ ((WindowRef)); | 8976 | extern OSStatus install_menu_target_item_handler P_ ((void)); |
| 8908 | 8977 | ||
| 8909 | #if TARGET_API_MAC_CARBON | ||
| 8910 | #ifdef MAC_OSX | 8978 | #ifdef MAC_OSX |
| 8911 | extern void init_service_handler (); | 8979 | extern OSStatus install_service_handler (); |
| 8912 | static Lisp_Object Qservice, Qpaste, Qperform; | 8980 | static Lisp_Object Qservice, Qpaste, Qperform; |
| 8913 | #endif | 8981 | #endif |
| 8914 | |||
| 8915 | /* Window Event Handler */ | ||
| 8916 | static pascal OSStatus mac_handle_window_event (EventHandlerCallRef, | ||
| 8917 | EventRef, void *); | ||
| 8918 | #endif | 8982 | #endif |
| 8919 | OSStatus install_window_handler (WindowRef); | ||
| 8920 | 8983 | ||
| 8921 | extern void init_emacs_passwd_dir (); | 8984 | extern void init_emacs_passwd_dir (); |
| 8922 | extern int emacs_main (int, char **, char **); | 8985 | extern int emacs_main (int, char **, char **); |
| @@ -9115,11 +9178,13 @@ mac_quit_char_key_p (modifiers, key_code) | |||
| 9115 | static int | 9178 | static int |
| 9116 | mac_event_to_emacs_modifiers (EventRef eventRef) | 9179 | mac_event_to_emacs_modifiers (EventRef eventRef) |
| 9117 | { | 9180 | { |
| 9118 | UInt32 mods = 0; | 9181 | UInt32 mods = 0, class; |
| 9182 | |||
| 9119 | GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL, | 9183 | GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL, |
| 9120 | sizeof (UInt32), NULL, &mods); | 9184 | sizeof (UInt32), NULL, &mods); |
| 9185 | class = GetEventClass (eventRef); | ||
| 9121 | if (!NILP (Vmac_emulate_three_button_mouse) && | 9186 | if (!NILP (Vmac_emulate_three_button_mouse) && |
| 9122 | GetEventClass(eventRef) == kEventClassMouse) | 9187 | (class == kEventClassMouse || class == kEventClassCommand)) |
| 9123 | { | 9188 | { |
| 9124 | mods &= ~(optionKey | cmdKey); | 9189 | mods &= ~(optionKey | cmdKey); |
| 9125 | } | 9190 | } |
| @@ -9639,6 +9704,210 @@ do_zoom_window (WindowRef w, int zoom_in_or_out) | |||
| 9639 | #endif | 9704 | #endif |
| 9640 | } | 9705 | } |
| 9641 | 9706 | ||
| 9707 | static void | ||
| 9708 | mac_set_unicode_keystroke_event (code, buf) | ||
| 9709 | UniChar code; | ||
| 9710 | struct input_event *buf; | ||
| 9711 | { | ||
| 9712 | int charset_id, c1, c2; | ||
| 9713 | |||
| 9714 | if (code < 0x80) | ||
| 9715 | { | ||
| 9716 | buf->kind = ASCII_KEYSTROKE_EVENT; | ||
| 9717 | buf->code = code; | ||
| 9718 | } | ||
| 9719 | else if (code < 0x100) | ||
| 9720 | { | ||
| 9721 | if (code < 0xA0) | ||
| 9722 | charset_id = CHARSET_8_BIT_CONTROL; | ||
| 9723 | else | ||
| 9724 | charset_id = charset_latin_iso8859_1; | ||
| 9725 | buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT; | ||
| 9726 | buf->code = MAKE_CHAR (charset_id, code, 0); | ||
| 9727 | } | ||
| 9728 | else | ||
| 9729 | { | ||
| 9730 | if (code < 0x2500) | ||
| 9731 | charset_id = charset_mule_unicode_0100_24ff, | ||
| 9732 | code -= 0x100; | ||
| 9733 | else if (code < 0x33FF) | ||
| 9734 | charset_id = charset_mule_unicode_2500_33ff, | ||
| 9735 | code -= 0x2500; | ||
| 9736 | else if (code >= 0xE000) | ||
| 9737 | charset_id = charset_mule_unicode_e000_ffff, | ||
| 9738 | code -= 0xE000; | ||
| 9739 | c1 = (code / 96) + 32, c2 = (code % 96) + 32; | ||
| 9740 | buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT; | ||
| 9741 | buf->code = MAKE_CHAR (charset_id, c1, c2); | ||
| 9742 | } | ||
| 9743 | } | ||
| 9744 | |||
| 9745 | static void | ||
| 9746 | do_keystroke (action, char_code, key_code, modifiers, timestamp, buf) | ||
| 9747 | EventKind action; | ||
| 9748 | unsigned char char_code; | ||
| 9749 | UInt32 key_code, modifiers; | ||
| 9750 | unsigned long timestamp; | ||
| 9751 | struct input_event *buf; | ||
| 9752 | { | ||
| 9753 | static SInt16 last_key_script = -1; | ||
| 9754 | SInt16 current_key_script = GetScriptManagerVariable (smKeyScript); | ||
| 9755 | UInt32 mapped_modifiers = mac_mapped_modifiers (modifiers); | ||
| 9756 | |||
| 9757 | #ifdef MAC_OSX | ||
| 9758 | if (mapped_modifiers & kEventKeyModifierFnMask | ||
| 9759 | && key_code <= 0x7f | ||
| 9760 | && fn_keycode_to_keycode_table[key_code]) | ||
| 9761 | key_code = fn_keycode_to_keycode_table[key_code]; | ||
| 9762 | #endif | ||
| 9763 | |||
| 9764 | if (key_code <= 0x7f && keycode_to_xkeysym_table[key_code]) | ||
| 9765 | { | ||
| 9766 | buf->kind = NON_ASCII_KEYSTROKE_EVENT; | ||
| 9767 | buf->code = 0xff00 | keycode_to_xkeysym_table[key_code]; | ||
| 9768 | #ifdef MAC_OSX | ||
| 9769 | if (modifiers & kEventKeyModifierFnMask | ||
| 9770 | && key_code <= 0x7f | ||
| 9771 | && fn_keycode_to_keycode_table[key_code] == key_code) | ||
| 9772 | modifiers &= ~kEventKeyModifierFnMask; | ||
| 9773 | #endif | ||
| 9774 | } | ||
| 9775 | else if (mapped_modifiers) | ||
| 9776 | { | ||
| 9777 | /* translate the keycode back to determine the original key */ | ||
| 9778 | #ifdef MAC_OSX | ||
| 9779 | UCKeyboardLayout *uchr_ptr = NULL; | ||
| 9780 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | ||
| 9781 | OSStatus err; | ||
| 9782 | KeyboardLayoutRef layout; | ||
| 9783 | |||
| 9784 | err = KLGetCurrentKeyboardLayout (&layout); | ||
| 9785 | if (err == noErr) | ||
| 9786 | err = KLGetKeyboardLayoutProperty (layout, kKLuchrData, | ||
| 9787 | (const void **) &uchr_ptr); | ||
| 9788 | #else | ||
| 9789 | static SInt16 last_key_layout_id = 0; | ||
| 9790 | static Handle uchr_handle = (Handle)-1; | ||
| 9791 | SInt16 current_key_layout_id = | ||
| 9792 | GetScriptVariable (current_key_script, smScriptKeys); | ||
| 9793 | |||
| 9794 | if (uchr_handle == (Handle)-1 | ||
| 9795 | || last_key_layout_id != current_key_layout_id) | ||
| 9796 | { | ||
| 9797 | uchr_handle = GetResource ('uchr', current_key_layout_id); | ||
| 9798 | last_key_layout_id = current_key_layout_id; | ||
| 9799 | } | ||
| 9800 | if (uchr_handle) | ||
| 9801 | uchr_ptr = (UCKeyboardLayout *)*uchr_handle; | ||
| 9802 | #endif | ||
| 9803 | |||
| 9804 | if (uchr_ptr) | ||
| 9805 | { | ||
| 9806 | OSStatus status; | ||
| 9807 | UInt16 key_action = action - keyDown; | ||
| 9808 | UInt32 modifier_key_state = (modifiers & ~mapped_modifiers) >> 8; | ||
| 9809 | UInt32 keyboard_type = LMGetKbdType (); | ||
| 9810 | SInt32 dead_key_state = 0; | ||
| 9811 | UniChar code; | ||
| 9812 | UniCharCount actual_length; | ||
| 9813 | |||
| 9814 | status = UCKeyTranslate (uchr_ptr, key_code, key_action, | ||
| 9815 | modifier_key_state, keyboard_type, | ||
| 9816 | kUCKeyTranslateNoDeadKeysMask, | ||
| 9817 | &dead_key_state, | ||
| 9818 | 1, &actual_length, &code); | ||
| 9819 | if (status == noErr && actual_length == 1) | ||
| 9820 | mac_set_unicode_keystroke_event (code, buf); | ||
| 9821 | } | ||
| 9822 | #endif /* MAC_OSX */ | ||
| 9823 | |||
| 9824 | if (buf->kind == NO_EVENT) | ||
| 9825 | { | ||
| 9826 | /* This code comes from Keyboard Resource, Appendix C of IM | ||
| 9827 | - Text. This is necessary since shift is ignored in KCHR | ||
| 9828 | table translation when option or command is pressed. It | ||
| 9829 | also does not translate correctly control-shift chars | ||
| 9830 | like C-% so mask off shift here also. */ | ||
| 9831 | /* Mask off modifier keys that are mapped to some Emacs | ||
| 9832 | modifiers. */ | ||
| 9833 | int new_modifiers = modifiers & ~mapped_modifiers; | ||
| 9834 | /* set high byte of keycode to modifier high byte*/ | ||
| 9835 | int new_key_code = key_code | new_modifiers; | ||
| 9836 | Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache); | ||
| 9837 | unsigned long some_state = 0; | ||
| 9838 | UInt32 new_char_code; | ||
| 9839 | |||
| 9840 | new_char_code = KeyTranslate (kchr_ptr, new_key_code, &some_state); | ||
| 9841 | if (new_char_code == 0) | ||
| 9842 | /* Seems like a dead key. Append up-stroke. */ | ||
| 9843 | new_char_code = KeyTranslate (kchr_ptr, new_key_code | 0x80, | ||
| 9844 | &some_state); | ||
| 9845 | if (new_char_code) | ||
| 9846 | { | ||
| 9847 | buf->kind = ASCII_KEYSTROKE_EVENT; | ||
| 9848 | buf->code = new_char_code & 0xff; | ||
| 9849 | } | ||
| 9850 | } | ||
| 9851 | } | ||
| 9852 | |||
| 9853 | if (buf->kind == NO_EVENT) | ||
| 9854 | { | ||
| 9855 | buf->kind = ASCII_KEYSTROKE_EVENT; | ||
| 9856 | buf->code = char_code; | ||
| 9857 | } | ||
| 9858 | |||
| 9859 | buf->modifiers = mac_to_emacs_modifiers (modifiers); | ||
| 9860 | buf->modifiers |= (extra_keyboard_modifiers | ||
| 9861 | & (meta_modifier | alt_modifier | ||
| 9862 | | hyper_modifier | super_modifier)); | ||
| 9863 | |||
| 9864 | #if TARGET_API_MAC_CARBON | ||
| 9865 | if (buf->kind == ASCII_KEYSTROKE_EVENT | ||
| 9866 | && buf->code >= 0x80 && buf->modifiers) | ||
| 9867 | { | ||
| 9868 | OSStatus err; | ||
| 9869 | TextEncoding encoding = kTextEncodingMacRoman; | ||
| 9870 | TextToUnicodeInfo ttu_info; | ||
| 9871 | |||
| 9872 | UpgradeScriptInfoToTextEncoding (current_key_script, | ||
| 9873 | kTextLanguageDontCare, | ||
| 9874 | kTextRegionDontCare, | ||
| 9875 | NULL, &encoding); | ||
| 9876 | err = CreateTextToUnicodeInfoByEncoding (encoding, &ttu_info); | ||
| 9877 | if (err == noErr) | ||
| 9878 | { | ||
| 9879 | UniChar code; | ||
| 9880 | Str255 pstr; | ||
| 9881 | ByteCount unicode_len; | ||
| 9882 | |||
| 9883 | pstr[0] = 1; | ||
| 9884 | pstr[1] = buf->code; | ||
| 9885 | err = ConvertFromPStringToUnicode (ttu_info, pstr, | ||
| 9886 | sizeof (UniChar), | ||
| 9887 | &unicode_len, &code); | ||
| 9888 | if (err == noErr && unicode_len == sizeof (UniChar)) | ||
| 9889 | mac_set_unicode_keystroke_event (code, buf); | ||
| 9890 | DisposeTextToUnicodeInfo (&ttu_info); | ||
| 9891 | } | ||
| 9892 | } | ||
| 9893 | #endif | ||
| 9894 | |||
| 9895 | if (buf->kind == ASCII_KEYSTROKE_EVENT | ||
| 9896 | && buf->code >= 0x80 | ||
| 9897 | && last_key_script != current_key_script) | ||
| 9898 | { | ||
| 9899 | struct input_event event; | ||
| 9900 | |||
| 9901 | EVENT_INIT (event); | ||
| 9902 | event.kind = LANGUAGE_CHANGE_EVENT; | ||
| 9903 | event.arg = Qnil; | ||
| 9904 | event.code = current_key_script; | ||
| 9905 | event.timestamp = timestamp; | ||
| 9906 | kbd_buffer_store_event (&event); | ||
| 9907 | last_key_script = current_key_script; | ||
| 9908 | } | ||
| 9909 | } | ||
| 9910 | |||
| 9642 | void | 9911 | void |
| 9643 | mac_store_apple_event (class, id, desc) | 9912 | mac_store_apple_event (class, id, desc) |
| 9644 | Lisp_Object class, id; | 9913 | Lisp_Object class, id; |
| @@ -9718,51 +9987,48 @@ mac_store_drag_event (window, mouse_pos, modifiers, desc) | |||
| 9718 | kbd_buffer_store_event (&buf); | 9987 | kbd_buffer_store_event (&buf); |
| 9719 | } | 9988 | } |
| 9720 | 9989 | ||
| 9721 | static pascal OSStatus | 9990 | #ifdef MAC_OSX |
| 9722 | mac_handle_command_event (next_handler, event, data) | 9991 | OSStatus |
| 9723 | EventHandlerCallRef next_handler; | 9992 | mac_store_service_event (event) |
| 9724 | EventRef event; | 9993 | EventRef event; |
| 9725 | void *data; | ||
| 9726 | { | 9994 | { |
| 9727 | OSStatus result, err; | 9995 | OSStatus err; |
| 9728 | HICommand command; | 9996 | Lisp_Object id_key; |
| 9729 | static const EventParamName names[] = | 9997 | int num_params; |
| 9730 | {kEventParamDirectObject, kEventParamKeyModifiers}; | 9998 | const EventParamName *names; |
| 9731 | static const EventParamType types[] = | 9999 | const EventParamType *types; |
| 9732 | {typeHICommand, typeUInt32}; | 10000 | static const EventParamName names_pfm[] = |
| 9733 | int num_params = sizeof (names) / sizeof (names[0]); | 10001 | {kEventParamServiceMessageName, kEventParamServiceUserData}; |
| 9734 | 10002 | static const EventParamType types_pfm[] = | |
| 9735 | result = CallNextEventHandler (next_handler, event); | 10003 | {typeCFStringRef, typeCFStringRef}; |
| 9736 | if (result != eventNotHandledErr) | ||
| 9737 | return result; | ||
| 9738 | 10004 | ||
| 9739 | err = GetEventParameter (event, kEventParamDirectObject, typeHICommand, | 10005 | switch (GetEventKind (event)) |
| 9740 | NULL, sizeof (HICommand), NULL, &command); | 10006 | { |
| 10007 | case kEventServicePaste: | ||
| 10008 | id_key = Qpaste; | ||
| 10009 | num_params = 0; | ||
| 10010 | names = NULL; | ||
| 10011 | types = NULL; | ||
| 10012 | break; | ||
| 9741 | 10013 | ||
| 9742 | if (err != noErr || command.commandID == 0) | 10014 | case kEventServicePerform: |
| 9743 | return eventNotHandledErr; | 10015 | id_key = Qperform; |
| 10016 | num_params = sizeof (names_pfm) / sizeof (names_pfm[0]); | ||
| 10017 | names = names_pfm; | ||
| 10018 | types = types_pfm; | ||
| 10019 | break; | ||
| 9744 | 10020 | ||
| 9745 | /* A HI command event is mapped to an Apple event whose event class | 10021 | default: |
| 9746 | symbol is `hi-command' and event ID is its command ID. */ | 10022 | abort (); |
| 9747 | err = mac_store_event_ref_as_apple_event (0, command.commandID, | 10023 | } |
| 9748 | Qhi_command, Qnil, | ||
| 9749 | event, num_params, names, types); | ||
| 9750 | return err == noErr ? noErr : eventNotHandledErr; | ||
| 9751 | } | ||
| 9752 | 10024 | ||
| 9753 | static OSStatus | 10025 | err = mac_store_event_ref_as_apple_event (0, 0, Qservice, id_key, |
| 9754 | init_command_handler () | 10026 | event, num_params, |
| 9755 | { | 10027 | names, types); |
| 9756 | static const EventTypeSpec specs[] = | ||
| 9757 | {{kEventClassCommand, kEventCommandProcess}}; | ||
| 9758 | static EventHandlerUPP handle_command_eventUPP = NULL; | ||
| 9759 | 10028 | ||
| 9760 | if (handle_command_eventUPP == NULL) | 10029 | return err; |
| 9761 | handle_command_eventUPP = NewEventHandlerUPP (mac_handle_command_event); | ||
| 9762 | return InstallApplicationEventHandler (handle_command_eventUPP, | ||
| 9763 | GetEventTypeCount (specs), specs, | ||
| 9764 | NULL, NULL); | ||
| 9765 | } | 10030 | } |
| 10031 | #endif /* MAC_OSX */ | ||
| 9766 | 10032 | ||
| 9767 | static pascal OSStatus | 10033 | static pascal OSStatus |
| 9768 | mac_handle_window_event (next_handler, event, data) | 10034 | mac_handle_window_event (next_handler, event, data) |
| @@ -9771,7 +10037,7 @@ mac_handle_window_event (next_handler, event, data) | |||
| 9771 | void *data; | 10037 | void *data; |
| 9772 | { | 10038 | { |
| 9773 | WindowRef wp; | 10039 | WindowRef wp; |
| 9774 | OSStatus result, err; | 10040 | OSStatus err, result = eventNotHandledErr; |
| 9775 | struct frame *f; | 10041 | struct frame *f; |
| 9776 | UInt32 attributes; | 10042 | UInt32 attributes; |
| 9777 | XSizeHints *size_hints; | 10043 | XSizeHints *size_hints; |
| @@ -9784,33 +10050,64 @@ mac_handle_window_event (next_handler, event, data) | |||
| 9784 | f = mac_window_to_frame (wp); | 10050 | f = mac_window_to_frame (wp); |
| 9785 | switch (GetEventKind (event)) | 10051 | switch (GetEventKind (event)) |
| 9786 | { | 10052 | { |
| 10053 | /* -- window refresh events -- */ | ||
| 10054 | |||
| 9787 | case kEventWindowUpdate: | 10055 | case kEventWindowUpdate: |
| 9788 | result = CallNextEventHandler (next_handler, event); | 10056 | result = CallNextEventHandler (next_handler, event); |
| 9789 | if (result != eventNotHandledErr) | 10057 | if (result != eventNotHandledErr) |
| 9790 | return result; | 10058 | break; |
| 9791 | 10059 | ||
| 9792 | do_window_update (wp); | 10060 | do_window_update (wp); |
| 9793 | return noErr; | 10061 | result = noErr; |
| 10062 | break; | ||
| 9794 | 10063 | ||
| 9795 | case kEventWindowGetIdealSize: | 10064 | /* -- window state change events -- */ |
| 9796 | result = CallNextEventHandler (next_handler, event); | ||
| 9797 | if (result != eventNotHandledErr) | ||
| 9798 | return result; | ||
| 9799 | 10065 | ||
| 9800 | { | 10066 | case kEventWindowShowing: |
| 9801 | Point ideal_size = mac_get_ideal_size (f); | 10067 | size_hints = FRAME_SIZE_HINTS (f); |
| 10068 | if (!(size_hints->flags & (USPosition | PPosition))) | ||
| 10069 | { | ||
| 10070 | struct frame *sf = SELECTED_FRAME (); | ||
| 9802 | 10071 | ||
| 9803 | err = SetEventParameter (event, kEventParamDimensions, | 10072 | if (!(FRAME_MAC_P (sf))) |
| 9804 | typeQDPoint, sizeof (Point), &ideal_size); | 10073 | RepositionWindow (wp, NULL, kWindowCenterOnMainScreen); |
| 9805 | if (err == noErr) | 10074 | else |
| 9806 | return noErr; | 10075 | { |
| 9807 | } | 10076 | RepositionWindow (wp, FRAME_MAC_WINDOW (sf), |
| 10077 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | ||
| 10078 | kWindowCascadeStartAtParentWindowScreen | ||
| 10079 | #else | ||
| 10080 | kWindowCascadeOnParentWindowScreen | ||
| 10081 | #endif | ||
| 10082 | ); | ||
| 10083 | } | ||
| 10084 | result = noErr; | ||
| 10085 | } | ||
| 10086 | break; | ||
| 10087 | |||
| 10088 | case kEventWindowHiding: | ||
| 10089 | /* Before unmapping the window, update the WM_SIZE_HINTS | ||
| 10090 | property to claim that the current position of the window is | ||
| 10091 | user-specified, rather than program-specified, so that when | ||
| 10092 | the window is mapped again, it will be placed at the same | ||
| 10093 | location, without forcing the user to position it by hand | ||
| 10094 | again (they have already done that once for this window.) */ | ||
| 10095 | x_wm_set_size_hint (f, (long) 0, 1); | ||
| 10096 | result = noErr; | ||
| 10097 | break; | ||
| 10098 | |||
| 10099 | case kEventWindowShown: | ||
| 10100 | case kEventWindowHidden: | ||
| 10101 | case kEventWindowCollapsed: | ||
| 10102 | case kEventWindowExpanded: | ||
| 10103 | mac_handle_visibility_change (f); | ||
| 10104 | result = noErr; | ||
| 9808 | break; | 10105 | break; |
| 9809 | 10106 | ||
| 9810 | case kEventWindowBoundsChanging: | 10107 | case kEventWindowBoundsChanging: |
| 9811 | result = CallNextEventHandler (next_handler, event); | 10108 | result = CallNextEventHandler (next_handler, event); |
| 9812 | if (result != eventNotHandledErr) | 10109 | if (result != eventNotHandledErr) |
| 9813 | return result; | 10110 | break; |
| 9814 | 10111 | ||
| 9815 | err = GetEventParameter (event, kEventParamAttributes, typeUInt32, | 10112 | err = GetEventParameter (event, kEventParamAttributes, typeUInt32, |
| 9816 | NULL, sizeof (UInt32), NULL, &attributes); | 10113 | NULL, sizeof (UInt32), NULL, &attributes); |
| @@ -9854,7 +10151,7 @@ mac_handle_window_event (next_handler, event, data) | |||
| 9854 | bounds.bottom = bounds.top + height; | 10151 | bounds.bottom = bounds.top + height; |
| 9855 | SetEventParameter (event, kEventParamCurrentBounds, | 10152 | SetEventParameter (event, kEventParamCurrentBounds, |
| 9856 | typeQDRectangle, sizeof (Rect), &bounds); | 10153 | typeQDRectangle, sizeof (Rect), &bounds); |
| 9857 | return noErr; | 10154 | result = noErr; |
| 9858 | } | 10155 | } |
| 9859 | break; | 10156 | break; |
| 9860 | 10157 | ||
| @@ -9885,21 +10182,12 @@ mac_handle_window_event (next_handler, event, data) | |||
| 9885 | if (attributes & kWindowBoundsChangeOriginChanged) | 10182 | if (attributes & kWindowBoundsChangeOriginChanged) |
| 9886 | mac_handle_origin_change (f); | 10183 | mac_handle_origin_change (f); |
| 9887 | 10184 | ||
| 9888 | return noErr; | 10185 | result = noErr; |
| 9889 | |||
| 9890 | case kEventWindowShown: | ||
| 9891 | case kEventWindowHidden: | ||
| 9892 | case kEventWindowExpanded: | ||
| 9893 | case kEventWindowCollapsed: | ||
| 9894 | result = CallNextEventHandler (next_handler, event); | ||
| 9895 | |||
| 9896 | mac_handle_visibility_change (f); | ||
| 9897 | return noErr; | ||
| 9898 | |||
| 9899 | break; | 10186 | break; |
| 9900 | 10187 | ||
| 10188 | /* -- window action events -- */ | ||
| 10189 | |||
| 9901 | case kEventWindowClose: | 10190 | case kEventWindowClose: |
| 9902 | result = CallNextEventHandler (next_handler, event); | ||
| 9903 | { | 10191 | { |
| 9904 | struct input_event buf; | 10192 | struct input_event buf; |
| 9905 | 10193 | ||
| @@ -9909,11 +10197,26 @@ mac_handle_window_event (next_handler, event, data) | |||
| 9909 | buf.arg = Qnil; | 10197 | buf.arg = Qnil; |
| 9910 | kbd_buffer_store_event (&buf); | 10198 | kbd_buffer_store_event (&buf); |
| 9911 | } | 10199 | } |
| 9912 | return noErr; | 10200 | result = noErr; |
| 10201 | break; | ||
| 10202 | |||
| 10203 | case kEventWindowGetIdealSize: | ||
| 10204 | result = CallNextEventHandler (next_handler, event); | ||
| 10205 | if (result != eventNotHandledErr) | ||
| 10206 | break; | ||
| 10207 | |||
| 10208 | { | ||
| 10209 | Point ideal_size = mac_get_ideal_size (f); | ||
| 10210 | |||
| 10211 | err = SetEventParameter (event, kEventParamDimensions, | ||
| 10212 | typeQDPoint, sizeof (Point), &ideal_size); | ||
| 10213 | if (err == noErr) | ||
| 10214 | result = noErr; | ||
| 10215 | } | ||
| 10216 | break; | ||
| 9913 | 10217 | ||
| 9914 | #ifdef MAC_OSX | 10218 | #ifdef MAC_OSX |
| 9915 | case kEventWindowToolbarSwitchMode: | 10219 | case kEventWindowToolbarSwitchMode: |
| 9916 | result = CallNextEventHandler (next_handler, event); | ||
| 9917 | { | 10220 | { |
| 9918 | static const EventParamName names[] = {kEventParamDirectObject, | 10221 | static const EventParamName names[] = {kEventParamDirectObject, |
| 9919 | kEventParamWindowMouseLocation, | 10222 | kEventParamWindowMouseLocation, |
| @@ -9935,23 +10238,195 @@ mac_handle_window_event (next_handler, event, data) | |||
| 9935 | event, num_params, | 10238 | event, num_params, |
| 9936 | names, types); | 10239 | names, types); |
| 9937 | } | 10240 | } |
| 9938 | return err == noErr ? noErr : result; | 10241 | if (err == noErr) |
| 10242 | result = noErr; | ||
| 10243 | break; | ||
| 9939 | #endif | 10244 | #endif |
| 9940 | 10245 | ||
| 9941 | #if USE_MAC_TSM | 10246 | #if USE_MAC_TSM |
| 10247 | /* -- window focus events -- */ | ||
| 10248 | |||
| 9942 | case kEventWindowFocusAcquired: | 10249 | case kEventWindowFocusAcquired: |
| 9943 | result = CallNextEventHandler (next_handler, event); | ||
| 9944 | err = mac_tsm_resume (); | 10250 | err = mac_tsm_resume (); |
| 9945 | return err == noErr ? noErr : result; | 10251 | if (err == noErr) |
| 10252 | result = noErr; | ||
| 10253 | break; | ||
| 9946 | 10254 | ||
| 9947 | case kEventWindowFocusRelinquish: | 10255 | case kEventWindowFocusRelinquish: |
| 9948 | result = CallNextEventHandler (next_handler, event); | ||
| 9949 | err = mac_tsm_suspend (); | 10256 | err = mac_tsm_suspend (); |
| 9950 | return err == noErr ? noErr : result; | 10257 | if (err == noErr) |
| 10258 | result = noErr; | ||
| 10259 | break; | ||
| 9951 | #endif | 10260 | #endif |
| 10261 | |||
| 10262 | default: | ||
| 10263 | abort (); | ||
| 10264 | } | ||
| 10265 | |||
| 10266 | return result; | ||
| 10267 | } | ||
| 10268 | |||
| 10269 | static pascal OSStatus | ||
| 10270 | mac_handle_application_event (next_handler, event, data) | ||
| 10271 | EventHandlerCallRef next_handler; | ||
| 10272 | EventRef event; | ||
| 10273 | void *data; | ||
| 10274 | { | ||
| 10275 | OSStatus err, result = eventNotHandledErr; | ||
| 10276 | |||
| 10277 | switch (GetEventKind (event)) | ||
| 10278 | { | ||
| 10279 | #if USE_MAC_TSM | ||
| 10280 | case kEventAppActivated: | ||
| 10281 | err = mac_tsm_resume (); | ||
| 10282 | break; | ||
| 10283 | |||
| 10284 | case kEventAppDeactivated: | ||
| 10285 | err = mac_tsm_suspend (); | ||
| 10286 | break; | ||
| 10287 | #endif | ||
| 10288 | |||
| 10289 | default: | ||
| 10290 | abort (); | ||
| 10291 | } | ||
| 10292 | |||
| 10293 | if (err == noErr) | ||
| 10294 | result = noErr; | ||
| 10295 | |||
| 10296 | return result; | ||
| 10297 | } | ||
| 10298 | |||
| 10299 | static pascal OSStatus | ||
| 10300 | mac_handle_keyboard_event (next_handler, event, data) | ||
| 10301 | EventHandlerCallRef next_handler; | ||
| 10302 | EventRef event; | ||
| 10303 | void *data; | ||
| 10304 | { | ||
| 10305 | OSStatus err, result = eventNotHandledErr; | ||
| 10306 | UInt32 event_kind, key_code, modifiers, mapped_modifiers; | ||
| 10307 | unsigned char char_code; | ||
| 10308 | |||
| 10309 | event_kind = GetEventKind (event); | ||
| 10310 | switch (event_kind) | ||
| 10311 | { | ||
| 10312 | case kEventRawKeyDown: | ||
| 10313 | case kEventRawKeyRepeat: | ||
| 10314 | case kEventRawKeyUp: | ||
| 10315 | if (read_socket_inev == NULL) | ||
| 10316 | { | ||
| 10317 | result = CallNextEventHandler (next_handler, event); | ||
| 10318 | break; | ||
| 10319 | } | ||
| 10320 | |||
| 10321 | err = GetEventParameter (event, kEventParamKeyModifiers, | ||
| 10322 | typeUInt32, NULL, | ||
| 10323 | sizeof (UInt32), NULL, &modifiers); | ||
| 10324 | if (err != noErr) | ||
| 10325 | break; | ||
| 10326 | |||
| 10327 | mapped_modifiers = mac_mapped_modifiers (modifiers); | ||
| 10328 | |||
| 10329 | /* When using Carbon Events, we need to pass raw keyboard events | ||
| 10330 | to the TSM ourselves. If TSM handles it, it will pass back | ||
| 10331 | noErr, otherwise it will pass back "eventNotHandledErr" and | ||
| 10332 | we can process it normally. */ | ||
| 10333 | if (!(mapped_modifiers | ||
| 10334 | & ~(mac_pass_command_to_system ? cmdKey : 0) | ||
| 10335 | & ~(mac_pass_control_to_system ? controlKey : 0))) | ||
| 10336 | { | ||
| 10337 | result = CallNextEventHandler (next_handler, event); | ||
| 10338 | if (result != eventNotHandledErr) | ||
| 10339 | break; | ||
| 10340 | } | ||
| 10341 | |||
| 10342 | #if USE_MAC_TSM | ||
| 10343 | if (read_socket_inev->kind != NO_EVENT) | ||
| 10344 | { | ||
| 10345 | result = noErr; | ||
| 10346 | break; | ||
| 10347 | } | ||
| 10348 | #endif | ||
| 10349 | |||
| 10350 | if (event_kind == kEventRawKeyUp) | ||
| 10351 | break; | ||
| 10352 | |||
| 10353 | err = GetEventParameter (event, kEventParamKeyMacCharCodes, | ||
| 10354 | typeChar, NULL, | ||
| 10355 | sizeof (char), NULL, &char_code); | ||
| 10356 | if (err != noErr) | ||
| 10357 | break; | ||
| 10358 | |||
| 10359 | err = GetEventParameter (event, kEventParamKeyCode, | ||
| 10360 | typeUInt32, NULL, | ||
| 10361 | sizeof (UInt32), NULL, &key_code); | ||
| 10362 | if (err != noErr) | ||
| 10363 | break; | ||
| 10364 | |||
| 10365 | do_keystroke ((GetEventKind (event) == kEventRawKeyDown | ||
| 10366 | ? keyDown : autoKey), | ||
| 10367 | char_code, key_code, modifiers, | ||
| 10368 | ((unsigned long) | ||
| 10369 | (GetEventTime (event) / kEventDurationMillisecond)), | ||
| 10370 | read_socket_inev); | ||
| 10371 | result = noErr; | ||
| 10372 | break; | ||
| 10373 | |||
| 10374 | default: | ||
| 10375 | abort (); | ||
| 10376 | } | ||
| 10377 | |||
| 10378 | return result; | ||
| 10379 | } | ||
| 10380 | |||
| 10381 | static pascal OSStatus | ||
| 10382 | mac_handle_command_event (next_handler, event, data) | ||
| 10383 | EventHandlerCallRef next_handler; | ||
| 10384 | EventRef event; | ||
| 10385 | void *data; | ||
| 10386 | { | ||
| 10387 | OSStatus err, result = eventNotHandledErr; | ||
| 10388 | HICommand command; | ||
| 10389 | static const EventParamName names[] = | ||
| 10390 | {kEventParamDirectObject, kEventParamKeyModifiers}; | ||
| 10391 | static const EventParamType types[] = | ||
| 10392 | {typeHICommand, typeUInt32}; | ||
| 10393 | int num_params = sizeof (names) / sizeof (names[0]); | ||
| 10394 | |||
| 10395 | err = GetEventParameter (event, kEventParamDirectObject, typeHICommand, | ||
| 10396 | NULL, sizeof (HICommand), NULL, &command); | ||
| 10397 | if (err != noErr) | ||
| 10398 | return eventNotHandledErr; | ||
| 10399 | |||
| 10400 | switch (GetEventKind (event)) | ||
| 10401 | { | ||
| 10402 | case kEventCommandProcess: | ||
| 10403 | result = CallNextEventHandler (next_handler, event); | ||
| 10404 | if (result != eventNotHandledErr) | ||
| 10405 | break; | ||
| 10406 | |||
| 10407 | err = GetEventParameter (event, kEventParamDirectObject, | ||
| 10408 | typeHICommand, NULL, | ||
| 10409 | sizeof (HICommand), NULL, &command); | ||
| 10410 | |||
| 10411 | if (err != noErr || command.commandID == 0) | ||
| 10412 | break; | ||
| 10413 | |||
| 10414 | /* A HI command event is mapped to an Apple event whose event | ||
| 10415 | class symbol is `hi-command' and event ID is its command | ||
| 10416 | ID. */ | ||
| 10417 | err = mac_store_event_ref_as_apple_event (0, command.commandID, | ||
| 10418 | Qhi_command, Qnil, | ||
| 10419 | event, num_params, | ||
| 10420 | names, types); | ||
| 10421 | if (err == noErr) | ||
| 10422 | result = noErr; | ||
| 10423 | break; | ||
| 10424 | |||
| 10425 | default: | ||
| 10426 | abort (); | ||
| 9952 | } | 10427 | } |
| 9953 | 10428 | ||
| 9954 | return eventNotHandledErr; | 10429 | return result; |
| 9955 | } | 10430 | } |
| 9956 | 10431 | ||
| 9957 | static pascal OSStatus | 10432 | static pascal OSStatus |
| @@ -9960,7 +10435,7 @@ mac_handle_mouse_event (next_handler, event, data) | |||
| 9960 | EventRef event; | 10435 | EventRef event; |
| 9961 | void *data; | 10436 | void *data; |
| 9962 | { | 10437 | { |
| 9963 | OSStatus result, err; | 10438 | OSStatus err, result = eventNotHandledErr; |
| 9964 | 10439 | ||
| 9965 | switch (GetEventKind (event)) | 10440 | switch (GetEventKind (event)) |
| 9966 | { | 10441 | { |
| @@ -9974,15 +10449,14 @@ mac_handle_mouse_event (next_handler, event, data) | |||
| 9974 | 10449 | ||
| 9975 | result = CallNextEventHandler (next_handler, event); | 10450 | result = CallNextEventHandler (next_handler, event); |
| 9976 | if (result != eventNotHandledErr || read_socket_inev == NULL) | 10451 | if (result != eventNotHandledErr || read_socket_inev == NULL) |
| 9977 | return result; | 10452 | break; |
| 10453 | |||
| 10454 | f = mac_focus_frame (&one_mac_display_info); | ||
| 9978 | 10455 | ||
| 9979 | err = GetEventParameter (event, kEventParamWindowRef, typeWindowRef, | 10456 | err = GetEventParameter (event, kEventParamWindowRef, typeWindowRef, |
| 9980 | NULL, sizeof (WindowRef), NULL, &wp); | 10457 | NULL, sizeof (WindowRef), NULL, &wp); |
| 9981 | if (err != noErr) | 10458 | if (err != noErr |
| 9982 | break; | 10459 | || wp != FRAME_MAC_WINDOW (f)) |
| 9983 | |||
| 9984 | f = mac_window_to_frame (wp); | ||
| 9985 | if (f != mac_focus_frame (&one_mac_display_info)) | ||
| 9986 | break; | 10460 | break; |
| 9987 | 10461 | ||
| 9988 | err = GetEventParameter (event, kEventParamMouseWheelAxis, | 10462 | err = GetEventParameter (event, kEventParamMouseWheelAxis, |
| @@ -9997,8 +10471,8 @@ mac_handle_mouse_event (next_handler, event, data) | |||
| 9997 | if (err != noErr) | 10471 | if (err != noErr) |
| 9998 | break; | 10472 | break; |
| 9999 | 10473 | ||
| 10000 | SetPortWindowPort (wp); | 10474 | point.h -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); |
| 10001 | GlobalToLocal (&point); | 10475 | point.v -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); |
| 10002 | if (point.h < 0 || point.v < 0 | 10476 | if (point.h < 0 || point.v < 0 |
| 10003 | || EQ (window_from_coordinates (f, point.h, point.v, 0, 0, 0, 1), | 10477 | || EQ (window_from_coordinates (f, point.h, point.v, 0, 0, 0, 1), |
| 10004 | f->tool_bar_window)) | 10478 | f->tool_bar_window)) |
| @@ -10019,68 +10493,16 @@ mac_handle_mouse_event (next_handler, event, data) | |||
| 10019 | XSETINT (read_socket_inev->y, point.v); | 10493 | XSETINT (read_socket_inev->y, point.v); |
| 10020 | XSETFRAME (read_socket_inev->frame_or_window, f); | 10494 | XSETFRAME (read_socket_inev->frame_or_window, f); |
| 10021 | 10495 | ||
| 10022 | return noErr; | 10496 | result = noErr; |
| 10023 | } | 10497 | } |
| 10024 | break; | 10498 | break; |
| 10025 | 10499 | ||
| 10026 | default: | 10500 | default: |
| 10027 | break; | 10501 | abort (); |
| 10028 | } | ||
| 10029 | |||
| 10030 | return eventNotHandledErr; | ||
| 10031 | } | ||
| 10032 | |||
| 10033 | #if USE_MAC_FONT_PANEL | ||
| 10034 | static pascal OSStatus | ||
| 10035 | mac_handle_font_event (next_handler, event, data) | ||
| 10036 | EventHandlerCallRef next_handler; | ||
| 10037 | EventRef event; | ||
| 10038 | void *data; | ||
| 10039 | { | ||
| 10040 | OSStatus result, err; | ||
| 10041 | Lisp_Object id_key; | ||
| 10042 | int num_params; | ||
| 10043 | const EventParamName *names; | ||
| 10044 | const EventParamType *types; | ||
| 10045 | static const EventParamName names_sel[] = {kEventParamATSUFontID, | ||
| 10046 | kEventParamATSUFontSize, | ||
| 10047 | kEventParamFMFontFamily, | ||
| 10048 | kEventParamFMFontSize, | ||
| 10049 | kEventParamFontColor}; | ||
| 10050 | static const EventParamType types_sel[] = {typeATSUFontID, | ||
| 10051 | typeATSUSize, | ||
| 10052 | typeFMFontFamily, | ||
| 10053 | typeFMFontSize, | ||
| 10054 | typeFontColor}; | ||
| 10055 | |||
| 10056 | result = CallNextEventHandler (next_handler, event); | ||
| 10057 | if (result != eventNotHandledErr) | ||
| 10058 | return result; | ||
| 10059 | |||
| 10060 | switch (GetEventKind (event)) | ||
| 10061 | { | ||
| 10062 | case kEventFontPanelClosed: | ||
| 10063 | id_key = Qpanel_closed; | ||
| 10064 | num_params = 0; | ||
| 10065 | names = NULL; | ||
| 10066 | types = NULL; | ||
| 10067 | break; | ||
| 10068 | |||
| 10069 | case kEventFontSelection: | ||
| 10070 | id_key = Qselection; | ||
| 10071 | num_params = sizeof (names_sel) / sizeof (names_sel[0]); | ||
| 10072 | names = names_sel; | ||
| 10073 | types = types_sel; | ||
| 10074 | break; | ||
| 10075 | } | 10502 | } |
| 10076 | 10503 | ||
| 10077 | err = mac_store_event_ref_as_apple_event (0, 0, Qfont, id_key, | 10504 | return result; |
| 10078 | event, num_params, | ||
| 10079 | names, types); | ||
| 10080 | |||
| 10081 | return err == noErr ? noErr : eventNotHandledErr; | ||
| 10082 | } | 10505 | } |
| 10083 | #endif | ||
| 10084 | 10506 | ||
| 10085 | #if USE_MAC_TSM | 10507 | #if USE_MAC_TSM |
| 10086 | static pascal OSStatus | 10508 | static pascal OSStatus |
| @@ -10137,6 +10559,8 @@ mac_handle_text_input_event (next_handler, event, data) | |||
| 10137 | typeUnicodeText}; | 10559 | typeUnicodeText}; |
| 10138 | 10560 | ||
| 10139 | result = CallNextEventHandler (next_handler, event); | 10561 | result = CallNextEventHandler (next_handler, event); |
| 10562 | if (result != eventNotHandledErr) | ||
| 10563 | return result; | ||
| 10140 | 10564 | ||
| 10141 | switch (GetEventKind (event)) | 10565 | switch (GetEventKind (event)) |
| 10142 | { | 10566 | { |
| @@ -10164,7 +10588,7 @@ mac_handle_text_input_event (next_handler, event, data) | |||
| 10164 | sizeof (UInt32), NULL, &modifiers); | 10588 | sizeof (UInt32), NULL, &modifiers); |
| 10165 | if (err == noErr && mac_mapped_modifiers (modifiers)) | 10589 | if (err == noErr && mac_mapped_modifiers (modifiers)) |
| 10166 | /* There're mapped modifier keys. Process it in | 10590 | /* There're mapped modifier keys. Process it in |
| 10167 | XTread_socket. */ | 10591 | do_keystroke. */ |
| 10168 | return eventNotHandledErr; | 10592 | return eventNotHandledErr; |
| 10169 | if (err == noErr) | 10593 | if (err == noErr) |
| 10170 | err = GetEventParameter (kbd_event, kEventParamKeyUnicodes, | 10594 | err = GetEventParameter (kbd_event, kEventParamKeyUnicodes, |
| @@ -10179,7 +10603,7 @@ mac_handle_text_input_event (next_handler, event, data) | |||
| 10179 | sizeof (UniChar), NULL, &code); | 10603 | sizeof (UniChar), NULL, &code); |
| 10180 | if (err == noErr && code < 0x80) | 10604 | if (err == noErr && code < 0x80) |
| 10181 | { | 10605 | { |
| 10182 | /* ASCII character. Process it in XTread_socket. */ | 10606 | /* ASCII character. Process it in do_keystroke. */ |
| 10183 | if (read_socket_inev && code >= 0x20 && code <= 0x7e) | 10607 | if (read_socket_inev && code >= 0x20 && code <= 0x7e) |
| 10184 | { | 10608 | { |
| 10185 | UInt32 key_code; | 10609 | UInt32 key_code; |
| @@ -10241,11 +10665,11 @@ mac_handle_text_input_event (next_handler, event, data) | |||
| 10241 | } | 10665 | } |
| 10242 | 10666 | ||
| 10243 | p.h = (WINDOW_TO_FRAME_PIXEL_X (w, w->cursor.x) | 10667 | p.h = (WINDOW_TO_FRAME_PIXEL_X (w, w->cursor.x) |
| 10244 | + WINDOW_LEFT_FRINGE_WIDTH (w)); | 10668 | + WINDOW_LEFT_FRINGE_WIDTH (w) |
| 10669 | + f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f)); | ||
| 10245 | p.v = (WINDOW_TO_FRAME_PIXEL_Y (w, w->cursor.y) | 10670 | p.v = (WINDOW_TO_FRAME_PIXEL_Y (w, w->cursor.y) |
| 10246 | + FONT_BASE (FRAME_FONT (f))); | 10671 | + FONT_BASE (FRAME_FONT (f)) |
| 10247 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | 10672 | + f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f)); |
| 10248 | LocalToGlobal (&p); | ||
| 10249 | err = SetEventParameter (event, kEventParamTextInputReplyPoint, | 10673 | err = SetEventParameter (event, kEventParamTextInputReplyPoint, |
| 10250 | typeQDPoint, sizeof (typeQDPoint), &p); | 10674 | typeQDPoint, sizeof (typeQDPoint), &p); |
| 10251 | } | 10675 | } |
| @@ -10259,146 +10683,155 @@ mac_handle_text_input_event (next_handler, event, data) | |||
| 10259 | err = mac_store_event_ref_as_apple_event (0, 0, Qtext_input, id_key, | 10683 | err = mac_store_event_ref_as_apple_event (0, 0, Qtext_input, id_key, |
| 10260 | event, num_params, | 10684 | event, num_params, |
| 10261 | names, types); | 10685 | names, types); |
| 10686 | if (err == noErr) | ||
| 10687 | result = noErr; | ||
| 10262 | 10688 | ||
| 10263 | return err == noErr ? noErr : result; | 10689 | return result; |
| 10264 | } | 10690 | } |
| 10265 | #endif | 10691 | #endif |
| 10692 | #endif /* TARGET_API_MAC_CARBON */ | ||
| 10693 | |||
| 10266 | 10694 | ||
| 10267 | #ifdef MAC_OSX | ||
| 10268 | OSStatus | 10695 | OSStatus |
| 10269 | mac_store_service_event (event) | 10696 | install_window_handler (window) |
| 10270 | EventRef event; | 10697 | WindowRef window; |
| 10271 | { | 10698 | { |
| 10272 | OSStatus err; | 10699 | OSStatus err = noErr; |
| 10273 | Lisp_Object id_key; | ||
| 10274 | int num_params; | ||
| 10275 | const EventParamName *names; | ||
| 10276 | const EventParamType *types; | ||
| 10277 | static const EventParamName names_pfm[] = | ||
| 10278 | {kEventParamServiceMessageName, kEventParamServiceUserData}; | ||
| 10279 | static const EventParamType types_pfm[] = | ||
| 10280 | {typeCFStringRef, typeCFStringRef}; | ||
| 10281 | 10700 | ||
| 10282 | switch (GetEventKind (event)) | 10701 | #if TARGET_API_MAC_CARBON |
| 10702 | if (err == noErr) | ||
| 10283 | { | 10703 | { |
| 10284 | case kEventServicePaste: | 10704 | static const EventTypeSpec specs[] = |
| 10285 | id_key = Qpaste; | 10705 | { |
| 10286 | num_params = 0; | 10706 | /* -- window refresh events -- */ |
| 10287 | names = NULL; | 10707 | {kEventClassWindow, kEventWindowUpdate}, |
| 10288 | types = NULL; | 10708 | /* -- window state change events -- */ |
| 10289 | break; | 10709 | {kEventClassWindow, kEventWindowShowing}, |
| 10710 | {kEventClassWindow, kEventWindowHiding}, | ||
| 10711 | {kEventClassWindow, kEventWindowShown}, | ||
| 10712 | {kEventClassWindow, kEventWindowHidden}, | ||
| 10713 | {kEventClassWindow, kEventWindowCollapsed}, | ||
| 10714 | {kEventClassWindow, kEventWindowExpanded}, | ||
| 10715 | {kEventClassWindow, kEventWindowBoundsChanging}, | ||
| 10716 | {kEventClassWindow, kEventWindowBoundsChanged}, | ||
| 10717 | /* -- window action events -- */ | ||
| 10718 | {kEventClassWindow, kEventWindowClose}, | ||
| 10719 | {kEventClassWindow, kEventWindowGetIdealSize}, | ||
| 10720 | #ifdef MAC_OSX | ||
| 10721 | {kEventClassWindow, kEventWindowToolbarSwitchMode}, | ||
| 10722 | #endif | ||
| 10723 | #if USE_MAC_TSM | ||
| 10724 | /* -- window focus events -- */ | ||
| 10725 | {kEventClassWindow, kEventWindowFocusAcquired}, | ||
| 10726 | {kEventClassWindow, kEventWindowFocusRelinquish}, | ||
| 10727 | #endif | ||
| 10728 | }; | ||
| 10729 | static EventHandlerUPP handle_window_eventUPP = NULL; | ||
| 10290 | 10730 | ||
| 10291 | case kEventServicePerform: | 10731 | if (handle_window_eventUPP == NULL) |
| 10292 | id_key = Qperform; | 10732 | handle_window_eventUPP = NewEventHandlerUPP (mac_handle_window_event); |
| 10293 | num_params = sizeof (names_pfm) / sizeof (names_pfm[0]); | ||
| 10294 | names = names_pfm; | ||
| 10295 | types = types_pfm; | ||
| 10296 | break; | ||
| 10297 | 10733 | ||
| 10298 | default: | 10734 | err = InstallWindowEventHandler (window, handle_window_eventUPP, |
| 10299 | abort (); | 10735 | GetEventTypeCount (specs), |
| 10736 | specs, NULL, NULL); | ||
| 10300 | } | 10737 | } |
| 10738 | #endif | ||
| 10301 | 10739 | ||
| 10302 | err = mac_store_event_ref_as_apple_event (0, 0, Qservice, id_key, | 10740 | if (err == noErr) |
| 10303 | event, num_params, | 10741 | err = install_drag_handler (window); |
| 10304 | names, types); | ||
| 10305 | 10742 | ||
| 10306 | return err; | 10743 | return err; |
| 10307 | } | 10744 | } |
| 10308 | #endif /* MAC_OSX */ | ||
| 10309 | #endif /* TARGET_API_MAC_CARBON */ | ||
| 10310 | |||
| 10311 | 10745 | ||
| 10312 | OSStatus | 10746 | void |
| 10313 | install_window_handler (window) | 10747 | remove_window_handler (window) |
| 10314 | WindowRef window; | 10748 | WindowRef window; |
| 10315 | { | 10749 | { |
| 10316 | OSStatus err = noErr; | 10750 | remove_drag_handler (window); |
| 10751 | } | ||
| 10752 | |||
| 10317 | #if TARGET_API_MAC_CARBON | 10753 | #if TARGET_API_MAC_CARBON |
| 10318 | static const EventTypeSpec specs_window[] = | 10754 | static OSStatus |
| 10319 | {{kEventClassWindow, kEventWindowUpdate}, | 10755 | install_application_handler () |
| 10320 | {kEventClassWindow, kEventWindowGetIdealSize}, | 10756 | { |
| 10321 | {kEventClassWindow, kEventWindowBoundsChanging}, | 10757 | OSStatus err = noErr; |
| 10322 | {kEventClassWindow, kEventWindowBoundsChanged}, | ||
| 10323 | {kEventClassWindow, kEventWindowShown}, | ||
| 10324 | {kEventClassWindow, kEventWindowHidden}, | ||
| 10325 | {kEventClassWindow, kEventWindowExpanded}, | ||
| 10326 | {kEventClassWindow, kEventWindowCollapsed}, | ||
| 10327 | {kEventClassWindow, kEventWindowClose}, | ||
| 10328 | #ifdef MAC_OSX | ||
| 10329 | {kEventClassWindow, kEventWindowToolbarSwitchMode}, | ||
| 10330 | #endif | ||
| 10331 | #if USE_MAC_TSM | ||
| 10332 | {kEventClassWindow, kEventWindowFocusAcquired}, | ||
| 10333 | {kEventClassWindow, kEventWindowFocusRelinquish}, | ||
| 10334 | #endif | ||
| 10335 | }; | ||
| 10336 | static const EventTypeSpec specs_mouse[] = | ||
| 10337 | {{kEventClassMouse, kEventMouseWheelMoved}}; | ||
| 10338 | static EventHandlerUPP handle_window_eventUPP = NULL; | ||
| 10339 | static EventHandlerUPP handle_mouse_eventUPP = NULL; | ||
| 10340 | #if USE_MAC_FONT_PANEL | ||
| 10341 | static const EventTypeSpec specs_font[] = | ||
| 10342 | {{kEventClassFont, kEventFontPanelClosed}, | ||
| 10343 | {kEventClassFont, kEventFontSelection}}; | ||
| 10344 | static EventHandlerUPP handle_font_eventUPP = NULL; | ||
| 10345 | #endif | ||
| 10346 | #if USE_MAC_TSM | ||
| 10347 | static const EventTypeSpec specs_text_input[] = | ||
| 10348 | {{kEventClassTextInput, kEventTextInputUpdateActiveInputArea}, | ||
| 10349 | {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent}, | ||
| 10350 | {kEventClassTextInput, kEventTextInputOffsetToPos}}; | ||
| 10351 | static EventHandlerUPP handle_text_input_eventUPP = NULL; | ||
| 10352 | #endif | ||
| 10353 | 10758 | ||
| 10354 | if (handle_window_eventUPP == NULL) | 10759 | if (err == noErr) |
| 10355 | handle_window_eventUPP = NewEventHandlerUPP (mac_handle_window_event); | 10760 | { |
| 10356 | if (handle_mouse_eventUPP == NULL) | 10761 | static const EventTypeSpec specs[] = { |
| 10357 | handle_mouse_eventUPP = NewEventHandlerUPP (mac_handle_mouse_event); | ||
| 10358 | #if USE_MAC_FONT_PANEL | ||
| 10359 | if (handle_font_eventUPP == NULL) | ||
| 10360 | handle_font_eventUPP = NewEventHandlerUPP (mac_handle_font_event); | ||
| 10361 | #endif | ||
| 10362 | #if USE_MAC_TSM | 10762 | #if USE_MAC_TSM |
| 10363 | if (handle_text_input_eventUPP == NULL) | 10763 | {kEventClassApplication, kEventAppActivated}, |
| 10364 | handle_text_input_eventUPP = | 10764 | {kEventClassApplication, kEventAppDeactivated}, |
| 10365 | NewEventHandlerUPP (mac_handle_text_input_event); | ||
| 10366 | #endif | 10765 | #endif |
| 10367 | err = InstallWindowEventHandler (window, handle_window_eventUPP, | 10766 | }; |
| 10368 | GetEventTypeCount (specs_window), | 10767 | |
| 10369 | specs_window, NULL, NULL); | 10768 | err = InstallApplicationEventHandler (NewEventHandlerUPP |
| 10769 | (mac_handle_application_event), | ||
| 10770 | GetEventTypeCount (specs), | ||
| 10771 | specs, NULL, NULL); | ||
| 10772 | } | ||
| 10773 | |||
| 10370 | if (err == noErr) | 10774 | if (err == noErr) |
| 10371 | err = InstallWindowEventHandler (window, handle_mouse_eventUPP, | 10775 | { |
| 10372 | GetEventTypeCount (specs_mouse), | 10776 | static const EventTypeSpec specs[] = |
| 10373 | specs_mouse, NULL, NULL); | 10777 | {{kEventClassKeyboard, kEventRawKeyDown}, |
| 10374 | #if USE_MAC_FONT_PANEL | 10778 | {kEventClassKeyboard, kEventRawKeyRepeat}, |
| 10779 | {kEventClassKeyboard, kEventRawKeyUp}}; | ||
| 10780 | |||
| 10781 | err = InstallApplicationEventHandler (NewEventHandlerUPP | ||
| 10782 | (mac_handle_keyboard_event), | ||
| 10783 | GetEventTypeCount (specs), | ||
| 10784 | specs, NULL, NULL); | ||
| 10785 | } | ||
| 10786 | |||
| 10375 | if (err == noErr) | 10787 | if (err == noErr) |
| 10376 | err = InstallWindowEventHandler (window, handle_font_eventUPP, | 10788 | { |
| 10377 | GetEventTypeCount (specs_font), | 10789 | static const EventTypeSpec specs[] = |
| 10378 | specs_font, NULL, NULL); | 10790 | {{kEventClassCommand, kEventCommandProcess}}; |
| 10379 | #endif | 10791 | |
| 10792 | err = InstallApplicationEventHandler (NewEventHandlerUPP | ||
| 10793 | (mac_handle_command_event), | ||
| 10794 | GetEventTypeCount (specs), | ||
| 10795 | specs, NULL, NULL); | ||
| 10796 | } | ||
| 10797 | |||
| 10798 | if (err == noErr) | ||
| 10799 | { | ||
| 10800 | static const EventTypeSpec specs[] = | ||
| 10801 | {{kEventClassMouse, kEventMouseWheelMoved}}; | ||
| 10802 | |||
| 10803 | err = InstallApplicationEventHandler (NewEventHandlerUPP | ||
| 10804 | (mac_handle_mouse_event), | ||
| 10805 | GetEventTypeCount (specs), | ||
| 10806 | specs, NULL, NULL); | ||
| 10807 | } | ||
| 10808 | |||
| 10380 | #if USE_MAC_TSM | 10809 | #if USE_MAC_TSM |
| 10381 | if (err == noErr) | 10810 | if (err == noErr) |
| 10382 | err = InstallWindowEventHandler (window, handle_text_input_eventUPP, | 10811 | { |
| 10383 | GetEventTypeCount (specs_text_input), | 10812 | static const EventTypeSpec spec[] = |
| 10384 | specs_text_input, window, NULL); | 10813 | {{kEventClassTextInput, kEventTextInputUpdateActiveInputArea}, |
| 10385 | #endif | 10814 | {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent}, |
| 10815 | {kEventClassTextInput, kEventTextInputOffsetToPos}}; | ||
| 10816 | |||
| 10817 | err = InstallApplicationEventHandler (NewEventHandlerUPP | ||
| 10818 | (mac_handle_text_input_event), | ||
| 10819 | GetEventTypeCount (spec), | ||
| 10820 | spec, NULL, NULL); | ||
| 10821 | } | ||
| 10386 | #endif | 10822 | #endif |
| 10823 | |||
| 10387 | if (err == noErr) | 10824 | if (err == noErr) |
| 10388 | err = install_drag_handler (window); | 10825 | err = install_menu_target_item_handler (); |
| 10826 | |||
| 10827 | #ifdef MAC_OSX | ||
| 10389 | if (err == noErr) | 10828 | if (err == noErr) |
| 10390 | err = install_menu_target_item_handler (window); | 10829 | err = install_service_handler (); |
| 10830 | #endif | ||
| 10391 | 10831 | ||
| 10392 | return err; | 10832 | return err; |
| 10393 | } | 10833 | } |
| 10394 | 10834 | #endif | |
| 10395 | void | ||
| 10396 | remove_window_handler (window) | ||
| 10397 | WindowRef window; | ||
| 10398 | { | ||
| 10399 | remove_drag_handler (window); | ||
| 10400 | } | ||
| 10401 | |||
| 10402 | 10835 | ||
| 10403 | static pascal void | 10836 | static pascal void |
| 10404 | mac_handle_dm_notification (event) | 10837 | mac_handle_dm_notification (event) |
| @@ -10407,20 +10840,48 @@ mac_handle_dm_notification (event) | |||
| 10407 | mac_screen_config_changed = 1; | 10840 | mac_screen_config_changed = 1; |
| 10408 | } | 10841 | } |
| 10409 | 10842 | ||
| 10843 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 | ||
| 10844 | static void | ||
| 10845 | mac_handle_cg_display_reconfig (display, flags, user_info) | ||
| 10846 | CGDirectDisplayID display; | ||
| 10847 | CGDisplayChangeSummaryFlags flags; | ||
| 10848 | void *user_info; | ||
| 10849 | { | ||
| 10850 | mac_screen_config_changed = 1; | ||
| 10851 | } | ||
| 10852 | #endif | ||
| 10853 | |||
| 10410 | static OSErr | 10854 | static OSErr |
| 10411 | init_dm_notification_handler () | 10855 | init_dm_notification_handler () |
| 10412 | { | 10856 | { |
| 10413 | OSErr err; | 10857 | OSErr err = noErr; |
| 10414 | static DMNotificationUPP handle_dm_notificationUPP = NULL; | ||
| 10415 | ProcessSerialNumber psn; | ||
| 10416 | 10858 | ||
| 10417 | if (handle_dm_notificationUPP == NULL) | 10859 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 |
| 10418 | handle_dm_notificationUPP = | 10860 | #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020 |
| 10419 | NewDMNotificationUPP (mac_handle_dm_notification); | 10861 | if (CGDisplayRegisterReconfigurationCallback != NULL) |
| 10862 | #endif | ||
| 10863 | { | ||
| 10864 | CGDisplayRegisterReconfigurationCallback (mac_handle_cg_display_reconfig, | ||
| 10865 | NULL); | ||
| 10866 | } | ||
| 10867 | #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020 | ||
| 10868 | else /* CGDisplayRegisterReconfigurationCallback == NULL */ | ||
| 10869 | #endif | ||
| 10870 | #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */ | ||
| 10871 | #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020 | ||
| 10872 | { | ||
| 10873 | static DMNotificationUPP handle_dm_notificationUPP = NULL; | ||
| 10874 | ProcessSerialNumber psn; | ||
| 10420 | 10875 | ||
| 10421 | err = GetCurrentProcess (&psn); | 10876 | if (handle_dm_notificationUPP == NULL) |
| 10422 | if (err == noErr) | 10877 | handle_dm_notificationUPP = |
| 10423 | err = DMRegisterNotifyProc (handle_dm_notificationUPP, &psn); | 10878 | NewDMNotificationUPP (mac_handle_dm_notification); |
| 10879 | |||
| 10880 | err = GetCurrentProcess (&psn); | ||
| 10881 | if (err == noErr) | ||
| 10882 | err = DMRegisterNotifyProc (handle_dm_notificationUPP, &psn); | ||
| 10883 | } | ||
| 10884 | #endif | ||
| 10424 | 10885 | ||
| 10425 | return err; | 10886 | return err; |
| 10426 | } | 10887 | } |
| @@ -10636,44 +11097,6 @@ mac_post_mouse_moved_event () | |||
| 10636 | 11097 | ||
| 10637 | return err; | 11098 | return err; |
| 10638 | } | 11099 | } |
| 10639 | |||
| 10640 | static void | ||
| 10641 | mac_set_unicode_keystroke_event (code, buf) | ||
| 10642 | UniChar code; | ||
| 10643 | struct input_event *buf; | ||
| 10644 | { | ||
| 10645 | int charset_id, c1, c2; | ||
| 10646 | |||
| 10647 | if (code < 0x80) | ||
| 10648 | { | ||
| 10649 | buf->kind = ASCII_KEYSTROKE_EVENT; | ||
| 10650 | buf->code = code; | ||
| 10651 | } | ||
| 10652 | else if (code < 0x100) | ||
| 10653 | { | ||
| 10654 | if (code < 0xA0) | ||
| 10655 | charset_id = CHARSET_8_BIT_CONTROL; | ||
| 10656 | else | ||
| 10657 | charset_id = charset_latin_iso8859_1; | ||
| 10658 | buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT; | ||
| 10659 | buf->code = MAKE_CHAR (charset_id, code, 0); | ||
| 10660 | } | ||
| 10661 | else | ||
| 10662 | { | ||
| 10663 | if (code < 0x2500) | ||
| 10664 | charset_id = charset_mule_unicode_0100_24ff, | ||
| 10665 | code -= 0x100; | ||
| 10666 | else if (code < 0x33FF) | ||
| 10667 | charset_id = charset_mule_unicode_2500_33ff, | ||
| 10668 | code -= 0x2500; | ||
| 10669 | else if (code >= 0xE000) | ||
| 10670 | charset_id = charset_mule_unicode_e000_ffff, | ||
| 10671 | code -= 0xE000; | ||
| 10672 | c1 = (code / 96) + 32, c2 = (code % 96) + 32; | ||
| 10673 | buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT; | ||
| 10674 | buf->code = MAKE_CHAR (charset_id, c1, c2); | ||
| 10675 | } | ||
| 10676 | } | ||
| 10677 | #endif | 11100 | #endif |
| 10678 | 11101 | ||
| 10679 | /* Emacs calls this whenever it wants to read an input event from the | 11102 | /* Emacs calls this whenever it wants to read an input event from the |
| @@ -10729,28 +11152,13 @@ XTread_socket (sd, expected, hold_quit) | |||
| 10729 | 11152 | ||
| 10730 | #if TARGET_API_MAC_CARBON | 11153 | #if TARGET_API_MAC_CARBON |
| 10731 | timestamp = GetEventTime (eventRef) / kEventDurationMillisecond; | 11154 | timestamp = GetEventTime (eventRef) / kEventDurationMillisecond; |
| 10732 | #else | ||
| 10733 | timestamp = er.when * (1000 / 60); /* ticks to milliseconds */ | ||
| 10734 | #endif | ||
| 10735 | 11155 | ||
| 10736 | #if TARGET_API_MAC_CARBON | ||
| 10737 | /* Handle new events */ | ||
| 10738 | if (!mac_convert_event_ref (eventRef, &er)) | 11156 | if (!mac_convert_event_ref (eventRef, &er)) |
| 10739 | { | 11157 | goto OTHER; |
| 10740 | /* There used to be a handler for the kEventMouseWheelMoved | 11158 | #else /* !TARGET_API_MAC_CARBON */ |
| 10741 | event here. But as of Mac OS X 10.4, this kind of event | 11159 | timestamp = er.when * (1000 / 60); /* ticks to milliseconds */ |
| 10742 | is not directly posted to the main event queue by | 11160 | #endif /* !TARGET_API_MAC_CARBON */ |
| 10743 | two-finger scrolling on the trackpad. Instead, some | 11161 | |
| 10744 | private event is posted and it is converted to a wheel | ||
| 10745 | event by the default handler for the application target. | ||
| 10746 | The converted one can be received by a Carbon event | ||
| 10747 | handler installed on a window target. */ | ||
| 10748 | read_socket_inev = &inev; | ||
| 10749 | SendEventToEventTarget (eventRef, toolbox_dispatcher); | ||
| 10750 | read_socket_inev = NULL; | ||
| 10751 | } | ||
| 10752 | else | ||
| 10753 | #endif /* TARGET_API_MAC_CARBON */ | ||
| 10754 | switch (er.what) | 11162 | switch (er.what) |
| 10755 | { | 11163 | { |
| 10756 | case mouseDown: | 11164 | case mouseDown: |
| @@ -10761,10 +11169,14 @@ XTread_socket (sd, expected, hold_quit) | |||
| 10761 | int tool_bar_p = 0; | 11169 | int tool_bar_p = 0; |
| 10762 | 11170 | ||
| 10763 | #if TARGET_API_MAC_CARBON | 11171 | #if TARGET_API_MAC_CARBON |
| 11172 | OSStatus err; | ||
| 11173 | |||
| 10764 | /* This is needed to send mouse events like aqua window | 11174 | /* This is needed to send mouse events like aqua window |
| 10765 | buttons to the correct handler. */ | 11175 | buttons to the correct handler. */ |
| 10766 | if (SendEventToEventTarget (eventRef, toolbox_dispatcher) | 11176 | read_socket_inev = &inev; |
| 10767 | != eventNotHandledErr) | 11177 | err = SendEventToEventTarget (eventRef, toolbox_dispatcher); |
| 11178 | read_socket_inev = NULL; | ||
| 11179 | if (err != eventNotHandledErr) | ||
| 10768 | break; | 11180 | break; |
| 10769 | #endif | 11181 | #endif |
| 10770 | last_mouse_glyph_frame = 0; | 11182 | last_mouse_glyph_frame = 0; |
| @@ -10813,16 +11225,19 @@ XTread_socket (sd, expected, hold_quit) | |||
| 10813 | { | 11225 | { |
| 10814 | ControlPartCode control_part_code; | 11226 | ControlPartCode control_part_code; |
| 10815 | ControlRef ch; | 11227 | ControlRef ch; |
| 10816 | Point mouse_loc = er.where; | 11228 | Point mouse_loc; |
| 10817 | #ifdef MAC_OSX | 11229 | #ifdef MAC_OSX |
| 10818 | ControlKind control_kind; | 11230 | ControlKind control_kind; |
| 10819 | #endif | 11231 | #endif |
| 10820 | 11232 | ||
| 10821 | f = mac_window_to_frame (window_ptr); | 11233 | f = mac_window_to_frame (window_ptr); |
| 10822 | /* convert to local coordinates of new window */ | 11234 | /* convert to local coordinates of new window */ |
| 10823 | SetPortWindowPort (window_ptr); | 11235 | mouse_loc.h = (er.where.h |
| 10824 | 11236 | - (f->left_pos | |
| 10825 | GlobalToLocal (&mouse_loc); | 11237 | + FRAME_OUTER_TO_INNER_DIFF_X (f))); |
| 11238 | mouse_loc.v = (er.where.v | ||
| 11239 | - (f->top_pos | ||
| 11240 | + FRAME_OUTER_TO_INNER_DIFF_Y (f))); | ||
| 10826 | #if TARGET_API_MAC_CARBON | 11241 | #if TARGET_API_MAC_CARBON |
| 10827 | ch = FindControlUnderMouse (mouse_loc, window_ptr, | 11242 | ch = FindControlUnderMouse (mouse_loc, window_ptr, |
| 10828 | &control_part_code); | 11243 | &control_part_code); |
| @@ -11008,33 +11423,15 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11008 | } | 11423 | } |
| 11009 | break; | 11424 | break; |
| 11010 | 11425 | ||
| 11426 | #if !TARGET_API_MAC_CARBON | ||
| 11011 | case updateEvt: | 11427 | case updateEvt: |
| 11012 | #if TARGET_API_MAC_CARBON | ||
| 11013 | if (SendEventToEventTarget (eventRef, toolbox_dispatcher) | ||
| 11014 | != eventNotHandledErr) | ||
| 11015 | break; | ||
| 11016 | #else | ||
| 11017 | do_window_update ((WindowRef) er.message); | 11428 | do_window_update ((WindowRef) er.message); |
| 11018 | #endif | ||
| 11019 | break; | 11429 | break; |
| 11430 | #endif | ||
| 11020 | 11431 | ||
| 11021 | case osEvt: | 11432 | case osEvt: |
| 11022 | #if TARGET_API_MAC_CARBON | ||
| 11023 | if (SendEventToEventTarget (eventRef, toolbox_dispatcher) | ||
| 11024 | != eventNotHandledErr) | ||
| 11025 | break; | ||
| 11026 | #endif | ||
| 11027 | switch ((er.message >> 24) & 0x000000FF) | 11433 | switch ((er.message >> 24) & 0x000000FF) |
| 11028 | { | 11434 | { |
| 11029 | case suspendResumeMessage: | ||
| 11030 | #if USE_MAC_TSM | ||
| 11031 | if (er.message & resumeFlag) | ||
| 11032 | mac_tsm_resume (); | ||
| 11033 | else | ||
| 11034 | mac_tsm_suspend (); | ||
| 11035 | #endif | ||
| 11036 | break; | ||
| 11037 | |||
| 11038 | case mouseMovedMessage: | 11435 | case mouseMovedMessage: |
| 11039 | #if !TARGET_API_MAC_CARBON | 11436 | #if !TARGET_API_MAC_CARBON |
| 11040 | SetRectRgn (mouse_region, er.where.h, er.where.v, | 11437 | SetRectRgn (mouse_region, er.where.h, er.where.v, |
| @@ -11058,12 +11455,14 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11058 | if (f) | 11455 | if (f) |
| 11059 | { | 11456 | { |
| 11060 | WindowRef wp = FRAME_MAC_WINDOW (f); | 11457 | WindowRef wp = FRAME_MAC_WINDOW (f); |
| 11061 | Point mouse_pos = er.where; | 11458 | Point mouse_pos; |
| 11062 | 11459 | ||
| 11063 | SetPortWindowPort (wp); | 11460 | mouse_pos.h = (er.where.h |
| 11064 | 11461 | - (f->left_pos | |
| 11065 | GlobalToLocal (&mouse_pos); | 11462 | + FRAME_OUTER_TO_INNER_DIFF_X (f))); |
| 11066 | 11463 | mouse_pos.v = (er.where.v | |
| 11464 | - (f->top_pos | ||
| 11465 | + FRAME_OUTER_TO_INNER_DIFF_Y (f))); | ||
| 11067 | if (dpyinfo->grabbed && tracked_scroll_bar) | 11466 | if (dpyinfo->grabbed && tracked_scroll_bar) |
| 11068 | #ifdef USE_TOOLKIT_SCROLL_BARS | 11467 | #ifdef USE_TOOLKIT_SCROLL_BARS |
| 11069 | x_scroll_bar_handle_drag (wp, tracked_scroll_bar, | 11468 | x_scroll_bar_handle_drag (wp, tracked_scroll_bar, |
| @@ -11111,6 +11510,9 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11111 | if (!NILP (help_echo_string) || !NILP (previous_help_echo_string)) | 11510 | if (!NILP (help_echo_string) || !NILP (previous_help_echo_string)) |
| 11112 | do_help = 1; | 11511 | do_help = 1; |
| 11113 | break; | 11512 | break; |
| 11513 | |||
| 11514 | default: | ||
| 11515 | goto OTHER; | ||
| 11114 | } | 11516 | } |
| 11115 | break; | 11517 | break; |
| 11116 | 11518 | ||
| @@ -11118,11 +11520,6 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11118 | { | 11520 | { |
| 11119 | WindowRef window_ptr = (WindowRef) er.message; | 11521 | WindowRef window_ptr = (WindowRef) er.message; |
| 11120 | 11522 | ||
| 11121 | #if TARGET_API_MAC_CARBON | ||
| 11122 | if (SendEventToEventTarget (eventRef, toolbox_dispatcher) | ||
| 11123 | != eventNotHandledErr) | ||
| 11124 | break; | ||
| 11125 | #endif | ||
| 11126 | if (window_ptr == tip_window) | 11523 | if (window_ptr == tip_window) |
| 11127 | { | 11524 | { |
| 11128 | HideWindow (tip_window); | 11525 | HideWindow (tip_window); |
| @@ -11130,21 +11527,26 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11130 | } | 11527 | } |
| 11131 | 11528 | ||
| 11132 | if (!is_emacs_window (window_ptr)) | 11529 | if (!is_emacs_window (window_ptr)) |
| 11133 | break; | 11530 | goto OTHER; |
| 11531 | |||
| 11532 | f = mac_window_to_frame (window_ptr); | ||
| 11134 | 11533 | ||
| 11135 | if ((er.modifiers & activeFlag) != 0) | 11534 | if ((er.modifiers & activeFlag) != 0) |
| 11136 | { | 11535 | { |
| 11137 | /* A window has been activated */ | 11536 | /* A window has been activated */ |
| 11138 | Point mouse_loc = er.where; | 11537 | Point mouse_loc; |
| 11139 | 11538 | ||
| 11140 | x_detect_focus_change (dpyinfo, &er, &inev); | 11539 | x_detect_focus_change (dpyinfo, &er, &inev); |
| 11141 | 11540 | ||
| 11142 | SetPortWindowPort (window_ptr); | 11541 | mouse_loc.h = (er.where.h |
| 11143 | GlobalToLocal (&mouse_loc); | 11542 | - (f->left_pos |
| 11543 | + FRAME_OUTER_TO_INNER_DIFF_X (f))); | ||
| 11544 | mouse_loc.v = (er.where.v | ||
| 11545 | - (f->top_pos | ||
| 11546 | + FRAME_OUTER_TO_INNER_DIFF_Y (f))); | ||
| 11144 | /* Window-activated event counts as mouse movement, | 11547 | /* Window-activated event counts as mouse movement, |
| 11145 | so update things that depend on mouse position. */ | 11548 | so update things that depend on mouse position. */ |
| 11146 | note_mouse_movement (mac_window_to_frame (window_ptr), | 11549 | note_mouse_movement (f, &mouse_loc); |
| 11147 | &mouse_loc); | ||
| 11148 | } | 11550 | } |
| 11149 | else | 11551 | else |
| 11150 | { | 11552 | { |
| @@ -11169,7 +11571,6 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11169 | 11571 | ||
| 11170 | x_detect_focus_change (dpyinfo, &er, &inev); | 11572 | x_detect_focus_change (dpyinfo, &er, &inev); |
| 11171 | 11573 | ||
| 11172 | f = mac_window_to_frame (window_ptr); | ||
| 11173 | if (f == dpyinfo->mouse_face_mouse_frame) | 11574 | if (f == dpyinfo->mouse_face_mouse_frame) |
| 11174 | { | 11575 | { |
| 11175 | /* If we move outside the frame, then we're | 11576 | /* If we move outside the frame, then we're |
| @@ -11192,218 +11593,26 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11192 | case keyDown: | 11593 | case keyDown: |
| 11193 | case keyUp: | 11594 | case keyUp: |
| 11194 | case autoKey: | 11595 | case autoKey: |
| 11195 | { | 11596 | ObscureCursor (); |
| 11196 | int keycode = (er.message & keyCodeMask) >> 8; | ||
| 11197 | static SInt16 last_key_script = -1; | ||
| 11198 | SInt16 current_key_script; | ||
| 11199 | UInt32 modifiers = er.modifiers, mapped_modifiers; | ||
| 11200 | |||
| 11201 | #ifdef MAC_OSX | ||
| 11202 | GetEventParameter (eventRef, kEventParamKeyModifiers, | ||
| 11203 | typeUInt32, NULL, | ||
| 11204 | sizeof (UInt32), NULL, &modifiers); | ||
| 11205 | #endif | ||
| 11206 | mapped_modifiers = mac_mapped_modifiers (modifiers); | ||
| 11207 | |||
| 11208 | #if defined (MAC_OSX) || USE_MAC_TSM | ||
| 11209 | /* When using Carbon Events, we need to pass raw keyboard | ||
| 11210 | events to the TSM ourselves. If TSM handles it, it | ||
| 11211 | will pass back noErr, otherwise it will pass back | ||
| 11212 | "eventNotHandledErr" and we can process it | ||
| 11213 | normally. */ | ||
| 11214 | if (!(mapped_modifiers | ||
| 11215 | & ~(mac_pass_command_to_system ? cmdKey : 0) | ||
| 11216 | & ~(mac_pass_control_to_system ? controlKey : 0))) | ||
| 11217 | { | ||
| 11218 | OSStatus err; | ||
| 11219 | |||
| 11220 | read_socket_inev = &inev; | ||
| 11221 | err = SendEventToEventTarget (eventRef, toolbox_dispatcher); | ||
| 11222 | read_socket_inev = NULL; | ||
| 11223 | if (err != eventNotHandledErr) | ||
| 11224 | break; | ||
| 11225 | } | ||
| 11226 | #endif | ||
| 11227 | if (er.what == keyUp) | ||
| 11228 | break; | ||
| 11229 | |||
| 11230 | ObscureCursor (); | ||
| 11231 | |||
| 11232 | f = mac_focus_frame (dpyinfo); | ||
| 11233 | |||
| 11234 | if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight) | ||
| 11235 | && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window)) | ||
| 11236 | { | ||
| 11237 | clear_mouse_face (dpyinfo); | ||
| 11238 | dpyinfo->mouse_face_hidden = 1; | ||
| 11239 | } | ||
| 11240 | |||
| 11241 | current_key_script = GetScriptManagerVariable (smKeyScript); | ||
| 11242 | if (last_key_script != current_key_script) | ||
| 11243 | { | ||
| 11244 | struct input_event event; | ||
| 11245 | |||
| 11246 | EVENT_INIT (event); | ||
| 11247 | event.kind = LANGUAGE_CHANGE_EVENT; | ||
| 11248 | event.arg = Qnil; | ||
| 11249 | event.code = current_key_script; | ||
| 11250 | event.timestamp = timestamp; | ||
| 11251 | kbd_buffer_store_event (&event); | ||
| 11252 | count++; | ||
| 11253 | last_key_script = current_key_script; | ||
| 11254 | } | ||
| 11255 | |||
| 11256 | #if USE_MAC_TSM | ||
| 11257 | if (inev.kind != NO_EVENT) | ||
| 11258 | break; | ||
| 11259 | #endif | ||
| 11260 | |||
| 11261 | #ifdef MAC_OSX | ||
| 11262 | if (mapped_modifiers & kEventKeyModifierFnMask | ||
| 11263 | && keycode <= 0x7f | ||
| 11264 | && fn_keycode_to_keycode_table[keycode]) | ||
| 11265 | keycode = fn_keycode_to_keycode_table[keycode]; | ||
| 11266 | #endif | ||
| 11267 | if (keycode <= 0x7f && keycode_to_xkeysym_table [keycode]) | ||
| 11268 | { | ||
| 11269 | inev.kind = NON_ASCII_KEYSTROKE_EVENT; | ||
| 11270 | inev.code = 0xff00 | keycode_to_xkeysym_table [keycode]; | ||
| 11271 | #ifdef MAC_OSX | ||
| 11272 | if (modifiers & kEventKeyModifierFnMask | ||
| 11273 | && keycode <= 0x7f | ||
| 11274 | && fn_keycode_to_keycode_table[keycode] == keycode) | ||
| 11275 | modifiers &= ~kEventKeyModifierFnMask; | ||
| 11276 | #endif | ||
| 11277 | } | ||
| 11278 | else if (mapped_modifiers) | ||
| 11279 | { | ||
| 11280 | /* translate the keycode back to determine the | ||
| 11281 | original key */ | ||
| 11282 | #ifdef MAC_OSX | ||
| 11283 | UCKeyboardLayout *uchr_ptr = NULL; | ||
| 11284 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | ||
| 11285 | OSStatus err; | ||
| 11286 | KeyboardLayoutRef layout; | ||
| 11287 | 11597 | ||
| 11288 | err = KLGetCurrentKeyboardLayout (&layout); | 11598 | f = mac_focus_frame (dpyinfo); |
| 11289 | if (err == noErr) | 11599 | XSETFRAME (inev.frame_or_window, f); |
| 11290 | KLGetKeyboardLayoutProperty (layout, kKLuchrData, | ||
| 11291 | (const void **) &uchr_ptr); | ||
| 11292 | #else | ||
| 11293 | static SInt16 last_key_layout_id = 0; | ||
| 11294 | static Handle uchr_handle = (Handle)-1; | ||
| 11295 | SInt16 current_key_layout_id = | ||
| 11296 | GetScriptVariable (current_key_script, smScriptKeys); | ||
| 11297 | |||
| 11298 | if (uchr_handle == (Handle)-1 | ||
| 11299 | || last_key_layout_id != current_key_layout_id) | ||
| 11300 | { | ||
| 11301 | uchr_handle = GetResource ('uchr', current_key_layout_id); | ||
| 11302 | last_key_layout_id = current_key_layout_id; | ||
| 11303 | } | ||
| 11304 | if (uchr_handle) | ||
| 11305 | uchr_ptr = (UCKeyboardLayout *)*uchr_handle; | ||
| 11306 | #endif | ||
| 11307 | |||
| 11308 | if (uchr_ptr) | ||
| 11309 | { | ||
| 11310 | OSStatus status; | ||
| 11311 | UInt16 key_action = er.what - keyDown; | ||
| 11312 | UInt32 modifier_key_state = | ||
| 11313 | (modifiers & ~mapped_modifiers) >> 8; | ||
| 11314 | UInt32 keyboard_type = LMGetKbdType (); | ||
| 11315 | SInt32 dead_key_state = 0; | ||
| 11316 | UniChar code; | ||
| 11317 | UniCharCount actual_length; | ||
| 11318 | |||
| 11319 | status = UCKeyTranslate (uchr_ptr, | ||
| 11320 | keycode, key_action, | ||
| 11321 | modifier_key_state, | ||
| 11322 | keyboard_type, | ||
| 11323 | kUCKeyTranslateNoDeadKeysMask, | ||
| 11324 | &dead_key_state, | ||
| 11325 | 1, &actual_length, &code); | ||
| 11326 | if (status == noErr && actual_length == 1) | ||
| 11327 | mac_set_unicode_keystroke_event (code, &inev); | ||
| 11328 | } | ||
| 11329 | #endif /* MAC_OSX */ | ||
| 11330 | |||
| 11331 | if (inev.kind == NO_EVENT) | ||
| 11332 | { | ||
| 11333 | /* This code comes from Keyboard Resource, | ||
| 11334 | Appendix C of IM - Text. This is necessary | ||
| 11335 | since shift is ignored in KCHR table | ||
| 11336 | translation when option or command is pressed. | ||
| 11337 | It also does not translate correctly | ||
| 11338 | control-shift chars like C-% so mask off shift | ||
| 11339 | here also. */ | ||
| 11340 | /* Mask off modifier keys that are mapped to some | ||
| 11341 | Emacs modifiers. */ | ||
| 11342 | int new_modifiers = er.modifiers & ~mapped_modifiers; | ||
| 11343 | /* set high byte of keycode to modifier high byte*/ | ||
| 11344 | int new_keycode = keycode | new_modifiers; | ||
| 11345 | Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache); | ||
| 11346 | unsigned long some_state = 0; | ||
| 11347 | UInt32 new_char_code; | ||
| 11348 | |||
| 11349 | new_char_code = KeyTranslate (kchr_ptr, new_keycode, | ||
| 11350 | &some_state); | ||
| 11351 | if (new_char_code == 0) | ||
| 11352 | /* Seems like a dead key. Append up-stroke. */ | ||
| 11353 | new_char_code = KeyTranslate (kchr_ptr, | ||
| 11354 | new_keycode | 0x80, | ||
| 11355 | &some_state); | ||
| 11356 | if (new_char_code) | ||
| 11357 | { | ||
| 11358 | inev.kind = ASCII_KEYSTROKE_EVENT; | ||
| 11359 | inev.code = new_char_code & 0xff; | ||
| 11360 | } | ||
| 11361 | } | ||
| 11362 | } | ||
| 11363 | |||
| 11364 | if (inev.kind == NO_EVENT) | ||
| 11365 | { | ||
| 11366 | inev.kind = ASCII_KEYSTROKE_EVENT; | ||
| 11367 | inev.code = er.message & charCodeMask; | ||
| 11368 | } | ||
| 11369 | |||
| 11370 | inev.modifiers = mac_to_emacs_modifiers (modifiers); | ||
| 11371 | inev.modifiers |= (extra_keyboard_modifiers | ||
| 11372 | & (meta_modifier | alt_modifier | ||
| 11373 | | hyper_modifier | super_modifier)); | ||
| 11374 | XSETFRAME (inev.frame_or_window, f); | ||
| 11375 | 11600 | ||
| 11601 | /* If mouse-highlight is an integer, input clears out mouse | ||
| 11602 | highlighting. */ | ||
| 11603 | if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight) | ||
| 11604 | && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window)) | ||
| 11605 | { | ||
| 11606 | clear_mouse_face (dpyinfo); | ||
| 11607 | dpyinfo->mouse_face_hidden = 1; | ||
| 11608 | } | ||
| 11376 | #if TARGET_API_MAC_CARBON | 11609 | #if TARGET_API_MAC_CARBON |
| 11377 | if (inev.kind == ASCII_KEYSTROKE_EVENT | 11610 | goto OTHER; |
| 11378 | && inev.code >= 0x80 && inev.modifiers) | 11611 | #else |
| 11379 | { | 11612 | do_keystroke (er.what, er.message & charCodeMask, |
| 11380 | OSStatus err; | 11613 | (er.message & keyCodeMask) >> 8, |
| 11381 | TextEncoding encoding = kTextEncodingMacRoman; | 11614 | er.modifiers, timestamp, &inev); |
| 11382 | TextToUnicodeInfo ttu_info; | ||
| 11383 | |||
| 11384 | UpgradeScriptInfoToTextEncoding (current_key_script, | ||
| 11385 | kTextLanguageDontCare, | ||
| 11386 | kTextRegionDontCare, | ||
| 11387 | NULL, &encoding); | ||
| 11388 | err = CreateTextToUnicodeInfoByEncoding (encoding, &ttu_info); | ||
| 11389 | if (err == noErr) | ||
| 11390 | { | ||
| 11391 | UniChar code; | ||
| 11392 | Str255 pstr; | ||
| 11393 | ByteCount unicode_len; | ||
| 11394 | |||
| 11395 | pstr[0] = 1; | ||
| 11396 | pstr[1] = inev.code; | ||
| 11397 | err = ConvertFromPStringToUnicode (ttu_info, pstr, | ||
| 11398 | sizeof (UniChar), | ||
| 11399 | &unicode_len, &code); | ||
| 11400 | if (err == noErr && unicode_len == sizeof (UniChar)) | ||
| 11401 | mac_set_unicode_keystroke_event (code, &inev); | ||
| 11402 | DisposeTextToUnicodeInfo (&ttu_info); | ||
| 11403 | } | ||
| 11404 | } | ||
| 11405 | #endif | 11615 | #endif |
| 11406 | } | ||
| 11407 | break; | 11616 | break; |
| 11408 | 11617 | ||
| 11409 | case kHighLevelEvent: | 11618 | case kHighLevelEvent: |
| @@ -11411,6 +11620,16 @@ XTread_socket (sd, expected, hold_quit) | |||
| 11411 | break; | 11620 | break; |
| 11412 | 11621 | ||
| 11413 | default: | 11622 | default: |
| 11623 | OTHER: | ||
| 11624 | #if TARGET_API_MAC_CARBON | ||
| 11625 | { | ||
| 11626 | OSStatus err; | ||
| 11627 | |||
| 11628 | read_socket_inev = &inev; | ||
| 11629 | err = SendEventToEventTarget (eventRef, toolbox_dispatcher); | ||
| 11630 | read_socket_inev = NULL; | ||
| 11631 | } | ||
| 11632 | #endif | ||
| 11414 | break; | 11633 | break; |
| 11415 | } | 11634 | } |
| 11416 | #if TARGET_API_MAC_CARBON | 11635 | #if TARGET_API_MAC_CARBON |
| @@ -11880,11 +12099,7 @@ mac_initialize () | |||
| 11880 | 12099 | ||
| 11881 | #if TARGET_API_MAC_CARBON | 12100 | #if TARGET_API_MAC_CARBON |
| 11882 | 12101 | ||
| 11883 | #ifdef MAC_OSX | 12102 | install_application_handler (); |
| 11884 | init_service_handler (); | ||
| 11885 | #endif /* MAC_OSX */ | ||
| 11886 | |||
| 11887 | init_command_handler (); | ||
| 11888 | 12103 | ||
| 11889 | init_menu_bar (); | 12104 | init_menu_bar (); |
| 11890 | 12105 | ||