1 | /* GTK - The GIMP Toolkit |
2 | * Copyright (C) 2017, Red Hat, Inc. |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
16 | * |
17 | * Author(s): Carlos Garnacho <carlosg@gnome.org> |
18 | */ |
19 | |
20 | /** |
21 | * GtkEventControllerLegacy: |
22 | * |
23 | * `GtkEventControllerLegacy` is an event controller that provides raw |
24 | * access to the event stream. |
25 | * |
26 | * It should only be used as a last resort if none of the other event |
27 | * controllers or gestures do the job. |
28 | */ |
29 | |
30 | #include "config.h" |
31 | |
32 | #include "gtkeventcontrollerlegacy.h" |
33 | #include "gtkeventcontrollerprivate.h" |
34 | #include "gtkmarshalers.h" |
35 | #include "gtkintl.h" |
36 | #include "gtkprivate.h" |
37 | |
38 | struct _GtkEventControllerLegacy |
39 | { |
40 | GtkEventController parent_instance; |
41 | }; |
42 | |
43 | struct _GtkEventControllerLegacyClass |
44 | { |
45 | GtkEventControllerClass parent_class; |
46 | }; |
47 | |
48 | enum { |
49 | EVENT, |
50 | N_SIGNALS |
51 | }; |
52 | |
53 | static guint signals[N_SIGNALS] = { 0, }; |
54 | |
55 | G_DEFINE_TYPE (GtkEventControllerLegacy, gtk_event_controller_legacy, |
56 | GTK_TYPE_EVENT_CONTROLLER) |
57 | |
58 | static gboolean |
59 | gtk_event_controller_legacy_handle_event (GtkEventController *controller, |
60 | GdkEvent *event, |
61 | double x, |
62 | double y) |
63 | { |
64 | gboolean handled; |
65 | |
66 | g_signal_emit (instance: controller, signal_id: signals[EVENT], detail: 0, event, &handled); |
67 | |
68 | return handled; |
69 | } |
70 | |
71 | static void |
72 | gtk_event_controller_legacy_class_init (GtkEventControllerLegacyClass *klass) |
73 | { |
74 | GtkEventControllerClass *controller_class = GTK_EVENT_CONTROLLER_CLASS (klass); |
75 | |
76 | controller_class->handle_event = gtk_event_controller_legacy_handle_event; |
77 | |
78 | /** |
79 | * GtkEventControllerLegacy::event: |
80 | * @controller: the object which received the signal |
81 | * @event: the `GdkEvent` which triggered this signal |
82 | * |
83 | * Emitted for each GDK event delivered to @controller. |
84 | * |
85 | * Returns: %TRUE to stop other handlers from being invoked for the event |
86 | * and the emission of this signal. %FALSE to propagate the event further. |
87 | */ |
88 | signals[EVENT] = |
89 | g_signal_new (I_("event" ), |
90 | G_TYPE_FROM_CLASS (klass), |
91 | signal_flags: G_SIGNAL_RUN_LAST, |
92 | class_offset: 0, accumulator: _gtk_boolean_handled_accumulator, NULL, |
93 | c_marshaller: _gtk_marshal_BOOLEAN__POINTER, |
94 | G_TYPE_BOOLEAN, n_params: 1, |
95 | GDK_TYPE_EVENT); |
96 | |
97 | g_signal_set_va_marshaller (signal_id: signals[EVENT], G_TYPE_FROM_CLASS (klass), |
98 | va_marshaller: _gtk_marshal_BOOLEAN__POINTERv); |
99 | } |
100 | |
101 | static void |
102 | gtk_event_controller_legacy_init (GtkEventControllerLegacy *controller) |
103 | { |
104 | } |
105 | |
106 | /** |
107 | * gtk_event_controller_legacy_new: |
108 | * |
109 | * Creates a new legacy event controller. |
110 | * |
111 | * Returns: the newly created event controller. |
112 | */ |
113 | GtkEventController * |
114 | gtk_event_controller_legacy_new (void) |
115 | { |
116 | return g_object_new (GTK_TYPE_EVENT_CONTROLLER_LEGACY, |
117 | NULL); |
118 | } |
119 | |