aboutsummaryrefslogtreecommitdiffstats
path: root/src/xmenu.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmenu.c')
-rw-r--r--src/xmenu.c117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/xmenu.c b/src/xmenu.c
index 2abf0a48319..8e994ac5efb 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -1301,9 +1301,119 @@ popup_get_selection (initial_event, dpyinfo, id, do_timers)
1301 } 1301 }
1302} 1302}
1303 1303
1304DEFUN ("menu-bar-open", Fmenu_bar_open, Smenu_bar_open, 0, 1, "i",
1305 doc: /* Start key navigation of the menu bar in FRAME.
1306This initially opens the first menu bar item and you can then navigate with the
1307arrow keys, select a menu entry with the return key or cancel with the
1308escape key. If FRAME has no menu bar this function does nothing.
1309
1310If FRAME is nil or not given, use the selected frame. */)
1311 (frame)
1312 Lisp_Object frame;
1313{
1314 XEvent ev;
1315 FRAME_PTR f = check_x_frame (frame);
1316 Widget menubar;
1317 BLOCK_INPUT;
1318
1319 if (FRAME_EXTERNAL_MENU_BAR (f))
1320 set_frame_menubar (f, 0, 1);
1321
1322 menubar = FRAME_X_OUTPUT (f)->menubar_widget;
1323 if (menubar)
1324 {
1325 Window child;
1326 int error_p = 0;
1327
1328 x_catch_errors (FRAME_X_DISPLAY (f));
1329 memset (&ev, 0, sizeof ev);
1330 ev.xbutton.display = FRAME_X_DISPLAY (f);
1331 ev.xbutton.window = XtWindow (menubar);
1332 ev.xbutton.root = FRAME_X_DISPLAY_INFO (f)->root_window;
1333 ev.xbutton.time = XtLastTimestampProcessed (FRAME_X_DISPLAY (f));
1334 ev.xbutton.button = Button1;
1335 ev.xbutton.x = ev.xbutton.y = FRAME_MENUBAR_HEIGHT (f) / 2;
1336 ev.xbutton.same_screen = True;
1337
1338#ifdef USE_MOTIF
1339 {
1340 Arg al[2];
1341 WidgetList list;
1342 Cardinal nr;
1343 XtSetArg (al[0], XtNchildren, &list);
1344 XtSetArg (al[1], XtNnumChildren, &nr);
1345 XtGetValues (menubar, al, 2);
1346 ev.xbutton.window = XtWindow (list[0]);
1347 }
1348#endif
1349
1350 XTranslateCoordinates (FRAME_X_DISPLAY (f),
1351 /* From-window, to-window. */
1352 ev.xbutton.window, ev.xbutton.root,
1353
1354 /* From-position, to-position. */
1355 ev.xbutton.x, ev.xbutton.y,
1356 &ev.xbutton.x_root, &ev.xbutton.y_root,
1357
1358 /* Child of win. */
1359 &child);
1360 error_p = x_had_errors_p (FRAME_X_DISPLAY (f));
1361 x_uncatch_errors ();
1362
1363 if (! error_p)
1364 {
1365 ev.type = ButtonPress;
1366 ev.xbutton.state = 0;
1367
1368 XtDispatchEvent (&ev);
1369 ev.xbutton.type = ButtonRelease;
1370 ev.xbutton.state = Button1Mask;
1371 XtDispatchEvent (&ev);
1372 }
1373 }
1374
1375 UNBLOCK_INPUT;
1376
1377 return Qnil;
1378}
1304#endif /* USE_X_TOOLKIT */ 1379#endif /* USE_X_TOOLKIT */
1305 1380
1381
1306#ifdef USE_GTK 1382#ifdef USE_GTK
1383DEFUN ("menu-bar-open", Fmenu_bar_open, Smenu_bar_open, 0, 1, "i",
1384 doc: /* Start key navigation of the menu bar in FRAME.
1385This initially opens the first menu bar item and you can then navigate with the
1386arrow keys, select a menu entry with the return key or cancel with the
1387escape key. If FRAME has no menu bar this function does nothing.
1388
1389If FRAME is nil or not given, use the selected frame. */)
1390 (frame)
1391 Lisp_Object frame;
1392{
1393 GtkWidget *menubar;
1394 BLOCK_INPUT;
1395 FRAME_PTR f = check_x_frame (frame);
1396
1397 if (FRAME_EXTERNAL_MENU_BAR (f))
1398 set_frame_menubar (f, 0, 1);
1399
1400 menubar = FRAME_X_OUTPUT (f)->menubar_widget;
1401 if (menubar)
1402 {
1403 /* Activate the first menu. */
1404 GList *children = gtk_container_get_children (GTK_CONTAINER (menubar));
1405
1406 gtk_menu_shell_select_item (GTK_MENU_SHELL (menubar),
1407 GTK_WIDGET (children->data));
1408
1409 popup_activated_flag = 1;
1410 g_list_free (children);
1411 }
1412 UNBLOCK_INPUT;
1413
1414 return Qnil;
1415}
1416
1307/* Loop util popup_activated_flag is set to zero in a callback. 1417/* Loop util popup_activated_flag is set to zero in a callback.
1308 Used for popup menus and dialogs. */ 1418 Used for popup menus and dialogs. */
1309 1419
@@ -3659,6 +3769,13 @@ The enable predicate for a menu command should check this variable. */);
3659#endif 3769#endif
3660 3770
3661 defsubr (&Sx_popup_menu); 3771 defsubr (&Sx_popup_menu);
3772
3773#if defined (USE_GTK) || defined (USE_X_TOOLKIT)
3774 defsubr (&Smenu_bar_open);
3775 Fdefalias (intern ("accelerate-menu"), intern (Smenu_bar_open.symbol_name),
3776 Qnil);
3777#endif
3778
3662#ifdef HAVE_MENUS 3779#ifdef HAVE_MENUS
3663 defsubr (&Sx_popup_dialog); 3780 defsubr (&Sx_popup_dialog);
3664#endif 3781#endif