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.

471 lines
11 KiB

  1. //
  2. // ico.cpp
  3. //
  4. #include "private.h"
  5. #include "ico.h"
  6. #include "helpers.h"
  7. //////////////////////////////////////////////////////////////////////////////
  8. //
  9. // CInputContextOwner
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. //+---------------------------------------------------------------------------
  13. //
  14. // IUnknown
  15. //
  16. //----------------------------------------------------------------------------
  17. STDAPI CInputContextOwner::QueryInterface(REFIID riid, void **ppvObj)
  18. {
  19. *ppvObj = NULL;
  20. if (IsEqualIID(riid, IID_IUnknown) ||
  21. IsEqualIID(riid, IID_ITfContextOwner))
  22. {
  23. *ppvObj = SAFECAST(this, CInputContextOwner *);
  24. }
  25. else if (IsEqualIID(riid, IID_ITfMouseTrackerACP))
  26. {
  27. *ppvObj = SAFECAST(this, ITfMouseTrackerACP *);
  28. }
  29. if (*ppvObj)
  30. {
  31. AddRef();
  32. return S_OK;
  33. }
  34. return E_NOINTERFACE;
  35. }
  36. STDAPI_(ULONG) CInputContextOwner::AddRef()
  37. {
  38. return ++_cRef;
  39. }
  40. STDAPI_(ULONG) CInputContextOwner::Release()
  41. {
  42. long cr;
  43. cr = --_cRef;
  44. Assert(cr >= 0);
  45. if (cr == 0)
  46. {
  47. delete this;
  48. }
  49. return cr;
  50. }
  51. //+---------------------------------------------------------------------------
  52. //
  53. // ctor
  54. //
  55. //----------------------------------------------------------------------------
  56. CInputContextOwner::CInputContextOwner(ICOCALLBACK pfnCallback, void *pv)
  57. {
  58. Dbg_MemSetThisName(TEXT("CInputContextOwner"));
  59. _cRef = 1;
  60. _dwCookie = ICO_INVALID_COOKIE;
  61. _pfnCallback = pfnCallback;
  62. _pv = pv;
  63. }
  64. //+---------------------------------------------------------------------------
  65. //
  66. // CInputContextOwner::PointToACP
  67. //
  68. //----------------------------------------------------------------------------
  69. STDAPI CInputContextOwner::GetACPFromPoint(const POINT *pt, DWORD dwFlags, LONG *pacp)
  70. {
  71. ICOARGS args;
  72. args.pta.pt = pt;
  73. args.pta.dwFlags = dwFlags;
  74. args.pta.pacp = pacp;
  75. return _pfnCallback(ICO_POINT_TO_ACP, &args, _pv);
  76. }
  77. //+---------------------------------------------------------------------------
  78. //
  79. // CInputContextOwner::GetScreenExt
  80. //
  81. //----------------------------------------------------------------------------
  82. STDAPI CInputContextOwner::GetScreenExt(RECT *prc)
  83. {
  84. ICOARGS args;
  85. args.scr_ext.prc = prc;
  86. return _pfnCallback(ICO_SCREENEXT, &args, _pv);
  87. }
  88. //+---------------------------------------------------------------------------
  89. //
  90. // CInputContextOwner::GetStatus
  91. //
  92. //----------------------------------------------------------------------------
  93. STDAPI CInputContextOwner::GetStatus(TF_STATUS *pdcs)
  94. {
  95. ICOARGS args;
  96. args.status.pdcs = pdcs;
  97. return _pfnCallback(ICO_STATUS, &args, _pv);
  98. }
  99. //+---------------------------------------------------------------------------
  100. //
  101. // CInputContextOwner::GetTextExt
  102. //
  103. //----------------------------------------------------------------------------
  104. STDAPI CInputContextOwner::GetTextExt(LONG acpStart, LONG acpEnd, RECT *prc, BOOL *pfClipped)
  105. {
  106. ICOARGS args;
  107. args.text_ext.acpStart = acpStart;
  108. args.text_ext.acpEnd = acpEnd;
  109. args.text_ext.prc = prc;
  110. args.text_ext.pfClipped = pfClipped;
  111. return _pfnCallback(ICO_TEXTEXT, &args, _pv);
  112. }
  113. //+---------------------------------------------------------------------------
  114. //
  115. // CInputContextOwner::GetWnd
  116. //
  117. //----------------------------------------------------------------------------
  118. STDAPI CInputContextOwner::GetWnd(HWND *phwnd)
  119. {
  120. ICOARGS args;
  121. args.hwnd.phwnd = phwnd;
  122. return _pfnCallback(ICO_WND, &args, _pv);
  123. }
  124. //+---------------------------------------------------------------------------
  125. //
  126. // CInputContextOwner::GetAttribute
  127. //
  128. //----------------------------------------------------------------------------
  129. STDAPI CInputContextOwner::GetAttribute(REFGUID rguidAttribute, VARIANT *pvarValue)
  130. {
  131. ICOARGS args;
  132. QuickVariantInit(pvarValue); // in case _pfnCallback ignores it
  133. args.sys_attr.pguid = &rguidAttribute;
  134. args.sys_attr.pvar = pvarValue;
  135. return _pfnCallback(ICO_ATTR, &args, _pv);
  136. }
  137. //+---------------------------------------------------------------------------
  138. //
  139. // CInputContextOwner::AdviseMouseSink
  140. //
  141. //----------------------------------------------------------------------------
  142. STDAPI CInputContextOwner::AdviseMouseSink(ITfRangeACP *rangeACP, ITfMouseSink *pSink, DWORD *pdwCookie)
  143. {
  144. ICOARGS args;
  145. args.advise_mouse.rangeACP = rangeACP;
  146. args.advise_mouse.pSink = pSink;
  147. args.advise_mouse.pdwCookie = pdwCookie;
  148. return _pfnCallback(ICO_ADVISEMOUSE, &args, _pv);
  149. }
  150. //+---------------------------------------------------------------------------
  151. //
  152. // CInputContextOwner::UnadviseMouseSink
  153. //
  154. //----------------------------------------------------------------------------
  155. STDAPI CInputContextOwner::UnadviseMouseSink(DWORD dwCookie)
  156. {
  157. ICOARGS args;
  158. args.unadvise_mouse.dwCookie = dwCookie;
  159. return _pfnCallback(ICO_UNADVISEMOUSE, &args, _pv);
  160. }
  161. //+---------------------------------------------------------------------------
  162. //
  163. // CInputContextOwner::_Advise
  164. //
  165. //----------------------------------------------------------------------------
  166. HRESULT CInputContextOwner::_Advise(ITfContext *pic)
  167. {
  168. HRESULT hr;
  169. ITfSource *source = NULL;
  170. _pic = NULL;
  171. hr = E_FAIL;
  172. if (FAILED(pic->QueryInterface(IID_ITfSource, (void **)&source)))
  173. goto Exit;
  174. if (FAILED(source->AdviseSink(IID_ITfContextOwner, SAFECAST(this, ITfContextOwner *), &_dwCookie)))
  175. goto Exit;
  176. _pic = pic;
  177. _pic->AddRef();
  178. hr = S_OK;
  179. Exit:
  180. SafeRelease(source);
  181. return hr;
  182. }
  183. //+---------------------------------------------------------------------------
  184. //
  185. // CInputContextOwner::_Unadvise
  186. //
  187. //----------------------------------------------------------------------------
  188. HRESULT CInputContextOwner::_Unadvise()
  189. {
  190. HRESULT hr;
  191. ITfSource *source = NULL;
  192. hr = E_FAIL;
  193. if (_pic == NULL)
  194. goto Exit;
  195. if (FAILED(_pic->QueryInterface(IID_ITfSource, (void **)&source)))
  196. goto Exit;
  197. if (FAILED(source->UnadviseSink(_dwCookie)))
  198. goto Exit;
  199. hr = S_OK;
  200. Exit:
  201. SafeRelease(source);
  202. SafeReleaseClear(_pic);
  203. return hr;
  204. }
  205. ////////////////////////////////////////////////////////////////////////////////
  206. //
  207. // CInputContextKeyEventSink
  208. //
  209. ////////////////////////////////////////////////////////////////////////////////
  210. //+---------------------------------------------------------------------------
  211. //
  212. // IUnknown
  213. //
  214. //----------------------------------------------------------------------------
  215. STDAPI CInputContextKeyEventSink::QueryInterface(REFIID riid, void **ppvObj)
  216. {
  217. *ppvObj = NULL;
  218. if (IsEqualIID(riid, IID_IUnknown) ||
  219. IsEqualIID(riid, IID_ITfContextKeyEventSink))
  220. {
  221. *ppvObj = SAFECAST(this, CInputContextKeyEventSink *);
  222. }
  223. if (*ppvObj)
  224. {
  225. AddRef();
  226. return S_OK;
  227. }
  228. return E_NOINTERFACE;
  229. }
  230. STDAPI_(ULONG) CInputContextKeyEventSink::AddRef()
  231. {
  232. return ++_cRef;
  233. }
  234. STDAPI_(ULONG) CInputContextKeyEventSink::Release()
  235. {
  236. long cr;
  237. cr = --_cRef;
  238. Assert(cr >= 0);
  239. if (cr == 0)
  240. {
  241. delete this;
  242. }
  243. return cr;
  244. }
  245. //+---------------------------------------------------------------------------
  246. //
  247. // ctor
  248. //
  249. //----------------------------------------------------------------------------
  250. CInputContextKeyEventSink::CInputContextKeyEventSink(ICOCALLBACK pfnCallback, void *pv)
  251. {
  252. Dbg_MemSetThisName(TEXT("CInputContextKeyEventSink"));
  253. _cRef = 1;
  254. _dwCookie = ICO_INVALID_COOKIE;
  255. _pfnCallback = pfnCallback;
  256. _pv = pv;
  257. }
  258. //+---------------------------------------------------------------------------
  259. //
  260. // CInputContextKeyEventSink::Advise
  261. //
  262. //----------------------------------------------------------------------------
  263. HRESULT CInputContextKeyEventSink::_Advise(ITfContext *pic)
  264. {
  265. HRESULT hr;
  266. ITfSource *source = NULL;
  267. _pic = NULL;
  268. hr = E_FAIL;
  269. if (FAILED(pic->QueryInterface(IID_ITfSource, (void **)&source)))
  270. goto Exit;
  271. if (FAILED(source->AdviseSink(IID_ITfContextKeyEventSink, this, &_dwCookie)))
  272. goto Exit;
  273. _pic = pic;
  274. _pic->AddRef();
  275. hr = S_OK;
  276. Exit:
  277. SafeRelease(source);
  278. return hr;
  279. }
  280. //+---------------------------------------------------------------------------
  281. //
  282. // CInputContextOwner::Unadvise
  283. //
  284. //----------------------------------------------------------------------------
  285. HRESULT CInputContextKeyEventSink::_Unadvise()
  286. {
  287. HRESULT hr;
  288. ITfSource *source = NULL;
  289. hr = E_FAIL;
  290. if (_pic == NULL)
  291. goto Exit;
  292. if (FAILED(_pic->QueryInterface(IID_ITfSource, (void **)&source)))
  293. goto Exit;
  294. if (FAILED(source->UnadviseSink(_dwCookie)))
  295. goto Exit;
  296. hr = S_OK;
  297. Exit:
  298. SafeRelease(source);
  299. SafeReleaseClear(_pic);
  300. return hr;
  301. }
  302. //+---------------------------------------------------------------------------
  303. //
  304. // KeyDown
  305. //
  306. //----------------------------------------------------------------------------
  307. STDAPI CInputContextKeyEventSink::OnKeyDown(WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
  308. {
  309. ICOARGS args;
  310. args.key.wParam = wParam;
  311. args.key.lParam = lParam;
  312. args.key.pic = _pic;
  313. args.key.pfEaten = pfEaten;
  314. return _pfnCallback(ICO_KEYDOWN, &args, _pv);
  315. }
  316. //+---------------------------------------------------------------------------
  317. //
  318. // OnKeyUp
  319. //
  320. //----------------------------------------------------------------------------
  321. STDAPI CInputContextKeyEventSink::OnKeyUp(WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
  322. {
  323. ICOARGS args;
  324. args.key.wParam = wParam;
  325. args.key.lParam = lParam;
  326. args.key.pic = _pic;
  327. args.key.pfEaten = pfEaten;
  328. return _pfnCallback(ICO_KEYUP, &args, _pv);
  329. }
  330. //+---------------------------------------------------------------------------
  331. //
  332. // KeyTestDown
  333. //
  334. //----------------------------------------------------------------------------
  335. STDAPI CInputContextKeyEventSink::OnTestKeyDown(WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
  336. {
  337. ICOARGS args;
  338. args.key.wParam = wParam;
  339. args.key.lParam = lParam;
  340. args.key.pic = _pic;
  341. args.key.pfEaten = pfEaten;
  342. return _pfnCallback(ICO_TESTKEYDOWN, &args, _pv);
  343. }
  344. //+---------------------------------------------------------------------------
  345. //
  346. // OnTestKeyUp
  347. //
  348. //----------------------------------------------------------------------------
  349. STDAPI CInputContextKeyEventSink::OnTestKeyUp(WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
  350. {
  351. ICOARGS args;
  352. args.key.wParam = wParam;
  353. args.key.lParam = lParam;
  354. args.key.pic = _pic;
  355. args.key.pfEaten = pfEaten;
  356. return _pfnCallback(ICO_TESTKEYUP, &args, _pv);
  357. }