change ukegine so filename, resize icon
[platform/core/uifw/ise-engine-unikey.git] / ukengine / ukengine.h
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  *   unikey@gmail.com
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., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, 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     int iconShown;
38
39     UnikeyOptions options;
40     UkInputProcessor input;
41     int usrKeyMapLoaded;
42     int usrKeyMap[256];
43     int charsetId;
44
45 #if defined(WIN32)
46     UnikeySysInfo sysInfo;
47 #endif
48     CMacroTable macStore;
49 };
50
51 #define CTRL_SHIFT_SW 0
52 #define ALT_Z_SW 1
53
54 #define MAX_UK_ENGINE 128
55
56 enum VnWordForm {vnw_nonVn, vnw_empty, vnw_c, vnw_v, vnw_cv, vnw_vc, vnw_cvc};
57
58 typedef void (* CheckKeyboardCaseCb)(int *pShiftPressed, int *pCapslockOn);
59
60 struct KeyBufEntry {
61     UkKeyEvent ev;
62     bool converted;
63 };
64
65 class UkEngine
66 {
67 public:
68     UkEngine();
69     void setCtrlInfo(UkSharedMem *p)
70     {
71         m_pCtrl = p;
72     }
73
74     void setCheckKbCaseFunc(CheckKeyboardCaseCb pFunc) 
75     {
76         m_keyCheckFunc = pFunc;
77     }
78
79     bool atWordBeginning();
80
81     int process(unsigned int keyCode, int & backs, unsigned char *outBuf, int & outSize, UkOutputType & outType);
82     void pass(int keyCode); //just pass through without filtering
83     void setSingleMode();
84
85     int processBackspace(int & backs, unsigned char *outBuf, int & outSize, UkOutputType & outType);
86     void reset();
87     int restoreKeyStrokes(int & backs, unsigned char *outBuf, int & outSize, UkOutputType & outType);
88
89     //following methods must be public just to enable the use of pointers to them
90     //they should not be called from outside.
91     int processTone(UkKeyEvent & ev);
92     int processRoof(UkKeyEvent & ev);
93     int processHook(UkKeyEvent & ev);
94     int processAppend(UkKeyEvent & ev);
95     int appendVowel(UkKeyEvent & ev);
96     int appendConsonnant(UkKeyEvent & ev);
97     int processDd(UkKeyEvent & ev);
98     int processMapChar(UkKeyEvent & ev);
99     int processTelexW(UkKeyEvent & ev);
100     int processEscChar(UkKeyEvent & ev);
101     bool lastWordIsNonVn();
102
103 protected:
104     static bool m_classInit;
105     CheckKeyboardCaseCb m_keyCheckFunc;
106     UkSharedMem *m_pCtrl;
107
108     int m_changePos;
109     int m_backs;
110     int m_bufSize;
111     int m_current;
112     int m_singleMode;
113
114     int m_keyBufSize;
115     //unsigned int m_keyStrokes[MAX_UK_ENGINE];
116     KeyBufEntry m_keyStrokes[MAX_UK_ENGINE];
117     int m_keyCurrent;
118     bool m_toEscape;
119
120     //varables valid in one session
121     unsigned char *m_pOutBuf;
122     int *m_pOutSize;
123     bool m_outputWritten;
124     bool m_reverted;
125     bool m_keyRestored;
126     bool m_keyRestoring;
127     UkOutputType m_outType;
128   
129     struct WordInfo {
130         //info for word ending at this position
131         VnWordForm form;
132         int c1Offset, vOffset, c2Offset;
133
134         union {
135             VowelSeq vseq;
136             ConSeq cseq;
137         };
138
139         //info for current symbol
140         int caps, tone;
141         //canonical symbol, after caps, tone are removed
142         //for non-Vn, vnSym == -1
143         VnLexiName vnSym;
144         int keyCode;
145     };
146
147     WordInfo m_buffer[MAX_UK_ENGINE];
148
149     int processHookWithUO(UkKeyEvent & ev);
150     int macroMatch(UkKeyEvent & ev);
151     void markChange(int pos);
152     void prepareBuffer(); //make sure we have a least 10 entries available
153     int writeOutput(unsigned char *outBuf, int & outSize);
154     //int getSeqLength(int first, int last);
155     int getSeqSteps(int first, int last);
156     int getTonePosition(VowelSeq vs, bool terminated);
157     void resetKeyBuf();
158     int checkEscapeVIQR(UkKeyEvent & ev);
159     int processNoSpellCheck(UkKeyEvent & ev);
160     int processWordEnd(UkKeyEvent & ev);
161     void synchKeyStrokeBuffer();
162     bool lastWordHasVnMark();
163 };
164
165 void SetupUnikeyEngine();
166
167 #endif