blob: 6bf35c01a0b48dc574067f8e039f0670fc4f16c2 [file] [log] [blame]
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001/* 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' Turner87250c22009-09-17 16:45:03 -070015#include "android/keycode.h"
Vladimir Chtchetkine71bb14f2010-07-07 15:57:00 -070016#include "android/keycode-array.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080017
18/* this defines a structure used to describe an Android keyboard charmap */
19typedef 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
vchtchetkine9085a282009-09-14 15:29:20 -070028/* Defines size of name buffer in AKeyCharmap entry. */
29#define AKEYCHARMAP_NAME_SIZE 32
30
31typedef struct AKeyCharmap {
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080032 const AKeyEntry* entries;
33 int num_entries;
vchtchetkine9085a282009-09-14 15:29:20 -070034 char name[ AKEYCHARMAP_NAME_SIZE ];
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080035} AKeyCharmap;
36
vchtchetkine9085a282009-09-14 15:29:20 -070037/* 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*/
50void 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*/
65int android_charmap_setup(const char* kcm_file_path);
66
67/* Cleanups initialization performed in android_charmap_setup routine. */
68void android_charmap_done(void);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080069
Vladimir Chtchetkine71bb14f2010-07-07 15:57:00 -070070/* 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 */
75const 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 */
80const 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 */
87int
88android_charmap_reverse_map_unicode(const AKeyCharmap* cmap,
89 unsigned int unicode,
90 int down,
91 AKeycodeBuffer* keycodes);
92
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -070093/* Gets default charmap (index 0) */
94const AKeyCharmap* android_get_default_charmap(void);
95
96/* Gets name of the default charmap (index 0) */
97const char* android_get_default_charmap_name(void);
98
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080099#endif /* _android_charmap_h */