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