/* Graphical user interface functions for Mac OS.
Copyright (C) 2000, 2001, 2002, 2003, 2004,
- 2005, 2006 Free Software Foundation, Inc.
+ 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
This file is part of GNU Emacs.
GNU Emacs is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Emacs is distributed in the hope that it will be useful,
extern void free_frame_menubar ();
+#if TARGET_API_MAC_CARBON
+
+/* Carbon version info */
+
+static Lisp_Object Vmac_carbon_version_string;
+
+#endif /* TARGET_API_MAC_CARBON */
+
/* Non-zero means we're allowed to display an hourglass cursor. */
int display_hourglass_p;
char *name;
} colormap_t;
-colormap_t mac_color_map[] =
+static const colormap_t mac_color_map[] =
{
{ RGB_TO_ULONG(255, 250, 250), "snow" },
{ RGB_TO_ULONG(248, 248, 255), "ghost white" },
Lisp_Object
mac_color_map_lookup (colorname)
- char *colorname;
+ const char *colorname;
{
Lisp_Object ret = Qnil;
int i;
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;
}
\f
/* Change the title of frame F to NAME.
- If NAME is nil, use the frame name as the title.
-
- If EXPLICIT is non-zero, that indicates that lisp code is setting the
- name; if NAME is a string, set F's name to NAME and set
- F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
-
- If EXPLICIT is zero, that indicates that Emacs redisplay code is
- suggesting a new name, which lisp code should override; if
- F->explicit_name is set, ignore the new name; otherwise, set it. */
+ If NAME is nil, use the frame name as the title. */
void
x_set_title (f, name, old_name)
#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;
mac_update_proxy_icon (f)
struct frame *f;
{
+ OSStatus err;
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;
- }
+ AliasHandle alias = NULL;
BLOCK_INPUT;
+ err = GetWindowProxyAlias (w, &alias);
+ if (err == errWindowDoesNotHaveProxy && !STRINGP (file_name))
+ goto out;
+
if (STRINGP (file_name))
{
- OSStatus err;
AEDesc desc;
+#ifdef MAC_OSX
+ FSRef fref, fref_proxy;
+#else
+ FSSpec fss, fss_proxy;
+#endif
+ Boolean changed;
Lisp_Object encoded_file_name = ENCODE_FILE (file_name);
-#ifdef MAC_OS8
+#ifdef MAC_OSX
+ err = AECoercePtr (TYPE_FILE_NAME, SDATA (encoded_file_name),
+ SBYTES (encoded_file_name), typeFSRef, &desc);
+#else
SetPortWindowPort (w);
-#endif
err = AECoercePtr (TYPE_FILE_NAME, SDATA (encoded_file_name),
- SBYTES (encoded_file_name), typeAlias, &desc);
+ SBYTES (encoded_file_name), typeFSS, &desc);
+#endif
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);
- }
+#ifdef MAC_OSX
+ err = AEGetDescData (&desc, &fref, sizeof (FSRef));
+#else
+ err = AEGetDescData (&desc, &fss, sizeof (FSSpec));
+#endif
AEDisposeDesc (&desc);
}
if (err == noErr)
{
- FRAME_FILE_NAME (f) = xmalloc (SBYTES (file_name) + 1);
- strcpy (FRAME_FILE_NAME (f), SDATA (file_name));
+ if (alias)
+ {
+ /* (FS)ResolveAlias never sets `changed' to true if
+ `alias' is minimal. */
+#ifdef MAC_OSX
+ err = FSResolveAlias (NULL, alias, &fref_proxy, &changed);
+ if (err == noErr)
+ err = FSCompareFSRefs (&fref, &fref_proxy);
+#else
+ err = ResolveAlias (NULL, alias, &fss_proxy, &changed);
+ if (err == noErr)
+ err = !(fss.vRefNum == fss_proxy.vRefNum
+ && fss.parID == fss_proxy.parID
+ && EqualString (fss.name, fss_proxy.name,
+ false, true));
+#endif
+ }
+ if (err != noErr || alias == NULL)
+ {
+ if (alias)
+ DisposeHandle ((Handle) alias);
+#ifdef MAC_OSX
+ err = FSNewAliasMinimal (&fref, &alias);
+#else
+ err = NewAliasMinimal (&fss, &alias);
+#endif
+ changed = true;
+ }
}
+ if (err == noErr)
+ if (changed)
+ err = SetWindowProxyAlias (w, alias);
}
- if (FRAME_FILE_NAME (f) == NULL)
+ if (alias)
+ DisposeHandle ((Handle) alias);
+
+ if (err != noErr || !STRINGP (file_name))
RemoveWindowProxy (w);
+ out:
UNBLOCK_INPUT;
}
#endif
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);
+ {
+ SetWindowModified (FRAME_MAC_WINDOW (f),
+ !MINI_WINDOW_P (w) && modified_p);
+ mac_update_proxy_icon (f);
+ }
#endif
}
DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
1, 1, 0,
doc: /* Make a new window, which is called a "frame" in Emacs terms.
-Returns an Emacs frame object.
+Return an Emacs frame object.
ALIST is an alist of frame parameters.
If the parameters specify that the frame should not have a minibuffer,
and do not specify a specific minibuffer window to use,
f->output_data.mac = (struct mac_output *) xmalloc (sizeof (struct mac_output));
bzero (f->output_data.mac, sizeof (struct mac_output));
FRAME_FONTSET (f) = -1;
- record_unwind_protect (unwind_create_frame, frame);
f->icon_name
= mac_get_arg (parms, Qicon_name, "iconName", "Title", RES_TYPE_STRING);
f->icon_name = Qnil;
/* FRAME_MAC_DISPLAY_INFO (f) = dpyinfo; */
+
+ /* With FRAME_MAC_DISPLAY_INFO set up, this unwind-protect is safe. */
+ record_unwind_protect (unwind_create_frame, frame);
#if GLYPH_DEBUG
image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount;
dpyinfo_refcount = dpyinfo->reference_count;
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),
(frame)
Lisp_Object frame;
{
+ OSErr err;
+ ProcessSerialNumber front_psn;
+ static const ProcessSerialNumber current_psn = {0, kCurrentProcess};
+ Boolean front_p;
struct frame *f = check_x_frame (frame);
BLOCK_INPUT;
+ /* Move the current process to the foreground if it is not. Don't
+ call SetFrontProcess if the current process is already running in
+ the foreground so as not to change the z-order of windows. */
+ err = GetFrontProcess (&front_psn);
+ if (err == noErr)
+ err = SameProcess (&front_psn, ¤t_psn, &front_p);
+ if (err == noErr)
+ if (!front_p)
+ {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
+ if (FrontNonFloatingWindow () == FRAME_MAC_WINDOW (f))
+ SetFrontProcessWithOptions (¤t_psn,
+ kSetFrontProcessFrontWindowOnly);
+ else
+#endif
+ SetFrontProcess (¤t_psn);
+ }
+
#ifdef MAC_OSX
ActivateWindow (ActiveNonFloatingWindow (), false);
ActivateWindow (FRAME_MAC_WINDOW (f), true);
CHECK_STRING (color);
if (mac_defined_color (f, SDATA (color), &foo, 0))
- {
- Lisp_Object rgb[3];
-
- rgb[0] = make_number (foo.red);
- rgb[1] = make_number (foo.green);
- rgb[2] = make_number (foo.blue);
- return Flist (3, rgb);
- }
+ return list3 (make_number (foo.red),
+ make_number (foo.green),
+ make_number (foo.blue));
else
return Qnil;
}
DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width,
0, 1, 0,
- doc: /* Returns the width in pixels of DISPLAY.
+ doc: /* Return the width in pixels of DISPLAY.
The optional argument DISPLAY specifies which display to ask about.
DISPLAY should be either a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
DEFUN ("x-display-pixel-height", Fx_display_pixel_height,
Sx_display_pixel_height, 0, 1, 0,
- doc: /* Returns the height in pixels of DISPLAY.
+ doc: /* Return the height in pixels of DISPLAY.
The optional argument DISPLAY specifies which display to ask about.
DISPLAY should be either a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes,
0, 1, 0,
- doc: /* Returns the number of bitplanes of DISPLAY.
+ doc: /* Return the number of bitplanes of DISPLAY.
The optional argument DISPLAY specifies which display to ask about.
DISPLAY should be either a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells,
0, 1, 0,
- doc: /* Returns the number of color cells of DISPLAY.
+ doc: /* Return the number of color cells of DISPLAY.
The optional argument DISPLAY specifies which display to ask about.
DISPLAY should be either a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
DEFUN ("x-server-max-request-size", Fx_server_max_request_size,
Sx_server_max_request_size,
0, 1, 0,
- doc: /* Returns the maximum request size of the server of DISPLAY.
+ doc: /* Return the maximum request size of the server of DISPLAY.
The optional argument DISPLAY specifies which display to ask about.
DISPLAY should be either a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
}
DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0,
- doc: /* Returns the "vendor ID" string of the Mac OS system (Apple).
+ doc: /* Return the "vendor ID" string of the Mac OS system (Apple).
The optional argument DISPLAY specifies which display to ask about.
DISPLAY should be either a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
(display)
Lisp_Object display;
{
- return build_string ("Apple Computers");
+ return build_string ("Apple Inc.");
}
DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0,
- doc: /* Returns the version numbers of the Mac OS system.
+ doc: /* Return the version numbers of the Mac OS system.
The value is a list of three integers: the major and minor
version numbers, and the vendor-specific release
number. See also the function `x-server-vendor'.
(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);
+ float mm_per_pixel;
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
+#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
+ if (CGDisplayScreenSize != NULL)
+#endif
+ {
+ CGSize size;
+
+ BLOCK_INPUT;
+ size = CGDisplayScreenSize (kCGDirectMainDisplay);
+ mm_per_pixel = size.height / CGDisplayPixelsHigh (kCGDirectMainDisplay);
+ UNBLOCK_INPUT;
+ }
+#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
+ else
+#endif
+#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */
+#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020
+ {
+ /* This is an approximation. */
+ mm_per_pixel = 25.4f / dpyinfo->resy;
+ }
+#endif
- return make_number ((int) (dpyinfo->height * 25.4 / dpyinfo->resy));
+ return make_number ((int) (dpyinfo->height * mm_per_pixel + 0.5f));
}
DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
(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);
+ float mm_per_pixel;
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
+#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
+ if (CGDisplayScreenSize != NULL)
+#endif
+ {
+ CGSize size;
+
+ BLOCK_INPUT;
+ size = CGDisplayScreenSize (kCGDirectMainDisplay);
+ mm_per_pixel = size.width / CGDisplayPixelsWide (kCGDirectMainDisplay);
+ UNBLOCK_INPUT;
+ }
+#if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
+ else
+#endif
+#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */
+#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020
+ {
+ /* This is an approximation. */
+ mm_per_pixel = 25.4f / dpyinfo->resx;
+ }
+#endif
- return make_number ((int) (dpyinfo->width * 25.4 / dpyinfo->resx));
+ return make_number ((int) (dpyinfo->width * mm_per_pixel + 0.5f));
}
DEFUN ("x-display-backing-store", Fx_display_backing_store,
Sx_display_backing_store, 0, 1, 0,
- doc: /* Returns an indication of whether DISPLAY does backing store.
+ doc: /* Return an indication of whether DISPLAY does backing store.
The value may be `always', `when-mapped', or `not-useful'.
The optional argument DISPLAY specifies which display to ask about.
DISPLAY should be either a frame or a display name (a string).
DEFUN ("x-display-visual-class", Fx_display_visual_class,
Sx_display_visual_class, 0, 1, 0,
- doc: /* Returns the visual class of DISPLAY.
+ doc: /* Return the visual class of DISPLAY.
The value is one of the symbols `static-gray', `gray-scale',
`static-color', `pseudo-color', `true-color', or `direct-color'.
DEFUN ("x-display-save-under", Fx_display_save_under,
Sx_display_save_under, 0, 1, 0,
- doc: /* Returns t if DISPLAY supports the save-under feature.
+ doc: /* Return t if DISPLAY supports the save-under feature.
The optional argument DISPLAY specifies which display to ask about.
DISPLAY should be either a frame or a display name (a string).
If omitted or nil, that stands for the selected frame's display. */)
doc: /* Show STRING in a "tooltip" window on frame FRAME.
A tooltip window is a small window displaying a string.
+This is an internal function; Lisp code should call `tooltip-show'.
+
FRAME nil or omitted means use the selected frame.
PARMS is an optional list of frame parameters which can be used to
(prompt, dir, default_filename, mustmatch, only_dir_p)
Lisp_Object prompt, dir, default_filename, mustmatch, only_dir_p;
{
- struct frame *f = SELECTED_FRAME ();
Lisp_Object file = Qnil;
int count = SPECPDL_INDEX ();
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
char filename[MAXPATHLEN];
static NavEventUPP mac_nav_event_callbackUPP = NULL;
+ check_mac ();
+
GCPRO6 (prompt, dir, default_filename, mustmatch, file, only_dir_p);
CHECK_STRING (prompt);
CHECK_STRING (dir);
filename[len++] = '/';
CFStringGetCString(reply.saveFileName, filename+len,
sizeof (filename) - len,
-#if MAC_OSX
+#ifdef MAC_OSX
kCFStringEncodingUTF8
#else
CFStringGetSystemEncoding ()
}
#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.
+DEFUN ("mac-set-font-panel-visible-p", Fmac_set_font_panel_visible_p,
+ Smac_set_font_panel_visible_p, 1, 1, 0,
+ doc: /* Make the font panel visible if and only if FLAG is non-nil.
This is for internal use only. Use `mac-font-panel-mode' instead. */)
- (visible)
- Lisp_Object visible;
+ (flag)
+ Lisp_Object flag;
{
OSStatus err = noErr;
check_mac ();
BLOCK_INPUT;
- if (NILP (visible) != !mac_font_panel_visible_p ())
+ if (NILP (flag) != !mac_font_panel_visible_p ())
{
err = mac_show_hide_font_panel ();
- if (err == noErr && !NILP (visible))
+ if (err == noErr && !NILP (flag))
{
Lisp_Object focus_frame = x_get_focus_frame (SELECTED_FRAME ());
struct frame *f = (NILP (focus_frame) ? SELECTED_FRAME ()
return Qnil;
}
#endif
+
+#if USE_ATSUI
+extern Lisp_Object mac_atsu_font_face_attributes P_ ((ATSUFontID));
+
+DEFUN ("mac-atsu-font-face-attributes", Fmac_atsu_font_face_attributes,
+ Smac_atsu_font_face_attributes, 1, 1, 0,
+ doc: /* Return plist of face attributes and values for ATSU font ID.
+ID is specified by either an integer or a float. */)
+ (id)
+ Lisp_Object id;
+{
+ ATSUFontID font_id;
+ Lisp_Object result;
+
+ check_mac ();
+ CHECK_NUMBER_OR_FLOAT (id);
+ font_id = INTEGERP (id) ? XINT (id) : XFLOAT_DATA (id);
+ BLOCK_INPUT;
+ result = mac_atsu_font_face_attributes (font_id);
+ UNBLOCK_INPUT;
+ return result;
+}
+#endif
+
\f
/***********************************************************************
Initialization
x_set_menu_bar_lines,
x_set_mouse_color,
x_explicitly_set_name,
- mac_set_scroll_bar_width,
+ x_set_scroll_bar_width,
x_set_title,
x_set_unsplittable,
x_set_vertical_scroll_bars,
Chinese, Japanese, and Korean. */);
Vx_pixel_size_width_font_regexp = Qnil;
+#if TARGET_API_MAC_CARBON
+ DEFVAR_LISP ("mac-carbon-version-string", &Vmac_carbon_version_string,
+ doc: /* Version info for Carbon API. */);
+ {
+ OSErr err;
+ UInt32 response;
+ char carbon_version[16] = "Unknown";
+
+ err = Gestalt (gestaltCarbonVersion, &response);
+ if (err == noErr)
+ sprintf (carbon_version, "%u.%u.%u",
+ (response >> 8) & 0xf, (response >> 4) & 0xf, response & 0xf);
+ Vmac_carbon_version_string = build_string (carbon_version);
+ }
+#endif /* TARGET_API_MAC_CARBON */
+
/* X window properties. */
defsubr (&Sx_change_window_property);
defsubr (&Sx_delete_window_property);
#endif
defsubr (&Smac_clear_font_name_table);
#if USE_MAC_FONT_PANEL
- defsubr (&Smac_set_font_panel_visibility);
+ defsubr (&Smac_set_font_panel_visible_p);
+#endif
+#if USE_ATSUI
+ defsubr (&Smac_atsu_font_face_attributes);
#endif
}