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.

787 lines
22 KiB

  1. /*++
  2. Copyright (c) 1995-1999 Microsoft Corporation, All Rights Reserved
  3. Module Name:
  4. UISUBS.c
  5. ++*/
  6. #include <windows.h>
  7. #include <htmlhelp.h>
  8. #include <immdev.h>
  9. #include <imedefs.h>
  10. /**********************************************************************/
  11. /* DrawDragBorder() */
  12. /**********************************************************************/
  13. void PASCAL DrawDragBorder(
  14. HWND hWnd, // window of IME is dragged
  15. LONG lCursorPos, // the cursor position
  16. LONG lCursorOffset) // the offset form cursor to window org
  17. {
  18. HDC hDC;
  19. int cxBorder, cyBorder;
  20. int x, y;
  21. RECT rcWnd;
  22. cxBorder = GetSystemMetrics(SM_CXBORDER); // width of border
  23. cyBorder = GetSystemMetrics(SM_CYBORDER); // height of border
  24. // get cursor position
  25. x = (*(LPPOINTS)&lCursorPos).x;
  26. y = (*(LPPOINTS)&lCursorPos).y;
  27. // calculate the org by the offset
  28. x -= (*(LPPOINTS)&lCursorOffset).x;
  29. y -= (*(LPPOINTS)&lCursorOffset).y;
  30. #if 0 // MultiMonitor support
  31. // check for the min boundary of the display
  32. if (x < sImeG.rcWorkArea.left) {
  33. x = sImeG.rcWorkArea.left;
  34. }
  35. if (y < sImeG.rcWorkArea.top) {
  36. y = sImeG.rcWorkArea.top;
  37. }
  38. #endif
  39. // check for the max boundary of the display
  40. GetWindowRect(hWnd, &rcWnd);
  41. #if 0 // MultiMonitor support
  42. if (x + rcWnd.right - rcWnd.left > sImeG.rcWorkArea.right) {
  43. x = sImeG.rcWorkArea.right - (rcWnd.right - rcWnd.left);
  44. }
  45. if (y + rcWnd.bottom - rcWnd.top > sImeG.rcWorkArea.bottom) {
  46. y = sImeG.rcWorkArea.bottom - (rcWnd.bottom - rcWnd.top);
  47. }
  48. #endif
  49. // draw the moving track
  50. hDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
  51. SelectObject(hDC, GetStockObject(GRAY_BRUSH));
  52. // ->
  53. PatBlt(hDC, x, y, rcWnd.right - rcWnd.left - cxBorder, cyBorder,
  54. PATINVERT);
  55. // v
  56. PatBlt(hDC, x, y + cyBorder, cxBorder, rcWnd.bottom - rcWnd.top -
  57. cyBorder, PATINVERT);
  58. // _>
  59. PatBlt(hDC, x + cxBorder, y + rcWnd.bottom - rcWnd.top,
  60. rcWnd.right - rcWnd.left - cxBorder, -cyBorder, PATINVERT);
  61. // v
  62. PatBlt(hDC, x + rcWnd.right - rcWnd.left, y,
  63. - cxBorder, rcWnd.bottom - rcWnd.top - cyBorder, PATINVERT);
  64. DeleteDC(hDC);
  65. return;
  66. }
  67. /**********************************************************************/
  68. /* DrawFrameBorder() */
  69. /**********************************************************************/
  70. void PASCAL DrawFrameBorder( // border of IME
  71. HDC hDC,
  72. HWND hWnd) // window of IME
  73. {
  74. RECT rcWnd;
  75. int xWi, yHi;
  76. GetWindowRect(hWnd, &rcWnd);
  77. xWi = rcWnd.right - rcWnd.left;
  78. yHi = rcWnd.bottom - rcWnd.top;
  79. // 1, ->
  80. PatBlt(hDC, 0, 0, xWi, 1, WHITENESS);
  81. // 1, v
  82. PatBlt(hDC, 0, 0, 1, yHi, WHITENESS);
  83. // 1, _>
  84. PatBlt(hDC, 0, yHi, xWi, -1, BLACKNESS);
  85. // 1, v
  86. PatBlt(hDC, xWi, 0, -1, yHi, BLACKNESS);
  87. xWi -= 2;
  88. yHi -= 2;
  89. SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
  90. // 2, ->
  91. PatBlt(hDC, 1, 1, xWi, 1, PATCOPY);
  92. // 2, v
  93. PatBlt(hDC, 1, 1, 1, yHi, PATCOPY);
  94. // 2, v
  95. PatBlt(hDC, xWi + 1, 1, -1, yHi, PATCOPY);
  96. SelectObject(hDC, GetStockObject(GRAY_BRUSH));
  97. // 2, _>
  98. PatBlt(hDC, 1, yHi + 1, xWi, -1, PATCOPY);
  99. xWi -= 2;
  100. yHi -= 2;
  101. // 3, ->
  102. PatBlt(hDC, 2, 2, xWi, 1, PATCOPY);
  103. // 3, v
  104. PatBlt(hDC, 2, 2, 1, yHi, PATCOPY);
  105. // 3, v
  106. PatBlt(hDC, xWi + 2, 3, -1, yHi - 1, WHITENESS);
  107. SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
  108. // 3, _>
  109. PatBlt(hDC, 2, yHi + 2, xWi, -1, PATCOPY);
  110. SelectObject(hDC, GetStockObject(GRAY_BRUSH));
  111. xWi -= 2;
  112. yHi -= 2;
  113. // 4, ->
  114. PatBlt(hDC, 3, 3, xWi, 1, PATCOPY);
  115. // 4, v
  116. PatBlt(hDC, 3, 3, 1, yHi, PATCOPY);
  117. SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
  118. // 4, v
  119. PatBlt(hDC, xWi + 3, 4, -1, yHi - 1, PATCOPY);
  120. // 4, _>
  121. PatBlt(hDC, 3, yHi + 3, xWi, -1, WHITENESS);
  122. return;
  123. }
  124. /**********************************************************************/
  125. /* ContextMenuWndProc() */
  126. /**********************************************************************/
  127. LRESULT CALLBACK ContextMenuWndProc(
  128. HWND hCMenuWnd,
  129. UINT uMsg,
  130. WPARAM wParam,
  131. LPARAM lParam)
  132. {
  133. switch (uMsg) {
  134. case WM_DESTROY:
  135. {
  136. HWND hUIWnd;
  137. hUIWnd = (HWND)GetWindowLongPtr(hCMenuWnd, CMENU_HUIWND);
  138. if (hUIWnd) {
  139. SendMessage(hUIWnd, WM_IME_NOTIFY, IMN_PRIVATE,
  140. IMN_PRIVATE_CMENUDESTROYED);
  141. }
  142. }
  143. break;
  144. case WM_USER_DESTROY:
  145. {
  146. SendMessage(hCMenuWnd, WM_CLOSE, 0, 0);
  147. DestroyWindow(hCMenuWnd);
  148. }
  149. break;
  150. case WM_COMMAND:
  151. switch(LOWORD(wParam)) {
  152. case IDM_SET:
  153. {
  154. HIMC hIMC;
  155. LPINPUTCONTEXT lpIMC;
  156. LPPRIVCONTEXT lpImcP;
  157. int UI_MODE;
  158. HWND hUIWnd;
  159. RECT rcWorkArea;
  160. hUIWnd = (HWND)GetWindowLongPtr(hCMenuWnd, CMENU_HUIWND);
  161. #if 1 // MultiMonitor support
  162. rcWorkArea = ImeMonitorWorkAreaFromWindow(hCMenuWnd);
  163. #endif
  164. if (!hUIWnd) {
  165. return (0L);
  166. }
  167. hIMC = (HIMC)GetWindowLongPtr(hUIWnd, IMMGWLP_IMC);
  168. if (!hIMC) {
  169. return (0L);
  170. }
  171. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  172. if (!lpIMC) {
  173. return (0L);
  174. }
  175. lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
  176. if (!lpImcP) {
  177. return (0L);
  178. }
  179. ImeConfigure(GetKeyboardLayout(0), lpIMC->hWnd, IME_CONFIG_GENERAL, NULL);
  180. #ifdef CROSSREF
  181. {
  182. HWND hCompWnd;
  183. hCompWnd = GetCompWnd(hUIWnd);
  184. DestroyWindow(hCompWnd);
  185. }
  186. #endif
  187. lpImcP->iImeState = CST_INIT;
  188. CompCancel(hIMC, lpIMC);
  189. // change compwnd size
  190. // init fields of hIMC
  191. lpIMC->fOpen = TRUE;
  192. if (!(lpIMC->fdwInit & INIT_CONVERSION)) {
  193. lpIMC->fdwConversion = IME_CMODE_NATIVE;
  194. lpIMC->fdwInit |= INIT_CONVERSION;
  195. }
  196. lpImcP->fdwImeMsg = lpImcP->fdwImeMsg | MSG_IMN_DESTROYCAND;
  197. GenerateMessage(hIMC, lpIMC, lpImcP);
  198. // set cand window data
  199. if(MBIndex.IMEChara[0].IC_Trace) {
  200. UI_MODE = BOX_UI;
  201. } else {
  202. POINT ptSTFixPos;
  203. UI_MODE = LIN_UI;
  204. ptSTFixPos.x = 0;
  205. ptSTFixPos.y = rcWorkArea.bottom - sImeG.yStatusHi;
  206. ImmSetStatusWindowPos(hIMC, (LPPOINT)&ptSTFixPos);
  207. }
  208. InitCandUIData(
  209. GetSystemMetrics(SM_CXBORDER),
  210. GetSystemMetrics(SM_CYBORDER), UI_MODE);
  211. ImmUnlockIMCC(lpIMC->hPrivate);
  212. ImmUnlockIMC(hIMC);
  213. break;
  214. }
  215. case IDM_CRTWORD:
  216. {
  217. HIMC hIMC;
  218. LPINPUTCONTEXT lpIMC;
  219. HWND hUIWnd;
  220. hUIWnd = (HWND)GetWindowLongPtr(hCMenuWnd, CMENU_HUIWND);
  221. if (!hUIWnd) {
  222. return (0L);
  223. }
  224. hIMC = (HIMC)GetWindowLongPtr(hUIWnd, IMMGWLP_IMC);
  225. if(!hIMC){
  226. break;
  227. }
  228. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  229. if (!lpIMC) {
  230. break;
  231. }
  232. DialogBox(hInst, TEXT("CREATEWORD"), (HWND)lpIMC->hWnd, (DLGPROC)CrtWordDlgProc);
  233. ImmUnlockIMC(hIMC);
  234. break;
  235. }
  236. case IDM_OPTGUD:
  237. {
  238. TCHAR szOPTGUDHlpName[MAX_PATH];
  239. szOPTGUDHlpName[0] = 0;
  240. GetWindowsDirectory((LPTSTR)szOPTGUDHlpName, MAX_PATH);
  241. lstrcat((LPTSTR)szOPTGUDHlpName, TEXT("\\HELP\\WINIME.CHM"));
  242. HtmlHelp(hCMenuWnd,szOPTGUDHlpName,HH_DISPLAY_TOPIC,0L);
  243. }
  244. break;
  245. case IDM_IMEGUD:
  246. {
  247. TCHAR szIMEGUDHlpName[MAX_PATH];
  248. int iLen;
  249. szIMEGUDHlpName[0] = 0;
  250. GetWindowsDirectory((LPTSTR)szIMEGUDHlpName, MAX_PATH);
  251. lstrcat((LPTSTR)szIMEGUDHlpName, TEXT("\\HELP\\"));
  252. lstrcat((LPTSTR)szIMEGUDHlpName, (LPTSTR)szImeMBFileName);
  253. iLen = lstrlen(szIMEGUDHlpName);
  254. szIMEGUDHlpName[iLen-3] = 0;
  255. lstrcat((LPTSTR)szIMEGUDHlpName, TEXT(".CHM"));
  256. HtmlHelp(hCMenuWnd,szIMEGUDHlpName,HH_DISPLAY_TOPIC,0L);
  257. }
  258. break;
  259. case IDM_VER:
  260. {
  261. HIMC hIMC;
  262. LPINPUTCONTEXT lpIMC;
  263. HWND hUIWnd;
  264. hUIWnd = (HWND)GetWindowLongPtr(hCMenuWnd, CMENU_HUIWND);
  265. if (!hUIWnd) {
  266. return (0L);
  267. }
  268. hIMC = (HIMC)GetWindowLongPtr(hUIWnd, IMMGWLP_IMC);
  269. if (!hIMC) { // Oh! Oh!
  270. return (0L);
  271. }
  272. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  273. if (!lpIMC) { // Oh! Oh!
  274. return (0L);
  275. }
  276. DialogBox(hInst, TEXT("IMEVER"), (HWND)lpIMC->hWnd, (DLGPROC)ImeVerDlgProc);
  277. ImmUnlockIMC(hIMC);
  278. break;
  279. }
  280. }
  281. break;
  282. case WM_CLOSE:
  283. {
  284. HMENU hMenu;
  285. GetMenu(hCMenuWnd);
  286. hMenu = (HMENU)GetWindowLongPtr(hCMenuWnd, CMENU_MENU);
  287. if (hMenu) {
  288. SetWindowLongPtr(hCMenuWnd, CMENU_MENU, (LONG_PTR)NULL);
  289. DestroyMenu(hMenu);
  290. }
  291. }
  292. return DefWindowProc(hCMenuWnd, uMsg, wParam, lParam);
  293. default:
  294. return DefWindowProc(hCMenuWnd, uMsg, wParam, lParam);
  295. }
  296. return (0L);
  297. }
  298. /**********************************************************************/
  299. /* SoftkeyMenuWndProc() */
  300. /**********************************************************************/
  301. LRESULT CALLBACK SoftkeyMenuWndProc(
  302. HWND hKeyMenuWnd,
  303. UINT uMsg,
  304. WPARAM wParam,
  305. LPARAM lParam)
  306. {
  307. switch (uMsg) {
  308. case WM_DESTROY:
  309. {
  310. HWND hUIWnd;
  311. hUIWnd = (HWND)GetWindowLongPtr(hKeyMenuWnd, SOFTKEYMENU_HUIWND);
  312. if (hUIWnd) {
  313. SendMessage(hUIWnd, WM_IME_NOTIFY, IMN_PRIVATE,
  314. IMN_PRIVATE_SOFTKEYMENUDESTROYED);
  315. }
  316. }
  317. break;
  318. case WM_USER_DESTROY:
  319. {
  320. SendMessage(hKeyMenuWnd, WM_CLOSE, 0, 0);
  321. DestroyWindow(hKeyMenuWnd);
  322. }
  323. break;
  324. case WM_COMMAND:
  325. switch(LOWORD(wParam)) {
  326. case IDM_SKL1:
  327. case IDM_SKL2:
  328. case IDM_SKL3:
  329. case IDM_SKL4:
  330. case IDM_SKL5:
  331. case IDM_SKL6:
  332. case IDM_SKL7:
  333. case IDM_SKL8:
  334. case IDM_SKL9:
  335. case IDM_SKL10:
  336. case IDM_SKL11:
  337. case IDM_SKL12:
  338. case IDM_SKL13:
  339. {
  340. HIMC hIMC;
  341. LPINPUTCONTEXT lpIMC;
  342. LPPRIVCONTEXT lpImcP;
  343. DWORD fdwConversion;
  344. HWND hUIWnd;
  345. hUIWnd = (HWND)GetWindowLongPtr(hKeyMenuWnd, SOFTKEYMENU_HUIWND);
  346. if (!hUIWnd) {
  347. return (0L);
  348. }
  349. hIMC = (HIMC)GetWindowLongPtr(hUIWnd,IMMGWLP_IMC);
  350. if (!hIMC) { // Oh! Oh!
  351. return (0L);
  352. }
  353. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  354. if (!lpIMC) { // Oh! Oh!
  355. return (0L);
  356. }
  357. lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
  358. if (!lpImcP) {
  359. return (0L);
  360. }
  361. {
  362. UINT i;
  363. lpImeL->dwSKWant = LOWORD(wParam) - IDM_SKL1;
  364. lpImeL->dwSKState[lpImeL->dwSKWant] =
  365. lpImeL->dwSKState[lpImeL->dwSKWant]^1;
  366. // clear other SK State
  367. for(i=0; i<NumsSK; i++) {
  368. if(i == lpImeL->dwSKWant) continue;
  369. lpImeL->dwSKState[i] = 0;
  370. }
  371. if(lpImeL->dwSKState[lpImeL->dwSKWant]) {
  372. if(LOWORD(wParam) == IDM_SKL1)
  373. lpImcP->iImeState = CST_INIT;
  374. else
  375. lpImcP->iImeState = CST_SOFTKB;
  376. fdwConversion = lpIMC->fdwConversion | IME_CMODE_SOFTKBD;
  377. } else {
  378. lpImcP->iImeState = CST_INIT;
  379. fdwConversion = lpIMC->fdwConversion & ~(IME_CMODE_SOFTKBD);
  380. }
  381. }
  382. ImmSetConversionStatus(hIMC, (fdwConversion & ~(IME_CMODE_SOFTKBD)),
  383. lpIMC->fdwSentence);
  384. ImmSetConversionStatus(hIMC, fdwConversion, lpIMC->fdwSentence);
  385. ImmUnlockIMCC(lpIMC->hPrivate);
  386. ImmUnlockIMC(hIMC);
  387. break;
  388. }
  389. }
  390. break;
  391. case WM_CLOSE:
  392. {
  393. HMENU hMenu;
  394. GetMenu(hKeyMenuWnd);
  395. hMenu = (HMENU)GetWindowLongPtr(hKeyMenuWnd, SOFTKEYMENU_MENU);
  396. if (hMenu) {
  397. SetWindowLongPtr(hKeyMenuWnd, SOFTKEYMENU_MENU, (LONG_PTR)NULL);
  398. DestroyMenu(hMenu);
  399. }
  400. }
  401. return DefWindowProc(hKeyMenuWnd, uMsg, wParam, lParam);
  402. default:
  403. return DefWindowProc(hKeyMenuWnd, uMsg, wParam, lParam);
  404. }
  405. return (0L);
  406. }
  407. /**********************************************************************/
  408. /* ContextMenu() */
  409. /**********************************************************************/
  410. void PASCAL ContextMenu(
  411. HWND hStatusWnd,
  412. int x,
  413. int y)
  414. {
  415. HWND hUIWnd;
  416. HWND hCMenuWnd;
  417. HGLOBAL hUIPrivate;
  418. LPUIPRIV lpUIPrivate;
  419. HIMC hIMC;
  420. LPINPUTCONTEXT lpIMC;
  421. HMENU hMenu, hCMenu;
  422. RECT rcStatusWnd;
  423. RECT rcWorkArea;
  424. hUIWnd = GetWindow(hStatusWnd, GW_OWNER);
  425. if(!hUIWnd){
  426. return;
  427. }
  428. GetWindowRect(hStatusWnd, &rcStatusWnd);
  429. hIMC = (HIMC)GetWindowLongPtr(hUIWnd, IMMGWLP_IMC);
  430. if (!hIMC) {
  431. return;
  432. }
  433. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  434. if (!lpIMC) {
  435. return;
  436. }
  437. hUIPrivate = (HGLOBAL)GetWindowLongPtr(hUIWnd, IMMGWLP_PRIVATE);
  438. if (!hUIPrivate) {
  439. goto ContextMenuUnlockIMC;
  440. }
  441. lpUIPrivate = (LPUIPRIV)GlobalLock(hUIPrivate);
  442. if (!lpUIPrivate) {
  443. goto ContextMenuUnlockIMC;
  444. }
  445. #if 1 // MultiMonitor support
  446. rcWorkArea = ImeMonitorWorkAreaFromWindow(lpIMC->hWnd);
  447. #endif
  448. if (lpUIPrivate->hCMenuWnd) {
  449. SetWindowPos(lpUIPrivate->hCMenuWnd, NULL,
  450. rcWorkArea.left, rcWorkArea.top, 0, 0,
  451. SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
  452. } else {
  453. // this is important to assign owner window, otherwise the focus
  454. // will be gone
  455. // When UI terminate, it need to destroy this window
  456. lpUIPrivate->hCMenuWnd = CreateWindowEx(CS_HREDRAW|CS_VREDRAW,
  457. szCMenuClassName, TEXT("Context Menu"),
  458. WS_POPUP|WS_DISABLED, 0, 0, 0, 0,
  459. lpIMC->hWnd, (HMENU)NULL, hInst, NULL);
  460. }
  461. hCMenuWnd = lpUIPrivate->hCMenuWnd;
  462. // Unlock before we call into TrackPopupMenu().
  463. GlobalUnlock(hUIPrivate);
  464. if (!hCMenuWnd) {
  465. goto ContextMenuUnlockIMC;
  466. }
  467. hMenu = LoadMenu(hInst, TEXT("PROPMENU"));
  468. hCMenu = GetSubMenu(hMenu, 0);
  469. if ( lpImeL->fWinLogon == TRUE )
  470. {
  471. // In Logon Mode, we don't want to show help and configuration dialog
  472. EnableMenuItem(hCMenu, 0, MF_BYPOSITION | MF_GRAYED );
  473. EnableMenuItem(hCMenu, IDM_CRTWORD, MF_BYCOMMAND | MF_GRAYED);
  474. EnableMenuItem(hCMenu, IDM_SET, MF_BYCOMMAND | MF_GRAYED);
  475. }
  476. SetWindowLongPtr(hCMenuWnd, CMENU_HUIWND, (LONG_PTR)hUIWnd);
  477. SetWindowLongPtr(hCMenuWnd, CMENU_MENU, (LONG_PTR)hMenu);
  478. TrackPopupMenu (hCMenu, TPM_LEFTBUTTON,
  479. rcStatusWnd.left, rcStatusWnd.top, 0, hCMenuWnd, NULL);
  480. hMenu = (HMENU)GetWindowLongPtr(hCMenuWnd, CMENU_MENU);
  481. if (hMenu) {
  482. SetWindowLongPtr(hCMenuWnd, CMENU_MENU, (LONG_PTR)NULL);
  483. DestroyMenu(hMenu);
  484. }
  485. ContextMenuUnlockIMC:
  486. ImmUnlockIMC(hIMC);
  487. return;
  488. }
  489. /**********************************************************************/
  490. /* SoftkeyMenu() */
  491. /**********************************************************************/
  492. void PASCAL SoftkeyMenu(
  493. HWND hStatusWnd,
  494. int x,
  495. int y)
  496. {
  497. HWND hUIWnd;
  498. HWND hSoftkeyMenuWnd;
  499. HGLOBAL hUIPrivate;
  500. LPUIPRIV lpUIPrivate;
  501. HIMC hIMC;
  502. LPINPUTCONTEXT lpIMC;
  503. HMENU hMenu, hKeyMenu;
  504. RECT rcStatusWnd;
  505. hUIWnd = GetWindow(hStatusWnd, GW_OWNER);
  506. if(!hUIWnd){
  507. return;
  508. }
  509. GetWindowRect(hStatusWnd, &rcStatusWnd);
  510. hIMC = (HIMC)GetWindowLongPtr(hUIWnd, IMMGWLP_IMC);
  511. if (!hIMC) {
  512. return;
  513. }
  514. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  515. if (!lpIMC) {
  516. return;
  517. }
  518. hUIPrivate = (HGLOBAL)GetWindowLongPtr(hUIWnd, IMMGWLP_PRIVATE);
  519. if (!hUIPrivate) {
  520. goto KeyMenuUnlockIMC;
  521. }
  522. lpUIPrivate = (LPUIPRIV)GlobalLock(hUIPrivate);
  523. if (!lpUIPrivate) {
  524. goto KeyMenuUnlockIMC;
  525. }
  526. if (!lpUIPrivate->hSoftkeyMenuWnd) {
  527. // this is important to assign owner window, otherwise the focus
  528. // will be gone
  529. // When UI terminate, it need to destroy this window
  530. lpUIPrivate->hSoftkeyMenuWnd = CreateWindowEx(CS_HREDRAW|CS_VREDRAW,
  531. szSoftkeyMenuClassName, TEXT("Softkey Menu"),
  532. WS_POPUP|WS_DISABLED, 0, 0, 0, 0,
  533. lpIMC->hWnd, (HMENU)NULL, hInst, NULL);
  534. }
  535. hSoftkeyMenuWnd = lpUIPrivate->hSoftkeyMenuWnd;
  536. // Unlock before we call into TrackPopupMenu().
  537. GlobalUnlock(hUIPrivate);
  538. if (!hSoftkeyMenuWnd) {
  539. goto KeyMenuUnlockIMC;
  540. }
  541. hMenu = LoadMenu(hInst, TEXT("SKMENU"));
  542. hKeyMenu = GetSubMenu(hMenu, 0);
  543. SetWindowLongPtr(hSoftkeyMenuWnd, SOFTKEYMENU_HUIWND, (LONG_PTR)hUIWnd);
  544. SetWindowLongPtr(hSoftkeyMenuWnd, SOFTKEYMENU_MENU, (LONG_PTR)hMenu);
  545. if(lpImeL->dwSKState[lpImeL->dwSKWant]) {
  546. CheckMenuItem(hMenu,lpImeL->dwSKWant + IDM_SKL1, MF_CHECKED);
  547. }
  548. TrackPopupMenu (hKeyMenu, TPM_LEFTBUTTON,
  549. rcStatusWnd.left, rcStatusWnd.top, 0, hSoftkeyMenuWnd, NULL);
  550. hMenu = (HMENU)GetWindowLongPtr(hSoftkeyMenuWnd, SOFTKEYMENU_MENU);
  551. if (hMenu) {
  552. SetWindowLongPtr(hSoftkeyMenuWnd, SOFTKEYMENU_MENU, (LONG_PTR)NULL);
  553. DestroyMenu(hMenu);
  554. }
  555. KeyMenuUnlockIMC:
  556. ImmUnlockIMC(hIMC);
  557. return;
  558. }
  559. #if 1 // MultiMonitor support
  560. /**********************************************************************/
  561. /* ImeMonitorWorkAreaFromWindow() */
  562. /**********************************************************************/
  563. RECT PASCAL ImeMonitorWorkAreaFromWindow(
  564. HWND hAppWnd)
  565. {
  566. HMONITOR hMonitor;
  567. hMonitor = MonitorFromWindow(hAppWnd, MONITOR_DEFAULTTONEAREST);
  568. if (hMonitor) {
  569. MONITORINFO sMonitorInfo;
  570. sMonitorInfo.cbSize = sizeof(sMonitorInfo);
  571. // init a default value to avoid GetMonitorInfo fails
  572. sMonitorInfo.rcWork = sImeG.rcWorkArea;
  573. #ifdef UNICODE
  574. GetMonitorInfoW(hMonitor, &sMonitorInfo);
  575. #else
  576. GetMonitorInfoA(hMonitor, &sMonitorInfo);
  577. #endif
  578. return sMonitorInfo.rcWork;
  579. } else {
  580. return sImeG.rcWorkArea;
  581. }
  582. }
  583. /**********************************************************************/
  584. /* ImeMonitorWorkAreaFromPoint() */
  585. /**********************************************************************/
  586. RECT PASCAL ImeMonitorWorkAreaFromPoint(
  587. POINT ptPoint)
  588. {
  589. HMONITOR hMonitor;
  590. hMonitor = MonitorFromPoint(ptPoint, MONITOR_DEFAULTTONEAREST);
  591. if (hMonitor) {
  592. MONITORINFO sMonitorInfo;
  593. sMonitorInfo.cbSize = sizeof(sMonitorInfo);
  594. // init a default value to avoid GetMonitorInfo fails
  595. sMonitorInfo.rcWork = sImeG.rcWorkArea;
  596. #ifdef UNICODE
  597. GetMonitorInfoW(hMonitor, &sMonitorInfo);
  598. #else
  599. GetMonitorInfoA(hMonitor, &sMonitorInfo);
  600. #endif
  601. return sMonitorInfo.rcWork;
  602. } else {
  603. return sImeG.rcWorkArea;
  604. }
  605. }
  606. /**********************************************************************/
  607. /* ImeMonitorWorkAreaFromRect() */
  608. /**********************************************************************/
  609. RECT PASCAL ImeMonitorWorkAreaFromRect(
  610. LPRECT lprcRect)
  611. {
  612. HMONITOR hMonitor;
  613. hMonitor = MonitorFromRect(lprcRect, MONITOR_DEFAULTTONEAREST);
  614. if (hMonitor) {
  615. MONITORINFO sMonitorInfo;
  616. sMonitorInfo.cbSize = sizeof(sMonitorInfo);
  617. // init a default value to avoid GetMonitorInfo fails
  618. sMonitorInfo.rcWork = sImeG.rcWorkArea;
  619. #ifdef UNICODE
  620. GetMonitorInfoW(hMonitor, &sMonitorInfo);
  621. #else
  622. GetMonitorInfoA(hMonitor, &sMonitorInfo);
  623. #endif
  624. return sMonitorInfo.rcWork;
  625. } else {
  626. return sImeG.rcWorkArea;
  627. }
  628. }
  629. #endif