]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkrc.c
Estonian translation update by Ivar Smolin.
[~andy/gtk] / gtk / gtkrc.c
index a570d62f3114c3abbf481c773115f35351bcd395..2100e00c7c61699906d47ef36e8f1e01f8531cff 100644 (file)
@@ -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 =
 {
@@ -319,7 +320,8 @@ static const gchar symbol_names[] =
   "im_module_file\0"
   "LTR\0"
   "RTL\0"
-  "color\0";
+  "color\0"
+  "unbind\0";
 
 static const struct
 {
@@ -361,7 +363,8 @@ static const struct
   { 245, GTK_RC_TOKEN_IM_MODULE_FILE },
   { 260, GTK_RC_TOKEN_LTR },
   { 264, GTK_RC_TOKEN_RTL },
-  { 268, GTK_RC_TOKEN_COLOR }
+  { 268, GTK_RC_TOKEN_COLOR },
+  { 274, GTK_RC_TOKEN_UNBIND }
 };
 
 static GHashTable *realized_style_ht = NULL;
@@ -661,11 +664,7 @@ gtk_rc_color_hash_changed (GtkSettings  *settings,
   
   g_object_get (settings, "color-hash", &context->color_hash, NULL);
 
-  if (context->color_hash)
-    g_hash_table_ref (context->color_hash);
-
-  if (!context->reloading)
-    gtk_rc_reparse_all_for_settings (settings, TRUE);
+  gtk_rc_reparse_all_for_settings (settings, TRUE);
 }
 
 static GtkRcContext *
@@ -682,6 +681,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,
@@ -690,9 +690,6 @@ gtk_rc_context_get (GtkSettings *settings)
                    "color-hash", &context->color_hash,
                    NULL);
 
-      if (context->color_hash)
-        g_hash_table_ref (context->color_hash);
-
       g_signal_connect (settings,
                        "notify::gtk-theme-name",
                        G_CALLBACK (gtk_rc_settings_changed),
@@ -879,15 +876,22 @@ _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"
-                      "widget \"gtk-tooltips*\" style : gtk \"gtk-default-tooltips-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"
+                       "class \"GtkLabel\" style : gtk \"gtk-default-label-style\"\n"
       );
 }
   
@@ -1163,14 +1167,12 @@ gtk_rc_style_finalize (GObject *object)
   rc_style = GTK_RC_STYLE (object);
   rc_priv = GTK_RC_STYLE_GET_PRIVATE (rc_style);
 
-  if (rc_style->name)
-    g_free (rc_style->name);
+  g_free (rc_style->name);
   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->bg_pixmap_name[i]);
   
   /* Now remove all references to this rc_style from
    * realized_style_ht
@@ -1264,6 +1266,36 @@ gtk_rc_style_copy (GtkRcStyle *orig)
   return 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);
+
+  insert_rc_property (rc_style, property, TRUE);
+}
+
+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));
+
+  node = _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);
+    }
+}
+
 void      
 gtk_rc_style_ref (GtkRcStyle *rc_style)
 {
@@ -1515,9 +1547,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));
     }
 }
 
@@ -1716,6 +1747,9 @@ gtk_rc_reparse_all_for_settings (GtkSettings *settings,
 
   context = gtk_rc_context_get (settings);
 
+  if (context->reloading)
+    return FALSE;
+
   if (!force_load)
     {
       /* Check through and see if any of the RC's have had their
@@ -2858,7 +2892,7 @@ gtk_rc_parse_statement (GtkRcContext *context,
       return gtk_rc_parse_style (context, scanner);
       
     case GTK_RC_TOKEN_BINDING:
-      return gtk_binding_parse_binding (scanner);
+      return _gtk_binding_parse_binding (scanner);
       
     case GTK_RC_TOKEN_PIXMAP_PATH:
       return gtk_rc_parse_pixmap_path (context, scanner);
@@ -3036,8 +3070,7 @@ gtk_rc_parse_style (GtkRcContext *context,
          
          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->bg_pixmap_name[i]);
              rc_style->bg_pixmap_name[i] = g_strdup (parent_style->bg_pixmap_name[i]);
            }
        }
@@ -3112,9 +3145,7 @@ gtk_rc_parse_style (GtkRcContext *context,
           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;
@@ -3392,8 +3423,7 @@ gtk_rc_parse_bg_pixmap (GtkRcContext *context,
   
   if (pixmap_file)
     {
-      if (rc_style->bg_pixmap_name[state])
-       g_free (rc_style->bg_pixmap_name[state]);
+      g_free (rc_style->bg_pixmap_name[state]);
       rc_style->bg_pixmap_name[state] = pixmap_file;
     }
   
@@ -3569,6 +3599,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)
@@ -3592,13 +3623,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;
@@ -3615,14 +3656,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)
            {
@@ -3631,6 +3682,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;
                }
@@ -3662,18 +3720,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);
@@ -3784,6 +3830,20 @@ gtk_rc_parse_priority (GScanner             *scanner,
   return G_TOKEN_NONE;
 }
 
+/**
+ * gtk_rc_parse_color:
+ * @scanner: a #GScanner
+ * @color: a pointer to a #GtkColor 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)
@@ -3791,7 +3851,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: a #GtkRcStyle, or %NULL
+ * @color: a pointer to a #GtkColor 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)
@@ -4048,8 +4123,7 @@ gtk_rc_parse_im_module_file (GScanner *scanner)
   if (token != G_TOKEN_STRING)
     return G_TOKEN_STRING;
 
-  if (im_module_file)
-    g_free (im_module_file);
+  g_free (im_module_file);
     
   im_module_file = g_strdup (scanner->value.v_string);
 
@@ -4204,9 +4278,9 @@ gtk_rc_parse_icon_source (GtkRcContext   *context,
                           gboolean       *icon_set_valid)
 {
   guint token;
-  GtkIconSource *source;
   gchar *full_filename;
-  
+  GtkIconSource *source = NULL;
+
   token = g_scanner_get_next_token (scanner);
   if (token != G_TOKEN_LEFT_CURLY)
     return G_TOKEN_LEFT_CURLY;
@@ -4216,12 +4290,11 @@ gtk_rc_parse_icon_source (GtkRcContext   *context,
   if (token != G_TOKEN_STRING && token != '@')
     return G_TOKEN_STRING;
   
-  source = gtk_icon_source_new ();
-
   if (token == G_TOKEN_STRING)
     {
       /* Filename */
-      
+
+      source = gtk_icon_source_new ();      
       full_filename = gtk_rc_find_pixmap_in_path (context->settings, scanner, scanner->value.v_string);
       if (full_filename)
        {
@@ -4238,6 +4311,7 @@ gtk_rc_parse_icon_source (GtkRcContext   *context,
       if (token != G_TOKEN_STRING)
        return G_TOKEN_STRING;
 
+      source = gtk_icon_source_new ();
       gtk_icon_source_set_icon_name (source, scanner->value.v_string);
     }