[gtksourceview/wip/chergert/gsv-gtk4: 144/192] pixbufhelper: track changes to GtkIconTheme




commit dad28174d48769df6b1973c1c65f92534cb034ad
Author: Christian Hergert <chergert redhat com>
Date:   Tue Mar 17 08:25:24 2020 -0700

    pixbufhelper: track changes to GtkIconTheme

 gtksourceview/gtksourcepixbufhelper.c | 65 +++++++++++------------------------
 tests/test-completion.c               | 12 ++++---
 2 files changed, 28 insertions(+), 49 deletions(-)
---
diff --git a/gtksourceview/gtksourcepixbufhelper.c b/gtksourceview/gtksourcepixbufhelper.c
index 32123c132..3f5359dec 100644
--- a/gtksourceview/gtksourcepixbufhelper.c
+++ b/gtksourceview/gtksourcepixbufhelper.c
@@ -57,7 +57,7 @@ gtk_source_pixbuf_helper_free (GtkSourcePixbufHelper *helper)
 
 static void
 set_cache (GtkSourcePixbufHelper *helper,
-          GdkPaintable          *paintable)
+           GdkPaintable          *paintable)
 {
        g_clear_object (&helper->cached_paintable);
        helper->cached_paintable = paintable;
@@ -159,10 +159,9 @@ from_gicon (GtkSourcePixbufHelper *helper,
             GtkWidget             *widget,
             gint                   size)
 {
-       GdkDisplay *display;
+       GtkIconPaintable *paintable = NULL;
        GtkIconTheme *icon_theme;
-       GtkIconInfo *info;
-       GtkIconLookupFlags flags;
+       GdkDisplay *display;
 
        if (helper->gicon == NULL)
        {
@@ -172,18 +171,14 @@ from_gicon (GtkSourcePixbufHelper *helper,
        display = gtk_widget_get_display (widget);
        icon_theme = gtk_icon_theme_get_for_display (display);
 
-       flags = GTK_ICON_LOOKUP_USE_BUILTIN;
+       paintable = gtk_icon_theme_lookup_by_gicon (icon_theme,
+                                                   helper->gicon,
+                                                   size,
+                                                   gtk_widget_get_scale_factor (widget),
+                                                   gtk_widget_get_direction (widget),
+                                                   GTK_ICON_LOOKUP_PRELOAD);
 
-       info = gtk_icon_theme_lookup_by_gicon (icon_theme,
-                                              helper->gicon,
-                                              size,
-                                              flags);
-
-       if (info)
-       {
-
-               set_cache (helper, gtk_icon_info_load_icon (info, NULL));
-       }
+       set_cache (helper, GDK_PAINTABLE (g_steal_pointer (&paintable)));
 }
 
 static void
@@ -191,11 +186,9 @@ from_name (GtkSourcePixbufHelper *helper,
            GtkWidget             *widget,
            gint                   size)
 {
-       GdkDisplay *display;
+       GtkIconPaintable *paintable;
        GtkIconTheme *icon_theme;
-       GtkIconInfo *info;
-       GtkIconLookupFlags flags;
-       gint scale;
+       GdkDisplay *display;
 
        if (helper->icon_name == NULL)
        {
@@ -205,33 +198,15 @@ from_name (GtkSourcePixbufHelper *helper,
        display = gtk_widget_get_display (widget);
        icon_theme = gtk_icon_theme_get_for_display (display);
 
-       flags = GTK_ICON_LOOKUP_USE_BUILTIN;
-        scale = gtk_widget_get_scale_factor (widget);
-
-       info = gtk_icon_theme_lookup_icon_for_scale (icon_theme,
-                                                    helper->icon_name,
-                                                    size,
-                                                    scale,
-                                                    flags);
-
-       if (info)
-       {
-               GdkPaintable *paintable;
+       paintable = gtk_icon_theme_lookup_icon (icon_theme,
+                                               helper->icon_name,
+                                               NULL,
+                                               size,
+                                               gtk_widget_get_scale_factor (widget),
+                                               gtk_widget_get_direction (widget),
+                                               GTK_ICON_LOOKUP_PRELOAD);
 
-               if (gtk_icon_info_is_symbolic (info))
-               {
-                       GtkStyleContext *context;
-
-                       context = gtk_widget_get_style_context (widget);
-                       paintable = gtk_icon_info_load_symbolic_for_context (info, context, NULL, NULL);
-               }
-               else
-               {
-                       paintable = gtk_icon_info_load_icon (info, NULL);
-               }
-
-               set_cache (helper, paintable);
-       }
+       set_cache (helper, GDK_PAINTABLE (g_steal_pointer (&paintable)));
 }
 
 GdkPaintable *
diff --git a/tests/test-completion.c b/tests/test-completion.c
index dbf4f5552..73c821c68 100644
--- a/tests/test-completion.c
+++ b/tests/test-completion.c
@@ -36,9 +36,9 @@ struct _TestProvider
        gint priority;
        gchar *name;
 
-       GdkPaintable *provider_icon;
+       GtkIconPaintable *provider_icon;
 
-       GdkPaintable *item_icon;
+       GtkIconPaintable *item_icon;
        GIcon *item_gicon;
 
        /* If it's a random provider, a subset of 'proposals' are choosen on
@@ -170,11 +170,15 @@ test_provider_init (TestProvider *self)
        GIcon *icon;
        GIcon *emblem_icon;
        GEmblem *emblem;
+       gint scale;
 
        theme = gtk_icon_theme_get_default ();
-       self->provider_icon = gtk_icon_theme_load_icon (theme, "dialog-information", 16, 0, NULL);
 
-       self->item_icon = gtk_icon_theme_load_icon (theme, "trophy-gold", 16, 0, NULL);
+       /* Just use some defaults for icons here. Normally we would create these with
+        * the widget to get proper direction, scale, etc.
+        */
+       self->provider_icon = gtk_icon_theme_lookup_icon (theme, "dialog-information", NULL, 16, 1, 
GTK_TEXT_DIR_LTR, GTK_ICON_LOOKUP_PRELOAD);
+       self->item_icon = gtk_icon_theme_lookup_icon (theme, "trophy-gold", NULL, 16, 1, GTK_TEXT_DIR_LTR, 
GTK_ICON_LOOKUP_PRELOAD);
 
        icon = g_themed_icon_new ("trophy-gold");
        emblem_icon = g_themed_icon_new ("emblem-urgent");


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