1 /* -*- Mode: C; indent-tabs-mode: ni; c-basic-offset: 8 -*- */
4 * This file is part of The Croco Library
6 * Copyright (C) 2002-2004 Dodji Seketeli
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of version 2.1 of the GNU Lesser General Public
10 * License as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 #include "cr-stylesheet.h"
29 *The definition of the #CRStyleSheet class
33 *Constructor of the #CRStyleSheet class.
34 *@param the initial list of css statements.
35 *@return the newly built css2 stylesheet, or NULL in case of error.
38 cr_stylesheet_new (CRStatement * a_stmts)
42 result = g_try_malloc (sizeof (CRStyleSheet));
44 cr_utils_trace_info ("Out of memory");
48 memset (result, 0, sizeof (CRStyleSheet));
51 result->statements = a_stmts;
57 *@param a_this the current instance of #CRStyleSheet
58 *@return the serialized stylesheet.
61 cr_stylesheet_to_string (CRStyleSheet *a_this)
64 GString *stringue = NULL;
65 CRStatement *cur_stmt = NULL;
67 g_return_val_if_fail (a_this, NULL);
69 if (a_this->statements) {
70 stringue = g_string_new (NULL) ;
71 g_return_val_if_fail (stringue, NULL) ;
73 for (cur_stmt = a_this->statements;
74 cur_stmt; cur_stmt = cur_stmt->next) {
76 g_string_append (stringue, "\n\n") ;
78 str = cr_statement_to_string (cur_stmt, 0) ;
80 g_string_append (stringue, str) ;
87 g_string_free (stringue, FALSE) ;
94 *Dumps the current css2 stylesheet to a file.
95 *@param a_this the current instance of #CRStyleSheet.
96 *@param a_fp the destination file
99 cr_stylesheet_dump (CRStyleSheet * a_this, FILE * a_fp)
103 g_return_if_fail (a_this);
105 str = cr_stylesheet_to_string (a_this) ;
107 fprintf (a_fp, "%s", str) ;
114 *Return the number of rules in the stylesheet.
115 *@param a_this the current instance of #CRStyleSheet.
116 *@return number of rules in the stylesheet.
119 cr_stylesheet_nr_rules (CRStyleSheet * a_this)
121 g_return_val_if_fail (a_this, -1);
123 return cr_statement_nr_rules (a_this->statements);
127 *Use an index to get a CRStatement from the rules in a given stylesheet.
128 *@param a_this the current instance of #CRStatement.
129 *@param itemnr the index into the rules.
130 *@return CRStatement at position itemnr, if itemnr > number of rules - 1,
131 *it will return NULL.
134 cr_stylesheet_statement_get_from_list (CRStyleSheet * a_this, int itemnr)
136 g_return_val_if_fail (a_this, NULL);
138 return cr_statement_get_from_list (a_this->statements, itemnr);
142 cr_stylesheet_ref (CRStyleSheet * a_this)
144 g_return_if_fail (a_this);
150 cr_stylesheet_unref (CRStyleSheet * a_this)
152 g_return_val_if_fail (a_this, FALSE);
154 if (a_this->ref_count)
157 if (!a_this->ref_count) {
158 cr_stylesheet_destroy (a_this);
166 *Destructor of the #CRStyleSheet class.
167 *@param a_this the current instance of the #CRStyleSheet class.
170 cr_stylesheet_destroy (CRStyleSheet * a_this)
172 g_return_if_fail (a_this);
174 if (a_this->statements) {
175 cr_statement_destroy (a_this->statements);
176 a_this->statements = NULL;