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