aboutsummaryrefslogtreecommitdiffstats
path: root/src/macmenu.c
diff options
context:
space:
mode:
authorKaroly Lorentey2005-06-15 12:57:51 +0000
committerKaroly Lorentey2005-06-15 12:57:51 +0000
commitef85512e51f043d73788f00a2aed13cccde0682c (patch)
treefc1fa1378533250f260ef8eaa9a84ae882d9df84 /src/macmenu.c
parent8736257554f49445f7b4402ac7a9436b38ce6452 (diff)
parentef88a9999004e6c26148c8d280d6a41f623d7249 (diff)
downloademacs-ef85512e51f043d73788f00a2aed13cccde0682c.tar.gz
emacs-ef85512e51f043d73788f00a2aed13cccde0682c.zip
Merged from miles@gnu.org--gnu-2005 (patch 80-82, 350-422)
Patches applied: * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-350 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-351 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-352 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-353 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-354 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-355 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-356 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-357 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-358 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-359 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-360 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-361 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-362 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-363 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-364 Remove "-face" suffix from widget faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-365 Remove "-face" suffix from custom faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-366 Remove "-face" suffix from change-log faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-367 Remove "-face" suffix from compilation faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368 Remove "-face" suffix from diff-mode faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-369 lisp/longlines.el (longlines-visible-face): Face removed * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-370 Remove "-face" suffix from woman faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371 Remove "-face" suffix from whitespace-highlight face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-372 Remove "-face" suffix from ruler-mode faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-373 Remove "-face" suffix from show-paren faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-374 Remove "-face" suffix from log-view faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-375 Remove "-face" suffix from smerge faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-376 Remove "-face" suffix from show-tabs faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-377 Remove "-face" suffix from highlight-changes faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-378 Remove "-face" suffix from and downcase info faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-379 Remove "-face" suffix from pcvs faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-380 Update uses of renamed pcvs faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-381 Tweak ChangeLog * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-382 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-383 Remove "-face" suffix from strokes-char face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-384 Remove "-face" suffix from compare-windows face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-385 Remove "-face" suffix from calendar faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-386 Remove "-face" suffix from diary-button face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-387 Remove "-face" suffix from testcover faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-388 Remove "-face" suffix from viper faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-389 Remove "-face" suffix from org faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-390 Remove "-face" suffix from sgml-namespace face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-391 Remove "-face" suffix from table-cell face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-392 Remove "-face" suffix from tex-mode faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-393 Remove "-face" suffix from texinfo-heading face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-394 Remove "-face" suffix from flyspell faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-395 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-396 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-397 Remove "-face" suffix from gomoku faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-398 Remove "-face" suffix from mpuz faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-399 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-400 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-401 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-402 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-403 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-404 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-405 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-406 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-407 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-408 Remove "-face" suffix from Buffer-menu-buffer face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-409 Remove "-face" suffix from antlr-mode faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-410 Remove "-face" suffix from ebrowse faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-411 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-412 Remove "-face" suffix from flymake faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-413 Remove "-face" suffix from idlwave faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-414 Remove "-face" suffix from sh-script faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-415 Remove "-face" suffix from vhdl-mode faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-416 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-417 Remove "-face" suffix from which-func face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-418 Remove "-face" suffix from cperl-mode faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-419 Remove "-face" suffix from ld-script faces * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-420 Fix cperl-mode font-lock problem * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-421 Tweak which-func face * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-422 Update from CVS * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-80 Merge from emacs--cvs-trunk--0 * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-81 Update from CVS * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-82 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-350
Diffstat (limited to 'src/macmenu.c')
-rw-r--r--src/macmenu.c171
1 files changed, 136 insertions, 35 deletions
diff --git a/src/macmenu.c b/src/macmenu.c
index 54393bca594..ee83a5f609f 100644
--- a/src/macmenu.c
+++ b/src/macmenu.c
@@ -602,6 +602,13 @@ list_of_items (pane)
602 } 602 }
603} 603}
604 604
605static Lisp_Object
606cleanup_popup_menu (arg)
607 Lisp_Object arg;
608{
609 discard_menu_items ();
610}
611
605DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0, 612DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0,
606 doc: /* Pop up a deck-of-cards menu and return user's selection. 613 doc: /* Pop up a deck-of-cards menu and return user's selection.
607POSITION is a position specification. This is either a mouse button 614POSITION is a position specification. This is either a mouse button
@@ -647,6 +654,8 @@ cached information about equivalent key sequences. */)
647 int keymaps = 0; 654 int keymaps = 0;
648 int for_click = 0; 655 int for_click = 0;
649 struct gcpro gcpro1; 656 struct gcpro gcpro1;
657 int specpdl_count = SPECPDL_INDEX ();
658
650 659
651#ifdef HAVE_MENUS 660#ifdef HAVE_MENUS
652 if (! NILP (position)) 661 if (! NILP (position))
@@ -806,13 +815,13 @@ cached information about equivalent key sequences. */)
806 815
807#ifdef HAVE_MENUS 816#ifdef HAVE_MENUS
808 /* Display them in a menu. */ 817 /* Display them in a menu. */
818 record_unwind_protect (cleanup_popup_menu, Qnil);
809 BLOCK_INPUT; 819 BLOCK_INPUT;
810 820
811 selection = mac_menu_show (f, xpos, ypos, for_click, 821 selection = mac_menu_show (f, xpos, ypos, for_click,
812 keymaps, title, &error_name); 822 keymaps, title, &error_name);
813 UNBLOCK_INPUT; 823 UNBLOCK_INPUT;
814 824 unbind_to (specpdl_count, Qnil);
815 discard_menu_items ();
816 825
817 UNGCPRO; 826 UNGCPRO;
818#endif /* HAVE_MENUS */ 827#endif /* HAVE_MENUS */
@@ -1347,6 +1356,68 @@ update_submenu_strings (first_wv)
1347} 1356}
1348 1357
1349 1358
1359/* Event handler function that pops down a menu on C-g. We can only pop
1360 down menus if CancelMenuTracking is present (OSX 10.3 or later). */
1361
1362#ifdef HAVE_CANCELMENUTRACKING
1363static pascal OSStatus
1364menu_quit_handler (nextHandler, theEvent, userData)
1365 EventHandlerCallRef nextHandler;
1366 EventRef theEvent;
1367 void* userData;
1368{
1369 UInt32 keyCode;
1370 UInt32 keyModifiers;
1371 extern int mac_quit_char_modifiers;
1372 extern int mac_quit_char_keycode;
1373
1374 GetEventParameter (theEvent, kEventParamKeyCode,
1375 typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode);
1376
1377 GetEventParameter (theEvent, kEventParamKeyModifiers,
1378 typeUInt32, NULL, sizeof(UInt32),
1379 NULL, &keyModifiers);
1380
1381 if (keyCode == mac_quit_char_keycode
1382 && keyModifiers == mac_quit_char_modifiers)
1383 {
1384 MenuRef menu = userData != 0
1385 ? (MenuRef)userData : AcquireRootMenu ();
1386
1387 CancelMenuTracking (menu, true, 0);
1388 if (!userData) ReleaseMenu (menu);
1389 return noErr;
1390 }
1391
1392 return CallNextEventHandler (nextHandler, theEvent);
1393}
1394#endif /* HAVE_CANCELMENUTRACKING */
1395
1396/* Add event handler for MENU_HANDLE so we can detect C-g.
1397 If MENU_HANDLE is NULL, install handler for all menus in the menu bar.
1398 If CancelMenuTracking isn't available, do nothing. */
1399
1400static void
1401install_menu_quit_handler (MenuHandle menu_handle)
1402{
1403#ifdef HAVE_CANCELMENUTRACKING
1404 EventHandlerUPP handler = NewEventHandlerUPP(menu_quit_handler);
1405 UInt32 numTypes = 1;
1406 EventTypeSpec typesList[] = { { kEventClassKeyboard, kEventRawKeyDown } };
1407 int i = MIN_MENU_ID;
1408 MenuHandle menu = menu_handle ? menu_handle : GetMenuHandle (i);
1409
1410 while (menu != NULL)
1411 {
1412 InstallMenuEventHandler (menu, handler, GetEventTypeCount (typesList),
1413 typesList, menu_handle, NULL);
1414 if (menu_handle) break;
1415 menu = GetMenuHandle (++i);
1416 }
1417 DisposeEventHandlerUPP (handler);
1418#endif /* HAVE_CANCELMENUTRACKING */
1419}
1420
1350/* Set the contents of the menubar widgets of frame F. 1421/* Set the contents of the menubar widgets of frame F.
1351 The argument FIRST_TIME is currently ignored; 1422 The argument FIRST_TIME is currently ignored;
1352 it is set the first time this is called, from initialize_frame_menubar. */ 1423 it is set the first time this is called, from initialize_frame_menubar. */
@@ -1404,7 +1475,7 @@ set_frame_menubar (f, first_time, deep_p)
1404 because it is not reentrant. */ 1475 because it is not reentrant. */
1405 specbind (Qdebug_on_next_call, Qnil); 1476 specbind (Qdebug_on_next_call, Qnil);
1406 1477
1407 record_unwind_protect (Fset_match_data, Fmatch_data (Qnil, Qnil)); 1478 record_unwind_save_match_data ();
1408 if (NILP (Voverriding_local_map_menu_flag)) 1479 if (NILP (Voverriding_local_map_menu_flag))
1409 { 1480 {
1410 specbind (Qoverriding_terminal_local_map, Qnil); 1481 specbind (Qoverriding_terminal_local_map, Qnil);
@@ -1566,6 +1637,8 @@ set_frame_menubar (f, first_time, deep_p)
1566 1637
1567 DrawMenuBar (); 1638 DrawMenuBar ();
1568 1639
1640 /* Add event handler so we can detect C-g. */
1641 install_menu_quit_handler (NULL);
1569 free_menubar_widget_value_tree (first_wv); 1642 free_menubar_widget_value_tree (first_wv);
1570 1643
1571 UNBLOCK_INPUT; 1644 UNBLOCK_INPUT;
@@ -1597,7 +1670,43 @@ free_frame_menubar (f)
1597} 1670}
1598 1671
1599 1672
1600/* mac_menu_show actually displays a menu using the panes and items in 1673static Lisp_Object
1674pop_down_menu (arg)
1675 Lisp_Object arg;
1676{
1677 struct Lisp_Save_Value *p1 = XSAVE_VALUE (Fcar (arg));
1678 struct Lisp_Save_Value *p2 = XSAVE_VALUE (Fcdr (arg));
1679
1680 FRAME_PTR f = p1->pointer;
1681 MenuHandle *menu = p2->pointer;
1682
1683 BLOCK_INPUT;
1684
1685 /* Must reset this manually because the button release event is not
1686 passed to Emacs event loop. */
1687 FRAME_MAC_DISPLAY_INFO (f)->grabbed = 0;
1688
1689 /* delete all menus */
1690 {
1691 int i = MIN_POPUP_SUBMENU_ID;
1692 MenuHandle submenu = GetMenuHandle (i);
1693 while (submenu != NULL)
1694 {
1695 DeleteMenu (i);
1696 DisposeMenu (submenu);
1697 submenu = GetMenuHandle (++i);
1698 }
1699 }
1700
1701 DeleteMenu (POPUP_SUBMENU_ID);
1702 DisposeMenu (*menu);
1703
1704 UNBLOCK_INPUT;
1705
1706 return Qnil;
1707}
1708
1709/* Mac_menu_show actually displays a menu using the panes and items in
1601 menu_items and returns the value selected from it; we assume input 1710 menu_items and returns the value selected from it; we assume input
1602 is blocked by the caller. */ 1711 is blocked by the caller. */
1603 1712
@@ -1635,6 +1744,7 @@ mac_menu_show (f, x, y, for_click, keymaps, title, error)
1635 = (Lisp_Object *) alloca (menu_items_used * sizeof (Lisp_Object)); 1744 = (Lisp_Object *) alloca (menu_items_used * sizeof (Lisp_Object));
1636 int submenu_depth = 0; 1745 int submenu_depth = 0;
1637 int first_pane; 1746 int first_pane;
1747 int specpdl_count = SPECPDL_INDEX ();
1638 1748
1639 *error = NULL; 1749 *error = NULL;
1640 1750
@@ -1808,7 +1918,7 @@ mac_menu_show (f, x, y, for_click, keymaps, title, error)
1808 title = ENCODE_MENU_STRING (title); 1918 title = ENCODE_MENU_STRING (title);
1809#endif 1919#endif
1810 wv_title->name = (char *) SDATA (title); 1920 wv_title->name = (char *) SDATA (title);
1811 wv_title->enabled = TRUE; 1921 wv_title->enabled = FALSE;
1812 wv_title->title = TRUE; 1922 wv_title->title = TRUE;
1813 wv_title->button_type = BUTTON_TYPE_NONE; 1923 wv_title->button_type = BUTTON_TYPE_NONE;
1814 wv_title->help = Qnil; 1924 wv_title->help = Qnil;
@@ -1821,6 +1931,10 @@ mac_menu_show (f, x, y, for_click, keymaps, title, error)
1821 submenu_id = MIN_POPUP_SUBMENU_ID; 1931 submenu_id = MIN_POPUP_SUBMENU_ID;
1822 fill_submenu (menu, first_wv->contents); 1932 fill_submenu (menu, first_wv->contents);
1823 1933
1934 /* Free the widget_value objects we used to specify the
1935 contents. */
1936 free_menubar_widget_value_tree (first_wv);
1937
1824 /* Adjust coordinates to be root-window-relative. */ 1938 /* Adjust coordinates to be root-window-relative. */
1825 pos.h = x; 1939 pos.h = x;
1826 pos.v = y; 1940 pos.v = y;
@@ -1835,11 +1949,18 @@ mac_menu_show (f, x, y, for_click, keymaps, title, error)
1835 1949
1836 InsertMenu (menu, -1); 1950 InsertMenu (menu, -1);
1837 1951
1952 record_unwind_protect (pop_down_menu,
1953 Fcons (make_save_value (f, 0),
1954 make_save_value (&menu, 0)));
1955
1956 /* Add event handler so we can detect C-g. */
1957 install_menu_quit_handler (menu);
1958
1838 /* Display the menu. */ 1959 /* Display the menu. */
1839 menu_item_choice = PopUpMenuSelect (menu, pos.v, pos.h, 0); 1960 menu_item_choice = PopUpMenuSelect (menu, pos.v, pos.h, 0);
1840 menu_item_selection = LoWord (menu_item_choice); 1961 menu_item_selection = LoWord (menu_item_choice);
1841 1962
1842 /* Get the refcon to find the correct item*/ 1963 /* Get the refcon to find the correct item */
1843 if (menu_item_selection) 1964 if (menu_item_selection)
1844 { 1965 {
1845 MenuHandle sel_menu = GetMenuHandle (HiWord (menu_item_choice)); 1966 MenuHandle sel_menu = GetMenuHandle (HiWord (menu_item_choice));
@@ -1847,35 +1968,10 @@ mac_menu_show (f, x, y, for_click, keymaps, title, error)
1847 GetMenuItemRefCon (sel_menu, menu_item_selection, &refcon); 1968 GetMenuItemRefCon (sel_menu, menu_item_selection, &refcon);
1848 } 1969 }
1849 } 1970 }
1850 1971 else if (! for_click)
1851#if 0 1972 /* Make "Cancel" equivalent to C-g unless this menu was popped up by
1852 /* Clean up extraneous mouse events which might have been generated 1973 a mouse press. */
1853 during the call. */ 1974 Fsignal (Qquit, Qnil);
1854 discard_mouse_events ();
1855#endif
1856
1857 /* Must reset this manually because the button release event is not
1858 passed to Emacs event loop. */
1859 FRAME_MAC_DISPLAY_INFO (f)->grabbed = 0;
1860
1861 /* Free the widget_value objects we used to specify the
1862 contents. */
1863 free_menubar_widget_value_tree (first_wv);
1864
1865 /* delete all menus */
1866 {
1867 int i = MIN_POPUP_SUBMENU_ID;
1868 MenuHandle submenu = GetMenuHandle (i);
1869 while (submenu != NULL)
1870 {
1871 DeleteMenu (i);
1872 DisposeMenu (submenu);
1873 submenu = GetMenuHandle (++i);
1874 }
1875 }
1876
1877 DeleteMenu (POPUP_SUBMENU_ID);
1878 DisposeMenu (menu);
1879 1975
1880 /* Find the selected item, and its pane, to return 1976 /* Find the selected item, and its pane, to return
1881 the proper value. */ 1977 the proper value. */
@@ -1931,6 +2027,11 @@ mac_menu_show (f, x, y, for_click, keymaps, title, error)
1931 } 2027 }
1932 } 2028 }
1933 } 2029 }
2030 else if (!for_click)
2031 /* Make "Cancel" equivalent to C-g. */
2032 Fsignal (Qquit, Qnil);
2033
2034 unbind_to (specpdl_count, Qnil);
1934 2035
1935 return Qnil; 2036 return Qnil;
1936} 2037}