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.GestureLongPress;
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  * #GtkGestureLongPress is a #GtkGesture implementation able to recognize
41  * long presses, triggering the #GtkGestureLongPress::pressed after the
42  * timeout is exceeded.
43  * 
44  * If the touchpoint is lifted before the timeout passes, or if it drifts
45  * too far of the initial press point, the #GtkGestureLongPress::cancelled
46  * signal will be emitted.
47  */
48 public class GestureLongPress : GestureSingle
49 {
50 	/** the main Gtk struct */
51 	protected GtkGestureLongPress* gtkGestureLongPress;
52 
53 	/** Get the main Gtk struct */
54 	public GtkGestureLongPress* getGestureLongPressStruct(bool transferOwnership = false)
55 	{
56 		if (transferOwnership)
57 			ownedRef = false;
58 		return gtkGestureLongPress;
59 	}
60 
61 	/** the main Gtk struct as a void* */
62 	protected override void* getStruct()
63 	{
64 		return cast(void*)gtkGestureLongPress;
65 	}
66 
67 	protected override void setStruct(GObject* obj)
68 	{
69 		gtkGestureLongPress = cast(GtkGestureLongPress*)obj;
70 		super.setStruct(obj);
71 	}
72 
73 	/**
74 	 * Sets our main struct and passes it to the parent class.
75 	 */
76 	public this (GtkGestureLongPress* gtkGestureLongPress, bool ownedRef = false)
77 	{
78 		this.gtkGestureLongPress = gtkGestureLongPress;
79 		super(cast(GtkGestureSingle*)gtkGestureLongPress, ownedRef);
80 	}
81 
82 
83 	/** */
84 	public static GType getType()
85 	{
86 		return gtk_gesture_long_press_get_type();
87 	}
88 
89 	/**
90 	 * Returns a newly created #GtkGesture that recognizes long presses.
91 	 *
92 	 * Params:
93 	 *     widget = a #GtkWidget
94 	 *
95 	 * Returns: a newly created #GtkGestureLongPress
96 	 *
97 	 * Since: 3.14
98 	 *
99 	 * Throws: ConstructionException GTK+ fails to create the object.
100 	 */
101 	public this(Widget widget)
102 	{
103 		auto p = gtk_gesture_long_press_new((widget is null) ? null : widget.getWidgetStruct());
104 
105 		if(p is null)
106 		{
107 			throw new ConstructionException("null returned by new");
108 		}
109 
110 		this(cast(GtkGestureLongPress*) p, true);
111 	}
112 
113 	protected class OnCancelledDelegateWrapper
114 	{
115 		void delegate(GestureLongPress) dlg;
116 		gulong handlerId;
117 
118 		this(void delegate(GestureLongPress) dlg)
119 		{
120 			this.dlg = dlg;
121 			onCancelledListeners ~= this;
122 		}
123 
124 		void remove(OnCancelledDelegateWrapper source)
125 		{
126 			foreach(index, wrapper; onCancelledListeners)
127 			{
128 				if (wrapper.handlerId == source.handlerId)
129 				{
130 					onCancelledListeners[index] = null;
131 					onCancelledListeners = std.algorithm.remove(onCancelledListeners, index);
132 					break;
133 				}
134 			}
135 		}
136 	}
137 	OnCancelledDelegateWrapper[] onCancelledListeners;
138 
139 	/**
140 	 * This signal is emitted whenever a press moved too far, or was released
141 	 * before #GtkGestureLongPress::pressed happened.
142 	 *
143 	 * Since: 3.14
144 	 */
145 	gulong addOnCancelled(void delegate(GestureLongPress) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
146 	{
147 		auto wrapper = new OnCancelledDelegateWrapper(dlg);
148 		wrapper.handlerId = Signals.connectData(
149 			this,
150 			"cancelled",
151 			cast(GCallback)&callBackCancelled,
152 			cast(void*)wrapper,
153 			cast(GClosureNotify)&callBackCancelledDestroy,
154 			connectFlags);
155 		return wrapper.handlerId;
156 	}
157 
158 	extern(C) static void callBackCancelled(GtkGestureLongPress* gesturelongpressStruct, OnCancelledDelegateWrapper wrapper)
159 	{
160 		wrapper.dlg(wrapper.outer);
161 	}
162 
163 	extern(C) static void callBackCancelledDestroy(OnCancelledDelegateWrapper wrapper, GClosure* closure)
164 	{
165 		wrapper.remove(wrapper);
166 	}
167 
168 	protected class OnPressedDelegateWrapper
169 	{
170 		void delegate(double, double, GestureLongPress) dlg;
171 		gulong handlerId;
172 
173 		this(void delegate(double, double, GestureLongPress) dlg)
174 		{
175 			this.dlg = dlg;
176 			onPressedListeners ~= this;
177 		}
178 
179 		void remove(OnPressedDelegateWrapper source)
180 		{
181 			foreach(index, wrapper; onPressedListeners)
182 			{
183 				if (wrapper.handlerId == source.handlerId)
184 				{
185 					onPressedListeners[index] = null;
186 					onPressedListeners = std.algorithm.remove(onPressedListeners, index);
187 					break;
188 				}
189 			}
190 		}
191 	}
192 	OnPressedDelegateWrapper[] onPressedListeners;
193 
194 	/**
195 	 * This signal is emitted whenever a press goes unmoved/unreleased longer than
196 	 * what the GTK+ defaults tell.
197 	 *
198 	 * Params:
199 	 *     x = the X coordinate where the press happened, relative to the widget allocation
200 	 *     y = the Y coordinate where the press happened, relative to the widget allocation
201 	 *
202 	 * Since: 3.14
203 	 */
204 	gulong addOnPressed(void delegate(double, double, GestureLongPress) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
205 	{
206 		auto wrapper = new OnPressedDelegateWrapper(dlg);
207 		wrapper.handlerId = Signals.connectData(
208 			this,
209 			"pressed",
210 			cast(GCallback)&callBackPressed,
211 			cast(void*)wrapper,
212 			cast(GClosureNotify)&callBackPressedDestroy,
213 			connectFlags);
214 		return wrapper.handlerId;
215 	}
216 
217 	extern(C) static void callBackPressed(GtkGestureLongPress* gesturelongpressStruct, double x, double y, OnPressedDelegateWrapper wrapper)
218 	{
219 		wrapper.dlg(x, y, wrapper.outer);
220 	}
221 
222 	extern(C) static void callBackPressedDestroy(OnPressedDelegateWrapper wrapper, GClosure* closure)
223 	{
224 		wrapper.remove(wrapper);
225 	}
226 }