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