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