Debian Codegraph @

gtk/src/gesture.hg

raw
1 /* Copyright (C) 2014 The gtkmm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #include <vector>
18 #include <gtkmm/eventcontroller.h>
19
20 _DEFS(gtkmm,gtk)
21 _PINCLUDE(gtkmm/private/eventcontroller_p.h)
22
23 namespace Gtk
24 {
25 _WRAP_ENUM(EventSequenceState, GtkEventSequenceState, decl_prefix GTKMM_API)
26
27 /** Abstract base class for gestures.
28 *
29 * This is the base object for gesture recognition. Although this
30 * object is quite generalized to serve as a base for multi-touch gestures,
31 * it is suitable to implement single-touch and pointer-based gestures (using
32 * the special GdkEventSequence value for these).
33 *
34 * The number of touches that a Gesture need to be recognized is controlled
35 * by the n-points property. If a gesture is keeping track of less
36 * or more than that number of sequences, it won't check whether the gesture
37 * is recognized.
38 *
39 * As soon as the gesture has the expected number of touches, the gesture will
40 * run check signal regularly on input events until the gesture
41 * is recognized. The criteria to consider a gesture as "recognized" is left to
42 * Gesture subclasses.
43 *
44 * A recognized gesture will then emit the following signals:
45 * - signal_begin() when the gesture is recognized.
46 * - A number of signal_update(), whenever an input event is processed.
47 * - signal_end() when the gesture is no longer recognized.
48 *
49 * <h2>Event propagation</h2>
50 *
51 * In order to receive events, a gesture needs to either set a propagation phase
52 * through EventController::set_propagation_phase(), or feed those manually
53 * through EventController::handle_event().
54 *
55 * In the capture phase, events are propagated from the toplevel down to the
56 * target widget, and gestures that are attached to containers above the widget
57 * get a chance to interact with the event before it reaches the target.
58 *
59 * After the capture phase, GTK+ emits the traditional Widget::signal_button_press_event(),
60 * Widget::signal_button_release_event(), Widget::signal_touch_event(), etc. Gestures
61 * with the Gtk::PHASE_TARGET phase are fed events from the default
62 * Widget::signal_event() handlers.
63 *
64 * In the bubble phase, events are propagated up from the target widget to the
65 * toplevel, and gestures that are attached to containers above the widget get
66 * a chance to interact with events that have not been handled yet.
67 *
68 * <h2>States of a sequence</h2>
69 *
70 * Whenever input interaction happens, a single event may trigger a cascade of
71 * Gesture%s, both across the parents of the widget receiving the
72 * event and parallelly within an individual widget. It is a responsibility of the
73 * widgets using those gestures to set the state of touch sequences accordingly
74 * in order to enable cooperation of gestures around the GdkEventSequence%s
75 * triggering those.
76 *
77 * Within a widget, gestures can be grouped through group().
78 * Grouped gestures synchronize the state of sequences, so calling
79 * set_sequence_state() on one will effectively propagate
80 * the state throughout the group.
81 *
82 * By default, all sequences start out in the Gtk::EVENT_SEQUENCE_NONE state.
83 * Sequences in this state trigger the gesture event handler, but event
84 * propagation will continue unstopped by gestures.
85 *
86 * If a sequence enters into the Gtk::EVENT_SEQUENCE_DENIED state, the gesture
87 * group will effectively ignore the sequence, letting events go unstopped
88 * through the gesture, but the "slot" will still remain occupied while
89 * the touch is active.
90 *
91 * If a sequence enters in the Gtk::EVENT_SEQUENCE_CLAIMED state, the gesture
92 * group will grab all interaction on the sequence, by:
93 * - Setting the same sequence to Gtk::EVENT_SEQUENCE_DENIED on every other gesture
94 * group within the widget, and every gesture on parent widgets in the propagation
95 * chain.
96 * - emitting signal_cancel() on every gesture in widgets underneath in the
97 * propagation chain.
98 * - Stopping event propagation after the gesture group handles the event.
99 *
100 * @note If a sequence is set early to Gtk::EVENT_SEQUENCE_CLAIMED on
101 * Gdk::TOUCH_BEGIN/Gdk::BUTTON_PRESS (so those events are captured before
102 * reaching the event widget, this implies Gtk::PHASE_CAPTURE), one similar
103 * event will be emulated if the sequence changes to Gtk::EVENT_SEQUENCE_DENIED.
104 * This way event coherence is preserved before event propagation is unstopped
105 * again.
106 *
107 * Sequence states can't be changed freely, see set_sequence_state()
108 * to know about the possible lifetimes of a GdkEventSequence.
109 *
110 * @newin{3,14}
111 *
112 * @ingroup Gestures
113 */
114 class GTKMM_API Gesture : public EventController
115 {
116 _CLASS_GOBJECT(Gesture, GtkGesture, GTK_GESTURE, EventController, GtkEventController, , , GTKMM_API)
117
118 protected:
119 /** There is no create() method that corresponds to this constructor,
120 * because only derived classes shall be created.
121 */
122 _CTOR_DEFAULT
123
124 public:
125 // No create() because only derived classes shall be instantiated.
126
127 _WRAP_METHOD(Glib::RefPtr<Gdk::Device> get_device(), gtk_gesture_get_device, refreturn)
128 _WRAP_METHOD(Glib::RefPtr<const Gdk::Device> get_device() const, gtk_gesture_get_device, refreturn, constversion)
129 _WRAP_METHOD(bool set_state(EventSequenceState state), gtk_gesture_set_state)
130 _WRAP_METHOD(EventSequenceState get_sequence_state(GdkEventSequence* sequence) const, gtk_gesture_get_sequence_state)
131 _WRAP_METHOD(bool set_sequence_state(GdkEventSequence* sequence, EventSequenceState state), gtk_gesture_set_sequence_state)
132
133 /** Returns the list of GdkEventSequence%s currently being interpreted.
134 *
135 * @newin{3,14}
136 *
137 * @return A std::vector of GdkEventSequence pointers.
138 * The GdkEventSequence%s are owned by GTK+ and must not be freed or modified.
139 */
140 std::vector<const GdkEventSequence*> get_sequences() const;
141 _IGNORE(gtk_gesture_get_sequences)
142
143 _WRAP_METHOD(GdkEventSequence* get_last_updated_sequence(), gtk_gesture_get_last_updated_sequence)
144 _WRAP_METHOD(const GdkEventSequence* get_last_updated_sequence() const, gtk_gesture_get_last_updated_sequence, constversion)
145 _WRAP_METHOD(bool handles_sequence(GdkEventSequence* sequence) const, gtk_gesture_handles_sequence)
146 _WRAP_METHOD(const GdkEvent* get_last_event(GdkEventSequence* sequence) const, gtk_gesture_get_last_event)
147 _WRAP_METHOD(bool get_point(GdkEventSequence* sequence, double& x, double& y) const, gtk_gesture_get_point)
148 _WRAP_METHOD(bool get_bounding_box(Gdk::Rectangle& rect) const, gtk_gesture_get_bounding_box)
149 _WRAP_METHOD(bool get_bounding_box_center(double& x, double& y) const, gtk_gesture_get_bounding_box_center)
150 _WRAP_METHOD(bool is_active() const, gtk_gesture_is_active)
151 _WRAP_METHOD(bool is_recognized() const, gtk_gesture_is_recognized)
152 _WRAP_METHOD(Glib::RefPtr<Gdk::Window> get_window(), gtk_gesture_get_window, refreturn)
153 _WRAP_METHOD(Glib::RefPtr<const Gdk::Window> get_window() const, gtk_gesture_get_window, refreturn, constversion)
154 _WRAP_METHOD(void set_window(const Glib::RefPtr<Gdk::Window>& window), gtk_gesture_set_window)
155
156 /** Undoes the effect of previous calls to set_window(),
157 * so the gesture will handle events targeting any Gdk::Window that pertains
158 * to Gtk::EventController::get_widget().
159 *
160 * @newin{3,14}
161 */
162 void unset_window();
163
164 #m4 _CONVERSION(`const Glib::RefPtr<Gesture>&',`GtkGesture*',__CONVERT_REFPTR_TO_P($3))
165 _WRAP_METHOD(void group(const Glib::RefPtr<Gesture>& group_gesture), gtk_gesture_group)
166 _WRAP_METHOD(void ungroup(), gtk_gesture_ungroup)
167
168 #m4 _CONVERSION(`GList*',`std::vector< Glib::RefPtr<Gesture> >',`Glib::ListHandler< Glib::RefPtr<Gesture> >::list_to_vector($3, Glib::OWNERSHIP_SHALLOW)')
169 _WRAP_METHOD(std::vector< Glib::RefPtr<Gesture> > get_group(), gtk_gesture_get_group)
170 #m4 _CONVERSION(`GList*',`std::vector< Glib::RefPtr<const Gesture> >',`Glib::ListHandler< Glib::RefPtr<const Gesture> >::list_to_vector($3, Glib::OWNERSHIP_SHALLOW)')
171 _WRAP_METHOD(std::vector< Glib::RefPtr<const Gesture> > get_group() const, gtk_gesture_get_group)
172
173 _WRAP_METHOD(bool is_grouped_with(const Glib::RefPtr<Gesture>& other) const, gtk_gesture_is_grouped_with)
174
175 // no_default_handler because GtkGestureClass is private.
176 _WRAP_SIGNAL(void begin(GdkEventSequence* sequence), "begin", no_default_handler)
177 _WRAP_SIGNAL(void end(GdkEventSequence* sequence), "end", no_default_handler)
178 _WRAP_SIGNAL(void update(GdkEventSequence* sequence), "update", no_default_handler)
179 _WRAP_SIGNAL(void cancel(GdkEventSequence* sequence), "cancel", no_default_handler)
180 _WRAP_SIGNAL(void sequence_state_changed(GdkEventSequence* sequence, EventSequenceState state), "sequence_state_changed", no_default_handler)
181
182 _WRAP_PROPERTY("n-points", unsigned int)
183 _WRAP_PROPERTY("window", Glib::RefPtr<Gdk::Window>)
184 };
185
186 } // namespace Gtk