Source code of Windows XP (NT5)
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.

316 lines
11 KiB

  1. /******************************************************************************
  2. *
  3. * File Name: escape.c
  4. *
  5. * - Sub function entry of ImeEscape API for Chicago-H.
  6. *
  7. * Author: Beomseok Oh (BeomOh)
  8. *
  9. * Copyright (C) Microsoft Corp 1993-1994. All rights reserved.
  10. *
  11. ******************************************************************************/
  12. // include files
  13. #include "precomp.h"
  14. // local definitions
  15. // IME_AUTOMATA subfunctions
  16. #define IMEA_INIT 0x01
  17. #define IMEA_NEXT 0x02
  18. #define IMEA_PREV 0x03
  19. // IME_MOVEIMEWINDOW
  20. #define MCW_DEFAULT 0x00
  21. #define MCW_WINDOW 0x02
  22. #define MCW_SCREEN 0x04
  23. // public data
  24. BOOL fWndOpen[3] = { TRUE, TRUE, TRUE };
  25. WORD wWndCmd[3] = { MCW_DEFAULT, MCW_DEFAULT, MCW_DEFAULT };
  26. #pragma data_seg(".text", "CODE")
  27. static BYTE Atm_table[2][95] =
  28. {
  29. { // 2 Beolsik.
  30. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* - ' */
  31. 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, /* ( - / */
  32. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0 - 7 */
  33. 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, /* 8 - ? */
  34. 0x40, 0x88, 0xBA, 0x90, 0x8D, 0xC6, 0x87, 0x94, /* @ - G */
  35. 0xAD, 0xA5, 0xA7, 0xA3, 0xBD, 0xBB, 0xB4, 0xA6, /* H - O */
  36. 0xAC, 0xCA, 0x83, 0x84, 0x8C, 0xAB, 0x93, 0xCF, /* P - W */
  37. 0x92, 0xB3, 0x91, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, /* X - _ */
  38. 0x60, 0x88, 0xBA, 0x90, 0x8D, 0x85, 0x87, 0x94, /* ` - g */
  39. 0xAD, 0xA5, 0xA7, 0xA3, 0xBD, 0xBB, 0xB4, 0xA4, /* h - o */
  40. 0xAA, 0x89, 0x82, 0x84, 0x8B, 0xAB, 0x93, 0x8E, /* p - w */
  41. 0x92, 0xB3, 0x91, 0x7B, 0x7C, 0x7D, 0x7E /* x - ~ */
  42. },
  43. { // 3 Beolsik.
  44. 0x20, 0xFD, 0x23, 0xFA, 0xEF, 0xEE, 0x37, 0xD2, /* - ' */
  45. 0x39, 0x25, 0x38, 0x2B, 0x2C, 0x2A, 0x2E, 0xAD, /* ( - / */
  46. 0x29, 0xF3, 0xF6, 0xB3, 0xAC, 0xBA, 0xA5, 0x28, /* 0 - 7 */
  47. 0xBC, 0xB4, 0x3A, 0x89, 0x2C, 0x3D, 0x2E, 0x21, /* 8 - ? */
  48. 0xF8, 0xE8, 0x3F, 0xEB, 0xEA, 0xE6, 0xE3, 0xE4, /* @ - G */
  49. 0x22, 0x35, 0x31, 0x32, 0x33, 0x30, 0x2D, 0x36, /* H - O */
  50. 0x7E, 0xFC, 0xF0, 0xE7, 0xED, 0x34, 0xEC, 0xFB, /* P - W */
  51. 0xF4, 0x27, 0xF9, 0x91, 0x5C, 0x3B, 0xA6, 0x2F, /* X - _ */
  52. 0x5D, 0xF7, 0xB4, 0xAA, 0xBD, 0xAB, 0xA3, 0xBB, /* ` - g */
  53. 0xC4, 0xC8, 0xCD, 0xC2, 0xCE, 0xD4, 0xCB, 0xD0, /* h - o */
  54. 0xD3, 0xF5, 0xA4, 0xE5, 0xA7, 0xC5, 0xAD, 0xE9, /* p - w */
  55. 0xE2, 0xC7, 0xF1, 0x7B, 0x40, 0x7D, 0x5B /* x - ~ */
  56. }
  57. };
  58. #pragma data_seg()
  59. int EscAutomata(HIMC hIMC, LPIMESTRUCT32 lpIME32, BOOL fNewFunc)
  60. {
  61. LPINPUTCONTEXT lpIMC;
  62. LPCOMPOSITIONSTRING lpCompStr;
  63. LPDWORD lpdwTransBuf;
  64. int iRet = FALSE;
  65. if (hIMC && (lpIMC = ImmLockIMC(hIMC)))
  66. {
  67. if (lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr))
  68. {
  69. if (fNewFunc)
  70. {
  71. // It's only for HWin31 IME app compatibility layer
  72. iRet = ImeProcessKey(hIMC, lpIME32->wParam,
  73. lpIME32->lParam1, (LPBYTE)lpIME32 + lpIME32->dchSource);
  74. if (iRet != FALSE)
  75. lpIME32->wCount = ImeToAsciiEx(lpIME32->wParam,
  76. HIWORD(lpIME32->lParam1), (LPBYTE)lpIME32 + lpIME32->dchSource,
  77. (LPDWORD)((LPBYTE)lpIME32 + lpIME32->dchDest), 0, hIMC);
  78. else if (lpIME32->wParam != VK_MENU)
  79. {
  80. lpIME32->wCount = 1;
  81. lpdwTransBuf = (LPDWORD)((LPBYTE)lpIME32 + lpIME32->dchDest) + 1;
  82. *lpdwTransBuf++ = (HIWORD(lpIME32->lParam1) & 0x8000)? WM_IME_KEYUP: WM_IME_KEYDOWN;
  83. *lpdwTransBuf++ = lpIME32->wParam;
  84. *lpdwTransBuf++ = lpIME32->lParam1;
  85. iRet = TRUE;
  86. }
  87. }
  88. else
  89. {
  90. switch (lpIME32->wParam)
  91. {
  92. lpIME32->dchSource = bState;
  93. case IMEA_INIT:
  94. lpCompStr->dwCompStrLen = lpCompStr->dwCompAttrLen = 0;
  95. *((LPSTR)lpCompStr + lpCompStr->dwCompAttrOffset) = 0;
  96. *((LPSTR)lpCompStr + lpCompStr->dwCompAttrOffset + 1) = 0;
  97. *((LPSTR)lpCompStr + lpCompStr->dwCompStrOffset) = 0;
  98. *((LPSTR)lpCompStr + lpCompStr->dwCompStrOffset + 1) = 0;
  99. // Initialize all Automata Variables.
  100. bState = NUL;
  101. JohabChar.w = WansungChar.w = mCho = mJung = mJong = 0;
  102. fComplete = FALSE;
  103. break;
  104. case IMEA_NEXT:
  105. HangeulAutomata(
  106. Atm_table[uCurrentInputMethod - IDD_2BEOL][lpIME32->dchSource - 0x20],
  107. NULL, lpCompStr);
  108. break;
  109. case IMEA_PREV:
  110. HangeulAutomata(0x80, NULL, lpCompStr); // 0x80 is for VK_BACK
  111. break;
  112. }
  113. iRet = TRUE;
  114. }
  115. ImmUnlockIMCC(lpIMC->hCompStr);
  116. }
  117. ImmUnlockIMC(hIMC);
  118. }
  119. return (iRet);
  120. }
  121. int EscGetOpen(HIMC hIMC, LPIMESTRUCT32 lpIME32)
  122. {
  123. int iRet = TRUE;
  124. if (lpIME32->dchSource > CAND_WINDOW)
  125. iRet = FALSE;
  126. else
  127. {
  128. iRet = fWndOpen[lpIME32->dchSource] | 0x80000000UL;
  129. lpIME32->wCount = wWndCmd[lpIME32->dchSource];
  130. switch (lpIME32->wCount)
  131. {
  132. case MCW_DEFAULT:
  133. lpIME32->lParam1 = MAKELONG(ptDefPos[lpIME32->dchSource].y,
  134. ptDefPos[lpIME32->dchSource].x);
  135. break;
  136. case MCW_SCREEN:
  137. switch (lpIME32->dchSource)
  138. {
  139. case COMP_WINDOW:
  140. lpIME32->lParam1 = MAKELONG(ptComp.y, ptComp.x);
  141. break;
  142. case STATE_WINDOW:
  143. lpIME32->lParam1 = MAKELONG(ptState.y, ptState.x);
  144. break;
  145. case CAND_WINDOW:
  146. lpIME32->lParam1 = MAKELONG(ptCand.y, ptCand.x);
  147. break;
  148. }
  149. break;
  150. case MCW_WINDOW:
  151. switch (lpIME32->dchSource)
  152. {
  153. case COMP_WINDOW:
  154. lpIME32->lParam1 = MAKELONG(ptComp.y, ptComp.x);
  155. break;
  156. case STATE_WINDOW:
  157. lpIME32->lParam1 = MAKELONG(ptState.y, ptState.x);
  158. break;
  159. case CAND_WINDOW:
  160. lpIME32->lParam1 = MAKELONG(ptCand.y, ptCand.x);
  161. break;
  162. }
  163. lpIME32->lParam1 -= lpIME32->lParam2;
  164. break;
  165. default:
  166. iRet = FALSE;
  167. }
  168. }
  169. return (iRet);
  170. }
  171. int EscHanjaMode(HIMC hIMC, LPIMESTRUCT32 lpIME32, BOOL fNewFunc)
  172. {
  173. LPTSTR lpSrc;
  174. LPINPUTCONTEXT lpIMC;
  175. LPCOMPOSITIONSTRING lpCompStr;
  176. DWORD dwCompStrLen;
  177. BYTE szCompStr[2];
  178. int iRet = FALSE;
  179. if (hIMC && (lpIMC = ImmLockIMC(hIMC)))
  180. {
  181. if (lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr))
  182. {
  183. // Keep original IMC values
  184. dwCompStrLen = lpCompStr->dwCompStrLen;
  185. szCompStr[0] = *((LPTSTR)lpCompStr + lpCompStr->dwCompStrOffset);
  186. szCompStr[1] = *((LPTSTR)lpCompStr + lpCompStr->dwCompStrOffset + 1);
  187. // Update IMC values with lpIME32
  188. lpSrc = (fNewFunc)? (LPTSTR)lpIME32 : lpSource(lpIME32);
  189. lpCompStr->dwCompStrLen = 2;
  190. *((LPTSTR)lpCompStr + lpCompStr->dwCompStrOffset) = *lpSrc;
  191. *((LPTSTR)lpCompStr + lpCompStr->dwCompStrOffset + 1) = *(lpSrc + 1);
  192. if (GenerateCandidateList(hIMC))
  193. {
  194. iRet = ImmSetConversionStatus(hIMC, lpIMC->fdwConversion | IME_CMODE_HANJACONVERT,
  195. lpIMC->fdwSentence);
  196. }
  197. else
  198. {
  199. // Restore IMC values
  200. lpCompStr->dwCompStrLen = dwCompStrLen;
  201. *((LPTSTR)lpCompStr + lpCompStr->dwCompStrOffset) = szCompStr[0];
  202. *((LPTSTR)lpCompStr + lpCompStr->dwCompStrOffset + 1) = szCompStr[1];
  203. MessageBeep(MB_ICONEXCLAMATION);
  204. }
  205. ImmUnlockIMCC(lpIMC->hCompStr);
  206. }
  207. ImmUnlockIMC(hIMC);
  208. }
  209. return (iRet);
  210. }
  211. int EscSetOpen(HIMC hIMC, LPIMESTRUCT32 lpIME32)
  212. {
  213. BOOL fTmp;
  214. LPINPUTCONTEXT lpIMC;
  215. HWND hDefIMEWnd;
  216. int iRet = TRUE;
  217. if (lpIME32->dchSource > CAND_WINDOW)
  218. iRet = FALSE;
  219. else
  220. {
  221. fTmp = fWndOpen[lpIME32->dchSource];
  222. fWndOpen[lpIME32->dchSource] = lpIME32->wParam;
  223. iRet = fTmp | 0x80000000UL;
  224. if (lpIME32->dchSource == STATE_WINDOW && hIMC && (lpIMC = ImmLockIMC(hIMC)))
  225. {
  226. hDefIMEWnd = ImmGetDefaultIMEWnd((HWND)lpIMC->hWnd);
  227. if (hDefIMEWnd)
  228. SendMessage(hDefIMEWnd, WM_IME_NOTIFY,
  229. (lpIME32->wParam)? IMN_OPENSTATUSWINDOW: IMN_CLOSESTATUSWINDOW, 0L);
  230. ImmUnlockIMC(hIMC);
  231. }
  232. }
  233. return (iRet);
  234. }
  235. int EscMoveIMEWindow(HIMC hIMC, LPIMESTRUCT32 lpIME32)
  236. {
  237. int iRet = TRUE;
  238. if (lpIME32->dchSource > CAND_WINDOW)
  239. iRet = FALSE;
  240. else
  241. {
  242. switch (wWndCmd[lpIME32->dchSource] = lpIME32->wParam)
  243. {
  244. case MCW_DEFAULT:
  245. switch (lpIME32->dchSource)
  246. {
  247. case COMP_WINDOW:
  248. ptComp.x = (ptState.x + STATEXSIZE + GAPX + COMPSIZE > rcScreen.right)?
  249. ptState.x - GAPX - COMPSIZE: ptState.x + STATEXSIZE + GAPX;
  250. ptComp.y = ptState.y + GAPY;
  251. break;
  252. case STATE_WINDOW:
  253. ptState = ptDefPos[STATE_WINDOW];
  254. break;
  255. case CAND_WINDOW:
  256. ptCand = ptDefPos[CAND_WINDOW];
  257. break;
  258. }
  259. break;
  260. case MCW_WINDOW:
  261. case MCW_SCREEN:
  262. switch (lpIME32->dchSource)
  263. {
  264. case COMP_WINDOW:
  265. ptComp.x = LOWORD(lpIME32->lParam1);
  266. ptComp.y = HIWORD(lpIME32->lParam1);
  267. break;
  268. case STATE_WINDOW:
  269. ptState.x = LOWORD(lpIME32->lParam1);
  270. ptState.y = HIWORD(lpIME32->lParam1);
  271. break;
  272. case CAND_WINDOW:
  273. ptCand.x = LOWORD(lpIME32->lParam1);
  274. ptCand.y = HIWORD(lpIME32->lParam1);
  275. break;
  276. }
  277. break;
  278. default:
  279. iRet = FALSE;
  280. }
  281. }
  282. return (iRet);
  283. }