]> code.delx.au - gnu-emacs/blobdiff - src/xmenu.c
Consistently use platform-specific function to detect window system.
[gnu-emacs] / src / xmenu.c
index 96a1ae87fdc82870e7db8983105aa2f0e69d64eb..e6291edf7d650f9b15fc8196a6f5bb30b2c55875 100644 (file)
@@ -1,7 +1,7 @@
 /* X Communication module for terminals which understand the X protocol.
 
-Copyright (C) 1986, 1988, 1993-1994, 1996, 1999-2012
-  Free Software Foundation, Inc.
+Copyright (C) 1986, 1988, 1993-1994, 1996, 1999-2013 Free Software
+Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -111,7 +111,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 static Lisp_Object Qdebug_on_next_call;
 
 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
-static Lisp_Object xdialog_show (FRAME_PTR, int, Lisp_Object, Lisp_Object,
+static Lisp_Object xdialog_show (FRAME_PTR, bool, Lisp_Object, Lisp_Object,
                                  const char **);
 #endif
 \f
@@ -132,11 +132,8 @@ menubar_id_to_frame (LWLIB_ID id)
   Lisp_Object tail, frame;
   FRAME_PTR f;
 
-  for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
+  FOR_EACH_FRAME (tail, frame)
     {
-      frame = XCAR (tail);
-      if (!FRAMEP (frame))
-        continue;
       f = XFRAME (frame);
       if (!FRAME_WINDOW_P (f))
        continue;
@@ -226,7 +223,7 @@ for instance using the window manager, then this produces a quit and
   FRAME_PTR f = NULL;
   Lisp_Object window;
 
-  check_x ();
+  check_window_system ();
 
   /* Decode the first argument: find the window or frame to use.  */
   if (EQ (position, Qt)
@@ -930,7 +927,8 @@ set_frame_menubar (FRAME_PTR f, bool first_time, bool deep_p)
   widget_value *wv, *first_wv, *prev_wv = 0;
   int i;
   int *submenu_start, *submenu_end;
-  int *submenu_top_level_items, *submenu_n_panes;
+  bool *submenu_top_level_items;
+  int *submenu_n_panes;
 
   if (! FRAME_X_P (f))
     emacs_abort ();
@@ -978,7 +976,7 @@ set_frame_menubar (FRAME_PTR f, bool first_time, bool deep_p)
       if (! menubar_widget)
        previous_menu_items_used = 0;
 
-      buffer = XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer;
+      buffer = XWINDOW (FRAME_SELECTED_WINDOW (f))->contents;
       specbind (Qinhibit_quit, Qt);
       /* Don't let the debugger step into this code
         because it is not reentrant.  */
@@ -1057,7 +1055,7 @@ set_frame_menubar (FRAME_PTR f, bool first_time, bool deep_p)
       wv->help = Qnil;
       first_wv = wv;
 
-      for (i = 0; 0 <= submenu_start[i]; i++)
+      for (i = 0; submenu_start[i] >= 0; i++)
        {
          menu_items_n_panes = submenu_n_panes[i];
          wv = digest_single_submenu (submenu_start[i], submenu_end[i],
@@ -1346,8 +1344,8 @@ free_frame_menubar (FRAME_PTR f)
 /* F is the frame the menu is for.
    X and Y are the frame-relative specified position,
    relative to the inside upper left corner of the frame F.
-   FOR_CLICK is nonzero if this menu was invoked for a mouse click.
-   KEYMAPS is 1 if this menu was specified with keymaps;
+   FOR_CLICK is true if this menu was invoked for a mouse click.
+   KEYMAPS is true if this menu was specified with keymaps;
     in that case, we return a list containing the chosen item's value
     and perhaps also the pane's prefix.
    TITLE is the specified menu title.
@@ -1413,11 +1411,9 @@ popup_selection_callback (GtkWidget *widget, gpointer client_data)
 static Lisp_Object
 pop_down_menu (Lisp_Object arg)
 {
-  struct Lisp_Save_Value *p = XSAVE_VALUE (arg);
-
   popup_activated_flag = 0;
   block_input ();
-  gtk_widget_destroy (GTK_WIDGET (p->pointer));
+  gtk_widget_destroy (GTK_WIDGET (XSAVE_POINTER (arg, 0)));
   unblock_input ();
   return Qnil;
 }
@@ -1427,14 +1423,14 @@ pop_down_menu (Lisp_Object arg)
    menu_item_selection will be set to the selection.  */
 static void
 create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y,
-                           int for_click, Time timestamp)
+                           bool for_click, Time timestamp)
 {
   int i;
   GtkWidget *menu;
   GtkMenuPositionFunc pos_func = 0;  /* Pop up at pointer.  */
   struct next_popup_x_y popup_x_y;
   ptrdiff_t specpdl_count = SPECPDL_INDEX ();
-  int use_pos_func = ! for_click;
+  bool use_pos_func = ! for_click;
 
 #ifdef HAVE_GTK3
   /* Always use position function for Gtk3.  Otherwise menus may become
@@ -1481,7 +1477,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y,
   gtk_menu_popup (GTK_MENU (menu), 0, 0, pos_func, &popup_x_y, i,
                  timestamp ? timestamp : gtk_get_current_event_time ());
 
-  record_unwind_protect (pop_down_menu, make_save_value (menu, 0));
+  record_unwind_protect (pop_down_menu, make_save_pointer (menu));
 
   if (gtk_widget_get_mapped (menu))
     {
@@ -1539,7 +1535,7 @@ pop_down_menu (Lisp_Object arg)
    menu_item_selection will be set to the selection.  */
 static void
 create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv,
-                           int x, int y, int for_click, Time timestamp)
+                           int x, int y, bool for_click, Time timestamp)
 {
   int i;
   Arg av[2];
@@ -1614,16 +1610,12 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv,
 static Lisp_Object
 cleanup_widget_value_tree (Lisp_Object arg)
 {
-  struct Lisp_Save_Value *p = XSAVE_VALUE (arg);
-  widget_value *wv = p->pointer;
-
-  free_menubar_widget_value_tree (wv);
-
+  free_menubar_widget_value_tree (XSAVE_POINTER (arg, 0));
   return Qnil;
 }
 
 Lisp_Object
-xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
+xmenu_show (FRAME_PTR f, int x, int y, bool for_click, bool keymaps,
            Lisp_Object title, const char **error_name, Time timestamp)
 {
   int i;
@@ -1834,7 +1826,7 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
   /* Make sure to free the widget_value objects we used to specify the
      contents even with longjmp.  */
   record_unwind_protect (cleanup_widget_value_tree,
-                        make_save_value (first_wv, 0));
+                        make_save_pointer (first_wv));
 
   /* Actually create and show the menu until popped down.  */
   create_and_show_popup_menu (f, first_wv, x, y, for_click, timestamp);
@@ -1878,7 +1870,7 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
                = AREF (menu_items, i + MENU_ITEMS_ITEM_VALUE);
              if (menu_item_selection == aref_addr (menu_items, i))
                {
-                 if (keymaps != 0)
+                 if (keymaps)
                    {
                      int j;
 
@@ -1933,7 +1925,7 @@ create_and_show_dialog (FRAME_PTR f, widget_value *first_wv)
   if (menu)
     {
       ptrdiff_t specpdl_count = SPECPDL_INDEX ();
-      record_unwind_protect (pop_down_menu, make_save_value (menu, 0));
+      record_unwind_protect (pop_down_menu, make_save_pointer (menu));
 
       /* Display the menu.  */
       gtk_widget_show_all (menu);
@@ -2011,7 +2003,7 @@ static const char * button_names [] = {
 
 static Lisp_Object
 xdialog_show (FRAME_PTR f,
-              int keymaps,
+              bool keymaps,
               Lisp_Object title,
               Lisp_Object header,
               const char **error_name)
@@ -2144,7 +2136,7 @@ xdialog_show (FRAME_PTR f,
   /* Make sure to free the widget_value objects we used to specify the
      contents even with longjmp.  */
   record_unwind_protect (cleanup_widget_value_tree,
-                        make_save_value (first_wv, 0));
+                        make_save_pointer (first_wv));
 
   /* Actually create and show the dialog.  */
   create_and_show_dialog (f, first_wv);
@@ -2244,11 +2236,8 @@ menu_help_callback (char const *help_string, int pane, int item)
 static Lisp_Object
 pop_down_menu (Lisp_Object arg)
 {
-  struct Lisp_Save_Value *p1 = XSAVE_VALUE (Fcar (arg));
-  struct Lisp_Save_Value *p2 = XSAVE_VALUE (Fcdr (arg));
-
-  FRAME_PTR f = p1->pointer;
-  XMenu *menu = p2->pointer;
+  FRAME_PTR f = XSAVE_POINTER (arg, 0);
+  XMenu *menu = XSAVE_POINTER (arg, 1);
 
   block_input ();
 #ifndef MSDOS
@@ -2277,7 +2266,7 @@ pop_down_menu (Lisp_Object arg)
 
 
 Lisp_Object
-xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
+xmenu_show (FRAME_PTR f, int x, int y, bool for_click, bool keymaps,
            Lisp_Object title, const char **error_name, Time timestamp)
 {
   Window root;
@@ -2490,8 +2479,7 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
 #endif
 
   record_unwind_protect (pop_down_menu,
-                         Fcons (make_save_value (f, 0),
-                                make_save_value (menu, 0)));
+                        make_save_value (SAVE_TYPE_PTR_PTR, f, menu));
 
   /* Help display under X won't work because XMenuActivate contains
      a loop that doesn't give Emacs a chance to process it.  */
@@ -2528,7 +2516,7 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
                    {
                      entry
                        = AREF (menu_items, i + MENU_ITEMS_ITEM_VALUE);
-                     if (keymaps != 0)
+                     if (keymaps)
                        {
                          entry = Fcons (entry, Qnil);
                          if (!NILP (pane_prefix))