eda143535301a2ba131ec65844119c2002639972
[mono.git] / bockbuild / mac-sdk / patches / gtk / 0062-cellrendererpixbuf-Use-scaled-icons-on-windows-with-.patch
1 From 52cba71be7d226b628731ea92c2064bf41f08b54 Mon Sep 17 00:00:00 2001
2 From: Carlos Garnacho <carlosg@gnome.org>
3 Date: Tue, 12 Feb 2013 14:04:09 +0100
4 Subject: [PATCH 62/68] cellrendererpixbuf: Use scaled icons on windows with a
5  scale factor
6
7 ---
8  gtk/gtkcellrendererpixbuf.c |  115 ++++++++++++++++++++++++++++++++++++++-----
9  1 file changed, 102 insertions(+), 13 deletions(-)
10
11 diff --git a/gtk/gtkcellrendererpixbuf.c b/gtk/gtkcellrendererpixbuf.c
12 index f689784..7c767b6 100644
13 --- a/gtk/gtkcellrendererpixbuf.c
14 +++ b/gtk/gtkcellrendererpixbuf.c
15 @@ -63,7 +63,8 @@ enum {
16    PROP_STOCK_DETAIL,
17    PROP_FOLLOW_STATE,
18    PROP_ICON_NAME,
19 -  PROP_GICON
20 +  PROP_GICON,
21 +  PROP_ICON_SET
22  };
23
24
25 @@ -78,6 +79,8 @@ struct _GtkCellRendererPixbufPrivate
26    gboolean follow_state;
27    gchar *icon_name;
28    GIcon *gicon;
29 +  GtkIconSet *icon_set;
30 +  gdouble render_scale;
31  };
32
33  G_DEFINE_TYPE (GtkCellRendererPixbuf, gtk_cell_renderer_pixbuf, GTK_TYPE_CELL_RENDERER)
34 @@ -173,6 +176,14 @@ gtk_cell_renderer_pixbuf_class_init (GtkCellRendererPixbufClass *class)
35                                                         NULL,
36                                                         GTK_PARAM_READWRITE));
37
38 +  g_object_class_install_property (object_class,
39 +                                   PROP_ICON_SET,
40 +                                   g_param_spec_boxed ("icon-set",
41 +                                                       P_("Icon set"),
42 +                                                       P_("Icon set to render the image from"),
43 +                                                       GTK_TYPE_ICON_SET,
44 +                                                       GTK_PARAM_READWRITE));
45 +
46    /**
47     * GtkCellRendererPixbuf:follow-state:
48     *
49 @@ -277,6 +288,9 @@ gtk_cell_renderer_pixbuf_get_property (GObject        *object,
50      case PROP_GICON:
51        g_value_set_object (value, priv->gicon);
52        break;
53 +    case PROP_ICON_SET:
54 +      g_value_set_boxed (value, priv->icon_set);
55 +      break;
56      default:
57        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
58        break;
59 @@ -300,6 +314,7 @@ gtk_cell_renderer_pixbuf_set_property (GObject      *object,
60        if (cellpixbuf->pixbuf)
61         g_object_unref (cellpixbuf->pixbuf);
62        cellpixbuf->pixbuf = (GdkPixbuf*) g_value_dup_object (value);
63 +      priv->render_scale = 1;
64        if (cellpixbuf->pixbuf)
65          {
66            if (priv->stock_id)
67 @@ -422,6 +437,7 @@ gtk_cell_renderer_pixbuf_set_property (GObject      *object,
68           g_object_unref (priv->gicon);
69         }
70        priv->gicon = (GIcon *) g_value_dup_object (value);
71 +      priv->render_scale = 1;
72        if (priv->gicon)
73          {
74           if (cellpixbuf->pixbuf)
75 @@ -444,6 +460,49 @@ gtk_cell_renderer_pixbuf_set_property (GObject      *object,
76              }
77          }
78        break;
79 +    case PROP_ICON_SET:
80 +      if (priv->icon_set)
81 +       {
82 +         if (cellpixbuf->pixbuf)
83 +           {
84 +             g_object_unref (cellpixbuf->pixbuf);
85 +             cellpixbuf->pixbuf = NULL;
86 +              g_object_notify (object, "pixbuf");
87 +           }
88 +
89 +          gtk_icon_set_unref (priv->icon_set);
90 +       }
91 +
92 +      priv->icon_set = g_value_dup_boxed (value);
93 +
94 +      if (priv->icon_set)
95 +        {
96 +         if (cellpixbuf->pixbuf)
97 +           {
98 +              g_object_unref (cellpixbuf->pixbuf);
99 +              cellpixbuf->pixbuf = NULL;
100 +              g_object_notify (object, "pixbuf");
101 +           }
102 +          if (priv->stock_id)
103 +            {
104 +              g_free (priv->stock_id);
105 +              priv->stock_id = NULL;
106 +              g_object_notify (object, "stock-id");
107 +            }
108 +          if (priv->icon_name)
109 +            {
110 +              g_free (priv->icon_name);
111 +              priv->icon_name = NULL;
112 +              g_object_notify (object, "icon-name");
113 +            }
114 +          if (priv->gicon)
115 +            {
116 +              g_object_unref (priv->gicon);
117 +              priv->gicon = NULL;
118 +              g_object_notify (object, "gicon");
119 +            }
120 +        }
121 +      break;
122      default:
123        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
124        break;
125 @@ -474,16 +533,19 @@ gtk_cell_renderer_pixbuf_create_stock_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
126                                                GtkWidget             *widget)
127  {
128    GtkCellRendererPixbufPrivate *priv;
129 +  GtkIconSet *icon_set;
130
131    priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (cellpixbuf);
132
133    if (cellpixbuf->pixbuf)
134      g_object_unref (cellpixbuf->pixbuf);
135
136 -  cellpixbuf->pixbuf = gtk_widget_render_icon (widget,
137 -                                               priv->stock_id,
138 -                                               priv->stock_size,
139 -                                               priv->stock_detail);
140 +  priv->render_scale = gtk_widget_get_scale_factor (widget);
141 +  cellpixbuf->pixbuf = gtk_widget_render_icon_scaled (widget,
142 +                                                      priv->stock_id,
143 +                                                      priv->stock_size,
144 +                                                      priv->stock_detail,
145 +                                                      &priv->render_scale);
146
147    g_object_notify (G_OBJECT (cellpixbuf), "pixbuf");
148  }
149 @@ -510,15 +572,24 @@ gtk_cell_renderer_pixbuf_create_themed_pixbuf (GtkCellRendererPixbuf *cellpixbuf
150    icon_theme = gtk_icon_theme_get_for_screen (screen);
151    settings = gtk_settings_get_for_screen (screen);
152
153 -  if (!gtk_icon_size_lookup_for_settings (settings,
154 -                                         priv->stock_size,
155 -                                         &width, &height))
156 +  if (!gtk_icon_size_lookup_scaled (settings,
157 +                                    priv->stock_size,
158 +                                    gdk_window_get_scale_factor (GTK_WIDGET (widget)->window),
159 +                                    &width, &height))
160      {
161        g_warning ("Invalid icon size %u\n", priv->stock_size);
162        width = height = 24;
163      }
164
165 -  if (priv->icon_name)
166 +  if (priv->icon_set)
167 +    cellpixbuf->pixbuf =
168 +      gtk_icon_set_render_icon_scaled (priv->icon_set,
169 +                                       widget->style,
170 +                                       gtk_widget_get_direction (widget),
171 +                                       gtk_widget_get_state (widget),
172 +                                       priv->stock_size, widget,
173 +                                       NULL, &priv->render_scale);
174 +  else if (priv->icon_name)
175      cellpixbuf->pixbuf = gtk_icon_theme_load_icon (icon_theme,
176                                                    priv->icon_name,
177                                                    MIN (width, height),
178 @@ -611,14 +682,28 @@ gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer *cell,
179      {
180        if (priv->stock_id)
181         gtk_cell_renderer_pixbuf_create_stock_pixbuf (cellpixbuf, widget);
182 +      else if (priv->icon_set)
183 +        {
184 +          gdouble scale;
185 +
186 +          scale = gtk_widget_get_scale_factor (widget);
187 +          cellpixbuf->pixbuf =
188 +            gtk_icon_set_render_icon_scaled (priv->icon_set,
189 +                                             widget->style,
190 +                                             gtk_widget_get_direction (widget),
191 +                                             gtk_widget_get_state (widget),
192 +                                             priv->stock_size,
193 +                                             widget, priv->stock_detail,
194 +                                             &scale);
195 +        }
196        else if (priv->icon_name || priv->gicon)
197         gtk_cell_renderer_pixbuf_create_themed_pixbuf (cellpixbuf, widget);
198      }
199
200    if (cellpixbuf->pixbuf)
201      {
202 -      pixbuf_width  = gdk_pixbuf_get_width (cellpixbuf->pixbuf);
203 -      pixbuf_height = gdk_pixbuf_get_height (cellpixbuf->pixbuf);
204 +      pixbuf_width  = gdk_pixbuf_get_width (cellpixbuf->pixbuf) / priv->render_scale;
205 +      pixbuf_height = gdk_pixbuf_get_height (cellpixbuf->pixbuf) / priv->render_scale;
206      }
207    if (cellpixbuf->pixbuf_expander_open)
208      {
209 @@ -761,10 +846,14 @@ gtk_cell_renderer_pixbuf_render (GtkCellRenderer      *cell,
210        pixbuf = colorized;
211      }
212
213 +  draw_rect.x -= pix_rect.x;
214 +  draw_rect.y -= pix_rect.y;
215 +
216    cr = gdk_cairo_create (window);
217 -
218 -  gdk_cairo_set_source_pixbuf (cr, pixbuf, pix_rect.x, pix_rect.y);
219 +  cairo_translate (cr, pix_rect.x, pix_rect.y);
220    gdk_cairo_rectangle (cr, &draw_rect);
221 +  cairo_scale (cr, 1 / priv->render_scale, 1 / priv->render_scale);
222 +  gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
223    cairo_fill (cr);
224
225    cairo_destroy (cr);
226 --
227 1.7.10.2 (Apple Git-33)