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.GestureLongPress; 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 * #GtkGestureLongPress is a #GtkGesture implementation able to recognize 41 * long presses, triggering the #GtkGestureLongPress::pressed after the 42 * timeout is exceeded. 43 * 44 * If the touchpoint is lifted before the timeout passes, or if it drifts 45 * too far of the initial press point, the #GtkGestureLongPress::cancelled 46 * signal will be emitted. 47 */ 48 public class GestureLongPress : GestureSingle 49 { 50 /** the main Gtk struct */ 51 protected GtkGestureLongPress* gtkGestureLongPress; 52 53 /** Get the main Gtk struct */ 54 public GtkGestureLongPress* getGestureLongPressStruct() 55 { 56 return gtkGestureLongPress; 57 } 58 59 /** the main Gtk struct as a void* */ 60 protected override void* getStruct() 61 { 62 return cast(void*)gtkGestureLongPress; 63 } 64 65 protected override void setStruct(GObject* obj) 66 { 67 gtkGestureLongPress = cast(GtkGestureLongPress*)obj; 68 super.setStruct(obj); 69 } 70 71 /** 72 * Sets our main struct and passes it to the parent class. 73 */ 74 public this (GtkGestureLongPress* gtkGestureLongPress, bool ownedRef = false) 75 { 76 this.gtkGestureLongPress = gtkGestureLongPress; 77 super(cast(GtkGestureSingle*)gtkGestureLongPress, ownedRef); 78 } 79 80 81 /** */ 82 public static GType getType() 83 { 84 return gtk_gesture_long_press_get_type(); 85 } 86 87 /** 88 * Returns a newly created #GtkGesture that recognizes long presses. 89 * 90 * Params: 91 * widget = a #GtkWidget 92 * 93 * Return: a newly created #GtkGestureLongPress 94 * 95 * Since: 3.14 96 * 97 * Throws: ConstructionException GTK+ fails to create the object. 98 */ 99 public this(Widget widget) 100 { 101 auto p = gtk_gesture_long_press_new((widget is null) ? null : widget.getWidgetStruct()); 102 103 if(p is null) 104 { 105 throw new ConstructionException("null returned by new"); 106 } 107 108 this(cast(GtkGestureLongPress*) p, true); 109 } 110 111 protected class OnCancelledDelegateWrapper 112 { 113 void delegate(GestureLongPress) dlg; 114 gulong handlerId; 115 ConnectFlags flags; 116 this(void delegate(GestureLongPress) dlg, gulong handlerId, ConnectFlags flags) 117 { 118 this.dlg = dlg; 119 this.handlerId = handlerId; 120 this.flags = flags; 121 } 122 } 123 protected OnCancelledDelegateWrapper[] onCancelledListeners; 124 125 /** 126 * This signal is emitted whenever a press moved too far, or was released 127 * before #GtkGestureLongPress::pressed happened. 128 * 129 * Since: 3.14 130 */ 131 gulong addOnCancelled(void delegate(GestureLongPress) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 132 { 133 onCancelledListeners ~= new OnCancelledDelegateWrapper(dlg, 0, connectFlags); 134 onCancelledListeners[onCancelledListeners.length - 1].handlerId = Signals.connectData( 135 this, 136 "cancelled", 137 cast(GCallback)&callBackCancelled, 138 cast(void*)onCancelledListeners[onCancelledListeners.length - 1], 139 cast(GClosureNotify)&callBackCancelledDestroy, 140 connectFlags); 141 return onCancelledListeners[onCancelledListeners.length - 1].handlerId; 142 } 143 144 extern(C) static void callBackCancelled(GtkGestureLongPress* gesturelongpressStruct,OnCancelledDelegateWrapper wrapper) 145 { 146 wrapper.dlg(wrapper.outer); 147 } 148 149 extern(C) static void callBackCancelledDestroy(OnCancelledDelegateWrapper wrapper, GClosure* closure) 150 { 151 wrapper.outer.internalRemoveOnCancelled(wrapper); 152 } 153 154 protected void internalRemoveOnCancelled(OnCancelledDelegateWrapper source) 155 { 156 foreach(index, wrapper; onCancelledListeners) 157 { 158 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 159 { 160 onCancelledListeners[index] = null; 161 onCancelledListeners = std.algorithm.remove(onCancelledListeners, index); 162 break; 163 } 164 } 165 } 166 167 168 protected class OnPressedDelegateWrapper 169 { 170 void delegate(double, double, GestureLongPress) dlg; 171 gulong handlerId; 172 ConnectFlags flags; 173 this(void delegate(double, double, GestureLongPress) dlg, gulong handlerId, ConnectFlags flags) 174 { 175 this.dlg = dlg; 176 this.handlerId = handlerId; 177 this.flags = flags; 178 } 179 } 180 protected OnPressedDelegateWrapper[] onPressedListeners; 181 182 /** 183 * This signal is emitted whenever a press goes unmoved/unreleased longer than 184 * what the GTK+ defaults tell. 185 * 186 * Params: 187 * x = the X coordinate where the press happened, relative to the widget allocation 188 * y = the Y coordinate where the press happened, relative to the widget allocation 189 * 190 * Since: 3.14 191 */ 192 gulong addOnPressed(void delegate(double, double, GestureLongPress) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 193 { 194 onPressedListeners ~= new OnPressedDelegateWrapper(dlg, 0, connectFlags); 195 onPressedListeners[onPressedListeners.length - 1].handlerId = Signals.connectData( 196 this, 197 "pressed", 198 cast(GCallback)&callBackPressed, 199 cast(void*)onPressedListeners[onPressedListeners.length - 1], 200 cast(GClosureNotify)&callBackPressedDestroy, 201 connectFlags); 202 return onPressedListeners[onPressedListeners.length - 1].handlerId; 203 } 204 205 extern(C) static void callBackPressed(GtkGestureLongPress* gesturelongpressStruct, double x, double y,OnPressedDelegateWrapper wrapper) 206 { 207 wrapper.dlg(x, y, wrapper.outer); 208 } 209 210 extern(C) static void callBackPressedDestroy(OnPressedDelegateWrapper wrapper, GClosure* closure) 211 { 212 wrapper.outer.internalRemoveOnPressed(wrapper); 213 } 214 215 protected void internalRemoveOnPressed(OnPressedDelegateWrapper source) 216 { 217 foreach(index, wrapper; onPressedListeners) 218 { 219 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 220 { 221 onPressedListeners[index] = null; 222 onPressedListeners = std.algorithm.remove(onPressedListeners, index); 223 break; 224 } 225 } 226 } 227 228 }