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.GestureDrag; 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 * #GtkGestureDrag is a #GtkGesture implementation that recognizes drag 41 * operations. The drag operation itself can be tracked throught the 42 * #GtkGestureDrag::drag-begin, #GtkGestureDrag::drag-update and 43 * #GtkGestureDrag::drag-end signals, or the relevant coordinates be 44 * extracted through gtk_gesture_drag_get_offset() and 45 * gtk_gesture_drag_get_start_point(). 46 */ 47 public class GestureDrag : GestureSingle 48 { 49 /** the main Gtk struct */ 50 protected GtkGestureDrag* gtkGestureDrag; 51 52 /** Get the main Gtk struct */ 53 public GtkGestureDrag* getGestureDragStruct(bool transferOwnership = false) 54 { 55 if (transferOwnership) 56 ownedRef = false; 57 return gtkGestureDrag; 58 } 59 60 /** the main Gtk struct as a void* */ 61 protected override void* getStruct() 62 { 63 return cast(void*)gtkGestureDrag; 64 } 65 66 /** 67 * Sets our main struct and passes it to the parent class. 68 */ 69 public this (GtkGestureDrag* gtkGestureDrag, bool ownedRef = false) 70 { 71 this.gtkGestureDrag = gtkGestureDrag; 72 super(cast(GtkGestureSingle*)gtkGestureDrag, ownedRef); 73 } 74 75 76 /** */ 77 public static GType getType() 78 { 79 return gtk_gesture_drag_get_type(); 80 } 81 82 /** 83 * Returns a newly created #GtkGesture that recognizes drags. 84 * 85 * Params: 86 * widget = a #GtkWidget 87 * 88 * Returns: a newly created #GtkGestureDrag 89 * 90 * Since: 3.14 91 * 92 * Throws: ConstructionException GTK+ fails to create the object. 93 */ 94 public this(Widget widget) 95 { 96 auto p = gtk_gesture_drag_new((widget is null) ? null : widget.getWidgetStruct()); 97 98 if(p is null) 99 { 100 throw new ConstructionException("null returned by new"); 101 } 102 103 this(cast(GtkGestureDrag*) p, true); 104 } 105 106 /** 107 * If the @gesture is active, this function returns %TRUE and 108 * fills in @x and @y with the coordinates of the current point, 109 * as an offset to the starting drag point. 110 * 111 * Params: 112 * x = X offset for the current point 113 * y = Y offset for the current point 114 * 115 * Returns: %TRUE if the gesture is active 116 * 117 * Since: 3.14 118 */ 119 public bool getOffset(out double x, out double y) 120 { 121 return gtk_gesture_drag_get_offset(gtkGestureDrag, &x, &y) != 0; 122 } 123 124 /** 125 * If the @gesture is active, this function returns %TRUE 126 * and fills in @x and @y with the drag start coordinates, 127 * in window-relative coordinates. 128 * 129 * Params: 130 * x = X coordinate for the drag start point 131 * y = Y coordinate for the drag start point 132 * 133 * Returns: %TRUE if the gesture is active 134 * 135 * Since: 3.14 136 */ 137 public bool getStartPoint(out double x, out double y) 138 { 139 return gtk_gesture_drag_get_start_point(gtkGestureDrag, &x, &y) != 0; 140 } 141 142 protected class OnDragBeginDelegateWrapper 143 { 144 void delegate(double, double, GestureDrag) dlg; 145 gulong handlerId; 146 147 this(void delegate(double, double, GestureDrag) dlg) 148 { 149 this.dlg = dlg; 150 onDragBeginListeners ~= this; 151 } 152 153 void remove(OnDragBeginDelegateWrapper source) 154 { 155 foreach(index, wrapper; onDragBeginListeners) 156 { 157 if (wrapper.handlerId == source.handlerId) 158 { 159 onDragBeginListeners[index] = null; 160 onDragBeginListeners = std.algorithm.remove(onDragBeginListeners, index); 161 break; 162 } 163 } 164 } 165 } 166 OnDragBeginDelegateWrapper[] onDragBeginListeners; 167 168 /** 169 * This signal is emitted whenever dragging starts. 170 * 171 * Params: 172 * startX = X coordinate, relative to the widget allocation 173 * startY = Y coordinate, relative to the widget allocation 174 * 175 * Since: 3.14 176 */ 177 gulong addOnDragBegin(void delegate(double, double, GestureDrag) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 178 { 179 auto wrapper = new OnDragBeginDelegateWrapper(dlg); 180 wrapper.handlerId = Signals.connectData( 181 this, 182 "drag-begin", 183 cast(GCallback)&callBackDragBegin, 184 cast(void*)wrapper, 185 cast(GClosureNotify)&callBackDragBeginDestroy, 186 connectFlags); 187 return wrapper.handlerId; 188 } 189 190 extern(C) static void callBackDragBegin(GtkGestureDrag* gesturedragStruct, double startX, double startY, OnDragBeginDelegateWrapper wrapper) 191 { 192 wrapper.dlg(startX, startY, wrapper.outer); 193 } 194 195 extern(C) static void callBackDragBeginDestroy(OnDragBeginDelegateWrapper wrapper, GClosure* closure) 196 { 197 wrapper.remove(wrapper); 198 } 199 200 protected class OnDragEndDelegateWrapper 201 { 202 void delegate(double, double, GestureDrag) dlg; 203 gulong handlerId; 204 205 this(void delegate(double, double, GestureDrag) dlg) 206 { 207 this.dlg = dlg; 208 onDragEndListeners ~= this; 209 } 210 211 void remove(OnDragEndDelegateWrapper source) 212 { 213 foreach(index, wrapper; onDragEndListeners) 214 { 215 if (wrapper.handlerId == source.handlerId) 216 { 217 onDragEndListeners[index] = null; 218 onDragEndListeners = std.algorithm.remove(onDragEndListeners, index); 219 break; 220 } 221 } 222 } 223 } 224 OnDragEndDelegateWrapper[] onDragEndListeners; 225 226 /** 227 * This signal is emitted whenever the dragging is finished. 228 * 229 * Params: 230 * offsetX = X offset, relative to the start point 231 * offsetY = Y offset, relative to the start point 232 * 233 * Since: 3.14 234 */ 235 gulong addOnDragEnd(void delegate(double, double, GestureDrag) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 236 { 237 auto wrapper = new OnDragEndDelegateWrapper(dlg); 238 wrapper.handlerId = Signals.connectData( 239 this, 240 "drag-end", 241 cast(GCallback)&callBackDragEnd, 242 cast(void*)wrapper, 243 cast(GClosureNotify)&callBackDragEndDestroy, 244 connectFlags); 245 return wrapper.handlerId; 246 } 247 248 extern(C) static void callBackDragEnd(GtkGestureDrag* gesturedragStruct, double offsetX, double offsetY, OnDragEndDelegateWrapper wrapper) 249 { 250 wrapper.dlg(offsetX, offsetY, wrapper.outer); 251 } 252 253 extern(C) static void callBackDragEndDestroy(OnDragEndDelegateWrapper wrapper, GClosure* closure) 254 { 255 wrapper.remove(wrapper); 256 } 257 258 protected class OnDragUpdateDelegateWrapper 259 { 260 void delegate(double, double, GestureDrag) dlg; 261 gulong handlerId; 262 263 this(void delegate(double, double, GestureDrag) dlg) 264 { 265 this.dlg = dlg; 266 onDragUpdateListeners ~= this; 267 } 268 269 void remove(OnDragUpdateDelegateWrapper source) 270 { 271 foreach(index, wrapper; onDragUpdateListeners) 272 { 273 if (wrapper.handlerId == source.handlerId) 274 { 275 onDragUpdateListeners[index] = null; 276 onDragUpdateListeners = std.algorithm.remove(onDragUpdateListeners, index); 277 break; 278 } 279 } 280 } 281 } 282 OnDragUpdateDelegateWrapper[] onDragUpdateListeners; 283 284 /** 285 * This signal is emitted whenever the dragging point moves. 286 * 287 * Params: 288 * offsetX = X offset, relative to the start point 289 * offsetY = Y offset, relative to the start point 290 * 291 * Since: 3.14 292 */ 293 gulong addOnDragUpdate(void delegate(double, double, GestureDrag) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 294 { 295 auto wrapper = new OnDragUpdateDelegateWrapper(dlg); 296 wrapper.handlerId = Signals.connectData( 297 this, 298 "drag-update", 299 cast(GCallback)&callBackDragUpdate, 300 cast(void*)wrapper, 301 cast(GClosureNotify)&callBackDragUpdateDestroy, 302 connectFlags); 303 return wrapper.handlerId; 304 } 305 306 extern(C) static void callBackDragUpdate(GtkGestureDrag* gesturedragStruct, double offsetX, double offsetY, OnDragUpdateDelegateWrapper wrapper) 307 { 308 wrapper.dlg(offsetX, offsetY, wrapper.outer); 309 } 310 311 extern(C) static void callBackDragUpdateDestroy(OnDragUpdateDelegateWrapper wrapper, GClosure* closure) 312 { 313 wrapper.remove(wrapper); 314 } 315 }