diff options
| author | Jan Djärv | 2003-11-02 16:47:32 +0000 |
|---|---|---|
| committer | Jan Djärv | 2003-11-02 16:47:32 +0000 |
| commit | da18b5acc8fd71658b8051ffc889314fe98132e8 (patch) | |
| tree | ad902bd9fd2042d67c692967e1ae2f36de9a730e /src | |
| parent | 10695e5cbcc795614b8585fda05bc14da278a4af (diff) | |
| download | emacs-da18b5acc8fd71658b8051ffc889314fe98132e8.tar.gz emacs-da18b5acc8fd71658b8051ffc889314fe98132e8.zip | |
Remove tear off capability for GTK popup menus.
Since the context in Lisp is not present anymore, we don't know
how to invoke the action for a menu item.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 27 | ||||
| -rw-r--r-- | src/gtkutil.c | 97 | ||||
| -rw-r--r-- | src/gtkutil.h | 8 | ||||
| -rw-r--r-- | src/xmenu.c | 14 |
4 files changed, 80 insertions, 66 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index b2f44c8573a..e30f54ba66c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,30 @@ | |||
| 1 | 2003-11-02 Jan Dj,Ad(Brv <jan.h.d@swipnet.se> | ||
| 2 | |||
| 3 | * gtkutil.h: Declare xg_have_tear_offs, remove xg_keep_popup | ||
| 4 | and xg_did_tearoff. | ||
| 5 | |||
| 6 | * gtkutil.c: Remove variable xg_did_tearoff. | ||
| 7 | (xg_have_tear_offs): New function. | ||
| 8 | (tearoff_remove): Just decrease xg_detached_menus. | ||
| 9 | (tearoff_activate): Increase xg_detached_menus and call | ||
| 10 | tearoff_remove when tearoff is removed. | ||
| 11 | (xg_keep_popup): Removed function. | ||
| 12 | (create_menus): Give add_tearoff_p as argument to recursive | ||
| 13 | call to create_menus. | ||
| 14 | (xg_create_widget): Use variables instead of multiple | ||
| 15 | strcmp. Tell create_menus to create tear off only for | ||
| 16 | menu bar menus. | ||
| 17 | (xg_update_menubar): Change title for a detached menu also. | ||
| 18 | (xg_modify_menubar_widgets): Always call xg_update_menubar, regardless | ||
| 19 | of deep_p. | ||
| 20 | (xg_initialize): Initialize xg_detached_menus, remove | ||
| 21 | initialization of xg_did_tearoff. | ||
| 22 | |||
| 23 | * xmenu.c (set_frame_menubar): For GTK, set deep_p if | ||
| 24 | xg_have_tear_offs returns non-zero. | ||
| 25 | (create_and_show_popup_menu): Remove setting of xg_did_tearoff and | ||
| 26 | call to xg_keep_popup. | ||
| 27 | |||
| 1 | 2003-11-01 Andrew Choi <akochoi@shaw.ca> | 28 | 2003-11-01 Andrew Choi <akochoi@shaw.ca> |
| 2 | 29 | ||
| 3 | * macterm.c (XTread_socket): Handle menubar selection and grow | 30 | * macterm.c (XTread_socket): Handle menubar selection and grow |
diff --git a/src/gtkutil.c b/src/gtkutil.c index b305d1c15a0..b37e69481b8 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c | |||
| @@ -1333,27 +1333,29 @@ xg_separator_p (char *label) | |||
| 1333 | return 0; | 1333 | return 0; |
| 1334 | } | 1334 | } |
| 1335 | 1335 | ||
| 1336 | GtkWidget *xg_did_tearoff; | 1336 | static int xg_detached_menus; |
| 1337 | |||
| 1338 | /* Returns non-zero if there are detached menus. */ | ||
| 1339 | int | ||
| 1340 | xg_have_tear_offs () | ||
| 1341 | { | ||
| 1342 | return xg_detached_menus > 0; | ||
| 1343 | } | ||
| 1337 | 1344 | ||
| 1338 | /* Callback invoked when a detached menu window is removed. Here we | 1345 | /* Callback invoked when a detached menu window is removed. Here we |
| 1339 | delete the popup menu. | 1346 | decrease the xg_detached_menus count. |
| 1340 | WIDGET is the top level window that is removed (the parent of the menu). | 1347 | WIDGET is the top level window that is removed (the parent of the menu). |
| 1341 | EVENT is the event that triggers the window removal. | 1348 | CLIENT_DATA is not used. */ |
| 1342 | CLIENT_DATA points to the menu that is detached. | 1349 | static void |
| 1343 | 1350 | tearoff_remove (widget, client_data) | |
| 1344 | Returns TRUE to tell GTK to stop processing this event. */ | ||
| 1345 | static gboolean | ||
| 1346 | tearoff_remove (widget, event, client_data) | ||
| 1347 | GtkWidget *widget; | 1351 | GtkWidget *widget; |
| 1348 | GdkEvent *event; | ||
| 1349 | gpointer client_data; | 1352 | gpointer client_data; |
| 1350 | { | 1353 | { |
| 1351 | gtk_widget_destroy (GTK_WIDGET (client_data)); | 1354 | if (xg_detached_menus > 0) --xg_detached_menus; |
| 1352 | return TRUE; | ||
| 1353 | } | 1355 | } |
| 1354 | 1356 | ||
| 1355 | /* Callback invoked when a menu is detached. It sets the xg_did_tearoff | 1357 | /* Callback invoked when a menu is detached. It increases the |
| 1356 | variable. | 1358 | xg_detached_menus count. |
| 1357 | WIDGET is the GtkTearoffMenuItem. | 1359 | WIDGET is the GtkTearoffMenuItem. |
| 1358 | CLIENT_DATA is not used. */ | 1360 | CLIENT_DATA is not used. */ |
| 1359 | static void | 1361 | static void |
| @@ -1362,31 +1364,15 @@ tearoff_activate (widget, client_data) | |||
| 1362 | gpointer client_data; | 1364 | gpointer client_data; |
| 1363 | { | 1365 | { |
| 1364 | GtkWidget *menu = gtk_widget_get_parent (widget); | 1366 | GtkWidget *menu = gtk_widget_get_parent (widget); |
| 1365 | if (! gtk_menu_get_tearoff_state (GTK_MENU (menu))) | 1367 | if (gtk_menu_get_tearoff_state (GTK_MENU (menu))) |
| 1366 | return; | 1368 | { |
| 1367 | 1369 | ++xg_detached_menus; | |
| 1368 | xg_did_tearoff = menu; | 1370 | g_signal_connect (G_OBJECT (gtk_widget_get_toplevel (widget)), |
| 1371 | "destroy", | ||
| 1372 | G_CALLBACK (tearoff_remove), 0); | ||
| 1373 | } | ||
| 1369 | } | 1374 | } |
| 1370 | 1375 | ||
| 1371 | /* If a detach of a popup menu is done, this function should be called | ||
| 1372 | to keep the menu around until the detached window is removed. | ||
| 1373 | MENU is the top level menu for the popup, | ||
| 1374 | SUBMENU is the menu that got detached (that is MENU or a | ||
| 1375 | submenu of MENU), see the xg_did_tearoff variable. */ | ||
| 1376 | void | ||
| 1377 | xg_keep_popup (menu, submenu) | ||
| 1378 | GtkWidget *menu; | ||
| 1379 | GtkWidget *submenu; | ||
| 1380 | { | ||
| 1381 | GtkWidget *p; | ||
| 1382 | |||
| 1383 | /* Find the top widget for the detached menu. */ | ||
| 1384 | p = gtk_widget_get_toplevel (submenu); | ||
| 1385 | |||
| 1386 | /* Delay destroying the menu until the detached menu is removed. */ | ||
| 1387 | g_signal_connect (G_OBJECT (p), "unmap_event", | ||
| 1388 | G_CALLBACK (tearoff_remove), menu); | ||
| 1389 | } | ||
| 1390 | 1376 | ||
| 1391 | /* Create a menu item widget, and connect the callbacks. | 1377 | /* Create a menu item widget, and connect the callbacks. |
| 1392 | ITEM decribes the menu item. | 1378 | ITEM decribes the menu item. |
| @@ -1585,7 +1571,7 @@ create_menus (data, f, select_cb, deactivate_cb, highlight_cb, | |||
| 1585 | highlight_cb, | 1571 | highlight_cb, |
| 1586 | 0, | 1572 | 0, |
| 1587 | 0, | 1573 | 0, |
| 1588 | 1, | 1574 | add_tearoff_p, |
| 1589 | 0, | 1575 | 0, |
| 1590 | cl_data, | 1576 | cl_data, |
| 1591 | 0); | 1577 | 0); |
| @@ -1626,6 +1612,9 @@ xg_create_widget (type, name, f, val, | |||
| 1626 | GCallback highlight_cb; | 1612 | GCallback highlight_cb; |
| 1627 | { | 1613 | { |
| 1628 | GtkWidget *w = 0; | 1614 | GtkWidget *w = 0; |
| 1615 | int menu_bar_p = strcmp (type, "menubar") == 0; | ||
| 1616 | int pop_up_p = strcmp (type, "popup") == 0; | ||
| 1617 | |||
| 1629 | if (strcmp (type, "dialog") == 0) | 1618 | if (strcmp (type, "dialog") == 0) |
| 1630 | { | 1619 | { |
| 1631 | w = create_dialog (val, select_cb, deactivate_cb); | 1620 | w = create_dialog (val, select_cb, deactivate_cb); |
| @@ -1636,23 +1625,23 @@ xg_create_widget (type, name, f, val, | |||
| 1636 | if (w) | 1625 | if (w) |
| 1637 | gtk_widget_set_name (w, "emacs-dialog"); | 1626 | gtk_widget_set_name (w, "emacs-dialog"); |
| 1638 | } | 1627 | } |
| 1639 | else if (strcmp (type, "menubar") == 0 || strcmp (type, "popup") == 0) | 1628 | else if (menu_bar_p || pop_up_p) |
| 1640 | { | 1629 | { |
| 1641 | w = create_menus (val->contents, | 1630 | w = create_menus (val->contents, |
| 1642 | f, | 1631 | f, |
| 1643 | select_cb, | 1632 | select_cb, |
| 1644 | deactivate_cb, | 1633 | deactivate_cb, |
| 1645 | highlight_cb, | 1634 | highlight_cb, |
| 1646 | strcmp (type, "popup") == 0, | 1635 | pop_up_p, |
| 1647 | strcmp (type, "menubar") == 0, | 1636 | menu_bar_p, |
| 1648 | 1, | 1637 | menu_bar_p, |
| 1649 | 0, | 1638 | 0, |
| 1650 | 0, | 1639 | 0, |
| 1651 | name); | 1640 | name); |
| 1652 | 1641 | ||
| 1653 | /* Set the cursor to an arrow for popup menus when they are mapped. | 1642 | /* Set the cursor to an arrow for popup menus when they are mapped. |
| 1654 | This is done by default for menu bar menus. */ | 1643 | This is done by default for menu bar menus. */ |
| 1655 | if (strcmp (type, "popup") == 0) | 1644 | if (pop_up_p) |
| 1656 | { | 1645 | { |
| 1657 | /* Must realize so the GdkWindow inside the widget is created. */ | 1646 | /* Must realize so the GdkWindow inside the widget is created. */ |
| 1658 | gtk_widget_realize (w); | 1647 | gtk_widget_realize (w); |
| @@ -1834,9 +1823,16 @@ xg_update_menubar (menubar, f, list, iter, pos, val, | |||
| 1834 | is up to date when leaving the minibuffer. */ | 1823 | is up to date when leaving the minibuffer. */ |
| 1835 | GtkLabel *wlabel = GTK_LABEL (gtk_bin_get_child (GTK_BIN (witem))); | 1824 | GtkLabel *wlabel = GTK_LABEL (gtk_bin_get_child (GTK_BIN (witem))); |
| 1836 | char *utf8_label = get_utf8_string (val->name); | 1825 | char *utf8_label = get_utf8_string (val->name); |
| 1826 | GtkWidget *submenu = gtk_menu_item_get_submenu (witem); | ||
| 1837 | 1827 | ||
| 1838 | gtk_label_set_text (wlabel, utf8_label); | 1828 | gtk_label_set_text (wlabel, utf8_label); |
| 1839 | 1829 | ||
| 1830 | /* If this item has a submenu that has been detached, change | ||
| 1831 | the title in the WM decorations also. */ | ||
| 1832 | if (submenu && gtk_menu_get_tearoff_state (GTK_MENU (submenu))) | ||
| 1833 | /* Set the title of the detached window. */ | ||
| 1834 | gtk_menu_set_title (GTK_MENU (submenu), utf8_label); | ||
| 1835 | |||
| 1840 | iter = g_list_next (iter); | 1836 | iter = g_list_next (iter); |
| 1841 | val = val->next; | 1837 | val = val->next; |
| 1842 | ++pos; | 1838 | ++pos; |
| @@ -2222,18 +2218,15 @@ xg_modify_menubar_widgets (menubar, f, val, deep_p, | |||
| 2222 | cl_data = (xg_menu_cb_data*) g_object_get_data (G_OBJECT (menubar), | 2218 | cl_data = (xg_menu_cb_data*) g_object_get_data (G_OBJECT (menubar), |
| 2223 | XG_FRAME_DATA); | 2219 | XG_FRAME_DATA); |
| 2224 | 2220 | ||
| 2225 | if (! deep_p) | 2221 | xg_update_menubar (menubar, f, &list, list, 0, val->contents, |
| 2226 | { | 2222 | select_cb, highlight_cb, cl_data); |
| 2227 | widget_value *cur = val->contents; | 2223 | |
| 2228 | xg_update_menubar (menubar, f, &list, list, 0, cur, | 2224 | if (deep_p); |
| 2229 | select_cb, highlight_cb, cl_data); | ||
| 2230 | } | ||
| 2231 | else | ||
| 2232 | { | 2225 | { |
| 2233 | widget_value *cur; | 2226 | widget_value *cur; |
| 2234 | 2227 | ||
| 2235 | /* Update all sub menus. | 2228 | /* Update all sub menus. |
| 2236 | We must keep the submenu names (GTK menu item widgets) since the | 2229 | We must keep the submenus (GTK menu item widgets) since the |
| 2237 | X Window in the XEvent that activates the menu are those widgets. */ | 2230 | X Window in the XEvent that activates the menu are those widgets. */ |
| 2238 | 2231 | ||
| 2239 | /* Update cl_data, menu_item things in F may have changed. */ | 2232 | /* Update cl_data, menu_item things in F may have changed. */ |
| @@ -2269,7 +2262,6 @@ xg_modify_menubar_widgets (menubar, f, val, deep_p, | |||
| 2269 | newly created sub menu under witem. */ | 2262 | newly created sub menu under witem. */ |
| 2270 | if (newsub != sub) | 2263 | if (newsub != sub) |
| 2271 | gtk_menu_item_set_submenu (witem, newsub); | 2264 | gtk_menu_item_set_submenu (witem, newsub); |
| 2272 | |||
| 2273 | } | 2265 | } |
| 2274 | } | 2266 | } |
| 2275 | 2267 | ||
| @@ -3250,8 +3242,7 @@ xg_initialize () | |||
| 3250 | { | 3242 | { |
| 3251 | xg_ignore_gtk_scrollbar = 0; | 3243 | xg_ignore_gtk_scrollbar = 0; |
| 3252 | xg_left_ptr_cursor = 0; | 3244 | xg_left_ptr_cursor = 0; |
| 3253 | xg_did_tearoff = 0; | 3245 | xg_detached_menus = 0; |
| 3254 | |||
| 3255 | xg_menu_cb_list.prev = xg_menu_cb_list.next = | 3246 | xg_menu_cb_list.prev = xg_menu_cb_list.next = |
| 3256 | xg_menu_item_cb_list.prev = xg_menu_item_cb_list.next = 0; | 3247 | xg_menu_item_cb_list.prev = xg_menu_item_cb_list.next = 0; |
| 3257 | 3248 | ||
diff --git a/src/gtkutil.h b/src/gtkutil.h index 3ede2f06ae4..5864a334edc 100644 --- a/src/gtkutil.h +++ b/src/gtkutil.h | |||
| @@ -150,7 +150,7 @@ extern void xg_modify_menubar_widgets P_ ((GtkWidget *menubar, | |||
| 150 | 150 | ||
| 151 | extern int xg_update_frame_menubar P_ ((FRAME_PTR f)); | 151 | extern int xg_update_frame_menubar P_ ((FRAME_PTR f)); |
| 152 | 152 | ||
| 153 | extern void xg_keep_popup P_ ((GtkWidget *menu, GtkWidget *submenu)); | 153 | extern int xg_have_tear_offs P_ ((void)); |
| 154 | 154 | ||
| 155 | extern int xg_get_scroll_id_for_window P_ ((Window wid)); | 155 | extern int xg_get_scroll_id_for_window P_ ((Window wid)); |
| 156 | 156 | ||
| @@ -201,12 +201,6 @@ extern void xg_initialize P_ ((void)); | |||
| 201 | to indicate that the callback should do nothing. */ | 201 | to indicate that the callback should do nothing. */ |
| 202 | extern int xg_ignore_gtk_scrollbar; | 202 | extern int xg_ignore_gtk_scrollbar; |
| 203 | 203 | ||
| 204 | /* If a detach of a menu is done, this is the menu widget that got | ||
| 205 | detached. Must be set to NULL before popping up popup menus. | ||
| 206 | Used with xg_keep_popup to delay deleting popup menus when they | ||
| 207 | have been detached. */ | ||
| 208 | extern GtkWidget *xg_did_tearoff; | ||
| 209 | |||
| 210 | #endif /* USE_GTK */ | 204 | #endif /* USE_GTK */ |
| 211 | #endif /* GTKUTIL_H */ | 205 | #endif /* GTKUTIL_H */ |
| 212 | 206 | ||
diff --git a/src/xmenu.c b/src/xmenu.c index 00a796b5312..14f7485759b 100644 --- a/src/xmenu.c +++ b/src/xmenu.c | |||
| @@ -1866,6 +1866,12 @@ set_frame_menubar (f, first_time, deep_p) | |||
| 1866 | f->output_data.x->saved_menu_event->type = 0; | 1866 | f->output_data.x->saved_menu_event->type = 0; |
| 1867 | } | 1867 | } |
| 1868 | 1868 | ||
| 1869 | #ifdef USE_GTK | ||
| 1870 | /* If we have detached menus, we must update deep so detached menus | ||
| 1871 | also gets updated. */ | ||
| 1872 | deep_p = deep_p || xg_have_tear_offs (); | ||
| 1873 | #endif | ||
| 1874 | |||
| 1869 | if (deep_p) | 1875 | if (deep_p) |
| 1870 | { | 1876 | { |
| 1871 | /* Make a widget-value tree representing the entire menu trees. */ | 1877 | /* Make a widget-value tree representing the entire menu trees. */ |
| @@ -2066,7 +2072,7 @@ set_frame_menubar (f, first_time, deep_p) | |||
| 2066 | xg_crazy_callback_abort = 1; | 2072 | xg_crazy_callback_abort = 1; |
| 2067 | if (menubar_widget) | 2073 | if (menubar_widget) |
| 2068 | { | 2074 | { |
| 2069 | /* The third arg is DEEP_P, which says to consider the entire | 2075 | /* The fourth arg is DEEP_P, which says to consider the entire |
| 2070 | menu trees we supply, rather than just the menu bar item names. */ | 2076 | menu trees we supply, rather than just the menu bar item names. */ |
| 2071 | xg_modify_menubar_widgets (menubar_widget, | 2077 | xg_modify_menubar_widgets (menubar_widget, |
| 2072 | f, | 2078 | f, |
| @@ -2343,17 +2349,13 @@ create_and_show_popup_menu (f, first_wv, x, y, for_click) | |||
| 2343 | gtk_widget_show_all (menu); | 2349 | gtk_widget_show_all (menu); |
| 2344 | gtk_menu_popup (GTK_MENU (menu), 0, 0, pos_func, &popup_x_y, i, 0); | 2350 | gtk_menu_popup (GTK_MENU (menu), 0, 0, pos_func, &popup_x_y, i, 0); |
| 2345 | 2351 | ||
| 2346 | xg_did_tearoff = 0; | ||
| 2347 | /* Set this to one. popup_widget_loop increases it by one, so it becomes | 2352 | /* Set this to one. popup_widget_loop increases it by one, so it becomes |
| 2348 | two. show_help_echo uses this to detect popup menus. */ | 2353 | two. show_help_echo uses this to detect popup menus. */ |
| 2349 | popup_activated_flag = 1; | 2354 | popup_activated_flag = 1; |
| 2350 | /* Process events that apply to the menu. */ | 2355 | /* Process events that apply to the menu. */ |
| 2351 | popup_widget_loop (); | 2356 | popup_widget_loop (); |
| 2352 | 2357 | ||
| 2353 | if (xg_did_tearoff) | 2358 | gtk_widget_destroy (menu); |
| 2354 | xg_keep_popup (menu, xg_did_tearoff); | ||
| 2355 | else | ||
| 2356 | gtk_widget_destroy (menu); | ||
| 2357 | 2359 | ||
| 2358 | /* Must reset this manually because the button release event is not passed | 2360 | /* Must reset this manually because the button release event is not passed |
| 2359 | to Emacs event loop. */ | 2361 | to Emacs event loop. */ |