gtk_widget_set_state() with GNOME generated menus.



Lately I have noticed that many gnome developers neglect to disable menu
items that arent usable. Cut/Copy/Paste is one of the best examples.
Paste is usually enabled even when there is nothing on the clipboard. I
assume this is because most gnome programs use the gnome menu builder,
which doesnt exactly co-operate well with finding GtkMenuItem's. In my
current application (http://gCatalog.sourceforge.net), I really wanted
to use the gnome menu builder, but I also wanted to be able to
de-activate some menu items according to some settings in a config file.
I was able to make pointers the the menu items by doing the following:

(GtkMenuBar *)menu_bar = GTK_MENU_BAR(GNOME_APP(window)->menubar);
// "File" is the first menu
(GtkMenuItem *)filemenu =
GTK_MENU_ITEM(GTK_MENU_BAR(menu_bar)->menu_shell.children->data);
// and "Edit" is the second
(GtkMenuItem *)editmenu =
GTK_MENU_ITEM(GTK_MENU_BAR(menu_bar)->menu_shell.children->next->data);
// dont get the very first menu item, because it is the little ---------
thing, which we dont want, so skip 1 item
(GtkPixmapMenuItem *)edit_menu_change =
GTK_PIXMAP_MENU_ITEM(GTK_MENU_SHELL(GTK_MENU_ITEM(editmenu)->submenu)->children->next->data);



if you continue to add a '->next' to the end of the last line (right
before the ->data), you can get pointers to each of the menu items for
use with all kinds of other gtk functions.

Not sure if anyone had ever documented this, but I thought it would be a
good idea to have it in the faq or at least in the list archives.

Cheers...
Chicane



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]