From 42e786b15bb25693d159281b3c84a9483e198891 Mon Sep 17 00:00:00 2001 From: Nickolas Lloyd Date: Mon, 14 Jun 2010 10:47:12 +0000 Subject: [PATCH] Remove deprecated Gtk+ symbols This patch removes all uses of deprecated Gtk+ symbols from mutter. https://bugzilla.gnome.org/show_bug.cgi?id=587991 --- src/tools/mutter-window-demo.c | 273 ++++++++++++++++++--------------- src/ui/theme-viewer.c | 120 ++++++++------- 2 files changed, 217 insertions(+), 176 deletions(-) diff --git a/src/tools/mutter-window-demo.c b/src/tools/mutter-window-demo.c index facc8c985..aa91f058a 100644 --- a/src/tools/mutter-window-demo.c +++ b/src/tools/mutter-window-demo.c @@ -309,17 +309,15 @@ response_cb (GtkDialog *dialog, } static void -dialog_cb (gpointer callback_data, - guint callback_action, - GtkWidget *widget) +dialog_cb (GtkAction *action, + gpointer callback_data) { make_dialog (GTK_WIDGET (callback_data), 1); } static void -modal_dialog_cb (gpointer callback_data, - guint callback_action, - GtkWidget *widget) +modal_dialog_cb (GtkAction *action, + gpointer callback_data) { GtkWidget *dialog; @@ -337,17 +335,15 @@ modal_dialog_cb (gpointer callback_data, } static void -no_parent_dialog_cb (gpointer callback_data, - guint callback_action, - GtkWidget *widget) +no_parent_dialog_cb (GtkAction *action, + gpointer callback_data) { make_dialog (NULL, 1); } static void -utility_cb (gpointer callback_data, - guint callback_action, - GtkWidget *widget) +utility_cb (GtkAction *action, + gpointer callback_data) { GtkWidget *window; GtkWidget *vbox; @@ -379,9 +375,8 @@ utility_cb (gpointer callback_data, } static void -toolbar_cb (gpointer callback_data, - guint callback_action, - GtkWidget *widget) +toolbar_cb (GtkAction *action, + gpointer callback_data) { GtkWidget *window; GtkWidget *vbox; @@ -404,9 +399,8 @@ toolbar_cb (gpointer callback_data, } static void -menu_cb (gpointer callback_data, - guint callback_action, - GtkWidget *widget) +menu_cb (GtkAction *action, + gpointer callback_data) { GtkWidget *window; GtkWidget *vbox; @@ -429,9 +423,8 @@ menu_cb (gpointer callback_data, } static void -override_redirect_cb (gpointer callback_data, - guint callback_action, - GtkWidget *widget) +override_redirect_cb (GtkAction *action, + gpointer callback_data) { GtkWidget *window; GtkWidget *vbox; @@ -451,9 +444,8 @@ override_redirect_cb (gpointer callback_data, } static void -border_only_cb (gpointer callback_data, - guint callback_action, - GtkWidget *widget) +border_only_cb (GtkAction *action, + gpointer callback_data) { GtkWidget *window; GtkWidget *vbox; @@ -477,9 +469,8 @@ border_only_cb (gpointer callback_data, #if 0 static void -changing_icon_cb (gpointer callback_data, - guint callback_action, - GtkWidget *widget) +changing_icon_cb (GtkAction *action, + gpointer callback_data) { GtkWidget *window; GtkWidget *vbox; @@ -545,9 +536,8 @@ focus_label (GtkWidget *window) } static void -splashscreen_cb (gpointer callback_data, - guint callback_action, - GtkWidget *widget) +splashscreen_cb (GtkAction *action, + gpointer callback_data) { GtkWidget *window; GtkWidget *image; @@ -654,10 +644,27 @@ make_dock (int type) } static void -dock_cb (gpointer callback_data, - guint callback_action, - GtkWidget *widget) +dock_cb (GtkAction *action, + gpointer callback_data) { + guint callback_action; + const gchar *name; + + name = gtk_action_get_name (action); + + if (!g_strcmp0 (name, "Top dock")) + callback_action = DOCK_TOP; + else if (!g_strcmp0 (name, "Bottom dock")) + callback_action = DOCK_BOTTOM; + else if (!g_strcmp0 (name, "Left dock")) + callback_action = DOCK_LEFT; + else if (!g_strcmp0 (name, "Right dock")) + callback_action = DOCK_RIGHT; + else if (!g_strcmp0 (name, "All docks")) + callback_action = DOCK_ALL; + else + return; + if (callback_action == DOCK_ALL) { make_dock (DOCK_TOP); @@ -672,9 +679,8 @@ dock_cb (gpointer callback_data, } static void -desktop_cb (gpointer callback_data, - guint callback_action, - GtkWidget *widget) +desktop_cb (GtkAction *action, + gpointer callback_data) { GtkWidget *window; GtkWidget *label; @@ -700,40 +706,20 @@ desktop_cb (gpointer callback_data, gtk_widget_show_all (window); } -static GtkItemFactoryEntry menu_items[] = -{ - { "/_Windows", NULL, NULL, 0, "" }, - { "/Windows/tearoff", NULL, NULL, 0, "" }, - { "/Windows/_Dialog", "d", dialog_cb, 0, NULL }, - { "/Windows/_Modal dialog", NULL, modal_dialog_cb, 0, NULL }, - { "/Windows/_Parentless dialog", NULL, no_parent_dialog_cb, 0, NULL }, - { "/Windows/_Utility", "u", utility_cb, 0, NULL }, - { "/Windows/_Splashscreen", "s", splashscreen_cb, 0, NULL }, - { "/Windows/_Top dock", NULL, dock_cb, DOCK_TOP, NULL }, - { "/Windows/_Bottom dock", NULL, dock_cb, DOCK_BOTTOM, NULL }, - { "/Windows/_Left dock", NULL, dock_cb, DOCK_LEFT, NULL }, - { "/Windows/_Right dock", NULL, dock_cb, DOCK_RIGHT, NULL }, - { "/Windows/_All docks", NULL, dock_cb, DOCK_ALL, NULL }, - { "/Windows/Des_ktop", NULL, desktop_cb, 0, NULL }, - { "/Windows/Me_nu", NULL, menu_cb, 0, NULL }, - { "/Windows/Tool_bar", NULL, toolbar_cb, 0, NULL }, - { "/Windows/Override Redirect", NULL, override_redirect_cb, 0, NULL }, - { "/Windows/Border Only", NULL, border_only_cb, 0, NULL } -}; - static void -sleep_cb (GtkWidget *button, +sleep_cb (GtkAction *action, gpointer data) { sleep (1000); } static void -toggle_aspect_ratio (GtkWidget *button, +toggle_aspect_ratio (GtkAction *action, gpointer data) { GtkWidget *window; GdkGeometry geom; + GtkWidget *widget = GTK_WIDGET (data); if (aspect_on) { @@ -748,10 +734,10 @@ toggle_aspect_ratio (GtkWidget *button, aspect_on = !aspect_on; - window = gtk_widget_get_ancestor (button, GTK_TYPE_WINDOW); + window = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW); if (window) gtk_window_set_geometry_hints (GTK_WINDOW (window), - GTK_WIDGET (data), + widget, &geom, GDK_HINT_ASPECT); @@ -762,7 +748,7 @@ toggle_decorated_cb (GtkWidget *button, gpointer data) { GtkWidget *window; - window = gtk_widget_get_ancestor (button, GTK_TYPE_WINDOW); + window = gtk_widget_get_ancestor (data, GTK_TYPE_WINDOW); if (window) gtk_window_set_decorated (GTK_WINDOW (window), !gtk_window_get_decorated (GTK_WINDOW (window))); @@ -836,39 +822,102 @@ destroy_cb (GtkWidget *w, gpointer data) gtk_main_quit (); } -static void -insert_stock_button (GtkWidget *toolbar, - const gchar *stock_id, - const gchar *text, - GCallback callback, - gpointer user_data) -{ - GtkToolItem *button; +static const gchar *menu_item_string = + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n"; - button = gtk_tool_button_new_from_stock (stock_id); - gtk_tool_item_set_tooltip_text (button, text); - g_signal_connect (G_OBJECT (button), - "clicked", - callback, - user_data); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), - button, - -1); /*-1 means append to end of toolbar*/ -} +static const GtkActionEntry menu_items[] = +{ + { "Windows", NULL, "_Windows", NULL, + NULL, NULL }, + { "Dialog", NULL, "_Dialog", "d", + NULL, G_CALLBACK (dialog_cb) }, + { "Modal dialog", NULL, "_Modal dialog", NULL, + NULL, G_CALLBACK (modal_dialog_cb) }, + { "Parentless dialog", NULL, "_Parentless dialog", NULL, + NULL, G_CALLBACK (no_parent_dialog_cb) }, + { "Utility", NULL, "_Utility", "u", + NULL, G_CALLBACK (utility_cb) }, + { "Splashscreen", NULL, "_Splashscreen", "s", + NULL, G_CALLBACK (splashscreen_cb) }, + { "Top dock", NULL, "_Top dock", NULL, + NULL, G_CALLBACK (dock_cb) }, + { "Bottom dock", NULL, "_Bottom dock", NULL, + NULL, G_CALLBACK (dock_cb) }, + { "Left dock", NULL, "_Left dock", NULL, + NULL, G_CALLBACK (dock_cb) }, + { "Right dock", NULL, "_Right dock", NULL, + NULL, G_CALLBACK (dock_cb) }, + { "All docks", NULL, "_All docks", NULL, + NULL, G_CALLBACK (dock_cb) }, + { "Desktop", NULL, "Des_ktop", NULL, + NULL, G_CALLBACK (desktop_cb) }, + { "Menu", NULL, "Me_nu", NULL, + NULL, G_CALLBACK (menu_cb) }, + { "Toolbar", NULL, "Tool_bar", NULL, + NULL, G_CALLBACK (toolbar_cb) }, + { "Override Redirect", NULL, "Override Redirect", NULL, + NULL, G_CALLBACK (override_redirect_cb) }, + { "Border Only", NULL, "Border Only", NULL, + NULL, G_CALLBACK (border_only_cb) } +}; + +static const GtkActionEntry tool_items[] = +{ + { "New", GTK_STOCK_NEW, NULL, NULL, + "Open another one of these windows", G_CALLBACK (do_appwindow) }, + { "Lock", GTK_STOCK_OPEN, NULL, NULL, + "This is a demo button that" + " locks up the demo", G_CALLBACK (sleep_cb) }, + { "Decorations", GTK_STOCK_OPEN, NULL, NULL, + "This is a demo button that " + "toggles window decorations", G_CALLBACK (toggle_decorated_cb) }, + { "Quit", GTK_STOCK_QUIT, NULL, NULL, + "This is a demo button with " + " a 'quit' icon", G_CALLBACK (clicked_toolbar_cb) }, + { "Ratio", GTK_STOCK_OPEN, NULL, NULL, + "This is a demo button that locks the aspect ratio " + "using a hint", G_CALLBACK (toggle_aspect_ratio) } +}; static GtkWidget * do_appwindow (void) { GtkWidget *window; GtkWidget *table; - GtkWidget *toolbar; GtkWidget *handlebox; GtkWidget *statusbar; GtkWidget *contents; GtkWidget *sw; GtkTextBuffer *buffer; - GtkAccelGroup *accel_group; - GtkItemFactory *item_factory; + GtkActionGroup *action_group; + GtkUIManager *ui_manager; /* Create the toplevel window */ @@ -890,25 +939,28 @@ do_appwindow (void) /* Create the menubar */ - accel_group = gtk_accel_group_new (); - gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); - g_object_unref (accel_group); - - item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "
", accel_group); + contents = gtk_text_view_new (); - /* Set up item factory to go away with the window */ - g_object_ref_sink (item_factory); - g_object_set_data_full (G_OBJECT (window), - "
", - item_factory, - (GDestroyNotify) g_object_unref); + action_group = gtk_action_group_new ("mainmenu"); + gtk_action_group_add_actions (action_group, + menu_items, + G_N_ELEMENTS (menu_items), + window); + gtk_action_group_add_actions (action_group, + tool_items, + G_N_ELEMENTS (tool_items), + window); + + ui_manager = gtk_ui_manager_new (); + + gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); /* create menu items */ - gtk_item_factory_create_items (item_factory, G_N_ELEMENTS (menu_items), - menu_items, window); + + gtk_ui_manager_add_ui_from_string (ui_manager, menu_item_string, -1, NULL); gtk_table_attach (GTK_TABLE (table), - gtk_item_factory_get_widget (item_factory, "
"), + gtk_ui_manager_get_widget (ui_manager, "/ui/menubar"), /* X direction */ /* Y direction */ 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, 0, @@ -936,7 +988,6 @@ do_appwindow (void) gtk_window_set_default_size (GTK_WINDOW (window), 200, 200); - contents = gtk_text_view_new (); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (contents), PANGO_WRAP_WORD); @@ -945,31 +996,11 @@ do_appwindow (void) /* Create the toolbar */ - toolbar = gtk_toolbar_new (); - - insert_stock_button (toolbar, GTK_STOCK_NEW, - "Open another one of these windows", - G_CALLBACK (do_appwindow), window); - - insert_stock_button (toolbar, GTK_STOCK_OPEN, - "This is a demo button that locks up the demo", - G_CALLBACK (sleep_cb), window); - - insert_stock_button (toolbar, GTK_STOCK_OPEN, - "This is a demo button that toggles window decorations", - G_CALLBACK (toggle_decorated_cb), window); - - insert_stock_button (toolbar, GTK_STOCK_OPEN, - "This is a demo button that locks the aspect ratio using a hint", - G_CALLBACK (toggle_aspect_ratio), contents); - - insert_stock_button (toolbar, GTK_STOCK_QUIT, - "This is a demo button with a 'quit' icon", - G_CALLBACK (clicked_toolbar_cb), window); handlebox = gtk_handle_box_new (); - gtk_container_add (GTK_CONTAINER (handlebox), toolbar); + gtk_container_add (GTK_CONTAINER (handlebox), + gtk_ui_manager_get_widget (ui_manager, "/ui/toolbar")); gtk_table_attach (GTK_TABLE (table), handlebox, @@ -1014,6 +1045,8 @@ do_appwindow (void) gtk_widget_show_all (window); + g_object_unref (ui_manager); + return window; } diff --git a/src/ui/theme-viewer.c b/src/ui/theme-viewer.c index 1d2be53fb..04a5b7680 100644 --- a/src/ui/theme-viewer.c +++ b/src/ui/theme-viewer.c @@ -70,94 +70,100 @@ static void run_position_expression_timings (void); static void run_theme_benchmark (void); -static GtkItemFactoryEntry menu_items[] = +static const gchar *menu_item_string = + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n"; + +static GtkActionEntry menu_items[] = { - { N_("/_Windows"), NULL, NULL, 0, "" }, - { N_("/Windows/tearoff"), NULL, NULL, 0, "" }, - { N_("/Windows/_Dialog"), "d", NULL, 0, NULL }, - { N_("/Windows/_Modal dialog"), NULL, NULL, 0, NULL }, - { N_("/Windows/_Utility"), "u", NULL, 0, NULL }, - { N_("/Windows/_Splashscreen"), "s", NULL, 0, NULL }, - { N_("/Windows/_Top dock"), NULL, NULL, 0, NULL }, - { N_("/Windows/_Bottom dock"), NULL, NULL, 0, NULL }, - { N_("/Windows/_Left dock"), NULL, NULL, 0, NULL }, - { N_("/Windows/_Right dock"), NULL, NULL, 0, NULL }, - { N_("/Windows/_All docks"), NULL, NULL, 0, NULL }, - { N_("/Windows/Des_ktop"), NULL, NULL, 0, NULL } + { "Windows", NULL, N_("_Windows"), NULL, NULL, NULL }, + { "Dialog", NULL, N_("_Dialog"), "d", NULL, NULL }, + { "Modal dialog", NULL, N_("_Modal dialog"), NULL, NULL, NULL }, + { "Utility", NULL, N_("_Utility"), "u", NULL, NULL }, + { "Splashscreen", NULL, N_("_Splashscreen"), "s", NULL, NULL }, + { "Top dock", NULL, N_("_Top dock"), NULL, NULL, NULL }, + { "Bottom dock", NULL, N_("_Bottom dock"), NULL, NULL, NULL }, + { "Left dock", NULL, N_("_Left dock"), NULL, NULL, NULL }, + { "Right dock", NULL, N_("_Right dock"), NULL, NULL, NULL }, + { "All docks", NULL, N_("_All docks"), NULL, NULL, NULL }, + { "Desktop", NULL, N_("Des_ktop"), NULL, NULL, NULL } }; -static void -insert_stock_button (GtkWidget *toolbar, - const gchar *stock_id, - const gchar *text) +static GtkActionEntry tool_items[] = { - GtkToolItem *button; - - button = gtk_tool_button_new_from_stock (stock_id); - gtk_tool_item_set_tooltip_text (button, text); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), - button, - -1); /*-1 means append to end of toolbar*/ - - return; -} + { "New", GTK_STOCK_NEW, NULL, NULL, + N_("Open another one of these windows"), NULL }, + { "Open", GTK_STOCK_OPEN, NULL, NULL, + N_("This is a demo button with an 'open' icon"), NULL }, + { "Quit", GTK_STOCK_QUIT, NULL, NULL, + N_("This is a demo button with a 'quit' icon"), NULL } +}; static GtkWidget * normal_contents (void) { GtkWidget *table; - GtkWidget *toolbar; GtkWidget *handlebox; GtkWidget *statusbar; GtkWidget *contents; GtkWidget *sw; - GtkItemFactory *item_factory; + GtkActionGroup *action_group; + GtkUIManager *ui_manager; table = gtk_table_new (1, 4, FALSE); /* Create the menubar */ - item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "
", NULL); + action_group = gtk_action_group_new ("mainmenu"); + gtk_action_group_add_actions (action_group, + menu_items, + G_N_ELEMENTS (menu_items), + NULL); + gtk_action_group_add_actions (action_group, + tool_items, + G_N_ELEMENTS (tool_items), + NULL); - gtk_item_factory_set_translate_func(item_factory, - (GtkTranslateFunc)gettext, NULL, NULL); + ui_manager = gtk_ui_manager_new (); - /* Set up item factory to go away */ - g_object_ref (item_factory); - g_object_ref_sink (item_factory); - g_object_unref (item_factory); - g_object_set_data_full (G_OBJECT (table), - "
", - item_factory, - (GDestroyNotify) g_object_unref); + gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); /* create menu items */ - gtk_item_factory_create_items (item_factory, G_N_ELEMENTS (menu_items), - menu_items, NULL); + gtk_ui_manager_add_ui_from_string (ui_manager, menu_item_string, -1, NULL); gtk_table_attach (GTK_TABLE (table), - gtk_item_factory_get_widget (item_factory, "
"), + gtk_ui_manager_get_widget (ui_manager, "/ui/menubar"), /* X direction */ /* Y direction */ 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, 0, 0, 0); - /* Create the toolbar - */ - toolbar = gtk_toolbar_new (); - - insert_stock_button (toolbar, GTK_STOCK_NEW, - _("Open another one of these windows")); - insert_stock_button (toolbar, GTK_STOCK_OPEN, - _("This is a demo button with an 'open' icon")); - insert_stock_button (toolbar, GTK_STOCK_QUIT, - _("This is a demo button with a 'quit' icon")); - handlebox = gtk_handle_box_new (); - gtk_container_add (GTK_CONTAINER (handlebox), toolbar); - + gtk_container_add (GTK_CONTAINER (handlebox), + gtk_ui_manager_get_widget (ui_manager, "/ui/toolbar")); + gtk_table_attach (GTK_TABLE (table), handlebox, /* X direction */ /* Y direction */ @@ -203,6 +209,8 @@ normal_contents (void) gtk_widget_show_all (table); + g_object_unref (ui_manager); + return table; }