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.

451 lines
14 KiB

  1. /*++
  2. Copyright (c) 2001, Microsoft Corporation
  3. Module Name:
  4. context.h
  5. Abstract:
  6. This file defines the CicInputContext Interface Class.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #ifndef _CONTEXT_H_
  12. #define _CONTEXT_H_
  13. #include "tls.h"
  14. #include "template.h"
  15. #include "boolean.h"
  16. #include "imc.h"
  17. #include "ctxtcomp.h"
  18. #include "globals.h"
  19. #include "modebias.h"
  20. #define ArrayZeroInit(x) memset(&(x), 0, sizeof(x));
  21. class CicInputContext;
  22. class CInputContextOwnerCallBack;
  23. class CTextEventSinkCallBack;
  24. class CThreadMgrEventSink_ICCallBack;
  25. class CKbdOpenCloseEventSink;
  26. class CCandidateWndOpenCloseEventSink;
  27. class CStartReconversionNotifySink;
  28. class CModeBias;
  29. typedef struct tagCTFIMECONTEXT {
  30. CicInputContext* m_pCicContext;
  31. BOOL m_fInDestroy : 1;
  32. } CTFIMECONTEXT, *PCTFIMECONTEXT;
  33. class CicInputContext : public ITfCleanupContextSink,
  34. public ITfContextOwnerCompositionSink,
  35. public ITfCompositionSink
  36. {
  37. public:
  38. CicInputContext(TfClientId tid,
  39. LIBTHREAD* pLibTLS,
  40. HIMC hIMC)
  41. : m_tid(tid), m_pLibTLS(pLibTLS), m_hIMC(hIMC)
  42. {
  43. m_ref = 1;
  44. m_fQueryPos = IME_QUERY_POS_UNKNOWN;
  45. }
  46. virtual ~CicInputContext() { }
  47. //
  48. // IUnknown methods
  49. //
  50. public:
  51. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  52. STDMETHODIMP_(ULONG) AddRef(void);
  53. STDMETHODIMP_(ULONG) Release(void);
  54. //
  55. // ITfCleanupContextSink methods
  56. //
  57. STDMETHODIMP OnCleanupContext(TfEditCookie ecWrite, ITfContext *pic);
  58. //
  59. // ITfContextOwnerCompositionSink
  60. //
  61. STDMETHODIMP OnStartComposition(ITfCompositionView *pComposition, BOOL *pfOk);
  62. STDMETHODIMP OnUpdateComposition(ITfCompositionView *pComposition, ITfRange *pRangeNew);
  63. STDMETHODIMP OnEndComposition(ITfCompositionView *pComposition);
  64. //
  65. // ITfCompositionSink
  66. //
  67. STDMETHODIMP OnCompositionTerminated(TfEditCookie ecWrite, ITfComposition* pComposition);
  68. public:
  69. HRESULT CreateInputContext(ITfThreadMgr_P* ptim_P, IMCLock& imc);
  70. HRESULT DestroyInputContext();
  71. void GenerateMessage(IMCLock& imc);
  72. BOOL SetCompositionString(IMCLock& imc, ITfThreadMgr_P* ptim_P, DWORD dwIndex, void* pComp, DWORD dwCompLen, void* pRead, DWORD dwReadLen, UINT cp);
  73. //
  74. // Cicero's context
  75. //
  76. public:
  77. ITfContext* GetInputContext()
  78. {
  79. return m_pic;
  80. }
  81. ITfDocumentMgr* GetDocumentManager()
  82. {
  83. return m_pdim;
  84. }
  85. ITfContextOwnerServices* GetInputContextOwnerSink()
  86. {
  87. return m_piccb;
  88. }
  89. //
  90. // ref count.
  91. //
  92. private:
  93. long m_ref;
  94. //
  95. // hIMC
  96. //
  97. private:
  98. HIMC m_hIMC;
  99. //
  100. // Cicero's context
  101. //
  102. private:
  103. ITfDocumentMgr *m_pdim; // Document Manager
  104. ITfContext *m_pic; // Input Context
  105. ITfContextOwnerServices *m_piccb; // Context owner service from m_pic
  106. //
  107. // Cicero's event sink callback
  108. //
  109. private:
  110. CInputContextOwnerCallBack *m_pICOwnerSink; // IC owner call back
  111. CTextEventSinkCallBack *m_pTextEventSink; // Text event sink callback
  112. CKbdOpenCloseEventSink *m_pKbdOpenCloseEventSink; // Kbd TIP Open/Close Compartment event sink callback
  113. CCandidateWndOpenCloseEventSink *m_pCandidateWndOpenCloseEventSink; // Candidate UI Window Open/Close Compartment event sink callback
  114. CStartReconversionNotifySink *m_pStartReconvSink;
  115. //
  116. // Reconvert
  117. //
  118. public:
  119. HRESULT SetupReconvertString(IMCLock& imc, ITfThreadMgr_P* ptim_P, UINT cp, UINT uPrivMsg, BOOL fUndoComposition);
  120. HRESULT EndReconvertString(IMCLock& imc);
  121. HRESULT DelayedReconvertFuncCall(IMCLock &imc);
  122. private:
  123. HRESULT _ReconvertStringNegotiation(IMCLock& imc, ITfThreadMgr_P* ptim_P, UINT cp, UINT uPrivMsg, BOOL fUndoComposition);
  124. HRESULT _ReconvertStringTextStore(IMCLock& imc, ITfThreadMgr_P* ptim_P, UINT uPrivMsg);
  125. HRESULT MakeReconversionFuncCall( IMCLock& imc, ITfThreadMgr_P* ptim_P, CWReconvertString &wReconvStr, BOOL fCallFunc);
  126. CWCompString m_PrevResultStr;
  127. public:
  128. void UpdatePrevResultStr(IMCLock& imc)
  129. {
  130. IMCCLock<COMPOSITIONSTRING> pCompStr((HIMCC)imc->hCompStr);
  131. m_PrevResultStr.RemoveAll();
  132. m_PrevResultStr.AddCompData(
  133. (WCHAR *)pCompStr.GetOffsetPointer(pCompStr->dwResultStrOffset),
  134. pCompStr->dwResultStrLen);
  135. }
  136. private:
  137. static HRESULT Internal_QueryReconvertString_ICOwnerSink(UINT uCode, ICOARGS *pargs, VOID *pv);
  138. HRESULT Internal_QueryReconvertString(IMCLock& imc, ITfThreadMgr_P* ptim_P, RECONVERTSTRING* pReconv, UINT cp, BOOL fNeedAW);
  139. HRESULT Internal_ReconvertString(IMCLock& imc, ITfThreadMgr_P* ptim_P, CWReconvertString& wReconvStr, CWReconvertString& wReconvReadStr);
  140. HRESULT Internal_SetCompositionString(IMCLock& imc, CWCompString& wCompStr, CWCompString& wCompReadStr);
  141. //
  142. // Document Feeding
  143. //
  144. public:
  145. HRESULT SetupDocFeedString(IMCLock& imc, UINT cp);
  146. HRESULT ClearDocFeedBuffer(IMCLock& imc, BOOL fSync = TRUE)
  147. {
  148. return EscbClearDocFeedBuffer(imc, fSync);
  149. }
  150. //
  151. // Undo composition string
  152. //
  153. public:
  154. HRESULT SetupUndoCompositionString(IMCLock& imc, ITfThreadMgr_P* ptim_P, UINT cp)
  155. {
  156. return SetupReconvertString(imc, ptim_P, cp, 0, TRUE); /* 0 == Don't need ITfFnReconvert */
  157. }
  158. HRESULT EndUndoCompositionString(IMCLock& imc)
  159. {
  160. return EndReconvertString(imc);
  161. }
  162. //
  163. // QueryCharPos
  164. //
  165. public:
  166. typedef enum {
  167. IME_QUERY_POS_UNKNOWN = 0,
  168. IME_QUERY_POS_NO = 1,
  169. IME_QUERY_POS_YES = 2
  170. } IME_QUERY_POS;
  171. HRESULT InquireIMECharPosition(LANGID langid, IMCLock& imc, IME_QUERY_POS* pfQueryPos);
  172. HRESULT RetrieveIMECharPosition(IMCLock& imc, IMECHARPOSITION* ip);
  173. HRESULT ResetIMECharPosition()
  174. {
  175. m_fQueryPos = IME_QUERY_POS_UNKNOWN;
  176. return S_OK;
  177. }
  178. private:
  179. BOOL QueryCharPos(IMCLock& imc, IMECHARPOSITION* position);
  180. //
  181. // Apps support QueryCharPos().
  182. //
  183. IME_QUERY_POS m_fQueryPos;
  184. //
  185. // Generate message
  186. //
  187. public:
  188. UINT TranslateImeMessage(IMCLock& imc, LPTRANSMSGLIST lpTransMsgList = NULL);
  189. CFirstInFirstOut<TRANSMSG, TRANSMSG> *m_pMessageBuffer;
  190. //
  191. // Mouse sink
  192. //
  193. LRESULT MsImeMouseHandler(ULONG uEdge, ULONG uQuadrant, ULONG dwBtnStatus, IMCLock& imc);
  194. //
  195. // Mode bias
  196. //
  197. public:
  198. CModeBias m_ModeBias;
  199. //
  200. // Flags
  201. //
  202. public:
  203. CBoolean m_fStartComposition; // TRUE: already sent WM_IME_STARTCOMPOSITION.
  204. CBoolean m_fOpenCandidateWindow; // TRUE: opening candidate list window.
  205. CBoolean m_fInReconvertEditSession; // TRUE: In reconvert edit session.
  206. CBoolean m_fInClearDocFeedEditSession; // TRUE: In ClearDocFeed edit session.
  207. CBoolean m_fInCompComplete; // TRUE: In CompComplete running.
  208. CBoolean m_fInUpdateComposition; // TRUE: In UpdateComposition running.
  209. CBoolean m_fHanjaReConversion;
  210. #if 0
  211. CBoolean m_fHanjaRequested;
  212. #endif
  213. #ifdef UNSELECTCHECK
  214. CBoolean m_fSelected; // TRUE: if this context is selected.
  215. #endif UNSELECTCHECK
  216. CBoolean m_fOpenStatusChanging;
  217. CBoolean m_fKorImxModeChanging;
  218. CBoolean m_fGeneratedEndComposition;
  219. CBoolean m_fInProcessKey;
  220. CBoolean m_fInToAsciiEx;
  221. CBoolean m_fSelectingInSelectEx;
  222. CBoolean m_fInDocFeedReconvert; // TRUE: In CFnDocFeed::StartReconvert function.
  223. //
  224. // ITfContextOwnerCompositionSink
  225. //
  226. public:
  227. CBoolean m_fModifyingDoc;
  228. int m_cCompositions;
  229. public:
  230. CBoolean m_fConversionSentenceModeChanged;
  231. CBoolean m_fOnceModeChanged;
  232. UINT m_nInConversionModeChangingRef;
  233. UINT m_nInConversionModeResetRef;
  234. //
  235. // IME share.
  236. //
  237. public:
  238. HRESULT GetGuidAtom(IMCLock& imc, BYTE bAttr, TfGuidAtom* atom);
  239. HRESULT MapAttributes(IMCLock& imc);
  240. VOID ClearGuidMap()
  241. {
  242. usGuidMapSize = 0;
  243. memset(&aGuidMap, 0, sizeof aGuidMap);
  244. }
  245. //
  246. // Default Key Handling
  247. //
  248. public:
  249. BOOL WantThisKey(UINT uVirtKey);
  250. private:
  251. BOOL IsTopNow()
  252. {
  253. BOOL bRet = FALSE;
  254. ITfContext *pic;
  255. if (SUCCEEDED(m_pdim->GetTop(&pic)))
  256. {
  257. bRet = (pic == m_pic) ? TRUE : FALSE;
  258. pic->Release();
  259. }
  260. return bRet;
  261. }
  262. private:
  263. USHORT usGuidMapSize;
  264. TfGuidAtom aGuidMap[256]; // GUIDATOM map to IME Attribute
  265. static const USHORT ATTR_LAYER_GUID_START = ATTR_FIXEDCONVERTED + 1;
  266. //
  267. // previous candidate position
  268. //
  269. private:
  270. HWND m_hwndPrevCandidatePos;
  271. RECT m_rcPrevAppPosForCandidatePos;
  272. CANDIDATEFORM m_cfPrevCandidatePos;
  273. RECT m_rcPrevAppCandidatePos;
  274. public:
  275. HRESULT OnSetCandidatePos(TLS* ptls, IMCLock& imc);
  276. void ClearPrevCandidatePos()
  277. {
  278. m_hwndPrevCandidatePos = NULL;
  279. ArrayZeroInit(m_rcPrevAppPosForCandidatePos);
  280. ArrayZeroInit(m_cfPrevCandidatePos);
  281. ArrayZeroInit(m_rcPrevAppCandidatePos);
  282. ResetIMECharPosition();
  283. }
  284. //
  285. // Edit session helper
  286. //
  287. public:
  288. HRESULT EscbHandleThisKey(IMCLock& imc, UINT uVirtKey)
  289. {
  290. return ::EscbHandleThisKey(imc, m_tid, m_pic, m_pLibTLS, uVirtKey);
  291. }
  292. HRESULT EscbCompComplete(IMCLock& imc)
  293. {
  294. return ::EscbCompComplete(imc, m_tid, m_pic, m_pLibTLS, TRUE);
  295. }
  296. HRESULT EscbCompCancel(IMCLock& imc)
  297. {
  298. return ::EscbCompCancel(imc, m_tid, m_pic, m_pLibTLS);
  299. }
  300. HRESULT EscbGetSelection(IMCLock& imc, Interface<ITfRange>* selection)
  301. {
  302. return ::EscbGetSelection(imc, m_tid, m_pic, m_pLibTLS, selection);
  303. }
  304. HRESULT EscbReadOnlyPropMargin(IMCLock& imc, Interface<ITfRangeACP>* range_acp, LONG* pcch)
  305. {
  306. return ::EscbReadOnlyPropMargin(imc, m_tid, m_pic, m_pLibTLS, range_acp, pcch);
  307. }
  308. protected:
  309. HRESULT EscbUpdateCompositionString(IMCLock& imc)
  310. {
  311. return ::EscbUpdateCompositionString(imc, m_tid, m_pic, m_pLibTLS, 0, 0);
  312. }
  313. HRESULT EscbReplaceWholeText(IMCLock& imc, CWCompString* wCompString)
  314. {
  315. return ::EscbReplaceWholeText(imc, m_tid, m_pic, m_pLibTLS, wCompString);
  316. }
  317. HRESULT EscbClearDocFeedBuffer(IMCLock& imc, BOOL fSync = TRUE)
  318. {
  319. return ::EscbClearDocFeedBuffer(imc, *this, m_tid, m_pic, m_pLibTLS, fSync);
  320. }
  321. HRESULT EscbQueryReconvertString(IMCLock& imc, Interface_Attach<ITfContext> local_pic, CWReconvertString* wReconvertString, Interface<ITfRange>* selection)
  322. {
  323. return ::EscbQueryReconvertString(imc, m_tid, local_pic, m_pLibTLS, wReconvertString, selection);
  324. }
  325. HRESULT EscbReconvertString(IMCLock& imc, CWReconvertString* wReconvertString, Interface<ITfRange>* selection, BOOL fDocFeedOnly)
  326. {
  327. return ::EscbReconvertString(imc, m_tid, m_pic, m_pLibTLS, wReconvertString, selection, fDocFeedOnly);
  328. }
  329. HRESULT EscbCalcRangePos(IMCLock& imc, Interface_Attach<ITfContext> local_pic, CWReconvertString* wReconvertString, Interface<ITfRange>* range)
  330. {
  331. return ::EscbCalcRangePos(imc, m_tid, local_pic, m_pLibTLS, wReconvertString, range);
  332. }
  333. //
  334. // Edit session friend
  335. //
  336. private:
  337. friend HRESULT EscbHandleThisKey(IMCLock& imc, TfClientId tid, Interface_Attach<ITfContext> pic, LIBTHREAD* pLibTLS,
  338. UINT uVirtKey);
  339. friend HRESULT EscbCompComplete(IMCLock& imc, TfClientId tid, Interface_Attach<ITfContext> pic, LIBTHREAD* pLibTLS,
  340. BOOL fSync);
  341. friend HRESULT EscbCompCancel(IMCLock& imc, TfClientId tid, Interface_Attach<ITfContext> pic, LIBTHREAD* pLibTLS);
  342. friend HRESULT EscbUpdateCompositionString(IMCLock& imc, TfClientId tid, Interface_Attach<ITfContext> pic, LIBTHREAD* pLibTLS,
  343. DWORD dwDeltaStart,
  344. DWORD dwFlags);
  345. friend HRESULT EscbReplaceWholeText(IMCLock& imc, TfClientId tid, Interface_Attach<ITfContext> pic, LIBTHREAD* pLibTLS,
  346. CWCompString* wCompString);
  347. friend HRESULT EscbReconvertString(IMCLock& imc, TfClientId tid, Interface_Attach<ITfContext> pic, LIBTHREAD* pLibTLS,
  348. CWReconvertString* wReconvertString,
  349. Interface<ITfRange>* selection,
  350. BOOL fDocFeedOnly);
  351. friend HRESULT EscbClearDocFeedBuffer(IMCLock& imc, CicInputContext& CicContext, TfClientId tid, Interface_Attach<ITfContext> pic, LIBTHREAD* pLibTLS,
  352. BOOL fSync);
  353. friend HRESULT EscbGetSelection(IMCLock& imc, TfClientId tid, Interface_Attach<ITfContext> pic, LIBTHREAD* pLibTLS,
  354. Interface<ITfRange>* selection);
  355. friend HRESULT EscbQueryReconvertString(IMCLock& imc, TfClientId tid, Interface_Attach<ITfContext> pic, LIBTHREAD* pLibTLS,
  356. CWReconvertString* wReconvertString,
  357. Interface<ITfRange>* selection);
  358. friend HRESULT EscbCalcRangePos(IMCLock& imc, TfClientId tid, Interface_Attach<ITfContext> pic, LIBTHREAD* pLibTLS,
  359. CWReconvertString* wReconvertString,
  360. Interface<ITfRange>* range);
  361. friend HRESULT EscbReadOnlyPropMargin(IMCLock& imc, TfClientId tid, Interface_Attach<ITfContext> pic, LIBTHREAD* pLibTLS,
  362. Interface<ITfRangeACP>* range_acp,
  363. LONG* pcch);
  364. private:
  365. TfClientId m_tid;
  366. LIBTHREAD* m_pLibTLS;
  367. };
  368. #endif // _CONTEXT_H_