]> code.delx.au - gnu-emacs/blobdiff - src/nsfns.m
* callint.c (Fcall_interactively): <, not <=, for optimization.
[gnu-emacs] / src / nsfns.m
index 1b46729765190359d1990a27aa515ce7693d515a..d4445d1d62764bf73bfb98088fc2d80abd974b1a 100644 (file)
@@ -1,6 +1,6 @@
 /* Functions for the NeXT/Open/GNUstep and MacOSX window system.
 
-Copyright (C) 1989, 1992, 1993, 1994, 2005, 2006, 2008, 2009, 2010
+Copyright (C) 1989, 1992-1994, 2005-2006, 2008-2011
   Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -82,11 +82,7 @@ extern Lisp_Object Qunderline, Qundefined;
 extern Lisp_Object Qheight, Qminibuffer, Qname, Qonly, Qwidth;
 extern Lisp_Object Qunsplittable, Qmenu_bar_lines, Qbuffer_predicate, Qtitle;
 extern Lisp_Object Qnone;
-extern Lisp_Object Vframe_title_format, Vicon_title_format;
 
-/* The below are defined in frame.c.  */
-
-extern Lisp_Object Vmenu_bar_mode, Vtool_bar_mode;
 
 Lisp_Object Qbuffered;
 Lisp_Object Qfontsize;
@@ -94,13 +90,6 @@ Lisp_Object Qfontsize;
 /* hack for OS X file panels */
 char panelOK = 0;
 
-/* Alist of elements (REGEXP . IMAGE) for images of icons associated
-   to frames.*/
-static Lisp_Object Vns_icon_type_alist;
-
-/* Toolkit version support. */
-static Lisp_Object Vns_version_string;
-
 EmacsTooltip *ns_tooltip;
 
 /* Need forward declaration here to preserve organizational integrity of file */
@@ -494,7 +483,7 @@ ns_set_name_internal (FRAME_PTR f, Lisp_Object name)
   if (!STRINGP (f->icon_name))
     encoded_icon_name = encoded_name;
   else
-    encoded_icon_name = ENCODE_UTF_8 (f->icon_name);    
+    encoded_icon_name = ENCODE_UTF_8 (f->icon_name);
 
   str = [NSString stringWithUTF8String: SDATA (encoded_icon_name)];
 
@@ -602,12 +591,13 @@ void
 ns_set_name_as_filename (struct frame *f)
 {
   NSView *view;
-  Lisp_Object name;
+  Lisp_Object name, filename;
   Lisp_Object buf = XWINDOW (f->selected_window)->buffer;
   const char *title;
   NSAutoreleasePool *pool;
   struct gcpro gcpro1;
-  Lisp_Object encoded_name;
+  Lisp_Object encoded_name, encoded_filename;
+  NSString *str;
   NSTRACE (ns_set_name_as_filename);
 
   if (f->explicit_name || ! NILP (f->title) || ns_in_resize)
@@ -615,16 +605,16 @@ ns_set_name_as_filename (struct frame *f)
 
   BLOCK_INPUT;
   pool = [[NSAutoreleasePool alloc] init];
-  name = XBUFFER (buf)->filename;
-  if (NILP (name) || FRAME_ICONIFIED_P (f)) name = XBUFFER (buf)->name;
-
-  if (FRAME_ICONIFIED_P (f) && !NILP (f->icon_name))
-    name = f->icon_name;
+  filename = BVAR (XBUFFER (buf), filename);
+  name = BVAR (XBUFFER (buf), name);
 
   if (NILP (name))
-    name = build_string ([ns_app_name UTF8String]);
-  else
-    CHECK_STRING (name);
+    {
+      if (! NILP (filename))
+        name = Ffile_name_nondirectory (filename);
+      else
+        name = build_string ([ns_app_name UTF8String]);
+    }
 
   GCPRO1 (name);
   encoded_name = ENCODE_UTF_8 (name);
@@ -642,33 +632,39 @@ ns_set_name_as_filename (struct frame *f)
       return;
     }
 
-  if (! FRAME_ICONIFIED_P (f))
+  str = [NSString stringWithUTF8String: SDATA (encoded_name)];
+  if (str == nil) str = @"Bad coding";
+
+  if (FRAME_ICONIFIED_P (f))
+    [[view window] setMiniwindowTitle: str];
+  else
     {
-#ifdef NS_IMPL_COCOA
-      /* work around a bug observed on 10.3 where
-         setTitleWithRepresentedFilename does not clear out previous state
-         if given filename does not exist */
-      NSString *str = [NSString stringWithUTF8String: SDATA (encoded_name)];
-      if (![[NSFileManager defaultManager] fileExistsAtPath: str])
+      NSString *fstr;
+
+      if (! NILP (filename))
         {
-          [[view window] setTitleWithRepresentedFilename: @""];
-          [[view window] setTitle: str];
+          GCPRO1 (filename);
+          encoded_filename = ENCODE_UTF_8 (filename);
+          UNGCPRO;
+
+          fstr = [NSString stringWithUTF8String: SDATA (encoded_filename)];
+          if (fstr == nil) fstr = @"";
+#ifdef NS_IMPL_COCOA
+          /* work around a bug observed on 10.3 and later where
+             setTitleWithRepresentedFilename does not clear out previous state
+             if given filename does not exist */
+          if (! [[NSFileManager defaultManager] fileExistsAtPath: fstr])
+            [[view window] setRepresentedFilename: @""];
+#endif
         }
       else
-        {
-          [[view window] setTitleWithRepresentedFilename: str];
-        }
-#else
-      [[view window] setTitleWithRepresentedFilename:
-                         [NSString stringWithUTF8String: SDATA (encoded_name)]];
-#endif
+        fstr = @"";
+
+      [[view window] setRepresentedFilename: fstr];
+      [[view window] setTitle: str];
       f->name = name;
     }
-  else
-    {
-      [[view window] setMiniwindowTitle:
-            [NSString stringWithUTF8String: SDATA (encoded_name)]];
-    }
+
   [pool release];
   UNBLOCK_INPUT;
 }
@@ -1025,8 +1021,8 @@ frame_parm_handler ns_frame_parm_handlers[] =
   0,  /* x_set_fullscreen will ignore */
   x_set_font_backend, /* generic OK */
   x_set_alpha,
-  0, /* x_set_sticky */  
-  0, /* x_set_tool_bar_position */  
+  0, /* x_set_sticky */
+  0, /* x_set_tool_bar_position */
 };
 
 
@@ -1333,9 +1329,9 @@ be shared by the new frame.  */)
     }
 
   if (FRAME_HAS_MINIBUF_P (f)
-      && (!FRAMEP (kb->Vdefault_minibuffer_frame)
-          || !FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame))))
-    kb->Vdefault_minibuffer_frame = frame;
+      && (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
+          || !FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame)))))
+    KVAR (kb, Vdefault_minibuffer_frame) = frame;
 
   /* All remaining specified parameters, which have not been "used"
      by x_get_arg and friends, now go in the misc. alist of the frame.  */
@@ -1432,7 +1428,7 @@ Optional arg INIT, if non-nil, provides a default file name to use.  */)
   NSString *promptS = NILP (prompt) || !STRINGP (prompt) ? nil :
     [NSString stringWithUTF8String: SDATA (prompt)];
   NSString *dirS = NILP (dir) || !STRINGP (dir) ?
-    [NSString stringWithUTF8String: SDATA (current_buffer->directory)] :
+    [NSString stringWithUTF8String: SDATA (BVAR (current_buffer, directory))] :
     [NSString stringWithUTF8String: SDATA (dir)];
   NSString *initS = NILP (init) || !STRINGP (init) ? nil :
     [NSString stringWithUTF8String: SDATA (init)];
@@ -2048,7 +2044,7 @@ In case the execution fails, an error is signaled. */)
      (Lisp_Object script)
 {
   Lisp_Object result;
-  long status;
+  int status;
 
   CHECK_STRING (script);
   check_ns ();
@@ -2334,7 +2330,7 @@ If omitted or nil, that stands for the selected frame's display.  */)
 {
   struct ns_display_info *dpyinfo;
   check_ns ();
-  
+
   dpyinfo = check_ns_display_info (display);
   /* We force 24+ bit depths to 24-bit to prevent an overflow.  */
   return make_number (1 << min (dpyinfo->n_planes, 24));
@@ -2377,7 +2373,7 @@ compute_tip_xy (struct frame *f,
       pt.y = x_display_pixel_height (FRAME_NS_DISPLAY_INFO (f)) - XINT (top)
         - height;
     }
-  
+
   /* Ensure in bounds.  (Note, screen origin = lower left.) */
   if (INTEGERP (left))
     *root_x = pt.x;
@@ -2586,7 +2582,7 @@ syms_of_nsfns (void)
   Qfontsize = intern_c_string ("fontsize");
   staticpro (&Qfontsize);
 
-  DEFVAR_LISP ("ns-icon-type-alist", &Vns_icon_type_alist,
+  DEFVAR_LISP ("ns-icon-type-alist", Vns_icon_type_alist,
                doc: /* Alist of elements (REGEXP . IMAGE) for images of icons associated to frames.
 If the title of a frame matches REGEXP, then IMAGE.tiff is
 selected as the image of the icon representing the frame when it's
@@ -2607,7 +2603,7 @@ When you miniaturize a Group, Summary or Article frame, Gnus.tiff will
 be used as the image of the icon representing the frame.  */);
   Vns_icon_type_alist = Fcons (Qt, Qnil);
 
-  DEFVAR_LISP ("ns-version-string", &Vns_version_string,
+  DEFVAR_LISP ("ns-version-string", Vns_version_string,
                doc: /* Toolkit version for NS Windowing.  */);
   Vns_version_string = ns_appkit_version_str ();
 
@@ -2659,4 +2655,3 @@ be used as the image of the icon representing the frame.  */);
   check_window_system_func = check_ns;
 
 }
-