1 // -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 /*------------------------------------------------------------------------------
3 UniKey - Open-source Vietnamese Keyboard
4 Copyright (C) 1998-2004 Pham Kim Long
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 --------------------------------------------------------------------------------*/
30 #include "usrkeymap.h"
34 //---- exported variables for use in UkEnginge class ----
35 UkSharedMem *pShMem = 0;
39 int UnikeyCapsLockOn = 0;
40 int UnikeyShiftPressed = 0;
41 //----------------------------------------------------
43 unsigned char UnikeyBuf[1024];
46 UkOutputType UnikeyOutput;
48 //--------------------------------------------
49 void UnikeySetInputMethod(UkInputMethod im)
51 if (im == UkTelex || im == UkVni || im == UkSimpleTelex || UkSimpleTelex2) {
52 pShMem->input.setIM(im);
55 else if (im == UkUsrIM && pShMem->usrKeyMapLoaded) {
56 //cout << "Switched to user mode\n"; //DEBUG
57 pShMem->input.setIM(pShMem->usrKeyMap);
61 //cout << "IM changed to: " << im << endl; //DEBUG
65 //--------------------------------------------
66 void UnikeySetCapsState(int shiftPressed, int CapsLockOn)
68 //UnikeyCapsAll = (shiftPressed && !CapsLockOn) || (!shiftPressed && CapsLockOn);
69 UnikeyCapsLockOn = CapsLockOn;
70 UnikeyShiftPressed = shiftPressed;
73 //--------------------------------------------
74 int UnikeySetOutputCharset(int charset)
76 pShMem->charsetId = charset;
81 //--------------------------------------------
82 void UnikeySetOptions(UnikeyOptions *pOpt)
84 pShMem->options.freeMarking = pOpt->freeMarking;
85 pShMem->options.modernStyle = pOpt->modernStyle;
86 pShMem->options.macroEnabled = pOpt->macroEnabled;
87 pShMem->options.useUnicodeClipboard = pOpt->useUnicodeClipboard;
88 pShMem->options.alwaysMacro = pOpt->alwaysMacro;
89 pShMem->options.spellCheckEnabled = pOpt->spellCheckEnabled;
90 pShMem->options.autoNonVnRestore = pOpt->autoNonVnRestore;
93 //--------------------------------------------
94 void UnikeyGetOptions(UnikeyOptions *pOpt)
96 *pOpt = pShMem->options;
99 //--------------------------------------------
100 void CreateDefaultUnikeyOptions(UnikeyOptions *pOpt)
102 pOpt->freeMarking = 1;
103 pOpt->modernStyle = 0;
104 pOpt->macroEnabled = 0;
105 pOpt->useUnicodeClipboard = 0;
106 pOpt->alwaysMacro = 0;
107 pOpt->spellCheckEnabled = 1;
108 pOpt->autoNonVnRestore = 0;
111 //--------------------------------------------
112 void UnikeyCheckKbCase(int *pShiftPressed, int *pCapsLockOn)
114 *pShiftPressed = UnikeyShiftPressed;
115 *pCapsLockOn = UnikeyCapsLockOn;
118 //--------------------------------------------
122 pShMem = new UkSharedMem;
123 pShMem->input.init();
124 pShMem->macStore.init();
126 pShMem->usrKeyMapLoaded = 0;
127 MyKbEngine.setCtrlInfo(pShMem);
128 MyKbEngine.setCheckKbCaseFunc(&UnikeyCheckKbCase);
129 UnikeySetInputMethod(UkTelex);
130 UnikeySetOutputCharset(CONV_CHARSET_XUTF8);
131 pShMem->initialized = 1;
132 CreateDefaultUnikeyOptions(&pShMem->options);
135 //--------------------------------------------
141 //--------------------------------------------
142 void UnikeyFilter(unsigned int ch)
144 UnikeyBufChars = sizeof(UnikeyBuf);
145 MyKbEngine.process(ch, UnikeyBackspaces, UnikeyBuf, UnikeyBufChars, UnikeyOutput);
148 //--------------------------------------------
149 void UnikeyPutChar(unsigned int ch)
153 UnikeyBackspaces = 0;
156 //--------------------------------------------
157 void UnikeyResetBuf()
162 //--------------------------------------------
163 void UnikeySetSingleMode()
165 MyKbEngine.setSingleMode();
168 //--------------------------------------------
169 void UnikeyBackspacePress()
171 UnikeyBufChars = sizeof(UnikeyBuf);
172 MyKbEngine.processBackspace(UnikeyBackspaces, UnikeyBuf, UnikeyBufChars, UnikeyOutput);
173 // printf("Backspaces: %d\n",UnikeyBackspaces);
176 //--------------------------------------------
177 int UnikeyLoadMacroTable(const char *fileName)
179 return pShMem->macStore.loadFromFile(fileName);
182 //--------------------------------------------
183 int UnikeyLoadUserKeyMap(const char *fileName)
185 if (UkLoadKeyMap(fileName, pShMem->usrKeyMap)) {
186 //cout << "User key map loaded!\n"; //DEBUG
187 pShMem->usrKeyMapLoaded = 1;
193 //--------------------------------------------
194 void UnikeyRestoreKeyStrokes()
196 UnikeyBufChars = sizeof(UnikeyBuf);
197 MyKbEngine.restoreKeyStrokes(UnikeyBackspaces, UnikeyBuf, UnikeyBufChars, UnikeyOutput);
200 bool UnikeyAtWordBeginning()
202 return MyKbEngine.atWordBeginning();
205 bool UnikeyLastWordIsNonVn()
207 return MyKbEngine.lastWordIsNonVn();