Home | History | Annotate | Download | only in android
      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 
     15 #include "android/keycode.h"
     16 #include "android/keycode-array.h"
     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 
     28 /* Defines size of name buffer in AKeyCharmap entry. */
     29 #define AKEYCHARMAP_NAME_SIZE   32
     30 
     31 typedef struct AKeyCharmap {
     32     const AKeyEntry*  entries;
     33     int               num_entries;
     34     char              name[ AKEYCHARMAP_NAME_SIZE ];
     35 } AKeyCharmap;
     36 
     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);
     69 
     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 
     93 #endif /* _android_charmap_h */
     94