1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*
* Copyright © 2016 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: Benjamin Otte <otte@gnome.org>
*/
#include "config.h"
#include "gtkcssstyledeclarationprivate.h"
#include "gtkcssdeclarationprivate.h"
typedef struct _GtkCssStyleDeclarationPrivate GtkCssStyleDeclarationPrivate;
struct _GtkCssStyleDeclarationPrivate {
GPtrArray *declarations;
};
G_DEFINE_TYPE_WITH_PRIVATE (GtkCssStyleDeclaration, gtk_css_style_declaration, G_TYPE_OBJECT)
static void
gtk_css_style_declaration_finalize (GObject *object)
{
GtkCssStyleDeclaration *style_declaration = GTK_CSS_STYLE_DECLARATION (object);
GtkCssStyleDeclarationPrivate *priv = gtk_css_style_declaration_get_instance_private (style_declaration);
g_ptr_array_unref (priv->declarations);
G_OBJECT_CLASS (gtk_css_style_declaration_parent_class)->finalize (object);
}
static void
gtk_css_style_declaration_class_init (GtkCssStyleDeclarationClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gtk_css_style_declaration_finalize;
}
static void
gtk_css_style_declaration_init (GtkCssStyleDeclaration *style_declaration)
{
GtkCssStyleDeclarationPrivate *priv = gtk_css_style_declaration_get_instance_private (style_declaration);
priv->declarations = g_ptr_array_new_with_free_func (g_object_unref);
}
GtkCssStyleDeclaration *
gtk_css_style_declaration_new (GtkCssRule *parent_rule)
{
return g_object_new (GTK_TYPE_CSS_STYLE_DECLARATION, NULL);
}
void
gtk_css_style_declaration_parse (GtkCssStyleDeclaration *style,
GtkCssTokenSource *source)
{
GtkCssStyleDeclarationPrivate *priv;
GtkCssTokenSource *decl_source;
GtkCssDeclaration *declaration;
const GtkCssToken *token;
priv = gtk_css_style_declaration_get_instance_private (style);
gtk_css_token_source_set_consumer (source, G_OBJECT (style));
for (token = gtk_css_token_source_get_token (source);
!gtk_css_token_is (token, GTK_CSS_TOKEN_EOF);
token = gtk_css_token_source_get_token (source))
{
if (gtk_css_token_is (token, GTK_CSS_TOKEN_SEMICOLON) ||
gtk_css_token_is (token, GTK_CSS_TOKEN_WHITESPACE))
{
gtk_css_token_source_consume_token (source);
}
else if (gtk_css_token_is (token, GTK_CSS_TOKEN_IDENT))
{
decl_source = gtk_css_token_source_new_for_part (source, GTK_CSS_TOKEN_SEMICOLON);
declaration = gtk_css_declaration_new_parse (style, decl_source);
if (declaration)
g_ptr_array_add (priv->declarations, declaration);
gtk_css_token_source_unref (decl_source);
gtk_css_token_source_consume_token (source);
}
else
{
gtk_css_token_source_error (source, "Expected property declaration");
decl_source = gtk_css_token_source_new_for_part (source, GTK_CSS_TOKEN_SEMICOLON);
gtk_css_token_source_consume_all (decl_source);
gtk_css_token_source_unref (decl_source);
gtk_css_token_source_consume_token (source);
}
}
}
GtkCssDeclaration *
gtk_css_style_declaration_get_declaration (GtkCssStyleDeclaration *declaration,
gssize id)
{
GtkCssStyleDeclarationPrivate *priv;
g_return_val_if_fail (GTK_IS_CSS_STYLE_DECLARATION (declaration), NULL);
priv = gtk_css_style_declaration_get_instance_private (declaration);
g_return_val_if_fail (id < priv->declarations->len, NULL);
return g_ptr_array_index (priv->declarations, id);
}
gsize
gtk_css_style_declaration_get_length (GtkCssStyleDeclaration *declaration)
{
GtkCssStyleDeclarationPrivate *priv;
g_return_val_if_fail (GTK_IS_CSS_STYLE_DECLARATION (declaration), 0);
priv = gtk_css_style_declaration_get_instance_private (declaration);
return priv->declarations->len;
}
|