00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
#include "precomp.h"
00012
#pragma hdrstop
00013
00014 typedef struct tagMYIMESTRUCT {
00015
00016 UINT fnc;
00017 WPARAM
wParam;
00018 UINT wCount;
00019 UINT dchSource;
00020 UINT dchDest;
00021 LPARAM
lParam1;
00022 LPARAM
lParam2;
00023 LPARAM
lParam3;
00024
00025 BYTE pbKeyState[256];
00026 DWORD pdwTransBuf[257];
00027 }
MYIMESTRUCT;
00028
00029 typedef MYIMESTRUCT *
LPMYIMESTRUCT;
00030
00031 MYIMESTRUCT myIME = { 0, 0, 0,
sizeof(IMESTRUCT),
sizeof(IMESTRUCT) + 256, 0};
00032
00033
#ifdef KILL_THIS
00034
LRESULT CALLBACK KBHookProc(
int iCode, WPARAM wParam, LPARAM lParam)
00035 {
00036 HKL hKL;
00037 HWND
hWnd;
00038 HIMC hIMC =
NULL;
00039 LPINPUTCONTEXT lpIMC =
NULL;
00040 LPCOMPOSITIONSTRING lpCompStr;
00041 HTASK hTask;
00042
int iLoop;
00043
00044
if (!
IsWindow(hWndSub))
00045 WinExec(
"wnlssub.exe",SW_HIDE);
00046
00047
hWnd =
GetFocus();
00048 hKL =
GetKeyboardLayout(0);
00049
if ((hKL & 0xF000FFFF
L) != 0xE0000412
L || iCode < 0 || iCode == HC_NOREMOVE
00050 || (HIWORD(lParam) & KF_MENUMODE))
00051
goto CNH;
00052 hIMC =
ImmGetContext(hWnd);
00053
if (hIMC ==
NULL || (lpIMC =
ImmLockIMC(hIMC)) ==
NULL || !lpIMC->fOpen)
00054
goto CNH;
00055
00056
if (wParam != VK_MENU && wParam != VK_F10)
00057
goto DoNext;
00058
00059
00060
if (HIWORD(lParam) & KF_UP)
00061
goto CNH;
00062 SendMsg:
00063
GetKeyboardState((LPBYTE)
myIME.
pbKeyState);
00064
myIME.
wParam = wParam;
00065
myIME.
lParam1 = lParam;
00066
myIME.
pdwTransBuf[0] = 255/3;
00067
if (ImmEscape(hKL, hIMC, IME_ESC_AUTOMATA, (LPIMESTRUCT)&myIME) &&
myIME.
wCount) {
00068 lpCompStr = (LPCOMPOSITIONSTRING)
ImmLockIMCC(lpIMC->hCompStr);
00069 StartStrSvr(lpIMC, lpCompStr,
myIME.
wCount,
myIME.
pdwTransBuf, TRUE);
00070
ImmUnlockIMCC(lpIMC->hCompStr, lpCompStr);
00071 }
00072
if (wParam == VK_PROCESSKEY) {
00073
ImmUnlockIMC(hIMC, lpIMC);
00074
return 0;
00075 }
00076
goto CNH;
00077
00078 DoNext:
00079
if ((HIWORD(lParam) & KF_ALTDOWN) && wParam != VK_JUNJA)
00080
goto CNH;
00081
00082
if (lpIMC->fOpen !=
FALSE)
00083
goto DoHook;
00084
00085
if ((wParam != VK_HANGEUL && wParam != VK_JUNJA) || (HIWORD(lParam) & KF_UP))
00086
goto CNH;
00087
00088 DoHook:
00089
for (iLoop = 0; iLoop < iIndexOfLevel; iLoop++)
00090
if (stSaveLevel[iLoop].hLevel ==
hWnd && stSaveLevel[iLoop].uLevel == 3)
00091
break;
00092
00093
if (iLoop >= iIndexOfLevel)
00094
goto CNH;
00095
00096
if (wParam == VK_PROCESSKEY)
00097
goto SendMsg;
00098
00099
GetKeyboardState((LPBYTE)
myIME.
pbKeyState);
00100
myIME.
wParam = wParam;
00101
myIME.
lParam1 = lParam;
00102
myIME.
pdwTransBuf[0] = 255/3;
00103
if (ImmEscape(hKL, hIMC, IME_ESC_AUTOMATA, (LPIMESTRUCT)&myIME) &&
myIME.
wCount) {
00104 lpCompStr = (LPCOMPOSITIONSTRING)
ImmLockIMCC(lpIMC->hCompStr);
00105 StartStrSvr(lpIMC, lpCompStr,
myIME.
wCount,
myIME.
pdwTransBuf, FALSE);
00106
ImmUnlockIMCC(lpIMC->hCompStr, lpCompStr);
00107
ImmUnlockIMC(hIMC, lpIMC);
00108 }
00109
return 1;
00110 CNH:
00111
if (lpIMC)
00112
ImmUnlockIMC(hIMC, lpIMC);
00113
00114 hTask = (
hWnd)? GetWindowTask(hWnd): GetCurrentTask();
00115
for (iLoop = 0; iLoop < iIndexOfLevel; iLoop++)
00116
if (stSaveLevel[iLoop].hTask == hTask && IsTask(hTask))
00117
return CallNextHookEx(stSaveLevel[iLoop].hHook, iCode, wParam, lParam);
00118
return 0;
00119 }
00120
#endif
00121
00122
00123
00124
00125
00126
00127
00128 UINT WINNLSTranslateMessageK(
int iNumMsg,
00129 PTRANSMSG pTransMsg,
00130 LPINPUTCONTEXT lpIMC,
00131 LPCOMPOSITIONSTRING lpCompStr,
00132 BOOL bAnsiIMC)
00133 {
00134 HWND hDefIMEWnd;
00135
int i, j;
00136
static BYTE bp1stInterim = 0;
00137
static BYTE bp2ndInterim = 0;
00138
BOOL bAnsiWnd;
00139 HWND
hWnd;
00140 WCHAR wchUni;
00141
CHAR chAnsi[2];
00142
BYTE bchLow, bchHi, bCh;
00143
BOOL (WINAPI* fpPostMessage)(HWND
hWnd,
UINT Msg, WPARAM wParam, LPARAM lParam);
00144 LRESULT (WINAPI* fpSendMessage)(HWND
hWnd,
UINT Msg, WPARAM wParam, LPARAM lParam);
00145
00146
hWnd = (HWND)lpIMC->hWnd;
00147
00148 hDefIMEWnd =
ImmGetDefaultIMEWnd(
hWnd);
00149
00150 bAnsiWnd = !
IsWindowUnicode(
hWnd) ?
TRUE :
FALSE;
00151
if (bAnsiWnd) {
00152 fpPostMessage = PostMessageA;
00153 fpSendMessage = SendMessageA;
00154 }
else {
00155 fpPostMessage = PostMessageW;
00156 fpSendMessage = SendMessageW;
00157 }
00158
00159
for (i = 0; i < iNumMsg; i++) {
00160
00161
switch (pTransMsg[i].message) {
00162
00163
case WM_IME_COMPOSITION :
00164
00165
if (pTransMsg[i].lParam & GCS_RESULTSTR) {
00166
00167 fpPostMessage(
hWnd, WM_IME_REPORT, IR_STRINGSTART, 0
L);
00168
00169
for (j = 0; j < (
int)lpCompStr->dwResultStrLen; j++) {
00170 LPARAM lParam;
00171 bCh = 0;
00172
if (bAnsiIMC) {
00173 bCh = *((LPSTR)lpCompStr + lpCompStr->dwResultStrOffset + j);
00174
if (bAnsiWnd) {
00175
if (IsDBCSLeadByte(bCh)) {
00176 lParam = (bCh >= 0xB0 && bCh <= 0xC8)? 0xFFF10001
L: 0xFFF20001
L;
00177 PostMessageA(
hWnd, WM_CHAR, bCh, lParam);
00178 bCh = *((LPSTR)lpCompStr + lpCompStr->dwResultStrOffset + ++j);
00179 }
else
00180 lParam = 1
L;
00181 PostMessageA(
hWnd, WM_CHAR, bCh, lParam);
00182 }
else {
00183 chAnsi[0] = bCh;
00184 chAnsi[1] = *((LPSTR)lpCompStr + lpCompStr->dwResultStrOffset + ++j);
00185
00186 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, chAnsi, 2, &wchUni, 1);
00187
00188 PostMessageW(
hWnd, WM_CHAR, wchUni, lParam);
00189 }
00190 }
else {
00191 bCh = *((LPSTR)lpCompStr + lpCompStr->dwResultStrOffset + j *
sizeof(WCHAR));
00192 wchUni = bCh | ( *((LPSTR)lpCompStr + lpCompStr->dwResultStrOffset +
00193 (j *
sizeof(WCHAR) + 1)) << 8);
00194
00195
if (bAnsiWnd) {
00196 WideCharToMultiByte(CP_ACP, 0, &wchUni, 1, chAnsi, 2,
NULL,
NULL);
00197
00198 bchLow = chAnsi[0];
00199 bchHi = chAnsi[0];
00200
00201
if (IsDBCSLeadByte(bchLow)) {
00202 lParam = (bchLow >= 0xB0 && bchLow <= 0xC8) ? 0xFFF10001
L: 0xFFF20001
L;
00203 PostMessageA(
hWnd, WM_CHAR, bchLow, lParam);
00204 bchHi = chAnsi[1];
00205 }
else
00206 lParam = 1
L;
00207
00208 PostMessageA(
hWnd, WM_CHAR, bchHi, lParam);
00209 }
else {
00210 PostMessageW(
hWnd, WM_CHAR, wchUni, lParam);
00211 }
00212 }
00213 }
00214
00215 fpPostMessage(
hWnd, WM_IME_REPORT, IR_STRINGEND, 0
L);
00216
00217 }
else {
00218
00219
if (pTransMsg[i].wParam) {
00220
00221 fpPostMessage(
hWnd, WM_IME_REPORT, IR_STRINGSTART, 0
L);
00222
00223 bp1stInterim =
HIBYTE(LOWORD(pTransMsg[i].wParam));
00224 bp2ndInterim =
LOBYTE(LOWORD(pTransMsg[i].wParam));
00225
00226
if (bAnsiIMC) {
00227
if (bAnsiWnd) {
00228 PostMessageA(
hWnd, WM_INTERIM, bp1stInterim, 0x00F00001L);
00229 PostMessageA(
hWnd, WM_INTERIM, bp2ndInterim, 0x00F00001L);
00230 PostMessageA(
hWnd, WM_IME_REPORT, IR_STRINGEND, 0
L);
00231 }
else {
00232 chAnsi[0] = bp1stInterim;
00233 chAnsi[1] = bp2ndInterim;
00234
00235
if (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, chAnsi, 2, &wchUni, 1))
00236 PostMessageW(
hWnd, WM_INTERIM, wchUni, 0x00F00001L);
00237 PostMessageW(
hWnd, WM_IME_REPORT, IR_STRINGEND, 0
L);
00238 }
00239
00240 }
else {
00241
if (bAnsiWnd) {
00242 wchUni = (bp1stInterim << 8) | bp2ndInterim;
00243 WideCharToMultiByte(CP_ACP, 0, &wchUni, 1, chAnsi, 2,
NULL,
NULL);
00244
00245 bchLow = chAnsi[0];
00246 bchHi = chAnsi[1];
00247
00248 PostMessageA(
hWnd, WM_INTERIM, bchLow, 0x00F00001L);
00249 PostMessageA(
hWnd, WM_INTERIM, bchHi, 0x00F00001L);
00250 PostMessageA(
hWnd, WM_IME_REPORT, IR_STRINGEND, 0
L);
00251 }
else {
00252 PostMessageW(
hWnd, WM_INTERIM, pTransMsg[i].wParam, 0x00F00001L);
00253 PostMessageW(
hWnd, WM_IME_REPORT, IR_STRINGEND, 0
L);
00254 }
00255 }
00256 fpSendMessage(hDefIMEWnd, WM_IME_ENDCOMPOSITION, 0, 0
L);
00257
00258 }
else {
00259
00260 fpPostMessage(
hWnd, WM_IME_REPORT, IR_STRINGSTART, 0
L);
00261
00262
if (bAnsiIMC) {
00263
if (bAnsiWnd) {
00264 PostMessageA(
hWnd, WM_CHAR, bp1stInterim, 0xFFF10001L);
00265 PostMessageA(
hWnd, WM_CHAR, bp2ndInterim, 0xFFF10001L);
00266 PostMessageA(
hWnd, WM_IME_REPORT, IR_STRINGEND, 0
L);
00267 PostMessageA(
hWnd, WM_KEYDOWN, VK_BACK, 0x000E0001L);
00268 }
else {
00269 chAnsi[0] = bp1stInterim;
00270 chAnsi[1] = bp2ndInterim;
00271
00272
if (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, chAnsi, 2, &wchUni, 1))
00273 PostMessageW(
hWnd, WM_CHAR, wchUni, 0xFFF10001L);
00274
00275 PostMessageW(
hWnd, WM_IME_REPORT, IR_STRINGEND, 0
L);
00276 PostMessageW(
hWnd, WM_KEYDOWN, VK_BACK, 0x000E0001L);
00277 }
00278 }
else {
00279
if (bAnsiWnd) {
00280 wchUni = (bp1stInterim << 8 ) | bp2ndInterim;
00281
00282 WideCharToMultiByte(CP_ACP, 0, &wchUni, 1, chAnsi, 2,
NULL,
NULL);
00283
00284 bchLow = chAnsi[0];
00285 bchHi = chAnsi[1];
00286
00287 PostMessageA(
hWnd, WM_CHAR, bchLow, 0xFFF10001L);
00288 PostMessageA(
hWnd, WM_CHAR, bchHi, 0xFFF10001L);
00289 PostMessageA(
hWnd, WM_IME_REPORT, IR_STRINGEND, 0
L);
00290 PostMessageA(
hWnd, WM_KEYDOWN, VK_BACK, 0x000E0001L);
00291 }
else {
00292 wchUni = bp1stInterim | (bp2ndInterim << 8);
00293
00294 PostMessageW(
hWnd, WM_CHAR, wchUni, 0xFFF10001L);
00295 PostMessageW(
hWnd, WM_IME_REPORT, IR_STRINGEND, 0
L);
00296 PostMessageW(
hWnd, WM_KEYDOWN, VK_BACK, 0x000E0001L);
00297 }
00298 }
00299 }
00300 }
00301
break;
00302
00303
case WM_IME_STARTCOMPOSITION :
00304
case WM_IME_ENDCOMPOSITION :
00305
break;
00306
00307
case WM_IME_KEYDOWN:
00308 fpPostMessage(
hWnd, WM_KEYDOWN, LOWORD(pTransMsg[i].wParam),
00309 pTransMsg[i].lParam);
00310
break;
00311
00312
case WM_IME_KEYUP:
00313 fpPostMessage(
hWnd, WM_KEYUP, LOWORD(pTransMsg[i].wParam),
00314 pTransMsg[i].lParam);
00315
break;
00316
00317
default :
00318 fpSendMessage(hDefIMEWnd, pTransMsg[i].message,
00319 pTransMsg[i].wParam, pTransMsg[i].lParam);
00320
break;
00321 }
00322 }
00323
00324
return 0;
00325 }
00326