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