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.

379 lines
9.3 KiB

  1. /*++
  2. Copyright (c) 2001, Microsoft Corporation
  3. Module Name:
  4. funcprv.cpp
  5. Abstract:
  6. This file implements the CFunctionProvider Class.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #include "private.h"
  12. #include "funcprv.h"
  13. #include "tls.h"
  14. #include "context.h"
  15. #include "profile.h"
  16. #include "cresstr.h"
  17. #include "resource.h"
  18. //////////////////////////////////////////////////////////////////////////////
  19. //
  20. // CFunctionProvider
  21. //
  22. //////////////////////////////////////////////////////////////////////////////
  23. //+---------------------------------------------------------------------------
  24. //
  25. // ctor
  26. //
  27. //----------------------------------------------------------------------------
  28. CFunctionProvider::CFunctionProvider(TfClientId tid) : CFunctionProviderBase(tid)
  29. {
  30. Init(CLSID_CAImmLayer, L"MSCTFIME::Function Provider");
  31. }
  32. //+---------------------------------------------------------------------------
  33. //
  34. // GetFunction
  35. //
  36. //----------------------------------------------------------------------------
  37. STDAPI CFunctionProvider::GetFunction(REFGUID rguid, REFIID riid, IUnknown **ppunk)
  38. {
  39. *ppunk = NULL;
  40. if (!IsEqualIID(rguid, GUID_NULL))
  41. return E_NOINTERFACE;
  42. if (IsEqualIID(riid, IID_IAImmFnDocFeed))
  43. {
  44. *ppunk = new CFnDocFeed();
  45. }
  46. if (*ppunk)
  47. return S_OK;
  48. return E_NOINTERFACE;
  49. }
  50. //////////////////////////////////////////////////////////////////////////////
  51. //
  52. // CFnDocFeed
  53. //
  54. //////////////////////////////////////////////////////////////////////////////
  55. //+---------------------------------------------------------------------------
  56. //
  57. // IUnknown
  58. //
  59. //----------------------------------------------------------------------------
  60. STDAPI CFnDocFeed::QueryInterface(REFIID riid, void **ppvObj)
  61. {
  62. *ppvObj = NULL;
  63. if (IsEqualIID(riid, IID_IUnknown) ||
  64. IsEqualIID(riid, IID_IAImmFnDocFeed))
  65. {
  66. *ppvObj = SAFECAST(this, CFnDocFeed *);
  67. }
  68. if (*ppvObj)
  69. {
  70. AddRef();
  71. return S_OK;
  72. }
  73. return E_NOINTERFACE;
  74. }
  75. STDAPI_(ULONG) CFnDocFeed::AddRef()
  76. {
  77. return InterlockedIncrement(&_cRef);
  78. }
  79. STDAPI_(ULONG) CFnDocFeed::Release()
  80. {
  81. long cr;
  82. cr = InterlockedDecrement(&_cRef);
  83. Assert(cr >= 0);
  84. if (cr == 0)
  85. {
  86. delete this;
  87. }
  88. return cr;
  89. }
  90. //+---------------------------------------------------------------------------
  91. //
  92. // CFnDocFeed::GetDisplayName
  93. //
  94. //----------------------------------------------------------------------------
  95. STDAPI CFnDocFeed::GetDisplayName(BSTR *pbstrName)
  96. {
  97. if (!pbstrName)
  98. return E_INVALIDARG;
  99. *pbstrName = SysAllocString(CRStr2(IDS_FUNCPRV_CONVERSION));
  100. if (!*pbstrName)
  101. return E_OUTOFMEMORY;
  102. return S_OK;
  103. }
  104. //+---------------------------------------------------------------------------
  105. //
  106. // CFnDocFeed::IsEnabled
  107. //
  108. //----------------------------------------------------------------------------
  109. STDAPI CFnDocFeed::IsEnabled(BOOL *pfEnable)
  110. {
  111. if (!pfEnable)
  112. return E_INVALIDARG;
  113. *pfEnable = TRUE;
  114. return S_OK;
  115. }
  116. //+---------------------------------------------------------------------------
  117. //
  118. // CFnDocFeed::DocFeed
  119. //
  120. //----------------------------------------------------------------------------
  121. STDAPI CFnDocFeed::DocFeed()
  122. {
  123. DebugMsg(TF_FUNC, TEXT("CFnDocFeed::DocFeed"));
  124. TLS* ptls = TLS::GetTLS();
  125. if (ptls == NULL)
  126. {
  127. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::DocFeed. ptls==NULL."));
  128. return E_OUTOFMEMORY;
  129. }
  130. HRESULT hr;
  131. IMCLock imc(GetActiveContext());
  132. if (FAILED(hr=imc.GetResult()))
  133. {
  134. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::DocFeed. imc==NULL."));
  135. return hr;
  136. }
  137. IMCCLock<CTFIMECONTEXT> imc_ctfime(imc->hCtfImeContext);
  138. if (FAILED(hr=imc_ctfime.GetResult()))
  139. {
  140. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::DocFeed. imc_ctfime==NULL."));
  141. return hr;
  142. }
  143. CicInputContext* pCicContext = imc_ctfime->m_pCicContext;
  144. if (!pCicContext)
  145. {
  146. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::DocFeed. pCicContext==NULL."));
  147. return E_FAIL;
  148. }
  149. UINT cp = CP_ACP;
  150. CicProfile* _pProfile = ptls->GetCicProfile();
  151. if (_pProfile == NULL)
  152. {
  153. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::DocFeed. _pProfile==NULL."));
  154. return E_FAIL;
  155. }
  156. _pProfile->GetCodePageA(&cp);
  157. pCicContext->SetupDocFeedString(imc, cp);
  158. return S_OK;
  159. }
  160. //+---------------------------------------------------------------------------
  161. //
  162. // CFnDocFeed::ClearDocFeedBuffer
  163. //
  164. //----------------------------------------------------------------------------
  165. STDAPI CFnDocFeed::ClearDocFeedBuffer()
  166. {
  167. DebugMsg(TF_FUNC, TEXT("CFnDocFeed::ClearDocFeedBuffer"));
  168. TLS* ptls = TLS::GetTLS();
  169. if (ptls == NULL)
  170. {
  171. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::ClearDocFeedBuffer. ptls==NULL."));
  172. return E_OUTOFMEMORY;
  173. }
  174. HRESULT hr;
  175. IMCLock imc(GetActiveContext());
  176. if (FAILED(hr=imc.GetResult()))
  177. {
  178. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::ClearDocFeedBuffer. imc==NULL."));
  179. return hr;
  180. }
  181. IMCCLock<CTFIMECONTEXT> imc_ctfime(imc->hCtfImeContext);
  182. if (FAILED(hr=imc_ctfime.GetResult()))
  183. {
  184. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::ClearDocFeed. imc_ctfime==NULL."));
  185. return hr;
  186. }
  187. CicInputContext* pCicContext = imc_ctfime->m_pCicContext;
  188. if (!pCicContext)
  189. {
  190. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::ClearDocFeed. pCicContext==NULL."));
  191. return E_FAIL;
  192. }
  193. pCicContext->ClearDocFeedBuffer(imc);
  194. return S_OK;
  195. }
  196. //+---------------------------------------------------------------------------
  197. //
  198. // CFnDocFeed::StartReconvert
  199. //
  200. //----------------------------------------------------------------------------
  201. STDAPI CFnDocFeed::StartReconvert()
  202. {
  203. DebugMsg(TF_FUNC, TEXT("CFnDocFeed::StartReconvert"));
  204. TLS* ptls = TLS::GetTLS();
  205. if (ptls == NULL)
  206. {
  207. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::StartReconvert. ptls==NULL."));
  208. return E_OUTOFMEMORY;
  209. }
  210. ITfThreadMgr_P* ptim_P = ptls->GetTIM();
  211. if (ptim_P == NULL)
  212. {
  213. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::StartReconvert. ptim_P==NULL."));
  214. return E_OUTOFMEMORY;
  215. }
  216. HRESULT hr;
  217. IMCLock imc(GetActiveContext());
  218. if (FAILED(hr=imc.GetResult()))
  219. {
  220. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::StartReconvert. imc==NULL."));
  221. return hr;
  222. }
  223. IMCCLock<CTFIMECONTEXT> imc_ctfime(imc->hCtfImeContext);
  224. if (FAILED(hr=imc_ctfime.GetResult()))
  225. {
  226. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::StartReconvert. imc_ctfime==NULL."));
  227. return hr;
  228. }
  229. CicInputContext* pCicContext = imc_ctfime->m_pCicContext;
  230. if (!pCicContext)
  231. {
  232. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::StartReconvert. _pCicContext==NULL."));
  233. return E_FAIL;
  234. }
  235. UINT cp = CP_ACP;
  236. CicProfile* _pProfile = ptls->GetCicProfile();
  237. if (_pProfile == NULL)
  238. {
  239. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::StartReconvert. _pProfile==NULL."));
  240. return E_FAIL;
  241. }
  242. _pProfile->GetCodePageA(&cp);
  243. pCicContext->m_fInDocFeedReconvert.SetFlag();
  244. pCicContext->SetupReconvertString(imc, ptim_P, cp, 0, FALSE);
  245. pCicContext->EndReconvertString(imc);
  246. pCicContext->m_fInDocFeedReconvert.ResetFlag();
  247. return S_OK;
  248. }
  249. //+---------------------------------------------------------------------------
  250. //
  251. // CFnDocFeed::StartUndoCompositionString
  252. //
  253. //----------------------------------------------------------------------------
  254. STDAPI CFnDocFeed::StartUndoCompositionString()
  255. {
  256. DebugMsg(TF_FUNC, TEXT("CFnDocFeed::StartUndoCompositionString"));
  257. TLS* ptls = TLS::GetTLS();
  258. if (ptls == NULL)
  259. {
  260. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::StartUndoCompositionString. ptls==NULL."));
  261. return E_OUTOFMEMORY;
  262. }
  263. ITfThreadMgr_P* ptim_P = ptls->GetTIM();
  264. if (ptim_P == NULL)
  265. {
  266. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::StartUndoCompositionString. ptim_P==NULL."));
  267. return E_OUTOFMEMORY;
  268. }
  269. HRESULT hr;
  270. IMCLock imc(GetActiveContext());
  271. if (FAILED(hr=imc.GetResult()))
  272. {
  273. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::StartUndoCompositionString. imc==NULL."));
  274. return hr;
  275. }
  276. IMCCLock<CTFIMECONTEXT> imc_ctfime(imc->hCtfImeContext);
  277. if (FAILED(hr=imc_ctfime.GetResult()))
  278. {
  279. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::StartUndoCompositionString. imc_ctfime==NULL."));
  280. return hr;
  281. }
  282. CicInputContext* pCicContext = imc_ctfime->m_pCicContext;
  283. if (!pCicContext)
  284. {
  285. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::StartUndoComposition. pCicContext==NULL."));
  286. return E_FAIL;
  287. }
  288. UINT cp = CP_ACP;
  289. CicProfile* _pProfile = ptls->GetCicProfile();
  290. if (_pProfile == NULL)
  291. {
  292. DebugMsg(TF_ERROR, TEXT("CFnDocFeed::StartUndoCompositionString. _pProfile==NULL."));
  293. return E_FAIL;
  294. }
  295. _pProfile->GetCodePageA(&cp);
  296. pCicContext->SetupUndoCompositionString(imc, ptim_P, cp);
  297. pCicContext->EndUndoCompositionString(imc);
  298. return S_OK;
  299. }