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