From 489c59c7e32028b4c59837b6e8c421b67a8489d8 Mon Sep 17 00:00:00 2001 From: Unia Date: Wed, 23 Oct 2013 01:12:49 +0200 Subject: [PATCH] buttons now use images, remove titles from headerbar and CSD are working --- src/callbacks.c | 15 ++++++++++----- src/main.c | 1 - src/ui.c | 11 ++++++----- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/callbacks.c b/src/callbacks.c index 4531a3e..a3919f9 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -227,25 +227,30 @@ void on_list_selection_changed (void) { void on_stack_page_change (void) { const gchar *page; + GtkWidget *image_delete, *image_save; page = gtk_stack_get_visible_child_name (GTK_STACK (stack)); if (g_strcmp0 (page, "scroll") == 0) { - gtk_button_set_label (GTK_BUTTON (button_save), _("Delete")); + image_delete = gtk_image_new_from_icon_name ("stock_delete", GTK_ICON_SIZE_MENU); + gtk_button_set_image (GTK_BUTTON (button_save), image_delete); if (gtk_tree_selection_get_selected (selection, NULL, &selection_iter)) gtk_widget_set_sensitive (button_save, TRUE); else gtk_widget_set_sensitive (button_save, FALSE); } else { - gtk_button_set_label (GTK_BUTTON (button_save), _("Save")); + image_save = gtk_image_new_from_icon_name ("stock_save", GTK_ICON_SIZE_MENU); + gtk_button_set_image (GTK_BUTTON (button_save), image_save); gtk_widget_set_sensitive (button_save, TRUE); } } void on_sd_button_clicked (void) { - const gchar *type; + const gchar *type = NULL; + GtkWidget *image; - type = gtk_button_get_label (GTK_BUTTON (button_save)); - if (g_strcmp0 (type, _("Save")) == 0) + image = gtk_button_get_image (GTK_BUTTON (button_save)); + gtk_image_get_icon_name (GTK_IMAGE (image), &type, NULL); + if (g_strcmp0 (type, "stock_save") == 0) open_save_dialog (); else { gchar *color_value; diff --git a/src/main.c b/src/main.c index b027cc9..053999e 100644 --- a/src/main.c +++ b/src/main.c @@ -37,7 +37,6 @@ int main (void) { colorvalue.red = colorvalue.green = colorvalue.blue = 65535; window = create_window (); - gtk_window_set_decorated (GTK_WINDOW (window), FALSE); gtk_widget_show_all (window); user_filename = g_build_filename (g_getenv ("HOME"), ".rgb.txt", NULL); diff --git a/src/ui.c b/src/ui.c index 61db729..c0edafa 100644 --- a/src/ui.c +++ b/src/ui.c @@ -126,7 +126,7 @@ GtkWidget *save_dialog_open (void) { } GtkWidget *create_window (void) { - GtkWidget *box_all, *header_bar, *stackswitcher, *box_color_chooser, *scroll, *button_about; + GtkWidget *box_all, *header_bar, *stackswitcher, *box_color_chooser, *scroll, *button_about, *image_about; GtkTreeViewColumn *column; GtkCellRenderer *renderer; @@ -139,8 +139,6 @@ GtkWidget *create_window (void) { gtk_container_set_border_width (GTK_CONTAINER (box_all), 5); header_bar = gtk_header_bar_new (); - gtk_header_bar_set_title (GTK_HEADER_BAR (header_bar), "Gcolor3"); - gtk_header_bar_set_subtitle (GTK_HEADER_BAR (header_bar), _("A simple color selection dialog in GTK3")); gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (header_bar), TRUE); stack = gtk_stack_new (); @@ -155,8 +153,10 @@ GtkWidget *create_window (void) { gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN); - button_save = gtk_button_new_with_label (_("Save")); - button_about = gtk_button_new_with_label (_("About")); + button_save = gtk_button_new (); + button_about = gtk_button_new (); + image_about = gtk_image_new_from_icon_name ("help-about", GTK_ICON_SIZE_MENU); + gtk_button_set_image (GTK_BUTTON (button_about), image_about); liststore = gtk_list_store_new (N_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL (liststore)); @@ -180,6 +180,7 @@ GtkWidget *create_window (void) { gtk_tree_view_column_set_sort_column_id (column, COLOR_NAME); gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column); + gtk_window_set_titlebar (GTK_WINDOW (window), header_bar); gtk_box_pack_start (GTK_BOX (box_all), header_bar, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box_color_chooser), color_chooser, FALSE, FALSE, 0); gtk_stack_add_titled (GTK_STACK (stack), box_color_chooser, "color chooser", _("Color chooser"));