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.

436 lines
13 KiB

  1. /*++
  2. Copyright (c) 2001, Microsoft Corporation
  3. Module Name:
  4. uicomp.h
  5. Abstract:
  6. This file defines the UIComposition Class.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #ifndef _UICOMP_H_
  12. #define _UICOMP_H_
  13. #include "imc.h"
  14. #include "polytext.h"
  15. #include "caret.h"
  16. #include "tls.h"
  17. #include "globals.h"
  18. #include "cuiwnd.h"
  19. #include "cuitb.h"
  20. #define WM_UICOMP_SETCURSOR (WM_USER + 1000)
  21. typedef enum {
  22. IME_UIWND_UNKNOWN = 0,
  23. IME_UIWND_LEVEL1 = 1,
  24. IME_UIWND_LEVEL2 = 2,
  25. IME_UIWND_LEVEL3 = 3,
  26. IME_UIWND_LEVEL1_OR_LEVEL2 = 4
  27. } IME_UIWND_STATE;
  28. static const LONG DEFFRAME_LEFT_MARGIN = 2;
  29. static const LONG DEFFRAME_TOP_MARGIN = 3;
  30. static const LONG DEFFRAME_BOTTOM_MARGIN = 7;
  31. static const LONG DEFFRAME_TOP_STR_MARGIN = 7;
  32. static const LONG DEFFRAME_ENTER_BTN_CX = 18;
  33. static const LONG DEFFRAME_ENTER_BTN_CY = 18;
  34. static const LONG COMPBTN_LEFT_MARGIN = 1;
  35. static const LONG COMPBTN_TOP_MARGIN = 1;
  36. class CCompFrameWindow;
  37. class CDefCompFrameWindow;
  38. //////////////////////////////////////////////////////////////////////////////
  39. //
  40. // CCompFinalizeButton
  41. //
  42. //////////////////////////////////////////////////////////////////////////////
  43. class CCompFinalizeButton : public CUIFToolbarButton
  44. {
  45. public:
  46. CCompFinalizeButton(CCompFrameWindow *pCompFrameWindow, DWORD dwID, RECT *prc, DWORD dwStyle, DWORD dwSBtnStyle, DWORD dwSBtnShowType);
  47. ~CCompFinalizeButton();
  48. virtual void OnLeftClick();
  49. CCompFrameWindow *m_pCompFrameWnd;
  50. };
  51. //////////////////////////////////////////////////////////////////////////////
  52. //
  53. // CCompFrameWinodow
  54. //
  55. //////////////////////////////////////////////////////////////////////////////
  56. class CCompFrameWindow : public CUIFWindow
  57. {
  58. public:
  59. CCompFrameWindow(HIMC hIMC, DWORD dwStyle) : CUIFWindow(::GetInstance(), dwStyle)
  60. {
  61. m_hIMC = hIMC;
  62. }
  63. HIMC GetIMC() {return m_hIMC;}
  64. private:
  65. HIMC m_hIMC;
  66. };
  67. //////////////////////////////////////////////////////////////////////////////
  68. //
  69. // CDefCompFrameFripper
  70. //
  71. //////////////////////////////////////////////////////////////////////////////
  72. class CDefCompFrameGripper : public CUIFGripper
  73. {
  74. public:
  75. CDefCompFrameGripper::CDefCompFrameGripper(CDefCompFrameWindow *pDefCompFrameWnd, RECT *prc, DWORD dwStyle);
  76. CDefCompFrameWindow *m_pDefCompFrameWnd;
  77. };
  78. //////////////////////////////////////////////////////////////////////////////
  79. //
  80. // CDefCompFrameWinodow
  81. //
  82. //////////////////////////////////////////////////////////////////////////////
  83. class CDefCompFrameWindow : public CCompFrameWindow
  84. {
  85. public:
  86. CDefCompFrameWindow(HIMC hIMC, DWORD dwStyle);
  87. virtual ~CDefCompFrameWindow();
  88. virtual void HandleMouseMsg( UINT uMsg, POINT pt );
  89. virtual BOOL OnSetCursor( UINT uMsg, POINT pt );
  90. void Init();
  91. void SetCompStrRect(int dx, int dy, BOOL fShow);
  92. virtual void OnCreate(HWND hWnd);
  93. virtual LRESULT OnWindowPosChanged(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  94. void SetCompStrWnd(HWND hwnd) {m_hwndCompStr = hwnd;}
  95. private:
  96. void SavePosition();
  97. void LoadPosition();
  98. int GetGripperWidth();
  99. void MyScreenToClient(POINT *ppt, RECT *prc)
  100. {
  101. if (ppt)
  102. ScreenToClient(GetWnd(), ppt);
  103. if (prc)
  104. {
  105. ScreenToClient(GetWnd(), (POINT *)&prc->left);
  106. ScreenToClient(GetWnd(), (POINT *)&prc->right);
  107. }
  108. }
  109. HWND m_hwndCompStr;
  110. CDefCompFrameGripper *m_pGripper;
  111. CCompFinalizeButton *m_pEnterButton;
  112. MARGINS _marginsButton;
  113. };
  114. //////////////////////////////////////////////////////////////////////////////
  115. //
  116. // CCompButtonFrameWinodow
  117. //
  118. //////////////////////////////////////////////////////////////////////////////
  119. class CCompButtonFrameWindow : public CCompFrameWindow
  120. {
  121. public:
  122. CCompButtonFrameWindow(HIMC hIMC, DWORD dwStyle);
  123. virtual ~CCompButtonFrameWindow();
  124. void Init();
  125. void OnCreate(HWND hWnd);
  126. void MoveShow(int x, int y, BOOL fShow);
  127. private:
  128. CCompFinalizeButton *m_pEnterButton;
  129. MARGINS _marginsButton;
  130. };
  131. //////////////////////////////////////////////////////////////////////////////
  132. //
  133. // UIComposition
  134. //
  135. //////////////////////////////////////////////////////////////////////////////
  136. class UIComposition
  137. {
  138. public:
  139. static LRESULT CompWndProc(HWND hCompWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  140. public:
  141. UIComposition(HWND hUIWnd);
  142. virtual ~UIComposition();
  143. public:
  144. HRESULT OnCreate();
  145. HRESULT OnDestroy();
  146. HRESULT OnImeSetContext(IMCLock& imc, HWND hUIWnd, BOOL fActivate, DWORD isc);
  147. HRESULT OnImeSetContextAfter(IMCLock& imc);
  148. HRESULT OnImeSelect(BOOL fSelect);
  149. HRESULT OnImeStartComposition(IMCLock& imc, HWND hUIWnd);
  150. HRESULT OnImeCompositionUpdate(IMCLock& imc);
  151. HRESULT OnImeCompositionUpdateByTimer(IMCLock& imc);
  152. HRESULT OnImeEndComposition();
  153. HRESULT OnImeNotifySetCompositionWindow(IMCLock& imc);
  154. HRESULT OnImeNotifySetCompositionFont(IMCLock& imc);
  155. HRESULT OnPaint(TLS* ptls, HWND hCompWnd, HDC hDC, PAINTSTRUCT& ps, IMCLock& imc);
  156. HRESULT OnTimer(HWND hCompWnd);
  157. HRESULT OnSetCursor(IMCLock& imc, WPARAM wParam, LPARAM lParam);
  158. private:
  159. HRESULT CreateCompositionWindow(IMCLock& imc, HWND hUIWnd);
  160. HRESULT DestroyCompositionWindow();
  161. HRESULT HideCompositionWindow();
  162. HRESULT UpdateShowCompWndFlag(IMCLock& imc, DWORD* pdwCompStrLen);
  163. HRESULT UpdateCompositionRect(IMCLock& imc);
  164. HRESULT UpdateFont(IMCLock& imc);
  165. UINT CalcSingleTextExtentPoint(IMCLock& imc, HDC hDC, LPCWSTR lpsz, int string_len, PBYTE lpAttr, BOOL fCompAttr, CCompClauseStore *compclause, int window_width, LPSIZE real_size, CPolyText& poly_text, int row_index);
  166. UINT CalcMultiTextExtentPoint(IMCLock& imc, HDC hDC, LPCWSTR lpsz, int string_len, PBYTE lpAttr, BOOL fCompAttr, CCompClauseStore *compclause, int window_width, LPSIZE real_size, CPolyText& poly_text);
  167. HRESULT SetCaretPos(HDC hDC, CCaret& caret, int x, int y, LPCWSTR lpCompStr, DWORD string_length, DWORD cursor_pos, BOOL fVert, BOOL fEndCaret);
  168. HRESULT UpdateCaretRect(HDC hDC, int index, DWORD dwCursorPos, BOOL fVert, BOOL fEndCaret);
  169. typedef struct tagCOMPWND {
  170. HWND hCompWnd;
  171. CPolyText poly_text;
  172. CCaret caret;
  173. struct {
  174. LONG acpStart;
  175. LONG cch;
  176. } sel;
  177. void _ClientToScreen(RECT *prc)
  178. {
  179. ::ClientToScreen(hCompWnd, (POINT *)&prc->left);
  180. ::ClientToScreen(hCompWnd, (POINT *)&prc->right);
  181. }
  182. BOOL fDefaultCompWnd : 1;
  183. } COMPWND;
  184. HRESULT PolyTextAndAttrOut(TLS* ptls, HDC hDC, BOOL fVert, COMPWND* pcompwnd);
  185. HRESULT MakeSquiggleLine(POINT start_pt, POINT end_pt, int frequency, int amplitude, BOOL fVert, CArray<POINT, POINT>& squiggle_line);
  186. //
  187. // Query IME UI Window state
  188. //
  189. public:
  190. static IME_UIWND_STATE InquireImeUIWndState(IMCLock& imc)
  191. {
  192. HWND hDefImeWnd;
  193. if (IsWindow(hDefImeWnd=ImmGetDefaultIMEWnd(NULL)))
  194. {
  195. //
  196. // Internal notification to UI window
  197. // When receive this msg in UI wnd, then return IME context flag.
  198. //
  199. return (IME_UIWND_STATE)SendMessage(hDefImeWnd, WM_IME_NOTIFY, IMN_PRIVATE_GETCONTEXTFLAG, 0);
  200. }
  201. return IME_UIWND_UNKNOWN;
  202. }
  203. typedef struct
  204. {
  205. LONG acpStart;
  206. LONG acpEnd;
  207. RECT *prc;
  208. BOOL *pfClipped;
  209. void SetICOARGS(ICOARGS *pArgs)
  210. {
  211. acpStart = pArgs->text_ext.acpStart;
  212. acpEnd = pArgs->text_ext.acpEnd;
  213. prc = pArgs->text_ext.prc;
  214. pfClipped = pArgs->text_ext.pfClipped;
  215. }
  216. } TEXTEXT;
  217. HRESULT OnPrivateGetTextExtent(IMCLock& imc, TEXTEXT *ptext_ext);
  218. static BOOL GetImeUIWndTextExtent(TEXTEXT *ptext_ext)
  219. {
  220. HWND hDefImeWnd;
  221. if (IsWindow(hDefImeWnd=ImmGetDefaultIMEWnd(NULL)))
  222. {
  223. //
  224. // Internal notification to UI window
  225. // When receive this msg in UI wnd, then return IME context flag.
  226. //
  227. return SendMessage(hDefImeWnd,
  228. WM_IME_NOTIFY,
  229. IMN_PRIVATE_GETTEXTEXT,
  230. (LPARAM)ptext_ext) ? TRUE : FALSE;
  231. }
  232. return FALSE;
  233. }
  234. public:
  235. HRESULT OnPrivateGetContextFlag(IMCLock& imc, BOOL fStartComposition, IME_UIWND_STATE* uists);
  236. HRESULT GetCompStrExtent(POINT pt, ULONG *puEdge, ULONG *puQuadrant, IMCLock& imc);
  237. //
  238. // Get candidate window rectangle from composition window
  239. //
  240. public:
  241. typedef struct tagCandRectFromComposition {
  242. LANGID langid;
  243. DWORD dwCharPos;
  244. RECT* out_rcArea;
  245. } CandRectFromComposition;
  246. static HRESULT GetCandRectFromComposition(IMCLock& imc, LANGID langid, DWORD dwCharPos, RECT* out_rcArea)
  247. {
  248. HWND hDefImeWnd;
  249. if (IsWindow(hDefImeWnd=ImmGetDefaultIMEWnd(NULL)))
  250. {
  251. //
  252. // Internal notification to UI window
  253. // When receive this msg in UI wnd, then return candidate window rectangle
  254. //
  255. CandRectFromComposition lParam;
  256. lParam.langid = langid;
  257. lParam.dwCharPos = dwCharPos;
  258. lParam.out_rcArea = out_rcArea;
  259. SendMessage(hDefImeWnd, WM_IME_NOTIFY, IMN_PRIVATE_GETCANDRECTFROMCOMPOSITION, (LPARAM)&lParam);
  260. return S_OK;
  261. }
  262. return S_FALSE;
  263. }
  264. public:
  265. HRESULT GetSelection(IMCLock& imc, LONG *pacpSelStart, LONG *pcchSel);
  266. HRESULT OnPrivateGetCandRectFromComposition(IMCLock& imc, CandRectFromComposition* pv);
  267. HRESULT CreateDefFrameWnd(HWND hwndParent, HIMC hIMC);
  268. HRESULT CreateCompButtonWnd(HWND hwndParent, HIMC hIMC);
  269. HWND GetUIWnd() {return m_hUIWnd;}
  270. void OnSetCompositionTimerStatus(BOOL bSetTimer) {m_bTimerCOMPOSITION = bSetTimer;}
  271. private:
  272. LPWSTR GetCompStrBuffer(int nSize)
  273. {
  274. if (!m_lpszCompStr)
  275. {
  276. m_lpszCompStr = (LPWSTR)cicMemAllocClear((nSize + 1) * sizeof(WCHAR));
  277. m_nCompStr = nSize;
  278. }
  279. if (m_nCompStr < nSize)
  280. {
  281. m_lpszCompStr = (LPWSTR)cicMemReAlloc(m_lpszCompStr, (nSize + 1) * sizeof(WCHAR));
  282. m_nCompStr = nSize;
  283. }
  284. return m_lpszCompStr;
  285. }
  286. IME_UIWND_STATE GetLevelFromIMC(IMCLock& imc)
  287. {
  288. if (imc->cfCompForm.dwStyle == CFS_DEFAULT)
  289. return IME_UIWND_LEVEL1;
  290. if (imc->cfCompForm.dwStyle & (CFS_RECT | CFS_POINT | CFS_FORCE_POSITION))
  291. {
  292. RECT rc;
  293. //
  294. // if there is no room to draw, try Level1.
  295. //
  296. GetClientRect(imc->hWnd, &rc);
  297. if (!PtInRect(&rc, imc->cfCompForm.ptCurrentPos))
  298. return IME_UIWND_LEVEL1;
  299. //
  300. // if there is no room to draw, try Level1.
  301. //
  302. if (imc->cfCompForm.dwStyle & CFS_RECT)
  303. {
  304. if ((imc->cfCompForm.rcArea.top ==
  305. imc->cfCompForm.rcArea.bottom) &&
  306. (imc->cfCompForm.rcArea.left ==
  307. imc->cfCompForm.rcArea.right))
  308. return IME_UIWND_LEVEL1;
  309. }
  310. return IME_UIWND_LEVEL2;
  311. }
  312. return IME_UIWND_UNKNOWN;
  313. }
  314. private:
  315. HWND m_hUIWnd;
  316. static const LONG COMPUI_WINDOW_INDEX = 0;
  317. typedef enum tagCOMPWNDINDEX {
  318. FIRST_WINDOW,
  319. MIDDLE_WINDOW,
  320. LAST_WINDOW,
  321. END_OF_INDEX,
  322. //
  323. DEFAULT_WINDOW = -1
  324. } COMPWNDINDEX;
  325. CBoolean m_fInitUIComp;
  326. COMPWND m_CompWnd[END_OF_INDEX];
  327. COMPWND m_DefCompWnd;
  328. HFONT m_hFontLevel1;
  329. int m_tmFontHeightLevel1;
  330. HFONT m_hFontLevel2;
  331. int m_tmFontHeightLevel2;
  332. static const LONG CARET_WIDTH = 2;
  333. SIZE m_caret_size;
  334. static const LONG LINE_BOLD_WIDTH = 2;
  335. static const LONG LINE_SQUIGGLE_FREQUENCY = 4;
  336. static const LONG LINE_SQUIGGLE_AMPLITUDE = 2;
  337. DWORD m_isc;
  338. BOOL m_fActive;
  339. LPWSTR m_lpszCompStr;
  340. int m_nCompStr;
  341. BOOL m_bTimerCOMPOSITION; // when WM_IME_COMPOSITION is passed to the UI window, UIWnd procedure
  342. // start a timer for it.
  343. // this data member indicates if a timer is set and not handled (killed)yet.
  344. CBoolean m_fShowCompWnd; // When arrive WM_IME_COMPOSITION in UI window handler, UI Wnd might be Level 1 or Level 2 if
  345. // comp str is valid length and set ISC_SHOWUICOMPOSITIONWINDOW
  346. CDefCompFrameWindow *m_pDefCompFrameWnd;
  347. CCompButtonFrameWindow *m_pCompButtonFrameWnd;
  348. };
  349. #endif // _UICOMP_H_