aboutsummaryrefslogtreecommitdiffstats
path: root/packages/gtk+/gtk+-2.6.4-1.osso7/gtkstyle.c.diff
blob: 6a94d96509a451cb042ae4b1184373df5dba189a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
--- gtk+-2.6.4/gtk/gtkstyle.c	2005-01-18 18:43:45.000000000 +0200
+++ gtk+-2.6.4/gtk/gtkstyle.c	2005-04-06 16:19:37.951768816 +0300
@@ -38,6 +38,7 @@
 #include "gtkthemes.h"
 #include "gtkiconfactory.h"
 #include "gtksettings.h"	/* _gtk_settings_parse_convert() */
+#include "gtkhashtable.h"
 
 #define LIGHTNESS_MULT  1.3
 #define DARKNESS_MULT   0.7
@@ -49,6 +50,14 @@
   GValue      value;
 } PropertyValue;
 
+#define GTK_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_STYLE, GtkStylePrivate))
+
+typedef struct _GtkStylePrivate GtkStylePrivate;
+
+struct _GtkStylePrivate {
+  GSList *logical_color_hashes;
+};
+
 /* --- prototypes --- */
 static void	 gtk_style_init			(GtkStyle	*style);
 static void	 gtk_style_class_init		(GtkStyleClass	*klass);
@@ -655,6 +664,7 @@
   klass->draw_layout = gtk_default_draw_layout;
   klass->draw_resize_grip = gtk_default_draw_resize_grip;
 
+  g_type_class_add_private (object_class, sizeof (GtkStylePrivate));
   
   /**
    * GtkStyle::realize:
@@ -714,9 +724,28 @@
 }
 
 static void
+free_object_list (GSList *list)
+{
+  if (list)
+    {
+      GSList *tmp_list = list;
+
+      while (tmp_list)
+	{
+	  g_object_unref (tmp_list->data);
+	  tmp_list = tmp_list->next;
+	}
+
+      g_slist_free (list);
+    }
+    
+}
+
+static void
 gtk_style_finalize (GObject *object)
 {
   GtkStyle *style = GTK_STYLE (object);
+  GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
 
   g_return_if_fail (style->attach_count == 0);
 
@@ -745,19 +774,9 @@
           g_slist_free_1 (style->styles);
         }
     }
-
-  if (style->icon_factories)
-    {
-      GSList *tmp_list = style->icon_factories;
-
-      while (tmp_list)
-	{
-	  g_object_unref (tmp_list->data);
-	  tmp_list = tmp_list->next;
-	}
-
-      g_slist_free (style->icon_factories);
-    }
+  
+  free_object_list (style->icon_factories);
+  free_object_list (priv->logical_color_hashes);
 
   pango_font_description_free (style->font_desc);
   
@@ -1003,6 +1022,51 @@
   return gtk_icon_factory_lookup_default (stock_id);
 }
 
+ /**
+ * gtk_style_lookup_logical_color:
+ * @style: a #GtkStyle
+ * @color_name: the name of the logical color to look up
+ * @color: the #GdkColor to fill in
+ *
+ * Looks up @color_name in the style's logical color mappings,
+ * filling in @color and returning %TRUE if found, otherwise
+ * returning %FALSE. Do not cache the found mapping, because
+ * it depends on the #GtkStyle and might change when a theme
+ * switch occurs.
+ *
+ * Return value: %TRUE if the mapping was found.
+ */
+gboolean
+gtk_style_lookup_logical_color (GtkStyle   *style,
+				const char *color_name,
+				GdkColor   *color)
+{
+  GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
+  GSList *iter;
+
+  g_return_val_if_fail (GTK_IS_STYLE (style), FALSE);
+  g_return_val_if_fail (color_name != NULL, FALSE);
+  g_return_val_if_fail (color != NULL, FALSE);
+  
+  iter = priv->logical_color_hashes;
+  while (iter != NULL)
+    {
+      GdkColor *mapping = g_hash_table_lookup (GTK_HASH_TABLE (iter->data)->hash,
+					       color_name);
+      if (mapping)
+        {
+          color->red = mapping->red;
+          color->green = mapping->green;
+          color->blue = mapping->blue;
+          return TRUE;
+        }
+      
+      iter = g_slist_next (iter);
+    }
+
+  return FALSE;
+}
+
 /**
  * gtk_draw_hline:
  * @style: a #GtkStyle
@@ -1717,10 +1781,32 @@
   clear_property_cache (style);
 }
 
+static GSList *
+copy_object_list (GSList *list)
+{
+  if (list)
+    {
+      GSList *iter;
+
+      iter = list;
+      while (iter != NULL)
+        {
+          g_object_ref (iter->data);
+          iter = g_slist_next (iter);
+        }
+      
+      return g_slist_copy (list);
+    }
+  else
+    return NULL;
+}
+
 static void
 gtk_style_real_init_from_rc (GtkStyle   *style,
 			     GtkRcStyle *rc_style)
 {
+  GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
+  GSList *logical_color_hashes;
   gint i;
 
   /* cache _should_ be still empty */
@@ -1746,19 +1832,10 @@
   if (rc_style->ythickness >= 0)
     style->ythickness = rc_style->ythickness;
 
-  if (rc_style->icon_factories)
-    {
-      GSList *iter;
+  style->icon_factories = copy_object_list (rc_style->icon_factories);
 
-      style->icon_factories = g_slist_copy (rc_style->icon_factories);
-      
-      iter = style->icon_factories;
-      while (iter != NULL)
-        {
-          g_object_ref (iter->data);
-          iter = g_slist_next (iter);
-        }
-    }
+  logical_color_hashes = _gtk_rc_style_get_logical_color_hashes (rc_style);
+  priv->logical_color_hashes = copy_object_list (logical_color_hashes);
 }
 
 static gint
@@ -2065,7 +2142,7 @@
                        const gchar         *detail)
 {
   GdkPixbuf *pixbuf;
-  
+
   g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
   g_return_val_if_fail (GTK_STYLE_GET_CLASS (style)->render_icon != NULL, NULL);
   
@@ -2156,7 +2233,7 @@
     {
       return gdk_pixbuf_scale_simple (src,
                                       width, height,
-                                      GDK_INTERP_BILINEAR);
+                                      GDK_INTERP_NEAREST);
     }
 }
 
@@ -2183,7 +2260,6 @@
    */
 
   base_pixbuf = gtk_icon_source_get_pixbuf (source);
-
   g_return_val_if_fail (base_pixbuf != NULL, NULL);
 
   if (widget && gtk_widget_has_screen (widget))
@@ -2213,7 +2289,9 @@
   /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
    * leave it alone.
    */
-  if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source))
+  /* Hildon addition: Device icons are never scaled */
+  if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source)
+      && size < HILDON_ICON_SIZE_26)
     scaled = scale_or_ref (base_pixbuf, width, height);
   else
     scaled = g_object_ref (base_pixbuf);
@@ -2224,7 +2302,7 @@
       if (state == GTK_STATE_INSENSITIVE)
         {
           stated = gdk_pixbuf_copy (scaled);      
-          
+
           gdk_pixbuf_saturate_and_pixelate (scaled, stated,
                                             0.8, TRUE);
           
@@ -2232,8 +2310,8 @@
         }
       else if (state == GTK_STATE_PRELIGHT)
         {
-          stated = gdk_pixbuf_copy (scaled);      
-          
+          stated = gdk_pixbuf_copy (scaled);
+
           gdk_pixbuf_saturate_and_pixelate (scaled, stated,
                                             1.2, FALSE);