[gtk+/wip/cssvalue: 113/165] cssvalue: Add a css value for engines
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cssvalue: 113/165] cssvalue: Add a css value for engines
- Date: Fri, 13 Apr 2012 23:12:17 +0000 (UTC)
commit 3dd0e43fe0a7cbabf9a6eb4d0bca6d83a01db0b4
Author: Benjamin Otte <otte redhat com>
Date: Tue Apr 3 21:26:34 2012 +0200
cssvalue: Add a css value for engines
gtk/Makefile.am | 2 +
gtk/gtkcssenginevalue.c | 127 ++++++++++++++++++++++++++++++++++++++++
gtk/gtkcssenginevalueprivate.h | 37 ++++++++++++
gtk/gtkcssstylepropertyimpl.c | 45 ++++++--------
gtk/gtkcssvalue.c | 11 ----
gtk/gtkcssvalueprivate.h | 2 -
6 files changed, 185 insertions(+), 39 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 3d7dd85..1416320 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -428,6 +428,7 @@ gtk_private_h_sources = \
gtkcsscornervalueprivate.h \
gtkcsscustompropertyprivate.h \
gtkcsseasevalueprivate.h \
+ gtkcssenginevalueprivate.h \
gtkcssenumvalueprivate.h \
gtkcssimagecrossfadeprivate.h \
gtkcssimagegradientprivate.h \
@@ -638,6 +639,7 @@ gtk_base_c_sources = \
gtkcsscustomproperty.c \
gtkcsseasevalue.c \
gtkcssenumvalue.c \
+ gtkcssenginevalue.c \
gtkcssimage.c \
gtkcssimagecrossfade.c \
gtkcssimagegradient.c \
diff --git a/gtk/gtkcssenginevalue.c b/gtk/gtkcssenginevalue.c
new file mode 100644
index 0000000..ff4ba67
--- /dev/null
+++ b/gtk/gtkcssenginevalue.c
@@ -0,0 +1,127 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gtkcssenginevalueprivate.h"
+
+#include "gtkstylepropertyprivate.h"
+
+struct _GtkCssValue {
+ GTK_CSS_VALUE_BASE
+ GtkThemingEngine *engine;
+};
+
+static void
+gtk_css_value_engine_free (GtkCssValue *value)
+{
+ g_object_unref (value->engine);
+
+ g_slice_free (GtkCssValue, value);
+}
+
+static gboolean
+gtk_css_value_engine_equal (const GtkCssValue *value1,
+ const GtkCssValue *value2)
+{
+ return value1->engine == value2->engine;
+}
+
+static GtkCssValue *
+gtk_css_value_engine_transition (GtkCssValue *start,
+ GtkCssValue *end,
+ double progress)
+{
+ return NULL;
+}
+
+static void
+gtk_css_value_engine_print (const GtkCssValue *value,
+ GString *string)
+{
+ char *name;
+
+ g_object_get (value->engine, "name", &name, NULL);
+
+ if (name)
+ g_string_append (string, name);
+ else
+ g_string_append (string, "none");
+
+ g_free (name);
+}
+
+static const GtkCssValueClass GTK_CSS_VALUE_ENGINE = {
+ gtk_css_value_engine_free,
+ gtk_css_value_engine_equal,
+ gtk_css_value_engine_transition,
+ gtk_css_value_engine_print
+};
+
+GtkCssValue *
+_gtk_css_engine_value_new (GtkThemingEngine *engine)
+{
+ GtkCssValue *result;
+
+ g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
+
+ result = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_ENGINE);
+ result->engine = g_object_ref (engine);
+
+ return result;
+}
+
+GtkCssValue *
+_gtk_css_engine_value_parse (GtkCssParser *parser)
+{
+ GtkThemingEngine *engine;
+ char *str;
+
+ g_return_val_if_fail (parser != NULL, NULL);
+
+ if (_gtk_css_parser_try (parser, "none", TRUE))
+ return _gtk_css_engine_value_new (gtk_theming_engine_load (NULL));
+
+ str = _gtk_css_parser_try_ident (parser, TRUE);
+ if (str == NULL)
+ {
+ _gtk_css_parser_error (parser, "Expected a valid theme name");
+ return NULL;
+ }
+
+ engine = gtk_theming_engine_load (str);
+
+ if (engine == NULL)
+ {
+ _gtk_css_parser_error (parser, "Theming engine '%s' not found", str);
+ g_free (str);
+ return NULL;
+ }
+
+ g_free (str);
+
+ return _gtk_css_engine_value_new (engine);
+}
+
+GtkThemingEngine *
+_gtk_css_engine_value_get_engine (const GtkCssValue *value)
+{
+ g_return_val_if_fail (value->class == >K_CSS_VALUE_ENGINE, NULL);
+
+ return value->engine;
+}
+
diff --git a/gtk/gtkcssenginevalueprivate.h b/gtk/gtkcssenginevalueprivate.h
new file mode 100644
index 0000000..888c07a
--- /dev/null
+++ b/gtk/gtkcssenginevalueprivate.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright  2012 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Alexander Larsson <alexl gnome org>
+ */
+
+#ifndef __GTK_CSS_ENGINE_VALUE_PRIVATE_H__
+#define __GTK_CSS_ENGINE_VALUE_PRIVATE_H__
+
+#include "gtkcssparserprivate.h"
+#include "gtkcssvalueprivate.h"
+#include "gtkthemingengine.h"
+
+G_BEGIN_DECLS
+
+GtkCssValue * _gtk_css_engine_value_new (GtkThemingEngine *engine);
+GtkCssValue * _gtk_css_engine_value_parse (GtkCssParser *parser);
+
+GtkThemingEngine * _gtk_css_engine_value_get_engine (const GtkCssValue *engine);
+
+
+G_END_DECLS
+
+#endif /* __GTK_CSS_ENGINE_VALUE_PRIVATE_H__ */
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 812787a..a7f3eb82 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -43,6 +43,7 @@
#include "gtkcssarrayvalueprivate.h"
#include "gtkcsscornervalueprivate.h"
#include "gtkcsseasevalueprivate.h"
+#include "gtkcssenginevalueprivate.h"
#include "gtkcssimagegradientprivate.h"
#include "gtkcssimageprivate.h"
#include "gtkcssimagevalueprivate.h"
@@ -772,31 +773,23 @@ engine_parse (GtkCssStyleProperty *property,
GtkCssParser *parser,
GFile *base)
{
- GtkThemingEngine *engine;
- char *str;
-
- if (_gtk_css_parser_try (parser, "none", TRUE))
- return _gtk_css_value_new_from_theming_engine (gtk_theming_engine_load (NULL));
-
- str = _gtk_css_parser_try_ident (parser, TRUE);
- if (str == NULL)
- {
- _gtk_css_parser_error (parser, "Expected a valid theme name");
- return NULL;
- }
-
- engine = gtk_theming_engine_load (str);
-
- if (engine == NULL)
- {
- _gtk_css_parser_error (parser, "Theming engine '%s' not found", str);
- g_free (str);
- return NULL;
- }
+ return _gtk_css_engine_value_parse (parser);
+}
- g_free (str);
+static void
+engine_query (GtkCssStyleProperty *property,
+ const GtkCssValue *css_value,
+ GValue *value)
+{
+ g_value_init (value, GTK_TYPE_THEMING_ENGINE);
+ g_value_set_object (value, _gtk_css_engine_value_get_engine (css_value));
+}
- return _gtk_css_value_new_from_theming_engine (engine);
+static GtkCssValue *
+engine_assign (GtkCssStyleProperty *property,
+ const GValue *value)
+{
+ return _gtk_css_engine_value_new (g_value_get_object (value));
}
static GtkCssValue *
@@ -1857,10 +1850,10 @@ _gtk_css_style_property_init_properties (void)
engine_parse,
NULL,
NULL,
- query_simple,
- assign_simple,
+ engine_query,
+ engine_assign,
NULL,
- _gtk_css_value_new_from_theming_engine (gtk_theming_engine_load (NULL)));
+ _gtk_css_engine_value_new (gtk_theming_engine_load (NULL)));
gtk_css_style_property_register ("transition",
GTK_CSS_PROPERTY_TRANSITION,
GTK_TYPE_ANIMATION_DESCRIPTION,
diff --git a/gtk/gtkcssvalue.c b/gtk/gtkcssvalue.c
index f2fd69a..83b79a1 100644
--- a/gtk/gtkcssvalue.c
+++ b/gtk/gtkcssvalue.c
@@ -257,17 +257,6 @@ _gtk_css_value_new_take_pattern (cairo_pattern_t *v)
}
GtkCssValue *
-_gtk_css_value_new_from_theming_engine (GtkThemingEngine *v)
-{
- GtkCssValue *value;
-
- value = gtk_css_value_new (GTK_TYPE_THEMING_ENGINE);
- value->u.ptr = g_object_ref (v);
-
- return value;
-}
-
-GtkCssValue *
_gtk_css_value_new_take_binding_sets (GPtrArray *array)
{
GtkCssValue *value;
diff --git a/gtk/gtkcssvalueprivate.h b/gtk/gtkcssvalueprivate.h
index aacc230..6541cf2 100644
--- a/gtk/gtkcssvalueprivate.h
+++ b/gtk/gtkcssvalueprivate.h
@@ -23,7 +23,6 @@
#include <glib-object.h>
#include "gtkcsstypesprivate.h"
#include "gtksymboliccolor.h"
-#include "gtkthemingengine.h"
G_BEGIN_DECLS
@@ -88,7 +87,6 @@ GtkCssValue *_gtk_css_value_new_from_boxed (GType
GtkCssValue *_gtk_css_value_new_from_color (const GdkColor *v);
GtkCssValue *_gtk_css_value_new_take_symbolic_color (GtkSymbolicColor *v);
GtkCssValue *_gtk_css_value_new_take_pattern (cairo_pattern_t *v);
-GtkCssValue *_gtk_css_value_new_from_theming_engine (GtkThemingEngine *v);
GtkCssValue *_gtk_css_value_new_take_binding_sets (GPtrArray *array);
GtkCssValue *_gtk_css_value_new_from_background_size (const GtkCssBackgroundSize *v);
GtkCssValue *_gtk_css_value_new_from_background_position (const GtkCssBackgroundPosition *v);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]