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.

468 lines
17 KiB

  1. //
  2. // tim.h
  3. //
  4. // CThreadInputMgr
  5. //
  6. #ifndef TIM_H
  7. #define TIM_H
  8. #include "private.h"
  9. #include "globals.h"
  10. #include "ptrmap.h"
  11. #include "ptrary.h"
  12. #include "nuimgr.h"
  13. #include "utb.h"
  14. #include "compart.h"
  15. #include "msctfp.h"
  16. #include "dim.h"
  17. #include "ic.h"
  18. extern void ExecuteLoader(void);
  19. #define TIM_NUM_CONNECTIONPTS 6
  20. // these are indices into _rgSinks, must match _c_rgConnectionIIDs
  21. #define TIM_SINK_ITfDisplayAttributeNotifySink 0
  22. #define TIM_SINK_ITfActiveLanguageProfileNotifySink 1
  23. #define TIM_SINK_ITfUIFocusSink 2
  24. #define TIM_SINK_ITfPreservedKeyNotifySink 3
  25. #define TIM_SINK_ITfThreadMgrEventSink 4
  26. #define TIM_SINK_ITfKeyTraceEventSink 5
  27. //
  28. // for _AsyncKeyHandler()
  29. //
  30. #define TIM_AKH_SYNC 0x0001
  31. #define TIM_AKH_TESTONLY 0x0002
  32. #define TIM_AKH_SIMULATEKEYMSGS 0x0004
  33. class CHotKey;
  34. // callback for CThreadMgr::_CleanupContexts
  35. typedef void (*POSTCLEANUPCALLBACK)(BOOL fAbort, LONG_PTR lPrivate);
  36. //////////////////////////////////////////////////////////////////////////////
  37. //
  38. // CTip
  39. //
  40. //////////////////////////////////////////////////////////////////////////////
  41. class CTip
  42. {
  43. public:
  44. CTip() {};
  45. ~CTip()
  46. {
  47. Assert(!_rgHotKey.Count());
  48. };
  49. void CleanUp()
  50. {
  51. Assert(!_pKeyEventSink);
  52. Assert(!_pFuncProvider);
  53. if (_hInstSubstituteHKL)
  54. {
  55. FreeLibrary(_hInstSubstituteHKL);
  56. _hInstSubstituteHKL = NULL;
  57. }
  58. SafeReleaseClear(_pKeyEventSink);
  59. SafeReleaseClear(_pFuncProvider);
  60. SafeReleaseClear(_pTip);
  61. }
  62. ITfTextInputProcessor *_pTip;
  63. TfGuidAtom _guidatom;
  64. ITfKeyEventSink *_pKeyEventSink;
  65. ITfFunctionProvider *_pFuncProvider;
  66. ITfCleanupContextDurationSink *_pCleanupDurationSink;
  67. BOOL _fForegroundKeyEventSink : 1;
  68. BOOL _fActivated : 1;
  69. BOOL _fNeedCleanupCall : 1;
  70. CPtrArray<CHotKey> _rgHotKey;
  71. HMODULE _hInstSubstituteHKL;
  72. };
  73. typedef struct _CLEANUPCONTEXT
  74. {
  75. BOOL fSync;
  76. const GUID *pCatId;
  77. LANGID langid;
  78. POSTCLEANUPCALLBACK pfnPostCleanup;
  79. LONG_PTR lPrivate;
  80. } CLEANUPCONTEXT;
  81. typedef enum { TIM_INITDIM, TIM_UNINITDIM, TIM_SETFOCUS, TIM_INITIC, TIM_UNINITIC } TimNotify;
  82. typedef enum { TSH_SYSHOTKEY, TSH_NONSYSHOTKEY, TSH_DONTCARE} TimSysHotkey;
  83. typedef enum { KS_DOWN, KS_DOWN_TEST, KS_UP, KS_UP_TEST } KSEnum;
  84. class CDocumentInputManager;
  85. class CInputContext;
  86. class CTIPRegister;
  87. class CACPWrap;
  88. class CFunctionProvider;
  89. //////////////////////////////////////////////////////////////////////////////
  90. //
  91. // CThreadInputMgr
  92. //
  93. //////////////////////////////////////////////////////////////////////////////
  94. class CThreadInputMgr : public ITfThreadMgr_P,
  95. public ITfKeystrokeMgr_P,
  96. public ITfLangBarItemMgr,
  97. public ITfSource,
  98. public ITfSourceSingle,
  99. public ITfMessagePump,
  100. public ITfConfigureSystemKeystrokeFeed,
  101. public ITfClientId,
  102. public CCompartmentMgr,
  103. public CComObjectRoot_CreateSingletonInstance_Verify<CThreadInputMgr>
  104. {
  105. public:
  106. CThreadInputMgr();
  107. ~CThreadInputMgr();
  108. BEGIN_COM_MAP_IMMX(CThreadInputMgr)
  109. COM_INTERFACE_ENTRY(ITfThreadMgr)
  110. COM_INTERFACE_ENTRY(ITfThreadMgr_P_old)
  111. COM_INTERFACE_ENTRY(ITfThreadMgr_P)
  112. COM_INTERFACE_ENTRY(ITfSource)
  113. COM_INTERFACE_ENTRY(ITfSourceSingle)
  114. COM_INTERFACE_ENTRY(ITfCompartmentMgr)
  115. COM_INTERFACE_ENTRY(ITfKeystrokeMgr)
  116. COM_INTERFACE_ENTRY(ITfKeystrokeMgr_P)
  117. COM_INTERFACE_ENTRY(ITfLangBarItemMgr)
  118. COM_INTERFACE_ENTRY(ITfMessagePump)
  119. COM_INTERFACE_ENTRY(ITfConfigureSystemKeystrokeFeed)
  120. COM_INTERFACE_ENTRY(ITfClientId)
  121. END_COM_MAP_IMMX()
  122. static BOOL VerifyCreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObj);
  123. static void PostCreateInstance(REFIID riid, void *pvObj) {}
  124. // ITfThreadMgr
  125. STDMETHODIMP Activate(TfClientId *ptid);
  126. STDMETHODIMP Deactivate();
  127. STDMETHODIMP CreateDocumentMgr(ITfDocumentMgr **ppdim);
  128. STDMETHODIMP EnumDocumentMgrs(IEnumTfDocumentMgrs **ppEnum);
  129. STDMETHODIMP GetFocus(ITfDocumentMgr **ppdimFocus);
  130. STDMETHODIMP SetFocus(ITfDocumentMgr *pdimFocus);
  131. STDMETHODIMP AssociateFocus(HWND hwnd, ITfDocumentMgr *pdimNew, ITfDocumentMgr **ppdimPrev);
  132. STDMETHODIMP IsThreadFocus(BOOL *pfUIFocus);
  133. STDMETHODIMP GetFunctionProvider(REFGUID guidPrvdr, ITfFunctionProvider **ppv);
  134. STDMETHODIMP EnumFunctionProviders(IEnumTfFunctionProviders **ppEnum);
  135. // ITfSource
  136. STDMETHODIMP AdviseSink(REFIID refiid, IUnknown *punk, DWORD *pdwCookie);
  137. STDMETHODIMP UnadviseSink(DWORD dwCookie);
  138. // ITfSourceSingle
  139. STDMETHODIMP AdviseSingleSink(TfClientId tid, REFIID riid, IUnknown *punk);
  140. STDMETHODIMP UnadviseSingleSink(TfClientId tid, REFIID riid);
  141. STDMETHODIMP GetGlobalCompartment(ITfCompartmentMgr **pCompMgr);
  142. // ITfThreadMgr_P
  143. STDMETHODIMP GetAssociated(HWND hWnd, ITfDocumentMgr **ppdim);
  144. STDMETHODIMP SetSysHookSink(ITfSysHookSink *pSink);
  145. STDMETHODIMP RequestPostponedLock(ITfContext *pic);
  146. STDMETHODIMP IsKeystrokeFeedEnabled(BOOL *pfEnabled);
  147. STDMETHODIMP CallImm32HotkeyHanlder(WPARAM wParam, LPARAM lParam, BOOL *pbHandled);
  148. STDMETHODIMP ActivateEx(TfClientId *ptid, DWORD dwFlags);
  149. //
  150. // ITfKeystrokeManager
  151. //
  152. STDMETHODIMP GetForeground(CLSID *pclsid);
  153. STDMETHODIMP AdviseKeyEventSink(TfClientId tid, ITfKeyEventSink *pSink, BOOL fForeground);
  154. STDMETHODIMP UnadviseKeyEventSink(TfClientId tid);
  155. STDMETHODIMP TestKeyDown(WPARAM wParam, LPARAM lParam, BOOL *pfEaten);
  156. STDMETHODIMP TestKeyUp(WPARAM wParam, LPARAM lParam, BOOL *pfEaten);
  157. STDMETHODIMP KeyDown(WPARAM wParam, LPARAM lParam, BOOL *pfEaten);
  158. STDMETHODIMP KeyUp(WPARAM wParam, LPARAM lParam, BOOL *pfEaten);
  159. STDMETHODIMP GetPreservedKey(ITfContext *pic, const TF_PRESERVEDKEY *pprekey, GUID *pguid);
  160. STDMETHODIMP IsPreservedKey(REFGUID rguid, const TF_PRESERVEDKEY *pprekey, BOOL *pfRegistered);
  161. STDMETHODIMP PreserveKey(TfClientId tid, REFGUID rguid, const TF_PRESERVEDKEY *prekey, const WCHAR *pchDesc, ULONG cchDesc);
  162. STDMETHODIMP UnpreserveKey(REFGUID rguid, const TF_PRESERVEDKEY *pprekey);
  163. STDMETHODIMP SetPreservedKeyDescription(REFGUID rguid, const WCHAR *pchDesc, ULONG cchDesc);
  164. STDMETHODIMP GetPreservedKeyDescription(REFGUID rguid, BSTR *pbstrDesc);
  165. STDMETHODIMP SimulatePreservedKey(ITfContext *pic, REFGUID rguid, BOOL *pfEaten);
  166. STDMETHODIMP KeyDownUpEx(WPARAM wParam, LPARAM lParam, DWORD dwFlags, BOOL *pfEaten);
  167. //
  168. // ITfKeystrokeManager_P
  169. //
  170. STDMETHODIMP PreserveKeyEx(TfClientId tid, REFGUID rguid, const TF_PRESERVEDKEY *prekey, const WCHAR *pchDesc, ULONG cchDesc, DWORD dwFlags);
  171. // ITfConfigureSystemKeystrokeFeed
  172. STDMETHODIMP DisableSystemKeystrokeFeed();
  173. STDMETHODIMP EnableSystemKeystrokeFeed();
  174. //
  175. // ITfLangBarItemMgr
  176. //
  177. STDMETHODIMP EnumItems(IEnumTfLangBarItems **ppEnum);
  178. STDMETHODIMP GetItem(REFGUID rguid, ITfLangBarItem **ppItem);
  179. STDMETHODIMP AddItem(ITfLangBarItem *punk);
  180. STDMETHODIMP RemoveItem(ITfLangBarItem *punk);
  181. STDMETHODIMP AdviseItemSink(ITfLangBarItemSink *punk, DWORD *pdwCookie, REFGUID rguid);
  182. STDMETHODIMP UnadviseItemSink(DWORD dwCookie);
  183. STDMETHODIMP GetItemFloatingRect(DWORD dwThreadId, REFGUID rguid, RECT *prc);
  184. STDMETHODIMP GetItemsStatus(ULONG ulCount, const GUID *prgguid, DWORD *pdwStatus);
  185. STDMETHODIMP GetItemNum(ULONG *pulCount);
  186. STDMETHODIMP GetItems(ULONG ulCount, ITfLangBarItem **ppItem, TF_LANGBARITEMINFO *pInfo, DWORD *pdwStatus, ULONG *pcFetched);
  187. STDMETHODIMP AdviseItemsSink(ULONG ulCount, ITfLangBarItemSink **ppunk, const GUID *pguidItem, DWORD *pdwCookie);
  188. STDMETHODIMP UnadviseItemsSink(ULONG ulCount, DWORD *pdwCookie);
  189. //
  190. // ITfMessagePump
  191. //
  192. STDMETHODIMP PeekMessageA(LPMSG pMsg, HWND hwnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg, BOOL *pfResult);
  193. STDMETHODIMP GetMessageA(LPMSG pMsg, HWND hwnd, UINT wMsgFilterMin, UINT wMsgFilterMax, BOOL *pfResult);
  194. STDMETHODIMP PeekMessageW(LPMSG pMsg, HWND hwnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg, BOOL *pfResult);
  195. STDMETHODIMP GetMessageW(LPMSG pMsg, HWND hwnd, UINT wMsgFilterMin, UINT wMsgFilterMax, BOOL *pfResult);
  196. //
  197. // ITfClientId
  198. //
  199. STDMETHODIMP GetClientId(REFCLSID rclsid, TfClientId *ptid);
  200. HRESULT ActivateInputProcessor(REFCLSID clsid, REFGUID guidProfile, HKL hklSubstitute, BOOL fActivate);
  201. HRESULT NotifyActivateInputProcessor(REFCLSID clsid, REFGUID guidProfile, BOOL fActivate);
  202. HRESULT _SetForeground(TfClientId tid);
  203. BOOL _ProcessHotKey(WPARAM wParam, LPARAM lParam, TimSysHotkey tsh, BOOL fTest, BOOL fSync);
  204. BOOL _SyncProcessHotKey(WPARAM wParam, LPARAM lParam, TimSysHotkey tsh, BOOL fTest);
  205. // use this to grab the single CThreadInputMgr for the calling thread
  206. static CThreadInputMgr *_GetThis()
  207. {
  208. SYSTHREAD *psfn = GetSYSTHREAD();
  209. if (!psfn)
  210. return NULL;
  211. return psfn->ptim;
  212. }
  213. static CThreadInputMgr *_GetThisFromSYSTHREAD(SYSTHREAD *psfn)
  214. {
  215. Assert(psfn);
  216. return psfn->ptim;
  217. }
  218. ITfTextInputProcessor *_tidToTIP(TfClientId tid)
  219. {
  220. ITfTextInputProcessor *tip;
  221. _GetITfIMEfromGUIDATOM(tid, &tip);
  222. return tip;
  223. }
  224. TfClientId _TIPToTid(ITfTextInputProcessor *tip)
  225. {
  226. TfClientId tid;
  227. _GetGUIDATOMfromITfIME(tip, &tid);
  228. return tid;
  229. }
  230. void _SetProcessAtom();
  231. HRESULT _OnThreadFocus(BOOL fActivate);
  232. void _GetSubstituteIMEModule(CTip *ptip, HKL hklSubstitute);
  233. HRESULT _ActivateTip(REFCLSID clsid, HKL hklSubstitute, CTip **pptip);
  234. HRESULT _DeactivateTip(CTip *ptip);
  235. HRESULT _SetFocus(CDocumentInputManager *pdim, BOOL fInternal);
  236. CDocumentInputManager *_GetAssoc(HWND hWnd);
  237. HWND _GetAssoced(CDocumentInputManager *pdim);
  238. BOOL _GetGUIDATOMfromITfIME(ITfTextInputProcessor *pIME, TfGuidAtom *pguidatom);
  239. BOOL _GetITfIMEfromGUIDATOM(TfGuidAtom guidatom, ITfTextInputProcessor **ppIME);
  240. BOOL _GetCTipfromGUIDATOM(TfGuidAtom guidatom, CTip **pptip);
  241. UINT _GetTIPCount() { return _rgTip.Count(); }
  242. const CTip *_GetCTip(UINT i) { return _rgTip.Get(i); }
  243. CDocumentInputManager *_GetFocusDocInputMgr() { return _pFocusDocInputMgr; }
  244. BOOL _IsInternalFocusedDim() { return _fInternalFocusedDim; }
  245. BOOL _IsNoFirstSetFocusAfterActivated() {return _fFirstSetFocusAfterActivated;}
  246. void _NotifyCallbacks(TimNotify notify, CDocumentInputManager *dim, void *pv);
  247. void UpdateDispAttr();
  248. CPtrArray<CDocumentInputManager> _rgdim;
  249. void InitSystemFunctionProvider();
  250. CFunctionProvider *GetSystemFunctionProvider();
  251. CStructArray<GENERICSINK> *_GetThreadMgrEventSink() { return &_rgSinks[TIM_SINK_ITfThreadMgrEventSink]; }
  252. CStructArray<GENERICSINK> *_GetActiveTIPNotifySinks() { return &_rgSinks[TIM_SINK_ITfActiveLanguageProfileNotifySink]; }
  253. CStructArray<GENERICSINK> *_GetDispAttrNotifySinks() { return &_rgSinks[TIM_SINK_ITfDisplayAttributeNotifySink]; }
  254. CStructArray<GENERICSINK> *_GetUIFocusSinks() { return &_rgSinks[TIM_SINK_ITfUIFocusSink]; }
  255. CStructArray<GENERICSINK> *_GetPreservedKeyNotifySinks() { return &_rgSinks[TIM_SINK_ITfPreservedKeyNotifySink]; }
  256. CStructArray<GENERICSINK> *_GetKeyTraceEventSinks() { return &_rgSinks[TIM_SINK_ITfKeyTraceEventSink]; }
  257. HRESULT _GetActiveInputProcessors(ULONG ulCount, CLSID *pclsid, ULONG *pulCount);
  258. HRESULT _IsActiveInputProcessor(REFCLSID clsid);
  259. HRESULT _IsActiveInputProcessorByATOM(TfGuidAtom guidatom);
  260. BOOL _AppWantsKeystrokes()
  261. {
  262. Assert(_cAppWantsKeystrokesRef >= 0);
  263. return _cAppWantsKeystrokesRef > 0;
  264. }
  265. BOOL _IsKeystrokeFeedEnabled()
  266. {
  267. Assert(_cDisableSystemKeystrokeFeedRef >= 0);
  268. return (_cDisableSystemKeystrokeFeedRef == 0);
  269. }
  270. BOOL _AsyncKeyHandler(WPARAM wParam, LPARAM lParam, DWORD dwFlags, BOOL *pfEaten);
  271. BOOL _IsMSAAEnabled() { return _pAAAdaptor != NULL; }
  272. IAccServerDocMgr *_GetAAAdaptor() { return _pAAAdaptor; }
  273. CPtrMap<HWND, CDocumentInputManager> *GetDimWndMap() {return &_dimwndMap;}
  274. CGlobalCompartmentMgr *GetGlobalComp(void)
  275. {
  276. SYSTHREAD *psfn = GetSYSTHREAD();
  277. return psfn->_pGlobalCompMgr;
  278. }
  279. void _CleanupContexts(CLEANUPCONTEXT *pcc);
  280. void _HandlePendingCleanupContext();
  281. void _NotifyKeyTraceEventSink(WPARAM wParam, LPARAM lParam);
  282. ITfSysHookSink *GetSysHookSink() {return _pSysHookSink;}
  283. TfClientId GetForegroundKeyboardTip() {return _tidForeground;}
  284. HRESULT _KeyStroke(KSEnum ksenum, WPARAM wParam, LPARAM lParam, BOOL *pfEaten, BOOL fSync, DWORD dwFlags);
  285. void _SendEndCleanupNotifications();
  286. BOOL _IsValidTfClientId(TfClientId tid)
  287. {
  288. CTip *ctip;
  289. return (tid == g_gaApp) || (tid == g_gaSystem) || _GetCTipfromGUIDATOM(tid, &ctip);
  290. }
  291. void _InitMSAA();
  292. void _UninitMSAA();
  293. void ClearLangBarItemMgr()
  294. {
  295. _plbim = NULL;
  296. }
  297. private:
  298. void _CleanupContextsWorker(CLEANUPCONTEXT *pcc);
  299. void _CalcAndSendBeginCleanupNotifications(CLEANUPCONTEXT *pcc);
  300. BOOL _CheckNewActiveView(CDocumentInputManager *pdim);
  301. HRESULT _CallKeyEventSink(TfClientId tid, CInputContext *pic, KSEnum ksenum, WPARAM wParam, LPARAM lParam, BOOL *pfEaten);
  302. HRESULT _CallKeyEventSinkNotForeground(TfClientId tid, CInputContext *pic, KSEnum ksenum, WPARAM wParam, LPARAM lParam, BOOL *pfEaten);
  303. HRESULT _CallSimulatePreservedKey(CHotKey *pHotKey, CInputContext *pic, REFGUID rguid, BOOL *pfEaten);
  304. BOOL _FindHotKeyByTID(TfClientId tid, WPARAM wParam, LPARAM lParam, CHotKey **ppHotKey, TimSysHotkey tsh, UINT uModSrc);
  305. BOOL _FindHotKeyAndIC(WPARAM wParam, LPARAM lParam, CHotKey **ppHotKey, CInputContext **ppic, TimSysHotkey tsh, UINT uModSrc);
  306. BOOL _FindHotKeyInIC(WPARAM wParam, LPARAM lParam, CHotKey **ppHotKey, CInputContext *pic, TimSysHotkey tsh, UINT uModSrc);
  307. BOOL _GetFirstPreservedKey(REFGUID rguid, CHotKey **ppHotKey);
  308. BOOL _CheckPreservedKey(KSEnum ksenum, WPARAM wParam, LPARAM lParam, BOOL fSync);
  309. HRESULT _OnPreservedKeyUpdate(CHotKey *pHotKey);
  310. BOOL _IsThisHotKey(TfClientId tid, const TF_PRESERVEDKEY *pprekey);
  311. HRESULT InternalPreserveKey(CTip *ctip, REFGUID rguid, const TF_PRESERVEDKEY *pprekey, const WCHAR *pchDesc, ULONG cchDesc, DWORD dwFlags, CHotKey **ppHotKey);
  312. HRESULT InitDefaultHotkeys();
  313. HRESULT UninitDefaultHotkeys();
  314. BOOL _IsMsctfimeDim(ITfDocumentMgr *pdim);
  315. static BOOL _SetThis(CThreadInputMgr *_this)
  316. {
  317. SYSTHREAD *psfn = GetSYSTHREAD();
  318. if (!psfn)
  319. return FALSE;
  320. psfn->ptim = _this;
  321. return TRUE;
  322. }
  323. static void _StaticInit_OnActivate();
  324. CStructArray<DWORD> _rgCookie;
  325. CPtrArray<CHotKey> *_rgHotKey[256];
  326. CFunctionProvider *_pSysFuncPrv;
  327. ITfFunctionProvider *_pAppFuncProvider;
  328. TfClientId _tidForeground;
  329. TfClientId _tidPrevForeground;
  330. static const IID *_c_rgConnectionIIDs[TIM_NUM_CONNECTIONPTS];
  331. CStructArray<GENERICSINK> _rgSinks[TIM_NUM_CONNECTIONPTS];
  332. CPtrMap<HWND, CDocumentInputManager> _dimwndMap;
  333. CPtrArray<CTip> _rgTip;
  334. CDocumentInputManager *_pFocusDocInputMgr;
  335. int _iActivateRefCount;
  336. TsViewCookie _vcActiveView; // only valid if _fActiveView == TRUE
  337. BOOL _fInternalFocusedDim : 1;
  338. BOOL _fActiveView : 1;
  339. // aa stuff
  340. //
  341. void _MSAA_OnSetFocus(CDocumentInputManager *dim)
  342. {
  343. CInputContext *pic;
  344. if (_pAAAdaptor == NULL)
  345. return; // no msaa hookup
  346. pic = (dim == NULL) ? NULL : dim->_GetTopIC();
  347. _pAAAdaptor->OnDocumentFocus((pic == NULL) ? NULL : pic->_GetAATSI());
  348. }
  349. IAccServerDocMgr *_pAAAdaptor; // the AA adaptor
  350. //
  351. // end aa stuff
  352. ITfLangBarItemMgr *_plbim;
  353. BOOL _fActiveUI : 1;
  354. int _cAppWantsKeystrokesRef;
  355. int _cDisableSystemKeystrokeFeedRef;
  356. BOOL _fInActivate : 1;
  357. BOOL _fInDeactivate : 1;
  358. BOOL _fFirstSetFocusAfterActivated : 1;
  359. CLEANUPCONTEXT *_pPendingCleanupContext;
  360. BOOL _fPendingCleanupContext : 1;
  361. BOOL _fAddedProcessAtom : 1;
  362. BOOL _fReleaseDisplayAttrMgr : 1;
  363. ITfSysHookSink *_pSysHookSink;
  364. DBG_ID_DECLARE;
  365. };
  366. #endif // TIM_H