[gtk+/icon-shadow: 7/9] entry: use gtk_render_icon()



commit 1f9e9720967c134e87e3912857427bf818381276
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue May 31 16:13:15 2011 -0400

    entry: use gtk_render_icon()

 gtk/gtkentry.c |   66 ++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 45 insertions(+), 21 deletions(-)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index b95fd8b..039dcc9 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -231,6 +231,8 @@ struct _EntryIconInfo
   gchar        *icon_name;
   GIcon        *gicon;
 
+  gboolean      symbolic;
+
   GtkTargetList *target_list;
   GdkDragAction actions;
 };
@@ -3372,26 +3374,35 @@ draw_icon (GtkWidget            *widget,
   x = (width  - gdk_pixbuf_get_width (pixbuf)) / 2;
   y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
 
-  icon_source = gtk_icon_source_new ();
-  gtk_icon_source_set_pixbuf (icon_source, pixbuf);
-  gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
+  if (!icon_info->symbolic)
+    {
+      GdkPixbuf *temp_pixbuf;
 
-  state = 0;
-  if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
-    state |= GTK_STATE_FLAG_INSENSITIVE;
-  else if (icon_info->prelight)
-    state |= GTK_STATE_FLAG_PRELIGHT;
+      icon_source = gtk_icon_source_new ();
+      gtk_icon_source_set_pixbuf (icon_source, pixbuf);
+      gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
 
-  context = gtk_widget_get_style_context (widget);
-  gtk_style_context_save (context);
-  gtk_style_context_set_state (context, state);
-  pixbuf = gtk_render_icon_pixbuf (context, icon_source, (GtkIconSize)-1);
-  gtk_style_context_restore (context);
+      state = 0;
+      if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
+        state |= GTK_STATE_FLAG_INSENSITIVE;
+      else if (icon_info->prelight)
+        state |= GTK_STATE_FLAG_PRELIGHT;
 
-  gtk_icon_source_free (icon_source);
+      context = gtk_widget_get_style_context (widget);
+      gtk_style_context_save (context);
+      gtk_style_context_set_state (context, state);
+      temp_pixbuf = gtk_render_icon_pixbuf (context, icon_source, (GtkIconSize)-1);
+      gtk_style_context_restore (context);
 
-  gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
-  cairo_paint (cr);
+      gtk_icon_source_free (icon_source);
+      
+      g_object_unref (pixbuf);
+      pixbuf = temp_pixbuf;
+    }
+
+  gtk_render_icon (context, cr,
+                   x, y, width, height,
+                   pixbuf);
 
   g_object_unref (pixbuf);
 }
@@ -6767,10 +6778,19 @@ gtk_entry_ensure_pixbuf (GtkEntry             *entry,
                                              GTK_ICON_SIZE_MENU,
                                              &width, &height);
 
-          icon_info->pixbuf = gtk_icon_theme_load_icon (icon_theme,
-                                                        icon_info->icon_name,
-                                                        MIN (width, height),
-                                                        0, NULL);
+          info = gtk_icon_theme_lookup_icon (icon_theme,
+                                             icon_info->icon_name,
+                                             MIN (width, height), 
+                                             0);
+          if (info)
+            {
+              icon_info->pixbuf = 
+                gtk_icon_info_load_symbolic_for_context (info,
+                                                         context,
+                                                         &icon_info->symbolic,
+                                                         NULL);
+              gtk_icon_info_free (info);
+            }
 
           if (icon_info->pixbuf == NULL)
             icon_info->pixbuf = create_normal_pixbuf (context,
@@ -6796,7 +6816,11 @@ gtk_entry_ensure_pixbuf (GtkEntry             *entry,
                                                  GTK_ICON_LOOKUP_USE_BUILTIN);
           if (info)
             {
-              icon_info->pixbuf = gtk_icon_info_load_icon (info, NULL);
+              icon_info->pixbuf = 
+                gtk_icon_info_load_symbolic_for_context (info,
+                                                         context,
+                                                         &icon_info->symbolic,
+                                                         NULL);
               gtk_icon_info_free (info);
             }
 



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