gtk2/gtk/gtkeventcontrollerlegacy.c
Emmanuele Bassi f28aa1ba02 Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.

The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.

The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 19:54:02 +01:00

121 lines
3.5 KiB
C

/* 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): Carlos Garnacho <carlosg@gnome.org>
*/
/**
* SECTION:gtkeventcontrollerlegacy
* @Short_description: Event controller for miscellaneous events
* @Title: GtkEventControllerLegacy
* @See_also: #GtkEventController
*
* #GtkEventControllerLegacy is an event controller that gives you
* direct access to the event stream. It should only be used as a
* last resort if none of the other event controllers or gestures
* do the job.
**/
#include "config.h"
#include "gtkeventcontrollerlegacy.h"
#include "gtkeventcontrollerprivate.h"
#include "gtkmarshalers.h"
#include "gtkintl.h"
#include "gtkprivate.h"
struct _GtkEventControllerLegacy
{
GtkEventController parent_instance;
};
struct _GtkEventControllerLegacyClass
{
GtkEventControllerClass parent_class;
};
enum {
EVENT,
N_SIGNALS
};
static guint signals[N_SIGNALS] = { 0, };
G_DEFINE_TYPE (GtkEventControllerLegacy, gtk_event_controller_legacy,
GTK_TYPE_EVENT_CONTROLLER)
static gboolean
gtk_event_controller_legacy_handle_event (GtkEventController *controller,
GdkEvent *event,
double x,
double y)
{
gboolean handled;
g_signal_emit (controller, signals[EVENT], 0, event, &handled);
return handled;
}
static void
gtk_event_controller_legacy_class_init (GtkEventControllerLegacyClass *klass)
{
GtkEventControllerClass *controller_class = GTK_EVENT_CONTROLLER_CLASS (klass);
controller_class->handle_event = gtk_event_controller_legacy_handle_event;
/**
* GtkEventControllerLegacy::event:
* @controller: the object which received the signal.
* @event: the #GdkEvent which triggered this signal
*
* Emitted for each GDK event delivered to @controller.
*
* Returns: %TRUE to stop other handlers from being invoked for the event
* and the emission of this signal. %FALSE to propagate the event further.
*/
signals[EVENT] =
g_signal_new (I_("event"),
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, _gtk_boolean_handled_accumulator, NULL,
_gtk_marshal_BOOLEAN__POINTER,
G_TYPE_BOOLEAN, 1,
GDK_TYPE_EVENT);
g_signal_set_va_marshaller (signals[EVENT], G_TYPE_FROM_CLASS (klass),
_gtk_marshal_BOOLEAN__POINTERv);
}
static void
gtk_event_controller_legacy_init (GtkEventControllerLegacy *controller)
{
}
/**
* gtk_event_controller_legacy_new:
*
* Creates a new legacy event controller.
*
* Returns: the newly created event controller.
*/
GtkEventController *
gtk_event_controller_legacy_new (void)
{
return g_object_new (GTK_TYPE_EVENT_CONTROLLER_LEGACY,
NULL);
}