alternative to assert
[gtkD.git] / gtkD / src / gdk / Device.d
blob9c51833c1812344ee22304703da7d71b7f56ff24
1 /*
2 * This file is part of gtkD.
4 * gtkD 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 * gtkD 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 gtkD; 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-Input-Devices.html
26 * outPack = gdk
27 * outFile = Device
28 * strct = GdkDevice
29 * realStrct=
30 * ctorStrct=
31 * clss = Device
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gdk_device_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.ListG
45 * - gdk.Device
46 * - gdk.Window
47 * structWrap:
48 * - GList* -> ListG
49 * - GdkDevice* -> Device
50 * - GdkWindow* -> Window
51 * module aliases:
52 * local aliases:
55 module gdk.Device;
57 version(noAssert)
59 version(Tango)
61 import tango.io.Stdout; // use the tango loging?
65 private import gtkc.gdktypes;
67 private import gtkc.gdk;
70 private import glib.ListG;
71 private import gdk.Device;
72 private import gdk.Window;
77 /**
78 * Description
79 * In addition to the normal keyboard and mouse input devices, GTK+ also
80 * contains support for extended input devices. In
81 * particular, this support is targeted at graphics tablets. Graphics
82 * tablets typically return sub-pixel positioning information and possibly
83 * information about the pressure and tilt of the stylus. Under
84 * X, the support for extended devices is done through the
85 * XInput extension.
86 * Because handling extended input devices may involve considerable
87 * overhead, they need to be turned on for each GdkWindow
88 * individually using gdk_input_set_extension_events().
89 * (Or, more typically, for GtkWidgets, using gtk_widget_set_extension_events()).
90 * As an additional complication, depending on the support from
91 * the windowing system, its possible that a normal mouse
92 * cursor will not be displayed for a particular extension
93 * device. If an application does not want to deal with displaying
94 * a cursor itself, it can ask only to get extension events
95 * from devices that will display a cursor, by passing the
96 * GDK_EXTENSION_EVENTS_CURSOR value to
97 * gdk_input_set_extension_events(). Otherwise, the application
98 * must retrieve the device information using gdk_devices_list(),
99 * check the has_cursor field, and,
100 * if it is FALSE, draw a cursor itself when it receives
101 * motion events.
102 * Each pointing device is assigned a unique integer ID; events from a
103 * particular device can be identified by the
104 * deviceid field in the event structure. The
105 * events generated by pointer devices have also been extended to contain
106 * pressure, xtilt
107 * and ytilt fields which contain the extended
108 * information reported as additional valuators
109 * from the device. The pressure field is a
110 * a double value ranging from 0.0 to 1.0, while the tilt fields are
111 * double values ranging from -1.0 to 1.0. (With -1.0 representing the
112 * maximum tilt to the left or up, and 1.0 representing the maximum
113 * tilt to the right or down.)
114 * One additional field in each event is the
115 * source field, which contains an
116 * enumeration value describing the type of device; this currently
117 * can be one of GDK_SOURCE_MOUSE, GDK_SOURCE_PEN, GDK_SOURCE_ERASER,
118 * or GDK_SOURCE_CURSOR. This field is present to allow simple
119 * applications to (for instance) delete when they detect eraser
120 * devices without having to keep track of complicated per-device
121 * settings.
122 * Various aspects of each device may be configured. The easiest way of
123 * creating a GUI to allow the user to configure such a device
124 * is to use the GtkInputDialog widget in GTK+.
125 * However, even when using this widget, application writers
126 * will need to directly query and set the configuration parameters
127 * in order to save the state between invocations of the application.
128 * The configuration of devices is queried using gdk_devices_list().
129 * Each device must be activated using gdk_device_set_mode(), which
130 * also controls whether the device's range is mapped to the
131 * entire screen or to a single window. The mapping of the valuators of
132 * the device onto the predefined valuator types is set using
133 * gdk_device_set_axis_use(). And the source type for each device
134 * can be set with gdk_device_set_source().
135 * Devices may also have associated keys
136 * or macro buttons. Such keys can be globally set to map
137 * into normal X keyboard events. The mapping is set using
138 * gdk_device_set_key().
139 * The interfaces in this section will most likely be considerably
140 * modified in the future to accomodate devices that may have different
141 * sets of additional valuators than the pressure xtilt
142 * and ytilt.
144 public class Device
147 /** the main Gtk struct */
148 protected GdkDevice* gdkDevice;
151 public GdkDevice* getDeviceStruct()
153 return gdkDevice;
157 /** the main Gtk struct as a void* */
158 protected void* getStruct()
160 return cast(void*)gdkDevice;
164 * Sets our main struct and passes it to the parent class
166 public this (GdkDevice* gdkDevice)
168 version(noAssert)
170 if ( gdkDevice is null )
172 int zero = 0;
173 version(Tango)
175 Stdout("struct gdkDevice is null on constructor").newline;
177 else
179 printf("struct gdkDevice is null on constructor");
181 zero = zero / zero;
184 else
186 assert(gdkDevice !is null, "struct gdkDevice is null on constructor");
188 this.gdkDevice = gdkDevice;
201 * Returns the list of available input devices for the default display.
202 * The list is statically allocated and should not be freed.
203 * Returns:
204 * a list of GdkDevice
206 public static ListG gdkDevicesList()
208 // GList* gdk_devices_list (void);
209 return new ListG( gdk_devices_list() );
213 * Sets the source type for an input device.
214 * device:
215 * a GdkDevice.
216 * source:
217 * the source type.
219 public void setSource(GdkInputSource source)
221 // void gdk_device_set_source (GdkDevice *device, GdkInputSource source);
222 gdk_device_set_source(gdkDevice, source);
226 * Sets a the mode of an input device. The mode controls if the
227 * device is active and whether the device's range is mapped to the
228 * entire screen or to a single window.
229 * device:
230 * a GdkDevice.
231 * mode:
232 * the input mode.
233 * Returns:
234 * TRUE if the mode was successfully changed.
236 public int setMode(GdkInputMode mode)
238 // gboolean gdk_device_set_mode (GdkDevice *device, GdkInputMode mode);
239 return gdk_device_set_mode(gdkDevice, mode);
243 * Specifies the X key event to generate when a macro button of a device
244 * is pressed.
245 * device:
246 * a GdkDevice.
247 * index_:
248 * the index of the macro button to set.
249 * keyval:
250 * the keyval to generate.
251 * modifiers:
252 * the modifiers to set.
254 public void setKey(uint index, uint keyval, GdkModifierType modifiers)
256 // void gdk_device_set_key (GdkDevice *device, guint index_, guint keyval, GdkModifierType modifiers);
257 gdk_device_set_key(gdkDevice, index, keyval, modifiers);
261 * Specifies how an axis of a device is used.
262 * device:
263 * a GdkDevice.
264 * index_:
265 * the index of the axis.
266 * use:
267 * specifies how the axis is used.
269 public void setAxisUse(uint index, GdkAxisUse use)
271 // void gdk_device_set_axis_use (GdkDevice *device, guint index_, GdkAxisUse use);
272 gdk_device_set_axis_use(gdkDevice, index, use);
276 * Returns the core pointer device for the default display.
277 * Returns:
278 * the core pointer device; this is owned by the
279 * display and should not be freed.
281 public static Device getCorePointer()
283 // GdkDevice* gdk_device_get_core_pointer (void);
284 return new Device( gdk_device_get_core_pointer() );
288 * Gets the current state of a device.
289 * device:
290 * a GdkDevice.
291 * window:
292 * a GdkWindow.
293 * axes:
294 * an array of doubles to store the values of the axes of device in,
295 * or NULL.
296 * mask:
297 * location to store the modifiers, or NULL.
299 public void getState(Window window, double* axes, GdkModifierType* mask)
301 // void gdk_device_get_state (GdkDevice *device, GdkWindow *window, gdouble *axes, GdkModifierType *mask);
302 gdk_device_get_state(gdkDevice, (window is null) ? null : window.getWindowStruct(), axes, mask);
306 * Obtains the motion history for a device; given a starting and
307 * ending timestamp, return all events in the motion history for
308 * the device in the given range of time. Some windowing systems
309 * do not support motion history, in which case, FALSE will
310 * be returned. (This is not distinguishable from the case where
311 * motion history is supported and no events were found.)
312 * device:
313 * a GdkDevice
314 * window:
315 * the window with respect to which which the event coordinates will be reported
316 * start:
317 * starting timestamp for range of events to return
318 * stop:
319 * ending timestamp for the range of events to return
320 * events:
321 * location to store a newly-allocated array of GdkTimeCoord, or NULL
322 * n_events:
323 * location to store the length of events, or NULL
324 * Returns:
325 * TRUE if the windowing system supports motion history and
326 * at least one event was found.
328 public int getHistory(Window window, uint start, uint stop, GdkTimeCoord*** events, int* nEvents)
330 // gboolean gdk_device_get_history (GdkDevice *device, GdkWindow *window, guint32 start, guint32 stop, GdkTimeCoord ***events, gint *n_events);
331 return gdk_device_get_history(gdkDevice, (window is null) ? null : window.getWindowStruct(), start, stop, events, nEvents);
335 * Frees an array of GdkTimeCoord that was returned by gdk_device_get_history().
336 * events:
337 * an array of GdkTimeCoord.
338 * n_events:
339 * the length of the array.
341 public static void freeHistory(GdkTimeCoord** events, int nEvents)
343 // void gdk_device_free_history (GdkTimeCoord **events, gint n_events);
344 gdk_device_free_history(events, nEvents);
349 * Interprets an array of double as axis values for a given device,
350 * and locates the value in the array for a given axis use.
351 * device:
352 * a GdkDevice
353 * axes:
354 * pointer to an array of axes
355 * use:
356 * the use to look for
357 * value:
358 * location to store the found value.
359 * Returns:
360 * TRUE if the given axis use was found, otherwise FALSE
362 public int getAxis(double* axes, GdkAxisUse use, double* value)
364 // gboolean gdk_device_get_axis (GdkDevice *device, gdouble *axes, GdkAxisUse use, gdouble *value);
365 return gdk_device_get_axis(gdkDevice, axes, use, value);
369 * Turns extension events on or off for a particular window,
370 * and specifies the event mask for extension events.
371 * window:
372 * a GdkWindow.
373 * mask:
374 * the event mask
375 * mode:
376 * the type of extension events that are desired.
378 public static void gdkInputSetExtensionEvents(Window window, int mask, GdkExtensionMode mode)
380 // void gdk_input_set_extension_events (GdkWindow *window, gint mask, GdkExtensionMode mode);
381 gdk_input_set_extension_events((window is null) ? null : window.getWindowStruct(), mask, mode);