| The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 1 | /* Copyright (C) 2007-2008 The Android Open Source Project |
| 2 | ** |
| 3 | ** This software is licensed under the terms of the GNU General Public |
| 4 | ** License version 2, as published by the Free Software Foundation, and |
| 5 | ** may be copied, distributed, and modified under those terms. |
| 6 | ** |
| 7 | ** This program is distributed in the hope that it will be useful, |
| 8 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | ** GNU General Public License for more details. |
| 11 | */ |
| 12 | #ifndef _android_charmap_h |
| 13 | #define _android_charmap_h |
| 14 | |
| David 'Digit' Turner | 87250c2 | 2009-09-17 16:45:03 -0700 | [diff] [blame] | 15 | #include "android/keycode.h" |
| Vladimir Chtchetkine | 71bb14f | 2010-07-07 15:57:00 -0700 | [diff] [blame^] | 16 | #include "android/keycode-array.h" |
| The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 17 | |
| 18 | /* this defines a structure used to describe an Android keyboard charmap */ |
| 19 | typedef struct AKeyEntry { |
| 20 | unsigned short code; |
| 21 | unsigned short base; |
| 22 | unsigned short caps; |
| 23 | unsigned short fn; |
| 24 | unsigned short caps_fn; |
| 25 | unsigned short number; |
| 26 | } AKeyEntry; |
| 27 | |
| vchtchetkine | 9085a28 | 2009-09-14 15:29:20 -0700 | [diff] [blame] | 28 | /* Defines size of name buffer in AKeyCharmap entry. */ |
| 29 | #define AKEYCHARMAP_NAME_SIZE 32 |
| 30 | |
| 31 | typedef struct AKeyCharmap { |
| The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 32 | const AKeyEntry* entries; |
| 33 | int num_entries; |
| vchtchetkine | 9085a28 | 2009-09-14 15:29:20 -0700 | [diff] [blame] | 34 | char name[ AKEYCHARMAP_NAME_SIZE ]; |
| The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 35 | } AKeyCharmap; |
| 36 | |
| vchtchetkine | 9085a28 | 2009-09-14 15:29:20 -0700 | [diff] [blame] | 37 | /* Extracts charmap name from .kcm file name. |
| 38 | * Charmap name, extracted by this routine is a name of the kcm file, trimmed |
| 39 | * of file name extension, and shrinked (if necessary) to fit into the name |
| 40 | * buffer. Here are examples on how this routine extracts charmap name: |
| 41 | * /a/path/to/kcmfile.kcm -> kcmfile |
| 42 | * /a/path/to/kcmfile.ext.kcm -> kcmfile.ext |
| 43 | * /a/path/to/kcmfile -> kcmfile |
| 44 | * /a/path/to/.kcmfile -> kcmfile |
| 45 | * /a/path/to/.kcmfile.kcm -> .kcmfile |
| 46 | * kcm_file_path - Path to key charmap file to extract charmap name from. |
| 47 | * charmap_name - Buffer, where to save extracted charname. |
| 48 | * max_len - charmap_name buffer size. |
| 49 | */ |
| 50 | void kcm_extract_charmap_name(const char* kcm_file_path, |
| 51 | char* charmap_name, |
| 52 | int max_len); |
| 53 | |
| 54 | /* Initialzes key charmap array. |
| 55 | * Key charmap array always contains two maps: one for qwerty, and |
| 56 | * another for qwerty2 keyboard layout. However, a custom layout can |
| 57 | * be requested with -charmap option. In tha case kcm_file_path |
| 58 | * parameter contains path to a .kcm file that defines that custom |
| 59 | * layout, and as the result, key charmap array will contain another |
| 60 | * entry built from that file. If -charmap option was not specified, |
| 61 | * kcm_file_path is NULL and final key charmap array will contain only |
| 62 | * two default entries. |
| 63 | * Returns a zero value on success, or -1 on failure. |
| 64 | */ |
| 65 | int android_charmap_setup(const char* kcm_file_path); |
| 66 | |
| 67 | /* Cleanups initialization performed in android_charmap_setup routine. */ |
| 68 | void android_charmap_done(void); |
| The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 69 | |
| Vladimir Chtchetkine | 71bb14f | 2010-07-07 15:57:00 -0700 | [diff] [blame^] | 70 | /* Gets charmap descriptor by its name. |
| 71 | * This routine finds and returns pointer to a descriptor in the array of |
| 72 | * charmaps that matches given name. If no such descriptor has been found, this |
| 73 | * routine returns NULL. |
| 74 | */ |
| 75 | const AKeyCharmap* android_get_charmap_by_name(const char* name); |
| 76 | |
| 77 | /* Gets charmap descriptor by its index in the array of charmaps. |
| 78 | * If index is greater than charmap array size, this routine returns NULL. |
| 79 | */ |
| 80 | const AKeyCharmap* android_get_charmap_by_index(unsigned int index); |
| 81 | |
| 82 | /* Maps given unicode key character into a keycode and adds mapped keycode into |
| 83 | * keycode array. This routine uses charmap passed as cmap parameter to do the |
| 84 | * translation, and 'down' parameter to generate appropriate ('down' or 'up') |
| 85 | * keycode. |
| 86 | */ |
| 87 | int |
| 88 | android_charmap_reverse_map_unicode(const AKeyCharmap* cmap, |
| 89 | unsigned int unicode, |
| 90 | int down, |
| 91 | AKeycodeBuffer* keycodes); |
| 92 | |
| The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 93 | #endif /* _android_charmap_h */ |