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.

270 lines
6.1 KiB

  1. //
  2. // funcprv.cpp
  3. //
  4. #include "private.h"
  5. #include "helpers.h"
  6. #include "immxutil.h"
  7. #include "funcprv.h"
  8. #include "cresstr.h"
  9. #include "resource.h"
  10. //////////////////////////////////////////////////////////////////////////////
  11. //
  12. // CFunctionProvider
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. //+---------------------------------------------------------------------------
  16. //
  17. // ctor
  18. //
  19. //----------------------------------------------------------------------------
  20. CFunctionProvider::CFunctionProvider(ImmIfIME *pImmIfIME, TfClientId tid) : CFunctionProviderBase(tid)
  21. {
  22. Init(CLSID_CAImmLayer, L"AIMM12 Function Provider");
  23. _ImmIfIME = pImmIfIME;
  24. }
  25. //+---------------------------------------------------------------------------
  26. //
  27. // GetFunction
  28. //
  29. //----------------------------------------------------------------------------
  30. STDAPI CFunctionProvider::GetFunction(REFGUID rguid, REFIID riid, IUnknown **ppunk)
  31. {
  32. *ppunk = NULL;
  33. if (!IsEqualIID(rguid, GUID_NULL))
  34. return E_NOINTERFACE;
  35. if (IsEqualIID(riid, IID_IAImmFnDocFeed))
  36. {
  37. *ppunk = new CFnDocFeed(this);
  38. }
  39. if (*ppunk)
  40. return S_OK;
  41. return E_NOINTERFACE;
  42. }
  43. //////////////////////////////////////////////////////////////////////////////
  44. //
  45. // CFnDocFeed
  46. //
  47. //////////////////////////////////////////////////////////////////////////////
  48. //+---------------------------------------------------------------------------
  49. //
  50. // IUnknown
  51. //
  52. //----------------------------------------------------------------------------
  53. STDAPI CFnDocFeed::QueryInterface(REFIID riid, void **ppvObj)
  54. {
  55. *ppvObj = NULL;
  56. if (IsEqualIID(riid, IID_IUnknown) ||
  57. IsEqualIID(riid, IID_IAImmFnDocFeed))
  58. {
  59. *ppvObj = SAFECAST(this, CFnDocFeed *);
  60. }
  61. if (*ppvObj)
  62. {
  63. AddRef();
  64. return S_OK;
  65. }
  66. return E_NOINTERFACE;
  67. }
  68. STDAPI_(ULONG) CFnDocFeed::AddRef()
  69. {
  70. return InterlockedIncrement(&_cRef);
  71. }
  72. STDAPI_(ULONG) CFnDocFeed::Release()
  73. {
  74. long cr;
  75. cr = InterlockedDecrement(&_cRef);
  76. Assert(cr >= 0);
  77. if (cr == 0)
  78. {
  79. delete this;
  80. }
  81. return cr;
  82. }
  83. //+---------------------------------------------------------------------------
  84. //
  85. // ctor
  86. //
  87. //----------------------------------------------------------------------------
  88. CFnDocFeed::CFnDocFeed(CFunctionProvider *pFuncPrv)
  89. {
  90. _cRef = 1;
  91. _pFuncPrv = pFuncPrv;
  92. _pFuncPrv->AddRef();
  93. }
  94. //+---------------------------------------------------------------------------
  95. //
  96. // dtor
  97. //
  98. //----------------------------------------------------------------------------
  99. CFnDocFeed::~CFnDocFeed()
  100. {
  101. _pFuncPrv->Release();
  102. }
  103. //+---------------------------------------------------------------------------
  104. //
  105. // dtor
  106. //
  107. //----------------------------------------------------------------------------
  108. STDAPI CFnDocFeed::GetDisplayName(BSTR *pbstrName)
  109. {
  110. if (!pbstrName)
  111. return E_INVALIDARG;
  112. *pbstrName = SysAllocString(CRStr2(IDS_FUNCPRV_CONVERSION));
  113. if (!*pbstrName)
  114. return E_OUTOFMEMORY;
  115. return S_OK;
  116. }
  117. //+---------------------------------------------------------------------------
  118. //
  119. // dtor
  120. //
  121. //----------------------------------------------------------------------------
  122. STDAPI CFnDocFeed::IsEnabled(BOOL *pfEnable)
  123. {
  124. if (!pfEnable)
  125. return E_INVALIDARG;
  126. *pfEnable = TRUE;
  127. return S_OK;
  128. }
  129. //+---------------------------------------------------------------------------
  130. //
  131. // CFnDocFeed::DocFeed
  132. //
  133. //----------------------------------------------------------------------------
  134. STDAPI CFnDocFeed::DocFeed()
  135. {
  136. IMTLS *ptls = IMTLS_GetOrAlloc();
  137. if (ptls == NULL)
  138. return E_FAIL;
  139. IMCLock imc(ptls->hIMC);
  140. if (imc.Invalid())
  141. return E_FAIL;
  142. CAImeContext* pAImeContext = imc->m_pAImeContext;
  143. if (!pAImeContext)
  144. return E_FAIL;
  145. Assert(_pFuncPrv);
  146. _pFuncPrv->_ImmIfIME->SetupDocFeedString(pAImeContext->GetInputContext(), imc);
  147. return S_OK;
  148. }
  149. //+---------------------------------------------------------------------------
  150. //
  151. // CFnDocFeed::ClearDocFeedBuffer
  152. //
  153. //----------------------------------------------------------------------------
  154. STDAPI CFnDocFeed::ClearDocFeedBuffer()
  155. {
  156. IMTLS *ptls = IMTLS_GetOrAlloc();
  157. if (ptls == NULL)
  158. return E_FAIL;
  159. IMCLock imc(ptls->hIMC);
  160. if (imc.Invalid())
  161. return E_FAIL;
  162. CAImeContext* pAImeContext = imc->m_pAImeContext;
  163. if (!pAImeContext)
  164. return E_FAIL;
  165. Assert(_pFuncPrv);
  166. _pFuncPrv->_ImmIfIME->ClearDocFeedBuffer(pAImeContext->GetInputContext(), imc);
  167. return S_OK;
  168. }
  169. //+---------------------------------------------------------------------------
  170. //
  171. // CFnDocFeed::StartReconvert
  172. //
  173. //----------------------------------------------------------------------------
  174. STDAPI CFnDocFeed::StartReconvert()
  175. {
  176. IMTLS *ptls = IMTLS_GetOrAlloc();
  177. if (ptls == NULL)
  178. return E_FAIL;
  179. IMCLock imc(ptls->hIMC);
  180. if (imc.Invalid())
  181. return E_FAIL;
  182. CAImeContext* pAImeContext = imc->m_pAImeContext;
  183. if (!pAImeContext)
  184. return E_FAIL;
  185. Assert(_pFuncPrv);
  186. pAImeContext->SetupReconvertString();
  187. pAImeContext->EndReconvertString();
  188. return S_OK;
  189. }
  190. //+---------------------------------------------------------------------------
  191. //
  192. // CFnDocFeed::StartUndoCompositionString
  193. //
  194. //----------------------------------------------------------------------------
  195. STDAPI CFnDocFeed::StartUndoCompositionString()
  196. {
  197. IMTLS *ptls = IMTLS_GetOrAlloc();
  198. if (ptls == NULL)
  199. return E_FAIL;
  200. IMCLock imc(ptls->hIMC);
  201. if (imc.Invalid())
  202. return E_FAIL;
  203. CAImeContext* pAImeContext = imc->m_pAImeContext;
  204. if (!pAImeContext)
  205. return E_FAIL;
  206. Assert(_pFuncPrv);
  207. pAImeContext->SetupUndoCompositionString();
  208. pAImeContext->EndUndoCompositionString();
  209. return S_OK;
  210. }