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