[gtk+] colorscale: Select for touch events
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] colorscale: Select for touch events
- Date: Sun, 4 Mar 2012 16:24:58 +0000 (UTC)
commit a986cb4a765a72fc30534d1a035e4def23066b90
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Mar 4 11:22:44 2012 -0500
colorscale: Select for touch events
We use long touches to trigger the popup.
gtk/gtkcolorscale.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkcolorscale.c b/gtk/gtkcolorscale.c
index 148a732..88e4459 100644
--- a/gtk/gtkcolorscale.c
+++ b/gtk/gtkcolorscale.c
@@ -24,6 +24,7 @@
#include "gtkorientable.h"
#include "gtkstylecontext.h"
#include "gtkaccessible.h"
+#include "gtkpressandholdprivate.h"
#include "gtkprivate.h"
#include "gtkintl.h"
@@ -35,6 +36,8 @@ struct _GtkColorScalePrivate
gint width, height;
GdkRGBA color;
GtkColorScaleType type;
+
+ GtkPressAndHold *press_and_hold;
};
enum
@@ -248,6 +251,7 @@ gtk_color_scale_init (GtkColorScale *scale)
scale->priv = G_TYPE_INSTANCE_GET_PRIVATE (scale,
GTK_TYPE_COLOR_SCALE,
GtkColorScalePrivate);
+ gtk_widget_add_events (GTK_WIDGET (scale), GDK_TOUCH_MASK);
}
static void
@@ -258,6 +262,8 @@ scale_finalize (GObject *object)
if (scale->priv->surface)
cairo_surface_destroy (scale->priv->surface);
+ g_clear_object (&scale->priv->press_and_hold);
+
G_OBJECT_CLASS (gtk_color_scale_parent_class)->finalize (object);
}
@@ -319,6 +325,48 @@ scale_set_property (GObject *object,
}
static void
+hold_action (GtkPressAndHold *pah,
+ gint x,
+ gint y,
+ GtkColorScale *scale)
+{
+ gboolean handled;
+
+ g_signal_emit_by_name (scale, "popup-menu", &handled);
+}
+
+static gboolean
+scale_touch (GtkWidget *widget,
+ GdkEventTouch *event)
+{
+ GtkColorScale *scale = GTK_COLOR_SCALE (widget);
+
+ if (!scale->priv->press_and_hold)
+ {
+ gint drag_threshold;
+
+ g_object_get (gtk_widget_get_settings (widget),
+ "gtk-dnd-drag-threshold", &drag_threshold,
+ NULL);
+
+ scale->priv->press_and_hold = gtk_press_and_hold_new ();
+
+ g_object_set (scale->priv->press_and_hold,
+ "drag-threshold", drag_threshold,
+ "hold-time", 1000,
+ NULL);
+
+ g_signal_connect (scale->priv->press_and_hold, "hold",
+ G_CALLBACK (hold_action), scale);
+ }
+
+ gtk_press_and_hold_process_event (scale->priv->press_and_hold, (GdkEvent *)event);
+
+ return GTK_WIDGET_CLASS (gtk_color_scale_parent_class)->touch_event (widget, event);
+}
+
+
+static void
gtk_color_scale_class_init (GtkColorScaleClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
@@ -329,6 +377,7 @@ gtk_color_scale_class_init (GtkColorScaleClass *class)
object_class->set_property = scale_set_property;
widget_class->draw = scale_draw;
+ widget_class->touch_event = scale_touch;
g_object_class_install_property (object_class, PROP_SCALE_TYPE,
g_param_spec_int ("scale-type", P_("Scale type"), P_("Scale type"),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]