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