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