18b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/* Copyright (C) 2007-2008 The Android Open Source Project 28b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project** 38b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project** This software is licensed under the terms of the GNU General Public 48b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project** License version 2, as published by the Free Software Foundation, and 58b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project** may be copied, distributed, and modified under those terms. 68b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project** 78b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project** This program is distributed in the hope that it will be useful, 88b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project** but WITHOUT ANY WARRANTY; without even the implied warranty of 98b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project** GNU General Public License for more details. 118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project*/ 128b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#ifndef _android_charmap_h 138b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define _android_charmap_h 148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 1587250c24aec9449eb615951cf537a2fcf709f1d8David 'Digit' Turner#include "android/keycode.h" 1671bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine#include "android/keycode-array.h" 178b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 188b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/* this defines a structure used to describe an Android keyboard charmap */ 198b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projecttypedef struct AKeyEntry { 208b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project unsigned short code; 218b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project unsigned short base; 228b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project unsigned short caps; 238b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project unsigned short fn; 248b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project unsigned short caps_fn; 258b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project unsigned short number; 268b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project} AKeyEntry; 278b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 289085a28c14f369d231dbae099a690689179f428avchtchetkine/* Defines size of name buffer in AKeyCharmap entry. */ 299085a28c14f369d231dbae099a690689179f428avchtchetkine#define AKEYCHARMAP_NAME_SIZE 32 309085a28c14f369d231dbae099a690689179f428avchtchetkine 319085a28c14f369d231dbae099a690689179f428avchtchetkinetypedef struct AKeyCharmap { 328b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project const AKeyEntry* entries; 338b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project int num_entries; 349085a28c14f369d231dbae099a690689179f428avchtchetkine char name[ AKEYCHARMAP_NAME_SIZE ]; 358b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project} AKeyCharmap; 368b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 379085a28c14f369d231dbae099a690689179f428avchtchetkine/* Extracts charmap name from .kcm file name. 389085a28c14f369d231dbae099a690689179f428avchtchetkine * Charmap name, extracted by this routine is a name of the kcm file, trimmed 399085a28c14f369d231dbae099a690689179f428avchtchetkine * of file name extension, and shrinked (if necessary) to fit into the name 409085a28c14f369d231dbae099a690689179f428avchtchetkine * buffer. Here are examples on how this routine extracts charmap name: 419085a28c14f369d231dbae099a690689179f428avchtchetkine * /a/path/to/kcmfile.kcm -> kcmfile 429085a28c14f369d231dbae099a690689179f428avchtchetkine * /a/path/to/kcmfile.ext.kcm -> kcmfile.ext 439085a28c14f369d231dbae099a690689179f428avchtchetkine * /a/path/to/kcmfile -> kcmfile 449085a28c14f369d231dbae099a690689179f428avchtchetkine * /a/path/to/.kcmfile -> kcmfile 459085a28c14f369d231dbae099a690689179f428avchtchetkine * /a/path/to/.kcmfile.kcm -> .kcmfile 469085a28c14f369d231dbae099a690689179f428avchtchetkine * kcm_file_path - Path to key charmap file to extract charmap name from. 479085a28c14f369d231dbae099a690689179f428avchtchetkine * charmap_name - Buffer, where to save extracted charname. 489085a28c14f369d231dbae099a690689179f428avchtchetkine * max_len - charmap_name buffer size. 499085a28c14f369d231dbae099a690689179f428avchtchetkine*/ 509085a28c14f369d231dbae099a690689179f428avchtchetkinevoid kcm_extract_charmap_name(const char* kcm_file_path, 519085a28c14f369d231dbae099a690689179f428avchtchetkine char* charmap_name, 529085a28c14f369d231dbae099a690689179f428avchtchetkine int max_len); 539085a28c14f369d231dbae099a690689179f428avchtchetkine 540158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turner/* Gets a pointer to the default hard-coded charmap */ 550158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turnerconst AKeyCharmap* android_get_default_charmap(void); 560158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turner 570158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turner/* Parse a charmap file and add it to our list. 589085a28c14f369d231dbae099a690689179f428avchtchetkine * Key charmap array always contains two maps: one for qwerty, and 599085a28c14f369d231dbae099a690689179f428avchtchetkine * another for qwerty2 keyboard layout. However, a custom layout can 609085a28c14f369d231dbae099a690689179f428avchtchetkine * be requested with -charmap option. In tha case kcm_file_path 619085a28c14f369d231dbae099a690689179f428avchtchetkine * parameter contains path to a .kcm file that defines that custom 629085a28c14f369d231dbae099a690689179f428avchtchetkine * layout, and as the result, key charmap array will contain another 639085a28c14f369d231dbae099a690689179f428avchtchetkine * entry built from that file. If -charmap option was not specified, 649085a28c14f369d231dbae099a690689179f428avchtchetkine * kcm_file_path is NULL and final key charmap array will contain only 659085a28c14f369d231dbae099a690689179f428avchtchetkine * two default entries. 669085a28c14f369d231dbae099a690689179f428avchtchetkine * Returns a zero value on success, or -1 on failure. 670158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turner * 680158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turner * Note: on success, the charmap will be returned by android_get_charmap() 690158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turner */ 709085a28c14f369d231dbae099a690689179f428avchtchetkineint android_charmap_setup(const char* kcm_file_path); 719085a28c14f369d231dbae099a690689179f428avchtchetkine 729085a28c14f369d231dbae099a690689179f428avchtchetkine/* Cleanups initialization performed in android_charmap_setup routine. */ 739085a28c14f369d231dbae099a690689179f428avchtchetkinevoid android_charmap_done(void); 748b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 7571bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine/* Gets charmap descriptor by its name. 760158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turner * This routine tries to find a charmap by name. This will compare the 770158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turner * name to the default charmap's name, or any charmap loaded with 780158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turner * android_charmap_setup(). Returns NULL on failure. 7971bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine */ 8071bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkineconst AKeyCharmap* android_get_charmap_by_name(const char* name); 8171bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine 8271bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine/* Maps given unicode key character into a keycode and adds mapped keycode into 8371bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine * keycode array. This routine uses charmap passed as cmap parameter to do the 8471bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine * translation, and 'down' parameter to generate appropriate ('down' or 'up') 8571bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine * keycode. 8671bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine */ 8771bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkineint 8871bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkineandroid_charmap_reverse_map_unicode(const AKeyCharmap* cmap, 8971bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine unsigned int unicode, 9071bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine int down, 9171bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine AKeycodeBuffer* keycodes); 9271bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine 930158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turner/* Return a pointer to the active charmap. If android_charmap_setup() was 940158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turner * called succesfully, this corresponds to the newly loaded charmap. 950158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turner * 960158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turner * Otherwise, return a pointer to the default charmap. 970158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turner */ 980158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turnerconst AKeyCharmap* android_get_charmap(void); 9943552dc4fa64aad0c9fdb8f4c92ae7ac79406596Vladimir Chtchetkine 1000158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turner/* Return the name of the charmap to be used. Same as 1010158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turner * android_get_charmap()->name */ 1020158ea3220978ecc0fa1738e4a0bdae83fa36175David 'Digit' Turnerconst char* android_get_charmap_name(void); 10343552dc4fa64aad0c9fdb8f4c92ae7ac79406596Vladimir Chtchetkine 1048b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#endif /* _android_charmap_h */ 105