Commit a986cb4a authored by Matthias Clasen's avatar Matthias Clasen

colorscale: Select for touch events

We use long touches to trigger the popup.
parent 7192f966
......@@ -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);
}
......@@ -318,6 +324,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)
{
......@@ -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"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment