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  * Conversion parameters:
26  * inFile  = gdk-Events.html
27  * outPack = gdk
28  * outFile = Event
29  * strct   = GdkEvent
30  * realStrct=
31  * ctorStrct=
32  * clss    = Event
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gdk_event_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- gdk.Window
48  * 	- gdk.Display
49  * 	- gdk.Screen
50  * 	- gobject.Value
51  * structWrap:
52  * 	- GValue* -> Value
53  * 	- GdkDisplay* -> Display
54  * 	- GdkEvent* -> Event
55  * 	- GdkScreen* -> Screen
56  * 	- GdkWindow* -> Window
57  * module aliases:
58  * local aliases:
59  * overrides:
60  */
61 
62 module gdk.Event;
63 
64 public  import gtkc.gdktypes;
65 
66 private import gtkc.gdk;
67 private import glib.ConstructionException;
68 private import gobject.ObjectG;
69 
70 
71 private import glib.Str;
72 private import gdk.Window;
73 private import gdk.Display;
74 private import gdk.Screen;
75 private import gobject.Value;
76 
77 
78 
79 
80 /**
81  * Description
82  * This section describes functions dealing with events from the window system.
83  * In GTK+ applications the events are handled automatically in
84  * gtk_main_do_event() and passed on to the appropriate widgets, so these
85  * functions are rarely needed. Though some of the fields in the
86  * Event Structures are useful.
87  */
88 public class Event
89 {
90 	
91 	/** the main Gtk struct */
92 	protected GdkEvent* gdkEvent;
93 	
94 	
95 	public GdkEvent* getEventStruct()
96 	{
97 		return gdkEvent;
98 	}
99 	
100 	
101 	/** the main Gtk struct as a void* */
102 	protected void* getStruct()
103 	{
104 		return cast(void*)gdkEvent;
105 	}
106 	
107 	/**
108 	 * Sets our main struct and passes it to the parent class
109 	 */
110 	public this (GdkEvent* gdkEvent)
111 	{
112 		this.gdkEvent = gdkEvent;
113 	}
114 	
115 	/** */
116 	public static bool isDoubleClick(GdkEventButton* eventButton, int buttonNumber=1)
117 	{
118 		return eventButton.button==buttonNumber
119 		&& eventButton.type == EventType.DOUBLE_BUTTON_PRESS;
120 	}
121 	
122 	/** */
123 	public static bool isTripleClick(GdkEventButton* eventButton, int buttonNumber=1)
124 	{
125 		return eventButton.button==buttonNumber
126 		&& eventButton.type == EventType.TRIPLE_BUTTON_PRESS;
127 	}
128 	
129 	/**
130 	 */
131 	
132 	/**
133 	 * Checks if any events are ready to be processed for any display.
134 	 * Returns: TRUE if any events are pending.
135 	 */
136 	public static int gdkEventsPending()
137 	{
138 		// gboolean gdk_events_pending (void);
139 		return gdk_events_pending();
140 	}
141 	
142 	/**
143 	 * If there is an event waiting in the event queue of some open
144 	 * display, returns a copy of it. See gdk_display_peek_event().
145 	 * Returns: a copy of the first GdkEvent on some event queue, or NULL if no events are in any queues. The returned GdkEvent should be freed with gdk_event_free().
146 	 */
147 	public static Event peek()
148 	{
149 		// GdkEvent * gdk_event_peek (void);
150 		auto p = gdk_event_peek();
151 		
152 		if(p is null)
153 		{
154 			return null;
155 		}
156 		
157 		return ObjectG.getDObject!(Event)(cast(GdkEvent*) p);
158 	}
159 	
160 	/**
161 	 * Checks all open displays for a GdkEvent to process,to be processed
162 	 * on, fetching events from the windowing system if necessary.
163 	 * See gdk_display_get_event().
164 	 * Returns: the next GdkEvent to be processed, or NULL if no events are pending. The returned GdkEvent should be freed with gdk_event_free().
165 	 */
166 	public static Event get()
167 	{
168 		// GdkEvent * gdk_event_get (void);
169 		auto p = gdk_event_get();
170 		
171 		if(p is null)
172 		{
173 			return null;
174 		}
175 		
176 		return ObjectG.getDObject!(Event)(cast(GdkEvent*) p);
177 	}
178 	
179 	/**
180 	 * Warning
181 	 * gdk_event_get_graphics_expose has been deprecated since version 2.18 and should not be used in newly-written code.
182 	 * Waits for a GraphicsExpose or NoExpose event from the X server.
183 	 * This is used in the GtkText and GtkCList widgets in GTK+ to make sure any
184 	 * GraphicsExpose events are handled before the widget is scrolled.
185 	 * Params:
186 	 * window = the GdkWindow to wait for the events for.
187 	 * Returns: a GdkEventExpose if a GraphicsExpose was received, or NULL if a NoExpose event was received.
188 	 */
189 	public static Event getGraphicsExpose(Window window)
190 	{
191 		// GdkEvent * gdk_event_get_graphics_expose (GdkWindow *window);
192 		auto p = gdk_event_get_graphics_expose((window is null) ? null : window.getWindowStruct());
193 		
194 		if(p is null)
195 		{
196 			return null;
197 		}
198 		
199 		return ObjectG.getDObject!(Event)(cast(GdkEvent*) p);
200 	}
201 	
202 	/**
203 	 * Appends a copy of the given event onto the front of the event
204 	 * queue for event->any.window's display, or the default event
205 	 * queue if event->any.window is NULL. See gdk_display_put_event().
206 	 */
207 	public void put()
208 	{
209 		// void gdk_event_put (const GdkEvent *event);
210 		gdk_event_put(gdkEvent);
211 	}
212 	
213 	/**
214 	 * Creates a new event of the given type. All fields are set to 0.
215 	 * Since 2.2
216 	 * Params:
217 	 * type = a GdkEventType
218 	 * Throws: ConstructionException GTK+ fails to create the object.
219 	 */
220 	public this (GdkEventType type)
221 	{
222 		// GdkEvent * gdk_event_new (GdkEventType type);
223 		auto p = gdk_event_new(type);
224 		if(p is null)
225 		{
226 			throw new ConstructionException("null returned by gdk_event_new(type)");
227 		}
228 		this(cast(GdkEvent*) p);
229 	}
230 	
231 	/**
232 	 * Copies a GdkEvent, copying or incrementing the reference count of the
233 	 * resources associated with it (e.g. GdkWindow's and strings).
234 	 * Returns: a copy of event. The returned GdkEvent should be freed with gdk_event_free().
235 	 */
236 	public Event copy()
237 	{
238 		// GdkEvent * gdk_event_copy (const GdkEvent *event);
239 		auto p = gdk_event_copy(gdkEvent);
240 		
241 		if(p is null)
242 		{
243 			return null;
244 		}
245 		
246 		return ObjectG.getDObject!(Event)(cast(GdkEvent*) p);
247 	}
248 	
249 	/**
250 	 * Frees a GdkEvent, freeing or decrementing any resources associated with it.
251 	 * Note that this function should only be called with events returned from
252 	 * functions such as gdk_event_peek(), gdk_event_get(),
253 	 * gdk_event_get_graphics_expose() and gdk_event_copy() and gdk_event_new().
254 	 */
255 	public void free()
256 	{
257 		// void gdk_event_free (GdkEvent *event);
258 		gdk_event_free(gdkEvent);
259 	}
260 	
261 	/**
262 	 * Returns the time stamp from event, if there is one; otherwise
263 	 * returns GDK_CURRENT_TIME. If event is NULL, returns GDK_CURRENT_TIME.
264 	 * Returns: time stamp field from event
265 	 */
266 	public uint getTime()
267 	{
268 		// guint32 gdk_event_get_time (const GdkEvent *event);
269 		return gdk_event_get_time(gdkEvent);
270 	}
271 	
272 	/**
273 	 * If the event contains a "state" field, puts that field in state. Otherwise
274 	 * stores an empty state (0). Returns TRUE if there was a state field
275 	 * in the event. event may be NULL, in which case it's treated
276 	 * as if the event had no state field.
277 	 * Params:
278 	 * state = return location for state. [out]
279 	 * Returns: TRUE if there was a state field in the event
280 	 */
281 	public int getState(out GdkModifierType state)
282 	{
283 		// gboolean gdk_event_get_state (const GdkEvent *event,  GdkModifierType *state);
284 		return gdk_event_get_state(gdkEvent, &state);
285 	}
286 	
287 	/**
288 	 * Extract the axis value for a particular axis use from
289 	 * an event structure.
290 	 * Params:
291 	 * axisUse = the axis use to look for
292 	 * value = location to store the value found. [out]
293 	 * Returns: TRUE if the specified axis was found, otherwise FALSE
294 	 */
295 	public int getAxis(GdkAxisUse axisUse, out double value)
296 	{
297 		// gboolean gdk_event_get_axis (const GdkEvent *event,  GdkAxisUse axis_use,  gdouble *value);
298 		return gdk_event_get_axis(gdkEvent, axisUse, &value);
299 	}
300 	
301 	/**
302 	 * Extract the event window relative x/y coordinates from an event.
303 	 * Params:
304 	 * xWin = location to put event window x coordinate. [out]
305 	 * yWin = location to put event window y coordinate. [out]
306 	 * Returns: TRUE if the event delivered event window coordinates
307 	 */
308 	public int getCoords(out double xWin, out double yWin)
309 	{
310 		// gboolean gdk_event_get_coords (const GdkEvent *event,  gdouble *x_win,  gdouble *y_win);
311 		return gdk_event_get_coords(gdkEvent, &xWin, &yWin);
312 	}
313 	
314 	/**
315 	 * Extract the root window relative x/y coordinates from an event.
316 	 * Params:
317 	 * xRoot = location to put root window x coordinate. [out]
318 	 * yRoot = location to put root window y coordinate. [out]
319 	 * Returns: TRUE if the event delivered root window coordinates
320 	 */
321 	public int getRootCoords(out double xRoot, out double yRoot)
322 	{
323 		// gboolean gdk_event_get_root_coords (const GdkEvent *event,  gdouble *x_root,  gdouble *y_root);
324 		return gdk_event_get_root_coords(gdkEvent, &xRoot, &yRoot);
325 	}
326 	
327 	/**
328 	 * Request more motion notifies if event is a motion notify hint event.
329 	 * This function should be used instead of gdk_window_get_pointer() to
330 	 * request further motion notifies, because it also works for extension
331 	 * events where motion notifies are provided for devices other than the
332 	 * core pointer. Coordinate extraction, processing and requesting more
333 	 * Since 2.12
334 	 * Params:
335 	 * event = a valid GdkEvent
336 	 */
337 	public static void requestMotions(GdkEventMotion* event)
338 	{
339 		// void gdk_event_request_motions (const GdkEventMotion *event);
340 		gdk_event_request_motions(event);
341 	}
342 	
343 	/**
344 	 * Sets the function to call to handle all events from GDK.
345 	 * Note that GTK+ uses this to install its own event handler, so it is
346 	 * usually not useful for GTK+ applications. (Although an application
347 	 * can call this function then call gtk_main_do_event() to pass
348 	 * events to GTK+.)
349 	 * Params:
350 	 * func = the function to call to handle events from GDK.
351 	 * data = user data to pass to the function.
352 	 * notify = the function to call when the handler function is removed, i.e. when
353 	 * gdk_event_handler_set() is called with another event handler.
354 	 */
355 	public static void handlerSet(GdkEventFunc func, void* data, GDestroyNotify notify)
356 	{
357 		// void gdk_event_handler_set (GdkEventFunc func,  gpointer data,  GDestroyNotify notify);
358 		gdk_event_handler_set(func, data, notify);
359 	}
360 	
361 	/**
362 	 * Sends an X ClientMessage event to a given window (which must be
363 	 * on the default GdkDisplay.)
364 	 * This could be used for communicating between different applications,
365 	 * though the amount of data is limited to 20 bytes.
366 	 * Params:
367 	 * winid = the window to send the X ClientMessage event to.
368 	 * Returns: non-zero on success.
369 	 */
370 	public int sendClientMessage(GdkNativeWindow winid)
371 	{
372 		// gboolean gdk_event_send_client_message (GdkEvent *event,  GdkNativeWindow winid);
373 		return gdk_event_send_client_message(gdkEvent, winid);
374 	}
375 	
376 	/**
377 	 * On X11, sends an X ClientMessage event to a given window. On
378 	 * Windows, sends a message registered with the name
379 	 * GDK_WIN32_CLIENT_MESSAGE.
380 	 * This could be used for communicating between different
381 	 * applications, though the amount of data is limited to 20 bytes on
382 	 * X11, and to just four bytes on Windows.
383 	 * Since 2.2
384 	 * Params:
385 	 * display = the GdkDisplay for the window where the message is to be sent.
386 	 * event = the GdkEvent to send, which should be a GdkEventClient.
387 	 * winid = the window to send the client message to.
388 	 * Returns: non-zero on success.
389 	 */
390 	public static int sendClientMessageForDisplay(Display display, Event event, GdkNativeWindow winid)
391 	{
392 		// gboolean gdk_event_send_client_message_for_display  (GdkDisplay *display,  GdkEvent *event,  GdkNativeWindow winid);
393 		return gdk_event_send_client_message_for_display((display is null) ? null : display.getDisplayStruct(), (event is null) ? null : event.getEventStruct(), winid);
394 	}
395 	
396 	/**
397 	 * Sends an X ClientMessage event to all toplevel windows on the default
398 	 * GdkScreen.
399 	 * Toplevel windows are determined by checking for the WM_STATE property, as
400 	 * described in the Inter-Client Communication Conventions Manual (ICCCM).
401 	 * If no windows are found with the WM_STATE property set, the message is sent
402 	 * to all children of the root window.
403 	 */
404 	public void sendClientmessageToall()
405 	{
406 		// void gdk_event_send_clientmessage_toall (GdkEvent *event);
407 		gdk_event_send_clientmessage_toall(gdkEvent);
408 	}
409 	
410 	/**
411 	 * Adds a filter to the default display to be called when X ClientMessage events
412 	 * are received. See gdk_display_add_client_message_filter().
413 	 * Params:
414 	 * messageType = the type of ClientMessage events to receive. This will be
415 	 * checked against the message_type field of the
416 	 * XClientMessage event struct.
417 	 * func = the function to call to process the event.
418 	 * data = user data to pass to func.
419 	 */
420 	public static void gdkAddClientMessageFilter(GdkAtom messageType, GdkFilterFunc func, void* data)
421 	{
422 		// void gdk_add_client_message_filter (GdkAtom message_type,  GdkFilterFunc func,  gpointer data);
423 		gdk_add_client_message_filter(messageType, func, data);
424 	}
425 	
426 	/**
427 	 * Gets whether event debugging output is enabled.
428 	 * Returns: TRUE if event debugging output is enabled.
429 	 */
430 	public static int gdkGetShowEvents()
431 	{
432 		// gboolean gdk_get_show_events (void);
433 		return gdk_get_show_events();
434 	}
435 	
436 	/**
437 	 * Sets whether a trace of received events is output.
438 	 * Note that GTK+ must be compiled with debugging (that is,
439 	 * configured using the --enable-debug option)
440 	 * to use this option.
441 	 * Params:
442 	 * showEvents = TRUE to output event debugging information.
443 	 */
444 	public static void gdkSetShowEvents(int showEvents)
445 	{
446 		// void gdk_set_show_events (gboolean show_events);
447 		gdk_set_show_events(showEvents);
448 	}
449 	
450 	/**
451 	 * Sets the screen for event to screen. The event must
452 	 * have been allocated by GTK+, for instance, by
453 	 * gdk_event_copy().
454 	 * Since 2.2
455 	 * Params:
456 	 * screen = a GdkScreen
457 	 */
458 	public void setScreen(Screen screen)
459 	{
460 		// void gdk_event_set_screen (GdkEvent *event,  GdkScreen *screen);
461 		gdk_event_set_screen(gdkEvent, (screen is null) ? null : screen.getScreenStruct());
462 	}
463 	
464 	/**
465 	 * Returns the screen for the event. The screen is
466 	 * typically the screen for event->any.window, but
467 	 * for events such as mouse events, it is the screen
468 	 * where the pointer was when the event occurs -
469 	 * that is, the screen which has the root window
470 	 * to which event->motion.x_root and
471 	 * event->motion.y_root are relative.
472 	 * Since 2.2
473 	 * Returns: the screen for the event
474 	 */
475 	public Screen getScreen()
476 	{
477 		// GdkScreen * gdk_event_get_screen (const GdkEvent *event);
478 		auto p = gdk_event_get_screen(gdkEvent);
479 		
480 		if(p is null)
481 		{
482 			return null;
483 		}
484 		
485 		return ObjectG.getDObject!(Screen)(cast(GdkScreen*) p);
486 	}
487 	
488 	/**
489 	 * Obtains a desktop-wide setting, such as the double-click time,
490 	 * for the default screen. See gdk_screen_get_setting().
491 	 * Params:
492 	 * name = the name of the setting.
493 	 * value = location to store the value of the setting.
494 	 * Returns: TRUE if the setting existed and a value was stored in value, FALSE otherwise.
495 	 */
496 	public static int gdkSettingGet(string name, Value value)
497 	{
498 		// gboolean gdk_setting_get (const gchar *name,  GValue *value);
499 		return gdk_setting_get(Str.toStringz(name), (value is null) ? null : value.getValueStruct());
500 	}
501 }