Commit d768c2cb authored by Carlos Garnacho's avatar Carlos Garnacho
Browse files

Remove GtkPressAndHold

This is replaced by GtkGestureLongPress, and all its callers have
been updated to use the replacement.
parent 4401be22
......@@ -541,7 +541,6 @@ gtk_private_h_sources = \
gtkorientableprivate.h \
gtkpango.h \
gtkpathbar.h \
gtkpressandholdprivate.h \
gtkprintoperation-private.h \
gtkprintutils.h \
gtkprivate.h \
......@@ -843,7 +842,6 @@ gtk_base_c_sources = \
gtkpapersize.c \
gtkpathbar.c \
gtkplacessidebar.c \
gtkpressandhold.c \
gtkprintcontext.c \
gtkprintoperation.c \
gtkprintoperationpreview.c \
......
/* GTK - The GIMP Toolkit
* Copyright (C) 2012 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gdk.h"
#include "gtkpressandholdprivate.h"
#include "gtkintl.h"
#include "gtkprivate.h"
struct _GtkPressAndHoldPrivate
{
gint hold_time;
gint drag_threshold;
GdkEventSequence *sequence;
GdkDevice *device;
guint button;
guint timeout;
gint start_x;
gint start_y;
gint x;
gint y;
};
enum
{
PROP_ZERO,
PROP_HOLD_TIME,
PROP_DRAG_THRESHOLD
};
enum
{
HOLD,
TAP,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
G_DEFINE_TYPE_WITH_PRIVATE (GtkPressAndHold, gtk_press_and_hold, G_TYPE_OBJECT)
static void
gtk_press_and_hold_init (GtkPressAndHold *pah)
{
pah->priv = gtk_press_and_hold_get_instance_private (pah);
pah->priv->hold_time = 1000;
pah->priv->drag_threshold = 8;
}
static void
press_and_hold_finalize (GObject *object)
{
GtkPressAndHold *pah = GTK_PRESS_AND_HOLD (object);
if (pah->priv->timeout)
g_source_remove (pah->priv->timeout);
G_OBJECT_CLASS (gtk_press_and_hold_parent_class)->finalize (object);
}
static void
press_and_hold_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkPressAndHold *pah = GTK_PRESS_AND_HOLD (object);
switch (prop_id)
{
case PROP_HOLD_TIME:
g_value_set_int (value, pah->priv->hold_time);
break;
case PROP_DRAG_THRESHOLD:
g_value_set_int (value, pah->priv->drag_threshold);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
press_and_hold_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkPressAndHold *pah = GTK_PRESS_AND_HOLD (object);
switch (prop_id)
{
case PROP_HOLD_TIME:
pah->priv->hold_time = g_value_get_int (value);
break;
case PROP_DRAG_THRESHOLD:
pah->priv->hold_time = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_press_and_hold_class_init (GtkPressAndHoldClass *class)
{
GObjectClass *object_class = (GObjectClass *)class;
object_class->get_property = press_and_hold_get_property;
object_class->set_property = press_and_hold_set_property;
object_class->finalize = press_and_hold_finalize;
signals[HOLD] =
g_signal_new ("hold",
GTK_TYPE_PRESS_AND_HOLD,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkPressAndHoldClass, hold),
NULL, NULL, NULL,
G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
signals[TAP] =
g_signal_new ("tap",
GTK_TYPE_PRESS_AND_HOLD,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkPressAndHoldClass, tap),
NULL, NULL, NULL,
G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
g_object_class_install_property (object_class, PROP_HOLD_TIME,
g_param_spec_int ("hold-time", P_("Hold Time"), P_("Hold Time (in milliseconds)"),
0, G_MAXINT, 1000, GTK_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_DRAG_THRESHOLD,
g_param_spec_int ("drag-threshold", P_("Drag Threshold"), P_("Drag Threshold (in pixels)"),
1, G_MAXINT, 8, GTK_PARAM_READWRITE));
}
static void
press_and_hold_cancel (GtkPressAndHold *pah)
{
GtkPressAndHoldPrivate *priv = pah->priv;
if (priv->timeout)
g_source_remove (priv->timeout);
priv->timeout = 0;
priv->sequence = NULL;
priv->device = NULL;
priv->button = 0;
}
static gboolean
hold_action (gpointer data)
{
GtkPressAndHold *pah = data;
GtkPressAndHoldPrivate *priv = pah->priv;
press_and_hold_cancel (pah);
g_signal_emit (pah, signals[HOLD], 0, priv->x, priv->y);
return G_SOURCE_REMOVE;
}
void
gtk_press_and_hold_process_event (GtkPressAndHold *pah,
GdkEvent *event)
{
GtkPressAndHoldPrivate *priv = pah->priv;
/* We're already tracking a different input, ignore */
if ((event->type == GDK_TOUCH_BEGIN && priv->sequence != NULL) ||
(event->type == GDK_BUTTON_PRESS && priv->device != NULL) ||
(event->type == GDK_TOUCH_UPDATE && priv->sequence != event->touch.sequence) ||
(event->type == GDK_TOUCH_END && priv->sequence != event->touch.sequence) ||
(event->type == GDK_TOUCH_CANCEL && priv->sequence != event->touch.sequence) ||
(event->type == GDK_BUTTON_RELEASE && priv->device != event->button.device) ||
(event->type == GDK_BUTTON_RELEASE && priv->button != event->button.button) ||
(event->type == GDK_MOTION_NOTIFY && priv->device != event->motion.device))
return;
if (event->type == GDK_TOUCH_BEGIN)
{
priv->sequence = event->touch.sequence;
priv->x = event->touch.x;
priv->y = event->touch.y;
priv->start_x = priv->x;
priv->start_y = priv->y;
priv->timeout =
gdk_threads_add_timeout (priv->hold_time, hold_action, pah);
g_source_set_name_by_id (priv->timeout, "[gtk+] hold_action");
}
else if (event->type == GDK_TOUCH_UPDATE)
{
priv->x = event->touch.x;
priv->y = event->touch.y;
if (ABS (priv->x - priv->start_x) > priv->drag_threshold ||
ABS (priv->y - priv->start_y) > priv->drag_threshold)
press_and_hold_cancel (pah);
}
else if (event->type == GDK_TOUCH_END)
{
press_and_hold_cancel (pah);
g_signal_emit (pah, signals[TAP], 0, priv->x, priv->y);
}
else if (event->type == GDK_TOUCH_CANCEL)
{
press_and_hold_cancel (pah);
}
else if (event->type == GDK_BUTTON_PRESS)
{
priv->device = event->button.device;
priv->button = event->button.button;
priv->x = event->button.x;
priv->y = event->button.y;
priv->start_x = priv->x;
priv->start_y = priv->y;
priv->timeout =
gdk_threads_add_timeout (priv->hold_time, hold_action, pah);
g_source_set_name_by_id (priv->timeout, "[gtk+] hold_action");
}
else if (event->type == GDK_BUTTON_RELEASE)
{
press_and_hold_cancel (pah);
}
else if (event->type == GDK_MOTION_NOTIFY)
{
priv->x = event->motion.x;
priv->y = event->motion.y;
if (ABS (priv->x - priv->start_x) > priv->drag_threshold ||
ABS (priv->y - priv->start_y) > priv->drag_threshold)
press_and_hold_cancel (pah);
}
}
GtkPressAndHold *
gtk_press_and_hold_new (void)
{
return (GtkPressAndHold *) g_object_new (GTK_TYPE_PRESS_AND_HOLD, NULL);
}
/* GTK - The GIMP Toolkit
* Copyright (C) 2012 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_PRESS_AND_HOLD_H__
#define __GTK_PRESS_AND_HOLD_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
G_BEGIN_DECLS
#define GTK_TYPE_PRESS_AND_HOLD (gtk_press_and_hold_get_type ())
#define GTK_PRESS_AND_HOLD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PRESS_AND_HOLD, GtkPressAndHold))
#define GTK_PRESS_AND_HOLD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_PRESS_AND_HOLD, GtkPressAndHoldClass))
#define GTK_IS_PRESS_AND_HOLD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_PRESS_AND_HOLD))
#define GTK_IS_PRESS_AND_HOLD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PRESS_AND_HOLD))
#define GTK_PRESS_AND_HOLD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PRESS_AND_HOLD, GtkPressAndHoldClass))
typedef struct _GtkPressAndHold GtkPressAndHold;
typedef struct _GtkPressAndHoldClass GtkPressAndHoldClass;
typedef struct _GtkPressAndHoldPrivate GtkPressAndHoldPrivate;
struct _GtkPressAndHold
{
GObject parent;
/*< private >*/
GtkPressAndHoldPrivate *priv;
};
struct _GtkPressAndHoldClass
{
GObjectClass parent_class;
void ( * hold) (GtkPressAndHold *pah, gint x, gint y);
void ( * tap) (GtkPressAndHold *pah, gint x, gint y);
};
GType gtk_press_and_hold_get_type (void) G_GNUC_CONST;
GtkPressAndHold * gtk_press_and_hold_new (void);
void gtk_press_and_hold_process_event (GtkPressAndHold *pah,
GdkEvent *event);
G_END_DECLS
#endif /* __GTK_PRESS_AND_HOLD_H__ */
Supports Markdown
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