changeset 58170:66ace4a9a250

(pop_down_menu): New function. (popup_get_selection, popup_widget_loop): Unwind protect to pop_down_menu. (popup_widget_loop): Add argument widget. (create_and_show_popup_menu, create_and_show_dialog): Pass new argument widget to popup_widget_loop.
author Jan Djärv <jan.h.d@swipnet.se>
date Fri, 12 Nov 2004 10:34:36 +0000
parents 611113427737
children e08eaff3b8ab
files src/ChangeLog src/xmenu.c
diffstat 2 files changed, 45 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri Nov 12 09:36:55 2004 +0000
+++ b/src/ChangeLog	Fri Nov 12 10:34:36 2004 +0000
@@ -10,6 +10,12 @@
 	x_menu_wait_for_event is called by XMenuActivate.
 	(create_and_show_popup_menu): Pass 1 for do_timers to 
 	popup_get_selection.
+	(pop_down_menu): New function.
+	(popup_get_selection, popup_widget_loop): Unwind protect to
+	pop_down_menu.
+	(popup_widget_loop): Add argument widget.
+	(create_and_show_popup_menu, create_and_show_dialog): Pass new
+	argument widget to popup_widget_loop.
 
 2004-11-10  Stefan Monnier  <monnier@iro.umontreal.ca>
 
--- a/src/xmenu.c	Fri Nov 12 09:36:55 2004 +0000
+++ b/src/xmenu.c	Fri Nov 12 10:34:36 2004 +0000
@@ -1132,7 +1132,7 @@
 
   while (
 #ifdef USE_X_TOOLKIT
-         XtAppPending (Xt_app_con)
+         ! XtAppPending (Xt_app_con)
 #elif defined USE_GTK
          ! gtk_events_pending ()
 #else
@@ -1171,6 +1171,15 @@
 
 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
 
+#ifdef USE_X_TOOLKIT
+
+static Lisp_Object
+pop_down_menu (dummy)
+     int dummy;
+{
+  popup_activated_flag = 0;
+}
+
 /* Loop in Xt until the menu pulldown or dialog popup has been
    popped down (deactivated).  This is used for x-popup-menu
    and x-popup-dialog; it is not used for the menu bar.
@@ -1180,7 +1189,6 @@
    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, down_on_keypress)
      XEvent *initial_event;
@@ -1191,6 +1199,9 @@
 {
   XEvent event;
 
+  int specpdl_count = SPECPDL_INDEX ();
+  record_unwind_protect (pop_down_menu, Qnil);
+
   while (popup_activated_flag)
     {
        if (initial_event)
@@ -1240,6 +1251,8 @@
 
       x_dispatch_event (&event, event.xany.display);
     }
+
+  unbind_to (specpdl_count, Qnil);
 }
 
 #endif /* USE_X_TOOLKIT */
@@ -1247,10 +1260,29 @@
 #ifdef USE_GTK
 /* Loop util popup_activated_flag is set to zero in a callback.
    Used for popup menus and dialogs. */
+static GtkWidget *current_menu;
+
+static Lisp_Object
+pop_down_menu (dummy)
+     int dummy;
+{
+  if (current_menu)
+    {
+      gtk_widget_unmap (current_menu);
+      current_menu = 0;
+      popup_activated_flag = 0;
+    }
+}
+
 static void
-popup_widget_loop (do_timers)
+popup_widget_loop (do_timers, widget)
      int do_timers;
+     GtkWidget *widget;
 {
+  int specpdl_count = SPECPDL_INDEX ();
+  current_menu = widget;
+  record_unwind_protect (pop_down_menu, Qnil);
+
   ++popup_activated_flag;
 
   /* Process events in the Gtk event loop until done.  */
@@ -1259,6 +1291,8 @@
       if (do_timers) x_menu_wait_for_event (0);
       gtk_main_iteration ();
     }
+
+  unbind_to (specpdl_count, Qnil);
 }
 #endif
 
@@ -2456,7 +2490,7 @@
      two.  show_help_echo uses this to detect popup menus.  */
   popup_activated_flag = 1;
   /* Process events that apply to the menu.  */
-  popup_widget_loop (1);
+  popup_widget_loop (1, 0);
 
   gtk_widget_destroy (menu);
 
@@ -2865,7 +2899,7 @@
       gtk_widget_show_all (menu);
 
       /* Process events that apply to the menu.  */
-      popup_widget_loop (1);
+      popup_widget_loop (1, menu);
 
       gtk_widget_destroy (menu);
     }