aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSteven Tamm2004-12-27 17:27:30 +0000
committerSteven Tamm2004-12-27 17:27:30 +0000
commitb15325b22a301f3f1d150ab15dff23521cc79711 (patch)
tree82a57d1a677ac34da4e6a4d0ab6767a4e2a10778 /src
parent22933cbff47c023e8a37677112e847c9242d8a54 (diff)
downloademacs-b15325b22a301f3f1d150ab15dff23521cc79711.tar.gz
emacs-b15325b22a301f3f1d150ab15dff23521cc79711.zip
* dispextern.h: Change HAVE_CARBON to MAC_OS.
(struct glyph_string): Likewise. * emacs.c (main) [MAC_OS8]: Call mac_term_init instead of mac_initialize. * fileio.c (Fnext_read_file_uses_dialog_p, Fread_file_name): Change TARGET_API_MAC_CARBON to HAVE_CARBON. * fns.c (vector): Change MAC_OSX to MAC_OS. * frame.c (x_set_frame_parameters, x_report_frame_params) (x_set_fullscreen): Remove #ifndef HAVE_CARBON. (x_set_border_width, Vdefault_frame_scroll_bars): Change HAVE_CARBON to MAC_OS. * image.c [MAC_OS]: Include sys/stat.h. [MAC_OS && !MAC_OSX]: Include sys/param.h, ImageCompression.h, and QuickTimeComponents.h. * mac.c [!MAC_OSX] (mac_wait_next_event): Add extern. [!MAC_OSX] (select): Use mac_wait_next_event. [!MAC_OSX] (run_mac_command): Change EXEC_SUFFIXES to Vexec_suffixes. [!MAC_OSX] (select, run_mac_command): Change `#ifdef TARGET_API_MAC_CARBON' to `#if TARGET_API_MAC_CARBON'. (mac_clear_font_name_table): Add extern. (Fmac_clear_font_name_table): New defun. (syms_of_mac): Defsubr it. [MAC_OSX] (SELECT_POLLING_PERIOD_USEC): New define. [MAC_OSX] (select_and_poll_event): New function. [MAC_OSX] (sys_select): Use it. [MAC_OSX && SELECT_USE_CFSOCKET] (socket_callback): New function. [MAC_OSX && SELECT_USE_CFSOCKET] (SELECT_TIMEOUT_THRESHOLD_RUNLOOP, EVENT_CLASS_SOCK): New defines. [MAC_OSX] (sys_select) [SELECT_USE_CFSOCKET]: Use CFSocket and RunLoop for simultaneously monitoring two kinds of inputs, window events and process outputs, without periodically polling. * macfns.c (mac_initialized): Remove extern. (stricmp): Put in #if 0. All callers changed to use xstricmp in xfaces.c. (strnicmp): Decrement `n' at the end of each loop, not the beginning. (check_mac): Use the term "Mac native windows" instead of "Mac OS". (check_x_display_info, x_display_info_for_name): Sync with xfns.c. (mac_get_rdb_resource): New function (from w32reg.c). (x_get_string_resource): Use it. (install_window_handler): Add extern. (mac_window): New function. (Fx_create_frame): Use it instead of make_mac_frame. Set parameter for Qfullscreen. Call x_wm_set_size_hint. (Fx_open_connection, Fx_close_connection): New defuns. (syms_of_macfns): Defsubr them. (x_create_tip_frame) [TARGET_API_MAC_CARBON]: Add kWindowNoUpdatesAttribute to the window attribute. (x_create_tip_frame) [!TARGET_API_MAC_CARBON]: Use NewCWindow. (x_create_tip_frame): Don't call ShowWindow. (Fx_show_tip): Call ShowWindow. (Fx_file_dialog): Change `#ifdef TARGET_API_MAC_CARBON' to `#if TARGET_API_MAC_CARBON'. (mac_frame_parm_handlers): Set handlers for Qfullscreen. (syms_of_macfns) [MAC_OSX]: Initialize mac_in_use to 0. * macgui.h [!MAC_OSX]: Don't include Controls.h. Include Windows.h. (Window): Typedef to WindowPtr and move outside `#if TARGET_API_MAC_CARBON'. (XSizeHints): New struct. * macterm.c (x_update_begin, x_update_end) [TARGET_API_MAC_CARBON]: Disable screen updates during update of a frame. (x_draw_glyph_string_background, x_draw_glyph_string_foreground) [MAC_OS8]: Use XDrawImageString/XDrawImageString16. (construct_mouse_click): Put in #if 0. (x_check_fullscreen, x_check_fullscreen_move): Remove decls. (x_scroll_bar_create, x_scroll_bar_handle_click): Change `#ifdef TARGET_API_MAC_CARBON' to `#if TARGET_API_MAC_CARBON'. (activate_scroll_bars, deactivate_scroll_bars) [!TARGET_API_MAC_CARBON]: Use ActivateControl/DeactivateControl. (x_make_frame_visible) [TARGET_API_MAC_CARBON]: Reposition window if the position is neither user-specified nor program-specified. (x_free_frame_resources): Free size_hints. (x_wm_set_size_hint): Allocate size_hints if needed. Set size_hints. (mac_clear_font_name_table): New function. (mac_do_list_fonts): Initialize font_name_table if needed. (x_list_fonts): Don't initialize font_name_table. Add BLOCK_INPUT around mac_do_list_fonts. (mac_unload_font): New function. (x_load_font): Add BLOCK_INPUT around XLoadQueryFont. (init_mac_drag_n_drop, mac_do_receive_drag): Enclose declarations and definitions with #if TARGET_API_MAC_CARBON. [USE_CARBON_EVENTS] (mac_handle_window_event): Add decl. (install_window_handler): Add decl. (do_window_update): Add BeginUpdate/EndUpdate for the tooltip window. Use UpdateControls. Get the rectangle that should be updated and restrict the target of expose_frame to it. (do_grow_window): Set minimum height/width according to size_hints. (do_grow_window) [TARGET_API_MAC_CARBON]: Use ResizeWindow. (do_zoom_window): Don't use x_set_window_size. [USE_CARBON_EVENTS] (mac_handle_window_event): New function. (install_window_handler): New function. [!USE_CARBON_EVENTS] (mouse_region): New variable. [!USE_CARBON_EVENTS] (mac_wait_next_event): New function. (XTread_socket) [USE_CARBON_EVENTS]: Move call to GetEventDispatcherTarget inside BLOCK_INPUT. (XTread_socket) [!USE_CARBON_EVENTS]: Use mac_wait_next_event. Update mouse_region when mouse is moved. (make_mac_frame): Remove. (make_mac_terminal_frame): Put in #ifdef MAC_OS8. Initialize mouse pointer shapes. Change values of f->left_pos and f->top_pos. Don't use make_mac_frame. Use NewCWindow. Don't call ShowWindow. (mac_initialize_display_info) [MAC_OSX]: Create mac_id_name from Vinvocation_name and Vsystem_name. (mac_make_rdb): New function (from w32term.c). (mac_term_init): Use it. Add BLOCK_INPUT. Error if display has already been opened. Don't pass argument to mac_initialize_display_info. Don't set dpyinfo->height/width. Add entries to x_display_list and x_display_name_list. (x_delete_display): New function. (mac_initialize): Don't call mac_initialize_display_info. (syms_of_macterm) [!MAC_OSX]: Don't call Fprovide. * macterm.h (check_mac): Add extern. (struct mac_output): New member size_hints. (FRAME_SIZE_HINTS): New macro. (mac_unload_font): Add extern. * xdisp.c (expose_window, expose_frame): Remove kludges for Mac. * xfaces.c (clear_font_table) [MAC_OS]: call mac_unload_font.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog127
-rw-r--r--src/dispextern.h4
-rw-r--r--src/emacs.c4
-rw-r--r--src/fileio.c4
-rw-r--r--src/fns.c4
-rw-r--r--src/frame.c12
-rw-r--r--src/image.c5
-rw-r--r--src/mac.c344
-rw-r--r--src/macfns.c157
-rw-r--r--src/macgui.h28
-rw-r--r--src/macterm.c748
-rw-r--r--src/macterm.h9
-rw-r--r--src/xdisp.c24
-rw-r--r--src/xfaces.c3
14 files changed, 1016 insertions, 457 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 0fa8e8f1754..eafd381817f 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,130 @@
12004-12-27 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
2
3 * dispextern.h: Change HAVE_CARBON to MAC_OS.
4 (struct glyph_string): Likewise.
5 * emacs.c (main) [MAC_OS8]: Call mac_term_init instead of
6 mac_initialize.
7 * fileio.c (Fnext_read_file_uses_dialog_p, Fread_file_name):
8 Change TARGET_API_MAC_CARBON to HAVE_CARBON.
9 * fns.c (vector): Change MAC_OSX to MAC_OS.
10 * frame.c (x_set_frame_parameters, x_report_frame_params)
11 (x_set_fullscreen): Remove #ifndef HAVE_CARBON.
12 (x_set_border_width, Vdefault_frame_scroll_bars): Change
13 HAVE_CARBON to MAC_OS.
14 * image.c [MAC_OS]: Include sys/stat.h.
15 [MAC_OS && !MAC_OSX]: Include sys/param.h, ImageCompression.h, and
16 QuickTimeComponents.h.
17 * mac.c [!MAC_OSX] (mac_wait_next_event): Add extern.
18 [!MAC_OSX] (select): Use mac_wait_next_event.
19 [!MAC_OSX] (run_mac_command): Change EXEC_SUFFIXES to
20 Vexec_suffixes.
21 [!MAC_OSX] (select, run_mac_command): Change `#ifdef
22 TARGET_API_MAC_CARBON' to `#if TARGET_API_MAC_CARBON'.
23 (mac_clear_font_name_table): Add extern.
24 (Fmac_clear_font_name_table): New defun.
25 (syms_of_mac): Defsubr it.
26 [MAC_OSX] (SELECT_POLLING_PERIOD_USEC): New define.
27 [MAC_OSX] (select_and_poll_event): New function.
28 [MAC_OSX] (sys_select): Use it.
29 [MAC_OSX && SELECT_USE_CFSOCKET] (socket_callback): New function.
30 [MAC_OSX && SELECT_USE_CFSOCKET]
31 (SELECT_TIMEOUT_THRESHOLD_RUNLOOP, EVENT_CLASS_SOCK): New defines.
32 [MAC_OSX] (sys_select) [SELECT_USE_CFSOCKET]: Use CFSocket and
33 RunLoop for simultaneously monitoring two kinds of inputs, window
34 events and process outputs, without periodically polling.
35 * macfns.c (mac_initialized): Remove extern.
36 (stricmp): Put in #if 0. All callers changed to use xstricmp in
37 xfaces.c.
38 (strnicmp): Decrement `n' at the end of each loop, not the
39 beginning.
40 (check_mac): Use the term "Mac native windows" instead of "Mac
41 OS".
42 (check_x_display_info, x_display_info_for_name): Sync with xfns.c.
43 (mac_get_rdb_resource): New function (from w32reg.c).
44 (x_get_string_resource): Use it.
45 (install_window_handler): Add extern.
46 (mac_window): New function.
47 (Fx_create_frame): Use it instead of make_mac_frame. Set
48 parameter for Qfullscreen. Call x_wm_set_size_hint.
49 (Fx_open_connection, Fx_close_connection): New defuns.
50 (syms_of_macfns): Defsubr them.
51 (x_create_tip_frame) [TARGET_API_MAC_CARBON]: Add
52 kWindowNoUpdatesAttribute to the window attribute.
53 (x_create_tip_frame) [!TARGET_API_MAC_CARBON]: Use NewCWindow.
54 (x_create_tip_frame): Don't call ShowWindow.
55 (Fx_show_tip): Call ShowWindow.
56 (Fx_file_dialog): Change `#ifdef TARGET_API_MAC_CARBON' to `#if
57 TARGET_API_MAC_CARBON'.
58 (mac_frame_parm_handlers): Set handlers for Qfullscreen.
59 (syms_of_macfns) [MAC_OSX]: Initialize mac_in_use to 0.
60 * macgui.h [!MAC_OSX]: Don't include Controls.h. Include
61 Windows.h.
62 (Window): Typedef to WindowPtr and move outside `#if
63 TARGET_API_MAC_CARBON'.
64 (XSizeHints): New struct.
65 * macterm.c (x_update_begin, x_update_end)
66 [TARGET_API_MAC_CARBON]: Disable screen updates during update of a
67 frame.
68 (x_draw_glyph_string_background, x_draw_glyph_string_foreground)
69 [MAC_OS8]: Use XDrawImageString/XDrawImageString16.
70 (construct_mouse_click): Put in #if 0.
71 (x_check_fullscreen, x_check_fullscreen_move): Remove decls.
72 (x_scroll_bar_create, x_scroll_bar_handle_click): Change `#ifdef
73 TARGET_API_MAC_CARBON' to `#if TARGET_API_MAC_CARBON'.
74 (activate_scroll_bars, deactivate_scroll_bars)
75 [!TARGET_API_MAC_CARBON]: Use ActivateControl/DeactivateControl.
76 (x_make_frame_visible) [TARGET_API_MAC_CARBON]: Reposition window
77 if the position is neither user-specified nor program-specified.
78 (x_free_frame_resources): Free size_hints.
79 (x_wm_set_size_hint): Allocate size_hints if needed. Set
80 size_hints.
81 (mac_clear_font_name_table): New function.
82 (mac_do_list_fonts): Initialize font_name_table if needed.
83 (x_list_fonts): Don't initialize font_name_table. Add BLOCK_INPUT
84 around mac_do_list_fonts.
85 (mac_unload_font): New function.
86 (x_load_font): Add BLOCK_INPUT around XLoadQueryFont.
87 (init_mac_drag_n_drop, mac_do_receive_drag): Enclose declarations
88 and definitions with #if TARGET_API_MAC_CARBON.
89 [USE_CARBON_EVENTS] (mac_handle_window_event): Add decl.
90 (install_window_handler): Add decl.
91 (do_window_update): Add BeginUpdate/EndUpdate for the tooltip
92 window. Use UpdateControls. Get the rectangle that should be
93 updated and restrict the target of expose_frame to it.
94 (do_grow_window): Set minimum height/width according to
95 size_hints.
96 (do_grow_window) [TARGET_API_MAC_CARBON]: Use ResizeWindow.
97 (do_zoom_window): Don't use x_set_window_size.
98 [USE_CARBON_EVENTS] (mac_handle_window_event): New function.
99 (install_window_handler): New function.
100 [!USE_CARBON_EVENTS] (mouse_region): New variable.
101 [!USE_CARBON_EVENTS] (mac_wait_next_event): New function.
102 (XTread_socket) [USE_CARBON_EVENTS]: Move call to
103 GetEventDispatcherTarget inside BLOCK_INPUT.
104 (XTread_socket) [!USE_CARBON_EVENTS]: Use mac_wait_next_event.
105 Update mouse_region when mouse is moved.
106 (make_mac_frame): Remove.
107 (make_mac_terminal_frame): Put in #ifdef MAC_OS8. Initialize
108 mouse pointer shapes. Change values of f->left_pos and
109 f->top_pos. Don't use make_mac_frame. Use NewCWindow. Don't
110 call ShowWindow.
111 (mac_initialize_display_info) [MAC_OSX]: Create mac_id_name from
112 Vinvocation_name and Vsystem_name.
113 (mac_make_rdb): New function (from w32term.c).
114 (mac_term_init): Use it. Add BLOCK_INPUT. Error if display has
115 already been opened. Don't pass argument to
116 mac_initialize_display_info. Don't set dpyinfo->height/width.
117 Add entries to x_display_list and x_display_name_list.
118 (x_delete_display): New function.
119 (mac_initialize): Don't call mac_initialize_display_info.
120 (syms_of_macterm) [!MAC_OSX]: Don't call Fprovide.
121 * macterm.h (check_mac): Add extern.
122 (struct mac_output): New member size_hints.
123 (FRAME_SIZE_HINTS): New macro.
124 (mac_unload_font): Add extern.
125 * xdisp.c (expose_window, expose_frame): Remove kludges for Mac.
126 * xfaces.c (clear_font_table) [MAC_OS]: call mac_unload_font.
127
12004-12-27 Richard M. Stallman <rms@gnu.org> 1282004-12-27 Richard M. Stallman <rms@gnu.org>
2 129
3 * buffer.c (Fbuffer_disable_undo): Deleted (moved to simple.el). 130 * buffer.c (Fbuffer_disable_undo): Deleted (moved to simple.el).
diff --git a/src/dispextern.h b/src/dispextern.h
index 2f80ac3615f..c9d85065e78 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -62,7 +62,7 @@ typedef XImage *XImagePtr;
62typedef HDC XImagePtr_or_DC; 62typedef HDC XImagePtr_or_DC;
63#endif 63#endif
64 64
65#ifdef HAVE_CARBON 65#ifdef MAC_OS
66#include "macgui.h" 66#include "macgui.h"
67typedef struct mac_display_info Display_Info; 67typedef struct mac_display_info Display_Info;
68/* Mac equivalent of XImage. */ 68/* Mac equivalent of XImage. */
@@ -1171,7 +1171,7 @@ struct glyph_string
1171 unsigned for_overlaps_p : 1; 1171 unsigned for_overlaps_p : 1;
1172 1172
1173 /* The GC to use for drawing this glyph string. */ 1173 /* The GC to use for drawing this glyph string. */
1174#if defined(HAVE_X_WINDOWS) || defined(HAVE_CARBON) 1174#if defined(HAVE_X_WINDOWS) || defined(MAC_OS)
1175 GC gc; 1175 GC gc;
1176#endif 1176#endif
1177#if defined(HAVE_NTGUI) 1177#if defined(HAVE_NTGUI)
diff --git a/src/emacs.c b/src/emacs.c
index 5c62ee071ff..0c8ac5bae79 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1306,7 +1306,7 @@ main (argc, argv
1306 creates a full-fledge output_mac type frame. This does not 1306 creates a full-fledge output_mac type frame. This does not
1307 work correctly before syms_of_textprop, syms_of_macfns, 1307 work correctly before syms_of_textprop, syms_of_macfns,
1308 syms_of_ccl, syms_of_fontset, syms_of_xterm, syms_of_search, 1308 syms_of_ccl, syms_of_fontset, syms_of_xterm, syms_of_search,
1309 syms_of_frame, mac_initialize, and init_keyboard have already 1309 syms_of_frame, mac_term_init, and init_keyboard have already
1310 been called. */ 1310 been called. */
1311 syms_of_textprop (); 1311 syms_of_textprop ();
1312 syms_of_macfns (); 1312 syms_of_macfns ();
@@ -1318,7 +1318,7 @@ main (argc, argv
1318 syms_of_search (); 1318 syms_of_search ();
1319 syms_of_frame (); 1319 syms_of_frame ();
1320 1320
1321 mac_initialize (); 1321 mac_term_init (build_string ("Mac"), NULL, NULL);
1322 init_keyboard (); 1322 init_keyboard ();
1323#endif 1323#endif
1324 1324
diff --git a/src/fileio.c b/src/fileio.c
index d58c49d2825..3ad87ebe667 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -6188,7 +6188,7 @@ The return value is only relevant for a call to `read-file-name' that happens
6188before any other event (mouse or keypress) is handeled. */) 6188before any other event (mouse or keypress) is handeled. */)
6189 () 6189 ()
6190{ 6190{
6191#if defined (USE_MOTIF) || defined (HAVE_NTGUI) || defined (USE_GTK) || defined (TARGET_API_MAC_CARBON) 6191#if defined (USE_MOTIF) || defined (HAVE_NTGUI) || defined (USE_GTK) || defined (HAVE_CARBON)
6192 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) 6192 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
6193 && use_dialog_box 6193 && use_dialog_box
6194 && use_file_dialog 6194 && use_file_dialog
@@ -6329,7 +6329,7 @@ and `read-file-name-function'. */)
6329 6329
6330 GCPRO2 (insdef, default_filename); 6330 GCPRO2 (insdef, default_filename);
6331 6331
6332#if defined (USE_MOTIF) || defined (HAVE_NTGUI) || defined (USE_GTK) || defined (TARGET_API_MAC_CARBON) 6332#if defined (USE_MOTIF) || defined (HAVE_NTGUI) || defined (USE_GTK) || defined (HAVE_CARBON)
6333 if (! NILP (Fnext_read_file_uses_dialog_p ())) 6333 if (! NILP (Fnext_read_file_uses_dialog_p ()))
6334 { 6334 {
6335 /* If DIR contains a file name, split it. */ 6335 /* If DIR contains a file name, split it. */
diff --git a/src/fns.c b/src/fns.c
index 457be6c96a9..b163223803c 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -26,8 +26,8 @@ Boston, MA 02111-1307, USA. */
26#endif 26#endif
27#include <time.h> 27#include <time.h>
28 28
29#ifndef MAC_OSX 29#ifndef MAC_OS
30/* On Mac OS X, defining this conflicts with precompiled headers. */ 30/* On Mac OS, defining this conflicts with precompiled headers. */
31 31
32/* Note on some machines this defines `vector' as a typedef, 32/* Note on some machines this defines `vector' as a typedef,
33 so make sure we don't use that name in this file. */ 33 so make sure we don't use that name in this file. */
diff --git a/src/frame.c b/src/frame.c
index 9a176a67741..36014df23c1 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -2815,8 +2815,6 @@ x_set_frame_parameters (f, alist)
2815 XSETINT (icon_top, 0); 2815 XSETINT (icon_top, 0);
2816 } 2816 }
2817 2817
2818#ifndef HAVE_CARBON
2819 /* MAC_TODO: fullscreen */
2820 if (FRAME_VISIBLE_P (f) && fullscreen_is_being_set) 2818 if (FRAME_VISIBLE_P (f) && fullscreen_is_being_set)
2821 { 2819 {
2822 /* If the frame is visible already and the fullscreen parameter is 2820 /* If the frame is visible already and the fullscreen parameter is
@@ -2832,7 +2830,6 @@ x_set_frame_parameters (f, alist)
2832 if (new_top != f->top_pos || new_left != f->left_pos) 2830 if (new_top != f->top_pos || new_left != f->left_pos)
2833 x_set_offset (f, new_left, new_top, 1); 2831 x_set_offset (f, new_left, new_top, 1);
2834 } 2832 }
2835#endif
2836 2833
2837 /* Don't set these parameters unless they've been explicitly 2834 /* Don't set these parameters unless they've been explicitly
2838 specified. The window might be mapped or resized while we're in 2835 specified. The window might be mapped or resized while we're in
@@ -2993,14 +2990,11 @@ x_report_frame_params (f, alistptr)
2993 store_in_alist (alistptr, Qdisplay, 2990 store_in_alist (alistptr, Qdisplay,
2994 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element)); 2991 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
2995 2992
2996#ifndef HAVE_CARBON
2997/* A Mac Window is identified by a struct, not an integer. */
2998 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window) 2993 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
2999 tem = Qnil; 2994 tem = Qnil;
3000 else 2995 else
3001 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc); 2996 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3002 store_in_alist (alistptr, Qparent_id, tem); 2997 store_in_alist (alistptr, Qparent_id, tem);
3003#endif
3004} 2998}
3005 2999
3006 3000
@@ -3012,7 +3006,6 @@ x_set_fullscreen (f, new_value, old_value)
3012 struct frame *f; 3006 struct frame *f;
3013 Lisp_Object new_value, old_value; 3007 Lisp_Object new_value, old_value;
3014{ 3008{
3015#ifndef HAVE_CARBON
3016 if (NILP (new_value)) 3009 if (NILP (new_value))
3017 f->want_fullscreen = FULLSCREEN_NONE; 3010 f->want_fullscreen = FULLSCREEN_NONE;
3018 else if (EQ (new_value, Qfullboth)) 3011 else if (EQ (new_value, Qfullboth))
@@ -3021,7 +3014,6 @@ x_set_fullscreen (f, new_value, old_value)
3021 f->want_fullscreen = FULLSCREEN_WIDTH; 3014 f->want_fullscreen = FULLSCREEN_WIDTH;
3022 else if (EQ (new_value, Qfullheight)) 3015 else if (EQ (new_value, Qfullheight))
3023 f->want_fullscreen = FULLSCREEN_HEIGHT; 3016 f->want_fullscreen = FULLSCREEN_HEIGHT;
3024#endif
3025} 3017}
3026 3018
3027 3019
@@ -3141,7 +3133,7 @@ x_set_border_width (f, arg, oldval)
3141 if (XINT (arg) == f->border_width) 3133 if (XINT (arg) == f->border_width)
3142 return; 3134 return;
3143 3135
3144#ifndef HAVE_CARBON 3136#ifndef MAC_OS
3145 if (FRAME_X_WINDOW (f) != 0) 3137 if (FRAME_X_WINDOW (f) != 0)
3146 error ("Cannot change the border width of a window"); 3138 error ("Cannot change the border width of a window");
3147#endif /* MAC_TODO */ 3139#endif /* MAC_TODO */
@@ -4052,7 +4044,7 @@ Setting this variable does not affect existing frames, only new ones. */);
4052 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars, 4044 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars,
4053 doc: /* Default position of scroll bars on this window-system. */); 4045 doc: /* Default position of scroll bars on this window-system. */);
4054#ifdef HAVE_WINDOW_SYSTEM 4046#ifdef HAVE_WINDOW_SYSTEM
4055#if defined(HAVE_NTGUI) || defined(HAVE_CARBON) 4047#if defined(HAVE_NTGUI) || defined(MAC_OS)
4056 /* MS-Windows has scroll bars on the right by default. */ 4048 /* MS-Windows has scroll bars on the right by default. */
4057 Vdefault_frame_scroll_bars = Qright; 4049 Vdefault_frame_scroll_bars = Qright;
4058#else 4050#else
diff --git a/src/image.c b/src/image.c
index 6a86708a9d7..9c2f6962b6e 100644
--- a/src/image.c
+++ b/src/image.c
@@ -83,16 +83,19 @@ typedef struct w32_bitmap_record Bitmap_Record;
83 83
84#ifdef MAC_OS 84#ifdef MAC_OS
85#include "macterm.h" 85#include "macterm.h"
86#include <sys/stat.h>
86#ifndef MAC_OSX 87#ifndef MAC_OSX
87#include <alloca.h> 88#include <alloca.h>
89#include <sys/param.h>
88#endif 90#endif
89#ifdef MAC_OSX 91#ifdef MAC_OSX
90#include <sys/stat.h>
91#include <QuickTime/QuickTime.h> 92#include <QuickTime/QuickTime.h>
92#else /* not MAC_OSX */ 93#else /* not MAC_OSX */
93#include <Windows.h> 94#include <Windows.h>
94#include <Gestalt.h> 95#include <Gestalt.h>
95#include <TextUtils.h> 96#include <TextUtils.h>
97#include <ImageCompression.h>
98#include <QuickTimeComponents.h>
96#endif /* not MAC_OSX */ 99#endif /* not MAC_OSX */
97 100
98/* MAC_TODO : Color tables on Mac. */ 101/* MAC_TODO : Color tables on Mac. */
diff --git a/src/mac.c b/src/mac.c
index 53e56cfb541..99e0d44830b 100644
--- a/src/mac.c
+++ b/src/mac.c
@@ -845,6 +845,8 @@ check_alarm ()
845} 845}
846 846
847 847
848extern Boolean mac_wait_next_event (EventRecord *, UInt32, Boolean);
849
848int 850int
849select (n, rfds, wfds, efds, timeout) 851select (n, rfds, wfds, efds, timeout)
850 int n; 852 int n;
@@ -853,49 +855,24 @@ select (n, rfds, wfds, efds, timeout)
853 SELECT_TYPE *efds; 855 SELECT_TYPE *efds;
854 struct timeval *timeout; 856 struct timeval *timeout;
855{ 857{
856#ifdef TARGET_API_MAC_CARBON 858#if TARGET_API_MAC_CARBON
857 return 1; 859 return 1;
858#else /* not TARGET_API_MAC_CARBON */ 860#else /* not TARGET_API_MAC_CARBON */
859 EMACS_TIME end_time, now;
860 EventRecord e; 861 EventRecord e;
862 UInt32 sleep_time = EMACS_SECS (*timeout) * 60 +
863 ((EMACS_USECS (*timeout) * 60) / 1000000);
861 864
862 /* Can only handle wait for keyboard input. */ 865 /* Can only handle wait for keyboard input. */
863 if (n > 1 || wfds || efds) 866 if (n > 1 || wfds || efds)
864 return -1; 867 return -1;
865 868
866 EMACS_GET_TIME (end_time); 869 /* Also return true if an event other than a keyDown has occurred.
867 EMACS_ADD_TIME (end_time, end_time, *timeout); 870 This causes kbd_buffer_get_event in keyboard.c to call
868 871 read_avail_input which in turn calls XTread_socket to poll for
869 do 872 these events. Otherwise these never get processed except but a
870 { 873 very slow poll timer. */
871 /* Also return true if an event other than a keyDown has 874 if (FD_ISSET (0, rfds) && mac_wait_next_event (&e, sleep_time, false))
872 occurred. This causes kbd_buffer_get_event in keyboard.c to 875 return 1;
873 call read_avail_input which in turn calls XTread_socket to
874 poll for these events. Otherwise these never get processed
875 except but a very slow poll timer. */
876 if (FD_ISSET (0, rfds) && EventAvail (everyEvent, &e))
877 return 1;
878
879 /* Also check movement of the mouse. */
880 {
881 Point mouse_pos;
882 static Point old_mouse_pos = {-1, -1};
883
884 GetMouse (&mouse_pos);
885 if (!EqualPt (mouse_pos, old_mouse_pos))
886 {
887 old_mouse_pos = mouse_pos;
888 return 1;
889 }
890 }
891
892 WaitNextEvent (0, &e, 1UL, NULL); /* Accept no event; wait 1
893 tic. by T.I. */
894
895 EMACS_GET_TIME (now);
896 EMACS_SUB_TIME (now, end_time, now);
897 }
898 while (!EMACS_TIME_NEG_P (now));
899 876
900 return 0; 877 return 0;
901#endif /* not TARGET_API_MAC_CARBON */ 878#endif /* not TARGET_API_MAC_CARBON */
@@ -1996,7 +1973,7 @@ run_mac_command (argv, workdir, infn, outfn, errfn)
1996 const char *workdir; 1973 const char *workdir;
1997 const char *infn, *outfn, *errfn; 1974 const char *infn, *outfn, *errfn;
1998{ 1975{
1999#ifdef TARGET_API_MAC_CARBON 1976#if TARGET_API_MAC_CARBON
2000 return -1; 1977 return -1;
2001#else /* not TARGET_API_MAC_CARBON */ 1978#else /* not TARGET_API_MAC_CARBON */
2002 char macappname[MAXPATHLEN+1], macworkdir[MAXPATHLEN+1]; 1979 char macappname[MAXPATHLEN+1], macworkdir[MAXPATHLEN+1];
@@ -2081,7 +2058,7 @@ run_mac_command (argv, workdir, infn, outfn, errfn)
2081 strcat (t, newargv[0]); 2058 strcat (t, newargv[0]);
2082#endif /* 0 */ 2059#endif /* 0 */
2083 Lisp_Object path; 2060 Lisp_Object path;
2084 openp (Vexec_path, build_string (newargv[0]), EXEC_SUFFIXES, &path, 2061 openp (Vexec_path, build_string (newargv[0]), Vexec_suffixes, &path,
2085 make_number (X_OK)); 2062 make_number (X_OK));
2086 2063
2087 if (NILP (path)) 2064 if (NILP (path))
@@ -2793,17 +2770,98 @@ and t is the same as `SECONDARY'. */)
2793 return Qnil; 2770 return Qnil;
2794} 2771}
2795 2772
2773extern void mac_clear_font_name_table P_ ((void));
2774
2775DEFUN ("mac-clear-font-name-table", Fmac_clear_font_name_table, Smac_clear_font_name_table, 0, 0, 0,
2776 doc: /* Clear the font name table. */)
2777 ()
2778{
2779 check_mac ();
2780 mac_clear_font_name_table ();
2781 return Qnil;
2782}
2783
2796#ifdef MAC_OSX 2784#ifdef MAC_OSX
2797#undef select 2785#undef select
2798 2786
2799extern int inhibit_window_system; 2787extern int inhibit_window_system;
2800extern int noninteractive; 2788extern int noninteractive;
2801 2789
2802/* When Emacs is started from the Finder, SELECT always immediately 2790/* Unlike in X11, window events in Carbon do not come from sockets.
2803 returns as if input is present when file descriptor 0 is polled for 2791 So we cannot simply use `select' to monitor two kinds of inputs:
2804 input. Strangely, when Emacs is run as a GUI application from the 2792 window events and process outputs. We emulate such functionality
2805 command line, it blocks in the same situation. This `wrapper' of 2793 by regarding fd 0 as the window event channel and simultaneously
2806 the system call SELECT corrects this discrepancy. */ 2794 monitoring both kinds of input channels. It is implemented by
2795 dividing into some cases:
2796 1. The window event channel is not involved.
2797 -> Use `select'.
2798 2. Sockets are not involved.
2799 -> Use ReceiveNextEvent.
2800 3. [If SELECT_USE_CFSOCKET is defined]
2801 Only the window event channel and socket read channels are
2802 involved, and timeout is not too short (greater than
2803 SELECT_TIMEOUT_THRESHHOLD_RUNLOOP seconds).
2804 -> Create CFSocket for each socket and add it into the current
2805 event RunLoop so that an `ready-to-read' event can be posted
2806 to the event queue that is also used for window events. Then
2807 ReceiveNextEvent can wait for both kinds of inputs.
2808 4. Otherwise.
2809 -> Periodically poll the window input channel while repeatedly
2810 executing `select' with a short timeout
2811 (SELECT_POLLING_PERIOD_USEC microseconds). */
2812
2813#define SELECT_POLLING_PERIOD_USEC 20000
2814#ifdef SELECT_USE_CFSOCKET
2815#define SELECT_TIMEOUT_THRESHOLD_RUNLOOP 0.2
2816#define EVENT_CLASS_SOCK 'Sock'
2817
2818static void
2819socket_callback (s, type, address, data, info)
2820 CFSocketRef s;
2821 CFSocketCallBackType type;
2822 CFDataRef address;
2823 const void *data;
2824 void *info;
2825{
2826 EventRef event;
2827
2828 CreateEvent (NULL, EVENT_CLASS_SOCK, 0, 0, kEventAttributeNone, &event);
2829 PostEventToQueue (GetCurrentEventQueue (), event, kEventPriorityStandard);
2830 ReleaseEvent (event);
2831}
2832#endif /* SELECT_USE_CFSOCKET */
2833
2834static int
2835select_and_poll_event (n, rfds, wfds, efds, timeout)
2836 int n;
2837 SELECT_TYPE *rfds;
2838 SELECT_TYPE *wfds;
2839 SELECT_TYPE *efds;
2840 struct timeval *timeout;
2841{
2842 int r;
2843 OSErr err;
2844
2845 r = select (n, rfds, wfds, efds, timeout);
2846 if (r != -1)
2847 {
2848 BLOCK_INPUT;
2849 err = ReceiveNextEvent (0, NULL, kEventDurationNoWait,
2850 kEventLeaveInQueue, NULL);
2851 UNBLOCK_INPUT;
2852 if (err == noErr)
2853 {
2854 FD_SET (0, rfds);
2855 r++;
2856 }
2857 }
2858 return r;
2859}
2860
2861#ifndef MAC_OS_X_VERSION_10_2
2862#undef SELECT_INVALIDATE_CFSOCKET
2863#endif
2864
2807int 2865int
2808sys_select (n, rfds, wfds, efds, timeout) 2866sys_select (n, rfds, wfds, efds, timeout)
2809 int n; 2867 int n;
@@ -2813,91 +2871,182 @@ sys_select (n, rfds, wfds, efds, timeout)
2813 struct timeval *timeout; 2871 struct timeval *timeout;
2814{ 2872{
2815 OSErr err; 2873 OSErr err;
2816 EMACS_TIME end_time, now, remaining_time; 2874 int i, r;
2817 2875 EMACS_TIME select_timeout;
2876
2818 if (inhibit_window_system || noninteractive 2877 if (inhibit_window_system || noninteractive
2819 || rfds == NULL || !FD_ISSET (0, rfds)) 2878 || rfds == NULL || !FD_ISSET (0, rfds))
2820 return select (n, rfds, wfds, efds, timeout); 2879 return select (n, rfds, wfds, efds, timeout);
2821 2880
2881 FD_CLR (0, rfds);
2882
2822 if (wfds == NULL && efds == NULL) 2883 if (wfds == NULL && efds == NULL)
2823 { 2884 {
2824 int i; 2885 int nsocks = 0;
2886 SELECT_TYPE orfds = *rfds;
2887
2888 EventTimeout timeout_sec =
2889 (timeout
2890 ? (EMACS_SECS (*timeout) * kEventDurationSecond
2891 + EMACS_USECS (*timeout) * kEventDurationMicrosecond)
2892 : kEventDurationForever);
2825 2893
2826 for (i = 1; i < n; i++) 2894 for (i = 1; i < n; i++)
2827 if (FD_ISSET (i, rfds)) 2895 if (FD_ISSET (i, rfds))
2828 break; 2896 nsocks++;
2829 if (i == n)
2830 {
2831 EventTimeout timeout_sec =
2832 (timeout
2833 ? (EMACS_SECS (*timeout) * kEventDurationSecond
2834 + EMACS_USECS (*timeout) * kEventDurationMicrosecond)
2835 : kEventDurationForever);
2836 2897
2898 if (nsocks == 0)
2899 {
2837 BLOCK_INPUT; 2900 BLOCK_INPUT;
2838 err = ReceiveNextEvent (0, NULL, timeout_sec, 2901 err = ReceiveNextEvent (0, NULL, timeout_sec,
2839 kEventLeaveInQueue, NULL); 2902 kEventLeaveInQueue, NULL);
2840 UNBLOCK_INPUT; 2903 UNBLOCK_INPUT;
2841 if (err == noErr) 2904 if (err == noErr)
2842 { 2905 {
2843 FD_ZERO (rfds);
2844 FD_SET (0, rfds); 2906 FD_SET (0, rfds);
2845 return 1; 2907 return 1;
2846 } 2908 }
2847 else 2909 else
2848 return 0; 2910 return 0;
2849 } 2911 }
2850 }
2851 2912
2852 if (timeout) 2913 /* Avoid initial overhead of RunLoop setup for the case that
2853 { 2914 some input is already available. */
2854 remaining_time = *timeout; 2915 EMACS_SET_SECS_USECS (select_timeout, 0, 0);
2855 EMACS_GET_TIME (now); 2916 r = select_and_poll_event (n, rfds, wfds, efds, &select_timeout);
2856 EMACS_ADD_TIME (end_time, now, remaining_time); 2917 if (r != 0 || timeout_sec == 0.0)
2857 } 2918 return r;
2858 FD_CLR (0, rfds);
2859 do
2860 {
2861 EMACS_TIME select_timeout;
2862 SELECT_TYPE orfds = *rfds;
2863 int r;
2864 2919
2865 EMACS_SET_SECS_USECS (select_timeout, 0, 20000); 2920 *rfds = orfds;
2866 2921
2867 if (timeout && EMACS_TIME_LT (remaining_time, select_timeout)) 2922#ifdef SELECT_USE_CFSOCKET
2868 select_timeout = remaining_time; 2923 if (timeout_sec > 0 && timeout_sec <= SELECT_TIMEOUT_THRESHOLD_RUNLOOP)
2924 goto poll_periodically;
2869 2925
2870 r = select (n, &orfds, wfds, efds, &select_timeout); 2926 {
2871 BLOCK_INPUT; 2927 CFRunLoopRef runloop =
2872 err = ReceiveNextEvent (0, NULL, kEventDurationNoWait, 2928 (CFRunLoopRef) GetCFRunLoopFromEventLoop (GetCurrentEventLoop ());
2873 kEventLeaveInQueue, NULL); 2929 EventTypeSpec specs[] = {{EVENT_CLASS_SOCK, 0}};
2874 UNBLOCK_INPUT; 2930#ifdef SELECT_INVALIDATE_CFSOCKET
2875 if (r > 0) 2931 CFSocketRef *shead, *s;
2876 { 2932#else
2877 *rfds = orfds; 2933 CFRunLoopSourceRef *shead, *s;
2878 if (err == noErr) 2934#endif
2935
2936 BLOCK_INPUT;
2937
2938#ifdef SELECT_INVALIDATE_CFSOCKET
2939 shead = xmalloc (sizeof (CFSocketRef) * nsocks);
2940#else
2941 shead = xmalloc (sizeof (CFRunLoopSourceRef) * nsocks);
2942#endif
2943 s = shead;
2944 for (i = 1; i < n; i++)
2945 if (FD_ISSET (i, rfds))
2879 { 2946 {
2880 FD_SET (0, rfds); 2947 CFSocketRef socket =
2881 r++; 2948 CFSocketCreateWithNative (NULL, i, kCFSocketReadCallBack,
2949 socket_callback, NULL);
2950 CFRunLoopSourceRef source =
2951 CFSocketCreateRunLoopSource (NULL, socket, 0);
2952
2953#ifdef SELECT_INVALIDATE_CFSOCKET
2954 CFSocketSetSocketFlags (socket, 0);
2955#endif
2956 CFRunLoopAddSource (runloop, source, kCFRunLoopDefaultMode);
2957#ifdef SELECT_INVALIDATE_CFSOCKET
2958 CFRelease (source);
2959 *s = socket;
2960#else
2961 CFRelease (socket);
2962 *s = source;
2963#endif
2964 s++;
2882 } 2965 }
2883 return r;
2884 }
2885 else if (err == noErr)
2886 {
2887 FD_ZERO (rfds);
2888 FD_SET (0, rfds);
2889 return 1;
2890 }
2891 2966
2892 if (timeout) 2967 err = ReceiveNextEvent (0, NULL, timeout_sec, kEventLeaveInQueue, NULL);
2893 { 2968
2894 EMACS_GET_TIME (now); 2969 do
2895 EMACS_SUB_TIME (remaining_time, end_time, now); 2970 {
2896 } 2971 --s;
2972#ifdef SELECT_INVALIDATE_CFSOCKET
2973 CFSocketInvalidate (*s);
2974#else
2975 CFRunLoopRemoveSource (runloop, *s, kCFRunLoopDefaultMode);
2976#endif
2977 CFRelease (*s);
2978 }
2979 while (s != shead);
2980
2981 xfree (shead);
2982
2983 if (err)
2984 {
2985 FD_ZERO (rfds);
2986 r = 0;
2987 }
2988 else
2989 {
2990 FlushEventsMatchingListFromQueue (GetCurrentEventQueue (),
2991 GetEventTypeCount (specs),
2992 specs);
2993 EMACS_SET_SECS_USECS (select_timeout, 0, 0);
2994 r = select_and_poll_event (n, rfds, wfds, efds, &select_timeout);
2995 }
2996
2997 UNBLOCK_INPUT;
2998
2999 return r;
3000 }
3001#endif /* SELECT_USE_CFSOCKET */
2897 } 3002 }
2898 while (!timeout || EMACS_TIME_LT (now, end_time));
2899 3003
2900 return 0; 3004 poll_periodically:
3005 {
3006 EMACS_TIME end_time, now, remaining_time;
3007 SELECT_TYPE orfds = *rfds, owfds, oefds;
3008
3009 if (wfds)
3010 owfds = *wfds;
3011 if (efds)
3012 oefds = *efds;
3013 if (timeout)
3014 {
3015 remaining_time = *timeout;
3016 EMACS_GET_TIME (now);
3017 EMACS_ADD_TIME (end_time, now, remaining_time);
3018 }
3019
3020 do
3021 {
3022 EMACS_SET_SECS_USECS (select_timeout, 0, SELECT_POLLING_PERIOD_USEC);
3023 if (timeout && EMACS_TIME_LT (remaining_time, select_timeout))
3024 select_timeout = remaining_time;
3025 r = select_and_poll_event (n, rfds, wfds, efds, &select_timeout);
3026 if (r != 0)
3027 return r;
3028
3029 *rfds = orfds;
3030 if (wfds)
3031 *wfds = owfds;
3032 if (efds)
3033 *efds = oefds;
3034
3035 if (timeout)
3036 {
3037 EMACS_GET_TIME (now);
3038 EMACS_SUB_TIME (remaining_time, end_time, now);
3039 }
3040 }
3041 while (!timeout || EMACS_TIME_LT (now, end_time));
3042
3043 FD_ZERO (rfds);
3044 if (wfds)
3045 FD_ZERO (wfds);
3046 if (efds)
3047 FD_ZERO (efds);
3048 return 0;
3049 }
2901} 3050}
2902 3051
2903/* Set up environment variables so that Emacs can correctly find its 3052/* Set up environment variables so that Emacs can correctly find its
@@ -3043,6 +3192,7 @@ syms_of_mac ()
3043 defsubr (&Smac_paste_function); 3192 defsubr (&Smac_paste_function);
3044 defsubr (&Smac_cut_function); 3193 defsubr (&Smac_cut_function);
3045 defsubr (&Sx_selection_exists_p); 3194 defsubr (&Sx_selection_exists_p);
3195 defsubr (&Smac_clear_font_name_table);
3046 3196
3047 defsubr (&Sdo_applescript); 3197 defsubr (&Sdo_applescript);
3048 defsubr (&Smac_file_name_to_posix); 3198 defsubr (&Smac_file_name_to_posix);
diff --git a/src/macfns.c b/src/macfns.c
index fdfe7a52416..dfbc5dacd5e 100644
--- a/src/macfns.c
+++ b/src/macfns.c
@@ -158,9 +158,7 @@ Lisp_Object Qshift;
158 158
159extern Lisp_Object Vwindow_system_version; 159extern Lisp_Object Vwindow_system_version;
160 160
161extern int mac_initialized; 161#if 0 /* Use xstricmp instead. */
162
163
164/* compare two strings ignoring case */ 162/* compare two strings ignoring case */
165 163
166static int 164static int
@@ -171,13 +169,14 @@ stricmp (const char *s, const char *t)
171 return 0; 169 return 0;
172 return tolower (*s) - tolower (*t); 170 return tolower (*s) - tolower (*t);
173} 171}
172#endif
174 173
175/* compare two strings up to n characters, ignoring case */ 174/* compare two strings up to n characters, ignoring case */
176 175
177static int 176static int
178strnicmp (const char *s, const char *t, unsigned int n) 177strnicmp (const char *s, const char *t, unsigned int n)
179{ 178{
180 for ( ; n-- > 0 && tolower (*s) == tolower (*t); s++, t++) 179 for ( ; n > 0 && tolower (*s) == tolower (*t); n--, s++, t++)
181 if (*s == '\0') 180 if (*s == '\0')
182 return 0; 181 return 0;
183 return n == 0 ? 0 : tolower (*s) - tolower (*t); 182 return n == 0 ? 0 : tolower (*s) - tolower (*t);
@@ -190,7 +189,7 @@ void
190check_mac () 189check_mac ()
191{ 190{
192 if (! mac_in_use) 191 if (! mac_in_use)
193 error ("Mac OS not in use or not initialized"); 192 error ("Mac native windows not in use or not initialized");
194} 193}
195 194
196/* Nonzero if we can use mouse menus. 195/* Nonzero if we can use mouse menus.
@@ -228,33 +227,28 @@ struct mac_display_info *
228check_x_display_info (frame) 227check_x_display_info (frame)
229 Lisp_Object frame; 228 Lisp_Object frame;
230{ 229{
231 if (!mac_initialized) 230 struct mac_display_info *dpyinfo = NULL;
232 {
233 mac_initialize ();
234 mac_initialized = 1;
235 }
236 231
237 if (NILP (frame)) 232 if (NILP (frame))
238 { 233 {
239 struct frame *sf = XFRAME (selected_frame); 234 struct frame *sf = XFRAME (selected_frame);
240 235
241 if (FRAME_MAC_P (sf) && FRAME_LIVE_P (sf)) 236 if (FRAME_MAC_P (sf) && FRAME_LIVE_P (sf))
242 return FRAME_MAC_DISPLAY_INFO (sf); 237 dpyinfo = FRAME_MAC_DISPLAY_INFO (sf);
238 else if (x_display_list != 0)
239 dpyinfo = x_display_list;
243 else 240 else
244 return &one_mac_display_info; 241 error ("Mac native windows are not in use or not initialized");
245 } 242 }
246 else if (STRINGP (frame)) 243 else if (STRINGP (frame))
247 return x_display_info_for_name (frame); 244 dpyinfo = x_display_info_for_name (frame);
248 else 245 else
249 { 246 {
250 FRAME_PTR f; 247 FRAME_PTR f = check_x_frame (frame);
251 248 dpyinfo = FRAME_MAC_DISPLAY_INFO (f);
252 CHECK_LIVE_FRAME (frame);
253 f = XFRAME (frame);
254 if (! FRAME_MAC_P (f))
255 error ("non-mac frame used");
256 return FRAME_MAC_DISPLAY_INFO (f);
257 } 249 }
250
251 return dpyinfo;
258} 252}
259 253
260/* Return the Emacs frame-object corresponding to a mac window. 254/* Return the Emacs frame-object corresponding to a mac window.
@@ -1109,7 +1103,7 @@ mac_color_map_lookup (colorname)
1109 BLOCK_INPUT; 1103 BLOCK_INPUT;
1110 1104
1111 for (i = 0; i < sizeof (mac_color_map) / sizeof (mac_color_map[0]); i++) 1105 for (i = 0; i < sizeof (mac_color_map) / sizeof (mac_color_map[0]); i++)
1112 if (stricmp (colorname, mac_color_map[i].name) == 0) 1106 if (xstricmp (colorname, mac_color_map[i].name) == 0)
1113 { 1107 {
1114 ret = make_number (mac_color_map[i].color); 1108 ret = make_number (mac_color_map[i].color);
1115 break; 1109 break;
@@ -2059,13 +2053,49 @@ x_set_scroll_bar_default_width (f)
2059 2053
2060/* Subroutines of creating a frame. */ 2054/* Subroutines of creating a frame. */
2061 2055
2056static char *
2057mac_get_rdb_resource (rdb, resource)
2058 char *rdb;
2059 char *resource;
2060{
2061 char *value = rdb;
2062 int len = strlen (resource);
2063
2064 while (*value)
2065 {
2066 if ((strncmp (value, resource, len) == 0) && (value[len] == ':'))
2067 return xstrdup (&value[len + 1]);
2068
2069 value = strchr (value, '\0') + 1;
2070 }
2071
2072 return NULL;
2073}
2074
2075/* Retrieve the string resource specified by NAME with CLASS from
2076 database RDB. */
2077
2062char * 2078char *
2063x_get_string_resource (rdb, name, class) 2079x_get_string_resource (rdb, name, class)
2064 XrmDatabase rdb; 2080 XrmDatabase rdb;
2065 char *name, *class; 2081 char *name, *class;
2066{ 2082{
2067 /* MAC_TODO: implement resource strings */ 2083 if (rdb)
2084 {
2085 char *resource;
2086
2087 if (resource = mac_get_rdb_resource (rdb, name))
2088 return resource;
2089 if (resource = mac_get_rdb_resource (rdb, class))
2090 return resource;
2091 }
2092
2093 /* MAC_TODO: implement resource strings. (Maybe Property Lists?) */
2094#if 0
2095 return mac_get_string_resource (name, class);
2096#else
2068 return (char *)0; 2097 return (char *)0;
2098#endif
2069} 2099}
2070 2100
2071/* Return the value of parameter PARAM. 2101/* Return the value of parameter PARAM.
@@ -2229,36 +2259,38 @@ XParseGeometry (string, x, y, width, height)
2229} 2259}
2230 2260
2231 2261
2232#if 0 /* MAC_TODO */
2233/* Create and set up the Mac window for frame F. */ 2262/* Create and set up the Mac window for frame F. */
2234 2263
2264extern install_window_handler (WindowPtr);
2265
2235static void 2266static void
2236mac_window (f, window_prompting, minibuffer_only) 2267mac_window (f)
2237 struct frame *f; 2268 struct frame *f;
2238 long window_prompting;
2239 int minibuffer_only;
2240{ 2269{
2241 Rect r; 2270 Rect r;
2242 2271
2243 BLOCK_INPUT; 2272 BLOCK_INPUT;
2244 2273
2245 /* Use the resource name as the top-level window name
2246 for looking up resources. Make a non-Lisp copy
2247 for the window manager, so GC relocation won't bother it.
2248
2249 Elsewhere we specify the window name for the window manager. */
2250
2251 {
2252 char *str = (char *) SDATA (Vx_resource_name);
2253 f->namebuf = (char *) xmalloc (strlen (str) + 1);
2254 strcpy (f->namebuf, str);
2255 }
2256
2257 SetRect (&r, f->left_pos, f->top_pos, 2274 SetRect (&r, f->left_pos, f->top_pos,
2258 f->left_pos + FRAME_PIXEL_WIDTH (f), 2275 f->left_pos + FRAME_PIXEL_WIDTH (f),
2259 f->top_pos + FRAME_PIXEL_HEIGHT (f)); 2276 f->top_pos + FRAME_PIXEL_HEIGHT (f));
2277#if TARGET_API_MAC_CARBON
2278 CreateNewWindow (kDocumentWindowClass,
2279 kWindowStandardDocumentAttributes
2280 /* | kWindowToolbarButtonAttribute */,
2281 &r, &FRAME_MAC_WINDOW (f));
2282 if (FRAME_MAC_WINDOW (f))
2283 {
2284 SetWRefCon (FRAME_MAC_WINDOW (f), (long) f->output_data.mac);
2285 install_window_handler (FRAME_MAC_WINDOW (f));
2286 }
2287#else
2260 FRAME_MAC_WINDOW (f) 2288 FRAME_MAC_WINDOW (f)
2261 = NewCWindow (NULL, &r, "\p", 1, zoomDocProc, (WindowPtr) -1, 1, (long) f->output_data.mac); 2289 = NewCWindow (NULL, &r, "\p", false, zoomDocProc,
2290 (WindowPtr) -1, 1, (long) f->output_data.mac);
2291#endif
2292 /* so that update events can find this mac_output struct */
2293 f->output_data.mac->mFP = f; /* point back to emacs frame */
2262 2294
2263 validate_x_resource_name (); 2295 validate_x_resource_name ();
2264 2296
@@ -2276,17 +2308,11 @@ mac_window (f, window_prompting, minibuffer_only)
2276 x_set_name (f, name, explicit); 2308 x_set_name (f, name, explicit);
2277 } 2309 }
2278 2310
2279 ShowWindow (FRAME_MAC_WINDOW (f));
2280
2281 UNBLOCK_INPUT; 2311 UNBLOCK_INPUT;
2282 2312
2283 if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f))
2284 initialize_frame_menubar (f);
2285
2286 if (FRAME_MAC_WINDOW (f) == 0) 2313 if (FRAME_MAC_WINDOW (f) == 0)
2287 error ("Unable to create window"); 2314 error ("Unable to create window");
2288} 2315}
2289#endif /* MAC_TODO */
2290 2316
2291/* Handle the icon stuff for this window. Perhaps later we might 2317/* Handle the icon stuff for this window. Perhaps later we might
2292 want an x_set_icon_position which can be called interactively as 2318 want an x_set_icon_position which can be called interactively as
@@ -2703,6 +2729,8 @@ This function is an internal primitive--use `make-frame' instead. */)
2703 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL); 2729 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL);
2704 x_default_parameter (f, parms, Qtitle, Qnil, 2730 x_default_parameter (f, parms, Qtitle, Qnil,
2705 "title", "Title", RES_TYPE_STRING); 2731 "title", "Title", RES_TYPE_STRING);
2732 x_default_parameter (f, parms, Qfullscreen, Qnil,
2733 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
2706 2734
2707 f->output_data.mac->parent_desc = FRAME_MAC_DISPLAY_INFO (f)->root_window; 2735 f->output_data.mac->parent_desc = FRAME_MAC_DISPLAY_INFO (f)->root_window;
2708 2736
@@ -2728,8 +2756,7 @@ This function is an internal primitive--use `make-frame' instead. */)
2728 tem = mac_get_arg (parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN); 2756 tem = mac_get_arg (parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
2729 f->no_split = minibuffer_only || EQ (tem, Qt); 2757 f->no_split = minibuffer_only || EQ (tem, Qt);
2730 2758
2731 /* mac_window (f, window_prompting, minibuffer_only); */ 2759 mac_window (f);
2732 make_mac_frame (f);
2733 2760
2734 x_icon (f, parms); 2761 x_icon (f, parms);
2735 x_make_gc (f); 2762 x_make_gc (f);
@@ -2763,14 +2790,12 @@ This function is an internal primitive--use `make-frame' instead. */)
2763 FRAME_LINES (f) = 0; 2790 FRAME_LINES (f) = 0;
2764 change_frame_size (f, height, width, 1, 0, 0); 2791 change_frame_size (f, height, width, 1, 0, 0);
2765 2792
2766#if 0 /* MAC_TODO: when we have window manager hints */
2767 /* Tell the server what size and position, etc, we want, and how 2793 /* Tell the server what size and position, etc, we want, and how
2768 badly we want them. This should be done after we have the menu 2794 badly we want them. This should be done after we have the menu
2769 bar so that its size can be taken into account. */ 2795 bar so that its size can be taken into account. */
2770 BLOCK_INPUT; 2796 BLOCK_INPUT;
2771 x_wm_set_size_hint (f, window_prompting, 0); 2797 x_wm_set_size_hint (f, window_prompting, 0);
2772 UNBLOCK_INPUT; 2798 UNBLOCK_INPUT;
2773#endif
2774 2799
2775 /* Make the window appear on the frame and enable display, unless 2800 /* Make the window appear on the frame and enable display, unless
2776 the caller says not to. However, with explicit parent, Emacs 2801 the caller says not to. However, with explicit parent, Emacs
@@ -3144,6 +3169,9 @@ x_display_info_for_name (name)
3144 3169
3145 CHECK_STRING (name); 3170 CHECK_STRING (name);
3146 3171
3172 if (! EQ (Vwindow_system, intern ("mac")))
3173 error ("Not using Mac native windows");
3174
3147 for (dpyinfo = &one_mac_display_info, names = x_display_name_list; 3175 for (dpyinfo = &one_mac_display_info, names = x_display_name_list;
3148 dpyinfo; 3176 dpyinfo;
3149 dpyinfo = dpyinfo->next, names = XCDR (names)) 3177 dpyinfo = dpyinfo->next, names = XCDR (names))
@@ -3171,7 +3199,6 @@ x_display_info_for_name (name)
3171 return dpyinfo; 3199 return dpyinfo;
3172} 3200}
3173 3201
3174#if 0 /* MAC_TODO: implement network support */
3175DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection, 3202DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection,
3176 1, 3, 0, 3203 1, 3, 0,
3177 doc: /* Open a connection to a server. 3204 doc: /* Open a connection to a server.
@@ -3190,7 +3217,7 @@ terminate Emacs if we can't open the connection. */)
3190 CHECK_STRING (xrm_string); 3217 CHECK_STRING (xrm_string);
3191 3218
3192 if (! EQ (Vwindow_system, intern ("mac"))) 3219 if (! EQ (Vwindow_system, intern ("mac")))
3193 error ("Not using Mac OS"); 3220 error ("Not using Mac native windows");
3194 3221
3195 if (! NILP (xrm_string)) 3222 if (! NILP (xrm_string))
3196 xrm_option = (unsigned char *) SDATA (xrm_string); 3223 xrm_option = (unsigned char *) SDATA (xrm_string);
@@ -3238,11 +3265,9 @@ If DISPLAY is nil, that stands for the selected frame's display. */)
3238 for (i = 0; i < dpyinfo->n_fonts; i++) 3265 for (i = 0; i < dpyinfo->n_fonts; i++)
3239 if (dpyinfo->font_table[i].name) 3266 if (dpyinfo->font_table[i].name)
3240 { 3267 {
3241 if (dpyinfo->font_table[i].name != dpyinfo->font_table[i].full_name) 3268 mac_unload_font (dpyinfo, dpyinfo->font_table[i].font);
3242 xfree (dpyinfo->font_table[i].full_name);
3243 xfree (dpyinfo->font_table[i].name);
3244 x_unload_font (dpyinfo, dpyinfo->font_table[i].font);
3245 } 3269 }
3270
3246 x_destroy_all_bitmaps (dpyinfo); 3271 x_destroy_all_bitmaps (dpyinfo);
3247 3272
3248 x_delete_display (dpyinfo); 3273 x_delete_display (dpyinfo);
@@ -3250,7 +3275,6 @@ If DISPLAY is nil, that stands for the selected frame's display. */)
3250 3275
3251 return Qnil; 3276 return Qnil;
3252} 3277}
3253#endif /* 0 */
3254 3278
3255DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0, 3279DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0,
3256 doc: /* Return the list of display names that Emacs has connections to. */) 3280 doc: /* Return the list of display names that Emacs has connections to. */)
@@ -3813,18 +3837,23 @@ x_create_tip_frame (dpyinfo, parms, text)
3813 3837
3814 BLOCK_INPUT; 3838 BLOCK_INPUT;
3815 SetRect (&r, 0, 0, 1, 1); 3839 SetRect (&r, 0, 0, 1, 1);
3840#if TARGET_API_MAC_CARBON
3816 if (CreateNewWindow (kHelpWindowClass, 3841 if (CreateNewWindow (kHelpWindowClass,
3817#ifdef MAC_OS_X_VERSION_10_2 3842#ifdef MAC_OS_X_VERSION_10_2
3818 kWindowIgnoreClicksAttribute | 3843 kWindowIgnoreClicksAttribute |
3819#endif 3844#endif
3845 kWindowNoUpdatesAttribute |
3820 kWindowNoActivatesAttribute, 3846 kWindowNoActivatesAttribute,
3821 &r, &tip_window) == noErr) 3847 &r, &tip_window) == noErr)
3848#else
3849 if (tip_window = NewCWindow (NULL, &r, "\p", false, plainDBox,
3850 NULL, false, 0L))
3851#endif
3822 { 3852 {
3823 FRAME_MAC_WINDOW (f) = tip_window; 3853 FRAME_MAC_WINDOW (f) = tip_window;
3824 SetWRefCon (tip_window, (long) f->output_data.mac); 3854 SetWRefCon (tip_window, (long) f->output_data.mac);
3825 /* so that update events can find this mac_output struct */ 3855 /* so that update events can find this mac_output struct */
3826 f->output_data.mac->mFP = f; 3856 f->output_data.mac->mFP = f;
3827 ShowWindow (tip_window);
3828 } 3857 }
3829 UNBLOCK_INPUT; 3858 UNBLOCK_INPUT;
3830 } 3859 }
@@ -4140,6 +4169,7 @@ Text larger than the specified size is clipped. */)
4140 BLOCK_INPUT; 4169 BLOCK_INPUT;
4141 MoveWindow (FRAME_MAC_WINDOW (f), root_x, root_y, false); 4170 MoveWindow (FRAME_MAC_WINDOW (f), root_x, root_y, false);
4142 SizeWindow (FRAME_MAC_WINDOW (f), width, height, true); 4171 SizeWindow (FRAME_MAC_WINDOW (f), width, height, true);
4172 ShowWindow (FRAME_MAC_WINDOW (f));
4143 BringToFront (FRAME_MAC_WINDOW (f)); 4173 BringToFront (FRAME_MAC_WINDOW (f));
4144 UNBLOCK_INPUT; 4174 UNBLOCK_INPUT;
4145 4175
@@ -4198,7 +4228,7 @@ Value is t if tooltip was open, nil otherwise. */)
4198 4228
4199 4229
4200 4230
4201#ifdef TARGET_API_MAC_CARBON 4231#if TARGET_API_MAC_CARBON
4202/*********************************************************************** 4232/***********************************************************************
4203 File selection dialog 4233 File selection dialog
4204 ***********************************************************************/ 4234 ***********************************************************************/
@@ -4405,14 +4435,19 @@ frame_parm_handler mac_frame_parm_handlers[] =
4405 x_set_fringe_width, 4435 x_set_fringe_width,
4406 x_set_fringe_width, 4436 x_set_fringe_width,
4407 0, /* x_set_wait_for_wm, */ 4437 0, /* x_set_wait_for_wm, */
4408 0, /* MAC_TODO: x_set_fullscreen, */ 4438 x_set_fullscreen,
4409}; 4439};
4410 4440
4411void 4441void
4412syms_of_macfns () 4442syms_of_macfns ()
4413{ 4443{
4414 /* Certainly running on Mac. */ 4444#ifdef MAC_OSX
4445 /* This is zero if not using Mac native windows. */
4446 mac_in_use = 0;
4447#else
4448 /* Certainly running on Mac native windows. */
4415 mac_in_use = 1; 4449 mac_in_use = 1;
4450#endif
4416 4451
4417 /* The section below is built by the lisp expression at the top of the file, 4452 /* The section below is built by the lisp expression at the top of the file,
4418 just above where these variables are declared. */ 4453 just above where these variables are declared. */
@@ -4536,10 +4571,8 @@ Chinese, Japanese, and Korean. */);
4536 defsubr (&Sx_display_backing_store); 4571 defsubr (&Sx_display_backing_store);
4537 defsubr (&Sx_display_save_under); 4572 defsubr (&Sx_display_save_under);
4538 defsubr (&Sx_create_frame); 4573 defsubr (&Sx_create_frame);
4539#if 0 /* MAC_TODO: implement network support */
4540 defsubr (&Sx_open_connection); 4574 defsubr (&Sx_open_connection);
4541 defsubr (&Sx_close_connection); 4575 defsubr (&Sx_close_connection);
4542#endif
4543 defsubr (&Sx_display_list); 4576 defsubr (&Sx_display_list);
4544 defsubr (&Sx_synchronize); 4577 defsubr (&Sx_synchronize);
4545 4578
diff --git a/src/macgui.h b/src/macgui.h
index e5ea665ac15..1e1447dfaa8 100644
--- a/src/macgui.h
+++ b/src/macgui.h
@@ -62,18 +62,17 @@ typedef unsigned long Time;
62#else 62#else
63#include <QuickDraw.h> /* for WindowPtr */ 63#include <QuickDraw.h> /* for WindowPtr */
64#include <QDOffscreen.h> /* for GWorldPtr */ 64#include <QDOffscreen.h> /* for GWorldPtr */
65#include <Controls.h> /* for ControlHandle in xdisp.c */ 65#include <Windows.h>
66#include <Gestalt.h> 66#include <Gestalt.h>
67#endif 67#endif
68 68
69typedef WindowPtr Window;
69typedef GWorldPtr Pixmap; 70typedef GWorldPtr Pixmap;
70 71
71#if TARGET_API_MAC_CARBON 72#if TARGET_API_MAC_CARBON
72typedef struct OpaqueWindowPtr *Window;
73#define Cursor ThemeCursor 73#define Cursor ThemeCursor
74#define No_Cursor (-1) 74#define No_Cursor (-1)
75#else 75#else
76typedef WindowPtr Window;
77#define SetPortWindowPort(w) SetPort(w) 76#define SetPortWindowPort(w) SetPort(w)
78#define Cursor CursHandle 77#define Cursor CursHandle
79#define No_Cursor (0) 78#define No_Cursor (0)
@@ -198,6 +197,29 @@ XCreateGC (void *, Window, unsigned long, XGCValues *);
198#define XNegative 0x0010 197#define XNegative 0x0010
199#define YNegative 0x0020 198#define YNegative 0x0020
200 199
200typedef struct {
201 long flags; /* marks which fields in this structure are defined */
202#if 0
203 int x, y; /* obsolete for new window mgrs, but clients */
204 int width, height; /* should set so old wm's don't mess up */
205#endif
206 int min_width, min_height;
207#if 0
208 int max_width, max_height;
209#endif
210 int width_inc, height_inc;
211#if 0
212 struct {
213 int x; /* numerator */
214 int y; /* denominator */
215 } min_aspect, max_aspect;
216#endif
217 int base_width, base_height; /* added by ICCCM version 1 */
218#if 0
219 int win_gravity; /* added by ICCCM version 1 */
220#endif
221} XSizeHints;
222
201#define USPosition (1L << 0) /* user specified x, y */ 223#define USPosition (1L << 0) /* user specified x, y */
202#define USSize (1L << 1) /* user specified width, height */ 224#define USSize (1L << 1) /* user specified width, height */
203 225
diff --git a/src/macterm.c b/src/macterm.c
index 9dae0b54d70..3f1fb1642f1 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -1178,7 +1178,17 @@ static void
1178x_update_begin (f) 1178x_update_begin (f)
1179 struct frame *f; 1179 struct frame *f;
1180{ 1180{
1181 /* Nothing to do. */ 1181#if TARGET_API_MAC_CARBON
1182 /* During update of a frame, availability of input events is
1183 periodically checked with ReceiveNextEvent if
1184 redisplay-dont-pause is nil. That normally flushes window buffer
1185 changes for every check, and thus screen update looks waving even
1186 if no input is available. So we disable screen updates during
1187 update of a frame. */
1188 BLOCK_INPUT;
1189 DisableScreenUpdates ();
1190 UNBLOCK_INPUT;
1191#endif
1182} 1192}
1183 1193
1184 1194
@@ -1263,7 +1273,7 @@ mac_draw_vertical_window_border (w, x, y0, y1)
1263 make sure that the mouse-highlight is properly redrawn. 1273 make sure that the mouse-highlight is properly redrawn.
1264 1274
1265 W may be a menu bar pseudo-window in case we don't have X toolkit 1275 W may be a menu bar pseudo-window in case we don't have X toolkit
1266 support. Such windows don't have a cursor, so don't display it 1276 support. Such windows don't have a cursor, so don't display it
1267 here. */ 1277 here. */
1268 1278
1269static void 1279static void
@@ -1327,6 +1337,9 @@ x_update_end (f)
1327 1337
1328 mac_set_backcolor (FRAME_BACKGROUND_PIXEL (f)); 1338 mac_set_backcolor (FRAME_BACKGROUND_PIXEL (f));
1329 1339
1340#if TARGET_API_MAC_CARBON
1341 EnableScreenUpdates ();
1342#endif
1330 XFlush (FRAME_MAC_DISPLAY (f)); 1343 XFlush (FRAME_MAC_DISPLAY (f));
1331 UNBLOCK_INPUT; 1344 UNBLOCK_INPUT;
1332} 1345}
@@ -1983,7 +1996,7 @@ x_draw_glyph_string_background (s, force_p)
1983 } 1996 }
1984 else 1997 else
1985#endif 1998#endif
1986#if 0 /* defined(MAC_OS8)*/ 1999#ifdef MAC_OS8
1987 if (FONT_HEIGHT (s->font) < s->height - 2 * box_line_width 2000 if (FONT_HEIGHT (s->font) < s->height - 2 * box_line_width
1988 || s->font_not_found_p 2001 || s->font_not_found_p
1989 || s->extends_to_end_of_line_p 2002 || s->extends_to_end_of_line_p
@@ -2041,7 +2054,7 @@ x_draw_glyph_string_foreground (s)
2041 for (i = 0; i < s->nchars; ++i) 2054 for (i = 0; i < s->nchars; ++i)
2042 char1b[i] = s->char2b[i].byte2; 2055 char1b[i] = s->char2b[i].byte2;
2043 2056
2044#if 0 /* defined(MAC_OS8) */ 2057#ifdef MAC_OS8
2045 /* Draw text with XDrawString if background has already been 2058 /* Draw text with XDrawString if background has already been
2046 filled. Otherwise, use XDrawImageString. (Note that 2059 filled. Otherwise, use XDrawImageString. (Note that
2047 XDrawImageString is usually faster than XDrawString.) Always 2060 XDrawImageString is usually faster than XDrawString.) Always
@@ -2059,7 +2072,7 @@ x_draw_glyph_string_foreground (s)
2059 XDrawString (s->display, s->window, s->gc, x, 2072 XDrawString (s->display, s->window, s->gc, x,
2060 s->ybase - boff, char1b, s->nchars); 2073 s->ybase - boff, char1b, s->nchars);
2061 } 2074 }
2062#if 0 /* defined(MAC_OS8)*/ 2075#ifdef MAC_OS8
2063 else 2076 else
2064 { 2077 {
2065 if (s->two_byte_p) 2078 if (s->two_byte_p)
@@ -3652,6 +3665,7 @@ x_get_keysym_name (keysym)
3652 3665
3653 3666
3654 3667
3668#if 0
3655/* Mouse clicks and mouse movement. Rah. */ 3669/* Mouse clicks and mouse movement. Rah. */
3656 3670
3657/* Prepare a mouse-event in *RESULT for placement in the input queue. 3671/* Prepare a mouse-event in *RESULT for placement in the input queue.
@@ -3685,6 +3699,7 @@ construct_mouse_click (result, event, f)
3685 result->arg = Qnil; 3699 result->arg = Qnil;
3686 return Qnil; 3700 return Qnil;
3687} 3701}
3702#endif
3688 3703
3689 3704
3690/* Function to report a mouse movement to the mainstream Emacs code. 3705/* Function to report a mouse movement to the mainstream Emacs code.
@@ -3754,8 +3769,6 @@ int disable_mouse_highlight;
3754 3769
3755static struct scroll_bar *x_window_to_scroll_bar (); 3770static struct scroll_bar *x_window_to_scroll_bar ();
3756static void x_scroll_bar_report_motion (); 3771static void x_scroll_bar_report_motion ();
3757static void x_check_fullscreen P_ ((struct frame *));
3758static void x_check_fullscreen_move P_ ((struct frame *));
3759static int glyph_rect P_ ((struct frame *f, int, int, Rect *)); 3772static int glyph_rect P_ ((struct frame *f, int, int, Rect *));
3760 3773
3761 3774
@@ -4017,7 +4030,7 @@ x_scroll_bar_create (w, top, left, width, height, disp_top, disp_height)
4017 r.right = left + width; 4030 r.right = left + width;
4018 r.bottom = disp_top + disp_height; 4031 r.bottom = disp_top + disp_height;
4019 4032
4020#ifdef TARGET_API_MAC_CARBON 4033#if TARGET_API_MAC_CARBON
4021 ch = NewControl (FRAME_MAC_WINDOW (f), &r, "\p", 1, 0, 0, 0, 4034 ch = NewControl (FRAME_MAC_WINDOW (f), &r, "\p", 1, 0, 0, 0,
4022 kControlScrollBarProc, 0L); 4035 kControlScrollBarProc, 0L);
4023#else 4036#else
@@ -4395,7 +4408,7 @@ activate_scroll_bars (frame)
4395 while (! NILP (bar)) 4408 while (! NILP (bar))
4396 { 4409 {
4397 ch = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (bar)); 4410 ch = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (bar));
4398#ifdef TARGET_API_MAC_CARBON 4411#if 1 /* TARGET_API_MAC_CARBON */
4399 ActivateControl (ch); 4412 ActivateControl (ch);
4400#else 4413#else
4401 SetControlMaximum (ch, 4414 SetControlMaximum (ch,
@@ -4419,10 +4432,10 @@ deactivate_scroll_bars (frame)
4419 while (! NILP (bar)) 4432 while (! NILP (bar))
4420 { 4433 {
4421 ch = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (bar)); 4434 ch = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (bar));
4422#ifdef TARGET_API_MAC_CARBON 4435#if 1 /* TARGET_API_MAC_CARBON */
4423 DeactivateControl (ch); 4436 DeactivateControl (ch);
4424#else 4437#else
4425 SetControlMaximum (ch, XINT (-1)); 4438 SetControlMaximum (ch, -1);
4426#endif 4439#endif
4427 bar = XSCROLL_BAR (bar)->next; 4440 bar = XSCROLL_BAR (bar)->next;
4428 } 4441 }
@@ -4466,7 +4479,7 @@ x_scroll_bar_handle_click (bar, part_code, er, bufp)
4466 case kControlPageDownPart: 4479 case kControlPageDownPart:
4467 bufp->part = scroll_bar_below_handle; 4480 bufp->part = scroll_bar_below_handle;
4468 break; 4481 break;
4469#ifdef TARGET_API_MAC_CARBON 4482#if TARGET_API_MAC_CARBON
4470 default: 4483 default:
4471#else 4484#else
4472 case kControlIndicatorPart: 4485 case kControlIndicatorPart:
@@ -4974,13 +4987,16 @@ x_new_font (f, fontname)
4974 XSetFont (FRAME_MAC_DISPLAY (f), f->output_data.mac->cursor_gc, 4987 XSetFont (FRAME_MAC_DISPLAY (f), f->output_data.mac->cursor_gc,
4975 FRAME_FONT (f)); 4988 FRAME_FONT (f));
4976 4989
4990 /* Don't change the size of a tip frame; there's no point in
4991 doing it because it's done in Fx_show_tip, and it leads to
4992 problems because the tip frame has no widget. */
4977 if (NILP (tip_frame) || XFRAME (tip_frame) != f) 4993 if (NILP (tip_frame) || XFRAME (tip_frame) != f)
4978 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f)); 4994 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
4979 } 4995 }
4980 4996
4981 return build_string (fontp->full_name); 4997 return build_string (fontp->full_name);
4982} 4998}
4983 4999
4984/* Give frame F the fontset named FONTSETNAME as its default font, and 5000/* Give frame F the fontset named FONTSETNAME as its default font, and
4985 return the full name of that fontset. FONTSETNAME may be a wildcard 5001 return the full name of that fontset. FONTSETNAME may be a wildcard
4986 pattern; in that case, we choose some fontset that fits the pattern. 5002 pattern; in that case, we choose some fontset that fits the pattern.
@@ -5369,6 +5385,25 @@ x_make_frame_visible (f)
5369 5385
5370 f->output_data.mac->asked_for_visible = 1; 5386 f->output_data.mac->asked_for_visible = 1;
5371 5387
5388#if TARGET_API_MAC_CARBON
5389 if (!(FRAME_SIZE_HINTS (f)->flags & (USPosition | PPosition)))
5390 {
5391 struct frame *sf = SELECTED_FRAME ();
5392 if (!FRAME_MAC_P (sf))
5393 RepositionWindow (FRAME_MAC_WINDOW (f), NULL,
5394 kWindowCenterOnMainScreen);
5395 else
5396 RepositionWindow (FRAME_MAC_WINDOW (f),
5397 FRAME_MAC_WINDOW (sf),
5398#ifdef MAC_OS_X_VERSION_10_2
5399 kWindowCascadeStartAtParentWindowScreen
5400#else
5401 kWindowCascadeOnParentWindowScreen
5402#endif
5403 );
5404 x_real_positions (f, &f->left_pos, &f->top_pos);
5405 }
5406#endif
5372 ShowWindow (FRAME_MAC_WINDOW (f)); 5407 ShowWindow (FRAME_MAC_WINDOW (f));
5373 } 5408 }
5374 5409
@@ -5496,6 +5531,9 @@ x_free_frame_resources (f)
5496 5531
5497 x_free_gcs (f); 5532 x_free_gcs (f);
5498 5533
5534 if (FRAME_SIZE_HINTS (f))
5535 xfree (FRAME_SIZE_HINTS (f));
5536
5499 xfree (f->output_data.mac); 5537 xfree (f->output_data.mac);
5500 f->output_data.mac = NULL; 5538 f->output_data.mac = NULL;
5501 5539
@@ -5548,143 +5586,39 @@ x_wm_set_size_hint (f, flags, user_position)
5548 long flags; 5586 long flags;
5549 int user_position; 5587 int user_position;
5550{ 5588{
5551#if 0 /* MAC_TODO: connect this to the Appearance Manager */ 5589 int base_width, base_height, width_inc, height_inc;
5552 XSizeHints size_hints; 5590 int min_rows = 0, min_cols = 0;
5553 5591 XSizeHints *size_hints;
5554#ifdef USE_X_TOOLKIT
5555 Arg al[2];
5556 int ac = 0;
5557 Dimension widget_width, widget_height;
5558 Window window = XtWindow (f->output_data.x->widget);
5559#else /* not USE_X_TOOLKIT */
5560 Window window = FRAME_X_WINDOW (f);
5561#endif /* not USE_X_TOOLKIT */
5562
5563 /* Setting PMaxSize caused various problems. */
5564 size_hints.flags = PResizeInc | PMinSize /* | PMaxSize */;
5565
5566 size_hints.x = f->left_pos;
5567 size_hints.y = f->top_pos;
5568
5569#ifdef USE_X_TOOLKIT
5570 XtSetArg (al[ac], XtNwidth, &widget_width); ac++;
5571 XtSetArg (al[ac], XtNheight, &widget_height); ac++;
5572 XtGetValues (f->output_data.x->widget, al, ac);
5573 size_hints.height = widget_height;
5574 size_hints.width = widget_width;
5575#else /* not USE_X_TOOLKIT */
5576 size_hints.height = FRAME_PIXEL_HEIGHT (f);
5577 size_hints.width = FRAME_PIXEL_WIDTH (f);
5578#endif /* not USE_X_TOOLKIT */
5579
5580 size_hints.width_inc = FRAME_COLUMN_WIDTH (f);
5581 size_hints.height_inc = FRAME_LINE_HEIGHT (f);
5582 size_hints.max_width
5583 = FRAME_X_DISPLAY_INFO (f)->width - FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, 0);
5584 size_hints.max_height
5585 = FRAME_X_DISPLAY_INFO (f)->height - FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, 0);
5586
5587 /* Calculate the base and minimum sizes.
5588
5589 (When we use the X toolkit, we don't do it here.
5590 Instead we copy the values that the widgets are using, below.) */
5591#ifndef USE_X_TOOLKIT
5592 {
5593 int base_width, base_height;
5594 int min_rows = 0, min_cols = 0;
5595
5596 base_width = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, 0);
5597 base_height = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, 0);
5598 5592
5599 check_frame_size (f, &min_rows, &min_cols); 5593 base_width = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, 0);
5594 base_height = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, 0);
5595 width_inc = FRAME_COLUMN_WIDTH (f);
5596 height_inc = FRAME_LINE_HEIGHT (f);
5600 5597
5601 /* The window manager uses the base width hints to calculate the 5598 check_frame_size (f, &min_rows, &min_cols);
5602 current number of rows and columns in the frame while
5603 resizing; min_width and min_height aren't useful for this
5604 purpose, since they might not give the dimensions for a
5605 zero-row, zero-column frame.
5606 5599
5607 We use the base_width and base_height members if we have 5600 size_hints = FRAME_SIZE_HINTS (f);
5608 them; otherwise, we set the min_width and min_height members 5601 if (size_hints == NULL)
5609 to the size for a zero x zero frame. */
5610
5611#ifdef HAVE_X11R4
5612 size_hints.flags |= PBaseSize;
5613 size_hints.base_width = base_width;
5614 size_hints.base_height = base_height;
5615 size_hints.min_width = base_width + min_cols * size_hints.width_inc;
5616 size_hints.min_height = base_height + min_rows * size_hints.height_inc;
5617#else
5618 size_hints.min_width = base_width;
5619 size_hints.min_height = base_height;
5620#endif
5621 }
5622
5623 /* If we don't need the old flags, we don't need the old hint at all. */
5624 if (flags)
5625 { 5602 {
5626 size_hints.flags |= flags; 5603 size_hints = FRAME_SIZE_HINTS (f) = xmalloc (sizeof (XSizeHints));
5627 goto no_read; 5604 bzero (size_hints, sizeof (XSizeHints));
5628 } 5605 }
5629#endif /* not USE_X_TOOLKIT */
5630
5631 {
5632 XSizeHints hints; /* Sometimes I hate X Windows... */
5633 long supplied_return;
5634 int value;
5635
5636#ifdef HAVE_X11R4
5637 value = XGetWMNormalHints (FRAME_X_DISPLAY (f), window, &hints,
5638 &supplied_return);
5639#else
5640 value = XGetNormalHints (FRAME_X_DISPLAY (f), window, &hints);
5641#endif
5642
5643#ifdef USE_X_TOOLKIT
5644 size_hints.base_height = hints.base_height;
5645 size_hints.base_width = hints.base_width;
5646 size_hints.min_height = hints.min_height;
5647 size_hints.min_width = hints.min_width;
5648#endif
5649
5650 if (flags)
5651 size_hints.flags |= flags;
5652 else
5653 {
5654 if (value == 0)
5655 hints.flags = 0;
5656 if (hints.flags & PSize)
5657 size_hints.flags |= PSize;
5658 if (hints.flags & PPosition)
5659 size_hints.flags |= PPosition;
5660 if (hints.flags & USPosition)
5661 size_hints.flags |= USPosition;
5662 if (hints.flags & USSize)
5663 size_hints.flags |= USSize;
5664 }
5665 }
5666
5667#ifndef USE_X_TOOLKIT
5668 no_read:
5669#endif
5670 5606
5671#ifdef PWinGravity 5607 size_hints->flags |= PResizeInc | PMinSize | PBaseSize ;
5672 size_hints.win_gravity = f->win_gravity; 5608 size_hints->width_inc = width_inc;
5673 size_hints.flags |= PWinGravity; 5609 size_hints->height_inc = height_inc;
5610 size_hints->min_width = base_width + min_cols * width_inc;
5611 size_hints->min_height = base_height + min_rows * height_inc;
5612 size_hints->base_width = base_width;
5613 size_hints->base_height = base_height;
5674 5614
5675 if (user_position) 5615 if (flags)
5616 size_hints->flags = flags;
5617 else if (user_position)
5676 { 5618 {
5677 size_hints.flags &= ~ PPosition; 5619 size_hints->flags &= ~ PPosition;
5678 size_hints.flags |= USPosition; 5620 size_hints->flags |= USPosition;
5679 } 5621 }
5680#endif /* PWinGravity */
5681
5682#ifdef HAVE_X11R4
5683 XSetWMNormalHints (FRAME_X_DISPLAY (f), window, &size_hints);
5684#else
5685 XSetNormalHints (FRAME_X_DISPLAY (f), window, &size_hints);
5686#endif
5687#endif /* MAC_TODO */
5688} 5622}
5689 5623
5690#if 0 /* MAC_TODO: hide application instead of iconify? */ 5624#if 0 /* MAC_TODO: hide application instead of iconify? */
@@ -6120,7 +6054,7 @@ init_font_name_table ()
6120 break; 6054 break;
6121 sc = GetTextEncodingBase (encoding); 6055 sc = GetTextEncodingBase (encoding);
6122 decode_mac_font_name (name, sizeof (name), sc); 6056 decode_mac_font_name (name, sizeof (name), sc);
6123 6057
6124 /* Point the instance iterator at the current font family. */ 6058 /* Point the instance iterator at the current font family. */
6125 if (FMResetFontFamilyInstanceIterator (ff, &ffii) != noErr) 6059 if (FMResetFontFamilyInstanceIterator (ff, &ffii) != noErr)
6126 break; 6060 break;
@@ -6259,6 +6193,19 @@ init_font_name_table ()
6259} 6193}
6260 6194
6261 6195
6196void
6197mac_clear_font_name_table ()
6198{
6199 int i;
6200
6201 for (i = 0; i < font_name_count; i++)
6202 xfree (font_name_table[i]);
6203 xfree (font_name_table);
6204 font_name_table = NULL;
6205 font_name_table_size = font_name_count = 0;
6206}
6207
6208
6262enum xlfd_scalable_field_index 6209enum xlfd_scalable_field_index
6263 { 6210 {
6264 XLFD_SCL_PIXEL_SIZE, 6211 XLFD_SCL_PIXEL_SIZE,
@@ -6311,6 +6258,9 @@ mac_do_list_fonts (pattern, maxnames)
6311 char *longest_start, *cur_start, *nonspecial; 6258 char *longest_start, *cur_start, *nonspecial;
6312 int longest_len, cur_len, exact; 6259 int longest_len, cur_len, exact;
6313 6260
6261 if (font_name_table == NULL) /* Initialize when first used. */
6262 init_font_name_table ();
6263
6314 for (i = 0; i < XLFD_SCL_LAST; i++) 6264 for (i = 0; i < XLFD_SCL_LAST; i++)
6315 scl_val[i] = -1; 6265 scl_val[i] = -1;
6316 6266
@@ -6471,9 +6421,6 @@ x_list_fonts (struct frame *f,
6471 Lisp_Object newlist = Qnil, tem, key; 6421 Lisp_Object newlist = Qnil, tem, key;
6472 struct mac_display_info *dpyinfo = f ? FRAME_MAC_DISPLAY_INFO (f) : NULL; 6422 struct mac_display_info *dpyinfo = f ? FRAME_MAC_DISPLAY_INFO (f) : NULL;
6473 6423
6474 if (font_name_table == NULL) /* Initialize when first used. */
6475 init_font_name_table ();
6476
6477 if (dpyinfo) 6424 if (dpyinfo)
6478 { 6425 {
6479 tem = XCDR (dpyinfo->name_list_element); 6426 tem = XCDR (dpyinfo->name_list_element);
@@ -6487,7 +6434,9 @@ x_list_fonts (struct frame *f,
6487 } 6434 }
6488 } 6435 }
6489 6436
6437 BLOCK_INPUT;
6490 newlist = mac_do_list_fonts (SDATA (pattern), maxnames); 6438 newlist = mac_do_list_fonts (SDATA (pattern), maxnames);
6439 UNBLOCK_INPUT;
6491 6440
6492 /* MAC_TODO: add code for matching outline fonts here */ 6441 /* MAC_TODO: add code for matching outline fonts here */
6493 6442
@@ -6791,6 +6740,18 @@ XLoadQueryFont (Display *dpy, char *fontname)
6791} 6740}
6792 6741
6793 6742
6743void
6744mac_unload_font (dpyinfo, font)
6745 struct mac_display_info *dpyinfo;
6746 XFontStruct *font;
6747{
6748 xfree (font->fontname);
6749 if (font->per_char)
6750 xfree (font->per_char);
6751 xfree (font);
6752}
6753
6754
6794/* Load font named FONTNAME of the size SIZE for frame F, and return a 6755/* Load font named FONTNAME of the size SIZE for frame F, and return a
6795 pointer to the structure font_info while allocating it dynamically. 6756 pointer to the structure font_info while allocating it dynamically.
6796 If SIZE is 0, load any size of font. 6757 If SIZE is 0, load any size of font.
@@ -6841,7 +6802,9 @@ x_load_font (f, fontname, size)
6841 if (size > 0 && !NILP (font_names)) 6802 if (size > 0 && !NILP (font_names))
6842 fontname = (char *) SDATA (XCAR (font_names)); 6803 fontname = (char *) SDATA (XCAR (font_names));
6843 6804
6805 BLOCK_INPUT;
6844 font = (MacFontStruct *) XLoadQueryFont (FRAME_MAC_DISPLAY (f), fontname); 6806 font = (MacFontStruct *) XLoadQueryFont (FRAME_MAC_DISPLAY (f), fontname);
6807 UNBLOCK_INPUT;
6845 if (!font) 6808 if (!font)
6846 return NULL; 6809 return NULL;
6847 6810
@@ -7121,15 +7084,21 @@ do_ae_print_documents (const AppleEvent *, AppleEvent *, long);
7121static pascal OSErr do_ae_open_documents (AppleEvent *, AppleEvent *, long); 7084static pascal OSErr do_ae_open_documents (AppleEvent *, AppleEvent *, long);
7122static pascal OSErr do_ae_quit_application (AppleEvent *, AppleEvent *, long); 7085static pascal OSErr do_ae_quit_application (AppleEvent *, AppleEvent *, long);
7123 7086
7087#if TARGET_API_MAC_CARBON
7124/* Drag and Drop */ 7088/* Drag and Drop */
7125static OSErr init_mac_drag_n_drop (); 7089static OSErr init_mac_drag_n_drop ();
7126static pascal OSErr mac_do_receive_drag (WindowPtr, void*, DragReference); 7090static pascal OSErr mac_do_receive_drag (WindowPtr, void*, DragReference);
7091#endif
7127 7092
7128#if USE_CARBON_EVENTS 7093#if USE_CARBON_EVENTS
7129/* Preliminary Support for the OSX Services Menu */ 7094/* Preliminary Support for the OSX Services Menu */
7130static OSStatus mac_handle_service_event (EventHandlerCallRef,EventRef,void*); 7095static OSStatus mac_handle_service_event (EventHandlerCallRef,EventRef,void*);
7131static void init_service_handler (); 7096static void init_service_handler ();
7097/* Window Event Handler */
7098static pascal OSStatus mac_handle_window_event (EventHandlerCallRef,
7099 EventRef, void *);
7132#endif 7100#endif
7101void install_window_handler (WindowPtr);
7133 7102
7134extern void init_emacs_passwd_dir (); 7103extern void init_emacs_passwd_dir ();
7135extern int emacs_main (int, char **, char **); 7104extern int emacs_main (int, char **, char **);
@@ -7336,12 +7305,11 @@ do_window_update (WindowPtr win)
7336{ 7305{
7337 struct frame *f = mac_window_to_frame (win); 7306 struct frame *f = mac_window_to_frame (win);
7338 7307
7339 if (win == tip_window) 7308 BeginUpdate (win);
7340 /* The tooltip has been drawn already. Avoid the
7341 SET_FRAME_GARBAGED below. */
7342 return;
7343 7309
7344 if (f) 7310 /* The tooltip has been drawn already. Avoid the SET_FRAME_GARBAGED
7311 below. */
7312 if (win != tip_window)
7345 { 7313 {
7346 if (f->async_visible == 0) 7314 if (f->async_visible == 0)
7347 { 7315 {
@@ -7358,17 +7326,30 @@ do_window_update (WindowPtr win)
7358 } 7326 }
7359 else 7327 else
7360 { 7328 {
7361 BeginUpdate (win); 7329 Rect r;
7330
7362 handling_window_update = 1; 7331 handling_window_update = 1;
7363 7332
7364 XClearWindow (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f)); 7333#if TARGET_API_MAC_CARBON
7334 {
7335 RgnHandle region = NewRgn ();
7365 7336
7366 expose_frame (f, 0, 0, 0, 0); 7337 GetPortVisibleRegion (GetWindowPort (win), region);
7338 UpdateControls (win, region);
7339 GetRegionBounds (region, &r);
7340 DisposeRgn (region);
7341 }
7342#else
7343 UpdateControls (win, win->visRgn);
7344 r = (*win->visRgn)->rgnBBox;
7345#endif
7346 expose_frame (f, r.left, r.top, r.right - r.left, r.bottom - r.top);
7367 7347
7368 handling_window_update = 0; 7348 handling_window_update = 0;
7369 EndUpdate (win);
7370 } 7349 }
7371 } 7350 }
7351
7352 EndUpdate (win);
7372} 7353}
7373 7354
7374static int 7355static int
@@ -7530,20 +7511,43 @@ do_menu_choice (SInt32 menu_choice)
7530static void 7511static void
7531do_grow_window (WindowPtr w, EventRecord *e) 7512do_grow_window (WindowPtr w, EventRecord *e)
7532{ 7513{
7533 long grow_size;
7534 Rect limit_rect; 7514 Rect limit_rect;
7535 int rows, columns; 7515 int rows, columns, width, height;
7536 struct frame *f = mac_window_to_frame (w); 7516 struct frame *f = mac_window_to_frame (w);
7517 XSizeHints *size_hints = FRAME_SIZE_HINTS (f);
7518 int min_width = MIN_DOC_SIZE, min_height = MIN_DOC_SIZE;
7519#if TARGET_API_MAC_CARBON
7520 Rect new_rect;
7521#else
7522 long grow_size;
7523#endif
7537 7524
7538 SetRect(&limit_rect, MIN_DOC_SIZE, MIN_DOC_SIZE, MAX_DOC_SIZE, MAX_DOC_SIZE); 7525 if (size_hints->flags & PMinSize)
7526 {
7527 min_width = size_hints->min_width;
7528 min_height = size_hints->min_height;
7529 }
7530 SetRect (&limit_rect, min_width, min_height, MAX_DOC_SIZE, MAX_DOC_SIZE);
7539 7531
7532#if TARGET_API_MAC_CARBON
7533 if (!ResizeWindow (w, e->where, &limit_rect, &new_rect))
7534 return;
7535 height = new_rect.bottom - new_rect.top;
7536 width = new_rect.right - new_rect.left;
7537#else
7540 grow_size = GrowWindow (w, e->where, &limit_rect); 7538 grow_size = GrowWindow (w, e->where, &limit_rect);
7541
7542 /* see if it really changed size */ 7539 /* see if it really changed size */
7543 if (grow_size != 0) 7540 if (grow_size == 0)
7541 return;
7542 height = HiWord (grow_size);
7543 width = LoWord (grow_size);
7544#endif
7545
7546 if (width != FRAME_PIXEL_WIDTH (f)
7547 || height != FRAME_PIXEL_HEIGHT (f))
7544 { 7548 {
7545 rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, HiWord (grow_size)); 7549 rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, height);
7546 columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, LoWord (grow_size)); 7550 columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, width);
7547 7551
7548 x_set_window_size (f, 0, columns, rows); 7552 x_set_window_size (f, 0, columns, rows);
7549 } 7553 }
@@ -7561,7 +7565,7 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
7561 GrafPtr save_port; 7565 GrafPtr save_port;
7562 Rect zoom_rect, port_rect; 7566 Rect zoom_rect, port_rect;
7563 Point top_left; 7567 Point top_left;
7564 int w_title_height, columns, rows; 7568 int w_title_height, columns, rows, width, height;
7565 struct frame *f = mac_window_to_frame (w); 7569 struct frame *f = mac_window_to_frame (w);
7566 7570
7567#if TARGET_API_MAC_CARBON 7571#if TARGET_API_MAC_CARBON
@@ -7636,12 +7640,26 @@ do_zoom_window (WindowPtr w, int zoom_in_or_out)
7636#else 7640#else
7637 port_rect = w->portRect; 7641 port_rect = w->portRect;
7638#endif 7642#endif
7639 rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, port_rect.bottom - port_rect.top); 7643 height = port_rect.bottom - port_rect.top;
7640 columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, port_rect.right - port_rect.left); 7644 width = port_rect.right - port_rect.left;
7641 x_set_window_size (f, 0, columns, rows); 7645
7646 if (width != FRAME_PIXEL_WIDTH (f)
7647 || height != FRAME_PIXEL_HEIGHT (f))
7648 {
7649 rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, height);
7650 columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, width);
7651
7652 change_frame_size (f, rows, columns, 0, 1, 0);
7653 SET_FRAME_GARBAGED (f);
7654 cancel_mouse_face (f);
7655
7656 FRAME_PIXEL_WIDTH (f) = width;
7657 FRAME_PIXEL_HEIGHT (f) = height;
7658 }
7642 x_real_positions (f, &f->left_pos, &f->top_pos); 7659 x_real_positions (f, &f->left_pos, &f->top_pos);
7643} 7660}
7644 7661
7662#if TARGET_API_MAC_CARBON
7645/* Initialize Drag And Drop to allow files to be dropped onto emacs frames */ 7663/* Initialize Drag And Drop to allow files to be dropped onto emacs frames */
7646static OSErr 7664static OSErr
7647init_mac_drag_n_drop () 7665init_mac_drag_n_drop ()
@@ -7649,6 +7667,7 @@ init_mac_drag_n_drop ()
7649 OSErr result = InstallReceiveHandler (mac_do_receive_drag, 0L, NULL); 7667 OSErr result = InstallReceiveHandler (mac_do_receive_drag, 0L, NULL);
7650 return result; 7668 return result;
7651} 7669}
7670#endif
7652 7671
7653/* Intialize AppleEvent dispatcher table for the required events. */ 7672/* Intialize AppleEvent dispatcher table for the required events. */
7654void 7673void
@@ -7819,7 +7838,93 @@ mac_handle_service_event (EventHandlerCallRef callRef,
7819 } 7838 }
7820 return err; 7839 return err;
7821} 7840}
7841
7842
7843static pascal OSStatus
7844mac_handle_window_event (next_handler, event, data)
7845 EventHandlerCallRef next_handler;
7846 EventRef event;
7847 void *data;
7848{
7849 extern Lisp_Object Qcontrol;
7850
7851 WindowPtr wp;
7852 OSStatus result;
7853 UInt32 attributes;
7854 XSizeHints *size_hints;
7855
7856 GetEventParameter (event, kEventParamDirectObject, typeWindowRef,
7857 NULL, sizeof (WindowPtr), NULL, &wp);
7858
7859 switch (GetEventKind (event))
7860 {
7861 case kEventWindowBoundsChanging:
7862 result = CallNextEventHandler (next_handler, event);
7863 if (result != eventNotHandledErr)
7864 return result;
7865
7866 GetEventParameter (event, kEventParamAttributes, typeUInt32,
7867 NULL, sizeof (UInt32), NULL, &attributes);
7868 size_hints = FRAME_SIZE_HINTS (mac_window_to_frame (wp));
7869 if ((attributes & kWindowBoundsChangeUserResize)
7870 && ((size_hints->flags & (PResizeInc | PBaseSize | PMinSize))
7871 == (PResizeInc | PBaseSize | PMinSize)))
7872 {
7873 Rect bounds;
7874 int width, height;
7875
7876 GetEventParameter (event, kEventParamCurrentBounds,
7877 typeQDRectangle,
7878 NULL, sizeof (Rect), NULL, &bounds);
7879 width = bounds.right - bounds.left;
7880 height = bounds.bottom - bounds.top;
7881
7882 if (width < size_hints->min_width)
7883 width = size_hints->min_width;
7884 else
7885 width = size_hints->base_width
7886 + (int) ((width - size_hints->base_width)
7887 / (float) size_hints->width_inc + .5)
7888 * size_hints->width_inc;
7889
7890 if (height < size_hints->min_height)
7891 height = size_hints->min_height;
7892 else
7893 height = size_hints->base_height
7894 + (int) ((height - size_hints->base_height)
7895 / (float) size_hints->height_inc + .5)
7896 * size_hints->height_inc;
7897
7898 bounds.right = bounds.left + width;
7899 bounds.bottom = bounds.top + height;
7900 SetEventParameter (event, kEventParamCurrentBounds,
7901 typeQDRectangle, sizeof (Rect), &bounds);
7902 return noErr;
7903 }
7904 break;
7905 }
7906
7907 return eventNotHandledErr;
7908}
7909#endif /* USE_CARBON_EVENTS */
7910
7911
7912void
7913install_window_handler (window)
7914 WindowPtr window;
7915{
7916#if USE_CARBON_EVENTS
7917 EventTypeSpec specs[] = {{kEventClassWindow, kEventWindowBoundsChanging}};
7918 static EventHandlerUPP handle_window_event_UPP = NULL;
7919
7920 if (handle_window_event_UPP == NULL)
7921 handle_window_event_UPP = NewEventHandlerUPP (mac_handle_window_event);
7922
7923 InstallWindowEventHandler (window, handle_window_event_UPP,
7924 GetEventTypeCount (specs), specs, NULL, NULL);
7822#endif 7925#endif
7926}
7927
7823 7928
7824/* Open Application Apple Event */ 7929/* Open Application Apple Event */
7825static pascal OSErr 7930static pascal OSErr
@@ -7915,6 +8020,7 @@ descriptor_error_exit:
7915} 8020}
7916 8021
7917 8022
8023#if TARGET_API_MAC_CARBON
7918static pascal OSErr 8024static pascal OSErr
7919mac_do_receive_drag (WindowPtr window, void *handlerRefCon, 8025mac_do_receive_drag (WindowPtr window, void *handlerRefCon,
7920 DragReference theDrag) 8026 DragReference theDrag)
@@ -7991,6 +8097,7 @@ mac_do_receive_drag (WindowPtr window, void *handlerRefCon,
7991 } 8097 }
7992 } 8098 }
7993} 8099}
8100#endif
7994 8101
7995 8102
7996/* Print Document Apple Event */ 8103/* Print Document Apple Event */
@@ -8140,6 +8247,45 @@ keycode_to_xkeysym (int keyCode, int *xKeySym)
8140 return *xKeySym != 0; 8247 return *xKeySym != 0;
8141} 8248}
8142 8249
8250#if !USE_CARBON_EVENTS
8251static RgnHandle mouse_region = NULL;
8252
8253Boolean
8254mac_wait_next_event (er, sleep_time, dequeue)
8255 EventRecord *er;
8256 UInt32 sleep_time;
8257 Boolean dequeue;
8258{
8259 static EventRecord er_buf = {nullEvent};
8260 UInt32 target_tick, current_tick;
8261 EventMask event_mask;
8262
8263 if (mouse_region == NULL)
8264 mouse_region = NewRgn ();
8265
8266 event_mask = everyEvent;
8267 if (NILP (Fboundp (Qmac_ready_for_drag_n_drop)))
8268 event_mask -= highLevelEventMask;
8269
8270 current_tick = TickCount ();
8271 target_tick = current_tick + sleep_time;
8272
8273 if (er_buf.what == nullEvent)
8274 while (!WaitNextEvent (event_mask, &er_buf,
8275 target_tick - current_tick, mouse_region))
8276 {
8277 current_tick = TickCount ();
8278 if (target_tick <= current_tick)
8279 return false;
8280 }
8281
8282 *er = er_buf;
8283 if (dequeue)
8284 er_buf.what = nullEvent;
8285 return true;
8286}
8287#endif /* not USE_CARBON_EVENTS */
8288
8143/* Emacs calls this whenever it wants to read an input event from the 8289/* Emacs calls this whenever it wants to read an input event from the
8144 user. */ 8290 user. */
8145int 8291int
@@ -8151,9 +8297,7 @@ XTread_socket (sd, expected, hold_quit)
8151 int count = 0; 8297 int count = 0;
8152#if USE_CARBON_EVENTS 8298#if USE_CARBON_EVENTS
8153 EventRef eventRef; 8299 EventRef eventRef;
8154 EventTargetRef toolbox_dispatcher = GetEventDispatcherTarget (); 8300 EventTargetRef toolbox_dispatcher;
8155#else
8156 EventMask event_mask;
8157#endif 8301#endif
8158 EventRecord er; 8302 EventRecord er;
8159 struct mac_display_info *dpyinfo = &one_mac_display_info; 8303 struct mac_display_info *dpyinfo = &one_mac_display_info;
@@ -8184,16 +8328,14 @@ XTread_socket (sd, expected, hold_quit)
8184 if (terminate_flag) 8328 if (terminate_flag)
8185 Fkill_emacs (make_number (1)); 8329 Fkill_emacs (make_number (1));
8186 8330
8187#if !USE_CARBON_EVENTS 8331#if USE_CARBON_EVENTS
8188 event_mask = everyEvent; 8332 toolbox_dispatcher = GetEventDispatcherTarget ();
8189 if (NILP (Fboundp (Qmac_ready_for_drag_n_drop)))
8190 event_mask -= highLevelEventMask;
8191 8333
8192 while (WaitNextEvent (event_mask, &er, 0L, NULL))
8193#else /* USE_CARBON_EVENTS */
8194 while (!ReceiveNextEvent (0, NULL, kEventDurationNoWait, 8334 while (!ReceiveNextEvent (0, NULL, kEventDurationNoWait,
8195 kEventRemoveFromQueue, &eventRef)) 8335 kEventRemoveFromQueue, &eventRef))
8196#endif /* USE_CARBON_EVENTS */ 8336#else /* !USE_CARBON_EVENTS */
8337 while (mac_wait_next_event (&er, 0, true))
8338#endif /* !USE_CARBON_EVENTS */
8197 { 8339 {
8198 int do_help = 0; 8340 int do_help = 0;
8199 struct frame *f; 8341 struct frame *f;
@@ -8260,6 +8402,7 @@ XTread_socket (sd, expected, hold_quit)
8260 SendEventToEventTarget (eventRef, toolbox_dispatcher); 8402 SendEventToEventTarget (eventRef, toolbox_dispatcher);
8261 8403
8262 break; 8404 break;
8405
8263 default: 8406 default:
8264 /* Send the event to the appropriate receiver. */ 8407 /* Send the event to the appropriate receiver. */
8265 SendEventToEventTarget (eventRef, toolbox_dispatcher); 8408 SendEventToEventTarget (eventRef, toolbox_dispatcher);
@@ -8497,6 +8640,10 @@ XTread_socket (sd, expected, hold_quit)
8497 break; 8640 break;
8498 8641
8499 case mouseMovedMessage: 8642 case mouseMovedMessage:
8643#if !USE_CARBON_EVENTS
8644 SetRectRgn (mouse_region, er.where.h, er.where.v,
8645 er.where.h + 1, er.where.v + 1);
8646#endif
8500 previous_help_echo_string = help_echo_string; 8647 previous_help_echo_string = help_echo_string;
8501 help_echo_string = help_echo_object = help_echo_window = Qnil; 8648 help_echo_string = help_echo_object = help_echo_window = Qnil;
8502 help_echo_pos = -1; 8649 help_echo_pos = -1;
@@ -8697,21 +8844,21 @@ XTread_socket (sd, expected, hold_quit)
8697 unsigned char ch = inev.code; 8844 unsigned char ch = inev.code;
8698 ByteCount actual_input_length, actual_output_length; 8845 ByteCount actual_input_length, actual_output_length;
8699 unsigned char outbuf[32]; 8846 unsigned char outbuf[32];
8700 8847
8701 convert_status = TECConvertText (converter, &ch, 1, 8848 convert_status = TECConvertText (converter, &ch, 1,
8702 &actual_input_length, 8849 &actual_input_length,
8703 outbuf, 1, 8850 outbuf, 1,
8704 &actual_output_length); 8851 &actual_output_length);
8705 if (convert_status == noErr 8852 if (convert_status == noErr
8706 && actual_input_length == 1 8853 && actual_input_length == 1
8707 && actual_output_length == 1) 8854 && actual_output_length == 1)
8708 inev.code = *outbuf; 8855 inev.code = *outbuf;
8709 8856
8710 /* Reset internal states of the converter object. 8857 /* Reset internal states of the converter object.
8711 If it fails, create another one. */ 8858 If it fails, create another one. */
8712 convert_status = TECFlushText (converter, outbuf, 8859 convert_status = TECFlushText (converter, outbuf,
8713 sizeof (outbuf), 8860 sizeof (outbuf),
8714 &actual_output_length); 8861 &actual_output_length);
8715 if (convert_status != noErr) 8862 if (convert_status != noErr)
8716 { 8863 {
8717 TECDisposeConverter (converter); 8864 TECDisposeConverter (converter);
@@ -8719,7 +8866,7 @@ XTread_socket (sd, expected, hold_quit)
8719 kTextEncodingMacRoman, 8866 kTextEncodingMacRoman,
8720 mac_keyboard_text_encoding); 8867 mac_keyboard_text_encoding);
8721 } 8868 }
8722 } 8869 }
8723 } 8870 }
8724 8871
8725#if USE_CARBON_EVENTS 8872#if USE_CARBON_EVENTS
@@ -8864,59 +9011,12 @@ __convert_from_newlines (unsigned char * p, size_t * n)
8864} 9011}
8865#endif 9012#endif
8866 9013
8867 9014#ifdef MAC_OS8
8868/* Initialize the struct pointed to by MW to represent a new COLS x
8869 ROWS Macintosh window, using font with name FONTNAME and size
8870 FONTSIZE. */
8871void
8872make_mac_frame (FRAME_PTR fp)
8873{
8874 mac_output *mwp;
8875#if TARGET_API_MAC_CARBON
8876 static int making_terminal_window = 0;
8877#else
8878 static int making_terminal_window = 1;
8879#endif
8880
8881 mwp = fp->output_data.mac;
8882
8883 BLOCK_INPUT;
8884 if (making_terminal_window)
8885 {
8886 if (!(mwp->mWP = GetNewCWindow (TERM_WINDOW_RESOURCE, NULL,
8887 (WindowPtr) -1)))
8888 abort ();
8889 making_terminal_window = 0;
8890 }
8891 else
8892 {
8893#if TARGET_API_MAC_CARBON
8894 Rect r;
8895
8896 SetRect (&r, 0, 0, 1, 1);
8897 if (CreateNewWindow (kDocumentWindowClass,
8898 kWindowStandardDocumentAttributes
8899 /* | kWindowToolbarButtonAttribute */,
8900 &r, &mwp->mWP) != noErr)
8901#else
8902 if (!(mwp->mWP = GetNewCWindow (WINDOW_RESOURCE, NULL, (WindowPtr) -1)))
8903#endif
8904 abort ();
8905 }
8906
8907 SetWRefCon (mwp->mWP, (long) mwp);
8908 /* so that update events can find this mac_output struct */
8909 mwp->mFP = fp; /* point back to emacs frame */
8910
8911 SizeWindow (mwp->mWP, FRAME_PIXEL_WIDTH (fp), FRAME_PIXEL_HEIGHT (fp), false);
8912 UNBLOCK_INPUT;
8913}
8914
8915
8916void 9015void
8917make_mac_terminal_frame (struct frame *f) 9016make_mac_terminal_frame (struct frame *f)
8918{ 9017{
8919 Lisp_Object frame; 9018 Lisp_Object frame;
9019 Rect r;
8920 9020
8921 XSETFRAME (frame, f); 9021 XSETFRAME (frame, f);
8922 9022
@@ -8940,10 +9040,17 @@ make_mac_terminal_frame (struct frame *f)
8940 f->output_data.mac->mouse_pixel = 0xff00ff; 9040 f->output_data.mac->mouse_pixel = 0xff00ff;
8941 f->output_data.mac->cursor_foreground_pixel = 0x0000ff; 9041 f->output_data.mac->cursor_foreground_pixel = 0x0000ff;
8942 9042
9043 f->output_data.mac->text_cursor = GetCursor (iBeamCursor);
9044 f->output_data.mac->nontext_cursor = &arrow_cursor;
9045 f->output_data.mac->modeline_cursor = &arrow_cursor;
9046 f->output_data.mac->hand_cursor = &arrow_cursor;
9047 f->output_data.mac->hourglass_cursor = GetCursor (watchCursor);
9048 f->output_data.mac->horizontal_drag_cursor = &arrow_cursor;
9049
8943 FRAME_FONTSET (f) = -1; 9050 FRAME_FONTSET (f) = -1;
8944 f->output_data.mac->explicit_parent = 0; 9051 f->output_data.mac->explicit_parent = 0;
8945 f->left_pos = 4; 9052 f->left_pos = 8;
8946 f->top_pos = 4; 9053 f->top_pos = 32;
8947 f->border_width = 0; 9054 f->border_width = 0;
8948 9055
8949 f->internal_border_width = 0; 9056 f->internal_border_width = 0;
@@ -8954,7 +9061,20 @@ make_mac_terminal_frame (struct frame *f)
8954 f->new_text_cols = 0; 9061 f->new_text_cols = 0;
8955 f->new_text_lines = 0; 9062 f->new_text_lines = 0;
8956 9063
8957 make_mac_frame (f); 9064 SetRect (&r, f->left_pos, f->top_pos,
9065 f->left_pos + FRAME_PIXEL_WIDTH (f),
9066 f->top_pos + FRAME_PIXEL_HEIGHT (f));
9067
9068 BLOCK_INPUT;
9069
9070 if (!(FRAME_MAC_WINDOW (f) =
9071 NewCWindow (NULL, &r, "\p", true, dBoxProc,
9072 (WindowPtr) -1, 1, (long) f->output_data.mac)))
9073 abort ();
9074 /* so that update events can find this mac_output struct */
9075 f->output_data.mac->mFP = f; /* point back to emacs frame */
9076
9077 UNBLOCK_INPUT;
8958 9078
8959 x_make_gc (f); 9079 x_make_gc (f);
8960 9080
@@ -8970,9 +9090,8 @@ make_mac_terminal_frame (struct frame *f)
8970 Fmodify_frame_parameters (frame, 9090 Fmodify_frame_parameters (frame,
8971 Fcons (Fcons (Qbackground_color, 9091 Fcons (Fcons (Qbackground_color,
8972 build_string ("white")), Qnil)); 9092 build_string ("white")), Qnil));
8973
8974 ShowWindow (f->output_data.mac->mWP);
8975} 9093}
9094#endif
8976 9095
8977 9096
8978/*********************************************************************** 9097/***********************************************************************
@@ -8989,12 +9108,7 @@ mac_initialize_display_info ()
8989 9108
8990 bzero (dpyinfo, sizeof (*dpyinfo)); 9109 bzero (dpyinfo, sizeof (*dpyinfo));
8991 9110
8992 /* Put it on x_display_name_list. */ 9111#ifdef MAC_OSX
8993 x_display_name_list = Fcons (Fcons (build_string ("Mac"), Qnil),
8994 x_display_name_list);
8995 dpyinfo->name_list_element = XCAR (x_display_name_list);
8996
8997#if 0
8998 dpyinfo->mac_id_name 9112 dpyinfo->mac_id_name
8999 = (char *) xmalloc (SCHARS (Vinvocation_name) 9113 = (char *) xmalloc (SCHARS (Vinvocation_name)
9000 + SCHARS (Vsystem_name) 9114 + SCHARS (Vsystem_name)
@@ -9049,6 +9163,61 @@ mac_initialize_display_info ()
9049 dpyinfo->mouse_face_hidden = 0; 9163 dpyinfo->mouse_face_hidden = 0;
9050} 9164}
9051 9165
9166/* Create an xrdb-style database of resources to supercede registry settings.
9167 The database is just a concatenation of C strings, finished by an additional
9168 \0. The string are submitted to some basic normalization, so
9169
9170 [ *]option[ *]:[ *]value...
9171
9172 becomes
9173
9174 option:value...
9175
9176 but any whitespace following value is not removed. */
9177
9178static char *
9179mac_make_rdb (xrm_option)
9180 char *xrm_option;
9181{
9182 char *buffer = xmalloc (strlen (xrm_option) + 2);
9183 char *current = buffer;
9184 char ch;
9185 int in_option = 1;
9186 int before_value = 0;
9187
9188 do {
9189 ch = *xrm_option++;
9190
9191 if (ch == '\n')
9192 {
9193 *current++ = '\0';
9194 in_option = 1;
9195 before_value = 0;
9196 }
9197 else if (ch != ' ')
9198 {
9199 *current++ = ch;
9200 if (in_option && (ch == ':'))
9201 {
9202 in_option = 0;
9203 before_value = 1;
9204 }
9205 else if (before_value)
9206 {
9207 before_value = 0;
9208 }
9209 }
9210 else if (!(in_option || before_value))
9211 {
9212 *current++ = ch;
9213 }
9214 } while (ch);
9215
9216 *current = '\0';
9217
9218 return buffer;
9219}
9220
9052struct mac_display_info * 9221struct mac_display_info *
9053mac_term_init (display_name, xrm_option, resource_name) 9222mac_term_init (display_name, xrm_option, resource_name)
9054 Lisp_Object display_name; 9223 Lisp_Object display_name;
@@ -9056,7 +9225,8 @@ mac_term_init (display_name, xrm_option, resource_name)
9056 char *resource_name; 9225 char *resource_name;
9057{ 9226{
9058 struct mac_display_info *dpyinfo; 9227 struct mac_display_info *dpyinfo;
9059 GDHandle main_device_handle; 9228
9229 BLOCK_INPUT;
9060 9230
9061 if (!mac_initialized) 9231 if (!mac_initialized)
9062 { 9232 {
@@ -9064,17 +9234,90 @@ mac_term_init (display_name, xrm_option, resource_name)
9064 mac_initialized = 1; 9234 mac_initialized = 1;
9065 } 9235 }
9066 9236
9067 mac_initialize_display_info (display_name); 9237 if (x_display_list)
9238 error ("Sorry, this version can only handle one display");
9239
9240 mac_initialize_display_info ();
9068 9241
9069 dpyinfo = &one_mac_display_info; 9242 dpyinfo = &one_mac_display_info;
9070 9243
9071 main_device_handle = LMGetMainDevice(); 9244 dpyinfo->xrdb = xrm_option ? mac_make_rdb (xrm_option) : NULL;
9072 9245
9073 dpyinfo->height = (**main_device_handle).gdRect.bottom; 9246 /* Put this display on the chain. */
9074 dpyinfo->width = (**main_device_handle).gdRect.right; 9247 dpyinfo->next = x_display_list;
9248 x_display_list = dpyinfo;
9249
9250 /* Put it on x_display_name_list. */
9251 x_display_name_list = Fcons (Fcons (display_name, Qnil),
9252 x_display_name_list);
9253 dpyinfo->name_list_element = XCAR (x_display_name_list);
9254
9255 UNBLOCK_INPUT;
9075 9256
9076 return dpyinfo; 9257 return dpyinfo;
9077} 9258}
9259/* Get rid of display DPYINFO, assuming all frames are already gone. */
9260
9261void
9262x_delete_display (dpyinfo)
9263 struct mac_display_info *dpyinfo;
9264{
9265 int i;
9266
9267 /* Discard this display from x_display_name_list and x_display_list.
9268 We can't use Fdelq because that can quit. */
9269 if (! NILP (x_display_name_list)
9270 && EQ (XCAR (x_display_name_list), dpyinfo->name_list_element))
9271 x_display_name_list = XCDR (x_display_name_list);
9272 else
9273 {
9274 Lisp_Object tail;
9275
9276 tail = x_display_name_list;
9277 while (CONSP (tail) && CONSP (XCDR (tail)))
9278 {
9279 if (EQ (XCAR (XCDR (tail)), dpyinfo->name_list_element))
9280 {
9281 XSETCDR (tail, XCDR (XCDR (tail)));
9282 break;
9283 }
9284 tail = XCDR (tail);
9285 }
9286 }
9287
9288 if (x_display_list == dpyinfo)
9289 x_display_list = dpyinfo->next;
9290 else
9291 {
9292 struct x_display_info *tail;
9293
9294 for (tail = x_display_list; tail; tail = tail->next)
9295 if (tail->next == dpyinfo)
9296 tail->next = tail->next->next;
9297 }
9298
9299 /* Free the font names in the font table. */
9300 for (i = 0; i < dpyinfo->n_fonts; i++)
9301 if (dpyinfo->font_table[i].name)
9302 {
9303 if (dpyinfo->font_table[i].name != dpyinfo->font_table[i].full_name)
9304 xfree (dpyinfo->font_table[i].full_name);
9305 xfree (dpyinfo->font_table[i].name);
9306 }
9307
9308 if (dpyinfo->font_table->font_encoder)
9309 xfree (dpyinfo->font_table->font_encoder);
9310
9311 xfree (dpyinfo->font_table);
9312 xfree (dpyinfo->mac_id_name);
9313
9314 if (x_display_list == 0)
9315 {
9316 mac_clear_font_name_table ();
9317 bzero (dpyinfo, sizeof (*dpyinfo));
9318 }
9319}
9320
9078 9321
9079#ifdef MAC_OSX 9322#ifdef MAC_OSX
9080void 9323void
@@ -9333,7 +9576,6 @@ mac_initialize ()
9333#endif 9576#endif
9334 9577
9335 BLOCK_INPUT; 9578 BLOCK_INPUT;
9336 mac_initialize_display_info ();
9337 9579
9338#if TARGET_API_MAC_CARBON 9580#if TARGET_API_MAC_CARBON
9339 init_required_apple_events (); 9581 init_required_apple_events ();
@@ -9371,7 +9613,9 @@ syms_of_macterm ()
9371 Qsuper = intern ("super"); 9613 Qsuper = intern ("super");
9372 Fput (Qsuper, Qmodifier_value, make_number (super_modifier)); 9614 Fput (Qsuper, Qmodifier_value, make_number (super_modifier));
9373 9615
9616#ifdef MAC_OSX
9374 Fprovide (intern ("mac-carbon"), Qnil); 9617 Fprovide (intern ("mac-carbon"), Qnil);
9618#endif
9375 9619
9376 staticpro (&Qreverse); 9620 staticpro (&Qreverse);
9377 Qreverse = intern ("reverse"); 9621 Qreverse = intern ("reverse");
diff --git a/src/macterm.h b/src/macterm.h
index ff7110828b1..fd6b066af4c 100644
--- a/src/macterm.h
+++ b/src/macterm.h
@@ -218,6 +218,9 @@ struct mac_display_info
218 struct image_cache *image_cache; 218 struct image_cache *image_cache;
219}; 219};
220 220
221/* This checks to make sure we have a display. */
222extern void check_mac P_ ((void));
223
221#define x_display_info mac_display_info 224#define x_display_info mac_display_info
222 225
223/* This is a chain of structures for all the X displays currently in use. */ 226/* This is a chain of structures for all the X displays currently in use. */
@@ -388,6 +391,9 @@ struct mac_output {
388 /* The background for which the above relief GCs were set up. 391 /* The background for which the above relief GCs were set up.
389 They are changed only when a different background is involved. */ 392 They are changed only when a different background is involved. */
390 unsigned long relief_background; 393 unsigned long relief_background;
394
395 /* Hints for the size and the position of a window. */
396 XSizeHints *size_hints;
391}; 397};
392 398
393typedef struct mac_output mac_output; 399typedef struct mac_output mac_output;
@@ -407,6 +413,8 @@ typedef struct mac_output mac_output;
407 413
408#define FRAME_BASELINE_OFFSET(f) ((f)->output_data.mac->baseline_offset) 414#define FRAME_BASELINE_OFFSET(f) ((f)->output_data.mac->baseline_offset)
409 415
416#define FRAME_SIZE_HINTS(f) ((f)->output_data.mac->size_hints)
417
410/* This gives the w32_display_info structure for the display F is on. */ 418/* This gives the w32_display_info structure for the display F is on. */
411#define FRAME_MAC_DISPLAY_INFO(f) (&one_mac_display_info) 419#define FRAME_MAC_DISPLAY_INFO(f) (&one_mac_display_info)
412#define FRAME_X_DISPLAY_INFO(f) (&one_mac_display_info) 420#define FRAME_X_DISPLAY_INFO(f) (&one_mac_display_info)
@@ -596,6 +604,7 @@ extern void XFreePixmap P_ ((Display *, Pixmap));
596extern void XSetForeground P_ ((Display *, GC, unsigned long)); 604extern void XSetForeground P_ ((Display *, GC, unsigned long));
597extern void mac_draw_line_to_pixmap P_ ((Display *, Pixmap, GC, int, int, 605extern void mac_draw_line_to_pixmap P_ ((Display *, Pixmap, GC, int, int,
598 int, int)); 606 int, int));
607extern void mac_unload_font P_ ((struct mac_display_info *, XFontStruct *));
599 608
600#define FONT_TYPE_FOR_UNIBYTE(font, ch) 0 609#define FONT_TYPE_FOR_UNIBYTE(font, ch) 0
601#define FONT_TYPE_FOR_MULTIBYTE(font, ch) 0 610#define FONT_TYPE_FOR_MULTIBYTE(font, ch) 0
diff --git a/src/xdisp.c b/src/xdisp.c
index 8ed0adfc89e..d485dc59b57 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -21908,20 +21908,6 @@ expose_window (w, fr)
21908 } 21908 }
21909 } 21909 }
21910 21910
21911#ifdef HAVE_CARBON
21912 /* Display scroll bar for this window. */
21913 if (!NILP (w->vertical_scroll_bar))
21914 {
21915 /* ++KFS:
21916 If this doesn't work here (maybe some header files are missing),
21917 make a function in macterm.c and call it to do the job! */
21918 ControlHandle ch
21919 = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (w->vertical_scroll_bar));
21920
21921 Draw1Control (ch);
21922 }
21923#endif
21924
21925 return mouse_face_overwritten_p; 21911 return mouse_face_overwritten_p;
21926} 21912}
21927 21913
@@ -21980,16 +21966,6 @@ expose_frame (f, x, y, w, h)
21980 return; 21966 return;
21981 } 21967 }
21982 21968
21983#ifdef HAVE_CARBON
21984 /* MAC_TODO: this is a kludge, but if scroll bars are not activated
21985 or deactivated here, for unknown reasons, activated scroll bars
21986 are shown in deactivated frames in some instances. */
21987 if (f == FRAME_MAC_DISPLAY_INFO (f)->x_focus_frame)
21988 activate_scroll_bars (f);
21989 else
21990 deactivate_scroll_bars (f);
21991#endif
21992
21993 /* If basic faces haven't been realized yet, there is no point in 21969 /* If basic faces haven't been realized yet, there is no point in
21994 trying to redraw anything. This can happen when we get an expose 21970 trying to redraw anything. This can happen when we get an expose
21995 event while Emacs is starting, e.g. by moving another window. */ 21971 event while Emacs is starting, e.g. by moving another window. */
diff --git a/src/xfaces.c b/src/xfaces.c
index 590e9885622..b980467882c 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -1072,6 +1072,9 @@ clear_font_table (dpyinfo)
1072#ifdef WINDOWSNT 1072#ifdef WINDOWSNT
1073 w32_unload_font (dpyinfo, font_info->font); 1073 w32_unload_font (dpyinfo, font_info->font);
1074#endif 1074#endif
1075#ifdef MAC_OS
1076 mac_unload_font (dpyinfo, font_info->font);
1077#endif
1075 UNBLOCK_INPUT; 1078 UNBLOCK_INPUT;
1076 1079
1077 /* Mark font table slot free. */ 1080 /* Mark font table slot free. */