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.

239 lines
5.5 KiB

  1. //
  2. // cleanup.cpp
  3. //
  4. #include "private.h"
  5. #include "cleanup.h"
  6. class CCleanupContextsEditSession : public ITfEditSession
  7. {
  8. public:
  9. CCleanupContextsEditSession(ITfContext *pic, ICleanupContextsClient *pClient);
  10. ~CCleanupContextsEditSession();
  11. //
  12. // IUnknown methods
  13. //
  14. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  15. STDMETHODIMP_(ULONG) AddRef(void);
  16. STDMETHODIMP_(ULONG) Release(void);
  17. //
  18. // ITfEditCallback
  19. //
  20. STDMETHODIMP DoEditSession(TfEditCookie ec);
  21. private:
  22. ITfContext *_pic;
  23. ICleanupContextsClient *_pClient;
  24. LONG _cRef;
  25. };
  26. //+---------------------------------------------------------------------------
  27. //
  28. // CleanupAllCompositions
  29. //
  30. //----------------------------------------------------------------------------
  31. BOOL CleanupAllCompositions(TfEditCookie ecWrite, ITfContext *pic,
  32. REFCLSID clsidOwner,
  33. CLEANUP_COMPOSITIONS_CALLBACK pfnCleanupCompositons,
  34. void *pvPrivate)
  35. {
  36. IEnumITfCompositionView *pEnum;
  37. ITfCompositionView *pCompositionView;
  38. ITfContextComposition *picc;
  39. ITfComposition *pComposition;
  40. ITfRange *range;
  41. CLSID clsid;
  42. HRESULT hr;
  43. BOOL fRet;
  44. // find all the compositions with our _tid, in _pic
  45. if (pic->QueryInterface(IID_ITfContextComposition, (void **)&picc) != S_OK)
  46. return FALSE;
  47. fRet = FALSE;
  48. if (picc->EnumCompositions(&pEnum) != S_OK)
  49. goto Exit;
  50. while (pEnum->Next(1, &pCompositionView, NULL) == S_OK)
  51. {
  52. pCompositionView->GetOwnerClsid(&clsid);
  53. // make sure we ignore other TIPs' compositions!
  54. if (!IsEqualCLSID(clsid, clsidOwner))
  55. goto NextComposition;
  56. if (pCompositionView->QueryInterface(IID_ITfComposition, (void **)&pComposition) != S_OK)
  57. goto NextComposition;
  58. hr = pComposition->GetRange(&range);
  59. // notify cicero, app
  60. pComposition->EndComposition(ecWrite);
  61. if (hr == S_OK)
  62. {
  63. // notify tip
  64. pfnCleanupCompositons(ecWrite, range, pvPrivate);
  65. range->Release();
  66. }
  67. pComposition->Release();
  68. NextComposition:
  69. pCompositionView->Release();
  70. }
  71. pEnum->Release();
  72. fRet = TRUE;
  73. Exit:
  74. picc->Release();
  75. return fRet;
  76. }
  77. //+---------------------------------------------------------------------------
  78. //
  79. // CleanupAllContexts
  80. //
  81. //----------------------------------------------------------------------------
  82. BOOL CleanupAllContexts(ITfThreadMgr *tim, TfClientId tid, ICleanupContextsClient *pClient)
  83. {
  84. IEnumTfDocumentMgrs *pEnumDm;
  85. ITfDocumentMgr *pDm;
  86. IEnumTfContexts *pEnumCtxt;
  87. ITfContext *pic;
  88. CCleanupContextsEditSession *pes;
  89. BOOL fInterested;
  90. HRESULT hr;
  91. if (tim->EnumDocumentMgrs(&pEnumDm) != S_OK)
  92. return FALSE;
  93. while (pEnumDm->Next(1, &pDm, NULL) == S_OK)
  94. {
  95. if (pDm->EnumContexts(&pEnumCtxt) != S_OK)
  96. goto NextDm;
  97. while (pEnumCtxt->Next(1, &pic, NULL) == S_OK)
  98. {
  99. if (pClient->IsInterestedInContext(pic, &fInterested) != S_OK || !fInterested)
  100. goto NextIC;
  101. if ((pes = new CCleanupContextsEditSession(pic, pClient)) == NULL)
  102. goto NextIC;
  103. pic->RequestEditSession(tid, pes, TF_ES_READWRITE, &hr);
  104. Assert(SUCCEEDED(hr));
  105. pes->Release();
  106. NextIC:
  107. pic->Release();
  108. }
  109. pEnumCtxt->Release();
  110. NextDm:
  111. pDm->Release();
  112. }
  113. pEnumDm->Release();
  114. return TRUE;
  115. }
  116. //+---------------------------------------------------------------------------
  117. //
  118. // ctor
  119. //
  120. //----------------------------------------------------------------------------
  121. CCleanupContextsEditSession::CCleanupContextsEditSession(ITfContext *pic, ICleanupContextsClient *pClient)
  122. {
  123. _pic = pic;
  124. _pic->AddRef();
  125. _pClient = pClient;
  126. _pClient->AddRef();
  127. _cRef = 1;
  128. }
  129. //+---------------------------------------------------------------------------
  130. //
  131. // dtor
  132. //
  133. //----------------------------------------------------------------------------
  134. CCleanupContextsEditSession::~CCleanupContextsEditSession()
  135. {
  136. _pic->Release();
  137. _pClient->Release();
  138. }
  139. //+---------------------------------------------------------------------------
  140. //
  141. // IUnknown
  142. //
  143. //----------------------------------------------------------------------------
  144. STDAPI CCleanupContextsEditSession::QueryInterface(REFIID riid, void **ppvObj)
  145. {
  146. *ppvObj = NULL;
  147. if (IsEqualIID(riid, IID_IUnknown) ||
  148. IsEqualIID(riid, IID_ITfEditSession))
  149. {
  150. *ppvObj = SAFECAST(this, CCleanupContextsEditSession *);
  151. }
  152. if (*ppvObj)
  153. {
  154. AddRef();
  155. return S_OK;
  156. }
  157. return E_NOINTERFACE;
  158. }
  159. STDAPI_(ULONG) CCleanupContextsEditSession::AddRef()
  160. {
  161. return ++_cRef;
  162. }
  163. STDAPI_(ULONG) CCleanupContextsEditSession::Release()
  164. {
  165. long cr;
  166. cr = --_cRef;
  167. Assert(cr >= 0);
  168. if (cr == 0)
  169. {
  170. delete this;
  171. }
  172. return cr;
  173. }
  174. //+---------------------------------------------------------------------------
  175. //
  176. // DoEditSession
  177. //
  178. //----------------------------------------------------------------------------
  179. STDAPI CCleanupContextsEditSession::DoEditSession(TfEditCookie ec)
  180. {
  181. _pClient->CleanupContext(ec, _pic);
  182. return S_OK;
  183. }