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.

301 lines
12 KiB

  1. /*
  2. * @doc INTERNAL
  3. *
  4. * @module _ime.h -- support for IME APIs |
  5. *
  6. * Purpose:
  7. * Most everything to do with FE composition string editing passes
  8. * through here.
  9. *
  10. * Authors: <nl>
  11. * Jon Matousek <nl>
  12. * Justin Voskuhl <nl>
  13. * Hon Wah Chan <nl>
  14. *
  15. * History: <nl>
  16. * 10/18/1995 jonmat Cleaned up level 2 code and converted it into
  17. * a class hierarchy supporting level 3.
  18. *
  19. * Copyright (c) 1995-1996 Microsoft Corporation. All rights reserved.
  20. *
  21. */
  22. #ifndef _IME_H
  23. #define _IME_H
  24. class CTextMsgFilter;
  25. // defines for IME Level 2 and 3
  26. #define IME_LEVEL_2 2
  27. #define IME_LEVEL_3 3
  28. #define IME_PROTECTED 4
  29. /*
  30. * IME
  31. *
  32. * @class base class for IME support.
  33. *
  34. * @devnote
  35. * For level 2, at caret IMEs, the IME will draw a window directly over the text giving the
  36. * impression that the text is being processed by the application--this is called pseudo inline.
  37. * All UI is handled by the IME. This mode is currenlty bypassed in favor of level 3 true inline (TI);
  38. * however, it would be trivial to allow a user preference to select this mode. Some IMEs may have
  39. * a "special" UI, in which case level 3 TI is *NOT* used, necessitating level 2.
  40. *
  41. * For level 2, near caret IMEs, the IME will draw a very small and obvious window near the current
  42. * caret position in the document. This currently occurs for PRC(?) and Taiwan.
  43. * All UI is handled by the IME.
  44. *
  45. * For level 3, at caret IMEs, the composition string is drawn by the application, which is called
  46. * true inline, bypassing the level 2 "composition window".
  47. * Currently, we allow the IME to support all remaining UI *except* drawing of the composition string.
  48. */
  49. class CIme
  50. {
  51. friend LRESULT OnGetIMECompositionMode ( CTextMsgFilter &TextMsgFilter );
  52. friend HRESULT CompositionStringGlue ( const LPARAM lparam, CTextMsgFilter &TextMsgFilter );
  53. friend HRESULT EndCompositionGlue ( CTextMsgFilter &TextMsgFilter, BOOL fForceDelete);
  54. friend void CheckDestroyIME ( CTextMsgFilter &TextMsgFilter );
  55. //@access Protected data
  56. protected:
  57. short _imeLevel; //@cmember IME Level 2 or 3
  58. short _cIgnoreIMECharMsg; //@cmember Level 2 IME use to eat WM_IME_CHAR message
  59. short _fIgnoreEndComposition; //@cmember ignore the next End Composition message
  60. short _fIMETerminated; //@cmember indicate this IME has been terminated
  61. short _fSkipFirstOvertype; //@cmember skip first overtype if selection is
  62. // deleted on StartComposition
  63. short _fGotFinalString; //@cmember indicate if we have received final string
  64. //@access Public methods
  65. public:
  66. virtual ~CIme() {};
  67. INT _compMessageRefCount; //@cmember so as not to delete if recursed.
  68. short _fDestroy; //@cmember set when object wishes to be deleted.
  69. //@cmember Handle WM_IME_STARTCOMPOSITION
  70. virtual HRESULT StartComposition ( CTextMsgFilter &TextMsgFilter ) = 0;
  71. //@cmember Handle WM_IME_COMPOSITION and WM_IME_ENDCOMPOSITION
  72. virtual HRESULT CompositionString ( const LPARAM lparam, CTextMsgFilter &TextMsgFilter ) = 0;
  73. //@cmember Handle post WM_IME_CHAR to update comp window.
  74. virtual void PostIMEChar( CTextMsgFilter &TextMsgFilter ) = 0;
  75. //@cmember Handle WM_IME_NOTIFY
  76. virtual HRESULT IMENotify (const WPARAM wparam, const LPARAM lparam, CTextMsgFilter &TextMsgFilter, BOOL fCCompWindow ) = 0;
  77. virtual BOOL IMEMouseOperation ( CTextMsgFilter &TextMsgFilter, UINT msg, WPARAM wParam, BOOL &fTerminateIME ) = 0;
  78. virtual LRESULT GetIMECompositionMode ( CTextMsgFilter &TextMsgFilter ) = 0;
  79. enum TerminateMode
  80. {
  81. TERMINATE_NORMAL = 1,
  82. TERMINATE_FORCECANCEL = 2
  83. };
  84. void TerminateIMEComposition(CTextMsgFilter &TextMsgFilter,
  85. CIme::TerminateMode mode); //@cmember Terminate current IME composition session.
  86. //@cmember check if we need to ignore WM_IME_CHAR messages
  87. BOOL IgnoreIMECharMsg() { return _cIgnoreIMECharMsg > 0; }
  88. //@cmember skip WM_IME_CHAR message
  89. void SkipIMECharMsg() { _cIgnoreIMECharMsg--; }
  90. //@cmember accept WM_IME_CHAR message
  91. void AcceptIMECharMsg() { _cIgnoreIMECharMsg = 0; }
  92. static void CheckKeyboardFontMatching ( long cp, CTextMsgFilter *pTextMsgFilter, ITextFont *pTextFont ); //@cmember Check current font/keyboard matching.
  93. BOOL IsTerminated () //@cmember Return _fIMETerminated
  94. {
  95. return _fIMETerminated;
  96. }
  97. INT GetIMELevel () //@cmember Return the current IME level.
  98. {
  99. return _imeLevel;
  100. }
  101. static HRESULT CheckInsertResultString ( const LPARAM lparam, CTextMsgFilter &TextMsgFilter,
  102. short *pcch = NULL, int *pcbSize = 0, WCHAR *pOutputBuff = NULL );
  103. //@access Protected methods
  104. protected: //@cmember Get composition string, convert to unicode.
  105. static INT GetCompositionStringInfo( HIMC hIMC, DWORD dwIndex, WCHAR *uniCompStr, INT cchUniCompStr, BYTE *attrib, INT cbAttrib, LONG *cursorCP, LONG *cchAttrib, UINT kbCodePage, BOOL bUnicodeIME, BOOL bUsingAimm );
  106. void SetCompositionFont ( CTextMsgFilter &TextMsgFilter, ITextFont *pTextFont ); //@cmember Setup for level 2 and 3 composition and candidate window's font.
  107. void SetCompositionForm ( CTextMsgFilter &TextMsgFilter ); //@cmember Setup for level 2 IME composition window's position.
  108. };
  109. /*
  110. * IME_Lev2
  111. *
  112. * @class Level 2 IME support.
  113. *
  114. */
  115. class CIme_Lev2 : public CIme
  116. {
  117. //@access Public methods
  118. public: //@cmember Handle level 2 WM_IME_STARTCOMPOSITION
  119. virtual HRESULT StartComposition ( CTextMsgFilter &TextMsgFilter );
  120. //@cmember Handle level 2 WM_IME_COMPOSITION
  121. virtual HRESULT CompositionString ( const LPARAM lparam, CTextMsgFilter &TextMsgFilter );
  122. //@cmember Handle post WM_IME_CHAR to update comp window.
  123. virtual void PostIMEChar( CTextMsgFilter &TextMsgFilter );
  124. //@cmember Handle level 2 WM_IME_NOTIFY
  125. virtual HRESULT IMENotify (const WPARAM wparam, const LPARAM lparam, CTextMsgFilter &TextMsgFilter, BOOL fIgnore );
  126. //@cmember Handle IME notify message
  127. virtual BOOL IMEMouseOperation ( CTextMsgFilter &TextMsgFilter, UINT msg, WPARAM wParam, BOOL &fTerminateIME );
  128. //@cmember Handle IME mouse Operation
  129. virtual LRESULT GetIMECompositionMode ( CTextMsgFilter &TextMsgFilter );
  130. //@cmember Return current composition mode
  131. CIme_Lev2( CTextMsgFilter &TextMsgFilter );
  132. virtual ~CIme_Lev2();
  133. ITextFont *_pTextFont; //@cmember base format
  134. };
  135. /*
  136. * IME_PROTECTED
  137. *
  138. * @class IME_PROTECTED
  139. *
  140. */
  141. class CIme_Protected : public CIme
  142. {
  143. //@access Public methods
  144. public: //@cmember Handle level 2 WM_IME_STARTCOMPOSITION
  145. virtual HRESULT StartComposition ( CTextMsgFilter &TextMsgFilter )
  146. {_imeLevel = IME_PROTECTED; return S_OK;}
  147. //@cmember Handle level 2 WM_IME_COMPOSITION
  148. virtual HRESULT CompositionString ( const LPARAM lparam, CTextMsgFilter &TextMsgFilter );
  149. //@cmember Handle post WM_IME_CHAR to update comp window.
  150. virtual void PostIMEChar( CTextMsgFilter &TextMsgFilter )
  151. {}
  152. //@cmember Handle level 2 WM_IME_NOTIFY
  153. virtual HRESULT IMENotify (const WPARAM wparam, const LPARAM lparam, CTextMsgFilter &TextMsgFilter, BOOL fIgnore )
  154. {return S_FALSE;}
  155. virtual BOOL IMEMouseOperation ( CTextMsgFilter &TextMsgFilter, UINT msg, WPARAM wParam, BOOL &fTerminateIME )
  156. {fTerminateIME = TRUE; return FALSE;}
  157. virtual LRESULT GetIMECompositionMode ( CTextMsgFilter &TextMsgFilter )
  158. { return ICM_NOTOPEN;}
  159. };
  160. /*
  161. * IME_Lev3
  162. *
  163. * @class Level 3 IME support.
  164. *
  165. */
  166. class CIme_Lev3 : public CIme_Lev2
  167. {
  168. //@access Private data
  169. private:
  170. //@access Protected data
  171. protected:
  172. long _ichStart; //@cmember maintain starting ich.
  173. long _cchCompStr; //@cmember maintain composition string's cch.
  174. short _sIMESuportMouse; //@cmember IME mouse support
  175. WPARAM _wParamBefore; //@cmember Previous wParam sent to IME
  176. HWND _hwndIME; //@cmember current IME hWnd
  177. long _crTextColor; //@cmember current font text color
  178. long _crBkColor; //@cmember current font background color
  179. // Helper function
  180. //@cmember get imeshare color for the attribute
  181. COLORREF GetIMEShareColor(CIMEShare *pIMEShare, DWORD dwAttribute, DWORD dwProperty);
  182. //@access Public methods
  183. public: //@cmember Handle level 3 WM_IME_STARTCOMPOSITION
  184. virtual HRESULT StartComposition ( CTextMsgFilter &TextMsgFilter );
  185. //@cmember Handle level 3 WM_IME_COMPOSITION
  186. virtual HRESULT CompositionString ( const LPARAM lparam, CTextMsgFilter &TextMsgFilter );
  187. //@cmember Handle level 3 WM_IME_NOTIFY
  188. virtual HRESULT IMENotify (const WPARAM wparam, const LPARAM lparam, CTextMsgFilter &TextMsgFilter, BOOL fCCompWindow );
  189. void SetCompositionStyle ( CTextMsgFilter &TextMsgFilter, UINT attribute, ITextFont *pTextFont );
  190. CIme_Lev3( CTextMsgFilter &TextMsgFilter );
  191. virtual ~CIme_Lev3() {};
  192. virtual BOOL IMEMouseOperation ( CTextMsgFilter &TextMsgFilter, UINT msg, WPARAM wParam, BOOL &fTerminateIME );
  193. virtual BOOL IMESupportMouse ( CTextMsgFilter &TextMsgFilter );
  194. virtual LRESULT GetIMECompositionMode ( CTextMsgFilter &TextMsgFilter );
  195. public:
  196. short _fUpdateWindow; //@cmember Update Window after closing CandidateWindow
  197. short _fHandlingFinalString; //@cmember In the middle of handling final result string
  198. long GetIMECompositionStart()
  199. { return _ichStart; }
  200. long GetIMECompositionLen()
  201. { return _cchCompStr; }
  202. };
  203. /*
  204. * Special IME_Lev3 for Korean Hangeul -> Hanja conversion
  205. *
  206. * @class Hangual IME support.
  207. *
  208. */
  209. class CIme_HangeulToHanja : public CIme_Lev3
  210. {
  211. //@access Private data
  212. private:
  213. public:
  214. CIme_HangeulToHanja( CTextMsgFilter &TextMsgFilter );
  215. //@cmember Handle Hangeul WM_IME_STARTCOMPOSITION
  216. virtual HRESULT StartComposition ( CTextMsgFilter &TextMsgFilter );
  217. //@cmember Handle Hangeul WM_IME_COMPOSITION
  218. virtual HRESULT CompositionString ( const LPARAM lparam, CTextMsgFilter &TextMsgFilter );
  219. virtual BOOL IMEMouseOperation ( CTextMsgFilter &TextMsgFilter, UINT msg, WPARAM wParam, BOOL &fTerminateIME )
  220. {fTerminateIME = TRUE; return FALSE;}
  221. };
  222. // Glue functions to call the respective methods of an IME object stored in the ed.
  223. HRESULT StartCompositionGlue ( CTextMsgFilter &TextMsgFilter );
  224. HRESULT CompositionStringGlue ( const LPARAM lparam, CTextMsgFilter &TextMsgFilter );
  225. HRESULT EndCompositionGlue ( CTextMsgFilter &TextMsgFilter, BOOL fForceDelete);
  226. void PostIMECharGlue ( CTextMsgFilter &TextMsgFilter );
  227. HRESULT IMENotifyGlue ( const WPARAM wparam, const LPARAM lparam, CTextMsgFilter &TextMsgFilter ); // @parm the containing text edit.
  228. HRESULT IMEMouseCheck(CTextMsgFilter &TextMsgFilter, UINT *pmsg, WPARAM *pwparam, LPARAM *plparam, LRESULT *plres);
  229. // IME helper functions.
  230. void IMECompositionFull ( CTextMsgFilter &TextMsgFilter );
  231. LRESULT OnGetIMECompositionMode ( CTextMsgFilter &TextMsgFilter );
  232. BOOL IMECheckGetInvertRange(CTextMsgFilter *ed, LONG &, LONG &);
  233. void CheckDestroyIME ( CTextMsgFilter &TextMsgFilter );
  234. BOOL IMEHangeulToHanja ( CTextMsgFilter &TextMsgFilter );
  235. BOOL IMEMessage ( CTextMsgFilter &TextMsgFilter, UINT uMsg,
  236. WPARAM wParam, LPARAM lParam, BOOL bPostMessage );
  237. HIMC LocalGetImmContext ( CTextMsgFilter &TextMsgFilter );
  238. void LocalReleaseImmContext ( CTextMsgFilter &TextMsgFilter, HIMC hIMC );
  239. long IMEShareToTomUL ( UINT ulID );
  240. #define TEST_LEFT 0x0001
  241. #define TEST_RIGHT 0x0002
  242. #define TEST_TOP 0x0004
  243. #define TEST_BOTTOM 0x0008
  244. #define TEST_ALL (TEST_LEFT | TEST_RIGHT | TEST_TOP | TEST_BOTTOM)
  245. LONG TestPoint ( POINT &pt1, POINT &pt2, POINT &ptTest, LONG lTestOption, LONG lTextFlow );
  246. #endif // define _IME_H