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