Commit aed76004 authored by Benjamin Otte's avatar Benjamin Otte

cssvalue: Add a css value for engines

parent 4f63c1c7
......@@ -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 \
......
/* 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, &GTK_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 == &GTK_CSS_VALUE_ENGINE, NULL);
return value->engine;
}
/*
* 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__ */
......@@ -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,
......
......@@ -256,17 +256,6 @@ _gtk_css_value_new_take_pattern (cairo_pattern_t *v)
return value;
}
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)
{
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment