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.

220 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 2001, Microsoft Corporation
  3. Module Name:
  4. reconvcb.cpp
  5. Abstract:
  6. This file implements the CStartReconversionNotifySink Class.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #include "private.h"
  12. #include "reconvcb.h"
  13. #include "imc.h"
  14. #include "context.h"
  15. #include "tls.h"
  16. #include "profile.h"
  17. //////////////////////////////////////////////////////////////////////////////
  18. //
  19. // CStartReconversionNotifySink
  20. //
  21. //////////////////////////////////////////////////////////////////////////////
  22. //+---------------------------------------------------------------------------
  23. //
  24. // IUnknown
  25. //
  26. //----------------------------------------------------------------------------
  27. STDAPI CStartReconversionNotifySink::QueryInterface(REFIID riid, void **ppvObj)
  28. {
  29. *ppvObj = NULL;
  30. if (IsEqualIID(riid, IID_IUnknown) ||
  31. IsEqualIID(riid, IID_ITfStartReconversionNotifySink))
  32. {
  33. *ppvObj = SAFECAST(this, CStartReconversionNotifySink *);
  34. }
  35. if (*ppvObj)
  36. {
  37. AddRef();
  38. return S_OK;
  39. }
  40. return E_NOINTERFACE;
  41. }
  42. STDAPI_(ULONG) CStartReconversionNotifySink::AddRef()
  43. {
  44. return ++m_cRef;
  45. }
  46. STDAPI_(ULONG) CStartReconversionNotifySink::Release()
  47. {
  48. long cr;
  49. cr = --m_cRef;
  50. Assert(cr >= 0);
  51. if (cr == 0)
  52. {
  53. delete this;
  54. }
  55. return cr;
  56. }
  57. //+---------------------------------------------------------------------------
  58. //
  59. // CStartReconversionNotifySink::Advise
  60. //
  61. //----------------------------------------------------------------------------
  62. HRESULT CStartReconversionNotifySink::_Advise(ITfContext *pic)
  63. {
  64. HRESULT hr;
  65. ITfSource *source = NULL;
  66. _pic = NULL;
  67. hr = E_FAIL;
  68. if (FAILED(pic->QueryInterface(IID_ITfSource, (void **)&source)))
  69. goto Exit;
  70. if (FAILED(source->AdviseSink(IID_ITfStartReconversionNotifySink, this, &_dwCookie)))
  71. goto Exit;
  72. _pic = pic;
  73. _pic->AddRef();
  74. hr = S_OK;
  75. Exit:
  76. SafeRelease(source);
  77. return hr;
  78. }
  79. //+---------------------------------------------------------------------------
  80. //
  81. // CStartReconversionNotifySink::Unadvise
  82. //
  83. //----------------------------------------------------------------------------
  84. HRESULT CStartReconversionNotifySink::_Unadvise()
  85. {
  86. HRESULT hr;
  87. ITfSource *source = NULL;
  88. hr = E_FAIL;
  89. if (_pic == NULL)
  90. goto Exit;
  91. if (FAILED(_pic->QueryInterface(IID_ITfSource, (void **)&source)))
  92. goto Exit;
  93. if (FAILED(source->UnadviseSink(_dwCookie)))
  94. goto Exit;
  95. hr = S_OK;
  96. Exit:
  97. SafeRelease(source);
  98. SafeReleaseClear(_pic);
  99. return hr;
  100. }
  101. //+---------------------------------------------------------------------------
  102. //
  103. // StartReconversionNotifySink::StartReconversion
  104. //
  105. //----------------------------------------------------------------------------
  106. STDAPI CStartReconversionNotifySink::StartReconversion()
  107. {
  108. DebugMsg(TF_FUNC, TEXT("CStartReconversionNotifySink::StartReconversion"));
  109. TLS* ptls = TLS::GetTLS();
  110. if (ptls == NULL)
  111. {
  112. DebugMsg(TF_ERROR, TEXT("CStartReconversionNotifySink::StartReconversion. ptls==NULL."));
  113. return E_OUTOFMEMORY;
  114. }
  115. ITfThreadMgr_P* ptim_P = ptls->GetTIM();
  116. if (ptim_P == NULL)
  117. {
  118. DebugMsg(TF_ERROR, TEXT("CStartReconversionNotifySink::StartReconversion. ptim_P==NULL."));
  119. return E_OUTOFMEMORY;
  120. }
  121. HRESULT hr;
  122. IMCLock imc(m_hIMC);
  123. if (FAILED(hr = imc.GetResult()))
  124. {
  125. DebugMsg(TF_ERROR, TEXT("CStartReconversionNotifySink::StartReconversion. imc==NULL."));
  126. return hr;
  127. }
  128. IMCCLock<CTFIMECONTEXT> imc_ctfime(imc->hCtfImeContext);
  129. if (FAILED(hr = imc_ctfime.GetResult()))
  130. {
  131. DebugMsg(TF_ERROR, TEXT("CStartReconversionNotifySink::StartReconversion. imc_ctfime==NULL."));
  132. return hr;
  133. }
  134. CicInputContext* _pCicContext = imc_ctfime->m_pCicContext;
  135. if (_pCicContext == NULL)
  136. {
  137. DebugMsg(TF_ERROR, TEXT("CStartReconversionNotifySink::StartReconversion. _pCicCotext==NULL."));
  138. return E_FAIL;
  139. }
  140. UINT cp = CP_ACP;
  141. CicProfile* _pProfile = ptls->GetCicProfile();
  142. if (_pProfile == NULL)
  143. {
  144. DebugMsg(TF_ERROR, TEXT("CStartReconversionNotifySink::StartReconversion. _pProfile==NULL."));
  145. return E_FAIL;
  146. }
  147. _pProfile->GetCodePageA(&cp);
  148. return _pCicContext->SetupReconvertString(imc, ptim_P, cp, 0, FALSE);
  149. }
  150. //+---------------------------------------------------------------------------
  151. //
  152. // StartReconversionNotifySink::EndReconversion
  153. //
  154. //----------------------------------------------------------------------------
  155. STDAPI CStartReconversionNotifySink::EndReconversion()
  156. {
  157. HRESULT hr;
  158. IMCLock imc(m_hIMC);
  159. if (FAILED(hr = imc.GetResult()))
  160. return hr;
  161. IMCCLock<CTFIMECONTEXT> imc_ctfime(imc->hCtfImeContext);
  162. if (FAILED(hr = imc_ctfime.GetResult()))
  163. return hr;
  164. CicInputContext* _pCicContext = imc_ctfime->m_pCicContext;
  165. if (_pCicContext == NULL)
  166. return E_FAIL;
  167. return _pCicContext->EndReconvertString(imc);
  168. }