From: Andy Spencer Date: Sat, 15 Oct 2011 09:20:50 +0000 (+0000) Subject: Add clicked signal to GritsObject X-Git-Tag: v0.6~13 X-Git-Url: http://pileus.org/git/?p=grits;a=commitdiff_plain;h=7940344c1faea5b80fb39b44419b508568d3a6fc Add clicked signal to GritsObject Using mouse-down/mouse-up is rather not helpful since GritsViewer does a lot with mouse drags. --- diff --git a/src/objects/grits-object.c b/src/objects/grits-object.c index 5eb15d9..65d7b42 100644 --- a/src/objects/grits-object.c +++ b/src/objects/grits-object.c @@ -38,6 +38,7 @@ enum { SIG_ENTER, SIG_LEAVE, + SIG_CLICKED, SIG_BUTTON_PRESS, SIG_BUTTON_RELEASE, SIG_KEY_PRESS, @@ -203,10 +204,20 @@ void grits_object_event(GritsObject *object, GdkEvent *event) }; if (!object->state.selected) return; - guint sig = signals[map[event->type]]; - if (!g_signal_has_handler_pending(object, sig, 0, FALSE)) + guint sig = map[event->type]; + + /* Handle button click */ + if (sig == SIG_BUTTON_PRESS) + object->state.clicking = TRUE; + if (sig == SIG_BUTTON_RELEASE && object->state.clicking) + g_signal_emit(object, signals[SIG_CLICKED], 0, event); + if (sig == SIG_BUTTON_RELEASE || sig == SIG_MOTION) + object->state.clicking = FALSE; + + /* Emit this signal */ + if (!g_signal_has_handler_pending(object, signals[sig], 0, FALSE)) return; - g_signal_emit(object, sig, 0, event); + g_signal_emit(object, signals[sig], 0, event); } /* GObject stuff */ @@ -257,6 +268,23 @@ static void grits_object_class_init(GritsObjectClass *klass) G_TYPE_NONE, 0); + /** + * GritsViewer::clicked: + * @object: the object. + * + * The ::clicked signal is emitted when the user clicks on the object + */ + signals[SIG_CLICKED] = g_signal_new( + "clicked", + G_TYPE_FROM_CLASS(gobject_class), + G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + /** * GritsViewer::button-press: * @object: the object. diff --git a/src/objects/grits-object.h b/src/objects/grits-object.h index 4390a41..7073576 100644 --- a/src/objects/grits-object.h +++ b/src/objects/grits-object.h @@ -40,6 +40,7 @@ typedef struct { guint picked : 1; guint selected : 1; + guint clicking : 1; } GritsState; typedef struct _GritsObject GritsObject;