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.

255 lines
8.2 KiB

  1. /*++
  2. Copyright (c) 1985 - 1999, Microsoft Corporation
  3. Module Name:
  4. immif.h
  5. Abstract:
  6. This file defines the IMM Interface Class.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #ifndef _IMMIF_H_
  12. #define _IMMIF_H_
  13. #include "imedefs.h"
  14. #include "cime.h"
  15. #include "ctxtcomp.h"
  16. #include "caime.h"
  17. #include "ico.h"
  18. #include "globals.h"
  19. #include "immxutil.h"
  20. #include "a_context.h"
  21. class ImmIfIME : public CAIME
  22. {
  23. public:
  24. ImmIfIME();
  25. ~ImmIfIME();
  26. //
  27. // IActiveIME methods
  28. //
  29. STDMETHODIMP ConnectIMM(IActiveIMMIME_Private *pActiveIMM);
  30. STDMETHODIMP UnconnectIMM();
  31. STDMETHODIMP Inquire(DWORD dwSystemInfoFlags, IMEINFO *pIMEInfo, LPWSTR szWndClass, DWORD *pdwPrivate);
  32. STDMETHODIMP ConversionList(HIMC hIMC, LPWSTR szSource, UINT uFlag, UINT uBufLen, CANDIDATELIST *pDest, UINT *puCopied);
  33. STDMETHODIMP Configure(HKL hKL, HWND hWnd, DWORD dwMode, REGISTERWORDW *pRegisterWord);
  34. STDMETHODIMP Destroy(UINT uReserved);
  35. STDMETHODIMP Escape(HIMC hIMC, UINT uEscape, void *pData, LRESULT *plResult);
  36. STDMETHODIMP ProcessKey(HIMC hIMC, UINT uVirKey, DWORD lParam, BYTE *pbKeyState);
  37. STDMETHODIMP Notify(HIMC hIMC, DWORD dwAction, DWORD dwIndex, DWORD dwValue);
  38. STDMETHODIMP SelectEx(HIMC hIMC, DWORD dwFlags, BOOL bIsRealIme_SelKL, BOOL bIsRealIme_UnSelKL);
  39. STDMETHODIMP UnSelectCheck(HIMC hIMC);
  40. STDMETHODIMP SetCompositionString(HIMC hIMC, DWORD dwIndex, void *pComp, DWORD dwCompLen, void *pRead, DWORD dwReadLen);
  41. STDMETHODIMP ToAsciiEx(UINT uVirKey, UINT uScanCode, BYTE *pbKeyState, UINT fuState, HIMC hIMC, DWORD *pdwTransBuf, UINT *puSize);
  42. STDMETHODIMP RegisterWord(LPWSTR szReading, DWORD dwStyle, LPWSTR szString);
  43. STDMETHODIMP UnregisterWord(LPWSTR szReading, DWORD dwStyle, LPWSTR szString);
  44. STDMETHODIMP GetRegisterWordStyle(UINT nItem, STYLEBUFW *pStyleBuf, UINT *puBufSize);
  45. STDMETHODIMP EnumRegisterWord(LPWSTR szReading, DWORD dwStyle, LPWSTR szRegister, LPVOID pData, IEnumRegisterWordW **ppEnum);
  46. STDMETHODIMP GetCodePageA(UINT *uCodePage);
  47. STDMETHODIMP GetLangId(LANGID *plid);
  48. STDMETHODIMP AssociateFocus(HWND hWnd, HIMC hIMC, DWORD dwFlags);
  49. STDMETHODIMP SetThreadCompartmentValue(REFGUID rguid, VARIANT *pvar);
  50. STDMETHODIMP GetThreadCompartmentValue(REFGUID rguid, VARIANT *pvar);
  51. HRESULT ToAsciiEx(UINT uVirKey, UINT uScanCode, BYTE* pbKeyState, UINT fuState, HIMC hIMC, TRANSMSGLIST* pTransBuf, UINT* puSize);
  52. //
  53. // AIMM1.2 interface
  54. //
  55. STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void **ppv);
  56. public:
  57. BOOL _ImeInquire(LPIMEINFO, LPWSTR, DWORD);
  58. //
  59. // Helpers
  60. //
  61. static BOOL WINAPI _RegisterImeClass(WNDPROC lpfnUIWndProc);
  62. static void WINAPI _UnRegisterImeClass();
  63. LIBTHREAD *_GetLibTLS()
  64. {
  65. return &_libTLS;
  66. }
  67. BOOL IsRealIme()
  68. {
  69. BOOL fReal = FALSE;
  70. if (m_pIActiveIMMIME)
  71. {
  72. m_pIActiveIMMIME->IsRealImePublic(&fReal);
  73. }
  74. return fReal;
  75. }
  76. private:
  77. BOOL WINAPI _NotifyIME(HIMC, DWORD dwAction, DWORD dwIndex, DWORD dwValue);
  78. HRESULT WINAPI _ToAsciiEx(HIMC hImc, UINT uVKey, UINT uScanCode, TRANSMSGLIST* pTransBuf, UINT* puSize);
  79. BOOL WINAPI _WantThisKey(HIMC hImc, UINT uVKey, BOOL* pfNextHook = NULL)
  80. {
  81. IMCLock imc(hImc);
  82. if (imc.Invalid())
  83. return false;
  84. return _WantThisKey(imc, uVKey, pfNextHook);
  85. }
  86. BOOL WINAPI _WantThisKey(IMCLock& imc, UINT uVKey, BOOL* pfNextHook = NULL);
  87. HRESULT _HandleThisKey(IMCLock& imc, UINT uVKey);
  88. public:
  89. HRESULT _UpdateCompositionString(DWORD dwDeltaStart = 0);
  90. HRESULT _CompCancel(IMCLock& imc);
  91. HRESULT _CompComplete(IMCLock& imc, BOOL fSync = TRUE);
  92. public:
  93. //
  94. // Cicero stuff
  95. //
  96. HRESULT InitIMMX();
  97. void UnInitIMMX();
  98. private:
  99. BOOL IsCheckAtom();
  100. public:
  101. Interface_Attach<ITfContext> GetInputContext(IMCLock& imc) const
  102. {
  103. CAImeContext* _pAImeContext = imc->m_pAImeContext;
  104. if (!_pAImeContext)
  105. return NULL;
  106. Interface_Attach<ITfContext> ic(_pAImeContext->GetInputContext());
  107. return ic;
  108. }
  109. Interface_Attach<ITfDocumentMgr> GetDocumentManager(IMCLock& imc) const
  110. {
  111. CAImeContext* _pAImeContext = imc->m_pAImeContext;
  112. if (!_pAImeContext)
  113. return NULL;
  114. Interface_Attach<ITfDocumentMgr> dim(_pAImeContext->GetDocumentManager());
  115. return dim;
  116. }
  117. Interface_Attach<ITfContextOwnerServices> GetInputContextOwnerSink(IMCLock& imc) const
  118. {
  119. CAImeContext* _pAImeContext = imc->m_pAImeContext;
  120. if (!_pAImeContext)
  121. return NULL;
  122. Interface_Attach<ITfContextOwnerServices> iccb(_pAImeContext->GetInputContextOwnerSink());
  123. return iccb;
  124. }
  125. Interface_Attach<ITfThreadMgr_P> GetThreadManagerInternal() const
  126. {
  127. Interface_Attach<ITfThreadMgr_P> tim(m_tim);
  128. return tim;
  129. }
  130. Interface_Attach<ImmIfIME> GetCurrentInterface()
  131. {
  132. Interface_Attach<ImmIfIME> ImmIfIme(this);
  133. return ImmIfIme;
  134. }
  135. TfClientId GetClientId() {return m_tfClientId;}
  136. bool IsOpenStatusChanging() {return m_ulOpenStatusChanging > 0;}
  137. protected:
  138. static const char s_szUIClassName[16];
  139. protected:
  140. bool m_fCicInit : 1;
  141. bool m_fOnSetFocus : 1;
  142. ULONG m_ulOpenStatusChanging;
  143. ULONG m_ulKorImxModeChanging;
  144. ITfThreadMgr_P *m_tim;
  145. ITfDocumentMgr *m_dimEmpty; // empty dim for NULL hIMC.
  146. TfClientId m_tfClientId;
  147. ITfKeystrokeMgr *m_pkm;
  148. IAImeProfile *m_AImeProfile;
  149. LIBTHREAD _libTLS; // tls for the helper library. Since this object is apt threaded,
  150. // all members are accessed in a single thread
  151. // also, cicero will only create a single instance of this obj per thread
  152. BOOL m_fAddedProcessAtom : 1;
  153. private:
  154. HRESULT Internal_SetCompositionString(CWCompString& wCompStr, CWCompString& wCompReadStr);
  155. HRESULT Internal_ReconvertString(IMCLock& imc, CWReconvertString& wReconvStr, CWReconvertString& wReconvReadStr);
  156. static HRESULT Internal_QueryReconvertString_ICOwnerSink(UINT uCode, ICOARGS *pargs, VOID *pv);
  157. HRESULT Internal_QueryReconvertString(IMCLock& imc, RECONVERTSTRING* pReconv, UINT cp, BOOL fNeedAW);
  158. void SetFocus(HWND hWnd, ITfDocumentMgr* pdim, BOOL fSetFocus);
  159. public:
  160. // void AdjustZeroCompLenReconvertString(RECONVERTSTRING *pReconv, UINT cp, BOOL fAnsi);
  161. HRESULT SetupReconvertString(ITfContext *pic, IMCLock& imc, UINT uPrivMsg = 0);
  162. HRESULT EndReconvertString(IMCLock& imc);
  163. HRESULT SetupDocFeedString(ITfContext *pic, IMCLock& imc);
  164. HRESULT ClearDocFeedBuffer(ITfContext *pic, IMCLock& imc, BOOL fSync = TRUE);
  165. private:
  166. HRESULT _ReconvertStringNegotiation(ITfContext *pic, IMCLock& imc, UINT uPrivMsg);
  167. HRESULT _ReconvertStringTextStore(ITfContext *pic, IMCLock& imc, UINT uPrivMsg);
  168. public:
  169. HRESULT GetTextAndAttribute(IMCLock& imc,
  170. CWCompString* wCompString, CWCompAttribute* wCompAttribute);
  171. HRESULT GetTextAndAttribute(IMCLock& imc,
  172. CBCompString* bCompString, CBCompAttribute* bCompAttribute);
  173. public:
  174. HRESULT GetCursorPosition(IMCLock& imc, CWCompCursorPos* wCursorPosition);
  175. public:
  176. HRESULT GetSelection(IMCLock& imc, CWCompCursorPos& wStartSelection, CWCompCursorPos& wEndSelection);
  177. //
  178. // Notification
  179. //
  180. public:
  181. HRESULT OnSetOpenStatus(IMCLock& imc);
  182. HRESULT OnSetConversionSentenceMode(IMCLock& imc);
  183. HRESULT OnSetCandidatePos(IMCLock& imc);
  184. HRESULT OnSetKorImxConversionMode(IMCLock& imc);
  185. };
  186. inline void SetThis(HWND hWnd, LPARAM lParam)
  187. {
  188. SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)((CREATESTRUCT *)lParam)->lpCreateParams);
  189. }
  190. inline ImmIfIME *GetThis(HWND hWnd)
  191. {
  192. ImmIfIME *pIME = (ImmIfIME *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
  193. ASSERT(pIME != NULL);
  194. return pIME;
  195. }
  196. #endif // _IMMIF_H_