]> code.delx.au - gnu-emacs/blobdiff - lwlib/xlwmenu.c
(motion_event_is_in_menu): Make x and y signed.
[gnu-emacs] / lwlib / xlwmenu.c
index 7a4eb3380625cdae3502aeb004eeb8b7be852a16..c2aae8d0e61cbe07e5b1fad274cf08217af61495 100644 (file)
@@ -37,9 +37,39 @@ XFontStruct *xlwmenu_default_font;
 
 static char 
 xlwMenuTranslations [] = 
-"<BtnDown>:    start()\n\
-<Motion>:      drag()\n\
-<BtnUp>:       select()\n\
+"<BtnDown>:      start()\n\
+<Motion>:        drag()\n\
+<BtnUp>:         select()\n\
+<Key>Shift_L:     nothing()\n\
+<Key>Shift_R:     nothing()\n\
+<Key>Meta_L:      nothing()\n\
+<Key>Meta_R:      nothing()\n\
+<Key>Control_L:   nothing()\n\
+<Key>Control_R:   nothing()\n\
+<Key>Hyper_L:     nothing()\n\
+<Key>Hyper_R:     nothing()\n\
+<Key>Super_L:     nothing()\n\
+<Key>Super_R:     nothing()\n\
+<Key>Alt_L:       nothing()\n\
+<Key>Alt_R:       nothing()\n\
+<Key>Caps_Lock:   nothing()\n\
+<Key>Shift_Lock:  nothing()\n\
+<KeyUp>Shift_L:   nothing()\n\
+<KeyUp>Shift_R:   nothing()\n\
+<KeyUp>Meta_L:    nothing()\n\
+<KeyUp>Meta_R:    nothing()\n\
+<KeyUp>Control_L: nothing()\n\
+<KeyUp>Control_R: nothing()\n\
+<KeyUp>Hyper_L:   nothing()\n\
+<KeyUp>Hyper_R:   nothing()\n\
+<KeyUp>Super_L:   nothing()\n\
+<KeyUp>Super_R:   nothing()\n\
+<KeyUp>Alt_L:     nothing()\n\
+<KeyUp>Alt_R:     nothing()\n\
+<KeyUp>Caps_Lock: nothing()\n\
+<KeyUp>Shift_Lock:nothing()\n\
+<Key>:            key()\n\
+<KeyUp>:          key()\n\
 ";
 
 #define offset(field) XtOffset(XlwMenuWidget, field)
@@ -97,6 +127,8 @@ static void XlwMenuClassInitialize();
 static void Start();
 static void Drag();
 static void Select();
+static void Key();
+static void Nothing();
 
 static XtActionsRec 
 xlwMenuActionsList [] =
@@ -104,6 +136,8 @@ xlwMenuActionsList [] =
   {"start",            Start},
   {"drag",             Drag},
   {"select",           Select},
+  {"key",              Key},
+  {"nothing",          Nothing},
 };
 
 #define SuperClass ((CoreWidgetClass)&coreClassRec)
@@ -486,8 +520,11 @@ display_menu_item (mw, val, ws, where, highlighted_p, horizontal_p, just_compute
       width = ws->width - 2 * shadow;
     }
 
+#if 0
   /* see if it should be a button in the menubar */
   button_p = horizontal_p && val->call_data;
+#endif
+  button_p = 0;
 
   /* Only highlight an enabled item that has a callback. */
   if (highlighted_p)
@@ -811,7 +848,7 @@ remap_menubar (mw)
     old_stack [i] = new_stack [i];
   mw->menu.old_depth = new_depth;
 
-  /* refresh the last seletion */
+  /* refresh the last selection */
   selection_position.x = 0;
   selection_position.y = 0;
   display_menu (mw, last_same, new_selection == old_selection,
@@ -855,8 +892,8 @@ motion_event_is_in_menu (mw, ev, level, relative_pos)
      XPoint* relative_pos;
 {
   window_state* ws = &mw->menu.windows [level];
-  unsigned int x = level == 0 ? ws->x : ws->x + mw->menu.shadow_thickness;
-  unsigned int y = level == 0 ? ws->y : ws->y + mw->menu.shadow_thickness;
+  int x = level == 0 ? ws->x : ws->x + mw->menu.shadow_thickness;
+  int y = level == 0 ? ws->y : ws->y + mw->menu.shadow_thickness;
   relative_pos->x = ev->x_root - x;
   relative_pos->y = ev->y_root - y;
   return (x < ev->x_root && ev->x_root < x + ws->width
@@ -1086,9 +1123,10 @@ XlwMenuInitialize (request, mw, args, num_args)
 /*  mw->menu.cursor = XCreateFontCursor (display, mw->menu.cursor_shape); */
   mw->menu.cursor = mw->menu.cursor_shape;
   
-  mw->menu.gray_pixmap = XCreatePixmapFromBitmapData (display, window,
-                                                     gray_bits, gray_width,
-                                                     gray_height, 1, 0, 1);
+  mw->menu.gray_pixmap
+    = XCreatePixmapFromBitmapData (display, window, gray_bits,
+                                  gray_width, gray_height,
+                                  (unsigned long)1, (unsigned long)0, 1);
   
   /* I don't understand why this ends up 0 sometimes,
      but it does.  This kludge works around it.
@@ -1247,6 +1285,11 @@ XlwMenuSetValues (current, request, new)
       && newmw->menu.contents->contents
       && newmw->menu.contents->contents->change >= VISIBLE_CHANGE)
     redisplay = True;
+  /* Do redisplay if the contents are entirely eliminated.  */
+  if (newmw->menu.contents
+      && newmw->menu.contents->contents == 0
+      && newmw->menu.contents->change >= VISIBLE_CHANGE)
+    redisplay = True;
 
   if (newmw->core.background_pixel != oldmw->core.background_pixel
       || newmw->menu.foreground != oldmw->menu.foreground
@@ -1370,10 +1413,54 @@ Drag (w, ev, params, num_params)
      Cardinal *num_params;
 {
   XlwMenuWidget mw = (XlwMenuWidget)w;
-  handle_motion_event (mw, &ev->xmotion);
+  if (mw->menu.popped_up)
+    handle_motion_event (mw, &ev->xmotion);
 }
 
-static void 
+/* Do nothing.
+   This is how we handle presses and releases of modifier keys.  */
+static void
+Nothing (w, ev, params, num_params)
+     Widget w;
+     XEvent *ev;
+     String *params;
+     Cardinal *num_params;
+{
+}
+
+/* Handle key press and release events while menu is popped up.
+   Our action is to get rid of the menu.  */
+static void
+Key (w, ev, params, num_params)
+     Widget w;
+     XEvent *ev;
+     String *params;
+     Cardinal *num_params;
+{
+  XlwMenuWidget mw = (XlwMenuWidget)w;
+
+  /* Pop down everything.  */
+  mw->menu.new_depth = 1;
+  remap_menubar (mw);
+
+  if (mw->menu.popped_up)
+    {
+      mw->menu.popped_up = False;
+      XtUngrabPointer ((Widget)mw, ev->xmotion.time);
+      if (XtIsShell (XtParent ((Widget) mw)))
+       XtPopdown (XtParent ((Widget) mw));
+      else
+       {
+         XtRemoveGrab ((Widget) mw);
+         display_menu (mw, 0, False, NULL, NULL, NULL, NULL, NULL);
+       }
+    }
+
+  /* callback */
+  XtCallCallbackList ((Widget)mw, mw->menu.select, (XtPointer)0);
+}
+
+static void
 Select (w, ev, params, num_params)
      Widget w;
      XEvent *ev;