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.

198 lines
4.7 KiB

  1. //
  2. // editssn.cpp
  3. //
  4. // CEditSession2
  5. //
  6. #include "private.h"
  7. #include "korimx.h"
  8. #include "editssn.h"
  9. #include "helpers.h"
  10. #define SafeAddRef(x) { if ((x)) { (x)->AddRef(); } }
  11. /* C E D I T S E S S I O N 2 */
  12. /*------------------------------------------------------------------------------
  13. Constructor
  14. ------------------------------------------------------------------------------*/
  15. CEditSession2::CEditSession2(ITfContext *pic, CKorIMX *ptip, ESSTRUCT *pess, PFNESCALLBACK pfnCallback)
  16. {
  17. Assert(pic != NULL);
  18. Assert(ptip != NULL);
  19. Assert(pess != NULL);
  20. m_cRef = 1;
  21. m_pic = pic;
  22. m_ptip = ptip;
  23. m_ess = *pess;
  24. m_pfnCallback = pfnCallback;
  25. // add reference count in the struct
  26. SafeAddRef(m_pic);
  27. SafeAddRef(m_ptip);
  28. SafeAddRef(m_ess.ptim);
  29. SafeAddRef(m_ess.pRange);
  30. SafeAddRef(m_ess.pEnumRange);
  31. SafeAddRef(m_ess.pCandList);
  32. SafeAddRef(m_ess.pCandStr);
  33. }
  34. /* ~ C E D I T S E S S I O N 2 */
  35. /*------------------------------------------------------------------------------
  36. Destructor
  37. ------------------------------------------------------------------------------*/
  38. CEditSession2::~CEditSession2( void )
  39. {
  40. SafeRelease(m_pic);
  41. SafeRelease(m_ptip);
  42. SafeRelease(m_ess.ptim);
  43. SafeRelease(m_ess.pRange);
  44. SafeRelease(m_ess.pEnumRange);
  45. SafeRelease(m_ess.pCandList);
  46. SafeRelease(m_ess.pCandStr);
  47. }
  48. /* Q U E R Y I N T E R F A C E */
  49. /*------------------------------------------------------------------------------
  50. Query interface of object
  51. (IUnknown method)
  52. ------------------------------------------------------------------------------*/
  53. STDAPI CEditSession2::QueryInterface(REFIID riid, void **ppvObj)
  54. {
  55. *ppvObj = NULL;
  56. if (IsEqualIID( riid, IID_IUnknown ) || IsEqualIID(riid, IID_ITfEditSession))
  57. *ppvObj = SAFECAST(this, ITfEditSession*);
  58. if (*ppvObj)
  59. {
  60. AddRef();
  61. return S_OK;
  62. }
  63. return E_NOINTERFACE;
  64. }
  65. /* A D D R E F */
  66. /*------------------------------------------------------------------------------
  67. Add reference count
  68. (IUnknown method)
  69. ------------------------------------------------------------------------------*/
  70. STDAPI_(ULONG) CEditSession2::AddRef()
  71. {
  72. return ++m_cRef;
  73. }
  74. /* R E L E A S E */
  75. /*------------------------------------------------------------------------------
  76. Release object
  77. (IUnknown method)
  78. ------------------------------------------------------------------------------*/
  79. STDAPI_(ULONG) CEditSession2::Release()
  80. {
  81. long cr;
  82. cr = --m_cRef;
  83. Assert(cr >= 0);
  84. if (cr == 0)
  85. delete this;
  86. return cr;
  87. }
  88. /* E D I T S E S S I O N */
  89. /*------------------------------------------------------------------------------
  90. Callback function of edit session
  91. (ITfEditSession method)
  92. ------------------------------------------------------------------------------*/
  93. STDAPI CEditSession2::DoEditSession(TfEditCookie ec)
  94. {
  95. return m_pfnCallback(ec, this);
  96. }
  97. /* I N V O K E */
  98. /*------------------------------------------------------------------------------
  99. ------------------------------------------------------------------------------*/
  100. HRESULT CEditSession2::Invoke(DWORD dwFlag, HRESULT *phrSession)
  101. {
  102. HRESULT hr;
  103. DWORD dwFlagES = 0;
  104. if ((m_pic == NULL) || (m_ptip == NULL))
  105. return E_FAIL;
  106. // read/readwrite flag
  107. switch (dwFlag & ES2_READWRITEMASK)
  108. {
  109. default:
  110. case ES2_READONLY:
  111. dwFlagES |= TF_ES_READ;
  112. break;
  113. case ES2_READWRITE:
  114. dwFlagES |= TF_ES_READWRITE;
  115. break;
  116. }
  117. // sync/async flag
  118. switch (dwFlag & ES2_SYNCMASK)
  119. {
  120. default:
  121. Assert(fFalse);
  122. // fall through
  123. case ES2_ASYNC:
  124. dwFlagES |= TF_ES_ASYNC;
  125. break;
  126. case ES2_SYNC:
  127. dwFlagES |= TF_ES_SYNC;
  128. break;
  129. case ES2_SYNCASYNC:
  130. dwFlagES |= TF_ES_ASYNCDONTCARE;
  131. break;
  132. }
  133. // invoke
  134. m_fProcessed = FALSE;
  135. hr = m_pic->RequestEditSession(m_ptip->GetTID(), this, dwFlagES, phrSession);
  136. // try ASYNC session when SYNC session failed
  137. // NOTE: KOJIW:
  138. // How can we know if the edit session has been processed synchronously?
  139. // Satori#2409 - do not invoke callback twice
  140. // if (!m_fProcessed && ((dwFlag & ES2_SYNCMASK) == ES2_SYNCASYNC)) {
  141. // hr = m_pic->EditSession( m_ptip->GetTID(), this, (dwFlagES & ~TF_ES_SYNC), phrSession );
  142. // }
  143. return hr;
  144. }