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.

357 lines
12 KiB

  1. /****************************************************************************
  2. ESCAPE.CPP
  3. Owner: cslim
  4. Copyright (c) 1997-1999 Microsoft Corporation
  5. ImeEscape functions
  6. History:
  7. 14-JUL-1999 cslim Copied from IME98 source tree
  8. *****************************************************************************/
  9. #include "precomp.h"
  10. #include "ui.h"
  11. #include "debug.h"
  12. #include "hanja.h"
  13. #include "escape.h"
  14. #include "apientry.h"
  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. BOOL vfWndOpen[3] = { fTrue, fTrue, fTrue };
  24. static WORD wWndCmd[3] = { MCW_DEFAULT, MCW_DEFAULT, MCW_DEFAULT };
  25. ///////////////////////////////////////////////////////////////////////////////
  26. // IME_ESC_HANJA_MODE processing routine called by ImeEscape
  27. // Korean specific
  28. // It is for conversion from Hangul to Hanja the Input parameter (LPSTR)lpData
  29. // is filled with Hangul charactert which will be converted to Hanja.
  30. int EscHanjaMode(PCIMECtx pImeCtx, LPSTR lpIME32, BOOL fNewFunc)
  31. {
  32. LPWSTR pwchSrc;
  33. LPSTR pchSrc;
  34. WCHAR wchSrc;
  35. INT iRet = fFalse;
  36. // Update IMC values with lpIME32
  37. if (pImeCtx->IsUnicodeEnv())
  38. {
  39. pwchSrc = (fNewFunc) ? (LPWSTR)lpIME32 : GET_LPSOURCEW((LPIMESTRUCT32)lpIME32);
  40. if (pwchSrc == NULL || *pwchSrc == L'\0')
  41. {
  42. DbgAssert(0);
  43. return 0;
  44. }
  45. wchSrc = *pwchSrc;
  46. }
  47. else
  48. {
  49. pchSrc = (fNewFunc) ? (LPSTR)lpIME32 : GET_LPSOURCEA((LPIMESTRUCT32)lpIME32);
  50. if (pchSrc == NULL || *pchSrc == '\0')
  51. {
  52. DbgAssert(0);
  53. return 0;
  54. }
  55. if (MultiByteToWideChar(CP_KOREA, MB_PRECOMPOSED, pchSrc, 2, &wchSrc, 1) == 0)
  56. {
  57. return 0;
  58. }
  59. }
  60. Dbg(DBGID_Hanja, TEXT("EscHanjaMode = %04X"), wchSrc);
  61. if (GenerateHanjaCandList(pImeCtx, wchSrc))
  62. {
  63. // Set current comp str
  64. if (pImeCtx->IsUnicodeEnv())
  65. pImeCtx->SetCompBufStr(wchSrc);
  66. else
  67. pImeCtx->SetCompBufStr(*pchSrc, *(pchSrc+1));
  68. // Change to Hanja conv mode
  69. iRet = OurImmSetConversionStatus(pImeCtx->GetHIMC(), pImeCtx->GetConversionMode() | IME_CMODE_HANJACONVERT,
  70. pImeCtx->GetSentenceMode());
  71. }
  72. else // if failed to convert
  73. {
  74. MessageBeep(MB_ICONEXCLAMATION);
  75. }
  76. Dbg(DBGID_Hanja, TEXT("EscHanjaMode return = %d"), iRet);
  77. return (iRet);
  78. }
  79. INT EscGetOpen(PCIMECtx pIMECtx, LPIMESTRUCT32 lpIME32)
  80. {
  81. LPIMEDATA lpImeData = pIMECtx->GetGDataRaw();
  82. INT iRet = fTrue;
  83. if (lpImeData == NULL)
  84. return fFalse;
  85. if (lpIME32->dchSource > CAND_WINDOW)
  86. iRet = fFalse;
  87. else
  88. {
  89. iRet = vfWndOpen[lpIME32->dchSource] | 0x80000000UL;
  90. lpIME32->wCount = wWndCmd[lpIME32->dchSource];
  91. switch (lpIME32->wCount)
  92. {
  93. case MCW_DEFAULT:
  94. switch (lpIME32->dchSource)
  95. {
  96. case COMP_WINDOW:
  97. lpIME32->lParam1 = MAKELONG(lpImeData->ptStatusPos.y,
  98. (lpImeData->ptStatusPos.x+lpImeData->xStatusWi+UI_GAPX + COMP_SIZEX > lpImeData->rcWorkArea.right) ?
  99. lpImeData->ptStatusPos.x - UI_GAPX - COMP_SIZEX : lpImeData->ptStatusPos.x + lpImeData->xStatusWi + UI_GAPX);
  100. break;
  101. case STATE_WINDOW:
  102. lpIME32->lParam1 = MAKELONG(lpImeData->rcWorkArea.bottom - lpImeData->yStatusHi,
  103. lpImeData->rcWorkArea.right - lpImeData->xStatusWi);
  104. break;
  105. case CAND_WINDOW:
  106. lpIME32->lParam1 = MAKELONG(lpImeData->rcWorkArea.bottom - lpImeData->yCandHi,
  107. lpImeData->rcWorkArea.right - lpImeData->xCandWi);
  108. break;
  109. }
  110. break;
  111. case MCW_SCREEN:
  112. switch (lpIME32->dchSource)
  113. {
  114. case COMP_WINDOW:
  115. lpIME32->lParam1 = MAKELONG(lpImeData->ptCompPos.y, lpImeData->ptCompPos.x);
  116. break;
  117. case STATE_WINDOW:
  118. lpIME32->lParam1 = MAKELONG(lpImeData->ptStatusPos.y, lpImeData->ptStatusPos.x);
  119. break;
  120. case CAND_WINDOW:
  121. lpIME32->lParam1 = MAKELONG(lpImeData->rcWorkArea.bottom - lpImeData->yCandHi,
  122. lpImeData->rcWorkArea.right - lpImeData->xCandWi);
  123. break;
  124. }
  125. break;
  126. case MCW_WINDOW:
  127. switch (lpIME32->dchSource)
  128. {
  129. case COMP_WINDOW:
  130. lpIME32->lParam1 = MAKELONG(lpImeData->ptCompPos.y, lpImeData->ptCompPos.x);
  131. break;
  132. case STATE_WINDOW:
  133. lpIME32->lParam1 = MAKELONG(lpImeData->ptStatusPos.y, lpImeData->ptStatusPos.x);
  134. break;
  135. case CAND_WINDOW:
  136. lpIME32->lParam1 = MAKELONG(lpImeData->rcWorkArea.bottom - lpImeData->yCandHi,
  137. lpImeData->rcWorkArea.right - lpImeData->xCandWi);
  138. break;
  139. }
  140. lpIME32->lParam1 -= lpIME32->lParam2;
  141. break;
  142. default:
  143. iRet = fFalse;
  144. }
  145. }
  146. return (iRet);
  147. }
  148. INT EscSetOpen(PCIMECtx pIMECtx, LPIMESTRUCT32 lpIME32)
  149. {
  150. BOOL fTmp;
  151. HWND hDefIMEWnd;
  152. INT iRet = fTrue;
  153. if (lpIME32->dchSource > CAND_WINDOW)
  154. iRet = fFalse;
  155. else
  156. {
  157. fTmp = vfWndOpen[lpIME32->dchSource];
  158. vfWndOpen[lpIME32->dchSource] = lpIME32->wParam;
  159. iRet = fTmp | 0x80000000UL;
  160. if (lpIME32->dchSource == STATE_WINDOW)
  161. {
  162. hDefIMEWnd = OurImmGetDefaultIMEWnd(pIMECtx->GetAppWnd());
  163. if (hDefIMEWnd)
  164. OurSendMessage(hDefIMEWnd, WM_IME_NOTIFY,
  165. (lpIME32->wParam)? IMN_OPENSTATUSWINDOW: IMN_CLOSESTATUSWINDOW, 0L);
  166. }
  167. }
  168. return (iRet);
  169. }
  170. INT EscMoveIMEWindow(PCIMECtx pIMECtx, LPIMESTRUCT32 lpIME32)
  171. {
  172. LPIMEDATA pImeData = pIMECtx->GetGDataRaw();
  173. INT iRet = fTrue;
  174. if (pImeData == NULL)
  175. return fFalse;
  176. if (lpIME32->dchSource > CAND_WINDOW)
  177. iRet = fFalse;
  178. else
  179. {
  180. switch (wWndCmd[lpIME32->dchSource] = lpIME32->wParam)
  181. {
  182. case MCW_DEFAULT:
  183. switch (lpIME32->dchSource)
  184. {
  185. case COMP_WINDOW:
  186. pImeData->ptCompPos.x = (pImeData->ptStatusPos.x+pImeData->xStatusWi+UI_GAPX + COMP_SIZEX > pImeData->rcWorkArea.right) ?
  187. pImeData->ptStatusPos.x - UI_GAPX - COMP_SIZEX : pImeData->ptStatusPos.x + pImeData->xStatusWi + UI_GAPX;
  188. pImeData->ptCompPos.y = pImeData->ptStatusPos.y;
  189. break;
  190. case STATE_WINDOW:
  191. pImeData->ptStatusPos.x = pImeData->rcWorkArea.right - pImeData->xStatusWi;
  192. pImeData->ptStatusPos.y = pImeData->rcWorkArea.bottom - pImeData->yStatusHi;
  193. break;
  194. case CAND_WINDOW:
  195. //pImeData->ptCandPos.x = pImeData->rcWorkArea.right - pImeData->xCandWi;
  196. //pImeData->ptCandPos.y = pImeData->rcWorkArea.bottom - pImeData->yCandHi;
  197. break;
  198. }
  199. break;
  200. case MCW_WINDOW:
  201. case MCW_SCREEN:
  202. switch (lpIME32->dchSource)
  203. {
  204. case COMP_WINDOW:
  205. pImeData->ptCompPos.x = LOWORD(lpIME32->lParam1);
  206. pImeData->ptCompPos.y = HIWORD(lpIME32->lParam1);
  207. break;
  208. case STATE_WINDOW:
  209. pImeData->ptStatusPos.x = LOWORD(lpIME32->lParam1);
  210. pImeData->ptStatusPos.y = HIWORD(lpIME32->lParam1);
  211. break;
  212. case CAND_WINDOW:
  213. //pImeData->ptCandPos.x = LOWORD(lpIME32->lParam1);
  214. //pImeData->ptCandPos.y = HIWORD(lpIME32->lParam1);
  215. break;
  216. }
  217. break;
  218. default:
  219. iRet = fFalse;
  220. }
  221. }
  222. return (iRet);
  223. }
  224. INT EscAutomata(PCIMECtx pIMECtx, LPIMESTRUCT32 lpIME32, BOOL fNewFunc)
  225. {
  226. // LPCOMPOSITIONSTRING lpCompStr;
  227. INT iRet = fFalse;
  228. WCHAR wcCur;
  229. Dbg(DBGID_Automata, TEXT("EscAutomata: fNewFunc=%d, lpIME32->wParam=%04X, lpIME32->lParam1=0x%08X, lpIME32->lParam2=0x%08X, lpIME32->lParam3=0x%08X"), fNewFunc, lpIME32->wParam, lpIME32->lParam1, lpIME32->lParam2, lpIME32->lParam3 );
  230. if (fNewFunc)
  231. {
  232. iRet = ImeProcessKey(pIMECtx->GetHIMC(), lpIME32->wParam,
  233. lpIME32->lParam1, (LPBYTE)lpIME32 + (INT_PTR)lpIME32->dchSource);
  234. if (iRet)
  235. {
  236. lpIME32->wCount = (WORD)ImeToAsciiEx(lpIME32->wParam,
  237. HIWORD(lpIME32->lParam1), (LPBYTE)lpIME32 + lpIME32->dchSource,
  238. (LPTRANSMSGLIST)((LPBYTE)lpIME32 + (INT_PTR)lpIME32->dchDest), 0, pIMECtx->GetHIMC());
  239. }
  240. else
  241. if (lpIME32->wParam != VK_MENU)
  242. {
  243. LPTRANSMSGLIST lpTransBuf;
  244. LPTRANSMSG lpTransMsg;
  245. lpIME32->wCount = 1;
  246. lpTransBuf = (LPTRANSMSGLIST)((LPBYTE)lpIME32 + (INT_PTR)lpIME32->dchDest);
  247. if (lpTransBuf)
  248. {
  249. lpTransMsg = lpTransBuf->TransMsg;
  250. SetTransBuffer(lpTransMsg, (HIWORD(lpIME32->lParam1) & 0x8000)? WM_IME_KEYUP: WM_IME_KEYDOWN, lpIME32->wParam, lpIME32->lParam1);
  251. lpTransMsg++;
  252. }
  253. iRet = fTrue;
  254. }
  255. }
  256. else
  257. {
  258. CHangulAutomata *pAutoMata = pIMECtx->GetAutomata();
  259. DbgAssert(pAutoMata != NULL);
  260. if (pAutoMata == NULL)
  261. {
  262. return fFalse;
  263. }
  264. // It's only for HWin31 IME app compatibility layer
  265. switch (lpIME32->wParam)
  266. {
  267. //lpIME32->dchSource = bState;
  268. case IMEA_INIT:
  269. pIMECtx->ClearCompositionStrBuffer();
  270. break;
  271. case IMEA_NEXT:
  272. //HangeulAutomata(
  273. // Atm_table[uCurrentInputMethod - IDD_2BEOL][lpIME32->dchSource - 0x20],
  274. // NULL, lpCompStr);
  275. DbgAssert(0);
  276. break;
  277. case IMEA_PREV:
  278. //HangeulAutomata(0x80, NULL, lpCompStr); // 0x80 is for VK_BACK
  279. pAutoMata->BackSpace();
  280. wcCur = pAutoMata->GetCompositionChar();
  281. if (pIMECtx->GetGData() && pIMECtx->GetGData()->GetJasoDel() == fFalse)
  282. {
  283. pAutoMata->InitState();
  284. wcCur = 0;
  285. }
  286. if (wcCur)
  287. {
  288. pIMECtx->SetCompositionStr(wcCur);
  289. pIMECtx->StoreComposition();
  290. }
  291. else
  292. pIMECtx->ClearCompositionStrBuffer();
  293. break;
  294. }
  295. iRet = fTrue;
  296. }
  297. return (iRet);
  298. }
  299. int EscGetIMEKeyLayout(PCIMECtx pIMECtx, LPIMESTRUCT32 lpIME32)
  300. {
  301. if (pIMECtx->GetGData() == NULL)
  302. return fFalse;
  303. else
  304. lpIME32->lParam1 = (LONG)(pIMECtx->GetGData()->GetCurrentBeolsik());
  305. return fTrue;
  306. }