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.GestureZoom;
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.Widget;
32 private import gtkc.gtk;
33 public  import gtkc.gtktypes;
34 private import std.algorithm;
35 
36 
37 /**
38  * #GtkGestureZoom is a #GtkGesture implementation able to recognize
39  * pinch/zoom gestures, whenever the distance between both tracked
40  * sequences changes, the #GtkGestureZoom::scale-changed signal is
41  * emitted to report the scale factor.
42  */
43 public class GestureZoom : Gesture
44 {
45 	/** the main Gtk struct */
46 	protected GtkGestureZoom* gtkGestureZoom;
47 
48 	/** Get the main Gtk struct */
49 	public GtkGestureZoom* getGestureZoomStruct(bool transferOwnership = false)
50 	{
51 		if (transferOwnership)
52 			ownedRef = false;
53 		return gtkGestureZoom;
54 	}
55 
56 	/** the main Gtk struct as a void* */
57 	protected override void* getStruct()
58 	{
59 		return cast(void*)gtkGestureZoom;
60 	}
61 
62 	protected override void setStruct(GObject* obj)
63 	{
64 		gtkGestureZoom = cast(GtkGestureZoom*)obj;
65 		super.setStruct(obj);
66 	}
67 
68 	/**
69 	 * Sets our main struct and passes it to the parent class.
70 	 */
71 	public this (GtkGestureZoom* gtkGestureZoom, bool ownedRef = false)
72 	{
73 		this.gtkGestureZoom = gtkGestureZoom;
74 		super(cast(GtkGesture*)gtkGestureZoom, ownedRef);
75 	}
76 
77 
78 	/** */
79 	public static GType getType()
80 	{
81 		return gtk_gesture_zoom_get_type();
82 	}
83 
84 	/**
85 	 * Returns a newly created #GtkGesture that recognizes zoom
86 	 * in/out gestures (usually known as pinch/zoom).
87 	 *
88 	 * Params:
89 	 *     widget = a #GtkWidget
90 	 *
91 	 * Returns: a newly created #GtkGestureZoom
92 	 *
93 	 * Since: 3.14
94 	 *
95 	 * Throws: ConstructionException GTK+ fails to create the object.
96 	 */
97 	public this(Widget widget)
98 	{
99 		auto p = gtk_gesture_zoom_new((widget is null) ? null : widget.getWidgetStruct());
100 		
101 		if(p is null)
102 		{
103 			throw new ConstructionException("null returned by new");
104 		}
105 		
106 		this(cast(GtkGestureZoom*) p, true);
107 	}
108 
109 	/**
110 	 * If @gesture is active, this function returns the zooming difference
111 	 * since the gesture was recognized (hence the starting point is
112 	 * considered 1:1). If @gesture is not active, 1 is returned.
113 	 *
114 	 * Returns: the scale delta
115 	 *
116 	 * Since: 3.14
117 	 */
118 	public double getScaleDelta()
119 	{
120 		return gtk_gesture_zoom_get_scale_delta(gtkGestureZoom);
121 	}
122 
123 	protected class OnScaleChangedDelegateWrapper
124 	{
125 		static OnScaleChangedDelegateWrapper[] listeners;
126 		void delegate(double, GestureZoom) dlg;
127 		gulong handlerId;
128 		
129 		this(void delegate(double, GestureZoom) dlg)
130 		{
131 			this.dlg = dlg;
132 			this.listeners ~= this;
133 		}
134 		
135 		void remove(OnScaleChangedDelegateWrapper source)
136 		{
137 			foreach(index, wrapper; listeners)
138 			{
139 				if (wrapper.handlerId == source.handlerId)
140 				{
141 					listeners[index] = null;
142 					listeners = std.algorithm.remove(listeners, index);
143 					break;
144 				}
145 			}
146 		}
147 	}
148 
149 	/**
150 	 * This signal is emitted whenever the distance between both tracked
151 	 * sequences changes.
152 	 *
153 	 * Params:
154 	 *     scale = Scale delta, taking the initial state as 1:1
155 	 *
156 	 * Since: 3.14
157 	 */
158 	gulong addOnScaleChanged(void delegate(double, GestureZoom) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
159 	{
160 		auto wrapper = new OnScaleChangedDelegateWrapper(dlg);
161 		wrapper.handlerId = Signals.connectData(
162 			this,
163 			"scale-changed",
164 			cast(GCallback)&callBackScaleChanged,
165 			cast(void*)wrapper,
166 			cast(GClosureNotify)&callBackScaleChangedDestroy,
167 			connectFlags);
168 		return wrapper.handlerId;
169 	}
170 	
171 	extern(C) static void callBackScaleChanged(GtkGestureZoom* gesturezoomStruct, double scale, OnScaleChangedDelegateWrapper wrapper)
172 	{
173 		wrapper.dlg(scale, wrapper.outer);
174 	}
175 	
176 	extern(C) static void callBackScaleChangedDestroy(OnScaleChangedDelegateWrapper wrapper, GClosure* closure)
177 	{
178 		wrapper.remove(wrapper);
179 	}
180 }