]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcssprovider.c
Change FSF Address
[~andy/gtk] / gtk / gtkcssprovider.c
index 462b551d41349bebdbc62fa51a92c18234deabba..32bdd3a5650f64132b78e86f1746e41f6c9d6ca9 100644 (file)
@@ -12,9 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
  *         <entry>darker(@color)</entry>
  *         <entry>A darker variant of @color</entry>
  *       </row>
+ *       <row>
+ *         <entry>alpha(@color, @f)</entry>
+ *         <entry>Modifies passed color's alpha by a factor @f. @f is a
+ *                floating point number. @f < 1.0 results in a more transparent
+ *                color while @f > 1.0 results in a more opaque color.
+ *         </entry>
+ *         <entry>alhpa(blue, 0.5)</entry>
+ *       </row>
  *     </tbody>
  *   </tgroup>
  * </informaltable>
@@ -985,6 +991,7 @@ struct _GtkCssProviderPrivate
   GHashTable *symbolic_colors;
 
   GArray *rulesets;
+  GResource *resource;
 };
 
 enum {
@@ -1194,23 +1201,27 @@ gtk_css_ruleset_add (GtkCssRuleset    *ruleset,
   if (GTK_IS_CSS_SHORTHAND_PROPERTY (prop))
     {
       GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (prop);
-      GValueArray *array = g_value_get_boxed (&value->value);
+      GArray *array = g_value_get_boxed (&value->value);
       guint i;
 
       for (i = 0; i < _gtk_css_shorthand_property_get_n_subproperties (shorthand); i++)
         {
           GtkCssStyleProperty *child = _gtk_css_shorthand_property_get_subproperty (shorthand, i);
+          const GValue *sub = &g_array_index (array, GValue, i);
           PropertyValue *val;
           
           val = property_value_new (value->section);
-          g_value_init (&val->value, G_VALUE_TYPE (g_value_array_get_nth (array, i)));
-          g_value_copy (g_value_array_get_nth (array, i), &val->value);
+          g_value_init (&val->value, G_VALUE_TYPE (sub));
+          g_value_copy (sub, &val->value);
           gtk_css_ruleset_add (ruleset, GTK_STYLE_PROPERTY (child), val);
         }
       property_value_free (value);
     }
   else if (GTK_IS_CSS_STYLE_PROPERTY (prop))
     {
+      g_return_if_fail (_gtk_css_style_property_is_specified_type (GTK_CSS_STYLE_PROPERTY (prop),
+                                                                   G_VALUE_TYPE (&value->value)));
+
       _gtk_bitmask_set (ruleset->set_styles,
                         _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)),
                         TRUE);
@@ -1587,6 +1598,13 @@ gtk_css_provider_finalize (GObject *object)
   if (priv->symbolic_colors)
     g_hash_table_destroy (priv->symbolic_colors);
 
+  if (priv->resource)
+    {
+      g_resources_unregister (priv->resource);
+      g_resource_unref (priv->resource);
+      priv->resource = NULL;
+    }
+
   G_OBJECT_CLASS (gtk_css_provider_parent_class)->finalize (object);
 }
 
@@ -1700,6 +1718,13 @@ gtk_css_provider_reset (GtkCssProvider *css_provider)
 
   priv = css_provider->priv;
 
+  if (priv->resource)
+    {
+      g_resources_unregister (priv->resource);
+      g_resource_unref (priv->resource);
+      priv->resource = NULL;
+    }
+
   g_hash_table_remove_all (priv->symbolic_colors);
 
   for (i = 0; i < priv->rulesets->len; i++)
@@ -1790,7 +1815,7 @@ parse_import (GtkCssScanner *scanner)
       return TRUE;
     }
 
-  if (!_gtk_css_parser_try (scanner->parser, ";", TRUE))
+  if (!_gtk_css_parser_try (scanner->parser, ";", FALSE))
     {
       gtk_css_provider_invalid_token (scanner->provider, scanner, "semicolon");
       _gtk_css_parser_resync (scanner->parser, TRUE, 0);
@@ -1818,6 +1843,8 @@ parse_import (GtkCssScanner *scanner)
   g_object_unref (file);
 
   gtk_css_scanner_pop_section (scanner, GTK_CSS_SECTION_IMPORT);
+  _gtk_css_parser_skip_whitespace (scanner->parser);
+
   return TRUE;
 }
 
@@ -2786,12 +2813,7 @@ gtk_css_provider_get_default (void)
 
   if (G_UNLIKELY (!provider))
     {
-
       provider = gtk_css_provider_new ();
-      if (!_gtk_css_provider_load_from_resource (provider, "/org/gtk/libgtk/gtk-default.css"))
-        {
-          g_error ("Failed to load the internal default CSS.");
-        }
     }
 
   return provider;
@@ -2832,27 +2854,37 @@ gtk_css_provider_get_named (const gchar *name,
   GtkCssProvider *provider;
   gchar *key;
 
-  if (G_UNLIKELY (!themes))
-    {
-      themes = g_hash_table_new (g_str_hash, g_str_equal);
-
-      provider = gtk_css_provider_new ();
-      if (!_gtk_css_provider_load_from_resource (provider, "/org/gtk/libgtk/gtk-win32.css"))
-        {
-          g_warning ("Failed to load the internal win32 default CSS.");
-         g_object_unref (provider);
-        }
-      else
-       g_hash_table_insert (themes, "gtk-win32", provider);
-    }
-
   if (variant == NULL)
     key = (gchar *)name;
   else
     key = g_strconcat (name, "-", variant, NULL);
 
+  if (G_UNLIKELY (!themes))
+    themes = g_hash_table_new (g_str_hash, g_str_equal);
+
   provider = g_hash_table_lookup (themes, key);
 
+  if (!provider)
+    {
+      gchar *resource_path = NULL;
+
+      if (variant)
+        resource_path = g_strdup_printf ("/org/gtk/libgtk/%s-%s.css", name, variant);
+      else
+        resource_path = g_strdup_printf ("/org/gtk/libgtk/%s.css", name);
+
+      if (g_resources_get_info (resource_path, 0, NULL, NULL, NULL))
+       {
+         provider = gtk_css_provider_new ();
+         if (!_gtk_css_provider_load_from_resource (provider, resource_path))
+           {
+             g_object_unref (provider);
+             provider = NULL;
+           }
+       }
+      g_free (resource_path);
+    }
+
   if (!provider)
     {
       const gchar *home_dir;
@@ -2896,17 +2928,36 @@ gtk_css_provider_get_named (const gchar *name,
 
       if (path)
         {
+         char *dir, *resource_file;
+         GResource *resource;
+
           provider = gtk_css_provider_new ();
 
+         dir = g_path_get_dirname (path);
+         resource_file = g_build_filename (dir, "gtk.gresource", NULL);
+         resource = g_resource_load (resource_file, NULL);
+         if (resource != NULL)
+           g_resources_register (resource);
+
           if (!gtk_css_provider_load_from_path (provider, path, NULL))
             {
+             if (resource != NULL)
+               {
+                 g_resources_unregister (resource);
+                 g_resource_unref (resource);
+               }
               g_object_unref (provider);
               provider = NULL;
             }
           else
-            g_hash_table_insert (themes, g_strdup (key), provider);
+           {
+             /* Only set this after load success, as load_from_path will clear it */
+             provider->priv->resource = resource;
+             g_hash_table_insert (themes, g_strdup (key), provider);
+           }
 
           g_free (path);
+          g_free (dir);
         }
     }