[goffice] Icons: introduce new helper to simplify icon-to-pixbuf code.



commit 81fb390986c88cbf765a19fdca4ca08000dd4c48
Author: Morten Welinder <terra gnome org>
Date:   Sun Jan 4 17:34:39 2015 -0500

    Icons: introduce new helper to simplify icon-to-pixbuf code.

 ChangeLog                             |   15 +++++++++
 goffice/gtk/go-action-combo-color.c   |   10 +-----
 goffice/gtk/go-action-combo-pixmaps.c |   21 +------------
 goffice/gtk/goffice-gtk.c             |   54 +++++++++++++++++++++++++++++++--
 goffice/gtk/goffice-gtk.h             |    5 +++
 goffice/utils/go-image.c              |    4 +-
 6 files changed, 75 insertions(+), 34 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 995e82e..8713e15 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2015-01-04  Morten Welinder  <terra gnome org>
+
+       * goffice/gtk/goffice-gtk.c (update_preview_cb): Fix flags
+       argument of gtk_icon_theme_load_icon.
+       (go_gtk_widget_render_icon_pixbuf): New function.
+
+       * goffice/gtk/go-action-combo-pixmaps.c (make_icon): Use
+       go_gtk_widget_render_icon_pixbuf.
+       * goffice/gtk/go-action-combo-color.c (make_icon): Ditto.
+
+2015-01-02  Morten Welinder  <terra gnome org>
+
+       * goffice/gtk/goffice-gtk.c (go_gtk_button_build_with_stock): Make
+       this work with icon names.
+
 2014-12-31  Morten Welinder  <terra gnome org>
 
        * goffice/utils/go-glib-extras.c (go_guess_encoding): Lean a bit
diff --git a/goffice/gtk/go-action-combo-color.c b/goffice/gtk/go-action-combo-color.c
index 75110e4..41d06bb 100644
--- a/goffice/gtk/go-action-combo-color.c
+++ b/goffice/gtk/go-action-combo-color.c
@@ -41,11 +41,8 @@ static GdkPixbuf *
 make_icon (GtkAction *a, GtkWidget *tool)
 {
        GtkIconSize size;
-       gint pixels = 8;
        char *stock_id;
        GdkPixbuf *icon;
-       GtkSettings *settings = gtk_widget_get_settings (tool);
-       GdkScreen *screen = gtk_widget_get_screen (tool);
 
        g_object_get (a, "stock-id", &stock_id, NULL);
        if (stock_id == NULL)
@@ -54,12 +51,7 @@ make_icon (GtkAction *a, GtkWidget *tool)
        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);
+       icon = go_gtk_widget_render_icon_pixbuf (tool, stock_id, size);
        g_free (stock_id);
 
        return icon;
diff --git a/goffice/gtk/go-action-combo-pixmaps.c b/goffice/gtk/go-action-combo-pixmaps.c
index c5e70d7..f63e3a8 100644
--- a/goffice/gtk/go-action-combo-pixmaps.c
+++ b/goffice/gtk/go-action-combo-pixmaps.c
@@ -76,7 +76,6 @@ static GdkPixbuf *
 make_icon (GtkAction *a, const char *stock_id, GtkWidget *tool)
 {
        GtkIconSize size;
-       int isize;
        GdkPixbuf *res;
 
        if (stock_id == NULL)
@@ -91,25 +90,7 @@ make_icon (GtkAction *a, const char *stock_id, GtkWidget *tool)
        if (res)
                return res;
 
-       switch (size) {
-       default:
-       case GTK_ICON_SIZE_MENU:
-       case GTK_ICON_SIZE_SMALL_TOOLBAR:
-       case GTK_ICON_SIZE_BUTTON:
-               isize = 16;
-               break;
-       case GTK_ICON_SIZE_LARGE_TOOLBAR:
-       case GTK_ICON_SIZE_DND:
-               isize = 24;
-               break;
-       case GTK_ICON_SIZE_DIALOG:
-               isize = 48;
-               break;
-       }
-
-       return gtk_icon_theme_load_icon
-               (gtk_icon_theme_get_default (),
-                stock_id, isize, 0, NULL);
+       return go_gtk_widget_render_icon_pixbuf (tool, stock_id, size);
 }
 
 
diff --git a/goffice/gtk/goffice-gtk.c b/goffice/gtk/goffice-gtk.c
index 1196521..b9bc4e4 100644
--- a/goffice/gtk/goffice-gtk.c
+++ b/goffice/gtk/goffice-gtk.c
@@ -52,7 +52,7 @@
 /**
  * go_gtk_button_build_with_stock:
  * @text: button label
- * @stock_id: id for stock icon
+ * @stock_id: icon name (or stock id)
  *
  * FROM : gedit
  * Creates a new GtkButton with custom label and stock image.
@@ -68,6 +68,9 @@ go_gtk_button_build_with_stock (char const *text, char const* stock_id)
        if (gtk_stock_lookup (stock_id, &item))
                gtk_button_set_image (GTK_BUTTON (button),
                        gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON));
+       else
+               gtk_button_set_image (GTK_BUTTON (button),
+                                     gtk_image_new_from_icon_name (stock_id, GTK_ICON_SIZE_BUTTON));
        return button;
 }
 
@@ -79,7 +82,7 @@ go_gtk_button_build_with_stock (char const *text, char const* stock_id)
  * FROM : gedit
  * Creates a new GtkButton with custom label and stock image.
  *
- * Deprecated: 09.6., use go_gtk_button_build_with_stock().
+ * Deprecated: 0.9.6., use go_gtk_button_build_with_stock().
  * Returns: (transfer full): newly created button
  **/
 GtkWidget*
@@ -796,7 +799,7 @@ update_preview_cb (GtkFileChooser *chooser)
                        GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (chooser));
                        buf = go_pixbuf_new_from_pixbuf (gtk_icon_theme_load_icon
                                                (gtk_icon_theme_get_for_screen (screen),
-                                                "unknown_image", 100, 100, NULL));
+                                                "unknown_image", 100, 0, NULL));
                        dummy = buf != NULL;
                }
 
@@ -1567,3 +1570,48 @@ go_gtk_url_show (gchar const *url, GdkScreen *screen)
        gtk_show_uri (screen, url, GDK_CURRENT_TIME, &error);
        return error;
 }
+
+/**
+ * go_gtk_widget_render_icon_pixbuf:
+ * @widget: a mapped widget determining the screen targeted
+ * @icon_name: the name of the icon to render
+ * @size: the symbolic size desired.
+ *
+ * This function works as gtk_widget_render_icon_pixbuf except that it takes
+ * an icon name, not a stock id.
+ *
+ * Returns: (transfer full): A #GdkPixbuf.
+ **/
+GdkPixbuf *
+go_gtk_widget_render_icon_pixbuf (GtkWidget   *widget,
+                                 const gchar *icon_name,
+                                 GtkIconSize  size)
+{
+       GdkScreen *screen;
+       GtkIconTheme *theme;
+       int pixels;
+
+       /* The widget really ought to be mapped.  */
+       screen = gtk_widget_get_screen (widget);
+       if (!screen)
+               screen = gdk_screen_get_default ();
+       theme = gtk_icon_theme_get_for_screen (screen);
+
+       switch (size) {
+       default:
+       case GTK_ICON_SIZE_MENU:
+       case GTK_ICON_SIZE_SMALL_TOOLBAR:
+       case GTK_ICON_SIZE_BUTTON:
+               pixels = 16;
+               break;
+       case GTK_ICON_SIZE_LARGE_TOOLBAR:
+       case GTK_ICON_SIZE_DND:
+               pixels = 24;
+               break;
+       case GTK_ICON_SIZE_DIALOG:
+               pixels = 48;
+               break;
+       }
+
+       return gtk_icon_theme_load_icon (theme, icon_name, pixels, 0, NULL);
+}
diff --git a/goffice/gtk/goffice-gtk.h b/goffice/gtk/goffice-gtk.h
index eeba9bc..a79a2e5 100644
--- a/goffice/gtk/goffice-gtk.h
+++ b/goffice/gtk/goffice-gtk.h
@@ -133,6 +133,11 @@ void          go_menu_position_below (GtkMenu *menu, gint *x, gint *y,
 
 GError   *go_gtk_url_show (gchar const *url, GdkScreen *screen);
 
+GdkPixbuf *go_gtk_widget_render_icon_pixbuf (GtkWidget   *widget,
+                                            const gchar *icon_name,
+                                            GtkIconSize  size);
+
+
 G_END_DECLS
 
 #endif /* _GOFFICE_GTK_H_ */
diff --git a/goffice/utils/go-image.c b/goffice/utils/go-image.c
index 491fee7..f970d18 100644
--- a/goffice/utils/go-image.c
+++ b/goffice/utils/go-image.c
@@ -425,8 +425,8 @@ go_image_draw_fb (GOImage *image, cairo_t *cr)
                cairo_fill (cr);
        } else {
                GdkPixbuf *placeholder = gtk_icon_theme_load_icon
-                                                                                       
(gtk_icon_theme_get_default (),
-                                                                                        "unknown_image", 
100, 0, NULL);
+                       (gtk_icon_theme_get_default (),
+                        "unknown_image", 100, 0, NULL);
                double dx, dy;
                int n;
                if (placeholder == NULL)


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