1
0
Fork 0

Wrap g_object_class_install_properties()

GObject ≥ 2.26.0 added a nice convenience call for installing properties
from an array of GParamSpec. Since we're already storing all GParamSpec
in an array in order to use them with g_object_notify_by_pspec(), this
turns out nicely for us.

Since we do not depend on GLib 2.26 (yet), we need to provide a simple
private wrapper that implements the fall back to the default
g_object_class_install_property() call.

ClutterDragAction has been converted as a proof of concept.
This commit is contained in:
Emmanuele Bassi 2010-09-30 10:29:00 +01:00
parent f090c3ea49
commit f753b0c4a1
2 changed files with 51 additions and 37 deletions

View file

@ -107,7 +107,7 @@ enum
PROP_LAST
};
static GParamSpec *obj_props[PROP_LAST];
static GParamSpec *drag_props[PROP_LAST] = { NULL, };
enum
{
@ -466,7 +466,6 @@ clutter_drag_action_class_init (ClutterDragActionClass *klass)
{
ClutterActorMetaClass *meta_class = CLUTTER_ACTOR_META_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GParamSpec *pspec;
g_type_class_add_private (klass, sizeof (ClutterDragActionPrivate));
@ -490,14 +489,13 @@ clutter_drag_action_class_init (ClutterDragActionClass *klass)
*
* Since: 1.4
*/
pspec = g_param_spec_uint ("x-drag-threshold",
P_("Horizontal Drag Threshold"),
P_("The horizontal amount of pixels required to start dragging"),
0, G_MAXUINT,
0,
CLUTTER_PARAM_READWRITE);
obj_props[PROP_X_DRAG_THRESHOLD] = pspec;
g_object_class_install_property (gobject_class, PROP_X_DRAG_THRESHOLD, pspec);
drag_props[PROP_X_DRAG_THRESHOLD] =
g_param_spec_uint ("x-drag-threshold",
P_("Horizontal Drag Threshold"),
P_("The horizontal amount of pixels required to start dragging"),
0, G_MAXUINT,
0,
CLUTTER_PARAM_READWRITE);
/**
* ClutterDragAction:y-drag-threshold:
@ -511,14 +509,13 @@ clutter_drag_action_class_init (ClutterDragActionClass *klass)
*
* Since: 1.4
*/
pspec = g_param_spec_uint ("y-drag-threshold",
P_("Vertical Drag Threshold"),
P_("The vertical amount of pixels required to start dragging"),
0, G_MAXUINT,
0,
CLUTTER_PARAM_READWRITE);
obj_props[PROP_Y_DRAG_THRESHOLD] = pspec;
g_object_class_install_property (gobject_class, PROP_Y_DRAG_THRESHOLD, pspec);
drag_props[PROP_Y_DRAG_THRESHOLD] =
g_param_spec_uint ("y-drag-threshold",
P_("Vertical Drag Threshold"),
P_("The vertical amount of pixels required to start dragging"),
0, G_MAXUINT,
0,
CLUTTER_PARAM_READWRITE);
/**
* ClutterDragAction:drag-handle:
@ -534,13 +531,12 @@ clutter_drag_action_class_init (ClutterDragActionClass *klass)
*
* Since: 1.4
*/
pspec = g_param_spec_object ("drag-handle",
P_("Drag Handle"),
P_("The actor that is being dragged"),
CLUTTER_TYPE_ACTOR,
CLUTTER_PARAM_READWRITE);
obj_props[PROP_DRAG_HANDLE] = pspec;
g_object_class_install_property (gobject_class, PROP_DRAG_HANDLE, pspec);
drag_props[PROP_DRAG_HANDLE] =
g_param_spec_object ("drag-handle",
P_("Drag Handle"),
P_("The actor that is being dragged"),
CLUTTER_TYPE_ACTOR,
CLUTTER_PARAM_READWRITE);
/**
* ClutterDragAction:drag-axis:
@ -549,14 +545,15 @@ clutter_drag_action_class_init (ClutterDragActionClass *klass)
*
* Since: 1.4
*/
pspec = g_param_spec_enum ("drag-axis",
P_("Drag Axis"),
P_("Constraints the dragging to an axis"),
CLUTTER_TYPE_DRAG_AXIS,
CLUTTER_DRAG_AXIS_NONE,
CLUTTER_PARAM_READWRITE);
obj_props[PROP_DRAG_AXIS] = pspec;
g_object_class_install_property (gobject_class, PROP_DRAG_AXIS, pspec);
drag_props[PROP_DRAG_AXIS] =
g_param_spec_enum ("drag-axis",
P_("Drag Axis"),
P_("Constraints the dragging to an axis"),
CLUTTER_TYPE_DRAG_AXIS,
CLUTTER_DRAG_AXIS_NONE,
CLUTTER_PARAM_READWRITE);
_clutter_object_class_install_properties (klass, PROP_LAST, drag_props);
/**
* ClutterDragAction::drag-begin:
@ -711,14 +708,14 @@ clutter_drag_action_set_drag_threshold (ClutterDragAction *action,
{
priv->x_drag_threshold = x_threshold;
_clutter_notify_by_pspec (self, obj_props[PROP_X_DRAG_THRESHOLD]);
_clutter_notify_by_pspec (self, drag_props[PROP_X_DRAG_THRESHOLD]);
}
if (priv->y_drag_threshold != y_threshold)
{
priv->y_drag_threshold = y_threshold;
_clutter_notify_by_pspec (self, obj_props[PROP_Y_DRAG_THRESHOLD]);
_clutter_notify_by_pspec (self, drag_props[PROP_Y_DRAG_THRESHOLD]);
}
g_object_thaw_notify (self);
@ -775,7 +772,7 @@ clutter_drag_action_set_drag_handle (ClutterDragAction *action,
priv->drag_handle = handle;
_clutter_notify_by_pspec (G_OBJECT (action), obj_props[PROP_DRAG_HANDLE]);
_clutter_notify_by_pspec (G_OBJECT (action), drag_props[PROP_DRAG_HANDLE]);
}
/**
@ -823,7 +820,7 @@ clutter_drag_action_set_drag_axis (ClutterDragAction *action,
priv->drag_axis = axis;
_clutter_notify_by_pspec (G_OBJECT (action), obj_props[PROP_DRAG_AXIS]);
_clutter_notify_by_pspec (G_OBJECT (action), drag_props[PROP_DRAG_AXIS]);
}
/**

View file

@ -549,6 +549,23 @@ gpointer _clutter_event_get_platform_data (const ClutterEvent *event);
#endif
/* wrapper for g_object_class_install_properties() */
static inline void
_clutter_object_class_install_properties (gpointer oclass,
guint n_pspecs,
GParamSpec **pspecs)
{
#if GLIB_CHECK_VERSION (2, 26, 0)
g_object_class_install_properties (oclass, n_pspecs, pspecs);
#else
int i;
/* XXX - we start at 1 because 0 is a reserved property id */
for (i = 1; i < n_pspecs; i++)
g_object_class_install_property (oclass, i, pspecs[i]);
#endif
}
void _clutter_paint_volume_init_static (ClutterActor *actor,
ClutterPaintVolume *pv);
ClutterPaintVolume *_clutter_paint_volume_new (ClutterActor *actor);