]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkiconhelper.c
filechooser: Also convert get_uris() to returning native paths
[~andy/gtk] / gtk / gtkiconhelper.c
index 589f1e974228bce9e954375b04a8b632f1e24098..58ae8a15db776402e7195525b871e10672a5192e 100644 (file)
@@ -36,7 +36,8 @@ struct _GtkIconHelperPrivate {
   GtkIconSize icon_size;
   gint pixel_size;
 
-  gboolean use_fallback;
+  guint use_fallback : 1;
+  guint force_scale_pixbuf : 1;
 
   GdkPixbuf *rendered_pixbuf;
   GtkStateFlags last_rendered_state;
@@ -262,7 +263,7 @@ ensure_pixbuf_for_icon_name_or_gicon (GtkIconHelper *self,
   self->priv->rendered_pixbuf = ensure_stated_icon_from_info (self, context, info);
 
   if (info)
-    gtk_icon_info_free (info);
+    g_object_unref (info);
 }
 
 static void
@@ -277,6 +278,35 @@ ensure_pixbuf_for_icon_set (GtkIconHelper *self,
     gtk_icon_set_render_icon_pixbuf (icon_set, context, self->priv->icon_size);
 }
 
+static void
+ensure_pixbuf_at_size (GtkIconHelper   *self,
+                       GtkStyleContext *context)
+{
+  gint width, height;
+
+  if (!check_invalidate_pixbuf (self, context))
+    return;
+
+  if (self->priv->rendered_pixbuf)
+    return;
+
+  if (self->priv->pixel_size != -1 ||
+      self->priv->icon_size != GTK_ICON_SIZE_INVALID)
+    {
+      ensure_icon_size (self, context, &width, &height);
+
+      if (width < gdk_pixbuf_get_width (self->priv->orig_pixbuf) ||
+          height < gdk_pixbuf_get_height (self->priv->orig_pixbuf))
+        self->priv->rendered_pixbuf =
+          gdk_pixbuf_scale_simple (self->priv->orig_pixbuf,
+                                   width, height,
+                                   GDK_INTERP_BILINEAR);
+    }
+
+  if (!self->priv->rendered_pixbuf)
+    self->priv->rendered_pixbuf = g_object_ref (self->priv->orig_pixbuf);
+}
+
 GdkPixbuf *
 _gtk_icon_helper_ensure_pixbuf (GtkIconHelper *self,
                                 GtkStyleContext *context)
@@ -287,12 +317,18 @@ _gtk_icon_helper_ensure_pixbuf (GtkIconHelper *self,
   switch (self->priv->storage_type)
     {
     case GTK_IMAGE_PIXBUF:
-      pixbuf = g_object_ref (self->priv->orig_pixbuf);
+      if (self->priv->force_scale_pixbuf)
+        ensure_pixbuf_at_size (self, context);
+      else
+        pixbuf = g_object_ref (self->priv->orig_pixbuf);
       break;
 
     case GTK_IMAGE_STOCK:
       icon_set = gtk_style_context_lookup_icon_set (context, self->priv->stock_id);
-      ensure_pixbuf_for_icon_set (self, context, icon_set);
+      if (icon_set != NULL)
+       ensure_pixbuf_for_icon_set (self, context, icon_set);
+      else
+       pixbuf = NULL;
       break;
 
     case GTK_IMAGE_ICON_SET:
@@ -377,7 +413,7 @@ _gtk_icon_helper_set_icon_name (GtkIconHelper *self,
   _gtk_icon_helper_clear (self);
 
   if (icon_name != NULL &&
-      g_strcmp0 (icon_name, "") != 0)
+      icon_name[0] != '\0')
     {
       self->priv->storage_type = GTK_IMAGE_ICON_NAME;
       self->priv->icon_name = g_strdup (icon_name);
@@ -433,7 +469,8 @@ _gtk_icon_helper_set_stock_id (GtkIconHelper *self,
 {
   _gtk_icon_helper_clear (self);
 
-  if (stock_id != NULL)
+  if (stock_id != NULL &&
+      stock_id[0] != '\0')
     {
       self->priv->storage_type = GTK_IMAGE_STOCK;
       self->priv->stock_id = g_strdup (stock_id);
@@ -563,3 +600,20 @@ _gtk_icon_helper_get_is_empty (GtkIconHelper *self)
 {
   return (self->priv->storage_type == GTK_IMAGE_EMPTY);
 }
+
+gboolean
+_gtk_icon_helper_get_force_scale_pixbuf (GtkIconHelper *self)
+{
+  return self->priv->force_scale_pixbuf;
+}
+
+void
+_gtk_icon_helper_set_force_scale_pixbuf (GtkIconHelper *self,
+                                         gboolean       force_scale)
+{
+  if (self->priv->force_scale_pixbuf != force_scale)
+    {
+      self->priv->force_scale_pixbuf = force_scale;
+      _gtk_icon_helper_invalidate (self);
+    }
+}