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