The following code is from listing 9-11 of Foundations of GTK+ Development. Through this book, I've been attempting to migrate any GTK2 specific stuff (or any depreciated code for that matter) to learn what's relevant at the present moment. That said, this generated a lot of warnings on compile.
#define NUM_ENTRIES 13
static GtkActionEntry entries[] =
{
{ "File", NULL, "_File", NULL, NULL, NULL },
{ "Open", GTK_STOCK_OPEN, NULL, NULL, "Open an existing file", G_CALLBACK(open) },
{ "Save", GTK_STOCK_SAVE, NULL, NULL, "Save the document to a file", G_CALLBACK(save) },
{ "Quit", GTK_STOCK_QUIT, NULL, NULL, "Quit the application", G_CALLBACK(quit) },
{ "Edit", NULL, "_Edit", NULL, NULL, NULL },
{ "Cut", GTK_STOCK_CUT, NULL, NULL, "Cut the selection to the clipboard", G_CALLBACK(cut) },
{ "Copy", GTK_STOCK_COPY, NULL, NULL, "Copy the selection to the clipboard", G_CALLBACK(copy) },
{ "Paste", GTK_STOCK_PASTE, NULL, NULL, "Paste from the clipboard", G_CALLBACK(paste) },
{ "SelectAll", GTK_STOCK_SELECT_ALL, NULL, NULL, "Select all the text", G_CALLBACK(selectall) },
{ "Deselect", NULL, "_Deselect", NULL, "Deselect text", G_CALLBACK(deselect) },
{ "Help", NULL, "_Help", NULL, NULL, NULL },
{ "Contents", GTK_STOCK_HELP, NULL, NULL, "Get help using the application", G_CALLBACK(help) },
{ "About", GTK_STOCK_ABOUT, NULL, NULL, "More information about the application", G_CALLBACK(about) }
};
int main(int argc, char *argv[])
{
GtkWidget *window, *menubar, *toolbar, *vbox;
GtkActionGroup *group;
GtkUIManager *uimanager;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "UI Manager");
gtk_widget_set_size_request(window, 250, -1);
g_signal_connect(window, "destroy", gtk_main_quit, NULL);
group = gtk_action_group_new("MainActionGroup");
gtk_action_group_add_actions(group, entries, NUM_ENTRIES, NULL);
uimanager = gtk_ui_manager_new();
gtk_ui_manager_insert_action_group(uimanager, group, 0);
gtk_ui_manager_add_ui_from_file(uimanager, "menu.ui", NULL);
gtk_ui_manager_add_ui_from_file(uimanager, "toolbar.ui", NULL);
menubar = gtk_ui_manager_get_widget(uimanager, "/MenuBar");
toolbar = gtk_ui_manager_get_widget(uimanager, "/Toolbar");
gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS);
gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(uimanager));
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
Specifically:
uimanager.c: At top level:
uimanager.c:18:3: warning: ‘GtkStock’ is deprecated [-Wdeprecated-declarations]
{ "Open", GTK_STOCK_OPEN, NULL, NULL, "Open an existing file", G_CALLBACK(open) },
^
...
uimanager.c: In function ‘main’:
uimanager.c:45:2: warning: ‘gtk_action_group_new’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkactiongroup.h:175) [-Wdeprecated-declarations]
group = gtk_action_group_new("MainActionGroup");
^
uimanager.c:46:2: warning: ‘gtk_action_group_add_actions’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkactiongroup.h:210) [-Wdeprecated-declarations]
gtk_action_group_add_actions(group, entries, NUM_ENTRIES, NULL);
^
uimanager.c:48:2: warning: ‘gtk_ui_manager_new’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkuimanager.h:130) [-Wdeprecated-declarations]
uimanager = gtk_ui_manager_new();
^
uimanager.c:49:2: warning: ‘gtk_ui_manager_insert_action_group’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkuimanager.h:138) [-Wdeprecated-declarations]
gtk_ui_manager_insert_action_group(uimanager, group, 0);
^
uimanager.c:50:2: warning: ‘gtk_ui_manager_add_ui_from_file’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkuimanager.h:163) [-Wdeprecated-declarations]
gtk_ui_manager_add_ui_from_file(uimanager, "menu.ui", NULL);
^
uimanager.c:51:2: warning: ‘gtk_ui_manager_add_ui_from_file’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkuimanager.h:163) [-Wdeprecated-declarations]
gtk_ui_manager_add_ui_from_file(uimanager, "toolbar.ui", NULL);
^
uimanager.c:53:2: warning: ‘gtk_ui_manager_get_widget’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkuimanager.h:149) [-Wdeprecated-declarations]
menubar = gtk_ui_manager_get_widget(uimanager, "/MenuBar");
^
uimanager.c:54:2: warning: ‘gtk_ui_manager_get_widget’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkuimanager.h:149) [-Wdeprecated-declarations]
toolbar = gtk_ui_manager_get_widget(uimanager, "/Toolbar");
^
uimanager.c:56:2: warning: ‘gtk_ui_manager_get_accel_group’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkuimanager.h:147) [-Wdeprecated-declarations]
gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(uimanager));
^
For whatever reason, I've yet to find proper guidance on what to do instead of using GtkStock items, though I've managed to work around them in every other tutorial. However, the same now goes for action groups, UI managers, and the lot of warnings in that second section. The docs just say they're depreciated and not to be used. If so, what should any of these items be replaced with?
Thus there is no complete guide step by step on how to do things
for GtkStock, there is that document: https://docs.google.com/document/d/1KCVPoYQBqMbDP11tHPpjW6uaEHrvLUmcDPqKAppCY8o/pub
For GtkUiManager and other there is some code example available when you downlod the source code, into the exemple directory action-namespace.c
At last gtk-demo provide some code examples as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With