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.

1534 lines
45 KiB

  1. /*++
  2. Copyright (c) 1990-1999 Microsoft Corporation, All Rights Reserved
  3. Module Name:
  4. ui.c
  5. ++*/
  6. #include <windows.h>
  7. #include <immdev.h>
  8. #include <imedefs.h>
  9. #include <regstr.h>
  10. /**********************************************************************/
  11. /* CMenuDestryed() */
  12. /**********************************************************************/
  13. void PASCAL CMenuDestroyed( // context menu window
  14. // already destroyed
  15. HWND hUIWnd)
  16. {
  17. HGLOBAL hUIPrivate;
  18. LPUIPRIV lpUIPrivate;
  19. hUIPrivate = (HGLOBAL)GetWindowLongPtr(hUIWnd, IMMGWLP_PRIVATE);
  20. if (!hUIPrivate) {
  21. return;
  22. }
  23. lpUIPrivate = (LPUIPRIV)GlobalLock(hUIPrivate);
  24. if (!lpUIPrivate) {
  25. return;
  26. }
  27. lpUIPrivate->hCMenuWnd = NULL;
  28. GlobalUnlock(hUIPrivate);
  29. }
  30. /**********************************************************************/
  31. /* SoftkeyMenuDestroyed() */
  32. /**********************************************************************/
  33. void PASCAL SoftkeyMenuDestroyed( // context menu window
  34. // already destroyed
  35. HWND hUIWnd)
  36. {
  37. HGLOBAL hUIPrivate;
  38. LPUIPRIV lpUIPrivate;
  39. hUIPrivate = (HGLOBAL)GetWindowLongPtr(hUIWnd, IMMGWLP_PRIVATE);
  40. if (!hUIPrivate) {
  41. return;
  42. }
  43. lpUIPrivate = (LPUIPRIV)GlobalLock(hUIPrivate);
  44. if (!lpUIPrivate) {
  45. return;
  46. }
  47. lpUIPrivate->hSoftkeyMenuWnd = NULL;
  48. GlobalUnlock(hUIPrivate);
  49. }
  50. /**********************************************************************/
  51. /* CreateUIWindow() */
  52. /**********************************************************************/
  53. void PASCAL CreateUIWindow( // create composition window
  54. HWND hUIWnd)
  55. {
  56. HGLOBAL hUIPrivate;
  57. // create storage for UI setting
  58. hUIPrivate = GlobalAlloc(GHND, sizeof(UIPRIV));
  59. if (!hUIPrivate) {
  60. return;
  61. }
  62. SetWindowLongPtr(hUIWnd, IMMGWLP_PRIVATE, (LONG_PTR)hUIPrivate);
  63. // set the default position for UI window, it is hide now
  64. SetWindowPos(hUIWnd, NULL, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOZORDER);
  65. ShowWindow(hUIWnd, SW_SHOWNOACTIVATE);
  66. return;
  67. }
  68. /**********************************************************************/
  69. /* DestroyUIWindow() */
  70. /**********************************************************************/
  71. void PASCAL DestroyUIWindow( // destroy composition window
  72. HWND hUIWnd)
  73. {
  74. HGLOBAL hUIPrivate;
  75. LPUIPRIV lpUIPrivate;
  76. hUIPrivate = (HGLOBAL)GetWindowLongPtr(hUIWnd, IMMGWLP_PRIVATE);
  77. if (!hUIPrivate) {
  78. return;
  79. }
  80. lpUIPrivate = (LPUIPRIV)GlobalLock(hUIPrivate);
  81. if (!lpUIPrivate) {
  82. return;
  83. }
  84. //destroy ContextMenuWnd
  85. if (lpUIPrivate->hCMenuWnd) {
  86. SetWindowLongPtr(lpUIPrivate->hCMenuWnd, CMENU_HUIWND,(LONG_PTR)0);
  87. PostMessage(lpUIPrivate->hCMenuWnd, WM_USER_DESTROY, 0, 0);
  88. }
  89. //destroy SoftkeyMenuWnd
  90. if (lpUIPrivate->hSoftkeyMenuWnd) {
  91. SetWindowLongPtr(lpUIPrivate->hSoftkeyMenuWnd, SOFTKEYMENU_HUIWND,(LONG_PTR)0);
  92. PostMessage(lpUIPrivate->hSoftkeyMenuWnd, WM_USER_DESTROY, 0, 0);
  93. }
  94. // composition window need to be destroyed
  95. if (lpUIPrivate->hCompWnd) {
  96. DestroyWindow(lpUIPrivate->hCompWnd);
  97. }
  98. // candidate window need to be destroyed
  99. if (lpUIPrivate->hCandWnd) {
  100. DestroyWindow(lpUIPrivate->hCandWnd);
  101. }
  102. // status window need to be destroyed
  103. if (lpUIPrivate->hStatusWnd) {
  104. DestroyWindow(lpUIPrivate->hStatusWnd);
  105. }
  106. // soft keyboard window need to be destroyed
  107. if (lpUIPrivate->hSoftKbdWnd) {
  108. ImmDestroySoftKeyboard(lpUIPrivate->hSoftKbdWnd);
  109. }
  110. GlobalUnlock(hUIPrivate);
  111. // free storage for UI settings
  112. GlobalFree(hUIPrivate);
  113. return;
  114. }
  115. /**********************************************************************/
  116. /* ShowSoftKbd */
  117. /**********************************************************************/
  118. void PASCAL ShowSoftKbd( // Show the soft keyboard window
  119. HWND hUIWnd,
  120. int nShowSoftKbdCmd,
  121. LPPRIVCONTEXT lpImcP)
  122. {
  123. HGLOBAL hUIPrivate;
  124. LPUIPRIV lpUIPrivate;
  125. hUIPrivate = (HGLOBAL)GetWindowLongPtr(hUIWnd, IMMGWLP_PRIVATE);
  126. if (!hUIPrivate) { // can not darw status window
  127. return;
  128. }
  129. lpUIPrivate = (LPUIPRIV)GlobalLock(hUIPrivate);
  130. if (!lpUIPrivate) { // can not draw status window
  131. return;
  132. }
  133. CheckMenuItem(lpImeL->hSKMenu, IDM_SKL1, MF_UNCHECKED);
  134. CheckMenuItem(lpImeL->hSKMenu, IDM_SKL2, MF_UNCHECKED);
  135. CheckMenuItem(lpImeL->hSKMenu, IDM_SKL3, MF_UNCHECKED);
  136. CheckMenuItem(lpImeL->hSKMenu, IDM_SKL4, MF_UNCHECKED);
  137. CheckMenuItem(lpImeL->hSKMenu, IDM_SKL5, MF_UNCHECKED);
  138. CheckMenuItem(lpImeL->hSKMenu, IDM_SKL6, MF_UNCHECKED);
  139. CheckMenuItem(lpImeL->hSKMenu, IDM_SKL7, MF_UNCHECKED);
  140. CheckMenuItem(lpImeL->hSKMenu, IDM_SKL8, MF_UNCHECKED);
  141. CheckMenuItem(lpImeL->hSKMenu, IDM_SKL9, MF_UNCHECKED);
  142. CheckMenuItem(lpImeL->hSKMenu, IDM_SKL10, MF_UNCHECKED);
  143. CheckMenuItem(lpImeL->hSKMenu, IDM_SKL11, MF_UNCHECKED);
  144. CheckMenuItem(lpImeL->hSKMenu, IDM_SKL12, MF_UNCHECKED);
  145. CheckMenuItem(lpImeL->hSKMenu, IDM_SKL13, MF_UNCHECKED);
  146. if (!lpUIPrivate->hSoftKbdWnd) {
  147. // not in show status window mode
  148. } else if (lpUIPrivate->nShowSoftKbdCmd != nShowSoftKbdCmd) {
  149. ImmShowSoftKeyboard(lpUIPrivate->hSoftKbdWnd, nShowSoftKbdCmd);
  150. lpUIPrivate->nShowSoftKbdCmd = nShowSoftKbdCmd;
  151. }
  152. GlobalUnlock(hUIPrivate);
  153. return;
  154. }
  155. /**********************************************************************/
  156. /* CheckSoftKbdPosition() */
  157. /**********************************************************************/
  158. void PASCAL CheckSoftKbdPosition(
  159. LPUIPRIV lpUIPrivate,
  160. LPINPUTCONTEXT lpIMC)
  161. {
  162. #ifndef MUL_MONITOR
  163. UINT fPortionBits = 0;
  164. UINT fPortionTest;
  165. int xPortion, yPortion, nPortion;
  166. RECT rcWnd;
  167. // portion of dispaly
  168. // 0 1
  169. // 2 3
  170. if (lpUIPrivate->hCompWnd) {
  171. GetWindowRect(lpUIPrivate->hCompWnd, &rcWnd);
  172. if (rcWnd.left > sImeG.rcWorkArea.right / 2) {
  173. xPortion = 1;
  174. } else {
  175. xPortion = 0;
  176. }
  177. if (rcWnd.top > sImeG.rcWorkArea.bottom / 2) {
  178. yPortion = 1;
  179. } else {
  180. yPortion = 0;
  181. }
  182. fPortionBits |= 0x0001 << (yPortion * 2 + xPortion);
  183. }
  184. if (lpUIPrivate->hStatusWnd) {
  185. GetWindowRect(lpUIPrivate->hStatusWnd, &rcWnd);
  186. if (rcWnd.left > sImeG.rcWorkArea.right / 2) {
  187. xPortion = 1;
  188. } else {
  189. xPortion = 0;
  190. }
  191. if (rcWnd.top > sImeG.rcWorkArea.bottom / 2) {
  192. yPortion = 1;
  193. } else {
  194. yPortion = 0;
  195. }
  196. fPortionBits |= 0x0001 << (yPortion * 2 + xPortion);
  197. }
  198. GetWindowRect(lpUIPrivate->hSoftKbdWnd, &rcWnd);
  199. // start from portion 3
  200. for (nPortion = 3, fPortionTest = 0x0008; fPortionTest;
  201. nPortion--, fPortionTest >>= 1) {
  202. if (fPortionTest & fPortionBits) {
  203. // someone here!
  204. continue;
  205. }
  206. if (nPortion % 2) {
  207. lpIMC->ptSoftKbdPos.x = sImeG.rcWorkArea.right -
  208. (rcWnd.right - rcWnd.left) - UI_MARGIN;
  209. } else {
  210. lpIMC->ptSoftKbdPos.x = sImeG.rcWorkArea.left;
  211. }
  212. if (nPortion / 2) {
  213. lpIMC->ptSoftKbdPos.y = sImeG.rcWorkArea.bottom -
  214. (rcWnd.bottom - rcWnd.top) - UI_MARGIN;
  215. } else {
  216. lpIMC->ptSoftKbdPos.y = sImeG.rcWorkArea.top;
  217. }
  218. lpIMC->fdwInit |= INIT_SOFTKBDPOS;
  219. break;
  220. }
  221. #else //MUL_MONITOR
  222. RECT rcWorkArea, rcWnd;
  223. GetWindowRect(lpUIPrivate->hSoftKbdWnd, &rcWnd);
  224. rcWorkArea = ImeMonitorWorkAreaFromWindow(lpIMC->hWnd);
  225. lpIMC->ptSoftKbdPos.x = rcWorkArea.right -
  226. (rcWnd.right-rcWnd.left)-UI_MARGIN;
  227. lpIMC->ptSoftKbdPos.y = rcWorkArea.bottom -
  228. (rcWnd.bottom-rcWnd.top)-UI_MARGIN;
  229. #endif
  230. return;
  231. }
  232. /**********************************************************************/
  233. /* SetSoftKbdData() */
  234. /**********************************************************************/
  235. void PASCAL SetSoftKbdData(
  236. HWND hSoftKbdWnd,
  237. LPINPUTCONTEXT lpIMC)
  238. {
  239. int i;
  240. LPSOFTKBDDATA lpSoftKbdData;
  241. LPPRIVCONTEXT lpImcP;
  242. HGLOBAL hsSoftKbdData;
  243. lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
  244. if (!lpImcP) {
  245. return;
  246. }
  247. hsSoftKbdData = GlobalAlloc(GHND, sizeof(SOFTKBDDATA) * 2);
  248. if (!hsSoftKbdData) {
  249. ImmUnlockIMCC(lpIMC->hPrivate);
  250. return;
  251. }
  252. lpSoftKbdData = (LPSOFTKBDDATA)GlobalLock(hsSoftKbdData);
  253. if (!lpSoftKbdData) { // can not draw soft keyboard window
  254. ImmUnlockIMCC(lpIMC->hPrivate);
  255. return;
  256. }
  257. lpSoftKbdData->uCount = 2;
  258. for (i = 0; i < 48; i++) {
  259. BYTE bVirtKey;
  260. bVirtKey = VirtKey48Map[i];
  261. if (!bVirtKey) {
  262. continue;
  263. }
  264. {
  265. WORD CHIByte, CLOByte;
  266. #ifdef UNICODE
  267. lpSoftKbdData->wCode[0][bVirtKey] = SKLayout[lpImeL->dwSKWant][i];
  268. lpSoftKbdData->wCode[1][bVirtKey] = SKLayoutS[lpImeL->dwSKWant][i];
  269. #else
  270. CHIByte = SKLayout[lpImeL->dwSKWant][i*2] & 0x00ff;
  271. CLOByte = SKLayout[lpImeL->dwSKWant][i*2 + 1] & 0x00ff;
  272. lpSoftKbdData->wCode[0][bVirtKey] = (CHIByte << 8) | CLOByte;
  273. CHIByte = SKLayoutS[lpImeL->dwSKWant][i*2] & 0x00ff;
  274. CLOByte = SKLayoutS[lpImeL->dwSKWant][i*2 + 1] & 0x00ff;
  275. lpSoftKbdData->wCode[1][bVirtKey] = (CHIByte << 8) | CLOByte;
  276. #endif
  277. }
  278. }
  279. SendMessage(hSoftKbdWnd, WM_IME_CONTROL, IMC_SETSOFTKBDDATA,
  280. (LPARAM)lpSoftKbdData);
  281. GlobalUnlock(hsSoftKbdData);
  282. // free storage for UI settings
  283. GlobalFree(hsSoftKbdData);
  284. ImmUnlockIMCC(lpIMC->hPrivate);
  285. return;
  286. }
  287. /**********************************************************************/
  288. /* UpdateSoftKbd() */
  289. /**********************************************************************/
  290. void PASCAL UpdateSoftKbd(
  291. HWND hUIWnd)
  292. {
  293. HIMC hIMC;
  294. LPINPUTCONTEXT lpIMC;
  295. LPPRIVCONTEXT lpImcP;
  296. HGLOBAL hUIPrivate;
  297. LPUIPRIV lpUIPrivate;
  298. hIMC = (HIMC)GetWindowLongPtr(hUIWnd, IMMGWLP_IMC);
  299. if (!hIMC) {
  300. return;
  301. }
  302. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  303. if (!lpIMC) {
  304. return;
  305. }
  306. hUIPrivate = (HGLOBAL)GetWindowLongPtr(hUIWnd, IMMGWLP_PRIVATE);
  307. if (!hUIPrivate) { // can not darw soft keyboard window
  308. ImmUnlockIMC(hIMC);
  309. return;
  310. }
  311. lpUIPrivate = (LPUIPRIV)GlobalLock(hUIPrivate);
  312. if (!lpUIPrivate) { // can not draw soft keyboard window
  313. ImmUnlockIMC(hIMC);
  314. return;
  315. }
  316. lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
  317. if (!lpImcP) {
  318. GlobalUnlock(hUIPrivate);
  319. ImmUnlockIMC(hIMC);
  320. return;
  321. }
  322. if (!(lpIMC->fdwConversion & IME_CMODE_SOFTKBD)) {
  323. if (lpUIPrivate->hSoftKbdWnd) {
  324. ImmDestroySoftKeyboard(lpUIPrivate->hSoftKbdWnd);
  325. lpUIPrivate->hSoftKbdWnd = NULL;
  326. }
  327. lpUIPrivate->nShowSoftKbdCmd = SW_HIDE;
  328. } else if (!lpIMC->fOpen) {
  329. if (lpUIPrivate->nShowSoftKbdCmd != SW_HIDE) {
  330. ShowSoftKbd(hUIWnd, SW_HIDE, NULL);
  331. }
  332. } else {
  333. if (!lpUIPrivate->hSoftKbdWnd) {
  334. // create soft keyboard
  335. lpUIPrivate->hSoftKbdWnd =
  336. ImmCreateSoftKeyboard(SOFTKEYBOARD_TYPE_C1, hUIWnd,
  337. 0, 0);
  338. }
  339. if (!(lpIMC->fdwInit & INIT_SOFTKBDPOS)) {
  340. CheckSoftKbdPosition(lpUIPrivate, lpIMC);
  341. }
  342. SetSoftKbdData(lpUIPrivate->hSoftKbdWnd, lpIMC);
  343. lpUIPrivate->fdwSetContext |= ISC_SHOW_SOFTKBD;
  344. if (lpUIPrivate->nShowSoftKbdCmd == SW_HIDE) {
  345. SetWindowPos(lpUIPrivate->hSoftKbdWnd, NULL,
  346. lpIMC->ptSoftKbdPos.x, lpIMC->ptSoftKbdPos.y,
  347. 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
  348. // only show, if the application want to show it
  349. if (lpUIPrivate->fdwSetContext & ISC_SHOW_SOFTKBD) {
  350. ShowSoftKbd(hUIWnd, SW_SHOWNOACTIVATE, lpImcP);
  351. }
  352. }
  353. }
  354. ImmUnlockIMCC(lpIMC->hPrivate);
  355. GlobalUnlock(hUIPrivate);
  356. ImmUnlockIMC(hIMC);
  357. return;
  358. }
  359. /**********************************************************************/
  360. /* SoftKbdDestryed() */
  361. /**********************************************************************/
  362. void PASCAL SoftKbdDestroyed( // soft keyboard window
  363. // already destroyed
  364. HWND hUIWnd)
  365. {
  366. HGLOBAL hUIPrivate;
  367. LPUIPRIV lpUIPrivate;
  368. hUIPrivate = (HGLOBAL)GetWindowLongPtr(hUIWnd, IMMGWLP_PRIVATE);
  369. if (!hUIPrivate) {
  370. return;
  371. }
  372. lpUIPrivate = (LPUIPRIV)GlobalLock(hUIPrivate);
  373. if (!lpUIPrivate) {
  374. return;
  375. }
  376. lpUIPrivate->hSoftKbdWnd = NULL;
  377. GlobalUnlock(hUIPrivate);
  378. }
  379. /**********************************************************************/
  380. /* StatusWndMsg() */
  381. /**********************************************************************/
  382. void PASCAL StatusWndMsg( // set the show hide state and
  383. HWND hUIWnd,
  384. BOOL fOn)
  385. {
  386. HGLOBAL hUIPrivate;
  387. HIMC hIMC;
  388. HWND hStatusWnd;
  389. register LPUIPRIV lpUIPrivate;
  390. hUIPrivate = (HGLOBAL)GetWindowLongPtr(hUIWnd, IMMGWLP_PRIVATE);
  391. if (!hUIPrivate) {
  392. return;
  393. }
  394. lpUIPrivate = (LPUIPRIV)GlobalLock(hUIPrivate);
  395. if (!lpUIPrivate) {
  396. return;
  397. }
  398. hIMC = (HIMC)GetWindowLongPtr(hUIWnd, IMMGWLP_IMC);
  399. if (!hIMC) {
  400. GlobalUnlock(hUIPrivate);
  401. return;
  402. }
  403. if (fOn) {
  404. lpUIPrivate->fdwSetContext |= ISC_OPEN_STATUS_WINDOW;
  405. if (!lpUIPrivate->hStatusWnd) {
  406. OpenStatus(
  407. hUIWnd);
  408. }
  409. } else {
  410. lpUIPrivate->fdwSetContext &= ~(ISC_OPEN_STATUS_WINDOW);
  411. }
  412. hStatusWnd = lpUIPrivate->hStatusWnd;
  413. GlobalUnlock(hUIPrivate);
  414. if (!hStatusWnd) {
  415. return;
  416. }
  417. if (!fOn) {
  418. register DWORD fdwSetContext;
  419. fdwSetContext = lpUIPrivate->fdwSetContext &
  420. (ISC_SHOWUICOMPOSITIONWINDOW|ISC_HIDE_COMP_WINDOW);
  421. if (fdwSetContext == ISC_HIDE_COMP_WINDOW) {
  422. ShowComp(
  423. hUIWnd, SW_HIDE);
  424. }
  425. fdwSetContext = lpUIPrivate->fdwSetContext &
  426. (ISC_SHOWUICANDIDATEWINDOW|ISC_HIDE_CAND_WINDOW);
  427. if (fdwSetContext == ISC_HIDE_CAND_WINDOW) {
  428. ShowCand(
  429. hUIWnd, SW_HIDE);
  430. }
  431. fdwSetContext = lpUIPrivate->fdwSetContext &
  432. (ISC_SHOW_SOFTKBD|ISC_HIDE_SOFTKBD);
  433. if (fdwSetContext == ISC_HIDE_SOFTKBD) {
  434. lpUIPrivate->fdwSetContext &= ~(ISC_HIDE_SOFTKBD);
  435. ShowSoftKbd(hUIWnd, SW_HIDE, NULL);
  436. }
  437. ShowStatus(
  438. hUIWnd, SW_HIDE);
  439. } else if (hIMC) {
  440. ShowStatus(
  441. hUIWnd, SW_SHOWNOACTIVATE);
  442. } else {
  443. ShowStatus(
  444. hUIWnd, SW_HIDE);
  445. }
  446. return;
  447. }
  448. /**********************************************************************/
  449. /* ShowUI() */
  450. /**********************************************************************/
  451. void PASCAL ShowUI( // show the sub windows
  452. HWND hUIWnd,
  453. int nShowCmd)
  454. {
  455. HIMC hIMC;
  456. LPINPUTCONTEXT lpIMC;
  457. LPPRIVCONTEXT lpImcP;
  458. HGLOBAL hUIPrivate;
  459. LPUIPRIV lpUIPrivate;
  460. if (nShowCmd == SW_HIDE) {
  461. } else if (!(hIMC = (HIMC)GetWindowLongPtr(hUIWnd, IMMGWLP_IMC))) {
  462. nShowCmd = SW_HIDE;
  463. } else if (!(lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC))) {
  464. nShowCmd = SW_HIDE;
  465. } else if (!(lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate))) {
  466. ImmUnlockIMC(hIMC);
  467. nShowCmd = SW_HIDE;
  468. } else {
  469. }
  470. if (nShowCmd == SW_HIDE) {
  471. ShowStatus(hUIWnd, nShowCmd);
  472. ShowComp(hUIWnd, nShowCmd);
  473. ShowCand(hUIWnd, nShowCmd);
  474. ShowSoftKbd(hUIWnd, nShowCmd, NULL);
  475. return;
  476. }
  477. hUIPrivate = (HGLOBAL)GetWindowLongPtr(hUIWnd, IMMGWLP_PRIVATE);
  478. if (!hUIPrivate) { // can not darw status window
  479. goto ShowUIUnlockIMCC;
  480. }
  481. lpUIPrivate = (LPUIPRIV)GlobalLock(hUIPrivate);
  482. if (!lpUIPrivate) { // can not draw status window
  483. goto ShowUIUnlockIMCC;
  484. }
  485. lpUIPrivate->fdwSetContext |= ISC_SHOWUICOMPOSITIONWINDOW;
  486. if ((lpUIPrivate->fdwSetContext & ISC_SHOWUICOMPOSITIONWINDOW) &&
  487. (lpImcP->fdwImeMsg & MSG_ALREADY_START)) {
  488. if (lpUIPrivate->hCompWnd) {
  489. if (lpUIPrivate->nShowCompCmd != SW_HIDE) {
  490. // some time the WM_NCPAINT is eaten by the app
  491. RedrawWindow(lpUIPrivate->hCompWnd, NULL, NULL,
  492. RDW_FRAME|RDW_INVALIDATE|RDW_ERASE);
  493. }
  494. if (sImeG.IC_Trace) { // modify 95.7.17
  495. SendMessage(lpUIPrivate->hCompWnd, WM_IME_NOTIFY,
  496. IMN_SETCOMPOSITIONWINDOW, 0);
  497. }
  498. if (lpUIPrivate->nShowCompCmd == SW_HIDE) {
  499. ShowComp(hUIWnd, nShowCmd);
  500. }
  501. } else {
  502. StartComp(hUIWnd);
  503. }
  504. } else if (lpUIPrivate->nShowCompCmd == SW_HIDE) {
  505. } else if (lpUIPrivate->fdwSetContext & ISC_OPEN_STATUS_WINDOW) {
  506. lpUIPrivate->fdwSetContext |= ISC_HIDE_COMP_WINDOW;
  507. } else {
  508. ShowComp(hUIWnd, SW_HIDE);
  509. }
  510. if ((lpUIPrivate->fdwSetContext & ISC_SHOWUICANDIDATEWINDOW) &&
  511. (lpImcP->fdwImeMsg & MSG_ALREADY_OPEN)) {
  512. if (lpUIPrivate->hCandWnd) {
  513. if (lpUIPrivate->nShowCandCmd != SW_HIDE) {
  514. // some time the WM_NCPAINT is eaten by the app
  515. RedrawWindow(lpUIPrivate->hCandWnd, NULL, NULL,
  516. RDW_FRAME|RDW_INVALIDATE|RDW_ERASE);
  517. }
  518. if (sImeG.IC_Trace) {
  519. SendMessage(lpUIPrivate->hCandWnd, WM_IME_NOTIFY,
  520. IMN_SETCANDIDATEPOS, 0x0001);
  521. }
  522. if (lpUIPrivate->nShowCandCmd == SW_HIDE) {
  523. ShowCand(hUIWnd, nShowCmd);
  524. }
  525. } else {
  526. OpenCand(hUIWnd);
  527. }
  528. } else if (lpUIPrivate->nShowCandCmd == SW_HIDE) {
  529. } else if (lpUIPrivate->fdwSetContext & ISC_OPEN_STATUS_WINDOW) {
  530. lpUIPrivate->fdwSetContext |= ISC_HIDE_CAND_WINDOW;
  531. } else {
  532. ShowCand(hUIWnd, SW_HIDE);
  533. }
  534. if (lpUIPrivate->fdwSetContext & ISC_OPEN_STATUS_WINDOW) {
  535. if (!lpUIPrivate->hStatusWnd) {
  536. OpenStatus(hUIWnd);
  537. }
  538. if (lpUIPrivate->nShowStatusCmd != SW_HIDE) {
  539. // some time the WM_NCPAINT is eaten by the app
  540. RedrawWindow(lpUIPrivate->hStatusWnd, NULL, NULL,
  541. RDW_FRAME|RDW_INVALIDATE|RDW_ERASE);
  542. }
  543. SendMessage(lpUIPrivate->hStatusWnd, WM_IME_NOTIFY,
  544. IMN_SETSTATUSWINDOWPOS, 0);
  545. if (lpUIPrivate->nShowStatusCmd == SW_HIDE) {
  546. ShowStatus(hUIWnd, nShowCmd);
  547. }
  548. else{
  549. ShowStatus(hUIWnd, nShowCmd);
  550. }
  551. } else if (lpUIPrivate->hStatusWnd) {
  552. DestroyWindow(lpUIPrivate->hStatusWnd);
  553. }
  554. if (!lpIMC->fOpen) {
  555. if (lpUIPrivate->nShowCompCmd != SW_HIDE) {
  556. ShowSoftKbd(hUIWnd, SW_HIDE, NULL);
  557. }
  558. } else if ((lpUIPrivate->fdwSetContext & ISC_SHOW_SOFTKBD) &&
  559. (lpIMC->fdwConversion & IME_CMODE_SOFTKBD)) {
  560. if (!lpUIPrivate->hSoftKbdWnd) {
  561. UpdateSoftKbd(hUIWnd);
  562. } else if (lpUIPrivate->nShowSoftKbdCmd == SW_HIDE) {
  563. ShowSoftKbd(hUIWnd, nShowCmd, lpImcP);
  564. } else if (lpUIPrivate->hIMC != hIMC) {
  565. UpdateSoftKbd(hUIWnd);
  566. } else {
  567. RedrawWindow(lpUIPrivate->hSoftKbdWnd, NULL, NULL,
  568. RDW_FRAME|RDW_INVALIDATE);
  569. }
  570. } else if (lpUIPrivate->nShowSoftKbdCmd == SW_HIDE) {
  571. } else if (lpUIPrivate->fdwSetContext & ISC_OPEN_STATUS_WINDOW) {
  572. lpUIPrivate->fdwSetContext |= ISC_HIDE_SOFTKBD;
  573. } else {
  574. ShowSoftKbd(hUIWnd, SW_HIDE, NULL);
  575. }
  576. // we switch to this hIMC
  577. lpUIPrivate->hIMC = hIMC;
  578. GlobalUnlock(hUIPrivate);
  579. ShowUIUnlockIMCC:
  580. ImmUnlockIMCC(lpIMC->hPrivate);
  581. ImmUnlockIMC(hIMC);
  582. return;
  583. }
  584. /**********************************************************************/
  585. /* ShowGuideLine */
  586. /**********************************************************************/
  587. void PASCAL ShowGuideLine(
  588. HWND hUIWnd)
  589. {
  590. HIMC hIMC;
  591. LPINPUTCONTEXT lpIMC;
  592. LPGUIDELINE lpGuideLine;
  593. hIMC = (HIMC)GetWindowLongPtr(hUIWnd, IMMGWLP_IMC);
  594. if (!hIMC) {
  595. return;
  596. }
  597. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  598. if (!lpIMC) {
  599. return;
  600. }
  601. lpGuideLine = (LPGUIDELINE)ImmLockIMCC(lpIMC->hGuideLine);
  602. if (!lpGuideLine) {
  603. } else if (lpGuideLine->dwLevel == GL_LEVEL_ERROR) {
  604. MessageBeep((UINT)-1);
  605. MessageBeep((UINT)-1);
  606. } else if (lpGuideLine->dwLevel == GL_LEVEL_WARNING) {
  607. MessageBeep((UINT)-1);
  608. } else {
  609. }
  610. ImmUnlockIMCC(lpIMC->hGuideLine);
  611. ImmUnlockIMC(hIMC);
  612. return;
  613. }
  614. /**********************************************************************/
  615. /* UpdateStatusWindow() */
  616. /* Return Value: */
  617. /* none */
  618. /**********************************************************************/
  619. BOOL UpdateStatusWindow(
  620. HWND hUIWnd)
  621. {
  622. HWND hStatusWnd;
  623. if (!(hStatusWnd = GetStatusWnd(hUIWnd))) {
  624. return (FALSE);
  625. }
  626. InvalidateRect(hStatusWnd, &(sImeG.rcStatusText), TRUE);
  627. UpdateWindow(hStatusWnd);
  628. return (TRUE);
  629. }
  630. /**********************************************************************/
  631. /* NotifyUI() */
  632. /**********************************************************************/
  633. void PASCAL NotifyUI(
  634. HWND hUIWnd,
  635. WPARAM wParam,
  636. LPARAM lParam)
  637. {
  638. HWND hStatusWnd;
  639. switch (wParam) {
  640. case IMN_OPENSTATUSWINDOW:
  641. //PostStatus(hUIWnd, TRUE);
  642. StatusWndMsg(hUIWnd, TRUE);
  643. break;
  644. case IMN_CLOSESTATUSWINDOW:
  645. //PostStatus(hUIWnd, FALSE);
  646. StatusWndMsg(hUIWnd, FALSE);
  647. break;
  648. case IMN_OPENCANDIDATE:
  649. if (lParam & 0x00000001) {
  650. OpenCand(hUIWnd);
  651. }
  652. break;
  653. case IMN_CHANGECANDIDATE:
  654. if (lParam & 0x00000001) {
  655. HDC hDC;
  656. HWND hCandWnd;
  657. hCandWnd = GetCandWnd(hUIWnd);
  658. if (!hCandWnd) {
  659. return;
  660. }
  661. hDC = GetDC(hCandWnd);
  662. PaintCandWindow(hCandWnd, hDC);
  663. ReleaseDC(hCandWnd, hDC);
  664. }
  665. break;
  666. case IMN_CLOSECANDIDATE:
  667. if (lParam & 0x00000001) {
  668. CloseCand(hUIWnd);
  669. }
  670. break;
  671. case IMN_SETSENTENCEMODE:
  672. break;
  673. case IMN_SETOPENSTATUS:
  674. case IMN_SETCONVERSIONMODE:
  675. hStatusWnd = GetStatusWnd(hUIWnd);
  676. if (!hStatusWnd) {
  677. return;
  678. }
  679. {
  680. RECT rcRect;
  681. rcRect = sImeG.rcStatusText;
  682. // off by 1
  683. rcRect.right += 1;
  684. rcRect.bottom += 1;
  685. RedrawWindow(hStatusWnd, &rcRect, NULL, RDW_INVALIDATE);
  686. }
  687. break;
  688. case IMN_SETCOMPOSITIONFONT:
  689. // we are not going to change font, but an IME can do this if it want
  690. break;
  691. case IMN_SETCOMPOSITIONWINDOW:
  692. {
  693. HWND hCompWnd;
  694. hCompWnd = GetCompWnd(hUIWnd);
  695. if (!hCompWnd) {
  696. return;
  697. }
  698. PostMessage(hCompWnd, WM_IME_NOTIFY, wParam, lParam);
  699. }
  700. break;
  701. case IMN_SETCANDIDATEPOS:
  702. {
  703. HWND hCandWnd;
  704. hCandWnd = GetCandWnd(hUIWnd);
  705. if (!hCandWnd) {
  706. return;
  707. }
  708. PostMessage(hCandWnd, WM_IME_NOTIFY, wParam, lParam);
  709. }
  710. break;
  711. case IMN_SETSTATUSWINDOWPOS:
  712. hStatusWnd = GetStatusWnd(hUIWnd);
  713. if (hStatusWnd) {
  714. PostMessage(hStatusWnd, WM_IME_NOTIFY, wParam, lParam);
  715. } else {
  716. }
  717. break;
  718. case IMN_GUIDELINE:
  719. ShowGuideLine(hUIWnd);
  720. break;
  721. case IMN_PRIVATE:
  722. switch (lParam) {
  723. case IMN_PRIVATE_UPDATE_SOFTKBD:
  724. UpdateSoftKbd(hUIWnd);
  725. break;
  726. case IMN_PRIVATE_UPDATE_STATUS:
  727. UpdateStatusWindow(hUIWnd);
  728. break;
  729. case IMN_PRIVATE_DESTROYCANDWIN:
  730. SendMessage(GetCandWnd(hUIWnd), WM_DESTROY, (WPARAM)0, (LPARAM)0);
  731. break;
  732. case IMN_PRIVATE_CMENUDESTROYED:
  733. CMenuDestroyed(hUIWnd);
  734. break;
  735. case IMN_PRIVATE_SOFTKEYMENUDESTROYED:
  736. SoftkeyMenuDestroyed(hUIWnd);
  737. break;
  738. }
  739. break;
  740. case IMN_SOFTKBDDESTROYED:
  741. SoftKbdDestroyed(hUIWnd);
  742. break;
  743. default:
  744. break;
  745. }
  746. return;
  747. }
  748. /**********************************************************************/
  749. /* SetContext() */
  750. /**********************************************************************/
  751. void PASCAL SetContext( // the context activated/deactivated
  752. HWND hUIWnd,
  753. BOOL fOn,
  754. LPARAM lShowUI)
  755. {
  756. HIMC hIMC;
  757. LPINPUTCONTEXT lpIMC;
  758. LPPRIVCONTEXT lpImcP;
  759. HGLOBAL hUIPrivate;
  760. register LPUIPRIV lpUIPrivate;
  761. #if defined(COMBO_IME)
  762. DWORD dwRegImeIndex;
  763. #endif
  764. RECT rcWorkArea;
  765. #ifdef MUL_MONITOR
  766. rcWorkArea = ImeMonitorWorkAreaFromWindow(hUIWnd);
  767. #else
  768. rcWorkArea = sImeG.rcWorkArea;
  769. #endif
  770. hIMC = (HIMC)GetWindowLongPtr(hUIWnd, IMMGWLP_IMC);
  771. if (!hIMC) {
  772. return ;
  773. }
  774. // get lpIMC
  775. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  776. if (!lpIMC) {
  777. return;
  778. }
  779. hUIPrivate = (HGLOBAL)GetWindowLongPtr(hUIWnd, IMMGWLP_PRIVATE);
  780. if (!hUIPrivate) {
  781. ImmUnlockIMC(hIMC);
  782. return;
  783. }
  784. lpUIPrivate = (LPUIPRIV)GlobalLock(hUIPrivate);
  785. if (!lpUIPrivate) {
  786. ImmUnlockIMC(hIMC);
  787. return;
  788. }
  789. if (fOn) {
  790. register DWORD fdwSetContext;
  791. lpUIPrivate->fdwSetContext = lpUIPrivate->fdwSetContext &
  792. ~(ISC_SHOWUIALL|ISC_HIDE_SOFTKBD);
  793. lpUIPrivate->fdwSetContext |= (lShowUI & ISC_SHOWUIALL) |
  794. ISC_SHOW_SOFTKBD;
  795. {
  796. HKEY hKey;
  797. DWORD bcData;
  798. char buf[256];
  799. bcData=256;
  800. if(RegOpenKeyEx (HKEY_CURRENT_USER,
  801. TEXT("Control Panel\\Input Method"),
  802. 0,
  803. KEY_ENUMERATE_SUB_KEYS |
  804. KEY_EXECUTE |
  805. KEY_QUERY_VALUE,
  806. &hKey)){
  807. goto SetShowStatus;
  808. }
  809. if(RegQueryValueEx (hKey, TEXT("show status"),
  810. NULL,
  811. NULL, //null-terminate string
  812. (LPBYTE)buf, //&bData,
  813. &bcData) != ERROR_SUCCESS){
  814. // Set default as ON if no entry in registry
  815. lpUIPrivate->fdwSetContext |= ISC_OPEN_STATUS_WINDOW;
  816. goto SetShowStatus;
  817. }
  818. if(strcmp(buf, "1")==0)
  819. lpUIPrivate->fdwSetContext |= ISC_OPEN_STATUS_WINDOW;
  820. else
  821. lpUIPrivate->fdwSetContext &= ~ISC_OPEN_STATUS_WINDOW;
  822. SetShowStatus:
  823. RegCloseKey(hKey);
  824. }
  825. fdwSetContext = lpUIPrivate->fdwSetContext &
  826. (ISC_SHOWUICOMPOSITIONWINDOW|ISC_HIDE_COMP_WINDOW);
  827. if (fdwSetContext == ISC_HIDE_COMP_WINDOW) {
  828. ShowComp(
  829. hUIWnd, SW_HIDE);
  830. } else if (fdwSetContext & ISC_HIDE_COMP_WINDOW) {
  831. lpUIPrivate->fdwSetContext &= ~(ISC_HIDE_COMP_WINDOW);
  832. } else {
  833. }
  834. fdwSetContext = lpUIPrivate->fdwSetContext &
  835. (ISC_SHOWUICANDIDATEWINDOW|ISC_HIDE_CAND_WINDOW);
  836. if (fdwSetContext == ISC_HIDE_CAND_WINDOW) {
  837. ShowCand(
  838. hUIWnd, SW_HIDE);
  839. } else if (fdwSetContext & ISC_HIDE_CAND_WINDOW) {
  840. lpUIPrivate->fdwSetContext &= ~(ISC_HIDE_CAND_WINDOW);
  841. } else {
  842. }
  843. if (lpIMC->cfCandForm[0].dwIndex != 0) {
  844. lpIMC->cfCandForm[0].dwStyle = CFS_DEFAULT;
  845. }
  846. lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
  847. if (!lpImcP) {
  848. GlobalUnlock(hUIPrivate);
  849. ImmUnlockIMC(hIMC);
  850. return;
  851. }
  852. // init ime properties & reset context
  853. {
  854. HKEY hKeyCurrVersion;
  855. HKEY hKeyGB;
  856. DWORD ValueType;
  857. DWORD ValueSize;
  858. LONG retCode;
  859. retCode = OpenReg_PathSetup(&hKeyCurrVersion);
  860. if (retCode) {
  861. TCHAR Buf[MAX_PATH];
  862. wsprintf (Buf, TEXT("Error: RegOpenKeyEx = %d"), retCode);
  863. MessageBox (lpIMC->hWnd, Buf, szWarnTitle, MB_OK | MB_ICONINFORMATION);
  864. return;
  865. }
  866. #if defined(COMBO_IME)
  867. retCode = OpenReg_User (hKeyCurrVersion,
  868. szImeRegName,
  869. &hKeyGB);
  870. #else
  871. retCode = OpenReg_User (hKeyCurrVersion,
  872. szImeName,
  873. &hKeyGB);
  874. #endif //COMBO_IME
  875. // query �������� value
  876. ValueSize = sizeof(DWORD);
  877. RegQueryValueEx (hKeyGB,szTrace ,
  878. (DWORD)0,
  879. (LPDWORD)&ValueType,
  880. (LPBYTE)&sImeG.IC_Trace,
  881. (LPDWORD)&ValueSize);
  882. #ifdef CROSSREF
  883. if(RegQueryValueEx (hKeyGB, szRegRevKL,
  884. NULL,
  885. NULL, //null-terminate string
  886. (LPBYTE)&sImeG.hRevKL, //&bData,
  887. &ValueSize) != ERROR_SUCCESS)
  888. sImeG.hRevKL = NULL;
  889. if(RegQueryValueEx (hKeyGB, szRegRevMaxKey,
  890. NULL,
  891. NULL, //null-terminate string
  892. (LPBYTE)&sImeG.nRevMaxKey, //&bData,
  893. &ValueSize) != ERROR_SUCCESS)
  894. sImeG.hRevKL = NULL;
  895. #endif
  896. #if defined(COMBO_IME)
  897. // query �������� value
  898. ValueSize = sizeof(DWORD);
  899. RegQueryValueEx (hKeyGB, szRegImeIndex,
  900. (DWORD)0,
  901. (LPDWORD)&ValueType,
  902. (LPBYTE)&dwRegImeIndex,
  903. (LPDWORD)&ValueSize);
  904. #endif
  905. RegCloseKey(hKeyGB);
  906. RegCloseKey(hKeyCurrVersion);
  907. }
  908. #if defined(COMBO_IME)
  909. if(sImeL.dwRegImeIndex != dwRegImeIndex) {
  910. DWORD dwConvMode;
  911. int cxBorder, cyBorder;
  912. //change current IME index
  913. dwConvMode = lpIMC->fdwConversion ^ (IME_CMODE_INDEX_FIRST << sImeL.dwRegImeIndex);
  914. sImeL.dwRegImeIndex = dwRegImeIndex;
  915. szImeName = pszImeName[dwRegImeIndex];
  916. dwConvMode |= (IME_CMODE_INDEX_FIRST << dwRegImeIndex);
  917. // re-caculate statusuidata
  918. cxBorder = GetSystemMetrics(SM_CXBORDER);
  919. cyBorder = GetSystemMetrics(SM_CYBORDER);
  920. InitStatusUIData(cxBorder, cyBorder);
  921. ImmSetConversionStatus(hIMC, dwConvMode, lpIMC->fdwSentence);
  922. }
  923. #endif //COMBO_IME
  924. if(sImeG.IC_Trace != SaTC_Trace) {
  925. int UI_MODE;
  926. lpImcP->iImeState = CST_INIT;
  927. CompCancel(hIMC, lpIMC);
  928. // init fields of hPrivate
  929. lpImcP->fdwImeMsg = (DWORD)0;
  930. lpImcP->dwCompChar = (DWORD)0;
  931. lpImcP->fdwGcsFlag = (DWORD)0;
  932. lpImcP->uSYHFlg = 0x00000000;
  933. lpImcP->uDYHFlg = 0x00000000;
  934. // change compwnd size
  935. // init fields of hIMC
  936. lpIMC->fOpen = TRUE;
  937. SendMessage(GetCandWnd(hUIWnd), WM_DESTROY, (WPARAM)0, (LPARAM)0);
  938. // set cand window data
  939. if(sImeG.IC_Trace) {
  940. UI_MODE = BOX_UI;
  941. } else {
  942. POINT ptSTFixPos;
  943. UI_MODE = LIN_UI;
  944. ptSTFixPos.x = 0;
  945. ptSTFixPos.y = rcWorkArea.bottom - sImeG.yStatusHi;
  946. ImmSetStatusWindowPos(hIMC, (LPPOINT)&ptSTFixPos);
  947. }
  948. InitCandUIData(
  949. GetSystemMetrics(SM_CXBORDER),
  950. GetSystemMetrics(SM_CYBORDER), UI_MODE);
  951. }
  952. SaTC_Trace = sImeG.IC_Trace;
  953. // init Caps
  954. {
  955. BYTE lpbKeyState[256];
  956. DWORD fdwConversion;
  957. if (!GetKeyboardState(lpbKeyState))
  958. lpbKeyState[VK_CAPITAL] = 0;
  959. if (lpbKeyState[VK_CAPITAL] & 0x01) {
  960. // 10.11 add
  961. uCaps = 1;
  962. // change to alphanumeric mode
  963. fdwConversion = lpIMC->fdwConversion & ~(IME_CMODE_CHARCODE |
  964. IME_CMODE_NATIVE | IME_CMODE_EUDC);
  965. } else {
  966. // change to native mode
  967. if(uCaps == 1) {
  968. fdwConversion = (lpIMC->fdwConversion | IME_CMODE_NATIVE) &
  969. ~(IME_CMODE_CHARCODE | IME_CMODE_EUDC);
  970. } else {
  971. fdwConversion = lpIMC->fdwConversion;
  972. }
  973. uCaps = 0;
  974. }
  975. ImmSetConversionStatus(hIMC, fdwConversion, lpIMC->fdwSentence);
  976. }
  977. if ((lpIMC->cfCompForm.dwStyle & CFS_FORCE_POSITION)
  978. && (sImeG.IC_Trace)) {
  979. POINT ptNew; // new position of UI
  980. POINT ptSTWPos;
  981. ImmGetStatusWindowPos(hIMC, (LPPOINT)&ptSTWPos);
  982. ptNew.x = ptSTWPos.x + sImeG.xStatusWi + UI_MARGIN;
  983. if((ptSTWPos.x + sImeG.xStatusWi + sImeG.xCandWi + lpImeL->xCompWi + 2 * UI_MARGIN) >=
  984. rcWorkArea.right) {
  985. ptNew.x = ptSTWPos.x - lpImeL->xCompWi - UI_MARGIN;
  986. }
  987. ptNew.x += lpImeL->cxCompBorder;
  988. ptNew.y = ptSTWPos.y + lpImeL->cyCompBorder;
  989. lpIMC->cfCompForm.ptCurrentPos = ptNew;
  990. ScreenToClient(lpIMC->hWnd, &lpIMC->cfCompForm.ptCurrentPos);
  991. lpIMC->cfCompForm.dwStyle = CFS_DEFAULT;
  992. }
  993. } else {
  994. lpUIPrivate->fdwSetContext &= ~ISC_SETCONTEXT_UI;
  995. }
  996. GlobalUnlock(hUIPrivate);
  997. UIPaint(hUIWnd);
  998. ImmUnlockIMC(hIMC);
  999. return;
  1000. }
  1001. /**********************************************************************/
  1002. /* GetCompWindow() */
  1003. /**********************************************************************/
  1004. LRESULT PASCAL GetCompWindow(
  1005. HWND hUIWnd,
  1006. LPCOMPOSITIONFORM lpCompForm)
  1007. {
  1008. HWND hCompWnd;
  1009. RECT rcCompWnd;
  1010. hCompWnd = GetCompWnd(hUIWnd);
  1011. if (!hCompWnd) {
  1012. return (1L);
  1013. }
  1014. if (!GetWindowRect(hCompWnd, &rcCompWnd)) {
  1015. return (1L);
  1016. }
  1017. lpCompForm->dwStyle = CFS_POINT|CFS_RECT;
  1018. lpCompForm->ptCurrentPos = *(LPPOINT)&rcCompWnd;
  1019. lpCompForm->rcArea = rcCompWnd;
  1020. return (0L);
  1021. }
  1022. /**********************************************************************/
  1023. /* SelectIME() */
  1024. /**********************************************************************/
  1025. void PASCAL SelectIME( // switch IMEs
  1026. HWND hUIWnd,
  1027. BOOL fSelect)
  1028. {
  1029. if (!fSelect) {
  1030. ShowUI(hUIWnd, SW_HIDE);
  1031. } else {
  1032. ShowUI(hUIWnd, SW_SHOWNOACTIVATE);
  1033. }
  1034. return;
  1035. }
  1036. /**********************************************************************/
  1037. /* UIPaint() */
  1038. /**********************************************************************/
  1039. LRESULT PASCAL UIPaint(
  1040. HWND hUIWnd)
  1041. {
  1042. PAINTSTRUCT ps;
  1043. MSG sMsg;
  1044. HGLOBAL hUIPrivate;
  1045. LPUIPRIV lpUIPrivate;
  1046. // for safety
  1047. BeginPaint(hUIWnd, &ps);
  1048. EndPaint(hUIWnd, &ps);
  1049. // some application will not remove the WM_PAINT messages
  1050. PeekMessage(&sMsg, hUIWnd, WM_PAINT, WM_PAINT, PM_REMOVE|PM_NOYIELD);
  1051. hUIPrivate = (HGLOBAL)GetWindowLongPtr(hUIWnd, IMMGWLP_PRIVATE);
  1052. if (!hUIPrivate) {
  1053. return (0L);
  1054. }
  1055. lpUIPrivate = (LPUIPRIV)GlobalLock(hUIPrivate);
  1056. if (!lpUIPrivate) {
  1057. return (0L);
  1058. }
  1059. if (lpUIPrivate->fdwSetContext & ISC_SETCONTEXT_UI) {
  1060. ShowUI(hUIWnd, SW_SHOWNOACTIVATE);
  1061. } else {
  1062. ShowUI(hUIWnd, SW_HIDE);
  1063. }
  1064. GlobalUnlock(hUIPrivate);
  1065. return (0L);
  1066. }
  1067. /**********************************************************************/
  1068. /* UIWndProc() */
  1069. /**********************************************************************/
  1070. LRESULT CALLBACK UIWndProc(
  1071. HWND hUIWnd,
  1072. UINT uMsg,
  1073. WPARAM wParam,
  1074. LPARAM lParam)
  1075. {
  1076. switch (uMsg) {
  1077. case WM_CREATE:
  1078. CreateUIWindow(hUIWnd);
  1079. break;
  1080. case WM_DESTROY:
  1081. DestroyUIWindow(hUIWnd);
  1082. break;
  1083. case WM_IME_STARTCOMPOSITION:
  1084. // you can create a window as the composition window here
  1085. StartComp(hUIWnd);
  1086. break;
  1087. case WM_IME_COMPOSITION:
  1088. if (!sImeG.IC_Trace) {
  1089. } else if (lParam & GCS_RESULTSTR) {
  1090. MoveDefaultCompPosition(hUIWnd);
  1091. } else {
  1092. }
  1093. {
  1094. HWND hCompWnd;
  1095. hCompWnd = GetCompWnd(hUIWnd);
  1096. if (hCompWnd) {
  1097. RECT rcRect;
  1098. rcRect = lpImeL->rcCompText;
  1099. // off by 1
  1100. rcRect.right += 1;
  1101. rcRect.bottom += 1;
  1102. RedrawWindow(hCompWnd, &rcRect, NULL, RDW_INVALIDATE);
  1103. }
  1104. }
  1105. break;
  1106. case WM_IME_ENDCOMPOSITION:
  1107. // you can destroy the composition window here
  1108. EndComp(hUIWnd);
  1109. break;
  1110. case WM_IME_NOTIFY:
  1111. NotifyUI(hUIWnd, wParam, lParam);
  1112. break;
  1113. case WM_IME_SETCONTEXT:
  1114. SetContext(hUIWnd, (BOOL)wParam, lParam);
  1115. if (wParam && GetWindowLongPtr(hUIWnd, IMMGWLP_IMC))
  1116. SetWindowPos(hUIWnd, NULL, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOMOVE);
  1117. break;
  1118. case WM_IME_CONTROL:
  1119. switch (wParam) {
  1120. case IMC_GETCANDIDATEPOS:
  1121. return (1L); // not implemented yet
  1122. case IMC_GETCOMPOSITIONFONT:
  1123. return (1L); // not implemented yet
  1124. case IMC_GETCOMPOSITIONWINDOW:
  1125. return GetCompWindow(hUIWnd, (LPCOMPOSITIONFORM)lParam);
  1126. case IMC_GETSTATUSWINDOWPOS:
  1127. {
  1128. HWND hStatusWnd;
  1129. RECT rcStatusWnd;
  1130. LPARAM lRetVal;
  1131. hStatusWnd = GetStatusWnd(hUIWnd);
  1132. if (!hStatusWnd) {
  1133. return (0L); // fail, return (0, 0)?
  1134. }
  1135. if (!GetWindowRect(hStatusWnd, &rcStatusWnd)) {
  1136. return (0L); // fail, return (0, 0)?
  1137. }
  1138. lRetVal = MAKELRESULT(rcStatusWnd.left, rcStatusWnd.top);
  1139. return (lRetVal);
  1140. }
  1141. return (0L);
  1142. case IMC_SETSTATUSWINDOWPOS:
  1143. {
  1144. HIMC hIMC;
  1145. LPINPUTCONTEXT lpIMC;
  1146. LPPRIVCONTEXT lpImcP;
  1147. //COMPOSITIONFORM CompForm;
  1148. POINT ptPos;
  1149. RECT rcWorkArea;
  1150. #ifdef MUL_MONITOR
  1151. rcWorkArea = ImeMonitorWorkAreaFromWindow(hUIWnd);
  1152. #else
  1153. rcWorkArea = sImeG.rcWorkArea;
  1154. #endif
  1155. ptPos.x = ((LPPOINTS)&lParam)->x;
  1156. ptPos.y = ((LPPOINTS)&lParam)->y;
  1157. hIMC = (HIMC)GetWindowLongPtr(hUIWnd, IMMGWLP_IMC);
  1158. if (!hIMC) {
  1159. return (1L);
  1160. }
  1161. if(!ImmSetStatusWindowPos(hIMC, &ptPos)) {
  1162. return (1L);
  1163. }
  1164. // set comp window position when TraceCuer
  1165. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  1166. if (!lpIMC) {
  1167. return (1L);
  1168. }
  1169. lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
  1170. if (!lpImcP) {
  1171. return (1L);
  1172. }
  1173. if(!sImeG.IC_Trace) {
  1174. lpIMC->cfCompForm.dwStyle = CFS_RECT;
  1175. lpIMC->cfCompForm.ptCurrentPos.x = ptPos.x + sImeG.xStatusWi + UI_MARGIN;
  1176. lpIMC->cfCompForm.ptCurrentPos.y = ptPos.y;
  1177. CopyRect(&lpIMC->cfCompForm.rcArea, &rcWorkArea);
  1178. ScreenToClient(lpIMC->hWnd, &lpIMC->cfCompForm.ptCurrentPos);
  1179. // set composition window to the new poosition
  1180. PostMessage(GetCompWnd(hUIWnd), WM_IME_NOTIFY, IMN_SETCOMPOSITIONWINDOW, 0);
  1181. }
  1182. ImmUnlockIMCC(lpIMC->hPrivate);
  1183. ImmUnlockIMC(hIMC);
  1184. return (0L);
  1185. }
  1186. return (1L);
  1187. default:
  1188. return (1L);
  1189. }
  1190. break;
  1191. case WM_IME_COMPOSITIONFULL:
  1192. return (0L);
  1193. case WM_IME_SELECT:
  1194. //#if defined(LATER)
  1195. SetContext(hUIWnd, (BOOL)wParam, 0);
  1196. //#else
  1197. // SelectIME(hUIWnd, (BOOL)wParam);
  1198. //#endif
  1199. return (0L);
  1200. case WM_MOUSEACTIVATE:
  1201. return (MA_NOACTIVATE);
  1202. case WM_PAINT:
  1203. return UIPaint(hUIWnd);
  1204. default:
  1205. return DefWindowProc(hUIWnd, uMsg, wParam, lParam);
  1206. }
  1207. return (0L);
  1208. }
  1209. void DrawConvexRect(HDC hDC, int x1, int y1, int x2, int y2)
  1210. {
  1211. HPEN hPen, hOldPen;
  1212. SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
  1213. SelectObject(hDC, GetStockObject(WHITE_PEN));
  1214. MoveToEx(hDC, x1, y1,NULL);
  1215. LineTo(hDC, x2, y1);
  1216. MoveToEx(hDC, x1, y1,NULL);
  1217. LineTo(hDC, x1, y2);
  1218. hPen = CreatePen(PS_SOLID, 1, RGB(128, 128, 128));
  1219. if ( hPen )
  1220. {
  1221. hOldPen = SelectObject (hDC, hPen);
  1222. MoveToEx(hDC, x2-1, y2-1,NULL);
  1223. LineTo(hDC, x2-1, y1);
  1224. MoveToEx(hDC, x2-1, y2-1,NULL);
  1225. LineTo(hDC, x1, y2-1);
  1226. SelectObject(hDC, hOldPen);
  1227. DeleteObject(hPen);
  1228. }
  1229. }
  1230. void DrawConvexRectP(HDC hDC, int x1, int y1, int x2, int y2)
  1231. {
  1232. HPEN hPen, hOldPen;
  1233. SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
  1234. SelectObject(hDC, GetStockObject(WHITE_PEN));
  1235. MoveToEx(hDC, x1, y1,NULL);
  1236. LineTo(hDC, x2 - 1, y1);
  1237. MoveToEx(hDC, x1, y1,NULL);
  1238. LineTo(hDC, x1, y2 - 1);
  1239. hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
  1240. if ( hPen )
  1241. {
  1242. hOldPen = SelectObject (hDC, hPen);
  1243. MoveToEx(hDC, x2-1, y2-1,NULL);
  1244. LineTo(hDC, x2-1, y1);
  1245. MoveToEx(hDC, x2-1, y2-1,NULL);
  1246. LineTo(hDC, x1, y2-1);
  1247. SelectObject(hDC, hOldPen);
  1248. DeleteObject(hPen);
  1249. }
  1250. }
  1251. void DrawConcaveRect(HDC hDC, int x1, int y1, int x2, int y2)
  1252. {
  1253. HPEN hLtPen = CreatePen(PS_SOLID, 1, 0x00808080);
  1254. if ( hLtPen != NULL )
  1255. {
  1256. HPEN OldPen = SelectObject(hDC, hLtPen);
  1257. MoveToEx(hDC, x1, y1,NULL);
  1258. LineTo(hDC, x2, y1);
  1259. MoveToEx(hDC, x1, y1,NULL);
  1260. LineTo(hDC, x1, y2);
  1261. SelectObject(hDC, GetStockObject(WHITE_PEN));
  1262. MoveToEx(hDC, x2 , y2,NULL);
  1263. LineTo(hDC, x2 , y1-1);
  1264. MoveToEx(hDC, x2 , y2,NULL);
  1265. LineTo(hDC, x1-1, y2);
  1266. SelectObject(hDC, OldPen);
  1267. DeleteObject(hLtPen);
  1268. }
  1269. }