以下代码来自Foundations of GTK+ Development的 list 9-11。通过这本书,我一直在尝试迁移任何特定于GTK2的内容(或任何与此相关的折旧代码),以了解当前的相关内容。也就是说,这在编译时产生了很多警告。
#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;
}
具体来说:
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));
^
出于任何原因,尽管我在其他所有教程中都设法解决了这些问题,但我尚未找到适当的指导来代替使用GtkStock项目。但是,现在对于 Action 组,UI管理器和第二部分中的许多警告也是如此。文档只是说它们已贬值,不被使用。如果是这样,这些项目中的任何一项应替换为什么?
最佳答案
关于c - gtk_action_group_new()和GtkStock-改用什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24788045/