cssnodedeclaration: Add possibility to set the name

This is supposed to be a replacement for setting the type. So far, both
options are possible - either will unset the other.
This commit is contained in:
Benjamin Otte 2015-09-04 19:38:50 +02:00
parent b65f400d56
commit 26450a661e
2 changed files with 35 additions and 1 deletions

View File

@ -33,6 +33,7 @@ struct _GtkCssNodeDeclaration {
guint refcount;
GtkJunctionSides junction_sides;
GType type;
const /* interned */ char *name;
const /* interned */ char *id;
GtkStateFlags state;
guint n_classes;
@ -118,6 +119,9 @@ gtk_css_node_declaration_new (void)
1, /* need to own a ref ourselves so the copy-on-write path kicks in when people change things */
0,
0,
NULL,
NULL,
0,
0,
0
};
@ -166,10 +170,12 @@ gboolean
gtk_css_node_declaration_set_type (GtkCssNodeDeclaration **decl,
GType type)
{
if ((*decl)->type == type)
if ((*decl)->type == type &&
(*decl)->name == NULL)
return FALSE;
gtk_css_node_declaration_make_writable (decl);
(*decl)->name = NULL;
(*decl)->type = type;
return TRUE;
@ -181,6 +187,27 @@ gtk_css_node_declaration_get_type (const GtkCssNodeDeclaration *decl)
return decl->type;
}
gboolean
gtk_css_node_declaration_set_name (GtkCssNodeDeclaration **decl,
/*interned*/ const char *name)
{
if ((*decl)->type == 0 &&
(*decl)->name == name)
return FALSE;
gtk_css_node_declaration_make_writable (decl);
(*decl)->type = 0;
(*decl)->name = name;
return TRUE;
}
/*interned*/ const char *
gtk_css_node_declaration_get_name (const GtkCssNodeDeclaration *decl)
{
return decl->name;
}
gboolean
gtk_css_node_declaration_set_id (GtkCssNodeDeclaration **decl,
const char *id)
@ -510,6 +537,7 @@ gtk_css_node_declaration_hash (gconstpointer elem)
guint hash, i;
hash = (guint) decl->type;
hash ^= GPOINTER_TO_UINT (decl->name);
hash <<= 5;
hash ^= GPOINTER_TO_UINT (decl->id);
@ -550,6 +578,9 @@ gtk_css_node_declaration_equal (gconstpointer elem1,
if (decl1->type != decl2->type)
return FALSE;
if (decl1->name != decl2->name)
return FALSE;
if (decl1->state != decl2->state)
return FALSE;

View File

@ -34,6 +34,9 @@ GtkJunctionSides gtk_css_node_declaration_get_junction_sides (const G
gboolean gtk_css_node_declaration_set_type (GtkCssNodeDeclaration **decl,
GType type);
GType gtk_css_node_declaration_get_type (const GtkCssNodeDeclaration *decl);
gboolean gtk_css_node_declaration_set_name (GtkCssNodeDeclaration **decl,
/*interned*/ const char *name);
/*interned*/ const char*gtk_css_node_declaration_get_name (const GtkCssNodeDeclaration *decl);
gboolean gtk_css_node_declaration_set_id (GtkCssNodeDeclaration **decl,
const char *id);
const char * gtk_css_node_declaration_get_id (const GtkCssNodeDeclaration *decl);