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-Keyboard-Handling.html
48 * - GdkDisplay* -> Display
49 * - GdkKeymap* -> Keymap
60 import tango
.io
.Stdout
; // use the tango loging?
64 private import gtkc
.gdktypes
;
66 private import gtkc
.gdk
;
69 private import glib
.Str
;
70 private import gdk
.Keymap
;
71 private import gdk
.Display
;
78 * Key values are the codes which are sent whenever a key is pressed or released.
79 * They appear in the keyval field of the
80 * GdkEventKey structure, which is passed to signal handlers for the
81 * "key-press-event" and "key-release-event" signals.
82 * The complete list of key values can be found in the <gdk/gdkkeysyms.h>
83 * header file. <gdk/gdkkeysyms.h> is not included in <gtk/gtk.h>,
84 * it must be included independently, because the file is quite large.
85 * Key values can be converted into a string representation using
86 * gdk_keyval_name(). The reverse function, converting a string to a key value,
87 * is provided by gdk_keyval_from_name().
88 * The case of key values can be determined using gdk_keyval_is_upper() and
89 * gdk_keyval_is_lower(). Key values can be converted to upper or lower case
90 * using gdk_keyval_to_upper() and gdk_keyval_to_lower().
91 * When it makes sense, key values can be converted to and from
92 * Unicode characters with gdk_keyval_to_unicode() and gdk_unicode_to_keyval().
93 * One GdkKeymap object exists for each user display. gdk_keymap_get_default()
94 * returns the GdkKeymap for the default display; to obtain keymaps for other
95 * displays, use gdk_keymap_get_for_display(). A keymap
96 * is a mapping from GdkKeymapKey to key values. You can think of a GdkKeymapKey
97 * as a representation of a symbol printed on a physical keyboard key. That is, it
98 * contains three pieces of information. First, it contains the hardware keycode;
99 * this is an identifying number for a physical key. Second, it contains the
100 * level of the key. The level indicates which symbol on the
101 * key will be used, in a vertical direction. So on a standard US keyboard, the key
102 * with the number "1" on it also has the exclamation point ("!") character on
103 * it. The level indicates whether to use the "1" or the "!" symbol. The letter
104 * keys are considered to have a lowercase letter at level 0, and an uppercase
105 * letter at level 1, though only the uppercase letter is printed. Third, the
106 * GdkKeymapKey contains a group; groups are not used on standard US keyboards,
107 * but are used in many other countries. On a keyboard with groups, there can be 3
108 * or 4 symbols printed on a single key. The group indicates movement in a
109 * horizontal direction. Usually groups are used for two different languages. In
110 * group 0, a key might have two English characters, and in group 1 it might have
111 * two Hebrew characters. The Hebrew characters will be printed on the key next to
112 * the English characters.
113 * In order to use a keymap to interpret a key event, it's necessary to first
114 * convert the keyboard state into an effective group and level. This is done via a
115 * set of rules that varies widely according to type of keyboard and user
116 * configuration. The function gdk_keymap_translate_keyboard_state() accepts a
117 * keyboard state -- consisting of hardware keycode pressed, active modifiers, and
118 * active group -- applies the appropriate rules, and returns the group/level to be
119 * used to index the keymap, along with the modifiers which did not affect the
120 * group and level. i.e. it returns "unconsumed modifiers." The keyboard group may
121 * differ from the effective group used for keymap lookups because some keys don't
122 * have multiple groups - e.g. the Enter key is always in group 0 regardless of
124 * Note that gdk_keymap_translate_keyboard_state() also returns the keyval, i.e. it
125 * goes ahead and performs the keymap lookup in addition to telling you which
126 * effective group/level values were used for the lookup. GdkEventKey already
127 * contains this keyval, however, so you don't normally need to call
128 * gdk_keymap_translate_keyboard_state() just to get the keyval.
130 private import gobject
.ObjectG
;
131 public class Keymap
: ObjectG
134 /** the main Gtk struct */
135 protected GdkKeymap
* gdkKeymap
;
138 public GdkKeymap
* getKeymapStruct()
144 /** the main Gtk struct as a void* */
145 protected void* getStruct()
147 return cast(void*)gdkKeymap
;
151 * Sets our main struct and passes it to the parent class
153 public this (GdkKeymap
* gdkKeymap
)
157 if ( gdkKeymap
is null )
162 Stdout("struct gdkKeymap is null on constructor").newline
;
166 printf("struct gdkKeymap is null on constructor");
173 assert(gdkKeymap
!is null, "struct gdkKeymap is null on constructor");
175 super(cast(GObject
*)gdkKeymap
);
176 this.gdkKeymap
= gdkKeymap
;
182 // imports for the signal processing
183 private import gobject
.Signals
;
184 private import gtkc
.gdktypes
;
185 int[char[]] connectedSignals
;
187 void delegate(Keymap
)[] onDirectionChangedListeners
;
188 void addOnDirectionChanged(void delegate(Keymap
) dlg
, ConnectFlags connectFlags
=cast(ConnectFlags
)0)
190 if ( !("direction-changed" in connectedSignals
) )
195 cast(GCallback
)&callBackDirectionChanged
,
199 connectedSignals
["direction-changed"] = 1;
201 onDirectionChangedListeners
~= dlg
;
203 extern(C
) static void callBackDirectionChanged(GdkKeymap
* keymapStruct
, Keymap keymap
)
205 bool consumed
= false;
207 foreach ( void delegate(Keymap
) dlg
; keymap
.onDirectionChangedListeners
)
215 void delegate(Keymap
)[] onKeysChangedListeners
;
216 void addOnKeysChanged(void delegate(Keymap
) dlg
, ConnectFlags connectFlags
=cast(ConnectFlags
)0)
218 if ( !("keys-changed" in connectedSignals
) )
223 cast(GCallback
)&callBackKeysChanged
,
227 connectedSignals
["keys-changed"] = 1;
229 onKeysChangedListeners
~= dlg
;
231 extern(C
) static void callBackKeysChanged(GdkKeymap
* keymapStruct
, Keymap keymap
)
233 bool consumed
= false;
235 foreach ( void delegate(Keymap
) dlg
; keymap
.onKeysChangedListeners
)
247 * Returns the GdkKeymap attached to the default display.
249 * the GdkKeymap attached to the default display.
251 public static Keymap
getDefault()
253 // GdkKeymap* gdk_keymap_get_default (void);
254 return new Keymap( gdk_keymap_get_default() );
258 * Returns the GdkKeymap attached to display.
262 * the GdkKeymap attached to display.
265 public static Keymap
getForDisplay(Display display
)
267 // GdkKeymap* gdk_keymap_get_for_display (GdkDisplay *display);
268 return new Keymap( gdk_keymap_get_for_display((display
is null) ?
null : display
.getDisplayStruct()) );
272 * Looks up the keyval mapped to a keycode/group/level triplet.
273 * If no keyval is bound to key, returns 0. For normal user input,
274 * you want to use gdk_keymap_translate_keyboard_state() instead of
275 * this function, since the effective group/level may not be
276 * the same as the current keyboard state.
278 * a GdkKeymap or NULL to use the default keymap
280 * a GdkKeymapKey with keycode, group, and level initialized
282 * a keyval, or 0 if none was mapped to the given key
284 public uint lookupKey(GdkKeymapKey
* key
)
286 // guint gdk_keymap_lookup_key (GdkKeymap *keymap, const GdkKeymapKey *key);
287 return gdk_keymap_lookup_key(gdkKeymap
, key
);
291 * Translates the contents of a GdkEventKey into a keyval, effective
292 * group, and level. Modifiers that affected the translation and
293 * are thus unavailable for application use are returned in
294 * consumed_modifiers. See gdk_keyval_get_keys() for an explanation of
295 * groups and levels. The effective_group is the group that was
296 * actually used for the translation; some keys such as Enter are not
297 * affected by the active keyboard group. The level is derived from
298 * state. For convenience, GdkEventKey already contains the translated
299 * keyval, so this function isn't as useful as you might think.
301 * consumed_modifiers gives modifiers that should be masked out
302 * from state when comparing this key press to a hot key. For
303 * instance, on a US keyboard, the plus
304 * symbol is shifted, so when comparing a key press to a
305 * <Control>plus accelerator <Shift> should
307 * /+* We want to ignore irrelevant modifiers like ScrollLock +/
308 * #define ALL_ACCELS_MASK (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK)
309 * gdk_keymap_translate_keyboard_state (keymap, event->hardware_keycode,
310 * event->state, event->group,
311 * keyval, NULL, NULL, consumed);
312 * if (keyval == GDK_PLUS
313 * (event->state ~consumed ALL_ACCELS_MASK) == GDK_CONTROL_MASK)
314 * /+* Control was pressed +/
315 * An older interpretation consumed_modifiers was that it contained
316 * all modifiers that might affect the translation of the key;
317 * this allowed accelerators to be stored with irrelevant consumed
318 * modifiers, by doing:
319 * /+* XXX Don't do this XXX +/
320 * if (keyval == accel_keyval
321 * (event->state ~consumed ALL_ACCELS_MASK) == (accel_mods ~consumed))
322 * /+* Accelerator was pressed +/
323 * However, this did not work if multi-modifier combinations were
324 * used in the keymap, since, for instance, <Control>
325 * would be masked out even if only <Control><Alt>
326 * was used in the keymap. To support this usage as well as well as
327 * possible, all single modifier combinations
328 * that could affect the key for any combination of modifiers will
329 * be returned in consumed_modifiers; multi-modifier combinations
330 * are returned only when actually found in state. When you store
331 * accelerators, you should always store them with consumed modifiers
332 * removed. Store <Control>plus,
333 * not <Control><Shift>plus,
335 * a GdkKeymap, or NULL to use the default
341 * active keyboard group
343 * return location for keyval, or NULL
345 * return location for effective group, or NULL
347 * return location for level, or NULL
348 * consumed_modifiers:
349 * return location for modifiers that were used to
350 * determine the group or level, or NULL
352 * TRUE if there was a keyval bound to the keycode/state/group
354 public int translateKeyboardState(uint hardwareKeycode
, GdkModifierType state
, int group
, uint* keyval
, int* effectiveGroup
, int* level
, GdkModifierType
* consumedModifiers
)
356 // gboolean gdk_keymap_translate_keyboard_state (GdkKeymap *keymap, guint hardware_keycode, GdkModifierType state, gint group, guint *keyval, gint *effective_group, gint *level, GdkModifierType *consumed_modifiers);
357 return gdk_keymap_translate_keyboard_state(gdkKeymap
, hardwareKeycode
, state
, group
, keyval
, effectiveGroup
, level
, consumedModifiers
);
361 * Obtains a list of keycode/group/level combinations that will
362 * generate keyval. Groups and levels are two kinds of keyboard mode;
363 * in general, the level determines whether the top or bottom symbol
364 * on a key is used, and the group determines whether the left or
365 * right symbol is used. On US keyboards, the shift key changes the
366 * keyboard level, and there are no groups. A group switch key might
367 * convert a keyboard between Hebrew to English modes, for example.
368 * GdkEventKey contains a group field that indicates the active
369 * keyboard group. The level is computed from the modifier mask.
370 * The returned array should be freed
373 * a GdkKeymap, or NULL to use the default keymap
375 * a keyval, such as GDK_a, GDK_Up, GDK_Return, etc.
377 * return location for an array of GdkKeymapKey
379 * return location for number of elements in returned array
381 * TRUE if keys were found and returned
383 public int getEntriesForKeyval(uint keyval
, GdkKeymapKey
** keys
, int* nKeys
)
385 // gboolean gdk_keymap_get_entries_for_keyval (GdkKeymap *keymap, guint keyval, GdkKeymapKey **keys, gint *n_keys);
386 return gdk_keymap_get_entries_for_keyval(gdkKeymap
, keyval
, keys
, nKeys
);
390 * Returns the keyvals bound to hardware_keycode.
391 * The Nth GdkKeymapKey in keys is bound to the Nth
392 * keyval in keyvals. Free the returned arrays with g_free().
393 * When a keycode is pressed by the user, the keyval from
394 * this list of entries is selected by considering the effective
395 * keyboard group and level. See gdk_keymap_translate_keyboard_state().
397 * a GdkKeymap or NULL to use the default keymap
401 * return location for array of GdkKeymapKey, or NULL
403 * return location for array of keyvals, or NULL
405 * length of keys and keyvals
407 * TRUE if there were any entries
409 public int getEntriesForKeycode(uint hardwareKeycode
, GdkKeymapKey
** keys
, uint** keyvals
, int* nEntries
)
411 // gboolean gdk_keymap_get_entries_for_keycode (GdkKeymap *keymap, guint hardware_keycode, GdkKeymapKey **keys, guint **keyvals, gint *n_entries);
412 return gdk_keymap_get_entries_for_keycode(gdkKeymap
, hardwareKeycode
, keys
, keyvals
, nEntries
);
416 * Returns the direction of the keymap.
418 * a GdkKeymap or NULL to use the default keymap.
419 * Returns: PANGO_DIRECTION_LTR or PANGO_DIRECTION_RTL.
421 * the direction of the keymap.
423 public PangoDirection
getDirection()
425 // PangoDirection gdk_keymap_get_direction (GdkKeymap *keymap);
426 return gdk_keymap_get_direction(gdkKeymap
);
430 * Converts a key value into a symbolic name.
431 * The names are the same as those in the <gdk/gdkkeysyms.h> header file
432 * but without the leading "GDK_".
436 * a string containing the name of the key, or NULL if keyval is not
437 * a valid key. The string should not be modified.
439 public static char[] gdkKeyvalName(uint keyval
)
441 // gchar* gdk_keyval_name (guint keyval);
442 return Str
.toString(gdk_keyval_name(keyval
) );
446 * Converts a key name to a key value.
450 * the corresponding key value, or GDK_VoidSymbol if the key name is
453 public static uint gdkKeyvalFromName(char[] keyvalName
)
455 // guint gdk_keyval_from_name (const gchar *keyval_name);
456 return gdk_keyval_from_name(Str
.toStringz(keyvalName
));
460 * Obtains the upper- and lower-case versions of the keyval symbol.
461 * Examples of keyvals are GDK_a, GDK_Enter, GDK_F1, etc.
465 * return location for lowercase version of symbol
467 * return location for uppercase version of symbol
469 public static void gdkKeyvalConvertCase(uint symbol
, uint* lower
, uint* upper
)
471 // void gdk_keyval_convert_case (guint symbol, guint *lower, guint *upper);
472 gdk_keyval_convert_case(symbol
, lower
, upper
);
476 * Converts a key value to upper case, if applicable.
480 * the upper case form of keyval, or keyval itself if it is already
481 * in upper case or it is not subject to case conversion.
483 public static uint gdkKeyvalToUpper(uint keyval
)
485 // guint gdk_keyval_to_upper (guint keyval);
486 return gdk_keyval_to_upper(keyval
);
490 * Converts a key value to lower case, if applicable.
494 * the lower case form of keyval, or keyval itself if it is already
495 * in lower case or it is not subject to case conversion.
497 public static uint gdkKeyvalToLower(uint keyval
)
499 // guint gdk_keyval_to_lower (guint keyval);
500 return gdk_keyval_to_lower(keyval
);
504 * Returns TRUE if the given key value is in upper case.
508 * TRUE if keyval is in upper case, or if keyval is not subject to
511 public static int gdkKeyvalIsUpper(uint keyval
)
513 // gboolean gdk_keyval_is_upper (guint keyval);
514 return gdk_keyval_is_upper(keyval
);
518 * Returns TRUE if the given key value is in lower case.
522 * TRUE if keyval is in lower case, or if keyval is not subject to
525 public static int gdkKeyvalIsLower(uint keyval
)
527 // gboolean gdk_keyval_is_lower (guint keyval);
528 return gdk_keyval_is_lower(keyval
);
532 * Convert from a GDK key symbol to the corresponding ISO10646 (Unicode)
537 * the corresponding unicode character, or 0 if there
538 * is no corresponding character.
540 public static uint gdkKeyvalToUnicode(uint keyval
)
542 // guint32 gdk_keyval_to_unicode (guint keyval);
543 return gdk_keyval_to_unicode(keyval
);
547 * Convert from a ISO10646 character to a key symbol.
549 * a ISO10646 encoded character
551 * the corresponding GDK key symbol, if one exists.
552 * or, if there is no corresponding symbol,
555 * The "direction-changed" signal
556 * void user_function (GdkKeymap *keymap,
557 * gpointer user_data) : Run Last
558 * The ::direction_changed signal gets emitted when the direction of
559 * the keymap changes.
561 * the object on which the signal is emitted
563 * user data set when the signal handler was connected.
566 public static uint gdkUnicodeToKeyval(uint wc
)
568 // guint gdk_unicode_to_keyval (guint32 wc);
569 return gdk_unicode_to_keyval(wc
);