From f1d1cd24db8ab975bbe9bf0c4260bd8025e8bd75 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20Dj=C3=A4rv?= Date: Fri, 12 Nov 2004 10:34:36 +0000 Subject: [PATCH] (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. --- src/ChangeLog | 6 ++++++ src/xmenu.c | 44 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b680abe8d4f..89002eaadd1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -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 diff --git a/src/xmenu.c b/src/xmenu.c index d8ab2eb58aa..d7551cd7e45 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -1132,7 +1132,7 @@ x_menu_wait_for_event (void *data) 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 @@ x_menu_wait_for_event (void *data) #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 @@ x_menu_wait_for_event (void *data) 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 @@ popup_get_selection (initial_event, dpyinfo, id, do_timers, down_on_keypress) { 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 @@ popup_get_selection (initial_event, dpyinfo, id, do_timers, down_on_keypress) x_dispatch_event (&event, event.xany.display); } + + unbind_to (specpdl_count, Qnil); } #endif /* USE_X_TOOLKIT */ @@ -1247,10 +1260,29 @@ popup_get_selection (initial_event, dpyinfo, id, do_timers, down_on_keypress) #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 @@ popup_widget_loop (do_timers) if (do_timers) x_menu_wait_for_event (0); gtk_main_iteration (); } + + unbind_to (specpdl_count, Qnil); } #endif @@ -2456,7 +2490,7 @@ create_and_show_popup_menu (f, first_wv, x, y, for_click) 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 @@ create_and_show_dialog (f, first_wv) 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); } -- 2.39.2