aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMiles Bader2007-06-11 01:00:07 +0000
committerMiles Bader2007-06-11 01:00:07 +0000
commit67f3ad67ee317226cb5d1bb139de0cfd883fdc5e (patch)
tree58a0e1bea7a1d8728fd32e6127a44434e7eac006 /src
parentd17cf4eb2024cf54e4a216312184665094ee3df4 (diff)
parent2d715b39ea1c89066f469405d065dd1a6631d28e (diff)
downloademacs-67f3ad67ee317226cb5d1bb139de0cfd883fdc5e.tar.gz
emacs-67f3ad67ee317226cb5d1bb139de0cfd883fdc5e.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--multi-tty--0--patch-21
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.c57
-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.c2124
-rw-r--r--src/macterm.h34
-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.c22
-rw-r--r--src/xmenu.c4
-rw-r--r--src/xselect.c2
-rw-r--r--src/xterm.c6
35 files changed, 1690 insertions, 1201 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 1ffb57b761a..a2e1e5b8484 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
@@ -13205,7 +13428,7 @@
13205 (single_submenu): Use ENCODE_MENU_STRING 13428 (single_submenu): Use ENCODE_MENU_STRING
13206 (mac_menu_show): Use ENCODE_MENU_STRING. Reset grabbed because 13429 (mac_menu_show): Use ENCODE_MENU_STRING. Reset grabbed because
13207 button release isn't passed to event loop 13430 button release isn't passed to event loop
13208 (add_menu_item): Use SetMenuItemWithCFString 13431 (add_menu_item): Use SetMenuItemWithCFString.
13209 13432
132102004-08-26 Steven Tamm <steventamm@mac.com> 134332004-08-26 Steven Tamm <steventamm@mac.com>
13211 13434
@@ -13474,7 +13697,7 @@
13474 blocking on event queue only by calling ReceiveNextEvent 13697 blocking on event queue only by calling ReceiveNextEvent
13475 instead of select (since GUI events aren't on an fd). 13698 instead of select (since GUI events aren't on an fd).
13476 (sys_read): Remove function 13699 (sys_read): Remove function
13477 * sysdep.c: Remove redefine of read to sys_read if HAVE_CARBON 13700 * sysdep.c: Remove redefine of read to sys_read if HAVE_CARBON.
13478 13701
134792004-07-18 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> 137022004-07-18 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
13480 13703
@@ -13484,12 +13707,12 @@
13484 * macterm.c (x_make_frame_visible): Comment in polling on 13707 * macterm.c (x_make_frame_visible): Comment in polling on
13485 frame creation. 13708 frame creation.
13486 13709
13487 * keyboard.c: Undef SIGIO on Carbon 13710 * keyboard.c: Undef SIGIO on Carbon.
13488 13711
13489 * atimer.c (alarm_signal_handler): Call alarm handlers after 13712 * atimer.c (alarm_signal_handler): Call alarm handlers after
13490 scheduling. 13713 scheduling.
13491 13714
13492 * eval.c (Feval): Remove quit_char test 13715 * eval.c (Feval): Remove quit_char test.
13493 13716
13494 * process.c (wait_reading_process_input): Remove clearing 13717 * process.c (wait_reading_process_input): Remove clearing
13495 stdin for select call on process input. 13718 stdin for select call on process input.
@@ -14441,7 +14664,7 @@
144412004-05-11 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> 146642004-05-11 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
14442 14665
14443 * macterm.c (x_flush, XTframe_up_to_date): Use FRAME_MAC_P 14666 * macterm.c (x_flush, XTframe_up_to_date): Use FRAME_MAC_P
14444 instead of FRAME_X_P 14667 instead of FRAME_X_P.
14445 14668
144462004-05-11 Kim F. Storm <storm@cua.dk> 146692004-05-11 Kim F. Storm <storm@cua.dk>
14447 14670
@@ -14611,7 +14834,7 @@
14611 14834
146122004-05-01 Jason Rumney <jasonr@gnu.org> 148352004-05-01 Jason Rumney <jasonr@gnu.org>
14613 14836
14614 * w32term.c (x_draw_hollow_cursor): Sync with xterm.c 14837 * w32term.c (x_draw_hollow_cursor): Sync with xterm.c.
14615 14838
146162004-04-30 Kim F. Storm <storm@cua.dk> 148392004-04-30 Kim F. Storm <storm@cua.dk>
14617 14840
@@ -17404,7 +17627,7 @@
17404 17627
17405 * makefile.w32-in (alloca.o): Remove. 17628 * makefile.w32-in (alloca.o): Remove.
17406 (coding.o): Depend on intervals.h 17629 (coding.o): Depend on intervals.h
17407 (emacs.o, bytecode.o): Depend on window.h 17630 (emacs.o, bytecode.o): Depend on window.h.
17408 17631
174092003-09-01 Dave Love <fx@gnu.org> 176322003-09-01 Dave Love <fx@gnu.org>
17410 17633
@@ -18185,7 +18408,7 @@
18185 * gtkutil.c: Include keyboard.h, charset.h, coding.h. 18408 * gtkutil.c: Include keyboard.h, charset.h, coding.h.
18186 (xg_create_frame_widgets): Use ENCODE_UTF_8. 18409 (xg_create_frame_widgets): Use ENCODE_UTF_8.
18187 18410
18188 * xterm.c (Qutf_8): Move to coding.c 18411 * xterm.c (Qutf_8): Move to coding.c.
18189 18412
18190 * xmenu.c (ENCODE_MENU_STRING): New. 18413 * xmenu.c (ENCODE_MENU_STRING): New.
18191 (list_of_panes, list_of_items, digest_single_submenu, xmenu_show): 18414 (list_of_panes, list_of_items, digest_single_submenu, xmenu_show):
@@ -20914,7 +21137,7 @@
20914 (redisplay_internal): Add check for USE_GTK and popup_activated. 21137 (redisplay_internal): Add check for USE_GTK and popup_activated.
20915 (redisplay_window): Add check for USE_GTK and FRAME_EXTERNAL_MENU_BAR. 21138 (redisplay_window): Add check for USE_GTK and FRAME_EXTERNAL_MENU_BAR.
20916 (redisplay_window): Add check for USE_GTK and FRAME_EXTERNAL_TOOL_BAR. 21139 (redisplay_window): Add check for USE_GTK and FRAME_EXTERNAL_TOOL_BAR.
20917 (display_menu_bar): Add check for USE_GTK 21140 (display_menu_bar): Add check for USE_GTK.
20918 21141
20919 * lisp.h (Vx_resource_name): Declare extern. 21142 * lisp.h (Vx_resource_name): Declare extern.
20920 21143
@@ -22032,7 +22255,7 @@
22032 22255
22033 * buffer.c (assoc_ignore_text_properties, Fother_buffer, Fkill_buffer) 22256 * buffer.c (assoc_ignore_text_properties, Fother_buffer, Fkill_buffer)
22034 (call_overlay_mod_hooks): Use CONSP and XCAR/XCDR. 22257 (call_overlay_mod_hooks): Use CONSP and XCAR/XCDR.
22035 (Fget_buffer_create, advance_to_char_boundary): Use BEG and BEG_BYTE; 22258 (Fget_buffer_create, advance_to_char_boundary): Use BEG and BEG_BYTE.
22036 22259
220372002-10-21 Stefan Monnier <monnier@cs.yale.edu> 222602002-10-21 Stefan Monnier <monnier@cs.yale.edu>
22038 22261
@@ -23731,8 +23954,8 @@
23731 * fns.c (Fstring_make_unibyte): Doc fix. 23954 * fns.c (Fstring_make_unibyte): Doc fix.
23732 23955
23733 * xselect.c (lisp_data_to_selection_data): If the requested type 23956 * xselect.c (lisp_data_to_selection_data): If the requested type
23734 is STRING, call string_make_unibyte to encode the selected text 23957 is STRING, call string_make_unibyte to encode the selected text
23735 as a string. 23958 as a string.
23736 23959
23737 * window.c (Fset_window_hscroll): Doc fix. 23960 * window.c (Fset_window_hscroll): Doc fix.
23738 23961
diff --git a/src/Makefile.in b/src/Makefile.in
index c8db387328d..93496ca1199 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -673,8 +673,12 @@ otherobj= $(termcapobj) lastfile.o $(mallocobj) $(allocaobj) $(widgetobj) $(LIBO
673#define MOUSE_SUPPORT ${lispsource}mouse.elc \ 673#define MOUSE_SUPPORT ${lispsource}mouse.elc \
674 ${lispsource}select.elc ${lispsource}scroll-bar.elc 674 ${lispsource}select.elc ${lispsource}scroll-bar.elc
675#else 675#else
676#ifdef HAVE_GPM
677#define MOUSE_SUPPORT ${lispsource}mouse.elc
678#else
676#define MOUSE_SUPPORT 679#define MOUSE_SUPPORT
677#endif 680#endif
681#endif
678 682
679#ifdef VMS 683#ifdef VMS
680#define VMS_SUPPORT ${lispsource}vmsproc.elc ${lispsource}vms-patch.elc 684#define VMS_SUPPORT ${lispsource}vmsproc.elc ${lispsource}vms-patch.elc
diff --git a/src/alloc.c b/src/alloc.c
index 574196059f8..cc6d1d55870 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -1759,6 +1759,8 @@ init_strings ()
1759 string_blocks = NULL; 1759 string_blocks = NULL;
1760 n_string_blocks = 0; 1760 n_string_blocks = 0;
1761 string_free_list = NULL; 1761 string_free_list = NULL;
1762 empty_unibyte_string = make_pure_string ("", 0, 0, 0);
1763 empty_multibyte_string = make_pure_string ("", 0, 0, 1);
1762} 1764}
1763 1765
1764 1766
@@ -2482,6 +2484,9 @@ make_uninit_string (length)
2482 int length; 2484 int length;
2483{ 2485{
2484 Lisp_Object val; 2486 Lisp_Object val;
2487
2488 if (!length)
2489 return empty_unibyte_string;
2485 val = make_uninit_multibyte_string (length, length); 2490 val = make_uninit_multibyte_string (length, length);
2486 STRING_SET_UNIBYTE (val); 2491 STRING_SET_UNIBYTE (val);
2487 return val; 2492 return val;
@@ -2500,6 +2505,8 @@ make_uninit_multibyte_string (nchars, nbytes)
2500 2505
2501 if (nchars < 0) 2506 if (nchars < 0)
2502 abort (); 2507 abort ();
2508 if (!nbytes)
2509 return empty_multibyte_string;
2503 2510
2504 s = allocate_string (); 2511 s = allocate_string ();
2505 allocate_string_data (s, nchars, nbytes); 2512 allocate_string_data (s, nchars, nbytes);
diff --git a/src/buffer.c b/src/buffer.c
index 15cb9f29356..dee7b04190a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -6016,7 +6016,7 @@ same format as a regular save would use. */);
6016The default is t, which means that text is invisible 6016The default is t, which means that text is invisible
6017if it has a non-nil `invisible' property. 6017if it has a non-nil `invisible' property.
6018If the value is a list, a text character is invisible if its `invisible' 6018If the value is a list, a text character is invisible if its `invisible'
6019property is an element in that list. 6019property is an element in that list (or is a list with members in common).
6020If an element is a cons cell of the form (PROP . ELLIPSIS), 6020If an element is a cons cell of the form (PROP . ELLIPSIS),
6021then characters with property value PROP are invisible, 6021then characters with property value PROP are invisible,
6022and they have an ellipsis as well if ELLIPSIS is non-nil. */); 6022and they have an ellipsis as well if ELLIPSIS is non-nil. */);
diff --git a/src/callint.c b/src/callint.c
index 84626031b3c..85ee6722710 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 37498e3b6f7..aca3383943d 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -1974,6 +1974,7 @@ the data it can't find. */)
1974 int offset = tm_diff (t, &gmt); 1974 int offset = tm_diff (t, &gmt);
1975 char *s = 0; 1975 char *s = 0;
1976 char buf[6]; 1976 char buf[6];
1977
1977#ifdef HAVE_TM_ZONE 1978#ifdef HAVE_TM_ZONE
1978 if (t->tm_zone) 1979 if (t->tm_zone)
1979 s = (char *)t->tm_zone; 1980 s = (char *)t->tm_zone;
@@ -1984,19 +1985,6 @@ the data it can't find. */)
1984#endif 1985#endif
1985#endif /* not HAVE_TM_ZONE */ 1986#endif /* not HAVE_TM_ZONE */
1986 1987
1987#if defined HAVE_TM_ZONE || defined HAVE_TZNAME
1988 if (s)
1989 {
1990 /* On Japanese w32, we can get a Japanese string as time
1991 zone name. Don't accept that. */
1992 char *p;
1993 for (p = s; *p && (isalnum ((unsigned char)*p) || *p == ' '); ++p)
1994 ;
1995 if (p == s || *p)
1996 s = NULL;
1997 }
1998#endif
1999
2000 if (!s) 1988 if (!s)
2001 { 1989 {
2002 /* No local time zone name is available; use "+-NNNN" instead. */ 1990 /* No local time zone name is available; use "+-NNNN" instead. */
@@ -2004,6 +1992,7 @@ the data it can't find. */)
2004 sprintf (buf, "%c%02d%02d", (offset < 0 ? '-' : '+'), am/60, am%60); 1992 sprintf (buf, "%c%02d%02d", (offset < 0 ? '-' : '+'), am/60, am%60);
2005 s = buf; 1993 s = buf;
2006 } 1994 }
1995
2007 return Fcons (make_number (offset), Fcons (build_string (s), Qnil)); 1996 return Fcons (make_number (offset), Fcons (build_string (s), Qnil));
2008 } 1997 }
2009 else 1998 else
@@ -3042,7 +3031,7 @@ DEFUN ("delete-and-extract-region", Fdelete_and_extract_region,
3042{ 3031{
3043 validate_region (&start, &end); 3032 validate_region (&start, &end);
3044 if (XINT (start) == XINT (end)) 3033 if (XINT (start) == XINT (end))
3045 return build_string (""); 3034 return empty_unibyte_string;
3046 return del_range_1 (XINT (start), XINT (end), 1, 1); 3035 return del_range_1 (XINT (start), XINT (end), 1, 1);
3047} 3036}
3048 3037
diff --git a/src/emacs.c b/src/emacs.c
index ac62fc420b9..079f13b2d4f 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -134,8 +134,8 @@ Lisp_Object Vinstallation_directory;
134/* Hook run by `kill-emacs' before it does really anything. */ 134/* Hook run by `kill-emacs' before it does really anything. */
135Lisp_Object Vkill_emacs_hook; 135Lisp_Object Vkill_emacs_hook;
136 136
137/* An empty lisp string. To avoid having to build any other. */ 137/* Empty lisp strings. To avoid having to build any others. */
138Lisp_Object empty_string; 138Lisp_Object empty_unibyte_string, empty_multibyte_string;
139 139
140/* Search path separator. */ 140/* Search path separator. */
141Lisp_Object Vpath_separator; 141Lisp_Object Vpath_separator;
@@ -857,17 +857,23 @@ main (argc, argv
857 So ignore --version otherwise. */ 857 So ignore --version otherwise. */
858 && initialized) 858 && initialized)
859 { 859 {
860 Lisp_Object tem; 860 Lisp_Object tem, tem2;
861 tem = Fsymbol_value (intern ("emacs-version")); 861 tem = Fsymbol_value (intern ("emacs-version"));
862 tem2 = Fsymbol_value (intern ("emacs-copyright"));
862 if (!STRINGP (tem)) 863 if (!STRINGP (tem))
863 { 864 {
864 fprintf (stderr, "Invalid value of `emacs-version'\n"); 865 fprintf (stderr, "Invalid value of `emacs-version'\n");
865 exit (1); 866 exit (1);
866 } 867 }
868 if (!STRINGP (tem2))
869 {
870 fprintf (stderr, "Invalid value of `emacs-copyright'\n");
871 exit (1);
872 }
867 else 873 else
868 { 874 {
869 printf ("GNU Emacs %s\n", SDATA (tem)); 875 printf ("GNU Emacs %s\n", SDATA (tem));
870 printf ("Copyright (C) 2007 Free Software Foundation, Inc.\n"); 876 printf ("%s\n", SDATA(tem2));
871 printf ("GNU Emacs comes with ABSOLUTELY NO WARRANTY.\n"); 877 printf ("GNU Emacs comes with ABSOLUTELY NO WARRANTY.\n");
872 printf ("You may redistribute copies of Emacs\n"); 878 printf ("You may redistribute copies of Emacs\n");
873 printf ("under the terms of the GNU General Public License.\n"); 879 printf ("under the terms of the GNU General Public License.\n");
@@ -2471,9 +2477,6 @@ see `kill-emacs-query-functions' instead.
2471The hook is not run in batch mode, i.e., if `noninteractive' is non-nil. */); 2477The hook is not run in batch mode, i.e., if `noninteractive' is non-nil. */);
2472 Vkill_emacs_hook = Qnil; 2478 Vkill_emacs_hook = Qnil;
2473 2479
2474 empty_string = build_string ("");
2475 staticpro (&empty_string);
2476
2477 DEFVAR_INT ("emacs-priority", &emacs_priority, 2480 DEFVAR_INT ("emacs-priority", &emacs_priority,
2478 doc: /* Priority for Emacs to run at. 2481 doc: /* Priority for Emacs to run at.
2479This value is effective only if set before Emacs is dumped, 2482This value is effective only if set before Emacs is dumped,
diff --git a/src/fileio.c b/src/fileio.c
index b9f9334a062..cdbd35748f1 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -6432,7 +6432,7 @@ and `read-file-name-function'. */)
6432 if (! replace_in_history) 6432 if (! replace_in_history)
6433 add_to_history = 1; 6433 add_to_history = 1;
6434 6434
6435 val = empty_string; 6435 val = empty_unibyte_string;
6436 } 6436 }
6437 6437
6438 unbind_to (count, Qnil); 6438 unbind_to (count, Qnil);
diff --git a/src/fns.c b/src/fns.c
index 8adaa0d3ea6..c25e62951dd 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -3134,7 +3134,7 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string. */)
3134 len = Flength (sequence); 3134 len = Flength (sequence);
3135 leni = XINT (len); 3135 leni = XINT (len);
3136 nargs = leni + leni - 1; 3136 nargs = leni + leni - 1;
3137 if (nargs < 0) return build_string (""); 3137 if (nargs < 0) return empty_unibyte_string;
3138 3138
3139 SAFE_ALLOCA_LISP (args, nargs); 3139 SAFE_ALLOCA_LISP (args, nargs);
3140 3140
diff --git a/src/frame.c b/src/frame.c
index 08379c7623c..a1b4e6bd85f 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -1706,7 +1706,7 @@ and returns whatever that function returns. */)
1706 f = SELECTED_FRAME (); 1706 f = SELECTED_FRAME ();
1707 x = y = Qnil; 1707 x = y = Qnil;
1708 1708
1709#ifdef HAVE_MOUSE 1709#if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1710 /* It's okay for the hook to refrain from storing anything. */ 1710 /* It's okay for the hook to refrain from storing anything. */
1711 if (FRAME_TERMINAL (f)->mouse_position_hook) 1711 if (FRAME_TERMINAL (f)->mouse_position_hook)
1712 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1, 1712 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
@@ -1750,7 +1750,7 @@ and nil for X and Y. */)
1750 f = SELECTED_FRAME (); 1750 f = SELECTED_FRAME ();
1751 x = y = Qnil; 1751 x = y = Qnil;
1752 1752
1753#ifdef HAVE_MOUSE 1753#if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1754 /* It's okay for the hook to refrain from storing anything. */ 1754 /* It's okay for the hook to refrain from storing anything. */
1755 if (FRAME_TERMINAL (f)->mouse_position_hook) 1755 if (FRAME_TERMINAL (f)->mouse_position_hook)
1756 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1, 1756 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
@@ -1837,6 +1837,13 @@ before calling this function on it, like this.
1837 Fselect_frame (frame); 1837 Fselect_frame (frame);
1838 mouse_moveto (XINT (x), XINT (y)); 1838 mouse_moveto (XINT (x), XINT (y));
1839 } 1839 }
1840#else
1841#ifdef HAVE_GPM
1842 {
1843 Fselect_frame (frame);
1844 term_mouse_moveto (XINT (x), XINT (y));
1845 }
1846#endif
1840#endif 1847#endif
1841#endif 1848#endif
1842 1849
diff --git a/src/image.c b/src/image.c
index fbd2f4e6a51..b53fe01d7f9 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
@@ -1877,7 +1901,6 @@ lookup_image (f, spec)
1877{ 1901{
1878 struct image_cache *c; 1902 struct image_cache *c;
1879 struct image *img; 1903 struct image *img;
1880 int i;
1881 unsigned hash; 1904 unsigned hash;
1882 struct gcpro gcpro1; 1905 struct gcpro gcpro1;
1883 EMACS_TIME now; 1906 EMACS_TIME now;
@@ -1893,12 +1916,7 @@ lookup_image (f, spec)
1893 1916
1894 /* Look up SPEC in the hash table of the image cache. */ 1917 /* Look up SPEC in the hash table of the image cache. */
1895 hash = sxhash (spec, 0); 1918 hash = sxhash (spec, 0);
1896 i = hash % IMAGE_CACHE_BUCKETS_SIZE; 1919 img = search_image_cache (f, spec, hash);
1897
1898 for (img = c->buckets[i]; img; img = img->next)
1899 if (img->hash == hash && !NILP (Fequal (img->spec, spec)))
1900 break;
1901
1902 if (img && img->load_failed_p) 1920 if (img && img->load_failed_p)
1903 { 1921 {
1904 free_image (f, img); 1922 free_image (f, img);
@@ -3963,9 +3981,6 @@ xpm_load (f, img)
3963 attrs.valuemask |= XpmCloseness; 3981 attrs.valuemask |= XpmCloseness;
3964#endif /* not XpmAllocCloseColors */ 3982#endif /* not XpmAllocCloseColors */
3965#endif /* ALLOC_XPM_COLORS */ 3983#endif /* ALLOC_XPM_COLORS */
3966#ifdef ALLOC_XPM_COLORS
3967 xpm_init_color_cache (f, &attrs);
3968#endif
3969 3984
3970 /* If image specification contains symbolic color definitions, add 3985 /* If image specification contains symbolic color definitions, add
3971 these to `attrs'. */ 3986 these to `attrs'. */
diff --git a/src/keyboard.c b/src/keyboard.c
index 576afd29843..9786449a003 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -1327,7 +1327,7 @@ cmd_error_internal (data, context)
1327 /* Use user's specified output function if any. */ 1327 /* Use user's specified output function if any. */
1328 if (!NILP (Vcommand_error_function)) 1328 if (!NILP (Vcommand_error_function))
1329 call3 (Vcommand_error_function, data, 1329 call3 (Vcommand_error_function, data,
1330 build_string (context ? context : ""), 1330 context ? build_string (context) : empty_unibyte_string,
1331 Vsignaling_function); 1331 Vsignaling_function);
1332 /* If the window system or terminal frame hasn't been initialized 1332 /* If the window system or terminal frame hasn't been initialized
1333 yet, or we're not interactive, write the message to stderr and exit. */ 1333 yet, or we're not interactive, write the message to stderr and exit. */
@@ -4029,6 +4029,9 @@ discard_mouse_events ()
4029#ifdef WINDOWSNT 4029#ifdef WINDOWSNT
4030 || sp->kind == W32_SCROLL_BAR_CLICK_EVENT 4030 || sp->kind == W32_SCROLL_BAR_CLICK_EVENT
4031#endif 4031#endif
4032#ifdef HAVE_GPM
4033 || sp->kind == GPM_CLICK_EVENT
4034#endif
4032 || sp->kind == SCROLL_BAR_CLICK_EVENT) 4035 || sp->kind == SCROLL_BAR_CLICK_EVENT)
4033 { 4036 {
4034 sp->kind = NO_EVENT; 4037 sp->kind = NO_EVENT;
diff --git a/src/keymap.c b/src/keymap.c
index 47e3f50786b..904e3c89d55 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -2181,7 +2181,7 @@ spaces are put between sequence elements, etc. */)
2181 len += 2; 2181 len += 2;
2182 } 2182 }
2183 else if (len == 0) 2183 else if (len == 0)
2184 return empty_string; 2184 return empty_unibyte_string;
2185 return Fconcat (len - 1, args); 2185 return Fconcat (len - 1, args);
2186 } 2186 }
2187 2187
diff --git a/src/lisp.h b/src/lisp.h
index 82036f3030e..7bf59d0f55a 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -701,7 +701,10 @@ extern int string_bytes P_ ((struct Lisp_String *));
701#endif /* not GC_CHECK_STRING_BYTES */ 701#endif /* not GC_CHECK_STRING_BYTES */
702 702
703/* Mark STR as a unibyte string. */ 703/* Mark STR as a unibyte string. */
704#define STRING_SET_UNIBYTE(STR) (XSTRING (STR)->size_byte = -1) 704#define STRING_SET_UNIBYTE(STR) \
705 do { if (EQ (STR, empty_multibyte_string)) \
706 (STR) = empty_unibyte_string; \
707 else XSTRING (STR)->size_byte = -1; } while (0)
705 708
706/* Get text properties. */ 709/* Get text properties. */
707#define STRING_INTERVALS(STR) (XSTRING (STR)->intervals + 0) 710#define STRING_INTERVALS(STR) (XSTRING (STR)->intervals + 0)
@@ -3065,7 +3068,8 @@ extern void syms_of_frame P_ ((void));
3065/* defined in emacs.c */ 3068/* defined in emacs.c */
3066extern Lisp_Object decode_env_path P_ ((char *, char *)); 3069extern Lisp_Object decode_env_path P_ ((char *, char *));
3067extern Lisp_Object Vinvocation_name, Vinvocation_directory; 3070extern Lisp_Object Vinvocation_name, Vinvocation_directory;
3068extern Lisp_Object Vinstallation_directory, empty_string; 3071extern Lisp_Object Vinstallation_directory;
3072extern Lisp_Object empty_unibyte_string, empty_multibyte_string;
3069EXFUN (Fkill_emacs, 1); 3073EXFUN (Fkill_emacs, 1);
3070#if HAVE_SETLOCALE 3074#if HAVE_SETLOCALE
3071void fixup_locale P_ ((void)); 3075void fixup_locale P_ ((void));
diff --git a/src/lread.c b/src/lread.c
index 49a56a0e935..5f4d69a3312 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1201,7 +1201,7 @@ openp (path, str, suffixes, storeptr, predicate)
1201 fn = (char *) alloca (fn_size = 100 + want_size); 1201 fn = (char *) alloca (fn_size = 100 + want_size);
1202 1202
1203 /* Loop over suffixes. */ 1203 /* Loop over suffixes. */
1204 for (tail = NILP (suffixes) ? Fcons (build_string (""), Qnil) : suffixes; 1204 for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : suffixes;
1205 CONSP (tail); tail = XCDR (tail)) 1205 CONSP (tail); tail = XCDR (tail))
1206 { 1206 {
1207 int lsuffix = SBYTES (XCAR (tail)); 1207 int lsuffix = SBYTES (XCAR (tail));
@@ -4072,8 +4072,7 @@ and, if so, which suffixes they should try to append to the file name
4072in order to do so. However, if you want to customize which suffixes 4072in order to do so. However, if you want to customize which suffixes
4073the loading functions recognize as compression suffixes, you should 4073the loading functions recognize as compression suffixes, you should
4074customize `jka-compr-load-suffixes' rather than the present variable. */); 4074customize `jka-compr-load-suffixes' rather than the present variable. */);
4075 /* We don't use empty_string because it's not initialized yet. */ 4075 Vload_file_rep_suffixes = Fcons (empty_unibyte_string, Qnil);
4076 Vload_file_rep_suffixes = Fcons (build_string (""), Qnil);
4077 4076
4078 DEFVAR_BOOL ("load-in-progress", &load_in_progress, 4077 DEFVAR_BOOL ("load-in-progress", &load_in_progress,
4079 doc: /* Non-nil iff inside of `load'. */); 4078 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 4c454399afb..cd02552df7a 100644
--- a/src/macfns.c
+++ b/src/macfns.c
@@ -217,9 +217,6 @@ void x_explicitly_set_name P_ ((struct frame *, Lisp_Object, Lisp_Object));
217void x_set_menu_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object)); 217void x_set_menu_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
218void x_set_title P_ ((struct frame *, Lisp_Object, Lisp_Object)); 218void x_set_title P_ ((struct frame *, Lisp_Object, Lisp_Object));
219void x_set_tool_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object)); 219void x_set_tool_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
220
221extern void mac_get_window_bounds P_ ((struct frame *, Rect *, Rect *));
222
223 220
224 221
225/* Store the screen positions of frame F into XPTR and YPTR. 222/* Store the screen positions of frame F into XPTR and YPTR.
@@ -2262,11 +2259,11 @@ mac_window (f, window_prompting, minibuffer_only)
2262 FRAME_MAC_WINDOW (f) = NULL; 2259 FRAME_MAC_WINDOW (f) = NULL;
2263 } 2260 }
2264 } 2261 }
2265#else 2262#else /* !TARGET_API_MAC_CARBON */
2266 FRAME_MAC_WINDOW (f) 2263 FRAME_MAC_WINDOW (f)
2267 = NewCWindow (NULL, &r, "\p", false, zoomDocProc, 2264 = NewCWindow (NULL, &r, "\p", false, zoomDocProc,
2268 (WindowPtr) -1, 1, (long) f->output_data.mac); 2265 (WindowRef) -1, 1, (long) f->output_data.mac);
2269#endif 2266#endif /* !TARGET_API_MAC_CARBON */
2270 /* so that update events can find this mac_output struct */ 2267 /* so that update events can find this mac_output struct */
2271 f->output_data.mac->mFP = f; /* point back to emacs frame */ 2268 f->output_data.mac->mFP = f; /* point back to emacs frame */
2272 2269
@@ -3123,7 +3120,7 @@ If omitted or nil, that stands for the selected frame's display. */)
3123 UNBLOCK_INPUT; 3120 UNBLOCK_INPUT;
3124 } 3121 }
3125#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020 3122#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
3126 else 3123 else /* CGDisplayScreenSize == NULL */
3127#endif 3124#endif
3128#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */ 3125#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */
3129#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020 3126#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020
@@ -3160,7 +3157,7 @@ If omitted or nil, that stands for the selected frame's display. */)
3160 UNBLOCK_INPUT; 3157 UNBLOCK_INPUT;
3161 } 3158 }
3162#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020 3159#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
3163 else 3160 else /* CGDisplayScreenSize == NULL */
3164#endif 3161#endif
3165#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */ 3162#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */
3166#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020 3163#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020
@@ -4069,8 +4066,12 @@ compute_tip_xy (f, parms, dx, dy, width, height, root_x, root_y)
4069 Point mouse_pos; 4066 Point mouse_pos;
4070 4067
4071 BLOCK_INPUT; 4068 BLOCK_INPUT;
4069#if TARGET_API_MAC_CARBON
4070 GetGlobalMouse (&mouse_pos);
4071#else
4072 GetMouse (&mouse_pos); 4072 GetMouse (&mouse_pos);
4073 LocalToGlobal (&mouse_pos); 4073 LocalToGlobal (&mouse_pos);
4074#endif
4074 *root_x = mouse_pos.h; 4075 *root_x = mouse_pos.h;
4075 *root_y = mouse_pos.v; 4076 *root_y = mouse_pos.v;
4076 UNBLOCK_INPUT; 4077 UNBLOCK_INPUT;
diff --git a/src/macgui.h b/src/macgui.h
index 1348fe479cb..990765593e1 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>
@@ -117,7 +117,7 @@ typedef unsigned long Time;
117#endif 117#endif
118#endif 118#endif
119 119
120typedef WindowPtr Window; 120typedef WindowRef Window;
121typedef GWorldPtr Pixmap; 121typedef GWorldPtr Pixmap;
122 122
123#define Cursor ThemeCursor 123#define Cursor ThemeCursor
diff --git a/src/macmenu.c b/src/macmenu.c
index a23e516dd07..1eb0b16cd95 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 0b8fec3a089..f8c79d1c865 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -35,12 +35,7 @@ Boston, MA 02110-1301, USA. */
35#include <alloca.h> 35#include <alloca.h>
36#endif 36#endif
37 37
38#if TARGET_API_MAC_CARBON 38#if !TARGET_API_MAC_CARBON
39/* USE_CARBON_EVENTS determines if the Carbon Event Manager is used to
40 obtain events from the event queue. If set to 0, WaitNextEvent is
41 used instead. */
42#define USE_CARBON_EVENTS 1
43#else /* not TARGET_API_MAC_CARBON */
44#include <Quickdraw.h> 39#include <Quickdraw.h>
45#include <ToolUtils.h> 40#include <ToolUtils.h>
46#include <Sound.h> 41#include <Sound.h>
@@ -263,7 +258,7 @@ static void x_scroll_bar_report_motion P_ ((struct frame **, Lisp_Object *,
263 Lisp_Object *, Lisp_Object *, 258 Lisp_Object *, Lisp_Object *,
264 unsigned long *)); 259 unsigned long *));
265 260
266static int is_emacs_window P_ ((WindowPtr)); 261static int is_emacs_window P_ ((WindowRef));
267static XCharStruct *mac_per_char_metric P_ ((XFontStruct *, XChar2b *, int)); 262static XCharStruct *mac_per_char_metric P_ ((XFontStruct *, XChar2b *, int));
268static void XSetFont P_ ((Display *, GC, XFontStruct *)); 263static void XSetFont P_ ((Display *, GC, XFontStruct *));
269static struct terminal *mac_create_terminal P_ ((struct mac_display_info *dpyinfo)); 264static struct terminal *mac_create_terminal P_ ((struct mac_display_info *dpyinfo));
@@ -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 955
949 956
950static void 957static void
951mac_invert_rectangle (f, x, y, width, height) 958mac_draw_image_string_atsui (f, gc, x, y, buf, nchars, bg_width,
952 struct frame *f; 959 overstrike_p, bytes_per_char)
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
968
969static void
970mac_draw_string_common (f, gc, x, y, buf, nchars, bg_width,
971 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
@@ -4368,7 +4374,7 @@ x_detect_focus_change (dpyinfo, event, bufp)
4368{ 4374{
4369 struct frame *frame; 4375 struct frame *frame;
4370 4376
4371 frame = mac_window_to_frame ((WindowPtr) event->message); 4377 frame = mac_window_to_frame ((WindowRef) event->message);
4372 if (! frame) 4378 if (! frame)
4373 return; 4379 return;
4374 4380
@@ -4608,8 +4614,14 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time)
4608 the frame are divided into. */ 4614 the frame are divided into. */
4609 Point mouse_pos; 4615 Point mouse_pos;
4610 4616
4617#if TARGET_API_MAC_CARBON
4618 GetGlobalMouse (&mouse_pos);
4619 mouse_pos.h -= f1->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f1);
4620 mouse_pos.v -= f1->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f1);
4621#else
4611 SetPortWindowPort (FRAME_MAC_WINDOW (f1)); 4622 SetPortWindowPort (FRAME_MAC_WINDOW (f1));
4612 GetMouse (&mouse_pos); 4623 GetMouse (&mouse_pos);
4624#endif
4613 remember_mouse_glyph (f1, mouse_pos.h, mouse_pos.v, 4625 remember_mouse_glyph (f1, mouse_pos.h, mouse_pos.v,
4614 &last_mouse_glyph); 4626 &last_mouse_glyph);
4615 last_mouse_glyph_frame = f1; 4627 last_mouse_glyph_frame = f1;
@@ -4639,14 +4651,14 @@ static OSStatus set_scroll_bar_timer P_ ((EventTimerInterval));
4639static int control_part_code_to_scroll_bar_part P_ ((ControlPartCode)); 4651static int control_part_code_to_scroll_bar_part P_ ((ControlPartCode));
4640static void construct_scroll_bar_click P_ ((struct scroll_bar *, int, 4652static void construct_scroll_bar_click P_ ((struct scroll_bar *, int,
4641 struct input_event *)); 4653 struct input_event *));
4642static OSStatus get_control_part_bounds P_ ((ControlHandle, ControlPartCode, 4654static OSStatus get_control_part_bounds P_ ((ControlRef, ControlPartCode,
4643 Rect *)); 4655 Rect *));
4644static void x_scroll_bar_handle_press P_ ((struct scroll_bar *, 4656static void x_scroll_bar_handle_press P_ ((struct scroll_bar *,
4645 ControlPartCode, Point, 4657 ControlPartCode, Point,
4646 struct input_event *)); 4658 struct input_event *));
4647static void x_scroll_bar_handle_release P_ ((struct scroll_bar *, 4659static void x_scroll_bar_handle_release P_ ((struct scroll_bar *,
4648 struct input_event *)); 4660 struct input_event *));
4649static void x_scroll_bar_handle_drag P_ ((WindowPtr, struct scroll_bar *, 4661static void x_scroll_bar_handle_drag P_ ((WindowRef, struct scroll_bar *,
4650 Point, struct input_event *)); 4662 Point, struct input_event *));
4651static void x_set_toolkit_scroll_bar_thumb P_ ((struct scroll_bar *, 4663static void x_set_toolkit_scroll_bar_thumb P_ ((struct scroll_bar *,
4652 int, int, int)); 4664 int, int, int));
@@ -4739,7 +4751,7 @@ construct_scroll_bar_click (bar, part, bufp)
4739 4751
4740static OSStatus 4752static OSStatus
4741get_control_part_bounds (ch, part_code, rect) 4753get_control_part_bounds (ch, part_code, rect)
4742 ControlHandle ch; 4754 ControlRef ch;
4743 ControlPartCode part_code; 4755 ControlPartCode part_code;
4744 Rect *rect; 4756 Rect *rect;
4745{ 4757{
@@ -4769,7 +4781,7 @@ x_scroll_bar_handle_press (bar, part_code, mouse_pos, bufp)
4769 if (part != scroll_bar_handle) 4781 if (part != scroll_bar_handle)
4770 { 4782 {
4771 construct_scroll_bar_click (bar, part, bufp); 4783 construct_scroll_bar_click (bar, part, bufp);
4772 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar), part_code); 4784 HiliteControl (SCROLL_BAR_CONTROL_REF (bar), part_code);
4773 set_scroll_bar_timer (SCROLL_BAR_FIRST_DELAY); 4785 set_scroll_bar_timer (SCROLL_BAR_FIRST_DELAY);
4774 bar->dragging = Qnil; 4786 bar->dragging = Qnil;
4775 } 4787 }
@@ -4777,7 +4789,7 @@ x_scroll_bar_handle_press (bar, part_code, mouse_pos, bufp)
4777 { 4789 {
4778 Rect r; 4790 Rect r;
4779 4791
4780 get_control_part_bounds (SCROLL_BAR_CONTROL_HANDLE (bar), 4792 get_control_part_bounds (SCROLL_BAR_CONTROL_REF (bar),
4781 kControlIndicatorPart, &r); 4793 kControlIndicatorPart, &r);
4782 XSETINT (bar->dragging, - (mouse_pos.v - r.top) - 1); 4794 XSETINT (bar->dragging, - (mouse_pos.v - r.top) - 1);
4783 } 4795 }
@@ -4795,7 +4807,7 @@ x_scroll_bar_handle_release (bar, bufp)
4795 || (INTEGERP (bar->dragging) && XINT (bar->dragging) >= 0)) 4807 || (INTEGERP (bar->dragging) && XINT (bar->dragging) >= 0))
4796 construct_scroll_bar_click (bar, scroll_bar_end_scroll, bufp); 4808 construct_scroll_bar_click (bar, scroll_bar_end_scroll, bufp);
4797 4809
4798 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar), 0); 4810 HiliteControl (SCROLL_BAR_CONTROL_REF (bar), 0);
4799 set_scroll_bar_timer (kEventDurationForever); 4811 set_scroll_bar_timer (kEventDurationForever);
4800 4812
4801 last_scroll_bar_part = -1; 4813 last_scroll_bar_part = -1;
@@ -4805,19 +4817,19 @@ x_scroll_bar_handle_release (bar, bufp)
4805 4817
4806static void 4818static void
4807x_scroll_bar_handle_drag (win, bar, mouse_pos, bufp) 4819x_scroll_bar_handle_drag (win, bar, mouse_pos, bufp)
4808 WindowPtr win; 4820 WindowRef win;
4809 struct scroll_bar *bar; 4821 struct scroll_bar *bar;
4810 Point mouse_pos; 4822 Point mouse_pos;
4811 struct input_event *bufp; 4823 struct input_event *bufp;
4812{ 4824{
4813 ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar); 4825 ControlRef ch = SCROLL_BAR_CONTROL_REF (bar);
4814 4826
4815 if (last_scroll_bar_part == scroll_bar_handle) 4827 if (last_scroll_bar_part == scroll_bar_handle)
4816 { 4828 {
4817 int top, top_range; 4829 int top, top_range;
4818 Rect r; 4830 Rect r;
4819 4831
4820 get_control_part_bounds (SCROLL_BAR_CONTROL_HANDLE (bar), 4832 get_control_part_bounds (SCROLL_BAR_CONTROL_REF (bar),
4821 kControlIndicatorPart, &r); 4833 kControlIndicatorPart, &r);
4822 4834
4823 if (INTEGERP (bar->dragging) && XINT (bar->dragging) < 0) 4835 if (INTEGERP (bar->dragging) && XINT (bar->dragging) < 0)
@@ -4865,13 +4877,13 @@ x_scroll_bar_handle_drag (win, bar, mouse_pos, bufp)
4865 } 4877 }
4866 4878
4867 if (unhilite_p) 4879 if (unhilite_p)
4868 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar), 0); 4880 HiliteControl (SCROLL_BAR_CONTROL_REF (bar), 0);
4869 else if (part != last_scroll_bar_part 4881 else if (part != last_scroll_bar_part
4870 || scroll_bar_timer_event_posted_p) 4882 || scroll_bar_timer_event_posted_p)
4871 { 4883 {
4872 construct_scroll_bar_click (bar, part, bufp); 4884 construct_scroll_bar_click (bar, part, bufp);
4873 last_scroll_bar_part = part; 4885 last_scroll_bar_part = part;
4874 HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar), part_code); 4886 HiliteControl (SCROLL_BAR_CONTROL_REF (bar), part_code);
4875 set_scroll_bar_timer (SCROLL_BAR_CONTINUOUS_DELAY); 4887 set_scroll_bar_timer (SCROLL_BAR_CONTINUOUS_DELAY);
4876 } 4888 }
4877 } 4889 }
@@ -4885,7 +4897,7 @@ x_set_toolkit_scroll_bar_thumb (bar, portion, position, whole)
4885 struct scroll_bar *bar; 4897 struct scroll_bar *bar;
4886 int portion, position, whole; 4898 int portion, position, whole;
4887{ 4899{
4888 ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar); 4900 ControlRef ch = SCROLL_BAR_CONTROL_REF (bar);
4889 int value, viewsize, maximum; 4901 int value, viewsize, maximum;
4890 4902
4891 if (XINT (bar->track_height) == 0) 4903 if (XINT (bar->track_height) == 0)
@@ -4944,7 +4956,7 @@ x_scroll_bar_create (w, top, left, width, height, disp_top, disp_height)
4944 struct scroll_bar *bar 4956 struct scroll_bar *bar
4945 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil)); 4957 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil));
4946 Rect r; 4958 Rect r;
4947 ControlHandle ch; 4959 ControlRef ch;
4948 4960
4949 BLOCK_INPUT; 4961 BLOCK_INPUT;
4950 4962
@@ -4968,7 +4980,7 @@ x_scroll_bar_create (w, top, left, width, height, disp_top, disp_height)
4968 ch = NewControl (FRAME_MAC_WINDOW (f), &r, "\p", width < disp_height, 4980 ch = NewControl (FRAME_MAC_WINDOW (f), &r, "\p", width < disp_height,
4969 0, 0, 0, scrollBarProc, (long) bar); 4981 0, 0, 0, scrollBarProc, (long) bar);
4970#endif 4982#endif
4971 SET_SCROLL_BAR_CONTROL_HANDLE (bar, ch); 4983 SET_SCROLL_BAR_CONTROL_REF (bar, ch);
4972 4984
4973 XSETWINDOW (bar->window, w); 4985 XSETWINDOW (bar->window, w);
4974 XSETINT (bar->top, top); 4986 XSETINT (bar->top, top);
@@ -5018,7 +5030,7 @@ x_scroll_bar_set_handle (bar, start, end, rebuild)
5018 int rebuild; 5030 int rebuild;
5019{ 5031{
5020 int dragging = ! NILP (bar->dragging); 5032 int dragging = ! NILP (bar->dragging);
5021 ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar); 5033 ControlRef ch = SCROLL_BAR_CONTROL_REF (bar);
5022 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); 5034 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
5023 int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); 5035 int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height));
5024 int length = end - start; 5036 int length = end - start;
@@ -5087,7 +5099,7 @@ x_scroll_bar_remove (bar)
5087 mac_prepare_for_quickdraw (f); 5099 mac_prepare_for_quickdraw (f);
5088#endif 5100#endif
5089 /* Destroy the Mac scroll bar control */ 5101 /* Destroy the Mac scroll bar control */
5090 DisposeControl (SCROLL_BAR_CONTROL_HANDLE (bar)); 5102 DisposeControl (SCROLL_BAR_CONTROL_REF (bar));
5091 5103
5092 /* Disassociate this scroll bar from its window. */ 5104 /* Disassociate this scroll bar from its window. */
5093 XWINDOW (bar->window)->vertical_scroll_bar = Qnil; 5105 XWINDOW (bar->window)->vertical_scroll_bar = Qnil;
@@ -5165,10 +5177,10 @@ XTset_vertical_scroll_bar (w, portion, whole, position)
5165 else 5177 else
5166 { 5178 {
5167 /* It may just need to be moved and resized. */ 5179 /* It may just need to be moved and resized. */
5168 ControlHandle ch; 5180 ControlRef ch;
5169 5181
5170 bar = XSCROLL_BAR (w->vertical_scroll_bar); 5182 bar = XSCROLL_BAR (w->vertical_scroll_bar);
5171 ch = SCROLL_BAR_CONTROL_HANDLE (bar); 5183 ch = SCROLL_BAR_CONTROL_REF (bar);
5172 5184
5173 BLOCK_INPUT; 5185 BLOCK_INPUT;
5174 5186
@@ -5224,7 +5236,7 @@ XTset_vertical_scroll_bar (w, portion, whole, position)
5224 } 5236 }
5225 else 5237 else
5226 { 5238 {
5227 ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar); 5239 ControlRef ch = SCROLL_BAR_CONTROL_REF (bar);
5228 Rect r0, r1; 5240 Rect r0, r1;
5229 5241
5230 BLOCK_INPUT; 5242 BLOCK_INPUT;
@@ -5501,19 +5513,24 @@ x_scroll_bar_report_motion (fp, bar_window, part, x, y, time)
5501 unsigned long *time; 5513 unsigned long *time;
5502{ 5514{
5503 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); 5515 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar);
5504 ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar); 5516 ControlRef ch = SCROLL_BAR_CONTROL_REF (bar);
5505#if TARGET_API_MAC_CARBON 5517#if TARGET_API_MAC_CARBON
5506 WindowPtr wp = GetControlOwner (ch); 5518 WindowRef wp = GetControlOwner (ch);
5507#else 5519#else
5508 WindowPtr wp = (*ch)->contrlOwner; 5520 WindowRef wp = (*ch)->contrlOwner;
5509#endif 5521#endif
5510 Point mouse_pos; 5522 Point mouse_pos;
5511 struct frame *f = mac_window_to_frame (wp); 5523 struct frame *f = mac_window_to_frame (wp);
5512 int win_y, top_range; 5524 int win_y, top_range;
5513 5525
5526#if TARGET_API_MAC_CARBON
5527 GetGlobalMouse (&mouse_pos);
5528 mouse_pos.h -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f);
5529 mouse_pos.v -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f);
5530#else
5514 SetPortWindowPort (wp); 5531 SetPortWindowPort (wp);
5515
5516 GetMouse (&mouse_pos); 5532 GetMouse (&mouse_pos);
5533#endif
5517 5534
5518 win_y = mouse_pos.v - XINT (bar->top); 5535 win_y = mouse_pos.v - XINT (bar->top);
5519 top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); 5536 top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height));
@@ -6141,9 +6158,7 @@ x_set_offset (f, xoff, yoff, change_gravity)
6141 ConstrainWindowToScreen (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn, 6158 ConstrainWindowToScreen (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn,
6142 kWindowConstrainMoveRegardlessOfFit 6159 kWindowConstrainMoveRegardlessOfFit
6143 | kWindowConstrainAllowPartial, NULL, NULL); 6160 | kWindowConstrainAllowPartial, NULL, NULL);
6144#if USE_CARBON_EVENTS
6145 if (!NILP (tip_frame) && XFRAME (tip_frame) == f) 6161 if (!NILP (tip_frame) && XFRAME (tip_frame) == f)
6146#endif
6147 mac_handle_origin_change (f); 6162 mac_handle_origin_change (f);
6148#else 6163#else
6149 { 6164 {
@@ -6219,7 +6234,7 @@ x_set_window_size (f, change_gravity, cols, rows)
6219 6234
6220 SizeWindow (FRAME_MAC_WINDOW (f), pixelwidth, pixelheight, 0); 6235 SizeWindow (FRAME_MAC_WINDOW (f), pixelwidth, pixelheight, 0);
6221 6236
6222#if USE_CARBON_EVENTS 6237#if TARGET_API_MAC_CARBON
6223 if (!NILP (tip_frame) && f == XFRAME (tip_frame)) 6238 if (!NILP (tip_frame) && f == XFRAME (tip_frame))
6224#endif 6239#endif
6225 mac_handle_size_change (f, pixelwidth, pixelheight); 6240 mac_handle_size_change (f, pixelwidth, pixelheight);
@@ -6266,17 +6281,11 @@ x_set_mouse_pixel_position (f, pix_x, pix_y)
6266 int pix_x, pix_y; 6281 int pix_x, pix_y;
6267{ 6282{
6268#ifdef MAC_OSX 6283#ifdef MAC_OSX
6269 Point p; 6284 pix_x += f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f);
6270 CGPoint point; 6285 pix_y += f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f);
6271 6286
6272 BLOCK_INPUT; 6287 BLOCK_INPUT;
6273 SetPortWindowPort (FRAME_MAC_WINDOW (f)); 6288 CGWarpMouseCursorPosition (CGPointMake (pix_x, pix_y));
6274 p.h = pix_x;
6275 p.v = pix_y;
6276 LocalToGlobal (&p);
6277 point.x = p.h;
6278 point.y = p.v;
6279 CGWarpMouseCursorPosition (point);
6280 UNBLOCK_INPUT; 6289 UNBLOCK_INPUT;
6281#else 6290#else
6282#if 0 /* MAC_TODO: LMSetMouseLocation and CursorDeviceMoveTo are non-Carbon */ 6291#if 0 /* MAC_TODO: LMSetMouseLocation and CursorDeviceMoveTo are non-Carbon */
@@ -6358,7 +6367,7 @@ static void
6358mac_handle_visibility_change (f) 6367mac_handle_visibility_change (f)
6359 struct frame *f; 6368 struct frame *f;
6360{ 6369{
6361 WindowPtr wp = FRAME_MAC_WINDOW (f); 6370 WindowRef wp = FRAME_MAC_WINDOW (f);
6362 int visible = 0, iconified = 0; 6371 int visible = 0, iconified = 0;
6363 struct input_event buf; 6372 struct input_event buf;
6364 6373
@@ -6426,32 +6435,7 @@ x_make_frame_visible (f)
6426 before the window gets really visible. */ 6435 before the window gets really visible. */
6427 if (! FRAME_ICONIFIED_P (f) 6436 if (! FRAME_ICONIFIED_P (f)
6428 && ! f->output_data.mac->asked_for_visible) 6437 && ! f->output_data.mac->asked_for_visible)
6429 { 6438 x_set_offset (f, f->left_pos, f->top_pos, 0);
6430#if TARGET_API_MAC_CARBON
6431 if (!(FRAME_SIZE_HINTS (f)->flags & (USPosition | PPosition)))
6432 {
6433 struct frame *sf = SELECTED_FRAME ();
6434 if (!FRAME_MAC_P (sf))
6435 RepositionWindow (FRAME_MAC_WINDOW (f), NULL,
6436 kWindowCenterOnMainScreen);
6437 else
6438 RepositionWindow (FRAME_MAC_WINDOW (f),
6439 FRAME_MAC_WINDOW (sf),
6440#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
6441 kWindowCascadeStartAtParentWindowScreen
6442#else
6443 kWindowCascadeOnParentWindowScreen
6444#endif
6445 );
6446#if USE_CARBON_EVENTS
6447 if (!NILP (tip_frame) && f == XFRAME (tip_frame))
6448#endif
6449 mac_handle_origin_change (f);
6450 }
6451 else
6452#endif
6453 x_set_offset (f, f->left_pos, f->top_pos, 0);
6454 }
6455 6439
6456 f->output_data.mac->asked_for_visible = 1; 6440 f->output_data.mac->asked_for_visible = 1;
6457 6441
@@ -6525,18 +6509,20 @@ x_make_frame_invisible (f)
6525 6509
6526 BLOCK_INPUT; 6510 BLOCK_INPUT;
6527 6511
6512#if !TARGET_API_MAC_CARBON
6528 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim 6513 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
6529 that the current position of the window is user-specified, rather than 6514 that the current position of the window is user-specified, rather than
6530 program-specified, so that when the window is mapped again, it will be 6515 program-specified, so that when the window is mapped again, it will be
6531 placed at the same location, without forcing the user to position it 6516 placed at the same location, without forcing the user to position it
6532 by hand again (they have already done that once for this window.) */ 6517 by hand again (they have already done that once for this window.) */
6533 x_wm_set_size_hint (f, (long) 0, 1); 6518 x_wm_set_size_hint (f, (long) 0, 1);
6519#endif
6534 6520
6535 HideWindow (FRAME_MAC_WINDOW (f)); 6521 HideWindow (FRAME_MAC_WINDOW (f));
6536 6522
6537 UNBLOCK_INPUT; 6523 UNBLOCK_INPUT;
6538 6524
6539#if !USE_CARBON_EVENTS 6525#if !TARGET_API_MAC_CARBON
6540 mac_handle_visibility_change (f); 6526 mac_handle_visibility_change (f);
6541#endif 6527#endif
6542} 6528}
@@ -6575,7 +6561,7 @@ x_iconify_frame (f)
6575 if (err != noErr) 6561 if (err != noErr)
6576 error ("Can't notify window manager of iconification"); 6562 error ("Can't notify window manager of iconification");
6577 6563
6578#if !USE_CARBON_EVENTS 6564#if !TARGET_API_MAC_CARBON
6579 mac_handle_visibility_change (f); 6565 mac_handle_visibility_change (f);
6580#endif 6566#endif
6581} 6567}
@@ -6588,7 +6574,7 @@ x_free_frame_resources (f)
6588 struct frame *f; 6574 struct frame *f;
6589{ 6575{
6590 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); 6576 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f);
6591 WindowPtr wp = FRAME_MAC_WINDOW (f); 6577 WindowRef wp = FRAME_MAC_WINDOW (f);
6592 6578
6593 BLOCK_INPUT; 6579 BLOCK_INPUT;
6594 6580
@@ -8723,16 +8709,93 @@ x_find_ccl_program (fontp)
8723 possible. */ 8709 possible. */
8724static int font_panel_shown_p = 0; 8710static int font_panel_shown_p = 0;
8725 8711
8712extern Lisp_Object Qfont;
8713static Lisp_Object Qpanel_closed, Qselection;
8714
8715static OSStatus mac_store_event_ref_as_apple_event P_ ((AEEventClass, AEEventID,
8716 Lisp_Object,
8717 Lisp_Object,
8718 EventRef, UInt32,
8719 const EventParamName *,
8720 const EventParamType *));
8721
8726int 8722int
8727mac_font_panel_visible_p () 8723mac_font_panel_visible_p ()
8728{ 8724{
8729 return font_panel_shown_p && FPIsFontPanelVisible (); 8725 return font_panel_shown_p && FPIsFontPanelVisible ();
8730} 8726}
8731 8727
8728static pascal OSStatus
8729mac_handle_font_event (next_handler, event, data)
8730 EventHandlerCallRef next_handler;
8731 EventRef event;
8732 void *data;
8733{
8734 OSStatus result, err;
8735 Lisp_Object id_key;
8736 int num_params;
8737 const EventParamName *names;
8738 const EventParamType *types;
8739 static const EventParamName names_sel[] = {kEventParamATSUFontID,
8740 kEventParamATSUFontSize,
8741 kEventParamFMFontFamily,
8742 kEventParamFMFontSize,
8743 kEventParamFontColor};
8744 static const EventParamType types_sel[] = {typeATSUFontID,
8745 typeATSUSize,
8746 typeFMFontFamily,
8747 typeFMFontSize,
8748 typeFontColor};
8749
8750 result = CallNextEventHandler (next_handler, event);
8751 if (result != eventNotHandledErr)
8752 return result;
8753
8754 switch (GetEventKind (event))
8755 {
8756 case kEventFontPanelClosed:
8757 id_key = Qpanel_closed;
8758 num_params = 0;
8759 names = NULL;
8760 types = NULL;
8761 break;
8762
8763 case kEventFontSelection:
8764 id_key = Qselection;
8765 num_params = sizeof (names_sel) / sizeof (names_sel[0]);
8766 names = names_sel;
8767 types = types_sel;
8768 break;
8769 }
8770
8771 err = mac_store_event_ref_as_apple_event (0, 0, Qfont, id_key,
8772 event, num_params,
8773 names, types);
8774 if (err == noErr)
8775 result = noErr;
8776
8777 return result;
8778}
8779
8732OSStatus 8780OSStatus
8733mac_show_hide_font_panel () 8781mac_show_hide_font_panel ()
8734{ 8782{
8735 font_panel_shown_p = 1; 8783 if (!font_panel_shown_p)
8784 {
8785 OSStatus err;
8786
8787 static const EventTypeSpec specs[] =
8788 {{kEventClassFont, kEventFontPanelClosed},
8789 {kEventClassFont, kEventFontSelection}};
8790
8791 err = InstallApplicationEventHandler (mac_handle_font_event,
8792 GetEventTypeCount (specs),
8793 specs, NULL, NULL);
8794 if (err != noErr)
8795 return err;
8796
8797 font_panel_shown_p = 1;
8798 }
8736 8799
8737 return FPShowHideFontPanel (); 8800 return FPShowHideFontPanel ();
8738} 8801}
@@ -8848,7 +8911,7 @@ Lisp_Object Vmac_function_modifier;
8848 a three button mouse */ 8911 a three button mouse */
8849Lisp_Object Vmac_emulate_three_button_mouse; 8912Lisp_Object Vmac_emulate_three_button_mouse;
8850 8913
8851#if USE_CARBON_EVENTS 8914#if TARGET_API_MAC_CARBON
8852/* Non-zero if the mouse wheel button (i.e. button 4) should map to 8915/* Non-zero if the mouse wheel button (i.e. button 4) should map to
8853 mouse-2, instead of mouse-3. */ 8916 mouse-2, instead of mouse-3. */
8854int mac_wheel_button_is_mouse_2; 8917int mac_wheel_button_is_mouse_2;
@@ -8873,16 +8936,12 @@ static int mac_screen_config_changed = 0;
8873Point saved_menu_event_location; 8936Point saved_menu_event_location;
8874 8937
8875/* Apple Events */ 8938/* Apple Events */
8876#if USE_CARBON_EVENTS 8939#if TARGET_API_MAC_CARBON
8877static Lisp_Object Qhi_command; 8940static Lisp_Object Qhi_command;
8878#ifdef MAC_OSX 8941#ifdef MAC_OSX
8879extern Lisp_Object Qwindow; 8942extern Lisp_Object Qwindow;
8880static Lisp_Object Qtoolbar_switch_mode; 8943static Lisp_Object Qtoolbar_switch_mode;
8881#endif 8944#endif
8882#if USE_MAC_FONT_PANEL
8883extern Lisp_Object Qfont;
8884static Lisp_Object Qpanel_closed, Qselection;
8885#endif
8886#if USE_MAC_TSM 8945#if USE_MAC_TSM
8887static TSMDocumentID tsm_document_id; 8946static TSMDocumentID tsm_document_id;
8888static Lisp_Object Qtext_input; 8947static Lisp_Object Qtext_input;
@@ -8894,7 +8953,7 @@ static Lisp_Object saved_ts_script_language_on_focus;
8894static ScriptLanguageRecord saved_ts_language; 8953static ScriptLanguageRecord saved_ts_language;
8895static Component saved_ts_component; 8954static Component saved_ts_component;
8896#endif 8955#endif
8897#endif 8956#endif /* TARGET_API_MAC_CARBON */
8898extern int mac_ready_for_apple_events; 8957extern int mac_ready_for_apple_events;
8899extern Lisp_Object Qundefined; 8958extern Lisp_Object Qundefined;
8900extern void init_apple_event_handler P_ ((void)); 8959extern void init_apple_event_handler P_ ((void));
@@ -8907,20 +8966,15 @@ extern OSErr init_coercion_handler P_ ((void));
8907extern OSErr install_drag_handler P_ ((WindowRef)); 8966extern OSErr install_drag_handler P_ ((WindowRef));
8908extern void remove_drag_handler P_ ((WindowRef)); 8967extern void remove_drag_handler P_ ((WindowRef));
8909 8968
8969#if TARGET_API_MAC_CARBON
8910/* Showing help echo string during menu tracking */ 8970/* Showing help echo string during menu tracking */
8911extern OSStatus install_menu_target_item_handler P_ ((WindowPtr)); 8971extern OSStatus install_menu_target_item_handler P_ ((void));
8912 8972
8913#if USE_CARBON_EVENTS
8914#ifdef MAC_OSX 8973#ifdef MAC_OSX
8915extern void init_service_handler (); 8974extern OSStatus install_service_handler ();
8916static Lisp_Object Qservice, Qpaste, Qperform; 8975static Lisp_Object Qservice, Qpaste, Qperform;
8917#endif 8976#endif
8918
8919/* Window Event Handler */
8920static pascal OSStatus mac_handle_window_event (EventHandlerCallRef,
8921 EventRef, void *);
8922#endif 8977#endif
8923OSStatus install_window_handler (WindowPtr);
8924 8978
8925extern void init_emacs_passwd_dir (); 8979extern void init_emacs_passwd_dir ();
8926extern int emacs_main (int, char **, char **); 8980extern int emacs_main (int, char **, char **);
@@ -9004,7 +9058,7 @@ static const unsigned char fn_keycode_to_keycode_table[] = {
9004#endif /* MAC_OSX */ 9058#endif /* MAC_OSX */
9005 9059
9006static int 9060static int
9007#if USE_CARBON_EVENTS 9061#if TARGET_API_MAC_CARBON
9008mac_to_emacs_modifiers (UInt32 mods) 9062mac_to_emacs_modifiers (UInt32 mods)
9009#else 9063#else
9010mac_to_emacs_modifiers (EventModifiers mods) 9064mac_to_emacs_modifiers (EventModifiers mods)
@@ -9113,17 +9167,19 @@ mac_quit_char_key_p (modifiers, key_code)
9113} 9167}
9114#endif 9168#endif
9115 9169
9116#if USE_CARBON_EVENTS 9170#if TARGET_API_MAC_CARBON
9117/* Obtains the event modifiers from the event ref and then calls 9171/* Obtains the event modifiers from the event ref and then calls
9118 mac_to_emacs_modifiers. */ 9172 mac_to_emacs_modifiers. */
9119static int 9173static int
9120mac_event_to_emacs_modifiers (EventRef eventRef) 9174mac_event_to_emacs_modifiers (EventRef eventRef)
9121{ 9175{
9122 UInt32 mods = 0; 9176 UInt32 mods = 0, class;
9177
9123 GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL, 9178 GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL,
9124 sizeof (UInt32), NULL, &mods); 9179 sizeof (UInt32), NULL, &mods);
9180 class = GetEventClass (eventRef);
9125 if (!NILP (Vmac_emulate_three_button_mouse) && 9181 if (!NILP (Vmac_emulate_three_button_mouse) &&
9126 GetEventClass(eventRef) == kEventClassMouse) 9182 (class == kEventClassMouse || class == kEventClassCommand))
9127 { 9183 {
9128 mods &= ~(optionKey | cmdKey); 9184 mods &= ~(optionKey | cmdKey);
9129 } 9185 }
@@ -9262,7 +9318,7 @@ static void
9262do_get_menus (void) 9318do_get_menus (void)
9263{ 9319{
9264 Handle menubar_handle; 9320 Handle menubar_handle;
9265 MenuHandle menu_handle; 9321 MenuRef menu;
9266 9322
9267 menubar_handle = GetNewMBar (128); 9323 menubar_handle = GetNewMBar (128);
9268 if(menubar_handle == NULL) 9324 if(menubar_handle == NULL)
@@ -9271,9 +9327,9 @@ do_get_menus (void)
9271 DrawMenuBar (); 9327 DrawMenuBar ();
9272 9328
9273#if !TARGET_API_MAC_CARBON 9329#if !TARGET_API_MAC_CARBON
9274 menu_handle = GetMenuHandle (M_APPLE); 9330 menu = GetMenuRef (M_APPLE);
9275 if(menu_handle != NULL) 9331 if (menu != NULL)
9276 AppendResMenu (menu_handle,'DRVR'); 9332 AppendResMenu (menu, 'DRVR');
9277 else 9333 else
9278 abort (); 9334 abort ();
9279#endif 9335#endif
@@ -9322,7 +9378,7 @@ do_check_ram_size (void)
9322#endif /* MAC_OS8 */ 9378#endif /* MAC_OS8 */
9323 9379
9324static void 9380static void
9325do_window_update (WindowPtr win) 9381do_window_update (WindowRef win)
9326{ 9382{
9327 struct frame *f = mac_window_to_frame (win); 9383 struct frame *f = mac_window_to_frame (win);
9328 9384
@@ -9367,7 +9423,7 @@ do_window_update (WindowPtr win)
9367} 9423}
9368 9424
9369static int 9425static int
9370is_emacs_window (WindowPtr win) 9426is_emacs_window (WindowRef win)
9371{ 9427{
9372 Lisp_Object tail, frame; 9428 Lisp_Object tail, frame;
9373 9429
@@ -9480,7 +9536,7 @@ do_apple_menu (SInt16 menu_item)
9480 NoteAlert (ABOUT_ALERT_ID, NULL); 9536 NoteAlert (ABOUT_ALERT_ID, NULL);
9481 else 9537 else
9482 { 9538 {
9483 GetMenuItemText (GetMenuHandle (M_APPLE), menu_item, item_name); 9539 GetMenuItemText (GetMenuRef (M_APPLE), menu_item, item_name);
9484 da_driver_refnum = OpenDeskAcc (item_name); 9540 da_driver_refnum = OpenDeskAcc (item_name);
9485 } 9541 }
9486} 9542}
@@ -9491,7 +9547,7 @@ do_apple_menu (SInt16 menu_item)
9491 9547
9492static void 9548static void
9493do_grow_window (w, e) 9549do_grow_window (w, e)
9494 WindowPtr w; 9550 WindowRef w;
9495 const EventRecord *e; 9551 const EventRecord *e;
9496{ 9552{
9497 Rect limit_rect; 9553 Rect limit_rect;
@@ -9543,7 +9599,7 @@ mac_get_ideal_size (f)
9543 struct frame *f; 9599 struct frame *f;
9544{ 9600{
9545 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); 9601 struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f);
9546 WindowPtr w = FRAME_MAC_WINDOW (f); 9602 WindowRef w = FRAME_MAC_WINDOW (f);
9547 Point ideal_size; 9603 Point ideal_size;
9548 Rect standard_rect; 9604 Rect standard_rect;
9549 int height, width, columns, rows; 9605 int height, width, columns, rows;
@@ -9569,7 +9625,7 @@ mac_get_ideal_size (f)
9569 wide (DEFAULT_NUM_COLS) and as tall as will fit on the screen. */ 9625 wide (DEFAULT_NUM_COLS) and as tall as will fit on the screen. */
9570 9626
9571static void 9627static void
9572do_zoom_window (WindowPtr w, int zoom_in_or_out) 9628do_zoom_window (WindowRef w, int zoom_in_or_out)
9573{ 9629{
9574 Rect zoom_rect, port_rect; 9630 Rect zoom_rect, port_rect;
9575 int width, height; 9631 int width, height;
@@ -9632,13 +9688,9 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
9632 SetPort (save_port); 9688 SetPort (save_port);
9633#endif /* not TARGET_API_MAC_CARBON */ 9689#endif /* not TARGET_API_MAC_CARBON */
9634 9690
9635#if !USE_CARBON_EVENTS 9691#if !TARGET_API_MAC_CARBON
9636 /* retrieve window size and update application values */ 9692 /* retrieve window size and update application values */
9637#if TARGET_API_MAC_CARBON
9638 GetWindowPortBounds (w, &port_rect);
9639#else
9640 port_rect = w->portRect; 9693 port_rect = w->portRect;
9641#endif
9642 height = port_rect.bottom - port_rect.top; 9694 height = port_rect.bottom - port_rect.top;
9643 width = port_rect.right - port_rect.left; 9695 width = port_rect.right - port_rect.left;
9644 9696
@@ -9647,6 +9699,210 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
9647#endif 9699#endif
9648} 9700}
9649 9701
9702static void
9703mac_set_unicode_keystroke_event (code, buf)
9704 UniChar code;
9705 struct input_event *buf;
9706{
9707 int charset_id, c1, c2;
9708
9709 if (code < 0x80)
9710 {
9711 buf->kind = ASCII_KEYSTROKE_EVENT;
9712 buf->code = code;
9713 }
9714 else if (code < 0x100)
9715 {
9716 if (code < 0xA0)
9717 charset_id = CHARSET_8_BIT_CONTROL;
9718 else
9719 charset_id = charset_latin_iso8859_1;
9720 buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT;
9721 buf->code = MAKE_CHAR (charset_id, code, 0);
9722 }
9723 else
9724 {
9725 if (code < 0x2500)
9726 charset_id = charset_mule_unicode_0100_24ff,
9727 code -= 0x100;
9728 else if (code < 0x33FF)
9729 charset_id = charset_mule_unicode_2500_33ff,
9730 code -= 0x2500;
9731 else if (code >= 0xE000)
9732 charset_id = charset_mule_unicode_e000_ffff,
9733 code -= 0xE000;
9734 c1 = (code / 96) + 32, c2 = (code % 96) + 32;
9735 buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT;
9736 buf->code = MAKE_CHAR (charset_id, c1, c2);
9737 }
9738}
9739
9740static void
9741do_keystroke (action, char_code, key_code, modifiers, timestamp, buf)
9742 EventKind action;
9743 unsigned char char_code;
9744 UInt32 key_code, modifiers;
9745 unsigned long timestamp;
9746 struct input_event *buf;
9747{
9748 static SInt16 last_key_script = -1;
9749 SInt16 current_key_script = GetScriptManagerVariable (smKeyScript);
9750 UInt32 mapped_modifiers = mac_mapped_modifiers (modifiers);
9751
9752#ifdef MAC_OSX
9753 if (mapped_modifiers & kEventKeyModifierFnMask
9754 && key_code <= 0x7f
9755 && fn_keycode_to_keycode_table[key_code])
9756 key_code = fn_keycode_to_keycode_table[key_code];
9757#endif
9758
9759 if (key_code <= 0x7f && keycode_to_xkeysym_table[key_code])
9760 {
9761 buf->kind = NON_ASCII_KEYSTROKE_EVENT;
9762 buf->code = 0xff00 | keycode_to_xkeysym_table[key_code];
9763#ifdef MAC_OSX
9764 if (modifiers & kEventKeyModifierFnMask
9765 && key_code <= 0x7f
9766 && fn_keycode_to_keycode_table[key_code] == key_code)
9767 modifiers &= ~kEventKeyModifierFnMask;
9768#endif
9769 }
9770 else if (mapped_modifiers)
9771 {
9772 /* translate the keycode back to determine the original key */
9773#ifdef MAC_OSX
9774 UCKeyboardLayout *uchr_ptr = NULL;
9775#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
9776 OSStatus err;
9777 KeyboardLayoutRef layout;
9778
9779 err = KLGetCurrentKeyboardLayout (&layout);
9780 if (err == noErr)
9781 err = KLGetKeyboardLayoutProperty (layout, kKLuchrData,
9782 (const void **) &uchr_ptr);
9783#else
9784 static SInt16 last_key_layout_id = 0;
9785 static Handle uchr_handle = (Handle)-1;
9786 SInt16 current_key_layout_id =
9787 GetScriptVariable (current_key_script, smScriptKeys);
9788
9789 if (uchr_handle == (Handle)-1
9790 || last_key_layout_id != current_key_layout_id)
9791 {
9792 uchr_handle = GetResource ('uchr', current_key_layout_id);
9793 last_key_layout_id = current_key_layout_id;
9794 }
9795 if (uchr_handle)
9796 uchr_ptr = (UCKeyboardLayout *)*uchr_handle;
9797#endif
9798
9799 if (uchr_ptr)
9800 {
9801 OSStatus status;
9802 UInt16 key_action = action - keyDown;
9803 UInt32 modifier_key_state = (modifiers & ~mapped_modifiers) >> 8;
9804 UInt32 keyboard_type = LMGetKbdType ();
9805 SInt32 dead_key_state = 0;
9806 UniChar code;
9807 UniCharCount actual_length;
9808
9809 status = UCKeyTranslate (uchr_ptr, key_code, key_action,
9810 modifier_key_state, keyboard_type,
9811 kUCKeyTranslateNoDeadKeysMask,
9812 &dead_key_state,
9813 1, &actual_length, &code);
9814 if (status == noErr && actual_length == 1)
9815 mac_set_unicode_keystroke_event (code, buf);
9816 }
9817#endif /* MAC_OSX */
9818
9819 if (buf->kind == NO_EVENT)
9820 {
9821 /* This code comes from Keyboard Resource, Appendix C of IM
9822 - Text. This is necessary since shift is ignored in KCHR
9823 table translation when option or command is pressed. It
9824 also does not translate correctly control-shift chars
9825 like C-% so mask off shift here also. */
9826 /* Mask off modifier keys that are mapped to some Emacs
9827 modifiers. */
9828 int new_modifiers = modifiers & ~mapped_modifiers;
9829 /* set high byte of keycode to modifier high byte*/
9830 int new_key_code = key_code | new_modifiers;
9831 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
9832 unsigned long some_state = 0;
9833 UInt32 new_char_code;
9834
9835 new_char_code = KeyTranslate (kchr_ptr, new_key_code, &some_state);
9836 if (new_char_code == 0)
9837 /* Seems like a dead key. Append up-stroke. */
9838 new_char_code = KeyTranslate (kchr_ptr, new_key_code | 0x80,
9839 &some_state);
9840 if (new_char_code)
9841 {
9842 buf->kind = ASCII_KEYSTROKE_EVENT;
9843 buf->code = new_char_code & 0xff;
9844 }
9845 }
9846 }
9847
9848 if (buf->kind == NO_EVENT)
9849 {
9850 buf->kind = ASCII_KEYSTROKE_EVENT;
9851 buf->code = char_code;
9852 }
9853
9854 buf->modifiers = mac_to_emacs_modifiers (modifiers);
9855 buf->modifiers |= (extra_keyboard_modifiers
9856 & (meta_modifier | alt_modifier
9857 | hyper_modifier | super_modifier));
9858
9859#if TARGET_API_MAC_CARBON
9860 if (buf->kind == ASCII_KEYSTROKE_EVENT
9861 && buf->code >= 0x80 && buf->modifiers)
9862 {
9863 OSStatus err;
9864 TextEncoding encoding = kTextEncodingMacRoman;
9865 TextToUnicodeInfo ttu_info;
9866
9867 UpgradeScriptInfoToTextEncoding (current_key_script,
9868 kTextLanguageDontCare,
9869 kTextRegionDontCare,
9870 NULL, &encoding);
9871 err = CreateTextToUnicodeInfoByEncoding (encoding, &ttu_info);
9872 if (err == noErr)
9873 {
9874 UniChar code;
9875 Str255 pstr;
9876 ByteCount unicode_len;
9877
9878 pstr[0] = 1;
9879 pstr[1] = buf->code;
9880 err = ConvertFromPStringToUnicode (ttu_info, pstr,
9881 sizeof (UniChar),
9882 &unicode_len, &code);
9883 if (err == noErr && unicode_len == sizeof (UniChar))
9884 mac_set_unicode_keystroke_event (code, buf);
9885 DisposeTextToUnicodeInfo (&ttu_info);
9886 }
9887 }
9888#endif
9889
9890 if (buf->kind == ASCII_KEYSTROKE_EVENT
9891 && buf->code >= 0x80
9892 && last_key_script != current_key_script)
9893 {
9894 struct input_event event;
9895
9896 EVENT_INIT (event);
9897 event.kind = LANGUAGE_CHANGE_EVENT;
9898 event.arg = Qnil;
9899 event.code = current_key_script;
9900 event.timestamp = timestamp;
9901 kbd_buffer_store_event (&event);
9902 last_key_script = current_key_script;
9903 }
9904}
9905
9650void 9906void
9651mac_store_apple_event (class, id, desc) 9907mac_store_apple_event (class, id, desc)
9652 Lisp_Object class, id; 9908 Lisp_Object class, id;
@@ -9725,54 +9981,49 @@ mac_store_drag_event (window, mouse_pos, modifiers, desc)
9725 buf.arg = mac_aedesc_to_lisp (desc); 9981 buf.arg = mac_aedesc_to_lisp (desc);
9726 kbd_buffer_store_event (&buf); 9982 kbd_buffer_store_event (&buf);
9727} 9983}
9728#endif
9729 9984
9730#if USE_CARBON_EVENTS 9985#ifdef MAC_OSX
9731static pascal OSStatus 9986OSStatus
9732mac_handle_command_event (next_handler, event, data) 9987mac_store_service_event (event)
9733 EventHandlerCallRef next_handler;
9734 EventRef event; 9988 EventRef event;
9735 void *data;
9736{ 9989{
9737 OSStatus result, err; 9990 OSStatus err;
9738 HICommand command; 9991 Lisp_Object id_key;
9739 static const EventParamName names[] = 9992 int num_params;
9740 {kEventParamDirectObject, kEventParamKeyModifiers}; 9993 const EventParamName *names;
9741 static const EventParamType types[] = 9994 const EventParamType *types;
9742 {typeHICommand, typeUInt32}; 9995 static const EventParamName names_pfm[] =
9743 int num_params = sizeof (names) / sizeof (names[0]); 9996 {kEventParamServiceMessageName, kEventParamServiceUserData};
9744 9997 static const EventParamType types_pfm[] =
9745 result = CallNextEventHandler (next_handler, event); 9998 {typeCFStringRef, typeCFStringRef};
9746 if (result != eventNotHandledErr)
9747 return result;
9748 9999
9749 err = GetEventParameter (event, kEventParamDirectObject, typeHICommand, 10000 switch (GetEventKind (event))
9750 NULL, sizeof (HICommand), NULL, &command); 10001 {
10002 case kEventServicePaste:
10003 id_key = Qpaste;
10004 num_params = 0;
10005 names = NULL;
10006 types = NULL;
10007 break;
9751 10008
9752 if (err != noErr || command.commandID == 0) 10009 case kEventServicePerform:
9753 return eventNotHandledErr; 10010 id_key = Qperform;
10011 num_params = sizeof (names_pfm) / sizeof (names_pfm[0]);
10012 names = names_pfm;
10013 types = types_pfm;
10014 break;
9754 10015
9755 /* A HI command event is mapped to an Apple event whose event class 10016 default:
9756 symbol is `hi-command' and event ID is its command ID. */ 10017 abort ();
9757 err = mac_store_event_ref_as_apple_event (0, command.commandID, 10018 }
9758 Qhi_command, Qnil,
9759 event, num_params, names, types);
9760 return err == noErr ? noErr : eventNotHandledErr;
9761}
9762 10019
9763static OSStatus 10020 err = mac_store_event_ref_as_apple_event (0, 0, Qservice, id_key,
9764init_command_handler () 10021 event, num_params,
9765{ 10022 names, types);
9766 static const EventTypeSpec specs[] =
9767 {{kEventClassCommand, kEventCommandProcess}};
9768 static EventHandlerUPP handle_command_eventUPP = NULL;
9769 10023
9770 if (handle_command_eventUPP == NULL) 10024 return err;
9771 handle_command_eventUPP = NewEventHandlerUPP (mac_handle_command_event);
9772 return InstallApplicationEventHandler (handle_command_eventUPP,
9773 GetEventTypeCount (specs), specs,
9774 NULL, NULL);
9775} 10025}
10026#endif /* MAC_OSX */
9776 10027
9777static pascal OSStatus 10028static pascal OSStatus
9778mac_handle_window_event (next_handler, event, data) 10029mac_handle_window_event (next_handler, event, data)
@@ -9780,47 +10031,78 @@ mac_handle_window_event (next_handler, event, data)
9780 EventRef event; 10031 EventRef event;
9781 void *data; 10032 void *data;
9782{ 10033{
9783 WindowPtr wp; 10034 WindowRef wp;
9784 OSStatus result, err; 10035 OSStatus err, result = eventNotHandledErr;
9785 struct frame *f; 10036 struct frame *f;
9786 UInt32 attributes; 10037 UInt32 attributes;
9787 XSizeHints *size_hints; 10038 XSizeHints *size_hints;
9788 10039
9789 err = GetEventParameter (event, kEventParamDirectObject, typeWindowRef, 10040 err = GetEventParameter (event, kEventParamDirectObject, typeWindowRef,
9790 NULL, sizeof (WindowPtr), NULL, &wp); 10041 NULL, sizeof (WindowRef), NULL, &wp);
9791 if (err != noErr) 10042 if (err != noErr)
9792 return eventNotHandledErr; 10043 return eventNotHandledErr;
9793 10044
9794 f = mac_window_to_frame (wp); 10045 f = mac_window_to_frame (wp);
9795 switch (GetEventKind (event)) 10046 switch (GetEventKind (event))
9796 { 10047 {
10048 /* -- window refresh events -- */
10049
9797 case kEventWindowUpdate: 10050 case kEventWindowUpdate:
9798 result = CallNextEventHandler (next_handler, event); 10051 result = CallNextEventHandler (next_handler, event);
9799 if (result != eventNotHandledErr) 10052 if (result != eventNotHandledErr)
9800 return result; 10053 break;
9801 10054
9802 do_window_update (wp); 10055 do_window_update (wp);
9803 return noErr; 10056 result = noErr;
10057 break;
9804 10058
9805 case kEventWindowGetIdealSize: 10059 /* -- window state change events -- */
9806 result = CallNextEventHandler (next_handler, event);
9807 if (result != eventNotHandledErr)
9808 return result;
9809 10060
9810 { 10061 case kEventWindowShowing:
9811 Point ideal_size = mac_get_ideal_size (f); 10062 size_hints = FRAME_SIZE_HINTS (f);
10063 if (!(size_hints->flags & (USPosition | PPosition)))
10064 {
10065 struct frame *sf = SELECTED_FRAME ();
9812 10066
9813 err = SetEventParameter (event, kEventParamDimensions, 10067 if (!(FRAME_MAC_P (sf)))
9814 typeQDPoint, sizeof (Point), &ideal_size); 10068 RepositionWindow (wp, NULL, kWindowCenterOnMainScreen);
9815 if (err == noErr) 10069 else
9816 return noErr; 10070 {
9817 } 10071 RepositionWindow (wp, FRAME_MAC_WINDOW (sf),
10072#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
10073 kWindowCascadeStartAtParentWindowScreen
10074#else
10075 kWindowCascadeOnParentWindowScreen
10076#endif
10077 );
10078 }
10079 result = noErr;
10080 }
10081 break;
10082
10083 case kEventWindowHiding:
10084 /* Before unmapping the window, update the WM_SIZE_HINTS
10085 property to claim that the current position of the window is
10086 user-specified, rather than program-specified, so that when
10087 the window is mapped again, it will be placed at the same
10088 location, without forcing the user to position it by hand
10089 again (they have already done that once for this window.) */
10090 x_wm_set_size_hint (f, (long) 0, 1);
10091 result = noErr;
10092 break;
10093
10094 case kEventWindowShown:
10095 case kEventWindowHidden:
10096 case kEventWindowCollapsed:
10097 case kEventWindowExpanded:
10098 mac_handle_visibility_change (f);
10099 result = noErr;
9818 break; 10100 break;
9819 10101
9820 case kEventWindowBoundsChanging: 10102 case kEventWindowBoundsChanging:
9821 result = CallNextEventHandler (next_handler, event); 10103 result = CallNextEventHandler (next_handler, event);
9822 if (result != eventNotHandledErr) 10104 if (result != eventNotHandledErr)
9823 return result; 10105 break;
9824 10106
9825 err = GetEventParameter (event, kEventParamAttributes, typeUInt32, 10107 err = GetEventParameter (event, kEventParamAttributes, typeUInt32,
9826 NULL, sizeof (UInt32), NULL, &attributes); 10108 NULL, sizeof (UInt32), NULL, &attributes);
@@ -9864,7 +10146,7 @@ mac_handle_window_event (next_handler, event, data)
9864 bounds.bottom = bounds.top + height; 10146 bounds.bottom = bounds.top + height;
9865 SetEventParameter (event, kEventParamCurrentBounds, 10147 SetEventParameter (event, kEventParamCurrentBounds,
9866 typeQDRectangle, sizeof (Rect), &bounds); 10148 typeQDRectangle, sizeof (Rect), &bounds);
9867 return noErr; 10149 result = noErr;
9868 } 10150 }
9869 break; 10151 break;
9870 10152
@@ -9895,21 +10177,12 @@ mac_handle_window_event (next_handler, event, data)
9895 if (attributes & kWindowBoundsChangeOriginChanged) 10177 if (attributes & kWindowBoundsChangeOriginChanged)
9896 mac_handle_origin_change (f); 10178 mac_handle_origin_change (f);
9897 10179
9898 return noErr; 10180 result = noErr;
9899
9900 case kEventWindowShown:
9901 case kEventWindowHidden:
9902 case kEventWindowExpanded:
9903 case kEventWindowCollapsed:
9904 result = CallNextEventHandler (next_handler, event);
9905
9906 mac_handle_visibility_change (f);
9907 return noErr;
9908
9909 break; 10181 break;
9910 10182
10183 /* -- window action events -- */
10184
9911 case kEventWindowClose: 10185 case kEventWindowClose:
9912 result = CallNextEventHandler (next_handler, event);
9913 { 10186 {
9914 struct input_event buf; 10187 struct input_event buf;
9915 10188
@@ -9919,11 +10192,26 @@ mac_handle_window_event (next_handler, event, data)
9919 buf.arg = Qnil; 10192 buf.arg = Qnil;
9920 kbd_buffer_store_event (&buf); 10193 kbd_buffer_store_event (&buf);
9921 } 10194 }
9922 return noErr; 10195 result = noErr;
10196 break;
10197
10198 case kEventWindowGetIdealSize:
10199 result = CallNextEventHandler (next_handler, event);
10200 if (result != eventNotHandledErr)
10201 break;
10202
10203 {
10204 Point ideal_size = mac_get_ideal_size (f);
10205
10206 err = SetEventParameter (event, kEventParamDimensions,
10207 typeQDPoint, sizeof (Point), &ideal_size);
10208 if (err == noErr)
10209 result = noErr;
10210 }
10211 break;
9923 10212
9924#ifdef MAC_OSX 10213#ifdef MAC_OSX
9925 case kEventWindowToolbarSwitchMode: 10214 case kEventWindowToolbarSwitchMode:
9926 result = CallNextEventHandler (next_handler, event);
9927 { 10215 {
9928 static const EventParamName names[] = {kEventParamDirectObject, 10216 static const EventParamName names[] = {kEventParamDirectObject,
9929 kEventParamWindowMouseLocation, 10217 kEventParamWindowMouseLocation,
@@ -9945,23 +10233,195 @@ mac_handle_window_event (next_handler, event, data)
9945 event, num_params, 10233 event, num_params,
9946 names, types); 10234 names, types);
9947 } 10235 }
9948 return err == noErr ? noErr : result; 10236 if (err == noErr)
10237 result = noErr;
10238 break;
9949#endif 10239#endif
9950 10240
9951#if USE_MAC_TSM 10241#if USE_MAC_TSM
10242 /* -- window focus events -- */
10243
9952 case kEventWindowFocusAcquired: 10244 case kEventWindowFocusAcquired:
9953 result = CallNextEventHandler (next_handler, event);
9954 err = mac_tsm_resume (); 10245 err = mac_tsm_resume ();
9955 return err == noErr ? noErr : result; 10246 if (err == noErr)
10247 result = noErr;
10248 break;
9956 10249
9957 case kEventWindowFocusRelinquish: 10250 case kEventWindowFocusRelinquish:
9958 result = CallNextEventHandler (next_handler, event);
9959 err = mac_tsm_suspend (); 10251 err = mac_tsm_suspend ();
9960 return err == noErr ? noErr : result; 10252 if (err == noErr)
10253 result = noErr;
10254 break;
10255#endif
10256
10257 default:
10258 abort ();
10259 }
10260
10261 return result;
10262}
10263
10264static pascal OSStatus
10265mac_handle_application_event (next_handler, event, data)
10266 EventHandlerCallRef next_handler;
10267 EventRef event;
10268 void *data;
10269{
10270 OSStatus err, result = eventNotHandledErr;
10271
10272 switch (GetEventKind (event))
10273 {
10274#if USE_MAC_TSM
10275 case kEventAppActivated:
10276 err = mac_tsm_resume ();
10277 break;
10278
10279 case kEventAppDeactivated:
10280 err = mac_tsm_suspend ();
10281 break;
9961#endif 10282#endif
10283
10284 default:
10285 abort ();
9962 } 10286 }
9963 10287
9964 return eventNotHandledErr; 10288 if (err == noErr)
10289 result = noErr;
10290
10291 return result;
10292}
10293
10294static pascal OSStatus
10295mac_handle_keyboard_event (next_handler, event, data)
10296 EventHandlerCallRef next_handler;
10297 EventRef event;
10298 void *data;
10299{
10300 OSStatus err, result = eventNotHandledErr;
10301 UInt32 event_kind, key_code, modifiers, mapped_modifiers;
10302 unsigned char char_code;
10303
10304 event_kind = GetEventKind (event);
10305 switch (event_kind)
10306 {
10307 case kEventRawKeyDown:
10308 case kEventRawKeyRepeat:
10309 case kEventRawKeyUp:
10310 if (read_socket_inev == NULL)
10311 {
10312 result = CallNextEventHandler (next_handler, event);
10313 break;
10314 }
10315
10316 err = GetEventParameter (event, kEventParamKeyModifiers,
10317 typeUInt32, NULL,
10318 sizeof (UInt32), NULL, &modifiers);
10319 if (err != noErr)
10320 break;
10321
10322 mapped_modifiers = mac_mapped_modifiers (modifiers);
10323
10324 /* When using Carbon Events, we need to pass raw keyboard events
10325 to the TSM ourselves. If TSM handles it, it will pass back
10326 noErr, otherwise it will pass back "eventNotHandledErr" and
10327 we can process it normally. */
10328 if (!(mapped_modifiers
10329 & ~(mac_pass_command_to_system ? cmdKey : 0)
10330 & ~(mac_pass_control_to_system ? controlKey : 0)))
10331 {
10332 result = CallNextEventHandler (next_handler, event);
10333 if (result != eventNotHandledErr)
10334 break;
10335 }
10336
10337#if USE_MAC_TSM
10338 if (read_socket_inev->kind != NO_EVENT)
10339 {
10340 result = noErr;
10341 break;
10342 }
10343#endif
10344
10345 if (event_kind == kEventRawKeyUp)
10346 break;
10347
10348 err = GetEventParameter (event, kEventParamKeyMacCharCodes,
10349 typeChar, NULL,
10350 sizeof (char), NULL, &char_code);
10351 if (err != noErr)
10352 break;
10353
10354 err = GetEventParameter (event, kEventParamKeyCode,
10355 typeUInt32, NULL,
10356 sizeof (UInt32), NULL, &key_code);
10357 if (err != noErr)
10358 break;
10359
10360 do_keystroke ((GetEventKind (event) == kEventRawKeyDown
10361 ? keyDown : autoKey),
10362 char_code, key_code, modifiers,
10363 ((unsigned long)
10364 (GetEventTime (event) / kEventDurationMillisecond)),
10365 read_socket_inev);
10366 result = noErr;
10367 break;
10368
10369 default:
10370 abort ();
10371 }
10372
10373 return result;
10374}
10375
10376static pascal OSStatus
10377mac_handle_command_event (next_handler, event, data)
10378 EventHandlerCallRef next_handler;
10379 EventRef event;
10380 void *data;
10381{
10382 OSStatus err, result = eventNotHandledErr;
10383 HICommand command;
10384 static const EventParamName names[] =
10385 {kEventParamDirectObject, kEventParamKeyModifiers};
10386 static const EventParamType types[] =
10387 {typeHICommand, typeUInt32};
10388 int num_params = sizeof (names) / sizeof (names[0]);
10389
10390 err = GetEventParameter (event, kEventParamDirectObject, typeHICommand,
10391 NULL, sizeof (HICommand), NULL, &command);
10392 if (err != noErr)
10393 return eventNotHandledErr;
10394
10395 switch (GetEventKind (event))
10396 {
10397 case kEventCommandProcess:
10398 result = CallNextEventHandler (next_handler, event);
10399 if (result != eventNotHandledErr)
10400 break;
10401
10402 err = GetEventParameter (event, kEventParamDirectObject,
10403 typeHICommand, NULL,
10404 sizeof (HICommand), NULL, &command);
10405
10406 if (err != noErr || command.commandID == 0)
10407 break;
10408
10409 /* A HI command event is mapped to an Apple event whose event
10410 class symbol is `hi-command' and event ID is its command
10411 ID. */
10412 err = mac_store_event_ref_as_apple_event (0, command.commandID,
10413 Qhi_command, Qnil,
10414 event, num_params,
10415 names, types);
10416 if (err == noErr)
10417 result = noErr;
10418 break;
10419
10420 default:
10421 abort ();
10422 }
10423
10424 return result;
9965} 10425}
9966 10426
9967static pascal OSStatus 10427static pascal OSStatus
@@ -9970,13 +10430,13 @@ mac_handle_mouse_event (next_handler, event, data)
9970 EventRef event; 10430 EventRef event;
9971 void *data; 10431 void *data;
9972{ 10432{
9973 OSStatus result, err; 10433 OSStatus err, result = eventNotHandledErr;
9974 10434
9975 switch (GetEventKind (event)) 10435 switch (GetEventKind (event))
9976 { 10436 {
9977 case kEventMouseWheelMoved: 10437 case kEventMouseWheelMoved:
9978 { 10438 {
9979 WindowPtr wp; 10439 WindowRef wp;
9980 struct frame *f; 10440 struct frame *f;
9981 EventMouseWheelAxis axis; 10441 EventMouseWheelAxis axis;
9982 SInt32 delta; 10442 SInt32 delta;
@@ -9984,15 +10444,14 @@ mac_handle_mouse_event (next_handler, event, data)
9984 10444
9985 result = CallNextEventHandler (next_handler, event); 10445 result = CallNextEventHandler (next_handler, event);
9986 if (result != eventNotHandledErr || read_socket_inev == NULL) 10446 if (result != eventNotHandledErr || read_socket_inev == NULL)
9987 return result; 10447 break;
10448
10449 f = mac_focus_frame (&one_mac_display_info);
9988 10450
9989 err = GetEventParameter (event, kEventParamWindowRef, typeWindowRef, 10451 err = GetEventParameter (event, kEventParamWindowRef, typeWindowRef,
9990 NULL, sizeof (WindowRef), NULL, &wp); 10452 NULL, sizeof (WindowRef), NULL, &wp);
9991 if (err != noErr) 10453 if (err != noErr
9992 break; 10454 || wp != FRAME_MAC_WINDOW (f))
9993
9994 f = mac_window_to_frame (wp);
9995 if (f != mac_focus_frame (&one_mac_display_info))
9996 break; 10455 break;
9997 10456
9998 err = GetEventParameter (event, kEventParamMouseWheelAxis, 10457 err = GetEventParameter (event, kEventParamMouseWheelAxis,
@@ -10007,8 +10466,8 @@ mac_handle_mouse_event (next_handler, event, data)
10007 if (err != noErr) 10466 if (err != noErr)
10008 break; 10467 break;
10009 10468
10010 SetPortWindowPort (wp); 10469 point.h -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f);
10011 GlobalToLocal (&point); 10470 point.v -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f);
10012 if (point.h < 0 || point.v < 0 10471 if (point.h < 0 || point.v < 0
10013 || EQ (window_from_coordinates (f, point.h, point.v, 0, 0, 0, 1), 10472 || EQ (window_from_coordinates (f, point.h, point.v, 0, 0, 0, 1),
10014 f->tool_bar_window)) 10473 f->tool_bar_window))
@@ -10029,68 +10488,16 @@ mac_handle_mouse_event (next_handler, event, data)
10029 XSETINT (read_socket_inev->y, point.v); 10488 XSETINT (read_socket_inev->y, point.v);
10030 XSETFRAME (read_socket_inev->frame_or_window, f); 10489 XSETFRAME (read_socket_inev->frame_or_window, f);
10031 10490
10032 return noErr; 10491 result = noErr;
10033 } 10492 }
10034 break; 10493 break;
10035 10494
10036 default: 10495 default:
10037 break; 10496 abort ();
10038 }
10039
10040 return eventNotHandledErr;
10041}
10042
10043#if USE_MAC_FONT_PANEL
10044static pascal OSStatus
10045mac_handle_font_event (next_handler, event, data)
10046 EventHandlerCallRef next_handler;
10047 EventRef event;
10048 void *data;
10049{
10050 OSStatus result, err;
10051 Lisp_Object id_key;
10052 int num_params;
10053 const EventParamName *names;
10054 const EventParamType *types;
10055 static const EventParamName names_sel[] = {kEventParamATSUFontID,
10056 kEventParamATSUFontSize,
10057 kEventParamFMFontFamily,
10058 kEventParamFMFontSize,
10059 kEventParamFontColor};
10060 static const EventParamType types_sel[] = {typeATSUFontID,
10061 typeATSUSize,
10062 typeFMFontFamily,
10063 typeFMFontSize,
10064 typeFontColor};
10065
10066 result = CallNextEventHandler (next_handler, event);
10067 if (result != eventNotHandledErr)
10068 return result;
10069
10070 switch (GetEventKind (event))
10071 {
10072 case kEventFontPanelClosed:
10073 id_key = Qpanel_closed;
10074 num_params = 0;
10075 names = NULL;
10076 types = NULL;
10077 break;
10078
10079 case kEventFontSelection:
10080 id_key = Qselection;
10081 num_params = sizeof (names_sel) / sizeof (names_sel[0]);
10082 names = names_sel;
10083 types = types_sel;
10084 break;
10085 } 10497 }
10086 10498
10087 err = mac_store_event_ref_as_apple_event (0, 0, Qfont, id_key, 10499 return result;
10088 event, num_params,
10089 names, types);
10090
10091 return err == noErr ? noErr : eventNotHandledErr;
10092} 10500}
10093#endif
10094 10501
10095#if USE_MAC_TSM 10502#if USE_MAC_TSM
10096static pascal OSStatus 10503static pascal OSStatus
@@ -10147,6 +10554,8 @@ mac_handle_text_input_event (next_handler, event, data)
10147 typeUnicodeText}; 10554 typeUnicodeText};
10148 10555
10149 result = CallNextEventHandler (next_handler, event); 10556 result = CallNextEventHandler (next_handler, event);
10557 if (result != eventNotHandledErr)
10558 return result;
10150 10559
10151 switch (GetEventKind (event)) 10560 switch (GetEventKind (event))
10152 { 10561 {
@@ -10174,7 +10583,7 @@ mac_handle_text_input_event (next_handler, event, data)
10174 sizeof (UInt32), NULL, &modifiers); 10583 sizeof (UInt32), NULL, &modifiers);
10175 if (err == noErr && mac_mapped_modifiers (modifiers)) 10584 if (err == noErr && mac_mapped_modifiers (modifiers))
10176 /* There're mapped modifier keys. Process it in 10585 /* There're mapped modifier keys. Process it in
10177 XTread_socket. */ 10586 do_keystroke. */
10178 return eventNotHandledErr; 10587 return eventNotHandledErr;
10179 if (err == noErr) 10588 if (err == noErr)
10180 err = GetEventParameter (kbd_event, kEventParamKeyUnicodes, 10589 err = GetEventParameter (kbd_event, kEventParamKeyUnicodes,
@@ -10189,7 +10598,7 @@ mac_handle_text_input_event (next_handler, event, data)
10189 sizeof (UniChar), NULL, &code); 10598 sizeof (UniChar), NULL, &code);
10190 if (err == noErr && code < 0x80) 10599 if (err == noErr && code < 0x80)
10191 { 10600 {
10192 /* ASCII character. Process it in XTread_socket. */ 10601 /* ASCII character. Process it in do_keystroke. */
10193 if (read_socket_inev && code >= 0x20 && code <= 0x7e) 10602 if (read_socket_inev && code >= 0x20 && code <= 0x7e)
10194 { 10603 {
10195 UInt32 key_code; 10604 UInt32 key_code;
@@ -10251,11 +10660,11 @@ mac_handle_text_input_event (next_handler, event, data)
10251 } 10660 }
10252 10661
10253 p.h = (WINDOW_TO_FRAME_PIXEL_X (w, w->cursor.x) 10662 p.h = (WINDOW_TO_FRAME_PIXEL_X (w, w->cursor.x)
10254 + WINDOW_LEFT_FRINGE_WIDTH (w)); 10663 + WINDOW_LEFT_FRINGE_WIDTH (w)
10664 + f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f));
10255 p.v = (WINDOW_TO_FRAME_PIXEL_Y (w, w->cursor.y) 10665 p.v = (WINDOW_TO_FRAME_PIXEL_Y (w, w->cursor.y)
10256 + FONT_BASE (FRAME_FONT (f))); 10666 + FONT_BASE (FRAME_FONT (f))
10257 SetPortWindowPort (FRAME_MAC_WINDOW (f)); 10667 + f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f));
10258 LocalToGlobal (&p);
10259 err = SetEventParameter (event, kEventParamTextInputReplyPoint, 10668 err = SetEventParameter (event, kEventParamTextInputReplyPoint,
10260 typeQDPoint, sizeof (typeQDPoint), &p); 10669 typeQDPoint, sizeof (typeQDPoint), &p);
10261 } 10670 }
@@ -10269,146 +10678,155 @@ mac_handle_text_input_event (next_handler, event, data)
10269 err = mac_store_event_ref_as_apple_event (0, 0, Qtext_input, id_key, 10678 err = mac_store_event_ref_as_apple_event (0, 0, Qtext_input, id_key,
10270 event, num_params, 10679 event, num_params,
10271 names, types); 10680 names, types);
10681 if (err == noErr)
10682 result = noErr;
10272 10683
10273 return err == noErr ? noErr : result; 10684 return result;
10274} 10685}
10275#endif 10686#endif
10687#endif /* TARGET_API_MAC_CARBON */
10688
10276 10689
10277#ifdef MAC_OSX
10278OSStatus 10690OSStatus
10279mac_store_service_event (event) 10691install_window_handler (window)
10280 EventRef event; 10692 WindowRef window;
10281{ 10693{
10282 OSStatus err; 10694 OSStatus err = noErr;
10283 Lisp_Object id_key;
10284 int num_params;
10285 const EventParamName *names;
10286 const EventParamType *types;
10287 static const EventParamName names_pfm[] =
10288 {kEventParamServiceMessageName, kEventParamServiceUserData};
10289 static const EventParamType types_pfm[] =
10290 {typeCFStringRef, typeCFStringRef};
10291 10695
10292 switch (GetEventKind (event)) 10696#if TARGET_API_MAC_CARBON
10697 if (err == noErr)
10293 { 10698 {
10294 case kEventServicePaste: 10699 static const EventTypeSpec specs[] =
10295 id_key = Qpaste; 10700 {
10296 num_params = 0; 10701 /* -- window refresh events -- */
10297 names = NULL; 10702 {kEventClassWindow, kEventWindowUpdate},
10298 types = NULL; 10703 /* -- window state change events -- */
10299 break; 10704 {kEventClassWindow, kEventWindowShowing},
10705 {kEventClassWindow, kEventWindowHiding},
10706 {kEventClassWindow, kEventWindowShown},
10707 {kEventClassWindow, kEventWindowHidden},
10708 {kEventClassWindow, kEventWindowCollapsed},
10709 {kEventClassWindow, kEventWindowExpanded},
10710 {kEventClassWindow, kEventWindowBoundsChanging},
10711 {kEventClassWindow, kEventWindowBoundsChanged},
10712 /* -- window action events -- */
10713 {kEventClassWindow, kEventWindowClose},
10714 {kEventClassWindow, kEventWindowGetIdealSize},
10715#ifdef MAC_OSX
10716 {kEventClassWindow, kEventWindowToolbarSwitchMode},
10717#endif
10718#if USE_MAC_TSM
10719 /* -- window focus events -- */
10720 {kEventClassWindow, kEventWindowFocusAcquired},
10721 {kEventClassWindow, kEventWindowFocusRelinquish},
10722#endif
10723 };
10724 static EventHandlerUPP handle_window_eventUPP = NULL;
10300 10725
10301 case kEventServicePerform: 10726 if (handle_window_eventUPP == NULL)
10302 id_key = Qperform; 10727 handle_window_eventUPP = NewEventHandlerUPP (mac_handle_window_event);
10303 num_params = sizeof (names_pfm) / sizeof (names_pfm[0]);
10304 names = names_pfm;
10305 types = types_pfm;
10306 break;
10307 10728
10308 default: 10729 err = InstallWindowEventHandler (window, handle_window_eventUPP,
10309 abort (); 10730 GetEventTypeCount (specs),
10731 specs, NULL, NULL);
10310 } 10732 }
10733#endif
10311 10734
10312 err = mac_store_event_ref_as_apple_event (0, 0, Qservice, id_key, 10735 if (err == noErr)
10313 event, num_params, 10736 err = install_drag_handler (window);
10314 names, types);
10315 10737
10316 return err; 10738 return err;
10317} 10739}
10318#endif /* MAC_OSX */
10319#endif /* USE_CARBON_EVENTS */
10320 10740
10741void
10742remove_window_handler (window)
10743 WindowRef window;
10744{
10745 remove_drag_handler (window);
10746}
10321 10747
10322OSStatus 10748#if TARGET_API_MAC_CARBON
10323install_window_handler (window) 10749static OSStatus
10324 WindowPtr window; 10750install_application_handler ()
10325{ 10751{
10326 OSStatus err = noErr; 10752 OSStatus err = noErr;
10327#if USE_CARBON_EVENTS
10328 static const EventTypeSpec specs_window[] =
10329 {{kEventClassWindow, kEventWindowUpdate},
10330 {kEventClassWindow, kEventWindowGetIdealSize},
10331 {kEventClassWindow, kEventWindowBoundsChanging},
10332 {kEventClassWindow, kEventWindowBoundsChanged},
10333 {kEventClassWindow, kEventWindowShown},
10334 {kEventClassWindow, kEventWindowHidden},
10335 {kEventClassWindow, kEventWindowExpanded},
10336 {kEventClassWindow, kEventWindowCollapsed},
10337 {kEventClassWindow, kEventWindowClose},
10338#ifdef MAC_OSX
10339 {kEventClassWindow, kEventWindowToolbarSwitchMode},
10340#endif
10341#if USE_MAC_TSM
10342 {kEventClassWindow, kEventWindowFocusAcquired},
10343 {kEventClassWindow, kEventWindowFocusRelinquish},
10344#endif
10345 };
10346 static const EventTypeSpec specs_mouse[] =
10347 {{kEventClassMouse, kEventMouseWheelMoved}};
10348 static EventHandlerUPP handle_window_eventUPP = NULL;
10349 static EventHandlerUPP handle_mouse_eventUPP = NULL;
10350#if USE_MAC_FONT_PANEL
10351 static const EventTypeSpec specs_font[] =
10352 {{kEventClassFont, kEventFontPanelClosed},
10353 {kEventClassFont, kEventFontSelection}};
10354 static EventHandlerUPP handle_font_eventUPP = NULL;
10355#endif
10356#if USE_MAC_TSM
10357 static const EventTypeSpec specs_text_input[] =
10358 {{kEventClassTextInput, kEventTextInputUpdateActiveInputArea},
10359 {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent},
10360 {kEventClassTextInput, kEventTextInputOffsetToPos}};
10361 static EventHandlerUPP handle_text_input_eventUPP = NULL;
10362#endif
10363 10753
10364 if (handle_window_eventUPP == NULL) 10754 if (err == noErr)
10365 handle_window_eventUPP = NewEventHandlerUPP (mac_handle_window_event); 10755 {
10366 if (handle_mouse_eventUPP == NULL) 10756 static const EventTypeSpec specs[] = {
10367 handle_mouse_eventUPP = NewEventHandlerUPP (mac_handle_mouse_event);
10368#if USE_MAC_FONT_PANEL
10369 if (handle_font_eventUPP == NULL)
10370 handle_font_eventUPP = NewEventHandlerUPP (mac_handle_font_event);
10371#endif
10372#if USE_MAC_TSM 10757#if USE_MAC_TSM
10373 if (handle_text_input_eventUPP == NULL) 10758 {kEventClassApplication, kEventAppActivated},
10374 handle_text_input_eventUPP = 10759 {kEventClassApplication, kEventAppDeactivated},
10375 NewEventHandlerUPP (mac_handle_text_input_event);
10376#endif 10760#endif
10377 err = InstallWindowEventHandler (window, handle_window_eventUPP, 10761 };
10378 GetEventTypeCount (specs_window), 10762
10379 specs_window, NULL, NULL); 10763 err = InstallApplicationEventHandler (NewEventHandlerUPP
10764 (mac_handle_application_event),
10765 GetEventTypeCount (specs),
10766 specs, NULL, NULL);
10767 }
10768
10380 if (err == noErr) 10769 if (err == noErr)
10381 err = InstallWindowEventHandler (window, handle_mouse_eventUPP, 10770 {
10382 GetEventTypeCount (specs_mouse), 10771 static const EventTypeSpec specs[] =
10383 specs_mouse, NULL, NULL); 10772 {{kEventClassKeyboard, kEventRawKeyDown},
10384#if USE_MAC_FONT_PANEL 10773 {kEventClassKeyboard, kEventRawKeyRepeat},
10774 {kEventClassKeyboard, kEventRawKeyUp}};
10775
10776 err = InstallApplicationEventHandler (NewEventHandlerUPP
10777 (mac_handle_keyboard_event),
10778 GetEventTypeCount (specs),
10779 specs, NULL, NULL);
10780 }
10781
10385 if (err == noErr) 10782 if (err == noErr)
10386 err = InstallWindowEventHandler (window, handle_font_eventUPP, 10783 {
10387 GetEventTypeCount (specs_font), 10784 static const EventTypeSpec specs[] =
10388 specs_font, NULL, NULL); 10785 {{kEventClassCommand, kEventCommandProcess}};
10389#endif 10786
10787 err = InstallApplicationEventHandler (NewEventHandlerUPP
10788 (mac_handle_command_event),
10789 GetEventTypeCount (specs),
10790 specs, NULL, NULL);
10791 }
10792
10793 if (err == noErr)
10794 {
10795 static const EventTypeSpec specs[] =
10796 {{kEventClassMouse, kEventMouseWheelMoved}};
10797
10798 err = InstallApplicationEventHandler (NewEventHandlerUPP
10799 (mac_handle_mouse_event),
10800 GetEventTypeCount (specs),
10801 specs, NULL, NULL);
10802 }
10803
10390#if USE_MAC_TSM 10804#if USE_MAC_TSM
10391 if (err == noErr) 10805 if (err == noErr)
10392 err = InstallWindowEventHandler (window, handle_text_input_eventUPP, 10806 {
10393 GetEventTypeCount (specs_text_input), 10807 static const EventTypeSpec spec[] =
10394 specs_text_input, window, NULL); 10808 {{kEventClassTextInput, kEventTextInputUpdateActiveInputArea},
10395#endif 10809 {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent},
10810 {kEventClassTextInput, kEventTextInputOffsetToPos}};
10811
10812 err = InstallApplicationEventHandler (NewEventHandlerUPP
10813 (mac_handle_text_input_event),
10814 GetEventTypeCount (spec),
10815 spec, NULL, NULL);
10816 }
10396#endif 10817#endif
10818
10397 if (err == noErr) 10819 if (err == noErr)
10398 err = install_drag_handler (window); 10820 err = install_menu_target_item_handler ();
10821
10822#ifdef MAC_OSX
10399 if (err == noErr) 10823 if (err == noErr)
10400 err = install_menu_target_item_handler (window); 10824 err = install_service_handler ();
10825#endif
10401 10826
10402 return err; 10827 return err;
10403} 10828}
10404 10829#endif
10405void
10406remove_window_handler (window)
10407 WindowPtr window;
10408{
10409 remove_drag_handler (window);
10410}
10411
10412 10830
10413static pascal void 10831static pascal void
10414mac_handle_dm_notification (event) 10832mac_handle_dm_notification (event)
@@ -10417,20 +10835,48 @@ mac_handle_dm_notification (event)
10417 mac_screen_config_changed = 1; 10835 mac_screen_config_changed = 1;
10418} 10836}
10419 10837
10838#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
10839static void
10840mac_handle_cg_display_reconfig (display, flags, user_info)
10841 CGDirectDisplayID display;
10842 CGDisplayChangeSummaryFlags flags;
10843 void *user_info;
10844{
10845 mac_screen_config_changed = 1;
10846}
10847#endif
10848
10420static OSErr 10849static OSErr
10421init_dm_notification_handler () 10850init_dm_notification_handler ()
10422{ 10851{
10423 OSErr err; 10852 OSErr err = noErr;
10424 static DMNotificationUPP handle_dm_notificationUPP = NULL;
10425 ProcessSerialNumber psn;
10426 10853
10427 if (handle_dm_notificationUPP == NULL) 10854#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
10428 handle_dm_notificationUPP = 10855#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
10429 NewDMNotificationUPP (mac_handle_dm_notification); 10856 if (CGDisplayRegisterReconfigurationCallback != NULL)
10857#endif
10858 {
10859 CGDisplayRegisterReconfigurationCallback (mac_handle_cg_display_reconfig,
10860 NULL);
10861 }
10862#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
10863 else /* CGDisplayRegisterReconfigurationCallback == NULL */
10864#endif
10865#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */
10866#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020
10867 {
10868 static DMNotificationUPP handle_dm_notificationUPP = NULL;
10869 ProcessSerialNumber psn;
10430 10870
10431 err = GetCurrentProcess (&psn); 10871 if (handle_dm_notificationUPP == NULL)
10432 if (err == noErr) 10872 handle_dm_notificationUPP =
10433 err = DMRegisterNotifyProc (handle_dm_notificationUPP, &psn); 10873 NewDMNotificationUPP (mac_handle_dm_notification);
10874
10875 err = GetCurrentProcess (&psn);
10876 if (err == noErr)
10877 err = DMRegisterNotifyProc (handle_dm_notificationUPP, &psn);
10878 }
10879#endif
10434 10880
10435 return err; 10881 return err;
10436} 10882}
@@ -10575,7 +11021,7 @@ main (void)
10575} 11021}
10576#endif 11022#endif
10577 11023
10578#if !USE_CARBON_EVENTS 11024#if !TARGET_API_MAC_CARBON
10579static RgnHandle mouse_region = NULL; 11025static RgnHandle mouse_region = NULL;
10580 11026
10581Boolean 11027Boolean
@@ -10612,7 +11058,7 @@ mac_wait_next_event (er, sleep_time, dequeue)
10612 er_buf.what = nullEvent; 11058 er_buf.what = nullEvent;
10613 return true; 11059 return true;
10614} 11060}
10615#endif /* not USE_CARBON_EVENTS */ 11061#endif /* not TARGET_API_MAC_CARBON */
10616 11062
10617#if TARGET_API_MAC_CARBON 11063#if TARGET_API_MAC_CARBON
10618OSStatus 11064OSStatus
@@ -10646,44 +11092,6 @@ mac_post_mouse_moved_event ()
10646 11092
10647 return err; 11093 return err;
10648} 11094}
10649
10650static void
10651mac_set_unicode_keystroke_event (code, buf)
10652 UniChar code;
10653 struct input_event *buf;
10654{
10655 int charset_id, c1, c2;
10656
10657 if (code < 0x80)
10658 {
10659 buf->kind = ASCII_KEYSTROKE_EVENT;
10660 buf->code = code;
10661 }
10662 else if (code < 0x100)
10663 {
10664 if (code < 0xA0)
10665 charset_id = CHARSET_8_BIT_CONTROL;
10666 else
10667 charset_id = charset_latin_iso8859_1;
10668 buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT;
10669 buf->code = MAKE_CHAR (charset_id, code, 0);
10670 }
10671 else
10672 {
10673 if (code < 0x2500)
10674 charset_id = charset_mule_unicode_0100_24ff,
10675 code -= 0x100;
10676 else if (code < 0x33FF)
10677 charset_id = charset_mule_unicode_2500_33ff,
10678 code -= 0x2500;
10679 else if (code >= 0xE000)
10680 charset_id = charset_mule_unicode_e000_ffff,
10681 code -= 0xE000;
10682 c1 = (code / 96) + 32, c2 = (code % 96) + 32;
10683 buf->kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT;
10684 buf->code = MAKE_CHAR (charset_id, c1, c2);
10685 }
10686}
10687#endif 11095#endif
10688 11096
10689/* Emacs calls this whenever it wants to read an input event from the 11097/* Emacs calls this whenever it wants to read an input event from the
@@ -10695,7 +11103,7 @@ XTread_socket (sd, expected, hold_quit)
10695{ 11103{
10696 struct input_event inev; 11104 struct input_event inev;
10697 int count = 0; 11105 int count = 0;
10698#if USE_CARBON_EVENTS 11106#if TARGET_API_MAC_CARBON
10699 EventRef eventRef; 11107 EventRef eventRef;
10700 EventTargetRef toolbox_dispatcher; 11108 EventTargetRef toolbox_dispatcher;
10701#endif 11109#endif
@@ -10716,7 +11124,7 @@ XTread_socket (sd, expected, hold_quit)
10716 11124
10717 ++handling_signal; 11125 ++handling_signal;
10718 11126
10719#if USE_CARBON_EVENTS 11127#if TARGET_API_MAC_CARBON
10720 toolbox_dispatcher = GetEventDispatcherTarget (); 11128 toolbox_dispatcher = GetEventDispatcherTarget ();
10721 11129
10722 while ( 11130 while (
@@ -10725,9 +11133,9 @@ XTread_socket (sd, expected, hold_quit)
10725#endif 11133#endif
10726 !ReceiveNextEvent (0, NULL, kEventDurationNoWait, 11134 !ReceiveNextEvent (0, NULL, kEventDurationNoWait,
10727 kEventRemoveFromQueue, &eventRef)) 11135 kEventRemoveFromQueue, &eventRef))
10728#else /* !USE_CARBON_EVENTS */ 11136#else /* !TARGET_API_MAC_CARBON */
10729 while (mac_wait_next_event (&er, 0, true)) 11137 while (mac_wait_next_event (&er, 0, true))
10730#endif /* !USE_CARBON_EVENTS */ 11138#endif /* !TARGET_API_MAC_CARBON */
10731 { 11139 {
10732 int do_help = 0; 11140 int do_help = 0;
10733 struct frame *f; 11141 struct frame *f;
@@ -10737,44 +11145,33 @@ XTread_socket (sd, expected, hold_quit)
10737 inev.kind = NO_EVENT; 11145 inev.kind = NO_EVENT;
10738 inev.arg = Qnil; 11146 inev.arg = Qnil;
10739 11147
10740#if USE_CARBON_EVENTS 11148#if TARGET_API_MAC_CARBON
10741 timestamp = GetEventTime (eventRef) / kEventDurationMillisecond; 11149 timestamp = GetEventTime (eventRef) / kEventDurationMillisecond;
10742#else
10743 timestamp = er.when * (1000 / 60); /* ticks to milliseconds */
10744#endif
10745 11150
10746#if USE_CARBON_EVENTS
10747 /* Handle new events */
10748 if (!mac_convert_event_ref (eventRef, &er)) 11151 if (!mac_convert_event_ref (eventRef, &er))
10749 { 11152 goto OTHER;
10750 /* There used to be a handler for the kEventMouseWheelMoved 11153#else /* !TARGET_API_MAC_CARBON */
10751 event here. But as of Mac OS X 10.4, this kind of event 11154 timestamp = er.when * (1000 / 60); /* ticks to milliseconds */
10752 is not directly posted to the main event queue by 11155#endif /* !TARGET_API_MAC_CARBON */
10753 two-finger scrolling on the trackpad. Instead, some 11156
10754 private event is posted and it is converted to a wheel
10755 event by the default handler for the application target.
10756 The converted one can be received by a Carbon event
10757 handler installed on a window target. */
10758 read_socket_inev = &inev;
10759 SendEventToEventTarget (eventRef, toolbox_dispatcher);
10760 read_socket_inev = NULL;
10761 }
10762 else
10763#endif /* USE_CARBON_EVENTS */
10764 switch (er.what) 11157 switch (er.what)
10765 { 11158 {
10766 case mouseDown: 11159 case mouseDown:
10767 case mouseUp: 11160 case mouseUp:
10768 { 11161 {
10769 WindowPtr window_ptr; 11162 WindowRef window_ptr;
10770 ControlPartCode part_code; 11163 ControlPartCode part_code;
10771 int tool_bar_p = 0; 11164 int tool_bar_p = 0;
10772 11165
10773#if USE_CARBON_EVENTS 11166#if TARGET_API_MAC_CARBON
11167 OSStatus err;
11168
10774 /* This is needed to send mouse events like aqua window 11169 /* This is needed to send mouse events like aqua window
10775 buttons to the correct handler. */ 11170 buttons to the correct handler. */
10776 if (SendEventToEventTarget (eventRef, toolbox_dispatcher) 11171 read_socket_inev = &inev;
10777 != eventNotHandledErr) 11172 err = SendEventToEventTarget (eventRef, toolbox_dispatcher);
11173 read_socket_inev = NULL;
11174 if (err != eventNotHandledErr)
10778 break; 11175 break;
10779#endif 11176#endif
10780 last_mouse_glyph_frame = 0; 11177 last_mouse_glyph_frame = 0;
@@ -10822,17 +11219,20 @@ XTread_socket (sd, expected, hold_quit)
10822 else 11219 else
10823 { 11220 {
10824 ControlPartCode control_part_code; 11221 ControlPartCode control_part_code;
10825 ControlHandle ch; 11222 ControlRef ch;
10826 Point mouse_loc = er.where; 11223 Point mouse_loc;
10827#ifdef MAC_OSX 11224#ifdef MAC_OSX
10828 ControlKind control_kind; 11225 ControlKind control_kind;
10829#endif 11226#endif
10830 11227
10831 f = mac_window_to_frame (window_ptr); 11228 f = mac_window_to_frame (window_ptr);
10832 /* convert to local coordinates of new window */ 11229 /* convert to local coordinates of new window */
10833 SetPortWindowPort (window_ptr); 11230 mouse_loc.h = (er.where.h
10834 11231 - (f->left_pos
10835 GlobalToLocal (&mouse_loc); 11232 + FRAME_OUTER_TO_INNER_DIFF_X (f)));
11233 mouse_loc.v = (er.where.v
11234 - (f->top_pos
11235 + FRAME_OUTER_TO_INNER_DIFF_Y (f)));
10836#if TARGET_API_MAC_CARBON 11236#if TARGET_API_MAC_CARBON
10837 ch = FindControlUnderMouse (mouse_loc, window_ptr, 11237 ch = FindControlUnderMouse (mouse_loc, window_ptr,
10838 &control_part_code); 11238 &control_part_code);
@@ -10845,7 +11245,7 @@ XTread_socket (sd, expected, hold_quit)
10845 &ch); 11245 &ch);
10846#endif 11246#endif
10847 11247
10848#if USE_CARBON_EVENTS 11248#if TARGET_API_MAC_CARBON
10849 inev.code = mac_get_mouse_btn (eventRef); 11249 inev.code = mac_get_mouse_btn (eventRef);
10850 inev.modifiers = mac_event_to_emacs_modifiers (eventRef); 11250 inev.modifiers = mac_event_to_emacs_modifiers (eventRef);
10851#else 11251#else
@@ -10981,16 +11381,14 @@ XTread_socket (sd, expected, hold_quit)
10981 DragWindow (window_ptr, er.where, NULL); 11381 DragWindow (window_ptr, er.where, NULL);
10982#else /* not TARGET_API_MAC_CARBON */ 11382#else /* not TARGET_API_MAC_CARBON */
10983 DragWindow (window_ptr, er.where, &qd.screenBits.bounds); 11383 DragWindow (window_ptr, er.where, &qd.screenBits.bounds);
10984#endif /* not TARGET_API_MAC_CARBON */
10985 /* Update the frame parameters. */ 11384 /* Update the frame parameters. */
10986#if !USE_CARBON_EVENTS
10987 { 11385 {
10988 struct frame *f = mac_window_to_frame (window_ptr); 11386 struct frame *f = mac_window_to_frame (window_ptr);
10989 11387
10990 if (f && !f->async_iconified) 11388 if (f && !f->async_iconified)
10991 mac_handle_origin_change (f); 11389 mac_handle_origin_change (f);
10992 } 11390 }
10993#endif 11391#endif /* not TARGET_API_MAC_CARBON */
10994 break; 11392 break;
10995 11393
10996 case inGoAway: 11394 case inGoAway:
@@ -11020,35 +11418,17 @@ XTread_socket (sd, expected, hold_quit)
11020 } 11418 }
11021 break; 11419 break;
11022 11420
11421#if !TARGET_API_MAC_CARBON
11023 case updateEvt: 11422 case updateEvt:
11024#if USE_CARBON_EVENTS 11423 do_window_update ((WindowRef) er.message);
11025 if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
11026 != eventNotHandledErr)
11027 break;
11028#else
11029 do_window_update ((WindowPtr) er.message);
11030#endif
11031 break; 11424 break;
11425#endif
11032 11426
11033 case osEvt: 11427 case osEvt:
11034#if USE_CARBON_EVENTS
11035 if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
11036 != eventNotHandledErr)
11037 break;
11038#endif
11039 switch ((er.message >> 24) & 0x000000FF) 11428 switch ((er.message >> 24) & 0x000000FF)
11040 { 11429 {
11041 case suspendResumeMessage:
11042#if USE_MAC_TSM
11043 if (er.message & resumeFlag)
11044 mac_tsm_resume ();
11045 else
11046 mac_tsm_suspend ();
11047#endif
11048 break;
11049
11050 case mouseMovedMessage: 11430 case mouseMovedMessage:
11051#if !USE_CARBON_EVENTS 11431#if !TARGET_API_MAC_CARBON
11052 SetRectRgn (mouse_region, er.where.h, er.where.v, 11432 SetRectRgn (mouse_region, er.where.h, er.where.v,
11053 er.where.h + 1, er.where.v + 1); 11433 er.where.h + 1, er.where.v + 1);
11054#endif 11434#endif
@@ -11069,13 +11449,15 @@ XTread_socket (sd, expected, hold_quit)
11069 11449
11070 if (f) 11450 if (f)
11071 { 11451 {
11072 WindowPtr wp = FRAME_MAC_WINDOW (f); 11452 WindowRef wp = FRAME_MAC_WINDOW (f);
11073 Point mouse_pos = er.where; 11453 Point mouse_pos;
11074 11454
11075 SetPortWindowPort (wp); 11455 mouse_pos.h = (er.where.h
11076 11456 - (f->left_pos
11077 GlobalToLocal (&mouse_pos); 11457 + FRAME_OUTER_TO_INNER_DIFF_X (f)));
11078 11458 mouse_pos.v = (er.where.v
11459 - (f->top_pos
11460 + FRAME_OUTER_TO_INNER_DIFF_Y (f)));
11079 if (dpyinfo->grabbed && tracked_scroll_bar) 11461 if (dpyinfo->grabbed && tracked_scroll_bar)
11080#ifdef USE_TOOLKIT_SCROLL_BARS 11462#ifdef USE_TOOLKIT_SCROLL_BARS
11081 x_scroll_bar_handle_drag (wp, tracked_scroll_bar, 11463 x_scroll_bar_handle_drag (wp, tracked_scroll_bar,
@@ -11123,18 +11505,16 @@ XTread_socket (sd, expected, hold_quit)
11123 if (!NILP (help_echo_string) || !NILP (previous_help_echo_string)) 11505 if (!NILP (help_echo_string) || !NILP (previous_help_echo_string))
11124 do_help = 1; 11506 do_help = 1;
11125 break; 11507 break;
11508
11509 default:
11510 goto OTHER;
11126 } 11511 }
11127 break; 11512 break;
11128 11513
11129 case activateEvt: 11514 case activateEvt:
11130 { 11515 {
11131 WindowPtr window_ptr = (WindowPtr) er.message; 11516 WindowRef window_ptr = (WindowRef) er.message;
11132 11517
11133#if USE_CARBON_EVENTS
11134 if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
11135 != eventNotHandledErr)
11136 break;
11137#endif
11138 if (window_ptr == tip_window) 11518 if (window_ptr == tip_window)
11139 { 11519 {
11140 HideWindow (tip_window); 11520 HideWindow (tip_window);
@@ -11142,21 +11522,26 @@ XTread_socket (sd, expected, hold_quit)
11142 } 11522 }
11143 11523
11144 if (!is_emacs_window (window_ptr)) 11524 if (!is_emacs_window (window_ptr))
11145 break; 11525 goto OTHER;
11526
11527 f = mac_window_to_frame (window_ptr);
11146 11528
11147 if ((er.modifiers & activeFlag) != 0) 11529 if ((er.modifiers & activeFlag) != 0)
11148 { 11530 {
11149 /* A window has been activated */ 11531 /* A window has been activated */
11150 Point mouse_loc = er.where; 11532 Point mouse_loc;
11151 11533
11152 x_detect_focus_change (dpyinfo, &er, &inev); 11534 x_detect_focus_change (dpyinfo, &er, &inev);
11153 11535
11154 SetPortWindowPort (window_ptr); 11536 mouse_loc.h = (er.where.h
11155 GlobalToLocal (&mouse_loc); 11537 - (f->left_pos
11538 + FRAME_OUTER_TO_INNER_DIFF_X (f)));
11539 mouse_loc.v = (er.where.v
11540 - (f->top_pos
11541 + FRAME_OUTER_TO_INNER_DIFF_Y (f)));
11156 /* Window-activated event counts as mouse movement, 11542 /* Window-activated event counts as mouse movement,
11157 so update things that depend on mouse position. */ 11543 so update things that depend on mouse position. */
11158 note_mouse_movement (mac_window_to_frame (window_ptr), 11544 note_mouse_movement (f, &mouse_loc);
11159 &mouse_loc);
11160 } 11545 }
11161 else 11546 else
11162 { 11547 {
@@ -11181,7 +11566,6 @@ XTread_socket (sd, expected, hold_quit)
11181 11566
11182 x_detect_focus_change (dpyinfo, &er, &inev); 11567 x_detect_focus_change (dpyinfo, &er, &inev);
11183 11568
11184 f = mac_window_to_frame (window_ptr);
11185 if (f == dpyinfo->mouse_face_mouse_frame) 11569 if (f == dpyinfo->mouse_face_mouse_frame)
11186 { 11570 {
11187 /* If we move outside the frame, then we're 11571 /* If we move outside the frame, then we're
@@ -11204,218 +11588,26 @@ XTread_socket (sd, expected, hold_quit)
11204 case keyDown: 11588 case keyDown:
11205 case keyUp: 11589 case keyUp:
11206 case autoKey: 11590 case autoKey:
11207 { 11591 ObscureCursor ();
11208 int keycode = (er.message & keyCodeMask) >> 8;
11209 static SInt16 last_key_script = -1;
11210 SInt16 current_key_script;
11211 UInt32 modifiers = er.modifiers, mapped_modifiers;
11212 11592
11213#if USE_CARBON_EVENTS && defined (MAC_OSX) 11593 f = mac_focus_frame (dpyinfo);
11214 GetEventParameter (eventRef, kEventParamKeyModifiers, 11594 XSETFRAME (inev.frame_or_window, f);
11215 typeUInt32, NULL,
11216 sizeof (UInt32), NULL, &modifiers);
11217#endif
11218 mapped_modifiers = mac_mapped_modifiers (modifiers);
11219
11220#if USE_CARBON_EVENTS && (defined (MAC_OSX) || USE_MAC_TSM)
11221 /* When using Carbon Events, we need to pass raw keyboard
11222 events to the TSM ourselves. If TSM handles it, it
11223 will pass back noErr, otherwise it will pass back
11224 "eventNotHandledErr" and we can process it
11225 normally. */
11226 if (!(mapped_modifiers
11227 & ~(mac_pass_command_to_system ? cmdKey : 0)
11228 & ~(mac_pass_control_to_system ? controlKey : 0)))
11229 {
11230 OSStatus err;
11231
11232 read_socket_inev = &inev;
11233 err = SendEventToEventTarget (eventRef, toolbox_dispatcher);
11234 read_socket_inev = NULL;
11235 if (err != eventNotHandledErr)
11236 break;
11237 }
11238#endif
11239 if (er.what == keyUp)
11240 break;
11241
11242 ObscureCursor ();
11243
11244 f = mac_focus_frame (dpyinfo);
11245
11246 if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight)
11247 && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window))
11248 {
11249 clear_mouse_face (dpyinfo);
11250 dpyinfo->mouse_face_hidden = 1;
11251 }
11252
11253 current_key_script = GetScriptManagerVariable (smKeyScript);
11254 if (last_key_script != current_key_script)
11255 {
11256 struct input_event event;
11257
11258 EVENT_INIT (event);
11259 event.kind = LANGUAGE_CHANGE_EVENT;
11260 event.arg = Qnil;
11261 event.code = current_key_script;
11262 event.timestamp = timestamp;
11263 kbd_buffer_store_event (&event);
11264 count++;
11265 last_key_script = current_key_script;
11266 }
11267
11268#if USE_MAC_TSM
11269 if (inev.kind != NO_EVENT)
11270 break;
11271#endif
11272
11273#ifdef MAC_OSX
11274 if (mapped_modifiers & kEventKeyModifierFnMask
11275 && keycode <= 0x7f
11276 && fn_keycode_to_keycode_table[keycode])
11277 keycode = fn_keycode_to_keycode_table[keycode];
11278#endif
11279 if (keycode <= 0x7f && keycode_to_xkeysym_table [keycode])
11280 {
11281 inev.kind = NON_ASCII_KEYSTROKE_EVENT;
11282 inev.code = 0xff00 | keycode_to_xkeysym_table [keycode];
11283#ifdef MAC_OSX
11284 if (modifiers & kEventKeyModifierFnMask
11285 && keycode <= 0x7f
11286 && fn_keycode_to_keycode_table[keycode] == keycode)
11287 modifiers &= ~kEventKeyModifierFnMask;
11288#endif
11289 }
11290 else if (mapped_modifiers)
11291 {
11292 /* translate the keycode back to determine the
11293 original key */
11294#ifdef MAC_OSX
11295 UCKeyboardLayout *uchr_ptr = NULL;
11296#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
11297 OSStatus err;
11298 KeyboardLayoutRef layout;
11299
11300 err = KLGetCurrentKeyboardLayout (&layout);
11301 if (err == noErr)
11302 KLGetKeyboardLayoutProperty (layout, kKLuchrData,
11303 (const void **) &uchr_ptr);
11304#else
11305 static SInt16 last_key_layout_id = 0;
11306 static Handle uchr_handle = (Handle)-1;
11307 SInt16 current_key_layout_id =
11308 GetScriptVariable (current_key_script, smScriptKeys);
11309
11310 if (uchr_handle == (Handle)-1
11311 || last_key_layout_id != current_key_layout_id)
11312 {
11313 uchr_handle = GetResource ('uchr', current_key_layout_id);
11314 last_key_layout_id = current_key_layout_id;
11315 }
11316 if (uchr_handle)
11317 uchr_ptr = (UCKeyboardLayout *)*uchr_handle;
11318#endif
11319
11320 if (uchr_ptr)
11321 {
11322 OSStatus status;
11323 UInt16 key_action = er.what - keyDown;
11324 UInt32 modifier_key_state =
11325 (modifiers & ~mapped_modifiers) >> 8;
11326 UInt32 keyboard_type = LMGetKbdType ();
11327 SInt32 dead_key_state = 0;
11328 UniChar code;
11329 UniCharCount actual_length;
11330
11331 status = UCKeyTranslate (uchr_ptr,
11332 keycode, key_action,
11333 modifier_key_state,
11334 keyboard_type,
11335 kUCKeyTranslateNoDeadKeysMask,
11336 &dead_key_state,
11337 1, &actual_length, &code);
11338 if (status == noErr && actual_length == 1)
11339 mac_set_unicode_keystroke_event (code, &inev);
11340 }
11341#endif /* MAC_OSX */
11342
11343 if (inev.kind == NO_EVENT)
11344 {
11345 /* This code comes from Keyboard Resource,
11346 Appendix C of IM - Text. This is necessary
11347 since shift is ignored in KCHR table
11348 translation when option or command is pressed.
11349 It also does not translate correctly
11350 control-shift chars like C-% so mask off shift
11351 here also. */
11352 /* Mask off modifier keys that are mapped to some
11353 Emacs modifiers. */
11354 int new_modifiers = er.modifiers & ~mapped_modifiers;
11355 /* set high byte of keycode to modifier high byte*/
11356 int new_keycode = keycode | new_modifiers;
11357 Ptr kchr_ptr = (Ptr) GetScriptManagerVariable (smKCHRCache);
11358 unsigned long some_state = 0;
11359 UInt32 new_char_code;
11360
11361 new_char_code = KeyTranslate (kchr_ptr, new_keycode,
11362 &some_state);
11363 if (new_char_code == 0)
11364 /* Seems like a dead key. Append up-stroke. */
11365 new_char_code = KeyTranslate (kchr_ptr,
11366 new_keycode | 0x80,
11367 &some_state);
11368 if (new_char_code)
11369 {
11370 inev.kind = ASCII_KEYSTROKE_EVENT;
11371 inev.code = new_char_code & 0xff;
11372 }
11373 }
11374 }
11375
11376 if (inev.kind == NO_EVENT)
11377 {
11378 inev.kind = ASCII_KEYSTROKE_EVENT;
11379 inev.code = er.message & charCodeMask;
11380 }
11381
11382 inev.modifiers = mac_to_emacs_modifiers (modifiers);
11383 inev.modifiers |= (extra_keyboard_modifiers
11384 & (meta_modifier | alt_modifier
11385 | hyper_modifier | super_modifier));
11386 XSETFRAME (inev.frame_or_window, f);
11387 11595
11596 /* If mouse-highlight is an integer, input clears out mouse
11597 highlighting. */
11598 if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight)
11599 && !EQ (f->tool_bar_window, dpyinfo->mouse_face_window))
11600 {
11601 clear_mouse_face (dpyinfo);
11602 dpyinfo->mouse_face_hidden = 1;
11603 }
11388#if TARGET_API_MAC_CARBON 11604#if TARGET_API_MAC_CARBON
11389 if (inev.kind == ASCII_KEYSTROKE_EVENT 11605 goto OTHER;
11390 && inev.code >= 0x80 && inev.modifiers) 11606#else
11391 { 11607 do_keystroke (er.what, er.message & charCodeMask,
11392 OSStatus err; 11608 (er.message & keyCodeMask) >> 8,
11393 TextEncoding encoding = kTextEncodingMacRoman; 11609 er.modifiers, timestamp, &inev);
11394 TextToUnicodeInfo ttu_info;
11395
11396 UpgradeScriptInfoToTextEncoding (current_key_script,
11397 kTextLanguageDontCare,
11398 kTextRegionDontCare,
11399 NULL, &encoding);
11400 err = CreateTextToUnicodeInfoByEncoding (encoding, &ttu_info);
11401 if (err == noErr)
11402 {
11403 UniChar code;
11404 Str255 pstr;
11405 ByteCount unicode_len;
11406
11407 pstr[0] = 1;
11408 pstr[1] = inev.code;
11409 err = ConvertFromPStringToUnicode (ttu_info, pstr,
11410 sizeof (UniChar),
11411 &unicode_len, &code);
11412 if (err == noErr && unicode_len == sizeof (UniChar))
11413 mac_set_unicode_keystroke_event (code, &inev);
11414 DisposeTextToUnicodeInfo (&ttu_info);
11415 }
11416 }
11417#endif 11610#endif
11418 }
11419 break; 11611 break;
11420 11612
11421 case kHighLevelEvent: 11613 case kHighLevelEvent:
@@ -11423,9 +11615,19 @@ XTread_socket (sd, expected, hold_quit)
11423 break; 11615 break;
11424 11616
11425 default: 11617 default:
11618 OTHER:
11619#if TARGET_API_MAC_CARBON
11620 {
11621 OSStatus err;
11622
11623 read_socket_inev = &inev;
11624 err = SendEventToEventTarget (eventRef, toolbox_dispatcher);
11625 read_socket_inev = NULL;
11626 }
11627#endif
11426 break; 11628 break;
11427 } 11629 }
11428#if USE_CARBON_EVENTS 11630#if TARGET_API_MAC_CARBON
11429 ReleaseEvent (eventRef); 11631 ReleaseEvent (eventRef);
11430#endif 11632#endif
11431 11633
@@ -11477,7 +11679,7 @@ XTread_socket (sd, expected, hold_quit)
11477 mac_screen_config_changed = 0; 11679 mac_screen_config_changed = 0;
11478 } 11680 }
11479 11681
11480#if !USE_CARBON_EVENTS 11682#if !TARGET_API_MAC_CARBON
11481 /* Check which frames are still visible. We do this here because 11683 /* Check which frames are still visible. We do this here because
11482 there doesn't seem to be any direct notification from the Window 11684 there doesn't seem to be any direct notification from the Window
11483 Manager that the visibility of a window has changed (at least, 11685 Manager that the visibility of a window has changed (at least,
@@ -11582,7 +11784,7 @@ make_mac_terminal_frame (struct frame *f)
11582 11784
11583 if (!(FRAME_MAC_WINDOW (f) = 11785 if (!(FRAME_MAC_WINDOW (f) =
11584 NewCWindow (NULL, &r, "\p", true, dBoxProc, 11786 NewCWindow (NULL, &r, "\p", true, dBoxProc,
11585 (WindowPtr) -1, 1, (long) f->output_data.mac))) 11787 (WindowRef) -1, 1, (long) f->output_data.mac)))
11586 abort (); 11788 abort ();
11587 /* so that update events can find this mac_output struct */ 11789 /* so that update events can find this mac_output struct */
11588 f->output_data.mac->mFP = f; /* point back to emacs frame */ 11790 f->output_data.mac->mFP = f; /* point back to emacs frame */
@@ -11780,7 +11982,6 @@ init_menu_bar ()
11780 &menu, &menu_index); 11982 &menu, &menu_index);
11781 if (err == noErr) 11983 if (err == noErr)
11782 SetMenuItemCommandKey (menu, menu_index, false, 0); 11984 SetMenuItemCommandKey (menu, menu_index, false, 0);
11783#if USE_CARBON_EVENTS
11784 EnableMenuCommand (NULL, kHICommandPreferences); 11985 EnableMenuCommand (NULL, kHICommandPreferences);
11785 err = GetIndMenuItemWithCommandID (NULL, kHICommandPreferences, 1, 11986 err = GetIndMenuItemWithCommandID (NULL, kHICommandPreferences, 1,
11786 &menu, &menu_index); 11987 &menu, &menu_index);
@@ -11792,10 +11993,9 @@ init_menu_bar ()
11792 InsertMenuItemTextWithCFString (menu, CFSTR ("About Emacs"), 11993 InsertMenuItemTextWithCFString (menu, CFSTR ("About Emacs"),
11793 0, 0, kHICommandAbout); 11994 0, 0, kHICommandAbout);
11794 } 11995 }
11795#endif /* USE_CARBON_EVENTS */
11796#else /* !MAC_OSX */ 11996#else /* !MAC_OSX */
11797#if USE_CARBON_EVENTS 11997#if TARGET_API_MAC_CARBON
11798 SetMenuItemCommandID (GetMenuHandle (M_APPLE), I_ABOUT, kHICommandAbout); 11998 SetMenuItemCommandID (GetMenuRef (M_APPLE), I_ABOUT, kHICommandAbout);
11799#endif 11999#endif
11800#endif 12000#endif
11801} 12001}
@@ -11929,19 +12129,13 @@ mac_initialize ()
11929 12129
11930#if TARGET_API_MAC_CARBON 12130#if TARGET_API_MAC_CARBON
11931 12131
11932#if USE_CARBON_EVENTS 12132 install_application_handler ();
11933#ifdef MAC_OSX
11934 init_service_handler ();
11935#endif /* MAC_OSX */
11936
11937 init_command_handler ();
11938 12133
11939 init_menu_bar (); 12134 init_menu_bar ();
11940 12135
11941#if USE_MAC_TSM 12136#if USE_MAC_TSM
11942 init_tsm (); 12137 init_tsm ();
11943#endif 12138#endif
11944#endif /* USE_CARBON_EVENTS */
11945 12139
11946#ifdef MAC_OSX 12140#ifdef MAC_OSX
11947 init_coercion_handler (); 12141 init_coercion_handler ();
@@ -11992,7 +12186,7 @@ syms_of_macterm ()
11992 Fput (Qhyper, Qmodifier_value, make_number (hyper_modifier)); 12186 Fput (Qhyper, Qmodifier_value, make_number (hyper_modifier));
11993 Fput (Qsuper, Qmodifier_value, make_number (super_modifier)); 12187 Fput (Qsuper, Qmodifier_value, make_number (super_modifier));
11994 12188
11995#if USE_CARBON_EVENTS 12189#if TARGET_API_MAC_CARBON
11996 Qhi_command = intern ("hi-command"); staticpro (&Qhi_command); 12190 Qhi_command = intern ("hi-command"); staticpro (&Qhi_command);
11997#ifdef MAC_OSX 12191#ifdef MAC_OSX
11998 Qtoolbar_switch_mode = intern ("toolbar-switch-mode"); 12192 Qtoolbar_switch_mode = intern ("toolbar-switch-mode");
@@ -12117,7 +12311,7 @@ The symbol `reverse' means that the option-key will register for
12117mouse-3 and the command-key will register for mouse-2. */); 12311mouse-3 and the command-key will register for mouse-2. */);
12118 Vmac_emulate_three_button_mouse = Qnil; 12312 Vmac_emulate_three_button_mouse = Qnil;
12119 12313
12120#if USE_CARBON_EVENTS 12314#if TARGET_API_MAC_CARBON
12121 DEFVAR_BOOL ("mac-wheel-button-is-mouse-2", &mac_wheel_button_is_mouse_2, 12315 DEFVAR_BOOL ("mac-wheel-button-is-mouse-2", &mac_wheel_button_is_mouse_2,
12122 doc: /* *Non-nil if the wheel button is mouse-2 and the right click mouse-3. 12316 doc: /* *Non-nil if the wheel button is mouse-2 and the right click mouse-3.
12123Otherwise, the right click will be treated as mouse-2 and the wheel 12317Otherwise, the right click will be treated as mouse-2 and the wheel
diff --git a/src/macterm.h b/src/macterm.h
index fe61674f30f..c880143634e 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. */
@@ -614,9 +620,10 @@ extern void x_free_frame_resources P_ ((struct frame *));
614extern void x_destroy_window P_ ((struct frame *)); 620extern 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 Pixmap XCreatePixmap P_ ((Display *, WindowPtr, unsigned int, 623extern void mac_initialize P_ ((void));
624extern Pixmap XCreatePixmap P_ ((Display *, WindowRef, unsigned int,
618 unsigned int, unsigned int)); 625 unsigned int, unsigned int));
619extern Pixmap XCreatePixmapFromBitmapData P_ ((Display *, WindowPtr, char *, 626extern Pixmap XCreatePixmapFromBitmapData P_ ((Display *, WindowRef, char *,
620 unsigned int, unsigned int, 627 unsigned int, unsigned int,
621 unsigned long, unsigned long, 628 unsigned long, unsigned long,
622 unsigned int)); 629 unsigned int));
@@ -625,7 +632,7 @@ extern GC XCreateGC P_ ((Display *, void *, unsigned long, XGCValues *));
625extern void XFreeGC P_ ((Display *, GC)); 632extern void XFreeGC P_ ((Display *, GC));
626extern void XSetForeground P_ ((Display *, GC, unsigned long)); 633extern void XSetForeground P_ ((Display *, GC, unsigned long));
627extern void XSetBackground P_ ((Display *, GC, unsigned long)); 634extern void XSetBackground P_ ((Display *, GC, unsigned long));
628extern void XSetWindowBackground P_ ((Display *, WindowPtr, unsigned long)); 635extern void XSetWindowBackground P_ ((Display *, WindowRef, unsigned long));
629extern void XDrawLine P_ ((Display *, Pixmap, GC, int, int, int, int)); 636extern void XDrawLine P_ ((Display *, Pixmap, GC, int, int, int, int));
630extern void mac_clear_area P_ ((struct frame *, int, int, 637extern void mac_clear_area P_ ((struct frame *, int, int,
631 unsigned int, unsigned int)); 638 unsigned int, unsigned int));
@@ -633,8 +640,8 @@ extern void mac_unload_font P_ ((struct mac_display_info *, XFontStruct *));
633extern int mac_font_panel_visible_p P_ ((void)); 640extern int mac_font_panel_visible_p P_ ((void));
634extern OSStatus mac_show_hide_font_panel P_ ((void)); 641extern OSStatus mac_show_hide_font_panel P_ ((void));
635extern 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));
636extern OSStatus install_window_handler P_ ((WindowPtr)); 643extern OSStatus install_window_handler P_ ((WindowRef));
637extern void remove_window_handler P_ ((WindowPtr)); 644extern void remove_window_handler P_ ((WindowRef));
638extern OSStatus mac_post_mouse_moved_event P_ ((void)); 645extern OSStatus mac_post_mouse_moved_event P_ ((void));
639#if !TARGET_API_MAC_CARBON 646#if !TARGET_API_MAC_CARBON
640extern void do_apple_menu P_ ((SInt16)); 647extern void do_apple_menu P_ ((SInt16));
@@ -642,6 +649,7 @@ extern void do_apple_menu P_ ((SInt16));
642#if USE_CG_DRAWING 649#if USE_CG_DRAWING
643extern void mac_prepare_for_quickdraw P_ ((struct frame *)); 650extern void mac_prepare_for_quickdraw P_ ((struct frame *));
644#endif 651#endif
652extern void mac_get_window_bounds P_ ((struct frame *, Rect *, Rect *));
645extern int mac_quit_char_key_p P_ ((UInt32, UInt32)); 653extern int mac_quit_char_key_p P_ ((UInt32, UInt32));
646 654
647#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 34caf2b430f..698a3478eb7 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 75888f2df2a..57c3cdfcd43 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 abc28619199..c9c6dfdd242 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2095,7 +2095,7 @@ wordify (string)
2095 if (SYNTAX (prev_c) == Sword) 2095 if (SYNTAX (prev_c) == Sword)
2096 word_count++; 2096 word_count++;
2097 if (!word_count) 2097 if (!word_count)
2098 return empty_string; 2098 return empty_unibyte_string;
2099 2099
2100 adjust = - punct_count + 5 * (word_count - 1) + 4; 2100 adjust = - punct_count + 5 * (word_count - 1) + 4;
2101 if (STRING_MULTIBYTE (string)) 2101 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 3a7490a2a30..ceeac103e85 100644
--- a/src/term.c
+++ b/src/term.c
@@ -208,11 +208,6 @@ static int mouse_face_past_end;
208static Lisp_Object Qmouse_face_window; 208static Lisp_Object Qmouse_face_window;
209static int mouse_face_face_id; 209static int mouse_face_face_id;
210 210
211/* FRAME and X, Y position of mouse when last checked for
212 highlighting. X and Y can be negative or out of range for the frame. */
213struct frame *mouse_face_mouse_frame;
214int mouse_face_mouse_x, mouse_face_mouse_y;
215
216static int pos_x, pos_y; 211static int pos_x, pos_y;
217static int last_mouse_x, last_mouse_y; 212static int last_mouse_x, last_mouse_y;
218#endif /* HAVE_GPM */ 213#endif /* HAVE_GPM */
@@ -2344,17 +2339,18 @@ the currently selected frame. */)
2344 ***********************************************************************/ 2339 ***********************************************************************/
2345 2340
2346#ifdef HAVE_GPM 2341#ifdef HAVE_GPM
2347void term_mouse_moveto (int x, int y) 2342void
2343term_mouse_moveto (int x, int y)
2348{ 2344{
2349 const char *name; 2345 const char *name;
2350 int fd; 2346 int fd;
2347 /* TODO: how to set mouse position?
2351 name = (const char *) ttyname (0); 2348 name = (const char *) ttyname (0);
2352 fd = open (name, O_WRONLY); 2349 fd = open (name, O_WRONLY);
2353 /* TODO: how to set mouse position? 2350 SOME_FUNCTION (x, y, fd);
2354 SOME_FUNCTION (x, y, fd); */
2355 close (fd); 2351 close (fd);
2356 last_mouse_x = x; 2352 last_mouse_x = x;
2357 last_mouse_y = y; 2353 last_mouse_y = y; */
2358} 2354}
2359 2355
2360static void 2356static void
@@ -2534,10 +2530,6 @@ term_mouse_highlight (struct frame *f, int x, int y)
2534 || !f->glyphs_initialized_p) 2530 || !f->glyphs_initialized_p)
2535 return; 2531 return;
2536 2532
2537 mouse_face_mouse_x = x;
2538 mouse_face_mouse_y = y;
2539 mouse_face_mouse_frame = f;
2540
2541 /* Which window is that in? */ 2533 /* Which window is that in? */
2542 window = window_from_coordinates (f, x, y, &part, &x, &y, 0); 2534 window = window_from_coordinates (f, x, y, &part, &x, &y, 0);
2543 2535
@@ -2779,7 +2771,7 @@ term_mouse_movement (FRAME_PTR frame, Gpm_Event *event)
2779 if (event->x != last_mouse_x || event->y != last_mouse_y) 2771 if (event->x != last_mouse_x || event->y != last_mouse_y)
2780 { 2772 {
2781 frame->mouse_moved = 1; 2773 frame->mouse_moved = 1;
2782 term_mouse_highlight (frame, event->x - 1, event->y - 1); 2774 term_mouse_highlight (frame, event->x, event->y);
2783 /* Remember which glyph we're now on. */ 2775 /* Remember which glyph we're now on. */
2784 last_mouse_x = event->x; 2776 last_mouse_x = event->x;
2785 last_mouse_y = event->y; 2777 last_mouse_y = event->y;
@@ -2799,7 +2791,7 @@ term_mouse_movement (FRAME_PTR frame, Gpm_Event *event)
2799 2791
2800 Set *time to the time the mouse was at the returned position. 2792 Set *time to the time the mouse was at the returned position.
2801 2793
2802 This should clear mouse_moved until the next motion 2794 This clears mouse_moved until the next motion
2803 event arrives. */ 2795 event arrives. */
2804static void 2796static void
2805term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window, 2797term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
@@ -2807,8 +2799,6 @@ term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
2807 Lisp_Object *y, unsigned long *time) 2799 Lisp_Object *y, unsigned long *time)
2808{ 2800{
2809 struct timeval now; 2801 struct timeval now;
2810 Lisp_Object frame, window;
2811 struct window *w;
2812 2802
2813 *fp = SELECTED_FRAME (); 2803 *fp = SELECTED_FRAME ();
2814 (*fp)->mouse_moved = 0; 2804 (*fp)->mouse_moved = 0;
@@ -2816,13 +2806,8 @@ term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
2816 *bar_window = Qnil; 2806 *bar_window = Qnil;
2817 *part = 0; 2807 *part = 0;
2818 2808
2819 XSETINT (*x, last_mouse_x); 2809 XSETINT (*x, last_mouse_x);
2820 XSETINT (*y, last_mouse_y); 2810 XSETINT (*y, last_mouse_y);
2821 XSETFRAME (frame, *fp);
2822 window = Fwindow_at (*x, *y, frame);
2823
2824 XSETINT (*x, last_mouse_x - WINDOW_LEFT_EDGE_COL (XWINDOW (window)));
2825 XSETINT (*y, last_mouse_y - WINDOW_TOP_EDGE_LINE (XWINDOW (window)));
2826 gettimeofday(&now, 0); 2811 gettimeofday(&now, 0);
2827 *time = (now.tv_sec * 1000) + (now.tv_usec / 1000); 2812 *time = (now.tv_sec * 1000) + (now.tv_usec / 1000);
2828} 2813}
@@ -2869,7 +2854,7 @@ term_mouse_click (struct input_event *result, Gpm_Event *event,
2869 if (event->type & GPM_DRAG) 2854 if (event->type & GPM_DRAG)
2870 result->modifiers |= drag_modifier; 2855 result->modifiers |= drag_modifier;
2871 2856
2872 if (!(event->type & (GPM_MOVE|GPM_DRAG))) { 2857 if (!(event->type & (GPM_MOVE | GPM_DRAG))) {
2873 2858
2874 /* 1 << KG_SHIFT */ 2859 /* 1 << KG_SHIFT */
2875 if (event->modifiers & (1 << 0)) 2860 if (event->modifiers & (1 << 0))
@@ -2885,8 +2870,8 @@ term_mouse_click (struct input_event *result, Gpm_Event *event,
2885 result->modifiers |= meta_modifier; 2870 result->modifiers |= meta_modifier;
2886 } 2871 }
2887 2872
2888 XSETINT (result->x, event->x - 1); 2873 XSETINT (result->x, event->x);
2889 XSETINT (result->y, event->y - 1); 2874 XSETINT (result->y, event->y);
2890 XSETFRAME (result->frame_or_window, f); 2875 XSETFRAME (result->frame_or_window, f);
2891 result->arg = Qnil; 2876 result->arg = Qnil;
2892 return Qnil; 2877 return Qnil;
@@ -2905,7 +2890,7 @@ handle_one_term_event (struct tty_display_info *tty, Gpm_Event *event, struct in
2905 ie.kind = NO_EVENT; 2890 ie.kind = NO_EVENT;
2906 ie.arg = Qnil; 2891 ie.arg = Qnil;
2907 2892
2908 if (event->type & GPM_MOVE) { 2893 if (event->type & (GPM_MOVE | GPM_DRAG)) {
2909 unsigned char buf[6 * sizeof (short)]; 2894 unsigned char buf[6 * sizeof (short)];
2910 unsigned short *arg = (unsigned short *) buf + 1; 2895 unsigned short *arg = (unsigned short *) buf + 1;
2911 const char *name; 2896 const char *name;
@@ -2916,8 +2901,8 @@ handle_one_term_event (struct tty_display_info *tty, Gpm_Event *event, struct in
2916 /* Display mouse pointer */ 2901 /* Display mouse pointer */
2917 buf[sizeof(short) - 1] = 2; /* set selection */ 2902 buf[sizeof(short) - 1] = 2; /* set selection */
2918 2903
2919 arg[0] = arg[2] = (unsigned short) event->x; 2904 arg[0] = arg[2] = (unsigned short) event->x + gpm_zerobased;
2920 arg[1] = arg[3] = (unsigned short) event->y; 2905 arg[1] = arg[3] = (unsigned short) event->y + gpm_zerobased;
2921 arg[4] = (unsigned short) 3; 2906 arg[4] = (unsigned short) 3;
2922 2907
2923 name = (const char *) ttyname (0); 2908 name = (const char *) ttyname (0);
@@ -2925,7 +2910,8 @@ handle_one_term_event (struct tty_display_info *tty, Gpm_Event *event, struct in
2925 ioctl (fd, TIOCLINUX, buf + sizeof (short) - 1); 2910 ioctl (fd, TIOCLINUX, buf + sizeof (short) - 1);
2926 close (fd); 2911 close (fd);
2927 2912
2928 term_mouse_movement (f, event); 2913 if (!term_mouse_movement (f, event))
2914 help_echo_string = previous_help_echo_string;
2929 2915
2930 /* If the contents of the global variable help_echo_string 2916 /* If the contents of the global variable help_echo_string
2931 has changed, generate a HELP_EVENT. */ 2917 has changed, generate a HELP_EVENT. */
@@ -2977,6 +2963,7 @@ DEFUN ("term-open-connection", Fterm_open_connection, Sterm_open_connection,
2977 connection.defaultMask = ~GPM_HARD; 2963 connection.defaultMask = ~GPM_HARD;
2978 connection.maxMod = ~0; 2964 connection.maxMod = ~0;
2979 connection.minMod = 0; 2965 connection.minMod = 0;
2966 gpm_zerobased = 1;
2980 2967
2981 /* We only support GPM on the controlling tty. */ 2968 /* We only support GPM on the controlling tty. */
2982 if (term_gpm || tty->terminal->id > 1 2969 if (term_gpm || tty->terminal->id > 1
diff --git a/src/w32fns.c b/src/w32fns.c
index 0306804f14c..e76ca2ddc62 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -7925,9 +7925,9 @@ If ONLY-DIR-P is non-nil, the user can only select directories. */)
7925 /* Apparently NT4 crashes if you give it an unexpected size. 7925 /* Apparently NT4 crashes if you give it an unexpected size.
7926 I'm not sure about Windows 9x, so play it safe. */ 7926 I'm not sure about Windows 9x, so play it safe. */
7927 if (w32_major_version > 4 && w32_major_version < 95) 7927 if (w32_major_version > 4 && w32_major_version < 95)
7928 file_details->lStructSize = sizeof (new_file_details); 7928 file_details->lStructSize = sizeof (NEWOPENFILENAME);
7929 else 7929 else
7930 file_details->lStructSize = sizeof (file_details); 7930 file_details->lStructSize = sizeof (OPENFILENAME);
7931 7931
7932 file_details->hwndOwner = FRAME_W32_WINDOW (f); 7932 file_details->hwndOwner = FRAME_W32_WINDOW (f);
7933 /* Undocumented Bug in Common File Dialog: 7933 /* Undocumented Bug in Common File Dialog:
diff --git a/src/window.c b/src/window.c
index 90fdbf6c9b5..70cb04fa63d 100644
--- a/src/window.c
+++ b/src/window.c
@@ -4112,8 +4112,8 @@ too small. */)
4112DEFUN ("shrink-window", Fshrink_window, Sshrink_window, 1, 2, "p", 4112DEFUN ("shrink-window", Fshrink_window, Sshrink_window, 1, 2, "p",
4113 doc: /* Make current window ARG lines smaller. 4113 doc: /* Make current window ARG lines smaller.
4114From program, optional second arg non-nil means shrink sideways arg columns. 4114From program, optional second arg non-nil means shrink sideways arg columns.
4115Interactively, if an argument is not given, make the window one line smaller. Only 4115Interactively, if an argument is not given, make the window one line smaller.
4116siblings to the right or below are changed. */) 4116Only siblings to the right or below are changed. */)
4117 (arg, side) 4117 (arg, side)
4118 Lisp_Object arg, side; 4118 Lisp_Object arg, side;
4119{ 4119{
diff --git a/src/xdisp.c b/src/xdisp.c
index 268f1ec8b8c..afa7f92a1cc 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -17354,7 +17354,7 @@ are the selected window and the window's buffer). */)
17354 CHECK_BUFFER (buffer); 17354 CHECK_BUFFER (buffer);
17355 17355
17356 if (NILP (format)) 17356 if (NILP (format))
17357 return build_string (""); 17357 return empty_unibyte_string;
17358 17358
17359 if (no_props) 17359 if (no_props)
17360 face = Qnil; 17360 face = Qnil;
@@ -17412,7 +17412,7 @@ are the selected window and the window's buffer). */)
17412 { 17412 {
17413 mode_line_string_list = Fnreverse (mode_line_string_list); 17413 mode_line_string_list = Fnreverse (mode_line_string_list);
17414 str = Fmapconcat (intern ("identity"), mode_line_string_list, 17414 str = Fmapconcat (intern ("identity"), mode_line_string_list,
17415 make_string ("", 0)); 17415 empty_unibyte_string);
17416 } 17416 }
17417 17417
17418 unbind_to (count, Qnil); 17418 unbind_to (count, Qnil);
@@ -24097,7 +24097,7 @@ and is used only on frames for which no explicit name has been set
24097 = Vframe_title_format 24097 = Vframe_title_format
24098 = Fcons (intern ("multiple-frames"), 24098 = Fcons (intern ("multiple-frames"),
24099 Fcons (build_string ("%b"), 24099 Fcons (build_string ("%b"),
24100 Fcons (Fcons (empty_string, 24100 Fcons (Fcons (empty_unibyte_string,
24101 Fcons (intern ("invocation-name"), 24101 Fcons (intern ("invocation-name"),
24102 Fcons (build_string ("@"), 24102 Fcons (build_string ("@"),
24103 Fcons (intern ("system-name"), 24103 Fcons (intern ("system-name"),
diff --git a/src/xfaces.c b/src/xfaces.c
index 86a40078919..75c8b3c7f49 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -3952,6 +3952,8 @@ Otherwise check for the existence of a global face. */)
3952{ 3952{
3953 Lisp_Object lface; 3953 Lisp_Object lface;
3954 3954
3955 face = resolve_face_name (face, 1);
3956
3955 if (!NILP (frame)) 3957 if (!NILP (frame))
3956 { 3958 {
3957 CHECK_LIVE_FRAME (frame); 3959 CHECK_LIVE_FRAME (frame);
diff --git a/src/xfns.c b/src/xfns.c
index f2c85814847..e51dea84118 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1525,6 +1525,8 @@ x_set_scroll_bar_background (f, value, oldval)
1525/* Encode Lisp string STRING as a text in a format appropriate for 1525/* Encode Lisp string STRING as a text in a format appropriate for
1526 XICCC (X Inter Client Communication Conventions). 1526 XICCC (X Inter Client Communication Conventions).
1527 1527
1528 This can call Lisp code, so callers must GCPRO.
1529
1528 If STRING contains only ASCII characters, do no conversion and 1530 If STRING contains only ASCII characters, do no conversion and
1529 return the string data of STRING. Otherwise, encode the text by 1531 return the string data of STRING. Otherwise, encode the text by
1530 CODING_SYSTEM, and return a newly allocated memory area which 1532 CODING_SYSTEM, and return a newly allocated memory area which
@@ -1572,7 +1574,11 @@ x_encode_text (string, coding_system, selectionp, text_bytes, stringp, freep)
1572 && SYMBOLP (coding.pre_write_conversion) 1574 && SYMBOLP (coding.pre_write_conversion)
1573 && !NILP (Ffboundp (coding.pre_write_conversion))) 1575 && !NILP (Ffboundp (coding.pre_write_conversion)))
1574 { 1576 {
1577 struct gcpro gcpro1;
1578 /* We don't need to GCPRO string. */
1579 GCPRO1 (coding_system);
1575 string = run_pre_post_conversion_on_str (string, &coding, 1); 1580 string = run_pre_post_conversion_on_str (string, &coding, 1);
1581 UNGCPRO;
1576 str = SDATA (string); 1582 str = SDATA (string);
1577 chars = SCHARS (string); 1583 chars = SCHARS (string);
1578 bytes = SBYTES (string); 1584 bytes = SBYTES (string);
@@ -1614,6 +1620,16 @@ x_set_name_internal (f, name)
1614 int bytes, stringp; 1620 int bytes, stringp;
1615 int do_free_icon_value = 0, do_free_text_value = 0; 1621 int do_free_icon_value = 0, do_free_text_value = 0;
1616 Lisp_Object coding_system; 1622 Lisp_Object coding_system;
1623#ifdef USE_GTK
1624 Lisp_Object encoded_name;
1625 struct gcpro gcpro1;
1626
1627 /* As ENCODE_UTF_8 may cause GC and relocation of string data,
1628 we use it before x_encode_text that may return string data. */
1629 GCPRO1 (name);
1630 encoded_name = ENCODE_UTF_8 (name);
1631 UNGCPRO;
1632#endif
1617 1633
1618 coding_system = Qcompound_text; 1634 coding_system = Qcompound_text;
1619 /* Note: Encoding strategy 1635 /* Note: Encoding strategy
@@ -1654,7 +1670,7 @@ x_set_name_internal (f, name)
1654 1670
1655#ifdef USE_GTK 1671#ifdef USE_GTK
1656 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), 1672 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
1657 (char *) SDATA (ENCODE_UTF_8 (name))); 1673 (char *) SDATA (encoded_name));
1658#else /* not USE_GTK */ 1674#else /* not USE_GTK */
1659 XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text); 1675 XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text);
1660#endif /* not USE_GTK */ 1676#endif /* not USE_GTK */
@@ -1840,9 +1856,9 @@ x_default_scroll_bar_color_parameter (f, alist, prop, xprop, xclass,
1840 build_string (foreground_p 1856 build_string (foreground_p
1841 ? "foreground" 1857 ? "foreground"
1842 : "background"), 1858 : "background"),
1843 empty_string, 1859 empty_unibyte_string,
1844 build_string ("verticalScrollBar"), 1860 build_string ("verticalScrollBar"),
1845 empty_string); 1861 empty_unibyte_string);
1846 if (!STRINGP (tem)) 1862 if (!STRINGP (tem))
1847 { 1863 {
1848 /* If nothing has been specified, scroll bars will use a 1864 /* If nothing has been specified, scroll bars will use a
diff --git a/src/xmenu.c b/src/xmenu.c
index 228c89f9aa4..4390d9429af 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}
@@ -3470,7 +3470,7 @@ menu_help_callback (help_string, pane, item)
3470 pane_name = first_item[MENU_ITEMS_PANE_NAME]; 3470 pane_name = first_item[MENU_ITEMS_PANE_NAME];
3471 else if (EQ (first_item[0], Qquote)) 3471 else if (EQ (first_item[0], Qquote))
3472 /* This shouldn't happen, see xmenu_show. */ 3472 /* This shouldn't happen, see xmenu_show. */
3473 pane_name = empty_string; 3473 pane_name = empty_unibyte_string;
3474 else 3474 else
3475 pane_name = first_item[MENU_ITEMS_ITEM_NAME]; 3475 pane_name = first_item[MENU_ITEMS_ITEM_NAME];
3476 3476
diff --git a/src/xselect.c b/src/xselect.c
index 5ce6763cd30..e491e5b661e 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -2712,7 +2712,7 @@ If the value is 0 or the atom is not known, return the empty string. */)
2712 ret = make_string (name, strlen (name)); 2712 ret = make_string (name, strlen (name));
2713 2713
2714 if (atom && name) XFree (name); 2714 if (atom && name) XFree (name);
2715 if (NILP (ret)) ret = make_string ("", 0); 2715 if (NILP (ret)) ret = empty_unibyte_string;
2716 2716
2717 UNBLOCK_INPUT; 2717 UNBLOCK_INPUT;
2718 2718
diff --git a/src/xterm.c b/src/xterm.c
index 6fcaa3d1294..9f392710270 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -8397,7 +8397,7 @@ wm_supports (f, atomname)
8397 prop_atom, 0, max_len, False, target_type, 8397 prop_atom, 0, max_len, False, target_type,
8398 &actual_type, &actual_format, &actual_size, 8398 &actual_type, &actual_format, &actual_size,
8399 &bytes_remaining, &tmp_data); 8399 &bytes_remaining, &tmp_data);
8400 8400
8401 if (rc != Success || actual_type != XA_WINDOW || x_had_errors_p (dpy)) 8401 if (rc != Success || actual_type != XA_WINDOW || x_had_errors_p (dpy))
8402 { 8402 {
8403 if (tmp_data) XFree (tmp_data); 8403 if (tmp_data) XFree (tmp_data);
@@ -8452,7 +8452,7 @@ wm_supports (f, atomname)
8452 rc = 0; 8452 rc = 0;
8453 want_atom = XInternAtom (dpy, atomname, False); 8453 want_atom = XInternAtom (dpy, atomname, False);
8454 8454
8455 for (i = 0; rc == 0 && i < dpyinfo->nr_net_supported_atoms; ++i) 8455 for (i = 0; rc == 0 && i < dpyinfo->nr_net_supported_atoms; ++i)
8456 rc = dpyinfo->net_supported_atoms[i] == want_atom; 8456 rc = dpyinfo->net_supported_atoms[i] == want_atom;
8457 8457
8458 x_uncatch_errors (); 8458 x_uncatch_errors ();
@@ -10699,7 +10699,7 @@ x_term_init (display_name, xrm_option, resource_name)
10699 UNBLOCK_INPUT; 10699 UNBLOCK_INPUT;
10700 terminal->kboard->Vsystem_key_alist 10700 terminal->kboard->Vsystem_key_alist
10701 = call1 (Qvendor_specific_keysyms, 10701 = call1 (Qvendor_specific_keysyms,
10702 build_string (vendor ? vendor : "")); 10702 vendor ? build_string (vendor) : empty_unibyte_string);
10703 BLOCK_INPUT; 10703 BLOCK_INPUT;
10704 } 10704 }
10705 10705