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 gdk.Event; 26 27 private import gdk.Device; 28 private import gdk.DeviceTool; 29 private import gdk.Display; 30 private import gdk.Seat; 31 private import gdk.Surface; 32 private import gdk.c.functions; 33 public import gdk.c.types; 34 private import gobject.ObjectG; 35 private import gtkd.Loader; 36 37 38 /** 39 * `GdkEvent`s are immutable data structures, created by GDK to 40 * represent windowing system events. 41 * 42 * In GTK applications the events are handled automatically by toplevel 43 * widgets and passed on to the event controllers of appropriate widgets, 44 * so using `GdkEvent` and its related API is rarely needed. 45 */ 46 public class Event 47 { 48 /** the main Gtk struct */ 49 protected GdkEvent* gdkEvent; 50 protected bool ownedRef; 51 52 /** Get the main Gtk struct */ 53 public GdkEvent* getEventStruct(bool transferOwnership = false) 54 { 55 if (transferOwnership) 56 ownedRef = false; 57 return gdkEvent; 58 } 59 60 /** the main Gtk struct as a void* */ 61 protected void* getStruct() 62 { 63 return cast(void*)gdkEvent; 64 } 65 66 /** 67 * Sets our main struct and passes it to the parent class. 68 */ 69 public this (GdkEvent* gdkEvent, bool ownedRef = false) 70 { 71 this.gdkEvent = gdkEvent; 72 this.ownedRef = ownedRef; 73 } 74 75 ~this () 76 { 77 if ( Linker.isLoaded(LIBRARY_GDK) && ownedRef ) 78 gdk_event_unref(gdkEvent); 79 } 80 81 82 /** */ 83 public static GType getType() 84 { 85 return gdk_event_get_type(); 86 } 87 88 /** 89 * Returns the relative angle from @event1 to @event2. 90 * 91 * The relative angle is the angle between the X axis and the line 92 * through both events' positions. The rotation direction for positive 93 * angles is from the positive X axis towards the positive Y axis. 94 * 95 * This assumes that both events have X/Y information. 96 * If not, this function returns %FALSE. 97 * 98 * Params: 99 * event2 = second `GdkEvent` 100 * angle = return location for the relative angle between both events 101 * 102 * Returns: %TRUE if the angle could be calculated. 103 */ 104 public bool GetAngle(Event event2, out double angle) 105 { 106 return gdk_events_get_angle(gdkEvent, (event2 is null) ? null : event2.getEventStruct(), &angle) != 0; 107 } 108 109 /** 110 * Returns the point halfway between the events' positions. 111 * 112 * This assumes that both events have X/Y information. 113 * If not, this function returns %FALSE. 114 * 115 * Params: 116 * event2 = second `GdkEvent` 117 * x = return location for the X coordinate of the center 118 * y = return location for the Y coordinate of the center 119 * 120 * Returns: %TRUE if the center could be calculated. 121 */ 122 public bool GetCenter(Event event2, out double x, out double y) 123 { 124 return gdk_events_get_center(gdkEvent, (event2 is null) ? null : event2.getEventStruct(), &x, &y) != 0; 125 } 126 127 /** 128 * Returns the distance between the event locations. 129 * 130 * This assumes that both events have X/Y information. 131 * If not, this function returns %FALSE. 132 * 133 * Params: 134 * event2 = second `GdkEvent` 135 * distance = return location for the distance 136 * 137 * Returns: %TRUE if the distance could be calculated. 138 */ 139 public bool GetDistance(Event event2, out double distance) 140 { 141 return gdk_events_get_distance(gdkEvent, (event2 is null) ? null : event2.getEventStruct(), &distance) != 0; 142 } 143 144 /** 145 * Extracts all axis values from an event. 146 * 147 * Params: 148 * axes = the array of values for all axes 149 * 150 * Returns: %TRUE on success, otherwise %FALSE 151 */ 152 public bool getAxes(out double[] axes) 153 { 154 double* outaxes; 155 uint nAxes; 156 157 auto __p = gdk_event_get_axes(gdkEvent, &outaxes, &nAxes) != 0; 158 159 axes = outaxes[0 .. nAxes]; 160 161 return __p; 162 } 163 164 /** 165 * Extract the axis value for a particular axis use from 166 * an event structure. 167 * 168 * Params: 169 * axisUse = the axis use to look for 170 * value = location to store the value found 171 * 172 * Returns: %TRUE if the specified axis was found, otherwise %FALSE 173 */ 174 public bool getAxis(GdkAxisUse axisUse, out double value) 175 { 176 return gdk_event_get_axis(gdkEvent, axisUse, &value) != 0; 177 } 178 179 /** 180 * Returns the device of an event. 181 * 182 * Returns: a #GdkDevice. 183 */ 184 public Device getDevice() 185 { 186 auto __p = gdk_event_get_device(gdkEvent); 187 188 if(__p is null) 189 { 190 return null; 191 } 192 193 return ObjectG.getDObject!(Device)(cast(GdkDevice*) __p); 194 } 195 196 /** 197 * Returns a `GdkDeviceTool` representing the tool that 198 * caused the event. 199 * 200 * If the was not generated by a device that supports 201 * different tools (such as a tablet), this function will 202 * return %NULL. 203 * 204 * Note: the `GdkDeviceTool` will be constant during 205 * the application lifetime, if settings must be stored 206 * persistently across runs, see [method@Gdk.DeviceTool.get_serial]. 207 * 208 * Returns: The current device tool, or %NULL 209 */ 210 public DeviceTool getDeviceTool() 211 { 212 auto __p = gdk_event_get_device_tool(gdkEvent); 213 214 if(__p is null) 215 { 216 return null; 217 } 218 219 return ObjectG.getDObject!(DeviceTool)(cast(GdkDeviceTool*) __p); 220 } 221 222 /** 223 * Retrieves the display associated to the @event. 224 * 225 * Returns: a #GdkDisplay 226 */ 227 public Display getDisplay() 228 { 229 auto __p = gdk_event_get_display(gdkEvent); 230 231 if(__p is null) 232 { 233 return null; 234 } 235 236 return ObjectG.getDObject!(Display)(cast(GdkDisplay*) __p); 237 } 238 239 /** 240 * Retuns the event sequence to which the event belongs. 241 * 242 * Related touch events are connected in a sequence. Other 243 * events typically don't have event sequence information. 244 * 245 * Returns: the event sequence that the event belongs to 246 */ 247 public GdkEventSequence* getEventSequence() 248 { 249 return gdk_event_get_event_sequence(gdkEvent); 250 } 251 252 /** 253 * Retrieves the type of the event. 254 * 255 * Returns: a `GdkEvent`Type 256 */ 257 public GdkEventType getEventType() 258 { 259 return gdk_event_get_event_type(gdkEvent); 260 } 261 262 /** 263 * Retrieves the history of the device that @event is for, as a list of 264 * time and coordinates. 265 * 266 * The history includes positions that are not delivered as separate events 267 * to the application because they occurred in the same frame as @event. 268 * 269 * Note that only motion and scroll events record history, and motion 270 * events do it only if one of the mouse buttons is down. 271 * 272 * Returns: an 273 * array of time and coordinates 274 */ 275 public GdkTimeCoord[] getHistory() 276 { 277 uint outNCoords; 278 279 auto __p = gdk_event_get_history(gdkEvent, &outNCoords); 280 281 return __p[0 .. outNCoords]; 282 } 283 284 /** 285 * Returns the modifier state field of an event. 286 * 287 * Returns: the modifier state of @event 288 */ 289 public GdkModifierType getModifierState() 290 { 291 return gdk_event_get_modifier_state(gdkEvent); 292 } 293 294 /** 295 * Returns whether this event is an 'emulated' pointer event. 296 * 297 * Emulated pointer events typically originate from a touch events. 298 * 299 * Returns: %TRUE if this event is emulated 300 */ 301 public bool getPointerEmulated() 302 { 303 return gdk_event_get_pointer_emulated(gdkEvent) != 0; 304 } 305 306 /** 307 * Extract the event surface relative x/y coordinates from an event. 308 * 309 * Params: 310 * x = location to put event surface x coordinate 311 * y = location to put event surface y coordinate 312 */ 313 public bool getPosition(out double x, out double y) 314 { 315 return gdk_event_get_position(gdkEvent, &x, &y) != 0; 316 } 317 318 /** 319 * Returns the seat that originated the event. 320 * 321 * Returns: a #GdkSeat. 322 */ 323 public Seat getSeat() 324 { 325 auto __p = gdk_event_get_seat(gdkEvent); 326 327 if(__p is null) 328 { 329 return null; 330 } 331 332 return ObjectG.getDObject!(Seat)(cast(GdkSeat*) __p); 333 } 334 335 /** 336 * Extracts the surface associated with an event. 337 * 338 * Returns: The #GdkSurface associated with the event 339 */ 340 public Surface getSurface() 341 { 342 auto __p = gdk_event_get_surface(gdkEvent); 343 344 if(__p is null) 345 { 346 return null; 347 } 348 349 return ObjectG.getDObject!(Surface)(cast(GdkSurface*) __p); 350 } 351 352 /** 353 * Returns the timestamp of @event. 354 * 355 * Not all events have timestamps. In that case, this function 356 * returns %GDK_CURRENT_TIME. 357 * 358 * Returns: timestamp field from @event 359 */ 360 public uint getTime() 361 { 362 return gdk_event_get_time(gdkEvent); 363 } 364 365 alias doref = ref_; 366 /** 367 * Increase the ref count of @event. 368 * 369 * Returns: @event 370 */ 371 public Event ref_() 372 { 373 auto __p = gdk_event_ref(gdkEvent); 374 375 if(__p is null) 376 { 377 return null; 378 } 379 380 return ObjectG.getDObject!(Event)(cast(GdkEvent*) __p, true); 381 } 382 383 /** 384 * Returns whether a `GdkEvent` should trigger a context menu, 385 * according to platform conventions. 386 * 387 * The right mouse button typically triggers context menus. 388 * 389 * This function should always be used instead of simply checking for 390 * event->button == %GDK_BUTTON_SECONDARY. 391 * 392 * Returns: %TRUE if the event should trigger a context menu. 393 */ 394 public bool triggersContextMenu() 395 { 396 return gdk_event_triggers_context_menu(gdkEvent) != 0; 397 } 398 399 /** 400 * Decrease the ref count of @event. 401 * 402 * If the last reference is dropped, the structure is freed. 403 */ 404 public void unref() 405 { 406 gdk_event_unref(gdkEvent); 407 } 408 }