mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-14 01:47:30 +00:00
Merge pull request #9384 from keymanapp/feat/linux/mcompile-DoConvert-read
feat(linux): mnemonic layout support 🐘
This commit is contained in:
commit
2f0deef21b
21 changed files with 3683 additions and 2539 deletions
|
|
@ -134,4 +134,3 @@ TabWidth: 8
|
|||
UseCRLF: false
|
||||
UseTab: Never
|
||||
...
|
||||
|
||||
|
|
|
|||
8
.gitignore
vendored
8
.gitignore
vendored
|
|
@ -183,11 +183,3 @@ lcov.info
|
|||
/keyman*.buildinfo
|
||||
/keyman*.changes
|
||||
/keyman*.tar.?z
|
||||
|
||||
#Sabine:
|
||||
# /common/test/keyboards/invalid/source/*.kmx
|
||||
# /developer/src/test/auto/kmcomp/*.kmn
|
||||
# /developer/src/test/auto/kmcomp/*.kvk
|
||||
# /developer/src/test/auto/kmcomp/*.kvk*
|
||||
# /developer/src/test/auto/kmcomp/*.txt
|
||||
/linux/mcompile/keymap/X_bak
|
||||
|
|
|
|||
2
linux/mcompile/keymap/.gitignore
vendored
Normal file
2
linux/mcompile/keymap/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
resources/
|
||||
build/
|
||||
|
|
@ -1,22 +1,7 @@
|
|||
# Keymap
|
||||
This is a proposal to rewrite mcompile for Linux. For this we need to query the base keyboard data from the Linux platform, then rewriting the keyboard .kmx using the same approach as is done in mcompile for Windows, but working from the data from the x11 keyboard on Linux.
|
||||
|
||||
Ideally, we'd rewrite mcompile to be cross-platform (Windows, Linux, macOS), so that the keyboard interrogation would be separated from the .kmx rewriting, at least to some degree. Nevertheless it would probably be easiest to start from a standalone implementation.
|
||||
Sample program that reads US basic keyboard and compares to key value group
|
||||
|
||||
|
||||
|
||||
TODO check if US basic is the right Keyboard to compare with
|
||||
TODO non-letter characters don't work OK yet
|
||||
TODO Umlauts don't work OK yet
|
||||
TODO Check for use of correct dimensions in Vector/prevent error if dims are not correct
|
||||
TODO prevent crashes: handle possible Errors in CreateCompleteRow_US, Split_US_To_3D_Vector
|
||||
TODO check Keycode of TLDE, BKSL, LSGT
|
||||
TODO remove unnecessary printf/cout
|
||||
TODO path for xkb/symbols as compile time option in meson
|
||||
TODO append_other_ToVector: ensure shift states of GetKeyvalsFromKeymap are not out of range
|
||||
TODO check how many/which shift states we use ( at the moment we read all shiftstate-columns of US but then use only 2 colums
|
||||
(non-shift + shift) then use as many colums for Other )
|
||||
|
||||
TODO define folder to store File_US.txt" in and find better name
|
||||
TODO get rid of GTK functions that are deprecated and use X11 instead
|
||||
TODO retrieve name of Other keyboard and use appropriate name instead of "Other"
|
||||
TODO ...
|
||||
# Keymap
|
||||
|
|
|
|||
63
linux/mcompile/keymap/build.sh
Executable file
63
linux/mcompile/keymap/build.sh
Executable file
|
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
## START STANDARD BUILD SCRIPT INCLUDE
|
||||
# adjust relative paths as necessary
|
||||
THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
|
||||
. "${THIS_SCRIPT%/*}/../../../resources/build/builder.inc.sh"
|
||||
## END STANDARD BUILD SCRIPT INCLUDE
|
||||
|
||||
#. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
|
||||
|
||||
################################ Main script ################################
|
||||
|
||||
builder_describe \
|
||||
"Mnemonic layout recompiler for Linux" \
|
||||
"@/common/include" \
|
||||
"clean" \
|
||||
"configure" \
|
||||
"build" \
|
||||
"test"
|
||||
|
||||
builder_parse "$@"
|
||||
|
||||
builder_describe_outputs \
|
||||
configure build/build.ninja \
|
||||
build build/mcompile
|
||||
|
||||
TARGET_PATH="$THIS_SCRIPT_PATH/build"
|
||||
|
||||
do_clean() {
|
||||
rm -rf "$THIS_SCRIPT_PATH/resources"
|
||||
rm -rf "$TARGET_PATH"
|
||||
}
|
||||
|
||||
do_configure() {
|
||||
# Import our standard compiler defines; this is copied from
|
||||
# /resources/build/meson/standard.meson.build by build.sh, because meson doesn't
|
||||
# allow us to reference a file outside its root
|
||||
mkdir -p "$THIS_SCRIPT_PATH/resources"
|
||||
cp "$KEYMAN_ROOT/resources/build/meson/standard.meson.build" "$THIS_SCRIPT_PATH/resources/meson.build"
|
||||
|
||||
pushd "$THIS_SCRIPT_PATH" > /dev/null
|
||||
# Additional arguments are used by Linux build, e.g. -Dprefix=${INSTALLDIR}
|
||||
meson setup build --buildtype $BUILDER_CONFIGURATION "${builder_extra_params[@]}"
|
||||
popd > /dev/null
|
||||
|
||||
}
|
||||
|
||||
do_build() {
|
||||
pushd "$TARGET_PATH" > /dev/null
|
||||
ninja
|
||||
popd > /dev/null
|
||||
}
|
||||
|
||||
do_test() {
|
||||
pushd "$TARGET_PATH" > /dev/null
|
||||
meson test "${builder_extra_params[@]}"
|
||||
popd > /dev/null
|
||||
}
|
||||
|
||||
builder_run_action clean do_clean
|
||||
builder_run_action configure do_configure
|
||||
builder_run_action build do_build
|
||||
builder_run_action test do_test
|
||||
331
linux/mcompile/keymap/deadkey.cpp
Normal file
331
linux/mcompile/keymap/deadkey.cpp
Normal file
|
|
@ -0,0 +1,331 @@
|
|||
/*
|
||||
* Keyman is copyright (C) 2004 - 2024 SIL International. MIT License.
|
||||
*
|
||||
* Mnemonic layout support for Linux
|
||||
*/
|
||||
|
||||
#include "keymap.h"
|
||||
#include "deadkey.h"
|
||||
|
||||
/**
|
||||
* @brief create a Vector of DeadKey containing all combinations of deadkey + character for ALL possible Linux keyboards
|
||||
* @return vector of Deadkey* that holds all combinations of deadkey + character
|
||||
*/
|
||||
std::vector<DeadKey*> create_deadkeys_by_basechar() {
|
||||
std::vector<DeadKey*> alDead;
|
||||
vec_dword_2D dk_ComposeTable;
|
||||
|
||||
create_DKTable(dk_ComposeTable);
|
||||
|
||||
for (int i = 0; i < (int)dk_ComposeTable.size() - 1; i++) {
|
||||
DeadKey* dk2 = new DeadKey(dk_ComposeTable[i][0]);
|
||||
for (int j = i; j < (int)dk_ComposeTable.size(); j++) {
|
||||
if ((dk_ComposeTable[i][0] == dk_ComposeTable[j][0]) && (IsKeymanUsedChar(dk_ComposeTable[j][1])))
|
||||
dk2->KMX_AddDeadKeyRow(dk_ComposeTable[j][1], dk_ComposeTable[j][2]);
|
||||
}
|
||||
alDead.push_back(dk2);
|
||||
}
|
||||
return alDead;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief filter entries for the currently used Linux Keyboard out of a vector of all existing deadKey combinations
|
||||
* @param dk the deadkey for which all combinations will be found
|
||||
* @param[in,out] dkVec combinations of deadkey + character for the currently used Linux Keyboard
|
||||
* @param r_All_Vec all existing combinations of deadkey + character for ALL possible Linux keyboards
|
||||
*/
|
||||
void refine_alDead(KMX_WCHAR dk, std::vector<DeadKey*>& dkVec, std::vector<DeadKey*>& r_All_Vec) {
|
||||
if (dk == 0)
|
||||
return;
|
||||
|
||||
for (int j = 0; j < (int)r_All_Vec.size(); j++) {
|
||||
if (dk == r_All_Vec[j]->KMX_GetDeadCharacter()) {
|
||||
if (!found_dk_inVector(dk, dkVec)) {
|
||||
dkVec.push_back(r_All_Vec[j]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief check whether a deadkey already exists in the deadkey vector
|
||||
* @param dk the deadkey to be found
|
||||
* @param dkVec vector containing combinations of deadkey + character
|
||||
* @return true if deadkey alredy exists;
|
||||
* false if not
|
||||
*/
|
||||
bool found_dk_inVector(KMX_WCHAR dk, std::vector<DeadKey*>& dkVec) {
|
||||
for (int i = 0; i < dkVec.size(); i++) {
|
||||
if (dk == dkVec[i]->KMX_GetDeadCharacter())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief find all deadkey combinations for a certain deadkey in a vector of all deadkey combinations
|
||||
* @param r_dk_ComposeTable vector containing all possible deadkey combinations
|
||||
* @param dk deadkey of interest
|
||||
* @param[in,out] dk_SingleTable vector containing all dk-character combinations for a specific deadkey dk
|
||||
* @return true if successful;
|
||||
* false if not
|
||||
*/
|
||||
bool query_dk_combinations_for_specific_dk(vec_dword_2D& r_dk_ComposeTable, KMX_DWORD dk, vec_dword_2D& dk_SingleTable) {
|
||||
vec_dword_1D row;
|
||||
|
||||
for (int i = 0; i < (int)r_dk_ComposeTable.size(); i++) {
|
||||
if (r_dk_ComposeTable[i][0] == dk && IsKeymanUsedChar(r_dk_ComposeTable[i][1])) {
|
||||
row.push_back(r_dk_ComposeTable[i][0]);
|
||||
row.push_back(r_dk_ComposeTable[i][1]);
|
||||
row.push_back(r_dk_ComposeTable[i][2]);
|
||||
dk_SingleTable.push_back(row);
|
||||
row.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (dk_SingleTable.size() > 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief convert a character to the upper-case equivalent and find the corresponding shiftstate
|
||||
* of the entered keyval: a(97) -> A(65) + Base A(65) -> A(65) + Shift
|
||||
* @param kval keyval that might be changed
|
||||
* @param[in,out] shift the shiftstate of the entered keyval
|
||||
* @param keymap a pointer to the currently used (underlying) keyboard layout
|
||||
* @return the upper case equivalent of the keyval
|
||||
*/
|
||||
KMX_DWORD KMX_change_keyname_to_capital(KMX_DWORD kVal, KMX_DWORD& shift, GdkKeymap* keymap) {
|
||||
guint keyval = (guint)kVal;
|
||||
GdkKeymapKey* keys;
|
||||
gint n_keys;
|
||||
|
||||
KMX_DWORD capitalKeyval = (KMX_DWORD)gdk_keyval_to_upper(kVal);
|
||||
if (keyval != 0) {
|
||||
gdk_keymap_get_entries_for_keyval(keymap, keyval, &keys, &n_keys);
|
||||
for (int i = 0; i < n_keys; i++) {
|
||||
if (keys[i].group == 0) {
|
||||
shift = keys[i].level;
|
||||
return capitalKeyval;
|
||||
}
|
||||
}
|
||||
}
|
||||
return capitalKeyval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief append a 1D-vector containing name, base character and unicode_value to a 2D-Vector
|
||||
* holding all possible combinations of deadkey + character for all Linux keyboards
|
||||
* @param[in,out] dk_ComposeTable 2D-Vector holding all possible combinations of deadkey + character
|
||||
* @param diacritic_name the name of a diacritic
|
||||
* @param base_char base character
|
||||
* @param unicode_value Unicode-value of the combined character
|
||||
*/
|
||||
void add_deadkey_combination(vec_dword_2D& dk_ComposeTable, std::string diacritic_name, std::string base_char, KMX_DWORD unicode_value) {
|
||||
vec_dword_1D line;
|
||||
line.push_back(convertNamesTo_DWORD_Value(diacritic_name));
|
||||
line.push_back(convertNamesTo_DWORD_Value(base_char));
|
||||
line.push_back(unicode_value);
|
||||
dk_ComposeTable.push_back(line);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief create a 2D-Vector containing all possible combinations of deadkey + character for all Linux keyboards
|
||||
* the values are taken from from: https://help.ubuntu.com/community/GtkDeadKeyTable#Accents
|
||||
* dk_ComposeTable[i][0] : diacritic_name (e.g. dead_circumflex)
|
||||
* dk_ComposeTable[i][1] : base_char (e.g. a)
|
||||
* dk_ComposeTable[i][2] : unicode_value-Value (e.g. 0x00E2)
|
||||
* @param[in,out] dk_ComposeTable
|
||||
*/
|
||||
void create_DKTable(vec_dword_2D& dk_ComposeTable) {
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_circumflex", "a", 0x00E2); // small A with circumflex
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_circumflex", "A", 0x00C2); // capital A with circumflex
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_circumflex", "e", 0x00EA); // small E with circumflex
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_circumflex", "E", 0x00CA); // capital E with circumflex
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_circumflex", "i", 0x00EE); // small I with circumflex
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_circumflex", "I", 0x00CE); // capital I with circumflex
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_circumflex", "o", 0x00F4); // small O with circumflex
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_circumflex", "O", 0x00D4); // capital O with circumflex
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_circumflex", "u", 0x00FB); // small U with circumflex
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_circumflex", "U", 0x00DB); // capital U with circumflex
|
||||
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "a", 0x00E1); // small A with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "A", 0x00C1); // capital A with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "c", 0x0107); // small C with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "C", 0x0106); // capital C with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "e", 0x00E9); // small E with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "E", 0x00C9); // capital E with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "i", 0x00ED); // small I with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "I", 0x00CD); // capital I with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "l", 0x013A); // small L with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "L", 0x0139); // capital L with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "n", 0x0144); // small N with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "N", 0x0143); // capital N with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "o", 0x00F3); // small O with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "O", 0x00D3); // capital O with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "r", 0x0155); // small R with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "R", 0x0154); // capital R with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "s", 0x015B); // small S with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "S", 0x015A); // capital S with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "u", 0x00FA); // small U with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "U", 0x00DA); // capital U with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "y", 0x00FD); // small Y with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "Y", 0x00DD); // capital Y with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "z", 0x017A); // small Z with acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "Z", 0x0179); // capital Z with acute
|
||||
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_grave", "a", 0x00E0); // small A with grave
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_grave", "A", 0x00C0); // capital A with grave
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_grave", "e", 0x00E8); // small E with grave
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_grave", "E", 0x00C8); // capital E with grave
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_grave", "i", 0x00EC); // small I with grave
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_grave", "I", 0x00CC); // capital I with grave
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_grave", "o", 0x00F2); // small O with grave
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_grave", "O", 0x00D2); // capital O with grave
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_grave", "u", 0x00F9); // small U with grave
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_grave", "U", 0x00D9); // capital U with grave
|
||||
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_tilde", "a", 0x00E3); // small A with tilde
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_tilde", "A", 0x00C3); // capital A with tilde
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_tilde", "i", 0x0129); // small I with tilde
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_tilde", "I", 0x0128); // capital I with tilde
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_tilde", "n", 0x00F1); // small N with tilde
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_tilde", "N", 0x00D1); // capital N with tilde
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_tilde", "o", 0x00F5); // small O with tilde
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_tilde", "O", 0x00D5); // capital O with tilde
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_tilde", "u", 0x0169); // small U with tilde
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_tilde", "U", 0x0168); // capital U with tilde
|
||||
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_macron", "a", 0x0101); // small A with macron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_macron", "A", 0x0100); // capital A with macron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_macron", "e", 0x0113); // small E with macron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_macron", "E", 0x0112); // capital E with macron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_macron", "i", 0x012B); // small I with macron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_macron", "I", 0x012A); // capital I with macron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_macron", "o", 0x014D); // small O with macron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_macron", "O", 0x014C); // capital O with macron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_macron", "u", 0x016B); // small U with macron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_macron", "U", 0x016A); // capital U with macron
|
||||
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_breve", "a", 0x0103); // small A with breve
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_breve", "A", 0x0102); // capital A with breve
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_breve", "g", 0x011F); // small G with breve
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_breve", "G", 0x011E); // capital G with breve
|
||||
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_abovedot", "e", 0x0117); // small E with dot above
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_abovedot", "E", 0x0116); // capital E with dot above
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_abovedot", "i", 0x0131); // small DOTLESS_I
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_abovedot", "I", 0x0130); // capital I with dot above
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_abovedot", "z", 0x017C); // small Z with dot above
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_abovedot", "Z", 0x017B); // capital Z with dot above
|
||||
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_diaeresis", "a", 0x00E4); // small A with diaeresis
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_diaeresis", "A", 0x00C4); // capital A with diaeresis
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_diaeresis", "e", 0x00EB); // small E with diaeresis
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_diaeresis", "E", 0x00CB); // capital E with diaeresis
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_diaeresis", "i", 0x00EF); // small I with diaeresis
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_diaeresis", "I", 0x00CF); // capital I with diaeresis
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_diaeresis", "o", 0x00F6); // small O with diaeresis
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_diaeresis", "O", 0x00D6); // capital O with diaeresis
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_diaeresis", "u", 0x00FC); // small U with diaeresis
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_diaeresis", "U", 0x00DC); // capital U with diaeresis
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_diaeresis", "y", 0x00FF); // small Y with diaeresis
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_diaeresis", "Y", 0x0178); // capital Y with diaeresis
|
||||
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_abovering", "a", 0x00E5); // small A with ring above
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_abovering", "A", 0x00C5); // capital A with ring above
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_abovering", "u", 0x016F); // small U with ring above
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_abovering", "U", 0x016E); // capital U with ring above
|
||||
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_doubleacute", "o", 0x0151); // small O with double acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_doubleacute", "O", 0x0150); // capital O with double acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_doubleacute", "u", 0x0171); // small U with double acute
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_doubleacute", "U", 0x0170); // capital U with double acute
|
||||
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "c", 0x010D); // small C with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "C", 0x010C); // capital C with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "d", 0x010F); // small D with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "D", 0x010E); // capital D with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "e", 0x011B); // small E with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "E", 0x011A); // capital E with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "l", 0x013E); // small L with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "L", 0x013D); // capital L with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "n", 0x0148); // small N with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "N", 0x0147); // capital N with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "r", 0x0159); // small R with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "R", 0x0158); // capital R with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "s", 0x0161); // small S with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "S", 0x0160); // capital S with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "t", 0x0165); // small T with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "T", 0x0164); // capital T with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "z", 0x017E); // small Z with caron
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "Z", 0x017D); // capital Z with caron
|
||||
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "c", 0x00E7); // small C with cedilla
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "C", 0x00C7); // capital C with cedilla
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "g", 0x0123); // small G with cedilla
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "G", 0x0122); // capital G with cedilla
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "k", 0x0137); // small K with cedilla
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "K", 0x0136); // capital K with cedilla
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "l", 0x013C); // small L with cedilla
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "L", 0x013B); // capital L with cedilla
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "n", 0x0146); // small N with cedilla
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "N", 0x0145); // capital N with cedilla
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "r", 0x0157); // small R with cedilla
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "R", 0x0156); // capital R with cedilla
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "s", 0x015F); // small S with cedilla
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "S", 0x015E); // capital S with cedilla
|
||||
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_ogonek", "a", 0x0105); // small A with ogonek
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_ogonek", "A", 0x0104); // capital A with ogonek
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_ogonek", "e", 0x0119); // small E with ogonek
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_ogonek", "E", 0x0118); // capital E with ogonek
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_ogonek", "i", 0x012F); // small I with ogonek
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_ogonek", "I", 0x012E); // capital I with ogonek
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_ogonek", "u", 0x0173); // small U with ogonek
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_ogonek", "U", 0x0172); // capital U with ogonek
|
||||
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_circumflex", "space", 0x005E); // CIRCUMFLEX_ACCENT
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "space", 0x0027); // APOSTROPHE
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_grave", "space", 0x0060); // GRAVE_ACCENT
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_breve", "space", 0x02D8); // BREVE
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_abovedot", "space", 0x02D9); // DOT_ABOVE
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_abovering", "space", 0x02DA); // RING_ABOVE
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_doubleacute", "space", 0x02DD); // DOUBLE_ACUTE_ACCENT
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "space", 0x02C7); // CARON
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "space", 0x00B8); // CEDILLA
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_ogonek", "space", 0x02DB); // OGONEK
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_tilde", "space", 0x007E); // TILDE
|
||||
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_breve", "dead_breve", 0x02D8); // BREVE
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_abovedot", "abovedot", 0x02D9); // DOT_ABOVE
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_abovedot", "dead_abovedot", 0x02D9); // DOT_ABOVE
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_abovering", "dead_abovering", 0x02DA); // RING_ABOVE
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "apostrophe", 0x00B4); // ACUTE_ACCENT
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "acute", 0x00B4); // ACUTE_ACCENT
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_acute", "dead_acute", 0x00B4); // ACUTE_ACCENT
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_doubleacute", "dead_doubleacute", 0x02DD); // DOUBLE_ACUTE_ACCENT
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "caron", 0x02C7); // CARON
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_caron", "dead_caron", 0x02C7); // CARON
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "comma", 0x00B8); // CEDILLA
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "cedilla", 0x00B8); // CEDILLA
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_cedilla", "dead_cedilla", 0x00B8); // CEDILLA
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_circumflex", "minus", 0x00AF); // MACRON
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_circumflex", "asciicircum", 0x005E); // CIRCUMFLEX_ACCENT
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_circumflex", "underscore", 0x00AF); // MACRON
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_circumflex", "dead_circumflex", 0x005E); // CIRCUMFLEX_ACCENT
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_diaeresis", "quotedbl", 0x00A8); // DIAERESIS
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_diaeresis", "diaeresis", 0x00A8); // DIAERESIS
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_diaeresis", "dead_diaeresis", 0x00A8); // DIAERESIS
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_grave", "grave", 0x0060); // GRAVE_ACCENT
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_grave", "dead_grave", 0x0060); // GRAVE_ACCENT
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_macron", "macron", 0x00AF); // MACRON
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_macron", "dead_macron", 0x00AF); // MACRON
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_ogonek", "ogonek", 0x02DB); // OGONEK
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_ogonek", "dead_ogonek", 0x02DB); // OGONEK
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_tilde", "asciitilde", 0x007E); // TILDE
|
||||
add_deadkey_combination(dk_ComposeTable, "dead_tilde", "dead_tilde", 0x007E); // TILDE
|
||||
}
|
||||
30
linux/mcompile/keymap/deadkey.h
Normal file
30
linux/mcompile/keymap/deadkey.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
#pragma once
|
||||
#ifndef DEADKEY_H
|
||||
#define DEADKEY_H
|
||||
|
||||
#include "mc_import_rules.h"
|
||||
#include <map>
|
||||
|
||||
/** @brief create a Vector of DeadKey containing all combinations of deadkey + character for ALL possible Linux keyboards */
|
||||
std::vector<DeadKey*> create_deadkeys_by_basechar();
|
||||
|
||||
/** @brief filter entries for the currently used Linux Keyboard out of a vector of all existing deadKey combinations */
|
||||
void refine_alDead(KMX_WCHAR dk, std::vector<DeadKey*>& dkVec, std::vector<DeadKey*>& r_All_Vec);
|
||||
|
||||
/** @brief check whether a deadkey already exists in the deadkey vector */
|
||||
bool found_dk_inVector(KMX_WCHAR dk, std::vector<DeadKey*>& dkVec);
|
||||
|
||||
/** @brief find all deadkey combinations for a certain deadkey in a vector of all deadkey combinations */
|
||||
bool query_dk_combinations_for_specific_dk(vec_dword_2D& r_dk_ComposeTable, KMX_DWORD dk, vec_dword_2D& dk_SingleTable);
|
||||
|
||||
/** @brief convert a character to the upper-case equivalent and find the corresponding shiftstate of the entered keyval */
|
||||
KMX_DWORD KMX_change_keyname_to_capital(KMX_DWORD kVal, KMX_DWORD& shift, GdkKeymap* keymap);
|
||||
|
||||
/** @brief append a 1D-vector containing name, base character and unicode_value to a 2D-Vector */
|
||||
void add_deadkey_combination(vec_dword_2D& dk_ComposeTable, std::string diacritic_name, std::string base_char, KMX_DWORD unicode_value);
|
||||
|
||||
/** @brief create a 2D-Vector containing all possible combinations of deadkey + character for all Linux keyboards */
|
||||
void create_DKTable(vec_dword_2D& dk_ComposeTable);
|
||||
|
||||
#endif /*DEADKEY_H*/
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,67 +1,574 @@
|
|||
// In ths program we use a 3D-Vector Vector[language][Keys][Shiftstates]
|
||||
#pragma once
|
||||
#ifndef KEYMAP_H
|
||||
#define KEYMAP_H
|
||||
|
||||
#include <X11/XKBlib.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "km_u16.h"
|
||||
#include <cassert>
|
||||
|
||||
#include "mc_kmxfile.h"
|
||||
#include "mc_savekeyboard.h"
|
||||
enum ShiftState {
|
||||
Base = 0, // 0
|
||||
Shft = 1, // 1
|
||||
Ctrl = 2, // 2
|
||||
ShftCtrl = Shft | Ctrl, // 3
|
||||
Menu = 4, // 4 -- NOT USED
|
||||
ShftMenu = Shft | Menu, // 5 -- NOT USED
|
||||
MenuCtrl = Menu | Ctrl, // 6
|
||||
ShftMenuCtrl = Shft | Menu | Ctrl, // 7
|
||||
Xxxx = 8, // 8
|
||||
ShftXxxx = Shft | Xxxx, // 9
|
||||
};
|
||||
|
||||
typedef std::vector<std::string> v_str_1D;
|
||||
typedef std::vector<std::vector<std::string> > v_str_2D;
|
||||
typedef std::vector<std::vector<std::vector<std::string> > > v_str_3D;
|
||||
#define VK_SPACE 0x20
|
||||
#define VK_COLON 0xBA
|
||||
#define VK_EQUAL 0xBB
|
||||
#define VK_COMMA 0xBC
|
||||
#define VK_HYPHEN 0xBD
|
||||
#define VK_PERIOD 0xBE
|
||||
#define VK_SLASH 0xBF
|
||||
#define VK_ACCENT 0xC0
|
||||
#define VK_LBRKT 0xDB
|
||||
#define VK_BKSLASH 0xDC
|
||||
#define VK_RBRKT 0xDD
|
||||
#define VK_QUOTE 0xDE
|
||||
#define VK_xDF 0xDF
|
||||
#define VK_OEM_102 0xE2 // "<>" or "\|" on RT 102-key kbd.
|
||||
|
||||
int shift_state_count = 2; // use shiftstate : no shift, shift
|
||||
#define VK_DIVIDE 0x6F
|
||||
#define VK_CANCEL 3
|
||||
#define VK_DECIMAL 0x2E
|
||||
|
||||
// read configuration file, split and write to 3D-Vector (Data for US on [0][ ][ ] )
|
||||
void write_US_ToVector(v_str_3D &vec, std::string language, const char *text);
|
||||
#define VK_OEM_CLEAR 0xFE
|
||||
#define VK_LSHIFT 0xA0
|
||||
#define VK_RSHIFT 0xA1
|
||||
#define VK_LCONTROL 0xA2
|
||||
#define VK_RCONTROL 0xA3
|
||||
#define VK_LMENU 0xA4
|
||||
#define VK_RMENU 0xA5
|
||||
|
||||
// 1. step: read complete Row of Configuration file US
|
||||
void CreateCompleteRow_US(v_str_1D &complete_List, FILE *fpp, const char *text, std::string language);
|
||||
#define VK_SHIFT 0x10
|
||||
#define VK_CONTROL 0x11
|
||||
#define VK_MENU 0x12
|
||||
#define VK_PAUSE 0x13
|
||||
#define VK_CAPITAL 0x14
|
||||
|
||||
// 2nd step: write contents to 3D vector
|
||||
void Split_US_To_3D_Vector(v_str_3D &all_US, v_str_1D completeList);
|
||||
|
||||
// replace Name of Key (e.g. <AD06>) wih Keycode ( e.g. 15 )
|
||||
int replace_PosKey_with_Keycode(std::string in);
|
||||
// Map of all US English virtual key codes that we can translate
|
||||
const KMX_DWORD KMX_VKMap[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
|
||||
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
|
||||
// append characters using GDK to 3D-Vector (Data for Other Language on [1][ ][ ] )
|
||||
void append_other_ToVector(v_str_3D &All_Vector, GdkKeymap *keymap);
|
||||
VK_SPACE, /* 32 */
|
||||
|
||||
// create an empty 2D vector containing "--" in all fields
|
||||
v_str_2D create_empty_2D(int dim_rows, int dim_shifts);
|
||||
VK_ACCENT, /* 192 VK_OEM_3 K_BKQUOTE */
|
||||
VK_HYPHEN, /* - 189 VK_OEM_MINUS */
|
||||
VK_EQUAL, /* = 187 VK_OEM_PLUS */
|
||||
|
||||
// find Keyvals to fill into 2D-Vector of Other Language
|
||||
int GetKeyvalsFromKeymap(GdkKeymap *keymap, guint keycode, int shift_state_pos);
|
||||
VK_LBRKT, /* [ 219 VK_OEM_4 */
|
||||
VK_RBRKT, /* ] 221 VK_OEM_6 */
|
||||
VK_BKSLASH, /* \ 220 VK_OEM_5 */
|
||||
|
||||
// print both sets of characters (US and OtherLanguage) to console and file for comparison
|
||||
void extract_difference(v_str_3D &All_Vector);
|
||||
VK_COLON, /* ; 186 VK_OEM_1 */
|
||||
VK_QUOTE, /* ' 222 VK_OEM_7 */
|
||||
|
||||
// get mapped key from Other (Other->US)
|
||||
std::string get_Other_Char_FromUS(std::string in, v_str_3D &All_Vector);
|
||||
// get mapped key from US->Other (US->Other)
|
||||
std::string get_US_Char_FromOther(std::string in, v_str_3D &All_Vector);
|
||||
// get KeyNr from US
|
||||
std::string getKeyNrOf_USChar(std::string in, v_str_3D &All_Vector);
|
||||
// get KeyNr from Other
|
||||
std::string getKeyNrOf_OtherChar(std::string in, v_str_3D &All_Vector);
|
||||
VK_COMMA, /* , 188 VK_OEM_COMMA */
|
||||
VK_PERIOD, /* . 190 VK_OEM_PERIOD */
|
||||
VK_SLASH, /* / 191 VK_OEM_2 */
|
||||
|
||||
// for testing/debugging - may be deleted later
|
||||
// prints out a 1:1 mapping US->Other
|
||||
void print_simple_map_US(v_str_3D &All_Vector, int shiftstate);
|
||||
// prints out a 1:1 mapping Other->US
|
||||
void print_simple_map_Other(v_str_3D &All_Vector, int shiftstate);
|
||||
// test of above functions (character mapping US <-> Other; KeyNr <-> CHaracter)
|
||||
void test_in_out(v_str_3D &All_Vector);
|
||||
// testing of Vector contents ( first row of US and Other)
|
||||
bool test(v_str_3D &V);
|
||||
// writing out mapping of some characters: a,b,m,w,x,y,z
|
||||
void test_specific_Characters(v_str_3D &All_Vector);
|
||||
VK_xDF, /* ß (?) 223*/
|
||||
VK_OEM_102, /* < > | 226 */
|
||||
0};
|
||||
|
||||
typedef std::vector<std::string> vec_string_1D;
|
||||
typedef std::vector<KMX_DWORD> vec_dword_1D;
|
||||
typedef std::vector<std::vector<KMX_DWORD> > vec_dword_2D;
|
||||
typedef std::vector<std::vector<std::vector<KMX_DWORD> > > vec_dword_3D;
|
||||
|
||||
static KMX_DWORD INVALID_NAME = 0;
|
||||
static gint keycode_max = 94;
|
||||
static KMX_DWORD deadkey_min = 0xfe50; // X11's keysymdef.h defines deadkeys between 0xfe50-0xfe93
|
||||
static KMX_DWORD deadkey_max = 0xfe93; // https://fossies.org/linux/tk/xlib/X11/keysymdef.h
|
||||
|
||||
/** @brief check if current machine uses little endian
|
||||
* @return true if little endian is used;
|
||||
* else false */
|
||||
inline bool isLittleEndianSystem() {
|
||||
char16_t test = 0x0102;
|
||||
return (reinterpret_cast<char*>(&test))[0] == 0x02;
|
||||
}
|
||||
|
||||
/** @brief map a shiftstate used on windows to a shiftstate suitable for gdk_keymap_translate_keyboard_state() on Linux */
|
||||
int convert_Shiftstate_to_LinuxShiftstate(int shiftState);
|
||||
|
||||
/** @brief map a shiftstate used for rgkey to a shiftstate suitable for gdk_keymap_translate_keyboard_state() on Linux */
|
||||
int convert_rgkey_Shiftstate_to_LinuxShiftstate(ShiftState shiftState);
|
||||
|
||||
/** @brief check for correct input parameter that will later be used in gdk_keymap_translate_keyboard_state() */
|
||||
bool ensureValidInputForKeyboardTranslation(int shiftstate, gint keycode);
|
||||
|
||||
/** @brief convert names of keys stated in a symbol file to a keyvalue */
|
||||
KMX_DWORD convertNamesTo_DWORD_Value(std::string tok_str);
|
||||
|
||||
/** @brief create a 3D-Vector containing data of the US keyboard and the currently used (underlying) keyboard */
|
||||
int createOneVectorFromBothKeyboards(vec_dword_3D& all_vector, GdkKeymap* keymap);
|
||||
|
||||
/** @brief write data of the US keyboard into a 3D-Vector which later will contain data of the US keyboard and the currently used (underlying) keyboard */
|
||||
int write_US_ToVector(vec_dword_3D& vec_us);
|
||||
|
||||
/** @brief create a 1D-Vector containing all relevant entries of the symbol file us basic */
|
||||
bool createCompleteVector_US(vec_string_1D& complete_List);
|
||||
|
||||
/** @brief convert the key name obtained from symbol file to the matching keycode */
|
||||
int get_keycode_from_keyname(std::string key_name);
|
||||
|
||||
/** @brief process each element of a 1D-Vector, split and write to a 3D-Vector */
|
||||
int split_US_To_3D_Vector(vec_dword_3D& all_US, vec_string_1D completeList);
|
||||
|
||||
/** @brief create an 2D-Vector with all fields containing INVALID_NAME */
|
||||
vec_dword_2D create_empty_2D_Vector(int dim_rows, int dim_ss);
|
||||
|
||||
/** @brief append a 2D-vector containing data of the currently used (underlying) keyboard to the 3D-vector */
|
||||
int append_underlying_ToVector(vec_dword_3D& all_vector, GdkKeymap* keymap);
|
||||
|
||||
/** @brief create a pointer to pointer of the current keymap for later use */
|
||||
bool InitializeGDK(GdkKeymap** keymap, int argc, gchar* argv[]);
|
||||
|
||||
const KMX_DWORD USVirtualKeyToScanCode[256] = {
|
||||
0x00, // L"K_?00", // &H0
|
||||
0x00, // L"K_LBUTTON", // &H1
|
||||
0x00, // L"K_RBUTTON", // &H2
|
||||
0x46, // L"K_CANCEL", // &H3
|
||||
0x00, // L"K_MBUTTON", // &H4
|
||||
0x00, // L"K_?05", // &H5
|
||||
0x00, // L"K_?06", // &H6
|
||||
0x00, // L"K_?07", // &H7
|
||||
0x0E, // L"K_BKSP", // &H8
|
||||
0x0F, // L"K_TAB", // &H9
|
||||
0x00, // L"K_?0A", // &HA
|
||||
0x00, // L"K_?0B", // &HB
|
||||
0x4C, // L"K_KP5", // &HC
|
||||
0x1C, // L"K_ENTER", // &HD
|
||||
0x00, // L"K_?0E", // &HE
|
||||
0x00, // L"K_?0F", // &HF
|
||||
0x2A, // L"K_SHIFT", // &H10
|
||||
0x1D, // L"K_CONTROL", // &H11
|
||||
0x38, // L"K_ALT", // &H12
|
||||
0x00, // L"K_PAUSE", // &H13
|
||||
0x3A, // L"K_CAPS", // &H14
|
||||
0x00, // L"K_KANJI?15", // &H15
|
||||
0x00, // L"K_KANJI?16", // &H16
|
||||
0x00, // L"K_KANJI?17", // &H17
|
||||
0x00, // L"K_KANJI?18", // &H18
|
||||
0x00, // L"K_KANJI?19", // &H19
|
||||
0x00, // L"K_?1A", // &H1A
|
||||
0x01, // L"K_ESC", // &H1B
|
||||
0x00, // L"K_KANJI?1C", // &H1C
|
||||
0x00, // L"K_KANJI?1D", // &H1D
|
||||
0x00, // L"K_KANJI?1E", // &H1E
|
||||
0x00, // L"K_KANJI?1F", // &H1F
|
||||
0x39, // L"K_SPACE", // &H20
|
||||
0x49, // L"K_PGUP", // &H21
|
||||
0x51, // L"K_PGDN", // &H22
|
||||
0x4F, // L"K_END", // &H23
|
||||
0x47, // L"K_HOME", // &H24
|
||||
0x4B, // L"K_LEFT", // &H25
|
||||
0x48, // L"K_UP", // &H26
|
||||
0x4D, // L"K_RIGHT", // &H27
|
||||
0x50, // L"K_DOWN", // &H28
|
||||
0x00, // L"K_SEL", // &H29
|
||||
0x00, // L"K_PRINT", // &H2A
|
||||
0x00, // L"K_EXEC", // &H2B
|
||||
0x54, // L"K_PRTSCN", // &H2C
|
||||
0x52, // L"K_INS", // &H2D
|
||||
0x53, // L"K_DEL", // &H2E
|
||||
0x63, // L"K_HELP", // &H2F
|
||||
0x0B, // L"K_0", // &H30
|
||||
0x02, // L"K_1", // &H31
|
||||
0x03, // L"K_2", // &H32
|
||||
0x04, // L"K_3", // &H33
|
||||
0x05, // L"K_4", // &H34
|
||||
0x06, // L"K_5", // &H35
|
||||
0x07, // L"K_6", // &H36
|
||||
0x08, // L"K_7", // &H37
|
||||
0x09, // L"K_8", // &H38
|
||||
0x0A, // L"K_9", // &H39
|
||||
0x00, // L"K_?3A", // &H3A
|
||||
0x00, // L"K_?3B", // &H3B
|
||||
0x00, // L"K_?3C", // &H3C
|
||||
0x00, // L"K_?3D", // &H3D
|
||||
0x00, // L"K_?3E", // &H3E
|
||||
0x00, // L"K_?3F", // &H3F
|
||||
0x00, // L"K_?40", // &H40
|
||||
0x1E, // L"K_A", // &H41
|
||||
0x30, // L"K_B", // &H42
|
||||
0x2E, // L"K_C", // &H43
|
||||
0x20, // L"K_D", // &H44
|
||||
0x12, // L"K_E", // &H45
|
||||
0x21, // L"K_F", // &H46
|
||||
0x22, // L"K_G", // &H47
|
||||
0x23, // L"K_H", // &H48
|
||||
0x17, // L"K_I", // &H49
|
||||
0x24, // L"K_J", // &H4A
|
||||
0x25, // L"K_K", // &H4B
|
||||
0x26, // L"K_L", // &H4C
|
||||
0x32, // L"K_M", // &H4D
|
||||
0x31, // L"K_N", // &H4E
|
||||
0x18, // L"K_O", // &H4F
|
||||
0x19, // L"K_P", // &H50
|
||||
0x10, // L"K_Q", // &H51
|
||||
0x13, // L"K_R", // &H52
|
||||
0x1F, // L"K_S", // &H53
|
||||
0x14, // L"K_T", // &H54
|
||||
0x16, // L"K_U", // &H55
|
||||
0x2F, // L"K_V", // &H56
|
||||
0x11, // L"K_W", // &H57
|
||||
0x2D, // L"K_X", // &H58
|
||||
0x15, // L"K_Y", // &H59
|
||||
0x2C, // L"K_Z", // &H5A
|
||||
0x5B, // L"K_?5B", // &H5B
|
||||
0x5C, // L"K_?5C", // &H5C
|
||||
0x5D, // L"K_?5D", // &H5D
|
||||
0x00, // L"K_?5E", // &H5E
|
||||
0x5F, // L"K_?5F", // &H5F
|
||||
0x52, // L"K_NP0", // &H60
|
||||
0x4F, // L"K_NP1", // &H61
|
||||
0x50, // L"K_NP2", // &H62
|
||||
0x51, // L"K_NP3", // &H63
|
||||
0x4B, // L"K_NP4", // &H64
|
||||
0x4C, // L"K_NP5", // &H65
|
||||
0x4D, // L"K_NP6", // &H66
|
||||
0x47, // L"K_NP7", // &H67
|
||||
0x48, // L"K_NP8", // &H68
|
||||
0x49, // L"K_NP9", // &H69
|
||||
0x37, // L"K_NPSTAR", // &H6A
|
||||
0x4E, // L"K_NPPLUS", // &H6B
|
||||
0x7E, // L"K_SEPARATOR", // &H6C // MCD 01-11-02: Brazilian Fix, 00 -> 7E
|
||||
0x4A, // L"K_NPMINUS", // &H6D
|
||||
0x53, // L"K_NPDOT", // &H6E
|
||||
0x135, // L"K_NPSLASH", // &H6F
|
||||
0x3B, // L"K_F1", // &H70
|
||||
0x3C, // L"K_F2", // &H71
|
||||
0x3D, // L"K_F3", // &H72
|
||||
0x3E, // L"K_F4", // &H73
|
||||
0x3F, // L"K_F5", // &H74
|
||||
0x40, // L"K_F6", // &H75
|
||||
0x41, // L"K_F7", // &H76
|
||||
0x42, // L"K_F8", // &H77
|
||||
0x43, // L"K_F9", // &H78
|
||||
0x44, // L"K_F10", // &H79
|
||||
0x57, // L"K_F11", // &H7A
|
||||
0x58, // L"K_F12", // &H7B
|
||||
0x64, // L"K_F13", // &H7C
|
||||
0x65, // L"K_F14", // &H7D
|
||||
0x66, // L"K_F15", // &H7E
|
||||
0x67, // L"K_F16", // &H7F
|
||||
0x68, // L"K_F17", // &H80
|
||||
0x69, // L"K_F18", // &H81
|
||||
0x6A, // L"K_F19", // &H82
|
||||
0x6B, // L"K_F20", // &H83
|
||||
0x6C, // L"K_F21", // &H84
|
||||
0x6D, // L"K_F22", // &H85
|
||||
0x6E, // L"K_F23", // &H86
|
||||
0x76, // L"K_F24", // &H87
|
||||
|
||||
0x00, // L"K_?88", // &H88
|
||||
0x00, // L"K_?89", // &H89
|
||||
0x00, // L"K_?8A", // &H8A
|
||||
0x00, // L"K_?8B", // &H8B
|
||||
0x00, // L"K_?8C", // &H8C
|
||||
0x00, // L"K_?8D", // &H8D
|
||||
0x00, // L"K_?8E", // &H8E
|
||||
0x00, // L"K_?8F", // &H8F
|
||||
|
||||
0x45, // L"K_NUMLOCK", // &H90
|
||||
0x46, // L"K_SCROL", // &H91
|
||||
|
||||
0x00, // L"K_?92", // &H92
|
||||
0x00, // L"K_?93", // &H93
|
||||
0x00, // L"K_?94", // &H94
|
||||
0x00, // L"K_?95", // &H95
|
||||
0x00, // L"K_?96", // &H96
|
||||
0x00, // L"K_?97", // &H97
|
||||
0x00, // L"K_?98", // &H98
|
||||
0x00, // L"K_?99", // &H99
|
||||
0x00, // L"K_?9A", // &H9A
|
||||
0x00, // L"K_?9B", // &H9B
|
||||
0x00, // L"K_?9C", // &H9C
|
||||
0x00, // L"K_?9D", // &H9D
|
||||
0x00, // L"K_?9E", // &H9E
|
||||
0x00, // L"K_?9F", // &H9F
|
||||
0x2A, // L"K_?A0", // &HA0
|
||||
0x36, // L"K_?A1", // &HA1
|
||||
0x1D, // L"K_?A2", // &HA2
|
||||
0x1D, // L"K_?A3", // &HA3
|
||||
0x38, // L"K_?A4", // &HA4
|
||||
0x38, // L"K_?A5", // &HA5
|
||||
0x6A, // L"K_?A6", // &HA6
|
||||
0x69, // L"K_?A7", // &HA7
|
||||
0x67, // L"K_?A8", // &HA8
|
||||
0x68, // L"K_?A9", // &HA9
|
||||
0x65, // L"K_?AA", // &HAA
|
||||
0x66, // L"K_?AB", // &HAB
|
||||
0x32, // L"K_?AC", // &HAC
|
||||
0x20, // L"K_?AD", // &HAD
|
||||
0x2E, // L"K_?AE", // &HAE
|
||||
0x30, // L"K_?AF", // &HAF
|
||||
0x19, // L"K_?B0", // &HB0
|
||||
0x10, // L"K_?B1", // &HB1
|
||||
0x24, // L"K_?B2", // &HB2
|
||||
0x22, // L"K_?B3", // &HB3
|
||||
0x6C, // L"K_?B4", // &HB4
|
||||
0x6D, // L"K_?B5", // &HB5
|
||||
0x6B, // L"K_?B6", // &HB6
|
||||
0x21, // L"K_?B7", // &HB7
|
||||
0x00, // L"K_?B8", // &HB8
|
||||
0x00, // L"K_?B9", // &HB9
|
||||
0x27, // L"K_COLON", // &HBA
|
||||
0x0D, // L"K_EQUAL", // &HBB
|
||||
0x33, // L"K_COMMA", // &HBC
|
||||
0x0C, // L"K_HYPHEN", // &HBD
|
||||
0x34, // L"K_PERIOD", // &HBE
|
||||
0x35, // L"K_SLASH", // &HBF
|
||||
0x29, // L"K_BKQUOTE", // &HC0
|
||||
|
||||
0x73, // L"K_?C1", // &HC1
|
||||
0x7E, // L"K_?C2", // &HC2
|
||||
0x00, // L"K_?C3", // &HC3
|
||||
0x00, // L"K_?C4", // &HC4
|
||||
0x00, // L"K_?C5", // &HC5
|
||||
0x00, // L"K_?C6", // &HC6
|
||||
0x00, // L"K_?C7", // &HC7
|
||||
0x00, // L"K_?C8", // &HC8
|
||||
0x00, // L"K_?C9", // &HC9
|
||||
0x00, // L"K_?CA", // &HCA
|
||||
0x00, // L"K_?CB", // &HCB
|
||||
0x00, // L"K_?CC", // &HCC
|
||||
0x00, // L"K_?CD", // &HCD
|
||||
0x00, // L"K_?CE", // &HCE
|
||||
0x00, // L"K_?CF", // &HCF
|
||||
0x00, // L"K_?D0", // &HD0
|
||||
0x00, // L"K_?D1", // &HD1
|
||||
0x00, // L"K_?D2", // &HD2
|
||||
0x00, // L"K_?D3", // &HD3
|
||||
0x00, // L"K_?D4", // &HD4
|
||||
0x00, // L"K_?D5", // &HD5
|
||||
0x00, // L"K_?D6", // &HD6
|
||||
0x00, // L"K_?D7", // &HD7
|
||||
0x00, // L"K_?D8", // &HD8
|
||||
0x00, // L"K_?D9", // &HD9
|
||||
0x00, // L"K_?DA", // &HDA
|
||||
0x1A, // L"K_LBRKT", // &HDB
|
||||
0x2B, // L"K_BKSLASH", // &HDC
|
||||
0x1B, // L"K_RBRKT", // &HDD
|
||||
0x28, // L"K_QUOTE", // &HDE
|
||||
0x73, // L"K_oDF", // &HDF // MCD 01-11-02: Brazilian fix: 00 -> 73
|
||||
0x00, // L"K_oE0", // &HE0
|
||||
0x00, // L"K_oE1", // &HE1
|
||||
0x56, // L"K_oE2", // &HE2
|
||||
0x00, // L"K_oE3", // &HE3
|
||||
0x00, // L"K_oE4", // &HE4
|
||||
|
||||
0x00, // L"K_?E5", // &HE5
|
||||
|
||||
0x00, // L"K_oE6", // &HE6
|
||||
|
||||
0x00, // L"K_?E7", // &HE7
|
||||
0x00, // L"K_?E8", // &HE8
|
||||
|
||||
0x71, // L"K_oE9", // &HE9
|
||||
0x5C, // L"K_oEA", // &HEA
|
||||
0x7B, // L"K_oEB", // &HEB
|
||||
0x00, // L"K_oEC", // &HEC
|
||||
0x6F, // L"K_oED", // &HED
|
||||
0x5A, // L"K_oEE", // &HEE
|
||||
0x00, // L"K_oEF", // &HEF
|
||||
0x00, // L"K_oF0", // &HF0
|
||||
0x5B, // L"K_oF1", // &HF1
|
||||
0x00, // L"K_oF2", // &HF2
|
||||
0x5F, // L"K_oF3", // &HF3
|
||||
0x00, // L"K_oF4", // &HF4
|
||||
0x5E, // L"K_oF5", // &HF5
|
||||
|
||||
0x00, // L"K_?F6", // &HF6
|
||||
0x00, // L"K_?F7", // &HF7
|
||||
0x00, // L"K_?F8", // &HF8
|
||||
0x5D, // L"K_?F9", // &HF9
|
||||
0x00, // L"K_?FA", // &HFA
|
||||
0x62, // L"K_?FB", // &HFB
|
||||
0x00, // L"K_?FC", // &HFC
|
||||
0x00, // L"K_?FD", // &HFD
|
||||
0x00, // L"K_?FE", // &HFE
|
||||
0x00 // L"K_?FF" // &HFF
|
||||
};
|
||||
|
||||
const KMX_DWORD ScanCodeToUSVirtualKey[128] = {
|
||||
0x01, // 0x00 => K_LBUTTON
|
||||
0x1b, // 0x01 => K_ESC
|
||||
0x31, // 0x02 => K_1
|
||||
0x32, // 0x03 => K_2
|
||||
0x33, // 0x04 => K_3
|
||||
0x34, // 0x05 => K_4
|
||||
0x35, // 0x06 => K_5
|
||||
0x36, // 0x07 => K_6
|
||||
0x37, // 0x08 => K_7
|
||||
0x38, // 0x09 => K_8
|
||||
0x39, // 0x0a => K_9
|
||||
0x30, // 0x0b => K_0
|
||||
0xbd, // 0x0c => K_HYPHEN
|
||||
0xbb, // 0x0d => K_EQUAL
|
||||
0x08, // 0x0e => K_BKSP
|
||||
0x09, // 0x0f => K_TAB
|
||||
0x51, // 0x10 => K_Q
|
||||
0x57, // 0x11 => K_W
|
||||
0x45, // 0x12 => K_E
|
||||
0x52, // 0x13 => K_R
|
||||
0x54, // 0x14 => K_T
|
||||
0x59, // 0x15 => K_Y
|
||||
0x55, // 0x16 => K_U
|
||||
0x49, // 0x17 => K_I
|
||||
0x4f, // 0x18 => K_O
|
||||
0x50, // 0x19 => K_P
|
||||
0xdb, // 0x1a => K_LBRKT
|
||||
0xdd, // 0x1b => K_RBRKT
|
||||
0x0d, // 0x1c => K_ENTER
|
||||
0x11, // 0x1d => K_CONTROL
|
||||
0x41, // 0x1e => K_A
|
||||
0x53, // 0x1f => K_S
|
||||
0x44, // 0x20 => K_D
|
||||
0x46, // 0x21 => K_F
|
||||
0x47, // 0x22 => K_G
|
||||
0x48, // 0x23 => K_H
|
||||
0x4a, // 0x24 => K_J
|
||||
0x4b, // 0x25 => K_K
|
||||
0x4c, // 0x26 => K_L
|
||||
0xba, // 0x27 => K_COLON
|
||||
0xde, // 0x28 => K_QUOTE
|
||||
0xc0, // 0x29 => K_BKQUOTE
|
||||
0x10, // 0x2a => K_SHIFT
|
||||
0xdc, // 0x2b => K_BKSLASH
|
||||
0x5a, // 0x2c => K_Z
|
||||
0x58, // 0x2d => K_X
|
||||
0x43, // 0x2e => K_C
|
||||
0x56, // 0x2f => K_V
|
||||
0x42, // 0x30 => K_B
|
||||
0x4e, // 0x31 => K_N
|
||||
0x4d, // 0x32 => K_M
|
||||
0xbc, // 0x33 => K_COMMA
|
||||
0xbe, // 0x34 => K_PERIOD
|
||||
0xbf, // 0x35 => K_SLASH
|
||||
0xa1, // 0x36 => K_?A1
|
||||
0x6a, // 0x37 => K_NPSTAR
|
||||
0x12, // 0x38 => K_ALT
|
||||
0x20, // 0x39 => K_SPACE
|
||||
0x14, // 0x3a => K_CAPS
|
||||
0x70, // 0x3b => K_F1
|
||||
0x71, // 0x3c => K_F2
|
||||
0x72, // 0x3d => K_F3
|
||||
0x73, // 0x3e => K_F4
|
||||
0x74, // 0x3f => K_F5
|
||||
0x75, // 0x40 => K_F6
|
||||
0x76, // 0x41 => K_F7
|
||||
0x77, // 0x42 => K_F8
|
||||
0x78, // 0x43 => K_F9
|
||||
0x79, // 0x44 => K_F10
|
||||
0x90, // 0x45 => K_NUMLOCK
|
||||
0x03, // 0x46 => K_CANCEL
|
||||
0x24, // 0x47 => K_HOME
|
||||
0x26, // 0x48 => K_UP
|
||||
0x21, // 0x49 => K_PGUP
|
||||
0x6d, // 0x4a => K_NPMINUS
|
||||
0x25, // 0x4b => K_LEFT
|
||||
0x0c, // 0x4c => K_KP5
|
||||
0x27, // 0x4d => K_RIGHT
|
||||
0x6b, // 0x4e => K_NPPLUS
|
||||
0x23, // 0x4f => K_END
|
||||
0x28, // 0x50 => K_DOWN
|
||||
0x22, // 0x51 => K_PGDN
|
||||
0x2d, // 0x52 => K_INS
|
||||
0x2e, // 0x53 => K_DEL
|
||||
0x2c, // 0x54 => K_PRTSCN
|
||||
0x00, // 0x55 => No match
|
||||
0xe2, // 0x56 => K_oE2
|
||||
0x7a, // 0x57 => K_F11
|
||||
0x7b, // 0x58 => K_F12
|
||||
0x00, // 0x59 => No match
|
||||
0xee, // 0x5a => K_oEE
|
||||
0x5b, // 0x5b => K_?5B
|
||||
0x5c, // 0x5c => K_?5C
|
||||
0x5d, // 0x5d => K_?5D
|
||||
0xf5, // 0x5e => K_oF5
|
||||
0x5f, // 0x5f => K_?5F
|
||||
0x00, // 0x60 => No match
|
||||
0x00, // 0x61 => No match
|
||||
0xfb, // 0x62 => K_?FB
|
||||
0x2f, // 0x63 => K_HELP
|
||||
0x7c, // 0x64 => K_F13
|
||||
0x7d, // 0x65 => K_F14
|
||||
0x7e, // 0x66 => K_F15
|
||||
0x7f, // 0x67 => K_F16
|
||||
0x80, // 0x68 => K_F17
|
||||
0x81, // 0x69 => K_F18
|
||||
0x82, // 0x6a => K_F19
|
||||
0x83, // 0x6b => K_F20
|
||||
0x84, // 0x6c => K_F21
|
||||
0x85, // 0x6d => K_F22
|
||||
0x86, // 0x6e => K_F23
|
||||
0xed, // 0x6f => K_oED
|
||||
0x00, // 0x70 => No match
|
||||
0xe9, // 0x71 => K_oE9
|
||||
0x00, // 0x72 => No match
|
||||
0xc1, // 0x73 => K_?C1
|
||||
0x00, // 0x74 => No match
|
||||
0x00, // 0x75 => No match
|
||||
0x87, // 0x76 => K_F24
|
||||
0x00, // 0x77 => No match
|
||||
0x00, // 0x78 => No match
|
||||
0x00, // 0x79 => No match
|
||||
0x00, // 0x7a => No match
|
||||
0xeb, // 0x7b => K_oEB
|
||||
0x00, // 0x7c => No match
|
||||
0x00, // 0x7d => No match
|
||||
0x6c, // 0x7e => K_SEPARATOR
|
||||
0x00 // 0x7f => No match
|
||||
};
|
||||
|
||||
/** @brief check if keyval correponds to a character used in mcompile */
|
||||
bool IsKeymanUsedChar(int kv);
|
||||
|
||||
/** @brief convert a deadkey-value to a u16string if it is in the range of deadkeys used for mcompile */
|
||||
std::u16string convert_DeadkeyValues_To_U16str(KMX_DWORD in);
|
||||
|
||||
/** @brief return the keyvalue for a given Keycode, shiftstate and caps of the currently used (underlying) keyboard layout. */
|
||||
KMX_DWORD KMX_get_KeyVal_From_KeyCode(GdkKeymap* keymap, guint keycode, ShiftState ss, int caps);
|
||||
|
||||
/** @brief return the keyvalue for a given Keycode and shiftstate of the currently used (underlying) keyboard layout. */
|
||||
KMX_DWORD KMX_get_KeyValUnderlying_From_KeyCodeUnderlying(GdkKeymap* keymap, guint keycode, int shiftState);
|
||||
|
||||
/** @brief return the keyvalue for a given Keycode and shiftstate of the currently used (underlying) keyboard layout. */
|
||||
KMX_DWORD KMX_get_KeyValUnderlying_From_KeyCodeUnderlying(GdkKeymap* keymap, guint keycode, KMX_DWORD shiftState, PKMX_WCHAR deadkey);
|
||||
|
||||
/** @brief return the keyvalue of a key of the the currently used (underlying) keyboard for a given keyvalue of the US keyboard */
|
||||
KMX_DWORD KMX_get_KeyValUnderlying_From_KeyValUS(vec_dword_3D& all_vector, KMX_DWORD kv_us);
|
||||
|
||||
/** @brief return the keycode of the currently used (underlying) keyboard for a given keycode of the US keyboard */
|
||||
KMX_DWORD KMX_get_KeyCodeUnderlying_From_KeyCodeUS(GdkKeymap* keymap, vec_dword_3D& all_vector, KMX_DWORD kc_us, ShiftState ss, int caps);
|
||||
|
||||
/** @brief return the keycode of the currently used (underlying) keyboard for a given virtual key of the US keyboard */
|
||||
KMX_DWORD KMX_get_KeyCodeUnderlying_From_VKUS(KMX_DWORD virtualKeyUS);
|
||||
|
||||
/** @brief return a virtual key of the US keyboard for a given keycode of the currently used (underlying) keyboard */
|
||||
KMX_DWORD KMX_get_VKUS_From_KeyCodeUnderlying(KMX_DWORD keycode);
|
||||
|
||||
/** @brief convert a codepoint to a u16string */
|
||||
std::u16string CodePointToU16String(unsigned int codepoint);
|
||||
|
||||
#endif /*KEYMAP_H*/
|
||||
|
|
|
|||
|
|
@ -1,88 +0,0 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#define snprintf _snprintf
|
||||
#define vsnprintf _vsnprintf
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#endif
|
||||
*/
|
||||
|
||||
#if defined(__LP64__) || defined(_LP64)
|
||||
/* 64-bit, g++ */
|
||||
#define KMX_64BIT
|
||||
#endif
|
||||
|
||||
#if defined(_WIN64) && !defined(USE_64)
|
||||
/* 64-bit, Windows */
|
||||
#define KMX_64BIT
|
||||
#endif
|
||||
|
||||
typedef uint32_t KMX_DWORD;
|
||||
typedef int32_t KMX_BOOL;
|
||||
typedef uint8_t KMX_BYTE;
|
||||
typedef uint16_t KMX_WORD;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
typedef char16_t km_kbp_cp;
|
||||
typedef char32_t km_kbp_usv;
|
||||
#else
|
||||
typedef uint16_t km_kbp_cp; // code point
|
||||
typedef uint32_t km_kbp_usv; // Unicode Scalar Value
|
||||
#endif
|
||||
|
||||
typedef km_kbp_cp KMX_WCHAR; // wc, 16-bit UNICODE character
|
||||
|
||||
typedef wchar_t WCHAR; // _S2 needs to be removed/ wchart-> char16
|
||||
typedef WCHAR KMX_WCHART; // _S2 needs to be removed/ wchart-> char16
|
||||
typedef KMX_WCHAR* PKMX_WCHAR; // _S2
|
||||
typedef wchar_t* PWSTR; // _S2 needs to be removed/ wchart-> char16
|
||||
typedef PWSTR PKMX_WCHART; // _S2 needs to be removed/ wchart-> char16
|
||||
|
||||
typedef wchar_t* LPKMX_WCHART; // _S2 needs to be removed/ wchart-> char16
|
||||
|
||||
typedef char* LPSTR; // _S2 needs to be removed?
|
||||
typedef LPSTR LPKMX_STR; // _S2 needs to be removed?
|
||||
|
||||
typedef uint8_t* LPBYTE; // _S2 needs to be removed/?
|
||||
typedef LPBYTE LPKMX_BYTE; // _S2 needs to be removed?
|
||||
|
||||
typedef uint8_t* PBYTE; // _S2 needs to be removed/?
|
||||
typedef PBYTE PKMX_BYTE; // _S2 needs to be removed?
|
||||
|
||||
// _S2 LPKEYBOARD ok to leave as is??
|
||||
|
||||
typedef char KMX_CHAR; // _S2 needs to be removed/?
|
||||
typedef char* PKMX_STR; // _S2 needs to be removed/?
|
||||
|
||||
typedef KMX_CHAR* PKMX_CHAR; // _S2 needs to be removed/?
|
||||
|
||||
typedef uint32_t KMX_UINT;
|
||||
|
||||
typedef KMX_BYTE* PKMX_BYTE;
|
||||
typedef KMX_WORD* PKMX_WORD;
|
||||
typedef KMX_DWORD* PKMX_DWORD;
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
// Macros and types to support char16_t vs wchar_t depending on project
|
||||
|
||||
#ifdef USE_CHAR16_T
|
||||
#define lpuch(x) u ## x
|
||||
typedef km_kbp_cp KMX_UCHAR;
|
||||
#else
|
||||
#define lpuch(x) L ## x
|
||||
typedef wchar_t KMX_UCHAR;
|
||||
#endif
|
||||
|
||||
typedef KMX_UCHAR* KMX_PUCHAR;
|
||||
|
|
@ -1,384 +0,0 @@
|
|||
/*
|
||||
Copyright: Copyright (C) 2003-2018 SIL International.
|
||||
Authors: mcdurdin
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <km_types.h>
|
||||
|
||||
#ifdef KMN_KBP
|
||||
// TODO: move this to a common namespace keyman::common::kmx_file or similar in the future
|
||||
namespace km {
|
||||
namespace kbp {
|
||||
namespace kmx {
|
||||
#endif
|
||||
|
||||
#define KMX_MAX_ALLOWED_FILE_SIZE (128 * 1024 * 1024) /* 128MB */
|
||||
/* */
|
||||
|
||||
#define KEYMAN_LAYOUT_DEFAULT 0x000005FE
|
||||
|
||||
#define KEYMANID_NONKEYMAN 0xFFFFFFFF
|
||||
#define KEYMANID_IGNORE 0xFFFFFFFE
|
||||
#define KEYMANID_INVALID 0xFFFFFFFD
|
||||
|
||||
/* Shift flags for hotkeys (version 1.0) */
|
||||
|
||||
#define SHIFTFLAG 0x2000
|
||||
#define CTRLFLAG 0x4000
|
||||
#define ALTFLAG 0x8000
|
||||
|
||||
/* Miscellaneous flags and defines */
|
||||
|
||||
#define MAXGROUPS 128
|
||||
|
||||
/* File version identifiers */
|
||||
|
||||
#define VERSION_30 0x00000300
|
||||
#define VERSION_31 0x00000301
|
||||
#define VERSION_32 0x00000302
|
||||
#define VERSION_40 0x00000400
|
||||
#define VERSION_50 0x00000500
|
||||
#define VERSION_501 0x00000501
|
||||
#define VERSION_60 0x00000600
|
||||
#define VERSION_70 0x00000700
|
||||
#define VERSION_80 0x00000800
|
||||
#define VERSION_90 0x00000900
|
||||
#define VERSION_100 0x00000A00
|
||||
#define VERSION_140 0x00000E00
|
||||
#define VERSION_150 0x00000F00
|
||||
|
||||
#define VERSION_160 0x00001000
|
||||
|
||||
#define VERSION_MIN VERSION_50
|
||||
#define VERSION_MAX VERSION_160
|
||||
|
||||
//
|
||||
// Backspace types
|
||||
//
|
||||
|
||||
#define BK_DEFAULT 0
|
||||
#define BK_DEADKEY 1
|
||||
|
||||
// Different begin types
|
||||
#define BEGIN_ANSI 0
|
||||
#define BEGIN_UNICODE 1
|
||||
#define BEGIN_NEWCONTEXT 2
|
||||
#define BEGIN_POSTKEYSTROKE 3
|
||||
|
||||
#define TSS_NONE 0
|
||||
#define TSS_BITMAP 1
|
||||
#define TSS_COPYRIGHT 2
|
||||
#define TSS_HOTKEY 3
|
||||
#define TSS_LANGUAGE 4
|
||||
#define TSS_LAYOUT 5
|
||||
#define TSS_MESSAGE 6
|
||||
#define TSS_NAME 7
|
||||
#define TSS_VERSION 8
|
||||
#define TSS_CAPSONONLY 9
|
||||
#define TSS_CAPSALWAYSOFF 10
|
||||
#define TSS_SHIFTFREESCAPS 11
|
||||
#define TSS_LANGUAGENAME 12
|
||||
|
||||
#define TSS_CALLDEFINITION 13
|
||||
#define TSS_CALLDEFINITION_LOADFAILED 14
|
||||
|
||||
#define TSS_ETHNOLOGUECODE 15
|
||||
|
||||
#define TSS_DEBUG_LINE 16
|
||||
|
||||
#define TSS_MNEMONIC 17
|
||||
|
||||
#define TSS_INCLUDECODES 18
|
||||
|
||||
#define TSS_OLDCHARPOSMATCHING 19
|
||||
|
||||
#define TSS_COMPILEDVERSION 20
|
||||
#define TSS_KEYMANCOPYRIGHT 21
|
||||
|
||||
#define TSS_CUSTOMKEYMANEDITION 22
|
||||
#define TSS_CUSTOMKEYMANEDITIONNAME 23
|
||||
|
||||
/* Keyman 7.0 system stores */
|
||||
|
||||
#define TSS__KEYMAN_60_MAX 23
|
||||
|
||||
#define TSS_VISUALKEYBOARD 24
|
||||
#define TSS_KMW_RTL 25
|
||||
#define TSS_KMW_HELPFILE 26
|
||||
#define TSS_KMW_HELPTEXT 27
|
||||
#define TSS_KMW_EMBEDJS 28
|
||||
|
||||
#define TSS_WINDOWSLANGUAGES 29
|
||||
|
||||
#define TSS__KEYMAN_70_MAX 29
|
||||
|
||||
/* Keyman 8.0 system stores */
|
||||
|
||||
#define TSS_COMPARISON 30
|
||||
|
||||
#define TSS__KEYMAN_80_MAX 30
|
||||
|
||||
/* Keyman 9.0 system stores */
|
||||
|
||||
#define TSS_PLATFORM 31
|
||||
#define TSS_BASELAYOUT 32
|
||||
#define TSS_LAYER 33
|
||||
|
||||
#define TSS_PLATFORM_NOMATCH 0x8001 // Reserved for internal use - after platform statement is run, set to either TSS_PLATFORM_NOMATCH or TSS_PLATFORM_MATCH
|
||||
#define TSS_PLATFORM_MATCH 0x8002 // Reserved for internal use - as the result will never change for the lifetime of the process.
|
||||
|
||||
#define TSS_VKDICTIONARY 34 // Dictionary of virtual key names for v9 dynamic layouts
|
||||
#define TSS_LAYOUTFILE 35 // Keyman 9 layer-based JSON OSK
|
||||
#define TSS_KEYBOARDVERSION 36 // &keyboardversion system store // I4140
|
||||
#define TSS_KMW_EMBEDCSS 37
|
||||
|
||||
#define TSS_TARGETS 38
|
||||
|
||||
#define TSS__KEYMAN_90_MAX 38
|
||||
|
||||
/* Keyman 14.0 system stores */
|
||||
|
||||
#define TSS_CASEDKEYS 39
|
||||
|
||||
#define TSS__KEYMAN_140_MAX 39
|
||||
|
||||
/* Keyman 15.0 system stores */
|
||||
|
||||
#define TSS_BEGIN_NEWCONTEXT 40
|
||||
#define TSS_BEGIN_POSTKEYSTROKE 41
|
||||
#define TSS_NEWLAYER 42
|
||||
#define TSS_OLDLAYER 43
|
||||
|
||||
#define TSS__KEYMAN_150_MAX 43
|
||||
|
||||
#define TSS__MAX 43
|
||||
|
||||
/* wm_keyman_control_internal message control codes */
|
||||
|
||||
#define KMCI_SELECTKEYBOARD 3 // I3933
|
||||
#define KMCI_SELECTKEYBOARD_TSF 4 // I3933
|
||||
#define KMCI_GETACTIVEKEYBOARD 5 // I3933
|
||||
#define KMCI_SETFOREGROUND 6 // I3933
|
||||
#define KMCI_SELECTKEYBOARD_BACKGROUND 7 // I4271
|
||||
#define KMCI_SELECTKEYBOARD_BACKGROUND_TSF 8 // I4271
|
||||
|
||||
#define FILEID_COMPILED 0x5354584B
|
||||
|
||||
#define SZMAX_LANGUAGENAME 80
|
||||
#define SZMAX_KEYBOARDNAME 80
|
||||
#define SZMAX_COPYRIGHT 256
|
||||
#define SZMAX_MESSAGE 1024
|
||||
|
||||
#define UC_SENTINEL 0xFFFF
|
||||
#define UC_SENTINEL_EXTENDEDEND 0x10 // was ((CODE_LASTCODE)+1)... what was I thinking?
|
||||
|
||||
#define U_UC_SENTINEL u"\uFFFF"
|
||||
|
||||
/*
|
||||
* VK__MAX defines the highest virtual key code defined in the system = 0xFF. Custom VK codes start at 256
|
||||
*/
|
||||
#define VK__MAX 255
|
||||
|
||||
#define CODE_ANY 0x01
|
||||
#define CODE_INDEX 0x02
|
||||
#define CODE_CONTEXT 0x03
|
||||
#define CODE_NUL 0x04
|
||||
#define CODE_USE 0x05
|
||||
#define CODE_RETURN 0x06
|
||||
#define CODE_BEEP 0x07
|
||||
#define CODE_DEADKEY 0x08
|
||||
// 0x09 = bkspace.-- we don't need to keep this separate though with UC_SENTINEL
|
||||
#define CODE_EXTENDED 0x0A
|
||||
//#define CODE_EXTENDEDEND 0x0B deprecated
|
||||
#define CODE_SWITCH 0x0C
|
||||
#define CODE_KEY 0x0D
|
||||
#define CODE_CLEARCONTEXT 0x0E
|
||||
#define CODE_CALL 0x0F
|
||||
// UC_SENTINEL_EXTENDEDEND 0x10
|
||||
#define CODE_CONTEXTEX 0x11
|
||||
|
||||
#define CODE_NOTANY 0x12
|
||||
|
||||
#define CODE_KEYMAN70_LASTCODE 0x12
|
||||
|
||||
#define CODE_SETOPT 0x13
|
||||
#define CODE_IFOPT 0x14
|
||||
#define CODE_SAVEOPT 0x15
|
||||
#define CODE_RESETOPT 0x16
|
||||
|
||||
#define CODE_KEYMAN80_LASTCODE 0x16
|
||||
|
||||
/* Keyman 9.0 codes */
|
||||
|
||||
#define CODE_IFSYSTEMSTORE 0x17
|
||||
#define CODE_SETSYSTEMSTORE 0x18
|
||||
|
||||
#define CODE_LASTCODE 0x18
|
||||
|
||||
#define U_CODE_ANY u"\u0001"
|
||||
#define U_CODE_INDEX u"\u0002"
|
||||
#define U_CODE_CONTEXT u"\u0003"
|
||||
#define U_CODE_NUL u"\u0004"
|
||||
#define U_CODE_USE u"\u0005"
|
||||
#define U_CODE_RETURN u"\u0006"
|
||||
#define U_CODE_BEEP u"\u0007"
|
||||
#define U_CODE_DEADKEY u"\u0008"
|
||||
#define U_CODE_EXTENDED u"\u000A"
|
||||
#define U_CODE_SWITCH u"\u000C"
|
||||
#define U_CODE_CLEARCONTEXT u"\u000E"
|
||||
#define U_CODE_CALL u"\u000F"
|
||||
#define U_CODE_EXTENDEDEND u"\u0010"
|
||||
#define U_CODE_CONTEXTEX u"\u0011"
|
||||
#define U_CODE_NOTANY u"\u0012"
|
||||
#define U_CODE_SETOPT u"\u0013"
|
||||
#define U_CODE_IFOPT u"\u0014"
|
||||
#define U_CODE_SAVEOPT u"\u0015"
|
||||
#define U_CODE_RESETOPT u"\u0016"
|
||||
#define U_CODE_IFSYSTEMSTORE u"\u0017"
|
||||
#define U_CODE_SETSYSTEMSTORE u"\u0018"
|
||||
|
||||
#define C_CODE_ANY(store) U_UC_SENTINEL U_CODE_ANY store
|
||||
#define C_CODE_INDEX(val1, val2) U_UC_SENTINEL U_CODE_INDEX val1 val2
|
||||
#define C_CODE_CONTEXT() U_UC_SENTINEL U_CODE_CONTEXT
|
||||
#define C_CODE_NUL() U_UC_SENTINEL U_CODE_NUL
|
||||
#define C_CODE_USE(val) U_UC_SENTINEL U_CODE_USE val
|
||||
#define C_CODE_RETURN() U_UC_SENTINEL U_CODE_RETURN
|
||||
#define C_CODE_BEEP() U_UC_SENTINEL U_CODE_BEEP
|
||||
#define C_CODE_DEADKEY(deadkey) U_UC_SENTINEL U_CODE_DEADKEY deadkey
|
||||
#define C_CODE_EXTENDED(varargs) U_UC_SENTINEL U_CODE_EXTENDED varargs
|
||||
#define C_CODE_SWITCH(val) U_UC_SENTINEL U_CODE_SWITCH val
|
||||
#define C_CODE_CLEARCONTEXT() U_UC_SENTINEL U_CODE_CLEARCONTEXT
|
||||
#define C_CODE_CALL(val) U_UC_SENTINEL U_CODE_CALL val
|
||||
#define C_CODE_CONTEXTEX(val) U_UC_SENTINEL U_CODE_CONTEXTEX val
|
||||
#define C_CODE_NOTANY(val) U_UC_SENTINEL U_CODE_NOTANY val
|
||||
#define C_CODE_SETOPT(val1, val2) U_UC_SENTINEL U_CODE_SETOPT val1 val2
|
||||
#define C_CODE_IFOPT(opt, val1, val2) U_UC_SENTINEL U_CODE_IFOPT opt val1 val2
|
||||
#define C_CODE_SAVEOPT(opt) U_UC_SENTINEL U_CODE_SAVEOPT opt
|
||||
#define C_CODE_RESETOPT(opt) U_UC_SENTINEL U_CODE_RESETOPT opt
|
||||
#define C_CODE_IFSYSTEMSTORE(store, val1, val2) U_UC_SENTINEL U_CODE_IFSYSTEMSTORE store val1 val2
|
||||
#define C_CODE_SETSYSTEMSTORE(store, val) U_UC_SENTINEL U_CODE_SETSYSTEMSTORE store val
|
||||
|
||||
#define KF_SHIFTFREESCAPS 0x0001
|
||||
#define KF_CAPSONONLY 0x0002
|
||||
#define KF_CAPSALWAYSOFF 0x0004
|
||||
#define KF_LOGICALLAYOUT 0x0008
|
||||
#define KF_AUTOMATICVERSION 0x0010
|
||||
|
||||
// 16.0: Support for LDML Keyboards in KMXPlus file format
|
||||
#define KF_KMXPLUS 0x0020
|
||||
|
||||
#define HK_ALT 0x00010000
|
||||
#define HK_CTRL 0x00020000
|
||||
#define HK_SHIFT 0x00040000
|
||||
|
||||
#define LCTRLFLAG 0x0001 // Left Control flag
|
||||
#define RCTRLFLAG 0x0002 // Right Control flag
|
||||
#define LALTFLAG 0x0004 // Left Alt flag
|
||||
#define RALTFLAG 0x0008 // Right Alt flag
|
||||
#define K_SHIFTFLAG 0x0010 // Either shift flag
|
||||
#define K_CTRLFLAG 0x0020 // Either ctrl flag
|
||||
#define K_ALTFLAG 0x0040 // Either alt flag
|
||||
//#define K_METAFLAG 0x0080 // Either Meta-key flag (tentative). Not usable in keyboard rules;
|
||||
// Used internally (currently, only by KMW) to ensure Meta-key
|
||||
// shortcuts safely bypass rules
|
||||
// Meta key = Command key on macOS, Windows key on Windows
|
||||
#define CAPITALFLAG 0x0100 // Caps lock on
|
||||
#define NOTCAPITALFLAG 0x0200 // Caps lock NOT on
|
||||
#define NUMLOCKFLAG 0x0400 // Num lock on
|
||||
#define NOTNUMLOCKFLAG 0x0800 // Num lock NOT on
|
||||
#define SCROLLFLAG 0x1000 // Scroll lock on
|
||||
#define NOTSCROLLFLAG 0x2000 // Scroll lock NOT on
|
||||
#define ISVIRTUALKEY 0x4000 // It is a Virtual Key Sequence
|
||||
#define VIRTUALCHARKEY 0x8000 // Keyman 6.0: Virtual Key Cap Sequence NOT YET
|
||||
|
||||
#define K_MODIFIERFLAG 0x007F
|
||||
#define K_NOTMODIFIERFLAG 0xFF00 // I4548
|
||||
|
||||
struct COMP_STORE {
|
||||
KMX_DWORD dwSystemID;
|
||||
KMX_DWORD dpName;
|
||||
KMX_DWORD dpString;
|
||||
};
|
||||
|
||||
struct COMP_KEY {
|
||||
KMX_WORD Key;
|
||||
KMX_WORD _reserved;
|
||||
KMX_DWORD Line;
|
||||
KMX_DWORD ShiftFlags;
|
||||
KMX_DWORD dpOutput;
|
||||
KMX_DWORD dpContext;
|
||||
};
|
||||
|
||||
struct COMP_GROUP {
|
||||
KMX_DWORD dpName;
|
||||
KMX_DWORD dpKeyArray; // [LPKEY] address of first item in key array
|
||||
KMX_DWORD dpMatch;
|
||||
KMX_DWORD dpNoMatch;
|
||||
KMX_DWORD cxKeyArray; // in array entries
|
||||
KMX_BOOL fUsingKeys; // group(xx) [using keys] <-- specified or not
|
||||
};
|
||||
|
||||
struct COMP_KEYBOARD {
|
||||
KMX_DWORD dwIdentifier; // 0000 Keyman compiled keyboard id
|
||||
|
||||
KMX_DWORD dwFileVersion; // 0004 Version of the file - Keyman 4.0 is 0x0400
|
||||
|
||||
KMX_DWORD dwCheckSum; // 0008 As stored in keyboard. DEPRECATED as of 16.0
|
||||
KMX_DWORD KeyboardID; // 000C as stored in HKEY_LOCAL_MACHINE//system//currentcontrolset//control//keyboard layouts
|
||||
KMX_DWORD IsRegistered; // 0010
|
||||
KMX_DWORD version; // 0014 keyboard version
|
||||
|
||||
KMX_DWORD cxStoreArray; // 0018 in array entries
|
||||
KMX_DWORD cxGroupArray; // 001C in array entries
|
||||
|
||||
KMX_DWORD dpStoreArray; // 0020 [LPSTORE] address of first item in store array
|
||||
KMX_DWORD dpGroupArray; // 0024 [LPGROUP] address of first item in group array
|
||||
|
||||
KMX_DWORD StartGroup[2]; // 0028 index of starting groups [2 of them]
|
||||
|
||||
KMX_DWORD dwFlags; // 0030 Flags for the keyboard file
|
||||
|
||||
KMX_DWORD dwHotKey; // 0034 standard windows hotkey (hiword=shift/ctrl/alt stuff, loword=vkey)
|
||||
|
||||
KMX_DWORD dpBitmapOffset; // 0038 offset of the bitmaps in the file
|
||||
KMX_DWORD dwBitmapSize; // 003C size in bytes of the bitmaps
|
||||
};
|
||||
|
||||
struct COMP_KEYBOARD_KMXPLUSINFO {
|
||||
KMX_DWORD dpKMXPlus; // 0040 offset of KMXPlus data, <sect> header is first
|
||||
KMX_DWORD dwKMXPlusSize; // 0044 size in bytes of entire KMXPlus data
|
||||
};
|
||||
|
||||
/**
|
||||
* Only valid if comp_keyboard.dwFlags&KF_KMXPLUS
|
||||
*/
|
||||
struct COMP_KEYBOARD_EX {
|
||||
COMP_KEYBOARD header; // 0000 see COMP_KEYBOARD
|
||||
COMP_KEYBOARD_KMXPLUSINFO kmxplus; // 0040 see COMP_KEYBOARD_EXTRA
|
||||
};
|
||||
|
||||
typedef COMP_KEYBOARD *PCOMP_KEYBOARD;
|
||||
typedef COMP_STORE *PCOMP_STORE;
|
||||
typedef COMP_KEY *PCOMP_KEY;
|
||||
typedef COMP_GROUP *PCOMP_GROUP;
|
||||
|
||||
extern const int CODE__SIZE[];
|
||||
#define CODE__SIZE_MAX 5
|
||||
|
||||
#define KEYBOARDFILEHEADER_SIZE 64
|
||||
#define KEYBOARDFILESTORE_SIZE 12
|
||||
#define KEYBOARDFILEGROUP_SIZE 24
|
||||
#define KEYBOARDFILEKEY_SIZE 20
|
||||
|
||||
static_assert(sizeof(COMP_STORE) == KEYBOARDFILESTORE_SIZE, "COMP_STORE must be KEYBOARDFILESTORE_SIZE bytes");
|
||||
static_assert(sizeof(COMP_KEY) == KEYBOARDFILEKEY_SIZE, "COMP_KEY must be KEYBOARDFILEKEY_SIZE bytes");
|
||||
static_assert(sizeof(COMP_GROUP) == KEYBOARDFILEGROUP_SIZE, "COMP_GROUP must be KEYBOARDFILEGROUP_SIZE bytes");
|
||||
static_assert(sizeof(COMP_KEYBOARD) == KEYBOARDFILEHEADER_SIZE, "COMP_KEYBOARD must be KEYBOARDFILEHEADER_SIZE bytes");
|
||||
|
||||
#ifdef KMN_KBP
|
||||
} // namespace kmx
|
||||
} // namespace kbp
|
||||
} // namespace km
|
||||
#endif
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
#include <gdk/gdk.h>
|
||||
|
||||
|
||||
static void PrintKeymapForCode(GdkKeymap *keymap, guint keycode)
|
||||
{
|
||||
GdkKeymapKey *maps;
|
||||
guint *keyvals;
|
||||
gint count;
|
||||
|
||||
if (!gdk_keymap_get_entries_for_keycode(keymap, keycode, &maps, &keyvals, &count))
|
||||
return;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (maps[i].level > 0 || maps[i].group > 1)
|
||||
continue;
|
||||
printf(" i=%d, keycode=%d, keyval=%d (%c), level=%d, group=%d\n", i, maps[i].keycode, keyvals[i], keyvals[i], maps[i].level, maps[i].group);
|
||||
}
|
||||
|
||||
g_free(keyvals);
|
||||
g_free(maps);
|
||||
}
|
||||
|
||||
int main(gint argc, gchar **argv)
|
||||
{
|
||||
gdk_init(&argc, &argv);
|
||||
GdkDisplay *display = gdk_display_get_default();
|
||||
if (!display) {
|
||||
printf("ERROR: can't get display\n");
|
||||
return 1;
|
||||
}
|
||||
GdkKeymap *keymap = gdk_keymap_get_for_display(display);
|
||||
if (!keymap) {
|
||||
printf("ERROR: Can't get keymap\n");
|
||||
gdk_display_close(display);
|
||||
return 2;
|
||||
}
|
||||
|
||||
for (int keycode = 10; keycode <= 61; keycode++) {
|
||||
printf("-------------------\n");
|
||||
printf("Keycode %d:\n", keycode);
|
||||
PrintKeymapForCode(keymap, keycode);
|
||||
}
|
||||
|
||||
gdk_display_close(display);
|
||||
|
||||
return 0;
|
||||
}
|
||||
669
linux/mcompile/keymap/mc_import_rules.cpp
Normal file
669
linux/mcompile/keymap/mc_import_rules.cpp
Normal file
|
|
@ -0,0 +1,669 @@
|
|||
/*
|
||||
* Keyman is copyright (C) 2004 - 2024 SIL International. MIT License.
|
||||
*
|
||||
* Mnemonic layout support for Linux
|
||||
*/
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include "mc_kmxfile.h"
|
||||
#include "keymap.h"
|
||||
|
||||
const int KMX_ShiftStateMap[] = {
|
||||
ISVIRTUALKEY,
|
||||
ISVIRTUALKEY | K_SHIFTFLAG,
|
||||
ISVIRTUALKEY | K_CTRLFLAG,
|
||||
ISVIRTUALKEY | K_SHIFTFLAG | K_CTRLFLAG,
|
||||
0,
|
||||
0,
|
||||
ISVIRTUALKEY | RALTFLAG,
|
||||
ISVIRTUALKEY | RALTFLAG | K_SHIFTFLAG,
|
||||
0,
|
||||
0};
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param deadCharacter a deadkey
|
||||
*/
|
||||
DeadKey::DeadKey(KMX_WCHAR deadCharacter) {
|
||||
this->m_deadchar = deadCharacter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief return dead character
|
||||
* @return deadkey character
|
||||
*/
|
||||
KMX_WCHAR DeadKey::KMX_DeadCharacter() {
|
||||
return this->m_deadchar;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set Deadkey with values
|
||||
* @param baseCharacter the base character
|
||||
* @param combinedCharacter the combined character
|
||||
*/
|
||||
void DeadKey::KMX_AddDeadKeyRow(KMX_WCHAR baseCharacter, KMX_WCHAR combinedCharacter) {
|
||||
this->m_rgbasechar.push_back(baseCharacter);
|
||||
this->m_rgcombchar.push_back(combinedCharacter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief check if character exists in DeadKey
|
||||
* @param baseCharacter a character to be found
|
||||
* @return true if found;
|
||||
* false if not found
|
||||
*/
|
||||
bool DeadKey::KMX_ContainsBaseCharacter(KMX_WCHAR baseCharacter) {
|
||||
std::vector<KMX_WCHAR>::iterator it;
|
||||
for (it = this->m_rgbasechar.begin(); it < m_rgbasechar.end(); it++) {
|
||||
if (*it == baseCharacter) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Find a keyvalue for given keycode, shiftstate and caps. A function similar to Window`s ToUnicodeEx() function.
|
||||
*
|
||||
* Contrary to what the function name might suggest, the function KMX_ToUnicodeEx does not process surrogate pairs.
|
||||
* This is because it is used in mcompile only which only deals with latin scripts.
|
||||
* In case this function should be used for surrogate pairs, they will be ignored and a message will be printed out
|
||||
*
|
||||
* @param keycode a key of the currently used keyboard Layout
|
||||
* @param pwszBuff Buffer to store resulting character
|
||||
* @param ss a shiftstate of the currently used keyboard Layout
|
||||
* @param caps state of the caps key of the currently used keyboard Layout
|
||||
* @param keymap the currently used (underlying)keyboard Layout
|
||||
* @return -1 if a deadkey was found;
|
||||
* 0 if no translation is available;
|
||||
* +1 if character was found and written to pwszBuff
|
||||
*/
|
||||
int KMX_ToUnicodeEx(guint keycode, PKMX_WCHAR pwszBuff, ShiftState rgkey_ss, int caps, GdkKeymap* keymap) {
|
||||
|
||||
GdkKeymapKey* maps;
|
||||
guint* keyvals;
|
||||
gint count;
|
||||
|
||||
if (!gdk_keymap_get_entries_for_keycode(keymap, keycode, &maps, &keyvals, &count))
|
||||
return 0;
|
||||
|
||||
if (!(ensureValidInputForKeyboardTranslation(convert_rgkey_Shiftstate_to_LinuxShiftstate(rgkey_ss), keycode))){
|
||||
g_free(keyvals);
|
||||
g_free(maps);
|
||||
return 0;
|
||||
}
|
||||
|
||||
KMX_DWORD keyVal = (KMX_DWORD)KMX_get_KeyVal_From_KeyCode(keymap, keycode, rgkey_ss, caps);
|
||||
std::u16string str = convert_DeadkeyValues_To_U16str(keyVal);
|
||||
KMX_WCHAR firstchar = *(PKMX_WCHAR)str.c_str();
|
||||
|
||||
if ((firstchar >= 0xD800) &&(firstchar <= 0xDFFF)) {
|
||||
wprintf(L"Surrogate pair found that is not processed in KMX_ToUnicodeEx\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
pwszBuff[0] = firstchar;
|
||||
|
||||
g_free(keyvals);
|
||||
g_free(maps);
|
||||
|
||||
if (u16len(pwszBuff) < 1)
|
||||
return 0;
|
||||
|
||||
if ((keyVal >= deadkey_min) && (keyVal <= deadkey_max)) // deadkeys
|
||||
return -1;
|
||||
else if (gdk_keyval_to_unicode(keyVal) == 0) // NO UNICODE
|
||||
return 0;
|
||||
else // usable char
|
||||
return 1;
|
||||
}
|
||||
|
||||
KMX_WCHAR KMX_DeadKeyMap(int index, std::vector<DeadKey*>* deadkeys, int deadkeyBase, std::vector<KMX_DeadkeyMapping>* deadkeyMappings) { // I4327 // I4353
|
||||
for (size_t i = 0; i < deadkeyMappings->size(); i++) {
|
||||
if ((*deadkeyMappings)[i].deadkey == index) {
|
||||
return (*deadkeyMappings)[i].dkid;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < deadkeys->size(); i++) {
|
||||
if ((*deadkeys)[i]->KMX_DeadCharacter() == index) {
|
||||
return (KMX_WCHAR)(deadkeyBase + i);
|
||||
}
|
||||
}
|
||||
return 0xFFFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Base class for dealing with rgkey
|
||||
*/
|
||||
class KMX_VirtualKey {
|
||||
private:
|
||||
KMX_DWORD m_vk;
|
||||
KMX_DWORD m_sc;
|
||||
bool m_rgfDeadKey[10][2];
|
||||
std::u16string m_rgss[10][2];
|
||||
|
||||
public:
|
||||
KMX_VirtualKey(KMX_DWORD scanCode) {
|
||||
this->m_vk = KMX_get_VKUS_From_KeyCodeUnderlying(scanCode);
|
||||
this->m_sc = scanCode;
|
||||
memset(this->m_rgfDeadKey, 0, sizeof(this->m_rgfDeadKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief return member variable virtual key
|
||||
*/
|
||||
KMX_DWORD VK() {
|
||||
return this->m_vk;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief return member variable scancode
|
||||
*/
|
||||
KMX_DWORD SC() {
|
||||
return this->m_sc;
|
||||
}
|
||||
|
||||
std::u16string KMX_GetShiftState(ShiftState shiftState, bool capsLock) {
|
||||
return this->m_rgss[(KMX_DWORD)shiftState][(capsLock ? 1 : 0)];
|
||||
}
|
||||
|
||||
void KMX_SetShiftState(ShiftState shiftState, std::u16string value, bool isDeadKey, bool capsLock) {
|
||||
this->m_rgfDeadKey[(KMX_DWORD)shiftState][(capsLock ? 1 : 0)] = isDeadKey;
|
||||
this->m_rgss[(KMX_DWORD)shiftState][(capsLock ? 1 : 0)] = value;
|
||||
}
|
||||
|
||||
bool KMX_IsSGCAPS() {
|
||||
std::u16string stBase = this->KMX_GetShiftState(Base, false);
|
||||
std::u16string stShift = this->KMX_GetShiftState(Shft, false);
|
||||
std::u16string stCaps = this->KMX_GetShiftState(Base, true);
|
||||
std::u16string stShiftCaps = this->KMX_GetShiftState(Shft, true);
|
||||
return (
|
||||
((stCaps.size() > 0) &&
|
||||
(stBase.compare(stCaps) != 0) &&
|
||||
(stShift.compare(stCaps) != 0)) ||
|
||||
((stShiftCaps.size() > 0) &&
|
||||
(stBase.compare(stShiftCaps) != 0) &&
|
||||
(stShift.compare(stShiftCaps) != 0)));
|
||||
}
|
||||
|
||||
bool KMX_IsCapsEqualToShift() {
|
||||
std::u16string stBase = this->KMX_GetShiftState(Base, false);
|
||||
std::u16string stShift = this->KMX_GetShiftState(Shft, false);
|
||||
std::u16string stCaps = this->KMX_GetShiftState(Base, true);
|
||||
return (
|
||||
(stBase.size() > 0) &&
|
||||
(stShift.size() > 0) &&
|
||||
(stBase.compare(stShift) != 0) &&
|
||||
(stShift.compare(stCaps) == 0));
|
||||
}
|
||||
|
||||
bool KMX_IsAltGrCapsEqualToAltGrShift() {
|
||||
std::u16string stBase = this->KMX_GetShiftState(MenuCtrl, false);
|
||||
std::u16string stShift = this->KMX_GetShiftState(ShftMenuCtrl, false);
|
||||
std::u16string stCaps = this->KMX_GetShiftState(MenuCtrl, true);
|
||||
return (
|
||||
(stBase.size() > 0) &&
|
||||
(stShift.size() > 0) &&
|
||||
(stBase.compare(stShift) != 0) &&
|
||||
(stShift.compare(stCaps) == 0));
|
||||
}
|
||||
|
||||
bool KMX_IsXxxxGrCapsEqualToXxxxShift() {
|
||||
std::u16string stBase = this->KMX_GetShiftState(Xxxx, false);
|
||||
std::u16string stShift = this->KMX_GetShiftState(ShftXxxx, false);
|
||||
std::u16string stCaps = this->KMX_GetShiftState(Xxxx, true);
|
||||
return (
|
||||
(stBase.size() > 0) &&
|
||||
(stShift.size() > 0) &&
|
||||
(stBase.compare(stShift) != 0) &&
|
||||
(stShift.compare(stCaps) == 0));
|
||||
}
|
||||
|
||||
bool KMX_IsEmpty() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int j = 0; j <= 1; j++) {
|
||||
if (this->KMX_GetShiftState((ShiftState)i, (j == 1)).size() > 0) {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @brief check if we use only keys used in mcompile
|
||||
*/
|
||||
bool KMX_IsKeymanUsedKey() {
|
||||
return (this->m_vk >= 0x20 && this->m_vk <= 0x5F) || (this->m_vk >= 0x88);
|
||||
}
|
||||
|
||||
KMX_DWORD KMX_GetShiftStateValue(int capslock, int caps, ShiftState ss) {
|
||||
return KMX_ShiftStateMap[(int)ss] | (capslock ? (caps ? CAPITALFLAG : NOTCAPITALFLAG) : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief count the number of keys
|
||||
*/
|
||||
int KMX_GetKeyCount(int MaxShiftState) {
|
||||
int nkeys = 0;
|
||||
|
||||
// Get the CAPSLOCK value
|
||||
for (int ss = 0; ss <= MaxShiftState; ss++) {
|
||||
if (ss == Menu || ss == ShftMenu) {
|
||||
// Alt and Shift+Alt don't work, so skip them
|
||||
continue;
|
||||
}
|
||||
for (int caps = 0; caps <= 1; caps++) {
|
||||
std::u16string st = this->KMX_GetShiftState((ShiftState)ss, (caps == 1));
|
||||
// ctrl and shift+ctrl will be skipped since rgkey has no entries in m_rgss[2] m_rgss[3]
|
||||
if (st.size() == 0) {
|
||||
// No character assigned here
|
||||
} else if (this->m_rgfDeadKey[(int)ss][caps]) {
|
||||
// It's a dead key, append an @ sign.
|
||||
nkeys++;
|
||||
} else {
|
||||
bool isvalid = true;
|
||||
for (size_t ich = 0; ich < st.size(); ich++) {
|
||||
if (st[ich] < 0x20 || st[ich] == 0x7F) {
|
||||
isvalid = false;
|
||||
printf("invalid for: %i\n", st[ich]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isvalid) {
|
||||
nkeys++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nkeys;
|
||||
}
|
||||
|
||||
bool KMX_LayoutRow(int MaxShiftState, LPKMX_KEY key, std::vector<DeadKey*>* deadkeys, int deadkeyBase, bool bDeadkeyConversion, vec_dword_3D& all_vector, GdkKeymap* keymap) { // I4552
|
||||
// Get the CAPSLOCK value
|
||||
/*int capslock =
|
||||
(this->KMX_IsCapsEqualToShift() ? 1 : 0) |
|
||||
(this->KMX_IsSGCAPS() ? 2 : 0) |
|
||||
(this->KMX_IsAltGrCapsEqualToAltGrShift() ? 4 : 0) |
|
||||
(this->KMX_IsXxxxGrCapsEqualToXxxxShift() ? 8 : 0);*/
|
||||
|
||||
int capslock = 1; // we do not use the equation to obtain capslock. On Linux we set capslock = 1
|
||||
|
||||
for (int ss = 0; ss <= MaxShiftState; ss++) {
|
||||
if (ss == Menu || ss == ShftMenu) {
|
||||
// Alt and Shift+Alt don't work, so skip them
|
||||
continue;
|
||||
}
|
||||
for (int caps = 0; caps <= 1; caps++) {
|
||||
std::u16string st = this->KMX_GetShiftState((ShiftState)ss, (caps == 1));
|
||||
|
||||
PKMX_WCHAR p;
|
||||
|
||||
if (st.size() == 0) {
|
||||
// No character assigned here
|
||||
} else if (this->m_rgfDeadKey[(int)ss][caps]) {
|
||||
// It's a dead key, append an @ sign.
|
||||
key->dpContext = new KMX_WCHAR[1];
|
||||
*key->dpContext = 0;
|
||||
|
||||
key->ShiftFlags = this->KMX_GetShiftStateValue(capslock, caps, (ShiftState)ss);
|
||||
// we already use VK_US so no need to convert it as we do on Windows
|
||||
key->Key = this->VK();
|
||||
key->Line = 0;
|
||||
|
||||
if (bDeadkeyConversion) { // I4552
|
||||
p = key->dpOutput = new KMX_WCHAR[2];
|
||||
*p++ = st[0];
|
||||
*p = 0;
|
||||
} else {
|
||||
p = key->dpOutput = new KMX_WCHAR[4];
|
||||
*p++ = UC_SENTINEL;
|
||||
*p++ = CODE_DEADKEY;
|
||||
*p++ = KMX_DeadKeyMap(st[0], deadkeys, deadkeyBase, &KMX_FDeadkeys); // I4353
|
||||
*p = 0;
|
||||
}
|
||||
key++;
|
||||
} else {
|
||||
bool isvalid = true;
|
||||
for (size_t ich = 0; ich < st.size(); ich++) {
|
||||
if (st[ich] < 0x20 || st[ich] == 0x7F) {
|
||||
isvalid = false;
|
||||
printf("invalid 16 for: %i\n", st[ich]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isvalid) {
|
||||
/*
|
||||
* this is different to mcompile Windows !!!!
|
||||
* this->m_sc stores SC-US = SCUnderlying
|
||||
* this->m_vk stores VK-US ( not VK underlying !!)
|
||||
* key->Key stores VK-US ( not VK underlying !!)
|
||||
* key->dpOutput stores character Underlying
|
||||
*/
|
||||
KMX_DWORD sc_underlying = KMX_get_KeyCodeUnderlying_From_KeyCodeUS(keymap, all_vector, this->SC(), (ShiftState)ss, caps);
|
||||
|
||||
key->Key = KMX_get_VKUS_From_KeyCodeUnderlying(sc_underlying);
|
||||
|
||||
key->Line = 0;
|
||||
key->ShiftFlags = this->KMX_GetShiftStateValue(capslock, caps, (ShiftState)ss);
|
||||
|
||||
key->dpContext = new KMX_WCHAR;
|
||||
*key->dpContext = 0;
|
||||
p = key->dpOutput = new KMX_WCHAR[st.size() + 1];
|
||||
for (size_t ich = 0; ich < st.size(); ich++) {
|
||||
*p++ = st[ich];
|
||||
}
|
||||
*p = 0;
|
||||
key++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Base class for KMX_loader
|
||||
*/
|
||||
class KMX_Loader {
|
||||
private:
|
||||
KMX_BYTE lpKeyStateNull[256];
|
||||
KMX_DWORD m_XxxxVk;
|
||||
|
||||
public:
|
||||
KMX_Loader() {
|
||||
m_XxxxVk = 0;
|
||||
memset(lpKeyStateNull, 0, sizeof(lpKeyStateNull));
|
||||
}
|
||||
|
||||
KMX_DWORD Get_XxxxVk() {
|
||||
return m_XxxxVk;
|
||||
}
|
||||
|
||||
void Set_XxxxVk(KMX_DWORD value) {
|
||||
m_XxxxVk = value;
|
||||
}
|
||||
|
||||
ShiftState KMX_MaxShiftState() {
|
||||
return (Get_XxxxVk() == 0 ? ShftMenuCtrl : ShftXxxx);
|
||||
}
|
||||
|
||||
bool KMX_IsControlChar(char16_t ch) {
|
||||
return (ch < 0x0020) || (ch >= 0x007F && ch <= 0x009F);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief find the maximum index of a deadkey
|
||||
@param p pointer to deadkey
|
||||
* @return index of deadkey
|
||||
*/
|
||||
int KMX_GetMaxDeadkeyIndex(KMX_WCHAR* p) {
|
||||
int n = 0;
|
||||
while (p && *p) {
|
||||
if (*p == UC_SENTINEL && *(p + 1) == CODE_DEADKEY)
|
||||
n = std::max(n, (int)*(p + 2));
|
||||
p = KMX_incxstr(p);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Collect the key data, translate it to kmx and append to the existing keyboard
|
||||
* It is important to understand that this function has different sorting order in rgkey compared to mcompile-windows!
|
||||
* On Windows the values of rgkey are sorted according to the VK of the underlying keyboard
|
||||
* On Linux the values of rgkey are sorted according to the VK of the the US keyboard
|
||||
* Since Linux Keyboards do not use a VK mcompile uses the VK of the the US keyboard because
|
||||
* these are available in mcompile through USVirtualKeyToScanCode/ScanCodeToUSVirtualKey and an offset of 8
|
||||
* @param kp pointer to keyboard
|
||||
* @param all_vector vector that holds the data of the US keyboard and the currently used (underlying) keyboard
|
||||
* @param keymap the currently used (underlying)keyboard Layout
|
||||
* @param FDeadkeys vector of all deadkeys for the currently used (underlying)keyboard Layout
|
||||
* @param bDeadkeyConversion 1 to convert a deadkey to a character; 0 no conversion
|
||||
* @return true in case of success
|
||||
*/
|
||||
bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap** keymap, std::vector<KMX_DeadkeyMapping>* FDeadkeys, KMX_BOOL bDeadkeyConversion) { // I4353 // I4552
|
||||
KMX_Loader loader;
|
||||
|
||||
std::vector<KMX_VirtualKey*> rgKey; //= new VirtualKey[256];
|
||||
std::vector<DeadKey*> alDead;
|
||||
std::vector<DeadKey*> alDead_byBasechar = create_deadkeys_by_basechar();
|
||||
|
||||
rgKey.resize(256);
|
||||
|
||||
// Scroll through the Scan Code (SC) values and get the valid Virtual Key (VK)
|
||||
// values in it. Then, store the SC in each valid VK so it can act as both a
|
||||
// flag that the VK is valid, and it can store the SC value.
|
||||
|
||||
// Windows and Linux Keycodes start with 1; Mac keycodes start with 0
|
||||
for (KMX_DWORD sc = 0x01; sc <= 0x7f; sc++) {
|
||||
/* HERE IS A BIG DIFFERENCE COMPARED TO MCOMPILE FOR WINDOWS:
|
||||
* mcompile on Windows fills rgkey.m_vk with the VK of the Underlying keyboard
|
||||
* mcompile for Linux fills rgkey.m_vk with the VK of the US keyboard
|
||||
* this results in a different sorting order in rgkey[] !
|
||||
|
||||
* Linux cannot get a VK for the underling Keyboard since this does not exist
|
||||
* Linux can only get a VK for the US Keyboard (by using USVirtualKeyToScanCode/ScanCodeToUSVirtualKey)
|
||||
* therefore we use VK_US in rgkey[ ] which we get from all_vector
|
||||
*/
|
||||
KMX_VirtualKey* key = new KMX_VirtualKey(sc);
|
||||
|
||||
if ((key->VK() != 0)) {
|
||||
rgKey[key->VK()] = key;
|
||||
} else {
|
||||
delete key;
|
||||
}
|
||||
}
|
||||
|
||||
// in this part we skip shiftstates 4, 5, 8, 9
|
||||
for (KMX_DWORD iKey = 0; iKey < rgKey.size(); iKey++) {
|
||||
if (rgKey[iKey] != NULL) {
|
||||
KMX_WCHAR sbBuffer[256]; // Scratchpad we use many places
|
||||
for (ShiftState ss = Base; ss <= loader.KMX_MaxShiftState(); ss = (ShiftState)((int)ss + 1)) {
|
||||
if (ss == Menu || ss == ShftMenu) {
|
||||
// Alt and Shift+Alt don't work, so skip them (ss 4+5)
|
||||
continue;
|
||||
}
|
||||
|
||||
KMX_DWORD kc_underlying = KMX_get_KeyCodeUnderlying_From_VKUS(iKey);
|
||||
|
||||
for (int caps = 0; caps <= 1; caps++) {
|
||||
int rc = KMX_ToUnicodeEx(kc_underlying, sbBuffer, ss, caps, *keymap);
|
||||
|
||||
if (rc > 0) {
|
||||
if (*sbBuffer == 0) {
|
||||
rgKey[iKey]->KMX_SetShiftState(ss, u"", false, (caps)); // different to windows since behavior on Linux is different (see above)
|
||||
} else {
|
||||
if ((ss == Ctrl || ss == ShftCtrl)) {
|
||||
continue;
|
||||
}
|
||||
sbBuffer[rc] = 0;
|
||||
rgKey[iKey]->KMX_SetShiftState(ss, sbBuffer, false, (caps)); // different to windows since behavior on Linux is different (see above)
|
||||
}
|
||||
} else if (rc < 0) {
|
||||
sbBuffer[2] = 0;
|
||||
rgKey[iKey]->KMX_SetShiftState(ss, sbBuffer, true, (caps)); // different to windows since behavior on Linux is different (see above)
|
||||
|
||||
refine_alDead(sbBuffer[0], alDead, alDead_byBasechar);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------
|
||||
// Now that we've collected the key data, we need to
|
||||
// translate it to kmx and append to the existing keyboard
|
||||
//-------------------------------------------------------------
|
||||
|
||||
int nDeadkey = 0;
|
||||
LPKMX_GROUP gp = new KMX_GROUP[kp->cxGroupArray + 4]; // leave space for old
|
||||
memcpy(gp, kp->dpGroupArray, sizeof(KMX_GROUP) * kp->cxGroupArray);
|
||||
|
||||
//
|
||||
// Find the current highest deadkey index
|
||||
//
|
||||
|
||||
kp->dpGroupArray = gp;
|
||||
for (KMX_DWORD i = 0; i < kp->cxGroupArray; i++, gp++) {
|
||||
LPKMX_KEY kkp = gp->dpKeyArray;
|
||||
|
||||
for (KMX_DWORD j = 0; j < gp->cxKeyArray; j++, kkp++) {
|
||||
nDeadkey = std::max(nDeadkey, KMX_GetMaxDeadkeyIndex(kkp->dpContext));
|
||||
nDeadkey = std::max(nDeadkey, KMX_GetMaxDeadkeyIndex(kkp->dpOutput));
|
||||
}
|
||||
}
|
||||
|
||||
kp->cxGroupArray++;
|
||||
gp = &kp->dpGroupArray[kp->cxGroupArray - 1];
|
||||
|
||||
// calculate the required size of `gp->dpKeyArray`
|
||||
|
||||
KMX_DWORD nkeys = 0;
|
||||
for (KMX_DWORD iKey = 0; iKey < rgKey.size(); iKey++) {
|
||||
if ((rgKey[iKey] != NULL) && rgKey[iKey]->KMX_IsKeymanUsedKey() && (!rgKey[iKey]->KMX_IsEmpty())) {
|
||||
nkeys += rgKey[iKey]->KMX_GetKeyCount(loader.KMX_MaxShiftState());
|
||||
}
|
||||
}
|
||||
|
||||
gp->fUsingKeys = TRUE;
|
||||
gp->dpMatch = NULL;
|
||||
gp->dpName = NULL;
|
||||
gp->dpNoMatch = NULL;
|
||||
gp->cxKeyArray = nkeys;
|
||||
gp->dpKeyArray = new KMX_KEY[gp->cxKeyArray];
|
||||
|
||||
nDeadkey++; // ensure a 1-based index above the max deadkey value already in the keyboard
|
||||
|
||||
//
|
||||
// Fill in the new rules
|
||||
//
|
||||
nkeys = 0;
|
||||
for (KMX_DWORD iKey = 0; iKey < rgKey.size(); iKey++) {
|
||||
if ((rgKey[iKey] != NULL) && rgKey[iKey]->KMX_IsKeymanUsedKey() && (!rgKey[iKey]->KMX_IsEmpty())) {
|
||||
if (rgKey[iKey]->KMX_LayoutRow(loader.KMX_MaxShiftState(), &gp->dpKeyArray[nkeys], &alDead, nDeadkey, bDeadkeyConversion, all_vector, *keymap)) { // I4552
|
||||
nkeys += rgKey[iKey]->KMX_GetKeyCount(loader.KMX_MaxShiftState());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gp->cxKeyArray = nkeys;
|
||||
|
||||
//
|
||||
// Add nomatch control to each terminating 'using keys' group // I4550
|
||||
//
|
||||
LPKMX_GROUP gp2 = kp->dpGroupArray;
|
||||
for (KMX_DWORD i = 0; i < kp->cxGroupArray - 1; i++, gp2++) {
|
||||
if (gp2->fUsingKeys && gp2->dpNoMatch == NULL) {
|
||||
KMX_WCHAR* p = gp2->dpNoMatch = new KMX_WCHAR[4];
|
||||
*p++ = UC_SENTINEL;
|
||||
*p++ = CODE_USE;
|
||||
*p++ = (KMX_WCHAR)(kp->cxGroupArray);
|
||||
*p = 0;
|
||||
|
||||
// I4550 - Each place we have a nomatch > use(baselayout) (this last group), we need to add all
|
||||
// the AltGr and ShiftAltGr combinations as rules to allow them to be matched as well. Yes, this
|
||||
// loop is not very efficient but it's not worthy of optimisation.
|
||||
//
|
||||
KMX_DWORD j;
|
||||
LPKMX_KEY kkp;
|
||||
for (j = 0, kkp = gp->dpKeyArray; j < gp->cxKeyArray; j++, kkp++) {
|
||||
if ((kkp->ShiftFlags & (K_CTRLFLAG | K_ALTFLAG | LCTRLFLAG | LALTFLAG | RCTRLFLAG | RALTFLAG)) != 0) {
|
||||
gp2->cxKeyArray++;
|
||||
LPKMX_KEY kkp2 = new KMX_KEY[gp2->cxKeyArray];
|
||||
memcpy(kkp2, gp2->dpKeyArray, sizeof(KMX_KEY) * (gp2->cxKeyArray - 1));
|
||||
gp2->dpKeyArray = kkp2;
|
||||
kkp2 = &kkp2[gp2->cxKeyArray - 1];
|
||||
kkp2->dpContext = new KMX_WCHAR;
|
||||
*kkp2->dpContext = 0;
|
||||
kkp2->Key = kkp->Key;
|
||||
kkp2->ShiftFlags = kkp->ShiftFlags;
|
||||
kkp2->Line = 0;
|
||||
KMX_WCHAR* p = kkp2->dpOutput = new KMX_WCHAR[4];
|
||||
*p++ = UC_SENTINEL;
|
||||
*p++ = CODE_USE;
|
||||
*p++ = (KMX_WCHAR)(kp->cxGroupArray);
|
||||
*p = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we have deadkeys, then add a new group to translate the deadkeys per the deadkey tables
|
||||
// We only do this if not in deadkey conversion mode
|
||||
//
|
||||
|
||||
if (alDead.size() > 0 && !bDeadkeyConversion) { // I4552
|
||||
kp->cxGroupArray++;
|
||||
|
||||
KMX_WCHAR* p = gp->dpMatch = new KMX_WCHAR[4];
|
||||
*p++ = UC_SENTINEL;
|
||||
*p++ = CODE_USE;
|
||||
*p++ = (KMX_WCHAR)kp->cxGroupArray;
|
||||
*p = 0;
|
||||
|
||||
gp++;
|
||||
|
||||
gp->fUsingKeys = FALSE;
|
||||
gp->dpMatch = NULL;
|
||||
gp->dpName = NULL;
|
||||
gp->dpNoMatch = NULL;
|
||||
gp->cxKeyArray = alDead.size();
|
||||
LPKMX_KEY kkp = gp->dpKeyArray = new KMX_KEY[alDead.size()];
|
||||
|
||||
LPKMX_STORE sp = new KMX_STORE[kp->cxStoreArray + alDead.size() * 2];
|
||||
memcpy(sp, kp->dpStoreArray, sizeof(KMX_STORE) * kp->cxStoreArray);
|
||||
|
||||
kp->dpStoreArray = sp;
|
||||
|
||||
sp = &sp[kp->cxStoreArray];
|
||||
int nStoreBase = kp->cxStoreArray;
|
||||
kp->cxStoreArray += alDead.size() * 2;
|
||||
|
||||
for (KMX_DWORD i = 0; i < alDead.size(); i++) {
|
||||
DeadKey* dk = alDead[i];
|
||||
|
||||
sp->dpName = NULL;
|
||||
sp->dwSystemID = 0;
|
||||
sp->dpString = new KMX_WCHAR[dk->KMX_Count() + 1];
|
||||
for (int j = 0; j < dk->KMX_Count(); j++)
|
||||
sp->dpString[j] = dk->KMX_GetBaseCharacter(j);
|
||||
sp->dpString[dk->KMX_Count()] = 0;
|
||||
sp++;
|
||||
|
||||
sp->dpName = NULL;
|
||||
sp->dwSystemID = 0;
|
||||
sp->dpString = new KMX_WCHAR[dk->KMX_Count() + 1];
|
||||
for (int j = 0; j < dk->KMX_Count(); j++)
|
||||
sp->dpString[j] = dk->KMX_GetCombinedCharacter(j);
|
||||
sp->dpString[dk->KMX_Count()] = 0;
|
||||
sp++;
|
||||
|
||||
kkp->Line = 0;
|
||||
kkp->ShiftFlags = 0;
|
||||
kkp->Key = 0;
|
||||
KMX_WCHAR* p = kkp->dpContext = new KMX_WCHAR[8];
|
||||
*p++ = UC_SENTINEL;
|
||||
*p++ = CODE_DEADKEY;
|
||||
*p++ = KMX_DeadKeyMap(dk->KMX_DeadCharacter(), &alDead, nDeadkey, FDeadkeys); // I4353
|
||||
// *p++ = nDeadkey+i;
|
||||
*p++ = UC_SENTINEL;
|
||||
*p++ = CODE_ANY;
|
||||
*p++ = nStoreBase + i * 2 + 1;
|
||||
*p = 0;
|
||||
|
||||
p = kkp->dpOutput = new KMX_WCHAR[5];
|
||||
*p++ = UC_SENTINEL;
|
||||
*p++ = CODE_INDEX;
|
||||
*p++ = nStoreBase + i * 2 + 2;
|
||||
*p++ = 2;
|
||||
*p = 0;
|
||||
kkp++;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
43
linux/mcompile/keymap/mc_import_rules.h
Normal file
43
linux/mcompile/keymap/mc_import_rules.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
#pragma once
|
||||
#ifndef MC_IMPORT_RULES_H
|
||||
#define MC_IMPORT_RULES_H
|
||||
|
||||
/** @brief Base class for Deadkey*/
|
||||
class DeadKey {
|
||||
private:
|
||||
KMX_WCHAR m_deadchar;
|
||||
std::vector<KMX_WCHAR> m_rgbasechar;
|
||||
std::vector<KMX_WCHAR> m_rgcombchar;
|
||||
|
||||
public:
|
||||
/** @brief Constructor */
|
||||
DeadKey(KMX_WCHAR deadCharacter);
|
||||
|
||||
/** @brief return dead character */
|
||||
KMX_WCHAR KMX_DeadCharacter();
|
||||
|
||||
/** @brief set Deadkey with values */
|
||||
void KMX_AddDeadKeyRow(KMX_WCHAR baseCharacter, KMX_WCHAR combinedCharacter);
|
||||
|
||||
int KMX_Count() {
|
||||
return this->m_rgbasechar.size();
|
||||
}
|
||||
|
||||
KMX_WCHAR KMX_GetDeadCharacter() {
|
||||
return this->m_deadchar;
|
||||
}
|
||||
|
||||
KMX_WCHAR KMX_GetBaseCharacter(int index) {
|
||||
return this->m_rgbasechar[index];
|
||||
}
|
||||
|
||||
KMX_WCHAR KMX_GetCombinedCharacter(int index) {
|
||||
return this->m_rgcombchar[index];
|
||||
}
|
||||
|
||||
/** @brief check if character exists in DeadKey */
|
||||
bool KMX_ContainsBaseCharacter(KMX_WCHAR baseCharacter);
|
||||
};
|
||||
|
||||
#endif /*MC_IMPORT_RULES_H*/
|
||||
|
|
@ -1,297 +1,581 @@
|
|||
/*
|
||||
* Keyman is copyright (C) 2004 - 2024 SIL International. MIT License.
|
||||
*
|
||||
* Mnemonic layout support for Linux
|
||||
*/
|
||||
|
||||
#include "mc_kmxfile.h"
|
||||
#include <typeinfo>
|
||||
|
||||
KMX_DWORD TEST2;
|
||||
#define CERR_None 0x00000000
|
||||
#define CERR_CannotAllocateMemory 0x00008004
|
||||
#define CERR_UnableToWriteFully 0x00008007
|
||||
#define CERR_SomewhereIGotItWrong 0x00008009
|
||||
|
||||
static KMX_BOOL LoadKeyboardFile(LPKMX_STR fileName, LPKEYBOARD *lpKeyboard);
|
||||
|
||||
KMX_BOOL VerifyKeyboard(LPKMX_BYTE filebase, KMX_DWORD sz);
|
||||
const int CODE__SIZE[] = {
|
||||
-1, // undefined 0x00
|
||||
1, // CODE_ANY 0x01
|
||||
2, // CODE_INDEX 0x02
|
||||
0, // CODE_CONTEXT 0x03
|
||||
0, // CODE_NUL 0x04
|
||||
1, // CODE_USE 0x05
|
||||
0, // CODE_RETURN 0x06
|
||||
0, // CODE_BEEP 0x07
|
||||
1, // CODE_DEADKEY 0x08
|
||||
-1, // unused 0x09
|
||||
2, // CODE_EXTENDED 0x0A
|
||||
-1, // CODE_EXTENDEDEND 0x0B (unused)
|
||||
1, // CODE_SWITCH 0x0C
|
||||
-1, // CODE_KEY 0x0D (never used)
|
||||
0, // CODE_CLEARCONTEXT 0x0E
|
||||
1, // CODE_CALL 0x0F
|
||||
-1, // UC_SENTINEL_EXTENDEDEND 0x10 (not valid with UC_SENTINEL)
|
||||
1, // CODE_CONTEXTEX 0x11
|
||||
1, // CODE_NOTANY 0x12
|
||||
2, // CODE_SETOPT 0x13
|
||||
3, // CODE_IFOPT 0x14
|
||||
1, // CODE_SAVEOPT 0x15
|
||||
1, // CODE_RESETOPT 0x16
|
||||
3, // CODE_IFSYSTEMSTORE 0x17
|
||||
2 // CODE_SETSYSTEMSTORE 0x18
|
||||
};
|
||||
|
||||
LPKEYBOARD FixupKeyboard(PKMX_BYTE bufp, PKMX_BYTE base, KMX_DWORD dwFileSize);
|
||||
/** @brief check if the file has correct version */
|
||||
KMX_BOOL KMX_VerifyKeyboard(PKMX_BYTE filebase, KMX_DWORD file_size);
|
||||
|
||||
/*void Err(wchar_t *s) {
|
||||
LogError(L"LoadKeyboard: %s, last error = %d\n", s, GetLastError());
|
||||
}*/
|
||||
/*BOOL LoadKeyboard(LPWSTR fileName, LPKEYBOARD *lpKeyboard) {
|
||||
DWORD sz;
|
||||
LPBYTE buf;
|
||||
HANDLE hFile;
|
||||
LPKEYBOARD kbp;
|
||||
PBYTE filebase;
|
||||
/** @brief Fixup the keyboard by expanding pointers. */
|
||||
LPKMX_KEYBOARD KMX_FixupKeyboard(PKMX_BYTE bufp, PKMX_BYTE base, KMX_DWORD dwFileSize);
|
||||
|
||||
if(!fileName || !lpKeyboard) {
|
||||
Err(L"Bad Filename");
|
||||
return FALSE;
|
||||
}
|
||||
/**
|
||||
* @brief Save a Keyboard to a file
|
||||
* @param fk pointer to the keyboard
|
||||
* @param hOutfile pointer to the output file
|
||||
* @param FSaveDebug
|
||||
* @return an Error in case of failure
|
||||
*/
|
||||
KMX_DWORD KMX_WriteCompiledKeyboardToFile(LPKMX_KEYBOARD fk, FILE* hOutfile, KMX_BOOL FSaveDebug) {
|
||||
LPKMX_GROUP fgp;
|
||||
LPKMX_STORE fsp;
|
||||
LPKMX_KEY fkp;
|
||||
|
||||
hFile = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if(hFile == INVALID_HANDLE_VALUE) {
|
||||
Err(L"Could not open file");
|
||||
return FALSE;
|
||||
}
|
||||
PCOMP_KEYBOARD ck;
|
||||
PCOMP_GROUP gp;
|
||||
PCOMP_STORE sp;
|
||||
PCOMP_KEY kp;
|
||||
PKMX_BYTE buf;
|
||||
KMX_DWORD size, offset;
|
||||
KMX_DWORD i, j;
|
||||
|
||||
sz = GetFileSize(hFile, NULL);
|
||||
// Calculate how much memory to allocate
|
||||
size = sizeof(COMP_KEYBOARD) +
|
||||
fk->cxGroupArray * sizeof(COMP_GROUP) +
|
||||
fk->cxStoreArray * sizeof(COMP_STORE) +
|
||||
// wcslen(fk->szName)*2 + 2 +
|
||||
// wcslen(fk->szCopyright)*2 + 2 +
|
||||
// wcslen(fk->szLanguageName)*2 + 2 +
|
||||
// wcslen(fk->szMessage)*2 + 2 +
|
||||
fk->dwBitmapSize;
|
||||
|
||||
buf = new BYTE[sz];
|
||||
for (i = 0, fgp = fk->dpGroupArray; i < fk->cxGroupArray; i++, fgp++) {
|
||||
if (fgp->dpName)
|
||||
size += (u16len(fgp->dpName) + 1) * sizeof(KMX_WCHAR);
|
||||
size += fgp->cxKeyArray * sizeof(COMP_KEY);
|
||||
for (j = 0, fkp = fgp->dpKeyArray; j < fgp->cxKeyArray; j++, fkp++) {
|
||||
size += (u16len(fkp->dpOutput) + 1) * sizeof(KMX_WCHAR);
|
||||
size += (u16len(fkp->dpContext) + 1) * sizeof(KMX_WCHAR);
|
||||
}
|
||||
|
||||
if(!buf) {
|
||||
Err(L"Not allocmem");
|
||||
CloseHandle(hFile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
filebase = buf;
|
||||
|
||||
if(!ReadFile(hFile, filebase, sz, &sz, NULL)) {
|
||||
Err(L"errReadFile");
|
||||
CloseHandle(hFile);
|
||||
delete[] buf;
|
||||
return FALSE;
|
||||
}
|
||||
CloseHandle(hFile);
|
||||
|
||||
if(!VerifyKeyboard(filebase, sz)) {
|
||||
Err(L"errVerifyKeyboard");
|
||||
delete[] buf;
|
||||
return FALSE;
|
||||
if (fgp->dpMatch)
|
||||
size += (u16len(fgp->dpMatch) + 1) * sizeof(KMX_WCHAR);
|
||||
if (fgp->dpNoMatch)
|
||||
size += (u16len(fgp->dpNoMatch) + 1) * sizeof(KMX_WCHAR);
|
||||
}
|
||||
|
||||
kbp = FixupKeyboard(buf, filebase, sz);
|
||||
if(!kbp) {
|
||||
Err(L"errFixupKeyboard");
|
||||
delete[] buf;
|
||||
return FALSE;
|
||||
for (i = 0; i < fk->cxStoreArray; i++) {
|
||||
size += (u16len(fk->dpStoreArray[i].dpString) + 1) * sizeof(KMX_WCHAR);
|
||||
if (fk->dpStoreArray[i].dpName)
|
||||
size += (u16len(fk->dpStoreArray[i].dpName) + 1) * sizeof(KMX_WCHAR);
|
||||
}
|
||||
|
||||
if(kbp->dwIdentifier != FILEID_COMPILED) {
|
||||
Err(L"errNotFileID");
|
||||
delete[] buf;
|
||||
return FALSE;
|
||||
buf = new KMX_BYTE[size];
|
||||
if (!buf)
|
||||
return CERR_CannotAllocateMemory;
|
||||
memset(buf, 0, size);
|
||||
|
||||
ck = (PCOMP_KEYBOARD)buf;
|
||||
|
||||
ck->dwIdentifier = FILEID_COMPILED;
|
||||
|
||||
ck->dwFileVersion = fk->dwFileVersion;
|
||||
ck->dwCheckSum = 0; // No checksum in 16.0, see #7276
|
||||
ck->KeyboardID = fk->xxkbdlayout;
|
||||
ck->IsRegistered = fk->IsRegistered;
|
||||
ck->cxStoreArray = fk->cxStoreArray;
|
||||
ck->cxGroupArray = fk->cxGroupArray;
|
||||
ck->StartGroup[0] = fk->StartGroup[0];
|
||||
ck->StartGroup[1] = fk->StartGroup[1];
|
||||
ck->dwHotKey = fk->dwHotKey;
|
||||
|
||||
ck->dwFlags = fk->dwFlags;
|
||||
|
||||
offset = sizeof(COMP_KEYBOARD);
|
||||
|
||||
ck->dpStoreArray = offset;
|
||||
sp = (PCOMP_STORE)(buf + offset);
|
||||
fsp = fk->dpStoreArray;
|
||||
offset += sizeof(COMP_STORE) * ck->cxStoreArray;
|
||||
for (i = 0; i < ck->cxStoreArray; i++, sp++, fsp++) {
|
||||
sp->dwSystemID = fsp->dwSystemID;
|
||||
sp->dpString = offset;
|
||||
u16ncpy((PKMX_WCHAR)(buf + offset), fsp->dpString, (size - offset) / sizeof(KMX_WCHAR)); // I3481 // I3641
|
||||
|
||||
offset += (u16len(fsp->dpString) + 1) * sizeof(KMX_WCHAR);
|
||||
if (!fsp->dpName) {
|
||||
sp->dpName = 0;
|
||||
} else {
|
||||
sp->dpName = offset;
|
||||
u16ncpy((PKMX_WCHAR)(buf + offset), fsp->dpName, (size - offset) / sizeof(KMX_WCHAR)); // I3481 // I3641
|
||||
offset += (u16len(fsp->dpName) + 1) * sizeof(KMX_WCHAR);
|
||||
}
|
||||
}
|
||||
|
||||
*lpKeyboard = kbp;
|
||||
return TRUE;
|
||||
}
|
||||
*/
|
||||
ck->dpGroupArray = offset;
|
||||
gp = (PCOMP_GROUP)(buf + offset);
|
||||
|
||||
/*PKMX_WCHART StringOffset(PKMX_BYTE base, KMX_DWORD offset) {
|
||||
if(offset == 0) return NULL;
|
||||
return (PKMX_WCHART)(base + offset);
|
||||
}*/
|
||||
offset += sizeof(COMP_GROUP) * ck->cxGroupArray;
|
||||
|
||||
for (i = 0, fgp = fk->dpGroupArray; i < ck->cxGroupArray; i++, gp++, fgp++) {
|
||||
gp->cxKeyArray = fgp->cxKeyArray;
|
||||
gp->fUsingKeys = fgp->fUsingKeys;
|
||||
|
||||
/*LPKEYBOARD FixupKeyboard(PBYTE bufp, PBYTE base, DWORD dwFileSize) {
|
||||
UNREFERENCED_PARAMETER(dwFileSize);
|
||||
gp->dpMatch = gp->dpNoMatch = 0;
|
||||
|
||||
DWORD i, j;
|
||||
PCOMP_KEYBOARD ckbp = (PCOMP_KEYBOARD) base;
|
||||
PCOMP_GROUP cgp;
|
||||
PCOMP_STORE csp;
|
||||
PCOMP_KEY ckp;
|
||||
LPKEYBOARD kbp = (LPKEYBOARD) bufp;
|
||||
LPSTORE sp;
|
||||
LPGROUP gp;
|
||||
LPKEY kp;
|
||||
if (fgp->dpMatch) {
|
||||
gp->dpMatch = offset;
|
||||
u16ncpy((PKMX_WCHAR)(buf + offset), fgp->dpMatch, (size - offset) / sizeof(KMX_WCHAR)); // I3481 // I3641
|
||||
offset += (u16len(fgp->dpMatch) + 1) * sizeof(KMX_WCHAR);
|
||||
}
|
||||
if (fgp->dpNoMatch) {
|
||||
gp->dpNoMatch = offset;
|
||||
u16ncpy((PKMX_WCHAR)(buf + offset), fgp->dpNoMatch, (size - offset) / sizeof(KMX_WCHAR)); // I3481 // I3641
|
||||
offset += (u16len(fgp->dpNoMatch) + 1) * sizeof(KMX_WCHAR);
|
||||
}
|
||||
|
||||
kbp->dpStoreArray = (LPSTORE) (base + ckbp->dpStoreArray);
|
||||
kbp->dpGroupArray = (LPGROUP) (base + ckbp->dpGroupArray);
|
||||
if (fgp->dpName) {
|
||||
gp->dpName = offset;
|
||||
u16ncpy((PKMX_WCHAR)(buf + offset), fgp->dpName, (size - offset) / sizeof(KMX_WCHAR)); // I3481 // I3641
|
||||
offset += (u16len(fgp->dpName) + 1) * sizeof(KMX_WCHAR);
|
||||
} else {
|
||||
gp->dpName = 0;
|
||||
}
|
||||
|
||||
for(sp = kbp->dpStoreArray, csp = (PCOMP_STORE) sp, i = 0; i < kbp->cxStoreArray; i++, sp++, csp++) {
|
||||
sp->dpName = StringOffset(base, csp->dpName);
|
||||
sp->dpString = StringOffset(base, csp->dpString);
|
||||
}
|
||||
gp->dpKeyArray = offset;
|
||||
kp = (PCOMP_KEY)(buf + offset);
|
||||
offset += gp->cxKeyArray * sizeof(COMP_KEY);
|
||||
|
||||
for(gp = kbp->dpGroupArray, cgp = (PCOMP_GROUP) gp, i = 0; i < kbp->cxGroupArray; i++, gp++, cgp++) {
|
||||
gp->dpName = StringOffset(base, cgp->dpName);
|
||||
gp->dpKeyArray = (LPKEY) (base + cgp->dpKeyArray);
|
||||
if(cgp->dpMatch != NULL) gp->dpMatch = (PWSTR) (base + cgp->dpMatch);
|
||||
if(cgp->dpNoMatch != NULL) gp->dpNoMatch = (PWSTR) (base + cgp->dpNoMatch);
|
||||
for (j = 0, fkp = fgp->dpKeyArray; j < gp->cxKeyArray; j++, kp++, fkp++) {
|
||||
kp->Key = fkp->Key;
|
||||
kp->Line = fkp->Line;
|
||||
kp->ShiftFlags = fkp->ShiftFlags;
|
||||
kp->dpOutput = offset;
|
||||
|
||||
for(kp = gp->dpKeyArray, ckp = (PCOMP_KEY) kp, j = 0; j < gp->cxKeyArray; j++, kp++, ckp++) {
|
||||
kp->dpOutput = (PWSTR) (base + ckp->dpOutput);
|
||||
kp->dpContext = (PWSTR) (base + ckp->dpContext);
|
||||
u16ncpy((PKMX_WCHAR)(buf + offset), fkp->dpOutput, (size - offset) / sizeof(KMX_WCHAR)); // I3481 // I3641
|
||||
offset += (u16len(fkp->dpOutput) + 1) * sizeof(KMX_WCHAR);
|
||||
|
||||
kp->dpContext = offset;
|
||||
u16ncpy((PKMX_WCHAR)(buf + offset), fkp->dpContext, (size - offset) / sizeof(KMX_WCHAR)); // I3481 // I3641
|
||||
offset += (u16len(fkp->dpContext) + 1) * sizeof(KMX_WCHAR);
|
||||
}
|
||||
}
|
||||
|
||||
return kbp;
|
||||
if (fk->dwBitmapSize > 0) {
|
||||
ck->dwBitmapSize = fk->dwBitmapSize;
|
||||
ck->dpBitmapOffset = offset;
|
||||
memcpy(buf + offset, ((PKMX_BYTE)fk) + fk->dpBitmapOffset, fk->dwBitmapSize);
|
||||
offset += fk->dwBitmapSize;
|
||||
} else {
|
||||
ck->dwBitmapSize = 0;
|
||||
ck->dpBitmapOffset = 0;
|
||||
}
|
||||
|
||||
size_t nr_elements = fwrite(buf, size, 1, hOutfile);
|
||||
|
||||
if (nr_elements < 1) {
|
||||
delete[] buf;
|
||||
return CERR_SomewhereIGotItWrong;
|
||||
}
|
||||
|
||||
if (offset != size) {
|
||||
delete[] buf;
|
||||
return CERR_UnableToWriteFully;
|
||||
}
|
||||
|
||||
delete[] buf;
|
||||
|
||||
return CERR_None;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief save keyboard to file
|
||||
* @param kbd pointer to the keyboard
|
||||
* @param filename pointer to filename of a kmx-file
|
||||
* @return TRUE on success;
|
||||
* else FALSE
|
||||
*/
|
||||
KMX_BOOL KMX_SaveKeyboard(LPKMX_KEYBOARD kbd, KMX_CHAR* filename) {
|
||||
FILE* fp;
|
||||
fp = Open_File(filename, "wb");
|
||||
|
||||
/*BOOL VerifyKeyboard(LPBYTE filebase, DWORD sz) {
|
||||
DWORD i;
|
||||
PCOMP_KEYBOARD ckbp = (PCOMP_KEYBOARD) filebase;
|
||||
PCOMP_STORE csp;
|
||||
if (fp == NULL) {
|
||||
KMX_LogError(L"Failed to create output file (%d)", errno);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Check file version //
|
||||
|
||||
if(ckbp->dwFileVersion < VERSION_MIN ||
|
||||
ckbp->dwFileVersion > VERSION_MAX) {
|
||||
// Old or new version -- identify the desired program version //
|
||||
for(csp = (PCOMP_STORE)(filebase + ckbp->dpStoreArray), i = 0; i < ckbp->cxStoreArray; i++, csp++) {
|
||||
if(csp->dwSystemID == TSS_COMPILEDVERSION) {
|
||||
wchar_t buf2[256];
|
||||
if(csp->dpString == 0) {
|
||||
wsprintf(buf2, L"errWrongFileVersion:NULL");
|
||||
} else {
|
||||
wsprintf(buf2, L"errWrongFileVersion:%10.10ls", StringOffset(filebase, csp->dpString));
|
||||
}
|
||||
Err(buf2);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
Err(L"errWrongFileVersion");
|
||||
return FALSE;
|
||||
}
|
||||
KMX_DWORD err = KMX_WriteCompiledKeyboardToFile(kbd, fp, FALSE);
|
||||
fclose(fp);
|
||||
|
||||
if (err != CERR_None) {
|
||||
KMX_LogError(L"Failed to write compiled keyboard with error %d", err);
|
||||
std::string s(filename);
|
||||
remove(s.c_str());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}*/
|
||||
|
||||
|
||||
//---------------------old----------------------------------------
|
||||
/*
|
||||
#include "pch.h"
|
||||
|
||||
|
||||
static BOOL LoadKeyboardFile(LPSTR fileName, LPKEYBOARD *lpKeyboard);
|
||||
BOOL VerifyKeyboard(LPBYTE filebase, DWORD sz);
|
||||
|
||||
LPKEYBOARD FixupKeyboard(PBYTE bufp, PBYTE base, DWORD dwFileSize);
|
||||
|
||||
void Err(wchar_t *s) {
|
||||
LogError(L"LoadKeyboard: %s, last error = %d\n", s, GetLastError());
|
||||
}
|
||||
|
||||
BOOL LoadKeyboard(LPWSTR fileName, LPKEYBOARD *lpKeyboard) {
|
||||
DWORD sz;
|
||||
LPBYTE buf;
|
||||
HANDLE hFile;
|
||||
LPKEYBOARD kbp;
|
||||
PBYTE filebase;
|
||||
|
||||
if(!fileName || !lpKeyboard) {
|
||||
Err(L"Bad Filename");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
hFile = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if(hFile == INVALID_HANDLE_VALUE) {
|
||||
Err(L"Could not open file");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
sz = GetFileSize(hFile, NULL);
|
||||
|
||||
buf = new BYTE[sz];
|
||||
|
||||
if(!buf) {
|
||||
Err(L"Not allocmem");
|
||||
CloseHandle(hFile);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
filebase = buf;
|
||||
|
||||
if(!ReadFile(hFile, filebase, sz, &sz, NULL)) {
|
||||
Err(L"errReadFile");
|
||||
CloseHandle(hFile);
|
||||
delete[] buf;
|
||||
return FALSE;
|
||||
}
|
||||
CloseHandle(hFile);
|
||||
|
||||
if(!VerifyKeyboard(filebase, sz)) {
|
||||
Err(L"errVerifyKeyboard");
|
||||
delete[] buf;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
kbp = FixupKeyboard(buf, filebase, sz);
|
||||
if(!kbp) {
|
||||
Err(L"errFixupKeyboard");
|
||||
delete[] buf;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(kbp->dwIdentifier != FILEID_COMPILED) {
|
||||
Err(L"errNotFileID");
|
||||
delete[] buf;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*lpKeyboard = kbp;
|
||||
return TRUE;
|
||||
/**
|
||||
* @brief add an offset
|
||||
* @param base pointer to starting point
|
||||
* @param offset a given offset
|
||||
* @return pointer to base + offset
|
||||
*/
|
||||
PKMX_WCHAR KMX_StringOffset(PKMX_BYTE base, KMX_DWORD offset) {
|
||||
if (offset == 0)
|
||||
return NULL;
|
||||
return (PKMX_WCHAR)(base + offset);
|
||||
}
|
||||
|
||||
PWCHAR StringOffset(PBYTE base, DWORD offset) {
|
||||
if(offset == 0) return NULL;
|
||||
return (PWCHAR)(base + offset);
|
||||
#ifdef KMX_64BIT
|
||||
|
||||
/**
|
||||
* @brief CopyKeyboard will copy the data into bufp from x86-sized structures into
|
||||
* x64-sized structures starting at `base`. After this function finishes, we still
|
||||
* need to keep the original data because we don't copy the strings. The method is
|
||||
* used on 64-bit architectures.
|
||||
* @param bufp pointer to buffer where data is copied into
|
||||
* @param base pointer to starting point
|
||||
* @return pointer to the keyboard
|
||||
*/
|
||||
LPKMX_KEYBOARD CopyKeyboard(PKMX_BYTE bufp, PKMX_BYTE base) {
|
||||
PCOMP_KEYBOARD ckbp = (PCOMP_KEYBOARD)base;
|
||||
|
||||
/* Copy keyboard structure */
|
||||
|
||||
LPKMX_KEYBOARD kbp = (LPKMX_KEYBOARD)bufp;
|
||||
bufp += sizeof(KMX_KEYBOARD);
|
||||
|
||||
kbp->dwIdentifier = ckbp->dwIdentifier;
|
||||
kbp->dwFileVersion = ckbp->dwFileVersion;
|
||||
kbp->dwCheckSum = ckbp->dwCheckSum;
|
||||
kbp->xxkbdlayout = ckbp->KeyboardID;
|
||||
kbp->IsRegistered = ckbp->IsRegistered;
|
||||
kbp->version = ckbp->version;
|
||||
kbp->cxStoreArray = ckbp->cxStoreArray;
|
||||
kbp->cxGroupArray = ckbp->cxGroupArray;
|
||||
kbp->StartGroup[0] = ckbp->StartGroup[0];
|
||||
kbp->StartGroup[1] = ckbp->StartGroup[1];
|
||||
kbp->dwFlags = ckbp->dwFlags;
|
||||
kbp->dwHotKey = ckbp->dwHotKey;
|
||||
|
||||
kbp->dpStoreArray = (LPKMX_STORE)bufp;
|
||||
bufp += sizeof(KMX_STORE) * kbp->cxStoreArray;
|
||||
|
||||
kbp->dpGroupArray = (LPKMX_GROUP)bufp;
|
||||
bufp += sizeof(KMX_GROUP) * kbp->cxGroupArray;
|
||||
|
||||
PCOMP_STORE csp;
|
||||
LPKMX_STORE sp;
|
||||
KMX_DWORD i;
|
||||
|
||||
for (csp = (PCOMP_STORE)(base + ckbp->dpStoreArray), sp = kbp->dpStoreArray, i = 0; i < kbp->cxStoreArray; i++, sp++, csp++) {
|
||||
sp->dwSystemID = csp->dwSystemID;
|
||||
sp->dpName = KMX_StringOffset(base, csp->dpName);
|
||||
sp->dpString = KMX_StringOffset(base, csp->dpString);
|
||||
}
|
||||
|
||||
PCOMP_GROUP cgp;
|
||||
LPKMX_GROUP gp;
|
||||
|
||||
for (cgp = (PCOMP_GROUP)(base + ckbp->dpGroupArray), gp = kbp->dpGroupArray, i = 0; i < kbp->cxGroupArray; i++, gp++, cgp++) {
|
||||
gp->dpName = KMX_StringOffset(base, cgp->dpName);
|
||||
gp->dpKeyArray = cgp->cxKeyArray > 0 ? (LPKMX_KEY)bufp : NULL;
|
||||
gp->cxKeyArray = cgp->cxKeyArray;
|
||||
bufp += sizeof(KMX_KEY) * gp->cxKeyArray;
|
||||
gp->dpMatch = KMX_StringOffset(base, cgp->dpMatch);
|
||||
gp->dpNoMatch = KMX_StringOffset(base, cgp->dpNoMatch);
|
||||
gp->fUsingKeys = cgp->fUsingKeys;
|
||||
|
||||
PCOMP_KEY ckp;
|
||||
LPKMX_KEY kp;
|
||||
KMX_DWORD j;
|
||||
|
||||
for (ckp = (PCOMP_KEY)(base + cgp->dpKeyArray), kp = gp->dpKeyArray, j = 0; j < gp->cxKeyArray; j++, kp++, ckp++) {
|
||||
kp->Key = ckp->Key;
|
||||
kp->Line = ckp->Line;
|
||||
kp->ShiftFlags = ckp->ShiftFlags;
|
||||
kp->dpOutput = KMX_StringOffset(base, ckp->dpOutput);
|
||||
kp->dpContext = KMX_StringOffset(base, ckp->dpContext);
|
||||
}
|
||||
}
|
||||
return kbp;
|
||||
}
|
||||
|
||||
LPKEYBOARD FixupKeyboard(PBYTE bufp, PBYTE base, DWORD dwFileSize) {
|
||||
// else KMX_FixupKeyboard
|
||||
#else
|
||||
/**
|
||||
* @brief Fixup the keyboard by expanding pointers. On disk the pointers are stored relative to the
|
||||
* beginning of the file, but we need real pointers. This method is used on 32-bit architectures.
|
||||
* @param bufp pointer to buffer where data will be copied into
|
||||
* @param base pointer to starting point
|
||||
* @param dwFileSize size of the file
|
||||
* @return pointer to the keyboard
|
||||
*/
|
||||
LPKMX_KEYBOARD KMX_FixupKeyboard(PKMX_BYTE bufp, PKMX_BYTE base, KMX_DWORD dwFileSize) {
|
||||
UNREFERENCED_PARAMETER(dwFileSize);
|
||||
|
||||
DWORD i, j;
|
||||
PCOMP_KEYBOARD ckbp = (PCOMP_KEYBOARD) base;
|
||||
KMX_DWORD i, j;
|
||||
PCOMP_KEYBOARD ckbp = (PCOMP_KEYBOARD)base;
|
||||
PCOMP_GROUP cgp;
|
||||
PCOMP_STORE csp;
|
||||
PCOMP_KEY ckp;
|
||||
LPKEYBOARD kbp = (LPKEYBOARD) bufp;
|
||||
LPSTORE sp;
|
||||
LPGROUP gp;
|
||||
LPKEY kp;
|
||||
LPKMX_KEYBOARD kbp = (LPKMX_KEYBOARD)bufp;
|
||||
LPKMX_STORE sp;
|
||||
LPKMX_GROUP gp;
|
||||
LPKMX_KEY kp;
|
||||
|
||||
kbp->dpStoreArray = (LPSTORE) (base + ckbp->dpStoreArray);
|
||||
kbp->dpGroupArray = (LPGROUP) (base + ckbp->dpGroupArray);
|
||||
kbp->dpStoreArray = (LPKMX_STORE)(base + ckbp->dpStoreArray);
|
||||
kbp->dpGroupArray = (LPKMX_GROUP)(base + ckbp->dpGroupArray);
|
||||
|
||||
for(sp = kbp->dpStoreArray, csp = (PCOMP_STORE) sp, i = 0; i < kbp->cxStoreArray; i++, sp++, csp++) {
|
||||
sp->dpName = StringOffset(base, csp->dpName);
|
||||
sp->dpString = StringOffset(base, csp->dpString);
|
||||
}
|
||||
for (sp = kbp->dpStoreArray, csp = (PCOMP_STORE)sp, i = 0; i < kbp->cxStoreArray; i++, sp++, csp++) {
|
||||
sp->dpName = KMX_StringOffset(base, csp->dpName);
|
||||
sp->dpString = KMX_StringOffset(base, csp->dpString);
|
||||
}
|
||||
|
||||
for(gp = kbp->dpGroupArray, cgp = (PCOMP_GROUP) gp, i = 0; i < kbp->cxGroupArray; i++, gp++, cgp++) {
|
||||
gp->dpName = StringOffset(base, cgp->dpName);
|
||||
gp->dpKeyArray = (LPKEY) (base + cgp->dpKeyArray);
|
||||
if(cgp->dpMatch != NULL) gp->dpMatch = (PWSTR) (base + cgp->dpMatch);
|
||||
if(cgp->dpNoMatch != NULL) gp->dpNoMatch = (PWSTR) (base + cgp->dpNoMatch);
|
||||
for (gp = kbp->dpGroupArray, cgp = (PCOMP_GROUP)gp, i = 0; i < kbp->cxGroupArray; i++, gp++, cgp++) {
|
||||
gp->dpName = KMX_StringOffset(base, cgp->dpName);
|
||||
gp->dpKeyArray = (LPKMX_KEY)(base + cgp->dpKeyArray);
|
||||
if (cgp->dpMatch != NULL)
|
||||
gp->dpMatch = (PKMX_WCHAR)(base + cgp->dpMatch);
|
||||
if (cgp->dpNoMatch != NULL)
|
||||
gp->dpNoMatch = (PKMX_WCHAR)(base + cgp->dpNoMatch);
|
||||
|
||||
for(kp = gp->dpKeyArray, ckp = (PCOMP_KEY) kp, j = 0; j < gp->cxKeyArray; j++, kp++, ckp++) {
|
||||
kp->dpOutput = (PWSTR) (base + ckp->dpOutput);
|
||||
kp->dpContext = (PWSTR) (base + ckp->dpContext);
|
||||
}
|
||||
}
|
||||
for (kp = gp->dpKeyArray, ckp = (PCOMP_KEY)kp, j = 0; j < gp->cxKeyArray; j++, kp++, ckp++) {
|
||||
kp->dpOutput = (PKMX_WCHAR)(base + ckp->dpOutput);
|
||||
kp->dpContext = (PKMX_WCHAR)(base + ckp->dpContext);
|
||||
}
|
||||
}
|
||||
|
||||
return kbp;
|
||||
}
|
||||
|
||||
BOOL VerifyKeyboard(LPBYTE filebase, DWORD sz) {
|
||||
DWORD i;
|
||||
PCOMP_KEYBOARD ckbp = (PCOMP_KEYBOARD) filebase;
|
||||
PCOMP_STORE csp;
|
||||
#endif
|
||||
|
||||
// Check file version //
|
||||
/** @brief load a keyboard kmx-file */
|
||||
KMX_BOOL KMX_LoadKeyboard(KMX_CHAR* fileName, LPKMX_KEYBOARD* lpKeyboard) {
|
||||
*lpKeyboard = NULL;
|
||||
PKMX_BYTE buf;
|
||||
FILE* fp;
|
||||
LPKMX_KEYBOARD kbp;
|
||||
PKMX_BYTE filebase;
|
||||
|
||||
if(ckbp->dwFileVersion < VERSION_MIN ||
|
||||
ckbp->dwFileVersion > VERSION_MAX) {
|
||||
// Old or new version -- identify the desired program version //
|
||||
for(csp = (PCOMP_STORE)(filebase + ckbp->dpStoreArray), i = 0; i < ckbp->cxStoreArray; i++, csp++) {
|
||||
if(csp->dwSystemID == TSS_COMPILEDVERSION) {
|
||||
wchar_t buf2[256];
|
||||
if(csp->dpString == 0) {
|
||||
wsprintf(buf2, L"errWrongFileVersion:NULL");
|
||||
} else {
|
||||
wsprintf(buf2, L"errWrongFileVersion:%10.10ls", StringOffset(filebase, csp->dpString));
|
||||
}
|
||||
Err(buf2);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
Err(L"errWrongFileVersion");
|
||||
return FALSE;
|
||||
}
|
||||
if (!fileName || !lpKeyboard) {
|
||||
KMX_LogError(L"Bad Filename\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fp = Open_File((const KMX_CHAR*)fileName, "rb");
|
||||
|
||||
if (fp == NULL) {
|
||||
KMX_LogError(L"Could not open file\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (fseek(fp, 0, SEEK_END) != 0) {
|
||||
fclose(fp);
|
||||
KMX_LogError(L"Could not fseek file\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
auto file_size = ftell(fp);
|
||||
if (file_size <= 0) {
|
||||
fclose(fp);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (fseek(fp, 0, SEEK_SET) != 0) {
|
||||
fclose(fp);
|
||||
KMX_LogError(L"Could not fseek(set) file\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifdef KMX_64BIT
|
||||
/**
|
||||
* allocate enough memory for expanded data structure + original data.
|
||||
* Expanded data structure is double the size of data on disk (8-byte
|
||||
* pointers) - on disk the "pointers" are relative to the beginning of
|
||||
* the file.
|
||||
* We save the original data at the end of buf; we don't copy strings, so
|
||||
* those will remain in the location at the end of the buffer.
|
||||
*/
|
||||
buf = new KMX_BYTE[file_size * 3];
|
||||
#else
|
||||
buf = new KMX_BYTE[file_size];
|
||||
#endif
|
||||
|
||||
if (!buf) {
|
||||
delete[] buf;
|
||||
fclose(fp);
|
||||
KMX_LogError(L"Not allocmem\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifdef KMX_64BIT
|
||||
filebase = buf + file_size * 2;
|
||||
#else
|
||||
filebase = buf;
|
||||
#endif
|
||||
|
||||
if (fread(filebase, 1, file_size, fp) < (size_t)file_size) {
|
||||
KMX_LogError(L"Could not read file\n");
|
||||
delete[] buf;
|
||||
fclose(fp);
|
||||
return FALSE;
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
if (*((PKMX_DWORD)filebase) != (KMX_DWORD)FILEID_COMPILED) {
|
||||
delete[] buf;
|
||||
KMX_LogError(L"Invalid file - signature is invalid\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!KMX_VerifyKeyboard(filebase, file_size)) {
|
||||
delete[] buf;
|
||||
KMX_LogError(L"errVerifyKeyboard\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifdef KMX_64BIT
|
||||
kbp = CopyKeyboard(buf, filebase);
|
||||
#else
|
||||
kbp = KMX_FixupKeyboard(buf, filebase, file_size);
|
||||
#endif
|
||||
|
||||
if (!kbp) {
|
||||
delete[] buf;
|
||||
KMX_LogError(L"errFixupKeyboard\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (kbp->dwIdentifier != FILEID_COMPILED) {
|
||||
delete[] buf;
|
||||
KMX_LogError(L"errNotFileID\n");
|
||||
return FALSE;
|
||||
}
|
||||
*lpKeyboard = kbp;
|
||||
return TRUE;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief check if the file has correct version
|
||||
* @param filebase containing data of the input file
|
||||
* @param file_size a size
|
||||
* @return true if successful;
|
||||
* false if not
|
||||
*/
|
||||
KMX_BOOL KMX_VerifyKeyboard(PKMX_BYTE filebase, KMX_DWORD file_size) {
|
||||
KMX_DWORD i;
|
||||
PCOMP_KEYBOARD ckbp = (PCOMP_KEYBOARD)filebase;
|
||||
PCOMP_STORE csp;
|
||||
|
||||
// Check file version //
|
||||
|
||||
if (ckbp->dwFileVersion < VERSION_MIN || ckbp->dwFileVersion > VERSION_MAX) {
|
||||
// Old or new version -- identify the desired program version //
|
||||
for (csp = (PCOMP_STORE)(filebase + ckbp->dpStoreArray), i = 0; i < ckbp->cxStoreArray; i++, csp++) {
|
||||
if (csp->dwSystemID == TSS_COMPILEDVERSION) {
|
||||
if (csp->dpString == 0) {
|
||||
KMX_LogError(L"errWrongFileVersion:NULL");
|
||||
} else {
|
||||
KMX_LogError(L"errWrongFileVersion:%10.10ls", (const PKMX_WCHAR)KMX_StringOffset((PKMX_BYTE)filebase, csp->dpString));
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
KMX_LogError(L"errWrongFileVersion");
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief increment in a string
|
||||
* @param p pointer to a character
|
||||
* @return pointer to the incremented character
|
||||
*/
|
||||
PKMX_WCHAR KMX_incxstr(PKMX_WCHAR p) {
|
||||
if (p == NULL || *p == 0)
|
||||
return p;
|
||||
if (*p != UC_SENTINEL) {
|
||||
if (*p >= 0xD800 && *p <= 0xDBFF && *(p + 1) >= 0xDC00 && *(p + 1) <= 0xDFFF)
|
||||
return p + 2;
|
||||
return p + 1;
|
||||
}
|
||||
// UC_SENTINEL(FFFF) with UC_SENTINEL_EXTENDEDEND(0x10) ==> variable length
|
||||
if (*(p + 1) == CODE_EXTENDED) {
|
||||
p += 2;
|
||||
while (*p && *p != UC_SENTINEL_EXTENDEDEND)
|
||||
p++;
|
||||
|
||||
if (*p == 0)
|
||||
return p;
|
||||
return p + 1;
|
||||
}
|
||||
|
||||
if (*(p + 1) > CODE_LASTCODE || CODE__SIZE[*(p + 1)] == -1) {
|
||||
return p + 1;
|
||||
}
|
||||
|
||||
int deltaptr = 2 + CODE__SIZE[*(p + 1)];
|
||||
|
||||
// check for \0 between UC_SENTINEL(FFFF) and next printable character
|
||||
for (int i = 0; i < deltaptr; i++) {
|
||||
if (*p == 0)
|
||||
return p;
|
||||
p++;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief open a file
|
||||
* @param filename name of the file
|
||||
* @param mode same as mode in fopen
|
||||
* @return pointer to file.
|
||||
* On error returns a null pointer
|
||||
*/
|
||||
FILE* Open_File(const KMX_CHAR* filename, const KMX_CHAR* mode) {
|
||||
#ifdef _MSC_VER
|
||||
std::string cpath = filename; //, cmode = mode;
|
||||
std::replace(cpath.begin(), cpath.end(), '/', '\\');
|
||||
return fopen(cpath.c_str(), (const KMX_CHAR*)mode);
|
||||
#else
|
||||
return fopen(filename, mode);
|
||||
std::string cpath, cmode;
|
||||
cpath = (const KMX_CHAR*)filename;
|
||||
cmode = (const KMX_CHAR*)mode;
|
||||
return fopen(cpath.c_str(), cmode.c_str());
|
||||
#endif
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,147 +1,83 @@
|
|||
#pragma once
|
||||
#ifndef MC_KMXFILE_H
|
||||
#define MC_KMXFILE_H
|
||||
|
||||
#include "km_types.h"
|
||||
|
||||
KMX_DWORD TEST;
|
||||
#include <kmx_file.h>
|
||||
#include "mcompile.h"
|
||||
|
||||
#ifndef _KMXFILE_H
|
||||
#define _KMXFILE_H
|
||||
|
||||
typedef struct tagSTORE {
|
||||
KMX_DWORD dwSystemID;
|
||||
PKMX_WCHART dpName;
|
||||
PKMX_WCHART dpString;
|
||||
} STORE, *LPSTORE;
|
||||
typedef struct KMX_tagSTORE {
|
||||
KMX_DWORD dwSystemID;
|
||||
PKMX_WCHAR dpName;
|
||||
PKMX_WCHAR dpString;
|
||||
} KMX_STORE, *LPKMX_STORE;
|
||||
|
||||
typedef struct KMX_tagKEY {
|
||||
KMX_WCHAR Key;
|
||||
KMX_DWORD Line;
|
||||
KMX_DWORD ShiftFlags;
|
||||
PKMX_WCHAR dpOutput;
|
||||
PKMX_WCHAR dpContext;
|
||||
} KMX_KEY, *LPKMX_KEY;
|
||||
|
||||
typedef struct KMX_tagGROUP {
|
||||
KMX_WCHAR* dpName;
|
||||
LPKMX_KEY dpKeyArray; // [LPKEY] address of first item in key array
|
||||
PKMX_WCHAR dpMatch;
|
||||
PKMX_WCHAR dpNoMatch;
|
||||
KMX_DWORD cxKeyArray; // in array entries
|
||||
int32_t fUsingKeys; // group(xx) [using keys] <-- specified or not
|
||||
} KMX_GROUP, *LPKMX_GROUP;
|
||||
|
||||
typedef struct KMX_tagKEYBOARD {
|
||||
KMX_DWORD dwIdentifier; // Keyman compiled keyboard id
|
||||
|
||||
KMX_DWORD dwFileVersion; // Version of the file - Keyman 4.0 is 0x0400
|
||||
|
||||
KMX_DWORD dwCheckSum; // As stored in keyboard. DEPRECATED as of 16.0
|
||||
KMX_DWORD xxkbdlayout; // as stored in HKEY_LOCAL_MACHINE//system//currentcontrolset//control//keyboard layouts
|
||||
KMX_DWORD IsRegistered; // layout id, from same registry key
|
||||
KMX_DWORD version; // keyboard version
|
||||
|
||||
KMX_DWORD cxStoreArray; // in array entries
|
||||
KMX_DWORD cxGroupArray; // in array entries
|
||||
|
||||
LPKMX_STORE dpStoreArray; // [LPSTORE] address of first item in store array, from start of file
|
||||
LPKMX_GROUP dpGroupArray; // [LPGROUP] address of first item in group array, from start of file
|
||||
|
||||
KMX_DWORD StartGroup[2]; // index of starting groups [2 of them]
|
||||
// Ansi=0, Unicode=1
|
||||
|
||||
KMX_DWORD dwFlags; // Flags for the keyboard file
|
||||
|
||||
KMX_DWORD dwHotKey; // standard windows hotkey (hiword=shift/ctrl/alt stuff, loword=vkey)
|
||||
|
||||
// PWSTR dpName; // offset of name
|
||||
// PWSTR dpLanguageName; // offset of language name;
|
||||
// PWSTR dpCopyright; // offset of copyright
|
||||
// PWSTR dpMessage; // offset of message in Keyboard About box
|
||||
|
||||
KMX_DWORD dpBitmapOffset; // 0038 offset of the bitmaps in the file
|
||||
KMX_DWORD dwBitmapSize; // 003C size in bytes of the bitmaps
|
||||
//HBITMAP hBitmap; // handle to the bitmap in the file;
|
||||
} KMX_KEYBOARD, *LPKMX_KEYBOARD;
|
||||
|
||||
|
||||
typedef struct tagKEY {
|
||||
KMX_WCHAR Key;
|
||||
KMX_DWORD Line;
|
||||
KMX_DWORD ShiftFlags;
|
||||
PKMX_WCHART dpOutput;
|
||||
PKMX_WCHART dpContext;
|
||||
} KEY, *LPKEY;
|
||||
/** @brief load a keyboard kmx-file */
|
||||
KMX_BOOL KMX_LoadKeyboard(KMX_CHAR* fileName, LPKMX_KEYBOARD* lpKeyboard);
|
||||
|
||||
/** @brief save keyboard to file */
|
||||
KMX_BOOL KMX_SaveKeyboard(LPKMX_KEYBOARD kbd, KMX_CHAR* filename);
|
||||
|
||||
typedef struct tagGROUP {
|
||||
PKMX_WCHART dpName;
|
||||
LPKEY dpKeyArray; // [LPKEY] address of first item in key array
|
||||
PKMX_WCHART dpMatch;
|
||||
PKMX_WCHART dpNoMatch;
|
||||
KMX_DWORD cxKeyArray; // in array entries
|
||||
KMX_BOOL fUsingKeys; // group(xx) [using keys] <-- specified or not
|
||||
} GROUP, *LPGROUP;
|
||||
/** @brief increment in a string */
|
||||
PKMX_WCHAR KMX_incxstr(PKMX_WCHAR p);
|
||||
|
||||
/** @brief open a file */
|
||||
FILE* Open_File(const KMX_CHAR* filename, const KMX_CHAR* mode);
|
||||
|
||||
#endif // _KMXFILE_H
|
||||
|
||||
typedef struct tagKEYBOARD {
|
||||
KMX_DWORD dwIdentifier; // Keyman compiled keyboard id
|
||||
|
||||
KMX_DWORD dwFileVersion; // Version of the file - Keyman 4.0 is 0x0400
|
||||
|
||||
KMX_DWORD dwCheckSum; // As stored in keyboard. DEPRECATED as of 16.0
|
||||
KMX_DWORD xxkbdlayout; // as stored in HKEY_LOCAL_MACHINE//system//currentcontrolset//control//keyboard layouts
|
||||
KMX_DWORD IsRegistered; // layout id, from same registry key
|
||||
KMX_DWORD version; // keyboard version
|
||||
|
||||
KMX_DWORD cxStoreArray; // in array entries
|
||||
KMX_DWORD cxGroupArray; // in array entries
|
||||
|
||||
LPSTORE dpStoreArray; // [LPSTORE] address of first item in store array, from start of file
|
||||
LPGROUP dpGroupArray; // [LPGROUP] address of first item in group array, from start of file
|
||||
|
||||
KMX_DWORD StartGroup[2]; // index of starting groups [2 of them]
|
||||
// Ansi=0, Unicode=1
|
||||
|
||||
KMX_DWORD dwFlags; // Flags for the keyboard file
|
||||
|
||||
KMX_DWORD dwHotKey; // standard windows hotkey (hiword=shift/ctrl/alt stuff, loword=vkey)
|
||||
|
||||
//PKMX_WCHART dpName; // offset of name
|
||||
//PKMX_WCHART dpLanguageName; // offset of language name;
|
||||
//PKMX_WCHART dpCopyright; // offset of copyright
|
||||
//PKMX_WCHART dpMessage; // offset of message in Keyboard About box
|
||||
|
||||
KMX_DWORD dpBitmapOffset; // 0038 offset of the bitmaps in the file
|
||||
KMX_DWORD dwBitmapSize; // 003C size in bytes of the bitmaps
|
||||
//HBITMAP hBitmap; // handle to the bitmap in the file;
|
||||
} KEYBOARD, *LPKEYBOARD;
|
||||
|
||||
KMX_BOOL LoadKeyboard(LPKMX_WCHART fileName, LPKEYBOARD *lpKeyboard); // _S2 LPKEYBOARD ok to leave as is??
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------old----------------------------------------
|
||||
/*
|
||||
#include <Windows.h>
|
||||
|
||||
#ifndef _KMXFILE_H
|
||||
#define _KMXFILE_H
|
||||
|
||||
typedef struct tagSTORE {
|
||||
DWORD dwSystemID;
|
||||
PWSTR dpName;
|
||||
PWSTR dpString;
|
||||
} STORE, *LPSTORE;
|
||||
|
||||
typedef struct tagKEY {
|
||||
WCHAR Key;
|
||||
DWORD Line;
|
||||
DWORD ShiftFlags;
|
||||
PWSTR dpOutput;
|
||||
PWSTR dpContext;
|
||||
} KEY, *LPKEY;
|
||||
|
||||
|
||||
typedef struct tagGROUP {
|
||||
PWSTR dpName;
|
||||
LPKEY dpKeyArray; // [LPKEY] address of first item in key array
|
||||
PWSTR dpMatch;
|
||||
PWSTR dpNoMatch;
|
||||
DWORD cxKeyArray; // in array entries
|
||||
BOOL fUsingKeys; // group(xx) [using keys] <-- specified or not
|
||||
} GROUP, *LPGROUP;
|
||||
|
||||
|
||||
typedef struct tagKEYBOARD {
|
||||
DWORD dwIdentifier; // Keyman compiled keyboard id
|
||||
|
||||
DWORD dwFileVersion; // Version of the file - Keyman 4.0 is 0x0400
|
||||
|
||||
DWORD dwCheckSum; // As stored in keyboard. DEPRECATED as of 16.0
|
||||
DWORD xxkbdlayout; // as stored in HKEY_LOCAL_MACHINE//system//currentcontrolset//control//keyboard layouts
|
||||
DWORD IsRegistered; // layout id, from same registry key
|
||||
DWORD version; // keyboard version
|
||||
|
||||
DWORD cxStoreArray; // in array entries
|
||||
DWORD cxGroupArray; // in array entries
|
||||
|
||||
LPSTORE dpStoreArray; // [LPSTORE] address of first item in store array, from start of file
|
||||
LPGROUP dpGroupArray; // [LPGROUP] address of first item in group array, from start of file
|
||||
|
||||
DWORD StartGroup[2]; // index of starting groups [2 of them]
|
||||
// Ansi=0, Unicode=1
|
||||
|
||||
DWORD dwFlags; // Flags for the keyboard file
|
||||
|
||||
DWORD dwHotKey; // standard windows hotkey (hiword=shift/ctrl/alt stuff, loword=vkey)
|
||||
|
||||
//PWSTR dpName; // offset of name
|
||||
//PWSTR dpLanguageName; // offset of language name;
|
||||
//PWSTR dpCopyright; // offset of copyright
|
||||
//PWSTR dpMessage; // offset of message in Keyboard About box
|
||||
|
||||
DWORD dpBitmapOffset; // 0038 offset of the bitmaps in the file
|
||||
DWORD dwBitmapSize; // 003C size in bytes of the bitmaps
|
||||
//HBITMAP hBitmap; // handle to the bitmap in the file;
|
||||
} KEYBOARD, *LPKEYBOARD;
|
||||
|
||||
BOOL LoadKeyboard(LPWSTR fileName, LPKEYBOARD *lpKeyboard);
|
||||
|
||||
#endif
|
||||
*/
|
||||
|
||||
#endif /*MC_KMXFILE_H*/
|
||||
|
|
|
|||
|
|
@ -1,423 +0,0 @@
|
|||
#include "mc_savekeyboard.h"
|
||||
|
||||
|
||||
/*BOOL SaveKeyboard(LPKEYBOARD kbd, PWSTR filename) {
|
||||
HANDLE hOutfile = CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
|
||||
if(hOutfile == INVALID_HANDLE_VALUE) {
|
||||
LogError(L"Failed to create output file (%d)", GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DWORD err = WriteCompiledKeyboard(kbd, hOutfile, FALSE);
|
||||
|
||||
CloseHandle(hOutfile);
|
||||
|
||||
if(err != CERR_None) {
|
||||
LogError(L"Failed to write compiled keyboard with error %d", err);
|
||||
DeleteFile(filename);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}*/
|
||||
|
||||
/*DWORD WriteCompiledKeyboard(LPKEYBOARD fk, HANDLE hOutfile, BOOL FSaveDebug)
|
||||
{
|
||||
LPGROUP fgp;
|
||||
LPSTORE fsp;
|
||||
LPKEY fkp;
|
||||
|
||||
PCOMP_KEYBOARD ck;
|
||||
PCOMP_GROUP gp;
|
||||
PCOMP_STORE sp;
|
||||
PCOMP_KEY kp;
|
||||
PBYTE buf;
|
||||
DWORD size, offset;
|
||||
DWORD i, j;
|
||||
|
||||
// Calculate how much memory to allocate
|
||||
|
||||
size = sizeof(COMP_KEYBOARD) +
|
||||
fk->cxGroupArray * sizeof(COMP_GROUP) +
|
||||
fk->cxStoreArray * sizeof(COMP_STORE) +
|
||||
//wcslen(fk->szName)*2 + 2 +
|
||||
//wcslen(fk->szCopyright)*2 + 2 +
|
||||
//wcslen(fk->szLanguageName)*2 + 2 +
|
||||
//wcslen(fk->szMessage)*2 + 2 +
|
||||
fk->dwBitmapSize;
|
||||
|
||||
for(i = 0, fgp = fk->dpGroupArray; i < fk->cxGroupArray; i++, fgp++) {
|
||||
if(fgp->dpName)
|
||||
size += wcslen(fgp->dpName)*2 + 2;
|
||||
size += fgp->cxKeyArray * sizeof(COMP_KEY);
|
||||
for(j = 0, fkp = fgp->dpKeyArray; j < fgp->cxKeyArray; j++, fkp++) {
|
||||
size += wcslen(fkp->dpOutput)*2 + 2;
|
||||
size += wcslen(fkp->dpContext)*2 + 2;
|
||||
}
|
||||
|
||||
if( fgp->dpMatch ) size += wcslen(fgp->dpMatch)*2 + 2;
|
||||
if( fgp->dpNoMatch ) size += wcslen(fgp->dpNoMatch)*2 + 2;
|
||||
}
|
||||
|
||||
for(i = 0; i < fk->cxStoreArray; i++)
|
||||
{
|
||||
size += wcslen(fk->dpStoreArray[i].dpString)*2 + 2;
|
||||
if(fk->dpStoreArray[i].dpName)
|
||||
size += wcslen(fk->dpStoreArray[i].dpName)*2 + 2;
|
||||
}
|
||||
|
||||
buf = new BYTE[size];
|
||||
if(!buf) return CERR_CannotAllocateMemory;
|
||||
memset(buf, 0, size);
|
||||
|
||||
ck = (PCOMP_KEYBOARD) buf;
|
||||
|
||||
ck->dwIdentifier = FILEID_COMPILED;
|
||||
|
||||
ck->dwFileVersion = fk->dwFileVersion;
|
||||
ck->dwCheckSum = 0; // No checksum in 16.0, see #7276
|
||||
ck->KeyboardID = fk->xxkbdlayout;
|
||||
ck->IsRegistered = fk->IsRegistered;
|
||||
ck->cxStoreArray = fk->cxStoreArray;
|
||||
ck->cxGroupArray = fk->cxGroupArray;
|
||||
ck->StartGroup[0] = fk->StartGroup[0];
|
||||
ck->StartGroup[1] = fk->StartGroup[1];
|
||||
ck->dwHotKey = fk->dwHotKey;
|
||||
|
||||
ck->dwFlags = fk->dwFlags;
|
||||
|
||||
offset = sizeof(COMP_KEYBOARD);
|
||||
|
||||
//ck->dpLanguageName = offset;
|
||||
//wcscpy((PWSTR)(buf + offset), fk->szLanguageName);
|
||||
//offset += wcslen(fk->szLanguageName)*2 + 2;
|
||||
|
||||
//ck->dpName = offset;
|
||||
//wcscpy((PWSTR)(buf + offset), fk->szName);
|
||||
//offset += wcslen(fk->szName)*2 + 2;
|
||||
|
||||
//ck->dpCopyright = offset;
|
||||
//wcscpy((PWSTR)(buf + offset), fk->szCopyright);
|
||||
//offset += wcslen(fk->szCopyright)*2 + 2;
|
||||
|
||||
//ck->dpMessage = offset;
|
||||
//wcscpy((PWSTR)(buf + offset), fk->szMessage);
|
||||
//offset += wcslen(fk->szMessage)*2 + 2;
|
||||
|
||||
ck->dpStoreArray = offset;
|
||||
sp = (PCOMP_STORE)(buf+offset);
|
||||
fsp = fk->dpStoreArray;
|
||||
offset += sizeof(COMP_STORE) * ck->cxStoreArray;
|
||||
for(i = 0; i < ck->cxStoreArray; i++, sp++, fsp++) {
|
||||
sp->dwSystemID = fsp->dwSystemID;
|
||||
sp->dpString = offset;
|
||||
wcscpy_s((PWSTR)(buf+offset), (size-offset) / sizeof(WCHAR), fsp->dpString); // I3481 // I3641
|
||||
offset += wcslen(fsp->dpString)*2 + 2;
|
||||
|
||||
if(!fsp->dpName) {
|
||||
sp->dpName = 0;
|
||||
} else {
|
||||
sp->dpName = offset;
|
||||
wcscpy_s((PWSTR)(buf+offset), (size-offset) / sizeof(WCHAR), fsp->dpName); // I3481 // I3641
|
||||
offset += wcslen(fsp->dpName)*2 + 2;
|
||||
}
|
||||
}
|
||||
|
||||
ck->dpGroupArray = offset;
|
||||
gp = (PCOMP_GROUP)(buf+offset);
|
||||
fgp = fk->dpGroupArray;
|
||||
|
||||
offset += sizeof(COMP_GROUP) * ck->cxGroupArray;
|
||||
|
||||
for(i = 0; i < ck->cxGroupArray; i++, gp++, fgp++) {
|
||||
gp->cxKeyArray = fgp->cxKeyArray;
|
||||
gp->fUsingKeys = fgp->fUsingKeys;
|
||||
|
||||
gp->dpMatch = gp->dpNoMatch = 0;
|
||||
|
||||
if(fgp->dpMatch) {
|
||||
gp->dpMatch = offset;
|
||||
wcscpy_s((PWSTR)(buf+offset), (size-offset) / sizeof(WCHAR), fgp->dpMatch); // I3481 // I3641
|
||||
offset += wcslen(fgp->dpMatch)*2 + 2;
|
||||
}
|
||||
if(fgp->dpNoMatch) {
|
||||
gp->dpNoMatch = offset;
|
||||
wcscpy_s((PWSTR)(buf+offset), (size-offset) / sizeof(WCHAR), fgp->dpNoMatch); // I3481 // I3641
|
||||
offset += wcslen(fgp->dpNoMatch)*2 + 2;
|
||||
}
|
||||
|
||||
if(fgp->dpName) {
|
||||
gp->dpName = offset;
|
||||
wcscpy_s((PWSTR)(buf+offset), (size-offset) / sizeof(WCHAR), fgp->dpName); // I3481 // I3641
|
||||
offset += wcslen(fgp->dpName)*2 + 2;
|
||||
} else {
|
||||
gp->dpName = 0;
|
||||
}
|
||||
|
||||
gp->dpKeyArray = offset;
|
||||
kp = (PCOMP_KEY) (buf + offset);
|
||||
fkp = fgp->dpKeyArray;
|
||||
offset += gp->cxKeyArray * sizeof(COMP_KEY);
|
||||
for(j = 0; j < gp->cxKeyArray; j++, kp++, fkp++) {
|
||||
kp->Key = fkp->Key;
|
||||
kp->Line = fkp->Line;
|
||||
kp->ShiftFlags = fkp->ShiftFlags;
|
||||
kp->dpOutput = offset;
|
||||
wcscpy_s((PWSTR)(buf+offset), (size-offset) / sizeof(WCHAR), fkp->dpOutput); // I3481 // I3641
|
||||
offset += wcslen(fkp->dpOutput)*2 + 2;
|
||||
|
||||
|
||||
kp->dpContext = offset;
|
||||
wcscpy_s((PWSTR)(buf+offset), (size-offset) / sizeof(WCHAR), fkp->dpContext); // I3481 // I3641
|
||||
offset += wcslen(fkp->dpContext)*2 + 2;
|
||||
}
|
||||
}
|
||||
|
||||
if(fk->dwBitmapSize > 0) {
|
||||
ck->dwBitmapSize = fk->dwBitmapSize;
|
||||
ck->dpBitmapOffset = offset;
|
||||
memcpy(buf + offset, ((PBYTE)fk) + fk->dpBitmapOffset, fk->dwBitmapSize);
|
||||
offset += fk->dwBitmapSize;
|
||||
} else {
|
||||
ck->dwBitmapSize = 0;
|
||||
ck->dpBitmapOffset = 0;
|
||||
}
|
||||
|
||||
if(offset != size)
|
||||
{
|
||||
delete[] buf;
|
||||
return CERR_SomewhereIGotItWrong;
|
||||
}
|
||||
|
||||
WriteFile(hOutfile, buf, size, &offset, NULL);
|
||||
|
||||
if(offset != size)
|
||||
{
|
||||
delete[] buf;
|
||||
return CERR_UnableToWriteFully;
|
||||
}
|
||||
|
||||
delete[] buf;
|
||||
|
||||
return CERR_None;
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------old----------------------------------------
|
||||
/*#include "pch.h"
|
||||
|
||||
// These four errors are copied from kmn_compiler_errors.h, because WriteCompiledKeyboard is
|
||||
// a clone of the compiler's equivalent function. However, the functions
|
||||
// diverge, as mc_savekeyboard.cpp's version is copying from an existing
|
||||
// compiled keyboard. The error codes have been kept consistent with those in
|
||||
// kmn_compiler_errors.h
|
||||
#define CERR_None 0x00000000
|
||||
#define CERR_CannotAllocateMemory 0x00008004
|
||||
#define CERR_UnableToWriteFully 0x00008007
|
||||
#define CERR_SomewhereIGotItWrong 0x00008009
|
||||
|
||||
DWORD WriteCompiledKeyboard(LPKEYBOARD fk, HANDLE hOutfile, BOOL FSaveDebug);
|
||||
|
||||
BOOL SaveKeyboard(LPKEYBOARD kbd, PWSTR filename) {
|
||||
HANDLE hOutfile = CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
|
||||
if(hOutfile == INVALID_HANDLE_VALUE) {
|
||||
LogError(L"Failed to create output file (%d)", GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DWORD err = WriteCompiledKeyboard(kbd, hOutfile, FALSE);
|
||||
|
||||
CloseHandle(hOutfile);
|
||||
|
||||
if(err != CERR_None) {
|
||||
LogError(L"Failed to write compiled keyboard with error %d", err);
|
||||
DeleteFile(filename);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
DWORD WriteCompiledKeyboard(LPKEYBOARD fk, HANDLE hOutfile, BOOL FSaveDebug)
|
||||
{
|
||||
LPGROUP fgp;
|
||||
LPSTORE fsp;
|
||||
LPKEY fkp;
|
||||
|
||||
PCOMP_KEYBOARD ck;
|
||||
PCOMP_GROUP gp;
|
||||
PCOMP_STORE sp;
|
||||
PCOMP_KEY kp;
|
||||
PBYTE buf;
|
||||
DWORD size, offset;
|
||||
DWORD i, j;
|
||||
|
||||
// Calculate how much memory to allocate
|
||||
|
||||
size = sizeof(COMP_KEYBOARD) +
|
||||
fk->cxGroupArray * sizeof(COMP_GROUP) +
|
||||
fk->cxStoreArray * sizeof(COMP_STORE) +
|
||||
//wcslen(fk->szName)*2 + 2 +
|
||||
//wcslen(fk->szCopyright)*2 + 2 +
|
||||
//wcslen(fk->szLanguageName)*2 + 2 +
|
||||
//wcslen(fk->szMessage)*2 + 2 +
|
||||
fk->dwBitmapSize;
|
||||
|
||||
for(i = 0, fgp = fk->dpGroupArray; i < fk->cxGroupArray; i++, fgp++) {
|
||||
if(fgp->dpName)
|
||||
size += wcslen(fgp->dpName)*2 + 2;
|
||||
size += fgp->cxKeyArray * sizeof(COMP_KEY);
|
||||
for(j = 0, fkp = fgp->dpKeyArray; j < fgp->cxKeyArray; j++, fkp++) {
|
||||
size += wcslen(fkp->dpOutput)*2 + 2;
|
||||
size += wcslen(fkp->dpContext)*2 + 2;
|
||||
}
|
||||
|
||||
if( fgp->dpMatch ) size += wcslen(fgp->dpMatch)*2 + 2;
|
||||
if( fgp->dpNoMatch ) size += wcslen(fgp->dpNoMatch)*2 + 2;
|
||||
}
|
||||
|
||||
for(i = 0; i < fk->cxStoreArray; i++)
|
||||
{
|
||||
size += wcslen(fk->dpStoreArray[i].dpString)*2 + 2;
|
||||
if(fk->dpStoreArray[i].dpName)
|
||||
size += wcslen(fk->dpStoreArray[i].dpName)*2 + 2;
|
||||
}
|
||||
|
||||
buf = new BYTE[size];
|
||||
if(!buf) return CERR_CannotAllocateMemory;
|
||||
memset(buf, 0, size);
|
||||
|
||||
ck = (PCOMP_KEYBOARD) buf;
|
||||
|
||||
ck->dwIdentifier = FILEID_COMPILED;
|
||||
|
||||
ck->dwFileVersion = fk->dwFileVersion;
|
||||
ck->dwCheckSum = 0; // No checksum in 16.0, see #7276
|
||||
ck->KeyboardID = fk->xxkbdlayout;
|
||||
ck->IsRegistered = fk->IsRegistered;
|
||||
ck->cxStoreArray = fk->cxStoreArray;
|
||||
ck->cxGroupArray = fk->cxGroupArray;
|
||||
ck->StartGroup[0] = fk->StartGroup[0];
|
||||
ck->StartGroup[1] = fk->StartGroup[1];
|
||||
ck->dwHotKey = fk->dwHotKey;
|
||||
|
||||
ck->dwFlags = fk->dwFlags;
|
||||
|
||||
offset = sizeof(COMP_KEYBOARD);
|
||||
|
||||
//ck->dpLanguageName = offset;
|
||||
//wcscpy((PWSTR)(buf + offset), fk->szLanguageName);
|
||||
//offset += wcslen(fk->szLanguageName)*2 + 2;
|
||||
|
||||
//ck->dpName = offset;
|
||||
//wcscpy((PWSTR)(buf + offset), fk->szName);
|
||||
//offset += wcslen(fk->szName)*2 + 2;
|
||||
|
||||
//ck->dpCopyright = offset;
|
||||
//wcscpy((PWSTR)(buf + offset), fk->szCopyright);
|
||||
//offset += wcslen(fk->szCopyright)*2 + 2;
|
||||
|
||||
//ck->dpMessage = offset;
|
||||
//wcscpy((PWSTR)(buf + offset), fk->szMessage);
|
||||
//offset += wcslen(fk->szMessage)*2 + 2;
|
||||
|
||||
ck->dpStoreArray = offset;
|
||||
sp = (PCOMP_STORE)(buf+offset);
|
||||
fsp = fk->dpStoreArray;
|
||||
offset += sizeof(COMP_STORE) * ck->cxStoreArray;
|
||||
for(i = 0; i < ck->cxStoreArray; i++, sp++, fsp++) {
|
||||
sp->dwSystemID = fsp->dwSystemID;
|
||||
sp->dpString = offset;
|
||||
wcscpy_s((PWSTR)(buf+offset), (size-offset) / sizeof(WCHAR), fsp->dpString); // I3481 // I3641
|
||||
offset += wcslen(fsp->dpString)*2 + 2;
|
||||
|
||||
if(!fsp->dpName) {
|
||||
sp->dpName = 0;
|
||||
} else {
|
||||
sp->dpName = offset;
|
||||
wcscpy_s((PWSTR)(buf+offset), (size-offset) / sizeof(WCHAR), fsp->dpName); // I3481 // I3641
|
||||
offset += wcslen(fsp->dpName)*2 + 2;
|
||||
}
|
||||
}
|
||||
|
||||
ck->dpGroupArray = offset;
|
||||
gp = (PCOMP_GROUP)(buf+offset);
|
||||
fgp = fk->dpGroupArray;
|
||||
|
||||
offset += sizeof(COMP_GROUP) * ck->cxGroupArray;
|
||||
|
||||
for(i = 0; i < ck->cxGroupArray; i++, gp++, fgp++) {
|
||||
gp->cxKeyArray = fgp->cxKeyArray;
|
||||
gp->fUsingKeys = fgp->fUsingKeys;
|
||||
|
||||
gp->dpMatch = gp->dpNoMatch = 0;
|
||||
|
||||
if(fgp->dpMatch) {
|
||||
gp->dpMatch = offset;
|
||||
wcscpy_s((PWSTR)(buf+offset), (size-offset) / sizeof(WCHAR), fgp->dpMatch); // I3481 // I3641
|
||||
offset += wcslen(fgp->dpMatch)*2 + 2;
|
||||
}
|
||||
if(fgp->dpNoMatch) {
|
||||
gp->dpNoMatch = offset;
|
||||
wcscpy_s((PWSTR)(buf+offset), (size-offset) / sizeof(WCHAR), fgp->dpNoMatch); // I3481 // I3641
|
||||
offset += wcslen(fgp->dpNoMatch)*2 + 2;
|
||||
}
|
||||
|
||||
if(fgp->dpName) {
|
||||
gp->dpName = offset;
|
||||
wcscpy_s((PWSTR)(buf+offset), (size-offset) / sizeof(WCHAR), fgp->dpName); // I3481 // I3641
|
||||
offset += wcslen(fgp->dpName)*2 + 2;
|
||||
} else {
|
||||
gp->dpName = 0;
|
||||
}
|
||||
|
||||
gp->dpKeyArray = offset;
|
||||
kp = (PCOMP_KEY) (buf + offset);
|
||||
fkp = fgp->dpKeyArray;
|
||||
offset += gp->cxKeyArray * sizeof(COMP_KEY);
|
||||
for(j = 0; j < gp->cxKeyArray; j++, kp++, fkp++) {
|
||||
kp->Key = fkp->Key;
|
||||
kp->Line = fkp->Line;
|
||||
kp->ShiftFlags = fkp->ShiftFlags;
|
||||
kp->dpOutput = offset;
|
||||
wcscpy_s((PWSTR)(buf+offset), (size-offset) / sizeof(WCHAR), fkp->dpOutput); // I3481 // I3641
|
||||
offset += wcslen(fkp->dpOutput)*2 + 2;
|
||||
|
||||
|
||||
kp->dpContext = offset;
|
||||
wcscpy_s((PWSTR)(buf+offset), (size-offset) / sizeof(WCHAR), fkp->dpContext); // I3481 // I3641
|
||||
offset += wcslen(fkp->dpContext)*2 + 2;
|
||||
}
|
||||
}
|
||||
|
||||
if(fk->dwBitmapSize > 0) {
|
||||
ck->dwBitmapSize = fk->dwBitmapSize;
|
||||
ck->dpBitmapOffset = offset;
|
||||
memcpy(buf + offset, ((PBYTE)fk) + fk->dpBitmapOffset, fk->dwBitmapSize);
|
||||
offset += fk->dwBitmapSize;
|
||||
} else {
|
||||
ck->dwBitmapSize = 0;
|
||||
ck->dpBitmapOffset = 0;
|
||||
}
|
||||
|
||||
if(offset != size)
|
||||
{
|
||||
delete[] buf;
|
||||
return CERR_SomewhereIGotItWrong;
|
||||
}
|
||||
|
||||
WriteFile(hOutfile, buf, size, &offset, NULL);
|
||||
|
||||
if(offset != size)
|
||||
{
|
||||
delete[] buf;
|
||||
return CERR_UnableToWriteFully;
|
||||
}
|
||||
|
||||
delete[] buf;
|
||||
|
||||
return CERR_None;
|
||||
}
|
||||
*/
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "km_types.h"
|
||||
KMX_DWORD TEST3;
|
||||
// this file is all new _S2
|
||||
|
||||
//#include "../../../common/include/km_types.h"
|
||||
|
||||
|
||||
#define CERR_None 0x00000000
|
||||
#define CERR_CannotAllocateMemory 0x00008004
|
||||
#define CERR_UnableToWriteFully 0x00008007
|
||||
#define CERR_SomewhereIGotItWrong 0x00008009
|
||||
/*
|
||||
DWORD WriteCompiledKeyboard(LPKEYBOARD fk, HANDLE hOutfile, BOOL FSaveDebug);
|
||||
BOOL SaveKeyboard(LPKEYBOARD kbd, PWSTR filename) ;
|
||||
DWORD WriteCompiledKeyboard(LPKEYBOARD fk, HANDLE hOutfile, BOOL FSaveDebug);
|
||||
*/
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,51 +1,38 @@
|
|||
/*
|
||||
Name: mcompile
|
||||
Copyright: Copyright (C) 2003-2017 SIL International.
|
||||
Documentation:
|
||||
Description:
|
||||
Documentation:
|
||||
Description:
|
||||
Create Date: 3 Aug 2014
|
||||
|
||||
Modified Date: 3 Aug 2014
|
||||
Authors: mcdurdin
|
||||
Related Files:
|
||||
Dependencies:
|
||||
Related Files:
|
||||
Dependencies:
|
||||
|
||||
Bugs:
|
||||
Todo:
|
||||
Notes:
|
||||
Bugs:
|
||||
Todo:
|
||||
Notes:
|
||||
History: 03 Aug 2014 - mcdurdin - I4353 - V9.0 - mnemonic layout recompiler mixes up deadkey rules
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef MCOMPILE_H
|
||||
#define MCOMPILE_H
|
||||
#include <vector>
|
||||
#include "km_types.h"
|
||||
#include "keymap.h"
|
||||
#include "deadkey.h"
|
||||
#include "mc_kmxfile.h"
|
||||
|
||||
void LogError(PKMX_WCHART message, ...);
|
||||
|
||||
|
||||
struct DeadkeyMapping { // I4353
|
||||
KMX_WCHART deadkey, dkid;
|
||||
KMX_UINT shift;
|
||||
struct KMX_DeadkeyMapping { // I4353
|
||||
KMX_WCHAR deadkey, dkid;
|
||||
KMX_DWORD shift;
|
||||
KMX_WORD vk;
|
||||
};
|
||||
|
||||
extern std::vector<DeadkeyMapping> FDeadkeys; // I4353
|
||||
extern std::vector<KMX_DeadkeyMapping> KMX_FDeadkeys; // I4353
|
||||
|
||||
/** @brief print (error) messages */
|
||||
void KMX_LogError(const wchar_t* fmt, ...);
|
||||
|
||||
//--------------------old
|
||||
/*
|
||||
#include <vector>
|
||||
|
||||
void LogError(PWSTR message, ...);
|
||||
|
||||
|
||||
struct DeadkeyMapping { // I4353
|
||||
WCHAR deadkey, dkid;
|
||||
UINT shift;
|
||||
WORD vk;
|
||||
};
|
||||
|
||||
extern std::vector<DeadkeyMapping> FDeadkeys; // I4353
|
||||
*/
|
||||
#endif /*MCOMPILE_H*/
|
||||
|
|
|
|||
|
|
@ -1,11 +1,31 @@
|
|||
project('keymap', 'c', 'cpp',
|
||||
project('mcompile', 'c', 'cpp',
|
||||
license: 'MIT',
|
||||
meson_version: '>=1.0')
|
||||
|
||||
gtk = dependency('gtk+-3.0', version: '>= 2.4')
|
||||
gtk = dependency('gtk+-3.0', version: '>= 2.4')
|
||||
xkb = dependency('xkbcommon')
|
||||
libxklavier = dependency('libxklavier')
|
||||
|
||||
keymap = executable(
|
||||
'keymap',
|
||||
sources: ['keymap.cpp'],
|
||||
dependencies: [gtk]
|
||||
)
|
||||
deps = [gtk, xkb,libxklavier]
|
||||
|
||||
subdir('resources')
|
||||
|
||||
cpp_files = files(
|
||||
'keymap.cpp',
|
||||
'deadkey.cpp',
|
||||
'mcompile.cpp',
|
||||
'mc_kmxfile.cpp',
|
||||
'mc_import_rules.cpp',
|
||||
'../../../common/cpp/km_u16.cpp',
|
||||
)
|
||||
|
||||
comon_include_dir = [
|
||||
include_directories('../../../common/include')
|
||||
]
|
||||
|
||||
mcompile = executable(
|
||||
'mcompile',
|
||||
sources: [cpp_files],
|
||||
dependencies: deps,
|
||||
include_directories : comon_include_dir
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue