aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMiles Bader2007-06-11 00:58:11 +0000
committerMiles Bader2007-06-11 00:58:11 +0000
commitfb9a13e3dca1685b81fcf4d345133fb34911594d (patch)
tree181797239f450c33ca8fd0d4d18686bbfc68859d /src
parent4d3e23e3e8273e820d69e0ecca0f409c4b9a179e (diff)
parent2d715b39ea1c89066f469405d065dd1a6631d28e (diff)
downloademacs-fb9a13e3dca1685b81fcf4d345133fb34911594d.tar.gz
emacs-fb9a13e3dca1685b81fcf4d345133fb34911594d.zip
Merge from emacs--devo--0
Patches applied: * emacs--devo--0 (patch 781-792) - Update from CVS - Merge from gnus--rel--5.10 - Merge from emacs--rel--22 * emacs--rel--22 (patch 33-41) * gnus--rel--5.10 (patch 226-228) - Update from CVS Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-219
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog291
-rw-r--r--src/Makefile.in4
-rw-r--r--src/alloc.c7
-rw-r--r--src/buffer.c2
-rw-r--r--src/callint.c2
-rw-r--r--src/editfns.c17
-rw-r--r--src/emacs.c17
-rw-r--r--src/fileio.c2
-rw-r--r--src/fns.c2
-rw-r--r--src/frame.c11
-rw-r--r--src/image.c58
-rw-r--r--src/keyboard.c5
-rw-r--r--src/keymap.c2
-rw-r--r--src/lisp.h8
-rw-r--r--src/lread.c5
-rw-r--r--src/mac.c4
-rw-r--r--src/macfns.c17
-rw-r--r--src/macgui.h4
-rw-r--r--src/macmenu.c161
-rw-r--r--src/macselect.c11
-rw-r--r--src/macterm.c2100
-rw-r--r--src/macterm.h33
-rw-r--r--src/minibuf.c2
-rw-r--r--src/s/ms-w32.h1
-rw-r--r--src/search.c2
-rw-r--r--src/sunfns.c2
-rw-r--r--src/term.c47
-rw-r--r--src/w32fns.c4
-rw-r--r--src/window.c4
-rw-r--r--src/xdisp.c6
-rw-r--r--src/xfaces.c2
-rw-r--r--src/xfns.c18
-rw-r--r--src/xmenu.c4
-rw-r--r--src/xselect.c2
-rw-r--r--src/xterm.c6
35 files changed, 1685 insertions, 1178 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 31b8f51bf18..ea0d71f90db 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,224 @@
12007-06-10 Jason Rumney <jasonr@gnu.org>
2
3 * w32fns.c (Fx_file_dialog): Take size from struct not pointer.
4
52007-06-08 Juanma Barranquero <lekktu@gmail.com>
6
7 * callint.c (Fcall_interactively):
8 * editfns.c (Fdelete_and_extract_region):
9 * fileio.c (Fread_file_name):
10 * fns.c (Fmapconcat):
11 * keyboard.c (cmd_error_internal):
12 * keymap.c (Fkey_description):
13 * lread.c (openp):
14 * minibuf.c (read_minibuf):
15 * search.c (wordify):
16 * sunfns.c (sel_read):
17 * xdisp.c (Fformat_mode_line, syms_of_xdisp):
18 * xfns.c (x_default_scroll_bar_color_parameter):
19 * xmenu.c (menu_help_callback):
20 * xselect.c (Fx_get_atom_name):
21 * xterm.c (x_term_init): Use empty_unibyte_string.
22
232007-06-08 Dmitry Antipov <dmitry.antipov@mail.ru> (tiny change)
24
25 * alloc.c (init_strings): Initialize canonical empty strings.
26 (make_uninit_string, make_uninit_multibyte_string): Return appropriate
27 canonical empty string when the requested size is 0.
28
29 * emacs.c (empty_unibyte_string): Rename from empty_string.
30 (empty_multibyte_string): New canonical empty string.
31 (syms_of_emacs): Don't initialize empty_string.
32
33 * lisp.h (STRING_SET_UNIBYTE): Return the canonical empty unibyte
34 string, if appropriate.
35 (empty_unibyte_string, empty_multibyte_string): New externs.
36 (empty_string): Remove extern.
37
38 * lread.c (syms_of_lread): Use empty_unibyte_string.
39
402007-06-07 Jason Rumney <jasonr@gnu.org>
41
42 * s/ms-w32.h: Don't define HAVE_TZNAME.
43
44 * editfns.c (Fcurrent_time_zone): Remove hack for Japanese Windows.
45
462007-06-07 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
47
48 * mac.c (xrm_get_preference_database): Remove BLOCK_INPUT.
49
50 * macfns.c (mac_get_window_bounds): Move extern to macterm.h.
51 (compute_tip_xy) [TARGET_API_MAC_CARBON]: Use GetGlobalMouse.
52
53 * macmenu.c [TARGET_API_MAC_CARBON] (menu_target_item_handler):
54 Don't call next handler.
55 [TARGET_API_MAC_CARBON] (install_menu_target_item_handler):
56 Remove argument. Install handler to application.
57 (set_frame_menubar): Don't change deep_p.
58 (mac_menu_show): Use FRAME_OUTER_TO_INNER_DIFF_X and
59 FRAME_OUTER_TO_INNER_DIFF_Y.
60 (DIALOG_BUTTON_COMMAND_ID_OFFSET, DIALOG_BUTTON_COMMAND_ID_P)
61 (DIALOG_BUTTON_COMMAND_ID_VALUE, DIALOG_BUTTON_MAKE_COMMAND_ID)
62 [HAVE_DIALOGS]: New macros.
63 [HAVE_DIALOGS] (mac_handle_dialog_event, create_and_show_dialog):
64 Use them.
65 (fill_menubar) [TARGET_API_MAC_CARBON]: Use CFString.
66
67 * macselect.c [MAC_OSX] (install_service_handler): Rename from
68 init_service_handler. All callers changed. Return OSStatus value.
69
70 * macterm.c (mac_begin_cg_clip): New arg F. Call SetPortWindowPort.
71 All callers changed so as not to call SetPortWindowPort.
72 (mac_begin_cg_clip) [USE_CG_DRAWING]: Call mac_prepare_for_quickdraw.
73 (mac_draw_image_string_atsui) [USE_ATSUI]: New function created from
74 mac_draw_string_common.
75 (mac_draw_image_string_qd): Likewise.
76 (mac_draw_string_common): Use them. Add INLINE.
77 (XTmouse_position, x_scroll_bar_report_motion) [TARGET_API_MAC_CARBON]:
78 Use FRAME_OUTER_TO_INNER_DIFF_X, FRAME_OUTER_TO_INNER_DIFF_Y, and
79 GetGlobalMouse.
80 (x_set_mouse_pixel_position) [MAC_OSX]: Use FRAME_OUTER_TO_INNER_DIFF_X
81 and FRAME_OUTER_TO_INNER_DIFF_Y.
82 [TARGET_API_MAC_CARBON] (mac_handle_mouse_event): Likewise.
83 [USE_MAC_TSM] (mac_handle_text_input_event): Likewise.
84 (x_make_frame_visible) [TARGET_API_MAC_CARBON]: Move code for
85 repositioning window to mac_handle_window_event.
86 (x_make_frame_invisible) [TARGET_API_MAC_CARBON]: Move code for
87 saving window location to mac_handle_window_event
88 [USE_MAC_FONT_PANEL] (mac_show_hide_font_panel): Install handler here.
89 (install_menu_target_item_handler): Remove argument in extern.
90 [TARGET_API_MAC_CARBON] (mac_event_to_emacs_modifiers):
91 Also accept command events.
92 (do_keystroke): New function created from XTread_socket.
93 (init_command_handler): Remove functions.
94 [TARGET_API_MAC_CARBON] (mac_handle_window_event): Reposition window
95 and save window location by kEventWindowShowing and kEventWindowHiding
96 handlers here. Don't call next handler for window state change and
97 focus events.
98 (mac_handle_application_event, mac_handle_keyboard_event)
99 [TARGET_API_MAC_CARBON]: New functions.
100 (install_window_handler) [TARGET_API_MAC_CARBON]: Register handlers for
101 kEventWindowShowing and kEventWindowHiding events. Move installation
102 of mouse, font, text input and menu target item handlers to
103 install_application_handler.
104 (install_application_handler) [TARGET_API_MAC_CARBON]: New function.
105 (mac_handle_cg_display_reconfig) [MAC_OS_X_VERSION_MAX_ALLOWED >= 1030]:
106 New function.
107 (init_dm_notification_handler) [MAC_OS_X_VERSION_MAX_ALLOWED >= 1030]:
108 Register it.
109 (XTread_socket) [TARGET_API_MAC_CARBON]: Consolidate
110 SendEventToEventTarget calls. Use FRAME_OUTER_TO_INNER_DIFF_X and
111 FRAME_OUTER_TO_INNER_DIFF_Y. Move application activation handler
112 to mac_handle_application_event. Move keyboard handler to
113 mac_handle_keyboard_event.
114 (XTread_socket) [!TARGET_API_MAC_CARBON]: Use do_keystroke.
115 (mac_initialize) [TARGET_API_MAC_CARBON]: Don't call
116 init_command_handler. Call install_application_handler.
117
118 * macterm.h (mac_get_window_bounds): Move extern from macfns.c.
119 (FRAME_OUTER_TO_INNER_DIFF_X, FRAME_OUTER_TO_INNER_DIFF_Y): New macros.
120
1212007-06-07 Glenn Morris <rgm@gnu.org>
122
123 * emacs.c (main): Use `emacs-copyright' in --version output.
124
1252007-06-06 Chong Yidong <cyd@stupidchicken.com>
126
127 * image.c (xpm_load): Remove spurious call to
128 xpm_init_color_cache.
129
1302007-06-06 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
131
132 * macfns.c (mac_window): Replace WindowPtr with WindowRef.
133
134 * macgui.h: Replace WindowPtr with WindowRef.
135
136 * macmenu.c: Replace MenuHandle and GetMenuHandle with MenuRef and
137 GetMenuRef, respectively. Replace WindowPtr with WindowRef.
138 Replace ControlHandle with ControlRef.
139 (install_menu_quit_handler): Rename arg MENU_HANDLE to ROOT_MENU.
140
141 * macterm.c: Replace MenuHandle and GetMenuHandle with MenuRef and
142 GetMenuRef, respectively. Replace WindowPtr with WindowRef.
143 Replace ControlHandle with ControlRef.
144 (USE_CARBON_EVENTS): Remove. Use TARGET_API_MAC_CARBON instead.
145 [MAC_OS8] (do_get_menus): Rename variable `menu_handle' to `menu'.
146
147 * macterm.h (struct scroll_bar): Rename member control_handle_low
148 and control_handle_high to control_ref_low and control_ref_high.
149 All uses changed.
150 (SCROLL_BAR_CONTROL_REF, SET_SCROLL_BAR_CONTROL_REF): Rename from
151 SCROLL_BAR_CONTROL_HANDLE and SET_SCROLL_BAR_CONTROL_HANDLE,
152 respectively. All uses changed.
153 (XCreatePixmap, XCreatePixmapFromBitmapData, XSetWindowBackground)
154 (install_window_handler, remove_window_handler): Replace WindowPtr
155 with WindowRef in externs.
156
1572007-06-05 Juanma Barranquero <lekktu@gmail.com>
158
159 * xfaces.c (Finternal_lisp_face_p): Signal error for face alias loops.
160
1612007-06-03 Nick Roberts <nickrob@snap.net.nz>
162
163 * keyboard.c (discard_mouse_events): Add GPM_CLICK_EVENT case.
164
165 * frame.c (Fmouse_position, Fmouse_pixel_position):
166 Condition on HAVE_GPM too.
167
168 * term.c (term_mouse_highlight): Remove unused variables.
169 (Fterm_open_connection): Set gpm_zerobased to 1.
170 (term_mouse_movement, term_mouse_click, handle_one_term_event):
171 Use zero based co-ordinates.
172 (handle_one_term_event): Report a drag as mouse movement too.
173
174 * Makefile.in (MOUSE_SUPPORT): Define for HAVE_GPM.
175
1762007-06-03 Chong Yidong <cyd@stupidchicken.com>
177
178 * image.c (search_image_cache): New function. Require background
179 color match if background color is unspecified in the image spec.
180 (uncache_image, lookup_image): Use it.
181
1822007-06-01 Juanma Barranquero <lekktu@gmail.com>
183
184 * window.c (Fshrink_window): Reflow docstring.
185
1862007-06-02 Chong Yidong <cyd@stupidchicken.com>
187
188 * Version 22.1 released.
189
1902007-06-01 Richard Stallman <rms@gnu.org>
191
192 * xfns.c (x_encode_text): Add GCPRO.
193
1942007-06-01 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
195
196 * xfns.c (x_set_name_internal): Save encoded name before
197 x_encode_text in case string data is relocated.
198
1992007-05-31 Richard Stallman <rms@gnu.org>
200
201 * buffer.c (syms_of_buffer): Doc fix.
202
2032007-05-30 Nick Roberts <nickrob@snap.net.nz>
204
205 * sysdep.c (init_sys_modes): Add rather than replace with
206 O_NONBLOCK.
207
208 * frame.c [HAVE_GPM] (Fset_mouse_pixel_position): Add call to
209 term_mouse_moveto.
210
211 * termhooks.h (term_mouse_moveto): New extern.
212
213 * term.c (mouse_face_window): Rename...
214 (Qmouse_face_window): ...to this.
215 (term_show_mouse_face, term_clear_mouse_face)
216 (term_mouse_highlight): Use Qmouse_face_window.
217 (term_mouse_moveto): New function.
218 (term_mouse_position): Make it work.
219 (syms_of_term): Uncomment assignment to mouse_position_hook.
220 Staticpro Qmouse_face_window.
221
12007-05-28 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> 2222007-05-28 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
2 223
3 * xdisp.c (redisplay_internal): Bind inhibit-point-motion-hooks to t 224 * xdisp.c (redisplay_internal): Bind inhibit-point-motion-hooks to t
@@ -6,14 +227,14 @@
62007-05-26 Dan Nicolaescu <dann@ics.uci.edu> 2272007-05-26 Dan Nicolaescu <dann@ics.uci.edu>
7 228
8 * xfaces.c (syms_of_xfaces): Delete stray semicolon. 229 * xfaces.c (syms_of_xfaces): Delete stray semicolon.
9 * xdisp.c (next_element_from_buffer): 230 * xdisp.c (next_element_from_buffer):
10 * window.c (delete_window): 231 * window.c (delete_window):
11 * term.c (term_mouse_highlight): 232 * term.c (term_mouse_highlight):
12 * msdos.c (getdefdir): 233 * msdos.c (getdefdir):
13 * macterm.c (mac_create_bitmap_from_bitmap_data) 234 * macterm.c (mac_create_bitmap_from_bitmap_data)
14 (init_font_name_table): 235 (init_font_name_table):
15 * fns.c (Fsxhash): 236 * fns.c (Fsxhash):
16 * data.c (Fmake_local_variable): 237 * data.c (Fmake_local_variable):
17 * ccl.c (ccl_driver): Likewise. 238 * ccl.c (ccl_driver): Likewise.
18 239
192007-05-24 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> 2402007-05-24 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
@@ -25,7 +246,7 @@
25 246
26 * image.c (uncache_image): Fix typo. 247 * image.c (uncache_image): Fix typo.
27 248
282007-05-23 Johannes Weiner <hannes@saeurebad.de> (tiny change) 2492007-05-23 Johannes Weiner <hannes@saeurebad.de> (tiny change)
29 250
30 * keyboard.c (make_lispy_movement): Condition on HAVE_GPM too. 251 * keyboard.c (make_lispy_movement): Condition on HAVE_GPM too.
31 252
@@ -78,7 +299,7 @@
78 299
79 * termhooks.h [HAVE_GPM_H] (enum event_kind): Add GPM_CLICK_EVENT. 300 * termhooks.h [HAVE_GPM_H] (enum event_kind): Add GPM_CLICK_EVENT.
80 Include gpm.h. 301 Include gpm.h.
81 (handle_one_term_event, term_gpm) New externs. 302 (handle_one_term_event, term_gpm): New externs.
82 303
83 * sysdep.c [HAVE_GPM_H] (init_sys_modes): Make gpm_fd nonblocking 304 * sysdep.c [HAVE_GPM_H] (init_sys_modes): Make gpm_fd nonblocking
84 and allow it to be interrupted by SIGIO. 305 and allow it to be interrupted by SIGIO.
@@ -144,11 +365,12 @@
144 365
1452007-05-07 Stefan Monnier <monnier@iro.umontreal.ca> 3662007-05-07 Stefan Monnier <monnier@iro.umontreal.ca>
146 367
147 * editfns.c (Ftranspose_regions): Yet another int/Lisp_Object mixup (YAILOM) 368 * editfns.c (Ftranspose_regions): Yet another int/Lisp_Object
369 mixup (YAILOM).
148 370
1492007-05-07 Andreas Schwab <schwab@suse.de> 3712007-05-07 Andreas Schwab <schwab@suse.de>
150 372
151 * keymap.c (Flookup_key): Fix typo in last change. 373 * keymap.c (Flookup_key): Fix typo in last change.
152 374
1532007-05-07 Stefan Monnier <monnier@iro.umontreal.ca> 3752007-05-07 Stefan Monnier <monnier@iro.umontreal.ca>
154 376
@@ -2599,7 +2821,7 @@
2599 for writing files. Call gtk_file_chooser_set_current_name to keep 2821 for writing files. Call gtk_file_chooser_set_current_name to keep
2600 default filename. 2822 default filename.
2601 2823
2602 * minibuf.c (Finternal_complete_buffer): Move after DEFUN:s it calls 2824 * minibuf.c (Finternal_complete_buffer): Move after DEFUN:s it calls.
2603 2825
26042006-09-02 Jindrich Makovicka <makovick@gmail.com> (tiny change) 28262006-09-02 Jindrich Makovicka <makovick@gmail.com> (tiny change)
2605 2827
@@ -2856,7 +3078,7 @@
2856 * xterm.h (struct x_display_info): Add x_dnd_atoms* to keep track 3078 * xterm.h (struct x_display_info): Add x_dnd_atoms* to keep track
2857 of drag and drop Atoms. 3079 of drag and drop Atoms.
2858 3080
2859 * xterm.c (x_term_init): Initialize dpyinfo->x_dnd_atoms* 3081 * xterm.c (x_term_init): Initialize dpyinfo->x_dnd_atoms*.
2860 3082
28612006-08-10 Jan Dj,Ad(Brv <jan.h.d@swipnet.se> 30832006-08-10 Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
2862 3084
@@ -4022,7 +4244,7 @@
4022 4244
40232006-05-23 Jan Dj,Ad(Brv <jan.h.d@swipnet.se> 42452006-05-23 Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
4024 4246
4025 * xterm.c: Remove declarations already in xterm.h 4247 * xterm.c: Remove declarations already in xterm.h.
4026 4248
4027 * xterm.h: Add extern declarations for x_clear_errors, 4249 * xterm.h: Add extern declarations for x_clear_errors,
4028 x_fully_uncatch_errors, x_catching_errors and 4250 x_fully_uncatch_errors, x_catching_errors and
@@ -4763,7 +4985,8 @@
4763 4985
4764 * puresize.h (pure_write_error): Mark as NO_RETURN. 4986 * puresize.h (pure_write_error): Mark as NO_RETURN.
4765 4987
4766 * lisp.h (args_out_of_range, args_out_of_range_3) 4988 * lisp.h (args_out_of_range, args_out_of_range_3, Fkill_emacs):
4989 Likewise.
4767 4990
47682006-04-08 Eli Zaretskii <eliz@gnu.org> 49912006-04-08 Eli Zaretskii <eliz@gnu.org>
4769 4992
@@ -6380,7 +6603,7 @@
6380 6603
6381 * macterm.c (Qmac_ready_for_drag_n_drop, Qapplication, Qabout) 6604 * macterm.c (Qmac_ready_for_drag_n_drop, Qapplication, Qabout)
6382 (Qpreferences): Remove variables. 6605 (Qpreferences): Remove variables.
6383 (syms_of_macterm) : Don't initialize them. 6606 (syms_of_macterm): Don't initialize them.
6384 (Qhicommand) [USE_CARBON_EVENTS]: New variable. 6607 (Qhicommand) [USE_CARBON_EVENTS]: New variable.
6385 (syms_of_macterm) [USE_CARBON_EVENTS]: Initialize it. 6608 (syms_of_macterm) [USE_CARBON_EVENTS]: Initialize it.
6386 (init_required_apple_events, do_ae_open_application) 6609 (init_required_apple_events, do_ae_open_application)
@@ -7062,7 +7285,7 @@
7062 7285
7063 * mac.c [TARGET_API_MAC_CARBON] (get_cfstring_encoding_from_lisp): 7286 * mac.c [TARGET_API_MAC_CARBON] (get_cfstring_encoding_from_lisp):
7064 Allow nil as argument. 7287 Allow nil as argument.
7065 [TARGET_API_MAC_CARBON] (Fmac_code_convert_string): Regard nil 7288 [TARGET_API_MAC_CARBON] (Fmac_code_convert_string): Regard nil
7066 for encoding arguments as UTF-16 in native byte order, no BOM. 7289 for encoding arguments as UTF-16 in native byte order, no BOM.
7067 7290
7068 * macfns.c (Fx_create_frame): Add debugging code. 7291 * macfns.c (Fx_create_frame): Add debugging code.
@@ -9998,7 +10221,7 @@
9998 (cfobject_desc_to_lisp, cfproperty_list_to_lisp): Likewise. 10221 (cfobject_desc_to_lisp, cfproperty_list_to_lisp): Likewise.
9999 10222
10000 * process.c (init_process): Change `#ifdef DARWIN' to `#if 10223 * process.c (init_process): Change `#ifdef DARWIN' to `#if
10001 defined (DARWIN) || defined (MAC_OSX)' 10224 defined (DARWIN) || defined (MAC_OSX)'.
10002 10225
10003 * s/darwin.h (DARWIN): Don't define. 10226 * s/darwin.h (DARWIN): Don't define.
10004 10227
@@ -10535,7 +10758,7 @@
105352005-02-03 Kim F. Storm <storm@cua.dk> 107582005-02-03 Kim F. Storm <storm@cua.dk>
10536 10759
10537 * dispnew.c (build_frame_matrix_from_leaf_window) 10760 * dispnew.c (build_frame_matrix_from_leaf_window)
10538 [!GLYPH_DEBUG]: Fix xassert. 10761 [!GLYPH_DEBUG]: Fix xassert.
10539 10762
10540 * xfaces.c (x_free_gc) [!GLYPH_DEBUG]: Fix xassert. 10763 * xfaces.c (x_free_gc) [!GLYPH_DEBUG]: Fix xassert.
10541 10764
@@ -11425,7 +11648,7 @@
11425 11648
114262004-12-20 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> 116492004-12-20 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
11427 11650
11428 * macterm.c (mac_do_list_fonts): Fix memory leak 11651 * macterm.c (mac_do_list_fonts): Fix memory leak.
11429 11652
114302004-12-20 Richard M. Stallman <rms@gnu.org> 116532004-12-20 Richard M. Stallman <rms@gnu.org>
11431 11654
@@ -12205,7 +12428,7 @@
12205 * Makefile.in (SOME_MACHINE_OBJECTS): Add fringe.o, image.o 12428 * Makefile.in (SOME_MACHINE_OBJECTS): Add fringe.o, image.o
12206 and w32*.o. 12429 and w32*.o.
12207 (temacs${EXEEXT}): Generate buildobj.lst when temacs is linked. 12430 (temacs${EXEEXT}): Generate buildobj.lst when temacs is linked.
12208 (mostlyclean): Rm buildobj.lst 12431 (mostlyclean): Rm buildobj.lst.
12209 12432
12210 * makefile.w32-in ($(TEMACS)): Generate buildobj.lst when temacs 12433 * makefile.w32-in ($(TEMACS)): Generate buildobj.lst when temacs
12211 is linked. 12434 is linked.
@@ -12543,7 +12766,7 @@
12543 (SAFE_ALLOCA, SAFE_ALLOCA_LISP): Increment it when malloc is used. 12766 (SAFE_ALLOCA, SAFE_ALLOCA_LISP): Increment it when malloc is used.
12544 (SAFE_FREE): Test it to determine if we need to unwind to free. 12767 (SAFE_FREE): Test it to determine if we need to unwind to free.
12545 Remove size arg. All users changed. 12768 Remove size arg. All users changed.
12546 (SAFE_FREE_LISP) Remove. All users changed to use SAFE_FREE. 12769 (SAFE_FREE_LISP): Remove. All users changed to use SAFE_FREE.
12547 12770
125482004-10-26 Jan Dj,Ad(Brv <jan.h.d@swipnet.se> 127712004-10-26 Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
12549 12772
@@ -13200,7 +13423,7 @@
13200 (single_submenu): Use ENCODE_MENU_STRING 13423 (single_submenu): Use ENCODE_MENU_STRING
13201 (mac_menu_show): Use ENCODE_MENU_STRING. Reset grabbed because 13424 (mac_menu_show): Use ENCODE_MENU_STRING. Reset grabbed because
13202 button release isn't passed to event loop 13425 button release isn't passed to event loop
13203 (add_menu_item): Use SetMenuItemWithCFString 13426 (add_menu_item): Use SetMenuItemWithCFString.
13204 13427
132052004-08-26 Steven Tamm <steventamm@mac.com> 134282004-08-26 Steven Tamm <steventamm@mac.com>
13206 13429
@@ -13469,7 +13692,7 @@
13469 blocking on event queue only by calling ReceiveNextEvent 13692 blocking on event queue only by calling ReceiveNextEvent
13470 instead of select (since GUI events aren't on an fd). 13693 instead of select (since GUI events aren't on an fd).
13471 (sys_read): Remove function 13694 (sys_read): Remove function
13472 * sysdep.c: Remove redefine of read to sys_read if HAVE_CARBON 13695 * sysdep.c: Remove redefine of read to sys_read if HAVE_CARBON.
13473 13696
134742004-07-18 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> 136972004-07-18 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
13475 13698
@@ -13479,12 +13702,12 @@
13479 * macterm.c (x_make_frame_visible): Comment in polling on 13702 * macterm.c (x_make_frame_visible): Comment in polling on
13480 frame creation. 13703 frame creation.
13481 13704
13482 * keyboard.c: Undef SIGIO on Carbon 13705 * keyboard.c: Undef SIGIO on Carbon.
13483 13706
13484 * atimer.c (alarm_signal_handler): Call alarm handlers after 13707 * atimer.c (alarm_signal_handler): Call alarm handlers after
13485 scheduling. 13708 scheduling.
13486 13709
13487 * eval.c (Feval): Remove quit_char test 13710 * eval.c (Feval): Remove quit_char test.
13488 13711
13489 * process.c (wait_reading_process_input): Remove clearing 13712 * process.c (wait_reading_process_input): Remove clearing
13490 stdin for select call on process input. 13713 stdin for select call on process input.
@@ -14436,7 +14659,7 @@
144362004-05-11 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> 146592004-05-11 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
14437 14660
14438 * macterm.c (x_flush, XTframe_up_to_date): Use FRAME_MAC_P 14661 * macterm.c (x_flush, XTframe_up_to_date): Use FRAME_MAC_P
14439 instead of FRAME_X_P 14662 instead of FRAME_X_P.
14440 14663
144412004-05-11 Kim F. Storm <storm@cua.dk> 146642004-05-11 Kim F. Storm <storm@cua.dk>
14442 14665
@@ -14606,7 +14829,7 @@
14606 14829
146072004-05-01 Jason Rumney <jasonr@gnu.org> 148302004-05-01 Jason Rumney <jasonr@gnu.org>
14608 14831
14609 * w32term.c (x_draw_hollow_cursor): Sync with xterm.c 14832 * w32term.c (x_draw_hollow_cursor): Sync with xterm.c.
14610 14833
146112004-04-30 Kim F. Storm <storm@cua.dk> 148342004-04-30 Kim F. Storm <storm@cua.dk>
14612 14835
@@ -17399,7 +17622,7 @@
17399 17622
17400 * makefile.w32-in (alloca.o): Remove. 17623 * makefile.w32-in (alloca.o): Remove.
17401 (coding.o): Depend on intervals.h 17624 (coding.o): Depend on intervals.h
17402 (emacs.o, bytecode.o): Depend on window.h 17625 (emacs.o, bytecode.o): Depend on window.h.
17403 17626
174042003-09-01 Dave Love <fx@gnu.org> 176272003-09-01 Dave Love <fx@gnu.org>
17405 17628
@@ -18180,7 +18403,7 @@
18180 * gtkutil.c: Include keyboard.h, charset.h, coding.h. 18403 * gtkutil.c: Include keyboard.h, charset.h, coding.h.
18181 (xg_create_frame_widgets): Use ENCODE_UTF_8. 18404 (xg_create_frame_widgets): Use ENCODE_UTF_8.
18182 18405
18183 * xterm.c (Qutf_8): Move to coding.c 18406 * xterm.c (Qutf_8): Move to coding.c.
18184 18407
18185 * xmenu.c (ENCODE_MENU_STRING): New. 18408 * xmenu.c (ENCODE_MENU_STRING): New.
18186 (list_of_panes, list_of_items, digest_single_submenu, xmenu_show): 18409 (list_of_panes, list_of_items, digest_single_submenu, xmenu_show):
@@ -20909,7 +21132,7 @@
20909 (redisplay_internal): Add check for USE_GTK and popup_activated. 21132 (redisplay_internal): Add check for USE_GTK and popup_activated.
20910 (redisplay_window): Add check for USE_GTK and FRAME_EXTERNAL_MENU_BAR. 21133 (redisplay_window): Add check for USE_GTK and FRAME_EXTERNAL_MENU_BAR.
20911 (redisplay_window): Add check for USE_GTK and FRAME_EXTERNAL_TOOL_BAR. 21134 (redisplay_window): Add check for USE_GTK and FRAME_EXTERNAL_TOOL_BAR.
20912 (display_menu_bar): Add check for USE_GTK 21135 (display_menu_bar): Add check for USE_GTK.
20913 21136
20914 * lisp.h (Vx_resource_name): Declare extern. 21137 * lisp.h (Vx_resource_name): Declare extern.
20915 21138
@@ -22027,7 +22250,7 @@
22027 22250
22028 * buffer.c (assoc_ignore_text_properties, Fother_buffer, Fkill_buffer) 22251 * buffer.c (assoc_ignore_text_properties, Fother_buffer, Fkill_buffer)
22029 (call_overlay_mod_hooks): Use CONSP and XCAR/XCDR. 22252 (call_overlay_mod_hooks): Use CONSP and XCAR/XCDR.
22030 (Fget_buffer_create, advance_to_char_boundary): Use BEG and BEG_BYTE; 22253 (Fget_buffer_create, advance_to_char_boundary): Use BEG and BEG_BYTE.
22031 22254
220322002-10-21 Stefan Monnier <monnier@cs.yale.edu> 222552002-10-21 Stefan Monnier <monnier@cs.yale.edu>
22033 22256
@@ -23726,8 +23949,8 @@
23726 * fns.c (Fstring_make_unibyte): Doc fix. 23949 * fns.c (Fstring_make_unibyte): Doc fix.
23727 23950
23728 * xselect.c (lisp_data_to_selection_data): If the requested type 23951 * xselect.c (lisp_data_to_selection_data): If the requested type
23729 is STRING, call string_make_unibyte to encode the selected text 23952 is STRING, call string_make_unibyte to encode the selected text
23730 as a string. 23953 as a string.
23731 23954
23732 * window.c (Fset_window_hscroll): Doc fix. 23955 * window.c (Fset_window_hscroll): Doc fix.
23733 23956
diff --git a/src/Makefile.in b/src/Makefile.in
index f0733a7c125..9506d49e16b 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -691,8 +691,12 @@ otherobj= $(termcapobj) lastfile.o $(mallocobj) $(allocaobj) $(widgetobj) $(LIBO
691#define MOUSE_SUPPORT ${lispsource}mouse.elc \ 691#define MOUSE_SUPPORT ${lispsource}mouse.elc \
692 ${lispsource}select.elc ${lispsource}scroll-bar.elc 692 ${lispsource}select.elc ${lispsource}scroll-bar.elc
693#else 693#else
694#ifdef HAVE_GPM
695#define MOUSE_SUPPORT ${lispsource}mouse.elc
696#else
694#define MOUSE_SUPPORT 697#define MOUSE_SUPPORT
695#endif 698#endif
699#endif
696 700
697#ifdef VMS 701#ifdef VMS
698#define VMS_SUPPORT ${lispsource}vmsproc.elc ${lispsource}vms-patch.elc 702#define VMS_SUPPORT ${lispsource}vmsproc.elc ${lispsource}vms-patch.elc
diff --git a/src/alloc.c b/src/alloc.c
index 6c757567354..5e9979d1f6e 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -1756,6 +1756,8 @@ init_strings ()
1756 string_blocks = NULL; 1756 string_blocks = NULL;
1757 n_string_blocks = 0; 1757 n_string_blocks = 0;
1758 string_free_list = NULL; 1758 string_free_list = NULL;
1759 empty_unibyte_string = make_pure_string ("", 0, 0, 0);
1760 empty_multibyte_string = make_pure_string ("", 0, 0, 1);
1759} 1761}
1760 1762
1761 1763
@@ -2479,6 +2481,9 @@ make_uninit_string (length)
2479 int length; 2481 int length;
2480{ 2482{
2481 Lisp_Object val; 2483 Lisp_Object val;
2484
2485 if (!length)
2486 return empty_unibyte_string;
2482 val = make_uninit_multibyte_string (length, length); 2487 val = make_uninit_multibyte_string (length, length);
2483 STRING_SET_UNIBYTE (val); 2488 STRING_SET_UNIBYTE (val);
2484 return val; 2489 return val;
@@ -2497,6 +2502,8 @@ make_uninit_multibyte_string (nchars, nbytes)
2497 2502
2498 if (nchars < 0) 2503 if (nchars < 0)
2499 abort (); 2504 abort ();
2505 if (!nbytes)
2506 return empty_multibyte_string;
2500 2507
2501 s = allocate_string (); 2508 s = allocate_string ();
2502 allocate_string_data (s, nchars, nbytes); 2509 allocate_string_data (s, nchars, nbytes);
diff --git a/src/buffer.c b/src/buffer.c
index 895bb2b32e8..331df150f62 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -6002,7 +6002,7 @@ same format as a regular save would use. */);
6002The default is t, which means that text is invisible 6002The default is t, which means that text is invisible
6003if it has a non-nil `invisible' property. 6003if it has a non-nil `invisible' property.
6004If the value is a list, a text character is invisible if its `invisible' 6004If the value is a list, a text character is invisible if its `invisible'
6005property is an element in that list. 6005property is an element in that list (or is a list with members in common).
6006If an element is a cons cell of the form (PROP . ELLIPSIS), 6006If an element is a cons cell of the form (PROP . ELLIPSIS),
6007then characters with property value PROP are invisible, 6007then characters with property value PROP are invisible,
6008and they have an ellipsis as well if ELLIPSIS is non-nil. */); 6008and they have an ellipsis as well if ELLIPSIS is non-nil. */);
diff --git a/src/callint.c b/src/callint.c
index 39b2046e8fc..a989f9afe6d 100644
--- a/src/callint.c
+++ b/src/callint.c
@@ -585,7 +585,7 @@ invoke it. If KEYS is omitted or nil, the return value of
585 case 'G': /* Possibly nonexistent file name, 585 case 'G': /* Possibly nonexistent file name,
586 default to directory alone. */ 586 default to directory alone. */
587 args[i] = Fread_file_name (callint_message, 587 args[i] = Fread_file_name (callint_message,
588 Qnil, Qnil, Qnil, build_string (""), Qnil); 588 Qnil, Qnil, Qnil, empty_unibyte_string, Qnil);
589 break; 589 break;
590 590
591 case 'i': /* Ignore an argument -- Does not do I/O */ 591 case 'i': /* Ignore an argument -- Does not do I/O */
diff --git a/src/editfns.c b/src/editfns.c
index 6cdd63f2fd1..22aa47688a5 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -1972,6 +1972,7 @@ the data it can't find. */)
1972 int offset = tm_diff (t, &gmt); 1972 int offset = tm_diff (t, &gmt);
1973 char *s = 0; 1973 char *s = 0;
1974 char buf[6]; 1974 char buf[6];
1975
1975#ifdef HAVE_TM_ZONE 1976#ifdef HAVE_TM_ZONE
1976 if (t->tm_zone) 1977 if (t->tm_zone)
1977 s = (char *)t->tm_zone; 1978 s = (char *)t->tm_zone;
@@ -1982,19 +1983,6 @@ the data it can't find. */)
1982#endif 1983#endif
1983#endif /* not HAVE_TM_ZONE */ 1984#endif /* not HAVE_TM_ZONE */
1984 1985
1985#if defined HAVE_TM_ZONE || defined HAVE_TZNAME
1986 if (s)
1987 {
1988 /* On Japanese w32, we can get a Japanese string as time
1989 zone name. Don't accept that. */
1990 char *p;
1991 for (p = s; *p && (isalnum ((unsigned char)*p) || *p == ' '); ++p)
1992 ;
1993 if (p == s || *p)
1994 s = NULL;
1995 }
1996#endif
1997
1998 if (!s) 1986 if (!s)
1999 { 1987 {
2000 /* No local time zone name is available; use "+-NNNN" instead. */ 1988 /* No local time zone name is available; use "+-NNNN" instead. */
@@ -2002,6 +1990,7 @@ the data it can't find. */)
2002 sprintf (buf, "%c%02d%02d", (offset < 0 ? '-' : '+'), am/60, am%60); 1990 sprintf (buf, "%c%02d%02d", (offset < 0 ? '-' : '+'), am/60, am%60);
2003 s = buf; 1991 s = buf;
2004 } 1992 }
1993
2005 return Fcons (make_number (offset), Fcons (build_string (s), Qnil)); 1994 return Fcons (make_number (offset), Fcons (build_string (s), Qnil));
2006 } 1995 }
2007 else 1996 else
@@ -3174,7 +3163,7 @@ DEFUN ("delete-and-extract-region", Fdelete_and_extract_region,
3174{ 3163{
3175 validate_region (&start, &end); 3164 validate_region (&start, &end);
3176 if (XINT (start) == XINT (end)) 3165 if (XINT (start) == XINT (end))
3177 return build_string (""); 3166 return empty_unibyte_string;
3178 return del_range_1 (XINT (start), XINT (end), 1, 1); 3167 return del_range_1 (XINT (start), XINT (end), 1, 1);
3179} 3168}
3180 3169
diff --git a/src/emacs.c b/src/emacs.c
index 8336981e66c..961a1799955 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -133,8 +133,8 @@ Lisp_Object Vinstallation_directory;
133/* Hook run by `kill-emacs' before it does really anything. */ 133/* Hook run by `kill-emacs' before it does really anything. */
134Lisp_Object Vkill_emacs_hook; 134Lisp_Object Vkill_emacs_hook;
135 135
136/* An empty lisp string. To avoid having to build any other. */ 136/* Empty lisp strings. To avoid having to build any others. */
137Lisp_Object empty_string; 137Lisp_Object empty_unibyte_string, empty_multibyte_string;
138 138
139/* Search path separator. */ 139/* Search path separator. */
140Lisp_Object Vpath_separator; 140Lisp_Object Vpath_separator;
@@ -859,17 +859,23 @@ main (argc, argv
859 So ignore --version otherwise. */ 859 So ignore --version otherwise. */
860 && initialized) 860 && initialized)
861 { 861 {
862 Lisp_Object tem; 862 Lisp_Object tem, tem2;
863 tem = Fsymbol_value (intern ("emacs-version")); 863 tem = Fsymbol_value (intern ("emacs-version"));
864 tem2 = Fsymbol_value (intern ("emacs-copyright"));
864 if (!STRINGP (tem)) 865 if (!STRINGP (tem))
865 { 866 {
866 fprintf (stderr, "Invalid value of `emacs-version'\n"); 867 fprintf (stderr, "Invalid value of `emacs-version'\n");
867 exit (1); 868 exit (1);
868 } 869 }
870 if (!STRINGP (tem2))
871 {
872 fprintf (stderr, "Invalid value of `emacs-copyright'\n");
873 exit (1);
874 }
869 else 875 else
870 { 876 {
871 printf ("GNU Emacs %s\n", SDATA (tem)); 877 printf ("GNU Emacs %s\n", SDATA (tem));
872 printf ("Copyright (C) 2007 Free Software Foundation, Inc.\n"); 878 printf ("%s\n", SDATA(tem2));
873 printf ("GNU Emacs comes with ABSOLUTELY NO WARRANTY.\n"); 879 printf ("GNU Emacs comes with ABSOLUTELY NO WARRANTY.\n");
874 printf ("You may redistribute copies of Emacs\n"); 880 printf ("You may redistribute copies of Emacs\n");
875 printf ("under the terms of the GNU General Public License.\n"); 881 printf ("under the terms of the GNU General Public License.\n");
@@ -2494,9 +2500,6 @@ see `kill-emacs-query-functions' instead.
2494The hook is not run in batch mode, i.e., if `noninteractive' is non-nil. */); 2500The hook is not run in batch mode, i.e., if `noninteractive' is non-nil. */);
2495 Vkill_emacs_hook = Qnil; 2501 Vkill_emacs_hook = Qnil;
2496 2502
2497 empty_string = build_string ("");
2498 staticpro (&empty_string);
2499
2500 DEFVAR_INT ("emacs-priority", &emacs_priority, 2503 DEFVAR_INT ("emacs-priority", &emacs_priority,
2501 doc: /* Priority for Emacs to run at. 2504 doc: /* Priority for Emacs to run at.
2502This value is effective only if set before Emacs is dumped, 2505This value is effective only if set before Emacs is dumped,
diff --git a/src/fileio.c b/src/fileio.c
index d24d26561f2..90ee5064c07 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -6346,7 +6346,7 @@ and `read-file-name-function'. */)
6346 if (! replace_in_history) 6346 if (! replace_in_history)
6347 add_to_history = 1; 6347 add_to_history = 1;
6348 6348
6349 val = empty_string; 6349 val = empty_unibyte_string;
6350 } 6350 }
6351 6351
6352 unbind_to (count, Qnil); 6352 unbind_to (count, Qnil);
diff --git a/src/fns.c b/src/fns.c
index 9460a7c87c2..626aaa62821 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -2497,7 +2497,7 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
2497 wrong_type_argument (Qlistp, sequence); 2497 wrong_type_argument (Qlistp, sequence);
2498 leni = XINT (len); 2498 leni = XINT (len);
2499 nargs = leni + leni - 1; 2499 nargs = leni + leni - 1;
2500 if (nargs < 0) return build_string (""); 2500 if (nargs < 0) return empty_unibyte_string;
2501 2501
2502 SAFE_ALLOCA_LISP (args, nargs); 2502 SAFE_ALLOCA_LISP (args, nargs);
2503 2503
diff --git a/src/frame.c b/src/frame.c
index 4b26e087c85..8d73df140b7 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -1460,7 +1460,7 @@ and returns whatever that function returns. */)
1460 f = SELECTED_FRAME (); 1460 f = SELECTED_FRAME ();
1461 x = y = Qnil; 1461 x = y = Qnil;
1462 1462
1463#ifdef HAVE_MOUSE 1463#if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1464 /* It's okay for the hook to refrain from storing anything. */ 1464 /* It's okay for the hook to refrain from storing anything. */
1465 if (mouse_position_hook) 1465 if (mouse_position_hook)
1466 (*mouse_position_hook) (&f, -1, 1466 (*mouse_position_hook) (&f, -1,
@@ -1504,7 +1504,7 @@ and nil for X and Y. */)
1504 f = SELECTED_FRAME (); 1504 f = SELECTED_FRAME ();
1505 x = y = Qnil; 1505 x = y = Qnil;
1506 1506
1507#ifdef HAVE_MOUSE 1507#if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1508 /* It's okay for the hook to refrain from storing anything. */ 1508 /* It's okay for the hook to refrain from storing anything. */
1509 if (mouse_position_hook) 1509 if (mouse_position_hook)
1510 (*mouse_position_hook) (&f, -1, 1510 (*mouse_position_hook) (&f, -1,
@@ -1591,6 +1591,13 @@ before calling this function on it, like this.
1591 Fselect_frame (frame); 1591 Fselect_frame (frame);
1592 mouse_moveto (XINT (x), XINT (y)); 1592 mouse_moveto (XINT (x), XINT (y));
1593 } 1593 }
1594#else
1595#ifdef HAVE_GPM
1596 {
1597 Fselect_frame (frame);
1598 term_mouse_moveto (XINT (x), XINT (y));
1599 }
1600#endif
1594#endif 1601#endif
1595#endif 1602#endif
1596 1603
diff --git a/src/image.c b/src/image.c
index 11f4425136c..9cfcd5a63f8 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1609,6 +1609,7 @@ x_alloc_image_color (f, img, color_name, dflt)
1609 Image Cache 1609 Image Cache
1610 ***********************************************************************/ 1610 ***********************************************************************/
1611 1611
1612static struct image *search_image_cache P_ ((struct frame *, Lisp_Object, unsigned));
1612static void cache_image P_ ((struct frame *f, struct image *img)); 1613static void cache_image P_ ((struct frame *f, struct image *img));
1613static void postprocess_image P_ ((struct frame *, struct image *)); 1614static void postprocess_image P_ ((struct frame *, struct image *));
1614 1615
@@ -1631,24 +1632,47 @@ make_image_cache ()
1631} 1632}
1632 1633
1633 1634
1634/* Search frame F for an images with spec SPEC, and free it. */ 1635/* Find an image matching SPEC in the cache, and return it. If no
1635 1636 image is found, return NULL. */
1636static void 1637static struct image *
1637uncache_image (f, spec) 1638search_image_cache (f, spec, hash)
1638 struct frame *f; 1639 struct frame *f;
1639 Lisp_Object spec; 1640 Lisp_Object spec;
1641 unsigned hash;
1640{ 1642{
1641 struct image_cache *c = FRAME_X_IMAGE_CACHE (f);
1642 struct image *img; 1643 struct image *img;
1643 unsigned hash = sxhash (spec, 0); 1644 struct image_cache *c = FRAME_X_IMAGE_CACHE (f);
1645 Lisp_Object specified_bg = image_spec_value (spec, QCbackground, NULL);
1644 int i = hash % IMAGE_CACHE_BUCKETS_SIZE; 1646 int i = hash % IMAGE_CACHE_BUCKETS_SIZE;
1645 1647
1648 /* If the image spec does not specify a background color, the cached
1649 image must have the same background color as the current frame.
1650 The following code be improved. For example, jpeg does not
1651 support transparency, but currently a jpeg image spec won't match
1652 a cached spec created with a different frame background. The
1653 extra memory usage is probably negligible in practice. */
1654 if (!c) return NULL;
1655
1646 for (img = c->buckets[i]; img; img = img->next) 1656 for (img = c->buckets[i]; img; img = img->next)
1647 if (img->hash == hash && !NILP (Fequal (img->spec, spec))) 1657 if (img->hash == hash
1648 { 1658 && !NILP (Fequal (img->spec, spec))
1649 free_image (f, img); 1659 && (STRINGP (specified_bg)
1650 break; 1660 || img->background == FRAME_BACKGROUND_PIXEL (f)))
1651 } 1661 break;
1662 return img;
1663}
1664
1665
1666/* Search frame F for an image with spec SPEC, and free it. */
1667
1668static void
1669uncache_image (f, spec)
1670 struct frame *f;
1671 Lisp_Object spec;
1672{
1673 struct image *img = search_image_cache (f, spec, sxhash (spec, 0));
1674 if (img)
1675 free_image (f, img);
1652} 1676}
1653 1677
1654 1678
@@ -1875,9 +1899,7 @@ lookup_image (f, spec)
1875 struct frame *f; 1899 struct frame *f;
1876 Lisp_Object spec; 1900 Lisp_Object spec;
1877{ 1901{
1878 struct image_cache *c = FRAME_X_IMAGE_CACHE (f);
1879 struct image *img; 1902 struct image *img;
1880 int i;
1881 unsigned hash; 1903 unsigned hash;
1882 struct gcpro gcpro1; 1904 struct gcpro gcpro1;
1883 EMACS_TIME now; 1905 EMACS_TIME now;
@@ -1891,12 +1913,7 @@ lookup_image (f, spec)
1891 1913
1892 /* Look up SPEC in the hash table of the image cache. */ 1914 /* Look up SPEC in the hash table of the image cache. */
1893 hash = sxhash (spec, 0); 1915 hash = sxhash (spec, 0);
1894 i = hash % IMAGE_CACHE_BUCKETS_SIZE; 1916 img = search_image_cache (f, spec, hash);
1895
1896 for (img = c->buckets[i]; img; img = img->next)
1897 if (img->hash == hash && !NILP (Fequal (img->spec, spec)))
1898 break;
1899
1900 if (img && img->load_failed_p) 1917 if (img && img->load_failed_p)
1901 { 1918 {
1902 free_image (f, img); 1919 free_image (f, img);
@@ -3961,9 +3978,6 @@ xpm_load (f, img)
3961 attrs.valuemask |= XpmCloseness; 3978 attrs.valuemask |= XpmCloseness;
3962#endif /* not XpmAllocCloseColors */ 3979#endif /* not XpmAllocCloseColors */
3963#endif /* ALLOC_XPM_COLORS */ 3980#endif /* ALLOC_XPM_COLORS */
3964#ifdef ALLOC_XPM_COLORS
3965 xpm_init_color_cache (f, &attrs);
3966#endif
3967 3981
3968 /* If image specification contains symbolic color definitions, add 3982 /* If image specification contains symbolic color definitions, add
3969 these to `attrs'. */ 3983 these to `attrs'. */
diff --git a/src/keyboard.c b/src/keyboard.c
index bcc4a5fd655..6df2d1b0b25 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -1249,7 +1249,7 @@ cmd_error_internal (data, context)
1249 /* Use user's specified output function if any. */ 1249 /* Use user's specified output function if any. */
1250 if (!NILP (Vcommand_error_function)) 1250 if (!NILP (Vcommand_error_function))
1251 call3 (Vcommand_error_function, data, 1251 call3 (Vcommand_error_function, data,
1252 build_string (context ? context : ""), 1252 context ? build_string (context) : empty_unibyte_string,
1253 Vsignaling_function); 1253 Vsignaling_function);
1254 /* If the window system or terminal frame hasn't been initialized 1254 /* If the window system or terminal frame hasn't been initialized
1255 yet, or we're not interactive, write the message to stderr and exit. */ 1255 yet, or we're not interactive, write the message to stderr and exit. */
@@ -3918,6 +3918,9 @@ discard_mouse_events ()
3918#ifdef WINDOWSNT 3918#ifdef WINDOWSNT
3919 || sp->kind == W32_SCROLL_BAR_CLICK_EVENT 3919 || sp->kind == W32_SCROLL_BAR_CLICK_EVENT
3920#endif 3920#endif
3921#ifdef HAVE_GPM
3922 || sp->kind == GPM_CLICK_EVENT
3923#endif
3921 || sp->kind == SCROLL_BAR_CLICK_EVENT) 3924 || sp->kind == SCROLL_BAR_CLICK_EVENT)
3922 { 3925 {
3923 sp->kind = NO_EVENT; 3926 sp->kind = NO_EVENT;
diff --git a/src/keymap.c b/src/keymap.c
index 95534f9efa6..3649177d045 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -2218,7 +2218,7 @@ spaces are put between sequence elements, etc. */)
2218 len += 2; 2218 len += 2;
2219 } 2219 }
2220 else if (len == 0) 2220 else if (len == 0)
2221 return empty_string; 2221 return empty_unibyte_string;
2222 return Fconcat (len - 1, args); 2222 return Fconcat (len - 1, args);
2223 } 2223 }
2224 2224
diff --git a/src/lisp.h b/src/lisp.h
index 407c59e0c63..df62a261fe4 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -704,7 +704,10 @@ extern int string_bytes P_ ((struct Lisp_String *));
704#endif /* not GC_CHECK_STRING_BYTES */ 704#endif /* not GC_CHECK_STRING_BYTES */
705 705
706/* Mark STR as a unibyte string. */ 706/* Mark STR as a unibyte string. */
707#define STRING_SET_UNIBYTE(STR) (XSTRING (STR)->size_byte = -1) 707#define STRING_SET_UNIBYTE(STR) \
708 do { if (EQ (STR, empty_multibyte_string)) \
709 (STR) = empty_unibyte_string; \
710 else XSTRING (STR)->size_byte = -1; } while (0)
708 711
709/* Get text properties. */ 712/* Get text properties. */
710#define STRING_INTERVALS(STR) (XSTRING (STR)->intervals + 0) 713#define STRING_INTERVALS(STR) (XSTRING (STR)->intervals + 0)
@@ -3098,7 +3101,8 @@ extern void syms_of_frame P_ ((void));
3098/* defined in emacs.c */ 3101/* defined in emacs.c */
3099extern Lisp_Object decode_env_path P_ ((char *, char *)); 3102extern Lisp_Object decode_env_path P_ ((char *, char *));
3100extern Lisp_Object Vinvocation_name, Vinvocation_directory; 3103extern Lisp_Object Vinvocation_name, Vinvocation_directory;
3101extern Lisp_Object Vinstallation_directory, empty_string; 3104extern Lisp_Object Vinstallation_directory;
3105extern Lisp_Object empty_unibyte_string, empty_multibyte_string;
3102EXFUN (Fkill_emacs, 1); 3106EXFUN (Fkill_emacs, 1);
3103#if HAVE_SETLOCALE 3107#if HAVE_SETLOCALE
3104void fixup_locale P_ ((void)); 3108void fixup_locale P_ ((void));
diff --git a/src/lread.c b/src/lread.c
index ebc42e361ef..0a1260eda4e 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1397,7 +1397,7 @@ openp (path, str, suffixes, storeptr, predicate)
1397 fn = (char *) alloca (fn_size = 100 + want_size); 1397 fn = (char *) alloca (fn_size = 100 + want_size);
1398 1398
1399 /* Loop over suffixes. */ 1399 /* Loop over suffixes. */
1400 for (tail = NILP (suffixes) ? Fcons (build_string (""), Qnil) : suffixes; 1400 for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : suffixes;
1401 CONSP (tail); tail = XCDR (tail)) 1401 CONSP (tail); tail = XCDR (tail))
1402 { 1402 {
1403 int lsuffix = SBYTES (XCAR (tail)); 1403 int lsuffix = SBYTES (XCAR (tail));
@@ -4201,8 +4201,7 @@ and, if so, which suffixes they should try to append to the file name
4201in order to do so. However, if you want to customize which suffixes 4201in order to do so. However, if you want to customize which suffixes
4202the loading functions recognize as compression suffixes, you should 4202the loading functions recognize as compression suffixes, you should
4203customize `jka-compr-load-suffixes' rather than the present variable. */); 4203customize `jka-compr-load-suffixes' rather than the present variable. */);
4204 /* We don't use empty_string because it's not initialized yet. */ 4204 Vload_file_rep_suffixes = Fcons (empty_unibyte_string, Qnil);
4205 Vload_file_rep_suffixes = Fcons (build_string (""), Qnil);
4206 4205
4207 DEFVAR_BOOL ("load-in-progress", &load_in_progress, 4206 DEFVAR_BOOL ("load-in-progress", &load_in_progress,
4208 doc: /* Non-nil iff inside of `load'. */); 4207 doc: /* Non-nil iff inside of `load'. */);
diff --git a/src/mac.c b/src/mac.c
index 8e3f49d2bfe..d783243399d 100644
--- a/src/mac.c
+++ b/src/mac.c
@@ -1826,8 +1826,6 @@ xrm_get_preference_database (application)
1826 1826
1827 GCPRO3 (database, quarks, value); 1827 GCPRO3 (database, quarks, value);
1828 1828
1829 BLOCK_INPUT;
1830
1831 app_id = kCFPreferencesCurrentApplication; 1829 app_id = kCFPreferencesCurrentApplication;
1832 if (application) 1830 if (application)
1833 { 1831 {
@@ -1879,8 +1877,6 @@ xrm_get_preference_database (application)
1879 CFRelease (key_set); 1877 CFRelease (key_set);
1880 CFRelease (app_id); 1878 CFRelease (app_id);
1881 1879
1882 UNBLOCK_INPUT;
1883
1884 UNGCPRO; 1880 UNGCPRO;
1885 1881
1886 return database; 1882 return database;
diff --git a/src/macfns.c b/src/macfns.c
index 849b24ea69b..b3ab709116a 100644
--- a/src/macfns.c
+++ b/src/macfns.c
@@ -218,9 +218,6 @@ void x_explicitly_set_name P_ ((struct frame *, Lisp_Object, Lisp_Object));
218void x_set_menu_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object)); 218void x_set_menu_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
219void x_set_title P_ ((struct frame *, Lisp_Object, Lisp_Object)); 219void x_set_title P_ ((struct frame *, Lisp_Object, Lisp_Object));
220void x_set_tool_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object)); 220void x_set_tool_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
221
222extern void mac_get_window_bounds P_ ((struct frame *, Rect *, Rect *));
223
224 221
225 222
226/* Store the screen positions of frame F into XPTR and YPTR. 223/* Store the screen positions of frame F into XPTR and YPTR.
@@ -2263,11 +2260,11 @@ mac_window (f)
2263 FRAME_MAC_WINDOW (f) = NULL; 2260 FRAME_MAC_WINDOW (f) = NULL;
2264 } 2261 }
2265 } 2262 }
2266#else 2263#else /* !TARGET_API_MAC_CARBON */
2267 FRAME_MAC_WINDOW (f) 2264 FRAME_MAC_WINDOW (f)
2268 = NewCWindow (NULL, &r, "\p", false, zoomDocProc, 2265 = NewCWindow (NULL, &r, "\p", false, zoomDocProc,
2269 (WindowPtr) -1, 1, (long) f->output_data.mac); 2266 (WindowRef) -1, 1, (long) f->output_data.mac);
2270#endif 2267#endif /* !TARGET_API_MAC_CARBON */
2271 /* so that update events can find this mac_output struct */ 2268 /* so that update events can find this mac_output struct */
2272 f->output_data.mac->mFP = f; /* point back to emacs frame */ 2269 f->output_data.mac->mFP = f; /* point back to emacs frame */
2273 2270
@@ -3120,7 +3117,7 @@ If omitted or nil, that stands for the selected frame's display. */)
3120 UNBLOCK_INPUT; 3117 UNBLOCK_INPUT;
3121 } 3118 }
3122#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020 3119#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
3123 else 3120 else /* CGDisplayScreenSize == NULL */
3124#endif 3121#endif
3125#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */ 3122#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */
3126#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020 3123#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020
@@ -3157,7 +3154,7 @@ If omitted or nil, that stands for the selected frame's display. */)
3157 UNBLOCK_INPUT; 3154 UNBLOCK_INPUT;
3158 } 3155 }
3159#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020 3156#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
3160 else 3157 else /* CGDisplayScreenSize == NULL */
3161#endif 3158#endif
3162#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */ 3159#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */
3163#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020 3160#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020
@@ -4076,8 +4073,12 @@ compute_tip_xy (f, parms, dx, dy, width, height, root_x, root_y)
4076 Point mouse_pos; 4073 Point mouse_pos;
4077 4074
4078 BLOCK_INPUT; 4075 BLOCK_INPUT;
4076#if TARGET_API_MAC_CARBON
4077 GetGlobalMouse (&mouse_pos);
4078#else
4079 GetMouse (&mouse_pos); 4079 GetMouse (&mouse_pos);
4080 LocalToGlobal (&mouse_pos); 4080 LocalToGlobal (&mouse_pos);
4081#endif
4081 *root_x = mouse_pos.h; 4082 *root_x = mouse_pos.h;
4082 *root_y = mouse_pos.v; 4083 *root_y = mouse_pos.v;
4083 UNBLOCK_INPUT; 4084 UNBLOCK_INPUT;
diff --git a/src/macgui.h b/src/macgui.h
index 3c37b86e22a..34a3f905487 100644
--- a/src/macgui.h
+++ b/src/macgui.h
@@ -71,7 +71,7 @@ typedef unsigned long Time;
71#undef Z 71#undef Z
72#define Z (current_buffer->text->z) 72#define Z (current_buffer->text->z)
73#else /* not HAVE_CARBON */ 73#else /* not HAVE_CARBON */
74#include <QuickDraw.h> /* for WindowPtr */ 74#include <QuickDraw.h> /* for WindowRef */
75#include <QDOffscreen.h> /* for GWorldPtr */ 75#include <QDOffscreen.h> /* for GWorldPtr */
76#include <Appearance.h> /* for ThemeCursor */ 76#include <Appearance.h> /* for ThemeCursor */
77#include <Windows.h> 77#include <Windows.h>
@@ -119,7 +119,7 @@ typedef unsigned long Time;
119#endif 119#endif
120#endif 120#endif
121 121
122typedef WindowPtr Window; 122typedef WindowRef Window;
123typedef GWorldPtr Pixmap; 123typedef GWorldPtr Pixmap;
124 124
125#define Cursor ThemeCursor 125#define Cursor ThemeCursor
diff --git a/src/macmenu.c b/src/macmenu.c
index a5196a156eb..5e6ad6f7d10 100644
--- a/src/macmenu.c
+++ b/src/macmenu.c
@@ -200,7 +200,7 @@ static void list_of_items P_ ((Lisp_Object));
200 200
201static void find_and_call_menu_selection P_ ((FRAME_PTR, int, Lisp_Object, 201static void find_and_call_menu_selection P_ ((FRAME_PTR, int, Lisp_Object,
202 void *)); 202 void *));
203static int fill_menu P_ ((MenuHandle, widget_value *, enum mac_menu_kind, int)); 203static int fill_menu P_ ((MenuRef, widget_value *, enum mac_menu_kind, int));
204static void fill_menubar P_ ((widget_value *, int)); 204static void fill_menubar P_ ((widget_value *, int));
205static void dispose_menus P_ ((enum mac_menu_kind, int)); 205static void dispose_menus P_ ((enum mac_menu_kind, int));
206 206
@@ -1162,7 +1162,7 @@ x_activate_menubar (f)
1162#endif 1162#endif
1163 if (menu_id) 1163 if (menu_id)
1164 { 1164 {
1165 MenuHandle menu = GetMenuHandle (menu_id); 1165 MenuRef menu = GetMenuRef (menu_id);
1166 1166
1167 if (menu) 1167 if (menu)
1168 { 1168 {
@@ -1595,15 +1595,13 @@ menu_target_item_handler (next_handler, event, data)
1595 EventRef event; 1595 EventRef event;
1596 void *data; 1596 void *data;
1597{ 1597{
1598 OSStatus err, result; 1598 OSStatus err;
1599 MenuRef menu; 1599 MenuRef menu;
1600 MenuItemIndex menu_item; 1600 MenuItemIndex menu_item;
1601 Lisp_Object help; 1601 Lisp_Object help;
1602 GrafPtr port; 1602 GrafPtr port;
1603 int specpdl_count = SPECPDL_INDEX (); 1603 int specpdl_count = SPECPDL_INDEX ();
1604 1604
1605 result = CallNextEventHandler (next_handler, event);
1606
1607 err = GetEventParameter (event, kEventParamDirectObject, typeMenuRef, 1605 err = GetEventParameter (event, kEventParamDirectObject, typeMenuRef,
1608 NULL, sizeof (MenuRef), NULL, &menu); 1606 NULL, sizeof (MenuRef), NULL, &menu);
1609 if (err == noErr) 1607 if (err == noErr)
@@ -1626,30 +1624,21 @@ menu_target_item_handler (next_handler, event, data)
1626 SetPort (port); 1624 SetPort (port);
1627 unbind_to (specpdl_count, Qnil); 1625 unbind_to (specpdl_count, Qnil);
1628 1626
1629 return err == noErr ? noErr : result; 1627 return err == noErr ? noErr : eventNotHandledErr;
1630} 1628}
1631#endif
1632 1629
1633OSStatus 1630OSStatus
1634install_menu_target_item_handler (window) 1631install_menu_target_item_handler ()
1635 WindowPtr window;
1636{ 1632{
1637 OSStatus err = noErr;
1638#if TARGET_API_MAC_CARBON
1639 static const EventTypeSpec specs[] = 1633 static const EventTypeSpec specs[] =
1640 {{kEventClassMenu, kEventMenuTargetItem}}; 1634 {{kEventClassMenu, kEventMenuTargetItem}};
1641 static EventHandlerUPP menu_target_item_handlerUPP = NULL;
1642
1643 if (menu_target_item_handlerUPP == NULL)
1644 menu_target_item_handlerUPP =
1645 NewEventHandlerUPP (menu_target_item_handler);
1646 1635
1647 err = InstallWindowEventHandler (window, menu_target_item_handlerUPP, 1636 return InstallApplicationEventHandler (NewEventHandlerUPP
1648 GetEventTypeCount (specs), specs, 1637 (menu_target_item_handler),
1649 NULL, NULL); 1638 GetEventTypeCount (specs),
1650#endif 1639 specs, NULL, NULL);
1651 return err;
1652} 1640}
1641#endif /* TARGET_API_MAC_CARBON */
1653 1642
1654/* Event handler function that pops down a menu on C-g. We can only pop 1643/* Event handler function that pops down a menu on C-g. We can only pop
1655 down menus if CancelMenuTracking is present (OSX 10.3 or later). */ 1644 down menus if CancelMenuTracking is present (OSX 10.3 or later). */
@@ -1687,15 +1676,15 @@ menu_quit_handler (nextHandler, theEvent, userData)
1687} 1676}
1688#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */ 1677#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */
1689 1678
1690/* Add event handler to all menus that belong to KIND so we can detect C-g. 1679/* Add event handler to all menus that belong to KIND so we can detect
1691 MENU_HANDLE is the root menu of the tracking session to dismiss 1680 C-g. ROOT_MENU is the root menu of the tracking session to dismiss
1692 when C-g is detected. NULL means the menu bar. 1681 when C-g is detected. NULL means the menu bar. If
1693 If CancelMenuTracking isn't available, do nothing. */ 1682 CancelMenuTracking isn't available, do nothing. */
1694 1683
1695static void 1684static void
1696install_menu_quit_handler (kind, menu_handle) 1685install_menu_quit_handler (kind, root_menu)
1697 enum mac_menu_kind kind; 1686 enum mac_menu_kind kind;
1698 MenuHandle menu_handle; 1687 MenuRef root_menu;
1699{ 1688{
1700#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 1689#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
1701 static const EventTypeSpec typesList[] = 1690 static const EventTypeSpec typesList[] =
@@ -1708,13 +1697,13 @@ install_menu_quit_handler (kind, menu_handle)
1708#endif 1697#endif
1709 for (id = min_menu_id[kind]; id < min_menu_id[kind + 1]; id++) 1698 for (id = min_menu_id[kind]; id < min_menu_id[kind + 1]; id++)
1710 { 1699 {
1711 MenuHandle menu = GetMenuHandle (id); 1700 MenuRef menu = GetMenuRef (id);
1712 1701
1713 if (menu == NULL) 1702 if (menu == NULL)
1714 break; 1703 break;
1715 InstallMenuEventHandler (menu, menu_quit_handler, 1704 InstallMenuEventHandler (menu, menu_quit_handler,
1716 GetEventTypeCount (typesList), 1705 GetEventTypeCount (typesList),
1717 typesList, menu_handle, NULL); 1706 typesList, root_menu, NULL);
1718 } 1707 }
1719#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */ 1708#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */
1720} 1709}
@@ -1738,10 +1727,13 @@ set_frame_menubar (f, first_time, deep_p)
1738 1727
1739 XSETFRAME (Vmenu_updating_frame, f); 1728 XSETFRAME (Vmenu_updating_frame, f);
1740 1729
1730 /* This seems to be unnecessary for Carbon. */
1731#if 0
1741 if (! menubar_widget) 1732 if (! menubar_widget)
1742 deep_p = 1; 1733 deep_p = 1;
1743 else if (pending_menu_activation && !deep_p) 1734 else if (pending_menu_activation && !deep_p)
1744 deep_p = 1; 1735 deep_p = 1;
1736#endif
1745 1737
1746 if (deep_p) 1738 if (deep_p)
1747 { 1739 {
@@ -1978,7 +1970,7 @@ pop_down_menu (arg)
1978{ 1970{
1979 struct Lisp_Save_Value *p = XSAVE_VALUE (arg); 1971 struct Lisp_Save_Value *p = XSAVE_VALUE (arg);
1980 FRAME_PTR f = p->pointer; 1972 FRAME_PTR f = p->pointer;
1981 MenuHandle menu = GetMenuHandle (min_menu_id[MAC_MENU_POPUP]); 1973 MenuRef menu = GetMenuRef (min_menu_id[MAC_MENU_POPUP]);
1982 1974
1983 BLOCK_INPUT; 1975 BLOCK_INPUT;
1984 1976
@@ -2024,8 +2016,7 @@ mac_menu_show (f, x, y, for_click, keymaps, title, error)
2024 int i; 2016 int i;
2025 int menu_item_choice; 2017 int menu_item_choice;
2026 UInt32 menu_item_selection; 2018 UInt32 menu_item_selection;
2027 MenuHandle menu; 2019 MenuRef menu;
2028 Point pos;
2029 widget_value *wv, *save_wv = 0, *first_wv = 0, *prev_wv = 0; 2020 widget_value *wv, *save_wv = 0, *first_wv = 0, *prev_wv = 0;
2030 widget_value **submenu_stack 2021 widget_value **submenu_stack
2031 = (widget_value **) alloca (menu_items_used * sizeof (widget_value *)); 2022 = (widget_value **) alloca (menu_items_used * sizeof (widget_value *));
@@ -2231,11 +2222,8 @@ mac_menu_show (f, x, y, for_click, keymaps, title, error)
2231 free_menubar_widget_value_tree (first_wv); 2222 free_menubar_widget_value_tree (first_wv);
2232 2223
2233 /* Adjust coordinates to be root-window-relative. */ 2224 /* Adjust coordinates to be root-window-relative. */
2234 pos.h = x; 2225 x += f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f);
2235 pos.v = y; 2226 y += f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f);
2236
2237 SetPortWindowPort (FRAME_MAC_WINDOW (f));
2238 LocalToGlobal (&pos);
2239 2227
2240 /* No selection has been chosen yet. */ 2228 /* No selection has been chosen yet. */
2241 menu_item_selection = 0; 2229 menu_item_selection = 0;
@@ -2248,13 +2236,13 @@ mac_menu_show (f, x, y, for_click, keymaps, title, error)
2248 2236
2249 /* Display the menu. */ 2237 /* Display the menu. */
2250 popup_activated_flag = 1; 2238 popup_activated_flag = 1;
2251 menu_item_choice = PopUpMenuSelect (menu, pos.v, pos.h, 0); 2239 menu_item_choice = PopUpMenuSelect (menu, y, x, 0);
2252 popup_activated_flag = 0; 2240 popup_activated_flag = 0;
2253 2241
2254 /* Get the refcon to find the correct item */ 2242 /* Get the refcon to find the correct item */
2255 if (menu_item_choice) 2243 if (menu_item_choice)
2256 { 2244 {
2257 MenuHandle sel_menu = GetMenuHandle (HiWord (menu_item_choice)); 2245 MenuRef sel_menu = GetMenuRef (HiWord (menu_item_choice));
2258 2246
2259 if (sel_menu) 2247 if (sel_menu)
2260 GetMenuItemRefCon (sel_menu, LoWord (menu_item_choice), 2248 GetMenuItemRefCon (sel_menu, LoWord (menu_item_choice),
@@ -2330,6 +2318,14 @@ mac_menu_show (f, x, y, for_click, keymaps, title, error)
2330 2318
2331#if TARGET_API_MAC_CARBON 2319#if TARGET_API_MAC_CARBON
2332 2320
2321#define DIALOG_BUTTON_COMMAND_ID_OFFSET 'Bt\0\0'
2322#define DIALOG_BUTTON_COMMAND_ID_P(id) \
2323 (((id) & ~0xffff) == DIALOG_BUTTON_COMMAND_ID_OFFSET)
2324#define DIALOG_BUTTON_COMMAND_ID_VALUE(id) \
2325 ((id) - DIALOG_BUTTON_COMMAND_ID_OFFSET)
2326#define DIALOG_BUTTON_MAKE_COMMAND_ID(value) \
2327 ((value) + DIALOG_BUTTON_COMMAND_ID_OFFSET)
2328
2333static pascal OSStatus 2329static pascal OSStatus
2334mac_handle_dialog_event (next_handler, event, data) 2330mac_handle_dialog_event (next_handler, event, data)
2335 EventHandlerCallRef next_handler; 2331 EventHandlerCallRef next_handler;
@@ -2349,7 +2345,7 @@ mac_handle_dialog_event (next_handler, event, data)
2349 typeHICommand, NULL, sizeof (HICommand), 2345 typeHICommand, NULL, sizeof (HICommand),
2350 NULL, &command); 2346 NULL, &command);
2351 if (err == noErr) 2347 if (err == noErr)
2352 if ((command.commandID & ~0xffff) == 'Bt\0\0') 2348 if (DIALOG_BUTTON_COMMAND_ID_P (command.commandID))
2353 { 2349 {
2354 SetWRefCon (window, command.commandID); 2350 SetWRefCon (window, command.commandID);
2355 err = QuitAppModalLoopForWindow (window); 2351 err = QuitAppModalLoopForWindow (window);
@@ -2402,7 +2398,10 @@ mac_handle_dialog_event (next_handler, event, data)
2402 break; 2398 break;
2403 } 2399 }
2404 2400
2405 return err == noErr ? noErr : result; 2401 if (err == noErr)
2402 result = noErr;
2403
2404 return result;
2406 } 2405 }
2407 break; 2406 break;
2408 2407
@@ -2518,14 +2517,16 @@ create_and_show_dialog (f, first_wv)
2518 } 2517 }
2519 if (err == noErr) 2518 if (err == noErr)
2520 { 2519 {
2520 UInt32 command_id;
2521
2521 OffsetRect (&rects[i], -rects[i].left, -rects[i].top); 2522 OffsetRect (&rects[i], -rects[i].left, -rects[i].top);
2522 if (rects[i].right < DIALOG_BUTTON_MIN_WIDTH) 2523 if (rects[i].right < DIALOG_BUTTON_MIN_WIDTH)
2523 rects[i].right = DIALOG_BUTTON_MIN_WIDTH; 2524 rects[i].right = DIALOG_BUTTON_MIN_WIDTH;
2524 else if (rects[i].right > DIALOG_MAX_INNER_WIDTH) 2525 else if (rects[i].right > DIALOG_MAX_INNER_WIDTH)
2525 rects[i].right = DIALOG_MAX_INNER_WIDTH; 2526 rects[i].right = DIALOG_MAX_INNER_WIDTH;
2526 2527
2527 err = SetControlCommandID (buttons[i], 2528 command_id = DIALOG_BUTTON_MAKE_COMMAND_ID ((int) wv->call_data);
2528 'Bt\0\0' + (int) wv->call_data); 2529 err = SetControlCommandID (buttons[i], command_id);
2529 } 2530 }
2530 if (err != noErr) 2531 if (err != noErr)
2531 break; 2532 break;
@@ -2702,8 +2703,8 @@ create_and_show_dialog (f, first_wv)
2702 { 2703 {
2703 UInt32 command_id = GetWRefCon (window); 2704 UInt32 command_id = GetWRefCon (window);
2704 2705
2705 if ((command_id & ~0xffff) == 'Bt\0\0') 2706 if (DIALOG_BUTTON_COMMAND_ID_P (command_id))
2706 result = command_id - 'Bt\0\0'; 2707 result = DIALOG_BUTTON_COMMAND_ID_VALUE (command_id);
2707 } 2708 }
2708 2709
2709 if (window) 2710 if (window)
@@ -2724,8 +2725,8 @@ mac_dialog (widget_value *wv)
2724 int i; 2725 int i;
2725 int dialog_width; 2726 int dialog_width;
2726 Rect rect; 2727 Rect rect;
2727 WindowPtr window_ptr; 2728 WindowRef window_ptr;
2728 ControlHandle ch; 2729 ControlRef ch;
2729 int left; 2730 int left;
2730 EventRecord event_record; 2731 EventRecord event_record;
2731 SInt16 part_code; 2732 SInt16 part_code;
@@ -2754,7 +2755,7 @@ mac_dialog (widget_value *wv)
2754 wv = wv->next; 2755 wv = wv->next;
2755 } 2756 }
2756 2757
2757 window_ptr = GetNewCWindow (DIALOG_WINDOW_RESOURCE, NULL, (WindowPtr) -1); 2758 window_ptr = GetNewCWindow (DIALOG_WINDOW_RESOURCE, NULL, (WindowRef) -1);
2758 2759
2759 SetPortWindowPort (window_ptr); 2760 SetPortWindowPort (window_ptr);
2760 2761
@@ -3031,7 +3032,7 @@ name_is_separator (name)
3031 3032
3032static void 3033static void
3033add_menu_item (menu, pos, wv) 3034add_menu_item (menu, pos, wv)
3034 MenuHandle menu; 3035 MenuRef menu;
3035 int pos; 3036 int pos;
3036 widget_value *wv; 3037 widget_value *wv;
3037{ 3038{
@@ -3108,7 +3109,7 @@ add_menu_item (menu, pos, wv)
3108 3109
3109static int 3110static int
3110fill_menu (menu, wv, kind, submenu_id) 3111fill_menu (menu, wv, kind, submenu_id)
3111 MenuHandle menu; 3112 MenuRef menu;
3112 widget_value *wv; 3113 widget_value *wv;
3113 enum mac_menu_kind kind; 3114 enum mac_menu_kind kind;
3114 int submenu_id; 3115 int submenu_id;
@@ -3120,7 +3121,7 @@ fill_menu (menu, wv, kind, submenu_id)
3120 add_menu_item (menu, pos, wv); 3121 add_menu_item (menu, pos, wv);
3121 if (wv->contents && submenu_id < min_menu_id[kind + 1]) 3122 if (wv->contents && submenu_id < min_menu_id[kind + 1])
3122 { 3123 {
3123 MenuHandle submenu = NewMenu (submenu_id, "\pX"); 3124 MenuRef submenu = NewMenu (submenu_id, "\pX");
3124 3125
3125 InsertMenu (submenu, -1); 3126 InsertMenu (submenu, -1);
3126 SetMenuItemHierarchicalID (menu, pos, submenu_id); 3127 SetMenuItemHierarchicalID (menu, pos, submenu_id);
@@ -3139,8 +3140,6 @@ fill_menubar (wv, deep_p)
3139 int deep_p; 3140 int deep_p;
3140{ 3141{
3141 int id, submenu_id; 3142 int id, submenu_id;
3142 MenuHandle menu;
3143 Str255 title;
3144#if !TARGET_API_MAC_CARBON 3143#if !TARGET_API_MAC_CARBON
3145 int title_changed_p = 0; 3144 int title_changed_p = 0;
3146#endif 3145#endif
@@ -3162,45 +3161,75 @@ fill_menubar (wv, deep_p)
3162 wv != NULL && id < min_menu_id[MAC_MENU_MENU_BAR + 1]; 3161 wv != NULL && id < min_menu_id[MAC_MENU_MENU_BAR + 1];
3163 wv = wv->next, id++) 3162 wv = wv->next, id++)
3164 { 3163 {
3164 OSStatus err = noErr;
3165 MenuRef menu;
3166#if TARGET_API_MAC_CARBON
3167 CFStringRef title;
3168
3169 title = CFStringCreateWithCString (NULL, wv->name,
3170 kCFStringEncodingMacRoman);
3171#else
3172 Str255 title;
3173
3165 strncpy (title, wv->name, 255); 3174 strncpy (title, wv->name, 255);
3166 title[255] = '\0'; 3175 title[255] = '\0';
3167 c2pstr (title); 3176 c2pstr (title);
3177#endif
3168 3178
3169 menu = GetMenuHandle (id); 3179 menu = GetMenuRef (id);
3170 if (menu) 3180 if (menu)
3171 { 3181 {
3172#if TARGET_API_MAC_CARBON 3182#if TARGET_API_MAC_CARBON
3173 Str255 old_title; 3183 CFStringRef old_title;
3174 3184
3175 GetMenuTitle (menu, old_title); 3185 err = CopyMenuTitleAsCFString (menu, &old_title);
3176 if (!EqualString (title, old_title, false, false)) 3186 if (err == noErr)
3177 SetMenuTitle (menu, title); 3187 {
3188 if (CFStringCompare (title, old_title, 0) != kCFCompareEqualTo)
3189 err = SetMenuTitleWithCFString (menu, title);
3190 CFRelease (old_title);
3191 }
3192 else
3193 err = SetMenuTitleWithCFString (menu, title);
3178#else /* !TARGET_API_MAC_CARBON */ 3194#else /* !TARGET_API_MAC_CARBON */
3179 if (!EqualString (title, (*menu)->menuData, false, false)) 3195 if (!EqualString (title, (*menu)->menuData, false, false))
3180 { 3196 {
3181 DeleteMenu (id); 3197 DeleteMenu (id);
3182 DisposeMenu (menu); 3198 DisposeMenu (menu);
3183 menu = NewMenu (id, title); 3199 menu = NewMenu (id, title);
3184 InsertMenu (menu, GetMenuHandle (id + 1) ? id + 1 : 0); 3200 InsertMenu (menu, GetMenuRef (id + 1) ? id + 1 : 0);
3185 title_changed_p = 1; 3201 title_changed_p = 1;
3186 } 3202 }
3187#endif /* !TARGET_API_MAC_CARBON */ 3203#endif /* !TARGET_API_MAC_CARBON */
3188 } 3204 }
3189 else 3205 else
3190 { 3206 {
3207#if TARGET_API_MAC_CARBON
3208 err = CreateNewMenu (id, 0, &menu);
3209 if (err == noErr)
3210 err = SetMenuTitleWithCFString (menu, title);
3211#else
3191 menu = NewMenu (id, title); 3212 menu = NewMenu (id, title);
3192 InsertMenu (menu, 0); 3213#endif
3214 if (err == noErr)
3215 {
3216 InsertMenu (menu, 0);
3193#if !TARGET_API_MAC_CARBON 3217#if !TARGET_API_MAC_CARBON
3194 title_changed_p = 1; 3218 title_changed_p = 1;
3195#endif 3219#endif
3220 }
3196 } 3221 }
3222#if TARGET_API_MAC_CARBON
3223 CFRelease (title);
3224#endif
3197 3225
3198 if (wv->contents) 3226 if (err == noErr)
3199 submenu_id = fill_menu (menu, wv->contents, MAC_MENU_MENU_BAR_SUB, 3227 if (wv->contents)
3200 submenu_id); 3228 submenu_id = fill_menu (menu, wv->contents, MAC_MENU_MENU_BAR_SUB,
3229 submenu_id);
3201 } 3230 }
3202 3231
3203 if (id < min_menu_id[MAC_MENU_MENU_BAR + 1] && GetMenuHandle (id)) 3232 if (id < min_menu_id[MAC_MENU_MENU_BAR + 1] && GetMenuRef (id))
3204 { 3233 {
3205 dispose_menus (MAC_MENU_MENU_BAR, id); 3234 dispose_menus (MAC_MENU_MENU_BAR, id);
3206#if !TARGET_API_MAC_CARBON 3235#if !TARGET_API_MAC_CARBON
@@ -3224,7 +3253,7 @@ dispose_menus (kind, id)
3224{ 3253{
3225 for (id = max (id, min_menu_id[kind]); id < min_menu_id[kind + 1]; id++) 3254 for (id = max (id, min_menu_id[kind]); id < min_menu_id[kind + 1]; id++)
3226 { 3255 {
3227 MenuHandle menu = GetMenuHandle (id); 3256 MenuRef menu = GetMenuRef (id);
3228 3257
3229 if (menu == NULL) 3258 if (menu == NULL)
3230 break; 3259 break;
diff --git a/src/macselect.c b/src/macselect.c
index c6aa97d5be9..a34f58df0f0 100644
--- a/src/macselect.c
+++ b/src/macselect.c
@@ -1623,16 +1623,19 @@ remove_drag_handler (window)
1623 Services menu support 1623 Services menu support
1624***********************************************************************/ 1624***********************************************************************/
1625#ifdef MAC_OSX 1625#ifdef MAC_OSX
1626void 1626OSStatus
1627init_service_handler () 1627install_service_handler ()
1628{ 1628{
1629 static const EventTypeSpec specs[] = 1629 static const EventTypeSpec specs[] =
1630 {{kEventClassService, kEventServiceGetTypes}, 1630 {{kEventClassService, kEventServiceGetTypes},
1631 {kEventClassService, kEventServiceCopy}, 1631 {kEventClassService, kEventServiceCopy},
1632 {kEventClassService, kEventServicePaste}, 1632 {kEventClassService, kEventServicePaste},
1633 {kEventClassService, kEventServicePerform}}; 1633 {kEventClassService, kEventServicePerform}};
1634 InstallApplicationEventHandler (NewEventHandlerUPP (mac_handle_service_event), 1634
1635 GetEventTypeCount (specs), specs, NULL, NULL); 1635 return InstallApplicationEventHandler (NewEventHandlerUPP
1636 (mac_handle_service_event),
1637 GetEventTypeCount (specs),
1638 specs, NULL, NULL);
1636} 1639}
1637 1640
1638extern OSStatus mac_store_service_event P_ ((EventRef)); 1641extern OSStatus mac_store_service_event P_ ((EventRef));
diff --git a/src/macterm.c b/src/macterm.c
index 64b4e094d14..1a67a9ebec1 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -35,12 +35,7 @@ Boston, MA 02110-1301, USA. */
35#include <alloca.h> 35#include <alloca.h>
36#endif 36#endif
37 37
38#if TARGET_API_MAC_CARBON 38#if !TARGET_API_MAC_CARBON
39/* USE_CARBON_EVENTS determines if the Carbon Event Manager is used to
40 obtain events from the event queue. If set to 0, WaitNextEvent is
41 used instead. */
42#define USE_CARBON_EVENTS 1
43#else /* not TARGET_API_MAC_CARBON */
44#include <Quickdraw.h> 39#include <Quickdraw.h>
45#include <ToolUtils.h> 40#include <ToolUtils.h>
46#include <Sound.h> 41#include <Sound.h>
@@ -265,7 +260,7 @@ static void x_scroll_bar_report_motion P_ ((struct frame **, Lisp_Object *,
265 Lisp_Object *, Lisp_Object *, 260 Lisp_Object *, Lisp_Object *,
266 unsigned long *)); 261 unsigned long *));
267 262
268static int is_emacs_window P_ ((WindowPtr)); 263static int is_emacs_window P_ ((WindowRef));
269static XCharStruct *mac_per_char_metric P_ ((XFontStruct *, XChar2b *, int)); 264static XCharStruct *mac_per_char_metric P_ ((XFontStruct *, XChar2b *, int));
270static void XSetFont P_ ((Display *, GC, XFontStruct *)); 265static void XSetFont P_ ((Display *, GC, XFontStruct *));
271 266
@@ -418,7 +413,8 @@ mac_prepare_for_quickdraw (f)
418static RgnHandle saved_port_clip_region = NULL; 413static RgnHandle saved_port_clip_region = NULL;
419 414
420static void 415static void
421mac_begin_clip (gc) 416mac_begin_clip (f, gc)
417 struct frame *f;
422 GC gc; 418 GC gc;
423{ 419{
424 static RgnHandle new_region = NULL; 420 static RgnHandle new_region = NULL;
@@ -428,6 +424,11 @@ mac_begin_clip (gc)
428 if (new_region == NULL) 424 if (new_region == NULL)
429 new_region = NewRgn (); 425 new_region = NewRgn ();
430 426
427#if USE_CG_DRAWING
428 mac_prepare_for_quickdraw (f);
429#endif
430 SetPortWindowPort (FRAME_MAC_WINDOW (f));
431
431 if (gc->n_clip_rects) 432 if (gc->n_clip_rects)
432 { 433 {
433 GetClip (saved_port_clip_region); 434 GetClip (saved_port_clip_region);
@@ -447,15 +448,6 @@ mac_end_clip (gc)
447 448
448/* X display function emulation */ 449/* X display function emulation */
449 450
450void
451XFreePixmap (display, pixmap)
452 Display *display; /* not used */
453 Pixmap pixmap;
454{
455 DisposeGWorld (pixmap);
456}
457
458
459/* Mac version of XDrawLine. */ 451/* Mac version of XDrawLine. */
460 452
461static void 453static void
@@ -497,11 +489,8 @@ mac_draw_line (f, gc, x1, y1, x2, y2)
497 x2--; 489 x2--;
498 } 490 }
499 491
500 SetPortWindowPort (FRAME_MAC_WINDOW (f)); 492 mac_begin_clip (f, gc);
501
502 RGBForeColor (GC_FORE_COLOR (gc)); 493 RGBForeColor (GC_FORE_COLOR (gc));
503
504 mac_begin_clip (gc);
505 MoveTo (x1, y1); 494 MoveTo (x1, y1);
506 LineTo (x2, y2); 495 LineTo (x2, y2);
507 mac_end_clip (gc); 496 mac_end_clip (gc);
@@ -557,25 +546,25 @@ mac_erase_rectangle (f, gc, x, y, width, height)
557 unsigned int width, height; 546 unsigned int width, height;
558{ 547{
559#if USE_CG_DRAWING 548#if USE_CG_DRAWING
560 CGContextRef context; 549 {
550 CGContextRef context;
561 551
562 context = mac_begin_cg_clip (f, gc); 552 context = mac_begin_cg_clip (f, gc);
563 CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc); 553 CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc);
564 CGContextFillRect (context, CGRectMake (x, y, width, height)); 554 CGContextFillRect (context, CGRectMake (x, y, width, height));
565 mac_end_cg_clip (f); 555 mac_end_cg_clip (f);
556 }
566#else 557#else
567 Rect r; 558 {
568 559 Rect r;
569 SetPortWindowPort (FRAME_MAC_WINDOW (f));
570
571 RGBBackColor (GC_BACK_COLOR (gc));
572 SetRect (&r, x, y, x + width, y + height);
573
574 mac_begin_clip (gc);
575 EraseRect (&r);
576 mac_end_clip (gc);
577 560
578 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); 561 mac_begin_clip (f, gc);
562 RGBBackColor (GC_BACK_COLOR (gc));
563 SetRect (&r, x, y, x + width, y + height);
564 EraseRect (&r);
565 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
566 mac_end_clip (gc);
567 }
579#endif 568#endif
580} 569}
581 570
@@ -598,15 +587,17 @@ mac_clear_window (f)
598 struct frame *f; 587 struct frame *f;
599{ 588{
600#if USE_CG_DRAWING 589#if USE_CG_DRAWING
601 CGContextRef context; 590 {
602 GC gc = FRAME_NORMAL_GC (f); 591 CGContextRef context;
603 592 GC gc = FRAME_NORMAL_GC (f);
604 context = mac_begin_cg_clip (f, NULL); 593
605 CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc); 594 context = mac_begin_cg_clip (f, NULL);
606 CGContextFillRect (context, CGRectMake (0, 0, FRAME_PIXEL_WIDTH (f), 595 CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc);
607 FRAME_PIXEL_HEIGHT (f))); 596 CGContextFillRect (context, CGRectMake (0, 0, FRAME_PIXEL_WIDTH (f),
608 mac_end_cg_clip (f); 597 FRAME_PIXEL_HEIGHT (f)));
609#else 598 mac_end_cg_clip (f);
599 }
600#else /* !USE_CG_DRAWING */
610 SetPortWindowPort (FRAME_MAC_WINDOW (f)); 601 SetPortWindowPort (FRAME_MAC_WINDOW (f));
611 602
612 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); 603 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
@@ -680,13 +671,10 @@ mac_draw_bitmap (f, gc, x, y, width, height, bits, overlay_p)
680 bitmap.baseAddr = (char *)bits; 671 bitmap.baseAddr = (char *)bits;
681 SetRect (&(bitmap.bounds), 0, 0, width, height); 672 SetRect (&(bitmap.bounds), 0, 0, width, height);
682 673
683 SetPortWindowPort (FRAME_MAC_WINDOW (f)); 674 mac_begin_clip (f, gc);
684
685 RGBForeColor (GC_FORE_COLOR (gc)); 675 RGBForeColor (GC_FORE_COLOR (gc));
686 RGBBackColor (GC_BACK_COLOR (gc)); 676 RGBBackColor (GC_BACK_COLOR (gc));
687 SetRect (&r, x, y, x + width, y + height); 677 SetRect (&r, x, y, x + width, y + height);
688
689 mac_begin_clip (gc);
690#if TARGET_API_MAC_CARBON 678#if TARGET_API_MAC_CARBON
691 { 679 {
692 CGrafPtr port; 680 CGrafPtr port;
@@ -701,9 +689,8 @@ mac_draw_bitmap (f, gc, x, y, width, height, bits, overlay_p)
701 CopyBits (&bitmap, &(FRAME_MAC_WINDOW (f)->portBits), &(bitmap.bounds), &r, 689 CopyBits (&bitmap, &(FRAME_MAC_WINDOW (f)->portBits), &(bitmap.bounds), &r,
702 overlay_p ? srcOr : srcCopy, 0); 690 overlay_p ? srcOr : srcCopy, 0);
703#endif /* not TARGET_API_MAC_CARBON */ 691#endif /* not TARGET_API_MAC_CARBON */
704 mac_end_clip (gc);
705
706 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); 692 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
693 mac_end_clip (gc);
707} 694}
708#endif /* !USE_CG_DRAWING */ 695#endif /* !USE_CG_DRAWING */
709 696
@@ -754,8 +741,8 @@ mac_free_bitmap (bitmap)
754 741
755Pixmap 742Pixmap
756XCreatePixmap (display, w, width, height, depth) 743XCreatePixmap (display, w, width, height, depth)
757 Display *display; /* not used */ 744 Display *display;
758 WindowPtr w; 745 WindowRef w;
759 unsigned int width, height; 746 unsigned int width, height;
760 unsigned int depth; 747 unsigned int depth;
761{ 748{
@@ -783,8 +770,8 @@ XCreatePixmap (display, w, width, height, depth)
783 770
784Pixmap 771Pixmap
785XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth) 772XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth)
786 Display *display; /* not used */ 773 Display *display;
787 WindowPtr w; 774 WindowRef w;
788 char *data; 775 char *data;
789 unsigned int width, height; 776 unsigned int width, height;
790 unsigned long fg, bg; 777 unsigned long fg, bg;
@@ -794,7 +781,7 @@ XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth)
794 BitMap bitmap; 781 BitMap bitmap;
795 CGrafPtr old_port; 782 CGrafPtr old_port;
796 GDHandle old_gdh; 783 GDHandle old_gdh;
797 static GC gc = NULL; /* not reentrant */ 784 static GC gc = NULL;
798 785
799 if (gc == NULL) 786 if (gc == NULL)
800 gc = XCreateGC (display, w, 0, NULL); 787 gc = XCreateGC (display, w, 0, NULL);
@@ -826,6 +813,15 @@ XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth)
826} 813}
827 814
828 815
816void
817XFreePixmap (display, pixmap)
818 Display *display;
819 Pixmap pixmap;
820{
821 DisposeGWorld (pixmap);
822}
823
824
829/* Mac replacement for XFillRectangle. */ 825/* Mac replacement for XFillRectangle. */
830 826
831static void 827static void
@@ -845,12 +841,9 @@ mac_fill_rectangle (f, gc, x, y, width, height)
845#else 841#else
846 Rect r; 842 Rect r;
847 843
848 SetPortWindowPort (FRAME_MAC_WINDOW (f)); 844 mac_begin_clip (f, gc);
849
850 RGBForeColor (GC_FORE_COLOR (gc)); 845 RGBForeColor (GC_FORE_COLOR (gc));
851 SetRect (&r, x, y, x + width, y + height); 846 SetRect (&r, x, y, x + width, y + height);
852
853 mac_begin_clip (gc);
854 PaintRect (&r); /* using foreground color of gc */ 847 PaintRect (&r); /* using foreground color of gc */
855 mac_end_clip (gc); 848 mac_end_clip (gc);
856#endif 849#endif
@@ -877,18 +870,34 @@ mac_draw_rectangle (f, gc, x, y, width, height)
877#else 870#else
878 Rect r; 871 Rect r;
879 872
880 SetPortWindowPort (FRAME_MAC_WINDOW (f)); 873 mac_begin_clip (f, gc);
881
882 RGBForeColor (GC_FORE_COLOR (gc)); 874 RGBForeColor (GC_FORE_COLOR (gc));
883 SetRect (&r, x, y, x + width + 1, y + height + 1); 875 SetRect (&r, x, y, x + width + 1, y + height + 1);
884
885 mac_begin_clip (gc);
886 FrameRect (&r); /* using foreground color of gc */ 876 FrameRect (&r); /* using foreground color of gc */
887 mac_end_clip (gc); 877 mac_end_clip (gc);
888#endif 878#endif
889} 879}
890 880
891 881
882static void
883mac_invert_rectangle (f, x, y, width, height)
884 struct frame *f;
885 int x, y;
886 unsigned int width, height;
887{
888 Rect r;
889
890#if USE_CG_DRAWING
891 mac_prepare_for_quickdraw (f);
892#endif
893 SetPortWindowPort (FRAME_MAC_WINDOW (f));
894
895 SetRect (&r, x, y, x + width, y + height);
896
897 InvertRect (&r);
898}
899
900
892#if USE_ATSUI 901#if USE_ATSUI
893static OSStatus 902static OSStatus
894atsu_get_text_layout_with_text_ptr (text, text_length, style, text_layout) 903atsu_get_text_layout_with_text_ptr (text, text_length, style, text_layout)
@@ -898,7 +907,7 @@ atsu_get_text_layout_with_text_ptr (text, text_length, style, text_layout)
898 ATSUTextLayout *text_layout; 907 ATSUTextLayout *text_layout;
899{ 908{
900 OSStatus err; 909 OSStatus err;
901 static ATSUTextLayout saved_text_layout = NULL; /* not reentrant */ 910 static ATSUTextLayout saved_text_layout = NULL;
902 911
903 if (saved_text_layout == NULL) 912 if (saved_text_layout == NULL)
904 { 913 {
@@ -925,7 +934,6 @@ atsu_get_text_layout_with_text_ptr (text, text_length, style, text_layout)
925 err = ATSUSetLayoutControls (saved_text_layout, 934 err = ATSUSetLayoutControls (saved_text_layout,
926 sizeof (tags) / sizeof (tags[0]), 935 sizeof (tags) / sizeof (tags[0]),
927 tags, sizes, values); 936 tags, sizes, values);
928 /* XXX: Should we do this? */
929 if (err == noErr) 937 if (err == noErr)
930 err = ATSUSetTransientFontMatching (saved_text_layout, true); 938 err = ATSUSetTransientFontMatching (saved_text_layout, true);
931 } 939 }
@@ -944,224 +952,224 @@ atsu_get_text_layout_with_text_ptr (text, text_length, style, text_layout)
944 *text_layout = saved_text_layout; 952 *text_layout = saved_text_layout;
945 return err; 953 return err;
946} 954}
947#endif
948
949
950static void
951mac_invert_rectangle (f, x, y, width, height)
952 struct frame *f;
953 int x, y;
954 unsigned int width, height;
955{
956 Rect r;
957
958#if USE_CG_DRAWING
959 mac_prepare_for_quickdraw (f);
960#endif
961 SetPortWindowPort (FRAME_MAC_WINDOW (f));
962
963 SetRect (&r, x, y, x + width, y + height);
964
965 InvertRect (&r);
966}
967 955
968 956
969static void 957static void
970mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width, 958mac_draw_image_string_atsui (f, gc, x, y, buf, nchars, bg_width,
971 overstrike_p, bytes_per_char) 959 overstrike_p, bytes_per_char)
972 struct frame *f; 960 struct frame *f;
973 GC gc; 961 GC gc;
974 int x, y; 962 int x, y;
975 char *buf; 963 char *buf;
976 int nchars, bg_width, overstrike_p, bytes_per_char; 964 int nchars, bg_width, overstrike_p, bytes_per_char;
977{ 965{
978 SetPortWindowPort (FRAME_MAC_WINDOW (f)); 966 OSStatus err;
979 967 ATSUTextLayout text_layout;
980#if USE_ATSUI
981 if (GC_FONT (gc)->mac_style)
982 {
983 OSStatus err;
984 ATSUTextLayout text_layout;
985 968
986 xassert (bytes_per_char == 2); 969 xassert (bytes_per_char == 2);
987 970
988#ifndef WORDS_BIG_ENDIAN 971#ifndef WORDS_BIG_ENDIAN
989 { 972 {
990 int i; 973 int i;
991 UniChar *text = (UniChar *)buf; 974 UniChar *text = (UniChar *)buf;
992 975
993 for (i = 0; i < nchars; i++) 976 for (i = 0; i < nchars; i++)
994 text[i] = EndianU16_BtoN (text[i]); 977 text[i] = EndianU16_BtoN (text[i]);
995 } 978 }
996#endif 979#endif
997 err = atsu_get_text_layout_with_text_ptr ((ConstUniCharArrayPtr)buf, 980 err = atsu_get_text_layout_with_text_ptr ((ConstUniCharArrayPtr)buf,
998 nchars, 981 nchars,
999 GC_FONT (gc)->mac_style, 982 GC_FONT (gc)->mac_style,
1000 &text_layout); 983 &text_layout);
1001 if (err != noErr) 984 if (err != noErr)
1002 return; 985 return;
1003#ifdef MAC_OSX 986#ifdef MAC_OSX
1004 if (!mac_use_core_graphics) 987 if (!mac_use_core_graphics)
1005 { 988 {
1006#endif
1007#if USE_CG_DRAWING
1008 mac_prepare_for_quickdraw (f);
1009#endif 989#endif
1010 mac_begin_clip (gc); 990 mac_begin_clip (f, gc);
1011 RGBForeColor (GC_FORE_COLOR (gc)); 991 RGBForeColor (GC_FORE_COLOR (gc));
1012 if (bg_width) 992 if (bg_width)
1013 { 993 {
1014 Rect r; 994 Rect r;
1015 995
1016 SetRect (&r, x, y - FONT_BASE (GC_FONT (gc)), 996 SetRect (&r, x, y - FONT_BASE (GC_FONT (gc)),
1017 x + bg_width, y + FONT_DESCENT (GC_FONT (gc))); 997 x + bg_width, y + FONT_DESCENT (GC_FONT (gc)));
1018 RGBBackColor (GC_BACK_COLOR (gc)); 998 RGBBackColor (GC_BACK_COLOR (gc));
1019 EraseRect (&r); 999 EraseRect (&r);
1020 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); 1000 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
1021 } 1001 }
1022 MoveTo (x, y); 1002 MoveTo (x, y);
1003 ATSUDrawText (text_layout,
1004 kATSUFromTextBeginning, kATSUToTextEnd,
1005 kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc);
1006 if (overstrike_p)
1007 {
1008 MoveTo (x + 1, y);
1023 ATSUDrawText (text_layout, 1009 ATSUDrawText (text_layout,
1024 kATSUFromTextBeginning, kATSUToTextEnd, 1010 kATSUFromTextBeginning, kATSUToTextEnd,
1025 kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); 1011 kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc);
1026 if (overstrike_p)
1027 {
1028 MoveTo (x + 1, y);
1029 ATSUDrawText (text_layout,
1030 kATSUFromTextBeginning, kATSUToTextEnd,
1031 kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc);
1032 }
1033 mac_end_clip (gc);
1034#ifdef MAC_OSX
1035 } 1012 }
1036 else 1013 mac_end_clip (gc);
1037 { 1014#ifdef MAC_OSX
1038 CGrafPtr port; 1015 }
1039 static CGContextRef context; 1016 else
1040 float port_height = FRAME_PIXEL_HEIGHT (f); 1017 {
1041 static const ATSUAttributeTag tags[] = {kATSUCGContextTag}; 1018 static CGContextRef context;
1042 static const ByteCount sizes[] = {sizeof (CGContextRef)}; 1019 float port_height = FRAME_PIXEL_HEIGHT (f);
1043 static const ATSUAttributeValuePtr values[] = {&context}; 1020 static const ATSUAttributeTag tags[] = {kATSUCGContextTag};
1021 static const ByteCount sizes[] = {sizeof (CGContextRef)};
1022 static const ATSUAttributeValuePtr values[] = {&context};
1044 1023
1045#if USE_CG_DRAWING 1024#if USE_CG_DRAWING
1046 context = mac_begin_cg_clip (f, gc); 1025 context = mac_begin_cg_clip (f, gc);
1047#else 1026#else
1048 GetPort (&port); 1027 CGrafPtr port;
1049 QDBeginCGContext (port, &context); 1028
1050 if (gc->n_clip_rects || bg_width) 1029 GetPort (&port);
1051 { 1030 QDBeginCGContext (port, &context);
1052 CGContextTranslateCTM (context, 0, port_height); 1031 if (gc->n_clip_rects || bg_width)
1053 CGContextScaleCTM (context, 1, -1); 1032 {
1054 if (gc->n_clip_rects) 1033 CGContextTranslateCTM (context, 0, port_height);
1055 CGContextClipToRects (context, gc->clip_rects, 1034 CGContextScaleCTM (context, 1, -1);
1056 gc->n_clip_rects); 1035 if (gc->n_clip_rects)
1057#endif 1036 CGContextClipToRects (context, gc->clip_rects,
1058 if (bg_width) 1037 gc->n_clip_rects);
1059 {
1060 CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc);
1061 CGContextFillRect
1062 (context,
1063 CGRectMake (x, y - FONT_BASE (GC_FONT (gc)),
1064 bg_width, FONT_HEIGHT (GC_FONT (gc))));
1065 }
1066 CGContextScaleCTM (context, 1, -1);
1067 CGContextTranslateCTM (context, 0, -port_height);
1068#if !USE_CG_DRAWING
1069 }
1070#endif 1038#endif
1071 CG_SET_FILL_COLOR_WITH_GC_FOREGROUND (context, gc); 1039 if (bg_width)
1072 err = ATSUSetLayoutControls (text_layout,
1073 sizeof (tags) / sizeof (tags[0]),
1074 tags, sizes, values);
1075 if (err == noErr)
1076 { 1040 {
1077 ATSUDrawText (text_layout, 1041 CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc);
1078 kATSUFromTextBeginning, kATSUToTextEnd, 1042 CGContextFillRect (context,
1079 Long2Fix (x), Long2Fix (port_height - y)); 1043 CGRectMake (x, y - FONT_BASE (GC_FONT (gc)),
1080 if (overstrike_p) 1044 bg_width,
1081 ATSUDrawText (text_layout, 1045 FONT_HEIGHT (GC_FONT (gc))));
1082 kATSUFromTextBeginning, kATSUToTextEnd,
1083 Long2Fix (x + 1), Long2Fix (port_height - y));
1084 } 1046 }
1047 CGContextScaleCTM (context, 1, -1);
1048 CGContextTranslateCTM (context, 0, -port_height);
1049#if !USE_CG_DRAWING
1050 }
1051#endif
1052 CG_SET_FILL_COLOR_WITH_GC_FOREGROUND (context, gc);
1053 err = ATSUSetLayoutControls (text_layout,
1054 sizeof (tags) / sizeof (tags[0]),
1055 tags, sizes, values);
1056 if (err == noErr)
1057 {
1058 ATSUDrawText (text_layout,
1059 kATSUFromTextBeginning, kATSUToTextEnd,
1060 Long2Fix (x), Long2Fix (port_height - y));
1061 if (overstrike_p)
1062 ATSUDrawText (text_layout,
1063 kATSUFromTextBeginning, kATSUToTextEnd,
1064 Long2Fix (x + 1), Long2Fix (port_height - y));
1065 }
1085#if USE_CG_DRAWING 1066#if USE_CG_DRAWING
1086 mac_end_cg_clip (f); 1067 mac_end_cg_clip (f);
1087 context = NULL; 1068 context = NULL;
1088#else 1069#else
1089 CGContextSynchronize (context); 1070 CGContextSynchronize (context);
1090 QDEndCGContext (port, &context); 1071 QDEndCGContext (port, &context);
1091#endif 1072#endif
1092#if 0 1073#if 0
1093 /* This doesn't work on Mac OS X 10.1. */ 1074 /* This doesn't work on Mac OS X 10.1. */
1094 ATSUClearLayoutControls (text_layout, 1075 ATSUClearLayoutControls (text_layout,
1095 sizeof (tags) / sizeof (tags[0]), tags); 1076 sizeof (tags) / sizeof (tags[0]), tags);
1096#else 1077#else
1097 ATSUSetLayoutControls (text_layout, 1078 ATSUSetLayoutControls (text_layout,
1098 sizeof (tags) / sizeof (tags[0]), 1079 sizeof (tags) / sizeof (tags[0]),
1099 tags, sizes, values); 1080 tags, sizes, values);
1100#endif 1081#endif
1101 }
1102#endif /* MAC_OSX */
1103 } 1082 }
1104 else 1083#endif /* MAC_OSX */
1084}
1105#endif /* USE_ATSUI */ 1085#endif /* USE_ATSUI */
1106 {
1107#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
1108 UInt32 savedFlags;
1109 1086
1110 if (mac_use_core_graphics) 1087
1111 savedFlags = SwapQDTextFlags (kQDUseCGTextRendering); 1088static void
1089mac_draw_image_string_qd (f, gc, x, y, buf, nchars, bg_width,
1090 overstrike_p, bytes_per_char)
1091 struct frame *f;
1092 GC gc;
1093 int x, y;
1094 char *buf;
1095 int nchars, bg_width, overstrike_p, bytes_per_char;
1096{
1097#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
1098 UInt32 savedFlags;
1112#endif 1099#endif
1113#if USE_CG_DRAWING 1100
1114 mac_prepare_for_quickdraw (f); 1101 mac_begin_clip (f, gc);
1102#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
1103 if (mac_use_core_graphics)
1104 savedFlags = SwapQDTextFlags (kQDUseCGTextRendering);
1115#endif 1105#endif
1116 mac_begin_clip (gc); 1106 RGBForeColor (GC_FORE_COLOR (gc));
1117 RGBForeColor (GC_FORE_COLOR (gc));
1118#ifdef MAC_OS8 1107#ifdef MAC_OS8
1119 if (bg_width) 1108 if (bg_width)
1120 { 1109 {
1121 RGBBackColor (GC_BACK_COLOR (gc)); 1110 RGBBackColor (GC_BACK_COLOR (gc));
1122 TextMode (srcCopy); 1111 TextMode (srcCopy);
1123 } 1112 }
1124 else 1113 else
1125 TextMode (srcOr); 1114 TextMode (srcOr);
1126#else 1115#else
1127 /* We prefer not to use srcCopy text transfer mode on Mac OS X 1116 /* We prefer not to use srcCopy text transfer mode on Mac OS X
1128 because: 1117 because:
1129 - Screen is double-buffered. (In srcCopy mode, a text is 1118 - Screen is double-buffered. (In srcCopy mode, a text is drawn
1130 drawn into an offscreen graphics world first. So 1119 into an offscreen graphics world first. So performance gain
1131 performance gain cannot be expected.) 1120 cannot be expected.)
1132 - It lowers rendering quality. 1121 - It lowers rendering quality.
1133 - Some fonts leave garbage on cursor movement. */ 1122 - Some fonts leave garbage on cursor movement. */
1134 if (bg_width) 1123 if (bg_width)
1135 { 1124 {
1136 Rect r; 1125 Rect r;
1137 1126
1138 RGBBackColor (GC_BACK_COLOR (gc)); 1127 RGBBackColor (GC_BACK_COLOR (gc));
1139 SetRect (&r, x, y - FONT_BASE (GC_FONT (gc)), 1128 SetRect (&r, x, y - FONT_BASE (GC_FONT (gc)),
1140 x + bg_width, y + FONT_DESCENT (GC_FONT (gc))); 1129 x + bg_width, y + FONT_DESCENT (GC_FONT (gc)));
1141 EraseRect (&r); 1130 EraseRect (&r);
1142 } 1131 }
1143 TextMode (srcOr); 1132 TextMode (srcOr);
1144#endif 1133#endif
1145 TextFont (GC_FONT (gc)->mac_fontnum); 1134 TextFont (GC_FONT (gc)->mac_fontnum);
1146 TextSize (GC_FONT (gc)->mac_fontsize); 1135 TextSize (GC_FONT (gc)->mac_fontsize);
1147 TextFace (GC_FONT (gc)->mac_fontface); 1136 TextFace (GC_FONT (gc)->mac_fontface);
1148 MoveTo (x, y); 1137 MoveTo (x, y);
1138 DrawText (buf, 0, nchars * bytes_per_char);
1139 if (overstrike_p)
1140 {
1141 TextMode (srcOr);
1142 MoveTo (x + 1, y);
1149 DrawText (buf, 0, nchars * bytes_per_char); 1143 DrawText (buf, 0, nchars * bytes_per_char);
1150 if (overstrike_p) 1144 }
1151 { 1145 if (bg_width)
1152 TextMode (srcOr); 1146 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
1153 MoveTo (x + 1, y); 1147 mac_end_clip (gc);
1154 DrawText (buf, 0, nchars * bytes_per_char);
1155 }
1156 if (bg_width)
1157 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
1158 mac_end_clip (gc);
1159 1148
1160#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 1149#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
1161 if (mac_use_core_graphics) 1150 if (mac_use_core_graphics)
1162 SwapQDTextFlags(savedFlags); 1151 SwapQDTextFlags(savedFlags);
1163#endif 1152#endif
1164 } 1153}
1154
1155
1156static INLINE void
1157mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width,
1158 overstrike_p, bytes_per_char)
1159 struct frame *f;
1160 GC gc;
1161 int x, y;
1162 char *buf;
1163 int nchars, bg_width, overstrike_p, bytes_per_char;
1164{
1165#if USE_ATSUI
1166 if (GC_FONT (gc)->mac_style)
1167 mac_draw_image_string_atsui (f, gc, x, y, buf, nchars, bg_width,
1168 overstrike_p, bytes_per_char);
1169 else
1170#endif /* USE_ATSUI */
1171 mac_draw_image_string_qd (f, gc, x, y, buf, nchars, bg_width,
1172 overstrike_p, bytes_per_char);
1165} 1173}
1166 1174
1167 1175
@@ -1378,7 +1386,6 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p)
1378 XChar2b *buf; 1386 XChar2b *buf;
1379 int nchars, bg_width, overstrike_p; 1387 int nchars, bg_width, overstrike_p;
1380{ 1388{
1381 CGrafPtr port;
1382 float port_height, gx, gy; 1389 float port_height, gx, gy;
1383 int i; 1390 int i;
1384 CGContextRef context; 1391 CGContextRef context;
@@ -1388,7 +1395,6 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p)
1388 if (!mac_use_core_graphics || GC_FONT (gc)->cg_font == NULL) 1395 if (!mac_use_core_graphics || GC_FONT (gc)->cg_font == NULL)
1389 return 0; 1396 return 0;
1390 1397
1391 port = GetWindowPort (FRAME_MAC_WINDOW (f));
1392 port_height = FRAME_PIXEL_HEIGHT (f); 1398 port_height = FRAME_PIXEL_HEIGHT (f);
1393 gx = x; 1399 gx = x;
1394 gy = port_height - y; 1400 gy = port_height - y;
@@ -1409,7 +1415,7 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p)
1409#if USE_CG_DRAWING 1415#if USE_CG_DRAWING
1410 context = mac_begin_cg_clip (f, gc); 1416 context = mac_begin_cg_clip (f, gc);
1411#else 1417#else
1412 QDBeginCGContext (port, &context); 1418 QDBeginCGContext (GetWindowPort (FRAME_MAC_WINDOW (f)), &context);
1413 if (gc->n_clip_rects || bg_width) 1419 if (gc->n_clip_rects || bg_width)
1414 { 1420 {
1415 CGContextTranslateCTM (context, 0, port_height); 1421 CGContextTranslateCTM (context, 0, port_height);
@@ -1449,7 +1455,7 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p)
1449 } 1455 }
1450 } 1456 }
1451#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020 1457#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
1452 else 1458 else /* CGContextShowGlyphsWithAdvances == NULL */
1453#endif 1459#endif
1454#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */ 1460#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */
1455#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020 1461#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020
@@ -1467,7 +1473,7 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p)
1467 mac_end_cg_clip (f); 1473 mac_end_cg_clip (f);
1468#else 1474#else
1469 CGContextSynchronize (context); 1475 CGContextSynchronize (context);
1470 QDEndCGContext (port, &context); 1476 QDEndCGContext (GetWindowPort (FRAME_MAC_WINDOW (f)), &context);
1471#endif 1477#endif
1472 1478
1473 return 1; 1479 return 1;
@@ -1489,7 +1495,7 @@ mac_copy_area (src, f, gc, src_x, src_y, width, height, dest_x, dest_y)
1489{ 1495{
1490 Rect src_r, dest_r; 1496 Rect src_r, dest_r;
1491 1497
1492 SetPortWindowPort (FRAME_MAC_WINDOW (f)); 1498 mac_begin_clip (f, gc);
1493 1499
1494 SetRect (&src_r, src_x, src_y, src_x + width, src_y + height); 1500 SetRect (&src_r, src_x, src_y, src_x + width, src_y + height);
1495 SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height); 1501 SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height);
@@ -1497,7 +1503,6 @@ mac_copy_area (src, f, gc, src_x, src_y, width, height, dest_x, dest_y)
1497 ForeColor (blackColor); 1503 ForeColor (blackColor);
1498 BackColor (whiteColor); 1504 BackColor (whiteColor);
1499 1505
1500 mac_begin_clip (gc);
1501 LockPixels (GetGWorldPixMap (src)); 1506 LockPixels (GetGWorldPixMap (src));
1502#if TARGET_API_MAC_CARBON 1507#if TARGET_API_MAC_CARBON
1503 { 1508 {
@@ -1515,9 +1520,10 @@ mac_copy_area (src, f, gc, src_x, src_y, width, height, dest_x, dest_y)
1515 &src_r, &dest_r, srcCopy, 0); 1520 &src_r, &dest_r, srcCopy, 0);
1516#endif /* not TARGET_API_MAC_CARBON */ 1521#endif /* not TARGET_API_MAC_CARBON */
1517 UnlockPixels (GetGWorldPixMap (src)); 1522 UnlockPixels (GetGWorldPixMap (src));
1518 mac_end_clip (gc);
1519 1523
1520 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); 1524 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
1525
1526 mac_end_clip (gc);
1521} 1527}
1522 1528
1523 1529
@@ -1533,7 +1539,7 @@ mac_copy_area_with_mask (src, mask, f, gc, src_x, src_y,
1533{ 1539{
1534 Rect src_r, dest_r; 1540 Rect src_r, dest_r;
1535 1541
1536 SetPortWindowPort (FRAME_MAC_WINDOW (f)); 1542 mac_begin_clip (f, gc);
1537 1543
1538 SetRect (&src_r, src_x, src_y, src_x + width, src_y + height); 1544 SetRect (&src_r, src_x, src_y, src_x + width, src_y + height);
1539 SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height); 1545 SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height);
@@ -1541,7 +1547,6 @@ mac_copy_area_with_mask (src, mask, f, gc, src_x, src_y,
1541 ForeColor (blackColor); 1547 ForeColor (blackColor);
1542 BackColor (whiteColor); 1548 BackColor (whiteColor);
1543 1549
1544 mac_begin_clip (gc);
1545 LockPixels (GetGWorldPixMap (src)); 1550 LockPixels (GetGWorldPixMap (src));
1546 LockPixels (GetGWorldPixMap (mask)); 1551 LockPixels (GetGWorldPixMap (mask));
1547#if TARGET_API_MAC_CARBON 1552#if TARGET_API_MAC_CARBON
@@ -1561,9 +1566,10 @@ mac_copy_area_with_mask (src, mask, f, gc, src_x, src_y,
1561#endif /* not TARGET_API_MAC_CARBON */ 1566#endif /* not TARGET_API_MAC_CARBON */
1562 UnlockPixels (GetGWorldPixMap (mask)); 1567 UnlockPixels (GetGWorldPixMap (mask));
1563 UnlockPixels (GetGWorldPixMap (src)); 1568 UnlockPixels (GetGWorldPixMap (src));
1564 mac_end_clip (gc);
1565 1569
1566 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); 1570 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
1571
1572 mac_end_clip (gc);
1567} 1573}
1568#endif /* !USE_CG_DRAWING */ 1574#endif /* !USE_CG_DRAWING */
1569 1575
@@ -1592,9 +1598,9 @@ mac_scroll_area (f, gc, src_x, src_y, width, height, dest_x, dest_y)
1592 DisposeRgn (dummy); 1598 DisposeRgn (dummy);
1593#else /* not TARGET_API_MAC_CARBON */ 1599#else /* not TARGET_API_MAC_CARBON */
1594 Rect src_r, dest_r; 1600 Rect src_r, dest_r;
1595 WindowPtr w = FRAME_MAC_WINDOW (f); 1601 WindowRef w = FRAME_MAC_WINDOW (f);
1596 1602
1597 SetPort (w); 1603 mac_begin_clip (f, gc);
1598 1604
1599 SetRect (&src_r, src_x, src_y, src_x + width, src_y + height); 1605 SetRect (&src_r, src_x, src_y, src_x + width, src_y + height);
1600 SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height); 1606 SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height);
@@ -1603,11 +1609,11 @@ mac_scroll_area (f, gc, src_x, src_y, width, height, dest_x, dest_y)
1603 color mapping in CopyBits. Otherwise, it will be slow. */ 1609 color mapping in CopyBits. Otherwise, it will be slow. */
1604 ForeColor (blackColor); 1610 ForeColor (blackColor);
1605 BackColor (whiteColor); 1611 BackColor (whiteColor);
1606 mac_begin_clip (gc);
1607 CopyBits (&(w->portBits), &(w->portBits), &src_r, &dest_r, srcCopy, 0); 1612 CopyBits (&(w->portBits), &(w->portBits), &src_r, &dest_r, srcCopy, 0);
1608 mac_end_clip (gc);
1609 1613
1610 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); 1614 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
1615
1616 mac_end_clip (gc);
1611#endif /* not TARGET_API_MAC_CARBON */ 1617#endif /* not TARGET_API_MAC_CARBON */
1612} 1618}
1613 1619
@@ -1852,7 +1858,7 @@ mac_reset_clip_rectangles (display, gc)
1852void 1858void
1853XSetWindowBackground (display, w, color) 1859XSetWindowBackground (display, w, color)
1854 Display *display; 1860 Display *display;
1855 WindowPtr w; 1861 WindowRef w;
1856 unsigned long color; 1862 unsigned long color;
1857{ 1863{
1858#if !TARGET_API_MAC_CARBON 1864#if !TARGET_API_MAC_CARBON
@@ -4375,7 +4381,7 @@ x_detect_focus_change (dpyinfo, event, bufp)
4375{ 4381{
4376 struct frame *frame; 4382 struct frame *frame;
4377 4383
4378 frame = mac_window_to_frame ((WindowPtr) event->message); 4384 frame = mac_window_to_frame ((WindowRef) event->message);
4379 if (! frame) 4385 if (! frame)
4380 return; 4386 return;
4381 4387
@@ -4615,8 +4621,14 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time)
4615 the frame are divided into. */ 4621 the frame are divided into. */
4616 Point mouse_pos; 4622 Point mouse_pos;
4617 4623
4624#if TARGET_API_MAC_CARBON
4625 GetGlobalMouse (&mouse_pos);
4626 mouse_pos.h -= f1->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f1);
4627 mouse_pos.v -= f1->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f1);
4628#else
4618 SetPortWindowPort (FRAME_MAC_WINDOW (f1)); 4629 SetPortWindowPort (FRAME_MAC_WINDOW (f1));
4619 GetMouse (&mouse_pos); 4630 GetMouse (&mouse_pos);
4631#endif
4620 remember_mouse_glyph (f1, mouse_pos.h, mouse_pos.v, 4632 remember_mouse_glyph (f1, mouse_pos.h, mouse_pos.v,
4621 &last_mouse_glyph); 4633 &last_mouse_glyph);
4622 last_mouse_glyph_frame = f1; 4634 last_mouse_glyph_frame = f1;
@@ -4646,14 +4658,14 @@ static OSStatus set_scroll_bar_timer P_ ((EventTimerInterval));
4646static int control_part_code_to_scroll_bar_part P_ ((ControlPartCode)); 4658static int control_part_code_to_scroll_bar_part P_ ((ControlPartCode));
4647static void construct_scroll_bar_click P_ ((struct scroll_bar *, int, 4659static void construct_scroll_bar_click P_ ((struct scroll_bar *, int,
4648 struct input_event *)); 4660 struct input_event *));
4649static OSStatus get_control_part_bounds P_ ((ControlHandle, ControlPartCode, 4661static OSStatus get_control_part_bounds P_ ((ControlRef, ControlPartCode,
4650 Rect *)); 4662 Rect *));
4651static void x_scroll_bar_handle_press P_ ((struct scroll_bar *, 4663static void x_scroll_bar_handle_press P_ ((struct scroll_bar *,
4652 ControlPartCode, Point, 4664 ControlPartCode, Point,
4653 struct input_event *)); 4665 struct input_event *));
4654static void x_scroll_bar_handle_release P_ ((struct scroll_bar *, 4666static void x_scroll_bar_handle_release P_ ((struct scroll_bar *,
4655 struct input_event *)); 4667 struct input_event *));
4656static void x_scroll_bar_handle_drag P_ ((WindowPtr, struct scroll_bar *, 4668static void x_scroll_bar_handle_drag P_ ((WindowRef, struct scroll_bar *,
4657 Point, struct input_event *)); 4669 Point, struct input_event *));
4658static void x_set_toolkit_scroll_bar_thumb P_ ((struct scroll_bar *, 4670static void x_set_toolkit_scroll_bar_thumb P_ ((struct scroll_bar *,
4659 int, int, int)); 4671 int, int, int));
@@ -4746,7 +4758,7 @@ construct_scroll_bar_click (bar, part, bufp)
4746 4758
4747static OSStatus 4759static OSStatus
4748get_control_part_bounds (ch, part_code, rect) 4760get_control_part_bounds (ch, part_code, rect)
4749 ControlHandle ch; 4761 ControlRef ch;
4750 ControlPartCode part_code; 4762 ControlPartCode part_code;
4751 Rect *rect; 4763 Rect *rect;
4752{ 4764{
@@ -4776,7 +4788,7 @@ x_scroll_bar_handle_press (bar, part_code, mouse_pos, bufp)
4776 if (part != scroll_bar_handle) 4788 if (part != scroll_bar_handle)
4777 { 4789 {
4778 construct_scroll_bar_click (bar, part, bufp); 4790 construct_scroll_bar_click (bar, part, bufp);
4779 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar), part_code); 4791 HiliteControl (SCROLL_BAR_CONTROL_REF (bar), part_code);
4780 set_scroll_bar_timer (SCROLL_BAR_FIRST_DELAY); 4792 set_scroll_bar_timer (SCROLL_BAR_FIRST_DELAY);
4781 bar->dragging = Qnil; 4793 bar->dragging = Qnil;
4782 } 4794 }
@@ -4784,7 +4796,7 @@ x_scroll_bar_handle_press (bar, part_code, mouse_pos, bufp)
4784 { 4796 {
4785 Rect r; 4797 Rect r;
4786 4798
4787 get_control_part_bounds (SCROLL_BAR_CONTROL_HANDLE (bar), 4799 get_control_part_bounds (SCROLL_BAR_CONTROL_REF (bar),
4788 kControlIndicatorPart, &r); 4800 kControlIndicatorPart, &r);
4789 XSETINT (bar->dragging, - (mouse_pos.v - r.top) - 1); 4801 XSETINT (bar->dragging, - (mouse_pos.v - r.top) - 1);
4790 } 4802 }
@@ -4802,7 +4814,7 @@ x_scroll_bar_handle_release (bar, bufp)
4802 || (INTEGERP (bar->dragging) && XINT (bar->dragging) >= 0)) 4814 || (INTEGERP (bar->dragging) && XINT (bar->dragging) >= 0))
4803 construct_scroll_bar_click (bar, scroll_bar_end_scroll, bufp); 4815 construct_scroll_bar_click (bar, scroll_bar_end_scroll, bufp);
4804 4816
4805 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar), 0); 4817 HiliteControl (SCROLL_BAR_CONTROL_REF (bar), 0);
4806 set_scroll_bar_timer (kEventDurationForever); 4818 set_scroll_bar_timer (kEventDurationForever);
4807 4819
4808 last_scroll_bar_part = -1; 4820 last_scroll_bar_part = -1;
@@ -4812,19 +4824,19 @@ x_scroll_bar_handle_release (bar, bufp)
4812 4824
4813static void 4825static void
4814x_scroll_bar_handle_drag (win, bar, mouse_pos, bufp) 4826x_scroll_bar_handle_drag (win, bar, mouse_pos, bufp)
4815 WindowPtr win; 4827 WindowRef win;
4816 struct scroll_bar *bar; 4828 struct scroll_bar *bar;
4817 Point mouse_pos; 4829 Point mouse_pos;
4818 struct input_event *bufp; 4830 struct input_event *bufp;
4819{ 4831{
4820 ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar); 4832 ControlRef ch = SCROLL_BAR_CONTROL_REF (bar);
4821 4833
4822 if (last_scroll_bar_part == scroll_bar_handle) 4834 if (last_scroll_bar_part == scroll_bar_handle)
4823 { 4835 {
4824 int top, top_range; 4836 int top, top_range;
4825 Rect r; 4837 Rect r;
4826 4838
4827 get_control_part_bounds (SCROLL_BAR_CONTROL_HANDLE (bar), 4839 get_control_part_bounds (SCROLL_BAR_CONTROL_REF (bar),
4828 kControlIndicatorPart, &r); 4840 kControlIndicatorPart, &r);
4829 4841
4830 if (INTEGERP (bar->dragging) && XINT (bar->dragging) < 0) 4842 if (INTEGERP (bar->dragging) && XINT (bar->dragging) < 0)
@@ -4872,13 +4884,13 @@ x_scroll_bar_handle_drag (win, bar, mouse_pos, bufp)
4872 } 4884 }
4873 4885
4874 if (unhilite_p) 4886 if (unhilite_p)
4875 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar), 0); 4887 HiliteControl (SCROLL_BAR_CONTROL_REF (bar), 0);
4876 else if (part != last_scroll_bar_part 4888 else if (part != last_scroll_bar_part
4877 || scroll_bar_timer_event_posted_p) 4889 || scroll_bar_timer_event_posted_p)
4878 { 4890 {
4879 construct_scroll_bar_click (bar, part, bufp); 4891 construct_scroll_bar_click (bar, part, bufp);
4880 last_scroll_bar_part = part; 4892 last_scroll_bar_part = part;
4881 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar), part_code); 4893 HiliteControl (SCROLL_BAR_CONTROL_REF (bar), part_code);
4882 set_scroll_bar_timer (SCROLL_BAR_CONTINUOUS_DELAY); 4894 set_scroll_bar_timer (SCROLL_BAR_CONTINUOUS_DELAY);
4883 } 4895 }
4884 } 4896 }
@@ -4892,7 +4904,7 @@ x_set_toolkit_scroll_bar_thumb (bar, portion, position, whole)
4892 struct scroll_bar *bar; 4904 struct scroll_bar *bar;
4893 int portion, position, whole; 4905 int portion, position, whole;
4894{ 4906{
4895 ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar); 4907 ControlRef ch = SCROLL_BAR_CONTROL_REF (bar);
4896 int value, viewsize, maximum; 4908 int value, viewsize, maximum;
4897 4909
4898 if (XINT (bar->track_height) == 0) 4910 if (XINT (bar->track_height) == 0)
@@ -4951,7 +4963,7 @@ x_scroll_bar_create (w, top, left, width, height, disp_top, disp_height)
4951 struct scroll_bar *bar 4963 struct scroll_bar *bar
4952 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil)); 4964 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil));
4953 Rect r; 4965 Rect r;
4954 ControlHandle ch; 4966 ControlRef ch;
4955 4967
4956 BLOCK_INPUT; 4968 BLOCK_INPUT;
4957 4969
@@ -4975,7 +4987,7 @@ x_scroll_bar_create (w, top, left, width, height, disp_top, disp_height)
4975 ch = NewControl (FRAME_MAC_WINDOW (f), &r, "\p", width < disp_height, 4987 ch = NewControl (FRAME_MAC_WINDOW (f), &r, "\p", width < disp_height,
4976 0, 0, 0, scrollBarProc, (long) bar); 4988 0, 0, 0, scrollBarProc, (long) bar);
4977#endif 4989#endif
4978 SET_SCROLL_BAR_CONTROL_HANDLE (bar, ch); 4990 SET_SCROLL_BAR_CONTROL_REF (bar, ch);
4979 4991
4980 XSETWINDOW (bar->window, w); 4992 XSETWINDOW (bar->window, w);
4981 XSETINT (bar->top, top); 4993 XSETINT (bar->top, top);
@@ -5025,7 +5037,7 @@ x_scroll_bar_set_handle (bar, start, end, rebuild)
5025 int rebuild; 5037 int rebuild;
5026{ 5038{
5027 int dragging = ! NILP (bar->dragging); 5039 int dragging = ! NILP (bar->dragging);
5028 ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar); 5040 ControlRef ch = SCROLL_BAR_CONTROL_REF (bar);
5029 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); 5041 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
5030 int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); 5042 int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height));
5031 int length = end - start; 5043 int length = end - start;
@@ -5094,7 +5106,7 @@ x_scroll_bar_remove (bar)
5094 mac_prepare_for_quickdraw (f); 5106 mac_prepare_for_quickdraw (f);
5095#endif 5107#endif
5096 /* Destroy the Mac scroll bar control */ 5108 /* Destroy the Mac scroll bar control */
5097 DisposeControl (SCROLL_BAR_CONTROL_HANDLE (bar)); 5109 DisposeControl (SCROLL_BAR_CONTROL_REF (bar));
5098 5110
5099 /* Disassociate this scroll bar from its window. */ 5111 /* Disassociate this scroll bar from its window. */
5100 XWINDOW (bar->window)->vertical_scroll_bar = Qnil; 5112 XWINDOW (bar->window)->vertical_scroll_bar = Qnil;
@@ -5172,10 +5184,10 @@ XTset_vertical_scroll_bar (w, portion, whole, position)
5172 else 5184 else
5173 { 5185 {
5174 /* It may just need to be moved and resized. */ 5186 /* It may just need to be moved and resized. */
5175 ControlHandle ch; 5187 ControlRef ch;
5176 5188
5177 bar = XSCROLL_BAR (w->vertical_scroll_bar); 5189 bar = XSCROLL_BAR (w->vertical_scroll_bar);
5178 ch = SCROLL_BAR_CONTROL_HANDLE (bar); 5190 ch = SCROLL_BAR_CONTROL_REF (bar);
5179 5191
5180 BLOCK_INPUT; 5192 BLOCK_INPUT;
5181 5193
@@ -5231,7 +5243,7 @@ XTset_vertical_scroll_bar (w, portion, whole, position)
5231 } 5243 }
5232 else 5244 else
5233 { 5245 {
5234 ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar); 5246 ControlRef ch = SCROLL_BAR_CONTROL_REF (bar);
5235 Rect r0, r1; 5247 Rect r0, r1;
5236 5248
5237 BLOCK_INPUT; 5249 BLOCK_INPUT;
@@ -5508,19 +5520,24 @@ x_scroll_bar_report_motion (fp, bar_window, part, x, y, time)
5508 unsigned long *time; 5520 unsigned long *time;
5509{ 5521{
5510 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); 5522 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar);
5511 ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar); 5523 ControlRef ch = SCROLL_BAR_CONTROL_REF (bar);
5512#if TARGET_API_MAC_CARBON 5524#if TARGET_API_MAC_CARBON
5513 WindowPtr wp = GetControlOwner (ch); 5525 WindowRef wp = GetControlOwner (ch);
5514#else 5526#else
5515 WindowPtr wp = (*ch)->contrlOwner; 5527 WindowRef wp = (*ch)->contrlOwner;
5516#endif 5528#endif
5517 Point mouse_pos; 5529 Point mouse_pos;
5518 struct frame *f = mac_window_to_frame (wp); 5530 struct frame *f = mac_window_to_frame (wp);
5519 int win_y, top_range; 5531 int win_y, top_range;
5520 5532
5533#if TARGET_API_MAC_CARBON
5534 GetGlobalMouse (&mouse_pos);
5535 mouse_pos.h -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f);
5536 mouse_pos.v -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f);
5537#else
5521 SetPortWindowPort (wp); 5538 SetPortWindowPort (wp);
5522
5523 GetMouse (&mouse_pos); 5539 GetMouse (&mouse_pos);
5540#endif
5524 5541
5525 win_y = mouse_pos.v - XINT (bar->top); 5542 win_y = mouse_pos.v - XINT (bar->top);
5526 top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); 5543 top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height));
@@ -6165,9 +6182,7 @@ x_set_offset (f, xoff, yoff, change_gravity)
6165 ConstrainWindowToScreen (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn, 6182 ConstrainWindowToScreen (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn,
6166 kWindowConstrainMoveRegardlessOfFit 6183 kWindowConstrainMoveRegardlessOfFit
6167 | kWindowConstrainAllowPartial, NULL, NULL); 6184 | kWindowConstrainAllowPartial, NULL, NULL);
6168#if USE_CARBON_EVENTS
6169 if (!NILP (tip_frame) && XFRAME (tip_frame) == f) 6185 if (!NILP (tip_frame) && XFRAME (tip_frame) == f)
6170#endif
6171 mac_handle_origin_change (f); 6186 mac_handle_origin_change (f);
6172#else 6187#else
6173 { 6188 {
@@ -6243,7 +6258,7 @@ x_set_window_size (f, change_gravity, cols, rows)
6243 6258
6244 SizeWindow (FRAME_MAC_WINDOW (f), pixelwidth, pixelheight, 0); 6259 SizeWindow (FRAME_MAC_WINDOW (f), pixelwidth, pixelheight, 0);
6245 6260
6246#if USE_CARBON_EVENTS 6261#if TARGET_API_MAC_CARBON
6247 if (!NILP (tip_frame) && f == XFRAME (tip_frame)) 6262 if (!NILP (tip_frame) && f == XFRAME (tip_frame))
6248#endif 6263#endif
6249 mac_handle_size_change (f, pixelwidth, pixelheight); 6264 mac_handle_size_change (f, pixelwidth, pixelheight);
@@ -6290,17 +6305,11 @@ x_set_mouse_pixel_position (f, pix_x, pix_y)
6290 int pix_x, pix_y; 6305 int pix_x, pix_y;
6291{ 6306{
6292#ifdef MAC_OSX 6307#ifdef MAC_OSX
6293 Point p; 6308 pix_x += f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f);
6294 CGPoint point; 6309 pix_y += f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f);
6295 6310
6296 BLOCK_INPUT; 6311 BLOCK_INPUT;
6297 SetPortWindowPort (FRAME_MAC_WINDOW (f)); 6312 CGWarpMouseCursorPosition (CGPointMake (pix_x, pix_y));
6298 p.h = pix_x;
6299 p.v = pix_y;
6300 LocalToGlobal (&p);
6301 point.x = p.h;
6302 point.y = p.v;
6303 CGWarpMouseCursorPosition (point);
6304 UNBLOCK_INPUT; 6313 UNBLOCK_INPUT;
6305#else 6314#else
6306#if 0 /* MAC_TODO: LMSetMouseLocation and CursorDeviceMoveTo are non-Carbon */ 6315#if 0 /* MAC_TODO: LMSetMouseLocation and CursorDeviceMoveTo are non-Carbon */
@@ -6382,7 +6391,7 @@ static void
6382mac_handle_visibility_change (f) 6391mac_handle_visibility_change (f)
6383 struct frame *f; 6392 struct frame *f;
6384{ 6393{
6385 WindowPtr wp = FRAME_MAC_WINDOW (f); 6394 WindowRef wp = FRAME_MAC_WINDOW (f);
6386 int visible = 0, iconified = 0; 6395 int visible = 0, iconified = 0;
6387 struct input_event buf; 6396 struct input_event buf;
6388 6397
@@ -6450,32 +6459,7 @@ x_make_frame_visible (f)
6450 before the window gets really visible. */ 6459 before the window gets really visible. */
6451 if (! FRAME_ICONIFIED_P (f) 6460 if (! FRAME_ICONIFIED_P (f)
6452 && ! f->output_data.mac->asked_for_visible) 6461 && ! f->output_data.mac->asked_for_visible)
6453 { 6462 x_set_offset (f, f->left_pos, f->top_pos, 0);
6454#if TARGET_API_MAC_CARBON
6455 if (!(FRAME_SIZE_HINTS (f)->flags & (USPosition | PPosition)))
6456 {
6457 struct frame *sf = SELECTED_FRAME ();
6458 if (!FRAME_MAC_P (sf))
6459 RepositionWindow (FRAME_MAC_WINDOW (f), NULL,
6460 kWindowCenterOnMainScreen);
6461 else
6462 RepositionWindow (FRAME_MAC_WINDOW (f),
6463 FRAME_MAC_WINDOW (sf),
6464#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
6465 kWindowCascadeStartAtParentWindowScreen
6466#else
6467 kWindowCascadeOnParentWindowScreen
6468#endif
6469 );
6470#if USE_CARBON_EVENTS
6471 if (!NILP (tip_frame) && f == XFRAME (tip_frame))
6472#endif
6473 mac_handle_origin_change (f);
6474 }
6475 else
6476#endif
6477 x_set_offset (f, f->left_pos, f->top_pos, 0);
6478 }
6479 6463
6480 f->output_data.mac->asked_for_visible = 1; 6464 f->output_data.mac->asked_for_visible = 1;
6481 6465
@@ -6549,18 +6533,20 @@ x_make_frame_invisible (f)
6549 6533
6550 BLOCK_INPUT; 6534 BLOCK_INPUT;
6551 6535
6536#if !TARGET_API_MAC_CARBON
6552 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim 6537 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
6553 that the current position of the window is user-specified, rather than 6538 that the current position of the window is user-specified, rather than
6554 program-specified, so that when the window is mapped again, it will be 6539 program-specified, so that when the window is mapped again, it will be
6555 placed at the same location, without forcing the user to position it 6540 placed at the same location, without forcing the user to position it
6556 by hand again (they have already done that once for this window.) */ 6541 by hand again (they have already done that once for this window.) */
6557 x_wm_set_size_hint (f, (long) 0, 1); 6542 x_wm_set_size_hint (f, (long) 0, 1);
6543#endif
6558 6544
6559 HideWindow (FRAME_MAC_WINDOW (f)); 6545 HideWindow (FRAME_MAC_WINDOW (f));
6560 6546
6561 UNBLOCK_INPUT; 6547 UNBLOCK_INPUT;
6562 6548
6563#if !USE_CARBON_EVENTS 6549#if !TARGET_API_MAC_CARBON
6564 mac_handle_visibility_change (f); 6550 mac_handle_visibility_change (f);
6565#endif 6551#endif
6566} 6552}
@@ -6599,7 +6585,7 @@ x_iconify_frame (f)
6599 if (err != noErr) 6585 if (err != noErr)
6600 error ("Can't notify window manager of iconification"); 6586 error ("Can't notify window manager of iconification");
6601 6587
6602#if !USE_CARBON_EVENTS 6588#if !TARGET_API_MAC_CARBON
6603 mac_handle_visibility_change (f); 6589 mac_handle_visibility_change (f);
6604#endif 6590#endif
6605} 6591}
@@ -6612,7 +6598,7 @@ x_free_frame_resources (f)
6612 struct frame *f; 6598 struct frame *f;
6613{ 6599{
6614 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); 6600 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f);
6615 WindowPtr wp = FRAME_MAC_WINDOW (f); 6601 WindowRef wp = FRAME_MAC_WINDOW (f);
6616 6602
6617 BLOCK_INPUT; 6603 BLOCK_INPUT;
6618 6604
@@ -8749,16 +8735,93 @@ x_find_ccl_program (fontp)
8749 possible. */ 8735 possible. */
8750static int font_panel_shown_p = 0; 8736static int font_panel_shown_p = 0;
8751 8737
8738extern Lisp_Object Qfont;
8739static Lisp_Object Qpanel_closed, Qselection;
8740
8741static OSStatus mac_store_event_ref_as_apple_event P_ ((AEEventClass, AEEventID,
8742 Lisp_Object,
8743 Lisp_Object,
8744 EventRef, UInt32,
8745 const EventParamName *,
8746 const EventParamType *));
8747
8752int 8748int
8753mac_font_panel_visible_p () 8749mac_font_panel_visible_p ()
8754{ 8750{
8755 return font_panel_shown_p && FPIsFontPanelVisible (); 8751 return font_panel_shown_p && FPIsFontPanelVisible ();
8756} 8752}
8757 8753
8754static pascal OSStatus
8755mac_handle_font_event (next_handler, event, data)
8756 EventHandlerCallRef next_handler;
8757 EventRef event;
8758 void *data;
8759{
8760 OSStatus result, err;
8761 Lisp_Object id_key;
8762 int num_params;
8763 const EventParamName *names;
8764 const EventParamType *types;
8765 static const EventParamName names_sel[] = {kEventParamATSUFontID,
8766 kEventParamATSUFontSize,
8767 kEventParamFMFontFamily,
8768 kEventParamFMFontSize,
8769 kEventParamFontColor};
8770 static const EventParamType types_sel[] = {typeATSUFontID,
8771 typeATSUSize,
8772 typeFMFontFamily,
8773 typeFMFontSize,
8774 typeFontColor};
8775
8776 result = CallNextEventHandler (next_handler, event);
8777 if (result != eventNotHandledErr)
8778 return result;
8779
8780 switch (GetEventKind (event))
8781 {
8782 case kEventFontPanelClosed:
8783 id_key = Qpanel_closed;
8784 num_params = 0;
8785 names = NULL;
8786 types = NULL;
8787 break;
8788
8789 case kEventFontSelection:
8790 id_key = Qselection;
8791 num_params = sizeof (names_sel) / sizeof (names_sel[0]);
8792 names = names_sel;
8793 types = types_sel;
8794 break;
8795 }
8796
8797 err = mac_store_event_ref_as_apple_event (0, 0, Qfont, id_key,
8798 event, num_params,
8799 names, types);
8800 if (err == noErr)
8801 result = noErr;
8802
8803 return result;
8804}
8805
8758OSStatus 8806OSStatus
8759mac_show_hide_font_panel () 8807mac_show_hide_font_panel ()
8760{ 8808{
8761 font_panel_shown_p = 1; 8809 if (!font_panel_shown_p)
8810 {
8811 OSStatus err;
8812
8813 static const EventTypeSpec specs[] =
8814 {{kEventClassFont, kEventFontPanelClosed},
8815 {kEventClassFont, kEventFontSelection}};
8816
8817 err = InstallApplicationEventHandler (mac_handle_font_event,
8818 GetEventTypeCount (specs),
8819 specs, NULL, NULL);
8820 if (err != noErr)
8821 return err;
8822
8823 font_panel_shown_p = 1;
8824 }
8762 8825
8763 return FPShowHideFontPanel (); 8826 return FPShowHideFontPanel ();
8764} 8827}
@@ -8874,7 +8937,7 @@ Lisp_Object Vmac_function_modifier;
8874 a three button mouse */ 8937 a three button mouse */
8875Lisp_Object Vmac_emulate_three_button_mouse; 8938Lisp_Object Vmac_emulate_three_button_mouse;
8876 8939
8877#if USE_CARBON_EVENTS 8940#if TARGET_API_MAC_CARBON
8878/* Non-zero if the mouse wheel button (i.e. button 4) should map to 8941/* Non-zero if the mouse wheel button (i.e. button 4) should map to
8879 mouse-2, instead of mouse-3. */ 8942 mouse-2, instead of mouse-3. */
8880int mac_wheel_button_is_mouse_2; 8943int mac_wheel_button_is_mouse_2;
@@ -8899,16 +8962,12 @@ static int mac_screen_config_changed = 0;
8899Point saved_menu_event_location; 8962Point saved_menu_event_location;
8900 8963
8901/* Apple Events */ 8964/* Apple Events */
8902#if USE_CARBON_EVENTS 8965#if TARGET_API_MAC_CARBON
8903static Lisp_Object Qhi_command; 8966static Lisp_Object Qhi_command;
8904#ifdef MAC_OSX 8967#ifdef MAC_OSX
8905extern Lisp_Object Qwindow; 8968extern Lisp_Object Qwindow;
8906static Lisp_Object Qtoolbar_switch_mode; 8969static Lisp_Object Qtoolbar_switch_mode;
8907#endif 8970#endif
8908#if USE_MAC_FONT_PANEL
8909extern Lisp_Object Qfont;
8910static Lisp_Object Qpanel_closed, Qselection;
8911#endif
8912#if USE_MAC_TSM 8971#if USE_MAC_TSM
8913static TSMDocumentID tsm_document_id; 8972static TSMDocumentID tsm_document_id;
8914static Lisp_Object Qtext_input; 8973static Lisp_Object Qtext_input;
@@ -8920,7 +8979,7 @@ static Lisp_Object saved_ts_script_language_on_focus;
8920static ScriptLanguageRecord saved_ts_language; 8979static ScriptLanguageRecord saved_ts_language;
8921static Component saved_ts_component; 8980static Component saved_ts_component;
8922#endif 8981#endif
8923#endif 8982#endif /* TARGET_API_MAC_CARBON */
8924extern int mac_ready_for_apple_events; 8983extern int mac_ready_for_apple_events;
8925extern Lisp_Object Qundefined; 8984extern Lisp_Object Qundefined;
8926extern void init_apple_event_handler P_ ((void)); 8985extern void init_apple_event_handler P_ ((void));
@@ -8933,20 +8992,15 @@ extern OSErr init_coercion_handler P_ ((void));
8933extern OSErr install_drag_handler P_ ((WindowRef)); 8992extern OSErr install_drag_handler P_ ((WindowRef));
8934extern void remove_drag_handler P_ ((WindowRef)); 8993extern void remove_drag_handler P_ ((WindowRef));
8935 8994
8995#if TARGET_API_MAC_CARBON
8936/* Showing help echo string during menu tracking */ 8996/* Showing help echo string during menu tracking */
8937extern OSStatus install_menu_target_item_handler P_ ((WindowPtr)); 8997extern OSStatus install_menu_target_item_handler P_ ((void));
8938 8998
8939#if USE_CARBON_EVENTS
8940#ifdef MAC_OSX 8999#ifdef MAC_OSX
8941extern void init_service_handler (); 9000extern OSStatus install_service_handler ();
8942static Lisp_Object Qservice, Qpaste, Qperform; 9001static Lisp_Object Qservice, Qpaste, Qperform;
8943#endif 9002#endif
8944
8945/* Window Event Handler */
8946static pascal OSStatus mac_handle_window_event (EventHandlerCallRef,
8947 EventRef, void *);
8948#endif 9003#endif
8949OSStatus install_window_handler (WindowPtr);
8950 9004
8951extern void init_emacs_passwd_dir (); 9005extern void init_emacs_passwd_dir ();
8952extern int emacs_main (int, char **, char **); 9006extern int emacs_main (int, char **, char **);
@@ -9030,7 +9084,7 @@ static const unsigned char fn_keycode_to_keycode_table[] = {
9030#endif /* MAC_OSX */ 9084#endif /* MAC_OSX */
9031 9085
9032static int 9086static int
9033#if USE_CARBON_EVENTS 9087#if TARGET_API_MAC_CARBON
9034mac_to_emacs_modifiers (UInt32 mods) 9088mac_to_emacs_modifiers (UInt32 mods)
9035#else 9089#else
9036mac_to_emacs_modifiers (EventModifiers mods) 9090mac_to_emacs_modifiers (EventModifiers mods)
@@ -9139,17 +9193,19 @@ mac_quit_char_key_p (modifiers, key_code)
9139} 9193}
9140#endif 9194#endif
9141 9195
9142#if USE_CARBON_EVENTS 9196#if TARGET_API_MAC_CARBON
9143/* Obtains the event modifiers from the event ref and then calls 9197/* Obtains the event modifiers from the event ref and then calls
9144 mac_to_emacs_modifiers. */ 9198 mac_to_emacs_modifiers. */
9145static int 9199static int
9146mac_event_to_emacs_modifiers (EventRef eventRef) 9200mac_event_to_emacs_modifiers (EventRef eventRef)
9147{ 9201{
9148 UInt32 mods = 0; 9202 UInt32 mods = 0, class;
9203
9149 GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL, 9204 GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL,
9150 sizeof (UInt32), NULL, &mods); 9205 sizeof (UInt32), NULL, &mods);
9206 class = GetEventClass (eventRef);
9151 if (!NILP (Vmac_emulate_three_button_mouse) && 9207 if (!NILP (Vmac_emulate_three_button_mouse) &&
9152 GetEventClass(eventRef) == kEventClassMouse) 9208 (class == kEventClassMouse || class == kEventClassCommand))
9153 { 9209 {
9154 mods &= ~(optionKey | cmdKey); 9210 mods &= ~(optionKey | cmdKey);
9155 } 9211 }
@@ -9288,7 +9344,7 @@ static void
9288do_get_menus (void) 9344do_get_menus (void)
9289{ 9345{
9290 Handle menubar_handle; 9346 Handle menubar_handle;
9291 MenuHandle menu_handle; 9347 MenuRef menu;
9292 9348
9293 menubar_handle = GetNewMBar (128); 9349 menubar_handle = GetNewMBar (128);
9294 if(menubar_handle == NULL) 9350 if(menubar_handle == NULL)
@@ -9297,9 +9353,9 @@ do_get_menus (void)
9297 DrawMenuBar (); 9353 DrawMenuBar ();
9298 9354
9299#if !TARGET_API_MAC_CARBON 9355#if !TARGET_API_MAC_CARBON
9300 menu_handle = GetMenuHandle (M_APPLE); 9356 menu = GetMenuRef (M_APPLE);
9301 if(menu_handle != NULL) 9357 if (menu != NULL)
9302 AppendResMenu (menu_handle,'DRVR'); 9358 AppendResMenu (menu, 'DRVR');
9303 else 9359 else
9304 abort (); 9360 abort ();
9305#endif 9361#endif
@@ -9348,7 +9404,7 @@ do_check_ram_size (void)
9348#endif /* MAC_OS8 */ 9404#endif /* MAC_OS8 */
9349 9405
9350static void 9406static void
9351do_window_update (WindowPtr win) 9407do_window_update (WindowRef win)
9352{ 9408{
9353 struct frame *f = mac_window_to_frame (win); 9409 struct frame *f = mac_window_to_frame (win);
9354 9410
@@ -9393,7 +9449,7 @@ do_window_update (WindowPtr win)
9393} 9449}
9394 9450
9395static int 9451static int
9396is_emacs_window (WindowPtr win) 9452is_emacs_window (WindowRef win)
9397{ 9453{
9398 Lisp_Object tail, frame; 9454 Lisp_Object tail, frame;
9399 9455
@@ -9506,7 +9562,7 @@ do_apple_menu (SInt16 menu_item)
9506 NoteAlert (ABOUT_ALERT_ID, NULL); 9562 NoteAlert (ABOUT_ALERT_ID, NULL);
9507 else 9563 else
9508 { 9564 {
9509 GetMenuItemText (GetMenuHandle (M_APPLE), menu_item, item_name); 9565 GetMenuItemText (GetMenuRef (M_APPLE), menu_item, item_name);
9510 da_driver_refnum = OpenDeskAcc (item_name); 9566 da_driver_refnum = OpenDeskAcc (item_name);
9511 } 9567 }
9512} 9568}
@@ -9517,7 +9573,7 @@ do_apple_menu (SInt16 menu_item)
9517 9573
9518static void 9574static void
9519do_grow_window (w, e) 9575do_grow_window (w, e)
9520 WindowPtr w; 9576 WindowRef w;
9521 const EventRecord *e; 9577 const EventRecord *e;
9522{ 9578{
9523 Rect limit_rect; 9579 Rect limit_rect;
@@ -9569,7 +9625,7 @@ mac_get_ideal_size (f)
9569 struct frame *f; 9625 struct frame *f;
9570{ 9626{
9571 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); 9627 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f);
9572 WindowPtr w = FRAME_MAC_WINDOW (f); 9628 WindowRef w = FRAME_MAC_WINDOW (f);
9573 Point ideal_size; 9629 Point ideal_size;
9574 Rect standard_rect; 9630 Rect standard_rect;
9575 int height, width, columns, rows; 9631 int height, width, columns, rows;
@@ -9595,7 +9651,7 @@ mac_get_ideal_size (f)
9595 wide (DEFAULT_NUM_COLS) and as tall as will fit on the screen. */ 9651 wide (DEFAULT_NUM_COLS) and as tall as will fit on the screen. */
9596 9652
9597static void 9653static void
9598do_zoom_window (WindowPtr w, int zoom_in_or_out) 9654do_zoom_window (WindowRef w, int zoom_in_or_out)
9599{ 9655{
9600 Rect zoom_rect, port_rect; 9656 Rect zoom_rect, port_rect;
9601 int width, height; 9657 int width, height;
@@ -9658,13 +9714,9 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
9658 SetPort (save_port); 9714 SetPort (save_port);
9659#endif /* not TARGET_API_MAC_CARBON */ 9715#endif /* not TARGET_API_MAC_CARBON */
9660 9716
9661#if !USE_CARBON_EVENTS 9717#if !TARGET_API_MAC_CARBON
9662 /* retrieve window size and update application values */ 9718 /* retrieve window size and update application values */
9663#if TARGET_API_MAC_CARBON
9664 GetWindowPortBounds (w, &port_rect);
9665#else
9666 port_rect = w->portRect; 9719 port_rect = w->portRect;
9667#endif
9668 height = port_rect.bottom - port_rect.top; 9720 height = port_rect.bottom - port_rect.top;
9669 width = port_rect.right - port_rect.left; 9721 width = port_rect.right - port_rect.left;
9670 9722
@@ -9673,6 +9725,210 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
9673#endif 9725#endif
9674} 9726}
9675 9727
9728static void
9729mac_set_unicode_keystroke_event (code, buf)
9730 UniChar code;
9731 struct input_event *buf;
9732{
9733 int charset_id, c1, c2;
9734
9735 if (code < 0x80)
9736 {
9737 buf->kind = ASCII_KEYSTROKE_EVENT;
9738 buf->code = code;
9739 }
9740 else if (code < 0x100)
9741 {
9742 if (code < 0xA0)
9743 charset_id = CHARSET_8_BIT_CONTROL;
9744 else
9745 charset_id = charset_latin_iso8859_1;
9746 buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT;
9747 buf->code = MAKE_CHAR (charset_id, code, 0);
9748 }
9749 else
9750 {
9751 if (code < 0x2500)
9752 charset_id = charset_mule_unicode_0100_24ff,
9753 code -= 0x100;
9754 else if (code < 0x33FF)
9755 charset_id = charset_mule_unicode_2500_33ff,
9756 code -= 0x2500;
9757 else if (code >= 0xE000)
9758 charset_id = charset_mule_unicode_e000_ffff,
9759 code -= 0xE000;
9760 c1 = (code / 96) + 32, c2 = (code % 96) + 32;
9761 buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT;
9762 buf->code = MAKE_CHAR (charset_id, c1, c2);
9763 }
9764}
9765
9766static void
9767do_keystroke (action, char_code, key_code, modifiers, timestamp, buf)
9768 EventKind action;
9769 unsigned char char_code;
9770 UInt32 key_code, modifiers;
9771 unsigned long timestamp;
9772 struct input_event *buf;
9773{
9774 static SInt16 last_key_script = -1;
9775 SInt16 current_key_script = GetScriptManagerVariable (smKeyScript);
9776 UInt32 mapped_modifiers = mac_mapped_modifiers (modifiers);
9777
9778#ifdef MAC_OSX
9779 if (mapped_modifiers & kEventKeyModifierFnMask
9780 && key_code <= 0x7f
9781 && fn_keycode_to_keycode_table[key_code])
9782 key_code = fn_keycode_to_keycode_table[key_code];
9783#endif
9784
9785 if (key_code <= 0x7f && keycode_to_xkeysym_table[key_code])
9786 {
9787 buf->kind = NON_ASCII_KEYSTROKE_EVENT;
9788 buf->code = 0xff00 | keycode_to_xkeysym_table[key_code];
9789#ifdef MAC_OSX
9790 if (modifiers & kEventKeyModifierFnMask
9791 && key_code <= 0x7f
9792 && fn_keycode_to_keycode_table[key_code] == key_code)
9793 modifiers &= ~kEventKeyModifierFnMask;
9794#endif
9795 }
9796 else if (mapped_modifiers)
9797 {
9798 /* translate the keycode back to determine the original key */
9799#ifdef MAC_OSX
9800 UCKeyboardLayout *uchr_ptr = NULL;
9801#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
9802 OSStatus err;
9803 KeyboardLayoutRef layout;
9804
9805 err = KLGetCurrentKeyboardLayout (&layout);
9806 if (err == noErr)
9807 err = KLGetKeyboardLayoutProperty (layout, kKLuchrData,
9808 (const void **) &uchr_ptr);
9809#else
9810 static SInt16 last_key_layout_id = 0;
9811 static Handle uchr_handle = (Handle)-1;
9812 SInt16 current_key_layout_id =
9813 GetScriptVariable (current_key_script, smScriptKeys);
9814
9815 if (uchr_handle == (Handle)-1
9816 || last_key_layout_id != current_key_layout_id)
9817 {
9818 uchr_handle = GetResource ('uchr', current_key_layout_id);
9819 last_key_layout_id = current_key_layout_id;
9820 }
9821 if (uchr_handle)
9822 uchr_ptr = (UCKeyboardLayout *)*uchr_handle;
9823#endif
9824
9825 if (uchr_ptr)
9826 {
9827 OSStatus status;
9828 UInt16 key_action = action - keyDown;
9829 UInt32 modifier_key_state = (modifiers & ~mapped_modifiers) >> 8;
9830 UInt32 keyboard_type = LMGetKbdType ();
9831 SInt32 dead_key_state = 0;
9832 UniChar code;
9833 UniCharCount actual_length;
9834
9835 status = UCKeyTranslate (uchr_ptr, key_code, key_action,
9836 modifier_key_state, keyboard_type,
9837 kUCKeyTranslateNoDeadKeysMask,
9838 &dead_key_state,
9839 1, &actual_length, &code);
9840 if (status == noErr && actual_length == 1)
9841 mac_set_unicode_keystroke_event (code, buf);
9842 }
9843#endif /* MAC_OSX */
9844
9845 if (buf->kind == NO_EVENT)
9846 {
9847 /* This code comes from Keyboard Resource, Appendix C of IM
9848 - Text. This is necessary since shift is ignored in KCHR
9849 table translation when option or command is pressed. It
9850 also does not translate correctly control-shift chars
9851 like C-% so mask off shift here also. */
9852 /* Mask off modifier keys that are mapped to some Emacs
9853 modifiers. */
9854 int new_modifiers = modifiers & ~mapped_modifiers;
9855 /* set high byte of keycode to modifier high byte*/
9856 int new_key_code = key_code | new_modifiers;
9857 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
9858 unsigned long some_state = 0;
9859 UInt32 new_char_code;
9860
9861 new_char_code = KeyTranslate (kchr_ptr, new_key_code, &some_state);
9862 if (new_char_code == 0)
9863 /* Seems like a dead key. Append up-stroke. */
9864 new_char_code = KeyTranslate (kchr_ptr, new_key_code | 0x80,
9865 &some_state);
9866 if (new_char_code)
9867 {
9868 buf->kind = ASCII_KEYSTROKE_EVENT;
9869 buf->code = new_char_code & 0xff;
9870 }
9871 }
9872 }
9873
9874 if (buf->kind == NO_EVENT)
9875 {
9876 buf->kind = ASCII_KEYSTROKE_EVENT;
9877 buf->code = char_code;
9878 }
9879
9880 buf->modifiers = mac_to_emacs_modifiers (modifiers);
9881 buf->modifiers |= (extra_keyboard_modifiers
9882 & (meta_modifier | alt_modifier
9883 | hyper_modifier | super_modifier));
9884
9885#if TARGET_API_MAC_CARBON
9886 if (buf->kind == ASCII_KEYSTROKE_EVENT
9887 && buf->code >= 0x80 && buf->modifiers)
9888 {
9889 OSStatus err;
9890 TextEncoding encoding = kTextEncodingMacRoman;
9891 TextToUnicodeInfo ttu_info;
9892
9893 UpgradeScriptInfoToTextEncoding (current_key_script,
9894 kTextLanguageDontCare,
9895 kTextRegionDontCare,
9896 NULL, &encoding);
9897 err = CreateTextToUnicodeInfoByEncoding (encoding, &ttu_info);
9898 if (err == noErr)
9899 {
9900 UniChar code;
9901 Str255 pstr;
9902 ByteCount unicode_len;
9903
9904 pstr[0] = 1;
9905 pstr[1] = buf->code;
9906 err = ConvertFromPStringToUnicode (ttu_info, pstr,
9907 sizeof (UniChar),
9908 &unicode_len, &code);
9909 if (err == noErr && unicode_len == sizeof (UniChar))
9910 mac_set_unicode_keystroke_event (code, buf);
9911 DisposeTextToUnicodeInfo (&ttu_info);
9912 }
9913 }
9914#endif
9915
9916 if (buf->kind == ASCII_KEYSTROKE_EVENT
9917 && buf->code >= 0x80
9918 && last_key_script != current_key_script)
9919 {
9920 struct input_event event;
9921
9922 EVENT_INIT (event);
9923 event.kind = LANGUAGE_CHANGE_EVENT;
9924 event.arg = Qnil;
9925 event.code = current_key_script;
9926 event.timestamp = timestamp;
9927 kbd_buffer_store_event (&event);
9928 last_key_script = current_key_script;
9929 }
9930}
9931
9676void 9932void
9677mac_store_apple_event (class, id, desc) 9933mac_store_apple_event (class, id, desc)
9678 Lisp_Object class, id; 9934 Lisp_Object class, id;
@@ -9751,54 +10007,49 @@ mac_store_drag_event (window, mouse_pos, modifiers, desc)
9751 buf.arg = mac_aedesc_to_lisp (desc); 10007 buf.arg = mac_aedesc_to_lisp (desc);
9752 kbd_buffer_store_event (&buf); 10008 kbd_buffer_store_event (&buf);
9753} 10009}
9754#endif
9755 10010
9756#if USE_CARBON_EVENTS 10011#ifdef MAC_OSX
9757static pascal OSStatus 10012OSStatus
9758mac_handle_command_event (next_handler, event, data) 10013mac_store_service_event (event)
9759 EventHandlerCallRef next_handler;
9760 EventRef event; 10014 EventRef event;
9761 void *data;
9762{ 10015{
9763 OSStatus result, err; 10016 OSStatus err;
9764 HICommand command; 10017 Lisp_Object id_key;
9765 static const EventParamName names[] = 10018 int num_params;
9766 {kEventParamDirectObject, kEventParamKeyModifiers}; 10019 const EventParamName *names;
9767 static const EventParamType types[] = 10020 const EventParamType *types;
9768 {typeHICommand, typeUInt32}; 10021 static const EventParamName names_pfm[] =
9769 int num_params = sizeof (names) / sizeof (names[0]); 10022 {kEventParamServiceMessageName, kEventParamServiceUserData};
9770 10023 static const EventParamType types_pfm[] =
9771 result = CallNextEventHandler (next_handler, event); 10024 {typeCFStringRef, typeCFStringRef};
9772 if (result != eventNotHandledErr)
9773 return result;
9774 10025
9775 err = GetEventParameter (event, kEventParamDirectObject, typeHICommand, 10026 switch (GetEventKind (event))
9776 NULL, sizeof (HICommand), NULL, &command); 10027 {
10028 case kEventServicePaste:
10029 id_key = Qpaste;
10030 num_params = 0;
10031 names = NULL;
10032 types = NULL;
10033 break;
9777 10034
9778 if (err != noErr || command.commandID == 0) 10035 case kEventServicePerform:
9779 return eventNotHandledErr; 10036 id_key = Qperform;
10037 num_params = sizeof (names_pfm) / sizeof (names_pfm[0]);
10038 names = names_pfm;
10039 types = types_pfm;
10040 break;
9780 10041
9781 /* A HI command event is mapped to an Apple event whose event class 10042 default:
9782 symbol is `hi-command' and event ID is its command ID. */ 10043 abort ();
9783 err = mac_store_event_ref_as_apple_event (0, command.commandID, 10044 }
9784 Qhi_command, Qnil,
9785 event, num_params, names, types);
9786 return err == noErr ? noErr : eventNotHandledErr;
9787}
9788 10045
9789static OSStatus 10046 err = mac_store_event_ref_as_apple_event (0, 0, Qservice, id_key,
9790init_command_handler () 10047 event, num_params,
9791{ 10048 names, types);
9792 static const EventTypeSpec specs[] =
9793 {{kEventClassCommand, kEventCommandProcess}};
9794 static EventHandlerUPP handle_command_eventUPP = NULL;
9795 10049
9796 if (handle_command_eventUPP == NULL) 10050 return err;
9797 handle_command_eventUPP = NewEventHandlerUPP (mac_handle_command_event);
9798 return InstallApplicationEventHandler (handle_command_eventUPP,
9799 GetEventTypeCount (specs), specs,
9800 NULL, NULL);
9801} 10051}
10052#endif /* MAC_OSX */
9802 10053
9803static pascal OSStatus 10054static pascal OSStatus
9804mac_handle_window_event (next_handler, event, data) 10055mac_handle_window_event (next_handler, event, data)
@@ -9806,47 +10057,78 @@ mac_handle_window_event (next_handler, event, data)
9806 EventRef event; 10057 EventRef event;
9807 void *data; 10058 void *data;
9808{ 10059{
9809 WindowPtr wp; 10060 WindowRef wp;
9810 OSStatus result, err; 10061 OSStatus err, result = eventNotHandledErr;
9811 struct frame *f; 10062 struct frame *f;
9812 UInt32 attributes; 10063 UInt32 attributes;
9813 XSizeHints *size_hints; 10064 XSizeHints *size_hints;
9814 10065
9815 err = GetEventParameter (event, kEventParamDirectObject, typeWindowRef, 10066 err = GetEventParameter (event, kEventParamDirectObject, typeWindowRef,
9816 NULL, sizeof (WindowPtr), NULL, &wp); 10067 NULL, sizeof (WindowRef), NULL, &wp);
9817 if (err != noErr) 10068 if (err != noErr)
9818 return eventNotHandledErr; 10069 return eventNotHandledErr;
9819 10070
9820 f = mac_window_to_frame (wp); 10071 f = mac_window_to_frame (wp);
9821 switch (GetEventKind (event)) 10072 switch (GetEventKind (event))
9822 { 10073 {
10074 /* -- window refresh events -- */
10075
9823 case kEventWindowUpdate: 10076 case kEventWindowUpdate:
9824 result = CallNextEventHandler (next_handler, event); 10077 result = CallNextEventHandler (next_handler, event);
9825 if (result != eventNotHandledErr) 10078 if (result != eventNotHandledErr)
9826 return result; 10079 break;
9827 10080
9828 do_window_update (wp); 10081 do_window_update (wp);
9829 return noErr; 10082 result = noErr;
10083 break;
9830 10084
9831 case kEventWindowGetIdealSize: 10085 /* -- window state change events -- */
9832 result = CallNextEventHandler (next_handler, event);
9833 if (result != eventNotHandledErr)
9834 return result;
9835 10086
9836 { 10087 case kEventWindowShowing:
9837 Point ideal_size = mac_get_ideal_size (f); 10088 size_hints = FRAME_SIZE_HINTS (f);
10089 if (!(size_hints->flags & (USPosition | PPosition)))
10090 {
10091 struct frame *sf = SELECTED_FRAME ();
9838 10092
9839 err = SetEventParameter (event, kEventParamDimensions, 10093 if (!(FRAME_MAC_P (sf)))
9840 typeQDPoint, sizeof (Point), &ideal_size); 10094 RepositionWindow (wp, NULL, kWindowCenterOnMainScreen);
9841 if (err == noErr) 10095 else
9842 return noErr; 10096 {
9843 } 10097 RepositionWindow (wp, FRAME_MAC_WINDOW (sf),
10098#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
10099 kWindowCascadeStartAtParentWindowScreen
10100#else
10101 kWindowCascadeOnParentWindowScreen
10102#endif
10103 );
10104 }
10105 result = noErr;
10106 }
10107 break;
10108
10109 case kEventWindowHiding:
10110 /* Before unmapping the window, update the WM_SIZE_HINTS
10111 property to claim that the current position of the window is
10112 user-specified, rather than program-specified, so that when
10113 the window is mapped again, it will be placed at the same
10114 location, without forcing the user to position it by hand
10115 again (they have already done that once for this window.) */
10116 x_wm_set_size_hint (f, (long) 0, 1);
10117 result = noErr;
10118 break;
10119
10120 case kEventWindowShown:
10121 case kEventWindowHidden:
10122 case kEventWindowCollapsed:
10123 case kEventWindowExpanded:
10124 mac_handle_visibility_change (f);
10125 result = noErr;
9844 break; 10126 break;
9845 10127
9846 case kEventWindowBoundsChanging: 10128 case kEventWindowBoundsChanging:
9847 result = CallNextEventHandler (next_handler, event); 10129 result = CallNextEventHandler (next_handler, event);
9848 if (result != eventNotHandledErr) 10130 if (result != eventNotHandledErr)
9849 return result; 10131 break;
9850 10132
9851 err = GetEventParameter (event, kEventParamAttributes, typeUInt32, 10133 err = GetEventParameter (event, kEventParamAttributes, typeUInt32,
9852 NULL, sizeof (UInt32), NULL, &attributes); 10134 NULL, sizeof (UInt32), NULL, &attributes);
@@ -9890,7 +10172,7 @@ mac_handle_window_event (next_handler, event, data)
9890 bounds.bottom = bounds.top + height; 10172 bounds.bottom = bounds.top + height;
9891 SetEventParameter (event, kEventParamCurrentBounds, 10173 SetEventParameter (event, kEventParamCurrentBounds,
9892 typeQDRectangle, sizeof (Rect), &bounds); 10174 typeQDRectangle, sizeof (Rect), &bounds);
9893 return noErr; 10175 result = noErr;
9894 } 10176 }
9895 break; 10177 break;
9896 10178
@@ -9921,21 +10203,12 @@ mac_handle_window_event (next_handler, event, data)
9921 if (attributes & kWindowBoundsChangeOriginChanged) 10203 if (attributes & kWindowBoundsChangeOriginChanged)
9922 mac_handle_origin_change (f); 10204 mac_handle_origin_change (f);
9923 10205
9924 return noErr; 10206 result = noErr;
9925
9926 case kEventWindowShown:
9927 case kEventWindowHidden:
9928 case kEventWindowExpanded:
9929 case kEventWindowCollapsed:
9930 result = CallNextEventHandler (next_handler, event);
9931
9932 mac_handle_visibility_change (f);
9933 return noErr;
9934
9935 break; 10207 break;
9936 10208
10209 /* -- window action events -- */
10210
9937 case kEventWindowClose: 10211 case kEventWindowClose:
9938 result = CallNextEventHandler (next_handler, event);
9939 { 10212 {
9940 struct input_event buf; 10213 struct input_event buf;
9941 10214
@@ -9945,11 +10218,26 @@ mac_handle_window_event (next_handler, event, data)
9945 buf.arg = Qnil; 10218 buf.arg = Qnil;
9946 kbd_buffer_store_event (&buf); 10219 kbd_buffer_store_event (&buf);
9947 } 10220 }
9948 return noErr; 10221 result = noErr;
10222 break;
10223
10224 case kEventWindowGetIdealSize:
10225 result = CallNextEventHandler (next_handler, event);
10226 if (result != eventNotHandledErr)
10227 break;
10228
10229 {
10230 Point ideal_size = mac_get_ideal_size (f);
10231
10232 err = SetEventParameter (event, kEventParamDimensions,
10233 typeQDPoint, sizeof (Point), &ideal_size);
10234 if (err == noErr)
10235 result = noErr;
10236 }
10237 break;
9949 10238
9950#ifdef MAC_OSX 10239#ifdef MAC_OSX
9951 case kEventWindowToolbarSwitchMode: 10240 case kEventWindowToolbarSwitchMode:
9952 result = CallNextEventHandler (next_handler, event);
9953 { 10241 {
9954 static const EventParamName names[] = {kEventParamDirectObject, 10242 static const EventParamName names[] = {kEventParamDirectObject,
9955 kEventParamWindowMouseLocation, 10243 kEventParamWindowMouseLocation,
@@ -9971,23 +10259,195 @@ mac_handle_window_event (next_handler, event, data)
9971 event, num_params, 10259 event, num_params,
9972 names, types); 10260 names, types);
9973 } 10261 }
9974 return err == noErr ? noErr : result; 10262 if (err == noErr)
10263 result = noErr;
10264 break;
9975#endif 10265#endif
9976 10266
9977#if USE_MAC_TSM 10267#if USE_MAC_TSM
10268 /* -- window focus events -- */
10269
9978 case kEventWindowFocusAcquired: 10270 case kEventWindowFocusAcquired:
9979 result = CallNextEventHandler (next_handler, event);
9980 err = mac_tsm_resume (); 10271 err = mac_tsm_resume ();
9981 return err == noErr ? noErr : result; 10272 if (err == noErr)
10273 result = noErr;
10274 break;
9982 10275
9983 case kEventWindowFocusRelinquish: 10276 case kEventWindowFocusRelinquish:
9984 result = CallNextEventHandler (next_handler, event);
9985 err = mac_tsm_suspend (); 10277 err = mac_tsm_suspend ();
9986 return err == noErr ? noErr : result; 10278 if (err == noErr)
10279 result = noErr;
10280 break;
9987#endif 10281#endif
10282
10283 default:
10284 abort ();
9988 } 10285 }
9989 10286
9990 return eventNotHandledErr; 10287 return result;
10288}
10289
10290static pascal OSStatus
10291mac_handle_application_event (next_handler, event, data)
10292 EventHandlerCallRef next_handler;
10293 EventRef event;
10294 void *data;
10295{
10296 OSStatus err, result = eventNotHandledErr;
10297
10298 switch (GetEventKind (event))
10299 {
10300#if USE_MAC_TSM
10301 case kEventAppActivated:
10302 err = mac_tsm_resume ();
10303 break;
10304
10305 case kEventAppDeactivated:
10306 err = mac_tsm_suspend ();
10307 break;
10308#endif
10309
10310 default:
10311 abort ();
10312 }
10313
10314 if (err == noErr)
10315 result = noErr;
10316
10317 return result;
10318}
10319
10320static pascal OSStatus
10321mac_handle_keyboard_event (next_handler, event, data)
10322 EventHandlerCallRef next_handler;
10323 EventRef event;
10324 void *data;
10325{
10326 OSStatus err, result = eventNotHandledErr;
10327 UInt32 event_kind, key_code, modifiers, mapped_modifiers;
10328 unsigned char char_code;
10329
10330 event_kind = GetEventKind (event);
10331 switch (event_kind)
10332 {
10333 case kEventRawKeyDown:
10334 case kEventRawKeyRepeat:
10335 case kEventRawKeyUp:
10336 if (read_socket_inev == NULL)
10337 {
10338 result = CallNextEventHandler (next_handler, event);
10339 break;
10340 }
10341
10342 err = GetEventParameter (event, kEventParamKeyModifiers,
10343 typeUInt32, NULL,
10344 sizeof (UInt32), NULL, &modifiers);
10345 if (err != noErr)
10346 break;
10347
10348 mapped_modifiers = mac_mapped_modifiers (modifiers);
10349
10350 /* When using Carbon Events, we need to pass raw keyboard events
10351 to the TSM ourselves. If TSM handles it, it will pass back
10352 noErr, otherwise it will pass back "eventNotHandledErr" and
10353 we can process it normally. */
10354 if (!(mapped_modifiers
10355 & ~(mac_pass_command_to_system ? cmdKey : 0)
10356 & ~(mac_pass_control_to_system ? controlKey : 0)))
10357 {
10358 result = CallNextEventHandler (next_handler, event);
10359 if (result != eventNotHandledErr)
10360 break;
10361 }
10362
10363#if USE_MAC_TSM
10364 if (read_socket_inev->kind != NO_EVENT)
10365 {
10366 result = noErr;
10367 break;
10368 }
10369#endif
10370
10371 if (event_kind == kEventRawKeyUp)
10372 break;
10373
10374 err = GetEventParameter (event, kEventParamKeyMacCharCodes,
10375 typeChar, NULL,
10376 sizeof (char), NULL, &char_code);
10377 if (err != noErr)
10378 break;
10379
10380 err = GetEventParameter (event, kEventParamKeyCode,
10381 typeUInt32, NULL,
10382 sizeof (UInt32), NULL, &key_code);
10383 if (err != noErr)
10384 break;
10385
10386 do_keystroke ((GetEventKind (event) == kEventRawKeyDown
10387 ? keyDown : autoKey),
10388 char_code, key_code, modifiers,
10389 ((unsigned long)
10390 (GetEventTime (event) / kEventDurationMillisecond)),
10391 read_socket_inev);
10392 result = noErr;
10393 break;
10394
10395 default:
10396 abort ();
10397 }
10398
10399 return result;
10400}
10401
10402static pascal OSStatus
10403mac_handle_command_event (next_handler, event, data)
10404 EventHandlerCallRef next_handler;
10405 EventRef event;
10406 void *data;
10407{
10408 OSStatus err, result = eventNotHandledErr;
10409 HICommand command;
10410 static const EventParamName names[] =
10411 {kEventParamDirectObject, kEventParamKeyModifiers};
10412 static const EventParamType types[] =
10413 {typeHICommand, typeUInt32};
10414 int num_params = sizeof (names) / sizeof (names[0]);
10415
10416 err = GetEventParameter (event, kEventParamDirectObject, typeHICommand,
10417 NULL, sizeof (HICommand), NULL, &command);
10418 if (err != noErr)
10419 return eventNotHandledErr;
10420
10421 switch (GetEventKind (event))
10422 {
10423 case kEventCommandProcess:
10424 result = CallNextEventHandler (next_handler, event);
10425 if (result != eventNotHandledErr)
10426 break;
10427
10428 err = GetEventParameter (event, kEventParamDirectObject,
10429 typeHICommand, NULL,
10430 sizeof (HICommand), NULL, &command);
10431
10432 if (err != noErr || command.commandID == 0)
10433 break;
10434
10435 /* A HI command event is mapped to an Apple event whose event
10436 class symbol is `hi-command' and event ID is its command
10437 ID. */
10438 err = mac_store_event_ref_as_apple_event (0, command.commandID,
10439 Qhi_command, Qnil,
10440 event, num_params,
10441 names, types);
10442 if (err == noErr)
10443 result = noErr;
10444 break;
10445
10446 default:
10447 abort ();
10448 }
10449
10450 return result;
9991} 10451}
9992 10452
9993static pascal OSStatus 10453static pascal OSStatus
@@ -9996,13 +10456,13 @@ mac_handle_mouse_event (next_handler, event, data)
9996 EventRef event; 10456 EventRef event;
9997 void *data; 10457 void *data;
9998{ 10458{
9999 OSStatus result, err; 10459 OSStatus err, result = eventNotHandledErr;
10000 10460
10001 switch (GetEventKind (event)) 10461 switch (GetEventKind (event))
10002 { 10462 {
10003 case kEventMouseWheelMoved: 10463 case kEventMouseWheelMoved:
10004 { 10464 {
10005 WindowPtr wp; 10465 WindowRef wp;
10006 struct frame *f; 10466 struct frame *f;
10007 EventMouseWheelAxis axis; 10467 EventMouseWheelAxis axis;
10008 SInt32 delta; 10468 SInt32 delta;
@@ -10010,15 +10470,14 @@ mac_handle_mouse_event (next_handler, event, data)
10010 10470
10011 result = CallNextEventHandler (next_handler, event); 10471 result = CallNextEventHandler (next_handler, event);
10012 if (result != eventNotHandledErr || read_socket_inev == NULL) 10472 if (result != eventNotHandledErr || read_socket_inev == NULL)
10013 return result; 10473 break;
10474
10475 f = mac_focus_frame (&one_mac_display_info);
10014 10476
10015 err = GetEventParameter (event, kEventParamWindowRef, typeWindowRef, 10477 err = GetEventParameter (event, kEventParamWindowRef, typeWindowRef,
10016 NULL, sizeof (WindowRef), NULL, &wp); 10478 NULL, sizeof (WindowRef), NULL, &wp);
10017 if (err != noErr) 10479 if (err != noErr
10018 break; 10480 || wp != FRAME_MAC_WINDOW (f))
10019
10020 f = mac_window_to_frame (wp);
10021 if (f != mac_focus_frame (&one_mac_display_info))
10022 break; 10481 break;
10023 10482
10024 err = GetEventParameter (event, kEventParamMouseWheelAxis, 10483 err = GetEventParameter (event, kEventParamMouseWheelAxis,
@@ -10033,8 +10492,8 @@ mac_handle_mouse_event (next_handler, event, data)
10033 if (err != noErr) 10492 if (err != noErr)
10034 break; 10493 break;
10035 10494
10036 SetPortWindowPort (wp); 10495 point.h -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f);
10037 GlobalToLocal (&point); 10496 point.v -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f);
10038 if (point.h < 0 || point.v < 0 10497 if (point.h < 0 || point.v < 0
10039 || EQ (window_from_coordinates (f, point.h, point.v, 0, 0, 0, 1), 10498 || EQ (window_from_coordinates (f, point.h, point.v, 0, 0, 0, 1),
10040 f->tool_bar_window)) 10499 f->tool_bar_window))
@@ -10055,68 +10514,16 @@ mac_handle_mouse_event (next_handler, event, data)
10055 XSETINT (read_socket_inev->y, point.v); 10514 XSETINT (read_socket_inev->y, point.v);
10056 XSETFRAME (read_socket_inev->frame_or_window, f); 10515 XSETFRAME (read_socket_inev->frame_or_window, f);
10057 10516
10058 return noErr; 10517 result = noErr;
10059 } 10518 }
10060 break; 10519 break;
10061 10520
10062 default: 10521 default:
10063 break; 10522 abort ();
10064 }
10065
10066 return eventNotHandledErr;
10067}
10068
10069#if USE_MAC_FONT_PANEL
10070static pascal OSStatus
10071mac_handle_font_event (next_handler, event, data)
10072 EventHandlerCallRef next_handler;
10073 EventRef event;
10074 void *data;
10075{
10076 OSStatus result, err;
10077 Lisp_Object id_key;
10078 int num_params;
10079 const EventParamName *names;
10080 const EventParamType *types;
10081 static const EventParamName names_sel[] = {kEventParamATSUFontID,
10082 kEventParamATSUFontSize,
10083 kEventParamFMFontFamily,
10084 kEventParamFMFontSize,
10085 kEventParamFontColor};
10086 static const EventParamType types_sel[] = {typeATSUFontID,
10087 typeATSUSize,
10088 typeFMFontFamily,
10089 typeFMFontSize,
10090 typeFontColor};
10091
10092 result = CallNextEventHandler (next_handler, event);
10093 if (result != eventNotHandledErr)
10094 return result;
10095
10096 switch (GetEventKind (event))
10097 {
10098 case kEventFontPanelClosed:
10099 id_key = Qpanel_closed;
10100 num_params = 0;
10101 names = NULL;
10102 types = NULL;
10103 break;
10104
10105 case kEventFontSelection:
10106 id_key = Qselection;
10107 num_params = sizeof (names_sel) / sizeof (names_sel[0]);
10108 names = names_sel;
10109 types = types_sel;
10110 break;
10111 } 10523 }
10112 10524
10113 err = mac_store_event_ref_as_apple_event (0, 0, Qfont, id_key, 10525 return result;
10114 event, num_params,
10115 names, types);
10116
10117 return err == noErr ? noErr : eventNotHandledErr;
10118} 10526}
10119#endif
10120 10527
10121#if USE_MAC_TSM 10528#if USE_MAC_TSM
10122static pascal OSStatus 10529static pascal OSStatus
@@ -10173,6 +10580,8 @@ mac_handle_text_input_event (next_handler, event, data)
10173 typeUnicodeText}; 10580 typeUnicodeText};
10174 10581
10175 result = CallNextEventHandler (next_handler, event); 10582 result = CallNextEventHandler (next_handler, event);
10583 if (result != eventNotHandledErr)
10584 return result;
10176 10585
10177 switch (GetEventKind (event)) 10586 switch (GetEventKind (event))
10178 { 10587 {
@@ -10200,7 +10609,7 @@ mac_handle_text_input_event (next_handler, event, data)
10200 sizeof (UInt32), NULL, &modifiers); 10609 sizeof (UInt32), NULL, &modifiers);
10201 if (err == noErr && mac_mapped_modifiers (modifiers)) 10610 if (err == noErr && mac_mapped_modifiers (modifiers))
10202 /* There're mapped modifier keys. Process it in 10611 /* There're mapped modifier keys. Process it in
10203 XTread_socket. */ 10612 do_keystroke. */
10204 return eventNotHandledErr; 10613 return eventNotHandledErr;
10205 if (err == noErr) 10614 if (err == noErr)
10206 err = GetEventParameter (kbd_event, kEventParamKeyUnicodes, 10615 err = GetEventParameter (kbd_event, kEventParamKeyUnicodes,
@@ -10215,7 +10624,7 @@ mac_handle_text_input_event (next_handler, event, data)
10215 sizeof (UniChar), NULL, &code); 10624 sizeof (UniChar), NULL, &code);
10216 if (err == noErr && code < 0x80) 10625 if (err == noErr && code < 0x80)
10217 { 10626 {
10218 /* ASCII character. Process it in XTread_socket. */ 10627 /* ASCII character. Process it in do_keystroke. */
10219 if (read_socket_inev && code >= 0x20 && code <= 0x7e) 10628 if (read_socket_inev && code >= 0x20 && code <= 0x7e)
10220 { 10629 {
10221 UInt32 key_code; 10630 UInt32 key_code;
@@ -10277,11 +10686,11 @@ mac_handle_text_input_event (next_handler, event, data)
10277 } 10686 }
10278 10687
10279 p.h = (WINDOW_TO_FRAME_PIXEL_X (w, w->cursor.x) 10688 p.h = (WINDOW_TO_FRAME_PIXEL_X (w, w->cursor.x)
10280 + WINDOW_LEFT_FRINGE_WIDTH (w)); 10689 + WINDOW_LEFT_FRINGE_WIDTH (w)
10690 + f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f));
10281 p.v = (WINDOW_TO_FRAME_PIXEL_Y (w, w->cursor.y) 10691 p.v = (WINDOW_TO_FRAME_PIXEL_Y (w, w->cursor.y)
10282 + FONT_BASE (FRAME_FONT (f))); 10692 + FONT_BASE (FRAME_FONT (f))
10283 SetPortWindowPort (FRAME_MAC_WINDOW (f)); 10693 + f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f));
10284 LocalToGlobal (&p);
10285 err = SetEventParameter (event, kEventParamTextInputReplyPoint, 10694 err = SetEventParameter (event, kEventParamTextInputReplyPoint,
10286 typeQDPoint, sizeof (typeQDPoint), &p); 10695 typeQDPoint, sizeof (typeQDPoint), &p);
10287 } 10696 }
@@ -10295,146 +10704,155 @@ mac_handle_text_input_event (next_handler, event, data)
10295 err = mac_store_event_ref_as_apple_event (0, 0, Qtext_input, id_key, 10704 err = mac_store_event_ref_as_apple_event (0, 0, Qtext_input, id_key,
10296 event, num_params, 10705 event, num_params,
10297 names, types); 10706 names, types);
10707 if (err == noErr)
10708 result = noErr;
10298 10709
10299 return err == noErr ? noErr : result; 10710 return result;
10300} 10711}
10301#endif 10712#endif
10713#endif /* TARGET_API_MAC_CARBON */
10714
10302 10715
10303#ifdef MAC_OSX
10304OSStatus 10716OSStatus
10305mac_store_service_event (event) 10717install_window_handler (window)
10306 EventRef event; 10718 WindowRef window;
10307{ 10719{
10308 OSStatus err; 10720 OSStatus err = noErr;
10309 Lisp_Object id_key;
10310 int num_params;
10311 const EventParamName *names;
10312 const EventParamType *types;
10313 static const EventParamName names_pfm[] =
10314 {kEventParamServiceMessageName, kEventParamServiceUserData};
10315 static const EventParamType types_pfm[] =
10316 {typeCFStringRef, typeCFStringRef};
10317 10721
10318 switch (GetEventKind (event)) 10722#if TARGET_API_MAC_CARBON
10723 if (err == noErr)
10319 { 10724 {
10320 case kEventServicePaste: 10725 static const EventTypeSpec specs[] =
10321 id_key = Qpaste; 10726 {
10322 num_params = 0; 10727 /* -- window refresh events -- */
10323 names = NULL; 10728 {kEventClassWindow, kEventWindowUpdate},
10324 types = NULL; 10729 /* -- window state change events -- */
10325 break; 10730 {kEventClassWindow, kEventWindowShowing},
10731 {kEventClassWindow, kEventWindowHiding},
10732 {kEventClassWindow, kEventWindowShown},
10733 {kEventClassWindow, kEventWindowHidden},
10734 {kEventClassWindow, kEventWindowCollapsed},
10735 {kEventClassWindow, kEventWindowExpanded},
10736 {kEventClassWindow, kEventWindowBoundsChanging},
10737 {kEventClassWindow, kEventWindowBoundsChanged},
10738 /* -- window action events -- */
10739 {kEventClassWindow, kEventWindowClose},
10740 {kEventClassWindow, kEventWindowGetIdealSize},
10741#ifdef MAC_OSX
10742 {kEventClassWindow, kEventWindowToolbarSwitchMode},
10743#endif
10744#if USE_MAC_TSM
10745 /* -- window focus events -- */
10746 {kEventClassWindow, kEventWindowFocusAcquired},
10747 {kEventClassWindow, kEventWindowFocusRelinquish},
10748#endif
10749 };
10750 static EventHandlerUPP handle_window_eventUPP = NULL;
10326 10751
10327 case kEventServicePerform: 10752 if (handle_window_eventUPP == NULL)
10328 id_key = Qperform; 10753 handle_window_eventUPP = NewEventHandlerUPP (mac_handle_window_event);
10329 num_params = sizeof (names_pfm) / sizeof (names_pfm[0]);
10330 names = names_pfm;
10331 types = types_pfm;
10332 break;
10333 10754
10334 default: 10755 err = InstallWindowEventHandler (window, handle_window_eventUPP,
10335 abort (); 10756 GetEventTypeCount (specs),
10757 specs, NULL, NULL);
10336 } 10758 }
10759#endif
10337 10760
10338 err = mac_store_event_ref_as_apple_event (0, 0, Qservice, id_key, 10761 if (err == noErr)
10339 event, num_params, 10762 err = install_drag_handler (window);
10340 names, types);
10341 10763
10342 return err; 10764 return err;
10343} 10765}
10344#endif /* MAC_OSX */
10345#endif /* USE_CARBON_EVENTS */
10346 10766
10767void
10768remove_window_handler (window)
10769 WindowRef window;
10770{
10771 remove_drag_handler (window);
10772}
10347 10773
10348OSStatus 10774#if TARGET_API_MAC_CARBON
10349install_window_handler (window) 10775static OSStatus
10350 WindowPtr window; 10776install_application_handler ()
10351{ 10777{
10352 OSStatus err = noErr; 10778 OSStatus err = noErr;
10353#if USE_CARBON_EVENTS
10354 static const EventTypeSpec specs_window[] =
10355 {{kEventClassWindow, kEventWindowUpdate},
10356 {kEventClassWindow, kEventWindowGetIdealSize},
10357 {kEventClassWindow, kEventWindowBoundsChanging},
10358 {kEventClassWindow, kEventWindowBoundsChanged},
10359 {kEventClassWindow, kEventWindowShown},
10360 {kEventClassWindow, kEventWindowHidden},
10361 {kEventClassWindow, kEventWindowExpanded},
10362 {kEventClassWindow, kEventWindowCollapsed},
10363 {kEventClassWindow, kEventWindowClose},
10364#ifdef MAC_OSX
10365 {kEventClassWindow, kEventWindowToolbarSwitchMode},
10366#endif
10367#if USE_MAC_TSM
10368 {kEventClassWindow, kEventWindowFocusAcquired},
10369 {kEventClassWindow, kEventWindowFocusRelinquish},
10370#endif
10371 };
10372 static const EventTypeSpec specs_mouse[] =
10373 {{kEventClassMouse, kEventMouseWheelMoved}};
10374 static EventHandlerUPP handle_window_eventUPP = NULL;
10375 static EventHandlerUPP handle_mouse_eventUPP = NULL;
10376#if USE_MAC_FONT_PANEL
10377 static const EventTypeSpec specs_font[] =
10378 {{kEventClassFont, kEventFontPanelClosed},
10379 {kEventClassFont, kEventFontSelection}};
10380 static EventHandlerUPP handle_font_eventUPP = NULL;
10381#endif
10382#if USE_MAC_TSM
10383 static const EventTypeSpec specs_text_input[] =
10384 {{kEventClassTextInput, kEventTextInputUpdateActiveInputArea},
10385 {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent},
10386 {kEventClassTextInput, kEventTextInputOffsetToPos}};
10387 static EventHandlerUPP handle_text_input_eventUPP = NULL;
10388#endif
10389 10779
10390 if (handle_window_eventUPP == NULL) 10780 if (err == noErr)
10391 handle_window_eventUPP = NewEventHandlerUPP (mac_handle_window_event); 10781 {
10392 if (handle_mouse_eventUPP == NULL) 10782 static const EventTypeSpec specs[] = {
10393 handle_mouse_eventUPP = NewEventHandlerUPP (mac_handle_mouse_event);
10394#if USE_MAC_FONT_PANEL
10395 if (handle_font_eventUPP == NULL)
10396 handle_font_eventUPP = NewEventHandlerUPP (mac_handle_font_event);
10397#endif
10398#if USE_MAC_TSM 10783#if USE_MAC_TSM
10399 if (handle_text_input_eventUPP == NULL) 10784 {kEventClassApplication, kEventAppActivated},
10400 handle_text_input_eventUPP = 10785 {kEventClassApplication, kEventAppDeactivated},
10401 NewEventHandlerUPP (mac_handle_text_input_event);
10402#endif 10786#endif
10403 err = InstallWindowEventHandler (window, handle_window_eventUPP, 10787 };
10404 GetEventTypeCount (specs_window), 10788
10405 specs_window, NULL, NULL); 10789 err = InstallApplicationEventHandler (NewEventHandlerUPP
10790 (mac_handle_application_event),
10791 GetEventTypeCount (specs),
10792 specs, NULL, NULL);
10793 }
10794
10406 if (err == noErr) 10795 if (err == noErr)
10407 err = InstallWindowEventHandler (window, handle_mouse_eventUPP, 10796 {
10408 GetEventTypeCount (specs_mouse), 10797 static const EventTypeSpec specs[] =
10409 specs_mouse, NULL, NULL); 10798 {{kEventClassKeyboard, kEventRawKeyDown},
10410#if USE_MAC_FONT_PANEL 10799 {kEventClassKeyboard, kEventRawKeyRepeat},
10800 {kEventClassKeyboard, kEventRawKeyUp}};
10801
10802 err = InstallApplicationEventHandler (NewEventHandlerUPP
10803 (mac_handle_keyboard_event),
10804 GetEventTypeCount (specs),
10805 specs, NULL, NULL);
10806 }
10807
10411 if (err == noErr) 10808 if (err == noErr)
10412 err = InstallWindowEventHandler (window, handle_font_eventUPP, 10809 {
10413 GetEventTypeCount (specs_font), 10810 static const EventTypeSpec specs[] =
10414 specs_font, NULL, NULL); 10811 {{kEventClassCommand, kEventCommandProcess}};
10415#endif 10812
10813 err = InstallApplicationEventHandler (NewEventHandlerUPP
10814 (mac_handle_command_event),
10815 GetEventTypeCount (specs),
10816 specs, NULL, NULL);
10817 }
10818
10819 if (err == noErr)
10820 {
10821 static const EventTypeSpec specs[] =
10822 {{kEventClassMouse, kEventMouseWheelMoved}};
10823
10824 err = InstallApplicationEventHandler (NewEventHandlerUPP
10825 (mac_handle_mouse_event),
10826 GetEventTypeCount (specs),
10827 specs, NULL, NULL);
10828 }
10829
10416#if USE_MAC_TSM 10830#if USE_MAC_TSM
10417 if (err == noErr) 10831 if (err == noErr)
10418 err = InstallWindowEventHandler (window, handle_text_input_eventUPP, 10832 {
10419 GetEventTypeCount (specs_text_input), 10833 static const EventTypeSpec spec[] =
10420 specs_text_input, window, NULL); 10834 {{kEventClassTextInput, kEventTextInputUpdateActiveInputArea},
10421#endif 10835 {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent},
10836 {kEventClassTextInput, kEventTextInputOffsetToPos}};
10837
10838 err = InstallApplicationEventHandler (NewEventHandlerUPP
10839 (mac_handle_text_input_event),
10840 GetEventTypeCount (spec),
10841 spec, NULL, NULL);
10842 }
10422#endif 10843#endif
10844
10423 if (err == noErr) 10845 if (err == noErr)
10424 err = install_drag_handler (window); 10846 err = install_menu_target_item_handler ();
10847
10848#ifdef MAC_OSX
10425 if (err == noErr) 10849 if (err == noErr)
10426 err = install_menu_target_item_handler (window); 10850 err = install_service_handler ();
10851#endif
10427 10852
10428 return err; 10853 return err;
10429} 10854}
10430 10855#endif
10431void
10432remove_window_handler (window)
10433 WindowPtr window;
10434{
10435 remove_drag_handler (window);
10436}
10437
10438 10856
10439static pascal void 10857static pascal void
10440mac_handle_dm_notification (event) 10858mac_handle_dm_notification (event)
@@ -10443,20 +10861,48 @@ mac_handle_dm_notification (event)
10443 mac_screen_config_changed = 1; 10861 mac_screen_config_changed = 1;
10444} 10862}
10445 10863
10864#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
10865static void
10866mac_handle_cg_display_reconfig (display, flags, user_info)
10867 CGDirectDisplayID display;
10868 CGDisplayChangeSummaryFlags flags;
10869 void *user_info;
10870{
10871 mac_screen_config_changed = 1;
10872}
10873#endif
10874
10446static OSErr 10875static OSErr
10447init_dm_notification_handler () 10876init_dm_notification_handler ()
10448{ 10877{
10449 OSErr err; 10878 OSErr err = noErr;
10450 static DMNotificationUPP handle_dm_notificationUPP = NULL;
10451 ProcessSerialNumber psn;
10452 10879
10453 if (handle_dm_notificationUPP == NULL) 10880#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
10454 handle_dm_notificationUPP = 10881#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
10455 NewDMNotificationUPP (mac_handle_dm_notification); 10882 if (CGDisplayRegisterReconfigurationCallback != NULL)
10883#endif
10884 {
10885 CGDisplayRegisterReconfigurationCallback (mac_handle_cg_display_reconfig,
10886 NULL);
10887 }
10888#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
10889 else /* CGDisplayRegisterReconfigurationCallback == NULL */
10890#endif
10891#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */
10892#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020
10893 {
10894 static DMNotificationUPP handle_dm_notificationUPP = NULL;
10895 ProcessSerialNumber psn;
10456 10896
10457 err = GetCurrentProcess (&psn); 10897 if (handle_dm_notificationUPP == NULL)
10458 if (err == noErr) 10898 handle_dm_notificationUPP =
10459 err = DMRegisterNotifyProc (handle_dm_notificationUPP, &psn); 10899 NewDMNotificationUPP (mac_handle_dm_notification);
10900
10901 err = GetCurrentProcess (&psn);
10902 if (err == noErr)
10903 err = DMRegisterNotifyProc (handle_dm_notificationUPP, &psn);
10904 }
10905#endif
10460 10906
10461 return err; 10907 return err;
10462} 10908}
@@ -10601,7 +11047,7 @@ main (void)
10601} 11047}
10602#endif 11048#endif
10603 11049
10604#if !USE_CARBON_EVENTS 11050#if !TARGET_API_MAC_CARBON
10605static RgnHandle mouse_region = NULL; 11051static RgnHandle mouse_region = NULL;
10606 11052
10607Boolean 11053Boolean
@@ -10638,7 +11084,7 @@ mac_wait_next_event (er, sleep_time, dequeue)
10638 er_buf.what = nullEvent; 11084 er_buf.what = nullEvent;
10639 return true; 11085 return true;
10640} 11086}
10641#endif /* not USE_CARBON_EVENTS */ 11087#endif /* not TARGET_API_MAC_CARBON */
10642 11088
10643#if TARGET_API_MAC_CARBON 11089#if TARGET_API_MAC_CARBON
10644OSStatus 11090OSStatus
@@ -10672,20 +11118,6 @@ mac_post_mouse_moved_event ()
10672 11118
10673 return err; 11119 return err;
10674} 11120}
10675
10676static void
10677mac_set_unicode_keystroke_event (code, buf)
10678 UniChar code;
10679 struct input_event *buf;
10680{
10681 int charset_id, c1, c2;
10682
10683 if (code < 0x80)
10684 buf->kind = ASCII_KEYSTROKE_EVENT;
10685 else
10686 buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT;
10687 buf->code = code;
10688}
10689#endif 11121#endif
10690 11122
10691/* Emacs calls this whenever it wants to read an input event from the 11123/* Emacs calls this whenever it wants to read an input event from the
@@ -10697,7 +11129,7 @@ XTread_socket (sd, expected, hold_quit)
10697{ 11129{
10698 struct input_event inev; 11130 struct input_event inev;
10699 int count = 0; 11131 int count = 0;
10700#if USE_CARBON_EVENTS 11132#if TARGET_API_MAC_CARBON
10701 EventRef eventRef; 11133 EventRef eventRef;
10702 EventTargetRef toolbox_dispatcher; 11134 EventTargetRef toolbox_dispatcher;
10703#endif 11135#endif
@@ -10718,7 +11150,7 @@ XTread_socket (sd, expected, hold_quit)
10718 11150
10719 ++handling_signal; 11151 ++handling_signal;
10720 11152
10721#if USE_CARBON_EVENTS 11153#if TARGET_API_MAC_CARBON
10722 toolbox_dispatcher = GetEventDispatcherTarget (); 11154 toolbox_dispatcher = GetEventDispatcherTarget ();
10723 11155
10724 while ( 11156 while (
@@ -10727,9 +11159,9 @@ XTread_socket (sd, expected, hold_quit)
10727#endif 11159#endif
10728 !ReceiveNextEvent (0, NULL, kEventDurationNoWait, 11160 !ReceiveNextEvent (0, NULL, kEventDurationNoWait,
10729 kEventRemoveFromQueue, &eventRef)) 11161 kEventRemoveFromQueue, &eventRef))
10730#else /* !USE_CARBON_EVENTS */ 11162#else /* !TARGET_API_MAC_CARBON */
10731 while (mac_wait_next_event (&er, 0, true)) 11163 while (mac_wait_next_event (&er, 0, true))
10732#endif /* !USE_CARBON_EVENTS */ 11164#endif /* !TARGET_API_MAC_CARBON */
10733 { 11165 {
10734 int do_help = 0; 11166 int do_help = 0;
10735 struct frame *f; 11167 struct frame *f;
@@ -10739,44 +11171,33 @@ XTread_socket (sd, expected, hold_quit)
10739 inev.kind = NO_EVENT; 11171 inev.kind = NO_EVENT;
10740 inev.arg = Qnil; 11172 inev.arg = Qnil;
10741 11173
10742#if USE_CARBON_EVENTS 11174#if TARGET_API_MAC_CARBON
10743 timestamp = GetEventTime (eventRef) / kEventDurationMillisecond; 11175 timestamp = GetEventTime (eventRef) / kEventDurationMillisecond;
10744#else
10745 timestamp = er.when * (1000 / 60); /* ticks to milliseconds */
10746#endif
10747 11176
10748#if USE_CARBON_EVENTS
10749 /* Handle new events */
10750 if (!mac_convert_event_ref (eventRef, &er)) 11177 if (!mac_convert_event_ref (eventRef, &er))
10751 { 11178 goto OTHER;
10752 /* There used to be a handler for the kEventMouseWheelMoved 11179#else /* !TARGET_API_MAC_CARBON */
10753 event here. But as of Mac OS X 10.4, this kind of event 11180 timestamp = er.when * (1000 / 60); /* ticks to milliseconds */
10754 is not directly posted to the main event queue by 11181#endif /* !TARGET_API_MAC_CARBON */
10755 two-finger scrolling on the trackpad. Instead, some 11182
10756 private event is posted and it is converted to a wheel
10757 event by the default handler for the application target.
10758 The converted one can be received by a Carbon event
10759 handler installed on a window target. */
10760 read_socket_inev = &inev;
10761 SendEventToEventTarget (eventRef, toolbox_dispatcher);
10762 read_socket_inev = NULL;
10763 }
10764 else
10765#endif /* USE_CARBON_EVENTS */
10766 switch (er.what) 11183 switch (er.what)
10767 { 11184 {
10768 case mouseDown: 11185 case mouseDown:
10769 case mouseUp: 11186 case mouseUp:
10770 { 11187 {
10771 WindowPtr window_ptr; 11188 WindowRef window_ptr;
10772 ControlPartCode part_code; 11189 ControlPartCode part_code;
10773 int tool_bar_p = 0; 11190 int tool_bar_p = 0;
10774 11191
10775#if USE_CARBON_EVENTS 11192#if TARGET_API_MAC_CARBON
11193 OSStatus err;
11194
10776 /* This is needed to send mouse events like aqua window 11195 /* This is needed to send mouse events like aqua window
10777 buttons to the correct handler. */ 11196 buttons to the correct handler. */
10778 if (SendEventToEventTarget (eventRef, toolbox_dispatcher) 11197 read_socket_inev = &inev;
10779 != eventNotHandledErr) 11198 err = SendEventToEventTarget (eventRef, toolbox_dispatcher);
11199 read_socket_inev = NULL;
11200 if (err != eventNotHandledErr)
10780 break; 11201 break;
10781#endif 11202#endif
10782 last_mouse_glyph_frame = 0; 11203 last_mouse_glyph_frame = 0;
@@ -10824,17 +11245,20 @@ XTread_socket (sd, expected, hold_quit)
10824 else 11245 else
10825 { 11246 {
10826 ControlPartCode control_part_code; 11247 ControlPartCode control_part_code;
10827 ControlHandle ch; 11248 ControlRef ch;
10828 Point mouse_loc = er.where; 11249 Point mouse_loc;
10829#ifdef MAC_OSX 11250#ifdef MAC_OSX
10830 ControlKind control_kind; 11251 ControlKind control_kind;
10831#endif 11252#endif
10832 11253
10833 f = mac_window_to_frame (window_ptr); 11254 f = mac_window_to_frame (window_ptr);
10834 /* convert to local coordinates of new window */ 11255 /* convert to local coordinates of new window */
10835 SetPortWindowPort (window_ptr); 11256 mouse_loc.h = (er.where.h
10836 11257 - (f->left_pos
10837 GlobalToLocal (&mouse_loc); 11258 + FRAME_OUTER_TO_INNER_DIFF_X (f)));
11259 mouse_loc.v = (er.where.v
11260 - (f->top_pos
11261 + FRAME_OUTER_TO_INNER_DIFF_Y (f)));
10838#if TARGET_API_MAC_CARBON 11262#if TARGET_API_MAC_CARBON
10839 ch = FindControlUnderMouse (mouse_loc, window_ptr, 11263 ch = FindControlUnderMouse (mouse_loc, window_ptr,
10840 &control_part_code); 11264 &control_part_code);
@@ -10847,7 +11271,7 @@ XTread_socket (sd, expected, hold_quit)
10847 &ch); 11271 &ch);
10848#endif 11272#endif
10849 11273
10850#if USE_CARBON_EVENTS 11274#if TARGET_API_MAC_CARBON
10851 inev.code = mac_get_mouse_btn (eventRef); 11275 inev.code = mac_get_mouse_btn (eventRef);
10852 inev.modifiers = mac_event_to_emacs_modifiers (eventRef); 11276 inev.modifiers = mac_event_to_emacs_modifiers (eventRef);
10853#else 11277#else
@@ -10983,16 +11407,14 @@ XTread_socket (sd, expected, hold_quit)
10983 DragWindow (window_ptr, er.where, NULL); 11407 DragWindow (window_ptr, er.where, NULL);
10984#else /* not TARGET_API_MAC_CARBON */ 11408#else /* not TARGET_API_MAC_CARBON */
10985 DragWindow (window_ptr, er.where, &qd.screenBits.bounds); 11409 DragWindow (window_ptr, er.where, &qd.screenBits.bounds);
10986#endif /* not TARGET_API_MAC_CARBON */
10987 /* Update the frame parameters. */ 11410 /* Update the frame parameters. */
10988#if !USE_CARBON_EVENTS
10989 { 11411 {
10990 struct frame *f = mac_window_to_frame (window_ptr); 11412 struct frame *f = mac_window_to_frame (window_ptr);
10991 11413
10992 if (f && !f->async_iconified) 11414 if (f && !f->async_iconified)
10993 mac_handle_origin_change (f); 11415 mac_handle_origin_change (f);
10994 } 11416 }
10995#endif 11417#endif /* not TARGET_API_MAC_CARBON */
10996 break; 11418 break;
10997 11419
10998 case inGoAway: 11420 case inGoAway:
@@ -11022,35 +11444,17 @@ XTread_socket (sd, expected, hold_quit)
11022 } 11444 }
11023 break; 11445 break;
11024 11446
11447#if !TARGET_API_MAC_CARBON
11025 case updateEvt: 11448 case updateEvt:
11026#if USE_CARBON_EVENTS 11449 do_window_update ((WindowRef) er.message);
11027 if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
11028 != eventNotHandledErr)
11029 break;
11030#else
11031 do_window_update ((WindowPtr) er.message);
11032#endif
11033 break; 11450 break;
11451#endif
11034 11452
11035 case osEvt: 11453 case osEvt:
11036#if USE_CARBON_EVENTS
11037 if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
11038 != eventNotHandledErr)
11039 break;
11040#endif
11041 switch ((er.message >> 24) & 0x000000FF) 11454 switch ((er.message >> 24) & 0x000000FF)
11042 { 11455 {
11043 case suspendResumeMessage:
11044#if USE_MAC_TSM
11045 if (er.message & resumeFlag)
11046 mac_tsm_resume ();
11047 else
11048 mac_tsm_suspend ();
11049#endif
11050 break;
11051
11052 case mouseMovedMessage: 11456 case mouseMovedMessage:
11053#if !USE_CARBON_EVENTS 11457#if !TARGET_API_MAC_CARBON
11054 SetRectRgn (mouse_region, er.where.h, er.where.v, 11458 SetRectRgn (mouse_region, er.where.h, er.where.v,
11055 er.where.h + 1, er.where.v + 1); 11459 er.where.h + 1, er.where.v + 1);
11056#endif 11460#endif
@@ -11071,13 +11475,15 @@ XTread_socket (sd, expected, hold_quit)
11071 11475
11072 if (f) 11476 if (f)
11073 { 11477 {
11074 WindowPtr wp = FRAME_MAC_WINDOW (f); 11478 WindowRef wp = FRAME_MAC_WINDOW (f);
11075 Point mouse_pos = er.where; 11479 Point mouse_pos;
11076 11480
11077 SetPortWindowPort (wp); 11481 mouse_pos.h = (er.where.h
11078 11482 - (f->left_pos
11079 GlobalToLocal (&mouse_pos); 11483 + FRAME_OUTER_TO_INNER_DIFF_X (f)));
11080 11484 mouse_pos.v = (er.where.v
11485 - (f->top_pos
11486 + FRAME_OUTER_TO_INNER_DIFF_Y (f)));
11081 if (dpyinfo->grabbed && tracked_scroll_bar) 11487 if (dpyinfo->grabbed && tracked_scroll_bar)
11082#ifdef USE_TOOLKIT_SCROLL_BARS 11488#ifdef USE_TOOLKIT_SCROLL_BARS
11083 x_scroll_bar_handle_drag (wp, tracked_scroll_bar, 11489 x_scroll_bar_handle_drag (wp, tracked_scroll_bar,
@@ -11125,18 +11531,16 @@ XTread_socket (sd, expected, hold_quit)
11125 if (!NILP (help_echo_string) || !NILP (previous_help_echo_string)) 11531 if (!NILP (help_echo_string) || !NILP (previous_help_echo_string))
11126 do_help = 1; 11532 do_help = 1;
11127 break; 11533 break;
11534
11535 default:
11536 goto OTHER;
11128 } 11537 }
11129 break; 11538 break;
11130 11539
11131 case activateEvt: 11540 case activateEvt:
11132 { 11541 {
11133 WindowPtr window_ptr = (WindowPtr) er.message; 11542 WindowRef window_ptr = (WindowRef) er.message;
11134 11543
11135#if USE_CARBON_EVENTS
11136 if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
11137 != eventNotHandledErr)
11138 break;
11139#endif
11140 if (window_ptr == tip_window) 11544 if (window_ptr == tip_window)
11141 { 11545 {
11142 HideWindow (tip_window); 11546 HideWindow (tip_window);
@@ -11144,21 +11548,26 @@ XTread_socket (sd, expected, hold_quit)
11144 } 11548 }
11145 11549
11146 if (!is_emacs_window (window_ptr)) 11550 if (!is_emacs_window (window_ptr))
11147 break; 11551 goto OTHER;
11552
11553 f = mac_window_to_frame (window_ptr);
11148 11554
11149 if ((er.modifiers & activeFlag) != 0) 11555 if ((er.modifiers & activeFlag) != 0)
11150 { 11556 {
11151 /* A window has been activated */ 11557 /* A window has been activated */
11152 Point mouse_loc = er.where; 11558 Point mouse_loc;
11153 11559
11154 x_detect_focus_change (dpyinfo, &er, &inev); 11560 x_detect_focus_change (dpyinfo, &er, &inev);
11155 11561
11156 SetPortWindowPort (window_ptr); 11562 mouse_loc.h = (er.where.h
11157 GlobalToLocal (&mouse_loc); 11563 - (f->left_pos
11564 + FRAME_OUTER_TO_INNER_DIFF_X (f)));
11565 mouse_loc.v = (er.where.v
11566 - (f->top_pos
11567 + FRAME_OUTER_TO_INNER_DIFF_Y (f)));
11158 /* Window-activated event counts as mouse movement, 11568 /* Window-activated event counts as mouse movement,
11159 so update things that depend on mouse position. */ 11569 so update things that depend on mouse position. */
11160 note_mouse_movement (mac_window_to_frame (window_ptr), 11570 note_mouse_movement (f, &mouse_loc);
11161 &mouse_loc);
11162 } 11571 }
11163 else 11572 else
11164 { 11573 {
@@ -11183,7 +11592,6 @@ XTread_socket (sd, expected, hold_quit)
11183 11592
11184 x_detect_focus_change (dpyinfo, &er, &inev); 11593 x_detect_focus_change (dpyinfo, &er, &inev);
11185 11594
11186 f = mac_window_to_frame (window_ptr);
11187 if (f == dpyinfo->mouse_face_mouse_frame) 11595 if (f == dpyinfo->mouse_face_mouse_frame)
11188 { 11596 {
11189 /* If we move outside the frame, then we're 11597 /* If we move outside the frame, then we're
@@ -11206,218 +11614,26 @@ XTread_socket (sd, expected, hold_quit)
11206 case keyDown: 11614 case keyDown:
11207 case keyUp: 11615 case keyUp:
11208 case autoKey: 11616 case autoKey:
11209 { 11617 ObscureCursor ();
11210 int keycode = (er.message & keyCodeMask) >> 8;
11211 static SInt16 last_key_script = -1;
11212 SInt16 current_key_script;
11213 UInt32 modifiers = er.modifiers, mapped_modifiers;
11214
11215#if USE_CARBON_EVENTS && defined (MAC_OSX)
11216 GetEventParameter (eventRef, kEventParamKeyModifiers,
11217 typeUInt32, NULL,
11218 sizeof (UInt32), NULL, &modifiers);
11219#endif
11220 mapped_modifiers = mac_mapped_modifiers (modifiers);
11221
11222#if USE_CARBON_EVENTS && (defined (MAC_OSX) || USE_MAC_TSM)
11223 /* When using Carbon Events, we need to pass raw keyboard
11224 events to the TSM ourselves. If TSM handles it, it
11225 will pass back noErr, otherwise it will pass back
11226 "eventNotHandledErr" and we can process it
11227 normally. */
11228 if (!(mapped_modifiers
11229 & ~(mac_pass_command_to_system ? cmdKey : 0)
11230 & ~(mac_pass_control_to_system ? controlKey : 0)))
11231 {
11232 OSStatus err;
11233
11234 read_socket_inev = &inev;
11235 err = SendEventToEventTarget (eventRef, toolbox_dispatcher);
11236 read_socket_inev = NULL;
11237 if (err != eventNotHandledErr)
11238 break;
11239 }
11240#endif
11241 if (er.what == keyUp)
11242 break;
11243
11244 ObscureCursor ();
11245 11618
11246 f = mac_focus_frame (dpyinfo); 11619 f = mac_focus_frame (dpyinfo);
11247 11620 XSETFRAME (inev.frame_or_window, f);
11248 if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight)
11249 && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window))
11250 {
11251 clear_mouse_face (dpyinfo);
11252 dpyinfo->mouse_face_hidden = 1;
11253 }
11254
11255 current_key_script = GetScriptManagerVariable (smKeyScript);
11256 if (last_key_script != current_key_script)
11257 {
11258 struct input_event event;
11259
11260 EVENT_INIT (event);
11261 event.kind = LANGUAGE_CHANGE_EVENT;
11262 event.arg = Qnil;
11263 event.code = current_key_script;
11264 event.timestamp = timestamp;
11265 kbd_buffer_store_event (&event);
11266 count++;
11267 last_key_script = current_key_script;
11268 }
11269
11270#if USE_MAC_TSM
11271 if (inev.kind != NO_EVENT)
11272 break;
11273#endif
11274
11275#ifdef MAC_OSX
11276 if (mapped_modifiers & kEventKeyModifierFnMask
11277 && keycode <= 0x7f
11278 && fn_keycode_to_keycode_table[keycode])
11279 keycode = fn_keycode_to_keycode_table[keycode];
11280#endif
11281 if (keycode <= 0x7f && keycode_to_xkeysym_table [keycode])
11282 {
11283 inev.kind = NON_ASCII_KEYSTROKE_EVENT;
11284 inev.code = 0xff00 | keycode_to_xkeysym_table [keycode];
11285#ifdef MAC_OSX
11286 if (modifiers & kEventKeyModifierFnMask
11287 && keycode <= 0x7f
11288 && fn_keycode_to_keycode_table[keycode] == keycode)
11289 modifiers &= ~kEventKeyModifierFnMask;
11290#endif
11291 }
11292 else if (mapped_modifiers)
11293 {
11294 /* translate the keycode back to determine the
11295 original key */
11296#ifdef MAC_OSX
11297 UCKeyboardLayout *uchr_ptr = NULL;
11298#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
11299 OSStatus err;
11300 KeyboardLayoutRef layout;
11301
11302 err = KLGetCurrentKeyboardLayout (&layout);
11303 if (err == noErr)
11304 KLGetKeyboardLayoutProperty (layout, kKLuchrData,
11305 (const void **) &uchr_ptr);
11306#else
11307 static SInt16 last_key_layout_id = 0;
11308 static Handle uchr_handle = (Handle)-1;
11309 SInt16 current_key_layout_id =
11310 GetScriptVariable (current_key_script, smScriptKeys);
11311
11312 if (uchr_handle == (Handle)-1
11313 || last_key_layout_id != current_key_layout_id)
11314 {
11315 uchr_handle = GetResource ('uchr', current_key_layout_id);
11316 last_key_layout_id = current_key_layout_id;
11317 }
11318 if (uchr_handle)
11319 uchr_ptr = (UCKeyboardLayout *)*uchr_handle;
11320#endif
11321
11322 if (uchr_ptr)
11323 {
11324 OSStatus status;
11325 UInt16 key_action = er.what - keyDown;
11326 UInt32 modifier_key_state =
11327 (modifiers & ~mapped_modifiers) >> 8;
11328 UInt32 keyboard_type = LMGetKbdType ();
11329 SInt32 dead_key_state = 0;
11330 UniChar code;
11331 UniCharCount actual_length;
11332
11333 status = UCKeyTranslate (uchr_ptr,
11334 keycode, key_action,
11335 modifier_key_state,
11336 keyboard_type,
11337 kUCKeyTranslateNoDeadKeysMask,
11338 &dead_key_state,
11339 1, &actual_length, &code);
11340 if (status == noErr && actual_length == 1)
11341 mac_set_unicode_keystroke_event (code, &inev);
11342 }
11343#endif /* MAC_OSX */
11344
11345 if (inev.kind == NO_EVENT)
11346 {
11347 /* This code comes from Keyboard Resource,
11348 Appendix C of IM - Text. This is necessary
11349 since shift is ignored in KCHR table
11350 translation when option or command is pressed.
11351 It also does not translate correctly
11352 control-shift chars like C-% so mask off shift
11353 here also. */
11354 /* Mask off modifier keys that are mapped to some
11355 Emacs modifiers. */
11356 int new_modifiers = er.modifiers & ~mapped_modifiers;
11357 /* set high byte of keycode to modifier high byte*/
11358 int new_keycode = keycode | new_modifiers;
11359 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
11360 unsigned long some_state = 0;
11361 UInt32 new_char_code;
11362
11363 new_char_code = KeyTranslate (kchr_ptr, new_keycode,
11364 &some_state);
11365 if (new_char_code == 0)
11366 /* Seems like a dead key. Append up-stroke. */
11367 new_char_code = KeyTranslate (kchr_ptr,
11368 new_keycode | 0x80,
11369 &some_state);
11370 if (new_char_code)
11371 {
11372 inev.kind = ASCII_KEYSTROKE_EVENT;
11373 inev.code = new_char_code & 0xff;
11374 }
11375 }
11376 }
11377
11378 if (inev.kind == NO_EVENT)
11379 {
11380 inev.kind = ASCII_KEYSTROKE_EVENT;
11381 inev.code = er.message & charCodeMask;
11382 }
11383
11384 inev.modifiers = mac_to_emacs_modifiers (modifiers);
11385 inev.modifiers |= (extra_keyboard_modifiers
11386 & (meta_modifier | alt_modifier
11387 | hyper_modifier | super_modifier));
11388 XSETFRAME (inev.frame_or_window, f);
11389 11621
11622 /* If mouse-highlight is an integer, input clears out mouse
11623 highlighting. */
11624 if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight)
11625 && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window))
11626 {
11627 clear_mouse_face (dpyinfo);
11628 dpyinfo->mouse_face_hidden = 1;
11629 }
11390#if TARGET_API_MAC_CARBON 11630#if TARGET_API_MAC_CARBON
11391 if (inev.kind == ASCII_KEYSTROKE_EVENT 11631 goto OTHER;
11392 && inev.code >= 0x80 && inev.modifiers) 11632#else
11393 { 11633 do_keystroke (er.what, er.message & charCodeMask,
11394 OSStatus err; 11634 (er.message & keyCodeMask) >> 8,
11395 TextEncoding encoding = kTextEncodingMacRoman; 11635 er.modifiers, timestamp, &inev);
11396 TextToUnicodeInfo ttu_info;
11397
11398 UpgradeScriptInfoToTextEncoding (current_key_script,
11399 kTextLanguageDontCare,
11400 kTextRegionDontCare,
11401 NULL, &encoding);
11402 err = CreateTextToUnicodeInfoByEncoding (encoding, &ttu_info);
11403 if (err == noErr)
11404 {
11405 UniChar code;
11406 Str255 pstr;
11407 ByteCount unicode_len;
11408
11409 pstr[0] = 1;
11410 pstr[1] = inev.code;
11411 err = ConvertFromPStringToUnicode (ttu_info, pstr,
11412 sizeof (UniChar),
11413 &unicode_len, &code);
11414 if (err == noErr && unicode_len == sizeof (UniChar))
11415 mac_set_unicode_keystroke_event (code, &inev);
11416 DisposeTextToUnicodeInfo (&ttu_info);
11417 }
11418 }
11419#endif 11636#endif
11420 }
11421 break; 11637 break;
11422 11638
11423 case kHighLevelEvent: 11639 case kHighLevelEvent:
@@ -11425,9 +11641,19 @@ XTread_socket (sd, expected, hold_quit)
11425 break; 11641 break;
11426 11642
11427 default: 11643 default:
11644 OTHER:
11645#if TARGET_API_MAC_CARBON
11646 {
11647 OSStatus err;
11648
11649 read_socket_inev = &inev;
11650 err = SendEventToEventTarget (eventRef, toolbox_dispatcher);
11651 read_socket_inev = NULL;
11652 }
11653#endif
11428 break; 11654 break;
11429 } 11655 }
11430#if USE_CARBON_EVENTS 11656#if TARGET_API_MAC_CARBON
11431 ReleaseEvent (eventRef); 11657 ReleaseEvent (eventRef);
11432#endif 11658#endif
11433 11659
@@ -11479,7 +11705,7 @@ XTread_socket (sd, expected, hold_quit)
11479 mac_screen_config_changed = 0; 11705 mac_screen_config_changed = 0;
11480 } 11706 }
11481 11707
11482#if !USE_CARBON_EVENTS 11708#if !TARGET_API_MAC_CARBON
11483 /* Check which frames are still visible. We do this here because 11709 /* Check which frames are still visible. We do this here because
11484 there doesn't seem to be any direct notification from the Window 11710 there doesn't seem to be any direct notification from the Window
11485 Manager that the visibility of a window has changed (at least, 11711 Manager that the visibility of a window has changed (at least,
@@ -11584,7 +11810,7 @@ make_mac_terminal_frame (struct frame *f)
11584 11810
11585 if (!(FRAME_MAC_WINDOW (f) = 11811 if (!(FRAME_MAC_WINDOW (f) =
11586 NewCWindow (NULL, &r, "\p", true, dBoxProc, 11812 NewCWindow (NULL, &r, "\p", true, dBoxProc,
11587 (WindowPtr) -1, 1, (long) f->output_data.mac))) 11813 (WindowRef) -1, 1, (long) f->output_data.mac)))
11588 abort (); 11814 abort ();
11589 /* so that update events can find this mac_output struct */ 11815 /* so that update events can find this mac_output struct */
11590 f->output_data.mac->mFP = f; /* point back to emacs frame */ 11816 f->output_data.mac->mFP = f; /* point back to emacs frame */
@@ -11774,7 +12000,6 @@ init_menu_bar ()
11774 &menu, &menu_index); 12000 &menu, &menu_index);
11775 if (err == noErr) 12001 if (err == noErr)
11776 SetMenuItemCommandKey (menu, menu_index, false, 0); 12002 SetMenuItemCommandKey (menu, menu_index, false, 0);
11777#if USE_CARBON_EVENTS
11778 EnableMenuCommand (NULL, kHICommandPreferences); 12003 EnableMenuCommand (NULL, kHICommandPreferences);
11779 err = GetIndMenuItemWithCommandID (NULL, kHICommandPreferences, 1, 12004 err = GetIndMenuItemWithCommandID (NULL, kHICommandPreferences, 1,
11780 &menu, &menu_index); 12005 &menu, &menu_index);
@@ -11786,10 +12011,9 @@ init_menu_bar ()
11786 InsertMenuItemTextWithCFString (menu, CFSTR ("About Emacs"), 12011 InsertMenuItemTextWithCFString (menu, CFSTR ("About Emacs"),
11787 0, 0, kHICommandAbout); 12012 0, 0, kHICommandAbout);
11788 } 12013 }
11789#endif /* USE_CARBON_EVENTS */
11790#else /* !MAC_OSX */ 12014#else /* !MAC_OSX */
11791#if USE_CARBON_EVENTS 12015#if TARGET_API_MAC_CARBON
11792 SetMenuItemCommandID (GetMenuHandle (M_APPLE), I_ABOUT, kHICommandAbout); 12016 SetMenuItemCommandID (GetMenuRef (M_APPLE), I_ABOUT, kHICommandAbout);
11793#endif 12017#endif
11794#endif 12018#endif
11795} 12019}
@@ -11896,19 +12120,13 @@ mac_initialize ()
11896 12120
11897#if TARGET_API_MAC_CARBON 12121#if TARGET_API_MAC_CARBON
11898 12122
11899#if USE_CARBON_EVENTS 12123 install_application_handler ();
11900#ifdef MAC_OSX
11901 init_service_handler ();
11902#endif /* MAC_OSX */
11903
11904 init_command_handler ();
11905 12124
11906 init_menu_bar (); 12125 init_menu_bar ();
11907 12126
11908#if USE_MAC_TSM 12127#if USE_MAC_TSM
11909 init_tsm (); 12128 init_tsm ();
11910#endif 12129#endif
11911#endif /* USE_CARBON_EVENTS */
11912 12130
11913#ifdef MAC_OSX 12131#ifdef MAC_OSX
11914 init_coercion_handler (); 12132 init_coercion_handler ();
@@ -11958,7 +12176,7 @@ syms_of_macterm ()
11958 Fput (Qhyper, Qmodifier_value, make_number (hyper_modifier)); 12176 Fput (Qhyper, Qmodifier_value, make_number (hyper_modifier));
11959 Fput (Qsuper, Qmodifier_value, make_number (super_modifier)); 12177 Fput (Qsuper, Qmodifier_value, make_number (super_modifier));
11960 12178
11961#if USE_CARBON_EVENTS 12179#if TARGET_API_MAC_CARBON
11962 Qhi_command = intern ("hi-command"); staticpro (&Qhi_command); 12180 Qhi_command = intern ("hi-command"); staticpro (&Qhi_command);
11963#ifdef MAC_OSX 12181#ifdef MAC_OSX
11964 Qtoolbar_switch_mode = intern ("toolbar-switch-mode"); 12182 Qtoolbar_switch_mode = intern ("toolbar-switch-mode");
@@ -12083,7 +12301,7 @@ The symbol `reverse' means that the option-key will register for
12083mouse-3 and the command-key will register for mouse-2. */); 12301mouse-3 and the command-key will register for mouse-2. */);
12084 Vmac_emulate_three_button_mouse = Qnil; 12302 Vmac_emulate_three_button_mouse = Qnil;
12085 12303
12086#if USE_CARBON_EVENTS 12304#if TARGET_API_MAC_CARBON
12087 DEFVAR_BOOL ("mac-wheel-button-is-mouse-2", &mac_wheel_button_is_mouse_2, 12305 DEFVAR_BOOL ("mac-wheel-button-is-mouse-2", &mac_wheel_button_is_mouse_2,
12088 doc: /* *Non-nil if the wheel button is mouse-2 and the right click mouse-3. 12306 doc: /* *Non-nil if the wheel button is mouse-2 and the right click mouse-3.
12089Otherwise, the right click will be treated as mouse-2 and the wheel 12307Otherwise, the right click will be treated as mouse-2 and the wheel
diff --git a/src/macterm.h b/src/macterm.h
index b3826c5e7f7..7984ff2b970 100644
--- a/src/macterm.h
+++ b/src/macterm.h
@@ -369,6 +369,12 @@ typedef struct mac_output mac_output;
369/* This is the 'font_info *' which frame F has. */ 369/* This is the 'font_info *' which frame F has. */
370#define FRAME_MAC_FONT_TABLE(f) (FRAME_MAC_DISPLAY_INFO (f)->font_table) 370#define FRAME_MAC_FONT_TABLE(f) (FRAME_MAC_DISPLAY_INFO (f)->font_table)
371 371
372/* The difference in pixels between the top left corner of the
373 Emacs window (including possible window manager decorations)
374 and FRAME_MAC_WINDOW (f). */
375#define FRAME_OUTER_TO_INNER_DIFF_X(f) ((f)->x_pixels_diff)
376#define FRAME_OUTER_TO_INNER_DIFF_Y(f) ((f)->y_pixels_diff)
377
372/* Value is the smallest width of any character in any font on frame F. */ 378/* Value is the smallest width of any character in any font on frame F. */
373 379
374#define FRAME_SMALLEST_CHAR_WIDTH(F) \ 380#define FRAME_SMALLEST_CHAR_WIDTH(F) \
@@ -406,9 +412,9 @@ struct scroll_bar {
406 /* The next and previous in the chain of scroll bars in this frame. */ 412 /* The next and previous in the chain of scroll bars in this frame. */
407 Lisp_Object next, prev; 413 Lisp_Object next, prev;
408 414
409 /* The Mac control handle of this scroll bar. Since this is a 415 /* The Mac control reference of this scroll bar. Since this is a
410 pointer value, we store it split into two Lisp integers. */ 416 pointer value, we store it split into two Lisp integers. */
411 Lisp_Object control_handle_low, control_handle_high; 417 Lisp_Object control_ref_low, control_ref_high;
412 418
413 /* The position and size of the scroll bar in pixels, relative to the 419 /* The position and size of the scroll bar in pixels, relative to the
414 frame. */ 420 frame. */
@@ -466,14 +472,14 @@ struct scroll_bar {
466 472
467/* Extract the Mac control handle of the scroll bar from a struct 473/* Extract the Mac control handle of the scroll bar from a struct
468 scroll_bar. */ 474 scroll_bar. */
469#define SCROLL_BAR_CONTROL_HANDLE(ptr) \ 475#define SCROLL_BAR_CONTROL_REF(ptr) \
470 ((ControlHandle) SCROLL_BAR_PACK ((ptr)->control_handle_low, \ 476 ((ControlRef) SCROLL_BAR_PACK ((ptr)->control_ref_low, \
471 (ptr)->control_handle_high)) 477 (ptr)->control_ref_high))
472 478
473/* Store a Mac control handle in a struct scroll_bar. */ 479/* Store a Mac control handle in a struct scroll_bar. */
474#define SET_SCROLL_BAR_CONTROL_HANDLE(ptr, handle) \ 480#define SET_SCROLL_BAR_CONTROL_REF(ptr, ref) \
475 (SCROLL_BAR_UNPACK ((ptr)->control_handle_low, \ 481 (SCROLL_BAR_UNPACK ((ptr)->control_ref_low, \
476 (ptr)->control_handle_high, (unsigned long) (handle))) 482 (ptr)->control_ref_high, (unsigned long) (ref)))
477 483
478/* Return the inside width of a vertical scroll bar, given the outside 484/* Return the inside width of a vertical scroll bar, given the outside
479 width. */ 485 width. */
@@ -615,9 +621,9 @@ extern void x_destroy_window P_ ((struct frame *));
615extern void x_wm_set_size_hint P_ ((struct frame *, long, int)); 621extern void x_wm_set_size_hint P_ ((struct frame *, long, int));
616extern void x_delete_display P_ ((struct x_display_info *)); 622extern void x_delete_display P_ ((struct x_display_info *));
617extern void mac_initialize P_ ((void)); 623extern void mac_initialize P_ ((void));
618extern Pixmap XCreatePixmap P_ ((Display *, WindowPtr, unsigned int, 624extern Pixmap XCreatePixmap P_ ((Display *, WindowRef, unsigned int,
619 unsigned int, unsigned int)); 625 unsigned int, unsigned int));
620extern Pixmap XCreatePixmapFromBitmapData P_ ((Display *, WindowPtr, char *, 626extern Pixmap XCreatePixmapFromBitmapData P_ ((Display *, WindowRef, char *,
621 unsigned int, unsigned int, 627 unsigned int, unsigned int,
622 unsigned long, unsigned long, 628 unsigned long, unsigned long,
623 unsigned int)); 629 unsigned int));
@@ -626,7 +632,7 @@ extern GC XCreateGC P_ ((Display *, void *, unsigned long, XGCValues *));
626extern void XFreeGC P_ ((Display *, GC)); 632extern void XFreeGC P_ ((Display *, GC));
627extern void XSetForeground P_ ((Display *, GC, unsigned long)); 633extern void XSetForeground P_ ((Display *, GC, unsigned long));
628extern void XSetBackground P_ ((Display *, GC, unsigned long)); 634extern void XSetBackground P_ ((Display *, GC, unsigned long));
629extern void XSetWindowBackground P_ ((Display *, WindowPtr, unsigned long)); 635extern void XSetWindowBackground P_ ((Display *, WindowRef, unsigned long));
630extern void XDrawLine P_ ((Display *, Pixmap, GC, int, int, int, int)); 636extern void XDrawLine P_ ((Display *, Pixmap, GC, int, int, int, int));
631extern void mac_clear_area P_ ((struct frame *, int, int, 637extern void mac_clear_area P_ ((struct frame *, int, int,
632 unsigned int, unsigned int)); 638 unsigned int, unsigned int));
@@ -634,8 +640,8 @@ extern void mac_unload_font P_ ((struct mac_display_info *, XFontStruct *));
634extern int mac_font_panel_visible_p P_ ((void)); 640extern int mac_font_panel_visible_p P_ ((void));
635extern OSStatus mac_show_hide_font_panel P_ ((void)); 641extern OSStatus mac_show_hide_font_panel P_ ((void));
636extern OSStatus mac_set_font_info_for_selection P_ ((struct frame *, int, int)); 642extern OSStatus mac_set_font_info_for_selection P_ ((struct frame *, int, int));
637extern OSStatus install_window_handler P_ ((WindowPtr)); 643extern OSStatus install_window_handler P_ ((WindowRef));
638extern void remove_window_handler P_ ((WindowPtr)); 644extern void remove_window_handler P_ ((WindowRef));
639extern OSStatus mac_post_mouse_moved_event P_ ((void)); 645extern OSStatus mac_post_mouse_moved_event P_ ((void));
640#if !TARGET_API_MAC_CARBON 646#if !TARGET_API_MAC_CARBON
641extern void do_apple_menu P_ ((SInt16)); 647extern void do_apple_menu P_ ((SInt16));
@@ -643,6 +649,7 @@ extern void do_apple_menu P_ ((SInt16));
643#if USE_CG_DRAWING 649#if USE_CG_DRAWING
644extern void mac_prepare_for_quickdraw P_ ((struct frame *)); 650extern void mac_prepare_for_quickdraw P_ ((struct frame *));
645#endif 651#endif
652extern void mac_get_window_bounds P_ ((struct frame *, Rect *, Rect *));
646extern int mac_quit_char_key_p P_ ((UInt32, UInt32)); 653extern int mac_quit_char_key_p P_ ((UInt32, UInt32));
647 654
648#define FONT_TYPE_FOR_UNIBYTE(font, ch) 0 655#define FONT_TYPE_FOR_UNIBYTE(font, ch) 0
diff --git a/src/minibuf.c b/src/minibuf.c
index 6c6fa7451fc..f275414d3aa 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -529,7 +529,7 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
529 GCPRO5 (map, initial, val, ambient_dir, input_method); 529 GCPRO5 (map, initial, val, ambient_dir, input_method);
530 530
531 if (!STRINGP (prompt)) 531 if (!STRINGP (prompt))
532 prompt = empty_string; 532 prompt = empty_unibyte_string;
533 533
534 if (!enable_recursive_minibuffers 534 if (!enable_recursive_minibuffers
535 && minibuf_level > 0) 535 && minibuf_level > 0)
diff --git a/src/s/ms-w32.h b/src/s/ms-w32.h
index ad699dff035..666b70b1ea5 100644
--- a/src/s/ms-w32.h
+++ b/src/s/ms-w32.h
@@ -255,7 +255,6 @@ Boston, MA 02110-1301, USA. */
255 255
256#undef TM_IN_SYS_TIME 256#undef TM_IN_SYS_TIME
257#undef HAVE_TM_ZONE 257#undef HAVE_TM_ZONE
258#define HAVE_TZNAME 1
259 258
260#define HAVE_LONG_FILE_NAMES 1 259#define HAVE_LONG_FILE_NAMES 1
261 260
diff --git a/src/search.c b/src/search.c
index 7f50032c024..fd7b474e4ab 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2076,7 +2076,7 @@ wordify (string)
2076 if (SYNTAX (prev_c) == Sword) 2076 if (SYNTAX (prev_c) == Sword)
2077 word_count++; 2077 word_count++;
2078 if (!word_count) 2078 if (!word_count)
2079 return empty_string; 2079 return empty_unibyte_string;
2080 2080
2081 adjust = - punct_count + 5 * (word_count - 1) + 4; 2081 adjust = - punct_count + 5 * (word_count - 1) + 4;
2082 if (STRING_MULTIBYTE (string)) 2082 if (STRING_MULTIBYTE (string))
diff --git a/src/sunfns.c b/src/sunfns.c
index c532ae7f849..2d96ac66aef 100644
--- a/src/sunfns.c
+++ b/src/sunfns.c
@@ -287,7 +287,7 @@ sel_read (sel, file)
287 register int i, n; 287 register int i, n;
288 register char *cp; 288 register char *cp;
289 289
290 Current_Selection = make_string ("", 0); 290 Current_Selection = empty_unibyte_string;
291 if (sel->sel_items <= 0) 291 if (sel->sel_items <= 0)
292 return (0); 292 return (0);
293 cp = (char *) malloc(sel->sel_items); 293 cp = (char *) malloc(sel->sel_items);
diff --git a/src/term.c b/src/term.c
index f23963cc39c..566b8b84915 100644
--- a/src/term.c
+++ b/src/term.c
@@ -430,11 +430,6 @@ static int mouse_face_past_end;
430static Lisp_Object Qmouse_face_window; 430static Lisp_Object Qmouse_face_window;
431static int mouse_face_face_id; 431static int mouse_face_face_id;
432 432
433/* FRAME and X, Y position of mouse when last checked for
434 highlighting. X and Y can be negative or out of range for the frame. */
435struct frame *mouse_face_mouse_frame;
436int mouse_face_mouse_x, mouse_face_mouse_y;
437
438static int pos_x, pos_y; 433static int pos_x, pos_y;
439static int last_mouse_x, last_mouse_y; 434static int last_mouse_x, last_mouse_y;
440#endif /* HAVE_GPM */ 435#endif /* HAVE_GPM */
@@ -2494,17 +2489,18 @@ set_tty_color_mode (f, val)
2494 ***********************************************************************/ 2489 ***********************************************************************/
2495 2490
2496#ifdef HAVE_GPM 2491#ifdef HAVE_GPM
2497void term_mouse_moveto (int x, int y) 2492void
2493term_mouse_moveto (int x, int y)
2498{ 2494{
2499 const char *name; 2495 const char *name;
2500 int fd; 2496 int fd;
2497 /* TODO: how to set mouse position?
2501 name = (const char *) ttyname (0); 2498 name = (const char *) ttyname (0);
2502 fd = open (name, O_WRONLY); 2499 fd = open (name, O_WRONLY);
2503 /* TODO: how to set mouse position? 2500 SOME_FUNCTION (x, y, fd);
2504 SOME_FUNCTION (x, y, fd); */
2505 close (fd); 2501 close (fd);
2506 last_mouse_x = x; 2502 last_mouse_x = x;
2507 last_mouse_y = y; 2503 last_mouse_y = y; */
2508} 2504}
2509 2505
2510static void 2506static void
@@ -2681,10 +2677,6 @@ term_mouse_highlight (struct frame *f, int x, int y)
2681 || !f->glyphs_initialized_p) 2677 || !f->glyphs_initialized_p)
2682 return; 2678 return;
2683 2679
2684 mouse_face_mouse_x = x;
2685 mouse_face_mouse_y = y;
2686 mouse_face_mouse_frame = f;
2687
2688 /* Which window is that in? */ 2680 /* Which window is that in? */
2689 window = window_from_coordinates (f, x, y, &part, &x, &y, 0); 2681 window = window_from_coordinates (f, x, y, &part, &x, &y, 0);
2690 2682
@@ -2926,7 +2918,7 @@ term_mouse_movement (FRAME_PTR frame, Gpm_Event *event)
2926 if (event->x != last_mouse_x || event->y != last_mouse_y) 2918 if (event->x != last_mouse_x || event->y != last_mouse_y)
2927 { 2919 {
2928 frame->mouse_moved = 1; 2920 frame->mouse_moved = 1;
2929 term_mouse_highlight (frame, event->x - 1, event->y - 1); 2921 term_mouse_highlight (frame, event->x, event->y);
2930 /* Remember which glyph we're now on. */ 2922 /* Remember which glyph we're now on. */
2931 last_mouse_x = event->x; 2923 last_mouse_x = event->x;
2932 last_mouse_y = event->y; 2924 last_mouse_y = event->y;
@@ -2946,7 +2938,7 @@ term_mouse_movement (FRAME_PTR frame, Gpm_Event *event)
2946 2938
2947 Set *time to the time the mouse was at the returned position. 2939 Set *time to the time the mouse was at the returned position.
2948 2940
2949 This should clear mouse_moved until the next motion 2941 This clears mouse_moved until the next motion
2950 event arrives. */ 2942 event arrives. */
2951static void 2943static void
2952term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window, 2944term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
@@ -2954,8 +2946,6 @@ term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
2954 Lisp_Object *y, unsigned long *time) 2946 Lisp_Object *y, unsigned long *time)
2955{ 2947{
2956 struct timeval now; 2948 struct timeval now;
2957 Lisp_Object frame, window;
2958 struct window *w;
2959 2949
2960 *fp = SELECTED_FRAME (); 2950 *fp = SELECTED_FRAME ();
2961 (*fp)->mouse_moved = 0; 2951 (*fp)->mouse_moved = 0;
@@ -2963,13 +2953,8 @@ term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
2963 *bar_window = Qnil; 2953 *bar_window = Qnil;
2964 *part = 0; 2954 *part = 0;
2965 2955
2966 XSETINT (*x, last_mouse_x); 2956 XSETINT (*x, last_mouse_x);
2967 XSETINT (*y, last_mouse_y); 2957 XSETINT (*y, last_mouse_y);
2968 XSETFRAME (frame, *fp);
2969 window = Fwindow_at (*x, *y, frame);
2970
2971 XSETINT (*x, last_mouse_x - WINDOW_LEFT_EDGE_COL (XWINDOW (window)));
2972 XSETINT (*y, last_mouse_y - WINDOW_TOP_EDGE_LINE (XWINDOW (window)));
2973 gettimeofday(&now, 0); 2958 gettimeofday(&now, 0);
2974 *time = (now.tv_sec * 1000) + (now.tv_usec / 1000); 2959 *time = (now.tv_sec * 1000) + (now.tv_usec / 1000);
2975} 2960}
@@ -3016,7 +3001,7 @@ term_mouse_click (struct input_event *result, Gpm_Event *event,
3016 if (event->type & GPM_DRAG) 3001 if (event->type & GPM_DRAG)
3017 result->modifiers |= drag_modifier; 3002 result->modifiers |= drag_modifier;
3018 3003
3019 if (!(event->type & (GPM_MOVE|GPM_DRAG))) { 3004 if (!(event->type & (GPM_MOVE | GPM_DRAG))) {
3020 3005
3021 /* 1 << KG_SHIFT */ 3006 /* 1 << KG_SHIFT */
3022 if (event->modifiers & (1 << 0)) 3007 if (event->modifiers & (1 << 0))
@@ -3032,8 +3017,8 @@ term_mouse_click (struct input_event *result, Gpm_Event *event,
3032 result->modifiers |= meta_modifier; 3017 result->modifiers |= meta_modifier;
3033 } 3018 }
3034 3019
3035 XSETINT (result->x, event->x - 1); 3020 XSETINT (result->x, event->x);
3036 XSETINT (result->y, event->y - 1); 3021 XSETINT (result->y, event->y);
3037 XSETFRAME (result->frame_or_window, f); 3022 XSETFRAME (result->frame_or_window, f);
3038 result->arg = Qnil; 3023 result->arg = Qnil;
3039 return Qnil; 3024 return Qnil;
@@ -3052,7 +3037,7 @@ handle_one_term_event (Gpm_Event *event, struct input_event* hold_quit)
3052 ie.kind = NO_EVENT; 3037 ie.kind = NO_EVENT;
3053 ie.arg = Qnil; 3038 ie.arg = Qnil;
3054 3039
3055 if (event->type & GPM_MOVE) { 3040 if (event->type & (GPM_MOVE | GPM_DRAG)) {
3056 unsigned char buf[6 * sizeof (short)]; 3041 unsigned char buf[6 * sizeof (short)];
3057 unsigned short *arg = (unsigned short *) buf + 1; 3042 unsigned short *arg = (unsigned short *) buf + 1;
3058 const char *name; 3043 const char *name;
@@ -3063,8 +3048,8 @@ handle_one_term_event (Gpm_Event *event, struct input_event* hold_quit)
3063 /* Display mouse pointer */ 3048 /* Display mouse pointer */
3064 buf[sizeof(short) - 1] = 2; /* set selection */ 3049 buf[sizeof(short) - 1] = 2; /* set selection */
3065 3050
3066 arg[0] = arg[2] = (unsigned short) event->x; 3051 arg[0] = arg[2] = (unsigned short) event->x + gpm_zerobased;
3067 arg[1] = arg[3] = (unsigned short) event->y; 3052 arg[1] = arg[3] = (unsigned short) event->y + gpm_zerobased;
3068 arg[4] = (unsigned short) 3; 3053 arg[4] = (unsigned short) 3;
3069 3054
3070 name = (const char *) ttyname (0); 3055 name = (const char *) ttyname (0);
@@ -3072,7 +3057,8 @@ handle_one_term_event (Gpm_Event *event, struct input_event* hold_quit)
3072 ioctl (fd, TIOCLINUX, buf + sizeof (short) - 1); 3057 ioctl (fd, TIOCLINUX, buf + sizeof (short) - 1);
3073 close (fd); 3058 close (fd);
3074 3059
3075 term_mouse_movement (f, event); 3060 if (!term_mouse_movement (f, event))
3061 help_echo_string = previous_help_echo_string;
3076 3062
3077 /* If the contents of the global variable help_echo_string 3063 /* If the contents of the global variable help_echo_string
3078 has changed, generate a HELP_EVENT. */ 3064 has changed, generate a HELP_EVENT. */
@@ -3123,6 +3109,7 @@ DEFUN ("term-open-connection", Fterm_open_connection, Sterm_open_connection,
3123 connection.defaultMask = ~GPM_HARD; 3109 connection.defaultMask = ~GPM_HARD;
3124 connection.maxMod = ~0; 3110 connection.maxMod = ~0;
3125 connection.minMod = 0; 3111 connection.minMod = 0;
3112 gpm_zerobased = 1;
3126 3113
3127 if (Gpm_Open (&connection, 0) < 0) 3114 if (Gpm_Open (&connection, 0) < 0)
3128 return Qnil; 3115 return Qnil;
diff --git a/src/w32fns.c b/src/w32fns.c
index dc36f41575b..94674def83a 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -8043,9 +8043,9 @@ If ONLY-DIR-P is non-nil, the user can only select directories. */)
8043 /* Apparently NT4 crashes if you give it an unexpected size. 8043 /* Apparently NT4 crashes if you give it an unexpected size.
8044 I'm not sure about Windows 9x, so play it safe. */ 8044 I'm not sure about Windows 9x, so play it safe. */
8045 if (w32_major_version > 4 && w32_major_version < 95) 8045 if (w32_major_version > 4 && w32_major_version < 95)
8046 file_details->lStructSize = sizeof (new_file_details); 8046 file_details->lStructSize = sizeof (NEWOPENFILENAME);
8047 else 8047 else
8048 file_details->lStructSize = sizeof (file_details); 8048 file_details->lStructSize = sizeof (OPENFILENAME);
8049 8049
8050 file_details->hwndOwner = FRAME_W32_WINDOW (f); 8050 file_details->hwndOwner = FRAME_W32_WINDOW (f);
8051 /* Undocumented Bug in Common File Dialog: 8051 /* Undocumented Bug in Common File Dialog:
diff --git a/src/window.c b/src/window.c
index f417c7458d4..61be973e180 100644
--- a/src/window.c
+++ b/src/window.c
@@ -4110,8 +4110,8 @@ too small. */)
4110DEFUN ("shrink-window", Fshrink_window, Sshrink_window, 1, 2, "p", 4110DEFUN ("shrink-window", Fshrink_window, Sshrink_window, 1, 2, "p",
4111 doc: /* Make current window ARG lines smaller. 4111 doc: /* Make current window ARG lines smaller.
4112From program, optional second arg non-nil means shrink sideways arg columns. 4112From program, optional second arg non-nil means shrink sideways arg columns.
4113Interactively, if an argument is not given, make the window one line smaller. Only 4113Interactively, if an argument is not given, make the window one line smaller.
4114siblings to the right or below are changed. */) 4114Only siblings to the right or below are changed. */)
4115 (arg, side) 4115 (arg, side)
4116 Lisp_Object arg, side; 4116 Lisp_Object arg, side;
4117{ 4117{
diff --git a/src/xdisp.c b/src/xdisp.c
index 268def4a0f2..b87a3d3ac08 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -17491,7 +17491,7 @@ are the selected window and the window's buffer). */)
17491 CHECK_BUFFER (buffer); 17491 CHECK_BUFFER (buffer);
17492 17492
17493 if (NILP (format)) 17493 if (NILP (format))
17494 return build_string (""); 17494 return empty_unibyte_string;
17495 17495
17496 if (no_props) 17496 if (no_props)
17497 face = Qnil; 17497 face = Qnil;
@@ -17549,7 +17549,7 @@ are the selected window and the window's buffer). */)
17549 { 17549 {
17550 mode_line_string_list = Fnreverse (mode_line_string_list); 17550 mode_line_string_list = Fnreverse (mode_line_string_list);
17551 str = Fmapconcat (intern ("identity"), mode_line_string_list, 17551 str = Fmapconcat (intern ("identity"), mode_line_string_list,
17552 make_string ("", 0)); 17552 empty_unibyte_string);
17553 } 17553 }
17554 17554
17555 unbind_to (count, Qnil); 17555 unbind_to (count, Qnil);
@@ -24387,7 +24387,7 @@ and is used only on frames for which no explicit name has been set
24387 = Vframe_title_format 24387 = Vframe_title_format
24388 = Fcons (intern ("multiple-frames"), 24388 = Fcons (intern ("multiple-frames"),
24389 Fcons (build_string ("%b"), 24389 Fcons (build_string ("%b"),
24390 Fcons (Fcons (empty_string, 24390 Fcons (Fcons (empty_unibyte_string,
24391 Fcons (intern ("invocation-name"), 24391 Fcons (intern ("invocation-name"),
24392 Fcons (build_string ("@"), 24392 Fcons (build_string ("@"),
24393 Fcons (intern ("system-name"), 24393 Fcons (intern ("system-name"),
diff --git a/src/xfaces.c b/src/xfaces.c
index b2ec813a465..63776cf98ac 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -4160,6 +4160,8 @@ Otherwise check for the existence of a global face. */)
4160{ 4160{
4161 Lisp_Object lface; 4161 Lisp_Object lface;
4162 4162
4163 face = resolve_face_name (face, 1);
4164
4163 if (!NILP (frame)) 4165 if (!NILP (frame))
4164 { 4166 {
4165 CHECK_LIVE_FRAME (frame); 4167 CHECK_LIVE_FRAME (frame);
diff --git a/src/xfns.c b/src/xfns.c
index 9fee9c52da4..dbc9f2d9b16 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1523,6 +1523,8 @@ x_set_scroll_bar_background (f, value, oldval)
1523/* Encode Lisp string STRING as a text in a format appropriate for 1523/* Encode Lisp string STRING as a text in a format appropriate for
1524 XICCC (X Inter Client Communication Conventions). 1524 XICCC (X Inter Client Communication Conventions).
1525 1525
1526 This can call Lisp code, so callers must GCPRO.
1527
1526 If STRING contains only ASCII characters, do no conversion and 1528 If STRING contains only ASCII characters, do no conversion and
1527 return the string data of STRING. Otherwise, encode the text by 1529 return the string data of STRING. Otherwise, encode the text by
1528 CODING_SYSTEM, and return a newly allocated memory area which 1530 CODING_SYSTEM, and return a newly allocated memory area which
@@ -1591,6 +1593,16 @@ x_set_name_internal (f, name)
1591 int bytes, stringp; 1593 int bytes, stringp;
1592 int do_free_icon_value = 0, do_free_text_value = 0; 1594 int do_free_icon_value = 0, do_free_text_value = 0;
1593 Lisp_Object coding_system; 1595 Lisp_Object coding_system;
1596#ifdef USE_GTK
1597 Lisp_Object encoded_name;
1598 struct gcpro gcpro1;
1599
1600 /* As ENCODE_UTF_8 may cause GC and relocation of string data,
1601 we use it before x_encode_text that may return string data. */
1602 GCPRO1 (name);
1603 encoded_name = ENCODE_UTF_8 (name);
1604 UNGCPRO;
1605#endif
1594 1606
1595 coding_system = Qcompound_text; 1607 coding_system = Qcompound_text;
1596 /* Note: Encoding strategy 1608 /* Note: Encoding strategy
@@ -1631,7 +1643,7 @@ x_set_name_internal (f, name)
1631 1643
1632#ifdef USE_GTK 1644#ifdef USE_GTK
1633 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), 1645 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
1634 (char *) SDATA (ENCODE_UTF_8 (name))); 1646 (char *) SDATA (encoded_name));
1635#else /* not USE_GTK */ 1647#else /* not USE_GTK */
1636 XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text); 1648 XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text);
1637#endif /* not USE_GTK */ 1649#endif /* not USE_GTK */
@@ -1817,9 +1829,9 @@ x_default_scroll_bar_color_parameter (f, alist, prop, xprop, xclass,
1817 build_string (foreground_p 1829 build_string (foreground_p
1818 ? "foreground" 1830 ? "foreground"
1819 : "background"), 1831 : "background"),
1820 empty_string, 1832 empty_unibyte_string,
1821 build_string ("verticalScrollBar"), 1833 build_string ("verticalScrollBar"),
1822 empty_string); 1834 empty_unibyte_string);
1823 if (!STRINGP (tem)) 1835 if (!STRINGP (tem))
1824 { 1836 {
1825 /* If nothing has been specified, scroll bars will use a 1837 /* If nothing has been specified, scroll bars will use a
diff --git a/src/xmenu.c b/src/xmenu.c
index 0518832d217..4390e34a914 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -325,7 +325,7 @@ restore_menu_items (saved)
325 menu_items_used = XINT (XCAR (saved)); 325 menu_items_used = XINT (XCAR (saved));
326 saved = XCDR (saved); 326 saved = XCDR (saved);
327 menu_items_n_panes = XINT (XCAR (saved)); 327 menu_items_n_panes = XINT (XCAR (saved));
328 saved = XCDR (saved); 328 saved = XCDR (saved);
329 menu_items_submenu_depth = XINT (XCAR (saved)); 329 menu_items_submenu_depth = XINT (XCAR (saved));
330 return Qnil; 330 return Qnil;
331} 331}
@@ -3428,7 +3428,7 @@ menu_help_callback (help_string, pane, item)
3428 pane_name = first_item[MENU_ITEMS_PANE_NAME]; 3428 pane_name = first_item[MENU_ITEMS_PANE_NAME];
3429 else if (EQ (first_item[0], Qquote)) 3429 else if (EQ (first_item[0], Qquote))
3430 /* This shouldn't happen, see xmenu_show. */ 3430 /* This shouldn't happen, see xmenu_show. */
3431 pane_name = empty_string; 3431 pane_name = empty_unibyte_string;
3432 else 3432 else
3433 pane_name = first_item[MENU_ITEMS_ITEM_NAME]; 3433 pane_name = first_item[MENU_ITEMS_ITEM_NAME];
3434 3434
diff --git a/src/xselect.c b/src/xselect.c
index 3fe109a5b85..17dc7c0e7d3 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -2678,7 +2678,7 @@ If the value is 0 or the atom is not known, return the empty string. */)
2678 ret = make_string (name, strlen (name)); 2678 ret = make_string (name, strlen (name));
2679 2679
2680 if (atom && name) XFree (name); 2680 if (atom && name) XFree (name);
2681 if (NILP (ret)) ret = make_string ("", 0); 2681 if (NILP (ret)) ret = empty_unibyte_string;
2682 2682
2683 UNBLOCK_INPUT; 2683 UNBLOCK_INPUT;
2684 2684
diff --git a/src/xterm.c b/src/xterm.c
index 462de3f32b1..772f7ea7bae 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -8652,7 +8652,7 @@ wm_supports (f, atomname)
8652 prop_atom, 0, max_len, False, target_type, 8652 prop_atom, 0, max_len, False, target_type,
8653 &actual_type, &actual_format, &actual_size, 8653 &actual_type, &actual_format, &actual_size,
8654 &bytes_remaining, &tmp_data); 8654 &bytes_remaining, &tmp_data);
8655 8655
8656 if (rc != Success || actual_type != XA_WINDOW || x_had_errors_p (dpy)) 8656 if (rc != Success || actual_type != XA_WINDOW || x_had_errors_p (dpy))
8657 { 8657 {
8658 if (tmp_data) XFree (tmp_data); 8658 if (tmp_data) XFree (tmp_data);
@@ -8707,7 +8707,7 @@ wm_supports (f, atomname)
8707 rc = 0; 8707 rc = 0;
8708 want_atom = XInternAtom (dpy, atomname, False); 8708 want_atom = XInternAtom (dpy, atomname, False);
8709 8709
8710 for (i = 0; rc == 0 && i < dpyinfo->nr_net_supported_atoms; ++i) 8710 for (i = 0; rc == 0 && i < dpyinfo->nr_net_supported_atoms; ++i)
8711 rc = dpyinfo->net_supported_atoms[i] == want_atom; 8711 rc = dpyinfo->net_supported_atoms[i] == want_atom;
8712 8712
8713 x_uncatch_errors (); 8713 x_uncatch_errors ();
@@ -11108,7 +11108,7 @@ x_term_init (display_name, xrm_option, resource_name)
11108 UNBLOCK_INPUT; 11108 UNBLOCK_INPUT;
11109 dpyinfo->kboard->Vsystem_key_alist 11109 dpyinfo->kboard->Vsystem_key_alist
11110 = call1 (Qvendor_specific_keysyms, 11110 = call1 (Qvendor_specific_keysyms,
11111 build_string (vendor ? vendor : "")); 11111 vendor ? build_string (vendor) : empty_unibyte_string);
11112 BLOCK_INPUT; 11112 BLOCK_INPUT;
11113 } 11113 }
11114 11114