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.

290 lines
11 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. //@access Public methods
  64. public:
  65. virtual ~CIme() {};
  66. INT _compMessageRefCount; //@cmember so as not to delete if recursed.
  67. short _fDestroy; //@cmember set when object wishes to be deleted.
  68. //@cmember Handle WM_IME_STARTCOMPOSITION
  69. virtual HRESULT StartComposition ( CTextMsgFilter &TextMsgFilter ) = 0;
  70. //@cmember Handle WM_IME_COMPOSITION and WM_IME_ENDCOMPOSITION
  71. virtual HRESULT CompositionString ( const LPARAM lparam, CTextMsgFilter &TextMsgFilter ) = 0;
  72. //@cmember Handle post WM_IME_CHAR to update comp window.
  73. virtual void PostIMEChar( CTextMsgFilter &TextMsgFilter ) = 0;
  74. //@cmember Handle WM_IME_NOTIFY
  75. virtual HRESULT IMENotify (const WPARAM wparam, const LPARAM lparam, CTextMsgFilter &TextMsgFilter, BOOL fCCompWindow ) = 0;
  76. virtual BOOL IMEMouseOperation ( CTextMsgFilter &TextMsgFilter, UINT msg ) = 0;
  77. enum TerminateMode
  78. {
  79. TERMINATE_NORMAL = 1,
  80. TERMINATE_FORCECANCEL = 2
  81. };
  82. void TerminateIMEComposition(CTextMsgFilter &TextMsgFilter,
  83. CIme::TerminateMode mode); //@cmember Terminate current IME composition session.
  84. //@cmember check if we need to ignore WM_IME_CHAR messages
  85. BOOL IgnoreIMECharMsg() { return _cIgnoreIMECharMsg > 0; }
  86. //@cmember skip WM_IME_CHAR message
  87. void SkipIMECharMsg() { _cIgnoreIMECharMsg--; }
  88. //@cmember accept WM_IME_CHAR message
  89. void AcceptIMECharMsg() { _cIgnoreIMECharMsg = 0; }
  90. static void CheckKeyboardFontMatching ( long cp, CTextMsgFilter &TextMsgFilter, ITextFont *pTextFont ); //@cmember Check current font/keyboard matching.
  91. BOOL IsTerminated () //@cmember Return _fIMETerminated
  92. {
  93. return _fIMETerminated;
  94. }
  95. INT GetIMELevel () //@cmember Return the current IME level.
  96. {
  97. return _imeLevel;
  98. }
  99. //@access Protected methods
  100. protected: //@cmember Get composition string, convert to unicode.
  101. 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 );
  102. static HRESULT CheckInsertResultString ( const LPARAM lparam, CTextMsgFilter &TextMsgFilter, short *pcch = NULL );
  103. void SetCompositionFont ( CTextMsgFilter &TextMsgFilter, ITextFont *pTextFont ); //@cmember Setup for level 2 and 3 composition and candidate window's font.
  104. void SetCompositionForm ( CTextMsgFilter &TextMsgFilter ); //@cmember Setup for level 2 IME composition window's position.
  105. };
  106. /*
  107. * IME_Lev2
  108. *
  109. * @class Level 2 IME support.
  110. *
  111. */
  112. class CIme_Lev2 : public CIme
  113. {
  114. //@access Public methods
  115. public: //@cmember Handle level 2 WM_IME_STARTCOMPOSITION
  116. virtual HRESULT StartComposition ( CTextMsgFilter &TextMsgFilter );
  117. //@cmember Handle level 2 WM_IME_COMPOSITION
  118. virtual HRESULT CompositionString ( const LPARAM lparam, CTextMsgFilter &TextMsgFilter );
  119. //@cmember Handle post WM_IME_CHAR to update comp window.
  120. virtual void PostIMEChar( CTextMsgFilter &TextMsgFilter );
  121. //@cmember Handle level 2 WM_IME_NOTIFY
  122. virtual HRESULT IMENotify (const WPARAM wparam, const LPARAM lparam, CTextMsgFilter &TextMsgFilter, BOOL fIgnore );
  123. virtual BOOL IMEMouseOperation ( CTextMsgFilter &TextMsgFilter, UINT msg )
  124. {return FALSE;}
  125. CIme_Lev2( CTextMsgFilter &TextMsgFilter );
  126. virtual ~CIme_Lev2();
  127. ITextFont *_pTextFont; //@cmember base format
  128. };
  129. /*
  130. * IME_PROTECTED
  131. *
  132. * @class IME_PROTECTED
  133. *
  134. */
  135. class CIme_Protected : public CIme
  136. {
  137. //@access Public methods
  138. public: //@cmember Handle level 2 WM_IME_STARTCOMPOSITION
  139. virtual HRESULT StartComposition ( CTextMsgFilter &TextMsgFilter )
  140. {_imeLevel = IME_PROTECTED; return S_OK;}
  141. //@cmember Handle level 2 WM_IME_COMPOSITION
  142. virtual HRESULT CompositionString ( const LPARAM lparam, CTextMsgFilter &TextMsgFilter );
  143. //@cmember Handle post WM_IME_CHAR to update comp window.
  144. virtual void PostIMEChar( CTextMsgFilter &TextMsgFilter )
  145. {}
  146. //@cmember Handle level 2 WM_IME_NOTIFY
  147. virtual HRESULT IMENotify (const WPARAM wparam, const LPARAM lparam, CTextMsgFilter &TextMsgFilter, BOOL fIgnore )
  148. {return S_FALSE;}
  149. virtual BOOL IMEMouseOperation ( CTextMsgFilter &TextMsgFilter, UINT msg )
  150. {return FALSE;}
  151. };
  152. /*
  153. * IME_Lev3
  154. *
  155. * @class Level 3 IME support.
  156. *
  157. */
  158. class CIme_Lev3 : public CIme_Lev2
  159. {
  160. //@access Private data
  161. private:
  162. //@access Protected data
  163. protected:
  164. long _ichStart; //@cmember maintain starting ich.
  165. long _cchCompStr; //@cmember maintain composition string's cch.
  166. short _sIMESuportMouse; //@cmember IME mouse support
  167. WPARAM _wParamBefore; //@cmember Previous wParam sent to IME
  168. HWND _hwndIME; //@cmember current IME hWnd
  169. long _crTextColor; //@cmember current font text color
  170. long _crBkColor; //@cmember current font background color
  171. // Helper function
  172. //@cmember get imeshare color for the attribute
  173. COLORREF GetIMEShareColor(CIMEShare *pIMEShare, DWORD dwAttribute, DWORD dwProperty);
  174. //@access Public methods
  175. public: //@cmember Handle level 3 WM_IME_STARTCOMPOSITION
  176. virtual HRESULT StartComposition ( CTextMsgFilter &TextMsgFilter );
  177. //@cmember Handle level 3 WM_IME_COMPOSITION
  178. virtual HRESULT CompositionString ( const LPARAM lparam, CTextMsgFilter &TextMsgFilter );
  179. //@cmember Handle level 3 WM_IME_NOTIFY
  180. virtual HRESULT IMENotify (const WPARAM wparam, const LPARAM lparam, CTextMsgFilter &TextMsgFilter, BOOL fCCompWindow );
  181. void SetCompositionStyle ( CTextMsgFilter &TextMsgFilter, UINT attribute, ITextFont *pTextFont );
  182. CIme_Lev3( CTextMsgFilter &TextMsgFilter );
  183. virtual ~CIme_Lev3() {};
  184. virtual BOOL IMEMouseOperation ( CTextMsgFilter &TextMsgFilter, UINT msg );
  185. virtual BOOL IMESupportMouse ( CTextMsgFilter &TextMsgFilter );
  186. public:
  187. short _fUpdateWindow; //@cmember Update Window after closing CandidateWindow
  188. long GetIMECompositionStart()
  189. { return _ichStart; }
  190. long GetIMECompositionLen()
  191. { return _cchCompStr; }
  192. };
  193. /*
  194. * Special IME_Lev3 for Korean Hangeul -> Hanja conversion
  195. *
  196. * @class Hangual IME support.
  197. *
  198. */
  199. class CIme_HangeulToHanja : public CIme_Lev3
  200. {
  201. //@access Private data
  202. private:
  203. public:
  204. CIme_HangeulToHanja( CTextMsgFilter &TextMsgFilter );
  205. //@cmember Handle Hangeul WM_IME_STARTCOMPOSITION
  206. virtual HRESULT StartComposition ( CTextMsgFilter &TextMsgFilter );
  207. //@cmember Handle Hangeul WM_IME_COMPOSITION
  208. virtual HRESULT CompositionString ( const LPARAM lparam, CTextMsgFilter &TextMsgFilter );
  209. virtual BOOL IMEMouseOperation ( CTextMsgFilter &TextMsgFilter, UINT msg )
  210. {return FALSE;}
  211. };
  212. // Glue functions to call the respective methods of an IME object stored in the ed.
  213. HRESULT StartCompositionGlue ( CTextMsgFilter &TextMsgFilter );
  214. HRESULT CompositionStringGlue ( const LPARAM lparam, CTextMsgFilter &TextMsgFilter );
  215. HRESULT EndCompositionGlue ( CTextMsgFilter &TextMsgFilter, BOOL fForceDelete);
  216. void PostIMECharGlue ( CTextMsgFilter &TextMsgFilter );
  217. HRESULT IMENotifyGlue ( const WPARAM wparam, const LPARAM lparam, CTextMsgFilter &TextMsgFilter ); // @parm the containing text edit.
  218. HRESULT IMEMouseCheck(CTextMsgFilter &TextMsgFilter, UINT *pmsg, WPARAM *pwparam, LPARAM *plparam, LRESULT *plres);
  219. // IME helper functions.
  220. void IMECompositionFull ( CTextMsgFilter &TextMsgFilter );
  221. LRESULT OnGetIMECompositionMode ( CTextMsgFilter &TextMsgFilter );
  222. BOOL IMECheckGetInvertRange(CTextMsgFilter *ed, LONG &, LONG &);
  223. void CheckDestroyIME ( CTextMsgFilter &TextMsgFilter );
  224. BOOL IMEHangeulToHanja ( CTextMsgFilter &TextMsgFilter );
  225. BOOL IMEMessage ( CTextMsgFilter &TextMsgFilter, UINT uMsg,
  226. WPARAM wParam, LPARAM lParam, BOOL bPostMessage );
  227. HIMC LocalGetImmContext ( CTextMsgFilter &TextMsgFilter );
  228. void LocalReleaseImmContext ( CTextMsgFilter &TextMsgFilter, HIMC hIMC );
  229. long IMEShareToTomUL ( UINT ulID );
  230. #endif // define _IME_H