forked from AuroraMiddleware/gtk
Add a simple motion eventcontroller
This can serve as a replacement for the legacy event signals for enter/leave/motion notify.
This commit is contained in:
parent
d871fd12cc
commit
911f9fb0ee
@ -93,6 +93,7 @@
|
||||
#include <gtk/gtkentrycompletion.h>
|
||||
#include <gtk/gtkenums.h>
|
||||
#include <gtk/gtkeventcontroller.h>
|
||||
#include <gtk/gtkeventcontrollermotion.h>
|
||||
#include <gtk/gtkeventcontrollerscroll.h>
|
||||
#include <gtk/gtkexpander.h>
|
||||
#include <gtk/gtkfixed.h>
|
||||
|
160
gtk/gtkeventcontrollermotion.c
Normal file
160
gtk/gtkeventcontrollermotion.c
Normal file
@ -0,0 +1,160 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2017, 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/>.
|
||||
*
|
||||
* Author(s): Matthias Clasen <mclasen@redhat.com>
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION:gtkeventcontrollermotion
|
||||
* @Short_description: Event controller for motion events
|
||||
* @Title: GtkEventControllerMotion
|
||||
* @See_also: #GtkEventController
|
||||
*
|
||||
* #GtkEventControllerMotion is an event controller meant for situations
|
||||
* where you need to track the position of the pointer.
|
||||
*
|
||||
* This object was added in 3.94.
|
||||
**/
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkintl.h"
|
||||
#include "gtkwidget.h"
|
||||
#include "gtkeventcontrollerprivate.h"
|
||||
#include "gtkeventcontrollermotion.h"
|
||||
#include "gtktypebuiltins.h"
|
||||
#include "gtkmarshalers.h"
|
||||
|
||||
struct _GtkEventControllerMotion
|
||||
{
|
||||
GtkEventController parent_instance;
|
||||
};
|
||||
|
||||
struct _GtkEventControllerMotionClass
|
||||
{
|
||||
GtkEventControllerClass parent_class;
|
||||
};
|
||||
|
||||
enum {
|
||||
ENTER,
|
||||
LEAVE,
|
||||
MOTION,
|
||||
N_SIGNALS
|
||||
};
|
||||
|
||||
static guint signals[N_SIGNALS] = { 0 };
|
||||
|
||||
G_DEFINE_TYPE (GtkEventControllerMotion, gtk_event_controller_motion, GTK_TYPE_EVENT_CONTROLLER)
|
||||
|
||||
static gboolean
|
||||
gtk_event_controller_motion_handle_event (GtkEventController *controller,
|
||||
const GdkEvent *event)
|
||||
{
|
||||
GtkEventControllerClass *parent_class;
|
||||
GdkEventType type;
|
||||
|
||||
type = gdk_event_get_event_type (event);
|
||||
if (type == GDK_ENTER_NOTIFY)
|
||||
g_signal_emit (controller, signals[ENTER], 0);
|
||||
else if (type == GDK_LEAVE_NOTIFY)
|
||||
g_signal_emit (controller, signals[LEAVE], 0);
|
||||
else if (type == GDK_MOTION_NOTIFY)
|
||||
{
|
||||
double x, y;
|
||||
gdk_event_get_coords (event, &x, &y);
|
||||
g_signal_emit (controller, signals[MOTION], 0, x, y);
|
||||
}
|
||||
|
||||
parent_class = GTK_EVENT_CONTROLLER_CLASS (gtk_event_controller_motion_parent_class);
|
||||
|
||||
return parent_class->handle_event (controller, event);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_event_controller_motion_class_init (GtkEventControllerMotionClass *klass)
|
||||
{
|
||||
GtkEventControllerClass *controller_class = GTK_EVENT_CONTROLLER_CLASS (klass);
|
||||
|
||||
controller_class->handle_event = gtk_event_controller_motion_handle_event;
|
||||
|
||||
/**
|
||||
* GtkEventControllerMotion::enter:
|
||||
* @controller: The object that received the signal
|
||||
*
|
||||
* Signals that the pointer has entered the widget.
|
||||
*/
|
||||
signals[ENTER] =
|
||||
g_signal_new (I_("enter"),
|
||||
GTK_TYPE_EVENT_CONTROLLER_MOTION,
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
0, NULL, NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE, 0);
|
||||
/**
|
||||
* GtkEventControllerMotion::leave:
|
||||
* @controller: The object that received the signal
|
||||
*
|
||||
* Signals that pointer has left the widget.
|
||||
*/
|
||||
signals[LEAVE] =
|
||||
g_signal_new (I_("leave"),
|
||||
GTK_TYPE_EVENT_CONTROLLER_MOTION,
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
0, NULL, NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE, 0);
|
||||
|
||||
/**
|
||||
* GtkEventControllerMotion::motion:
|
||||
* @controller: The object that received the signal
|
||||
* @x: the x coordinate
|
||||
* @y: the y coordinate
|
||||
*
|
||||
* Emitted when the pointer moves inside the widget.
|
||||
*/
|
||||
signals[MOTION] =
|
||||
g_signal_new (I_("motion"),
|
||||
GTK_TYPE_EVENT_CONTROLLER_MOTION,
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
0, NULL, NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE, 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_event_controller_motion_init (GtkEventControllerMotion *motion)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_event_controller_motion_new:
|
||||
* @widget: a #GtkWidget
|
||||
*
|
||||
* Creates a new event controller that will handle motion events
|
||||
* for the given @widget.
|
||||
*
|
||||
* Returns: a new #GtkEventControllerMotion
|
||||
*
|
||||
* Since: 3.94
|
||||
**/
|
||||
GtkEventController *
|
||||
gtk_event_controller_motion_new (GtkWidget *widget)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
|
||||
|
||||
return g_object_new (GTK_TYPE_EVENT_CONTROLLER_MOTION,
|
||||
"widget", widget,
|
||||
NULL);
|
||||
}
|
50
gtk/gtkeventcontrollermotion.h
Normal file
50
gtk/gtkeventcontrollermotion.h
Normal file
@ -0,0 +1,50 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2017, 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/>.
|
||||
*
|
||||
* Author(s): Matthias Clasen <mclasen@redhat.com>
|
||||
*/
|
||||
|
||||
#ifndef __GTK_EVENT_CONTROLLER_MOTION_H__
|
||||
#define __GTK_EVENT_CONTROLLER_MOTION_H__
|
||||
|
||||
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gtk/gtkeventcontroller.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_EVENT_CONTROLLER_MOTION (gtk_event_controller_motion_get_type ())
|
||||
#define GTK_EVENT_CONTROLLER_MOTION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_EVENT_CONTROLLER_MOTION, GtkEventControllerMotion))
|
||||
#define GTK_EVENT_CONTROLLER_MOTION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_EVENT_CONTROLLER_MOTION, GtkEventControllerMotionClass))
|
||||
#define GTK_IS_EVENT_CONTROLLER_MOTION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_EVENT_CONTROLLER_MOTION))
|
||||
#define GTK_IS_EVENT_CONTROLLER_MOTION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_EVENT_CONTROLLER_MOTION))
|
||||
#define GTK_EVENT_CONTROLLER_MOTION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_EVENT_CONTROLLER_MOTION, GtkEventControllerMotionClass))
|
||||
|
||||
typedef struct _GtkEventControllerMotion GtkEventControllerMotion;
|
||||
typedef struct _GtkEventControllerMotionClass GtkEventControllerMotionClass;
|
||||
|
||||
GDK_AVAILABLE_IN_3_94
|
||||
GType gtk_event_controller_motion_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GDK_AVAILABLE_IN_3_94
|
||||
GtkEventController *gtk_event_controller_motion_new (GtkWidget *widget);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_EVENT_CONTROLLER_MOTION_H__ */
|
@ -146,6 +146,7 @@ gtk_public_sources = files([
|
||||
'gtkentrycompletion.c',
|
||||
'gtkeventcontroller.c',
|
||||
'gtkeventcontrollerlegacy.c',
|
||||
'gtkeventcontrollermotion.c',
|
||||
'gtkeventcontrollerscroll.c',
|
||||
'gtkexpander.c',
|
||||
'gtkfilechooser.c',
|
||||
|
Loading…
Reference in New Issue
Block a user