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