[grits] Add clicked signal to GritsObject
- From: Andy Spencer <andys src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grits] Add clicked signal to GritsObject
- Date: Tue, 3 Jan 2012 01:19:13 +0000 (UTC)
commit 7940344c1faea5b80fb39b44419b508568d3a6fc
Author: Andy Spencer <andy753421 gmail com>
Date: Sat Oct 15 09:20:50 2011 +0000
Add clicked signal to GritsObject
Using mouse-down/mouse-up is rather not helpful since GritsViewer does a
lot with mouse drags.
src/objects/grits-object.c | 34 +++++++++++++++++++++++++++++++---
src/objects/grits-object.h | 1 +
2 files changed, 32 insertions(+), 3 deletions(-)
---
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 */
@@ -258,6 +269,23 @@ static void grits_object_class_init(GritsObjectClass *klass)
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.
* @event: the GdkEventButton which triggered this signal
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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]