* xmenu.c (popup_get_selection): Check new parameter down_on_keypress
authorJan Djärv <jan.h.d@swipnet.se>
Mon, 12 Jan 2004 01:46:49 +0000 (01:46 +0000)
committerJan Djärv <jan.h.d@swipnet.se>
Mon, 12 Jan 2004 01:46:49 +0000 (01:46 +0000)
if a key press should pop down.  Only pop down if a key is pressed
outside the menu/dialog.
(create_and_show_popup_menu): Pass 0 for down_on_keypress to
popup_get_selection.
(create_and_show_dialog): Pass 1 for down_on_keypress to
popup_get_selection.

src/ChangeLog
src/xmenu.c

index 8b6160f..9c21def 100644 (file)
@@ -1,3 +1,13 @@
+2004-01-12  Jan Dj\e,Ad\e(Brv  <jan.h.d@swipnet.se>
+
+       * xmenu.c (popup_get_selection): Check new parameter down_on_keypress
+       if a key press should pop down.  Only pop down if a key is pressed
+       outside the menu/dialog.
+       (create_and_show_popup_menu): Pass 0 for down_on_keypress to
+       popup_get_selection.
+       (create_and_show_dialog): Pass 1 for down_on_keypress to
+       popup_get_selection.
+
 2004-01-11  Jan Dj\e,Ad\e(Brv  <jan.h.d@swipnet.se>
 
        * alloc.c (allocate_vectorlike): Surround calls to mallopt with
index 439f500..473e29d 100644 (file)
@@ -1121,17 +1121,19 @@ on the left of the dialog box and all following items on the right.
    and x-popup-dialog; it is not used for the menu bar.
 
    If DO_TIMERS is nonzero, run timers.
+   If DOWN_ON_KEYPRESS is nonzero, pop down if a key is pressed.
 
    NOTE: All calls to popup_get_selection should be protected
    with BLOCK_INPUT, UNBLOCK_INPUT wrappers.  */
 
 #ifdef USE_X_TOOLKIT
 static void
-popup_get_selection (initial_event, dpyinfo, id, do_timers)
+popup_get_selection (initial_event, dpyinfo, id, do_timers, down_on_keypress)
      XEvent *initial_event;
      struct x_display_info *dpyinfo;
      LWLIB_ID id;
      int do_timers;
+     int down_on_keypress;
 {
   XEvent event;
 
@@ -1167,15 +1169,20 @@ popup_get_selection (initial_event, dpyinfo, id, do_timers)
           event.xbutton.state = 0;
 #endif
         }
-      /* If the user presses a key, deactivate the menu.
+      /* If the user presses a key that doesn't go to the menu,
+         deactivate the menu.
          The user is likely to do that if we get wedged.
-         This is mostly for Lucid, Motif pops down the menu on ESC.  */
+         All toolkits now pop down menus on ESC.
+         For dialogs however, the focus may not be on the dialog, so
+         in that case, we pop down. */
       else if (event.type == KeyPress
+               && down_on_keypress
                && dpyinfo->display == event.xbutton.display)
         {
           KeySym keysym = XLookupKeysym (&event.xkey, 0);
-          if (!IsModifierKey (keysym))
-            popup_activated_flag = 0;
+          if (!IsModifierKey (keysym)
+              && x_any_window_to_frame (dpyinfo, event.xany.window) != NULL)
+           popup_activated_flag = 0;
         }
 
       x_dispatch_event (&event, event.xany.display);
@@ -2448,7 +2455,7 @@ create_and_show_popup_menu (f, first_wv, x, y, for_click)
   popup_activated_flag = 1;
 
   /* Process events that apply to the menu.  */
-  popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f), menu_id, 0);
+  popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f), menu_id, 0, 0);
 
   /* fp turned off the following statement and wrote a comment
      that it is unnecessary--that the menu has already disappeared.
@@ -2842,7 +2849,8 @@ create_and_show_dialog (f, first_wv)
                            Fcons (make_number (dialog_id >> (fact)),
                                   make_number (dialog_id & ~(-1 << (fact)))));
 
-    popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f), dialog_id, 1);
+    popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f),
+                         dialog_id, 1, 1);
 
     unbind_to (count, Qnil);
   }