* src/profiler.c: Delete.
[bpt/emacs.git] / src / menu.c
index b75e3dd..240f873 100644 (file)
@@ -66,9 +66,6 @@ Lisp_Object menu_items;
 
 /* If non-nil, means that the global vars defined here are already in use.
    Used to detect cases where we try to re-enter this non-reentrant code.  */
-#if ! (defined USE_GTK || defined USE_MOTIF)
-static
-#endif
 Lisp_Object menu_items_inuse;
 
 /* Number of slots currently allocated in menu_items.  */
@@ -1162,13 +1159,17 @@ no quit occurs and `x-popup-menu' returns nil.  */)
   struct frame *f = NULL;
   Lisp_Object x, y, window;
   int menuflags = 0;
-  ptrdiff_t specpdl_count = SPECPDL_INDEX ();
+  dynwind_begin ();
+  ptrdiff_t specpdl_count2;
   struct gcpro gcpro1;
 
   if (NILP (position))
     /* This is an obsolete call, which wants us to precompute the
        keybinding equivalents, but we don't do that any more anyway.  */
-    return Qnil;
+    {
+      dynwind_end ();
+      return Qnil;
+    }
 
   {
     bool get_current_pos_p = 0;
@@ -1236,7 +1237,7 @@ no quit occurs and `x-popup-menu' returns nil.  */)
          {
            int cur_x, cur_y;
 
-           mouse_position_for_popup (new_f, &cur_x, &cur_y);
+           x_relative_mouse_position (new_f, &cur_x, &cur_y);
            /* cur_x/y may be negative, so use make_number.  */
            x = make_number (cur_x);
            y = make_number (cur_y);
@@ -1386,7 +1387,7 @@ no quit occurs and `x-popup-menu' returns nil.  */)
       menuflags &= ~MENU_KEYMAPS;
     }
 
-  unbind_to (specpdl_count, Qnil);
+  dynwind_end ();
 
 #ifdef HAVE_WINDOW_SYSTEM
   /* Hide a previous tip, if any.  */
@@ -1409,20 +1410,25 @@ no quit occurs and `x-popup-menu' returns nil.  */)
     }
 #endif
 
+  dynwind_begin ();
+
 #ifdef HAVE_NS                 /* FIXME: ns-specific, why? --Stef  */
   record_unwind_protect_void (discard_menu_items);
 #endif
 
-  /* Display them in a menu.  */
-  selection = FRAME_TERMINAL (f)->menu_show_hook (f, xpos, ypos, menuflags,
-                                                 title, &error_name);
+  /* Display them in a menu, but not if F is the initial frame that
+     doesn't have its hooks set (e.g., in a batch session), because
+     such a frame cannot display menus.  */
+  if (!FRAME_INITIAL_P (f))
+    selection = FRAME_TERMINAL (f)->menu_show_hook (f, xpos, ypos, menuflags,
+                                                   title, &error_name);
 
-#ifdef HAVE_NS
-  unbind_to (specpdl_count, Qnil);
-#else
+#ifndef HAVE_NS
   discard_menu_items ();
 #endif
 
+  dynwind_end ();
+
 #ifdef HAVE_NTGUI     /* FIXME: Is it really w32-specific?  --Stef  */
   if (FRAME_W32_P (f))
     FRAME_DISPLAY_INFO (f)->grabbed = 0;
@@ -1434,7 +1440,7 @@ no quit occurs and `x-popup-menu' returns nil.  */)
   return selection;
 }
 
-/* If F's terminal is not capable to display popup dialog,
+/* If F's terminal is not capable of displaying a popup dialog,
    emulate it with a menu.  */
 
 static Lisp_Object
@@ -1457,7 +1463,7 @@ emulate_dialog_with_menu (struct frame *f, Lisp_Object contents)
        x_coord -= SCHARS (prompt);
       y_coord = FRAME_LINES (f);
     }
-  
+
   XSETFRAME (frame, f);
   XSETINT (x, x_coord / 2);
   XSETINT (y, y_coord / 2);
@@ -1546,9 +1552,12 @@ for instance using the window manager, then this produces a quit and
       Lisp_Object selection
        = FRAME_TERMINAL (f)->popup_dialog_hook (f, header, contents);
 #ifdef HAVE_NTGUI
+      /* NTGUI supports only simple dialogs with Yes/No choices.  For
+        other dialogs, it returns the symbol 'unsupported--w32-dialog',
+        as a signal for the caller to fall back to the emulation code.  */
       if (!EQ (selection, Qunsupported__w32_dialog))
-#endif 
-      return selection;
+#endif
+       return selection;
     }
   /* ... or emulate it with a menu.  */
   return emulate_dialog_with_menu (f, contents);
@@ -1557,11 +1566,9 @@ for instance using the window manager, then this produces a quit and
 void
 syms_of_menu (void)
 {
+#include "menu.x"
+
   staticpro (&menu_items);
   menu_items = Qnil;
   menu_items_inuse = Qnil;
-
-  defsubr (&Sx_popup_menu);
-  defsubr (&Sx_popup_dialog);
-  defsubr (&Smenu_bar_menu_at_x_y);
 }