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.

419 lines
14 KiB

  1. /*++
  2. Copyright (c) 1990-1998 Microsoft Corporation, All Rights Reserved
  3. Module Name:
  4. UICAND.C
  5. ++*/
  6. /**********************************************************************/
  7. #include "windows.h"
  8. #include "immdev.h"
  9. #include "fakeime.h"
  10. int PASCAL GetCompFontHeight(LPUIEXTRA lpUIExtra);
  11. /**********************************************************************/
  12. /* */
  13. /* CandWndProc() */
  14. /* IME UI window procedure */
  15. /* */
  16. /**********************************************************************/
  17. LRESULT CALLBACK CandWndProc( hWnd, message, wParam, lParam )
  18. HWND hWnd;
  19. UINT message;
  20. WPARAM wParam;
  21. LPARAM lParam;
  22. {
  23. HWND hUIWnd;
  24. switch (message)
  25. {
  26. case WM_PAINT:
  27. PaintCandWindow(hWnd);
  28. break;
  29. case WM_SETCURSOR:
  30. case WM_MOUSEMOVE:
  31. case WM_LBUTTONUP:
  32. case WM_RBUTTONUP:
  33. DragUI(hWnd,message,wParam,lParam);
  34. if ((message == WM_SETCURSOR) &&
  35. (HIWORD(lParam) != WM_LBUTTONDOWN) &&
  36. (HIWORD(lParam) != WM_RBUTTONDOWN))
  37. return DefWindowProc(hWnd,message,wParam,lParam);
  38. if ((message == WM_LBUTTONUP) || (message == WM_RBUTTONUP))
  39. SetWindowLong(hWnd,FIGWL_MOUSE,0L);
  40. break;
  41. case WM_MOVE:
  42. hUIWnd = (HWND)GetWindowLongPtr(hWnd,FIGWL_SVRWND);
  43. if (IsWindow(hUIWnd))
  44. SendMessage(hUIWnd,WM_UI_CANDMOVE,wParam,lParam);
  45. break;
  46. default:
  47. if (!MyIsIMEMessage(message))
  48. return DefWindowProc(hWnd,message,wParam,lParam);
  49. break;
  50. }
  51. return 0L;
  52. }
  53. /**********************************************************************/
  54. /* */
  55. /* GetCandPosFromCompWnd() */
  56. /* */
  57. /**********************************************************************/
  58. BOOL PASCAL GetCandPosFromCompWnd(LPUIEXTRA lpUIExtra,LPPOINT lppt)
  59. {
  60. RECT rc;
  61. if (lpUIExtra->dwCompStyle)
  62. {
  63. if (lpUIExtra->uiComp[0].bShow)
  64. {
  65. GetWindowRect(lpUIExtra->uiComp[0].hWnd,&rc);
  66. lppt->x = rc.left;
  67. lppt->y = rc.bottom+1;
  68. return TRUE;
  69. }
  70. }
  71. else
  72. {
  73. if (lpUIExtra->uiDefComp.bShow)
  74. {
  75. GetWindowRect(lpUIExtra->uiDefComp.hWnd,&rc);
  76. lppt->x = rc.left;
  77. lppt->y = rc.bottom+1;
  78. return TRUE;
  79. }
  80. }
  81. return FALSE;
  82. }
  83. /**********************************************************************/
  84. /* */
  85. /* GetCandPosFromCompForm() */
  86. /* */
  87. /**********************************************************************/
  88. BOOL PASCAL GetCandPosFromCompForm(LPINPUTCONTEXT lpIMC, LPUIEXTRA lpUIExtra,LPPOINT lppt)
  89. {
  90. if (lpUIExtra->dwCompStyle)
  91. {
  92. if (lpIMC && lpIMC->fdwInit & INIT_COMPFORM)
  93. {
  94. if (!lpUIExtra->bVertical)
  95. {
  96. lppt->x = lpIMC->cfCompForm.ptCurrentPos.x;
  97. lppt->y = lpIMC->cfCompForm.ptCurrentPos.y +
  98. GetCompFontHeight(lpUIExtra);
  99. }
  100. else
  101. {
  102. lppt->x = lpIMC->cfCompForm.ptCurrentPos.x -
  103. GetCompFontHeight(lpUIExtra);
  104. lppt->y = lpIMC->cfCompForm.ptCurrentPos.y;
  105. }
  106. return TRUE;
  107. }
  108. }
  109. else
  110. {
  111. if (GetCandPosFromCompWnd(lpUIExtra,lppt))
  112. {
  113. ScreenToClient(lpIMC->hWnd,lppt);
  114. return TRUE;
  115. }
  116. }
  117. return FALSE;
  118. }
  119. /**********************************************************************/
  120. /* */
  121. /* CreateCandWindow() */
  122. /* */
  123. /**********************************************************************/
  124. void PASCAL CreateCandWindow( HWND hUIWnd,LPUIEXTRA lpUIExtra, LPINPUTCONTEXT lpIMC )
  125. {
  126. POINT pt;
  127. if (GetCandPosFromCompWnd(lpUIExtra,&pt))
  128. {
  129. lpUIExtra->uiCand.pt.x = pt.x;
  130. lpUIExtra->uiCand.pt.y = pt.y;
  131. }
  132. if (!IsWindow(lpUIExtra->uiCand.hWnd))
  133. {
  134. lpUIExtra->uiCand.hWnd =
  135. CreateWindowEx(WS_EX_WINDOWEDGE,
  136. (LPTSTR)szCandClassName,NULL,
  137. WS_COMPDEFAULT | WS_DLGFRAME,
  138. lpUIExtra->uiCand.pt.x,
  139. lpUIExtra->uiCand.pt.y,
  140. 1,1,
  141. hUIWnd,NULL,hInst,NULL);
  142. }
  143. SetWindowLongPtr(lpUIExtra->uiCand.hWnd,FIGWL_SVRWND,(LONG_PTR)hUIWnd);
  144. ShowWindow(lpUIExtra->uiCand.hWnd, SW_HIDE);
  145. lpUIExtra->uiCand.bShow = FALSE;
  146. return;
  147. }
  148. /**********************************************************************/
  149. /* */
  150. /* PaintCandWindow() */
  151. /* */
  152. /**********************************************************************/
  153. void PASCAL PaintCandWindow( HWND hCandWnd)
  154. {
  155. PAINTSTRUCT ps;
  156. HIMC hIMC;
  157. LPINPUTCONTEXT lpIMC;
  158. LPCANDIDATEINFO lpCandInfo;
  159. LPCANDIDATELIST lpCandList;
  160. HBRUSH hbr;
  161. HDC hDC;
  162. RECT rc;
  163. LPMYSTR lpstr;
  164. int height;
  165. DWORD i;
  166. SIZE sz;
  167. HWND hSvrWnd;
  168. HBRUSH hbrHightLight = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
  169. HBRUSH hbrLGR = GetStockObject(LTGRAY_BRUSH);
  170. HFONT hOldFont;
  171. GetClientRect(hCandWnd,&rc);
  172. hDC = BeginPaint(hCandWnd,&ps);
  173. SetBkMode(hDC,TRANSPARENT);
  174. hSvrWnd = (HWND)GetWindowLongPtr(hCandWnd,FIGWL_SVRWND);
  175. if (hIMC = (HIMC)GetWindowLongPtr(hSvrWnd,IMMGWLP_IMC))
  176. {
  177. lpIMC = ImmLockIMC(hIMC);
  178. hOldFont = CheckNativeCharset(hDC);
  179. if (lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo))
  180. {
  181. height = GetSystemMetrics(SM_CYEDGE);
  182. lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo + lpCandInfo->dwOffset[0]);
  183. for (i = lpCandList->dwPageStart;
  184. i < (lpCandList->dwPageStart + lpCandList->dwPageSize); i++)
  185. {
  186. lpstr = (LPMYSTR)((LPSTR)lpCandList + lpCandList->dwOffset[i]);
  187. MyGetTextExtentPoint(hDC,lpstr,Mylstrlen(lpstr),&sz);
  188. if (((LPMYCAND)lpCandInfo)->cl.dwSelection == (DWORD)i)
  189. {
  190. hbr = SelectObject(hDC,hbrHightLight);
  191. PatBlt(hDC,0,height,rc.right,sz.cy,PATCOPY);
  192. SelectObject(hDC,hbr);
  193. SetTextColor(hDC,GetSysColor(COLOR_HIGHLIGHTTEXT));
  194. }
  195. else
  196. {
  197. hbr = SelectObject(hDC,hbrLGR);
  198. PatBlt(hDC,0,height,rc.right,sz.cy,PATCOPY);
  199. SelectObject(hDC,hbr);
  200. SetTextColor(hDC,RGB(0,0,0));
  201. }
  202. MyTextOut(hDC,GetSystemMetrics(SM_CXEDGE),height,lpstr,Mylstrlen(lpstr));
  203. height += sz.cy;
  204. }
  205. ImmUnlockIMCC(lpIMC->hCandInfo);
  206. }
  207. if (hOldFont) {
  208. DeleteObject(SelectObject(hDC, hOldFont));
  209. }
  210. ImmUnlockIMC(hIMC);
  211. }
  212. EndPaint(hCandWnd,&ps);
  213. DeleteObject(hbrHightLight);
  214. }
  215. /**********************************************************************/
  216. /* */
  217. /* ResizeCandWindow() */
  218. /* */
  219. /**********************************************************************/
  220. void PASCAL ResizeCandWindow( LPUIEXTRA lpUIExtra,LPINPUTCONTEXT lpIMC )
  221. {
  222. LPCANDIDATEINFO lpCandInfo;
  223. LPCANDIDATELIST lpCandList;
  224. HDC hDC;
  225. LPMYSTR lpstr;
  226. int width = 0;
  227. int height = 0;
  228. DWORD i;
  229. RECT rc;
  230. SIZE sz;
  231. if (IsWindow(lpUIExtra->uiCand.hWnd))
  232. {
  233. HFONT hOldFont;
  234. hDC = GetDC(lpUIExtra->uiCand.hWnd);
  235. hOldFont = CheckNativeCharset(hDC);
  236. if (lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo))
  237. {
  238. width = 0;
  239. height = 0;
  240. lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo + lpCandInfo->dwOffset[0]);
  241. for (i = lpCandList->dwPageStart;
  242. i < (lpCandList->dwPageStart + lpCandList->dwPageSize); i++)
  243. {
  244. lpstr = (LPMYSTR)((LPSTR)lpCandList + lpCandList->dwOffset[i]);
  245. MyGetTextExtentPoint(hDC,lpstr,Mylstrlen(lpstr),&sz);
  246. if (width < sz.cx)
  247. width = sz.cx;
  248. height += sz.cy;
  249. }
  250. ImmUnlockIMCC(lpIMC->hCandInfo);
  251. }
  252. if (hOldFont) {
  253. DeleteObject(SelectObject(hDC, hOldFont));
  254. }
  255. ReleaseDC(lpUIExtra->uiCand.hWnd,hDC);
  256. GetWindowRect(lpUIExtra->uiCand.hWnd,&rc);
  257. MoveWindow(lpUIExtra->uiCand.hWnd,
  258. rc.left,
  259. rc.top,
  260. width+ 4 * GetSystemMetrics(SM_CXEDGE),
  261. height+ 4 * GetSystemMetrics(SM_CYEDGE),
  262. TRUE);
  263. }
  264. }
  265. /**********************************************************************/
  266. /* */
  267. /* HideCandWindow() */
  268. /* */
  269. /**********************************************************************/
  270. void PASCAL HideCandWindow( LPUIEXTRA lpUIExtra)
  271. {
  272. RECT rc;
  273. if (IsWindow(lpUIExtra->uiCand.hWnd))
  274. {
  275. GetWindowRect(lpUIExtra->uiCand.hWnd,(LPRECT)&rc);
  276. lpUIExtra->uiCand.pt.x = rc.left;
  277. lpUIExtra->uiCand.pt.y = rc.top;
  278. MoveWindow(lpUIExtra->uiCand.hWnd, -1 , -1 , 0 , 0, TRUE);
  279. ShowWindow(lpUIExtra->uiCand.hWnd, SW_HIDE);
  280. lpUIExtra->uiCand.bShow = FALSE;
  281. }
  282. }
  283. /**********************************************************************/
  284. /* */
  285. /* MoveCandWindow() */
  286. /* */
  287. /**********************************************************************/
  288. void PASCAL MoveCandWindow(HWND hUIWnd, LPINPUTCONTEXT lpIMC, LPUIEXTRA lpUIExtra, BOOL fForceComp)
  289. {
  290. RECT rc;
  291. POINT pt;
  292. CANDIDATEFORM caf;
  293. if (fForceComp)
  294. {
  295. if (GetCandPosFromCompForm(lpIMC, lpUIExtra, &pt))
  296. {
  297. caf.dwIndex = 0;
  298. caf.dwStyle = CFS_CANDIDATEPOS;
  299. caf.ptCurrentPos.x = pt.x;
  300. caf.ptCurrentPos.y = pt.y;
  301. ImmSetCandidateWindow(lpUIExtra->hIMC,&caf);
  302. }
  303. return;
  304. }
  305. // Not initialized !!
  306. if (lpIMC->cfCandForm[0].dwIndex == -1)
  307. {
  308. if (GetCandPosFromCompWnd(lpUIExtra,&pt))
  309. {
  310. lpUIExtra->uiCand.pt.x = pt.x;
  311. lpUIExtra->uiCand.pt.y = pt.y;
  312. GetWindowRect(lpUIExtra->uiCand.hWnd,&rc);
  313. MoveWindow(lpUIExtra->uiCand.hWnd,pt.x,pt.y, rc.right - rc.left ,rc.bottom - rc.top ,TRUE);
  314. ShowWindow(lpUIExtra->uiCand.hWnd,SW_SHOWNOACTIVATE);
  315. lpUIExtra->uiCand.bShow = TRUE;
  316. InvalidateRect(lpUIExtra->uiCand.hWnd,NULL,FALSE);
  317. SendMessage(hUIWnd,WM_UI_CANDMOVE, 0,MAKELONG((WORD)pt.x,(WORD)pt.y));
  318. }
  319. return;
  320. }
  321. if (!IsCandidate(lpIMC))
  322. return;
  323. if (lpIMC->cfCandForm[0].dwStyle == CFS_EXCLUDE)
  324. {
  325. RECT rcWork;
  326. RECT rcAppWnd;
  327. SystemParametersInfo(SPI_GETWORKAREA,0,&rcWork,FALSE);
  328. GetClientRect(lpUIExtra->uiCand.hWnd,&rc);
  329. GetWindowRect(lpIMC->hWnd,&rcAppWnd);
  330. if (!lpUIExtra->bVertical)
  331. {
  332. pt.x = lpIMC->cfCandForm[0].ptCurrentPos.x;
  333. pt.y = lpIMC->cfCandForm[0].rcArea.bottom;
  334. ClientToScreen(lpIMC->hWnd,&pt);
  335. if (pt.y + rc.bottom > rcWork.bottom)
  336. pt.y = rcAppWnd.top +
  337. lpIMC->cfCandForm[0].rcArea.top - rc.bottom;
  338. }
  339. else
  340. {
  341. pt.x = lpIMC->cfCandForm[0].rcArea.left - rc.right;
  342. pt.y = lpIMC->cfCandForm[0].ptCurrentPos.y;
  343. ClientToScreen(lpIMC->hWnd,&pt);
  344. if (pt.x < 0)
  345. pt.x = rcAppWnd.left +
  346. lpIMC->cfCandForm[0].rcArea.right;
  347. }
  348. if (IsWindow(lpUIExtra->uiCand.hWnd))
  349. {
  350. GetWindowRect(lpUIExtra->uiCand.hWnd,&rc);
  351. MoveWindow(lpUIExtra->uiCand.hWnd,pt.x,pt.y, rc.right - rc.left ,rc.bottom - rc.top ,TRUE);
  352. ShowWindow(lpUIExtra->uiCand.hWnd,SW_SHOWNOACTIVATE);
  353. lpUIExtra->uiCand.bShow = TRUE;
  354. InvalidateRect(lpUIExtra->uiCand.hWnd,NULL,FALSE);
  355. }
  356. SendMessage(hUIWnd,WM_UI_CANDMOVE, 0,MAKELONG((WORD)pt.x,(WORD)pt.y));
  357. }
  358. else if (lpIMC->cfCandForm[0].dwStyle == CFS_CANDIDATEPOS)
  359. {
  360. pt.x = lpIMC->cfCandForm[0].ptCurrentPos.x;
  361. pt.y = lpIMC->cfCandForm[0].ptCurrentPos.y;
  362. ClientToScreen(lpIMC->hWnd,&pt);
  363. if (IsWindow(lpUIExtra->uiCand.hWnd))
  364. {
  365. GetWindowRect(lpUIExtra->uiCand.hWnd,&rc);
  366. MoveWindow(lpUIExtra->uiCand.hWnd,pt.x,pt.y, rc.right - rc.left ,rc.bottom - rc.top ,TRUE);
  367. ShowWindow(lpUIExtra->uiCand.hWnd,SW_SHOWNOACTIVATE);
  368. lpUIExtra->uiCand.bShow = TRUE;
  369. InvalidateRect(lpUIExtra->uiCand.hWnd,NULL,FALSE);
  370. }
  371. SendMessage(hUIWnd,WM_UI_CANDMOVE, 0,MAKELONG((WORD)pt.x,(WORD)pt.y));
  372. }
  373. }