]> Pileus Git - grits/commitdiff
Add clicked signal to GritsObject
authorAndy Spencer <andy753421@gmail.com>
Sat, 15 Oct 2011 09:20:50 +0000 (09:20 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sat, 15 Oct 2011 09:20:50 +0000 (09:20 +0000)
Using mouse-down/mouse-up is rather not helpful since GritsViewer does a
lot with mouse drags.

src/objects/grits-object.c
src/objects/grits-object.h

index 5eb15d96c19b31eadebf9fb0e3c037aed00c870a..65d7b420aae2e44e55e6585b327a385d104a273f 100644 (file)
@@ -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.
index 4390a41fe994cbfb3a0245e4ecc88b4c0c6ae4f2..7073576d1e58b4c8ee9f1d78136a4d1b5dc1b63f 100644 (file)
@@ -40,6 +40,7 @@
 typedef struct {
        guint picked   : 1;
        guint selected : 1;
+       guint clicking : 1;
 } GritsState;
 
 typedef struct _GritsObject      GritsObject;