[gtk+/wip/baedert/symbolic-icons: 5/8] GtkImage: Do not always invalidate the icon helper



commit 6781a94b775b1d9ec05647b3295e276a15e5437b
Author: Timm Bäder <mail baedert org>
Date:   Fri Feb 5 09:32:56 2016 +0100

    GtkImage: Do not always invalidate the icon helper
    
    If the css change only affects symbolic icons, but the icon helper's
    surface is noy symbolic, don't invalidate it -- and don't inavlidate it
    either if the css change affects colored icons but the icon helper's
    surface is symbolic.

 gtk/gtkimage.c |  101 +++++++++++++++++++++++++++++---------------------------
 1 files changed, 52 insertions(+), 49 deletions(-)
---
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index 32d43bd..8a6830c 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -19,7 +19,7 @@
  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
  * file for a list of people on the GTK+ Team.  See the ChangeLog
  * files for a list of changes.  These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
  */
 
 #include "config.h"
@@ -235,7 +235,7 @@ gtk_image_class_init (GtkImageClass *class)
   GtkWidgetClass *widget_class;
 
   gobject_class = G_OBJECT_CLASS (class);
-  
+
   gobject_class->set_property = gtk_image_set_property;
   gobject_class->get_property = gtk_image_get_property;
   gobject_class->finalize = gtk_image_finalize;
@@ -511,7 +511,7 @@ gtk_image_set_property (GObject      *object,
     }
 }
 
-static void 
+static void
 gtk_image_get_property (GObject     *object,
                        guint        prop_id,
                        GValue      *value,
@@ -573,7 +573,7 @@ gtk_image_get_property (GObject     *object,
 /**
  * gtk_image_new_from_file:
  * @filename: (type filename): a filename
- * 
+ *
  * Creates a new #GtkImage displaying the file @filename. If the file
  * isn’t found or can’t be loaded, the resulting #GtkImage will
  * display a “broken image” icon. This function never returns %NULL,
@@ -590,7 +590,7 @@ gtk_image_get_property (GObject     *object,
  * The storage type (gtk_image_get_storage_type()) of the returned
  * image is not defined, it will be whatever is appropriate for
  * displaying the file.
- * 
+ *
  * Returns: a new #GtkImage
  **/
 GtkWidget*
@@ -650,11 +650,11 @@ gtk_image_new_from_resource (const gchar *resource_path)
  * The #GtkImage does not assume a reference to the
  * pixbuf; you still need to unref it if you own references.
  * #GtkImage will add its own reference rather than adopting yours.
- * 
+ *
  * Note that this function just creates an #GtkImage from the pixbuf. The
- * #GtkImage created will not react to state changes. Should you want that, 
+ * #GtkImage created will not react to state changes. Should you want that,
  * you should use gtk_image_new_from_icon_name().
- * 
+ *
  * Returns: a new #GtkImage
  **/
 GtkWidget*
@@ -666,7 +666,7 @@ gtk_image_new_from_pixbuf (GdkPixbuf *pixbuf)
 
   gtk_image_set_from_pixbuf (image, pixbuf);
 
-  return GTK_WIDGET (image);  
+  return GTK_WIDGET (image);
 }
 
 /**
@@ -677,7 +677,7 @@ gtk_image_new_from_pixbuf (GdkPixbuf *pixbuf)
  * The #GtkImage does not assume a reference to the
  * surface; you still need to unref it if you own references.
  * #GtkImage will add its own reference rather than adopting yours.
- * 
+ *
  * Returns: a new #GtkImage
  *
  * Since: 3.10
@@ -691,21 +691,21 @@ gtk_image_new_from_surface (cairo_surface_t *surface)
 
   gtk_image_set_from_surface (image, surface);
 
-  return GTK_WIDGET (image);  
+  return GTK_WIDGET (image);
 }
 
 /**
  * gtk_image_new_from_stock:
  * @stock_id: a stock icon name
  * @size: (type int): a stock icon size (#GtkIconSize)
- * 
+ *
  * Creates a #GtkImage displaying a stock icon. Sample stock icon
  * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. Sample stock sizes
  * are #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_SMALL_TOOLBAR. If the stock
  * icon name isn’t known, the image will be empty.
  * You can register your own stock icon names, see
  * gtk_icon_factory_add_default() and gtk_icon_factory_add().
- * 
+ *
  * Returns: a new #GtkImage displaying the stock icon
  *
  * Deprecated: 3.10: Use gtk_image_new_from_icon_name() instead.
@@ -741,7 +741,7 @@ gtk_image_new_from_stock (const gchar    *stock_id,
  * The #GtkImage does not assume a reference to the
  * icon set; you still need to unref it if you own references.
  * #GtkImage will add its own reference rather than adopting yours.
- * 
+ *
  * Returns: a new #GtkImage
  *
  * Deprecated: 3.10: Use gtk_image_new_from_icon_name() instead.
@@ -766,7 +766,7 @@ gtk_image_new_from_icon_set (GtkIconSet     *icon_set,
 /**
  * gtk_image_new_from_animation:
  * @animation: an animation
- * 
+ *
  * Creates a #GtkImage displaying the given animation.
  * The #GtkImage does not assume a reference to the
  * animation; you still need to unref it if you own references.
@@ -785,7 +785,7 @@ gtk_image_new_from_animation (GdkPixbufAnimation *animation)
   GtkImage *image;
 
   g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), NULL);
-  
+
   image = g_object_new (GTK_TYPE_IMAGE, NULL);
 
   gtk_image_set_from_animation (image, animation);
@@ -797,12 +797,12 @@ gtk_image_new_from_animation (GdkPixbufAnimation *animation)
  * gtk_image_new_from_icon_name:
  * @icon_name: an icon name
  * @size: (type int): a stock icon size (#GtkIconSize)
- * 
+ *
  * Creates a #GtkImage displaying an icon from the current icon theme.
  * If the icon name isn’t known, a “broken image” icon will be
  * displayed instead.  If the current icon theme is changed, the icon
  * will be updated appropriately.
- * 
+ *
  * Returns: a new #GtkImage displaying the themed icon
  *
  * Since: 2.6
@@ -824,12 +824,12 @@ gtk_image_new_from_icon_name (const gchar    *icon_name,
  * gtk_image_new_from_gicon:
  * @icon: an icon
  * @size: (type int): a stock icon size (#GtkIconSize)
- * 
+ *
  * Creates a #GtkImage displaying an icon from the current icon theme.
  * If the icon name isn’t known, a “broken image” icon will be
  * displayed instead.  If the current icon theme is changed, the icon
  * will be updated appropriately.
- * 
+ *
  * Returns: a new #GtkImage displaying the themed icon
  *
  * Since: 2.14
@@ -951,13 +951,13 @@ gtk_image_set_from_file   (GtkImage    *image,
   GtkImagePrivate *priv;
   GdkPixbufAnimation *anim;
   gint scale_factor;
-  
+
   g_return_if_fail (GTK_IS_IMAGE (image));
 
   priv = image->priv;
 
   g_object_freeze_notify (G_OBJECT (image));
-  
+
   gtk_image_clear (image);
 
   if (filename == NULL)
@@ -994,7 +994,7 @@ gtk_image_set_from_file   (GtkImage    *image,
   g_object_unref (anim);
 
   priv->filename = g_strdup (filename);
-  
+
   g_object_thaw_notify (G_OBJECT (image));
 }
 
@@ -1075,14 +1075,14 @@ gtk_image_set_from_pixbuf (GtkImage  *image,
   priv = image->priv;
 
   g_object_freeze_notify (G_OBJECT (image));
-  
+
   gtk_image_clear (image);
 
   if (pixbuf != NULL)
     _gtk_icon_helper_set_pixbuf (priv->icon_helper, pixbuf);
 
   g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_PIXBUF]);
-  
+
   g_object_thaw_notify (G_OBJECT (image));
 }
 
@@ -1173,7 +1173,7 @@ gtk_image_set_from_icon_set  (GtkImage       *image,
  * gtk_image_set_from_animation:
  * @image: a #GtkImage
  * @animation: the #GdkPixbufAnimation
- * 
+ *
  * Causes the #GtkImage to display the given animation (or display
  * nothing, if you set the animation to %NULL).
  **/
@@ -1190,7 +1190,7 @@ gtk_image_set_from_animation (GtkImage           *image,
   priv = image->priv;
 
   g_object_freeze_notify (G_OBJECT (image));
-  
+
   if (animation)
     g_object_ref (animation);
 
@@ -1214,7 +1214,7 @@ gtk_image_set_from_animation (GtkImage           *image,
  * @size: (type int): an icon size (#GtkIconSize)
  *
  * See gtk_image_new_from_icon_name() for details.
- * 
+ *
  * Since: 2.6
  **/
 void
@@ -1248,7 +1248,7 @@ gtk_image_set_from_icon_name  (GtkImage       *image,
  * @size: (type int): an icon size (#GtkIconSize)
  *
  * See gtk_image_new_from_gicon() for details.
- * 
+ *
  * Since: 2.14
  **/
 void
@@ -1277,7 +1277,7 @@ gtk_image_set_from_gicon  (GtkImage       *image,
 
   g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_GICON]);
   g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_ICON_SIZE]);
-  
+
   g_object_thaw_notify (G_OBJECT (image));
 }
 
@@ -1287,7 +1287,7 @@ gtk_image_set_from_gicon  (GtkImage       *image,
  * @surface: a cairo_surface_t
  *
  * See gtk_image_new_from_surface() for details.
- * 
+ *
  * Since: 3.10
  **/
 void
@@ -1314,18 +1314,18 @@ gtk_image_set_from_surface (GtkImage       *image,
     }
 
   g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_SURFACE]);
-  
+
   g_object_thaw_notify (G_OBJECT (image));
 }
 
 /**
  * gtk_image_get_storage_type:
  * @image: a #GtkImage
- * 
+ *
  * Gets the type of representation being used by the #GtkImage
  * to store image data. If the #GtkImage has no image data,
  * the return value will be %GTK_IMAGE_EMPTY.
- * 
+ *
  * Returns: image representation being used
  **/
 GtkImageType
@@ -1345,7 +1345,7 @@ gtk_image_get_storage_type (GtkImage *image)
  * %GTK_IMAGE_PIXBUF (see gtk_image_get_storage_type()).
  * The caller of this function does not own a reference to the
  * returned pixbuf.
- * 
+ *
  * Returns: (nullable) (transfer none): the displayed pixbuf, or %NULL if
  * the image is empty
  **/
@@ -1432,7 +1432,7 @@ gtk_image_get_icon_set  (GtkImage        *image,
  * %GTK_IMAGE_ANIMATION (see gtk_image_get_storage_type()).
  * The caller of this function does not own a reference to the
  * returned animation.
- * 
+ *
  * Returns: (nullable) (transfer none): the displayed animation, or %NULL if
  * the image is empty
  **/
@@ -1461,7 +1461,7 @@ gtk_image_get_animation (GtkImage *image)
  * %GTK_IMAGE_ICON_NAME (see gtk_image_get_storage_type()).
  * The returned string is owned by the #GtkImage and should not
  * be freed.
- * 
+ *
  * Since: 2.6
  **/
 void
@@ -1495,7 +1495,7 @@ gtk_image_get_icon_name  (GtkImage     *image,
  * %GTK_IMAGE_GICON (see gtk_image_get_storage_type()).
  * The caller of this function does not own a reference to the
  * returned #GIcon.
- * 
+ *
  * Since: 2.14
  **/
 void
@@ -1518,10 +1518,10 @@ gtk_image_get_gicon (GtkImage     *image,
 
 /**
  * gtk_image_new:
- * 
+ *
  * Creates a new empty #GtkImage widget.
- * 
- * Returns: a newly created #GtkImage widget. 
+ *
+ * Returns: a newly created #GtkImage widget.
  **/
 GtkWidget*
 gtk_image_new (void)
@@ -1623,7 +1623,7 @@ get_animation_frame (GtkImage *image)
     {
       int delay;
 
-      priv->animation_iter = 
+      priv->animation_iter =
         gdk_pixbuf_animation_get_iter (_gtk_icon_helper_peek_animation (priv->icon_helper), NULL);
 
       delay = gdk_pixbuf_animation_iter_get_delay_time (priv->animation_iter);
@@ -1810,7 +1810,7 @@ gtk_image_set_from_definition (GtkImage           *image,
   priv = image->priv;
 
   g_object_freeze_notify (G_OBJECT (image));
-  
+
   gtk_image_clear (image);
 
   if (def != NULL)
@@ -1821,7 +1821,7 @@ gtk_image_set_from_definition (GtkImage           *image,
     }
 
   _gtk_icon_helper_set_icon_size (priv->icon_helper, icon_size);
-  
+
   g_object_thaw_notify (G_OBJECT (image));
 }
 
@@ -1929,8 +1929,11 @@ gtk_image_style_updated (GtkWidget *widget)
   if (context)
     {
       GtkCssStyleChange *change = gtk_style_context_get_change (context);
+      gboolean symbolic = gtk_icon_helper_surface_is_symbolic (priv->icon_helper);
 
-      if (change && gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_ICON))
+      if (change &&
+          ((gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_SYMBOLIC_ICON) && symbolic) ||
+           (gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_ICON) && !symbolic)))
         gtk_icon_helper_invalidate (priv->icon_helper);
     }
 
@@ -1943,20 +1946,20 @@ gtk_image_style_updated (GtkWidget *widget)
  * gtk_image_set_pixel_size:
  * @image: a #GtkImage
  * @pixel_size: the new pixel size
- * 
+ *
  * Sets the pixel size to use for named icons. If the pixel size is set
  * to a value != -1, it is used instead of the icon size set by
  * gtk_image_set_from_icon_name().
  *
  * Since: 2.6
  */
-void 
+void
 gtk_image_set_pixel_size (GtkImage *image,
                          gint      pixel_size)
 {
   g_return_if_fail (GTK_IS_IMAGE (image));
 
-  if (_gtk_icon_helper_set_pixel_size (image->priv->icon_helper, pixel_size)) 
+  if (_gtk_icon_helper_set_pixel_size (image->priv->icon_helper, pixel_size))
     {
       if (gtk_widget_get_visible (GTK_WIDGET (image)))
         gtk_widget_queue_resize (GTK_WIDGET (image));
@@ -1967,7 +1970,7 @@ gtk_image_set_pixel_size (GtkImage *image,
 /**
  * gtk_image_get_pixel_size:
  * @image: a #GtkImage
- * 
+ *
  * Gets the pixel size used for named icons.
  *
  * Returns: the pixel size used for named icons.


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