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