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