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-Keyboard-Handling.html 27 * outPack = gdk 28 * outFile = Keymap 29 * strct = GdkKeymap 30 * realStrct= 31 * ctorStrct= 32 * clss = Keymap 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gdk_keymap_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * - glib.Str 47 * - gdk.Display 48 * structWrap: 49 * - GdkDisplay* -> Display 50 * - GdkKeymap* -> Keymap 51 * module aliases: 52 * local aliases: 53 * overrides: 54 */ 55 56 module gdk.Keymap; 57 58 public import gtkc.gdktypes; 59 60 private import gtkc.gdk; 61 private import glib.ConstructionException; 62 private import gobject.ObjectG; 63 64 private import gobject.Signals; 65 public import gtkc.gdktypes; 66 67 private import glib.Str; 68 private import gdk.Display; 69 70 71 72 private import gobject.ObjectG; 73 74 /** 75 * Description 76 * Key values are the codes which are sent whenever a key is pressed or released. 77 * They appear in the keyval field of the 78 * GdkEventKey structure, which is passed to signal handlers for the 79 * "key-press-event" and "key-release-event" signals. 80 * The complete list of key values can be found in the <gdk/gdkkeysyms.h> 81 * header file. <gdk/gdkkeysyms.h> is not included in <gdk/gdk.h>, 82 * it must be included independently, because the file is quite large. 83 * Key values are regularly updated from the upstream X.org X11 implementation, 84 * so new values are added regularly. They will be prefixed with GDK_ rather than 85 * XF86XK_ or XK_ (for older symbols). 86 * Key values can be converted into a string representation using 87 * gdk_keyval_name(). The reverse function, converting a string to a key value, 88 * is provided by gdk_keyval_from_name(). 89 * The case of key values can be determined using gdk_keyval_is_upper() and 90 * gdk_keyval_is_lower(). Key values can be converted to upper or lower case 91 * using gdk_keyval_to_upper() and gdk_keyval_to_lower(). 92 * When it makes sense, key values can be converted to and from 93 * Unicode characters with gdk_keyval_to_unicode() and gdk_unicode_to_keyval(). 94 * One GdkKeymap object exists for each user display. gdk_keymap_get_default() 95 * returns the GdkKeymap for the default display; to obtain keymaps for other 96 * displays, use gdk_keymap_get_for_display(). A keymap 97 * is a mapping from GdkKeymapKey to key values. You can think of a GdkKeymapKey 98 * as a representation of a symbol printed on a physical keyboard key. That is, it 99 * contains three pieces of information. First, it contains the hardware keycode; 100 * this is an identifying number for a physical key. Second, it contains the 101 * level of the key. The level indicates which symbol on the 102 * key will be used, in a vertical direction. So on a standard US keyboard, the key 103 * with the number "1" on it also has the exclamation point ("!") character on 104 * it. The level indicates whether to use the "1" or the "!" symbol. The letter 105 * keys are considered to have a lowercase letter at level 0, and an uppercase 106 * letter at level 1, though only the uppercase letter is printed. Third, the 107 * GdkKeymapKey contains a group; groups are not used on standard US keyboards, 108 * but are used in many other countries. On a keyboard with groups, there can be 3 109 * or 4 symbols printed on a single key. The group indicates movement in a 110 * horizontal direction. Usually groups are used for two different languages. In 111 * group 0, a key might have two English characters, and in group 1 it might have 112 * two Hebrew characters. The Hebrew characters will be printed on the key next to 113 * the English characters. 114 * In order to use a keymap to interpret a key event, it's necessary to first 115 * convert the keyboard state into an effective group and level. This is done via a 116 * set of rules that varies widely according to type of keyboard and user 117 * configuration. The function gdk_keymap_translate_keyboard_state() accepts a 118 * keyboard state -- consisting of hardware keycode pressed, active modifiers, and 119 * active group -- applies the appropriate rules, and returns the group/level to be 120 * used to index the keymap, along with the modifiers which did not affect the 121 * group and level. i.e. it returns "unconsumed modifiers." The keyboard group may 122 * differ from the effective group used for keymap lookups because some keys don't 123 * have multiple groups - e.g. the Enter key is always in group 0 regardless of 124 * keyboard state. 125 * Note that gdk_keymap_translate_keyboard_state() also returns the keyval, i.e. it 126 * goes ahead and performs the keymap lookup in addition to telling you which 127 * effective group/level values were used for the lookup. GdkEventKey already 128 * contains this keyval, however, so you don't normally need to call 129 * gdk_keymap_translate_keyboard_state() just to get the keyval. 130 */ 131 public class Keymap : ObjectG 132 { 133 134 /** the main Gtk struct */ 135 protected GdkKeymap* gdkKeymap; 136 137 138 public GdkKeymap* getKeymapStruct() 139 { 140 return gdkKeymap; 141 } 142 143 144 /** the main Gtk struct as a void* */ 145 protected override void* getStruct() 146 { 147 return cast(void*)gdkKeymap; 148 } 149 150 /** 151 * Sets our main struct and passes it to the parent class 152 */ 153 public this (GdkKeymap* gdkKeymap) 154 { 155 super(cast(GObject*)gdkKeymap); 156 this.gdkKeymap = gdkKeymap; 157 } 158 159 protected override void setStruct(GObject* obj) 160 { 161 super.setStruct(obj); 162 gdkKeymap = cast(GdkKeymap*)obj; 163 } 164 165 /** 166 */ 167 int[string] connectedSignals; 168 169 void delegate(Keymap)[] onDirectionChangedListeners; 170 /** 171 * The ::direction-changed signal gets emitted when the direction of 172 * the keymap changes. 173 * Since 2.0 174 */ 175 void addOnDirectionChanged(void delegate(Keymap) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 176 { 177 if ( !("direction-changed" in connectedSignals) ) 178 { 179 Signals.connectData( 180 getStruct(), 181 "direction-changed", 182 cast(GCallback)&callBackDirectionChanged, 183 cast(void*)this, 184 null, 185 connectFlags); 186 connectedSignals["direction-changed"] = 1; 187 } 188 onDirectionChangedListeners ~= dlg; 189 } 190 extern(C) static void callBackDirectionChanged(GdkKeymap* keymapStruct, Keymap _keymap) 191 { 192 foreach ( void delegate(Keymap) dlg ; _keymap.onDirectionChangedListeners ) 193 { 194 dlg(_keymap); 195 } 196 } 197 198 void delegate(Keymap)[] onKeysChangedListeners; 199 /** 200 * The ::keys-changed signal is emitted when the mapping represented by 201 * keymap changes. 202 * Since 2.2 203 */ 204 void addOnKeysChanged(void delegate(Keymap) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 205 { 206 if ( !("keys-changed" in connectedSignals) ) 207 { 208 Signals.connectData( 209 getStruct(), 210 "keys-changed", 211 cast(GCallback)&callBackKeysChanged, 212 cast(void*)this, 213 null, 214 connectFlags); 215 connectedSignals["keys-changed"] = 1; 216 } 217 onKeysChangedListeners ~= dlg; 218 } 219 extern(C) static void callBackKeysChanged(GdkKeymap* keymapStruct, Keymap _keymap) 220 { 221 foreach ( void delegate(Keymap) dlg ; _keymap.onKeysChangedListeners ) 222 { 223 dlg(_keymap); 224 } 225 } 226 227 void delegate(Keymap)[] onStateChangedListeners; 228 /** 229 * The ::state-changed signal is emitted when the state of the 230 * keyboard changes, e.g when Caps Lock is turned on or off. 231 * See gdk_keymap_get_caps_lock_state(). 232 * Since 2.16 233 */ 234 void addOnStateChanged(void delegate(Keymap) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 235 { 236 if ( !("state-changed" in connectedSignals) ) 237 { 238 Signals.connectData( 239 getStruct(), 240 "state-changed", 241 cast(GCallback)&callBackStateChanged, 242 cast(void*)this, 243 null, 244 connectFlags); 245 connectedSignals["state-changed"] = 1; 246 } 247 onStateChangedListeners ~= dlg; 248 } 249 extern(C) static void callBackStateChanged(GdkKeymap* keymapStruct, Keymap _keymap) 250 { 251 foreach ( void delegate(Keymap) dlg ; _keymap.onStateChangedListeners ) 252 { 253 dlg(_keymap); 254 } 255 } 256 257 258 /** 259 * Returns the GdkKeymap attached to the default display. 260 * Returns: the GdkKeymap attached to the default display. 261 */ 262 public static Keymap getDefault() 263 { 264 // GdkKeymap * gdk_keymap_get_default (void); 265 auto p = gdk_keymap_get_default(); 266 267 if(p is null) 268 { 269 return null; 270 } 271 272 return ObjectG.getDObject!(Keymap)(cast(GdkKeymap*) p); 273 } 274 275 /** 276 * Returns the GdkKeymap attached to display. 277 * Since 2.2 278 * Params: 279 * display = the GdkDisplay. 280 * Returns: the GdkKeymap attached to display. 281 */ 282 public static Keymap getForDisplay(Display display) 283 { 284 // GdkKeymap * gdk_keymap_get_for_display (GdkDisplay *display); 285 auto p = gdk_keymap_get_for_display((display is null) ? null : display.getDisplayStruct()); 286 287 if(p is null) 288 { 289 return null; 290 } 291 292 return ObjectG.getDObject!(Keymap)(cast(GdkKeymap*) p); 293 } 294 295 /** 296 * Looks up the keyval mapped to a keycode/group/level triplet. 297 * If no keyval is bound to key, returns 0. For normal user input, 298 * you want to use gdk_keymap_translate_keyboard_state() instead of 299 * this function, since the effective group/level may not be 300 * the same as the current keyboard state. 301 * Params: 302 * key = a GdkKeymapKey with keycode, group, and level initialized 303 * Returns: a keyval, or 0 if none was mapped to the given key 304 */ 305 public uint lookupKey(out GdkKeymapKey key) 306 { 307 // guint gdk_keymap_lookup_key (GdkKeymap *keymap, const GdkKeymapKey *key); 308 return gdk_keymap_lookup_key(gdkKeymap, &key); 309 } 310 311 /** 312 * Translates the contents of a GdkEventKey into a keyval, effective 313 * group, and level. Modifiers that affected the translation and 314 * are thus unavailable for application use are returned in 315 * consumed_modifiers. See the section called “Description” for an explanation of 316 * groups and levels. The effective_group is the group that was 317 * actually used for the translation; some keys such as Enter are not 318 * affected by the active keyboard group. The level is derived from 319 * state. For convenience, GdkEventKey already contains the translated 320 * keyval, so this function isn't as useful as you might think. 321 * Note 322 * consumed_modifiers gives modifiers that should be masked out 323 * from state when comparing this key press to a hot key. For 324 * instance, on a US keyboard, the plus 325 * symbol is shifted, so when comparing a key press to a 326 * <Control>plus accelerator <Shift> should 327 * be masked out. 328 * $(DDOC_COMMENT example) 329 * An older interpretation consumed_modifiers was that it contained 330 * all modifiers that might affect the translation of the key; 331 * this allowed accelerators to be stored with irrelevant consumed 332 * Params: 333 * hardwareKeycode = a keycode 334 * state = a modifier state 335 * group = active keyboard group 336 * keyval = return location for keyval, or NULL. [out][allow-none] 337 * effectiveGroup = return location for effective group, or NULL. [out][allow-none] 338 * level = return location for level, or NULL. [out][allow-none] 339 * consumedModifiers = return location for modifiers that were used to 340 * determine the group or level, or NULL. [out][allow-none] 341 * Returns: TRUE if there was a keyval bound to the keycode/state/group 342 */ 343 public int translateKeyboardState(uint hardwareKeycode, GdkModifierType state, int group, out uint keyval, out int effectiveGroup, out int level, out GdkModifierType consumedModifiers) 344 { 345 // 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); 346 return gdk_keymap_translate_keyboard_state(gdkKeymap, hardwareKeycode, state, group, &keyval, &effectiveGroup, &level, &consumedModifiers); 347 } 348 349 /** 350 * Obtains a list of keycode/group/level combinations that will 351 * generate keyval. Groups and levels are two kinds of keyboard mode; 352 * in general, the level determines whether the top or bottom symbol 353 * on a key is used, and the group determines whether the left or 354 * right symbol is used. On US keyboards, the shift key changes the 355 * keyboard level, and there are no groups. A group switch key might 356 * convert a keyboard between Hebrew to English modes, for example. 357 * GdkEventKey contains a group field that indicates the active 358 * keyboard group. The level is computed from the modifier mask. 359 * The returned array should be freed 360 * with g_free(). 361 * Params: 362 * keyval = a keyval, such as GDK_a, GDK_Up, GDK_Return, etc. 363 * keys = return location for an array of GdkKeymapKey 364 * Returns: TRUE if keys were found and returned 365 */ 366 public int getEntriesForKeyval(uint keyval, out GdkKeymapKey[] keys) 367 { 368 // gboolean gdk_keymap_get_entries_for_keyval (GdkKeymap *keymap, guint keyval, GdkKeymapKey **keys, gint *n_keys); 369 GdkKeymapKey* outkeys = null; 370 int nKeys; 371 372 auto p = gdk_keymap_get_entries_for_keyval(gdkKeymap, keyval, &outkeys, &nKeys); 373 374 keys = outkeys[0 .. nKeys]; 375 return p; 376 } 377 378 /** 379 * Returns the keyvals bound to hardware_keycode. 380 * The Nth GdkKeymapKey in keys is bound to the Nth 381 * keyval in keyvals. Free the returned arrays with g_free(). 382 * When a keycode is pressed by the user, the keyval from 383 * this list of entries is selected by considering the effective 384 * keyboard group and level. See gdk_keymap_translate_keyboard_state(). 385 * Params: 386 * hardwareKeycode = a keycode 387 * keys = return location for array of GdkKeymapKey, or NULL 388 * keyvals = return location for array of keyvals, or NULL 389 * Returns: TRUE if there were any entries 390 */ 391 public int getEntriesForKeycode(uint hardwareKeycode, out GdkKeymapKey[] keys, out uint[] keyvals) 392 { 393 // gboolean gdk_keymap_get_entries_for_keycode (GdkKeymap *keymap, guint hardware_keycode, GdkKeymapKey **keys, guint **keyvals, gint *n_entries); 394 GdkKeymapKey* outkeys = null; 395 guint* outkeyvals = null; 396 int nEntries; 397 398 auto p = gdk_keymap_get_entries_for_keycode(gdkKeymap, hardwareKeycode, &outkeys, &outkeyvals, &nEntries); 399 400 keys = outkeys[0 .. nEntries]; 401 keyvals = outkeyvals[0 .. nEntries]; 402 return p; 403 } 404 405 /** 406 * Returns the direction of effective layout of the keymap. 407 * Note that passing NULL for keymap is deprecated and will stop 408 * to work in GTK+ 3.0. Use gdk_keymap_get_for_display() instead. 409 * Returns the direction of the keymap. 410 * Returns: PANGO_DIRECTION_LTR or PANGO_DIRECTION_RTL if it can determine the direction. PANGO_DIRECTION_NEUTRAL otherwise. 411 */ 412 public PangoDirection getDirection() 413 { 414 // PangoDirection gdk_keymap_get_direction (GdkKeymap *keymap); 415 return gdk_keymap_get_direction(gdkKeymap); 416 } 417 418 /** 419 * Determines if keyboard layouts for both right-to-left and left-to-right 420 * languages are in use. 421 * Note that passing NULL for keymap is deprecated and will stop 422 * to work in GTK+ 3.0. Use gdk_keymap_get_for_display() instead. 423 * Since 2.12 424 * Returns: TRUE if there are layouts in both directions, FALSE otherwise 425 */ 426 public int haveBidiLayouts() 427 { 428 // gboolean gdk_keymap_have_bidi_layouts (GdkKeymap *keymap); 429 return gdk_keymap_have_bidi_layouts(gdkKeymap); 430 } 431 432 /** 433 * Returns whether the Caps Lock modifer is locked. 434 * Since 2.16 435 * Returns: TRUE if Caps Lock is on 436 */ 437 public int getCapsLockState() 438 { 439 // gboolean gdk_keymap_get_caps_lock_state (GdkKeymap *keymap); 440 return gdk_keymap_get_caps_lock_state(gdkKeymap); 441 } 442 443 /** 444 * Adds virtual modifiers (i.e. Super, Hyper and Meta) which correspond 445 * to the real modifiers (i.e Mod2, Mod3, ...) in modifiers. 446 * are set in state to their non-virtual counterparts (i.e. Mod2, 447 * Mod3,...) and set the corresponding bits in state. 448 * GDK already does this before delivering key events, but for 449 * compatibility reasons, it only sets the first virtual modifier 450 * it finds, whereas this function sets all matching virtual modifiers. 451 * This function is useful when matching key events against 452 * accelerators. 453 * Since 2.20 454 * Params: 455 * state = pointer to the modifier mask to change 456 */ 457 public void addVirtualModifiers(ref GdkModifierType state) 458 { 459 // void gdk_keymap_add_virtual_modifiers (GdkKeymap *keymap, GdkModifierType *state); 460 gdk_keymap_add_virtual_modifiers(gdkKeymap, &state); 461 } 462 463 /** 464 * Maps the virtual modifiers (i.e. Super, Hyper and Meta) which 465 * are set in state to their non-virtual counterparts (i.e. Mod2, 466 * Mod3,...) and set the corresponding bits in state. 467 * This function is useful when matching key events against 468 * accelerators. 469 * Since 2.20 470 * Params: 471 * state = pointer to the modifier state to map 472 * Returns: TRUE if no virtual modifiers were mapped to the same non-virtual modifier. Note that FALSE is also returned if a virtual modifier is mapped to a non-virtual modifier that was already set in state. 473 */ 474 public int mapVirtualModifiers(ref GdkModifierType state) 475 { 476 // gboolean gdk_keymap_map_virtual_modifiers (GdkKeymap *keymap, GdkModifierType *state); 477 return gdk_keymap_map_virtual_modifiers(gdkKeymap, &state); 478 } 479 480 /** 481 * Converts a key value into a symbolic name. 482 * The names are the same as those in the 483 * <gdk/gdkkeysyms.h> header file 484 * but without the leading "GDK_KEY_". 485 * Converts a key value into a symbolic name. 486 * The names are the same as those in the <gdk/gdkkeysyms.h> header file 487 * but without the leading "GDK_". 488 * Params: 489 * keyval = a key value 490 * Returns: a string containing the name of the key, or NULL if keyval is not a valid key. The string should not be modified. [transfer none] 491 */ 492 public static string gdkKeyvalName(uint keyval) 493 { 494 // gchar * gdk_keyval_name (guint keyval); 495 return Str.toString(gdk_keyval_name(keyval)); 496 } 497 498 /** 499 * Converts a key name to a key value. 500 * The names are the same as those in the 501 * <gdk/gdkkeysyms.h> header file 502 * but without the leading "GDK_KEY_". 503 * Converts a key name to a key value. 504 * Params: 505 * keyvalName = a key name 506 * Returns: the corresponding key value, or GDK_KEY_VoidSymbol if the key name is not a valid key 507 */ 508 public static uint gdkKeyvalFromName(string keyvalName) 509 { 510 // guint gdk_keyval_from_name (const gchar *keyval_name); 511 return gdk_keyval_from_name(Str.toStringz(keyvalName)); 512 } 513 514 /** 515 * Obtains the upper- and lower-case versions of the keyval symbol. 516 * Examples of keyvals are GDK_a, GDK_Enter, GDK_F1, etc. 517 * Params: 518 * symbol = a keyval 519 * lower = return location for lowercase version of symbol. [out] 520 * upper = return location for uppercase version of symbol. [out] 521 */ 522 public static void gdkKeyvalConvertCase(uint symbol, out uint lower, out uint upper) 523 { 524 // void gdk_keyval_convert_case (guint symbol, guint *lower, guint *upper); 525 gdk_keyval_convert_case(symbol, &lower, &upper); 526 } 527 528 /** 529 * Converts a key value to upper case, if applicable. 530 * Params: 531 * keyval = a key value. 532 * Returns: the upper case form of keyval, or keyval itself if it is already in upper case or it is not subject to case conversion. 533 */ 534 public static uint gdkKeyvalToUpper(uint keyval) 535 { 536 // guint gdk_keyval_to_upper (guint keyval); 537 return gdk_keyval_to_upper(keyval); 538 } 539 540 /** 541 * Converts a key value to lower case, if applicable. 542 * Params: 543 * keyval = a key value. 544 * Returns: the lower case form of keyval, or keyval itself if it is already in lower case or it is not subject to case conversion. 545 */ 546 public static uint gdkKeyvalToLower(uint keyval) 547 { 548 // guint gdk_keyval_to_lower (guint keyval); 549 return gdk_keyval_to_lower(keyval); 550 } 551 552 /** 553 * Returns TRUE if the given key value is in upper case. 554 * Params: 555 * keyval = a key value. 556 * Returns: TRUE if keyval is in upper case, or if keyval is not subject to case conversion. 557 */ 558 public static int gdkKeyvalIsUpper(uint keyval) 559 { 560 // gboolean gdk_keyval_is_upper (guint keyval); 561 return gdk_keyval_is_upper(keyval); 562 } 563 564 /** 565 * Returns TRUE if the given key value is in lower case. 566 * Params: 567 * keyval = a key value. 568 * Returns: TRUE if keyval is in lower case, or if keyval is not subject to case conversion. 569 */ 570 public static int gdkKeyvalIsLower(uint keyval) 571 { 572 // gboolean gdk_keyval_is_lower (guint keyval); 573 return gdk_keyval_is_lower(keyval); 574 } 575 576 /** 577 * Convert from a GDK key symbol to the corresponding ISO10646 (Unicode) 578 * character. 579 * Params: 580 * keyval = a GDK key symbol 581 * Returns: the corresponding unicode character, or 0 if there is no corresponding character. 582 */ 583 public static uint gdkKeyvalToUnicode(uint keyval) 584 { 585 // guint32 gdk_keyval_to_unicode (guint keyval); 586 return gdk_keyval_to_unicode(keyval); 587 } 588 589 /** 590 * Convert from a ISO10646 character to a key symbol. 591 * Since 2.0 592 * Params: 593 * wc = a ISO10646 encoded character 594 * Returns: the corresponding GDK key symbol, if one exists. or, if there is no corresponding symbol, wc | 0x01000000 Signal Details The "direction-changed" signal void user_function (GdkKeymap *keymap, gpointer user_data) : Run Last The ::direction-changed signal gets emitted when the direction of the keymap changes. 595 */ 596 public static uint gdkUnicodeToKeyval(uint wc) 597 { 598 // guint gdk_unicode_to_keyval (guint32 wc); 599 return gdk_unicode_to_keyval(wc); 600 } 601 }