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 /* Gets a pointer to the default hard-coded charmap */
     55 const AKeyCharmap* android_get_default_charmap(void);
     56 
     57 /* Parse a charmap file and add it to our list.
     58  * Key charmap array always contains two maps: one for qwerty, and
     59  * another for qwerty2 keyboard layout. However, a custom layout can
     60  * be requested with -charmap option. In tha case kcm_file_path
     61  * parameter contains path to a .kcm file that defines that custom
     62  * layout, and as the result, key charmap array will contain another
     63  * entry built from that file. If -charmap option was not specified,
     64  * kcm_file_path is NULL and final key charmap array will contain only
     65  * two default entries.
     66  * Returns a zero value on success, or -1 on failure.
     67  *
     68  * Note: on success, the charmap will be returned by android_get_charmap()
     69  */
     70 int android_charmap_setup(const char* kcm_file_path);
     71 
     72 /* Cleanups initialization performed in android_charmap_setup routine. */
     73 void android_charmap_done(void);
     74 
     75 /* Gets charmap descriptor by its name.
     76  * This routine tries to find a charmap by name. This will compare the
     77  * name to the default charmap's name, or any charmap loaded with
     78  * android_charmap_setup(). Returns NULL on failure.
     79  */
     80 const AKeyCharmap* android_get_charmap_by_name(const char* name);
     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 /* Return a pointer to the active charmap. If android_charmap_setup() was
     94  * called succesfully, this corresponds to the newly loaded charmap.
     95  *
     96  * Otherwise, return a pointer to the default charmap.
     97  */
     98 const AKeyCharmap* android_get_charmap(void);
     99 
    100 /* Return the name of the charmap to be used. Same as
    101  * android_get_charmap()->name */
    102 const char* android_get_charmap_name(void);
    103 
    104 #endif /* _android_charmap_h */
    105