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.GestureMultiPress; 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 * #GtkGestureMultiPress is a #GtkGesture implementation able to recognize 40 * multiple clicks on a nearby zone, which can be listened for through the 41 * #GtkGestureMultiPress::pressed signal. Whenever time or distance between 42 * clicks exceed the GTK+ defaults, #GtkGestureMultiPress::stopped is emitted, 43 * and the click counter is reset. 44 * 45 * Callers may also restrict the area that is considered valid for a >1 46 * touch/button press through gtk_gesture_multi_press_set_area(), so any 47 * click happening outside that area is considered to be a first click of 48 * its own. 49 */ 50 public class GestureMultiPress : GestureSingle 51 { 52 /** the main Gtk struct */ 53 protected GtkGestureMultiPress* gtkGestureMultiPress; 54 55 /** Get the main Gtk struct */ 56 public GtkGestureMultiPress* getGestureMultiPressStruct() 57 { 58 return gtkGestureMultiPress; 59 } 60 61 /** the main Gtk struct as a void* */ 62 protected override void* getStruct() 63 { 64 return cast(void*)gtkGestureMultiPress; 65 } 66 67 protected override void setStruct(GObject* obj) 68 { 69 gtkGestureMultiPress = cast(GtkGestureMultiPress*)obj; 70 super.setStruct(obj); 71 } 72 73 /** 74 * Sets our main struct and passes it to the parent class. 75 */ 76 public this (GtkGestureMultiPress* gtkGestureMultiPress, bool ownedRef = false) 77 { 78 this.gtkGestureMultiPress = gtkGestureMultiPress; 79 super(cast(GtkGestureSingle*)gtkGestureMultiPress, ownedRef); 80 } 81 82 83 /** */ 84 public static GType getType() 85 { 86 return gtk_gesture_multi_press_get_type(); 87 } 88 89 /** 90 * Returns a newly created #GtkGesture that recognizes single and multiple 91 * presses. 92 * 93 * Params: 94 * widget = a #GtkWidget 95 * 96 * Returns: a newly created #GtkGestureMultiPress 97 * 98 * Since: 3.14 99 * 100 * Throws: ConstructionException GTK+ fails to create the object. 101 */ 102 public this(Widget widget) 103 { 104 auto p = gtk_gesture_multi_press_new((widget is null) ? null : widget.getWidgetStruct()); 105 106 if(p is null) 107 { 108 throw new ConstructionException("null returned by new"); 109 } 110 111 this(cast(GtkGestureMultiPress*) p, true); 112 } 113 114 /** 115 * If an area was set through gtk_gesture_multi_press_set_area(), 116 * this function will return %TRUE and fill in @rect with the 117 * press area. See gtk_gesture_multi_press_set_area() for more 118 * details on what the press area represents. 119 * 120 * Params: 121 * rect = return location for the press area 122 * 123 * Returns: %TRUE if @rect was filled with the press area 124 * 125 * Since: 3.14 126 */ 127 public bool getArea(out GdkRectangle rect) 128 { 129 return gtk_gesture_multi_press_get_area(gtkGestureMultiPress, &rect) != 0; 130 } 131 132 /** 133 * If @rect is non-%NULL, the press area will be checked to be 134 * confined within the rectangle, otherwise the button count 135 * will be reset so the press is seen as being the first one. 136 * If @rect is #NULL, the area will be reset to an unrestricted 137 * state. 138 * 139 * Note: The rectangle is only used to determine whether any 140 * non-first click falls within the expected area. This is not 141 * akin to an input shape. 142 * 143 * Params: 144 * rect = rectangle to receive coordinates on 145 * 146 * Since: 3.14 147 */ 148 public void setArea(GdkRectangle* rect) 149 { 150 gtk_gesture_multi_press_set_area(gtkGestureMultiPress, rect); 151 } 152 153 protected class OnPressedDelegateWrapper 154 { 155 static OnPressedDelegateWrapper[] listeners; 156 void delegate(int, double, double, GestureMultiPress) dlg; 157 gulong handlerId; 158 159 this(void delegate(int, double, double, GestureMultiPress) dlg) 160 { 161 this.dlg = dlg; 162 this.listeners ~= this; 163 } 164 165 void remove(OnPressedDelegateWrapper source) 166 { 167 foreach(index, wrapper; listeners) 168 { 169 if (wrapper.handlerId == source.handlerId) 170 { 171 listeners[index] = null; 172 listeners = std.algorithm.remove(listeners, index); 173 break; 174 } 175 } 176 } 177 } 178 179 /** 180 * This signal is emitted whenever a button or touch press happens. 181 * 182 * Params: 183 * nPress = how many touch/button presses happened with this one 184 * x = The X coordinate, in widget allocation coordinates 185 * y = The Y coordinate, in widget allocation coordinates 186 * 187 * Since: 3.14 188 */ 189 gulong addOnPressed(void delegate(int, double, double, GestureMultiPress) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 190 { 191 auto wrapper = new OnPressedDelegateWrapper(dlg); 192 wrapper.handlerId = Signals.connectData( 193 this, 194 "pressed", 195 cast(GCallback)&callBackPressed, 196 cast(void*)wrapper, 197 cast(GClosureNotify)&callBackPressedDestroy, 198 connectFlags); 199 return wrapper.handlerId; 200 } 201 202 extern(C) static void callBackPressed(GtkGestureMultiPress* gesturemultipressStruct, int nPress, double x, double y, OnPressedDelegateWrapper wrapper) 203 { 204 wrapper.dlg(nPress, x, y, wrapper.outer); 205 } 206 207 extern(C) static void callBackPressedDestroy(OnPressedDelegateWrapper wrapper, GClosure* closure) 208 { 209 wrapper.remove(wrapper); 210 } 211 212 protected class OnReleasedDelegateWrapper 213 { 214 static OnReleasedDelegateWrapper[] listeners; 215 void delegate(int, double, double, GestureMultiPress) dlg; 216 gulong handlerId; 217 218 this(void delegate(int, double, double, GestureMultiPress) dlg) 219 { 220 this.dlg = dlg; 221 this.listeners ~= this; 222 } 223 224 void remove(OnReleasedDelegateWrapper source) 225 { 226 foreach(index, wrapper; listeners) 227 { 228 if (wrapper.handlerId == source.handlerId) 229 { 230 listeners[index] = null; 231 listeners = std.algorithm.remove(listeners, index); 232 break; 233 } 234 } 235 } 236 } 237 238 /** 239 * This signal is emitted when a button or touch is released. @n_press 240 * will report the number of press that is paired to this event, note 241 * that #GtkGestureMultiPress::stopped may have been emitted between the 242 * press and its release, @n_press will only start over at the next press. 243 * 244 * Params: 245 * nPress = number of press that is paired with this release 246 * x = The X coordinate, in widget allocation coordinates 247 * y = The Y coordinate, in widget allocation coordinates 248 * 249 * Since: 3.14 250 */ 251 gulong addOnReleased(void delegate(int, double, double, GestureMultiPress) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 252 { 253 auto wrapper = new OnReleasedDelegateWrapper(dlg); 254 wrapper.handlerId = Signals.connectData( 255 this, 256 "released", 257 cast(GCallback)&callBackReleased, 258 cast(void*)wrapper, 259 cast(GClosureNotify)&callBackReleasedDestroy, 260 connectFlags); 261 return wrapper.handlerId; 262 } 263 264 extern(C) static void callBackReleased(GtkGestureMultiPress* gesturemultipressStruct, int nPress, double x, double y, OnReleasedDelegateWrapper wrapper) 265 { 266 wrapper.dlg(nPress, x, y, wrapper.outer); 267 } 268 269 extern(C) static void callBackReleasedDestroy(OnReleasedDelegateWrapper wrapper, GClosure* closure) 270 { 271 wrapper.remove(wrapper); 272 } 273 274 protected class OnStoppedDelegateWrapper 275 { 276 static OnStoppedDelegateWrapper[] listeners; 277 void delegate(GestureMultiPress) dlg; 278 gulong handlerId; 279 280 this(void delegate(GestureMultiPress) dlg) 281 { 282 this.dlg = dlg; 283 this.listeners ~= this; 284 } 285 286 void remove(OnStoppedDelegateWrapper source) 287 { 288 foreach(index, wrapper; listeners) 289 { 290 if (wrapper.handlerId == source.handlerId) 291 { 292 listeners[index] = null; 293 listeners = std.algorithm.remove(listeners, index); 294 break; 295 } 296 } 297 } 298 } 299 300 /** 301 * This signal is emitted whenever any time/distance threshold has 302 * been exceeded. 303 * 304 * Since: 3.14 305 */ 306 gulong addOnStopped(void delegate(GestureMultiPress) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 307 { 308 auto wrapper = new OnStoppedDelegateWrapper(dlg); 309 wrapper.handlerId = Signals.connectData( 310 this, 311 "stopped", 312 cast(GCallback)&callBackStopped, 313 cast(void*)wrapper, 314 cast(GClosureNotify)&callBackStoppedDestroy, 315 connectFlags); 316 return wrapper.handlerId; 317 } 318 319 extern(C) static void callBackStopped(GtkGestureMultiPress* gesturemultipressStruct, OnStoppedDelegateWrapper wrapper) 320 { 321 wrapper.dlg(wrapper.outer); 322 } 323 324 extern(C) static void callBackStoppedDestroy(OnStoppedDelegateWrapper wrapper, GClosure* closure) 325 { 326 wrapper.remove(wrapper); 327 } 328 }