Mercurial > emacs
comparison src/macmenu.c @ 49600:23a1cea22d13
Trailing whitespace deleted.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Tue, 04 Feb 2003 14:56:31 +0000 |
parents | 3cabed8b65b7 |
children | 22a5614b558f d7ddb3e565de |
comparison
equal
deleted
inserted
replaced
49599:5ade352e8d1c | 49600:23a1cea22d13 |
---|---|
118 { | 118 { |
119 /* name of widget */ | 119 /* name of widget */ |
120 char* name; | 120 char* name; |
121 /* value (meaning depend on widget type) */ | 121 /* value (meaning depend on widget type) */ |
122 char* value; | 122 char* value; |
123 /* keyboard equivalent. no implications for XtTranslations */ | 123 /* keyboard equivalent. no implications for XtTranslations */ |
124 char* key; | 124 char* key; |
125 /* Help string or nil if none. | 125 /* Help string or nil if none. |
126 GC finds this string through the frame's menu_bar_vector | 126 GC finds this string through the frame's menu_bar_vector |
127 or through menu_items. */ | 127 or through menu_items. */ |
128 Lisp_Object help; | 128 Lisp_Object help; |
172 | 172 |
173 #ifndef TRUE | 173 #ifndef TRUE |
174 #define TRUE 1 | 174 #define TRUE 1 |
175 #define FALSE 0 | 175 #define FALSE 0 |
176 #endif /* no TRUE */ | 176 #endif /* no TRUE */ |
177 | 177 |
178 Lisp_Object Vmenu_updating_frame; | 178 Lisp_Object Vmenu_updating_frame; |
179 | 179 |
180 Lisp_Object Qdebug_on_next_call; | 180 Lisp_Object Qdebug_on_next_call; |
181 | 181 |
182 extern Lisp_Object Qmenu_bar; | 182 extern Lisp_Object Qmenu_bar; |
505 } | 505 } |
506 } | 506 } |
507 | 507 |
508 /* This is a subroutine of single_keymap_panes that handles one | 508 /* This is a subroutine of single_keymap_panes that handles one |
509 keymap entry. | 509 keymap entry. |
510 KEY is a key in a keymap and ITEM is its binding. | 510 KEY is a key in a keymap and ITEM is its binding. |
511 PENDING_MAPS_PTR points to a list of keymaps waiting to be made into | 511 PENDING_MAPS_PTR points to a list of keymaps waiting to be made into |
512 separate panes. | 512 separate panes. |
513 If NOTREAL is nonzero, only check for equivalent key bindings, don't | 513 If NOTREAL is nonzero, only check for equivalent key bindings, don't |
514 evaluate expressions in menu items and don't make any menu. | 514 evaluate expressions in menu items and don't make any menu. |
515 If we encounter submenus deeper than MAXDEPTH levels, ignore them. */ | 515 If we encounter submenus deeper than MAXDEPTH levels, ignore them. */ |
521 int maxdepth, notreal; | 521 int maxdepth, notreal; |
522 { | 522 { |
523 Lisp_Object map, item_string, enabled; | 523 Lisp_Object map, item_string, enabled; |
524 struct gcpro gcpro1, gcpro2; | 524 struct gcpro gcpro1, gcpro2; |
525 int res; | 525 int res; |
526 | 526 |
527 /* Parse the menu item and leave the result in item_properties. */ | 527 /* Parse the menu item and leave the result in item_properties. */ |
528 GCPRO2 (key, item); | 528 GCPRO2 (key, item); |
529 res = parse_menu_item (item, notreal, 0); | 529 res = parse_menu_item (item, notreal, 0); |
530 UNGCPRO; | 530 UNGCPRO; |
531 if (!res) | 531 if (!res) |
532 return; /* Not a menu item. */ | 532 return; /* Not a menu item. */ |
533 | 533 |
534 map = XVECTOR (item_properties)->contents[ITEM_PROPERTY_MAP]; | 534 map = XVECTOR (item_properties)->contents[ITEM_PROPERTY_MAP]; |
535 | 535 |
536 if (notreal) | 536 if (notreal) |
537 { | 537 { |
538 /* We don't want to make a menu, just traverse the keymaps to | 538 /* We don't want to make a menu, just traverse the keymaps to |
539 precompute equivalent key bindings. */ | 539 precompute equivalent key bindings. */ |
540 if (!NILP (map)) | 540 if (!NILP (map)) |
541 single_keymap_panes (map, Qnil, key, 1, maxdepth - 1); | 541 single_keymap_panes (map, Qnil, key, 1, maxdepth - 1); |
542 return; | 542 return; |
543 } | 543 } |
544 | 544 |
545 enabled = XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE]; | 545 enabled = XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE]; |
546 item_string = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME]; | 546 item_string = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME]; |
547 | 547 |
548 if (!NILP (map) && SREF (item_string, 0) == '@') | 548 if (!NILP (map) && SREF (item_string, 0) == '@') |
549 { | 549 { |
550 if (!NILP (enabled)) | 550 if (!NILP (enabled)) |
551 /* An enabled separate pane. Remember this to handle it later. */ | 551 /* An enabled separate pane. Remember this to handle it later. */ |
816 | 816 |
817 list_of_panes (Fcdr (menu)); | 817 list_of_panes (Fcdr (menu)); |
818 | 818 |
819 keymaps = 0; | 819 keymaps = 0; |
820 } | 820 } |
821 | 821 |
822 if (NILP (position)) | 822 if (NILP (position)) |
823 { | 823 { |
824 discard_menu_items (); | 824 discard_menu_items (); |
825 UNGCPRO; | 825 UNGCPRO; |
826 return Qnil; | 826 return Qnil; |
969 processing of the menus. | 969 processing of the menus. |
970 | 970 |
971 But first we recompute the menu bar contents (the whole tree). | 971 But first we recompute the menu bar contents (the whole tree). |
972 | 972 |
973 This way we can safely execute Lisp code. */ | 973 This way we can safely execute Lisp code. */ |
974 | 974 |
975 void | 975 void |
976 x_activate_menubar (f) | 976 x_activate_menubar (f) |
977 FRAME_PTR f; | 977 FRAME_PTR f; |
978 { | 978 { |
979 SInt32 menu_choice; | 979 SInt32 menu_choice; |
1180 wv->button_type = BUTTON_TYPE_NONE; | 1180 wv->button_type = BUTTON_TYPE_NONE; |
1181 wv->help = Qnil; | 1181 wv->help = Qnil; |
1182 first_wv = wv; | 1182 first_wv = wv; |
1183 save_wv = 0; | 1183 save_wv = 0; |
1184 prev_wv = 0; | 1184 prev_wv = 0; |
1185 | 1185 |
1186 /* Loop over all panes and items made during this call | 1186 /* Loop over all panes and items made during this call |
1187 and construct a tree of widget_value objects. | 1187 and construct a tree of widget_value objects. |
1188 Ignore the panes and items made by previous calls to | 1188 Ignore the panes and items made by previous calls to |
1189 single_submenu, even though those are also in menu_items. */ | 1189 single_submenu, even though those are also in menu_items. */ |
1190 i = previous_items; | 1190 i = previous_items; |
1284 AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY) = descrip; | 1284 AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY) = descrip; |
1285 } | 1285 } |
1286 #endif /* not HAVE_MULTILINGUAL_MENU */ | 1286 #endif /* not HAVE_MULTILINGUAL_MENU */ |
1287 | 1287 |
1288 wv = xmalloc_widget_value (); | 1288 wv = xmalloc_widget_value (); |
1289 if (prev_wv) | 1289 if (prev_wv) |
1290 prev_wv->next = wv; | 1290 prev_wv->next = wv; |
1291 else | 1291 else |
1292 save_wv->contents = wv; | 1292 save_wv->contents = wv; |
1293 | 1293 |
1294 wv->name = (char *) SDATA (item_name); | 1294 wv->name = (char *) SDATA (item_name); |
1430 maps = XVECTOR (items)->contents[i + 2]; | 1430 maps = XVECTOR (items)->contents[i + 2]; |
1431 if (NILP (string)) | 1431 if (NILP (string)) |
1432 break; | 1432 break; |
1433 | 1433 |
1434 wv = single_submenu (key, string, maps); | 1434 wv = single_submenu (key, string, maps); |
1435 if (prev_wv) | 1435 if (prev_wv) |
1436 prev_wv->next = wv; | 1436 prev_wv->next = wv; |
1437 else | 1437 else |
1438 first_wv->contents = wv; | 1438 first_wv->contents = wv; |
1439 /* Don't set wv->name here; GC during the loop might relocate it. */ | 1439 /* Don't set wv->name here; GC during the loop might relocate it. */ |
1440 wv->enabled = 1; | 1440 wv->enabled = 1; |
1506 menu item is really supposed to be empty. */ | 1506 menu item is really supposed to be empty. */ |
1507 /* The EMACS_INT cast avoids a warning. | 1507 /* The EMACS_INT cast avoids a warning. |
1508 This value just has to be different from small integers. */ | 1508 This value just has to be different from small integers. */ |
1509 wv->call_data = (void *) (EMACS_INT) (-1); | 1509 wv->call_data = (void *) (EMACS_INT) (-1); |
1510 | 1510 |
1511 if (prev_wv) | 1511 if (prev_wv) |
1512 prev_wv->next = wv; | 1512 prev_wv->next = wv; |
1513 else | 1513 else |
1514 first_wv->contents = wv; | 1514 first_wv->contents = wv; |
1515 prev_wv = wv; | 1515 prev_wv = wv; |
1516 } | 1516 } |
1535 { | 1535 { |
1536 DeleteMenu (i); | 1536 DeleteMenu (i); |
1537 DisposeMenu (menu); | 1537 DisposeMenu (menu); |
1538 menu = GetMenuHandle (++i); | 1538 menu = GetMenuHandle (++i); |
1539 } | 1539 } |
1540 | 1540 |
1541 i = MIN_SUBMENU_ID; | 1541 i = MIN_SUBMENU_ID; |
1542 menu = GetMenuHandle (i); | 1542 menu = GetMenuHandle (i); |
1543 while (menu != NULL) | 1543 while (menu != NULL) |
1544 { | 1544 { |
1545 DeleteMenu (i); | 1545 DeleteMenu (i); |
1547 menu = GetMenuHandle (++i); | 1547 menu = GetMenuHandle (++i); |
1548 } | 1548 } |
1549 } | 1549 } |
1550 | 1550 |
1551 fill_menubar (first_wv->contents); | 1551 fill_menubar (first_wv->contents); |
1552 | 1552 |
1553 DrawMenuBar (); | 1553 DrawMenuBar (); |
1554 | 1554 |
1555 free_menubar_widget_value_tree (first_wv); | 1555 free_menubar_widget_value_tree (first_wv); |
1556 | 1556 |
1557 UNBLOCK_INPUT; | 1557 UNBLOCK_INPUT; |
1558 } | 1558 } |
1559 | 1559 |
1638 wv->enabled = 1; | 1638 wv->enabled = 1; |
1639 wv->button_type = BUTTON_TYPE_NONE; | 1639 wv->button_type = BUTTON_TYPE_NONE; |
1640 wv->help = Qnil; | 1640 wv->help = Qnil; |
1641 first_wv = wv; | 1641 first_wv = wv; |
1642 first_pane = 1; | 1642 first_pane = 1; |
1643 | 1643 |
1644 /* Loop over all panes and items, filling in the tree. */ | 1644 /* Loop over all panes and items, filling in the tree. */ |
1645 i = 0; | 1645 i = 0; |
1646 while (i < menu_items_used) | 1646 while (i < menu_items_used) |
1647 { | 1647 { |
1648 if (EQ (XVECTOR (menu_items)->contents[i], Qnil)) | 1648 if (EQ (XVECTOR (menu_items)->contents[i], Qnil)) |
1741 AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY) = descrip; | 1741 AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY) = descrip; |
1742 } | 1742 } |
1743 #endif /* not HAVE_MULTILINGUAL_MENU */ | 1743 #endif /* not HAVE_MULTILINGUAL_MENU */ |
1744 | 1744 |
1745 wv = xmalloc_widget_value (); | 1745 wv = xmalloc_widget_value (); |
1746 if (prev_wv) | 1746 if (prev_wv) |
1747 prev_wv->next = wv; | 1747 prev_wv->next = wv; |
1748 else | 1748 else |
1749 save_wv->contents = wv; | 1749 save_wv->contents = wv; |
1750 wv->name = (char *) SDATA (item_name); | 1750 wv->name = (char *) SDATA (item_name); |
1751 if (!NILP (descrip)) | 1751 if (!NILP (descrip)) |
1752 wv->key = (char *) SDATA (descrip); | 1752 wv->key = (char *) SDATA (descrip); |
1753 wv->value = 0; | 1753 wv->value = 0; |
1828 /* Display the menu. */ | 1828 /* Display the menu. */ |
1829 menu_item_choice = PopUpMenuSelect (menu, pos.v, pos.h, 0); | 1829 menu_item_choice = PopUpMenuSelect (menu, pos.v, pos.h, 0); |
1830 menu_item_selection = LoWord (menu_item_choice); | 1830 menu_item_selection = LoWord (menu_item_choice); |
1831 | 1831 |
1832 /* Get the refcon to find the correct item*/ | 1832 /* Get the refcon to find the correct item*/ |
1833 if (menu_item_selection) | 1833 if (menu_item_selection) |
1834 { | 1834 { |
1835 menu = GetMenuHandle (HiWord (menu_item_choice)); | 1835 menu = GetMenuHandle (HiWord (menu_item_choice)); |
1836 if (menu) { | 1836 if (menu) { |
1837 GetMenuItemRefCon (menu, menu_item_selection, &refcon); | 1837 GetMenuItemRefCon (menu, menu_item_selection, &refcon); |
1838 } | 1838 } |
1839 } | 1839 } |
1840 | 1840 |
1841 #if 0 | 1841 #if 0 |
1842 /* Clean up extraneous mouse events which might have been generated | 1842 /* Clean up extraneous mouse events which might have been generated |
1843 during the call. */ | 1843 during the call. */ |
1844 discard_mouse_events (); | 1844 discard_mouse_events (); |
1845 #endif | 1845 #endif |
1942 int left; | 1942 int left; |
1943 EventRecord event_record; | 1943 EventRecord event_record; |
1944 SInt16 part_code; | 1944 SInt16 part_code; |
1945 int control_part_code; | 1945 int control_part_code; |
1946 Point mouse; | 1946 Point mouse; |
1947 | 1947 |
1948 dialog_name = wv->name; | 1948 dialog_name = wv->name; |
1949 nb_buttons = dialog_name[1] - '0'; | 1949 nb_buttons = dialog_name[1] - '0'; |
1950 left_count = nb_buttons - (dialog_name[4] - '0'); | 1950 left_count = nb_buttons - (dialog_name[4] - '0'); |
1951 button_labels = (char **) alloca (sizeof (char *) * nb_buttons); | 1951 button_labels = (char **) alloca (sizeof (char *) * nb_buttons); |
1952 ref_cons = (UInt32 *) alloca (sizeof (UInt32) * nb_buttons); | 1952 ref_cons = (UInt32 *) alloca (sizeof (UInt32) * nb_buttons); |
1953 | 1953 |
1954 wv = wv->contents; | 1954 wv = wv->contents; |
1955 prompt = (char *) alloca (strlen (wv->value) + 1); | 1955 prompt = (char *) alloca (strlen (wv->value) + 1); |
1956 strcpy (prompt, wv->value); | 1956 strcpy (prompt, wv->value); |
1957 c2pstr (prompt); | 1957 c2pstr (prompt); |
1958 | 1958 |
1972 #if TARGET_API_MAC_CARBON | 1972 #if TARGET_API_MAC_CARBON |
1973 SetPort (GetWindowPort (window_ptr)); | 1973 SetPort (GetWindowPort (window_ptr)); |
1974 #else | 1974 #else |
1975 SetPort (window_ptr); | 1975 SetPort (window_ptr); |
1976 #endif | 1976 #endif |
1977 | 1977 |
1978 TextFont (0); | 1978 TextFont (0); |
1979 /* Left and right margins in the dialog are 13 pixels each.*/ | 1979 /* Left and right margins in the dialog are 13 pixels each.*/ |
1980 dialog_width = 14; | 1980 dialog_width = 14; |
1981 /* Calculate width of dialog box: 8 pixels on each side of the text | 1981 /* Calculate width of dialog box: 8 pixels on each side of the text |
1982 label in each button, 12 pixels between buttons. */ | 1982 label in each button, 12 pixels between buttons. */ |
1994 #if TARGET_API_MAC_CARBON | 1994 #if TARGET_API_MAC_CARBON |
1995 SetPort (GetWindowPort (window_ptr)); | 1995 SetPort (GetWindowPort (window_ptr)); |
1996 #else | 1996 #else |
1997 SetPort (window_ptr); | 1997 SetPort (window_ptr); |
1998 #endif | 1998 #endif |
1999 | 1999 |
2000 TextFont (0); | 2000 TextFont (0); |
2001 | 2001 |
2002 MoveTo (13, 29); | 2002 MoveTo (13, 29); |
2003 DrawString (prompt); | 2003 DrawString (prompt); |
2004 | 2004 |
2032 } | 2032 } |
2033 } | 2033 } |
2034 } | 2034 } |
2035 | 2035 |
2036 DisposeWindow (window_ptr); | 2036 DisposeWindow (window_ptr); |
2037 | 2037 |
2038 return i; | 2038 return i; |
2039 } | 2039 } |
2040 | 2040 |
2041 static char * button_names [] = { | 2041 static char * button_names [] = { |
2042 "button1", "button2", "button3", "button4", "button5", | 2042 "button1", "button2", "button3", "button4", "button5", |
2074 Lisp_Object pane_name, prefix; | 2074 Lisp_Object pane_name, prefix; |
2075 char *pane_string; | 2075 char *pane_string; |
2076 pane_name = XVECTOR (menu_items)->contents[MENU_ITEMS_PANE_NAME]; | 2076 pane_name = XVECTOR (menu_items)->contents[MENU_ITEMS_PANE_NAME]; |
2077 prefix = XVECTOR (menu_items)->contents[MENU_ITEMS_PANE_PREFIX]; | 2077 prefix = XVECTOR (menu_items)->contents[MENU_ITEMS_PANE_PREFIX]; |
2078 pane_string = (NILP (pane_name) | 2078 pane_string = (NILP (pane_name) |
2079 ? "" : (char *) SDATA (pane_name)); | 2079 ? "" : (char *) SDATA (pane_name)); |
2080 prev_wv = xmalloc_widget_value (); | 2080 prev_wv = xmalloc_widget_value (); |
2081 prev_wv->value = pane_string; | 2081 prev_wv->value = pane_string; |
2082 if (keymaps && !NILP (prefix)) | 2082 if (keymaps && !NILP (prefix)) |
2083 prev_wv->name++; | 2083 prev_wv->name++; |
2084 prev_wv->enabled = 1; | 2084 prev_wv->enabled = 1; |
2085 prev_wv->name = "message"; | 2085 prev_wv->name = "message"; |
2086 prev_wv->help = Qnil; | 2086 prev_wv->help = Qnil; |
2087 first_wv = prev_wv; | 2087 first_wv = prev_wv; |
2088 | 2088 |
2089 /* Loop over all panes and items, filling in the tree. */ | 2089 /* Loop over all panes and items, filling in the tree. */ |
2090 i = MENU_ITEMS_PANE_LENGTH; | 2090 i = MENU_ITEMS_PANE_LENGTH; |
2091 while (i < menu_items_used) | 2091 while (i < menu_items_used) |
2092 { | 2092 { |
2093 | 2093 |
2094 /* Create a new item within current pane. */ | 2094 /* Create a new item within current pane. */ |
2095 Lisp_Object item_name, enable, descrip, help; | 2095 Lisp_Object item_name, enable, descrip, help; |
2096 | 2096 |
2097 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME]; | 2097 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME]; |
2098 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE]; | 2098 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE]; |
2099 descrip | 2099 descrip |
2100 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY]; | 2100 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY]; |
2101 help = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_HELP]; | 2101 help = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_HELP]; |
2102 | 2102 |
2103 if (NILP (item_name)) | 2103 if (NILP (item_name)) |
2104 { | 2104 { |
2105 free_menubar_widget_value_tree (first_wv); | 2105 free_menubar_widget_value_tree (first_wv); |
2106 *error = "Submenu in dialog items"; | 2106 *error = "Submenu in dialog items"; |
2107 return Qnil; | 2107 return Qnil; |
2238 Str255 item_name; | 2238 Str255 item_name; |
2239 int pos, i; | 2239 int pos, i; |
2240 | 2240 |
2241 if (name_is_separator (wv->name)) | 2241 if (name_is_separator (wv->name)) |
2242 AppendMenu (menu, "\p-"); | 2242 AppendMenu (menu, "\p-"); |
2243 else | 2243 else |
2244 { | 2244 { |
2245 AppendMenu (menu, "\pX"); | 2245 AppendMenu (menu, "\pX"); |
2246 | 2246 |
2247 #if TARGET_API_MAC_CARBON | 2247 #if TARGET_API_MAC_CARBON |
2248 pos = CountMenuItems (menu); | 2248 pos = CountMenuItems (menu); |
2249 #else | 2249 #else |
2250 pos = CountMItems (menu); | 2250 pos = CountMItems (menu); |
2251 #endif | 2251 #endif |
2338 | 2338 |
2339 for (id = MIN_MENU_ID; wv != NULL; wv = wv->next, id++) | 2339 for (id = MIN_MENU_ID; wv != NULL; wv = wv->next, id++) |
2340 { | 2340 { |
2341 MenuHandle menu; | 2341 MenuHandle menu; |
2342 Str255 title; | 2342 Str255 title; |
2343 | 2343 |
2344 strncpy (title, wv->name, 255); | 2344 strncpy (title, wv->name, 255); |
2345 title[255] = 0; | 2345 title[255] = 0; |
2346 c2pstr (title); | 2346 c2pstr (title); |
2347 menu = NewMenu (id, title); | 2347 menu = NewMenu (id, title); |
2348 | 2348 |
2349 if (wv->contents) | 2349 if (wv->contents) |
2350 fill_menu (menu, wv->contents); | 2350 fill_menu (menu, wv->contents); |
2351 | 2351 |
2352 InsertMenu (menu, 0); | 2352 InsertMenu (menu, 0); |
2353 } | 2353 } |
2354 } | 2354 } |
2355 | 2355 |
2356 #endif /* HAVE_MENUS */ | 2356 #endif /* HAVE_MENUS */ |