]> code.delx.au - gnu-emacs/blobdiff - src/macfns.c
* process.c (wait_reading_process_output): Check for window
[gnu-emacs] / src / macfns.c
index 21cff69dd4086bf9ed877fac4fd4f7077f2495b4..19947cadae466b3552f36f8ae93e32d24ebf4beb 100644 (file)
@@ -1,12 +1,12 @@
 /* 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,
@@ -1855,15 +1855,7 @@ x_implicitly_set_name (f, arg, oldval)
 }
 \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)
@@ -1909,24 +1901,6 @@ 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;
@@ -2514,7 +2488,7 @@ unwind_create_frame (frame)
 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,
@@ -2863,9 +2837,31 @@ FRAME nil means use the selected frame.  */)
      (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, &current_psn, &front_p);
+  if (err == noErr)
+    if (!front_p)
+      {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
+       if (FrontNonFloatingWindow () == FRAME_MAC_WINDOW (f))
+         SetFrontProcessWithOptions (&current_psn,
+                                     kSetFrontProcessFrontWindowOnly);
+       else
+#endif
+         SetFrontProcess (&current_psn);
+      }
+
 #ifdef MAC_OSX
   ActivateWindow (ActiveNonFloatingWindow (), false);
   ActivateWindow (FRAME_MAC_WINDOW (f), true);
@@ -2952,7 +2948,7 @@ If omitted or nil, that stands for the selected frame's display.  */)
 
 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.  */)
@@ -2966,7 +2962,7 @@ 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.  */)
@@ -2980,7 +2976,7 @@ 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.  */)
@@ -2994,7 +2990,7 @@ 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.  */)
@@ -3010,7 +3006,7 @@ 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.  */)
@@ -3023,18 +3019,18 @@ 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'.
@@ -3101,8 +3097,8 @@ If omitted or nil, that stands for the selected frame's display.  */)
      Lisp_Object display;
 {
   struct mac_display_info *dpyinfo = check_x_display_info (display);
+  float mm_per_pixel;
 
-  /* Only of the main display.  */
 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
 #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
   if (CGDisplayScreenSize != NULL)
@@ -3112,9 +3108,8 @@ If omitted or nil, that stands for the selected frame's display.  */)
 
       BLOCK_INPUT;
       size = CGDisplayScreenSize (kCGDirectMainDisplay);
+      mm_per_pixel = size.height / CGDisplayPixelsHigh (kCGDirectMainDisplay);
       UNBLOCK_INPUT;
-
-      return make_number ((int) (size.height + .5f));
     }
 #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
   else
@@ -3123,9 +3118,11 @@ If omitted or nil, that stands for the selected frame's display.  */)
 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020
     {
       /* This is an approximation.  */
-      return make_number ((int) (dpyinfo->height * 25.4 / dpyinfo->resy));
+      mm_per_pixel = 25.4f / dpyinfo->resy;
     }
 #endif
+
+  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,
@@ -3137,8 +3134,8 @@ If omitted or nil, that stands for the selected frame's display.  */)
      Lisp_Object display;
 {
   struct mac_display_info *dpyinfo = check_x_display_info (display);
+  float mm_per_pixel;
 
-  /* Only of the main display.  */
 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
 #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
   if (CGDisplayScreenSize != NULL)
@@ -3148,9 +3145,8 @@ If omitted or nil, that stands for the selected frame's display.  */)
 
       BLOCK_INPUT;
       size = CGDisplayScreenSize (kCGDirectMainDisplay);
+      mm_per_pixel = size.width / CGDisplayPixelsWide (kCGDirectMainDisplay);
       UNBLOCK_INPUT;
-
-      return make_number ((int) (size.width + .5f));
     }
 #if MAC_OS_X_VERSION_MIN_REQUIRED == 1020
   else
@@ -3159,14 +3155,16 @@ If omitted or nil, that stands for the selected frame's display.  */)
 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 || MAC_OS_X_VERSION_MIN_REQUIRED == 1020
     {
       /* This is an approximation.  */
-      return make_number ((int) (dpyinfo->width * 25.4 / dpyinfo->resx));
+      mm_per_pixel = 25.4f / dpyinfo->resx;
     }
 #endif
+
+  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).
@@ -3179,7 +3177,7 @@ If omitted or nil, that stands for the selected frame's display.  */)
 
 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'.
 
@@ -3210,7 +3208,7 @@ If omitted or nil, that stands for the selected frame's display.  */)
 
 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.  */)
@@ -4111,6 +4109,8 @@ DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
        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
@@ -4513,7 +4513,7 @@ If ONLY-DIR-P is non-nil, the user can only select directories.  */)
                      filename[len++] = '/';
                    CFStringGetCString(reply.saveFileName, filename+len,
                                       sizeof (filename) - len,
-#if MAC_OSX
+#ifdef MAC_OSX
                                       kCFStringEncodingUTF8
 #else
                                       CFStringGetSystemEncoding ()
@@ -4575,22 +4575,22 @@ DEFUN ("mac-clear-font-name-table", Fmac_clear_font_name_table,
 }
 
 #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 ()
@@ -4621,8 +4621,8 @@ ID is specified by either an integer or a float.  */)
   Lisp_Object result;
 
   check_mac ();
-  CHECK_NUMBER_OR_FLOAT(id);
-  font_id = NUMBERP (id) ? XINT (id) : (ATSUFontID) XFLOAT (id);
+  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;
@@ -4655,7 +4655,7 @@ frame_parm_handler mac_frame_parm_handlers[] =
   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,
@@ -4860,7 +4860,7 @@ Chinese, Japanese, and Korean.  */);
 #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);