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.GestureDrag;
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 gtk.c.functions;
34 public  import gtk.c.types;
35 public  import gtkc.gtktypes;
36 private import std.algorithm;
37 
38 
39 /**
40  * #GtkGestureDrag is a #GtkGesture implementation that recognizes drag
41  * operations. The drag operation itself can be tracked throught the
42  * #GtkGestureDrag::drag-begin, #GtkGestureDrag::drag-update and
43  * #GtkGestureDrag::drag-end signals, or the relevant coordinates be
44  * extracted through gtk_gesture_drag_get_offset() and
45  * gtk_gesture_drag_get_start_point().
46  */
47 public class GestureDrag : GestureSingle
48 {
49 	/** the main Gtk struct */
50 	protected GtkGestureDrag* gtkGestureDrag;
51 
52 	/** Get the main Gtk struct */
53 	public GtkGestureDrag* getGestureDragStruct(bool transferOwnership = false)
54 	{
55 		if (transferOwnership)
56 			ownedRef = false;
57 		return gtkGestureDrag;
58 	}
59 
60 	/** the main Gtk struct as a void* */
61 	protected override void* getStruct()
62 	{
63 		return cast(void*)gtkGestureDrag;
64 	}
65 
66 	protected override void setStruct(GObject* obj)
67 	{
68 		gtkGestureDrag = cast(GtkGestureDrag*)obj;
69 		super.setStruct(obj);
70 	}
71 
72 	/**
73 	 * Sets our main struct and passes it to the parent class.
74 	 */
75 	public this (GtkGestureDrag* gtkGestureDrag, bool ownedRef = false)
76 	{
77 		this.gtkGestureDrag = gtkGestureDrag;
78 		super(cast(GtkGestureSingle*)gtkGestureDrag, ownedRef);
79 	}
80 
81 
82 	/** */
83 	public static GType getType()
84 	{
85 		return gtk_gesture_drag_get_type();
86 	}
87 
88 	/**
89 	 * Returns a newly created #GtkGesture that recognizes drags.
90 	 *
91 	 * Params:
92 	 *     widget = a #GtkWidget
93 	 *
94 	 * Returns: a newly created #GtkGestureDrag
95 	 *
96 	 * Since: 3.14
97 	 *
98 	 * Throws: ConstructionException GTK+ fails to create the object.
99 	 */
100 	public this(Widget widget)
101 	{
102 		auto p = gtk_gesture_drag_new((widget is null) ? null : widget.getWidgetStruct());
103 
104 		if(p is null)
105 		{
106 			throw new ConstructionException("null returned by new");
107 		}
108 
109 		this(cast(GtkGestureDrag*) p, true);
110 	}
111 
112 	/**
113 	 * If the @gesture is active, this function returns %TRUE and
114 	 * fills in @x and @y with the coordinates of the current point,
115 	 * as an offset to the starting drag point.
116 	 *
117 	 * Params:
118 	 *     x = X offset for the current point
119 	 *     y = Y offset for the current point
120 	 *
121 	 * Returns: %TRUE if the gesture is active
122 	 *
123 	 * Since: 3.14
124 	 */
125 	public bool getOffset(out double x, out double y)
126 	{
127 		return gtk_gesture_drag_get_offset(gtkGestureDrag, &x, &y) != 0;
128 	}
129 
130 	/**
131 	 * If the @gesture is active, this function returns %TRUE
132 	 * and fills in @x and @y with the drag start coordinates,
133 	 * in window-relative coordinates.
134 	 *
135 	 * Params:
136 	 *     x = X coordinate for the drag start point
137 	 *     y = Y coordinate for the drag start point
138 	 *
139 	 * Returns: %TRUE if the gesture is active
140 	 *
141 	 * Since: 3.14
142 	 */
143 	public bool getStartPoint(out double x, out double y)
144 	{
145 		return gtk_gesture_drag_get_start_point(gtkGestureDrag, &x, &y) != 0;
146 	}
147 
148 	protected class OnDragBeginDelegateWrapper
149 	{
150 		void delegate(double, double, GestureDrag) dlg;
151 		gulong handlerId;
152 
153 		this(void delegate(double, double, GestureDrag) dlg)
154 		{
155 			this.dlg = dlg;
156 			onDragBeginListeners ~= this;
157 		}
158 
159 		void remove(OnDragBeginDelegateWrapper source)
160 		{
161 			foreach(index, wrapper; onDragBeginListeners)
162 			{
163 				if (wrapper.handlerId == source.handlerId)
164 				{
165 					onDragBeginListeners[index] = null;
166 					onDragBeginListeners = std.algorithm.remove(onDragBeginListeners, index);
167 					break;
168 				}
169 			}
170 		}
171 	}
172 	OnDragBeginDelegateWrapper[] onDragBeginListeners;
173 
174 	/**
175 	 * This signal is emitted whenever dragging starts.
176 	 *
177 	 * Params:
178 	 *     startX = X coordinate, relative to the widget allocation
179 	 *     startY = Y coordinate, relative to the widget allocation
180 	 *
181 	 * Since: 3.14
182 	 */
183 	gulong addOnDragBegin(void delegate(double, double, GestureDrag) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
184 	{
185 		auto wrapper = new OnDragBeginDelegateWrapper(dlg);
186 		wrapper.handlerId = Signals.connectData(
187 			this,
188 			"drag-begin",
189 			cast(GCallback)&callBackDragBegin,
190 			cast(void*)wrapper,
191 			cast(GClosureNotify)&callBackDragBeginDestroy,
192 			connectFlags);
193 		return wrapper.handlerId;
194 	}
195 
196 	extern(C) static void callBackDragBegin(GtkGestureDrag* gesturedragStruct, double startX, double startY, OnDragBeginDelegateWrapper wrapper)
197 	{
198 		wrapper.dlg(startX, startY, wrapper.outer);
199 	}
200 
201 	extern(C) static void callBackDragBeginDestroy(OnDragBeginDelegateWrapper wrapper, GClosure* closure)
202 	{
203 		wrapper.remove(wrapper);
204 	}
205 
206 	protected class OnDragEndDelegateWrapper
207 	{
208 		void delegate(double, double, GestureDrag) dlg;
209 		gulong handlerId;
210 
211 		this(void delegate(double, double, GestureDrag) dlg)
212 		{
213 			this.dlg = dlg;
214 			onDragEndListeners ~= this;
215 		}
216 
217 		void remove(OnDragEndDelegateWrapper source)
218 		{
219 			foreach(index, wrapper; onDragEndListeners)
220 			{
221 				if (wrapper.handlerId == source.handlerId)
222 				{
223 					onDragEndListeners[index] = null;
224 					onDragEndListeners = std.algorithm.remove(onDragEndListeners, index);
225 					break;
226 				}
227 			}
228 		}
229 	}
230 	OnDragEndDelegateWrapper[] onDragEndListeners;
231 
232 	/**
233 	 * This signal is emitted whenever the dragging is finished.
234 	 *
235 	 * Params:
236 	 *     offsetX = X offset, relative to the start point
237 	 *     offsetY = Y offset, relative to the start point
238 	 *
239 	 * Since: 3.14
240 	 */
241 	gulong addOnDragEnd(void delegate(double, double, GestureDrag) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
242 	{
243 		auto wrapper = new OnDragEndDelegateWrapper(dlg);
244 		wrapper.handlerId = Signals.connectData(
245 			this,
246 			"drag-end",
247 			cast(GCallback)&callBackDragEnd,
248 			cast(void*)wrapper,
249 			cast(GClosureNotify)&callBackDragEndDestroy,
250 			connectFlags);
251 		return wrapper.handlerId;
252 	}
253 
254 	extern(C) static void callBackDragEnd(GtkGestureDrag* gesturedragStruct, double offsetX, double offsetY, OnDragEndDelegateWrapper wrapper)
255 	{
256 		wrapper.dlg(offsetX, offsetY, wrapper.outer);
257 	}
258 
259 	extern(C) static void callBackDragEndDestroy(OnDragEndDelegateWrapper wrapper, GClosure* closure)
260 	{
261 		wrapper.remove(wrapper);
262 	}
263 
264 	protected class OnDragUpdateDelegateWrapper
265 	{
266 		void delegate(double, double, GestureDrag) dlg;
267 		gulong handlerId;
268 
269 		this(void delegate(double, double, GestureDrag) dlg)
270 		{
271 			this.dlg = dlg;
272 			onDragUpdateListeners ~= this;
273 		}
274 
275 		void remove(OnDragUpdateDelegateWrapper source)
276 		{
277 			foreach(index, wrapper; onDragUpdateListeners)
278 			{
279 				if (wrapper.handlerId == source.handlerId)
280 				{
281 					onDragUpdateListeners[index] = null;
282 					onDragUpdateListeners = std.algorithm.remove(onDragUpdateListeners, index);
283 					break;
284 				}
285 			}
286 		}
287 	}
288 	OnDragUpdateDelegateWrapper[] onDragUpdateListeners;
289 
290 	/**
291 	 * This signal is emitted whenever the dragging point moves.
292 	 *
293 	 * Params:
294 	 *     offsetX = X offset, relative to the start point
295 	 *     offsetY = Y offset, relative to the start point
296 	 *
297 	 * Since: 3.14
298 	 */
299 	gulong addOnDragUpdate(void delegate(double, double, GestureDrag) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
300 	{
301 		auto wrapper = new OnDragUpdateDelegateWrapper(dlg);
302 		wrapper.handlerId = Signals.connectData(
303 			this,
304 			"drag-update",
305 			cast(GCallback)&callBackDragUpdate,
306 			cast(void*)wrapper,
307 			cast(GClosureNotify)&callBackDragUpdateDestroy,
308 			connectFlags);
309 		return wrapper.handlerId;
310 	}
311 
312 	extern(C) static void callBackDragUpdate(GtkGestureDrag* gesturedragStruct, double offsetX, double offsetY, OnDragUpdateDelegateWrapper wrapper)
313 	{
314 		wrapper.dlg(offsetX, offsetY, wrapper.outer);
315 	}
316 
317 	extern(C) static void callBackDragUpdateDestroy(OnDragUpdateDelegateWrapper wrapper, GClosure* closure)
318 	{
319 		wrapper.remove(wrapper);
320 	}
321 }