]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkrc.c
Make 3.0 parallel-installable to 2.x
[~andy/gtk] / gtk / gtkrc.c
index 41f2c7347d4a38c660141bbe8eb28bbcd9ea9618..a23a605785f46dce88629dfeb40a1c4fa1bc6613 100644 (file)
@@ -24,7 +24,7 @@
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#include <config.h>
+#include "config.h"
 
 #include <locale.h>
 #ifdef HAVE_UNISTD_H
@@ -218,9 +218,6 @@ static guint       gtk_rc_parse_stock                (GtkRcContext    *context,
 static guint       gtk_rc_parse_logical_color        (GScanner        *scanner,
                                                       GtkRcStyle      *rc_style,
                                                       GHashTable      *hash);
-static guint       gtk_rc_parse_color_full           (GScanner        *scanner,
-                                                      GtkRcStyle      *style,
-                                                      GdkColor        *color);
 
 static void        gtk_rc_clear_hash_node            (gpointer         key,
                                                       gpointer         data,
@@ -240,6 +237,10 @@ static gint           gtk_rc_properties_cmp             (gconstpointer    bsearch_node1,
                                                      gconstpointer    bsearch_node2);
 static void        gtk_rc_set_free                   (GtkRcSet        *rc_set);
 
+static void       insert_rc_property                (GtkRcStyle      *style,
+                                                     GtkRcProperty   *property,
+                                                     gboolean         replace);
+
 
 static const GScannerConfig gtk_rc_scanner_config =
 {
@@ -398,9 +399,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", GTK_BINARY_VERSION, type, NULL);
+    path = g_build_filename (var, "lib", "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
   else
-    path = g_build_filename (GTK_LIBDIR, "gtk-2.0", GTK_BINARY_VERSION, type, NULL);
+    path = g_build_filename (GTK_LIBDIR, "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
 
   return path;
 }
@@ -449,7 +450,7 @@ gtk_rc_get_im_module_file (void)
       if (im_module_file)
        result = g_strdup (im_module_file);
       else
-       result = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtk.immodules", NULL);
+       result = g_build_filename (GTK_SYSCONFDIR, "gtk-3.0", "gtk.immodules", NULL);
     }
 
   return result;
@@ -521,7 +522,7 @@ gtk_rc_add_initial_default_files (void)
   else
     {
       const gchar *home;
-      str = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtkrc", NULL);
+      str = g_build_filename (GTK_SYSCONFDIR, "gtk-3.0", "gtkrc", NULL);
 
       gtk_rc_add_default_file (str);
       g_free (str);
@@ -529,7 +530,7 @@ gtk_rc_add_initial_default_files (void)
       home = g_get_home_dir ();
       if (home)
        {
-         str = g_build_filename (home, ".gtkrc-2.0", NULL);
+         str = g_build_filename (home, ".gtkrc-3.0", NULL);
          gtk_rc_add_default_file (str);
          g_free (str);
        }
@@ -658,11 +659,15 @@ gtk_rc_color_hash_changed (GtkSettings  *settings,
                           GParamSpec   *pspec,
                           GtkRcContext *context)
 {
-  if (context->color_hash)
-    g_hash_table_unref (context->color_hash);
-  
+  GHashTable *old_hash;
+
+  old_hash = context->color_hash;
+
   g_object_get (settings, "color-hash", &context->color_hash, NULL);
 
+  if (old_hash)
+    g_hash_table_unref (old_hash);
+
   gtk_rc_reparse_all_for_settings (settings, TRUE);
 }
 
@@ -680,6 +685,7 @@ gtk_rc_context_get (GtkSettings *settings)
       context->rc_sets_class = NULL;
       context->rc_files = NULL;
       context->default_style = NULL;
+      context->reloading = FALSE;
 
       g_object_get (settings,
                    "gtk-theme-name", &context->theme_name,
@@ -789,11 +795,11 @@ gtk_rc_parse_named (GtkRcContext *context,
   gchar *subpath;
 
   if (type)
-    subpath = g_strconcat ("gtk-2.0-", type,
+    subpath = g_strconcat ("gtk-3.0-", type,
                           G_DIR_SEPARATOR_S "gtkrc",
                           NULL);
   else
-    subpath = g_strdup ("gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
+    subpath = g_strdup ("gtk-3.0" G_DIR_SEPARATOR_S "gtkrc");
   
   /* First look in the users home directory
    */
@@ -835,6 +841,8 @@ gtk_rc_parse_default_files (GtkRcContext *context)
 {
   gint i;
 
+  gtk_rc_add_initial_default_files ();
+
   for (i = 0; gtk_rc_default_files[i] != NULL; i++)
     gtk_rc_context_parse_file (context, gtk_rc_default_files[i], GTK_PATH_PRIO_RC, FALSE);
 }
@@ -863,6 +871,11 @@ _gtk_rc_init (void)
                       "  bg[NORMAL]   = \"#c4c2bd\"\n"
                       "}\n"
                       "\n"
+                      "style \"gtk-default-entry-style\" {\n"
+                      "  bg[SELECTED] = \"#b7c3cd\"\n"
+                      "  fg[SELECTED] = \"#000000\"\n"
+                      "}\n"
+                      "\n"
                       "style \"gtk-default-menu-bar-item-style\" {\n"
                       "  GtkMenuItem::horizontal_padding = 5\n"
                       "}\n"
@@ -874,18 +887,13 @@ _gtk_rc_init (void)
                       "  text[PRELIGHT] = \"#ffffff\"\n"
                       "}\n"
                       "\n"
-                       /* Make transparent tray icons work */
-                      "style \"gtk-default-tray-icon-style\" {\n"
-                      "  bg_pixmap[NORMAL] = \"<parent>\"\n"
-                      "}\n"
-                      "\n"
                        /* Work around clipping of accelerator underlines */
                        "style \"gtk-default-label-style\" {\n"
                        "  GtkWidget::draw-border = {0,0,0,1}\n"
                        "}\n"
                        "\n"    
                       "class \"GtkProgressBar\" style : gtk \"gtk-default-progress-bar-style\"\n"
-                      "class \"GtkTrayIcon\" style : gtk \"gtk-default-tray-icon-style\"\n"
+                      "class \"GtkEntry\" style : gtk \"gtk-default-entry-style\"\n"
                       "widget \"gtk-tooltip*\" style : gtk \"gtk-default-tooltips-style\"\n"
                       "widget_class \"*<GtkMenuItem>*\" style : gtk \"gtk-default-menu-item-style\"\n"
                       "widget_class \"*<GtkMenuBar>*<GtkMenuItem>\" style : gtk \"gtk-default-menu-bar-item-style\"\n"
@@ -1264,20 +1272,36 @@ gtk_rc_style_copy (GtkRcStyle *orig)
   return style;
 }
 
-void      
-gtk_rc_style_ref (GtkRcStyle *rc_style)
+void
+_gtk_rc_style_set_rc_property (GtkRcStyle *rc_style,
+                              GtkRcProperty *property)
 {
   g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
+  g_return_if_fail (property != NULL);
 
-  g_object_ref (rc_style);
+  insert_rc_property (rc_style, property, TRUE);
 }
 
-void      
-gtk_rc_style_unref (GtkRcStyle *rc_style)
+void
+_gtk_rc_style_unset_rc_property (GtkRcStyle *rc_style,
+                                GQuark      type_name,
+                                GQuark      property_name)
 {
+  GtkRcProperty *node;
+
   g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
 
-  g_object_unref (rc_style);
+  node = (GtkRcProperty *) _gtk_rc_style_lookup_rc_property (rc_style,
+                                                             type_name,
+                                                             property_name);
+
+  if (node != NULL)
+    {
+      guint index = node - (GtkRcProperty *) rc_style->rc_properties->data;
+      g_value_unset (&node->value);
+      g_free (node->origin);
+      g_array_remove_index (rc_style->rc_properties, index);
+    }
 }
 
 static GtkRcStyle *
@@ -1294,6 +1318,34 @@ _gtk_rc_style_get_color_hashes (GtkRcStyle *rc_style)
   return priv->color_hashes;
 }
 
+static void gtk_rc_style_prepend_empty_color_hash (GtkRcStyle *rc_style);
+
+void
+_gtk_rc_style_set_symbolic_color (GtkRcStyle     *rc_style,
+                                  const gchar    *name,
+                                  const GdkColor *color)
+{
+  GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (rc_style);
+  GHashTable *our_hash = NULL;
+
+  if (priv->color_hashes)
+    our_hash = priv->color_hashes->data;
+
+  if (our_hash == NULL)
+    {
+      if (color == NULL)
+        return;
+
+      gtk_rc_style_prepend_empty_color_hash (rc_style);
+      our_hash = priv->color_hashes->data;
+    }
+
+  if (color)
+    g_hash_table_insert (our_hash, g_strdup (name), gdk_color_copy (color));
+  else
+    g_hash_table_remove (our_hash, name);
+}
+
 static gint
 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
                       gconstpointer bsearch_node2)
@@ -1515,9 +1567,8 @@ gtk_rc_style_copy_icons_and_colors (GtkRcStyle   *rc_style,
     {
       gtk_rc_style_prepend_empty_color_hash (rc_style);
 
-      priv->color_hashes =
-        g_slist_append (priv->color_hashes,
-                        g_hash_table_ref (context->color_hash));
+      priv->color_hashes = g_slist_append (priv->color_hashes,
+                                           g_hash_table_ref (context->color_hash));
     }
 }
 
@@ -1526,7 +1577,7 @@ gtk_rc_clear_hash_node (gpointer key,
                        gpointer data, 
                        gpointer user_data)
 {
-  gtk_rc_style_unref (data);
+  g_object_unref (data);
 }
 
 static void
@@ -1989,13 +2040,13 @@ 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
+ * @widget_path: (allow-none): 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
+ * @class_path: (allow-none): 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
- * 
+ *
  * Creates up a #GtkStyle from styles defined in a RC file by providing
  * the raw components used in matching. This function may be useful
  * when creating pseudo-widgets that should be themed like widgets but
@@ -2003,12 +2054,13 @@ gtk_rc_get_style (GtkWidget *widget)
  * would be items inside a GNOME canvas 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,
+ * |[
+ *  gtk_widget_path (widget, NULL, &path, NULL);
+ *  gtk_widget_class_path (widget, NULL, &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 nothing matching was specified and the default style should
@@ -2094,86 +2146,6 @@ gtk_rc_get_style_by_paths (GtkSettings *settings,
   return NULL;
 }
 
-static GSList *
-gtk_rc_add_rc_sets (GSList      *slist,
-                   GtkRcStyle  *rc_style,
-                   const gchar *pattern,
-                   GtkPathType  path_type)
-{
-  GtkRcStyle *new_style;
-  GtkRcSet *rc_set;
-  guint i;
-  
-  new_style = gtk_rc_style_new ();
-  *new_style = *rc_style;
-  new_style->name = g_strdup (rc_style->name);
-  if (rc_style->font_desc)
-    new_style->font_desc = pango_font_description_copy (rc_style->font_desc);
-  
-  for (i = 0; i < 5; i++)
-    new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]);
-  
-  rc_set = g_new (GtkRcSet, 1);
-  rc_set->type = path_type;
-  
-  if (path_type == GTK_PATH_WIDGET_CLASS)
-    {
-      rc_set->pspec = NULL;
-      rc_set->path = _gtk_rc_parse_widget_class_path (pattern);
-    }
-  else
-    {
-      rc_set->pspec = g_pattern_spec_new (pattern);
-      rc_set->path = NULL;
-    }
-  
-  rc_set->rc_style = rc_style;
-  
-  return g_slist_prepend (slist, rc_set);
-}
-
-void
-gtk_rc_add_widget_name_style (GtkRcStyle  *rc_style,
-                             const gchar *pattern)
-{
-  GtkRcContext *context;
-  
-  g_return_if_fail (rc_style != NULL);
-  g_return_if_fail (pattern != NULL);
-
-  context = gtk_rc_context_get (gtk_settings_get_default ());
-  
-  context->rc_sets_widget = gtk_rc_add_rc_sets (context->rc_sets_widget, rc_style, pattern, GTK_PATH_WIDGET);
-}
-
-void
-gtk_rc_add_widget_class_style (GtkRcStyle  *rc_style,
-                              const gchar *pattern)
-{
-  GtkRcContext *context;
-  
-  g_return_if_fail (rc_style != NULL);
-  g_return_if_fail (pattern != NULL);
-
-  context = gtk_rc_context_get (gtk_settings_get_default ());
-  
-  context->rc_sets_widget_class = gtk_rc_add_rc_sets (context->rc_sets_widget_class, rc_style, pattern, GTK_PATH_WIDGET_CLASS);
-}
-
-void
-gtk_rc_add_class_style (GtkRcStyle  *rc_style,
-                       const gchar *pattern)
-{
-  GtkRcContext *context;
-  
-  g_return_if_fail (rc_style != NULL);
-  g_return_if_fail (pattern != NULL);
-
-  context = gtk_rc_context_get (gtk_settings_get_default ());
-  
-  context->rc_sets_class = gtk_rc_add_rc_sets (context->rc_sets_class, rc_style, pattern, GTK_PATH_CLASS);
-}
-
 GScanner*
 gtk_rc_scanner_new (void)
 {
@@ -2221,11 +2193,9 @@ gtk_rc_parse_any (GtkRcContext *context,
 
          if (expected_token != G_TOKEN_NONE)
            {
-             gchar *symbol_name;
-             gchar *msg;
-             
-             msg = NULL;
-             symbol_name = NULL;
+             const gchar *symbol_name = NULL;
+             gchar *msg = NULL;
+
              if (scanner->scope_id == 0)
                {
                  /* if we are in scope 0, we know the symbol names
@@ -2236,12 +2206,16 @@ gtk_rc_parse_any (GtkRcContext *context,
                  if (expected_token > GTK_RC_TOKEN_INVALID &&
                      expected_token < GTK_RC_TOKEN_LAST)
                    {
+                      const gchar *sym = NULL;
+
                      for (i = 0; i < G_N_ELEMENTS (symbols); i++)
                        if (symbols[i].token == expected_token)
-                         msg = symbol_names + symbols[i].name_offset;
-                     if (msg)
-                       msg = g_strconcat ("e.g. `", msg, "'", NULL);
+                         sym = symbol_names + symbols[i].name_offset;
+
+                     if (sym)
+                       msg = g_strconcat ("e.g. `", sym, "'", NULL);
                    }
+
                  if (scanner->token > GTK_RC_TOKEN_INVALID &&
                      scanner->token < GTK_RC_TOKEN_LAST)
                    {
@@ -2251,6 +2225,7 @@ gtk_rc_parse_any (GtkRcContext *context,
                          symbol_name = symbol_names + symbols[i].name_offset;
                    }
                }
+
              g_scanner_unexp_token (scanner,
                                     expected_token,
                                     NULL,
@@ -2416,7 +2391,7 @@ gtk_rc_init_style (GtkRcContext *context,
          }
 
       style = gtk_rc_style_to_style (context, proto_style);
-      gtk_rc_style_unref (proto_style);
+      g_object_unref (proto_style);
 
       g_hash_table_insert (realized_style_ht, rc_styles, style);
     }
@@ -3109,14 +3084,14 @@ gtk_rc_parse_style (GtkRcContext *context,
           break;
         case GTK_RC_TOKEN_COLOR:
           if (our_hash == NULL)
-            gtk_rc_style_prepend_empty_color_hash (rc_style);
-          our_hash = rc_priv->color_hashes->data;
+            {
+              gtk_rc_style_prepend_empty_color_hash (rc_style);
+              our_hash = rc_priv->color_hashes->data;
+            }
           token = gtk_rc_parse_logical_color (scanner, rc_style, our_hash);
           break;
        case G_TOKEN_IDENTIFIER:
-         if (is_c_identifier (scanner->next_value.v_identifier) &&
-             scanner->next_value.v_identifier[0] >= 'A' &&
-             scanner->next_value.v_identifier[0] <= 'Z') /* match namespaced type names */
+         if (is_c_identifier (scanner->next_value.v_identifier))
            {
              GtkRcProperty prop = { 0, 0, NULL, { 0, }, };
              gchar *name;
@@ -3200,7 +3175,7 @@ gtk_rc_parse_style (GtkRcContext *context,
 
  err:
   if (rc_style != orig_style)
-    gtk_rc_style_unref (rc_style);
+    g_object_unref (rc_style);
 
   if (orig_style)
     g_object_unref (orig_style);
@@ -3570,6 +3545,7 @@ gtk_rc_parse_engine (GtkRcContext *context,
   guint result = G_TOKEN_NONE;
   GtkRcStyle *new_style = NULL;
   gboolean parsed_curlies = FALSE;
+  GtkRcStylePrivate *rc_priv, *new_priv;
   
   token = g_scanner_get_next_token (scanner);
   if (token != GTK_RC_TOKEN_ENGINE)
@@ -3593,13 +3569,23 @@ gtk_rc_parse_engine (GtkRcContext *context,
 
       parsed_curlies = TRUE;
 
+      rc_priv = GTK_RC_STYLE_GET_PRIVATE (*rc_style);
+
       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);
+
+          new_style->name = g_strdup ((*rc_style)->name);
+
+          /* take over icon factories and color hashes 
+           * from the to-be-deleted style
+           */
+          new_style->icon_factories = (*rc_style)->icon_factories;
+          (*rc_style)->icon_factories = NULL;
+          new_priv = GTK_RC_STYLE_GET_PRIVATE (new_style);
+          new_priv->color_hashes = rc_priv->color_hashes;
+          rc_priv->color_hashes = NULL;
        }
       else
        (*rc_style)->engine_specified = TRUE;
@@ -3616,14 +3602,24 @@ gtk_rc_parse_engine (GtkRcContext *context,
        {
          GtkRcStyleClass *new_class;
          
+         rc_priv = GTK_RC_STYLE_GET_PRIVATE (*rc_style);
          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);
+
+          new_style->name = g_strdup ((*rc_style)->name);
+
+          /* take over icon factories and color hashes 
+           * from the to-be-deleted style
+           */
+          new_style->icon_factories = (*rc_style)->icon_factories;
+          (*rc_style)->icon_factories = NULL;
+          new_priv = GTK_RC_STYLE_GET_PRIVATE (new_style);
+          new_priv->color_hashes = rc_priv->color_hashes;
+          rc_priv->color_hashes = NULL;
          
          if (new_class->parse)
            {
@@ -3632,6 +3628,13 @@ gtk_rc_parse_engine (GtkRcContext *context,
              
              if (result != G_TOKEN_NONE)
                {
+                  /* copy icon factories and color hashes back
+                   */
+                  (*rc_style)->icon_factories = new_style->icon_factories;
+                  new_style->icon_factories = NULL;
+                  rc_priv->color_hashes = new_priv->color_hashes;
+                  new_priv->color_hashes = NULL;
+
                  g_object_unref (new_style);
                  new_style = NULL;
                }
@@ -3663,18 +3666,6 @@ gtk_rc_parse_engine (GtkRcContext *context,
 
   if (new_style)
     {
-      GtkRcStylePrivate *rc_priv = GTK_RC_STYLE_GET_PRIVATE (*rc_style);
-      GtkRcStylePrivate *new_priv = GTK_RC_STYLE_GET_PRIVATE (new_style);
-
-      /* take over icon factories and color hashes from the to-be-deleted style
-       */
-
-      new_style->icon_factories = (*rc_style)->icon_factories;
-      (*rc_style)->icon_factories = NULL;
-
-      new_priv->color_hashes = rc_priv->color_hashes;
-      rc_priv->color_hashes = NULL;
-
       new_style->engine_specified = TRUE;
 
       g_object_unref (*rc_style);
@@ -3785,6 +3776,20 @@ gtk_rc_parse_priority (GScanner             *scanner,
   return G_TOKEN_NONE;
 }
 
+/**
+ * gtk_rc_parse_color:
+ * @scanner: a #GScanner
+ * @color: a pointer to a #GdkColor structure in which to store the result
+ *
+ * Parses a color in the <link linkend="color=format">format</link> expected
+ * in a RC file. 
+ *
+ * Note that theme engines should use gtk_rc_parse_color_full() in 
+ * order to support symbolic colors.
+ *
+ * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
+ *     that was expected but not found
+ */
 guint
 gtk_rc_parse_color (GScanner *scanner,
                    GdkColor *color)
@@ -3792,7 +3797,22 @@ gtk_rc_parse_color (GScanner *scanner,
   return gtk_rc_parse_color_full (scanner, NULL, color);
 }
 
-static guint
+/**
+ * gtk_rc_parse_color_full:
+ * @scanner: a #GScanner
+ * @style: (allow-none): a #GtkRcStyle, or %NULL
+ * @color: a pointer to a #GdkColor structure in which to store the result
+ *
+ * Parses a color in the <link linkend="color=format">format</link> expected
+ * in a RC file. If @style is not %NULL, it will be consulted to resolve
+ * references to symbolic colors.
+ *
+ * Returns: %G_TOKEN_NONE if parsing succeeded, otherwise the token
+ *     that was expected but not found
+ *
+ * Since: 2.12
+ */
+guint
 gtk_rc_parse_color_full (GScanner   *scanner,
                          GtkRcStyle *style,
                          GdkColor   *color)
@@ -4779,7 +4799,7 @@ _gtk_rc_match_widget_class (GSList  *list,
   return match_widget_class_recursive (list, length, path, path_reversed);
 }
 
-#ifdef G_OS_WIN32
+#if defined (G_OS_WIN32) && !defined (_WIN64)
 
 /* DLL ABI stability backward compatibility versions */