Don't include ../oldXMenu/XMenu.h if USE_X_TOOLKIT.
authorRichard M. Stallman <rms@gnu.org>
Thu, 15 Dec 1994 12:16:00 +0000 (12:16 +0000)
committerRichard M. Stallman <rms@gnu.org>
Thu, 15 Dec 1994 12:16:00 +0000 (12:16 +0000)
(push_menu_item): New arg DEF.
(single_keymap_panes, list_of_items): Pass new arg.
(MENU_ITEMS_ITEM_DEFINITION): New macro.
(MENU_ITEMS_ITEM_LENGTH): Now 5.
[USE_X_TOOLKIT] (xmenu_show): Store 0 in call_data if item def is 0.
(single_submenu): Likewise.

(xmenu_show): Call x_mouse_leave.

src/xmenu.c

index fffcdc4..267491e 100644 (file)
@@ -57,9 +57,6 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "dispextern.h"
 
 #ifdef HAVE_X_WINDOWS
-#include "../oldXMenu/XMenu.h"
-#endif
-
 #ifdef USE_X_TOOLKIT
 #include <X11/Xlib.h>
 #include <X11/IntrinsicP.h>
@@ -67,7 +64,10 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <X11/StringDefs.h>
 #include <X11/Shell.h>
 #include "../lwlib/lwlib.h"
-#endif /* USE_X_TOOLKIT */
+#else /* not USE_X_TOOLKIT */
+#include "../oldXMenu/XMenu.h"
+#endif /* not USE_X_TOOLKIT */
+#endif /* HAVE_X_WINDOWS */
 
 #define min(x,y) (((x) < (y)) ? (x) : (y))
 #define max(x,y) (((x) > (y)) ? (x) : (y))
@@ -102,9 +102,9 @@ static void list_of_items ();
 
    Each pane is described by 3 elements in the vector:
    t, the pane name, the pane's prefix key.
-   Then follow the pane's items, with 4 elements per item:
+   Then follow the pane's items, with 5 elements per item:
    the item string, the enable flag, the item's value,
-   and the equivalent keyboard key's description string.
+   the definition, and the equivalent keyboard key's description string.
 
    In some cases, multiple levels of menus may be described.
    A single vector slot containing nil indicates the start of a submenu.
@@ -125,7 +125,8 @@ static void list_of_items ();
 #define MENU_ITEMS_ITEM_ENABLE 1
 #define MENU_ITEMS_ITEM_VALUE 2
 #define MENU_ITEMS_ITEM_EQUIV_KEY 3
-#define MENU_ITEMS_ITEM_LENGTH 4
+#define MENU_ITEMS_ITEM_DEFINITION 4
+#define MENU_ITEMS_ITEM_LENGTH 5
 
 static Lisp_Object menu_items;
 
@@ -257,12 +258,14 @@ push_menu_pane (name, prefix_vec)
 /* Push one menu item into the current pane.
    NAME is the string to display.  ENABLE if non-nil means
    this item can be selected.  KEY is the key generated by
-   choosing this item.  EQUIV is the textual description
-   of the keyboard equivalent for this item (or nil if none).  */
+   choosing this item, or nil if this item doesn't really have a definition.
+   DEF is the definition of this item.
+   EQUIV is the textual description of the keyboard equivalent for
+   this item (or nil if none).  */
 
 static void
-push_menu_item (name, enable, key, equiv)
-     Lisp_Object name, enable, key, equiv;
+push_menu_item (name, enable, key, def, equiv)
+     Lisp_Object name, enable, key, def, equiv;
 {
   if (menu_items_used + MENU_ITEMS_ITEM_LENGTH > menu_items_allocated)
     grow_menu_items ();
@@ -271,6 +274,7 @@ push_menu_item (name, enable, key, equiv)
   XVECTOR (menu_items)->contents[menu_items_used++] = enable;
   XVECTOR (menu_items)->contents[menu_items_used++] = key;
   XVECTOR (menu_items)->contents[menu_items_used++] = equiv;
+  XVECTOR (menu_items)->contents[menu_items_used++] = def;
 }
 \f
 /* Figure out the current keyboard equivalent of a menu item ITEM1.
@@ -519,7 +523,9 @@ single_keymap_panes (keymap, pane_name, prefix, notreal)
                        item_string = concat2 (item_string,
                                               build_string (" >"));
 #endif
-                     push_menu_item (item_string, enabled, XCONS (item)->car,
+                     /* If definition is nil, pass nil as the key.  */
+                     push_menu_item (item_string, enabled,
+                                     XCONS (item)->car, def,
                                      descrip);
 #ifdef USE_X_TOOLKIT
                      /* Display a submenu using the toolkit.  */
@@ -588,8 +594,9 @@ single_keymap_panes (keymap, pane_name, prefix, notreal)
                            item_string = concat2 (item_string,
                                                   build_string (" >"));
 #endif
+                         /* If definition is nil, pass nil as the key.  */
                          push_menu_item (item_string, enabled, character,
-                                         descrip);
+                                         def, descrip);
 #ifdef USE_X_TOOLKIT
                          if (! NILP (submap))
                            {
@@ -660,7 +667,7 @@ list_of_items (pane)
     {
       item = Fcar (tail);
       if (STRINGP (item))
-       push_menu_item (item, Qnil, Qnil, Qnil);
+       push_menu_item (item, Qnil, Qnil, Qt, Qnil);
       else if (NILP (item))
        push_left_right_boundary ();
       else
@@ -668,7 +675,7 @@ list_of_items (pane)
          CHECK_CONS (item, 0);
          item1 = Fcar (item);
          CHECK_STRING (item1, 1);
-         push_menu_item (item1, Qt, Fcdr (item), Qnil);
+         push_menu_item (item1, Qt, Fcdr (item), Qt, Qnil);
        }
     }
 }
@@ -1283,11 +1290,12 @@ single_submenu (item_key, item_name, maps)
       else
        {
          /* Create a new item within current pane.  */
-         Lisp_Object item_name, enable, descrip;
+         Lisp_Object item_name, enable, descrip, def;
          item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME];
          enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE];
          descrip
            = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY];
+         def = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_DEFINITION];
 
          wv = malloc_widget_value ();
          if (prev_wv) 
@@ -1298,7 +1306,7 @@ single_submenu (item_key, item_name, maps)
          if (!NILP (descrip))
            wv->key = (char *) XSTRING (descrip)->data;
          wv->value = 0;
-         wv->call_data = (void *) i;
+         wv->call_data = (!NILP (def) ? (void *) i : 0);
          wv->enabled = !NILP (enable);
          prev_wv = wv;
 
@@ -1545,8 +1553,7 @@ xmenu_show (f, x, y, menubarp, keymaps, title, error)
      FRAME_PTR f;
      int x;
      int y;
-     int menubarp;             /* Dummy parameter for Xt version of
-                                  xmenu_show() */
+     int menubarp;             /* This arg is unused in Xt version.  */
      int keymaps;
      Lisp_Object title;
      char **error;
@@ -1665,11 +1672,12 @@ xmenu_show (f, x, y, menubarp, keymaps, title, error)
       else
        {
          /* Create a new item within current pane.  */
-         Lisp_Object item_name, enable, descrip;
+         Lisp_Object item_name, enable, descrip, def;
          item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME];
          enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE];
          descrip
            = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY];
+         def = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_DEFINITION];
 
          wv = malloc_widget_value ();
          if (prev_wv) 
@@ -1680,7 +1688,11 @@ xmenu_show (f, x, y, menubarp, keymaps, title, error)
          if (!NILP (descrip))
            wv->key = (char *) XSTRING (descrip)->data;
          wv->value = 0;
-         wv->call_data = (void *) &XVECTOR (menu_items)->contents[i];
+         /* If this item has a null value,
+            make the call_data null so that it won't display a box
+            when the mouse is on it.  */
+         wv->call_data
+           = (!NILP (def) ? (void *) &XVECTOR (menu_items)->contents[i] : 0);
          wv->enabled = !NILP (enable);
          prev_wv = wv;
 
@@ -2263,6 +2275,12 @@ xmenu_show (f, x, y, menubarp, keymaps, title, error)
   
   status = XMenuActivate (FRAME_X_DISPLAY (f), menu, &pane, &selidx,
                          x, y, ButtonReleaseMask, &datap);
+
+
+  /* Assume the mouse has moved out of the X window.
+     If it has actually moved in, we will get an EnterNotify.  */
+  x_mouse_leave ();
+
   switch (status)
     {
     case XM_SUCCESS: