1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.GestureMultiPress;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gtk.Gesture;
31 private import gtk.GestureSingle;
32 private import gtk.Widget;
33 public  import gtkc.gdktypes;
34 private import gtkc.gtk;
35 public  import gtkc.gtktypes;
36 private import std.algorithm;
37 
38 
39 /**
40  * #GtkGestureMultiPress is a #GtkGesture implementation able to recognize
41  * multiple clicks on a nearby zone, which can be listened for through the
42  * #GtkGestureMultiPress::pressed signal. Whenever time or distance between
43  * clicks exceed the GTK+ defaults, #GtkGestureMultiPress::stopped is emitted,
44  * and the click counter is reset.
45  * 
46  * Callers may also restrict the area that is considered valid for a >1
47  * touch/button press through gtk_gesture_multi_press_set_area(), so any
48  * click happening outside that area is considered to be a first click of
49  * its own.
50  */
51 public class GestureMultiPress : GestureSingle
52 {
53 	/** the main Gtk struct */
54 	protected GtkGestureMultiPress* gtkGestureMultiPress;
55 
56 	/** Get the main Gtk struct */
57 	public GtkGestureMultiPress* getGestureMultiPressStruct()
58 	{
59 		return gtkGestureMultiPress;
60 	}
61 
62 	/** the main Gtk struct as a void* */
63 	protected override void* getStruct()
64 	{
65 		return cast(void*)gtkGestureMultiPress;
66 	}
67 
68 	protected override void setStruct(GObject* obj)
69 	{
70 		gtkGestureMultiPress = cast(GtkGestureMultiPress*)obj;
71 		super.setStruct(obj);
72 	}
73 
74 	/**
75 	 * Sets our main struct and passes it to the parent class.
76 	 */
77 	public this (GtkGestureMultiPress* gtkGestureMultiPress, bool ownedRef = false)
78 	{
79 		this.gtkGestureMultiPress = gtkGestureMultiPress;
80 		super(cast(GtkGestureSingle*)gtkGestureMultiPress, ownedRef);
81 	}
82 
83 
84 	/** */
85 	public static GType getType()
86 	{
87 		return gtk_gesture_multi_press_get_type();
88 	}
89 
90 	/**
91 	 * Returns a newly created #GtkGesture that recognizes single and multiple
92 	 * presses.
93 	 *
94 	 * Params:
95 	 *     widget = a #GtkWidget
96 	 *
97 	 * Return: a newly created #GtkGestureMultiPress
98 	 *
99 	 * Since: 3.14
100 	 *
101 	 * Throws: ConstructionException GTK+ fails to create the object.
102 	 */
103 	public this(Widget widget)
104 	{
105 		auto p = gtk_gesture_multi_press_new((widget is null) ? null : widget.getWidgetStruct());
106 		
107 		if(p is null)
108 		{
109 			throw new ConstructionException("null returned by new");
110 		}
111 		
112 		this(cast(GtkGestureMultiPress*) p, true);
113 	}
114 
115 	/**
116 	 * If an area was set through gtk_gesture_multi_press_set_area(),
117 	 * this function will return %TRUE and fill in @rect with the
118 	 * press area. See gtk_gesture_multi_press_set_area() for more
119 	 * details on what the press area represents.
120 	 *
121 	 * Params:
122 	 *     rect = return location for the press area
123 	 *
124 	 * Return: %TRUE if @rect was filled with the press area
125 	 *
126 	 * Since: 3.14
127 	 */
128 	public bool getArea(out GdkRectangle rect)
129 	{
130 		return gtk_gesture_multi_press_get_area(gtkGestureMultiPress, &rect) != 0;
131 	}
132 
133 	/**
134 	 * If @rect is non-%NULL, the press area will be checked to be
135 	 * confined within the rectangle, otherwise the button count
136 	 * will be reset so the press is seen as being the first one.
137 	 * If @rect is #NULL, the area will be reset to an unrestricted
138 	 * state.
139 	 *
140 	 * Note: The rectangle is only used to determine whether any
141 	 * non-first click falls within the expected area. This is not
142 	 * akin to an input shape.
143 	 *
144 	 * Params:
145 	 *     rect = rectangle to receive coordinates on
146 	 *
147 	 * Since: 3.14
148 	 */
149 	public void setArea(GdkRectangle* rect)
150 	{
151 		gtk_gesture_multi_press_set_area(gtkGestureMultiPress, rect);
152 	}
153 
154 	protected class OnPressedDelegateWrapper
155 	{
156 		void delegate(int, double, double, GestureMultiPress) dlg;
157 		gulong handlerId;
158 		ConnectFlags flags;
159 		this(void delegate(int, double, double, GestureMultiPress) dlg, gulong handlerId, ConnectFlags flags)
160 		{
161 			this.dlg = dlg;
162 			this.handlerId = handlerId;
163 			this.flags = flags;
164 		}
165 	}
166 	protected OnPressedDelegateWrapper[] onPressedListeners;
167 
168 	/**
169 	 * This signal is emitted whenever a button or touch press happens.
170 	 *
171 	 * Params:
172 	 *     nPress = how many touch/button presses happened with this one
173 	 *     x = The X coordinate, in widget allocation coordinates
174 	 *     y = The Y coordinate, in widget allocation coordinates
175 	 *
176 	 * Since: 3.14
177 	 */
178 	gulong addOnPressed(void delegate(int, double, double, GestureMultiPress) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
179 	{
180 		onPressedListeners ~= new OnPressedDelegateWrapper(dlg, 0, connectFlags);
181 		onPressedListeners[onPressedListeners.length - 1].handlerId = Signals.connectData(
182 			this,
183 			"pressed",
184 			cast(GCallback)&callBackPressed,
185 			cast(void*)onPressedListeners[onPressedListeners.length - 1],
186 			cast(GClosureNotify)&callBackPressedDestroy,
187 			connectFlags);
188 		return onPressedListeners[onPressedListeners.length - 1].handlerId;
189 	}
190 	
191 	extern(C) static void callBackPressed(GtkGestureMultiPress* gesturemultipressStruct, int nPress, double x, double y,OnPressedDelegateWrapper wrapper)
192 	{
193 		wrapper.dlg(nPress, x, y, wrapper.outer);
194 	}
195 	
196 	extern(C) static void callBackPressedDestroy(OnPressedDelegateWrapper wrapper, GClosure* closure)
197 	{
198 		wrapper.outer.internalRemoveOnPressed(wrapper);
199 	}
200 
201 	protected void internalRemoveOnPressed(OnPressedDelegateWrapper source)
202 	{
203 		foreach(index, wrapper; onPressedListeners)
204 		{
205 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
206 			{
207 				onPressedListeners[index] = null;
208 				onPressedListeners = std.algorithm.remove(onPressedListeners, index);
209 				break;
210 			}
211 		}
212 	}
213 	
214 
215 	protected class OnReleasedDelegateWrapper
216 	{
217 		void delegate(int, double, double, GestureMultiPress) dlg;
218 		gulong handlerId;
219 		ConnectFlags flags;
220 		this(void delegate(int, double, double, GestureMultiPress) dlg, gulong handlerId, ConnectFlags flags)
221 		{
222 			this.dlg = dlg;
223 			this.handlerId = handlerId;
224 			this.flags = flags;
225 		}
226 	}
227 	protected OnReleasedDelegateWrapper[] onReleasedListeners;
228 
229 	/**
230 	 * This signal is emitted when a button or touch is released. @n_press
231 	 * will report the number of press that is paired to this event, note
232 	 * that #GtkGestureMultiPress::stopped may have been emitted between the
233 	 * press and its release, @n_press will only start over at the next press.
234 	 *
235 	 * Params:
236 	 *     nPress = number of press that is paired with this release
237 	 *     x = The X coordinate, in widget allocation coordinates
238 	 *     y = The Y coordinate, in widget allocation coordinates
239 	 *
240 	 * Since: 3.14
241 	 */
242 	gulong addOnReleased(void delegate(int, double, double, GestureMultiPress) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
243 	{
244 		onReleasedListeners ~= new OnReleasedDelegateWrapper(dlg, 0, connectFlags);
245 		onReleasedListeners[onReleasedListeners.length - 1].handlerId = Signals.connectData(
246 			this,
247 			"released",
248 			cast(GCallback)&callBackReleased,
249 			cast(void*)onReleasedListeners[onReleasedListeners.length - 1],
250 			cast(GClosureNotify)&callBackReleasedDestroy,
251 			connectFlags);
252 		return onReleasedListeners[onReleasedListeners.length - 1].handlerId;
253 	}
254 	
255 	extern(C) static void callBackReleased(GtkGestureMultiPress* gesturemultipressStruct, int nPress, double x, double y,OnReleasedDelegateWrapper wrapper)
256 	{
257 		wrapper.dlg(nPress, x, y, wrapper.outer);
258 	}
259 	
260 	extern(C) static void callBackReleasedDestroy(OnReleasedDelegateWrapper wrapper, GClosure* closure)
261 	{
262 		wrapper.outer.internalRemoveOnReleased(wrapper);
263 	}
264 
265 	protected void internalRemoveOnReleased(OnReleasedDelegateWrapper source)
266 	{
267 		foreach(index, wrapper; onReleasedListeners)
268 		{
269 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
270 			{
271 				onReleasedListeners[index] = null;
272 				onReleasedListeners = std.algorithm.remove(onReleasedListeners, index);
273 				break;
274 			}
275 		}
276 	}
277 	
278 
279 	protected class OnStoppedDelegateWrapper
280 	{
281 		void delegate(GestureMultiPress) dlg;
282 		gulong handlerId;
283 		ConnectFlags flags;
284 		this(void delegate(GestureMultiPress) dlg, gulong handlerId, ConnectFlags flags)
285 		{
286 			this.dlg = dlg;
287 			this.handlerId = handlerId;
288 			this.flags = flags;
289 		}
290 	}
291 	protected OnStoppedDelegateWrapper[] onStoppedListeners;
292 
293 	/**
294 	 * This signal is emitted whenever any time/distance threshold has
295 	 * been exceeded.
296 	 *
297 	 * Since: 3.14
298 	 */
299 	gulong addOnStopped(void delegate(GestureMultiPress) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
300 	{
301 		onStoppedListeners ~= new OnStoppedDelegateWrapper(dlg, 0, connectFlags);
302 		onStoppedListeners[onStoppedListeners.length - 1].handlerId = Signals.connectData(
303 			this,
304 			"stopped",
305 			cast(GCallback)&callBackStopped,
306 			cast(void*)onStoppedListeners[onStoppedListeners.length - 1],
307 			cast(GClosureNotify)&callBackStoppedDestroy,
308 			connectFlags);
309 		return onStoppedListeners[onStoppedListeners.length - 1].handlerId;
310 	}
311 	
312 	extern(C) static void callBackStopped(GtkGestureMultiPress* gesturemultipressStruct,OnStoppedDelegateWrapper wrapper)
313 	{
314 		wrapper.dlg(wrapper.outer);
315 	}
316 	
317 	extern(C) static void callBackStoppedDestroy(OnStoppedDelegateWrapper wrapper, GClosure* closure)
318 	{
319 		wrapper.outer.internalRemoveOnStopped(wrapper);
320 	}
321 
322 	protected void internalRemoveOnStopped(OnStoppedDelegateWrapper source)
323 	{
324 		foreach(index, wrapper; onStoppedListeners)
325 		{
326 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
327 			{
328 				onStoppedListeners[index] = null;
329 				onStoppedListeners = std.algorithm.remove(onStoppedListeners, index);
330 				break;
331 			}
332 		}
333 	}
334 	
335 }