blob: 4c39495ad9a5e4e93fb4efb591363f5b4eacf7ca [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
David 'Digit' Turner0158ea32011-01-19 05:21:31 +010054/* Gets a pointer to the default hard-coded charmap */
55const AKeyCharmap* android_get_default_charmap(void);
56
57/* Parse a charmap file and add it to our list.
vchtchetkine9085a282009-09-14 15:29:20 -070058 * 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.
David 'Digit' Turner0158ea32011-01-19 05:21:31 +010067 *
68 * Note: on success, the charmap will be returned by android_get_charmap()
69 */
vchtchetkine9085a282009-09-14 15:29:20 -070070int android_charmap_setup(const char* kcm_file_path);
71
72/* Cleanups initialization performed in android_charmap_setup routine. */
73void android_charmap_done(void);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080074
Vladimir Chtchetkine71bb14f2010-07-07 15:57:00 -070075/* Gets charmap descriptor by its name.
David 'Digit' Turner0158ea32011-01-19 05:21:31 +010076 * 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.
Vladimir Chtchetkine71bb14f2010-07-07 15:57:00 -070079 */
80const AKeyCharmap* android_get_charmap_by_name(const char* name);
81
Vladimir Chtchetkine71bb14f2010-07-07 15:57:00 -070082/* 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
David 'Digit' Turner0158ea32011-01-19 05:21:31 +010093/* 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 */
98const AKeyCharmap* android_get_charmap(void);
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -070099
David 'Digit' Turner0158ea32011-01-19 05:21:31 +0100100/* Return the name of the charmap to be used. Same as
101 * android_get_charmap()->name */
102const char* android_get_charmap_name(void);
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -0700103
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800104#endif /* _android_charmap_h */