Mercurial > emacs
diff src/macfns.c @ 59146:9bde7721ad0f
* 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.
| author | Steven Tamm <steventamm@mac.com> |
|---|---|
| date | Mon, 27 Dec 2004 17:27:30 +0000 |
| parents | 4ad0594e1ac4 |
| children | 60ffced08532 |
line wrap: on
line diff
--- a/src/macfns.c Mon Dec 27 17:23:53 2004 +0000 +++ b/src/macfns.c Mon Dec 27 17:27:30 2004 +0000 @@ -158,9 +158,7 @@ extern Lisp_Object Vwindow_system_version; -extern int mac_initialized; - - +#if 0 /* Use xstricmp instead. */ /* compare two strings ignoring case */ static int @@ -171,13 +169,14 @@ return 0; return tolower (*s) - tolower (*t); } +#endif /* compare two strings up to n characters, ignoring case */ static int strnicmp (const char *s, const char *t, unsigned int n) { - for ( ; n-- > 0 && tolower (*s) == tolower (*t); s++, t++) + for ( ; n > 0 && tolower (*s) == tolower (*t); n--, s++, t++) if (*s == '\0') return 0; return n == 0 ? 0 : tolower (*s) - tolower (*t); @@ -190,7 +189,7 @@ check_mac () { if (! mac_in_use) - error ("Mac OS not in use or not initialized"); + error ("Mac native windows not in use or not initialized"); } /* Nonzero if we can use mouse menus. @@ -228,33 +227,28 @@ check_x_display_info (frame) Lisp_Object frame; { - if (!mac_initialized) - { - mac_initialize (); - mac_initialized = 1; - } + struct mac_display_info *dpyinfo = NULL; if (NILP (frame)) { struct frame *sf = XFRAME (selected_frame); if (FRAME_MAC_P (sf) && FRAME_LIVE_P (sf)) - return FRAME_MAC_DISPLAY_INFO (sf); + dpyinfo = FRAME_MAC_DISPLAY_INFO (sf); + else if (x_display_list != 0) + dpyinfo = x_display_list; else - return &one_mac_display_info; + error ("Mac native windows are not in use or not initialized"); } else if (STRINGP (frame)) - return x_display_info_for_name (frame); + dpyinfo = x_display_info_for_name (frame); else { - FRAME_PTR f; - - CHECK_LIVE_FRAME (frame); - f = XFRAME (frame); - if (! FRAME_MAC_P (f)) - error ("non-mac frame used"); - return FRAME_MAC_DISPLAY_INFO (f); + FRAME_PTR f = check_x_frame (frame); + dpyinfo = FRAME_MAC_DISPLAY_INFO (f); } + + return dpyinfo; } /* Return the Emacs frame-object corresponding to a mac window. @@ -1109,7 +1103,7 @@ BLOCK_INPUT; for (i = 0; i < sizeof (mac_color_map) / sizeof (mac_color_map[0]); i++) - if (stricmp (colorname, mac_color_map[i].name) == 0) + if (xstricmp (colorname, mac_color_map[i].name) == 0) { ret = make_number (mac_color_map[i].color); break; @@ -2059,13 +2053,49 @@ /* Subroutines of creating a frame. */ +static char * +mac_get_rdb_resource (rdb, resource) + char *rdb; + char *resource; +{ + char *value = rdb; + int len = strlen (resource); + + while (*value) + { + if ((strncmp (value, resource, len) == 0) && (value[len] == ':')) + return xstrdup (&value[len + 1]); + + value = strchr (value, '\0') + 1; + } + + return NULL; +} + +/* Retrieve the string resource specified by NAME with CLASS from + database RDB. */ + char * x_get_string_resource (rdb, name, class) XrmDatabase rdb; char *name, *class; { - /* MAC_TODO: implement resource strings */ + if (rdb) + { + char *resource; + + if (resource = mac_get_rdb_resource (rdb, name)) + return resource; + if (resource = mac_get_rdb_resource (rdb, class)) + return resource; + } + + /* MAC_TODO: implement resource strings. (Maybe Property Lists?) */ +#if 0 + return mac_get_string_resource (name, class); +#else return (char *)0; +#endif } /* Return the value of parameter PARAM. @@ -2229,36 +2259,38 @@ } -#if 0 /* MAC_TODO */ /* Create and set up the Mac window for frame F. */ +extern install_window_handler (WindowPtr); + static void -mac_window (f, window_prompting, minibuffer_only) +mac_window (f) struct frame *f; - long window_prompting; - int minibuffer_only; { Rect r; BLOCK_INPUT; - /* Use the resource name as the top-level window name - for looking up resources. Make a non-Lisp copy - for the window manager, so GC relocation won't bother it. - - Elsewhere we specify the window name for the window manager. */ - - { - char *str = (char *) SDATA (Vx_resource_name); - f->namebuf = (char *) xmalloc (strlen (str) + 1); - strcpy (f->namebuf, str); - } - SetRect (&r, f->left_pos, f->top_pos, f->left_pos + FRAME_PIXEL_WIDTH (f), f->top_pos + FRAME_PIXEL_HEIGHT (f)); +#if TARGET_API_MAC_CARBON + CreateNewWindow (kDocumentWindowClass, + kWindowStandardDocumentAttributes + /* | kWindowToolbarButtonAttribute */, + &r, &FRAME_MAC_WINDOW (f)); + if (FRAME_MAC_WINDOW (f)) + { + SetWRefCon (FRAME_MAC_WINDOW (f), (long) f->output_data.mac); + install_window_handler (FRAME_MAC_WINDOW (f)); + } +#else FRAME_MAC_WINDOW (f) - = NewCWindow (NULL, &r, "\p", 1, zoomDocProc, (WindowPtr) -1, 1, (long) f->output_data.mac); + = NewCWindow (NULL, &r, "\p", false, zoomDocProc, + (WindowPtr) -1, 1, (long) f->output_data.mac); +#endif + /* so that update events can find this mac_output struct */ + f->output_data.mac->mFP = f; /* point back to emacs frame */ validate_x_resource_name (); @@ -2276,17 +2308,11 @@ x_set_name (f, name, explicit); } - ShowWindow (FRAME_MAC_WINDOW (f)); - UNBLOCK_INPUT; - if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f)) - initialize_frame_menubar (f); - if (FRAME_MAC_WINDOW (f) == 0) error ("Unable to create window"); } -#endif /* MAC_TODO */ /* Handle the icon stuff for this window. Perhaps later we might want an x_set_icon_position which can be called interactively as @@ -2703,6 +2729,8 @@ "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL); x_default_parameter (f, parms, Qtitle, Qnil, "title", "Title", RES_TYPE_STRING); + x_default_parameter (f, parms, Qfullscreen, Qnil, + "fullscreen", "Fullscreen", RES_TYPE_SYMBOL); f->output_data.mac->parent_desc = FRAME_MAC_DISPLAY_INFO (f)->root_window; @@ -2728,8 +2756,7 @@ tem = mac_get_arg (parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN); f->no_split = minibuffer_only || EQ (tem, Qt); - /* mac_window (f, window_prompting, minibuffer_only); */ - make_mac_frame (f); + mac_window (f); x_icon (f, parms); x_make_gc (f); @@ -2763,14 +2790,12 @@ FRAME_LINES (f) = 0; change_frame_size (f, height, width, 1, 0, 0); -#if 0 /* MAC_TODO: when we have window manager hints */ /* Tell the server what size and position, etc, we want, and how badly we want them. This should be done after we have the menu bar so that its size can be taken into account. */ BLOCK_INPUT; x_wm_set_size_hint (f, window_prompting, 0); UNBLOCK_INPUT; -#endif /* Make the window appear on the frame and enable display, unless the caller says not to. However, with explicit parent, Emacs @@ -3144,6 +3169,9 @@ CHECK_STRING (name); + if (! EQ (Vwindow_system, intern ("mac"))) + error ("Not using Mac native windows"); + for (dpyinfo = &one_mac_display_info, names = x_display_name_list; dpyinfo; dpyinfo = dpyinfo->next, names = XCDR (names)) @@ -3171,7 +3199,6 @@ return dpyinfo; } -#if 0 /* MAC_TODO: implement network support */ DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection, 1, 3, 0, doc: /* Open a connection to a server. @@ -3190,7 +3217,7 @@ CHECK_STRING (xrm_string); if (! EQ (Vwindow_system, intern ("mac"))) - error ("Not using Mac OS"); + error ("Not using Mac native windows"); if (! NILP (xrm_string)) xrm_option = (unsigned char *) SDATA (xrm_string); @@ -3238,11 +3265,9 @@ for (i = 0; i < dpyinfo->n_fonts; i++) if (dpyinfo->font_table[i].name) { - if (dpyinfo->font_table[i].name != dpyinfo->font_table[i].full_name) - xfree (dpyinfo->font_table[i].full_name); - xfree (dpyinfo->font_table[i].name); - x_unload_font (dpyinfo, dpyinfo->font_table[i].font); + mac_unload_font (dpyinfo, dpyinfo->font_table[i].font); } + x_destroy_all_bitmaps (dpyinfo); x_delete_display (dpyinfo); @@ -3250,7 +3275,6 @@ return Qnil; } -#endif /* 0 */ DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0, doc: /* Return the list of display names that Emacs has connections to. */) @@ -3813,18 +3837,23 @@ BLOCK_INPUT; SetRect (&r, 0, 0, 1, 1); +#if TARGET_API_MAC_CARBON if (CreateNewWindow (kHelpWindowClass, #ifdef MAC_OS_X_VERSION_10_2 kWindowIgnoreClicksAttribute | #endif + kWindowNoUpdatesAttribute | kWindowNoActivatesAttribute, &r, &tip_window) == noErr) +#else + if (tip_window = NewCWindow (NULL, &r, "\p", false, plainDBox, + NULL, false, 0L)) +#endif { FRAME_MAC_WINDOW (f) = tip_window; SetWRefCon (tip_window, (long) f->output_data.mac); /* so that update events can find this mac_output struct */ f->output_data.mac->mFP = f; - ShowWindow (tip_window); } UNBLOCK_INPUT; } @@ -4140,6 +4169,7 @@ BLOCK_INPUT; MoveWindow (FRAME_MAC_WINDOW (f), root_x, root_y, false); SizeWindow (FRAME_MAC_WINDOW (f), width, height, true); + ShowWindow (FRAME_MAC_WINDOW (f)); BringToFront (FRAME_MAC_WINDOW (f)); UNBLOCK_INPUT; @@ -4198,7 +4228,7 @@ -#ifdef TARGET_API_MAC_CARBON +#if TARGET_API_MAC_CARBON /*********************************************************************** File selection dialog ***********************************************************************/ @@ -4405,14 +4435,19 @@ x_set_fringe_width, x_set_fringe_width, 0, /* x_set_wait_for_wm, */ - 0, /* MAC_TODO: x_set_fullscreen, */ + x_set_fullscreen, }; void syms_of_macfns () { - /* Certainly running on Mac. */ +#ifdef MAC_OSX + /* This is zero if not using Mac native windows. */ + mac_in_use = 0; +#else + /* Certainly running on Mac native windows. */ mac_in_use = 1; +#endif /* The section below is built by the lisp expression at the top of the file, just above where these variables are declared. */ @@ -4536,10 +4571,8 @@ defsubr (&Sx_display_backing_store); defsubr (&Sx_display_save_under); defsubr (&Sx_create_frame); -#if 0 /* MAC_TODO: implement network support */ defsubr (&Sx_open_connection); defsubr (&Sx_close_connection); -#endif defsubr (&Sx_display_list); defsubr (&Sx_synchronize);
