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
|
/* vim: set ts=8 sw=8 noexpandtab: */
/* The `C' CSS Library.
* Copyright (C) 2008 Robert Staudinger
*
* 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, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <glib.h>
#include "ccss-block-priv.h"
#include "config.h"
ccss_block_t *
ccss_block_create (void)
{
ccss_block_t *self;
self = g_new0 (ccss_block_t, 1);
self->reference_count = 1;
self->properties = g_hash_table_new_full ((GHashFunc) g_direct_hash,
(GEqualFunc) g_direct_equal,
NULL,
(GDestroyNotify) ccss_property_destroy);
return self;
}
void
ccss_block_destroy (ccss_block_t *self)
{
g_return_if_fail (self && self->properties);
self->reference_count--;
if (self->reference_count == 0) {
g_hash_table_destroy (self->properties), self->properties = NULL;
g_free (self);
}
}
ccss_block_t *
ccss_block_reference (ccss_block_t *self)
{
g_return_val_if_fail (self, NULL);
self->reference_count++;
return self;
}
/**
* ccss_block_add_property:
* @self: a #ccss_block_t.
* @property_name: the property name, e.g. %background-color.
* @property: pointer to the property instance.
*
* Adds a property to a CSS block.
**/
void
ccss_block_add_property (ccss_block_t *self,
char const *property_name,
ccss_property_base_t *property)
{
GQuark property_id;
property_id = g_quark_try_string (property_name);
if (0 == property_id) {
property_id = g_quark_from_string (property_name);
}
g_hash_table_insert (
self->properties,
(gpointer) property_id,
(gpointer) property);
}
void
ccss_block_dump (ccss_block_t const *self)
{
GHashTableIter iter;
GQuark property_id;
ccss_property_base_t const *property;
char *strval;
g_hash_table_iter_init (&iter, self->properties);
while (g_hash_table_iter_next (&iter, (gpointer *) &property_id, (gpointer *) &property)) {
strval = NULL;
if (CCSS_PROPERTY_STATE_NONE == property->state ||
CCSS_PROPERTY_STATE_INHERIT == property->state) {
strval = g_strdup (ccss_property_state_serialize (property->state));
} else if (property->property_class &&
property->property_class->convert) {
property->property_class->convert (property,
CCSS_PROPERTY_TYPE_STRING,
&strval);
}
if (NULL == strval)
strval = g_strdup ("<unknown>");
printf ("\t%s: %s;\n",
g_quark_to_string (property_id),
strval);
g_free (strval);
}
}
|