aboutsummaryrefslogtreecommitdiffstats
path: root/src/xmenu.c
diff options
context:
space:
mode:
authorDmitry Antipov2014-06-02 22:01:21 +0400
committerDmitry Antipov2014-06-02 22:01:21 +0400
commit5668fb88bf3731d39c4e958c8e79a549f789ce1e (patch)
treeb0d3fd3555fca3b34c47b803a633da2f36d31165 /src/xmenu.c
parentda11196a248b530c3b3a8329497d71332f8c71a3 (diff)
downloademacs-5668fb88bf3731d39c4e958c8e79a549f789ce1e.tar.gz
emacs-5668fb88bf3731d39c4e958c8e79a549f789ce1e.zip
Use common memory management functions for lwlib and refactor users.
* lwlib/lwlib.h (widget_value): Do not maintain a free list any more. (malloc_widget_value, free_widget_value): Remove prototypes. * lwlib/lwlib.c (malloc_widget_value, free_widget_value): (widget_value_free_list, malloc_cpt): Remove. (free_widget_value_tree, copy_widget_value_tree): Adjust users. * src/menu.h (xmalloc_widget_value): Replaced by ... (make_widget_value): ... new prototype. * src/menu.c (xmalloc_widget_value): Replaced by ... (make_widget_value): ... new function. (free_menubar_widget_value_tree, digest_single_submenu): Adjust users. * src/gtkutil.c (malloc_widget_value, free_widget_value): (widget_value_free_list, malloc_cpt): Remove old lwlib-compatible code. * src/keyboard.h (enum button_type, struct _widget_value): * src/gtkutil.h, src/nsgui.h, src/w32gui.h (malloc_widget_value): (free_widget_value): Likewise. * src/nsmenu.m (ns_update_menubar, ns_menu_show): * src/w32menu.c (set_frame_menubar, w32_menu_show, w32_dialog_show): * src/xmenu.c (set_frame_menubar, xmenu_show, x_dialog_show): Adjust users. * src/xterm.h (XtParent) [USE_GTK]: Remove unused macro.
Diffstat (limited to 'src/xmenu.c')
-rw-r--r--src/xmenu.c74
1 files changed, 16 insertions, 58 deletions
diff --git a/src/xmenu.c b/src/xmenu.c
index 683e9c6cd90..c167eaa8159 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -882,12 +882,8 @@ set_frame_menubar (struct frame *f, bool first_time, bool deep_p)
882 /* Convert menu_items into widget_value trees 882 /* Convert menu_items into widget_value trees
883 to display the menu. This cannot evaluate Lisp code. */ 883 to display the menu. This cannot evaluate Lisp code. */
884 884
885 wv = xmalloc_widget_value (); 885 wv = make_widget_value ("menubar", NULL, true, Qnil);
886 wv->name = "menubar";
887 wv->value = 0;
888 wv->enabled = 1;
889 wv->button_type = BUTTON_TYPE_NONE; 886 wv->button_type = BUTTON_TYPE_NONE;
890 wv->help = Qnil;
891 first_wv = wv; 887 first_wv = wv;
892 888
893 for (i = 0; submenu_start[i] >= 0; i++) 889 for (i = 0; submenu_start[i] >= 0; i++)
@@ -952,12 +948,8 @@ set_frame_menubar (struct frame *f, bool first_time, bool deep_p)
952 /* Make a widget-value tree containing 948 /* Make a widget-value tree containing
953 just the top level menu bar strings. */ 949 just the top level menu bar strings. */
954 950
955 wv = xmalloc_widget_value (); 951 wv = make_widget_value ("menubar", NULL, true, Qnil);
956 wv->name = "menubar";
957 wv->value = 0;
958 wv->enabled = 1;
959 wv->button_type = BUTTON_TYPE_NONE; 952 wv->button_type = BUTTON_TYPE_NONE;
960 wv->help = Qnil;
961 first_wv = wv; 953 first_wv = wv;
962 954
963 items = FRAME_MENU_BAR_ITEMS (f); 955 items = FRAME_MENU_BAR_ITEMS (f);
@@ -969,12 +961,8 @@ set_frame_menubar (struct frame *f, bool first_time, bool deep_p)
969 if (NILP (string)) 961 if (NILP (string))
970 break; 962 break;
971 963
972 wv = xmalloc_widget_value (); 964 wv = make_widget_value (SSDATA (string), NULL, true, Qnil);
973 wv->name = SSDATA (string);
974 wv->value = 0;
975 wv->enabled = 1;
976 wv->button_type = BUTTON_TYPE_NONE; 965 wv->button_type = BUTTON_TYPE_NONE;
977 wv->help = Qnil;
978 /* This prevents lwlib from assuming this 966 /* This prevents lwlib from assuming this
979 menu item is really supposed to be empty. */ 967 menu item is really supposed to be empty. */
980 /* The intptr_t cast avoids a warning. 968 /* The intptr_t cast avoids a warning.
@@ -1474,12 +1462,8 @@ xmenu_show (struct frame *f, int x, int y, bool for_click, bool keymaps,
1474 1462
1475 /* Create a tree of widget_value objects 1463 /* Create a tree of widget_value objects
1476 representing the panes and their items. */ 1464 representing the panes and their items. */
1477 wv = xmalloc_widget_value (); 1465 wv = make_widget_value ("menu", NULL, true, Qnil);
1478 wv->name = "menu";
1479 wv->value = 0;
1480 wv->enabled = 1;
1481 wv->button_type = BUTTON_TYPE_NONE; 1466 wv->button_type = BUTTON_TYPE_NONE;
1482 wv->help =Qnil;
1483 first_wv = wv; 1467 first_wv = wv;
1484 first_pane = 1; 1468 first_pane = 1;
1485 1469
@@ -1537,18 +1521,14 @@ xmenu_show (struct frame *f, int x, int y, bool for_click, bool keymaps,
1537 with its items as a submenu beneath it. */ 1521 with its items as a submenu beneath it. */
1538 if (!keymaps && strcmp (pane_string, "")) 1522 if (!keymaps && strcmp (pane_string, ""))
1539 { 1523 {
1540 wv = xmalloc_widget_value (); 1524 wv = make_widget_value (pane_string, NULL, true, Qnil);
1541 if (save_wv) 1525 if (save_wv)
1542 save_wv->next = wv; 1526 save_wv->next = wv;
1543 else 1527 else
1544 first_wv->contents = wv; 1528 first_wv->contents = wv;
1545 wv->name = (char *) pane_string;
1546 if (keymaps && !NILP (prefix)) 1529 if (keymaps && !NILP (prefix))
1547 wv->name++; 1530 wv->name++;
1548 wv->value = 0;
1549 wv->enabled = 1;
1550 wv->button_type = BUTTON_TYPE_NONE; 1531 wv->button_type = BUTTON_TYPE_NONE;
1551 wv->help = Qnil;
1552 save_wv = wv; 1532 save_wv = wv;
1553 prev_wv = 0; 1533 prev_wv = 0;
1554 } 1534 }
@@ -1586,20 +1566,18 @@ xmenu_show (struct frame *f, int x, int y, bool for_click, bool keymaps,
1586 } 1566 }
1587#endif /* not HAVE_MULTILINGUAL_MENU */ 1567#endif /* not HAVE_MULTILINGUAL_MENU */
1588 1568
1589 wv = xmalloc_widget_value (); 1569 wv = make_widget_value (SSDATA (item_name), NULL, !NILP (enable),
1570 STRINGP (help) ? help : Qnil);
1590 if (prev_wv) 1571 if (prev_wv)
1591 prev_wv->next = wv; 1572 prev_wv->next = wv;
1592 else 1573 else
1593 save_wv->contents = wv; 1574 save_wv->contents = wv;
1594 wv->name = SSDATA (item_name);
1595 if (!NILP (descrip)) 1575 if (!NILP (descrip))
1596 wv->key = SSDATA (descrip); 1576 wv->key = SSDATA (descrip);
1597 wv->value = 0;
1598 /* If this item has a null value, 1577 /* If this item has a null value,
1599 make the call_data null so that it won't display a box 1578 make the call_data null so that it won't display a box
1600 when the mouse is on it. */ 1579 when the mouse is on it. */
1601 wv->call_data = !NILP (def) ? aref_addr (menu_items, i) : 0; 1580 wv->call_data = !NILP (def) ? aref_addr (menu_items, i) : 0;
1602 wv->enabled = !NILP (enable);
1603 1581
1604 if (NILP (type)) 1582 if (NILP (type))
1605 wv->button_type = BUTTON_TYPE_NONE; 1583 wv->button_type = BUTTON_TYPE_NONE;
@@ -1612,11 +1590,6 @@ xmenu_show (struct frame *f, int x, int y, bool for_click, bool keymaps,
1612 1590
1613 wv->selected = !NILP (selected); 1591 wv->selected = !NILP (selected);
1614 1592
1615 if (! STRINGP (help))
1616 help = Qnil;
1617
1618 wv->help = help;
1619
1620 prev_wv = wv; 1593 prev_wv = wv;
1621 1594
1622 i += MENU_ITEMS_ITEM_LENGTH; 1595 i += MENU_ITEMS_ITEM_LENGTH;
@@ -1626,27 +1599,20 @@ xmenu_show (struct frame *f, int x, int y, bool for_click, bool keymaps,
1626 /* Deal with the title, if it is non-nil. */ 1599 /* Deal with the title, if it is non-nil. */
1627 if (!NILP (title)) 1600 if (!NILP (title))
1628 { 1601 {
1629 widget_value *wv_title = xmalloc_widget_value (); 1602 widget_value *wv_title;
1630 widget_value *wv_sep1 = xmalloc_widget_value (); 1603 widget_value *wv_sep1 = make_widget_value ("--", NULL, false, Qnil);
1631 widget_value *wv_sep2 = xmalloc_widget_value (); 1604 widget_value *wv_sep2 = make_widget_value ("--", NULL, false, Qnil);
1632 1605
1633 wv_sep2->name = "--";
1634 wv_sep2->next = first_wv->contents; 1606 wv_sep2->next = first_wv->contents;
1635 wv_sep2->help = Qnil;
1636
1637 wv_sep1->name = "--";
1638 wv_sep1->next = wv_sep2; 1607 wv_sep1->next = wv_sep2;
1639 wv_sep1->help = Qnil;
1640 1608
1641#ifndef HAVE_MULTILINGUAL_MENU 1609#ifndef HAVE_MULTILINGUAL_MENU
1642 if (STRING_MULTIBYTE (title)) 1610 if (STRING_MULTIBYTE (title))
1643 title = ENCODE_MENU_STRING (title); 1611 title = ENCODE_MENU_STRING (title);
1644#endif 1612#endif
1645 1613
1646 wv_title->name = SSDATA (title); 1614 wv_title = make_widget_value (SSDATA (title), NULL, true, Qnil);
1647 wv_title->enabled = true;
1648 wv_title->button_type = BUTTON_TYPE_NONE; 1615 wv_title->button_type = BUTTON_TYPE_NONE;
1649 wv_title->help = Qnil;
1650 wv_title->next = wv_sep1; 1616 wv_title->next = wv_sep1;
1651 first_wv->contents = wv_title; 1617 first_wv->contents = wv_title;
1652 } 1618 }
@@ -1867,11 +1833,7 @@ x_dialog_show (struct frame *f, Lisp_Object title,
1867 pane_name = AREF (menu_items, MENU_ITEMS_PANE_NAME); 1833 pane_name = AREF (menu_items, MENU_ITEMS_PANE_NAME);
1868 pane_string = (NILP (pane_name) 1834 pane_string = (NILP (pane_name)
1869 ? "" : SSDATA (pane_name)); 1835 ? "" : SSDATA (pane_name));
1870 prev_wv = xmalloc_widget_value (); 1836 prev_wv = make_widget_value ("message", (char *) pane_string, true, Qnil);
1871 prev_wv->value = (char *) pane_string;
1872 prev_wv->enabled = 1;
1873 prev_wv->name = "message";
1874 prev_wv->help = Qnil;
1875 first_wv = prev_wv; 1837 first_wv = prev_wv;
1876 1838
1877 /* Loop over all panes and items, filling in the tree. */ 1839 /* Loop over all panes and items, filling in the tree. */
@@ -1907,15 +1869,13 @@ x_dialog_show (struct frame *f, Lisp_Object title,
1907 return Qnil; 1869 return Qnil;
1908 } 1870 }
1909 1871
1910 wv = xmalloc_widget_value (); 1872 wv = make_widget_value (button_names[nb_buttons],
1873 SSDATA (item_name),
1874 !NILP (enable), Qnil);
1911 prev_wv->next = wv; 1875 prev_wv->next = wv;
1912 wv->name = (char *) button_names[nb_buttons];
1913 if (!NILP (descrip)) 1876 if (!NILP (descrip))
1914 wv->key = SSDATA (descrip); 1877 wv->key = SSDATA (descrip);
1915 wv->value = SSDATA (item_name);
1916 wv->call_data = aref_addr (menu_items, i); 1878 wv->call_data = aref_addr (menu_items, i);
1917 wv->enabled = !NILP (enable);
1918 wv->help = Qnil;
1919 prev_wv = wv; 1879 prev_wv = wv;
1920 1880
1921 if (! boundary_seen) 1881 if (! boundary_seen)
@@ -1930,9 +1890,7 @@ x_dialog_show (struct frame *f, Lisp_Object title,
1930 if (! boundary_seen) 1890 if (! boundary_seen)
1931 left_count = nb_buttons - nb_buttons / 2; 1891 left_count = nb_buttons - nb_buttons / 2;
1932 1892
1933 wv = xmalloc_widget_value (); 1893 wv = make_widget_value (dialog_name, NULL, false, Qnil);
1934 wv->name = dialog_name;
1935 wv->help = Qnil;
1936 1894
1937 /* Frame title: 'Q' = Question, 'I' = Information. 1895 /* Frame title: 'Q' = Question, 'I' = Information.
1938 Can also have 'E' = Error if, one day, we want 1896 Can also have 'E' = Error if, one day, we want