Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

324 lines
13 KiB

  1. /**************************************************************************\
  2. * Module Name: ktranmsg.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * This module contains all the code for the Korean translation subroutine.
  7. *
  8. * History:
  9. * 15-Jul-1995
  10. \**************************************************************************/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. typedef struct tagMYIMESTRUCT {
  14. // This is the same as IMESTRUCT
  15. UINT fnc; // function code
  16. WPARAM wParam; // word parameter
  17. UINT wCount; // word counter
  18. UINT dchSource; // offset to pbKeyState
  19. UINT dchDest; // offset to pdwTransBuf
  20. LPARAM lParam1;
  21. LPARAM lParam2;
  22. LPARAM lParam3;
  23. // My additional buffer
  24. BYTE pbKeyState[256];
  25. DWORD pdwTransBuf[257];
  26. } MYIMESTRUCT;
  27. typedef MYIMESTRUCT *LPMYIMESTRUCT;
  28. MYIMESTRUCT myIME = { 0, 0, 0, sizeof(IMESTRUCT), sizeof(IMESTRUCT) + 256, 0};
  29. #ifdef KILL_THIS
  30. LRESULT CALLBACK KBHookProc(int iCode, WPARAM wParam, LPARAM lParam)
  31. {
  32. HKL hKL;
  33. HWND hWnd;
  34. HIMC hIMC = NULL;
  35. LPINPUTCONTEXT lpIMC = NULL;
  36. LPCOMPOSITIONSTRING lpCompStr;
  37. HTASK hTask;
  38. int iLoop;
  39. if (!IsWindow(hWndSub))
  40. WinExec("wnlssub.exe",SW_HIDE);
  41. hWnd = GetFocus();
  42. hKL = GetKeyboardLayout(0);
  43. if ((hKL & 0xF000FFFFL) != 0xE0000412L || iCode < 0 || iCode == HC_NOREMOVE
  44. || (HIWORD(lParam) & KF_MENUMODE))
  45. goto CNH;
  46. hIMC = ImmGetContext(hWnd);
  47. if (hIMC == NULL || (lpIMC = ImmLockIMC(hIMC)) == NULL || !lpIMC->fOpen)
  48. goto CNH;
  49. if (wParam != VK_MENU && wParam != VK_F10)
  50. goto DoNext;
  51. // Menu is press with interim character
  52. if (HIWORD(lParam) & KF_UP)
  53. goto CNH;
  54. SendMsg:
  55. GetKeyboardState((LPBYTE)myIME.pbKeyState);
  56. myIME.wParam = wParam;
  57. myIME.lParam1 = lParam;
  58. myIME.pdwTransBuf[0] = 255/3;
  59. if (ImmEscape(hKL, hIMC, IME_ESC_AUTOMATA, (LPIMESTRUCT)&myIME) && myIME.wCount) {
  60. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  61. StartStrSvr(lpIMC, lpCompStr, myIME.wCount, myIME.pdwTransBuf, TRUE);
  62. ImmUnlockIMCC(lpIMC->hCompStr, lpCompStr);
  63. }
  64. if (wParam == VK_PROCESSKEY) {
  65. ImmUnlockIMC(hIMC, lpIMC);
  66. return 0;
  67. }
  68. goto CNH;
  69. DoNext:
  70. if ((HIWORD(lParam) & KF_ALTDOWN) && wParam != VK_JUNJA)
  71. goto CNH;
  72. if (lpIMC->fOpen != FALSE)
  73. goto DoHook;
  74. if ((wParam != VK_HANGEUL && wParam != VK_JUNJA) || (HIWORD(lParam) & KF_UP))
  75. goto CNH;
  76. DoHook:
  77. for (iLoop = 0; iLoop < iIndexOfLevel; iLoop++)
  78. if (stSaveLevel[iLoop].hLevel == hWnd && stSaveLevel[iLoop].uLevel == 3)
  79. break;
  80. if (iLoop >= iIndexOfLevel)
  81. goto CNH;
  82. if (wParam == VK_PROCESSKEY)
  83. goto SendMsg;
  84. GetKeyboardState((LPBYTE)myIME.pbKeyState);
  85. myIME.wParam = wParam;
  86. myIME.lParam1 = lParam;
  87. myIME.pdwTransBuf[0] = 255/3;
  88. if (ImmEscape(hKL, hIMC, IME_ESC_AUTOMATA, (LPIMESTRUCT)&myIME) && myIME.wCount) {
  89. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  90. StartStrSvr(lpIMC, lpCompStr, myIME.wCount, myIME.pdwTransBuf, FALSE);
  91. ImmUnlockIMCC(lpIMC->hCompStr, lpCompStr);
  92. ImmUnlockIMC(hIMC, lpIMC);
  93. }
  94. return 1;
  95. CNH:
  96. if (lpIMC)
  97. ImmUnlockIMC(hIMC, lpIMC);
  98. hTask = (hWnd)? GetWindowTask(hWnd): GetCurrentTask();
  99. for (iLoop = 0; iLoop < iIndexOfLevel; iLoop++)
  100. if (stSaveLevel[iLoop].hTask == hTask && IsTask(hTask))
  101. return CallNextHookEx(stSaveLevel[iLoop].hHook, iCode, wParam, lParam);
  102. return 0;
  103. }
  104. #endif
  105. /**********************************************************************/
  106. /* WINNLSTranslateMessageK() */
  107. /* translate messages for 3.1 apps
  108. /* Return Value: */
  109. /* number of translated message */
  110. /**********************************************************************/
  111. UINT WINNLSTranslateMessageK(int iNumMsg,
  112. PTRANSMSG pTransMsg,
  113. LPINPUTCONTEXT lpIMC,
  114. LPCOMPOSITIONSTRING lpCompStr,
  115. BOOL bAnsiIMC)
  116. {
  117. HWND hDefIMEWnd;
  118. int i, j;
  119. static BYTE bp1stInterim = 0;
  120. static BYTE bp2ndInterim = 0;
  121. BOOL bAnsiWnd;
  122. HWND hWnd;
  123. WCHAR wchUni;
  124. CHAR chAnsi[2];
  125. BYTE bchLow, bchHi, bCh;
  126. BOOL (WINAPI* fpPostMessage)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  127. LRESULT (WINAPI* fpSendMessage)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  128. hWnd = (HWND)lpIMC->hWnd;
  129. hDefIMEWnd = ImmGetDefaultIMEWnd(hWnd);
  130. bAnsiWnd = !IsWindowUnicode(hWnd) ? TRUE : FALSE;
  131. if (bAnsiWnd) {
  132. fpPostMessage = PostMessageA;
  133. fpSendMessage = SendMessageA;
  134. } else {
  135. fpPostMessage = PostMessageW;
  136. fpSendMessage = SendMessageW;
  137. }
  138. for (i = 0; i < iNumMsg; i++) {
  139. switch (pTransMsg[i].message) {
  140. case WM_IME_COMPOSITION :
  141. if (pTransMsg[i].lParam & GCS_RESULTSTR) {
  142. fpPostMessage(hWnd, WM_IME_REPORT, IR_STRINGSTART, 0L);
  143. for (j = 0; j < (int)lpCompStr->dwResultStrLen; j++) {
  144. LPARAM lParam = 1L;
  145. bCh = 0;
  146. if (bAnsiIMC) {
  147. bCh = *((LPSTR)lpCompStr + lpCompStr->dwResultStrOffset + j);
  148. if (bAnsiWnd) {
  149. if (IsDBCSLeadByte(bCh)) {
  150. lParam = (bCh >= 0xB0 && bCh <= 0xC8)? 0xFFF10001L: 0xFFF20001L;
  151. PostMessageA(hWnd, WM_CHAR, bCh, lParam);
  152. bCh = *((LPSTR)lpCompStr + lpCompStr->dwResultStrOffset + ++j);
  153. }
  154. PostMessageA(hWnd, WM_CHAR, bCh, lParam);
  155. } else {
  156. chAnsi[0] = bCh;
  157. chAnsi[1] = *((LPSTR)lpCompStr + lpCompStr->dwResultStrOffset + ++j);
  158. MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, chAnsi, 2, &wchUni, 1);
  159. PostMessageW(hWnd, WM_CHAR, wchUni, lParam);
  160. }
  161. } else { // !bAnsiIMC
  162. bCh = *((LPSTR)lpCompStr + lpCompStr->dwResultStrOffset + j * sizeof(WCHAR));
  163. wchUni = bCh | ( *((LPSTR)lpCompStr + lpCompStr->dwResultStrOffset +
  164. (j * sizeof(WCHAR) + 1)) << 8);
  165. if (bAnsiWnd) {
  166. WideCharToMultiByte(CP_ACP, 0, &wchUni, 1, chAnsi, 2, NULL, NULL);
  167. bchLow = chAnsi[0];
  168. bchHi = chAnsi[0]; //(BYTE)chAnsi;
  169. if (IsDBCSLeadByte(bchLow)) {
  170. lParam = (bchLow >= 0xB0 && bchLow <= 0xC8) ? 0xFFF10001L: 0xFFF20001L;
  171. PostMessageA(hWnd, WM_CHAR, bchLow, lParam);
  172. bchHi = chAnsi[1];
  173. }
  174. PostMessageA(hWnd, WM_CHAR, bchHi, lParam);
  175. } else {
  176. PostMessageW(hWnd, WM_CHAR, wchUni, lParam);
  177. }
  178. }
  179. }
  180. fpPostMessage(hWnd, WM_IME_REPORT, IR_STRINGEND, 0L);
  181. } else { // !(pTransMsg[i].lParam & GCS_RESULTSTR)
  182. if (pTransMsg[i].wParam) {
  183. fpPostMessage(hWnd, WM_IME_REPORT, IR_STRINGSTART, 0L);
  184. bp1stInterim = HIBYTE(LOWORD(pTransMsg[i].wParam));
  185. bp2ndInterim = LOBYTE(LOWORD(pTransMsg[i].wParam));
  186. if (bAnsiIMC) {
  187. if (bAnsiWnd) {
  188. PostMessageA(hWnd, WM_INTERIM, bp1stInterim, 0x00F00001L);
  189. PostMessageA(hWnd, WM_INTERIM, bp2ndInterim, 0x00F00001L);
  190. PostMessageA(hWnd, WM_IME_REPORT, IR_STRINGEND, 0L);
  191. } else {
  192. chAnsi[0] = bp1stInterim;
  193. chAnsi[1] = bp2ndInterim;
  194. if (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, chAnsi, 2, &wchUni, 1))
  195. PostMessageW(hWnd, WM_INTERIM, wchUni, 0x00F00001L);
  196. PostMessageW(hWnd, WM_IME_REPORT, IR_STRINGEND, 0L);
  197. }
  198. } else {
  199. if (bAnsiWnd) {
  200. wchUni = (bp1stInterim << 8) | bp2ndInterim; //(WORD)lpdwTransKey[i*3 + 1];
  201. WideCharToMultiByte(CP_ACP, 0, &wchUni, 1, chAnsi, 2, NULL, NULL);
  202. bchLow = chAnsi[0];
  203. bchHi = chAnsi[1];
  204. PostMessageA(hWnd, WM_INTERIM, bchLow, 0x00F00001L);
  205. PostMessageA(hWnd, WM_INTERIM, bchHi, 0x00F00001L);
  206. PostMessageA(hWnd, WM_IME_REPORT, IR_STRINGEND, 0L);
  207. } else {
  208. PostMessageW(hWnd, WM_INTERIM, pTransMsg[i].wParam, 0x00F00001L);
  209. PostMessageW(hWnd, WM_IME_REPORT, IR_STRINGEND, 0L);
  210. }
  211. }
  212. fpSendMessage(hDefIMEWnd, WM_IME_ENDCOMPOSITION, 0, 0L);
  213. } else { // !pTransMsg[i].wParam
  214. fpPostMessage(hWnd, WM_IME_REPORT, IR_STRINGSTART, 0L);
  215. if (bAnsiIMC) {
  216. if (bAnsiWnd) {
  217. PostMessageA(hWnd, WM_CHAR, bp1stInterim, 0xFFF10001L);
  218. PostMessageA(hWnd, WM_CHAR, bp2ndInterim, 0xFFF10001L);
  219. PostMessageA(hWnd, WM_IME_REPORT, IR_STRINGEND, 0L);
  220. PostMessageA(hWnd, WM_KEYDOWN, VK_BACK, 0x000E0001L);
  221. } else {
  222. chAnsi[0] = bp1stInterim;
  223. chAnsi[1] = bp2ndInterim;
  224. if (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, chAnsi, 2, &wchUni, 1))
  225. PostMessageW(hWnd, WM_CHAR, wchUni, 0xFFF10001L);
  226. PostMessageW(hWnd, WM_IME_REPORT, IR_STRINGEND, 0L);
  227. PostMessageW(hWnd, WM_KEYDOWN, VK_BACK, 0x000E0001L);
  228. }
  229. } else { // !bAnsiIMC
  230. if (bAnsiWnd) {
  231. wchUni = (bp1stInterim << 8 ) | bp2ndInterim;
  232. WideCharToMultiByte(CP_ACP, 0, &wchUni, 1, chAnsi, 2, NULL, NULL);
  233. bchLow = chAnsi[0];
  234. bchHi = chAnsi[1];
  235. PostMessageA(hWnd, WM_CHAR, bchLow, 0xFFF10001L);
  236. PostMessageA(hWnd, WM_CHAR, bchHi, 0xFFF10001L);
  237. PostMessageA(hWnd, WM_IME_REPORT, IR_STRINGEND, 0L);
  238. PostMessageA(hWnd, WM_KEYDOWN, VK_BACK, 0x000E0001L);
  239. } else {
  240. wchUni = bp1stInterim | (bp2ndInterim << 8);
  241. PostMessageW(hWnd, WM_CHAR, wchUni, 0xFFF10001L);
  242. PostMessageW(hWnd, WM_IME_REPORT, IR_STRINGEND, 0L);
  243. PostMessageW(hWnd, WM_KEYDOWN, VK_BACK, 0x000E0001L);
  244. }
  245. }
  246. }
  247. }
  248. break;
  249. case WM_IME_STARTCOMPOSITION :
  250. case WM_IME_ENDCOMPOSITION :
  251. break;
  252. case WM_IME_KEYDOWN:
  253. fpPostMessage(hWnd, WM_KEYDOWN, LOWORD(pTransMsg[i].wParam),
  254. pTransMsg[i].lParam);
  255. break;
  256. case WM_IME_KEYUP:
  257. fpPostMessage(hWnd, WM_KEYUP, LOWORD(pTransMsg[i].wParam),
  258. pTransMsg[i].lParam);
  259. break;
  260. default :
  261. fpSendMessage(hDefIMEWnd, pTransMsg[i].message,
  262. pTransMsg[i].wParam, pTransMsg[i].lParam);
  263. break;
  264. }
  265. }
  266. return 0; // indicates all messages are post/sent within this function.
  267. }