X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/052c4ff370464bf164912207381857e8182cc87a..6704fec12c803525a5c0b89feeaa80d82db9765c:/src/macfns.c diff --git a/src/macfns.c b/src/macfns.c index 617167dfc4..494d6ec1da 100644 --- a/src/macfns.c +++ b/src/macfns.c @@ -210,15 +210,6 @@ void x_explicitly_set_name P_ ((struct frame *, Lisp_Object, Lisp_Object)); void x_set_menu_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object)); void x_set_title P_ ((struct frame *, Lisp_Object, Lisp_Object)); void x_set_tool_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object)); -void x_set_scroll_bar_foreground P_ ((struct frame *, Lisp_Object, - Lisp_Object)); -void x_set_scroll_bar_background P_ ((struct frame *, Lisp_Object, - Lisp_Object)); -static Lisp_Object x_default_scroll_bar_color_parameter P_ ((struct frame *, - Lisp_Object, - Lisp_Object, - char *, char *, - int)); extern void mac_get_window_bounds P_ ((struct frame *, Rect *, Rect *)); @@ -1033,7 +1024,7 @@ Lisp_Object x_to_mac_color (colorname) char * colorname; { - register Lisp_Object tail, ret = Qnil; + register Lisp_Object ret = Qnil; BLOCK_INPUT; @@ -1100,7 +1091,7 @@ x_to_mac_color (colorname) char *color; unsigned long colorval; int i, pos; - pos = 0; + pos = 16; colorval = 0; color = colorname + 4; @@ -1136,7 +1127,7 @@ x_to_mac_color (colorname) if (value == ULONG_MAX) break; colorval |= (value << pos); - pos += 0x8; + pos -= 0x8; if (i == 2) { if (*end != '\0') @@ -1155,7 +1146,7 @@ x_to_mac_color (colorname) char *color; unsigned long colorval; int i, pos; - pos = 0; + pos = 16; colorval = 0; color = colorname + 5; @@ -1177,7 +1168,7 @@ x_to_mac_color (colorname) if (val == 0x100) val = 0xFF; colorval |= (val << pos); - pos += 0x8; + pos -= 0x8; if (i == 2) { if (*end != '\0') @@ -1368,7 +1359,6 @@ x_set_mouse_color (f, arg, oldval) Lisp_Object arg, oldval; { struct x_output *x = f->output_data.x; - Display *dpy = FRAME_MAC_DISPLAY (f); Cursor cursor, nontext_cursor, mode_cursor, hand_cursor; Cursor hourglass_cursor, horizontal_drag_cursor; unsigned long pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); @@ -1602,7 +1592,7 @@ x_set_icon_name (f, arg, oldval) if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt)) return; } - else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil)) + else if (!NILP (arg) || NILP (oldval)) return; f->icon_name = arg; @@ -1897,7 +1887,7 @@ x_set_scroll_bar_default_width (f) int wid = FRAME_COLUMN_WIDTH (f); #ifdef MAC_OSX - FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = 16; /* Aqua scroll bars. */ + FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = MAC_AQUA_VERTICAL_SCROLL_BAR_WIDTH; FRAME_CONFIG_SCROLL_BAR_COLS (f) = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) + wid - 1) / wid; #else /* not MAC_OSX */ @@ -1911,6 +1901,139 @@ x_set_scroll_bar_default_width (f) #endif /* not MAC_OSX */ } +void +mac_set_scroll_bar_width (f, arg, oldval) + struct frame *f; + Lisp_Object arg, oldval; +{ +#ifdef MAC_OSX + if (INTEGERP (arg) && XINT (arg) > 0) + { + if (XINT (arg) < (MAC_AQUA_SMALL_VERTICAL_SCROLL_BAR_WIDTH + + MAC_AQUA_VERTICAL_SCROLL_BAR_WIDTH) / 2) + XSETINT (arg, MAC_AQUA_SMALL_VERTICAL_SCROLL_BAR_WIDTH); + else + XSETINT (arg, MAC_AQUA_VERTICAL_SCROLL_BAR_WIDTH); + } +#endif + x_set_scroll_bar_width (f, arg, oldval); +} + +static void +mac_set_font (f, arg, oldval) + struct frame *f; + Lisp_Object arg, oldval; +{ + x_set_font (f, arg, oldval); +#if USE_MAC_FONT_PANEL + { + Lisp_Object focus_frame = x_get_focus_frame (f); + + if ((NILP (focus_frame) && f == SELECTED_FRAME ()) + || XFRAME (focus_frame) == f) + { + BLOCK_INPUT; + mac_set_font_info_for_selection (f, DEFAULT_FACE_ID, 0); + UNBLOCK_INPUT; + } + } +#endif +} + +#if TARGET_API_MAC_CARBON +static void +mac_update_proxy_icon (f) + struct frame *f; +{ + Lisp_Object file_name = + XBUFFER (XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer)->filename; + Window w = FRAME_MAC_WINDOW (f); + + if (FRAME_FILE_NAME (f) == NULL && !STRINGP (file_name)) + return; + if (FRAME_FILE_NAME (f) && STRINGP (file_name) + && strcmp (FRAME_FILE_NAME (f), SDATA (file_name)) == 0) + return; + + if (FRAME_FILE_NAME (f)) + { + xfree (FRAME_FILE_NAME (f)); + FRAME_FILE_NAME (f) = NULL; + } + + BLOCK_INPUT; + + if (STRINGP (file_name)) + { + OSStatus err; + AEDesc desc; + Lisp_Object encoded_file_name = ENCODE_FILE (file_name); + +#ifdef MAC_OS8 + SetPortWindowPort (w); +#endif + err = AECoercePtr (TYPE_FILE_NAME, SDATA (encoded_file_name), + SBYTES (encoded_file_name), typeAlias, &desc); + if (err == noErr) + { + Size size = AEGetDescDataSize (&desc); + AliasHandle alias = (AliasHandle) NewHandle (size); + + if (alias == NULL) + err = memFullErr; + else + { + HLock ((Handle) alias); + err = AEGetDescData (&desc, *alias, size); + HUnlock ((Handle) alias); + if (err == noErr) + err = SetWindowProxyAlias (w, alias); + DisposeHandle ((Handle) alias); + } + AEDisposeDesc (&desc); + } + if (err == noErr) + { + FRAME_FILE_NAME (f) = xmalloc (SBYTES (file_name) + 1); + strcpy (FRAME_FILE_NAME (f), SDATA (file_name)); + } + } + + if (FRAME_FILE_NAME (f) == NULL) + RemoveWindowProxy (w); + + UNBLOCK_INPUT; +} +#endif + +void +mac_update_title_bar (f, save_match_data) + struct frame *f; + int save_match_data; +{ +#if TARGET_API_MAC_CARBON + struct window *w; + int modified_p; + + if (!FRAME_MAC_P (f)) + return; + + w = XWINDOW (FRAME_SELECTED_WINDOW (f)); + modified_p = (BUF_SAVE_MODIFF (XBUFFER (w->buffer)) + < BUF_MODIFF (XBUFFER (w->buffer))); + if (windows_or_buffers_changed + /* Minibuffer modification status shown in the close button is + confusing. */ + || (!MINI_WINDOW_P (w) + && (modified_p != !NILP (w->last_had_star)))) + SetWindowModified (FRAME_MAC_WINDOW (f), + !MINI_WINDOW_P (w) && modified_p); + + if (windows_or_buffers_changed) + mac_update_proxy_icon (f); +#endif +} + /* Subroutines of creating a frame. */ @@ -2111,8 +2234,10 @@ mac_window (f) #if TARGET_API_MAC_CARBON CreateNewWindow (kDocumentWindowClass, kWindowStandardDocumentAttributes - /* | kWindowToolbarButtonAttribute */, - &r, &FRAME_MAC_WINDOW (f)); +#ifdef MAC_OSX + | kWindowToolbarButtonAttribute +#endif + , &r, &FRAME_MAC_WINDOW (f)); if (FRAME_MAC_WINDOW (f)) { SetWRefCon (FRAME_MAC_WINDOW (f), (long) f->output_data.mac); @@ -2378,7 +2503,6 @@ This function is an internal primitive--use `make-frame' instead. */) struct mac_display_info *dpyinfo = NULL; Lisp_Object parent; struct kboard *kb; - static int x_frame_count = 2; /* begins at 2 because terminal frame is F1 */ check_mac (); @@ -2522,8 +2646,7 @@ This function is an internal primitive--use `make-frame' instead. */) error ("Cannot find any usable font"); UNBLOCK_INPUT; - x_default_parameter (f, parms, Qfont, font, - "font", "Font", RES_TYPE_STRING); + x_set_frame_parameters (f, Fcons (Fcons (Qfont, font), Qnil)); } x_default_parameter (f, parms, Qborder_width, make_number (0), @@ -2705,26 +2828,22 @@ FRAME nil means use the selected frame. */) Lisp_Object frame; { struct frame *f = check_x_frame (frame); - struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); - if (dpyinfo->x_focus_frame != f) - { - BLOCK_INPUT; + BLOCK_INPUT; #ifdef MAC_OSX - ActivateWindow (ActiveNonFloatingWindow (), false); - ActivateWindow (FRAME_MAC_WINDOW (f), true); + ActivateWindow (ActiveNonFloatingWindow (), false); + ActivateWindow (FRAME_MAC_WINDOW (f), true); #else #if !TARGET_API_MAC_CARBON - /* SelectWindow (Non-Carbon) does not issue deactivate events if - the possibly inactive window that is to be selected is - already the frontmost one. */ - SendBehind (FRAME_MAC_WINDOW (f), NULL); + /* SelectWindow (Non-Carbon) does not issue deactivate events if the + possibly inactive window that is to be selected is already the + frontmost one. */ + SendBehind (FRAME_MAC_WINDOW (f), NULL); #endif - /* This brings the window to the front. */ - SelectWindow (FRAME_MAC_WINDOW (f)); + /* This brings the window to the front. */ + SelectWindow (FRAME_MAC_WINDOW (f)); #endif - UNBLOCK_INPUT; - } + UNBLOCK_INPUT; return Qnil; } @@ -2901,23 +3020,25 @@ If omitted or nil, that stands for the selected frame's display. */) BLOCK_INPUT; err = Gestalt (gestaltSystemVersion, &response); if (err == noErr) - if (response >= 0x00001040) - { - err = Gestalt ('sys1', &major); /* gestaltSystemVersionMajor */ - if (err == noErr) - err = Gestalt ('sys2', &minor); /* gestaltSystemVersionMinor */ - if (err == noErr) - err = Gestalt ('sys3', &bugfix); /* gestaltSystemVersionBugFix */ - } - else - { - bugfix = response & 0xf; - response >>= 4; - minor = response & 0xf; - response >>= 4; - /* convert BCD to int */ - major = response - (response >> 4) * 6; - } + { + if (response >= 0x00001040) + { + err = Gestalt (gestaltSystemVersionMajor, &major); + if (err == noErr) + err = Gestalt (gestaltSystemVersionMinor, &minor); + if (err == noErr) + err = Gestalt (gestaltSystemVersionBugFix, &bugfix); + } + else + { + bugfix = response & 0xf; + response >>= 4; + minor = response & 0xf; + response >>= 4; + /* convert BCD to int */ + major = response - (response >> 4) * 6; + } + } UNBLOCK_INPUT; if (err != noErr) @@ -2948,11 +3069,20 @@ If omitted or nil, that stands for the selected frame's display. */) (display) Lisp_Object display; { - /* MAC_TODO: this is an approximation, and only of the main display */ - struct mac_display_info *dpyinfo = check_x_display_info (display); + /* Only of the main display. */ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 + CGSize size; + + BLOCK_INPUT; + size = CGDisplayScreenSize (kCGDirectMainDisplay); + UNBLOCK_INPUT; + return make_number ((int) (size.height + .5f)); +#else + /* This is an approximation. */ return make_number ((int) (dpyinfo->height * 25.4 / dpyinfo->resy)); +#endif } DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0, @@ -2963,11 +3093,20 @@ If omitted or nil, that stands for the selected frame's display. */) (display) Lisp_Object display; { - /* MAC_TODO: this is an approximation, and only of the main display */ - struct mac_display_info *dpyinfo = check_x_display_info (display); + /* Only of the main display. */ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 + CGSize size; + BLOCK_INPUT; + size = CGDisplayScreenSize (kCGDirectMainDisplay); + UNBLOCK_INPUT; + + return make_number ((int) (size.width + .5f)); +#else + /* This is an approximation. */ return make_number ((int) (dpyinfo->width * 25.4 / dpyinfo->resx)); +#endif } DEFUN ("x-display-backing-store", Fx_display_backing_store, @@ -3201,6 +3340,14 @@ DEFUN ("x-synchronize", Fx_synchronize, Sx_synchronize, 1, 2, 0, return Qnil; } +/* x_sync is a no-op on Mac. */ + +void +x_sync (f) + FRAME_PTR f; +{ +} + /*********************************************************************** Window properties @@ -3453,6 +3600,9 @@ show_hourglass (timer) if (FRAME_LIVE_P (f) && FRAME_MAC_P (f) && FRAME_MAC_WINDOW (f) != tip_window) { +#if USE_CG_DRAWING + mac_prepare_for_quickdraw (f); +#endif if (!f->output_data.mac->hourglass_control) { Window w = FRAME_MAC_WINDOW (f); @@ -3497,7 +3647,12 @@ hide_hourglass () if (FRAME_MAC_P (f) /* Watch out for newly created frames. */ && f->output_data.mac->hourglass_control) - HideControl (f->output_data.mac->hourglass_control); + { +#if USE_CG_DRAWING + mac_prepare_for_quickdraw (f); +#endif + HideControl (f->output_data.mac->hourglass_control); + } } hourglass_shown_p = 0; @@ -3582,6 +3737,7 @@ x_create_tip_frame (dpyinfo, parms, text) check_mac (); + parms = Fcopy_alist (parms); #ifdef MULTI_KBOARD kb = dpyinfo->kboard; @@ -4177,7 +4333,6 @@ If ONLY-DIR-P is non-nil, the user can only select directories. */) int count = SPECPDL_INDEX (); struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; char filename[MAXPATHLEN]; - int default_filter_index = 1; /* 1: All Files, 2: Directories only */ static NavEventUPP mac_nav_event_callbackUPP = NULL; GCPRO6 (prompt, dir, default_filename, mustmatch, file, only_dir_p); @@ -4349,6 +4504,53 @@ mac_nav_event_callback (selector, parms, data) } #endif +/*********************************************************************** + Fonts + ***********************************************************************/ + +DEFUN ("mac-clear-font-name-table", Fmac_clear_font_name_table, + Smac_clear_font_name_table, 0, 0, 0, + doc: /* Clear the font name table. */) + () +{ + check_mac (); + mac_clear_font_name_table (); + return Qnil; +} + +#if USE_MAC_FONT_PANEL +DEFUN ("mac-set-font-panel-visibility", Fmac_set_font_panel_visibility, + Smac_set_font_panel_visibility, 1, 1, 0, + doc: /* Make the font panel visible if and only if VISIBLE is non-nil. +This is for internal use only. Use `mac-font-panel-mode' instead. */) + (visible) + Lisp_Object visible; +{ + OSStatus err = noErr; + + check_mac (); + + BLOCK_INPUT; + if (NILP (visible) != !mac_font_panel_visible_p ()) + { + err = mac_show_hide_font_panel (); + if (err == noErr && !NILP (visible)) + { + Lisp_Object focus_frame = x_get_focus_frame (SELECTED_FRAME ()); + struct frame *f = (NILP (focus_frame) ? SELECTED_FRAME () + : XFRAME (focus_frame)); + + mac_set_font_info_for_selection (f, DEFAULT_FACE_ID, 0); + } + } + UNBLOCK_INPUT; + + if (err != noErr) + error ("Cannot change visibility of the font panel"); + return Qnil; +} +#endif + /*********************************************************************** Initialization ***********************************************************************/ @@ -4365,7 +4567,7 @@ frame_parm_handler mac_frame_parm_handlers[] = x_set_border_width, x_set_cursor_color, x_set_cursor_type, - x_set_font, + mac_set_font, x_set_foreground_color, x_set_icon_name, 0, /* MAC_TODO: x_set_icon_type, */ @@ -4373,7 +4575,7 @@ frame_parm_handler mac_frame_parm_handlers[] = x_set_menu_bar_lines, x_set_mouse_color, x_explicitly_set_name, - x_set_scroll_bar_width, + mac_set_scroll_bar_width, x_set_title, x_set_unsplittable, x_set_vertical_scroll_bars, @@ -4541,7 +4743,7 @@ Chinese, Japanese, and Korean. */); load_font_func = x_load_font; find_ccl_program_func = x_find_ccl_program; query_font_func = x_query_font; - set_frame_fontset_func = x_set_font; + set_frame_fontset_func = mac_set_font; check_window_system_func = check_mac; hourglass_atimer = NULL; @@ -4559,6 +4761,10 @@ Chinese, Japanese, and Korean. */); #if TARGET_API_MAC_CARBON defsubr (&Sx_file_dialog); +#endif + defsubr (&Smac_clear_font_name_table); +#if USE_MAC_FONT_PANEL + defsubr (&Smac_set_font_panel_visibility); #endif }