From 6a2cb75412be707fd68b20399e2e1376b10b9f33 Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Sun, 29 Feb 2004 11:54:43 +0000 Subject: applied a patch from Rob BUIS that provides new apis to manipulate CSS 2004-02-29 Dodji Seketeli * src/cr-statement.[ch],src/cr-stylesheet.[ch]: applied a patch from Rob BUIS that provides new apis to manipulate CSS statements. --- ChangeLog | 6 +++++ src/cr-statement.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/cr-statement.h | 12 +++++++++ src/cr-stylesheet.c | 28 ++++++++++++++++++++ src/cr-stylesheet.h | 6 +++++ 5 files changed, 125 insertions(+) diff --git a/ChangeLog b/ChangeLog index a80c22f..5a944bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-02-29 Dodji Seketeli + + * src/cr-statement.[ch],src/cr-stylesheet.[ch]: + applied a patch from Rob BUIS that provides new apis + to manipulate CSS statements. + 2004-02-29 Dodji Seketeli * src/cr-sel-eng.c: diff --git a/src/cr-statement.c b/src/cr-statement.c index b675826..b8ff481 100644 --- a/src/cr-statement.c +++ b/src/cr-statement.c @@ -752,6 +752,45 @@ cr_statement_dump_page (CRStatement *a_this, FILE *a_fp, gulong a_indent) } } +/** + *Return the number of rules in the statement list; + *@param a_this the current instance of #CRStatement. + *@return number of rules in the statement list. + */ +int +cr_statement_nr_rules (CRStatement *a_this) +{ + CRStatement *cur = NULL ; + int nr = 0; + + g_return_val_if_fail (a_this, -1) ; + + for (cur = a_this ; cur ; cur = cur->next) + nr ++; + return nr; +} + +/** + *Use an index to get a CRStatement from the statement list. + *@param a_this the current instance of #CRStatement. + *@param itemnr the index into the statement list. + *@return CRStatement at position itemnr, if itemnr > number of statements - 1, + *it will return NULL. + */ +CRStatement * +cr_statement_get_from_list (CRStatement *a_this, int itemnr) +{ + CRStatement *cur = NULL ; + int nr = 0; + + g_return_val_if_fail (a_this, NULL) ; + + for (cur = a_this ; cur ; cur = cur->next) + if (nr++ == itemnr) + return cur; + return NULL; +} + /** *Dumps an @media rule statement to a file. *@param a_this the statement to dump. @@ -2107,6 +2146,40 @@ cr_statement_at_import_rule_get_url (CRStatement *a_this, return CR_OK ; } +/** + *Return the number of rules in the media rule; + *@param a_this the current instance of #CRStatement. + *@return number of rules in the media rule. + */ +int +cr_statement_at_media_nr_rules (CRStatement *a_this) +{ + g_return_val_if_fail (a_this + && a_this->type == AT_MEDIA_RULE_STMT + && a_this->kind.media_rule, + CR_BAD_PARAM_ERROR) ; + + return cr_statement_nr_rules (a_this->kind.media_rule->rulesets); +} + +/** + *Use an index to get a CRStatement from the media rule list of rules. + *@param a_this the current instance of #CRStatement. + *@param itemnr the index into the media rule list of rules. + *@return CRStatement at position itemnr, if itemnr > number of rules - 1, + *it will return NULL. + */ +CRStatement * +cr_statement_at_media_get_from_list (CRStatement *a_this, int itemnr) +{ + g_return_val_if_fail (a_this + && a_this->type == AT_MEDIA_RULE_STMT + && a_this->kind.media_rule, + NULL) ; + + return cr_statement_get_from_list (a_this->kind.media_rule->rulesets, itemnr); +} + /** *Sets a declaration list to the current @page rule statement. *@param a_this the current @page rule statement. diff --git a/src/cr-statement.h b/src/cr-statement.h index b052c26..78a38b4 100644 --- a/src/cr-statement.h +++ b/src/cr-statement.h @@ -350,6 +350,12 @@ enum CRStatus cr_statement_at_import_rule_get_url (CRStatement *a_this, GString **a_url) ; +int +cr_statement_at_media_nr_rules (CRStatement *a_this) ; + +CRStatement * +cr_statement_at_media_get_from_list (CRStatement *a_this, int itemnr) ; + enum CRStatus cr_statement_at_page_rule_set_sel (CRStatement *a_this, CRSelector *a_sel) ; @@ -390,6 +396,12 @@ cr_statement_at_font_face_rule_add_decl (CRStatement *a_this, void cr_statement_dump (CRStatement *a_this, FILE *a_fp, gulong a_indent) ; +int +cr_statement_nr_rules (CRStatement *a_this) ; + +CRStatement * +cr_statement_get_from_list (CRStatement *a_this, int itemnr) ; + void cr_statement_destroy (CRStatement *a_this) ; diff --git a/src/cr-stylesheet.c b/src/cr-stylesheet.c index 06b1c5f..a1b8b01 100644 --- a/src/cr-stylesheet.c +++ b/src/cr-stylesheet.c @@ -78,6 +78,34 @@ cr_stylesheet_dump (CRStyleSheet *a_this, FILE *a_fp) } } +/** + *Return the number of rules in the stylesheet. + *@param a_this the current instance of #CRStyleSheet. + *@return number of rules in the stylesheet. + */ +int +cr_stylesheets_nr_rules (CRStyleSheet *a_this) +{ + g_return_val_if_fail (a_this, -1) ; + + return cr_statement_nr_rules (a_this->statements); +} + +/** + *Use an index to get a CRStatement from the rules in a given stylesheet. + *@param a_this the current instance of #CRStatement. + *@param itemnr the index into the rules. + *@return CRStatement at position itemnr, if itemnr > number of rules - 1, + *it will return NULL. + */ +CRStatement * +cr_stylesheet_statement_get_from_list (CRStyleSheet *a_this, int itemnr) +{ + g_return_val_if_fail (a_this, NULL) ; + + return cr_statement_get_from_list (a_this->statements, itemnr); +} + void cr_stylesheet_ref (CRStyleSheet *a_this) { diff --git a/src/cr-stylesheet.h b/src/cr-stylesheet.h index c850e6e..6ea3ab0 100644 --- a/src/cr-stylesheet.h +++ b/src/cr-stylesheet.h @@ -91,6 +91,12 @@ cr_stylesheet_new (CRStatement *a_stmts) ; void cr_stylesheet_dump (CRStyleSheet *a_this, FILE *a_fp) ; +int +cr_stylesheet_nr_rules (CRStyleSheet *a_this) ; + +CRStatement * +cr_stylesheet_statement_get_from_list (CRStyleSheet *a_this, int itemnr) ; + void cr_stylesheet_ref (CRStyleSheet *a_this) ; -- cgit v1.2.1