]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkrc.c
Don't use zip -r on the etc directory, to avoid including editor backup
[~andy/gtk] / gtk / gtkrc.c
index 7f400b765da271293adc536ad600260fc4b96732..1c488973446c93db8dcef72314ff7fb51e77a236 100644 (file)
@@ -78,6 +78,7 @@ struct _GtkRcFile
   time_t mtime;
   gchar *name;
   gchar *canonical_name;
+  gchar *directory;
   guint reload;
 };
 
@@ -119,13 +120,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);
@@ -284,10 +287,19 @@ static gchar *im_module_file = NULL;
 #define GTK_RC_MAX_DEFAULT_FILES 128
 static gchar *gtk_rc_default_files[GTK_RC_MAX_DEFAULT_FILES];
 
-/* A stack of directories for RC files we are parsing currently.
- * these are implicitely added to the end of PIXMAP_PATHS
+/* A stack of information of RC files we are parsing currently.
+ * The directories for these files are implicitely added to the end of
+ * PIXMAP_PATHS.
  */
-static GSList *rc_dir_stack = NULL;
+static GSList *current_files_stack = NULL;
+
+/* RC files and strings that are parsed for every context
+ */
+static GSList *global_rc_files = NULL;
+
+/* Keep list of all current RC contexts for convenience
+ */
+static GSList *rc_contexts;
 
 /* RC file handling */
 
@@ -299,9 +311,9 @@ gtk_rc_make_default_dir (const gchar *type)
 
   var = g_getenv ("GTK_EXE_PREFIX");
   if (var)
-    path = g_build_filename (var, "lib", "gtk-2.0", type, GTK_BINARY_VERSION, NULL);
+    path = g_build_filename (var, "lib", "gtk-2.0", GTK_BINARY_VERSION, type, NULL);
   else
-    path = g_build_filename (GTK_LIBDIR, "gtk-2.0", type, GTK_BINARY_VERSION, NULL);
+    path = g_build_filename (GTK_LIBDIR, "gtk-2.0", GTK_BINARY_VERSION, type, NULL);
 
   return path;
 }
@@ -367,6 +379,16 @@ gtk_rc_get_theme_dir (void)
   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)
 {
@@ -388,7 +410,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);
@@ -560,6 +582,8 @@ gtk_rc_context_get (GtkSettings *settings)
       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;
@@ -609,7 +633,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);
     }
 
@@ -622,7 +646,7 @@ gtk_rc_parse_default_files (GtkRcContext *context)
   gint i;
 
   for (i = 0; gtk_rc_default_files[i] != NULL; i++)
-    gtk_rc_parse_file (context, gtk_rc_default_files[i], GTK_PATH_PRIO_RC, FALSE);
+    gtk_rc_context_parse_file (context, gtk_rc_default_files[i], GTK_PATH_PRIO_RC, FALSE);
 }
 
 void
@@ -637,25 +661,49 @@ _gtk_rc_init (void)
       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] = \"#ffffc0\"\n"
+                      "  bg[NORMAL] = \"#eee1b3\"\n"
                       "  fg[NORMAL] = \"#000000\"\n"
                       "}\n"
                       "\n"
-                      "widget \"gtk-tooltips*\" style : gtk \"gtk-default-tooltips-style\"\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;
-  /* This is wrong; once we have meaningful multiple RC contexts, we need to parse the
-   * string in all contexts, and in fact, in future contexts as well.
-   */
-  GtkRcContext *context = gtk_rc_context_get (gtk_settings_get_default ());
+  GSList *tmp_list;
       
   g_return_if_fail (rc_string != NULL);
 
@@ -663,51 +711,63 @@ gtk_rc_parse_string (const gchar *rc_string)
   rc_file->is_string = TRUE;
   rc_file->name = g_strdup (rc_string);
   rc_file->canonical_name = NULL;
+  rc_file->directory = NULL;
   rc_file->mtime = 0;
   rc_file->reload = TRUE;
+  
+  global_rc_files = g_slist_append (global_rc_files, rc_file);
 
-  context->rc_files = g_slist_append (context->rc_files, rc_file);
-
-  gtk_rc_parse_any (context, "-", -1, rc_string);
+  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_one_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->is_string = FALSE;
-      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->directory = 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)
     {
@@ -723,32 +783,32 @@ gtk_rc_parse_one_file (GtkRcContext *context,
          rc_file->canonical_name = g_build_filename (cwd, rc_file->name, NULL);
          g_free (cwd);
        }
+      
+      rc_file->directory = g_path_get_dirname (rc_file->canonical_name);
     }
 
+  /* If the file is already being parsed (recursion), do nothing
+   */
+  if (g_slist_find (current_files_stack, rc_file))
+    return;
+
   if (!lstat (rc_file->canonical_name, &statbuf))
     {
       gint fd;
-      GSList *tmp_list;
-
+      
       rc_file->mtime = statbuf.st_mtime;
 
       fd = open (rc_file->canonical_name, O_RDONLY);
       if (fd < 0)
        goto out;
 
-      /* Temporarily push directory name for this file on
-       * a stack of directory names while parsing it
+      /* Temporarily push information for this file on
+       * a stack of current files while parsing it.
        */
-      rc_dir_stack = 
-       g_slist_prepend (rc_dir_stack,
-                        g_path_get_dirname (rc_file->canonical_name));
+      current_files_stack = g_slist_prepend (current_files_stack, rc_file);
       gtk_rc_parse_any (context, filename, fd, NULL);
-      tmp_list = rc_dir_stack;
-      rc_dir_stack = rc_dir_stack->next;
-      g_free (tmp_list->data);
-      g_slist_free_1 (tmp_list);
+      current_files_stack = g_slist_delete_link (current_files_stack,
+                                                current_files_stack);
 
       close (fd);
     }
@@ -772,23 +832,19 @@ strchr_len (const gchar *str, gint len, char c)
 }
 
 static void
-gtk_rc_parse_file (GtkRcContext *context,
-                  const gchar  *filename,
-                  gint          priority,
-                  gboolean      reload)
+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;
+  gchar *locale;
   gint length, j;
   gboolean found = FALSE;
 
-  #ifdef G_OS_WIN32      
-  locale = g_win32_getlocale ();
-#else      
-  locale = setlocale (LC_CTYPE, NULL);
-#endif      
+  locale = _gtk_get_lc_ctype ();
 
   if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
     {
@@ -813,8 +869,10 @@ gtk_rc_parse_file (GtkRcContext *context,
          locale_suffixes[n_locale_suffixes++] = g_strndup (locale, length);
        }
     }
+
+  g_free (locale);
   
-  gtk_rc_parse_one_file (context, filename, priority, reload);
+  gtk_rc_context_parse_one_file (context, filename, priority, reload);
   for (j = 0; j < n_locale_suffixes; j++)
     {
       if (!found)
@@ -822,7 +880,7 @@ gtk_rc_parse_file (GtkRcContext *context,
          gchar *name = g_strconcat (filename, ".", locale_suffixes[j], NULL);
          if (g_file_test (name, G_FILE_TEST_EXISTS))
            {
-             gtk_rc_parse_one_file (context, name, priority, FALSE);
+             gtk_rc_context_parse_one_file (context, name, priority, FALSE);
              found = TRUE;
            }
              
@@ -836,13 +894,14 @@ gtk_rc_parse_file (GtkRcContext *context,
 void
 gtk_rc_parse (const gchar *filename)
 {
+  GSList *tmp_list;
+  
   g_return_if_fail (filename != NULL);
 
-  /* This is wrong; once we have meaningful multiple RC contexts, we need to parse the
-   * file in all contexts, and in fact, in future contexts as well.
-   */
-  gtk_rc_parse_file (gtk_rc_context_get (gtk_settings_get_default ()),
-                    filename, GTK_PATH_PRIO_RC, TRUE);
+  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 */
@@ -850,11 +909,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,
@@ -867,12 +926,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
@@ -943,7 +1001,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
@@ -986,8 +1044,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);
@@ -1029,19 +1086,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 *
@@ -1234,10 +1291,10 @@ 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 ();
@@ -1245,8 +1302,11 @@ gtk_rc_reset_widgets (GtkRcContext *context)
   
   for (list = toplevels; list; list = list->next)
     {
-      gtk_widget_reset_rc_styles (list->data);
-      gtk_widget_unref (list->data);
+      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);
 }
@@ -1271,6 +1331,53 @@ gtk_rc_clear_realized_style (gpointer key,
   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 (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)
 {
@@ -1287,29 +1394,10 @@ _gtk_rc_context_get_default_font_name (GtkSettings *settings)
 
   if (new_font_name != context->font_name && !(new_font_name && strcmp (context->font_name, new_font_name) == 0))
     {
-      gboolean reset = FALSE;
-      g_free (context->font_name);
-      context->font_name = g_strdup (new_font_name);
-
-      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 (context);
+       g_free (context->font_name);
+       context->font_name = g_strdup (new_font_name);
+       _gtk_rc_reset_styles (settings);
     }
           
   g_free (new_font_name);
@@ -1369,38 +1457,42 @@ 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)
-           {
-             if (rc_file->is_string)
-               gtk_rc_parse_string (rc_file->name);
-             else
-               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->directory);
          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);
@@ -1417,10 +1509,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;
 }
 
 /**
@@ -1435,7 +1527,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 *
@@ -1560,16 +1662,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);
@@ -1577,24 +1679,26 @@ 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 = gtk_object_get_data_by_id (GTK_OBJECT (widget),
-                                              rc_style_key_id);
+  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 ();
+       {
+         context->default_style = gtk_style_new ();
+         _gtk_style_init_for_settings (context->default_style, context->settings);
+       }
 
       return context->default_style;
     }
@@ -1604,7 +1708,9 @@ gtk_rc_get_style (GtkWidget *widget)
  * 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
  * 
@@ -1616,10 +1722,10 @@ gtk_rc_get_style (GtkWidget *widget)
  *
  * The action of gtk_rc_get_style() is similar to:
  * <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));
+ *  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,
@@ -1645,7 +1751,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;
@@ -1658,7 +1764,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;
@@ -1694,7 +1800,7 @@ gtk_rc_get_style_by_paths (GtkSettings *settings,
   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;
 }
@@ -1920,11 +2026,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;
 
@@ -1937,7 +2045,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;
@@ -2002,7 +2111,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);
                 }
 
@@ -2022,7 +2131,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);
@@ -2177,7 +2286,7 @@ gtk_rc_parse_assignment (GScanner      *scanner,
     case G_TOKEN_LEFT_BRACE:
       if (!negate)
        {
-         GString *gstring = g_string_new ("");
+         GString *gstring = g_string_new (NULL);
 
          token = rc_parse_token_or_compound (scanner, gstring, 0);
          if (token == G_TOKEN_NONE)
@@ -2230,7 +2339,7 @@ parse_include_file (GtkRcContext *context,
   
   if (g_path_is_absolute (filename))
     {
-      /* For abolute paths, we call gtk_rc_parse_file unconditionally. We
+      /* 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);
@@ -2242,10 +2351,11 @@ parse_include_file (GtkRcContext *context,
        * so we can give meaningful error messages, and because on reparsing
        * non-absolute paths don't make sense.
        */
-      GSList *tmp_list = rc_dir_stack;
+      GSList *tmp_list = current_files_stack;
       while (tmp_list)
        {
-         gchar *tmpname = g_build_filename (tmp_list->data, filename, NULL);
+         GtkRcFile *curfile = tmp_list->data;
+         gchar *tmpname = g_build_filename (curfile->directory, filename, NULL);
 
          if (g_file_test (tmpname, G_FILE_TEST_EXISTS))
            {
@@ -2261,7 +2371,7 @@ parse_include_file (GtkRcContext *context,
 
   if (to_parse)
     {
-      gtk_rc_parse_file (context, to_parse, context->default_priority, FALSE);
+      gtk_rc_context_parse_file (context, to_parse, context->default_priority, FALSE);
       g_free (to_parse);
     }
   else
@@ -2333,9 +2443,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))
@@ -2499,7 +2609,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;
                 }
             }
@@ -2897,10 +3007,11 @@ gtk_rc_find_pixmap_in_path (GtkSettings  *settings,
        return filename;
     }
  
-  tmp_list = rc_dir_stack;
+  tmp_list = current_files_stack;
   while (tmp_list)
     {
-      filename = gtk_rc_check_pixmap_dir (tmp_list->data, pixmap_file);
+      GtkRcFile *curfile = tmp_list->data;
+      filename = gtk_rc_check_pixmap_dir (curfile->directory, pixmap_file);
       if (filename)
        return filename;
        
@@ -2998,7 +3109,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;
 }
@@ -3075,7 +3190,7 @@ gtk_rc_parse_engine (GtkRcContext *context,
              
              if (result != G_TOKEN_NONE)
                {
-                 g_object_unref (G_OBJECT (new_style));
+                 g_object_unref (new_style);
                  new_style = NULL;
                }
            }
@@ -3107,8 +3222,8 @@ gtk_rc_parse_engine (GtkRcContext *context,
   if (new_style)
     {
       new_style->engine_specified = TRUE;
-      
-      g_object_unref (G_OBJECT (*rc_style));
+
+      g_object_unref (*rc_style);
       *rc_style = new_style;
     }
 
@@ -3537,17 +3652,32 @@ gtk_rc_parse_icon_source (GtkRcContext   *context,
 
   token = g_scanner_get_next_token (scanner);
   
-  if (token != G_TOKEN_STRING)
+  if (token != G_TOKEN_STRING && token != '@')
     return G_TOKEN_STRING;
-
   
   source = gtk_icon_source_new ();
-  
-  full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
-  if (full_filename)
+
+  if (token == G_TOKEN_STRING)
+    {
+      /* Filename */
+      
+      full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
+      if (full_filename)
+       {
+         gtk_icon_source_set_filename (source, full_filename);
+         g_free (full_filename);
+       }
+    }
+  else
     {
-      gtk_icon_source_set_filename (source, full_filename);
-      g_free (full_filename);
+      /* Icon name */
+      
+      token = g_scanner_get_next_token (scanner);
+  
+      if (token != G_TOKEN_STRING)
+       return G_TOKEN_STRING;
+
+      gtk_icon_source_set_icon_name (source, scanner->value.v_string);
     }
 
   /* We continue parsing even if we didn't find the pixmap so that rest of the
@@ -3683,7 +3813,8 @@ gtk_rc_parse_icon_source (GtkRcContext   *context,
     }
 
  done:
-  if (gtk_icon_source_get_filename (source))
+  if (gtk_icon_source_get_filename (source) ||
+      gtk_icon_source_get_icon_name (source))
     {
       gtk_icon_set_add_source (icon_set, source);
       *icon_set_valid = TRUE;
@@ -3752,12 +3883,13 @@ gtk_rc_parse_stock (GtkRcContext   *context,
         }
     }
 
-  if (icon_set && icon_set_valid)
+  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);
     }