event-controller: Add widget property to SugarEventController
controllers were already intrinsically related to a widget, so set a property so controllers have a back reference to the widget they attach to Signed-off-by: Carlos Garnacho <carlos@lanedo.com> Acked-by: Simon Schampijer <simon@laptop.org>
This commit is contained in:
parent
7d0a6e25af
commit
63ff76b95f
@ -24,9 +24,11 @@
|
|||||||
|
|
||||||
typedef struct _SugarControllerItem SugarControllerItem;
|
typedef struct _SugarControllerItem SugarControllerItem;
|
||||||
typedef struct _SugarControllerWidgetData SugarControllerWidgetData;
|
typedef struct _SugarControllerWidgetData SugarControllerWidgetData;
|
||||||
|
typedef struct _SugarEventControllerPriv SugarEventControllerPriv;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PROP_STATE = 1
|
PROP_STATE = 1,
|
||||||
|
PROP_WIDGET
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -35,6 +37,11 @@ enum {
|
|||||||
LAST_SIGNAL
|
LAST_SIGNAL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct _SugarEventControllerPriv
|
||||||
|
{
|
||||||
|
GtkWidget *widget;
|
||||||
|
};
|
||||||
|
|
||||||
struct _SugarControllerItem
|
struct _SugarControllerItem
|
||||||
{
|
{
|
||||||
SugarEventController *controller;
|
SugarEventController *controller;
|
||||||
@ -61,6 +68,10 @@ sugar_event_controller_get_property (GObject *object,
|
|||||||
GValue *value,
|
GValue *value,
|
||||||
GParamSpec *pspec)
|
GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
|
SugarEventControllerPriv *priv;
|
||||||
|
|
||||||
|
priv = SUGAR_EVENT_CONTROLLER (object)->_priv;
|
||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
case PROP_STATE:
|
case PROP_STATE:
|
||||||
@ -71,6 +82,29 @@ sugar_event_controller_get_property (GObject *object,
|
|||||||
g_value_set_enum (value, state);
|
g_value_set_enum (value, state);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case PROP_WIDGET:
|
||||||
|
g_value_set_object (value, priv->widget);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sugar_event_controller_set_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
const GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
SugarEventControllerPriv *priv;
|
||||||
|
|
||||||
|
priv = SUGAR_EVENT_CONTROLLER (object)->_priv;
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_WIDGET:
|
||||||
|
priv->widget = g_value_get_object (value);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
}
|
}
|
||||||
@ -82,6 +116,7 @@ sugar_event_controller_class_init (SugarEventControllerClass *klass)
|
|||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
|
|
||||||
object_class->get_property = sugar_event_controller_get_property;
|
object_class->get_property = sugar_event_controller_get_property;
|
||||||
|
object_class->set_property = sugar_event_controller_set_property;
|
||||||
|
|
||||||
g_object_class_install_property (object_class,
|
g_object_class_install_property (object_class,
|
||||||
PROP_STATE,
|
PROP_STATE,
|
||||||
@ -94,6 +129,16 @@ sugar_event_controller_class_init (SugarEventControllerClass *klass)
|
|||||||
G_PARAM_STATIC_NAME |
|
G_PARAM_STATIC_NAME |
|
||||||
G_PARAM_STATIC_NICK |
|
G_PARAM_STATIC_NICK |
|
||||||
G_PARAM_STATIC_BLURB));
|
G_PARAM_STATIC_BLURB));
|
||||||
|
g_object_class_install_property (object_class,
|
||||||
|
PROP_WIDGET,
|
||||||
|
g_param_spec_object ("widget",
|
||||||
|
"Widget",
|
||||||
|
"Widget the controller is attached to",
|
||||||
|
GTK_TYPE_WIDGET,
|
||||||
|
G_PARAM_READWRITE |
|
||||||
|
G_PARAM_STATIC_NAME |
|
||||||
|
G_PARAM_STATIC_NICK |
|
||||||
|
G_PARAM_STATIC_BLURB));
|
||||||
signals[STARTED] =
|
signals[STARTED] =
|
||||||
g_signal_new ("started",
|
g_signal_new ("started",
|
||||||
G_TYPE_FROM_CLASS (klass),
|
G_TYPE_FROM_CLASS (klass),
|
||||||
@ -111,12 +156,16 @@ sugar_event_controller_class_init (SugarEventControllerClass *klass)
|
|||||||
g_cclosure_marshal_VOID__VOID,
|
g_cclosure_marshal_VOID__VOID,
|
||||||
G_TYPE_NONE, 0);
|
G_TYPE_NONE, 0);
|
||||||
|
|
||||||
|
g_type_class_add_private (object_class, sizeof (SugarEventControllerPriv));
|
||||||
quark_widget_controller_data = g_quark_from_static_string ("sugar-widget-controller-data");
|
quark_widget_controller_data = g_quark_from_static_string ("sugar-widget-controller-data");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sugar_event_controller_init (SugarEventController *controller)
|
sugar_event_controller_init (SugarEventController *controller)
|
||||||
{
|
{
|
||||||
|
controller->_priv = G_TYPE_INSTANCE_GET_PRIVATE (controller,
|
||||||
|
SUGAR_TYPE_EVENT_CONTROLLER,
|
||||||
|
SugarEventControllerPriv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -300,6 +349,7 @@ sugar_event_controller_attach (SugarEventController *controller,
|
|||||||
G_CALLBACK (_sugar_event_controller_state_notify),
|
G_CALLBACK (_sugar_event_controller_state_notify),
|
||||||
widget);
|
widget);
|
||||||
g_array_append_val (data->controllers, item);
|
g_array_append_val (data->controllers, item);
|
||||||
|
g_object_set (controller, "widget", widget, NULL);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -328,6 +378,7 @@ sugar_event_controller_detach (SugarEventController *controller,
|
|||||||
if (item->controller == controller)
|
if (item->controller == controller)
|
||||||
{
|
{
|
||||||
sugar_event_controller_reset (item->controller);
|
sugar_event_controller_reset (item->controller);
|
||||||
|
g_object_set (controller, "widget", NULL, NULL);
|
||||||
g_object_unref (item->controller);
|
g_object_unref (item->controller);
|
||||||
g_signal_handler_disconnect (item->controller,
|
g_signal_handler_disconnect (item->controller,
|
||||||
item->notify_handler_id);
|
item->notify_handler_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user