| 1 |
// -*- mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- |
| 2 |
/* Unikey Vietnamese Input Method |
| 3 |
* Copyright (C) 2000-2005 Pham Kim Long |
| 4 |
* Contact: |
| 5 |
* [email protected] |
| 6 |
* UniKey project: http://unikey.org |
| 7 |
* |
| 8 |
* This library is free software; you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU Lesser General Public |
| 10 |
* License as published by the Free Software Foundation; either |
| 11 |
* version 2 of the License, or (at your option) any later version. |
| 12 |
* |
| 13 |
* This library is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
* Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public |
| 19 |
* License along with this library; if not, write to the |
| 20 |
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor |
| 21 |
* Boston, MA 02110-1301, USA. |
| 22 |
*/ |
| 23 |
|
| 24 |
#ifndef __UKENGINE_H |
| 25 |
#define __UKENGINE_H |
| 26 |
|
| 27 |
#include "charset.h" |
| 28 |
#include "vnlexi.h" |
| 29 |
#include "inputproc.h" |
| 30 |
#include "mactab.h" |
| 31 |
|
| 32 |
//This is a shared object among processes, do not put any pointer in it |
| 33 |
struct UkSharedMem { |
| 34 |
//states |
| 35 |
int initialized; |
| 36 |
int vietKey; |
| 37 |
|
| 38 |
UnikeyOptions options; |
| 39 |
UkInputProcessor input; |
| 40 |
int usrKeyMapLoaded; |
| 41 |
int usrKeyMap[256]; |
| 42 |
int charsetId; |
| 43 |
|
| 44 |
CMacroTable macStore; |
| 45 |
}; |
| 46 |
|
| 47 |
#define MAX_UK_ENGINE 128 |
| 48 |
|
| 49 |
enum VnWordForm {vnw_nonVn, vnw_empty, vnw_c, vnw_v, vnw_cv, vnw_vc, vnw_cvc}; |
| 50 |
|
| 51 |
typedef void (* CheckKeyboardCaseCb)(int *pShiftPressed, int *pCapslockOn); |
| 52 |
|
| 53 |
struct KeyBufEntry { |
| 54 |
UkKeyEvent ev; |
| 55 |
bool converted; |
| 56 |
}; |
| 57 |
|
| 58 |
class UkEngine |
| 59 |
{ |
| 60 |
public: |
| 61 |
UkEngine(); |
| 62 |
void setCtrlInfo(UkSharedMem *p) |
| 63 |
{ |
| 64 |
m_pCtrl = p; |
| 65 |
} |
| 66 |
|
| 67 |
void setCheckKbCaseFunc(CheckKeyboardCaseCb pFunc) |
| 68 |
{ |
| 69 |
m_keyCheckFunc = pFunc; |
| 70 |
} |
| 71 |
|
| 72 |
bool atWordBeginning(); |
| 73 |
|
| 74 |
int process(unsigned int keyCode, int & backs, unsigned char *outBuf, int & outSize, UkOutputType & outType); |
| 75 |
void pass(int keyCode); //just pass through without filtering |
| 76 |
void setSingleMode(); |
| 77 |
|
| 78 |
int processBackspace(int & backs, unsigned char *outBuf, int & outSize, UkOutputType & outType); |
| 79 |
void reset(); |
| 80 |
int restoreKeyStrokes(int & backs, unsigned char *outBuf, int & outSize, UkOutputType & outType); |
| 81 |
|
| 82 |
//following methods must be public just to enable the use of pointers to them |
| 83 |
//they should not be called from outside. |
| 84 |
int processTone(UkKeyEvent & ev); |
| 85 |
int processRoof(UkKeyEvent & ev); |
| 86 |
int processHook(UkKeyEvent & ev); |
| 87 |
int processAppend(UkKeyEvent & ev); |
| 88 |
int appendVowel(UkKeyEvent & ev); |
| 89 |
int appendConsonnant(UkKeyEvent & ev); |
| 90 |
int processDd(UkKeyEvent & ev); |
| 91 |
int processMapChar(UkKeyEvent & ev); |
| 92 |
int processTelexW(UkKeyEvent & ev); |
| 93 |
int processEscChar(UkKeyEvent & ev); |
| 94 |
|
| 95 |
protected: |
| 96 |
static bool m_classInit; |
| 97 |
CheckKeyboardCaseCb m_keyCheckFunc; |
| 98 |
UkSharedMem *m_pCtrl; |
| 99 |
|
| 100 |
int m_changePos; |
| 101 |
int m_backs; |
| 102 |
int m_bufSize; |
| 103 |
int m_current; |
| 104 |
int m_singleMode; |
| 105 |
|
| 106 |
int m_keyBufSize; |
| 107 |
//unsigned int m_keyStrokes[MAX_UK_ENGINE]; |
| 108 |
KeyBufEntry m_keyStrokes[MAX_UK_ENGINE]; |
| 109 |
int m_keyCurrent; |
| 110 |
bool m_toEscape; |
| 111 |
|
| 112 |
//varables valid in one session |
| 113 |
unsigned char *m_pOutBuf; |
| 114 |
int *m_pOutSize; |
| 115 |
bool m_outputWritten; |
| 116 |
bool m_reverted; |
| 117 |
bool m_keyRestored; |
| 118 |
bool m_keyRestoring; |
| 119 |
UkOutputType m_outType; |
| 120 |
|
| 121 |
struct WordInfo { |
| 122 |
//info for word ending at this position |
| 123 |
VnWordForm form; |
| 124 |
int c1Offset, vOffset, c2Offset; |
| 125 |
|
| 126 |
union { |
| 127 |
VowelSeq vseq; |
| 128 |
ConSeq cseq; |
| 129 |
}; |
| 130 |
|
| 131 |
//info for current symbol |
| 132 |
int caps, tone; |
| 133 |
//canonical symbol, after caps, tone are removed |
| 134 |
//for non-Vn, vnSym == -1 |
| 135 |
VnLexiName vnSym; |
| 136 |
int keyCode; |
| 137 |
}; |
| 138 |
|
| 139 |
WordInfo m_buffer[MAX_UK_ENGINE]; |
| 140 |
|
| 141 |
int processHookWithUO(UkKeyEvent & ev); |
| 142 |
int macroMatch(UkKeyEvent & ev); |
| 143 |
void markChange(int pos); |
| 144 |
void prepareBuffer(); //make sure we have a least 10 entries available |
| 145 |
int writeOutput(unsigned char *outBuf, int & outSize); |
| 146 |
//int getSeqLength(int first, int last); |
| 147 |
int getSeqSteps(int first, int last); |
| 148 |
int getTonePosition(VowelSeq vs, bool terminated); |
| 149 |
void resetKeyBuf(); |
| 150 |
int checkEscapeVIQR(UkKeyEvent & ev); |
| 151 |
int processNoSpellCheck(UkKeyEvent & ev); |
| 152 |
int processWordEnd(UkKeyEvent & ev); |
| 153 |
void synchKeyStrokeBuffer(); |
| 154 |
bool lastWordHasVnMark(); |
| 155 |
bool lastWordIsNonVn(); |
| 156 |
}; |
| 157 |
|
| 158 |
void SetupUnikeyEngine(); |
| 159 |
|
| 160 |
#endif |