[gtk+] API: icontheme: Add 2 new GtkIconLookupFlags



commit 9619b8cff421614490d81f6bc6fe1a2ab3a0bd28
Author: Benjamin Otte <otte redhat com>
Date:   Sat May 10 15:35:12 2014 +0200

    API: icontheme: Add 2 new GtkIconLookupFlags
    
    GTK_ICON_LOOKUP_FORCE_REGULAR and GTK_ICON_LOOKUP_FORCE_SYMBOLIC can be
    used to force a regular or symbolic icon to be loaded, even if the icon
    names specify a different version.
    
    This is intended to support the CSS property -gtk-icon-style.

 gtk/gtkicontheme.c |   69 ++++++++++++++++++++++++++++++++++++++++++++++++----
 gtk/gtkicontheme.h |    8 +++++-
 2 files changed, 71 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 1d9209a..8bf1062 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -1592,11 +1592,11 @@ symbolic_pixbuf_cache_free (SymbolicPixbufCache *cache)
 }
 
 static GtkIconInfo *
-choose_icon (GtkIconTheme       *icon_theme,
-            const gchar        *icon_names[],
-            gint                size,
-             gint                scale,
-            GtkIconLookupFlags  flags)
+real_choose_icon (GtkIconTheme       *icon_theme,
+                  const gchar        *icon_names[],
+                  gint                size,
+                  gint                scale,
+                  GtkIconLookupFlags  flags)
 {
   GtkIconThemePrivate *priv;
   GList *l;
@@ -1794,6 +1794,65 @@ choose_icon (GtkIconTheme       *icon_theme,
   return icon_info;
 }
 
+static GtkIconInfo *
+choose_icon (GtkIconTheme       *icon_theme,
+             const gchar        *icon_names[],
+             gint                size,
+             gint                scale,
+             GtkIconLookupFlags  flags)
+{
+  gboolean has_regular = FALSE, has_symbolic = FALSE;
+  GtkIconInfo *icon_info;
+  gchar **new_names;
+  guint i;
+
+  for (i = 0; icon_names[i]; i++)
+    {
+      if (g_str_has_suffix (icon_names[i], "-symbolic"))
+        has_symbolic = TRUE;
+      else
+        has_regular = TRUE;
+    }
+
+  if ((flags & GTK_ICON_LOOKUP_FORCE_REGULAR) && has_symbolic)
+    {
+      new_names = g_new0 (gchar *, i + 1);
+      for (i = 0; icon_names[i]; i++)
+        {
+          if (g_str_has_suffix (icon_names[i], "-symbolic"))
+            new_names[i] = g_strndup (icon_names[i], strlen (icon_names[i]) - strlen ("-symbolic"));
+          else
+            new_names[i] = g_strdup (icon_names[i]);
+        }
+    }
+  else if ((flags & GTK_ICON_LOOKUP_FORCE_SYMBOLIC) && has_regular)
+    {
+      new_names = g_new0 (gchar *, i + 1);
+      for (i = 0; icon_names[i]; i++)
+        {
+          if (!g_str_has_suffix (icon_names[i], "-symbolic"))
+            new_names[i] = g_strconcat (icon_names[i], "-symbolic", NULL);
+          else
+            new_names[i] = g_strdup (icon_names[i]);
+        }
+    }
+  else
+    {
+      new_names = NULL;
+    }
+
+  icon_info = real_choose_icon (icon_theme,
+                                new_names ? (const gchar **) new_names : icon_names,
+                                size,
+                                scale,
+                                flags & ~(GTK_ICON_LOOKUP_FORCE_REGULAR | GTK_ICON_LOOKUP_FORCE_SYMBOLIC));
+
+  if (new_names)
+    g_strfreev (new_names);
+
+  return icon_info;
+}
+
 
 /**
  * gtk_icon_theme_lookup_icon:
diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h
index 84bb0b6..bdbaafe 100644
--- a/gtk/gtkicontheme.h
+++ b/gtk/gtkicontheme.h
@@ -113,6 +113,10 @@ struct _GtkIconThemeClass
  *   fallback, see gtk_icon_theme_choose_icon(). Since 2.12.
  * @GTK_ICON_LOOKUP_FORCE_SIZE: Always get the icon scaled to the
  *   requested size. Since 2.14.
+ * @GTK_ICON_LOOKUP_FORCE_REGULAR: Always load regular icons, even when
+ *   symbolic icon names are given. Since 3.14.
+ * @GTK_ICON_LOOKUP_FORCE_SYMBOLIC: Always load symbolic icons, even when
+ *   regular icon names are given. Since 3.14.
  * 
  * Used to specify options for gtk_icon_theme_lookup_icon()
  */
@@ -122,7 +126,9 @@ typedef enum
   GTK_ICON_LOOKUP_FORCE_SVG        = 1 << 1,
   GTK_ICON_LOOKUP_USE_BUILTIN      = 1 << 2,
   GTK_ICON_LOOKUP_GENERIC_FALLBACK = 1 << 3,
-  GTK_ICON_LOOKUP_FORCE_SIZE       = 1 << 4
+  GTK_ICON_LOOKUP_FORCE_SIZE       = 1 << 4,
+  GTK_ICON_LOOKUP_FORCE_REGULAR    = 1 << 5,
+  GTK_ICON_LOOKUP_FORCE_SYMBOLIC   = 1 << 6
 } GtkIconLookupFlags;
 
 /**


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