]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkrc.c
new default color scheme based on the GNOME stock icon palette. (#80691,
[~andy/gtk] / gtk / gtkrc.c
index 6a13c2ffd343cc5c1cd3f557f080278f4f91f799..82700ebf47e1ee3db5c0222509b187a6fe231a00 100644 (file)
@@ -27,7 +27,6 @@
 #include "config.h"
 
 #include <locale.h>
-#include <ctype.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -53,6 +52,8 @@
 #include "gtkthemes.h"
 #include "gtkintl.h"
 #include "gtkiconfactory.h"
+#include "gtkmain.h"
+#include "gtkprivate.h"
 #include "gtksettings.h"
 #include "gtkwindow.h"
 
@@ -73,6 +74,7 @@ struct _GtkRcSet
 
 struct _GtkRcFile
 {
+  gboolean is_string;          /* If TRUE, name is a string to parse with gtk_rc_parse_string() */
   time_t mtime;
   gchar *name;
   gchar *canonical_name;
@@ -94,10 +96,12 @@ struct _GtkRcContext
 
   gchar *theme_name;
   gchar *key_theme_name;
+  gchar *font_name;
   
   gchar *pixmap_path[GTK_RC_MAX_PIXMAP_PATHS];
 
   gint default_priority;
+  GtkStyle *default_style;
 };
 
 static GtkRcContext *gtk_rc_context_get              (GtkSettings     *settings);
@@ -115,13 +119,15 @@ static GSList *    gtk_rc_styles_match               (GSList          *rc_styles
                                                       guint            path_length,
                                                       const gchar     *path,
                                                       const gchar     *path_reversed);
-static GtkStyle *  gtk_rc_style_to_style             (GtkRcStyle      *rc_style);
-static GtkStyle*   gtk_rc_init_style                 (GSList          *rc_styles);
+static GtkStyle *  gtk_rc_style_to_style             (GtkRcContext    *context,
+                                                     GtkRcStyle      *rc_style);
+static GtkStyle*   gtk_rc_init_style                 (GtkRcContext    *context,
+                                                     GSList          *rc_styles);
 static void        gtk_rc_parse_default_files        (GtkRcContext    *context);
 static void        gtk_rc_parse_named                (GtkRcContext    *context,
                                                      const gchar     *name,
                                                      const gchar     *type);
-static void        gtk_rc_parse_file                 (GtkRcContext    *context,
+static void        gtk_rc_context_parse_file         (GtkRcContext    *context,
                                                      const gchar     *filename,
                                                      gint             priority,
                                                       gboolean         reload);
@@ -165,8 +171,6 @@ static void        gtk_rc_parse_pixmap_path_string   (GtkRcContext    *context,
                                                      GScanner        *scanner,
                                                      const gchar     *pix_path);
 static guint       gtk_rc_parse_module_path          (GScanner        *scanner);
-static void        gtk_rc_parse_module_path_string   (const gchar     *mod_path);
-static guint       gtk_rc_parse_im_module_path       (GScanner        *scanner);
 static guint       gtk_rc_parse_im_module_file       (GScanner        *scanner);
 static guint       gtk_rc_parse_path_pattern         (GtkRcContext    *context,
                                                      GScanner        *scanner);
@@ -178,7 +182,6 @@ static void        gtk_rc_clear_hash_node            (gpointer         key,
                                                       gpointer         data,
                                                       gpointer         user_data);
 static void        gtk_rc_clear_styles               (GtkRcContext    *context);
-static void        gtk_rc_append_default_module_path (void);
 static void        gtk_rc_add_initial_default_files  (void);
 
 static void        gtk_rc_style_init                 (GtkRcStyle      *style);
@@ -271,7 +274,6 @@ static const struct
   { "engine", GTK_RC_TOKEN_ENGINE },
   { "module_path", GTK_RC_TOKEN_MODULE_PATH },
   { "stock", GTK_RC_TOKEN_STOCK },
-  { "im_module_path", GTK_RC_TOKEN_IM_MODULE_PATH },
   { "im_module_file", GTK_RC_TOKEN_IM_MODULE_FILE },
   { "LTR", GTK_RC_TOKEN_LTR },
   { "RTL", GTK_RC_TOKEN_RTL }
@@ -279,77 +281,71 @@ static const struct
 
 static GHashTable *realized_style_ht = NULL;
 
-static gchar *im_module_path = NULL;
 static gchar *im_module_file = NULL;
 
 #define GTK_RC_MAX_DEFAULT_FILES 128
 static gchar *gtk_rc_default_files[GTK_RC_MAX_DEFAULT_FILES];
 
-#define GTK_RC_MAX_MODULE_PATHS 128
-static gchar *module_path[GTK_RC_MAX_MODULE_PATHS];
-
 /* A stack of directories for RC files we are parsing currently.
  * these are implicitely added to the end of PIXMAP_PATHS
  */
 static GSList *rc_dir_stack = NULL;
 
-/* RC file handling */
-
-#ifdef G_OS_WIN32
-static gchar *
-get_gtk_dll_name (void)
-{
-  static gchar *gtk_dll = NULL;
+/* RC files and strings that are parsed for every context
+ */
+static GSList *global_rc_files = NULL;
 
-  if (!gtk_dll)
-    gtk_dll = g_strdup_printf ("gtk-%d.%d.dll", GTK_MAJOR_VERSION, GTK_MINOR_VERSION);
+/* Keep list of all current RC contexts for convenience
+ */
+static GSList *rc_contexts;
 
-  return gtk_dll;
-}
+/* RC file handling */
 
-static gchar *
-get_themes_directory (void)
-{
-  return g_win32_get_package_installation_subdirectory (GETTEXT_PACKAGE,
-                                                       get_gtk_dll_name (),
-                                                       "themes");
-}
-#endif /* G_OS_WIN32 */
 static gchar *
 gtk_rc_make_default_dir (const gchar *type)
 {
-  gchar *var, *path;
+  const gchar *var;
+  gchar *path;
 
-#ifndef G_OS_WIN32
-  var = getenv("GTK_EXE_PREFIX");
+  var = g_getenv ("GTK_EXE_PREFIX");
   if (var)
-    path = g_strconcat (var, "/lib/gtk-2.0/" GTK_VERSION "/", type, NULL);
+    path = g_build_filename (var, "lib", "gtk-2.0", GTK_BINARY_VERSION, type, NULL);
   else
-    path = g_strconcat (GTK_LIBDIR "/gtk-2.0/" GTK_VERSION "/", type, NULL);
-#else
-  path = g_strconcat ("%s\\%s", get_themes_directory (), type);
-#endif
+    path = g_build_filename (GTK_LIBDIR, "gtk-2.0", GTK_BINARY_VERSION, type, NULL);
 
   return path;
 }
 
+/**
+ * gtk_rc_get_im_module_path:
+ * @returns: a newly-allocated string containing the path in which to 
+ *    look for IM modules.
+ *
+ * Obtains the path in which to look for IM modules. See the documentation
+ * of the <link linkend="im-module-path"><envar>GTK_PATH</envar></link>
+ * environment variable for more details about looking up modules. This
+ * function is useful solely for utilities supplied with GTK+ and should
+ * not be used by applications under normal circumstances.
+ */
 gchar *
 gtk_rc_get_im_module_path (void)
 {
-  const gchar *result = g_getenv ("GTK_IM_MODULE_PATH");
-
-  if (!result)
-    {
-      if (im_module_path)
-       result = im_module_path;
-      else
-       return gtk_rc_make_default_dir ("immodules");
-    }
+  gchar **paths = _gtk_get_module_path ("immodules");
+  gchar *result = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, paths);
+  g_strfreev (paths);
 
-  return g_strdup (result);
+  return result;
 }
 
+/**
+ * gtk_rc_get_im_module_file:
+ * @returns: a newly-allocated string containing the name of the file
+ * listing the IM modules available for loading
+ *
+ * Obtains the path to the IM modules file. See the documentation
+ * of the <link linkend="im-module-file"><envar>GTK_IM_MODULE_FILE</envar></link>
+ * environment variable for more details.
+ */
 gchar *
 gtk_rc_get_im_module_file (void)
 {
@@ -360,83 +356,43 @@ gtk_rc_get_im_module_file (void)
       if (im_module_file)
        result = g_strdup (im_module_file);
       else
-#ifndef G_OS_WIN32
-       result = g_strdup (GTK_SYSCONFDIR G_DIR_SEPARATOR_S "gtk-2.0" G_DIR_SEPARATOR_S "gtk.immodules");
-#else
-       result = g_strdup_printf ("%s\\gtk.immodules", g_win32_get_package_installation_directory (GETTEXT_PACKAGE, get_gtk_dll_name ()));
-#endif
+       result = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtk.immodules", NULL);
     }
 
   return result;
 }
 
 gchar *
-gtk_rc_get_theme_dir(void)
+gtk_rc_get_theme_dir (void)
 {
-  gchar *var, *path;
+  const gchar *var;
+  gchar *path;
 
-#ifndef G_OS_WIN32
-  var = getenv("GTK_DATA_PREFIX");
+  var = g_getenv ("GTK_DATA_PREFIX");
   if (var)
-    path = g_strconcat (var, "/share/themes", NULL);
+    path = g_build_filename (var, "share", "themes", NULL);
   else
-    path = g_strconcat (GTK_DATA_PREFIX, "/share/themes", NULL);
-#else
-  path = g_strdup (get_themes_directory ());
-#endif
+    path = g_build_filename (GTK_DATA_PREFIX, "share", "themes", NULL);
 
   return path;
 }
 
+/**
+ * gtk_rc_get_module_dir:
+ * 
+ * Returns a directory in which GTK+ looks for theme engines.
+ * For full information about the search for theme engines,
+ * see the docs for <envar>GTK_PATH</envar> in
+ * <xref linkend="gtk-running"/>.
+ * 
+ * return value: the directory. (Must be freed with g_free())
+ **/
 gchar *
-gtk_rc_get_module_dir(void)
+gtk_rc_get_module_dir (void)
 {
   return gtk_rc_make_default_dir ("engines");
 }
 
-static void
-gtk_rc_append_default_module_path(void)
-{
-  const gchar *var;
-  gchar *path;
-  gint n;
-
-  for (n = 0; module_path[n]; n++) ;
-  if (n >= GTK_RC_MAX_MODULE_PATHS - 1)
-    return;
-  
-#ifndef G_OS_WIN32
-  var = getenv("GTK_EXE_PREFIX");
-  if (var)
-    path = g_strconcat(var, "/lib/gtk-2.0/" GTK_VERSION "/engines", NULL);
-  else
-    path = g_strdup (GTK_LIBDIR "/gtk-2.0/" GTK_VERSION "/engines");
-#else
-  path = g_strconcat (get_themes_directory (), "\\engines", NULL);
-#endif
-  module_path[n++] = path;
-
-  var = g_get_home_dir ();
-  if (var)
-    {
-      gchar *sep;
-      /* Don't duplicate the directory separator, causes trouble at
-       * least on Windows.
-       */
-      if (var[strlen (var) -1] != G_DIR_SEPARATOR)
-       sep = G_DIR_SEPARATOR_S;
-      else
-       sep = "";
-      /* This produces something like ~/.gtk-2.0/2.0/engines */
-      path = g_strconcat (var, sep,
-                         ".gtk-2.0" G_DIR_SEPARATOR_S
-                         GTK_VERSION G_DIR_SEPARATOR_S
-                         "engines", NULL);
-      module_path[n++] = path;
-    }
-  module_path[n] = NULL;
-}
-
 static void
 gtk_rc_add_initial_default_files (void)
 {
@@ -452,7 +408,7 @@ gtk_rc_add_initial_default_files (void)
   gtk_rc_default_files[0] = NULL;
   init = TRUE;
 
-  var = g_getenv("GTK_RC_FILES");
+  var = g_getenv ("GTK2_RC_FILES");
   if (var)
     {
       files = g_strsplit (var, G_SEARCHPATH_SEPARATOR_S, 128);
@@ -466,11 +422,7 @@ gtk_rc_add_initial_default_files (void)
     }
   else
     {
-#ifndef G_OS_WIN32
-      str = g_strdup (GTK_SYSCONFDIR G_DIR_SEPARATOR_S "gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
-#else
-      str = g_strdup_printf ("%s\\gtkrc", g_win32_get_package_installation_directory (GETTEXT_PACKAGE, get_gtk_dll_name ()));
-#endif
+      str = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtkrc", NULL);
 
       gtk_rc_add_default_file (str);
       g_free (str);
@@ -478,12 +430,7 @@ gtk_rc_add_initial_default_files (void)
       var = g_get_home_dir ();
       if (var)
        {
-         gchar *sep;
-         if (var[strlen (var) -1] != G_DIR_SEPARATOR)
-           sep = G_DIR_SEPARATOR_S;
-         else
-           sep = "";
-         str = g_strdup_printf ("%s%s.gtkrc-2.0", var, sep);
+         str = g_build_filename (var, ".gtkrc-2.0", NULL);
          gtk_rc_add_default_file (str);
          g_free (str);
        }
@@ -492,7 +439,8 @@ gtk_rc_add_initial_default_files (void)
 
 /**
  * gtk_rc_add_default_file:
- * @filename: the pathname to the file.
+ * @filename: the pathname to the file. If @filename is not absolute, it
+ *    is searched in the current directory.
  * 
  * Adds a file to the list of files to be parsed at the
  * end of gtk_init().
@@ -514,10 +462,10 @@ gtk_rc_add_default_file (const gchar *filename)
 
 /**
  * gtk_rc_set_default_files:
- * @filenames: A %NULL terminated list of filenames.
+ * @filenames: A %NULL-terminated list of filenames.
  * 
  * Sets the list of files that GTK+ will read at the
- * end of gtk_init()
+ * end of gtk_init().
  **/
 void
 gtk_rc_set_default_files (gchar **filenames)
@@ -547,12 +495,11 @@ gtk_rc_set_default_files (gchar **filenames)
  * gtk_rc_get_default_files:
  * 
  * Retrieves the current list of RC files that will be parsed
- * at the end of gtk_init()
+ * at the end of gtk_init().
  * 
- * Return value: A NULL terminated array of filenames. This memory
+ * Return value: A %NULL-terminated array of filenames. This memory
  * is owned by GTK+ and must not be freed by the application.
- *  If you want to store this information, you should make a 
- * copy.
+ * If you want to store this information, you should make a copy.
  **/
 gchar **
 gtk_rc_get_default_files (void)
@@ -562,55 +509,6 @@ gtk_rc_get_default_files (void)
   return gtk_rc_default_files;
 }
 
-/* The following routine is based on _nl_normalize_codeset from
- * the GNU C library. Contributed by
- *
- * Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
- * Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
- * 
- * Normalize codeset name.  There is no standard for the codeset
- * names.  Normalization allows the user to use any of the common
- * names.
- */
-static gchar *
-_gtk_normalize_codeset (const gchar *codeset, gint name_len)
-{
-  gint len = 0;
-  gint only_digit = 1;
-  gchar *retval;
-  gchar *wp;
-  gint cnt;
-
-  for (cnt = 0; cnt < name_len; ++cnt)
-    if (isalnum (codeset[cnt]))
-      {
-       ++len;
-
-       if (isalpha (codeset[cnt]))
-        only_digit = 0;
-      }
-
-  retval = g_malloc ((only_digit ? 3 : 0) + len + 1);
-
-  if (only_digit)
-    {
-      memcpy (retval, "iso", 4);
-      wp = retval + 3;
-    }
-  else
-    wp = retval;
-
-  for (cnt = 0; cnt < name_len; ++cnt)
-    if (isalpha (codeset[cnt]))
-      *wp++ = isupper(codeset[cnt]) ? tolower (codeset[cnt]) : codeset[cnt];
-    else if (isdigit (codeset[cnt]))
-      *wp++ = codeset[cnt];
-
-  *wp = '\0';
-
-  return retval;
-}
-
 static void
 gtk_rc_settings_changed (GtkSettings  *settings,
                         GParamSpec   *pspec,
@@ -636,6 +534,14 @@ gtk_rc_settings_changed (GtkSettings  *settings,
   g_free (new_key_theme_name);
 }
 
+static void
+gtk_rc_font_name_changed (GtkSettings  *settings,
+                          GParamSpec   *pspec,
+                          GtkRcContext *context)
+{
+  _gtk_rc_context_get_default_font_name (settings);
+}
+
 static GtkRcContext *
 gtk_rc_context_get (GtkSettings *settings)
 {
@@ -649,10 +555,12 @@ gtk_rc_context_get (GtkSettings *settings)
       context->rc_sets_widget_class = NULL;
       context->rc_sets_class = NULL;
       context->rc_files = NULL;
+      context->default_style = NULL;
 
       g_object_get (settings,
                    "gtk-theme-name", &context->theme_name,
                    "gtk-key-theme-name", &context->key_theme_name,
+                   "gtk-font-name", &context->font_name,
                    NULL);
 
       g_signal_connect (settings,
@@ -663,10 +571,17 @@ gtk_rc_context_get (GtkSettings *settings)
                        "notify::gtk-key-theme-name",
                        G_CALLBACK (gtk_rc_settings_changed),
                        context);
+      g_signal_connect (settings,
+                       "notify::gtk-font-name",
+                       G_CALLBACK (gtk_rc_font_name_changed),
+                       context);
+
       
       context->pixmap_path[0] = NULL;
 
       context->default_priority = GTK_PATH_PRIO_RC;
+
+      rc_contexts = g_slist_prepend (rc_contexts, settings->rc_context);
     }
 
   return settings->rc_context;
@@ -678,36 +593,22 @@ gtk_rc_parse_named (GtkRcContext *context,
                    const gchar  *type)
 {
   gchar *path = NULL;
-  gchar *home_dir;
+  const gchar *home_dir;
   gchar *subpath;
 
   if (type)
-    subpath = g_strconcat (G_DIR_SEPARATOR_S "gtk-2.0-",
-                          type,
+    subpath = g_strconcat ("gtk-2.0-", type,
                           G_DIR_SEPARATOR_S "gtkrc",
                           NULL);
   else
-    subpath = g_strdup (G_DIR_SEPARATOR_S "gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
+    subpath = g_strdup ("gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
   
   /* First look in the users home directory
    */
   home_dir = g_get_home_dir ();
   if (home_dir)
     {
-      gchar *sep;
-      /* Don't duplicate the directory separator, causes trouble at
-       * least on Windows.
-       */
-      if (home_dir[strlen (home_dir) -1] != G_DIR_SEPARATOR)
-       sep = G_DIR_SEPARATOR_S;
-      else
-       sep = "";
-      path = g_strconcat (home_dir, sep,
-                         ".themes" G_DIR_SEPARATOR_S ,
-                         name,
-                         subpath,
-                         NULL);
-
+      path = g_build_filename (home_dir, ".themes", name, subpath, NULL);
       if (!g_file_test (path, G_FILE_TEST_EXISTS))
        {
          g_free (path);
@@ -715,10 +616,10 @@ gtk_rc_parse_named (GtkRcContext *context,
        }
     }
 
-  if (!name)
+  if (!path)
     {
       gchar *theme_dir = gtk_rc_get_theme_dir ();
-      gchar *path = g_strconcat (theme_dir, G_DIR_SEPARATOR_S, name, subpath);
+      path = g_build_filename (theme_dir, name, subpath, NULL);
       g_free (theme_dir);
       
       if (!g_file_test (path, G_FILE_TEST_EXISTS))
@@ -730,7 +631,7 @@ gtk_rc_parse_named (GtkRcContext *context,
 
   if (path)
     {
-      gtk_rc_parse_file (context, path, GTK_PATH_PRIO_THEME, FALSE);
+      gtk_rc_context_parse_file (context, path, GTK_PATH_PRIO_THEME, FALSE);
       g_free (path);
     }
 
@@ -740,79 +641,10 @@ gtk_rc_parse_named (GtkRcContext *context,
 static void
 gtk_rc_parse_default_files (GtkRcContext *context)
 {
-  gchar *locale_suffixes[3];
-  gint n_locale_suffixes = 0;
-  gint i, j;
-  gint length;
-  gchar *locale;
-  gchar *p;
-
-#ifdef G_OS_WIN32      
-  locale = g_win32_getlocale ();
-#else      
-  locale = setlocale (LC_CTYPE, NULL);
-#endif      
+  gint i;
 
-  if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
-    {
-      /* Determine locale-specific suffixes for RC files
-       *
-       * We normalize the charset into a standard form,
-       * which has all '-' and '_' characters removed,
-       * and is lowercase.
-       */
-      gchar *normalized_locale;
-      
-      p = strchr (locale, '@');
-      length = p ? (p -locale) : strlen (locale);
-      
-      p = strchr (locale, '.');
-      if (p)
-       {
-         gchar *tmp1 = g_strndup (locale, p - locale + 1);
-         gchar *tmp2 = _gtk_normalize_codeset (p + 1, length - (p - locale + 1));
-         
-         normalized_locale = g_strconcat (tmp1, tmp2, NULL);
-         g_free (tmp1);
-         g_free (tmp2);
-         
-         locale_suffixes[n_locale_suffixes++] = g_strdup (normalized_locale);
-         length = p - locale;
-       }
-      else
-       normalized_locale = g_strndup (locale, length);
-      
-      p = strchr (normalized_locale, '_');
-      if (p)
-       {
-         locale_suffixes[n_locale_suffixes++] = g_strndup (normalized_locale, length);
-         length = p - normalized_locale;
-       }
-      
-      locale_suffixes[n_locale_suffixes++] = g_strndup (normalized_locale, length);
-      
-      g_free (normalized_locale);
-    }
-  
   for (i = 0; gtk_rc_default_files[i] != NULL; i++)
-    {
-      /* Try to find a locale specific RC file corresponding to the
-       * current locale to parse before the default file.
-       */
-      for (j = n_locale_suffixes - 1; j >= 0; j--)
-       {
-         gchar *name = g_strconcat (gtk_rc_default_files[i],
-                                    ".",
-                                    locale_suffixes[j],
-                                    NULL);
-         gtk_rc_parse_file (context, name, GTK_PATH_PRIO_RC, FALSE);
-         g_free (name);
-       }
-      gtk_rc_parse_file (context, gtk_rc_default_files[i], GTK_PATH_PRIO_RC, FALSE);
-    }
-
-  for (j = 0; j < n_locale_suffixes; j++)
-    g_free (locale_suffixes[j]);
+    gtk_rc_context_parse_file (context, gtk_rc_default_files[i], GTK_PATH_PRIO_RC, FALSE);
 }
 
 void
@@ -824,61 +656,115 @@ _gtk_rc_init (void)
     {
       initialized = TRUE;
       
-      module_path[0] = NULL;
-      gtk_rc_append_default_module_path();
-      
       gtk_rc_add_initial_default_files ();
     }
   
-  gtk_rc_reparse_all_for_settings (gtk_settings_get_default (), TRUE);
+  /* Default RC string */
+  gtk_rc_parse_string ("style \"gtk-default-tooltips-style\" {\n"
+                      "  bg[NORMAL] = \"#eee1b3\"\n"
+                      "  fg[NORMAL] = \"#000000\"\n"
+                      "}\n"
+                      "\n"
+                      "style \"gtk-default-progress-bar-style\" {\n"
+                      "  bg[PRELIGHT] = \"#4b6983\"\n"
+                      "  fg[PRELIGHT] = \"#ffffff\"\n"
+                      "  bg[NORMAL]   = \"#bab5ab\"\n"
+                      "}\n"
+                      "\n"
+                      "style \"gtk-default-menu-item-style\" {\n"
+                      "  bg[PRELIGHT] = \"#4b6983\"\n"
+                      "  fg[PRELIGHT] = \"#ffffff\"\n"
+                      "  base[PRELIGHT] = \"#4b6983\"\n"
+                      "  text[PRELIGHT] = \"#ffffff\"\n"
+                      "}\n"
+                      "\n"
+                      "class \"GtkProgressBar\" style : gtk \"gtk-default-progress-bar-style\"\n"
+                      "widget \"gtk-tooltips*\" style : gtk \"gtk-default-tooltips-style\"\n"
+                      "class \"GtkMenuItem\" style : gtk \"gtk-default-menu-item-style\"\n"
+                      "widget_class \"*.GtkMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
+                      "widget_class \"*.GtkAccelMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
+                      "widget_class \"*.GtkRadioMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
+                      "widget_class \"*.GtkCheckMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
+                      "widget_class \"*.GtkImageMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
+                      "widget_class \"*.GtkSeparatorMenuItem.*\" style : gtk \"gtk-default-menu-item-style\"\n"
+      );
 }
   
+static void
+gtk_rc_context_parse_string (GtkRcContext *context,
+                            const gchar  *rc_string)
+{
+  gtk_rc_parse_any (context, "-", -1, rc_string);
+}
+
 void
 gtk_rc_parse_string (const gchar *rc_string)
 {
+  GtkRcFile *rc_file;
+  GSList *tmp_list;
+      
   g_return_if_fail (rc_string != NULL);
 
-  gtk_rc_parse_any (gtk_rc_context_get (gtk_settings_get_default ()),
-                   "-", -1, rc_string);        /* FIXME */
+  rc_file = g_new (GtkRcFile, 1);
+  rc_file->is_string = TRUE;
+  rc_file->name = g_strdup (rc_string);
+  rc_file->canonical_name = NULL;
+  rc_file->mtime = 0;
+  rc_file->reload = TRUE;
+
+  global_rc_files = g_slist_append (global_rc_files, rc_file);
+
+  for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
+    gtk_rc_context_parse_string (tmp_list->data, rc_string);
 }
 
-static void
-gtk_rc_parse_file (GtkRcContext *context,
-                  const gchar  *filename,
-                  gint          priority,
-                  gboolean      reload)
+static GtkRcFile *
+add_to_rc_file_list (GSList     **rc_file_list,
+                    const char  *filename,
+                    gboolean     reload)
 {
-  GtkRcFile *rc_file = NULL;
-  struct stat statbuf;
   GSList *tmp_list;
-  gint saved_priority;
-
-  g_return_if_fail (filename != NULL);
-
-  saved_priority = context->default_priority;
-  context->default_priority = priority;
+  GtkRcFile *rc_file;
   
-  tmp_list = context->rc_files;
+  tmp_list = *rc_file_list;
   while (tmp_list)
     {
       rc_file = tmp_list->data;
       if (!strcmp (rc_file->name, filename))
-       break;
+       return rc_file;
       
       tmp_list = tmp_list->next;
     }
 
-  if (!tmp_list)
-    {
-      rc_file = g_new (GtkRcFile, 1);
-      rc_file->name = g_strdup (filename);
-      rc_file->canonical_name = NULL;
-      rc_file->mtime = 0;
-      rc_file->reload = reload;
+  rc_file = g_new (GtkRcFile, 1);
+  rc_file->is_string = FALSE;
+  rc_file->name = g_strdup (filename);
+  rc_file->canonical_name = NULL;
+  rc_file->mtime = 0;
+  rc_file->reload = reload;
+  
+  *rc_file_list = g_slist_append (*rc_file_list, rc_file);
+  
+  return rc_file;
+}
 
-      context->rc_files = g_slist_append (context->rc_files, rc_file);
-    }
+static void
+gtk_rc_context_parse_one_file (GtkRcContext *context,
+                              const gchar  *filename,
+                              gint          priority,
+                              gboolean      reload)
+{
+  GtkRcFile *rc_file;
+  struct stat statbuf;
+  gint saved_priority;
+
+  g_return_if_fail (filename != NULL);
+
+  saved_priority = context->default_priority;
+  context->default_priority = priority;
 
+  rc_file = add_to_rc_file_list (&context->rc_files, filename, reload);
+  
   if (!rc_file->canonical_name)
     {
       /* Get the absolute pathname */
@@ -887,18 +773,11 @@ gtk_rc_parse_file (GtkRcContext *context,
        rc_file->canonical_name = rc_file->name;
       else
        {
-         GString *str;
          gchar *cwd;
 
          cwd = g_get_current_dir ();
-
-         str = g_string_new (cwd);
+         rc_file->canonical_name = g_build_filename (cwd, rc_file->name, NULL);
          g_free (cwd);
-         g_string_append_c (str, G_DIR_SEPARATOR);
-         g_string_append (str, rc_file->name);
-         
-         rc_file->canonical_name = str->str;
-         g_string_free (str, FALSE);
        }
     }
 
@@ -934,13 +813,93 @@ gtk_rc_parse_file (GtkRcContext *context,
   context->default_priority = saved_priority;
 }
 
+static gchar *
+strchr_len (const gchar *str, gint len, char c)
+{
+  while (len--)
+    {
+      if (*str == c)
+       return (gchar *)str;
+
+      str++;
+    }
+
+  return NULL;
+}
+
+static void
+gtk_rc_context_parse_file (GtkRcContext *context,
+                          const gchar  *filename,
+                          gint          priority,
+                          gboolean      reload)
+{
+  gchar *locale_suffixes[2];
+  gint n_locale_suffixes = 0;
+  gchar *p;
+  const gchar *locale;
+  gint length, j;
+  gboolean found = FALSE;
+
+#ifdef G_OS_WIN32      
+  locale = g_win32_getlocale ();
+#else      
+  locale = setlocale (LC_CTYPE, NULL);
+#endif      
+
+  if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
+    {
+      /* Determine locale-specific suffixes for RC files.
+       */
+      length = strlen (locale);
+      
+      p = strchr (locale, '@');
+      if (p)
+       length = p - locale;
+
+      p = strchr_len (locale, length, '.');
+      if (p)
+       length = p - locale;
+      
+      locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
+      
+      p = strchr_len (locale, length, '_');
+      if (p)
+       {
+         length = p - locale;
+         locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
+       }
+    }
+  
+  gtk_rc_context_parse_one_file (context, filename, priority, reload);
+  for (j = 0; j < n_locale_suffixes; j++)
+    {
+      if (!found)
+       {
+         gchar *name = g_strconcat (filename, ".", locale_suffixes[j], NULL);
+         if (g_file_test (name, G_FILE_TEST_EXISTS))
+           {
+             gtk_rc_context_parse_one_file (context, name, priority, FALSE);
+             found = TRUE;
+           }
+             
+         g_free (name);
+       }
+      
+      g_free (locale_suffixes[j]);
+    }
+}
+
 void
 gtk_rc_parse (const gchar *filename)
 {
+  GSList *tmp_list;
+  
   g_return_if_fail (filename != NULL);
 
-  gtk_rc_parse_file (gtk_rc_context_get (gtk_settings_get_default ()),
-                    filename, GTK_PATH_PRIO_RC, TRUE); /* FIXME */
+  add_to_rc_file_list (&global_rc_files, filename, TRUE);
+  
+  for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
+    gtk_rc_context_parse_file (tmp_list->data, filename, GTK_PATH_PRIO_RC, TRUE);
 }
 
 /* Handling of RC styles */
@@ -948,11 +907,11 @@ gtk_rc_parse (const gchar *filename)
 GType
 gtk_rc_style_get_type (void)
 {
-  static GType object_type = 0;
+  static GType rc_style_type = 0;
 
-  if (!object_type)
+  if (!rc_style_type)
     {
-      static const GTypeInfo object_info =
+      static const GTypeInfo rc_style_info =
       {
         sizeof (GtkRcStyleClass),
         (GBaseInitFunc) NULL,
@@ -965,12 +924,11 @@ gtk_rc_style_get_type (void)
         (GInstanceInitFunc) gtk_rc_style_init,
       };
       
-      object_type = g_type_register_static (G_TYPE_OBJECT,
-                                            "GtkRcStyle",
-                                            &object_info, 0);
+      rc_style_type = g_type_register_static (G_TYPE_OBJECT, "GtkRcStyle",
+                                             &rc_style_info, 0);
     }
   
-  return object_type;
+  return rc_style_type;
 }
 
 static void
@@ -1041,7 +999,7 @@ gtk_rc_style_finalize (GObject *object)
     {
       GSList *rc_styles = tmp_list1->data;
       GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles);
-      gtk_style_unref (style);
+      g_object_unref (style);
 
       /* Remove the list of styles from the other rc_styles
        * in the list
@@ -1084,8 +1042,7 @@ gtk_rc_style_finalize (GObject *object)
   tmp_list1 = rc_style->icon_factories;
   while (tmp_list1)
     {
-      g_object_unref (G_OBJECT (tmp_list1->data));
-
+      g_object_unref (tmp_list1->data);
       tmp_list1 = tmp_list1->next;
     }
   g_slist_free (rc_style->icon_factories);
@@ -1107,8 +1064,8 @@ gtk_rc_style_new (void)
  * gtk_rc_style_copy:
  * @orig: the style to copy
  * 
- * Make a copy of the specified #GtkRcStyle. This function
- * will correctly copy an rc style that is a member of a class
+ * Makes a copy of the specified #GtkRcStyle. This function
+ * will correctly copy an RC style that is a member of a class
  * derived from #GtkRcStyle.
  * 
  * Return value: the resulting #GtkRcStyle
@@ -1127,19 +1084,19 @@ gtk_rc_style_copy (GtkRcStyle *orig)
 }
 
 void      
-gtk_rc_style_ref (GtkRcStyle  *rc_style)
+gtk_rc_style_ref (GtkRcStyle *rc_style)
 {
   g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
 
-  g_object_ref (G_OBJECT (rc_style));
+  g_object_ref (rc_style);
 }
 
 void      
-gtk_rc_style_unref (GtkRcStyle  *rc_style)
+gtk_rc_style_unref (GtkRcStyle *rc_style)
 {
   g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
 
-  g_object_unref (G_OBJECT (rc_style));
+  g_object_unref (rc_style);
 }
 
 static GtkRcStyle *
@@ -1180,8 +1137,8 @@ insert_rc_property (GtkRcStyle    *style,
   while (i < style->rc_properties->len)
     {
       gint cmp = gtk_rc_properties_cmp (&key, &g_array_index (style->rc_properties, GtkRcProperty, i));
+
       if (cmp == 0)
-       
        {
          if (replace)
            {
@@ -1196,7 +1153,7 @@ insert_rc_property (GtkRcStyle    *style,
          else
            return;
        }
-      else if (cmp > 0)
+      else if (cmp < 0)
        break;
 
       i++;
@@ -1255,8 +1212,13 @@ gtk_rc_style_real_merge (GtkRcStyle *dest,
   if (dest->ythickness < 0 && src->ythickness >= 0)
     dest->ythickness = src->ythickness;
 
-  if (!dest->font_desc && src->font_desc)
-    dest->font_desc = pango_font_description_copy (src->font_desc);
+  if (src->font_desc)
+    {
+      if (!dest->font_desc)
+       dest->font_desc = pango_font_description_copy (src->font_desc);
+      else
+       pango_font_description_merge (dest->font_desc, src->font_desc, FALSE);
+    }
 
   if (src->rc_properties)
     {
@@ -1327,21 +1289,118 @@ gtk_rc_clear_styles (GtkRcContext *context)
  * icon sets so they get re-rendered.
  */
 static void
-gtk_rc_reset_widgets (GtkRcContext *context)
+gtk_rc_reset_widgets (GtkSettings *settings)
 {
   GList *list, *toplevels;
-  
+
   _gtk_icon_set_invalidate_caches ();
   
   toplevels = gtk_window_list_toplevels ();
   g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
   
-  for (list = toplevels; list; list = list->next)
+  for (list = toplevels; list; list = list->next)
+    {
+      if (gtk_widget_get_screen (list->data) == settings->screen)
+       {
+         gtk_widget_reset_rc_styles (list->data);
+         g_object_unref (list->data);
+       }
+    }
+  g_list_free (toplevels);
+}
+
+static void
+gtk_rc_clear_realized_style (gpointer key,
+                            gpointer value,
+                            gpointer data)
+{
+  GSList *rc_styles = key;
+  GSList *tmp_list = rc_styles;
+
+  while (tmp_list)
+    {
+      GtkRcStyle *rc_style = tmp_list->data;
+      
+      rc_style->rc_style_lists = g_slist_remove_all (rc_style->rc_style_lists,
+                                                    rc_styles);
+      tmp_list = tmp_list->next;
+    }
+
+  g_slist_free (rc_styles);
+}
+
+/**
+ * _gtk_rc_reset_styles:
+ * @settings: a #GtkSettings
+ * 
+ * This setting resets all of our styles; we use it when the font
+ * rendering parameters or the icon sizes have changed. It's both less
+ * and more comprehensive then we actually need:
+ *
+ * Less comprehensive: it doesn't affect widgets that have a style
+ *   set on them.
+ *
+ * More comprehensive: it resets the styles, but the styles haven't
+ *   changed. The main reason for resetting the styles is becaues
+ *   most widgets will redo all their font stuff when their style
+ *   change.
+ **/
+void
+_gtk_rc_reset_styles (GtkSettings *settings)
+{
+  GtkRcContext *context;
+  gboolean reset = FALSE;
+
+  g_return_if_fail (GTK_IS_SETTINGS (settings));
+
+  context = gtk_rc_context_get (settings);
+  
+  if (context->default_style)
+    {
+      g_object_unref (G_OBJECT (context->default_style));
+      context->default_style = NULL;
+      reset = TRUE;
+    }
+  
+  /* Clear out styles that have been looked up already
+   */
+  if (realized_style_ht)
+    {
+      g_hash_table_foreach (realized_style_ht, gtk_rc_clear_realized_style, NULL);
+      g_hash_table_destroy (realized_style_ht);
+      realized_style_ht = NULL;
+      reset = TRUE;
+    }
+  
+  if (reset)
+    gtk_rc_reset_widgets (settings);
+}
+
+const gchar*
+_gtk_rc_context_get_default_font_name (GtkSettings *settings)
+{
+  GtkRcContext *context;
+  gchar *new_font_name;
+  
+  g_return_val_if_fail (GTK_IS_SETTINGS (settings), NULL);
+
+  context = gtk_rc_context_get (settings);
+
+  g_object_get (context->settings,
+                "gtk-font-name", &new_font_name,
+                NULL);
+
+  if (new_font_name != context->font_name && !(new_font_name && strcmp (context->font_name, new_font_name) == 0))
     {
-      gtk_widget_reset_rc_styles (list->data);
-      gtk_widget_unref (list->data);
+       g_free (context->font_name);
+       context->font_name = g_strdup (new_font_name);
+       _gtk_rc_reset_styles (settings);
     }
-  g_list_free (toplevels);
+          
+  g_free (new_font_name);
+
+  return context->font_name;
 }
 
 /**
@@ -1350,7 +1409,7 @@ gtk_rc_reset_widgets (GtkRcContext *context)
  * @force_load: load whether or not anything changed
  * 
  * If the modification time on any previously read file
- * for the given GtkSettings has changed, discard all style information
+ * for the given #GtkSettings has changed, discard all style information
  * and then reread all previously read RC files.
  * 
  * Return value: %TRUE if the files were reread.
@@ -1379,12 +1438,15 @@ gtk_rc_reparse_all_for_settings (GtkSettings *settings,
       while (tmp_list)
        {
          rc_file = tmp_list->data;
-         
-         if (!lstat (rc_file->name, &statbuf) && 
-             (statbuf.st_mtime > rc_file->mtime))
+
+         if (!rc_file->is_string)
            {
-             mtime_modified = TRUE;
-             break;
+             if (!lstat (rc_file->name, &statbuf) && 
+                 (statbuf.st_mtime > rc_file->mtime))
+               {
+                 mtime_modified = TRUE;
+                 break;
+               }
            }
          
          tmp_list = tmp_list->next;
@@ -1393,35 +1455,45 @@ gtk_rc_reparse_all_for_settings (GtkSettings *settings,
       
   if (force_load || mtime_modified)
     {
-      GSList *old_files;
-      
+      _gtk_binding_reset_parsed ();
       gtk_rc_clear_styles (context);
       g_object_freeze_notify (G_OBJECT (context->settings));
 
-      old_files = context->rc_files;
-      context->rc_files = NULL;
-
-      gtk_rc_parse_default_files (context);
-
-      tmp_list = old_files;
+      _gtk_settings_reset_rc_values (context->settings);
+      tmp_list = context->rc_files;
       while (tmp_list)
        {
          rc_file = tmp_list->data;
-         if (rc_file->reload)
-           gtk_rc_parse_file (context, rc_file->name, GTK_PATH_PRIO_RC, TRUE);
 
          if (rc_file->canonical_name != rc_file->name)
            g_free (rc_file->canonical_name);
          g_free (rc_file->name);
          g_free (rc_file);
-         
+
          tmp_list = tmp_list->next;
        }
 
-      g_slist_free (old_files);;
+      g_slist_free (context->rc_files);
+      context->rc_files = NULL;
+
+      gtk_rc_parse_default_files (context);
+
+      tmp_list = global_rc_files;
+      while (tmp_list)
+       {
+         rc_file = tmp_list->data;
+
+         if (rc_file->is_string)
+           gtk_rc_context_parse_string (context, rc_file->name);
+         else
+           gtk_rc_context_parse_file (context, rc_file->name, GTK_PATH_PRIO_RC, FALSE);
+
+         tmp_list = tmp_list->next;
+       }
 
       g_free (context->theme_name);
       g_free (context->key_theme_name);
+
       g_object_get (context->settings,
                    "gtk-theme-name", &context->theme_name,
                    "gtk-key-theme-name", &context->key_theme_name,
@@ -1434,10 +1506,10 @@ gtk_rc_reparse_all_for_settings (GtkSettings *settings,
       
       g_object_thaw_notify (G_OBJECT (context->settings));
 
-      gtk_rc_reset_widgets (context);
+      gtk_rc_reset_widgets (context->settings);
     }
 
-  return mtime_modified;
+  return force_load || mtime_modified;
 }
 
 /**
@@ -1452,7 +1524,17 @@ gtk_rc_reparse_all_for_settings (GtkSettings *settings,
 gboolean
 gtk_rc_reparse_all (void)
 {
-  return gtk_rc_reparse_all_for_settings (gtk_settings_get_default (), FALSE);
+  GSList *tmp_list;
+  gboolean result = FALSE;
+
+  for (tmp_list = rc_contexts; tmp_list; tmp_list = tmp_list->next)
+    {
+      GtkRcContext *context = tmp_list->data;
+      if (gtk_rc_reparse_all_for_settings (context->settings, FALSE))
+       result = TRUE;
+    }
+
+  return result;
 }
 
 static GSList *
@@ -1471,12 +1553,54 @@ gtk_rc_styles_match (GSList       *rc_styles,
       sets = sets->next;
 
       if (g_pattern_match (rc_set->pspec, path_length, path, path_reversed))
-       rc_styles = g_slist_append (rc_styles, rc_set->rc_style);
+       rc_styles = g_slist_append (rc_styles, rc_set);
     }
   
   return rc_styles;
 }
 
+static gint
+rc_set_compare (gconstpointer a, gconstpointer b)
+{
+  const GtkRcSet *set_a = a;
+  const GtkRcSet *set_b = b;
+
+  return (set_a->priority < set_b->priority) ? 1 : (set_a->priority == set_b->priority ? 0 : -1);
+}
+
+static GSList *
+sort_and_dereference_sets (GSList *styles)
+{
+  GSList *tmp_list;
+  
+  /* At this point, the list of sets is ordered by:
+   *
+   * a) 'widget' patterns are earlier than 'widget_class' patterns
+   *    which are ealier than 'class' patterns.
+   * a) For two matches for class patterns, a match to a child type
+   *    is before a match to a parent type
+   * c) a match later in the RC file (or in a later RC file) is before a
+   *    match earlier in the RC file.
+   *
+   * With a) taking precedence over b) which takes precendence over c).
+   *
+   * Now sort by priority, which has the highest precendence for sort order
+   */
+  styles = g_slist_sort (styles, rc_set_compare);
+
+  /* Make styles->data = styles->data->rc_style
+   */
+  tmp_list = styles;
+  while (tmp_list)
+    {
+      GtkRcSet *set = tmp_list->data;
+      tmp_list->data = set->rc_style;
+      tmp_list = tmp_list->next;
+    }
+
+  return styles;
+}
+
 /**
  * gtk_rc_get_style:
  * @widget: a #GtkWidget
@@ -1511,12 +1635,6 @@ gtk_rc_get_style (GtkWidget *widget)
   if (!rc_style_key_id)
     rc_style_key_id = g_quark_from_static_string ("gtk-rc-style");
 
-  widget_rc_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
-                                              rc_style_key_id);
-
-  if (widget_rc_style)
-    rc_styles = g_slist_prepend (rc_styles, widget_rc_style);
-  
   if (context->rc_sets_widget)
     {
       gchar *path, *path_reversed;
@@ -1541,16 +1659,16 @@ gtk_rc_get_style (GtkWidget *widget)
 
   if (context->rc_sets_class)
     {
-      GtkType type;
+      GType type;
 
-      type = GTK_OBJECT_TYPE (widget);
+      type = G_TYPE_FROM_INSTANCE (widget);
       while (type)
        {
          const gchar *path;
           gchar *path_reversed;
          guint path_length;
 
-         path = gtk_type_name (type);
+         path = g_type_name (type);
          path_length = strlen (path);
          path_reversed = g_strdup (path);
          g_strreverse (path_reversed);
@@ -1558,23 +1676,40 @@ gtk_rc_get_style (GtkWidget *widget)
          rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
          g_free (path_reversed);
       
-         type = gtk_type_parent (type);
+         type = g_type_parent (type);
        }
     }
   
+  rc_styles = sort_and_dereference_sets (rc_styles);
+  
+  widget_rc_style = g_object_get_qdata (G_OBJECT (widget), rc_style_key_id);
+
+  if (widget_rc_style)
+    rc_styles = g_slist_prepend (rc_styles, widget_rc_style);
+
   if (rc_styles)
-    return gtk_rc_init_style (rc_styles);
+    return gtk_rc_init_style (context, rc_styles);
+  else
+    {
+      if (!context->default_style)
+       {
+         context->default_style = gtk_style_new ();
+         _gtk_style_init_for_settings (context->default_style, context->settings);
+       }
 
-  return NULL;
+      return context->default_style;
+    }
 }
 
 /**
  * gtk_rc_get_style_by_paths:
  * @settings: a #GtkSettings object
  * @widget_path: the widget path to use when looking up the style, or %NULL
+ *               if no matching against the widget path should be done
  * @class_path: the class path to use when looking up the style, or %NULL
+ *               if no matching against the class path should be done.
  * @type: a type that will be used along with parent types of this type
- *        when matching against class styles, or G_TYPE_NONE
+ *        when matching against class styles, or #G_TYPE_NONE
  * 
  * Creates up a #GtkStyle from styles defined in a RC file by providing
  * the raw components used in matching. This function may be useful
@@ -1583,14 +1718,15 @@ gtk_rc_get_style (GtkWidget *widget)
  * would be items inside a GNOME canvas widget.
  *
  * The action of gtk_rc_get_style() is similar to:
- *
- *  gtk_widget_path (widget, NULL, &path, NULL);
- *  gtk_widget_class_path (widget, NULL, &class_path, NULL);
+ * <informalexample><programlisting>
+ *  gtk_widget_path (widget, NULL, &amp;path, NULL);
+ *  gtk_widget_class_path (widget, NULL, &amp;class_path, NULL);
  *  gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget), path, class_path,
  *                             G_OBJECT_TYPE (widget));
+ * </programlisting></informalexample>
  * 
  * Return value: A style created by matching with the supplied paths,
- *   or %NULL if nothign matching was specified and the  default style should
+ *   or %NULL if nothing matching was specified and the default style should
  *   be used. The returned value is owned by GTK+ as part of an internal cache,
  *   so you must call g_object_ref() on the returned value if you want to
  *   keep a reference to it.
@@ -1612,7 +1748,7 @@ gtk_rc_get_style_by_paths (GtkSettings *settings,
 
   context = gtk_rc_context_get (settings);
 
-  if (context->rc_sets_widget)
+  if (widget_path && context->rc_sets_widget)
     {
       gchar *path_reversed;
       guint path_length;
@@ -1625,7 +1761,7 @@ gtk_rc_get_style_by_paths (GtkSettings *settings,
       g_free (path_reversed);
     }
   
-  if (context->rc_sets_widget_class)
+  if (class_path && context->rc_sets_widget_class)
     {
       gchar *path_reversed;
       guint path_length;
@@ -1657,9 +1793,11 @@ gtk_rc_get_style_by_paths (GtkSettings *settings,
          type = g_type_parent (type);
        }
     }
+  rc_styles = sort_and_dereference_sets (rc_styles);
   
   if (rc_styles)
-    return gtk_rc_init_style (rc_styles);
+    return gtk_rc_init_style (context, rc_styles);
 
   return NULL;
 }
@@ -1764,7 +1902,7 @@ gtk_rc_parse_any (GtkRcContext *context,
   scanner->input_name = input_name;
 
   for (i = 0; i < G_N_ELEMENTS (symbols); i++)
-    g_scanner_add_symbol (scanner, symbols[i].name, GINT_TO_POINTER (symbols[i].token));
+    g_scanner_scope_add_symbol (scanner, 0, symbols[i].name, GINT_TO_POINTER (symbols[i].token));
   
   done = FALSE;
   while (!done)
@@ -1787,7 +1925,7 @@ gtk_rc_parse_any (GtkRcContext *context,
              if (scanner->scope_id == 0)
                {
                  /* if we are in scope 0, we know the symbol names
-                  * that are associated with certaintoken values.
+                  * that are associated with certain token values.
                   * so we look them up to make the error messages
                   * more readable.
                   */
@@ -1885,11 +2023,13 @@ gtk_rc_style_find (GtkRcContext *context,
 }
 
 static GtkStyle *
-gtk_rc_style_to_style (GtkRcStyle *rc_style)
+gtk_rc_style_to_style (GtkRcContext *context,
+                      GtkRcStyle   *rc_style)
 {
   GtkStyle *style;
 
   style = GTK_RC_STYLE_GET_CLASS (rc_style)->create_style (rc_style);
+  _gtk_style_init_for_settings (style, context->settings);
 
   style->rc_style = rc_style;
 
@@ -1902,7 +2042,8 @@ gtk_rc_style_to_style (GtkRcStyle *rc_style)
 
 /* Reuses or frees rc_styles */
 static GtkStyle *
-gtk_rc_init_style (GSList *rc_styles)
+gtk_rc_init_style (GtkRcContext *context,
+                  GSList       *rc_styles)
 {
   GtkStyle *style = NULL;
   gint i;
@@ -1923,9 +2064,10 @@ gtk_rc_init_style (GSList *rc_styles)
       GSList *tmp_styles;
       GType rc_style_type = GTK_TYPE_RC_STYLE;
 
-      /* Find the first derived style in the list, and use that to
-       * create the merged style. If we only have raw GtkRcStyles, use
-       * the first style to create the merged style.
+      /* Find the the first style where the RC file specified engine "" {}
+       * or the first derived style and use that to create the
+       * merged style. If we only have raw GtkRcStyles, use the first
+       * style to create the merged style.
        */
       base_style = rc_styles->data;
       tmp_styles = rc_styles;
@@ -1933,7 +2075,8 @@ gtk_rc_init_style (GSList *rc_styles)
        {
          GtkRcStyle *rc_style = tmp_styles->data;
           
-         if (G_OBJECT_TYPE (rc_style) != rc_style_type)
+         if (rc_style->engine_specified ||
+             G_OBJECT_TYPE (rc_style) != rc_style_type)
            {
              base_style = rc_style;
              break;
@@ -1965,7 +2108,7 @@ gtk_rc_init_style (GSList *rc_styles)
               iter = factories;
               while (iter != NULL)
                 {
-                  g_object_ref (G_OBJECT (iter->data));
+                  g_object_ref (iter->data);
                   iter = g_slist_next (iter);
                 }
 
@@ -1985,7 +2128,7 @@ gtk_rc_init_style (GSList *rc_styles)
            proto_style->bg_pixmap_name[i] = NULL;
          }
 
-      style = gtk_rc_style_to_style (proto_style);
+      style = gtk_rc_style_to_style (context, proto_style);
       gtk_rc_style_unref (proto_style);
 
       g_hash_table_insert (realized_style_ht, rc_styles, style);
@@ -2017,10 +2160,10 @@ rc_parse_token_or_compound (GScanner  *scanner,
     {
       gchar *string;
     case G_TOKEN_INT:
-      g_string_printfa (gstring, " 0x%lx", scanner->value.v_int);
+      g_string_append_printf (gstring, " 0x%lx", scanner->value.v_int);
       break;
     case G_TOKEN_FLOAT:
-      g_string_printfa (gstring, " %f", scanner->value.v_float);
+      g_string_append_printf (gstring, " %f", scanner->value.v_float);
       break;
     case G_TOKEN_STRING:
       string = g_strescape (scanner->value.v_string, NULL);
@@ -2184,6 +2327,58 @@ is_c_identifier (const gchar *string)
   return is_varname;
 }
 
+static void
+parse_include_file (GtkRcContext *context,
+                   GScanner     *scanner,
+                   const gchar  *filename)
+{
+  char *to_parse = NULL;
+  
+  if (g_path_is_absolute (filename))
+    {
+      /* For abolute paths, we call gtk_rc_context_parse_file unconditionally. We
+       * don't print an error in this case.
+       */
+      to_parse = g_strdup (filename);
+    }
+  else
+    {
+      /* if a relative path, we look relative to all the RC files in the
+       * include stack. We require the file to be found in this case
+       * so we can give meaningful error messages, and because on reparsing
+       * non-absolute paths don't make sense.
+       */
+      GSList *tmp_list = rc_dir_stack;
+      while (tmp_list)
+       {
+         gchar *tmpname = g_build_filename (tmp_list->data, filename, NULL);
+
+         if (g_file_test (tmpname, G_FILE_TEST_EXISTS))
+           {
+             to_parse = tmpname;
+             break;
+           }
+
+         g_free (tmpname);
+         
+         tmp_list = tmp_list->next;
+       }
+    }
+
+  if (to_parse)
+    {
+      gtk_rc_context_parse_file (context, to_parse, context->default_priority, FALSE);
+      g_free (to_parse);
+    }
+  else
+    {
+      g_scanner_warn (scanner, 
+                     _("Unable to find include file: \"%s\""),
+                     filename);
+    }
+
+}
+
 static guint
 gtk_rc_parse_statement (GtkRcContext *context,
                        GScanner     *scanner)
@@ -2200,7 +2395,7 @@ gtk_rc_parse_statement (GtkRcContext *context,
       token = g_scanner_get_next_token (scanner);
       if (token != G_TOKEN_STRING)
        return G_TOKEN_STRING;
-      gtk_rc_parse_file (context, scanner->value.v_string, context->default_priority, FALSE);
+      parse_include_file (context, scanner, scanner->value.v_string);
       return G_TOKEN_NONE;
       
     case GTK_RC_TOKEN_STYLE:
@@ -2224,9 +2419,6 @@ gtk_rc_parse_statement (GtkRcContext *context,
     case GTK_RC_TOKEN_MODULE_PATH:
       return gtk_rc_parse_module_path (scanner);
       
-    case GTK_RC_TOKEN_IM_MODULE_PATH:
-      return gtk_rc_parse_im_module_path (scanner);
-      
     case GTK_RC_TOKEN_IM_MODULE_FILE:
       return gtk_rc_parse_im_module_file (scanner);
 
@@ -2247,9 +2439,9 @@ gtk_rc_parse_statement (GtkRcContext *context,
              svalue.origin = prop.origin;
              memcpy (&svalue.value, &prop.value, sizeof (prop.value));
              g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
-             gtk_settings_set_property_value (context->settings,
-                                              name,
-                                              &svalue);
+             _gtk_settings_set_property_value_from_rc (context->settings,
+                                                       name,
+                                                       &svalue);
            }
          g_free (prop.origin);
          if (G_VALUE_TYPE (&prop.value))
@@ -2269,14 +2461,38 @@ gtk_rc_parse_statement (GtkRcContext *context,
     }
 }
 
+static void
+fixup_rc_set (GSList     *list,
+             GtkRcStyle *orig,
+             GtkRcStyle *new)
+{
+  while (list)
+    {
+      GtkRcSet *set = list->data;
+      if (set->rc_style == orig)
+       set->rc_style = new;
+      list = list->next;
+    }
+}
+
+static void
+fixup_rc_sets (GtkRcContext *context,
+              GtkRcStyle   *orig,
+              GtkRcStyle   *new)
+{
+  fixup_rc_set (context->rc_sets_widget, orig, new);
+  fixup_rc_set (context->rc_sets_widget_class, orig, new);
+  fixup_rc_set (context->rc_sets_class, orig, new);
+}
+
 static guint
 gtk_rc_parse_style (GtkRcContext *context,
                    GScanner     *scanner)
 {
   GtkRcStyle *rc_style;
+  GtkRcStyle *orig_style;
   GtkRcStyle *parent_style;
   guint token;
-  gint insert;
   gint i;
   GtkIconFactory *our_factory = NULL;
   
@@ -2288,8 +2504,11 @@ gtk_rc_parse_style (GtkRcContext *context,
   if (token != G_TOKEN_STRING)
     return G_TOKEN_STRING;
   
-  insert = FALSE;
   rc_style = gtk_rc_style_find (context, scanner->value.v_string);
+  if (rc_style)
+    orig_style = g_object_ref (rc_style);
+  else
+    orig_style = NULL;
 
   /* If there's a list, its first member is always the factory belonging
    * to this RcStyle
@@ -2299,7 +2518,6 @@ gtk_rc_parse_style (GtkRcContext *context,
   
   if (!rc_style)
     {
-      insert = TRUE;
       rc_style = gtk_rc_style_new ();
       rc_style->name = g_strdup (scanner->value.v_string);
       
@@ -2318,10 +2536,8 @@ gtk_rc_parse_style (GtkRcContext *context,
       token = g_scanner_get_next_token (scanner);
       if (token != G_TOKEN_STRING)
        {
-         if (insert)
-           g_free (rc_style);
-
-         return G_TOKEN_STRING;
+         token = G_TOKEN_STRING;
+         goto err;
        }
       
       parent_style = gtk_rc_style_find (context, scanner->value.v_string);
@@ -2389,7 +2605,7 @@ gtk_rc_parse_style (GtkRcContext *context,
               factories = parent_style->icon_factories;
               while (factories != NULL)
                 {
-                  g_object_ref (G_OBJECT (factories->data));
+                  g_object_ref (factories->data);
                   factories = factories->next;
                 }
             }
@@ -2399,10 +2615,8 @@ gtk_rc_parse_style (GtkRcContext *context,
   token = g_scanner_get_next_token (scanner);
   if (token != G_TOKEN_LEFT_CURLY)
     {
-      if (insert)
-       g_free (rc_style);
-
-      return G_TOKEN_LEFT_CURLY;
+      token = G_TOKEN_LEFT_CURLY;
+      goto err;
     }
   
   token = g_scanner_peek_next_token (scanner);
@@ -2502,42 +2716,46 @@ gtk_rc_parse_style (GtkRcContext *context,
        }
 
       if (token != G_TOKEN_NONE)
-       {
-         if (insert)
-           gtk_rc_style_unref (rc_style);
+       goto err;
 
-         return token;
-       }
       token = g_scanner_peek_next_token (scanner);
     } /* while (token != G_TOKEN_RIGHT_CURLY) */
   
   token = g_scanner_get_next_token (scanner);
   if (token != G_TOKEN_RIGHT_CURLY)
     {
-      if (insert)
-       {
-         if (rc_style->font_desc)
-           pango_font_description_free (rc_style->font_desc);
-         
-         for (i = 0; i < 5; i++)
-           if (rc_style->bg_pixmap_name[i])
-             g_free (rc_style->bg_pixmap_name[i]);
-         
-         g_free (rc_style);
-       }
-      return G_TOKEN_RIGHT_CURLY;
+      token = G_TOKEN_RIGHT_CURLY;
+      goto err;
     }
   
-  if (insert)
+  if (rc_style != orig_style)
     {
       if (!context->rc_style_ht)
        context->rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
                                                 (GEqualFunc) gtk_rc_style_equal);
       
-      g_hash_table_insert (context->rc_style_ht, rc_style->name, rc_style);
+      g_hash_table_replace (context->rc_style_ht, rc_style->name, rc_style);
+
+      /* If we copied the data into a new rc style, fix up references to the old rc style
+       * in bindings that we have.
+       */
+      if (orig_style)
+       fixup_rc_sets (context, orig_style, rc_style);
     }
+
+  if (orig_style)
+    g_object_unref (orig_style);
   
   return G_TOKEN_NONE;
+
+ err:
+  if (rc_style != orig_style)
+    gtk_rc_style_unref (rc_style);
+
+  if (orig_style)
+    g_object_unref (orig_style);
+  
+  return token;
 }
 
 const GtkRcProperty*
@@ -2740,7 +2958,7 @@ gtk_rc_check_pixmap_dir (const gchar *dir, const gchar *pixmap_file)
   gchar *buf;
   gint fd;
 
-  buf = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s", dir, pixmap_file);
+  buf = g_build_filename (dir, pixmap_file, NULL);
   
   fd = open (buf, O_RDONLY);
   if (fd >= 0)
@@ -2755,8 +2973,8 @@ gtk_rc_check_pixmap_dir (const gchar *dir, const gchar *pixmap_file)
  }
 
 /**
- * gtk_rc_context_find_pixmap_in_path:
- * @settings: a #GtkSettinsg
+ * gtk_rc_find_pixmap_in_path:
+ * @settings: a #GtkSettings
  * @scanner: Scanner used to get line number information for the
  *   warning message, or %NULL
  * @pixmap_file: name of the pixmap file to locate.
@@ -2765,7 +2983,7 @@ gtk_rc_check_pixmap_dir (const gchar *dir, const gchar *pixmap_file)
  * If the file is not found, it outputs a warning message using
  * g_warning() and returns %NULL.
  *
- * Return value: 
+ * Return value: the filename. 
  **/
 gchar*
 gtk_rc_find_pixmap_in_path (GtkSettings  *settings,
@@ -2796,8 +3014,9 @@ gtk_rc_find_pixmap_in_path (GtkSettings  *settings,
     }
   
   if (scanner)
-    g_warning (_("Unable to locate image file in pixmap_path: \"%s\" line %d"),
-              pixmap_file, scanner->line);
+    g_scanner_warn (scanner, 
+                    _("Unable to locate image file in pixmap_path: \"%s\""),
+                    pixmap_file);
   else
     g_warning (_("Unable to locate image file in pixmap_path: \"%s\""),
               pixmap_file);
@@ -2805,29 +3024,20 @@ gtk_rc_find_pixmap_in_path (GtkSettings  *settings,
   return NULL;
 }
 
+/**
+ * gtk_rc_find_module_in_path:
+ * @module_file: name of a theme engine
+ * 
+ * Searches for a theme engine in the GTK+ search path. This function
+ * is not useful for applications and should not be used.
+ * 
+ * Return value: The filename, if found (must be freed with g_free()),
+ *   otherwise %NULL.
+ **/
 gchar*
 gtk_rc_find_module_in_path (const gchar *module_file)
 {
-  gint i;
-  gint fd;
-  gchar *buf;
-  
-  for (i = 0; (i < GTK_RC_MAX_MODULE_PATHS) && (module_path[i] != NULL); i++)
-    {
-      buf = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s",
-                            module_path[i], module_file);
-      
-      fd = open (buf, O_RDONLY);
-      if (fd >= 0)
-       {
-         close (fd);
-         return buf;
-       }
-      
-      g_free (buf);
-    }
-    
-  return NULL;
+  return _gtk_find_module (module_file, "engines");
 }
 
 static guint
@@ -2894,7 +3104,11 @@ gtk_rc_parse_font_name (GScanner   *scanner,
   if (token != G_TOKEN_STRING)
     return G_TOKEN_STRING;
 
-  rc_style->font_desc = pango_font_description_from_string (scanner->value.v_string);
+  if (rc_style->font_desc)
+    pango_font_description_free (rc_style->font_desc);
+
+  rc_style->font_desc = 
+    pango_font_description_from_string (scanner->value.v_string);
   
   return G_TOKEN_NONE;
 }
@@ -2918,34 +3132,62 @@ gtk_rc_parse_engine (GtkRcContext *context,
   if (token != G_TOKEN_STRING)
     return G_TOKEN_STRING;
 
-  engine = gtk_theme_engine_get (scanner->value.v_string);
-  
-  token = g_scanner_get_next_token (scanner);
-  if (token != G_TOKEN_LEFT_CURLY)
-    return G_TOKEN_LEFT_CURLY;
-
-  if (engine)
+  if (!scanner->value.v_string[0])
     {
-      GtkRcStyleClass *new_class;
+      /* Support engine "" {} to mean override to the default engine
+       */
+      token = g_scanner_get_next_token (scanner);
+      if (token != G_TOKEN_LEFT_CURLY)
+       return G_TOKEN_LEFT_CURLY;
       
-      new_style = gtk_theme_engine_create_rc_style (engine);
-      g_type_module_unuse (G_TYPE_MODULE (engine));
+      token = g_scanner_get_next_token (scanner);
+      if (token != G_TOKEN_RIGHT_CURLY)
+       return G_TOKEN_RIGHT_CURLY;
 
-      new_class = GTK_RC_STYLE_GET_CLASS (new_style);
+      parsed_curlies = TRUE;
 
-      new_class->merge (new_style, *rc_style);
-      if ((*rc_style)->name)
-       new_style->name = g_strdup ((*rc_style)->name);
+      if (G_OBJECT_TYPE (*rc_style) != GTK_TYPE_RC_STYLE)
+       {
+         new_style = gtk_rc_style_new ();
+         gtk_rc_style_real_merge (new_style, *rc_style);
+         
+         if ((*rc_style)->name)
+           new_style->name = g_strdup ((*rc_style)->name);
+       }
+      else
+       (*rc_style)->engine_specified = TRUE;
+    }
+  else
+    {
+      engine = gtk_theme_engine_get (scanner->value.v_string);
       
-      if (new_class->parse)
+      token = g_scanner_get_next_token (scanner);
+      if (token != G_TOKEN_LEFT_CURLY)
+       return G_TOKEN_LEFT_CURLY;
+      
+      if (engine)
        {
-         parsed_curlies = TRUE;
-         result = new_class->parse (new_style, context->settings, scanner);
-
-         if (result != G_TOKEN_NONE)
+         GtkRcStyleClass *new_class;
+         
+         new_style = gtk_theme_engine_create_rc_style (engine);
+         g_type_module_unuse (G_TYPE_MODULE (engine));
+         
+         new_class = GTK_RC_STYLE_GET_CLASS (new_style);
+         
+         new_class->merge (new_style, *rc_style);
+         if ((*rc_style)->name)
+           new_style->name = g_strdup ((*rc_style)->name);
+         
+         if (new_class->parse)
            {
-             g_object_unref (G_OBJECT (new_style));
-             new_style = NULL;
+             parsed_curlies = TRUE;
+             result = new_class->parse (new_style, context->settings, scanner);
+             
+             if (result != G_TOKEN_NONE)
+               {
+                 g_object_unref (new_style);
+                 new_style = NULL;
+               }
            }
        }
     }
@@ -2974,7 +3216,9 @@ gtk_rc_parse_engine (GtkRcContext *context,
 
   if (new_style)
     {
-      g_object_unref (G_OBJECT (*rc_style));
+      new_style->engine_specified = TRUE;
+
+      g_object_unref (*rc_style);
       *rc_style = new_style;
     }
 
@@ -3228,32 +3472,11 @@ gtk_rc_parse_module_path (GScanner *scanner)
   if (token != GTK_RC_TOKEN_MODULE_PATH)
     return GTK_RC_TOKEN_MODULE_PATH;
   
-  token = g_scanner_get_next_token (scanner);
-  if (token != G_TOKEN_STRING)
-    return G_TOKEN_STRING;
-  
-  gtk_rc_parse_module_path_string (scanner->value.v_string);
-  
-  return G_TOKEN_NONE;
-}
-
-static guint
-gtk_rc_parse_im_module_path (GScanner *scanner)
-{
-  guint token;
-  
-  token = g_scanner_get_next_token (scanner);
-  if (token != GTK_RC_TOKEN_IM_MODULE_FILE)
-    return GTK_RC_TOKEN_IM_MODULE_FILE;
-  
   token = g_scanner_get_next_token (scanner);
   if (token != G_TOKEN_STRING)
     return G_TOKEN_STRING;
 
-  if (im_module_path)
-    g_free (im_module_path);
-    
-  im_module_path = g_strdup (scanner->value.v_string);
+  g_warning ("module_path directive is now ignored\n");
 
   return G_TOKEN_NONE;
 }
@@ -3279,54 +3502,6 @@ gtk_rc_parse_im_module_file (GScanner *scanner)
   return G_TOKEN_NONE;
 }
 
-static void
-gtk_rc_parse_module_path_string (const gchar *mod_path)
-{
-  gint end_offset;
-  gint start_offset = 0;
-  gint path_len;
-  gint path_num;
-  
-  /* free the old one, or just add to the old one ? */
-  for (path_num=0; module_path[path_num]; path_num++)
-    {
-      g_free (module_path[path_num]);
-      module_path[path_num] = NULL;
-    }
-  
-  path_num = 0;
-  
-  path_len = strlen (mod_path);
-  
-  for (end_offset = 0; end_offset <= path_len; end_offset++)
-    {
-      if ((mod_path[end_offset] == G_SEARCHPATH_SEPARATOR) ||
-         (end_offset == path_len))
-       {
-         module_path[path_num] = g_strndup (mod_path + start_offset, end_offset - start_offset);
-         path_num++;
-         module_path[path_num] = NULL;
-         start_offset = end_offset + 1;
-       }
-    }
-  gtk_rc_append_default_module_path();
-}
-
-static gint
-rc_set_compare (gconstpointer a, gconstpointer b)
-{
-  const GtkRcSet *set_a = a;
-  const GtkRcSet *set_b = b;
-
-  return (set_a->priority < set_b->priority) ? 1 : (set_a->priority == set_b->priority ? 0 : -1);
-}
-
-static GSList *
-insert_rc_set (GSList *list, GtkRcSet *set)
-{
-  return g_slist_insert_sorted (list, set, rc_set_compare);
-}
-
 static guint
 gtk_rc_parse_path_pattern (GtkRcContext *context,
                           GScanner     *scanner)
@@ -3418,11 +3593,11 @@ gtk_rc_parse_path_pattern (GtkRcContext *context,
       rc_set->priority = priority;
 
       if (path_type == GTK_PATH_WIDGET)
-       context->rc_sets_widget = insert_rc_set (context->rc_sets_widget, rc_set);
+       context->rc_sets_widget = g_slist_prepend (context->rc_sets_widget, rc_set);
       else if (path_type == GTK_PATH_WIDGET_CLASS)
-       context->rc_sets_widget_class = insert_rc_set (context->rc_sets_widget_class, rc_set);
+       context->rc_sets_widget_class = g_slist_prepend (context->rc_sets_widget_class, rc_set);
       else
-       context->rc_sets_class = insert_rc_set (context->rc_sets_class, rc_set);
+       context->rc_sets_class = g_slist_prepend (context->rc_sets_class, rc_set);
     }
 
   g_free (pattern);
@@ -3459,7 +3634,8 @@ gtk_rc_parse_stock_id (GScanner    *scanner,
 static guint
 gtk_rc_parse_icon_source (GtkRcContext   *context,
                          GScanner       *scanner,
-                          GtkIconSet     *icon_set)
+                          GtkIconSet     *icon_set,
+                          gboolean       *icon_set_valid)
 {
   guint token;
   GtkIconSource *source;
@@ -3485,7 +3661,8 @@ gtk_rc_parse_icon_source (GtkRcContext   *context,
     }
 
   /* We continue parsing even if we didn't find the pixmap so that rest of the
-   * file is read, even if the syntax is bad
+   * file is read, even if the syntax is bad. However we don't validate the 
+   * icon_set so the caller can choose not to install it.
    */
   token = g_scanner_get_next_token (scanner);
 
@@ -3617,7 +3794,10 @@ gtk_rc_parse_icon_source (GtkRcContext   *context,
 
  done:
   if (gtk_icon_source_get_filename (source))
-    gtk_icon_set_add_source (icon_set, source);
+    {
+      gtk_icon_set_add_source (icon_set, source);
+      *icon_set_valid = TRUE;
+    }
   gtk_icon_source_free (source);
   
   return G_TOKEN_NONE;
@@ -3630,6 +3810,7 @@ gtk_rc_parse_stock (GtkRcContext   *context,
                     GtkIconFactory *factory)
 {
   GtkIconSet *icon_set = NULL;
+  gboolean icon_set_valid = FALSE;
   gchar *stock_id = NULL;
   guint token;
   
@@ -3661,7 +3842,8 @@ gtk_rc_parse_stock (GtkRcContext   *context,
       if (icon_set == NULL)
         icon_set = gtk_icon_set_new ();
       
-      token = gtk_rc_parse_icon_source (context, scanner, icon_set);
+      token = gtk_rc_parse_icon_source (context, 
+                                        scanner, icon_set, &icon_set_valid);
       if (token != G_TOKEN_NONE)
         {
           g_free (stock_id);
@@ -3682,10 +3864,11 @@ gtk_rc_parse_stock (GtkRcContext   *context,
 
   if (icon_set)
     {
-      gtk_icon_factory_add (factory,
-                            stock_id,
-                            icon_set);
-      
+      if (icon_set_valid)
+        gtk_icon_factory_add (factory,
+                              stock_id,
+                              icon_set);
+
       gtk_icon_set_unref (icon_set);
     }