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.

203 lines
4.4 KiB

  1. //
  2. // tes.cpp
  3. //
  4. #include "private.h"
  5. #include "korimx.h"
  6. #include "textsink.h"
  7. #include "editcb.h"
  8. #include "helpers.h"
  9. //////////////////////////////////////////////////////////////////////////////
  10. //
  11. // CTextEventSink
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. //+---------------------------------------------------------------------------
  15. //
  16. // IUnknown
  17. //
  18. //----------------------------------------------------------------------------
  19. STDAPI CTextEditSink::QueryInterface(REFIID riid, void **ppvObj)
  20. {
  21. *ppvObj = NULL;
  22. if (IsEqualIID(riid, IID_IUnknown) ||
  23. IsEqualIID(riid, IID_ITfTextEditSink))
  24. {
  25. *ppvObj = SAFECAST(this, ITfTextEditSink *);
  26. }
  27. if (*ppvObj)
  28. {
  29. AddRef();
  30. return S_OK;
  31. }
  32. return E_NOINTERFACE;
  33. }
  34. STDAPI_(ULONG) CTextEditSink::AddRef()
  35. {
  36. return ++m_cRef;
  37. }
  38. STDAPI_(ULONG) CTextEditSink::Release()
  39. {
  40. long cr;
  41. cr = --m_cRef;
  42. Assert(cr >= 0);
  43. if (cr == 0)
  44. {
  45. delete this;
  46. }
  47. return cr;
  48. }
  49. //+---------------------------------------------------------------------------
  50. //
  51. // ctor
  52. //
  53. //----------------------------------------------------------------------------
  54. CTextEditSink::CTextEditSink(void *pv)
  55. {
  56. Dbg_MemSetThisName(TEXT("CTextEditSink"));
  57. m_cRef = 1;
  58. m_dwEditCookie = TES_INVALID_COOKIE;
  59. m_pv = pv;
  60. Assert(m_pv != NULL);
  61. //m_dwLayoutCookie = TES_INVALID_COOKIE;
  62. }
  63. //+---------------------------------------------------------------------------
  64. //
  65. // EndEdit
  66. //
  67. //----------------------------------------------------------------------------
  68. STDAPI CTextEditSink::OnEndEdit(TfEditCookie ecReadOnly, ITfEditRecord *pEditRecord)
  69. {
  70. CKorIMX *pKorImx;
  71. CHangulAutomata *pAutomata;
  72. CEditSession *pes;
  73. BOOL fChanged = fFalse;
  74. HRESULT hr = S_OK;
  75. pKorImx = (CKorIMX *)m_pv;
  76. Assert(pKorImx);
  77. #if 0
  78. pEditRecord->GetSelectionStatus(&fChanged);
  79. if (fChanged)
  80. {
  81. BOOL fInWriteSession;
  82. if (SUCCEEDED(m_pic->InWriteSession(pKorImx->GetTID(), &fInWriteSession)))
  83. {
  84. if (!fInWriteSession)
  85. if (pes = new CEditSession(CKorIMX::_EditSessionCallback))
  86. {
  87. // Complete the current composition here.
  88. // But you have to use async edit session here.
  89. // because this TextEditSink notification is inside of
  90. // another edit session. You can not have recursive
  91. // edit session.
  92. pes->_state.u = ESCB_COMP_COMPLETE;
  93. pes->_state.pv = pKorImx;
  94. pes->_state.pRange = NULL;
  95. pes->_state.pic = m_pic;
  96. m_pic->EditSession(pKorImx->GetTID(), pes, TF_ES_READWRITE, &hr);
  97. pes->Release();
  98. }
  99. }
  100. }
  101. #else
  102. pEditRecord->GetSelectionStatus(&fChanged);
  103. if (fChanged)
  104. {
  105. BOOL fInWriteSession;
  106. if (SUCCEEDED(m_pic->InWriteSession(pKorImx->GetTID(), &fInWriteSession)))
  107. {
  108. if (!fInWriteSession)
  109. {
  110. pAutomata = pKorImx->GetAutomata(m_pic);
  111. Assert(pAutomata);
  112. //pAutomata->MakeComplete();
  113. }
  114. }
  115. }
  116. #endif
  117. return hr;
  118. }
  119. //+---------------------------------------------------------------------------
  120. //
  121. // CTextEditSink::Advise
  122. //
  123. //----------------------------------------------------------------------------
  124. HRESULT CTextEditSink::_Advise(ITfContext *pic)
  125. {
  126. HRESULT hr = E_FAIL;
  127. ITfSource *source = NULL;
  128. m_pic = NULL;
  129. if (FAILED(pic->QueryInterface(IID_ITfSource, (void **)&source)))
  130. goto Exit;
  131. if (FAILED(source->AdviseSink(IID_ITfTextEditSink, (ITfTextEditSink *)this, &m_dwEditCookie)))
  132. goto Exit;
  133. m_pic = pic;
  134. m_pic->AddRef();
  135. hr = S_OK;
  136. Exit:
  137. SafeRelease(source);
  138. return hr;
  139. }
  140. //+---------------------------------------------------------------------------
  141. //
  142. // CTextEditSink::Unadvise
  143. //
  144. //----------------------------------------------------------------------------
  145. HRESULT CTextEditSink::_Unadvise()
  146. {
  147. HRESULT hr = E_FAIL;
  148. ITfSource *source = NULL;
  149. if (m_pic == NULL)
  150. goto Exit;
  151. if (FAILED(m_pic->QueryInterface(IID_ITfSource, (void **)&source)))
  152. goto Exit;
  153. if (SUCCEEDED(source->UnadviseSink(m_dwEditCookie)))
  154. goto Exit;
  155. hr = S_OK;
  156. Exit:
  157. SafeRelease(source);
  158. SafeReleaseClear(m_pic);
  159. return hr;
  160. }