#include "gtkmenu.h"
#include "gtkmenuitem.h"
#include "gtkmenushell.h"
+#include "gtkpressandholdprivate.h"
#include "gtkprivate.h"
#include "gtkintl.h"
-#include "a11y/gtkcolorswatchaccessible.h"
+#include "a11y/gtkcolorswatchaccessibleprivate.h"
-typedef struct {
- GtkWidget *widget;
-
- GdkEventSequence *sequence;
- guint press_and_hold_id;
- gint start_x;
- gint start_y;
-} GtkPressAndHoldData;
-
struct _GtkColorSwatchPrivate
{
GdkRGBA color;
GdkWindow *event_window;
- GtkPressAndHoldData *press_and_hold;
+ GtkPressAndHold *press_and_hold;
};
enum
{
cairo_save (cr);
- _gtk_rounded_box_path (&background.clip_box, cr);
+ _gtk_rounded_box_path (&background.padding_box, cr);
cairo_clip_preserve (cr);
cairo_set_source_rgb (cr, 0.33, 0.33, 0.33);
cairo_set_source_rgba (cr, 1., 1., 1., 0.4);
else
cairo_set_source_rgba (cr, 0., 0., 0., 0.4);
- _gtk_rounded_box_shrink (&background.clip_box, 3, 3, 3, 3);
- _gtk_rounded_box_path (&background.clip_box, cr);
- cairo_stroke (cr);
+ _gtk_rounded_box_shrink (&background.padding_box, 3, 3, 3, 3);
+ _gtk_rounded_box_path (&background.padding_box, cr);
+ cairo_stroke (cr);
}
if (swatch->priv->icon)
g_object_unref (pixbuf);
}
- gtk_icon_info_free (icon_info);
+ g_object_unref (icon_info);
}
cairo_restore (cr);
}
static void
-swatch_press_and_hold_cancel (GtkWidget *widget,
- GtkPressAndHoldData *data)
+hold_action (GtkPressAndHold *pah,
+ gint x,
+ gint y,
+ GtkColorSwatch *swatch)
{
- if (data->press_and_hold_id)
- {
- g_source_remove (data->press_and_hold_id);
- data->press_and_hold_id = 0;
- }
-
- data->sequence = NULL;
+ emit_customize (swatch);
}
static void
-swatch_press_and_hold_free (GtkPressAndHoldData *data)
+tap_action (GtkPressAndHold *pah,
+ gint x,
+ gint y,
+ GtkColorSwatch *swatch)
{
- swatch_press_and_hold_cancel (data->widget, data);
- g_slice_free (GtkPressAndHoldData, data);
-}
-
-static gboolean
-swatch_press_and_hold_action (gpointer data)
-{
- GtkPressAndHoldData *pah = data;
-
- emit_customize (GTK_COLOR_SWATCH (pah->widget));
- swatch_press_and_hold_cancel (pah->widget, pah);
-
- return G_SOURCE_REMOVE;
+ swatch_primary_action (swatch);
}
-
static gboolean
swatch_touch (GtkWidget *widget,
GdkEventTouch *event)
{
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
- GtkPressAndHoldData *data;
if (!swatch->priv->press_and_hold)
- swatch->priv->press_and_hold = g_slice_new0 (GtkPressAndHoldData);
+ {
+ gint drag_threshold;
- data = swatch->priv->press_and_hold;
+ g_object_get (gtk_widget_get_settings (widget),
+ "gtk-dnd-drag-threshold", &drag_threshold,
+ NULL);
- /* We're already tracking a different touch, ignore */
- if (data->sequence != NULL && data->sequence != event->sequence)
- return TRUE;
+ swatch->priv->press_and_hold = gtk_press_and_hold_new ();
- if (event->type == GDK_TOUCH_BEGIN)
- {
- data->widget = widget;
- data->sequence = event->sequence;
- data->start_x = event->x;
- data->start_y = event->y;
+ g_object_set (swatch->priv->press_and_hold,
+ "drag-threshold", drag_threshold,
+ "hold-time", 1000,
+ NULL);
- data->press_and_hold_id =
- gdk_threads_add_timeout (1000, swatch_press_and_hold_action, data);
- }
- else if (event->type == GDK_TOUCH_UPDATE)
- {
- if (gtk_drag_check_threshold (widget,
- data->start_x, data->start_y,
- event->x, event->y))
- swatch_press_and_hold_cancel (widget, data);
- }
- else if (event->type == GDK_TOUCH_END)
- {
- swatch_press_and_hold_cancel (widget, data);
- swatch_primary_action (swatch);
- }
- else if (event->type == GDK_TOUCH_CANCEL)
- {
- swatch_press_and_hold_cancel (widget, data);
+ g_signal_connect (swatch->priv->press_and_hold, "hold",
+ G_CALLBACK (hold_action), swatch);
+ g_signal_connect (swatch->priv->press_and_hold, "tap",
+ G_CALLBACK (tap_action), swatch);
}
+ gtk_press_and_hold_process_event (swatch->priv->press_and_hold, (GdkEvent *)event);
+
return TRUE;
}
swatch->priv->event_window =
gdk_window_new (window,
&attributes, attributes_mask);
- gdk_window_set_user_data (swatch->priv->event_window, widget);
+ gtk_widget_register_window (widget, swatch->priv->event_window);
}
static void
if (swatch->priv->event_window)
{
- gdk_window_set_user_data (swatch->priv->event_window, NULL);
+ gtk_widget_unregister_window (widget, swatch->priv->event_window);
gdk_window_destroy (swatch->priv->event_window);
swatch->priv->event_window = NULL;
}
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
g_free (swatch->priv->icon);
- if (swatch->priv->press_and_hold)
- swatch_press_and_hold_free (swatch->priv->press_and_hold);
+ g_clear_object (&swatch->priv->press_and_hold);
G_OBJECT_CLASS (gtk_color_swatch_parent_class)->finalize (object);
}