]> Pileus Git - ~andy/gtk/blob - gtk/gtksettings.c
Add translator comment
[~andy/gtk] / gtk / gtksettings.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2000 Red Hat, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #define PANGO_ENABLE_BACKEND /* for pango_fc_font_map_cache_clear() */
20
21 #include "config.h"
22
23 #include <string.h>
24
25 #include "gtkmodules.h"
26 #include "gtksettings.h"
27 #include "gtkrc.h"
28 #include "gtkintl.h"
29 #include "gtkwidget.h"
30 #include "gtkprivate.h"
31 #include "gtkalias.h"
32
33 #ifdef GDK_WINDOWING_X11
34 #include "x11/gdkx.h"
35 #include <pango/pangofc-fontmap.h>
36 #endif
37
38 #define DEFAULT_TIMEOUT_INITIAL 200
39 #define DEFAULT_TIMEOUT_REPEAT   20
40 #define DEFAULT_TIMEOUT_EXPAND  500
41
42 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
43
44 typedef enum
45 {
46   GTK_SETTINGS_SOURCE_DEFAULT,
47   GTK_SETTINGS_SOURCE_RC_FILE,
48   GTK_SETTINGS_SOURCE_XSETTING,
49   GTK_SETTINGS_SOURCE_APPLICATION
50 } GtkSettingsSource;
51
52 struct _GtkSettingsValuePrivate
53 {
54   GtkSettingsValue public;
55   GtkSettingsSource source;
56 };
57
58 struct _GtkSettingsPropertyValue
59 {
60   GValue value;
61   GtkSettingsSource source;
62 };
63
64 enum {
65   PROP_0,
66   PROP_DOUBLE_CLICK_TIME,
67   PROP_DOUBLE_CLICK_DISTANCE,
68   PROP_CURSOR_BLINK,
69   PROP_CURSOR_BLINK_TIME,
70   PROP_CURSOR_BLINK_TIMEOUT,
71   PROP_SPLIT_CURSOR,
72   PROP_THEME_NAME,
73   PROP_ICON_THEME_NAME,
74   PROP_FALLBACK_ICON_THEME,
75   PROP_KEY_THEME_NAME,
76   PROP_MENU_BAR_ACCEL,
77   PROP_DND_DRAG_THRESHOLD,
78   PROP_FONT_NAME,
79   PROP_ICON_SIZES,
80   PROP_MODULES,
81 #ifdef GDK_WINDOWING_X11
82   PROP_XFT_ANTIALIAS,
83   PROP_XFT_HINTING,
84   PROP_XFT_HINTSTYLE,
85   PROP_XFT_RGBA,
86   PROP_XFT_DPI,
87   PROP_CURSOR_THEME_NAME,
88   PROP_CURSOR_THEME_SIZE,
89 #endif
90   PROP_ALTERNATIVE_BUTTON_ORDER,
91   PROP_ALTERNATIVE_SORT_ARROWS,
92   PROP_SHOW_INPUT_METHOD_MENU,
93   PROP_SHOW_UNICODE_MENU,
94   PROP_TIMEOUT_INITIAL,
95   PROP_TIMEOUT_REPEAT,
96   PROP_TIMEOUT_EXPAND,
97   PROP_COLOR_SCHEME,
98   PROP_ENABLE_ANIMATIONS,
99   PROP_TOUCHSCREEN_MODE,
100   PROP_TOOLTIP_TIMEOUT,
101   PROP_TOOLTIP_BROWSE_TIMEOUT,
102   PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
103   PROP_KEYNAV_CURSOR_ONLY,
104   PROP_KEYNAV_WRAP_AROUND,
105   PROP_ERROR_BELL,
106   PROP_COLOR_HASH,
107   PROP_FILE_CHOOSER_BACKEND,
108   PROP_PRINT_BACKENDS,
109   PROP_PRINT_PREVIEW_COMMAND,
110   PROP_ENABLE_MNEMONICS,
111   PROP_ENABLE_ACCELS,
112   PROP_RECENT_FILES_LIMIT,
113   PROP_IM_MODULE,
114   PROP_RECENT_FILES_MAX_AGE,
115   PROP_FONTCONFIG_TIMESTAMP,
116   PROP_SOUND_THEME_NAME,
117   PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
118   PROP_ENABLE_EVENT_SOUNDS,
119   PROP_ENABLE_TOOLTIPS
120 };
121
122
123 /* --- prototypes --- */
124 static void     gtk_settings_finalize            (GObject               *object);
125 static void     gtk_settings_get_property        (GObject               *object,
126                                                   guint                  property_id,
127                                                   GValue                *value,
128                                                   GParamSpec            *pspec);
129 static void     gtk_settings_set_property        (GObject               *object,
130                                                   guint                  property_id,
131                                                   const GValue          *value,
132                                                   GParamSpec            *pspec);
133 static void     gtk_settings_notify              (GObject               *object,
134                                                   GParamSpec            *pspec);
135 static guint    settings_install_property_parser (GtkSettingsClass      *class,
136                                                   GParamSpec            *pspec,
137                                                   GtkRcPropertyParser    parser);
138 static void    settings_update_double_click      (GtkSettings           *settings);
139 static void    settings_update_modules           (GtkSettings           *settings);
140
141 #ifdef GDK_WINDOWING_X11
142 static void    settings_update_cursor_theme      (GtkSettings           *settings);
143 static void    settings_update_resolution        (GtkSettings           *settings);
144 static void    settings_update_font_options      (GtkSettings           *settings);
145 static gboolean settings_update_fontconfig       (GtkSettings           *settings);
146 #endif
147 static void    settings_update_color_scheme      (GtkSettings *settings);
148
149 static void    merge_color_scheme                (GtkSettings           *settings, 
150                                                   const GValue          *value, 
151                                                   GtkSettingsSource      source);
152 static gchar  *get_color_scheme                  (GtkSettings           *settings);
153 static GHashTable *get_color_hash                (GtkSettings           *settings);
154
155
156 /* --- variables --- */
157 static GQuark            quark_property_parser = 0;
158 static GSList           *object_list = NULL;
159 static guint             class_n_properties = 0;
160
161
162 G_DEFINE_TYPE (GtkSettings, gtk_settings, G_TYPE_OBJECT)
163
164 /* --- functions --- */
165 static void
166 gtk_settings_init (GtkSettings *settings)
167 {
168   GParamSpec **pspecs, **p;
169   guint i = 0;
170   
171   g_datalist_init (&settings->queued_settings);
172   object_list = g_slist_prepend (object_list, settings);
173
174   /* build up property array for all yet existing properties and queue
175    * notification for them (at least notification for internal properties
176    * will instantly be caught)
177    */
178   pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
179   for (p = pspecs; *p; p++)
180     if ((*p)->owner_type == G_OBJECT_TYPE (settings))
181       i++;
182   settings->property_values = g_new0 (GtkSettingsPropertyValue, i);
183   i = 0;
184   g_object_freeze_notify (G_OBJECT (settings));
185   for (p = pspecs; *p; p++)
186     {
187       GParamSpec *pspec = *p;
188
189       if (pspec->owner_type != G_OBJECT_TYPE (settings))
190         continue;
191       g_value_init (&settings->property_values[i].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
192       g_param_value_set_default (pspec, &settings->property_values[i].value);
193       g_object_notify (G_OBJECT (settings), pspec->name);
194       settings->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
195       i++;
196     }
197   g_object_thaw_notify (G_OBJECT (settings));
198   g_free (pspecs);
199 }
200
201 static void
202 gtk_settings_class_init (GtkSettingsClass *class)
203 {
204   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
205   guint result;
206   
207   gobject_class->finalize = gtk_settings_finalize;
208   gobject_class->get_property = gtk_settings_get_property;
209   gobject_class->set_property = gtk_settings_set_property;
210   gobject_class->notify = gtk_settings_notify;
211
212   quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
213   result = settings_install_property_parser (class,
214                                              g_param_spec_int ("gtk-double-click-time",
215                                                                P_("Double Click Time"),
216                                                                P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
217                                                                0, G_MAXINT, 250,
218                                                                GTK_PARAM_READWRITE),
219                                              NULL);
220   g_assert (result == PROP_DOUBLE_CLICK_TIME);
221   result = settings_install_property_parser (class,
222                                              g_param_spec_int ("gtk-double-click-distance",
223                                                                P_("Double Click Distance"),
224                                                                P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
225                                                                0, G_MAXINT, 5,
226                                                                GTK_PARAM_READWRITE),
227                                              NULL);
228   g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
229
230   /**
231    * GtkSettings:gtk-cursor-blink:
232    *
233    * Whether the cursor should blink. 
234    *
235    * Also see the #GtkSettings:gtk-cursor-blink-timeout setting, 
236    * which allows more flexible control over cursor blinking.
237    */
238   result = settings_install_property_parser (class,
239                                              g_param_spec_boolean ("gtk-cursor-blink",
240                                                                    P_("Cursor Blink"),
241                                                                    P_("Whether the cursor should blink"),
242                                                                    TRUE,
243                                                                    GTK_PARAM_READWRITE),
244                                              NULL);
245   g_assert (result == PROP_CURSOR_BLINK);
246   result = settings_install_property_parser (class,
247                                              g_param_spec_int ("gtk-cursor-blink-time",
248                                                                P_("Cursor Blink Time"),
249                                                                P_("Length of the cursor blink cycle, in milliseconds"),
250                                                                100, G_MAXINT, 1200,
251                                                                GTK_PARAM_READWRITE),
252                                              NULL);
253   g_assert (result == PROP_CURSOR_BLINK_TIME);
254  
255   /**
256    * GtkSettings:gtk-cursor-blink-timeout:
257    *
258    * Time after which the cursor stops blinking, in seconds.
259    * The timer is reset after each user interaction.
260    *
261    * Setting this to zero has the same effect as setting
262    * #GtkSettings:gtk-cursor-blink to %FALSE. 
263    *
264    * Since: 2.12
265    */
266   result = settings_install_property_parser (class,
267                                              g_param_spec_int ("gtk-cursor-blink-timeout",
268                                                                P_("Cursor Blink Timeout"),
269                                                                P_("Time after which the cursor stops blinking, in seconds"),
270                                                                1, G_MAXINT, G_MAXINT,
271                                                                GTK_PARAM_READWRITE),
272                                              NULL);
273   g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
274   result = settings_install_property_parser (class,
275                                              g_param_spec_boolean ("gtk-split-cursor",
276                                                                    P_("Split Cursor"),
277                                                                    P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
278                                                                    TRUE,
279                                                                    GTK_PARAM_READWRITE),
280                                              NULL);
281   g_assert (result == PROP_SPLIT_CURSOR);
282   result = settings_install_property_parser (class,
283                                              g_param_spec_string ("gtk-theme-name",
284                                                                    P_("Theme Name"),
285                                                                    P_("Name of theme RC file to load"),
286                                                                   "Raleigh",
287                                                                   GTK_PARAM_READWRITE),
288                                              NULL);
289   g_assert (result == PROP_THEME_NAME);
290
291   result = settings_install_property_parser (class,
292                                              g_param_spec_string ("gtk-icon-theme-name",
293                                                                   P_("Icon Theme Name"),
294                                                                   P_("Name of icon theme to use"),
295                                                                   "hicolor",
296                                                                   GTK_PARAM_READWRITE),
297                                              NULL);
298   g_assert (result == PROP_ICON_THEME_NAME);
299
300   result = settings_install_property_parser (class,
301                                              g_param_spec_string ("gtk-fallback-icon-theme",
302                                                                   P_("Fallback Icon Theme Name"),
303                                                                   P_("Name of a icon theme to fall back to"),
304                                                                   NULL,
305                                                                   GTK_PARAM_READWRITE),
306                                              NULL);
307   g_assert (result == PROP_FALLBACK_ICON_THEME);
308   
309   result = settings_install_property_parser (class,
310                                              g_param_spec_string ("gtk-key-theme-name",
311                                                                   P_("Key Theme Name"),
312                                                                   P_("Name of key theme RC file to load"),
313                                                                   NULL,
314                                                                   GTK_PARAM_READWRITE),
315                                              NULL);
316   g_assert (result == PROP_KEY_THEME_NAME);    
317
318   result = settings_install_property_parser (class,
319                                              g_param_spec_string ("gtk-menu-bar-accel",
320                                                                   P_("Menu bar accelerator"),
321                                                                   P_("Keybinding to activate the menu bar"),
322                                                                   "F10",
323                                                                   GTK_PARAM_READWRITE),
324                                              NULL);
325   g_assert (result == PROP_MENU_BAR_ACCEL);
326
327   result = settings_install_property_parser (class,
328                                              g_param_spec_int ("gtk-dnd-drag-threshold",
329                                                                P_("Drag threshold"),
330                                                                P_("Number of pixels the cursor can move before dragging"),
331                                                                1, G_MAXINT, 8,
332                                                                GTK_PARAM_READWRITE),
333                                              NULL);
334   g_assert (result == PROP_DND_DRAG_THRESHOLD);
335
336   result = settings_install_property_parser (class,
337                                              g_param_spec_string ("gtk-font-name",
338                                                                    P_("Font Name"),
339                                                                    P_("Name of default font to use"),
340                                                                   "Sans 10",
341                                                                   GTK_PARAM_READWRITE),
342                                              NULL);
343   g_assert (result == PROP_FONT_NAME);
344
345   /**
346    * GtkSettings:gtk-icon-sizes:
347    *
348    * A list of icon sizes. The list is separated by colons, and
349    * item has the form:
350    *
351    * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
352    *
353    * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48". 
354    * GTK+ itself use the following named icon sizes: gtk-menu, 
355    * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd, 
356    * gtk-dialog. Applications can register their own named icon 
357    * sizes with gtk_icon_size_register().
358    */
359   result = settings_install_property_parser (class,
360                                              g_param_spec_string ("gtk-icon-sizes",
361                                                                    P_("Icon Sizes"),
362                                                                    P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
363                                                                   NULL,
364                                                                   GTK_PARAM_READWRITE),
365                                              NULL);
366   g_assert (result == PROP_ICON_SIZES);
367
368   result = settings_install_property_parser (class,
369                                              g_param_spec_string ("gtk-modules",
370                                                                   P_("GTK Modules"),
371                                                                   P_("List of currently active GTK modules"),
372                                                                   NULL,
373                                                                   GTK_PARAM_READWRITE),
374                                              NULL);
375   g_assert (result == PROP_MODULES);
376
377 #ifdef GDK_WINDOWING_X11
378   result = settings_install_property_parser (class,
379                                              g_param_spec_int ("gtk-xft-antialias",
380                                                                P_("Xft Antialias"),
381                                                                P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
382                                                                -1, 1, -1,
383                                                                GTK_PARAM_READWRITE),
384                                              NULL);
385  
386   g_assert (result == PROP_XFT_ANTIALIAS);
387   
388   result = settings_install_property_parser (class,
389                                              g_param_spec_int ("gtk-xft-hinting",
390                                                                P_("Xft Hinting"),
391                                                                P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
392                                                                -1, 1, -1,
393                                                                GTK_PARAM_READWRITE),
394                                              NULL);
395   
396   g_assert (result == PROP_XFT_HINTING);
397   
398   result = settings_install_property_parser (class,
399                                              g_param_spec_string ("gtk-xft-hintstyle",
400                                                                   P_("Xft Hint Style"),
401                                                                   P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
402                                                                   NULL,
403                                                                   GTK_PARAM_READWRITE),
404                                               NULL);
405   
406   g_assert (result == PROP_XFT_HINTSTYLE);
407   
408   result = settings_install_property_parser (class,
409                                              g_param_spec_string ("gtk-xft-rgba",
410                                                                   P_("Xft RGBA"),
411                                                                   P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
412                                                                   NULL,
413                                                                   GTK_PARAM_READWRITE),
414                                              NULL);
415   
416   g_assert (result == PROP_XFT_RGBA);
417   
418   result = settings_install_property_parser (class,
419                                              g_param_spec_int ("gtk-xft-dpi",
420                                                                P_("Xft DPI"),
421                                                                P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
422                                                                -1, 1024*1024, -1,
423                                                                GTK_PARAM_READWRITE),
424                                              NULL);
425   
426   g_assert (result == PROP_XFT_DPI);
427
428   result = settings_install_property_parser (class,
429                                              g_param_spec_string ("gtk-cursor-theme-name",
430                                                                   P_("Cursor theme name"),
431                                                                   P_("Name of the cursor theme to use, or NULL to use the default theme"),
432                                                                   NULL,
433                                                                   GTK_PARAM_READWRITE),
434                                              NULL);
435   g_assert (result == PROP_CURSOR_THEME_NAME);
436
437   result = settings_install_property_parser (class,
438                                              g_param_spec_int ("gtk-cursor-theme-size",
439                                                                P_("Cursor theme size"),
440                                                                P_("Size to use for cursors, or 0 to use the default size"),
441                                                                0, 128, 0,
442                                                                GTK_PARAM_READWRITE),
443                                              NULL);
444   
445   g_assert (result == PROP_CURSOR_THEME_SIZE);
446
447 #endif  /* GDK_WINDOWING_X11 */
448   result = settings_install_property_parser (class,
449                                              g_param_spec_boolean ("gtk-alternative-button-order",
450                                                                    P_("Alternative button order"),
451                                                                    P_("Whether buttons in dialogs should use the alternative button order"),
452                                                                    FALSE,
453                                                                    GTK_PARAM_READWRITE),
454                                              NULL);
455   g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
456
457   /**
458    * GtkSettings:gtk-alternative-sort-arrows:
459    *
460    * Controls the direction of the sort indicators in sorted list and tree
461    * views. By default an arrow pointing down means the column is sorted
462    * in ascending order. When set to %TRUE, this order will be inverted.
463    *
464    * Since: 2.12
465    */
466   result = settings_install_property_parser (class,
467                                              g_param_spec_boolean ("gtk-alternative-sort-arrows",
468                                                                    P_("Alternative sort indicator direction"),
469                                                                    P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
470                                                                    FALSE,
471                                                                    GTK_PARAM_READWRITE),
472                                              NULL);
473   g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
474
475   result = settings_install_property_parser (class,
476                                              g_param_spec_boolean ("gtk-show-input-method-menu",
477                                                                    P_("Show the 'Input Methods' menu"),
478                                                                    P_("Whether the context menus of entries and text views should offer to change the input method"),
479                                                                    TRUE,
480                                                                    GTK_PARAM_READWRITE),
481                                              NULL);
482   g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
483
484   result = settings_install_property_parser (class,
485                                              g_param_spec_boolean ("gtk-show-unicode-menu",
486                                                                    P_("Show the 'Insert Unicode Control Character' menu"),
487                                                                    P_("Whether the context menus of entries and text views should offer to insert control characters"),
488                                                                    TRUE,
489                                                                    GTK_PARAM_READWRITE),
490                                              NULL);
491   g_assert (result == PROP_SHOW_UNICODE_MENU);
492
493   result = settings_install_property_parser (class,
494                                              g_param_spec_int ("gtk-timeout-initial",
495                                                                P_("Start timeout"),
496                                                                P_("Starting value for timeouts, when button is pressed"),
497                                                                0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
498                                                                GTK_PARAM_READWRITE),
499                                              NULL);
500
501   g_assert (result == PROP_TIMEOUT_INITIAL);
502
503   result = settings_install_property_parser (class,
504                                              g_param_spec_int ("gtk-timeout-repeat",
505                                                                P_("Repeat timeout"),
506                                                                P_("Repeat value for timeouts, when button is pressed"),
507                                                                0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
508                                                                GTK_PARAM_READWRITE),
509                                              NULL);
510
511   g_assert (result == PROP_TIMEOUT_REPEAT);
512
513   result = settings_install_property_parser (class,
514                                              g_param_spec_int ("gtk-timeout-expand",
515                                                                P_("Expand timeout"),
516                                                                P_("Expand value for timeouts, when a widget is expanding a new region"),
517                                                                0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
518                                                                GTK_PARAM_READWRITE),
519                                              NULL);
520
521   g_assert (result == PROP_TIMEOUT_EXPAND);
522
523   /**
524    * GtkSettings:gtk-color-scheme:
525    *
526    * A palette of named colors for use in themes. The format of the string is
527    * <programlisting>
528    * name1: color1
529    * name2: color2
530    * ...
531    * </programlisting>
532    * Color names must be acceptable as identifiers in the 
533    * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
534    * color specifications must be in the format accepted by
535    * gdk_color_parse().
536    * 
537    * Note that due to the way the color tables from different sources are
538    * merged, color specifications will be converted to hexadecimal form
539    * when getting this property.
540    *
541    * Starting with GTK+ 2.12, the entries can alternatively be separated
542    * by ';' instead of newlines:
543    * <programlisting>
544    * name1: color1; name2: color2; ...
545    * </programlisting>
546    *
547    * Since: 2.10
548    */
549   result = settings_install_property_parser (class,
550                                              g_param_spec_string ("gtk-color-scheme",
551                                                                   P_("Color scheme"),
552                                                                   P_("A palette of named colors for use in themes"),
553                                                                   "",
554                                                                   GTK_PARAM_READWRITE),
555                                              NULL);
556
557   g_assert (result == PROP_COLOR_SCHEME);
558
559   result = settings_install_property_parser (class,
560                                              g_param_spec_boolean ("gtk-enable-animations",
561                                                                    P_("Enable Animations"),
562                                                                    P_("Whether to enable toolkit-wide animations."),
563                                                                    TRUE,
564                                                                    GTK_PARAM_READWRITE),
565                                              NULL);
566
567   g_assert (result == PROP_ENABLE_ANIMATIONS);
568
569   /**
570    * GtkSettings:gtk-touchscreen-mode:
571    *
572    * When %TRUE, there are no motion notify events delivered on this screen,
573    * and widgets can't use the pointer hovering them for any essential
574    * functionality.
575    *
576    * Since: 2.10
577    */
578   result = settings_install_property_parser (class,
579                                              g_param_spec_boolean ("gtk-touchscreen-mode",
580                                                                    P_("Enable Touchscreen Mode"),
581                                                                    P_("When TRUE, there are no motion notify events delivered on this screen"),
582                                                                    FALSE,
583                                                                    GTK_PARAM_READWRITE),
584                                              NULL);
585
586   g_assert (result == PROP_TOUCHSCREEN_MODE);
587
588   /**
589    * GtkSettings:gtk-tooltip-timeout:
590    *
591    * Time, in milliseconds, after which a tooltip could appear if the
592    * cursor is hovering on top of a widget.
593    *
594    * Since: 2.12
595    */
596   result = settings_install_property_parser (class,
597                                              g_param_spec_int ("gtk-tooltip-timeout",
598                                                                P_("Tooltip timeout"),
599                                                                P_("Timeout before tooltip is shown"),
600                                                                0, G_MAXINT,
601                                                                500,
602                                                                GTK_PARAM_READWRITE),
603                                              NULL);
604
605   g_assert (result == PROP_TOOLTIP_TIMEOUT);
606
607   /**
608    * GtkSettings:gtk-tooltip-browse-timeout:
609    *
610    * Controls the time after which tooltips will appear when
611    * browse mode is enabled, in milliseconds.
612    *
613    * Browse mode is enabled when the mouse pointer moves off an object
614    * where a tooltip was currently being displayed. If the mouse pointer
615    * hits another object before the browse mode timeout expires (see
616    * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the 
617    * amount of milliseconds specified by this setting to popup the tooltip
618    * for the new object.
619    *
620    * Since: 2.12
621    */
622   result = settings_install_property_parser (class,
623                                              g_param_spec_int ("gtk-tooltip-browse-timeout",
624                                                                P_("Tooltip browse timeout"),
625                                                                P_("Timeout before tooltip is shown when browse mode is enabled"),
626                                                                0, G_MAXINT,
627                                                                60,
628                                                                GTK_PARAM_READWRITE),
629                                              NULL);
630
631   g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
632
633   /**
634    * GtkSettings:gtk-tooltip-browse-mode-timeout:
635    *
636    * Amount of time, in milliseconds, after which the browse mode
637    * will be disabled.
638    *
639    * See #GtkSettings:gtk-tooltip-browse-timeout for more information
640    * about browse mode.
641    *
642    * Since: 2.12
643    */
644   result = settings_install_property_parser (class,
645                                              g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
646                                                                P_("Tooltip browse mode timeout"),
647                                                                P_("Timeout after which browse mode is disabled"),
648                                                                0, G_MAXINT,
649                                                                500,
650                                                                GTK_PARAM_READWRITE),
651                                              NULL);
652
653   g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
654
655   /**
656    * GtkSettings:gtk-keynav-cursor-only:
657    *
658    * When %TRUE, keyboard navigation should be able to reach all widgets
659    * by using the cursor keys only. Tab, Shift etc. keys can't be expected
660    * to be present on the used input device.
661    *
662    * Since: 2.12
663    */
664   result = settings_install_property_parser (class,
665                                              g_param_spec_boolean ("gtk-keynav-cursor-only",
666                                                                    P_("Keynav Cursor Only"),
667                                                                    P_("When TRUE, there are only cursor keys available to navigate widgets"),
668                                                                    FALSE,
669                                                                    GTK_PARAM_READWRITE),
670                                              NULL);
671
672   g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
673
674   /**
675    * GtkSettings:gtk-keynav-wrap-around:
676    *
677    * When %TRUE, some widgets will wrap around when doing keyboard
678    * navigation, such as menus, menubars and notebooks.
679    *
680    * Since: 2.12
681    */
682   result = settings_install_property_parser (class,
683                                              g_param_spec_boolean ("gtk-keynav-wrap-around",
684                                                                    P_("Keynav Wrap Around"),
685                                                                    P_("Whether to wrap around when keyboard-navigating widgets"),
686                                                                    TRUE,
687                                                                    GTK_PARAM_READWRITE),
688                                              NULL);
689
690   g_assert (result == PROP_KEYNAV_WRAP_AROUND);
691
692   /**
693    * GtkSettings:gtk-error-bell:
694    *
695    * When %TRUE, keyboard navigation and other input-related errors
696    * will cause a beep. Since the error bell is implemented using
697    * gdk_window_beep(), the windowing system may offer ways to
698    * configure the error bell in many ways, such as flashing the
699    * window or similar visual effects.
700    *
701    * Since: 2.12
702    */
703   result = settings_install_property_parser (class,
704                                              g_param_spec_boolean ("gtk-error-bell",
705                                                                    P_("Error Bell"),
706                                                                    P_("When TRUE, keyboard navigation and other errors will cause a beep"),
707                                                                    TRUE,
708                                                                    GTK_PARAM_READWRITE),
709                                              NULL);
710
711   g_assert (result == PROP_ERROR_BELL);
712
713   /**
714    * GtkSettings:color-hash:
715    *
716    * Holds a hash table representation of the #GtkSettings:gtk-color-scheme 
717    * setting, mapping color names to #GdkColor<!-- -->s. 
718    *
719    * Since: 2.10
720    */
721   result = settings_install_property_parser (class, 
722                                              g_param_spec_boxed ("color-hash",
723                                                                  P_("Color Hash"),
724                                                                  P_("A hash table representation of the color scheme."),
725                                                                  G_TYPE_HASH_TABLE,
726                                                                  GTK_PARAM_READABLE),
727                                              NULL);
728   g_assert (result == PROP_COLOR_HASH);
729
730   result = settings_install_property_parser (class, 
731                                              g_param_spec_string ("gtk-file-chooser-backend",
732                                                                   P_("Default file chooser backend"),
733                                                                   P_("Name of the GtkFileChooser backend to use by default"),
734                                                                   NULL,
735                                                                   GTK_PARAM_READWRITE),
736                                              NULL);
737   g_assert (result == PROP_FILE_CHOOSER_BACKEND);
738
739   /**
740    * GtkSettings:gtk-print-backends:
741    *
742    * A comma-separated list of print backends to use in the print
743    * dialog. Available print backends depend on the GTK+ installation,
744    * and may include "pdf", "cups" or "lpr".
745    *
746    * Since: 2.10
747    */
748   result = settings_install_property_parser (class,
749                                              g_param_spec_string ("gtk-print-backends",
750                                                                   P_("Default print backend"),
751                                                                   P_("List of the GtkPrintBackend backends to use by default"),
752                                                                   GTK_PRINT_BACKENDS,
753                                                                   GTK_PARAM_READWRITE),
754                                              NULL);
755   g_assert (result == PROP_PRINT_BACKENDS);
756
757   /**
758    * GtkSettings:gtk-print-preview-command:
759    *
760    * A command to run for displaying the print preview. The command
761    * should contain a %f placeholder, which will get replaced by
762    * the path to the pdf file. The command may also contain a %s
763    * placeholder, which will get replaced by the path to a file
764    * containing the print settings in the format produced by 
765    * gtk_print_settings_to_file().
766    *
767    * The preview application is responsible for removing the pdf file
768    * and the print settings file when it is done.
769    *
770    * Since: 2.10
771    */
772   result = settings_install_property_parser (class,
773                                              g_param_spec_string ("gtk-print-preview-command",
774                                                                   P_("Default command to run when displaying a print preview"),
775                                                                   P_("Command to run when displaying a print preview"),
776                                                                   GTK_PRINT_PREVIEW_COMMAND,
777                                                                   GTK_PARAM_READWRITE),
778                                              NULL); 
779   g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
780
781   /**
782    * GtkSettings:gtk-enable-mnemonics:
783    *
784    * Whether labels and menu items should have visible mnemonics which
785    * can be activated.
786    *
787    * Since: 2.12
788    */
789   result = settings_install_property_parser (class,
790                                              g_param_spec_boolean ("gtk-enable-mnemonics",
791                                                                    P_("Enable Mnemonics"),
792                                                                    P_("Whether labels should have mnemonics"),
793                                                                    TRUE,
794                                                                    GTK_PARAM_READWRITE),
795                                              NULL);
796   g_assert (result == PROP_ENABLE_MNEMONICS);
797
798   /**
799    * GtkSettings:gtk-enable-accels:
800    *
801    * Whether menu items should have visible accelerators which can be
802    * activated.
803    *
804    * Since: 2.12
805    */
806   result = settings_install_property_parser (class,
807                                              g_param_spec_boolean ("gtk-enable-accels",
808                                                                    P_("Enable Accelerators"),
809                                                                    P_("Whether menu items should have accelerators"),
810                                                                    TRUE,
811                                                                    GTK_PARAM_READWRITE),
812                                              NULL);
813   g_assert (result == PROP_ENABLE_ACCELS);
814
815   /**
816    * GtkSettings:gtk-recent-files-limit:
817    *
818    * The number of recently used files that should be displayed by default by
819    * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
820    * -1 means every recently used file stored.
821    *
822    * Since: 2.12
823    */
824   result = settings_install_property_parser (class,
825                                              g_param_spec_int ("gtk-recent-files-limit",
826                                                                P_("Recent Files Limit"),
827                                                                P_("Number of recently used files"),
828                                                                -1, G_MAXINT,
829                                                                50,
830                                                                GTK_PARAM_READWRITE),
831                                              NULL);
832   g_assert (result == PROP_RECENT_FILES_LIMIT);
833
834   /**
835    * GtkSettings:gtk-im-module:
836    *
837    * Which IM module should be used by default.
838    */
839   result = settings_install_property_parser (class,
840                                              g_param_spec_string ("gtk-im-module",
841                                                                   P_("Default IM module"),
842                                                                   P_("Which IM module should be used by default"),
843                                                                   NULL,
844                                                                   GTK_PARAM_READWRITE),
845                                              NULL);
846   g_assert (result == PROP_IM_MODULE);
847
848   /**
849    * GtkSettings:gtk-recent-files-max-age:
850    *
851    * The maximum age, in days, of the items inside the recently used
852    * resources list. Items older than this setting will be excised
853    * from the list. If set to 0, the list will always be empty; if
854    * set to -1, no item will be removed.
855    *
856    * Since: 2.14
857    */
858   result = settings_install_property_parser (class,
859                                              g_param_spec_int ("gtk-recent-files-max-age",
860                                                                P_("Recent Files Max Age"),
861                                                                P_("Maximum age of recently used files, in days"),
862                                                                -1, G_MAXINT,
863                                                                30,
864                                                                GTK_PARAM_READWRITE),
865                                              NULL);
866   g_assert (result == PROP_RECENT_FILES_MAX_AGE);
867
868   result = settings_install_property_parser (class,
869                                              g_param_spec_int ("gtk-fontconfig-timestamp",
870                                                                P_("Fontconfig configuration timestamp"),
871                                                                P_("Timestamp of current fontconfig configuration"),
872                                                                G_MININT, G_MAXINT, 0,
873                                                                GTK_PARAM_READWRITE),
874                                              NULL);
875   
876   g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
877
878   /**
879    * GtkSettings:gtk-sound-theme-name:
880    *
881    * The XDG sound theme to use for event sounds.
882    *
883    * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink> 
884    * for more information on event sounds and sound themes.
885    *
886    * GTK+ itself does not support event sounds, you have to use a loadable 
887    * module like the one that comes with libcanberra.
888    *
889    * Since: 2.14
890    */
891   result = settings_install_property_parser (class,
892                                              g_param_spec_string ("gtk-sound-theme-name",
893                                                                   P_("Sound Theme Name"),
894                                                                   P_("XDG sound theme name"),
895                                                                   "freedesktop",
896                                                                   GTK_PARAM_READWRITE),
897                                              NULL);
898   g_assert (result == PROP_SOUND_THEME_NAME);
899
900   /**
901    * GtkSettings:gtk-enable-input-feedback-sounds:
902    *
903    * Whether to play event sounds as feedback to user input.
904    *
905    * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink> 
906    * for more information on event sounds and sound themes.
907    *
908    * GTK+ itself does not support event sounds, you have to use a loadable 
909    * module like the one that comes with libcanberra.
910    *
911    * Since: 2.14
912    */
913   result = settings_install_property_parser (class,
914                                              g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
915                                                                    /* Translators: this means sounds that are played as feedback to user input */
916                                                                    P_("Aureal Input Feedback"),
917                                                                    P_("Whether to play event sounds as feedback to user input"),
918                                                                    TRUE,
919                                                                    GTK_PARAM_READWRITE),
920                                              NULL);
921   g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
922
923   /**
924    * GtkSettings:gtk-enable-event-sounds:
925    *
926    * Whether to play any event sounds at all.
927    *
928    * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink> 
929    * for more information on event sounds and sound themes.
930    *
931    * GTK+ itself does not support event sounds, you have to use a loadable 
932    * module like the one that comes with libcanberra.
933    *
934    * Since: 2.14
935    */
936   result = settings_install_property_parser (class,
937                                              g_param_spec_boolean ("gtk-enable-event-sounds",
938                                                                    P_("Enable Event Sounds"),
939                                                                    P_("Whether to play any event sounds at all"),
940                                                                    TRUE,
941                                                                    GTK_PARAM_READWRITE),
942                                              NULL);
943   g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
944
945   /**
946    * GtkSettings:gtk-enable-tooltips:
947    *
948    * Whether tooltips should be shown on widgets.
949    *
950    * Since: 2.14
951    */
952   result = settings_install_property_parser (class,
953                                              g_param_spec_boolean ("gtk-enable-tooltips",
954                                                                    P_("Enable Tooltips"),
955                                                                    P_("Whether tooltips should be shown on widgets"),
956                                                                    TRUE,
957                                                                    GTK_PARAM_READWRITE),
958                                              NULL);
959   g_assert (result == PROP_ENABLE_TOOLTIPS);
960 }
961
962 static void
963 gtk_settings_finalize (GObject *object)
964 {
965   GtkSettings *settings = GTK_SETTINGS (object);
966   guint i;
967
968   object_list = g_slist_remove (object_list, settings);
969
970   _gtk_rc_context_destroy (settings);
971
972   for (i = 0; i < class_n_properties; i++)
973     g_value_unset (&settings->property_values[i].value);
974   g_free (settings->property_values);
975   
976   g_datalist_clear (&settings->queued_settings);
977
978   G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
979 }
980
981 /**
982  * gtk_settings_get_for_screen:
983  * @screen : a #GdkScreen.
984  * 
985  * Gets the #GtkSettings object for @screen, creating it if necessary.
986  *
987  * Return value: a #GtkSettings object.
988  *
989  * Since: 2.2
990  */
991 GtkSettings*
992 gtk_settings_get_for_screen (GdkScreen *screen)
993 {
994   GtkSettings *settings;
995   
996   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
997   
998   settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
999   if (!settings)
1000     {
1001       settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1002       settings->screen = screen;
1003       g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"), 
1004                               settings, g_object_unref);
1005
1006       gtk_rc_reparse_all_for_settings (settings, TRUE);
1007       settings_update_double_click (settings);
1008 #ifdef GDK_WINDOWING_X11
1009       settings_update_cursor_theme (settings);
1010       settings_update_resolution (settings);
1011       settings_update_font_options (settings);
1012 #endif
1013       settings_update_color_scheme (settings);
1014     }
1015   
1016   return settings;
1017 }
1018
1019 /**
1020  * gtk_settings_get_default:
1021  * 
1022  * Gets the #GtkSettings object for the default GDK screen, creating
1023  * it if necessary. See gtk_settings_get_for_screen().
1024  * 
1025  * Return value: a #GtkSettings object. If there is no default
1026  *  screen, then returns %NULL.
1027  **/
1028 GtkSettings*
1029 gtk_settings_get_default (void)
1030 {
1031   GdkScreen *screen = gdk_screen_get_default ();
1032
1033   if (screen)
1034     return gtk_settings_get_for_screen (screen);
1035   else
1036     return NULL;
1037 }
1038
1039 static void
1040 gtk_settings_set_property (GObject      *object,
1041                            guint         property_id,
1042                            const GValue *value,
1043                            GParamSpec   *pspec)
1044 {
1045   GtkSettings *settings = GTK_SETTINGS (object);
1046
1047   g_value_copy (value, &settings->property_values[property_id - 1].value);
1048   settings->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1049   
1050   if (pspec->param_id == PROP_COLOR_SCHEME)
1051     merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1052 }
1053
1054 static void
1055 gtk_settings_get_property (GObject     *object,
1056                            guint        property_id,
1057                            GValue      *value,
1058                            GParamSpec  *pspec)
1059 {
1060   GtkSettings *settings = GTK_SETTINGS (object);
1061   GType value_type = G_VALUE_TYPE (value);
1062   GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1063
1064   /* handle internal properties */
1065   switch (property_id)
1066     {
1067     case PROP_COLOR_HASH:
1068       g_value_set_boxed (value, get_color_hash (settings));
1069       return;
1070     case PROP_COLOR_SCHEME:
1071       g_value_take_string (value, get_color_scheme (settings));
1072       return;
1073     default: ;
1074     }
1075
1076   /* For enums and strings, we need to get the value as a string,
1077    * not as an int, since we support using names/nicks as the setting
1078    * value.
1079    */
1080   if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1081        !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1082       g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1083       g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1084     {
1085       if (settings->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1086           !gdk_screen_get_setting (settings->screen, pspec->name, value))
1087         g_value_copy (&settings->property_values[property_id - 1].value, value);
1088       else 
1089         g_param_value_validate (pspec, value);
1090     }
1091   else
1092     {
1093       GValue val = { 0, };
1094
1095       /* Try to get xsetting as a string and parse it. */
1096       
1097       g_value_init (&val, G_TYPE_STRING);
1098
1099       if (settings->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1100           !gdk_screen_get_setting (settings->screen, pspec->name, &val))
1101         {
1102           g_value_copy (&settings->property_values[property_id - 1].value, value);
1103         }
1104       else
1105         {
1106           GValue tmp_value = { 0, };
1107           GValue gstring_value = { 0, };
1108           GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1109           
1110           g_value_init (&gstring_value, G_TYPE_GSTRING);
1111           g_value_take_boxed (&gstring_value,
1112                               g_string_new (g_value_get_string (&val)));
1113
1114           g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1115
1116           if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1117                                                      pspec, &tmp_value))
1118             {
1119               g_value_copy (&tmp_value, value);
1120               g_param_value_validate (pspec, value);
1121             }
1122           else
1123             {
1124               g_value_copy (&settings->property_values[property_id - 1].value, value);
1125             }
1126
1127           g_value_unset (&gstring_value);
1128           g_value_unset (&tmp_value);
1129         }
1130
1131       g_value_unset (&val);
1132     }
1133 }
1134
1135 static void
1136 gtk_settings_notify (GObject    *object,
1137                      GParamSpec *pspec)
1138 {
1139   GtkSettings *settings = GTK_SETTINGS (object);
1140   guint property_id = pspec->param_id;
1141
1142   if (settings->screen == NULL) /* initialization */
1143     return;
1144
1145   switch (property_id)
1146     {
1147     case PROP_MODULES:
1148       settings_update_modules (settings);
1149       break;
1150     case PROP_DOUBLE_CLICK_TIME:
1151     case PROP_DOUBLE_CLICK_DISTANCE:
1152       settings_update_double_click (settings);
1153       break;
1154     case PROP_COLOR_SCHEME:
1155       settings_update_color_scheme (settings);
1156       break;
1157 #ifdef GDK_WINDOWING_X11
1158     case PROP_XFT_DPI:
1159       settings_update_resolution (settings);
1160       /* This is a hack because with gtk_rc_reset_styles() doesn't get
1161        * widgets with gtk_widget_style_set(), and also causes more
1162        * recomputation than necessary.
1163        */
1164       gtk_rc_reset_styles (GTK_SETTINGS (object));
1165       break;
1166     case PROP_XFT_ANTIALIAS:
1167     case PROP_XFT_HINTING:
1168     case PROP_XFT_HINTSTYLE:
1169     case PROP_XFT_RGBA:
1170       settings_update_font_options (settings);
1171       gtk_rc_reset_styles (GTK_SETTINGS (object));
1172       break;
1173     case PROP_FONTCONFIG_TIMESTAMP:
1174       if (settings_update_fontconfig (settings))
1175         gtk_rc_reset_styles (GTK_SETTINGS (object));
1176       break;
1177     case PROP_CURSOR_THEME_NAME:
1178     case PROP_CURSOR_THEME_SIZE:
1179       settings_update_cursor_theme (settings);
1180       break;
1181 #endif /* GDK_WINDOWING_X11 */
1182     }
1183 }
1184
1185 gboolean
1186 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1187                              const GValue       *src_value,
1188                              GParamSpec         *pspec,
1189                              GValue             *dest_value)
1190 {
1191   gboolean success = FALSE;
1192
1193   g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1194
1195   if (parser)
1196     {
1197       GString *gstring;
1198       gboolean free_gstring = TRUE;
1199       
1200       if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1201         {
1202           gstring = g_value_get_boxed (src_value);
1203           free_gstring = FALSE;
1204         }
1205       else if (G_VALUE_HOLDS_LONG (src_value))
1206         {
1207           gstring = g_string_new (NULL);
1208           g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1209         }
1210       else if (G_VALUE_HOLDS_DOUBLE (src_value))
1211         {
1212           gstring = g_string_new (NULL);
1213           g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1214         }
1215       else if (G_VALUE_HOLDS_STRING (src_value))
1216         {
1217           gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1218           
1219           gstring = g_string_new ("\"");
1220           g_string_append (gstring, tstr);
1221           g_string_append_c (gstring, '\"');
1222           g_free (tstr);
1223         }
1224       else
1225         {
1226           g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1227           gstring = NULL; /* silence compiler */
1228         }
1229
1230       success = (parser (pspec, gstring, dest_value) &&
1231                  !g_param_value_validate (pspec, dest_value));
1232
1233       if (free_gstring)
1234         g_string_free (gstring, TRUE);
1235     }
1236   else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1237     {
1238       if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1239         {
1240           GString *gstring = g_value_get_boxed (src_value);
1241
1242           g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1243           success = !g_param_value_validate (pspec, dest_value);
1244         }
1245     }
1246   else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1247     success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1248
1249   return success;
1250 }
1251
1252 static void
1253 apply_queued_setting (GtkSettings             *data,
1254                       GParamSpec              *pspec,
1255                       GtkSettingsValuePrivate *qvalue)
1256 {
1257   GValue tmp_value = { 0, };
1258   GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1259
1260   g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1261   if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1262                                    pspec, &tmp_value))
1263     {
1264       if (pspec->param_id == PROP_COLOR_SCHEME) 
1265         merge_color_scheme (data, &tmp_value, qvalue->source);
1266
1267       if (data->property_values[pspec->param_id - 1].source <= qvalue->source)
1268         {
1269           g_value_copy (&tmp_value, &data->property_values[pspec->param_id - 1].value);
1270           data->property_values[pspec->param_id - 1].source = qvalue->source;
1271           g_object_notify (G_OBJECT (data), g_param_spec_get_name (pspec));
1272         }
1273
1274     }
1275   else
1276     {
1277       gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1278       
1279       g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1280                  qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1281                  pspec->name,
1282                  g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1283                  debug,
1284                  G_VALUE_TYPE_NAME (&tmp_value));
1285       g_free (debug);
1286     }
1287   g_value_unset (&tmp_value);
1288 }
1289
1290 static guint
1291 settings_install_property_parser (GtkSettingsClass   *class,
1292                                   GParamSpec         *pspec,
1293                                   GtkRcPropertyParser parser)
1294 {
1295   GSList *node, *next;
1296
1297   switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1298     {
1299     case G_TYPE_BOOLEAN:
1300     case G_TYPE_UCHAR:
1301     case G_TYPE_CHAR:
1302     case G_TYPE_UINT:
1303     case G_TYPE_INT:
1304     case G_TYPE_ULONG:
1305     case G_TYPE_LONG:
1306     case G_TYPE_FLOAT:
1307     case G_TYPE_DOUBLE:
1308     case G_TYPE_STRING:
1309       break;
1310     case G_TYPE_BOXED:
1311       if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1312         {
1313           break;
1314         }
1315       /* fall through */
1316     default:
1317       if (!parser)
1318         {
1319           g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1320                      pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1321           return 0;
1322         }
1323     }
1324   if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1325     {
1326       g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1327                  pspec->name);
1328       return 0;
1329     }
1330   
1331   for (node = object_list; node; node = node->next)
1332     g_object_freeze_notify (node->data);
1333
1334   g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1335   g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1336
1337   for (node = object_list; node; node = node->next)
1338     {
1339       GtkSettings *settings = node->data;
1340       GtkSettingsValuePrivate *qvalue;
1341       
1342       settings->property_values = g_renew (GtkSettingsPropertyValue, settings->property_values, class_n_properties);
1343       settings->property_values[class_n_properties - 1].value.g_type = 0;
1344       g_value_init (&settings->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1345       g_param_value_set_default (pspec, &settings->property_values[class_n_properties - 1].value);
1346       settings->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1347       g_object_notify (G_OBJECT (settings), pspec->name);
1348       
1349       qvalue = g_datalist_get_data (&settings->queued_settings, pspec->name);
1350       if (qvalue)
1351         apply_queued_setting (settings, pspec, qvalue);
1352     }
1353
1354   for (node = object_list; node; node = next)
1355     {
1356       next = node->next;
1357       g_object_thaw_notify (node->data);
1358     }
1359
1360   return class_n_properties;
1361 }
1362
1363 GtkRcPropertyParser
1364 _gtk_rc_property_parser_from_type (GType type)
1365 {
1366   if (type == GDK_TYPE_COLOR)
1367     return gtk_rc_property_parse_color;
1368   else if (type == GTK_TYPE_REQUISITION)
1369     return gtk_rc_property_parse_requisition;
1370   else if (type == GTK_TYPE_BORDER)
1371     return gtk_rc_property_parse_border;
1372   else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1373     return gtk_rc_property_parse_enum;
1374   else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1375     return gtk_rc_property_parse_flags;
1376   else
1377     return NULL;
1378 }
1379
1380 void
1381 gtk_settings_install_property (GParamSpec *pspec)
1382 {
1383   static GtkSettingsClass *klass = NULL;
1384
1385   GtkRcPropertyParser parser;
1386
1387   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1388
1389   if (! klass)
1390     klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1391
1392   parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
1393
1394   settings_install_property_parser (klass, pspec, parser);
1395 }
1396
1397 void
1398 gtk_settings_install_property_parser (GParamSpec          *pspec,
1399                                       GtkRcPropertyParser  parser)
1400 {
1401   static GtkSettingsClass *klass = NULL;
1402
1403   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1404   g_return_if_fail (parser != NULL);
1405
1406   if (! klass)
1407     klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1408
1409   settings_install_property_parser (klass, pspec, parser);
1410 }
1411
1412 static void
1413 free_value (gpointer data)
1414 {
1415   GtkSettingsValuePrivate *qvalue = data;
1416   
1417   g_value_unset (&qvalue->public.value);
1418   g_free (qvalue->public.origin);
1419   g_slice_free (GtkSettingsValuePrivate, qvalue);
1420 }
1421
1422 static void
1423 gtk_settings_set_property_value_internal (GtkSettings            *settings,
1424                                           const gchar            *prop_name,
1425                                           const GtkSettingsValue *new_value,
1426                                           GtkSettingsSource       source)
1427 {
1428   GtkSettingsValuePrivate *qvalue;
1429   GParamSpec *pspec;
1430   gchar *name;
1431   GQuark name_quark;
1432
1433   if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
1434       !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
1435       !G_VALUE_HOLDS_STRING (&new_value->value) &&
1436       !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
1437     {
1438       g_warning (G_STRLOC ": value type invalid");
1439       return;
1440     }
1441   
1442   name = g_strdup (prop_name);
1443   g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
1444   name_quark = g_quark_from_string (name);
1445   g_free (name);
1446
1447   qvalue = g_datalist_id_get_data (&settings->queued_settings, name_quark);
1448   if (!qvalue)
1449     {
1450       qvalue = g_slice_new0 (GtkSettingsValuePrivate);
1451       g_datalist_id_set_data_full (&settings->queued_settings, name_quark, qvalue, free_value);
1452     }
1453   else
1454     {
1455       g_free (qvalue->public.origin);
1456       g_value_unset (&qvalue->public.value);
1457     }
1458   qvalue->public.origin = g_strdup (new_value->origin);
1459   g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
1460   g_value_copy (&new_value->value, &qvalue->public.value);
1461   qvalue->source = source;
1462   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
1463   if (pspec)
1464     apply_queued_setting (settings, pspec, qvalue);
1465 }
1466
1467 void
1468 gtk_settings_set_property_value (GtkSettings            *settings,
1469                                  const gchar            *prop_name,
1470                                  const GtkSettingsValue *new_value)
1471 {
1472   g_return_if_fail (GTK_SETTINGS (settings));
1473   g_return_if_fail (prop_name != NULL);
1474   g_return_if_fail (new_value != NULL);
1475
1476   gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1477                                             GTK_SETTINGS_SOURCE_APPLICATION);
1478 }
1479
1480 void
1481 _gtk_settings_set_property_value_from_rc (GtkSettings            *settings,
1482                                           const gchar            *prop_name,
1483                                           const GtkSettingsValue *new_value)
1484 {
1485   g_return_if_fail (GTK_SETTINGS (settings));
1486   g_return_if_fail (prop_name != NULL);
1487   g_return_if_fail (new_value != NULL);
1488
1489   gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1490                                             GTK_SETTINGS_SOURCE_RC_FILE);
1491 }
1492
1493 void
1494 gtk_settings_set_string_property (GtkSettings *settings,
1495                                   const gchar *name,
1496                                   const gchar *v_string,
1497                                   const gchar *origin)
1498 {
1499   GtkSettingsValue svalue = { NULL, { 0, }, };
1500
1501   g_return_if_fail (GTK_SETTINGS (settings));
1502   g_return_if_fail (name != NULL);
1503   g_return_if_fail (v_string != NULL);
1504
1505   svalue.origin = (gchar*) origin;
1506   g_value_init (&svalue.value, G_TYPE_STRING);
1507   g_value_set_static_string (&svalue.value, v_string);
1508   gtk_settings_set_property_value (settings, name, &svalue);
1509   g_value_unset (&svalue.value);
1510 }
1511
1512 void
1513 gtk_settings_set_long_property (GtkSettings *settings,
1514                                 const gchar *name,
1515                                 glong        v_long,
1516                                 const gchar *origin)
1517 {
1518   GtkSettingsValue svalue = { NULL, { 0, }, };
1519   
1520   g_return_if_fail (GTK_SETTINGS (settings));
1521   g_return_if_fail (name != NULL);
1522
1523   svalue.origin = (gchar*) origin;
1524   g_value_init (&svalue.value, G_TYPE_LONG);
1525   g_value_set_long (&svalue.value, v_long);
1526   gtk_settings_set_property_value (settings, name, &svalue);
1527   g_value_unset (&svalue.value);
1528 }
1529
1530 void
1531 gtk_settings_set_double_property (GtkSettings *settings,
1532                                   const gchar *name,
1533                                   gdouble      v_double,
1534                                   const gchar *origin)
1535 {
1536   GtkSettingsValue svalue = { NULL, { 0, }, };
1537
1538   g_return_if_fail (GTK_SETTINGS (settings));
1539   g_return_if_fail (name != NULL);
1540
1541   svalue.origin = (gchar*) origin;
1542   g_value_init (&svalue.value, G_TYPE_DOUBLE);
1543   g_value_set_double (&svalue.value, v_double);
1544   gtk_settings_set_property_value (settings, name, &svalue);
1545   g_value_unset (&svalue.value);
1546 }
1547
1548 /**
1549  * gtk_rc_property_parse_color:
1550  * @pspec: a #GParamSpec
1551  * @gstring: the #GString to be parsed
1552  * @property_value: a #GValue which must hold #GdkColor values.
1553  * 
1554  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1555  * or gtk_widget_class_install_style_property_parser() which parses a
1556  * color given either by its name or in the form 
1557  * <literal>{ red, green, blue }</literal> where %red, %green and
1558  * %blue are integers between 0 and 65535 or floating-point numbers
1559  * between 0 and 1.
1560  * 
1561  * Return value: %TRUE if @gstring could be parsed and @property_value
1562  * has been set to the resulting #GdkColor.
1563  **/
1564 gboolean
1565 gtk_rc_property_parse_color (const GParamSpec *pspec,
1566                              const GString    *gstring,
1567                              GValue           *property_value)
1568 {
1569   GdkColor color = { 0, 0, 0, 0, };
1570   GScanner *scanner;
1571   gboolean success;
1572
1573   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1574   g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
1575
1576   scanner = gtk_rc_scanner_new ();
1577   g_scanner_input_text (scanner, gstring->str, gstring->len);
1578   if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
1579       g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
1580     {
1581       g_value_set_boxed (property_value, &color);
1582       success = TRUE;
1583     }
1584   else
1585     success = FALSE;
1586   g_scanner_destroy (scanner);
1587
1588   return success;
1589 }
1590
1591 /**
1592  * gtk_rc_property_parse_enum:
1593  * @pspec: a #GParamSpec
1594  * @gstring: the #GString to be parsed
1595  * @property_value: a #GValue which must hold enum values.
1596  * 
1597  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1598  * or gtk_widget_class_install_style_property_parser() which parses a single
1599  * enumeration value.
1600  *
1601  * The enumeration value can be specified by its name, its nickname or
1602  * its numeric value. For consistency with flags parsing, the value
1603  * may be surrounded by parentheses.
1604  * 
1605  * Return value: %TRUE if @gstring could be parsed and @property_value
1606  * has been set to the resulting #GEnumValue.
1607  **/
1608 gboolean
1609 gtk_rc_property_parse_enum (const GParamSpec *pspec,
1610                             const GString    *gstring,
1611                             GValue           *property_value)
1612 {
1613   gboolean need_closing_brace = FALSE, success = FALSE;
1614   GScanner *scanner;
1615   GEnumValue *enum_value = NULL;
1616
1617   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1618   g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
1619
1620   scanner = gtk_rc_scanner_new ();
1621   g_scanner_input_text (scanner, gstring->str, gstring->len);
1622
1623   /* we just want to parse _one_ value, but for consistency with flags parsing
1624    * we support optional parenthesis
1625    */
1626   g_scanner_get_next_token (scanner);
1627   if (scanner->token == '(')
1628     {
1629       need_closing_brace = TRUE;
1630       g_scanner_get_next_token (scanner);
1631     }
1632   if (scanner->token == G_TOKEN_IDENTIFIER)
1633     {
1634       GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
1635       
1636       enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
1637       if (!enum_value)
1638         enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
1639       if (enum_value)
1640         {
1641           g_value_set_enum (property_value, enum_value->value);
1642           success = TRUE;
1643         }
1644     }
1645   else if (scanner->token == G_TOKEN_INT)
1646     {
1647       g_value_set_enum (property_value, scanner->value.v_int);
1648       success = TRUE;
1649     }
1650   if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
1651     success = FALSE;
1652   if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
1653     success = FALSE;
1654
1655   g_scanner_destroy (scanner);
1656
1657   return success;
1658 }
1659
1660 static guint
1661 parse_flags_value (GScanner    *scanner,
1662                    GFlagsClass *class,
1663                    guint       *number)
1664 {
1665   g_scanner_get_next_token (scanner);
1666   if (scanner->token == G_TOKEN_IDENTIFIER)
1667     {
1668       GFlagsValue *flags_value;
1669
1670       flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
1671       if (!flags_value)
1672         flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
1673       if (flags_value)
1674         {
1675           *number |= flags_value->value;
1676           return G_TOKEN_NONE;
1677         }
1678     }
1679   else if (scanner->token == G_TOKEN_INT)
1680     {
1681       *number |= scanner->value.v_int;
1682       return G_TOKEN_NONE;
1683     }
1684   return G_TOKEN_IDENTIFIER;
1685 }
1686
1687 /**
1688  * gtk_rc_property_parse_flags:
1689  * @pspec: a #GParamSpec
1690  * @gstring: the #GString to be parsed
1691  * @property_value: a #GValue which must hold flags values.
1692  * 
1693  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1694  * or gtk_widget_class_install_style_property_parser() which parses flags. 
1695  * 
1696  * Flags can be specified by their name, their nickname or
1697  * numerically. Multiple flags can be specified in the form 
1698  * <literal>"( flag1 | flag2 | ... )"</literal>.
1699  * 
1700  * Return value: %TRUE if @gstring could be parsed and @property_value
1701  * has been set to the resulting flags value.
1702  **/
1703 gboolean
1704 gtk_rc_property_parse_flags (const GParamSpec *pspec,
1705                              const GString    *gstring,
1706                              GValue           *property_value)
1707 {
1708   GFlagsClass *class;
1709    gboolean success = FALSE;
1710   GScanner *scanner;
1711
1712   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1713   g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
1714
1715   class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
1716   scanner = gtk_rc_scanner_new ();
1717   g_scanner_input_text (scanner, gstring->str, gstring->len);
1718
1719   /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
1720   if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
1721       scanner->next_token == G_TOKEN_INT)
1722     {
1723       guint token, flags_value = 0;
1724       
1725       token = parse_flags_value (scanner, class, &flags_value);
1726
1727       if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1728         {
1729           success = TRUE;
1730           g_value_set_flags (property_value, flags_value);
1731         }
1732       
1733     }
1734   else if (g_scanner_get_next_token (scanner) == '(')
1735     {
1736       guint token, flags_value = 0;
1737
1738       /* parse first value */
1739       token = parse_flags_value (scanner, class, &flags_value);
1740
1741       /* parse nth values, preceeded by '|' */
1742       while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
1743         token = parse_flags_value (scanner, class, &flags_value);
1744
1745       /* done, last token must have closed expression */
1746       if (token == G_TOKEN_NONE && scanner->token == ')' &&
1747           g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1748         {
1749           g_value_set_flags (property_value, flags_value);
1750           success = TRUE;
1751         }
1752     }
1753   g_scanner_destroy (scanner);
1754
1755   return success;
1756 }
1757
1758 static gboolean
1759 get_braced_int (GScanner *scanner,
1760                 gboolean  first,
1761                 gboolean  last,
1762                 gint     *value)
1763 {
1764   if (first)
1765     {
1766       g_scanner_get_next_token (scanner);
1767       if (scanner->token != '{')
1768         return FALSE;
1769     }
1770
1771   g_scanner_get_next_token (scanner);
1772   if (scanner->token != G_TOKEN_INT)
1773     return FALSE;
1774
1775   *value = scanner->value.v_int;
1776
1777   if (last)
1778     {
1779       g_scanner_get_next_token (scanner);
1780       if (scanner->token != '}')
1781         return FALSE;
1782     }
1783   else
1784     {
1785       g_scanner_get_next_token (scanner);
1786       if (scanner->token != ',')
1787         return FALSE;
1788     }
1789
1790   return TRUE;
1791 }
1792
1793 /**
1794  * gtk_rc_property_parse_requisition:
1795  * @pspec: a #GParamSpec
1796  * @gstring: the #GString to be parsed
1797  * @property_value: a #GValue which must hold boxed values.
1798  * 
1799  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1800  * or gtk_widget_class_install_style_property_parser() which parses a
1801  * requisition in the form 
1802  * <literal>"{ width, height }"</literal> for integers %width and %height.
1803  * 
1804  * Return value: %TRUE if @gstring could be parsed and @property_value
1805  * has been set to the resulting #GtkRequisition.
1806  **/
1807 gboolean
1808 gtk_rc_property_parse_requisition  (const GParamSpec *pspec,
1809                                     const GString    *gstring,
1810                                     GValue           *property_value)
1811 {
1812   GtkRequisition requisition;
1813   GScanner *scanner;
1814   gboolean success = FALSE;
1815
1816   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1817   g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
1818
1819   scanner = gtk_rc_scanner_new ();
1820   g_scanner_input_text (scanner, gstring->str, gstring->len);
1821
1822   if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
1823       get_braced_int (scanner, FALSE, TRUE, &requisition.height))
1824     {
1825       g_value_set_boxed (property_value, &requisition);
1826       success = TRUE;
1827     }
1828
1829   g_scanner_destroy (scanner);
1830
1831   return success;
1832 }
1833
1834 /**
1835  * gtk_rc_property_parse_border:
1836  * @pspec: a #GParamSpec
1837  * @gstring: the #GString to be parsed
1838  * @property_value: a #GValue which must hold boxed values.
1839  * 
1840  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1841  * or gtk_widget_class_install_style_property_parser() which parses
1842  * borders in the form 
1843  * <literal>"{ left, right, top, bottom }"</literal> for integers 
1844  * %left, %right, %top and %bottom.
1845  * 
1846  * Return value: %TRUE if @gstring could be parsed and @property_value
1847  * has been set to the resulting #GtkBorder.
1848  **/
1849 gboolean
1850 gtk_rc_property_parse_border (const GParamSpec *pspec,
1851                               const GString    *gstring,
1852                               GValue           *property_value)
1853 {
1854   GtkBorder border;
1855   GScanner *scanner;
1856   gboolean success = FALSE;
1857
1858   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1859   g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
1860
1861   scanner = gtk_rc_scanner_new ();
1862   g_scanner_input_text (scanner, gstring->str, gstring->len);
1863
1864   if (get_braced_int (scanner, TRUE, FALSE, &border.left) &&
1865       get_braced_int (scanner, FALSE, FALSE, &border.right) &&
1866       get_braced_int (scanner, FALSE, FALSE, &border.top) &&
1867       get_braced_int (scanner, FALSE, TRUE, &border.bottom))
1868     {
1869       g_value_set_boxed (property_value, &border);
1870       success = TRUE;
1871     }
1872
1873   g_scanner_destroy (scanner);
1874
1875   return success;
1876 }
1877
1878 void
1879 _gtk_settings_handle_event (GdkEventSetting *event)
1880 {
1881   GtkSettings *settings;
1882   GParamSpec *pspec;
1883   guint property_id;
1884
1885   settings = gtk_settings_get_for_screen (gdk_drawable_get_screen (event->window));
1886   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
1887  
1888   if (pspec) 
1889     {
1890       property_id = pspec->param_id;
1891
1892       if (property_id == PROP_COLOR_SCHEME)
1893         {
1894           GValue value = { 0, };
1895
1896           g_value_init (&value, G_TYPE_STRING);
1897           if (!gdk_screen_get_setting (settings->screen, pspec->name, &value))
1898             g_value_set_static_string (&value, "");
1899           merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
1900           g_value_unset (&value);
1901         }
1902
1903       g_object_notify (G_OBJECT (settings), pspec->name);
1904    }
1905 }
1906
1907 static void
1908 reset_rc_values_foreach (GQuark    key_id,
1909                          gpointer  data,
1910                          gpointer  user_data)
1911 {
1912   GtkSettingsValuePrivate *qvalue = data;
1913   GSList **to_reset = user_data;
1914
1915   if (qvalue->source == GTK_SETTINGS_SOURCE_RC_FILE)
1916     *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
1917 }
1918
1919 void
1920 _gtk_settings_reset_rc_values (GtkSettings *settings)
1921 {
1922   GSList *to_reset = NULL;
1923   GSList *tmp_list;
1924   GParamSpec **pspecs, **p;
1925   gint i;
1926
1927   /* Remove any queued settings
1928    */
1929   g_datalist_foreach (&settings->queued_settings,
1930                       reset_rc_values_foreach,
1931                       &to_reset);
1932
1933   for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
1934     {
1935       GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
1936       g_datalist_id_remove_data (&settings->queued_settings, key_id);
1937     }
1938
1939    g_slist_free (to_reset);
1940
1941   /* Now reset the active settings
1942    */
1943   pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
1944   i = 0;
1945
1946   g_object_freeze_notify (G_OBJECT (settings));
1947   for (p = pspecs; *p; p++)
1948     {
1949       if (settings->property_values[i].source == GTK_SETTINGS_SOURCE_RC_FILE)
1950         {
1951           GParamSpec *pspec = *p;
1952
1953           g_param_value_set_default (pspec, &settings->property_values[i].value);
1954           g_object_notify (G_OBJECT (settings), pspec->name);
1955         }
1956       i++;
1957     }
1958   g_object_thaw_notify (G_OBJECT (settings));
1959   g_free (pspecs);
1960 }
1961
1962 static void
1963 settings_update_double_click (GtkSettings *settings)
1964 {
1965   if (gdk_screen_get_number (settings->screen) == 0)
1966     {
1967       GdkDisplay *display = gdk_screen_get_display (settings->screen);
1968       gint double_click_time;
1969       gint double_click_distance;
1970   
1971       g_object_get (settings, 
1972                     "gtk-double-click-time", &double_click_time, 
1973                     "gtk-double-click-distance", &double_click_distance,
1974                     NULL);
1975       
1976       gdk_display_set_double_click_time (display, double_click_time);
1977       gdk_display_set_double_click_distance (display, double_click_distance);
1978     }
1979 }
1980
1981 static void
1982 settings_update_modules (GtkSettings *settings)
1983 {
1984   gchar *modules;
1985   
1986   g_object_get (settings, 
1987                 "gtk-modules", &modules,
1988                 NULL);
1989   
1990   _gtk_modules_settings_changed (settings, modules);
1991   
1992   g_free (modules);
1993 }
1994
1995 #ifdef GDK_WINDOWING_X11
1996 static void
1997 settings_update_cursor_theme (GtkSettings *settings)
1998 {
1999   GdkDisplay *display = gdk_screen_get_display (settings->screen);
2000   gchar *theme = NULL;
2001   gint size = 0;
2002   
2003   g_object_get (settings, 
2004                 "gtk-cursor-theme-name", &theme,
2005                 "gtk-cursor-theme-size", &size,
2006                 NULL);
2007   
2008   gdk_x11_display_set_cursor_theme (display, theme, size);
2009
2010   g_free (theme);
2011 }
2012
2013 static void
2014 settings_update_font_options (GtkSettings *settings)
2015 {
2016   gint hinting;
2017   gchar *hint_style_str;
2018   cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2019   gint antialias;
2020   cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2021   gchar *rgba_str;
2022   cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2023   cairo_font_options_t *options;
2024   
2025   g_object_get (settings,
2026                 "gtk-xft-antialias", &antialias,
2027                 "gtk-xft-hinting", &hinting,
2028                 "gtk-xft-hintstyle", &hint_style_str,
2029                 "gtk-xft-rgba", &rgba_str,
2030                 NULL);
2031
2032   options = cairo_font_options_create ();
2033
2034   cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2035   
2036   if (hinting >= 0 && !hinting)
2037     {
2038       hint_style = CAIRO_HINT_STYLE_NONE;
2039     }
2040   else if (hint_style_str)
2041     {
2042       if (strcmp (hint_style_str, "hintnone") == 0)
2043         hint_style = CAIRO_HINT_STYLE_NONE;
2044       else if (strcmp (hint_style_str, "hintslight") == 0)
2045         hint_style = CAIRO_HINT_STYLE_SLIGHT;
2046       else if (strcmp (hint_style_str, "hintmedium") == 0)
2047         hint_style = CAIRO_HINT_STYLE_MEDIUM;
2048       else if (strcmp (hint_style_str, "hintfull") == 0)
2049         hint_style = CAIRO_HINT_STYLE_FULL;
2050     }
2051
2052   g_free (hint_style_str);
2053
2054   cairo_font_options_set_hint_style (options, hint_style);
2055
2056   if (rgba_str)
2057     {
2058       if (strcmp (rgba_str, "rgb") == 0)
2059         subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2060       else if (strcmp (rgba_str, "bgr") == 0)
2061         subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2062       else if (strcmp (rgba_str, "vrgb") == 0)
2063         subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2064       else if (strcmp (rgba_str, "vbgr") == 0)
2065         subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2066
2067       g_free (rgba_str);
2068     }
2069
2070   cairo_font_options_set_subpixel_order (options, subpixel_order);
2071   
2072   if (antialias >= 0 && !antialias)
2073     antialias_mode = CAIRO_ANTIALIAS_NONE;
2074   else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2075     antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2076   else if (antialias >= 0)
2077     antialias_mode = CAIRO_ANTIALIAS_GRAY;
2078   
2079   cairo_font_options_set_antialias (options, antialias_mode);
2080
2081   gdk_screen_set_font_options (settings->screen, options);
2082   
2083   cairo_font_options_destroy (options);
2084 }
2085
2086 #ifdef GDK_WINDOWING_X11
2087 static gboolean
2088 settings_update_fontconfig (GtkSettings *settings)
2089 {
2090   static guint    last_update_timestamp;
2091   static gboolean last_update_needed;
2092
2093   gint timestamp;
2094
2095   g_object_get (settings,
2096                 "gtk-fontconfig-timestamp", &timestamp,
2097                 NULL);
2098
2099   /* if timestamp is the same as last_update_timestamp, we already have
2100    * updated fontconig on this timestamp (another screen requested it perhaps?),
2101    * just return the cached result.*/
2102
2103   if (timestamp != last_update_timestamp)
2104     {
2105       PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2106       gboolean update_needed = FALSE;
2107
2108       if (PANGO_IS_FC_FONT_MAP (fontmap) &&
2109           !FcConfigUptoDate (NULL) && FcInitReinitialize ())
2110         {
2111           update_needed = TRUE;
2112           pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2113         }
2114
2115       last_update_timestamp = timestamp;
2116       last_update_needed = update_needed;
2117     }
2118
2119   return last_update_needed;
2120 }
2121 #endif /* GDK_WINDOWING_X11 */
2122
2123 static void
2124 settings_update_resolution (GtkSettings *settings)
2125 {
2126   gint dpi_int;
2127   double dpi;
2128   
2129   g_object_get (settings,
2130                 "gtk-xft-dpi", &dpi_int,
2131                 NULL);
2132
2133   if (dpi_int > 0)
2134     dpi = dpi_int / 1024.;
2135   else
2136     dpi = -1.;
2137
2138   gdk_screen_set_resolution (settings->screen, dpi);
2139 }
2140 #endif
2141
2142 typedef struct {
2143   GHashTable *color_hash;
2144   GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2145   gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2146 } ColorSchemeData;
2147
2148 static void
2149 color_scheme_data_free (ColorSchemeData *data)
2150 {
2151   gint i;
2152
2153   g_hash_table_unref (data->color_hash);
2154
2155   for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2156     {
2157       if (data->tables[i])
2158         g_hash_table_unref (data->tables[i]);
2159       g_free (data->lastentry[i]);
2160     }
2161
2162   g_slice_free (ColorSchemeData, data);
2163 }
2164
2165 static void
2166 settings_update_color_scheme (GtkSettings *settings)
2167 {
2168   if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2169     {
2170       ColorSchemeData *data;
2171       GValue value = { 0, };
2172
2173       data = g_slice_new0 (ColorSchemeData);
2174       data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2175                                                 (GDestroyNotify) gdk_color_free);
2176       g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2177                               data, (GDestroyNotify) color_scheme_data_free); 
2178
2179       g_value_init (&value, G_TYPE_STRING);
2180       if (gdk_screen_get_setting (settings->screen, "gtk-color-scheme", &value))
2181         {
2182           merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2183           g_value_unset (&value);
2184         }
2185    }
2186 }
2187
2188 static gboolean
2189 add_color_to_hash (gchar      *name, 
2190                    GdkColor   *color, 
2191                    GHashTable *target)
2192 {
2193   GdkColor *old;
2194
2195   old = g_hash_table_lookup (target, name);
2196   if (!old || !gdk_color_equal (old, color))
2197     {
2198       g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2199       
2200       return TRUE;
2201     }
2202
2203   return FALSE;
2204 }
2205
2206 static gboolean
2207 add_colors_to_hash_from_string (GHashTable  *hash, 
2208                                 const gchar *colors)
2209 {
2210   gchar *s, *p, *name;
2211   GdkColor color;
2212   gboolean changed = FALSE;
2213   gchar *copy;
2214
2215   copy = g_strdup (colors);
2216   s = copy;
2217   while (s && *s)
2218     {
2219       name = s;
2220       p = strchr (s, ':');
2221       if (p)
2222         {
2223           *p = '\0';
2224           p++;
2225         }
2226       else
2227         break;
2228
2229       while (*p == ' ')
2230         p++;
2231
2232       s = p;
2233       while (*s) 
2234         {
2235           if (*s == '\n' || *s == ';')
2236             {
2237               *s = '\0';
2238               s++;
2239               break;
2240             }
2241           s++;
2242         }
2243
2244       if (gdk_color_parse (p, &color))
2245         changed |= add_color_to_hash (name, &color, hash);
2246     }
2247
2248   g_free (copy);
2249
2250   return changed;
2251 }
2252
2253 static gboolean
2254 update_color_hash (ColorSchemeData   *data,
2255                    const gchar       *str, 
2256                    GtkSettingsSource  source)
2257 {
2258   gboolean changed = FALSE;
2259   gint i;
2260
2261   if ((str == NULL || *str == '\0') && 
2262       (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2263     return FALSE;
2264
2265   if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2266     return FALSE;
2267
2268   /* For the RC_FILE source we merge the values rather than over-writing 
2269    * them, since multiple rc files might define independent sets of colors
2270    */
2271   if ((source != GTK_SETTINGS_SOURCE_RC_FILE) && 
2272       data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2273     {
2274       g_hash_table_unref (data->tables[source]);
2275       data->tables[source] = NULL;
2276       changed = TRUE; /* We can't rely on the code below since str might be "" */
2277     }
2278
2279   if (data->tables[source] == NULL)
2280     data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal, 
2281                                                   g_free,
2282                                                   (GDestroyNotify) gdk_color_free);
2283
2284   g_free (data->lastentry[source]);
2285   data->lastentry[source] = g_strdup (str);
2286   
2287   changed |= add_colors_to_hash_from_string (data->tables[source], str);
2288
2289   if (!changed)
2290     return FALSE;
2291     
2292   /* Rebuild the merged hash table. */
2293   if (data->color_hash)
2294     g_hash_table_unref (data->color_hash);
2295   data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2296                                             (GDestroyNotify) gdk_color_free);
2297   for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2298     {
2299       if (data->tables[i])
2300         g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2301                               data->color_hash);
2302     }
2303
2304   return TRUE;
2305 }
2306
2307 static void
2308 merge_color_scheme (GtkSettings       *settings, 
2309                     const GValue      *value, 
2310                     GtkSettingsSource  source)
2311 {
2312   ColorSchemeData *data;
2313   const gchar *colors;
2314
2315   g_object_freeze_notify (G_OBJECT (settings));
2316
2317   colors = g_value_get_string (value);
2318
2319   settings_update_color_scheme (settings);
2320
2321   data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2322                                                 "gtk-color-scheme");
2323   
2324   if (update_color_hash (data, colors, source))
2325     g_object_notify (G_OBJECT (settings), "color-hash");
2326
2327   g_object_thaw_notify (G_OBJECT (settings));
2328 }
2329
2330 static GHashTable *
2331 get_color_hash (GtkSettings *settings)
2332 {
2333   ColorSchemeData *data;
2334
2335   settings_update_color_scheme (settings);
2336   
2337   data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings), 
2338                                                "gtk-color-scheme");
2339
2340   return data->color_hash;
2341 }
2342
2343 static void 
2344 append_color_scheme (gpointer key,
2345                      gpointer value,
2346                      gpointer data)
2347 {
2348   gchar *name = (gchar *)key;
2349   GdkColor *color = (GdkColor *)value;
2350   GString *string = (GString *)data;
2351
2352   g_string_append_printf (string, "%s: #%04x%04x%04x\n",
2353                           name, color->red, color->green, color->blue);
2354 }
2355
2356 static gchar *
2357 get_color_scheme (GtkSettings *settings)
2358 {
2359   ColorSchemeData *data;
2360   GString *string;
2361   
2362   settings_update_color_scheme (settings);
2363
2364   data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2365                                                 "gtk-color-scheme");
2366
2367   string = g_string_new ("");
2368
2369   g_hash_table_foreach (data->color_hash, append_color_scheme, string);
2370
2371   return g_string_free (string, FALSE);
2372 }
2373
2374
2375 #define __GTK_SETTINGS_C__
2376 #include "gtkaliasdef.c"