1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
34 #ifdef HAVE_SYS_PARAM_H
35 #include <sys/param.h>
44 #include <glib/gstdio.h>
47 #include "gtkversion.h"
49 #include "gtkbindings.h"
51 #include "gtkiconfactory.h"
53 #include "gtkmodules.h"
54 #include "gtkprivate.h"
55 #include "gtksettingsprivate.h"
56 #include "gtkwindow.h"
80 #define GTK_RC_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RC_STYLE, GtkRcStylePrivate))
82 typedef struct _GtkRcStylePrivate GtkRcStylePrivate;
84 struct _GtkRcStylePrivate
89 static void gtk_rc_style_finalize (GObject *object);
90 static void gtk_rc_style_real_merge (GtkRcStyle *dest,
92 static GtkRcStyle* gtk_rc_style_real_create_rc_style (GtkRcStyle *rc_style);
93 static GtkStyle* gtk_rc_style_real_create_style (GtkRcStyle *rc_style);
94 static gint gtk_rc_properties_cmp (gconstpointer bsearch_node1,
95 gconstpointer bsearch_node2);
97 static void insert_rc_property (GtkRcStyle *style,
98 GtkRcProperty *property,
102 static const GScannerConfig gtk_rc_scanner_config =
106 ) /* cset_skip_characters */,
111 ) /* cset_identifier_first */,
117 ) /* cset_identifier_nth */,
118 ( "#\n" ) /* cpair_comment_single */,
120 TRUE /* case_sensitive */,
122 TRUE /* skip_comment_multi */,
123 TRUE /* skip_comment_single */,
124 TRUE /* scan_comment_multi */,
125 TRUE /* scan_identifier */,
126 FALSE /* scan_identifier_1char */,
127 FALSE /* scan_identifier_NULL */,
128 TRUE /* scan_symbols */,
129 TRUE /* scan_binary */,
130 TRUE /* scan_octal */,
131 TRUE /* scan_float */,
133 TRUE /* scan_hex_dollar */,
134 TRUE /* scan_string_sq */,
135 TRUE /* scan_string_dq */,
136 TRUE /* numbers_2_int */,
137 FALSE /* int_2_float */,
138 FALSE /* identifier_2_string */,
139 TRUE /* char_2_token */,
140 TRUE /* symbol_2_token */,
141 FALSE /* scope_0_fallback */,
144 static const gchar symbol_names[] =
188 { 0, GTK_RC_TOKEN_INCLUDE },
189 { 8, GTK_RC_TOKEN_NORMAL },
190 { 15, GTK_RC_TOKEN_ACTIVE },
191 { 22, GTK_RC_TOKEN_PRELIGHT },
192 { 31, GTK_RC_TOKEN_SELECTED },
193 { 40, GTK_RC_TOKEN_INSENSITIVE },
194 { 52, GTK_RC_TOKEN_FG },
195 { 55, GTK_RC_TOKEN_BG },
196 { 58, GTK_RC_TOKEN_TEXT },
197 { 63, GTK_RC_TOKEN_BASE },
198 { 68, GTK_RC_TOKEN_XTHICKNESS },
199 { 79, GTK_RC_TOKEN_YTHICKNESS },
200 { 90, GTK_RC_TOKEN_FONT },
201 { 95, GTK_RC_TOKEN_FONTSET },
202 { 103, GTK_RC_TOKEN_FONT_NAME },
203 { 113, GTK_RC_TOKEN_BG_PIXMAP },
204 { 123, GTK_RC_TOKEN_PIXMAP_PATH },
205 { 135, GTK_RC_TOKEN_STYLE },
206 { 141, GTK_RC_TOKEN_BINDING },
207 { 149, GTK_RC_TOKEN_BIND },
208 { 154, GTK_RC_TOKEN_WIDGET },
209 { 161, GTK_RC_TOKEN_WIDGET_CLASS },
210 { 174, GTK_RC_TOKEN_CLASS },
211 { 180, GTK_RC_TOKEN_LOWEST },
212 { 187, GTK_RC_TOKEN_GTK },
213 { 191, GTK_RC_TOKEN_APPLICATION },
214 { 203, GTK_RC_TOKEN_THEME },
215 { 209, GTK_RC_TOKEN_RC },
216 { 212, GTK_RC_TOKEN_HIGHEST },
217 { 220, GTK_RC_TOKEN_ENGINE },
218 { 227, GTK_RC_TOKEN_MODULE_PATH },
219 { 239, GTK_RC_TOKEN_STOCK },
220 { 245, GTK_RC_TOKEN_IM_MODULE_FILE },
221 { 260, GTK_RC_TOKEN_LTR },
222 { 264, GTK_RC_TOKEN_RTL },
223 { 268, GTK_RC_TOKEN_COLOR },
224 { 274, GTK_RC_TOKEN_UNBIND }
227 static GHashTable *realized_style_ht = NULL;
229 static gchar *im_module_file = NULL;
231 static gchar **gtk_rc_default_files = NULL;
233 /* RC file handling */
236 gtk_rc_make_default_dir (const gchar *type)
241 var = g_getenv ("GTK_EXE_PREFIX");
244 path = g_build_filename (var, "lib", "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
246 path = g_build_filename (GTK_LIBDIR, "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
252 * gtk_rc_get_im_module_path:
253 * @returns: (type filename): a newly-allocated string containing the
254 * path in which to look for IM modules.
256 * Obtains the path in which to look for IM modules. See the documentation
257 * of the <link linkend="im-module-path"><envar>GTK_PATH</envar></link>
258 * environment variable for more details about looking up modules. This
259 * function is useful solely for utilities supplied with GTK+ and should
260 * not be used by applications under normal circumstances.
263 gtk_rc_get_im_module_path (void)
265 gchar **paths = _gtk_get_module_path ("immodules");
266 gchar *result = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, paths);
273 * gtk_rc_get_im_module_file:
274 * @returns: (type filename): a newly-allocated string containing the
275 * name of the file listing the IM modules available for loading
277 * Obtains the path to the IM modules file. See the documentation
278 * of the <link linkend="im-module-file"><envar>GTK_IM_MODULE_FILE</envar></link>
279 * environment variable for more details.
282 gtk_rc_get_im_module_file (void)
284 const gchar *var = g_getenv ("GTK_IM_MODULE_FILE");
285 gchar *result = NULL;
288 result = g_strdup (var);
293 result = g_strdup (im_module_file);
295 result = gtk_rc_make_default_dir ("immodules.cache");
302 gtk_rc_get_theme_dir (void)
307 var = g_getenv ("GTK_DATA_PREFIX");
310 path = g_build_filename (var, "share", "themes", NULL);
312 path = g_build_filename (GTK_DATA_PREFIX, "share", "themes", NULL);
318 * gtk_rc_get_module_dir:
320 * Returns a directory in which GTK+ looks for theme engines.
321 * For full information about the search for theme engines,
322 * see the docs for <envar>GTK_PATH</envar> in
323 * <xref linkend="gtk-running"/>.
325 * return value: (type filename): the directory. (Must be freed with g_free())
328 gtk_rc_get_module_dir (void)
330 return gtk_rc_make_default_dir ("engines");
334 * gtk_rc_add_default_file:
335 * @filename: (type filename): the pathname to the file. If @filename
336 * is not absolute, it is searched in the current directory.
338 * Adds a file to the list of files to be parsed at the
341 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
344 gtk_rc_add_default_file (const gchar *filename)
349 * gtk_rc_set_default_files:
350 * @filenames: (array zero-terminated=1) (element-type filename): A
351 * %NULL-terminated list of filenames.
353 * Sets the list of files that GTK+ will read at the
356 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
359 gtk_rc_set_default_files (gchar **filenames)
364 * gtk_rc_get_default_files:
366 * Retrieves the current list of RC files that will be parsed
367 * at the end of gtk_init().
369 * Return value: (transfer none) (array zero-terminated=1) (element-type filename):
370 * A %NULL-terminated array of filenames. This memory is owned
371 * by GTK+ and must not be freed by the application. If you want
372 * to store this information, you should make a copy.
374 * Deprecated:3.0: Use #GtkStyleContext instead
377 gtk_rc_get_default_files (void)
379 return gtk_rc_default_files;
383 gtk_rc_parse_string (const gchar *rc_string)
385 g_return_if_fail (rc_string != NULL);
389 gtk_rc_parse (const gchar *filename)
391 g_return_if_fail (filename != NULL);
394 /* Handling of RC styles */
396 G_DEFINE_TYPE (GtkRcStyle, gtk_rc_style, G_TYPE_OBJECT)
399 gtk_rc_style_init (GtkRcStyle *style)
401 GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (style);
405 style->font_desc = NULL;
407 for (i = 0; i < 5; i++)
409 static const GdkColor init_color = { 0, 0, 0, 0, };
411 style->bg_pixmap_name[i] = NULL;
412 style->color_flags[i] = 0;
413 style->fg[i] = init_color;
414 style->bg[i] = init_color;
415 style->text[i] = init_color;
416 style->base[i] = init_color;
418 style->xthickness = -1;
419 style->ythickness = -1;
420 style->rc_properties = NULL;
422 style->rc_style_lists = NULL;
423 style->icon_factories = NULL;
425 priv->color_hashes = NULL;
429 gtk_rc_style_class_init (GtkRcStyleClass *klass)
431 GObjectClass *object_class = G_OBJECT_CLASS (klass);
433 object_class->finalize = gtk_rc_style_finalize;
436 klass->create_rc_style = gtk_rc_style_real_create_rc_style;
437 klass->merge = gtk_rc_style_real_merge;
438 klass->create_style = gtk_rc_style_real_create_style;
440 g_type_class_add_private (object_class, sizeof (GtkRcStylePrivate));
444 gtk_rc_style_finalize (GObject *object)
446 GSList *tmp_list1, *tmp_list2;
447 GtkRcStyle *rc_style;
448 GtkRcStylePrivate *rc_priv;
451 rc_style = GTK_RC_STYLE (object);
452 rc_priv = GTK_RC_STYLE_GET_PRIVATE (rc_style);
454 g_free (rc_style->name);
455 if (rc_style->font_desc)
456 pango_font_description_free (rc_style->font_desc);
458 for (i = 0; i < 5; i++)
459 g_free (rc_style->bg_pixmap_name[i]);
461 /* Now remove all references to this rc_style from
464 tmp_list1 = rc_style->rc_style_lists;
467 GSList *rc_styles = tmp_list1->data;
468 GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
469 g_object_unref (style);
471 /* Remove the list of styles from the other rc_styles
474 tmp_list2 = rc_styles;
477 GtkRcStyle *other_style = tmp_list2->data;
479 if (other_style != rc_style)
480 other_style->rc_style_lists = g_slist_remove_all (other_style->rc_style_lists,
482 tmp_list2 = tmp_list2->next;
485 /* And from the hash table itself
487 g_hash_table_remove (realized_style_ht, rc_styles);
488 g_slist_free (rc_styles);
490 tmp_list1 = tmp_list1->next;
492 g_slist_free (rc_style->rc_style_lists);
494 if (rc_style->rc_properties)
498 for (i = 0; i < rc_style->rc_properties->len; i++)
500 GtkRcProperty *node = &g_array_index (rc_style->rc_properties, GtkRcProperty, i);
502 g_free (node->origin);
503 g_value_unset (&node->value);
505 g_array_free (rc_style->rc_properties, TRUE);
506 rc_style->rc_properties = NULL;
509 g_slist_foreach (rc_style->icon_factories, (GFunc) g_object_unref, NULL);
510 g_slist_free (rc_style->icon_factories);
512 g_slist_foreach (rc_priv->color_hashes, (GFunc) g_hash_table_unref, NULL);
513 g_slist_free (rc_priv->color_hashes);
515 G_OBJECT_CLASS (gtk_rc_style_parent_class)->finalize (object);
519 gtk_rc_style_new (void)
523 style = g_object_new (GTK_TYPE_RC_STYLE, NULL);
530 * @orig: the style to copy
532 * Makes a copy of the specified #GtkRcStyle. This function
533 * will correctly copy an RC style that is a member of a class
534 * derived from #GtkRcStyle.
536 * Return value: (transfer full): the resulting #GtkRcStyle
539 gtk_rc_style_copy (GtkRcStyle *orig)
543 g_return_val_if_fail (GTK_IS_RC_STYLE (orig), NULL);
545 style = GTK_RC_STYLE_GET_CLASS (orig)->create_rc_style (orig);
546 GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
552 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
554 return g_object_new (G_OBJECT_TYPE (style), NULL);
558 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
559 gconstpointer bsearch_node2)
561 const GtkRcProperty *prop1 = bsearch_node1;
562 const GtkRcProperty *prop2 = bsearch_node2;
564 if (prop1->type_name == prop2->type_name)
565 return prop1->property_name < prop2->property_name ? -1 : prop1->property_name == prop2->property_name ? 0 : 1;
567 return prop1->type_name < prop2->type_name ? -1 : 1;
571 insert_rc_property (GtkRcStyle *style,
572 GtkRcProperty *property,
576 GtkRcProperty *new_property = NULL;
577 GtkRcProperty key = { 0, 0, NULL, { 0, }, };
579 key.type_name = property->type_name;
580 key.property_name = property->property_name;
582 if (!style->rc_properties)
583 style->rc_properties = g_array_new (FALSE, FALSE, sizeof (GtkRcProperty));
586 while (i < style->rc_properties->len)
588 gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
594 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
596 g_free (new_property->origin);
597 g_value_unset (&new_property->value);
613 g_array_insert_val (style->rc_properties, i, key);
614 new_property = &g_array_index (style->rc_properties, GtkRcProperty, i);
617 new_property->origin = g_strdup (property->origin);
618 g_value_init (&new_property->value, G_VALUE_TYPE (&property->value));
619 g_value_copy (&property->value, &new_property->value);
623 gtk_rc_style_real_merge (GtkRcStyle *dest,
628 for (i = 0; i < 5; i++)
630 if (!dest->bg_pixmap_name[i] && src->bg_pixmap_name[i])
631 dest->bg_pixmap_name[i] = g_strdup (src->bg_pixmap_name[i]);
633 if (!(dest->color_flags[i] & GTK_RC_FG) &&
634 src->color_flags[i] & GTK_RC_FG)
636 dest->fg[i] = src->fg[i];
637 dest->color_flags[i] |= GTK_RC_FG;
639 if (!(dest->color_flags[i] & GTK_RC_BG) &&
640 src->color_flags[i] & GTK_RC_BG)
642 dest->bg[i] = src->bg[i];
643 dest->color_flags[i] |= GTK_RC_BG;
645 if (!(dest->color_flags[i] & GTK_RC_TEXT) &&
646 src->color_flags[i] & GTK_RC_TEXT)
648 dest->text[i] = src->text[i];
649 dest->color_flags[i] |= GTK_RC_TEXT;
651 if (!(dest->color_flags[i] & GTK_RC_BASE) &&
652 src->color_flags[i] & GTK_RC_BASE)
654 dest->base[i] = src->base[i];
655 dest->color_flags[i] |= GTK_RC_BASE;
659 if (dest->xthickness < 0 && src->xthickness >= 0)
660 dest->xthickness = src->xthickness;
661 if (dest->ythickness < 0 && src->ythickness >= 0)
662 dest->ythickness = src->ythickness;
666 if (!dest->font_desc)
667 dest->font_desc = pango_font_description_copy (src->font_desc);
669 pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
672 if (src->rc_properties)
676 for (i = 0; i < src->rc_properties->len; i++)
677 insert_rc_property (dest,
678 &g_array_index (src->rc_properties, GtkRcProperty, i),
684 gtk_rc_style_real_create_style (GtkRcStyle *rc_style)
686 return gtk_style_new ();
690 * gtk_rc_reset_styles:
691 * @settings: a #GtkSettings
693 * This function recomputes the styles for all widgets that use a
694 * particular #GtkSettings object. (There is one #GtkSettings object
695 * per #GdkScreen, see gtk_settings_get_for_screen()); It is useful
696 * when some global parameter has changed that affects the appearance
697 * of all widgets, because when a widget gets a new style, it will
698 * both redraw and recompute any cached information about its
699 * appearance. As an example, it is used when the default font size
700 * set by the operating system changes. Note that this function
701 * doesn't affect widgets that have a style set explicitely on them
702 * with gtk_widget_set_style().
707 gtk_rc_reset_styles (GtkSettings *settings)
709 gtk_style_context_reset_widgets (_gtk_settings_get_screen (settings));
713 * gtk_rc_reparse_all_for_settings:
714 * @settings: a #GtkSettings
715 * @force_load: load whether or not anything changed
717 * If the modification time on any previously read file
718 * for the given #GtkSettings has changed, discard all style information
719 * and then reread all previously read RC files.
721 * Return value: %TRUE if the files were reread.
724 gtk_rc_reparse_all_for_settings (GtkSettings *settings,
731 * gtk_rc_reparse_all:
733 * If the modification time on any previously read file for the
734 * default #GtkSettings has changed, discard all style information
735 * and then reread all previously read RC files.
737 * Return value: %TRUE if the files were reread.
740 gtk_rc_reparse_all (void)
747 * @widget: a #GtkWidget
749 * Finds all matching RC styles for a given widget,
750 * composites them together, and then creates a
751 * #GtkStyle representing the composite appearance.
752 * (GTK+ actually keeps a cache of previously
753 * created styles, so a new style may not be
756 * Returns: (transfer none): the resulting style. No refcount is added
757 * to the returned style, so if you want to save this style around,
758 * you should add a reference yourself.
760 * Deprecated:3.0: Use #GtkStyleContext instead
763 gtk_rc_get_style (GtkWidget *widget)
765 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
767 gtk_widget_ensure_style (widget);
769 return gtk_widget_get_style (widget);
773 * gtk_rc_get_style_by_paths:
774 * @settings: a #GtkSettings object
775 * @widget_path: (allow-none): the widget path to use when looking up the
776 * style, or %NULL if no matching against the widget path should be done
777 * @class_path: (allow-none): the class path to use when looking up the style,
778 * or %NULL if no matching against the class path should be done.
779 * @type: a type that will be used along with parent types of this type
780 * when matching against class styles, or #G_TYPE_NONE
782 * Creates up a #GtkStyle from styles defined in a RC file by providing
783 * the raw components used in matching. This function may be useful
784 * when creating pseudo-widgets that should be themed like widgets but
785 * don't actually have corresponding GTK+ widgets. An example of this
786 * would be items inside a GNOME canvas widget.
788 * The action of gtk_rc_get_style() is similar to:
790 * gtk_widget_path (widget, NULL, &path, NULL);
791 * gtk_widget_class_path (widget, NULL, &class_path, NULL);
792 * gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget),
794 * G_OBJECT_TYPE (widget));
797 * Return value: (transfer none): A style created by matching with the
798 * supplied paths, or %NULL if nothing matching was specified and the
799 * default style should be used. The returned value is owned by GTK+
800 * as part of an internal cache, so you must call g_object_ref() on
801 * the returned value if you want to keep a reference to it.
803 * Deprecated:3.0: Use #GtkStyleContext instead
806 gtk_rc_get_style_by_paths (GtkSettings *settings,
807 const char *widget_path,
808 const char *class_path,
814 path = gtk_widget_path_new ();
816 /* For compatibility, we return a GtkStyle based on a GtkStyleContext
817 * with a GtkWidgetPath appropriate for the supplied information.
819 * GtkWidgetPath is composed of a list of GTypes with optional names;
820 * In GTK+-2.0, widget_path consisted of the widget names, or
821 * the class names for unnamed widgets, while class_path had the
822 * class names always. So, use class_path to determine the GTypes
823 * and extract widget names from widget_path as applicable.
825 if (class_path == NULL)
827 gtk_widget_path_append_type (path, type == G_TYPE_NONE ? GTK_TYPE_WIDGET : type);
831 const gchar *widget_p, *widget_next;
832 const gchar *class_p, *class_next;
834 widget_next = widget_path;
835 class_next = class_path;
839 GType component_type;
840 gchar *component_class;
841 gchar *component_name;
844 class_p = class_next;
848 widget_p = widget_next; /* Might be NULL */
849 if (widget_p && *widget_p == '.')
852 class_next = strchr (class_p, '.');
853 if (class_next == NULL)
854 class_next = class_p + strlen (class_p);
858 widget_next = strchr (widget_p, '.');
859 if (widget_next == NULL)
860 widget_next = widget_p + strlen (widget_p);
863 component_class = g_strndup (class_p, class_next - class_p);
864 if (widget_p && *widget_p)
865 component_name = g_strndup (widget_p, widget_next - widget_p);
867 component_name = NULL;
869 component_type = g_type_from_name (component_class);
870 if (component_type == G_TYPE_INVALID)
871 component_type = GTK_TYPE_WIDGET;
873 pos = gtk_widget_path_append_type (path, component_type);
874 if (component_name != NULL && strcmp (component_name, component_name) != 0)
875 gtk_widget_path_iter_set_name (path, pos, component_name);
877 g_free (component_class);
878 g_free (component_name);
882 style = _gtk_style_new_for_path (_gtk_settings_get_screen (settings),
885 gtk_widget_path_free (path);
891 * gtk_rc_scanner_new: (skip)
893 * Deprecated:3.0: Use #GtkCssProvider instead
896 gtk_rc_scanner_new (void)
898 return g_scanner_new (>k_rc_scanner_config);
901 /*********************
902 * Parsing functions *
903 *********************/
906 lookup_color (GtkRcStyle *style,
907 const char *color_name,
910 GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (style);
913 for (iter = priv->color_hashes; iter != NULL; iter = iter->next)
915 GHashTable *hash = iter->data;
916 GdkColor *match = g_hash_table_lookup (hash, color_name);
920 color->red = match->red;
921 color->green = match->green;
922 color->blue = match->blue;
931 * gtk_rc_find_pixmap_in_path:
932 * @settings: a #GtkSettings
933 * @scanner: Scanner used to get line number information for the
934 * warning message, or %NULL
935 * @pixmap_file: name of the pixmap file to locate.
937 * Looks up a file in pixmap path for the specified #GtkSettings.
938 * If the file is not found, it outputs a warning message using
939 * g_warning() and returns %NULL.
941 * Return value: (type filename): the filename.
944 gtk_rc_find_pixmap_in_path (GtkSettings *settings,
946 const gchar *pixmap_file)
948 g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
954 * gtk_rc_find_module_in_path:
955 * @module_file: name of a theme engine
957 * Searches for a theme engine in the GTK+ search path. This function
958 * is not useful for applications and should not be used.
960 * Return value: (type filename): The filename, if found (must be
961 * freed with g_free()), otherwise %NULL.
964 gtk_rc_find_module_in_path (const gchar *module_file)
966 return _gtk_find_module (module_file, "engines");
970 * gtk_rc_parse_state:
974 * Deprecated:3.0: Use #GtkCssProvider instead
977 gtk_rc_parse_state (GScanner *scanner,
983 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
984 g_return_val_if_fail (state != NULL, G_TOKEN_ERROR);
986 /* we don't know where we got called from, so we reset the scope here.
987 * if we bail out due to errors, we *don't* reset the scope, so the
988 * error messaging code can make sense of our tokens.
990 old_scope = g_scanner_set_scope (scanner, 0);
992 token = g_scanner_get_next_token (scanner);
993 if (token != G_TOKEN_LEFT_BRACE)
994 return G_TOKEN_LEFT_BRACE;
996 token = g_scanner_get_next_token (scanner);
999 case GTK_RC_TOKEN_ACTIVE:
1000 *state = GTK_STATE_ACTIVE;
1002 case GTK_RC_TOKEN_INSENSITIVE:
1003 *state = GTK_STATE_INSENSITIVE;
1005 case GTK_RC_TOKEN_NORMAL:
1006 *state = GTK_STATE_NORMAL;
1008 case GTK_RC_TOKEN_PRELIGHT:
1009 *state = GTK_STATE_PRELIGHT;
1011 case GTK_RC_TOKEN_SELECTED:
1012 *state = GTK_STATE_SELECTED;
1015 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_NORMAL;
1018 token = g_scanner_get_next_token (scanner);
1019 if (token != G_TOKEN_RIGHT_BRACE)
1020 return G_TOKEN_RIGHT_BRACE;
1022 g_scanner_set_scope (scanner, old_scope);
1024 return G_TOKEN_NONE;
1028 * gtk_rc_parse_priority:
1032 * Deprecated:3.0: Use #GtkCssProvider instead
1035 gtk_rc_parse_priority (GScanner *scanner,
1036 GtkPathPriorityType *priority)
1041 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1042 g_return_val_if_fail (priority != NULL, G_TOKEN_ERROR);
1044 /* we don't know where we got called from, so we reset the scope here.
1045 * if we bail out due to errors, we *don't* reset the scope, so the
1046 * error messaging code can make sense of our tokens.
1048 old_scope = g_scanner_set_scope (scanner, 0);
1050 token = g_scanner_get_next_token (scanner);
1054 token = g_scanner_get_next_token (scanner);
1057 case GTK_RC_TOKEN_LOWEST:
1058 *priority = GTK_PATH_PRIO_LOWEST;
1060 case GTK_RC_TOKEN_GTK:
1061 *priority = GTK_PATH_PRIO_GTK;
1063 case GTK_RC_TOKEN_APPLICATION:
1064 *priority = GTK_PATH_PRIO_APPLICATION;
1066 case GTK_RC_TOKEN_THEME:
1067 *priority = GTK_PATH_PRIO_THEME;
1069 case GTK_RC_TOKEN_RC:
1070 *priority = GTK_PATH_PRIO_RC;
1072 case GTK_RC_TOKEN_HIGHEST:
1073 *priority = GTK_PATH_PRIO_HIGHEST;
1076 return /* G_TOKEN_SYMBOL */ GTK_RC_TOKEN_APPLICATION;
1079 g_scanner_set_scope (scanner, old_scope);
1081 return G_TOKEN_NONE;
1085 * gtk_rc_parse_color:
1086 * @scanner: a #GScanner
1087 * @color: (out): a pointer to a #GdkColor structure in which to store
1090 * Parses a color in the <link linkend="color=format">format</link> expected
1093 * Note that theme engines should use gtk_rc_parse_color_full() in
1094 * order to support symbolic colors.
1096 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1097 * that was expected but not found
1099 * Deprecated:3.0: Use #GtkCssProvider instead
1102 gtk_rc_parse_color (GScanner *scanner,
1105 return gtk_rc_parse_color_full (scanner, NULL, color);
1109 * gtk_rc_parse_color_full:
1110 * @scanner: a #GScanner
1111 * @style: (allow-none): a #GtkRcStyle, or %NULL
1112 * @color: (out): a pointer to a #GdkColor structure in which to store
1115 * Parses a color in the <link linkend="color=format">format</link> expected
1116 * in a RC file. If @style is not %NULL, it will be consulted to resolve
1117 * references to symbolic colors.
1119 * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
1120 * that was expected but not found
1124 * Deprecated:3.0: Use #GtkCssProvider instead
1127 gtk_rc_parse_color_full (GScanner *scanner,
1133 g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR);
1135 /* we don't need to set our own scope here, because
1136 * we don't need own symbols
1139 token = g_scanner_get_next_token (scanner);
1147 case G_TOKEN_LEFT_CURLY:
1148 token = g_scanner_get_next_token (scanner);
1149 if (token == G_TOKEN_INT)
1150 token_int = scanner->value.v_int;
1151 else if (token == G_TOKEN_FLOAT)
1152 token_int = scanner->value.v_float * 65535.0;
1154 return G_TOKEN_FLOAT;
1155 color->red = CLAMP (token_int, 0, 65535);
1157 token = g_scanner_get_next_token (scanner);
1158 if (token != G_TOKEN_COMMA)
1159 return G_TOKEN_COMMA;
1161 token = g_scanner_get_next_token (scanner);
1162 if (token == G_TOKEN_INT)
1163 token_int = scanner->value.v_int;
1164 else if (token == G_TOKEN_FLOAT)
1165 token_int = scanner->value.v_float * 65535.0;
1167 return G_TOKEN_FLOAT;
1168 color->green = CLAMP (token_int, 0, 65535);
1170 token = g_scanner_get_next_token (scanner);
1171 if (token != G_TOKEN_COMMA)
1172 return G_TOKEN_COMMA;
1174 token = g_scanner_get_next_token (scanner);
1175 if (token == G_TOKEN_INT)
1176 token_int = scanner->value.v_int;
1177 else if (token == G_TOKEN_FLOAT)
1178 token_int = scanner->value.v_float * 65535.0;
1180 return G_TOKEN_FLOAT;
1181 color->blue = CLAMP (token_int, 0, 65535);
1183 token = g_scanner_get_next_token (scanner);
1184 if (token != G_TOKEN_RIGHT_CURLY)
1185 return G_TOKEN_RIGHT_CURLY;
1186 return G_TOKEN_NONE;
1188 case G_TOKEN_STRING:
1189 if (!gdk_color_parse (scanner->value.v_string, color))
1191 g_scanner_warn (scanner, "Invalid color constant '%s'",
1192 scanner->value.v_string);
1193 return G_TOKEN_STRING;
1195 return G_TOKEN_NONE;
1198 token = g_scanner_get_next_token (scanner);
1199 if (token != G_TOKEN_IDENTIFIER)
1200 return G_TOKEN_IDENTIFIER;
1202 if (!style || !lookup_color (style, scanner->value.v_identifier, color))
1204 g_scanner_warn (scanner, "Invalid symbolic color '%s'",
1205 scanner->value.v_identifier);
1206 return G_TOKEN_IDENTIFIER;
1209 return G_TOKEN_NONE;
1211 case G_TOKEN_IDENTIFIER:
1212 if (strcmp (scanner->value.v_identifier, "mix") == 0)
1214 token = g_scanner_get_next_token (scanner);
1215 if (token != G_TOKEN_LEFT_PAREN)
1216 return G_TOKEN_LEFT_PAREN;
1219 if (g_scanner_peek_next_token (scanner) == '-')
1221 g_scanner_get_next_token (scanner); /* eat sign */
1225 token = g_scanner_get_next_token (scanner);
1226 if (token != G_TOKEN_FLOAT)
1227 return G_TOKEN_FLOAT;
1229 l = negate ? -scanner->value.v_float : scanner->value.v_float;
1231 token = g_scanner_get_next_token (scanner);
1232 if (token != G_TOKEN_COMMA)
1233 return G_TOKEN_COMMA;
1235 token = gtk_rc_parse_color_full (scanner, style, &c1);
1236 if (token != G_TOKEN_NONE)
1239 token = g_scanner_get_next_token (scanner);
1240 if (token != G_TOKEN_COMMA)
1241 return G_TOKEN_COMMA;
1243 token = gtk_rc_parse_color_full (scanner, style, &c2);
1244 if (token != G_TOKEN_NONE)
1247 token = g_scanner_get_next_token (scanner);
1248 if (token != G_TOKEN_RIGHT_PAREN)
1249 return G_TOKEN_RIGHT_PAREN;
1251 color->red = l * c1.red + (1.0 - l) * c2.red;
1252 color->green = l * c1.green + (1.0 - l) * c2.green;
1253 color->blue = l * c1.blue + (1.0 - l) * c2.blue;
1255 return G_TOKEN_NONE;
1257 else if (strcmp (scanner->value.v_identifier, "shade") == 0)
1259 token = g_scanner_get_next_token (scanner);
1260 if (token != G_TOKEN_LEFT_PAREN)
1261 return G_TOKEN_LEFT_PAREN;
1264 if (g_scanner_peek_next_token (scanner) == '-')
1266 g_scanner_get_next_token (scanner); /* eat sign */
1270 token = g_scanner_get_next_token (scanner);
1271 if (token != G_TOKEN_FLOAT)
1272 return G_TOKEN_FLOAT;
1274 l = negate ? -scanner->value.v_float : scanner->value.v_float;
1276 token = g_scanner_get_next_token (scanner);
1277 if (token != G_TOKEN_COMMA)
1278 return G_TOKEN_COMMA;
1280 token = gtk_rc_parse_color_full (scanner, style, &c1);
1281 if (token != G_TOKEN_NONE)
1284 token = g_scanner_get_next_token (scanner);
1285 if (token != G_TOKEN_RIGHT_PAREN)
1286 return G_TOKEN_RIGHT_PAREN;
1288 _gtk_style_shade (&c1, color, l);
1290 return G_TOKEN_NONE;
1292 else if (strcmp (scanner->value.v_identifier, "lighter") == 0 ||
1293 strcmp (scanner->value.v_identifier, "darker") == 0)
1295 if (scanner->value.v_identifier[0] == 'l')
1300 token = g_scanner_get_next_token (scanner);
1301 if (token != G_TOKEN_LEFT_PAREN)
1302 return G_TOKEN_LEFT_PAREN;
1304 token = gtk_rc_parse_color_full (scanner, style, &c1);
1305 if (token != G_TOKEN_NONE)
1308 token = g_scanner_get_next_token (scanner);
1309 if (token != G_TOKEN_RIGHT_PAREN)
1310 return G_TOKEN_RIGHT_PAREN;
1312 _gtk_style_shade (&c1, color, l);
1314 return G_TOKEN_NONE;
1317 return G_TOKEN_IDENTIFIER;
1320 return G_TOKEN_STRING;