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