[goffice] GUI: Handle reconfig for color toolbar buttons also.



commit f01d5a460773480ccde9f36160cb6abb10ee9793
Author: Morten Welinder <terra gnome org>
Date:   Fri Jan 31 21:34:38 2014 -0500

    GUI: Handle reconfig for color toolbar buttons also.

 ChangeLog                             |   13 +++++++++-
 NEWS                                  |    3 +-
 goffice/gtk/go-action-combo-color.c   |   37 +++++++++++++--------------
 goffice/gtk/go-action-combo-pixmaps.c |   18 +++++--------
 goffice/gtk/go-combo-color.c          |   43 +++++++++++++++++++++++----------
 goffice/gtk/go-combo-color.h          |    1 +
 6 files changed, 70 insertions(+), 45 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index bdabb9a..5c86504 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,18 @@
 2014-01-31  Morten Welinder  <terra gnome org>
 
+       * goffice/gtk/go-combo-color.c (go_combo_color_set_icon): New
+       function.
+
+       * goffice/gtk/go-action-combo-pixmaps.c (make_icon): Simplify
+       sizing.
+
+       * goffice/gtk/go-action-combo-color.c
+       (go_action_combo_color_create_tool_item): Handle reconfiguration
+       of the toolbar the item is in.
+       (make_icon): Simplify sizing.
+
        * goffice/gtk/go-action-combo-stack.c
-       (go_action_combo_stack_create_tool_item): Handler reconfiguration
+       (go_action_combo_stack_create_tool_item): Handle reconfiguration
        of the toolbar the item is in.
 
 2014-01-17  Jean Brefort  <jean brefort normalesup org>
diff --git a/NEWS b/NEWS
index 83473eb..eaeef64 100644
--- a/NEWS
+++ b/NEWS
@@ -13,7 +13,8 @@ Morten:
          functions.
        * Add go_sinpi, go_cospi, go_tanpi, go_atan2pi.
        * Improve "General" format.
-       * Improve Undo/Redo buttons.
+       * Improve Undo/Redo toolbar items.
+       * Improve Color selector toolbar items.
 
 --------------------------------------------------------------------------
 goffice 0.10.9:
diff --git a/goffice/gtk/go-action-combo-color.c b/goffice/gtk/go-action-combo-color.c
index da21ef7..75110e4 100644
--- a/goffice/gtk/go-action-combo-color.c
+++ b/goffice/gtk/go-action-combo-color.c
@@ -50,18 +50,13 @@ make_icon (GtkAction *a, GtkWidget *tool)
        g_object_get (a, "stock-id", &stock_id, NULL);
        if (stock_id == NULL)
                return NULL;
-       if (GO_IS_TOOL_COMBO_COLOR (tool)) {
-               GtkWidget *parent = gtk_widget_get_parent (tool);
-               if (parent)
-                       size = gtk_toolbar_get_icon_size (GTK_TOOLBAR (parent));
-               else
-                       g_object_get (settings,
-                                         "gtk-toolbar-icon-size", &size,
-                                         NULL);
-               gtk_icon_size_lookup_for_settings (settings, size,
-                                                  &pixels, NULL);
-       } else
-               size = GTK_ICON_SIZE_MENU;
+
+       size = GTK_IS_TOOL_ITEM (tool)
+               ? gtk_tool_item_get_icon_size (GTK_TOOL_ITEM (tool))
+               : GTK_ICON_SIZE_MENU;
+       gtk_icon_size_lookup_for_settings (settings, size,
+                                          &pixels, NULL);
+
        icon = gtk_icon_theme_load_icon
                (gtk_icon_theme_get_for_screen (screen),
                 stock_id, pixels, 0, NULL);
@@ -148,15 +143,23 @@ cb_proxy_custom_dialog (G_GNUC_UNUSED GObject *ignored,
 }
 
 static void
-cb_toolbar_reconfigured (GOToolComboColor *tool)
+cb_toolbar_reconfigured (GOToolComboColor *tool, GtkAction *a)
 {
        GtkOrientation o = gtk_tool_item_get_orientation (GTK_TOOL_ITEM (tool));
        gboolean horiz = (o == GTK_ORIENTATION_HORIZONTAL);
+       GtkReliefStyle relief = gtk_tool_item_get_relief_style (GTK_TOOL_ITEM (tool));
+       GdkPixbuf *icon;
 
        g_object_set (G_OBJECT (tool->combo),
                      "show-arrow", horiz,
                      NULL);
        go_combo_color_set_instant_apply (GO_COMBO_COLOR (tool->combo), horiz);
+
+       icon = make_icon (a, GTK_WIDGET (tool));
+       go_combo_color_set_icon (GO_COMBO_COLOR (tool->combo), icon);
+       if (icon) g_object_unref (icon);
+
+       go_combo_box_set_relief (GO_COMBO_BOX (tool->combo), relief);
 }
 
 static GtkWidget *
@@ -165,9 +168,6 @@ go_action_combo_color_create_tool_item (GtkAction *a)
        GOActionComboColor *caction = (GOActionComboColor *)a;
        GOToolComboColor *tool = g_object_new (GO_TYPE_TOOL_COMBO_COLOR, NULL);
        char *title;
-
-       /* FIXME: We probably should re-do this when tool changes screen or
-          parent.  */
        GdkPixbuf *icon = make_icon (a, GTK_WIDGET (tool));
 
        tool->combo = (GOComboColor *)go_combo_color_new (icon,
@@ -176,15 +176,14 @@ go_action_combo_color_create_tool_item (GtkAction *a)
        if (icon) g_object_unref (icon);
 
        go_combo_color_set_allow_alpha (GO_COMBO_COLOR (tool->combo), caction->allow_alpha);
-       go_combo_box_set_relief (GO_COMBO_BOX (tool->combo), GTK_RELIEF_NONE);
        title = get_title (a);
        go_combo_box_set_title (GO_COMBO_BOX (tool->combo), title);
        g_free (title);
 
        g_signal_connect (tool, "toolbar-reconfigured",
                          G_CALLBACK (cb_toolbar_reconfigured),
-                         NULL);
-       cb_toolbar_reconfigured (tool);
+                         a);
+       cb_toolbar_reconfigured (tool, a);
 
        go_gtk_widget_disable_focus (GTK_WIDGET (tool->combo));
        gtk_container_add (GTK_CONTAINER (tool), GTK_WIDGET (tool->combo));
diff --git a/goffice/gtk/go-action-combo-pixmaps.c b/goffice/gtk/go-action-combo-pixmaps.c
index 0910932..e2fd786 100644
--- a/goffice/gtk/go-action-combo-pixmaps.c
+++ b/goffice/gtk/go-action-combo-pixmaps.c
@@ -79,16 +79,10 @@ make_icon (GtkAction *a, const char *stock_id, GtkWidget *tool)
 
        if (stock_id == NULL)
                return NULL;
-       if (GO_IS_TOOL_COMBO_PIXMAPS (tool)) {
-               GtkWidget *parent = gtk_widget_get_parent (tool);
-               if (parent)
-                       size = gtk_toolbar_get_icon_size (GTK_TOOLBAR (parent));
-               else {
-                       GtkSettings *settings = gtk_widget_get_settings (tool);
-                       g_object_get (settings, "gtk-toolbar-icon-size", &size, NULL);
-               }
-       } else
-               size = GTK_ICON_SIZE_MENU;
+
+       size = GTK_IS_TOOL_ITEM (tool)
+               ? gtk_tool_item_get_icon_size (GTK_TOOL_ITEM (tool))
+               : GTK_ICON_SIZE_MENU;
 
        return gtk_widget_render_icon_pixbuf (tool, stock_id, size);
 }
@@ -138,10 +132,13 @@ static void
 cb_toolbar_reconfigured (GOToolComboPixmaps *tool)
 {
        GtkOrientation o = gtk_tool_item_get_orientation (GTK_TOOL_ITEM (tool));
+       GtkReliefStyle relief = gtk_tool_item_get_relief_style (GTK_TOOL_ITEM (tool));
 
        g_object_set (G_OBJECT (tool->combo),
                      "show-arrow", o == GTK_ORIENTATION_HORIZONTAL,
                      NULL);
+
+       go_combo_box_set_relief (GO_COMBO_BOX (tool->combo), relief);
 }
 
 static GtkWidget *
@@ -167,7 +164,6 @@ go_action_combo_pixmaps_create_tool_item (GtkAction *a)
                          NULL);
        cb_toolbar_reconfigured (tool);
 
-       go_combo_box_set_relief (GO_COMBO_BOX (tool->combo), GTK_RELIEF_NONE);
        go_gtk_widget_disable_focus (GTK_WIDGET (tool->combo));
        gtk_container_add (GTK_CONTAINER (tool), GTK_WIDGET (tool->combo));
        gtk_widget_show (GTK_WIDGET (tool->combo));
diff --git a/goffice/gtk/go-combo-color.c b/goffice/gtk/go-combo-color.c
index eac550b..4b03d6c 100644
--- a/goffice/gtk/go-combo-color.c
+++ b/goffice/gtk/go-combo-color.c
@@ -324,6 +324,35 @@ go_combo_color_set_color_to_default (GOComboColor *cc)
 }
 
 /**
+ * go_combo_color_set_icon:
+ * @icon: optionally NULL.
+ **/
+void
+go_combo_color_set_icon (GOComboColor *cc, GdkPixbuf *icon)
+{
+       GdkPixbuf *pixbuf;
+
+       if (cc->preview_image)
+               gtk_container_remove (GTK_CONTAINER (cc->preview_button), cc->preview_image);
+
+       if (icon != NULL &&
+           gdk_pixbuf_get_width (icon) > 4 &&
+           gdk_pixbuf_get_height (icon) > 4) {
+               cc->preview_is_icon = TRUE;
+               pixbuf = gdk_pixbuf_copy (icon);
+       } else {
+               cc->preview_is_icon = FALSE;
+               pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
+                                        PREVIEW_SIZE, PREVIEW_SIZE);
+       }
+
+       cc->preview_image = gtk_image_new_from_pixbuf (pixbuf);
+       g_object_unref (pixbuf);
+       gtk_widget_show (cc->preview_image);
+       gtk_container_add (GTK_CONTAINER (cc->preview_button), cc->preview_image);
+}
+
+/**
  * go_combo_color_new :
  * @icon: optionally NULL.
  * @no_color_label: FIXME
@@ -342,23 +371,11 @@ go_combo_color_new (GdkPixbuf *icon, char const *no_color_label,
 {
        GOColor     color;
        gboolean    is_default;
-       GdkPixbuf  *pixbuf = NULL;
        GOComboColor *cc = g_object_new (GO_TYPE_COMBO_COLOR, NULL);
 
         cc->default_color = default_color;
-       if (icon != NULL &&
-           gdk_pixbuf_get_width (icon) > 4 &&
-           gdk_pixbuf_get_height (icon) > 4) {
-               cc->preview_is_icon = TRUE;
-               pixbuf = gdk_pixbuf_copy (icon);
-       } else
-               pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
-                                        PREVIEW_SIZE, PREVIEW_SIZE);
 
-       cc->preview_image = gtk_image_new_from_pixbuf (pixbuf);
-       g_object_unref (pixbuf);
-       gtk_widget_show (cc->preview_image);
-       gtk_container_add (GTK_CONTAINER (cc->preview_button), cc->preview_image);
+       go_combo_color_set_icon (cc, icon);
 
        color_table_setup (cc, no_color_label, color_group);
        gtk_widget_show_all (cc->preview_button);
diff --git a/goffice/gtk/go-combo-color.h b/goffice/gtk/go-combo-color.h
index 4cea36f..ce9e3d7 100644
--- a/goffice/gtk/go-combo-color.h
+++ b/goffice/gtk/go-combo-color.h
@@ -50,6 +50,7 @@ GOColor go_combo_color_get_color (GOComboColor  *cc, gboolean *is_default);
 void    go_combo_color_set_color (GOComboColor  *cc, GOColor   color);
 void    go_combo_color_set_color_to_default (GOComboColor *cc);
 void    go_combo_color_set_color_gdk (GOComboColor *cc, GdkRGBA *color);
+void    go_combo_color_set_icon (GOComboColor *cc, GdkPixbuf *icon);
 
 void go_combo_color_set_allow_alpha    (GOComboColor *cc, gboolean allow_alpha);
 void go_combo_color_set_instant_apply  (GOComboColor *cc, gboolean active);


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