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