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.

402 lines
10 KiB

  1. //
  2. // nuimgr.h
  3. //
  4. #ifndef NUIMGR_H
  5. #define NUIMGR_H
  6. #include "private.h"
  7. #include "ptrary.h"
  8. #include "helpers.h"
  9. #include "systhrd.h"
  10. class CThreadInputMgr;
  11. class CLBarItemSinkProxy;
  12. class CLangBarItemMgr;
  13. //////////////////////////////////////////////////////////////////////////////
  14. //
  15. // CLBarItemSink
  16. //
  17. //////////////////////////////////////////////////////////////////////////////
  18. class CLBarItemSink
  19. {
  20. public:
  21. CLBarItemSink()
  22. {
  23. #ifdef DEBUG
  24. _fUnadvised = FALSE;
  25. #endif
  26. }
  27. ~CLBarItemSink()
  28. {
  29. SafeRelease(_pItemSink);
  30. }
  31. BOOL Init(ITfLangBarItemSink *pItemSink,
  32. TF_LANGBARITEMINFO *pinfo,
  33. DWORD dwCookie)
  34. {
  35. _pItemSink = pItemSink;
  36. _pItemSink->AddRef();
  37. _dwCookie = dwCookie;
  38. _info = *pinfo;
  39. return TRUE;
  40. }
  41. ITfLangBarItemSink *_pItemSink;
  42. TF_LANGBARITEMINFO _info;
  43. DWORD _dwCookie;
  44. DWORD _dwDirtyUpdateFlags;
  45. #ifdef DEBUG
  46. BOOL _fUnadvised;
  47. #endif
  48. DBG_ID_DECLARE;
  49. };
  50. //////////////////////////////////////////////////////////////////////////////
  51. //
  52. // CLangBarItemMgr
  53. //
  54. //////////////////////////////////////////////////////////////////////////////
  55. class CLangBarItemMgr : public ITfLangBarItemMgr,
  56. public CSysThreadRef
  57. {
  58. public:
  59. CLangBarItemMgr(SYSTHREAD *psfn);
  60. ~CLangBarItemMgr();
  61. // IUnknown methods
  62. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  63. STDMETHODIMP_(ULONG) AddRef(void);
  64. STDMETHODIMP_(ULONG) Release(void);
  65. static HRESULT CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObj);
  66. BOOL _Init();
  67. //
  68. // ITfLangBarItemMgr
  69. //
  70. STDMETHODIMP EnumItems(IEnumTfLangBarItems **ppEnum);
  71. STDMETHODIMP GetItem(REFGUID rguid, ITfLangBarItem **ppItem);
  72. STDMETHODIMP AddItem(ITfLangBarItem *punk);
  73. STDMETHODIMP RemoveItem(ITfLangBarItem *punk);
  74. STDMETHODIMP AdviseItemSink(ITfLangBarItemSink *punk, DWORD *pdwCookie, REFGUID rguidItem);
  75. STDMETHODIMP UnadviseItemSink(DWORD dwCookie);
  76. STDMETHODIMP GetItemFloatingRect(DWORD dwThreadId, REFGUID rguid, RECT *prc);
  77. STDMETHODIMP GetItemsStatus(ULONG ulCount, const GUID *prgguid, DWORD *pdwStatus);
  78. STDMETHODIMP GetItemNum(ULONG *pulCount);
  79. STDMETHODIMP GetItems(ULONG ulCount, ITfLangBarItem **ppItem, TF_LANGBARITEMINFO *pInfo, DWORD *pdwStatus, ULONG *pcFetched);
  80. STDMETHODIMP AdviseItemsSink(ULONG ulCount, ITfLangBarItemSink **ppunk, const GUID *pguidItem, DWORD *pdwCookie);
  81. STDMETHODIMP UnadviseItemsSink(ULONG ulCount, DWORD *pdwCookie);
  82. HRESULT RemoveItem(REFGUID rguid);
  83. HRESULT OnUpdate(ITfLangBarItem *plbi, DWORD dwFlags);
  84. BOOL IsInOnUpdateHandler() {return _fInOnUpdateHandler ? TRUE : FALSE;}
  85. HRESULT OnUpdateHandler();
  86. CLBarItemDeviceType *FindDeviceTypeItem(REFGUID guid);
  87. void CleanUp();
  88. CPtrArray<CLBarItemSinkProxy> _rglbiProxy;
  89. static CLangBarItemMgr *_GetThis()
  90. {
  91. SYSTHREAD *psfn = GetSYSTHREAD();
  92. if (!psfn)
  93. return NULL;
  94. return psfn->plbim;
  95. }
  96. BOOL _SetThis(CLangBarItemMgr *_this)
  97. {
  98. if (!_psfn)
  99. return FALSE;
  100. _psfn->plbim = _this;
  101. return TRUE;
  102. }
  103. void EnterAssemblyChange()
  104. {
  105. _ulInAssemblyChange++;
  106. _fItemChanged = FALSE;
  107. }
  108. BOOL LeaveAssemblyChange()
  109. {
  110. Assert(_ulInAssemblyChange);
  111. _ulInAssemblyChange--;
  112. return (_fItemChanged && (_ulInAssemblyChange == 0)) ? TRUE : FALSE;
  113. }
  114. BOOL InAssemblyChange()
  115. {
  116. return _ulInAssemblyChange ? TRUE : FALSE;
  117. }
  118. void SetItemChange()
  119. {
  120. _fItemChanged = TRUE;
  121. }
  122. void StopHandlingOnUpdate() {_fHandleOnUpdate = FALSE;}
  123. void StartHandlingOnUpdate() {_fHandleOnUpdate = TRUE;}
  124. CLBarItemCtrl *_GetLBarItemCtrl() { return _plbiCtrl; }
  125. CLBarItemReconv *_GetLBarItemReconv() { return _plbiReconv; }
  126. CLBarItemWin32IME *_GetLBarItemWin32IME() { return _plbiWin32IME; }
  127. //CLBarItemHelp *_GetLBarItemHelp() { return _plbiHelp; } // unused
  128. CPtrArray<CLBarItemDeviceType> *_GetLBarItemDeviceTypeArray() { return &_rglbiDeviceType; }
  129. void _AddWin32IMECtrl(BOOL fNotify);
  130. void _RemoveWin32IMECtrl();
  131. void _RemoveSystemItems(SYSTHREAD *psfn);
  132. void ResetDirtyUpdate()
  133. {
  134. _fDirtyUpdateHandling = FALSE;
  135. }
  136. private:
  137. CLBarItemSinkProxy *GetItemSinkProxy(REFGUID rguid);
  138. DWORD _GetCookie() {_dwCurCookie++; return _dwCurCookie;} // Issue: need to prevent wrap-around
  139. DWORD _dwCurCookie;
  140. CPtrArray<CLBarItemSink> _rgSink;
  141. ULONG _ulInAssemblyChange;
  142. BOOL _fItemChanged : 1;
  143. BOOL _fHandleOnUpdate : 1;
  144. BOOL _fDirtyUpdateHandling : 1;
  145. BOOL _fInOnUpdateHandler : 1;
  146. DWORD dwDirtyUpdateHandlingTime;
  147. // system ctls
  148. CLBarItemCtrl *_plbiCtrl;
  149. CLBarItemReconv *_plbiReconv;
  150. CLBarItemWin32IME *_plbiWin32IME;
  151. CLBarItemHelp *_plbiHelp;
  152. CPtrArray<CLBarItemDeviceType> _rglbiDeviceType;
  153. DBG_ID_DECLARE;
  154. };
  155. // wrapper for CoCreateInstance calls, unlike CLangBarItemMgr this
  156. // class calls DllAddRef/Release
  157. class CLangBarItemMgr_Ole : public ITfLangBarItemMgr,
  158. public CComObjectRootImmx
  159. {
  160. public:
  161. BEGIN_COM_MAP_IMMX(CLangBarItemMgr_Ole)
  162. COM_INTERFACE_ENTRY(ITfLangBarItemMgr)
  163. END_COM_MAP_IMMX()
  164. CLangBarItemMgr_Ole()
  165. {
  166. _plbim = NULL;
  167. }
  168. ~CLangBarItemMgr_Ole()
  169. {
  170. SafeRelease(_plbim);
  171. }
  172. static HRESULT CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObj)
  173. {
  174. CLangBarItemMgr_Ole *pLangBarItemMgr_Ole;
  175. HRESULT hr;
  176. if (ppvObj == NULL)
  177. return E_INVALIDARG;
  178. *ppvObj = NULL;
  179. if (pUnkOuter != NULL)
  180. return CLASS_E_NOAGGREGATION;
  181. pLangBarItemMgr_Ole = new CLangBarItemMgr_Ole;
  182. if (pLangBarItemMgr_Ole == NULL)
  183. return E_OUTOFMEMORY;
  184. hr = pLangBarItemMgr_Ole->QueryInterface(riid, ppvObj);
  185. pLangBarItemMgr_Ole->Release();
  186. if (hr == S_OK)
  187. {
  188. hr = CLangBarItemMgr::CreateInstance(pUnkOuter, IID_ITfLangBarItemMgr, (void **)&pLangBarItemMgr_Ole->_plbim);
  189. if (hr != S_OK) // only reason I can think of would be E_OUTOFMEMORY, but be careful
  190. {
  191. pLangBarItemMgr_Ole->Release();
  192. *ppvObj = NULL;
  193. hr = E_FAIL;
  194. }
  195. }
  196. return hr;
  197. }
  198. // ITfLangBarItemMgr
  199. STDMETHODIMP EnumItems(IEnumTfLangBarItems **ppEnum)
  200. {
  201. return _plbim->EnumItems(ppEnum);
  202. }
  203. STDMETHODIMP GetItem(REFGUID rguid, ITfLangBarItem **ppItem)
  204. {
  205. return _plbim->GetItem(rguid, ppItem);
  206. }
  207. STDMETHODIMP AddItem(ITfLangBarItem *punk)
  208. {
  209. return _plbim->AddItem(punk);
  210. }
  211. STDMETHODIMP RemoveItem(ITfLangBarItem *punk)
  212. {
  213. return _plbim->RemoveItem(punk);
  214. }
  215. STDMETHODIMP AdviseItemSink(ITfLangBarItemSink *punk, DWORD *pdwCookie, REFGUID rguidItem)
  216. {
  217. return _plbim->AdviseItemSink(punk, pdwCookie, rguidItem);
  218. }
  219. STDMETHODIMP UnadviseItemSink(DWORD dwCookie)
  220. {
  221. return _plbim->UnadviseItemSink(dwCookie);
  222. }
  223. STDMETHODIMP GetItemFloatingRect(DWORD dwThreadId, REFGUID rguid, RECT *prc)
  224. {
  225. return _plbim->GetItemFloatingRect(dwThreadId, rguid, prc);
  226. }
  227. STDMETHODIMP GetItemsStatus(ULONG ulCount, const GUID *prgguid, DWORD *pdwStatus)
  228. {
  229. return _plbim->GetItemsStatus(ulCount, prgguid, pdwStatus);
  230. }
  231. STDMETHODIMP GetItemNum(ULONG *pulCount)
  232. {
  233. return _plbim->GetItemNum(pulCount);
  234. }
  235. STDMETHODIMP GetItems(ULONG ulCount, ITfLangBarItem **ppItem, TF_LANGBARITEMINFO *pInfo, DWORD *pdwStatus, ULONG *pcFetched)
  236. {
  237. return _plbim->GetItems(ulCount, ppItem, pInfo, pdwStatus, pcFetched);
  238. }
  239. STDMETHODIMP AdviseItemsSink(ULONG ulCount, ITfLangBarItemSink **ppunk, const GUID *pguidItem, DWORD *pdwCookie)
  240. {
  241. return _plbim->AdviseItemsSink(ulCount, ppunk, pguidItem, pdwCookie);
  242. }
  243. STDMETHODIMP UnadviseItemsSink(ULONG ulCount, DWORD *pdwCookie)
  244. {
  245. return _plbim->UnadviseItemsSink(ulCount, pdwCookie);
  246. }
  247. private:
  248. ITfLangBarItemMgr *_plbim;
  249. };
  250. //////////////////////////////////////////////////////////////////////////////
  251. //
  252. // CLBarItemSinkProxy
  253. //
  254. //////////////////////////////////////////////////////////////////////////////
  255. class CLBarItemSinkProxy : public ITfLangBarItemSink,
  256. public CComObjectRootImmx_NoDllAddRef
  257. {
  258. public:
  259. CLBarItemSinkProxy()
  260. {
  261. }
  262. ~CLBarItemSinkProxy()
  263. {
  264. Clear();
  265. }
  266. BOOL Init(CLangBarItemMgr *plbiMgr, ITfLangBarItem *plbi, TF_LANGBARITEMINFO *pinfo);
  267. void Clear()
  268. {
  269. _plbiMgr = NULL; // not AddRef'd
  270. SafeReleaseClear(_plbi);
  271. }
  272. BEGIN_COM_MAP_IMMX(CLBarItemSinkProxy)
  273. COM_INTERFACE_ENTRY(ITfLangBarItemSink)
  274. END_COM_MAP_IMMX()
  275. IMMX_OBJECT_IUNKNOWN_FOR_ATL()
  276. //
  277. // ITfLangBarItemSink
  278. //
  279. STDMETHODIMP OnUpdate(DWORD dwFlags)
  280. {
  281. if (!_plbiMgr || !_plbi)
  282. return E_FAIL;
  283. return _plbiMgr->OnUpdate(_plbi, dwFlags);
  284. }
  285. CLangBarItemMgr *_plbiMgr;
  286. ITfLangBarItem *_plbi;
  287. DWORD _dwCookie;
  288. BOOL _fCicTip;
  289. TF_LANGBARITEMINFO _info;
  290. DBG_ID_DECLARE;
  291. };
  292. //////////////////////////////////////////////////////////////////////////////
  293. //
  294. // CEnumLBItem
  295. //
  296. //////////////////////////////////////////////////////////////////////////////
  297. // Issue: this class should copy all data in ctor
  298. // and derive from CEnumUnknown base
  299. class CEnumLBItem : public IEnumTfLangBarItems,
  300. public CSysThreadRef,
  301. public CComObjectRootImmx
  302. {
  303. public:
  304. CEnumLBItem(SYSTHREAD *psfn);
  305. ~CEnumLBItem();
  306. BEGIN_COM_MAP_IMMX(CEnumLBItem)
  307. COM_INTERFACE_ENTRY(IEnumTfLangBarItems)
  308. END_COM_MAP_IMMX()
  309. IMMX_OBJECT_IUNKNOWN_FOR_ATL()
  310. //
  311. // IEnumTfLBItem
  312. //
  313. STDMETHODIMP Clone(IEnumTfLangBarItems **ppEnum);
  314. STDMETHODIMP Next(ULONG ulCount, ITfLangBarItem **ppNUI, ULONG *pcFetched);
  315. STDMETHODIMP Reset();
  316. STDMETHODIMP Skip(ULONG ulCount);
  317. private:
  318. int _nCur;
  319. BOOL _fHasFocusDIM;
  320. DBG_ID_DECLARE;
  321. };
  322. #endif // NUIMGR_H