![]() |
![]() |
![]() |
Netbook Toolkit Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
NbtkStylableIface; void nbtk_stylable_iface_install_property (NbtkStylableIface *iface, GType owner_type, GParamSpec *pspec); void nbtk_stylable_freeze_notify (NbtkStylable *stylable); void nbtk_stylable_notify (NbtkStylable *stylable, const gchar *property_name); void nbtk_stylable_thaw_notify (NbtkStylable *stylable); GParamSpec ** nbtk_stylable_list_properties (NbtkStylable *stylable, guint *n_props); GParamSpec * nbtk_stylable_find_property (NbtkStylable *stylable, const gchar *property_name); void nbtk_stylable_set_style (NbtkStylable *stylable, NbtkStyle *style); NbtkStyle * nbtk_stylable_get_style (NbtkStylable *stylable); void nbtk_stylable_get (NbtkStylable *stylable, const gchar *first_property_name, ...); void nbtk_stylable_get_property (NbtkStylable *stylable, const gchar *property_name, GValue *value); gboolean nbtk_stylable_get_default_value (NbtkStylable *stylable, const gchar *property_name, GValue *value_out); NbtkStylable* nbtk_stylable_get_container (NbtkStylable *stylable); NbtkStylable* nbtk_stylable_get_base_style (NbtkStylable *stylable); const gchar* nbtk_stylable_get_style_id (NbtkStylable *stylable); const gchar* nbtk_stylable_get_style_type (NbtkStylable *stylable); const gchar* nbtk_stylable_get_style_class (NbtkStylable *stylable); const gchar* nbtk_stylable_get_pseudo_class (NbtkStylable *stylable); gchar* nbtk_stylable_get_attribute (NbtkStylable *stylable, const gchar *name); gboolean nbtk_stylable_get_viewport (NbtkStylable *stylable, gint *x, gint *y, gint *width, gint *height); void nbtk_stylable_changed (NbtkStylable *stylable);
Stylable objects are classes that can have "style properties", that is properties that can be changed by attaching a NbtkStyle to them.
Objects can choose to subclass NbtkWidget, and thus inherit all the NbtkWidget style properties; or they can subclass NbtkWidget and reimplement the NbtkStylable interface to add new style properties specific for them (and their subclasses); or, finally, they can simply subclass GObject and implement NbtkStylable to install new properties.
typedef struct { GTypeInterface g_iface; /* virtual functions */ NbtkStyle *(* get_style) (NbtkStylable *stylable); void (* set_style) (NbtkStylable *stylable, NbtkStyle *style); /* context virtual functions */ NbtkStylable *(*get_container) (NbtkStylable *stylable); NbtkStylable *(*get_base_style) (NbtkStylable *stylable); const gchar *(*get_style_id) (NbtkStylable *stylable); const gchar *(*get_style_type) (NbtkStylable *stylable); const gchar *(*get_style_class) (NbtkStylable *stylable); const gchar *(*get_pseudo_class) (NbtkStylable *stylable); gchar *(*get_attribute) (NbtkStylable *stylable, const gchar *name); gboolean (*get_viewport) (NbtkStylable *stylable, gint *x, gint *y, gint *width, gint *height); /* signals, not vfuncs */ void (* style_notify) (NbtkStylable *stylable, GParamSpec *pspec); void (* style_changed) (NbtkStylable *stylable); void (* stylable_changed) (NbtkStylable *stylable); } NbtkStylableIface;
void nbtk_stylable_iface_install_property (NbtkStylableIface *iface, GType owner_type, GParamSpec *pspec);
Installs a property for owner_type
using pspec
as the property
description.
This function should be used inside the NbtkStylableIface initialization function of a class, for instance:
G_DEFINE_TYPE_WITH_CODE (FooActor, foo_actor, CLUTTER_TYPE_ACTOR, G_IMPLEMENT_INTERFACE (NBTK_TYPE_STYLABLE, nbtk_stylable_init)); ... static void nbtk_stylable_init (NbtkStylableIface *iface) { static gboolean is_initialized = FALSE; if (!is_initialized) { ... nbtk_stylable_iface_install_property (stylable, FOO_TYPE_ACTOR, g_param_spec_int ("x-spacing", "X Spacing", "Horizontal spacing", -1, G_MAXINT, 2, G_PARAM_READWRITE)); ... } }
|
a NbtkStylableIface |
|
GType of the style property owner |
|
a GParamSpec |
void nbtk_stylable_freeze_notify (NbtkStylable *stylable);
|
void nbtk_stylable_notify (NbtkStylable *stylable, const gchar *property_name);
|
|
|
GParamSpec ** nbtk_stylable_list_properties (NbtkStylable *stylable, guint *n_props);
Retrieves all the GParamSpecs installed by stylable
.
|
a NbtkStylable |
|
return location for the number of properties, or NULL
|
Returns : |
an array of GParamSpecs. Free it with
g_free() when done.
|
GParamSpec * nbtk_stylable_find_property (NbtkStylable *stylable, const gchar *property_name);
Finds the GParamSpec installed by stylable
for the property
with property_name
.
|
a NbtkStylable |
|
the name of the property to find |
Returns : |
a GParamSpec for the given property, or NULL if
no property with that name was found
|
void nbtk_stylable_set_style (NbtkStylable *stylable, NbtkStyle *style);
Sets style
as the new NbtkStyle to be used by stylable
.
The NbtkStylable will take ownership of the passed NbtkStyle.
After the NbtkStle has been set, the NbtkStylable::style-set signal will be emitted.
|
a NbtkStylable |
|
a NbtkStyle |
NbtkStyle * nbtk_stylable_get_style (NbtkStylable *stylable);
Retrieves the NbtkStyle used by stylable
. This function does not
alter the reference count of the returned object.
|
a NbtkStylable |
Returns : |
a NbtkStyle |
void nbtk_stylable_get (NbtkStylable *stylable, const gchar *first_property_name, ...);
Gets the style properties for stylable
.
In general, a copy is made of the property contents and the called is responsible for freeing the memory in the appropriate manner for the property type.
Example 1. Using nbtk_stylable_get()
An example of using nbtk_stylable_get()
to get the contents of
two style properties - one of type G_TYPE_INT and one of type
""
gint x_spacing; ClutterColor *bg_color; nbtk_stylable_get (stylable, "x-spacing", &x_spacing, "bg-color", &bg_color, NULL); /* do something with x_spacing and bg_color */ clutter_color_free (bg_color);
|
a NbtkStylable |
|
name of the first property to get |
|
return location for the first property, followed optionally
by more name/return location pairs, followed by NULL
|
void nbtk_stylable_get_property (NbtkStylable *stylable, const gchar *property_name, GValue *value);
Retrieves the value of property_name
for stylable
, and puts it
into value
.
|
a NbtkStylable |
|
the name of the property |
|
return location for an empty GValue |
gboolean nbtk_stylable_get_default_value (NbtkStylable *stylable, const gchar *property_name, GValue *value_out);
Query stylable
for the default value of property property_name
and
fill value_out
with the result.
|
a NbtkStylable |
|
name of the property to query |
|
return location for the default value |
Returns : |
TRUE if property property_name exists and the default value has
been returned.
|
NbtkStylable* nbtk_stylable_get_container (NbtkStylable *stylable);
Obtain the parent NbtkStylable that contains stylable
.
|
a NbtkStylable |
Returns : |
The parent NbtkStylable |
NbtkStylable* nbtk_stylable_get_base_style (NbtkStylable *stylable);
Get the parent ancestor NbtkStylable of stylable
.
|
a NbtkStylable |
Returns : |
the parent NbtkStylable |
const gchar* nbtk_stylable_get_style_id (NbtkStylable *stylable);
Get the ID value of stylable
|
a NbtkStylable |
Returns : |
the id of stylable
|
const gchar* nbtk_stylable_get_style_type (NbtkStylable *stylable);
Get the type name of stylable
|
a NbtkStylable |
Returns : |
the type name of stylable
|
const gchar* nbtk_stylable_get_style_class (NbtkStylable *stylable);
Get the style class name of stylable
|
a NbtkStylable |
Returns : |
the type name of stylable
|
const gchar* nbtk_stylable_get_pseudo_class (NbtkStylable *stylable);
Get the pseudo class name of stylable
|
a NbtkStylable |
Returns : |
the pseudo class name of stylable
|
gchar* nbtk_stylable_get_attribute (NbtkStylable *stylable, const gchar *name);
Get the named attribute from stylable
|
a NbtkStylable |
|
attribute name |
Returns : |
the value of the attribute |
gboolean nbtk_stylable_get_viewport (NbtkStylable *stylable, gint *x, gint *y, gint *width, gint *height);
Obtain the position and dimensions of stylable
.
|
a NbtkStylable |
|
location to store X coordinate |
|
location to store Y coordinate |
|
location to store width |
|
location to store height |
Returns : |
true if the function succeeded |