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