alternative to assert
[gtkD.git] / src / gdk / Event.d
blobab440afd2ef04647002e7cd4177e3d7572e707ac
1 /*
2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = gdk-Events.html
26 * outPack = gdk
27 * outFile = Event
28 * strct = GdkEvent
29 * realStrct=
30 * ctorStrct=
31 * clss = Event
32 * interf =
33 * class Code: Yes
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gdk_event_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.Str
45 * - gdk.Event
46 * - gdk.Window
47 * - gdk.Display
48 * - gdk.Screen
49 * - gobject.Value
50 * structWrap:
51 * - GValue* -> Value
52 * - GdkDisplay* -> Display
53 * - GdkEvent* -> Event
54 * - GdkScreen* -> Screen
55 * - GdkWindow* -> Window
56 * local aliases:
59 module gdk.Event;
61 private import gdk.gdktypes;
63 private import lib.gdk;
65 private import glib.Str;
66 private import gdk.Event;
67 private import gdk.Window;
68 private import gdk.Display;
69 private import gdk.Screen;
70 private import gobject.Value;
72 /**
73 * Description
74 * This section describes functions dealing with events from the window system.
75 * In GTK+ applications the events are handled automatically in
76 * gtk_main_do_event() and passed on to the appropriate widgets, so these
77 * functions are rarely needed. Though some of the fields in the
78 * Event Structures are useful.
80 public class Event
83 /** the main Gtk struct */
84 protected GdkEvent* gdkEvent;
87 public GdkEvent* getEventStruct()
89 return gdkEvent;
93 /** the main Gtk struct as a void* */
94 protected void* getStruct()
96 return cast(void*)gdkEvent;
99 /**
100 * Sets our main struct and passes it to the parent class
102 public this (GdkEvent* gdkEvent)
104 this.gdkEvent = gdkEvent;
107 public static bool isDoubleClick(GdkEventButton* eventButton, int buttonNumber=1)
109 return eventButton.button==buttonNumber
110 && eventButton.type == EventType.DOUBLE_BUTTON_PRESS;
113 public static bool isTrippleClick(GdkEventButton* eventButton, int buttonNumber=1)
115 return eventButton.button==buttonNumber
116 && eventButton.type == EventType.TRIPPLE_BUTTON_PRESS;
128 * Checks if any events are ready to be processed for any display.
129 * Returns:
130 * TRUE if any events are pending.
132 public static int gdkEventsPending()
134 // gboolean gdk_events_pending (void);
135 return gdk_events_pending();
139 * If there is an event waiting in the event queue of some open
140 * display, returns a copy of it. See gdk_display_peek_event().
141 * Returns:
142 * a copy of the first GdkEvent on some event queue, or NULL if no
143 * events are in any queues. The returned GdkEvent should be freed with
144 * gdk_event_free().
146 public static Event peek()
148 // GdkEvent* gdk_event_peek (void);
149 return new Event( gdk_event_peek() );
153 * Checks all open displays for a GdkEvent to process,to be processed
154 * on, fetching events from the windowing system if necessary.
155 * See gdk_display_get_event().
156 * Returns:
157 * the next GdkEvent to be processed, or NULL if no events
158 * are pending. The returned GdkEvent should be freed with gdk_event_free().
160 public static Event get()
162 // GdkEvent* gdk_event_get (void);
163 return new Event( gdk_event_get() );
167 * Waits for a GraphicsExpose or NoExpose event from the X server.
168 * This is used in the GtkText and GtkCList widgets in GTK+ to make sure any
169 * GraphicsExpose events are handled before the widget is scrolled.
170 * window:
171 * the GdkWindow to wait for the events for.
172 * Returns:
173 * a GdkEventExpose if a GraphicsExpose was received, or NULL if a
174 * NoExpose event was received.
176 public static Event getGraphicsExpose(Window window)
178 // GdkEvent* gdk_event_get_graphics_expose (GdkWindow *window);
179 return new Event( gdk_event_get_graphics_expose((window is null) ? null : window.getWindowStruct()) );
183 * Appends a copy of the given event onto the front of the event
184 * queue for event->any.window's display, or the default event
185 * queue if event->any.window is NULL. See gdk_display_put_event().
186 * event:
187 * a GdkEvent.
189 public void put()
191 // void gdk_event_put (GdkEvent *event);
192 gdk_event_put(gdkEvent);
196 * Creates a new event of the given type. All fields are set to 0.
197 * type:
198 * a GdkEventType
199 * Returns:
200 * a newly-allocated GdkEvent. The returned GdkEvent
201 * should be freed with gdk_event_free().
202 * Since 2.2
204 public this (GdkEventType type)
206 // GdkEvent* gdk_event_new (GdkEventType type);
207 this(cast(GdkEvent*)gdk_event_new(type) );
211 * Copies a GdkEvent, copying or incrementing the reference count of the
212 * resources associated with it (e.g. GdkWindow's and strings).
213 * event:
214 * a GdkEvent
215 * Returns:
216 * a copy of event. The returned GdkEvent should be freed with
217 * gdk_event_free().
219 public Event copy()
221 // GdkEvent* gdk_event_copy (GdkEvent *event);
222 return new Event( gdk_event_copy(gdkEvent) );
226 * Frees a GdkEvent, freeing or decrementing any resources associated with it.
227 * Note that this function should only be called with events returned from
228 * functions such as gdk_event_peek(), gdk_event_get(),
229 * gdk_event_get_graphics_expose() and gdk_event_copy().
230 * event:
231 * a GdkEvent.
233 public void free()
235 // void gdk_event_free (GdkEvent *event);
236 gdk_event_free(gdkEvent);
240 * Returns the time stamp from event, if there is one; otherwise
241 * returns GDK_CURRENT_TIME. If event is NULL, returns GDK_CURRENT_TIME.
242 * event:
243 * a GdkEvent
244 * Returns:
245 * time stamp field from event
247 public uint getTime()
249 // guint32 gdk_event_get_time (GdkEvent *event);
250 return gdk_event_get_time(gdkEvent);
254 * If the event contains a "state" field, puts that field in state. Otherwise
255 * stores an empty state (0). Returns TRUE if there was a state field
256 * in the event. event may be NULL, in which case it's treated
257 * as if the event had no state field.
258 * event:
259 * a GdkEvent or NULL
260 * state:
261 * return location for state
262 * Returns:
263 * TRUE if there was a state field in the event
265 public int getState(GdkModifierType* state)
267 // gboolean gdk_event_get_state (GdkEvent *event, GdkModifierType *state);
268 return gdk_event_get_state(gdkEvent, state);
272 * Extract the axis value for a particular axis use from
273 * an event structure.
274 * event:
275 * a GdkEvent
276 * axis_use:
277 * the axis use to look for
278 * value:
279 * location to store the value found
280 * Returns:
281 * TRUE if the specified axis was found, otherwise FALSE
283 public int getAxis(GdkAxisUse axisUse, double* value)
285 // gboolean gdk_event_get_axis (GdkEvent *event, GdkAxisUse axis_use, gdouble *value);
286 return gdk_event_get_axis(gdkEvent, axisUse, value);
290 * Extract the event window relative x/y coordinates from an event.
291 * event:
292 * a GdkEvent
293 * x_win:
294 * location to put event window x coordinate
295 * y_win:
296 * location to put event window y coordinate
297 * Returns:
298 * TRUE if the event delivered event window coordinates
300 public int getCoords(double* xWin, double* yWin)
302 // gboolean gdk_event_get_coords (GdkEvent *event, gdouble *x_win, gdouble *y_win);
303 return gdk_event_get_coords(gdkEvent, xWin, yWin);
307 * Extract the root window relative x/y coordinates from an event.
308 * event:
309 * a GdkEvent
310 * x_root:
311 * location to put root window x coordinate
312 * y_root:
313 * location to put root window y coordinate
314 * Returns:
315 * TRUE if the event delivered root window coordinates
317 public int getRootCoords(double* xRoot, double* yRoot)
319 // gboolean gdk_event_get_root_coords (GdkEvent *event, gdouble *x_root, gdouble *y_root);
320 return gdk_event_get_root_coords(gdkEvent, xRoot, yRoot);
324 * Sets the function to call to handle all events from GDK.
325 * Note that GTK+ uses this to install its own event handler, so it is
326 * usually not useful for GTK+ applications. (Although an application
327 * can call this function then call gtk_main_do_event() to pass
328 * events to GTK+.)
329 * func:
330 * the function to call to handle events from GDK.
331 * data:
332 * user data to pass to the function.
333 * notify:
334 * the function to call when the handler function is removed, i.e. when
335 * gdk_event_handler_set() is called with another event handler.
337 public static void handlerSet(GdkEventFunc func, void* data, GDestroyNotify notify)
339 // void gdk_event_handler_set (GdkEventFunc func, gpointer data, GDestroyNotify notify);
340 gdk_event_handler_set(func, data, notify);
345 * Sends an X ClientMessage event to a given window (which must be
346 * on the default GdkDisplay.)
347 * This could be used for communicating between different applications,
348 * though the amount of data is limited to 20 bytes.
349 * event:
350 * the GdkEvent to send, which should be a GdkEventClient.
351 * winid:
352 * the window to send the X ClientMessage event to.
353 * Returns:
354 * non-zero on success.
356 public int sendClientMessage(GdkNativeWindow winid)
358 // gboolean gdk_event_send_client_message (GdkEvent *event, GdkNativeWindow winid);
359 return gdk_event_send_client_message(gdkEvent, winid);
363 * On X11, sends an X ClientMessage event to a given window. On
364 * Windows, sends a message registered with the name
365 * GDK_WIN32_CLIENT_MESSAGE.
366 * This could be used for communicating between different
367 * applications, though the amount of data is limited to 20 bytes on
368 * X11, and to just four bytes on Windows.
369 * display:
370 * the GdkDisplay for the window where the message is to be sent.
371 * event:
372 * the GdkEvent to send, which should be a GdkEventClient.
373 * winid:
374 * the window to send the client message to.
375 * Returns:
376 * non-zero on success.
377 * Since 2.2
379 public static int sendClientMessageForDisplay(Display display, Event event, GdkNativeWindow winid)
381 // gboolean gdk_event_send_client_message_for_display (GdkDisplay *display, GdkEvent *event, GdkNativeWindow winid);
382 return gdk_event_send_client_message_for_display((display is null) ? null : display.getDisplayStruct(), (event is null) ? null : event.getEventStruct(), winid);
386 * Sends an X ClientMessage event to all toplevel windows on the default
387 * GdkScreen.
388 * Toplevel windows are determined by checking for the WM_STATE property, as
389 * described in the Inter-Client Communication Conventions Manual (ICCCM).
390 * If no windows are found with the WM_STATE property set, the message is sent
391 * to all children of the root window.
392 * event:
393 * the GdkEvent to send, which should be a GdkEventClient.
395 public void sendClientmessageToall()
397 // void gdk_event_send_clientmessage_toall (GdkEvent *event);
398 gdk_event_send_clientmessage_toall(gdkEvent);
402 * Adds a filter to the default display to be called when X ClientMessage events
403 * are received. See gdk_display_add_client_message_filter().
404 * message_type:
405 * the type of ClientMessage events to receive. This will be
406 * checked against the message_type field of the
407 * XClientMessage event struct.
408 * func:
409 * the function to call to process the event.
410 * data:
411 * user data to pass to func.
413 public static void gdkAddClientMessageFilter(GdkAtom messageType, GdkFilterFunc func, void* data)
415 // void gdk_add_client_message_filter (GdkAtom message_type, GdkFilterFunc func, gpointer data);
416 gdk_add_client_message_filter(messageType, func, data);
420 * Gets whether event debugging output is enabled.
421 * Returns:
422 * TRUE if event debugging output is enabled.
424 public static int gdkGetShowEvents()
426 // gboolean gdk_get_show_events (void);
427 return gdk_get_show_events();
431 * Sets whether a trace of received events is output.
432 * Note that GTK+ must be compiled with debugging (that is,
433 * configured using the --enable-debug option)
434 * to use this option.
435 * show_events:
436 * TRUE to output event debugging information.
438 public static void gdkSetShowEvents(int showEvents)
440 // void gdk_set_show_events (gboolean show_events);
441 gdk_set_show_events(showEvents);
445 * Sets the screen for event to screen. The event must
446 * have been allocated by GTK+, for instance, by
447 * gdk_event_copy().
448 * event:
449 * a GdkEvent
450 * screen:
451 * a GdkScreen
452 * Since 2.2
454 public void setScreen(Screen screen)
456 // void gdk_event_set_screen (GdkEvent *event, GdkScreen *screen);
457 gdk_event_set_screen(gdkEvent, (screen is null) ? null : screen.getScreenStruct());
461 * Returns the screen for the event. The screen is
462 * typically the screen for event->any.window, but
463 * for events such as mouse events, it is the screen
464 * where the pointer was when the event occurs -
465 * that is, the screen which has the root window
466 * to which event->motion.x_root and
467 * event->motion.y_root are relative.
468 * event:
469 * a GdkEvent
470 * Returns:
471 * the screen for the event
472 * Since 2.2
474 public Screen getScreen()
476 // GdkScreen* gdk_event_get_screen (GdkEvent *event);
477 return new Screen( gdk_event_get_screen(gdkEvent) );
481 * Obtains a desktop-wide setting, such as the double-click time,
482 * for the default screen. See gdk_screen_get_setting().
483 * name:
484 * the name of the setting.
485 * value:
486 * location to store the value of the setting.
487 * Returns:
488 * : TRUE if the setting existed and a value was stored
489 * in value, FALSE otherwise.
490 * See Also
491 * Event Structures
492 * The structs used for each type of event.
494 public static int gdkSettingGet(char[] name, Value value)
496 // gboolean gdk_setting_get (const gchar *name, GValue *value);
497 return gdk_setting_get(Str.toStringz(name), (value is null) ? null : value.getValueStruct());