Mercurial > emacs
comparison src/xmenu.c @ 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 |
comparison
equal
deleted
inserted
replaced
58169:611113427737 | 58170:66ace4a9a250 |
---|---|
1130 anyway, and with callbacks we would have three variants for timer handling | 1130 anyway, and with callbacks we would have three variants for timer handling |
1131 instead of the small ifdefs below. */ | 1131 instead of the small ifdefs below. */ |
1132 | 1132 |
1133 while ( | 1133 while ( |
1134 #ifdef USE_X_TOOLKIT | 1134 #ifdef USE_X_TOOLKIT |
1135 XtAppPending (Xt_app_con) | 1135 ! XtAppPending (Xt_app_con) |
1136 #elif defined USE_GTK | 1136 #elif defined USE_GTK |
1137 ! gtk_events_pending () | 1137 ! gtk_events_pending () |
1138 #else | 1138 #else |
1139 ! XPending ((Display*) data) | 1139 ! XPending ((Display*) data) |
1140 #endif | 1140 #endif |
1169 #endif /* ! MSDOS */ | 1169 #endif /* ! MSDOS */ |
1170 | 1170 |
1171 | 1171 |
1172 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) | 1172 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) |
1173 | 1173 |
1174 #ifdef USE_X_TOOLKIT | |
1175 | |
1176 static Lisp_Object | |
1177 pop_down_menu (dummy) | |
1178 int dummy; | |
1179 { | |
1180 popup_activated_flag = 0; | |
1181 } | |
1182 | |
1174 /* Loop in Xt until the menu pulldown or dialog popup has been | 1183 /* Loop in Xt until the menu pulldown or dialog popup has been |
1175 popped down (deactivated). This is used for x-popup-menu | 1184 popped down (deactivated). This is used for x-popup-menu |
1176 and x-popup-dialog; it is not used for the menu bar. | 1185 and x-popup-dialog; it is not used for the menu bar. |
1177 | 1186 |
1178 If DOWN_ON_KEYPRESS is nonzero, pop down if a key is pressed. | 1187 If DOWN_ON_KEYPRESS is nonzero, pop down if a key is pressed. |
1179 | 1188 |
1180 NOTE: All calls to popup_get_selection should be protected | 1189 NOTE: All calls to popup_get_selection should be protected |
1181 with BLOCK_INPUT, UNBLOCK_INPUT wrappers. */ | 1190 with BLOCK_INPUT, UNBLOCK_INPUT wrappers. */ |
1182 | 1191 |
1183 #ifdef USE_X_TOOLKIT | |
1184 static void | 1192 static void |
1185 popup_get_selection (initial_event, dpyinfo, id, do_timers, down_on_keypress) | 1193 popup_get_selection (initial_event, dpyinfo, id, do_timers, down_on_keypress) |
1186 XEvent *initial_event; | 1194 XEvent *initial_event; |
1187 struct x_display_info *dpyinfo; | 1195 struct x_display_info *dpyinfo; |
1188 LWLIB_ID id; | 1196 LWLIB_ID id; |
1189 int do_timers; | 1197 int do_timers; |
1190 int down_on_keypress; | 1198 int down_on_keypress; |
1191 { | 1199 { |
1192 XEvent event; | 1200 XEvent event; |
1201 | |
1202 int specpdl_count = SPECPDL_INDEX (); | |
1203 record_unwind_protect (pop_down_menu, Qnil); | |
1193 | 1204 |
1194 while (popup_activated_flag) | 1205 while (popup_activated_flag) |
1195 { | 1206 { |
1196 if (initial_event) | 1207 if (initial_event) |
1197 { | 1208 { |
1238 popup_activated_flag = 0; | 1249 popup_activated_flag = 0; |
1239 } | 1250 } |
1240 | 1251 |
1241 x_dispatch_event (&event, event.xany.display); | 1252 x_dispatch_event (&event, event.xany.display); |
1242 } | 1253 } |
1254 | |
1255 unbind_to (specpdl_count, Qnil); | |
1243 } | 1256 } |
1244 | 1257 |
1245 #endif /* USE_X_TOOLKIT */ | 1258 #endif /* USE_X_TOOLKIT */ |
1246 | 1259 |
1247 #ifdef USE_GTK | 1260 #ifdef USE_GTK |
1248 /* Loop util popup_activated_flag is set to zero in a callback. | 1261 /* Loop util popup_activated_flag is set to zero in a callback. |
1249 Used for popup menus and dialogs. */ | 1262 Used for popup menus and dialogs. */ |
1263 static GtkWidget *current_menu; | |
1264 | |
1265 static Lisp_Object | |
1266 pop_down_menu (dummy) | |
1267 int dummy; | |
1268 { | |
1269 if (current_menu) | |
1270 { | |
1271 gtk_widget_unmap (current_menu); | |
1272 current_menu = 0; | |
1273 popup_activated_flag = 0; | |
1274 } | |
1275 } | |
1276 | |
1250 static void | 1277 static void |
1251 popup_widget_loop (do_timers) | 1278 popup_widget_loop (do_timers, widget) |
1252 int do_timers; | 1279 int do_timers; |
1253 { | 1280 GtkWidget *widget; |
1281 { | |
1282 int specpdl_count = SPECPDL_INDEX (); | |
1283 current_menu = widget; | |
1284 record_unwind_protect (pop_down_menu, Qnil); | |
1285 | |
1254 ++popup_activated_flag; | 1286 ++popup_activated_flag; |
1255 | 1287 |
1256 /* Process events in the Gtk event loop until done. */ | 1288 /* Process events in the Gtk event loop until done. */ |
1257 while (popup_activated_flag) | 1289 while (popup_activated_flag) |
1258 { | 1290 { |
1259 if (do_timers) x_menu_wait_for_event (0); | 1291 if (do_timers) x_menu_wait_for_event (0); |
1260 gtk_main_iteration (); | 1292 gtk_main_iteration (); |
1261 } | 1293 } |
1294 | |
1295 unbind_to (specpdl_count, Qnil); | |
1262 } | 1296 } |
1263 #endif | 1297 #endif |
1264 | 1298 |
1265 /* Activate the menu bar of frame F. | 1299 /* Activate the menu bar of frame F. |
1266 This is called from keyboard.c when it gets the | 1300 This is called from keyboard.c when it gets the |
2454 | 2488 |
2455 /* Set this to one. popup_widget_loop increases it by one, so it becomes | 2489 /* Set this to one. popup_widget_loop increases it by one, so it becomes |
2456 two. show_help_echo uses this to detect popup menus. */ | 2490 two. show_help_echo uses this to detect popup menus. */ |
2457 popup_activated_flag = 1; | 2491 popup_activated_flag = 1; |
2458 /* Process events that apply to the menu. */ | 2492 /* Process events that apply to the menu. */ |
2459 popup_widget_loop (1); | 2493 popup_widget_loop (1, 0); |
2460 | 2494 |
2461 gtk_widget_destroy (menu); | 2495 gtk_widget_destroy (menu); |
2462 | 2496 |
2463 /* Must reset this manually because the button release event is not passed | 2497 /* Must reset this manually because the button release event is not passed |
2464 to Emacs event loop. */ | 2498 to Emacs event loop. */ |
2863 { | 2897 { |
2864 /* Display the menu. */ | 2898 /* Display the menu. */ |
2865 gtk_widget_show_all (menu); | 2899 gtk_widget_show_all (menu); |
2866 | 2900 |
2867 /* Process events that apply to the menu. */ | 2901 /* Process events that apply to the menu. */ |
2868 popup_widget_loop (1); | 2902 popup_widget_loop (1, menu); |
2869 | 2903 |
2870 gtk_widget_destroy (menu); | 2904 gtk_widget_destroy (menu); |
2871 } | 2905 } |
2872 } | 2906 } |
2873 | 2907 |