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