| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2000-2005 Pham Kim Long <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
#ifndef __UKENGINE_H |
| 8 |
#define __UKENGINE_H |
| 9 |
|
| 10 |
#include "charset.h" |
| 11 |
#include "inputproc.h" |
| 12 |
#include "mactab.h" |
| 13 |
#include "vnlexi.h" |
| 14 |
#include <functional> |
| 15 |
|
| 16 |
// This is a shared object among processes, do not put any pointer in it |
| 17 |
struct UkSharedMem { |
| 18 |
// states |
| 19 |
bool vietKey; |
| 20 |
|
| 21 |
UnikeyOptions options; |
| 22 |
UkInputProcessor input; |
| 23 |
bool usrKeyMapLoaded; |
| 24 |
int usrKeyMap[256]; |
| 25 |
int charsetId; |
| 26 |
|
| 27 |
CMacroTable macStore; |
| 28 |
}; |
| 29 |
|
| 30 |
#define MAX_UK_ENGINE 128 |
| 31 |
|
| 32 |
enum VnWordForm { vnw_nonVn, vnw_empty, vnw_c, vnw_v, vnw_cv, vnw_vc, vnw_cvc }; |
| 33 |
|
| 34 |
typedef std::function<void(int *pShiftPressed, int *pCapslockOn)> |
| 35 |
CheckKeyboardCaseCb; |
| 36 |
|
| 37 |
struct KeyBufEntry { |
| 38 |
UkKeyEvent ev; |
| 39 |
bool converted; |
| 40 |
}; |
| 41 |
|
| 42 |
class UkEngine { |
| 43 |
public: |
| 44 |
UkEngine(); |
| 45 |
void setCtrlInfo(UkSharedMem *p) { m_pCtrl = p; } |
| 46 |
|
| 47 |
void setCheckKbCaseFunc(CheckKeyboardCaseCb pFunc) { |
| 48 |
m_keyCheckFunc = pFunc; |
| 49 |
} |
| 50 |
|
| 51 |
bool atWordBeginning() const; |
| 52 |
|
| 53 |
int process(unsigned int keyCode, int &backs, unsigned char *outBuf, |
| 54 |
int &outSize, UkOutputType &outType); |
| 55 |
// just pass through without filtering |
| 56 |
void pass(int keyCode); |
| 57 |
// rebuild preedit from surrounding char |
| 58 |
void rebuildChar(VnLexiName ch, int &backs, unsigned char *outBuf, |
| 59 |
int &outSize); |
| 60 |
|
| 61 |
void setSingleMode(); |
| 62 |
|
| 63 |
int processBackspace(int &backs, unsigned char *outBuf, int &outSize, |
| 64 |
UkOutputType &outType); |
| 65 |
void reset(); |
| 66 |
int restoreKeyStrokes(int &backs, unsigned char *outBuf, int &outSize, |
| 67 |
UkOutputType &outType); |
| 68 |
|
| 69 |
// following methods must be public just to enable the use of pointers to |
| 70 |
// them they should not be called from outside. |
| 71 |
int processTone(UkKeyEvent &ev); |
| 72 |
int processRoof(UkKeyEvent &ev); |
| 73 |
int processHook(UkKeyEvent &ev); |
| 74 |
int processAppend(UkKeyEvent &ev); |
| 75 |
int appendVowel(UkKeyEvent &ev); |
| 76 |
int appendConsonnant(UkKeyEvent &ev); |
| 77 |
int processDd(UkKeyEvent &ev); |
| 78 |
int processMapChar(UkKeyEvent &ev); |
| 79 |
int processTelexW(UkKeyEvent &ev); |
| 80 |
int processEscChar(UkKeyEvent &ev); |
| 81 |
|
| 82 |
protected: |
| 83 |
static bool m_classInit; |
| 84 |
CheckKeyboardCaseCb m_keyCheckFunc; |
| 85 |
UkSharedMem *m_pCtrl; |
| 86 |
|
| 87 |
int m_changePos; |
| 88 |
int m_backs; |
| 89 |
int m_bufSize; |
| 90 |
int m_current; |
| 91 |
int m_singleMode; |
| 92 |
|
| 93 |
int m_keyBufSize; |
| 94 |
// unsigned int m_keyStrokes[MAX_UK_ENGINE]; |
| 95 |
KeyBufEntry m_keyStrokes[MAX_UK_ENGINE]; |
| 96 |
int m_keyCurrent; |
| 97 |
bool m_toEscape; |
| 98 |
|
| 99 |
// variables valid in one session |
| 100 |
unsigned char *m_pOutBuf; |
| 101 |
int *m_pOutSize; |
| 102 |
bool m_outputWritten; |
| 103 |
bool m_reverted; |
| 104 |
bool m_keyRestored; |
| 105 |
bool m_keyRestoring; |
| 106 |
UkOutputType m_outType; |
| 107 |
|
| 108 |
struct WordInfo { |
| 109 |
// info for word ending at this position |
| 110 |
VnWordForm form; |
| 111 |
int c1Offset, vOffset, c2Offset; |
| 112 |
|
| 113 |
union { |
| 114 |
VowelSeq vseq; |
| 115 |
ConSeq cseq; |
| 116 |
}; |
| 117 |
|
| 118 |
// info for current symbol |
| 119 |
int caps, tone; |
| 120 |
// canonical symbol, after caps, tone are removed |
| 121 |
// for non-Vn, vnSym == -1 |
| 122 |
VnLexiName vnSym; |
| 123 |
int keyCode; |
| 124 |
}; |
| 125 |
|
| 126 |
WordInfo m_buffer[MAX_UK_ENGINE]; |
| 127 |
|
| 128 |
int processHookWithUO(UkKeyEvent &ev); |
| 129 |
int macroMatch(UkKeyEvent &ev); |
| 130 |
void markChange(int pos); |
| 131 |
void prepareBuffer(); // make sure we have a least 10 entries available |
| 132 |
int writeOutput(unsigned char *outBuf, int &outSize); |
| 133 |
// int getSeqLength(int first, int last); |
| 134 |
int getSeqSteps(int first, int last) const; |
| 135 |
int getTonePosition(VowelSeq vs, bool terminated) const; |
| 136 |
void resetKeyBuf(); |
| 137 |
int checkEscapeVIQR(UkKeyEvent &ev); |
| 138 |
int processNoSpellCheck(UkKeyEvent &ev); |
| 139 |
int processWordEnd(UkKeyEvent &ev); |
| 140 |
void synchKeyStrokeBuffer(); |
| 141 |
bool lastWordHasVnMark() const; |
| 142 |
bool lastWordIsNonVn() const; |
| 143 |
}; |
| 144 |
|
| 145 |
void SetupUnikeyEngine(); |
| 146 |
|
| 147 |
#endif |