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.GesturePan;
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.GestureDrag;
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  * #GtkGesturePan is a #GtkGesture implementation able to recognize
41  * pan gestures, those are drags that are locked to happen along one
42  * axis. The axis that a #GtkGesturePan handles is defined at
43  * construct time, and can be changed through
44  * gtk_gesture_pan_set_orientation().
45  * 
46  * When the gesture starts to be recognized, #GtkGesturePan will
47  * attempt to determine as early as possible whether the sequence
48  * is moving in the expected direction, and denying the sequence if
49  * this does not happen.
50  * 
51  * Once a panning gesture along the expected axis is recognized,
52  * the #GtkGesturePan::pan signal will be emitted as input events
53  * are received, containing the offset in the given axis.
54  */
55 public class GesturePan : GestureDrag
56 {
57 	/** the main Gtk struct */
58 	protected GtkGesturePan* gtkGesturePan;
59 
60 	/** Get the main Gtk struct */
61 	public GtkGesturePan* getGesturePanStruct(bool transferOwnership = false)
62 	{
63 		if (transferOwnership)
64 			ownedRef = false;
65 		return gtkGesturePan;
66 	}
67 
68 	/** the main Gtk struct as a void* */
69 	protected override void* getStruct()
70 	{
71 		return cast(void*)gtkGesturePan;
72 	}
73 
74 	protected override void setStruct(GObject* obj)
75 	{
76 		gtkGesturePan = cast(GtkGesturePan*)obj;
77 		super.setStruct(obj);
78 	}
79 
80 	/**
81 	 * Sets our main struct and passes it to the parent class.
82 	 */
83 	public this (GtkGesturePan* gtkGesturePan, bool ownedRef = false)
84 	{
85 		this.gtkGesturePan = gtkGesturePan;
86 		super(cast(GtkGestureDrag*)gtkGesturePan, ownedRef);
87 	}
88 
89 
90 	/** */
91 	public static GType getType()
92 	{
93 		return gtk_gesture_pan_get_type();
94 	}
95 
96 	/**
97 	 * Returns a newly created #GtkGesture that recognizes pan gestures.
98 	 *
99 	 * Params:
100 	 *     widget = a #GtkWidget
101 	 *     orientation = expected orientation
102 	 *
103 	 * Returns: a newly created #GtkGesturePan
104 	 *
105 	 * Since: 3.14
106 	 *
107 	 * Throws: ConstructionException GTK+ fails to create the object.
108 	 */
109 	public this(Widget widget, GtkOrientation orientation)
110 	{
111 		auto p = gtk_gesture_pan_new((widget is null) ? null : widget.getWidgetStruct(), orientation);
112 
113 		if(p is null)
114 		{
115 			throw new ConstructionException("null returned by new");
116 		}
117 
118 		this(cast(GtkGesturePan*) p, true);
119 	}
120 
121 	/**
122 	 * Returns the orientation of the pan gestures that this @gesture expects.
123 	 *
124 	 * Returns: the expected orientation for pan gestures
125 	 *
126 	 * Since: 3.14
127 	 */
128 	public GtkOrientation getOrientation()
129 	{
130 		return gtk_gesture_pan_get_orientation(gtkGesturePan);
131 	}
132 
133 	/**
134 	 * Sets the orientation to be expected on pan gestures.
135 	 *
136 	 * Params:
137 	 *     orientation = expected orientation
138 	 *
139 	 * Since: 3.14
140 	 */
141 	public void setOrientation(GtkOrientation orientation)
142 	{
143 		gtk_gesture_pan_set_orientation(gtkGesturePan, orientation);
144 	}
145 
146 	protected class OnPanDelegateWrapper
147 	{
148 		void delegate(GtkPanDirection, double, GesturePan) dlg;
149 		gulong handlerId;
150 
151 		this(void delegate(GtkPanDirection, double, GesturePan) dlg)
152 		{
153 			this.dlg = dlg;
154 			onPanListeners ~= this;
155 		}
156 
157 		void remove(OnPanDelegateWrapper source)
158 		{
159 			foreach(index, wrapper; onPanListeners)
160 			{
161 				if (wrapper.handlerId == source.handlerId)
162 				{
163 					onPanListeners[index] = null;
164 					onPanListeners = std.algorithm.remove(onPanListeners, index);
165 					break;
166 				}
167 			}
168 		}
169 	}
170 	OnPanDelegateWrapper[] onPanListeners;
171 
172 	/**
173 	 * This signal is emitted once a panning gesture along the
174 	 * expected axis is detected.
175 	 *
176 	 * Params:
177 	 *     direction = current direction of the pan gesture
178 	 *     offset = Offset along the gesture orientation
179 	 *
180 	 * Since: 3.14
181 	 */
182 	gulong addOnPan(void delegate(GtkPanDirection, double, GesturePan) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
183 	{
184 		auto wrapper = new OnPanDelegateWrapper(dlg);
185 		wrapper.handlerId = Signals.connectData(
186 			this,
187 			"pan",
188 			cast(GCallback)&callBackPan,
189 			cast(void*)wrapper,
190 			cast(GClosureNotify)&callBackPanDestroy,
191 			connectFlags);
192 		return wrapper.handlerId;
193 	}
194 
195 	extern(C) static void callBackPan(GtkGesturePan* gesturepanStruct, GtkPanDirection direction, double offset, OnPanDelegateWrapper wrapper)
196 	{
197 		wrapper.dlg(direction, offset, wrapper.outer);
198 	}
199 
200 	extern(C) static void callBackPanDestroy(OnPanDelegateWrapper wrapper, GClosure* closure)
201 	{
202 		wrapper.remove(wrapper);
203 	}
204 }