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.

235 lines
5.3 KiB

  1. //
  2. // mark.cpp
  3. //
  4. // IUnknown, ITfTextInputProcessor implementation.
  5. //
  6. #include "globals.h"
  7. #include "mark.h"
  8. //+---------------------------------------------------------------------------
  9. //
  10. // CreateInstance
  11. //
  12. //----------------------------------------------------------------------------
  13. /* static */
  14. HRESULT CMarkTextService::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObj)
  15. {
  16. CMarkTextService *pMark;
  17. HRESULT hr;
  18. if (ppvObj == NULL)
  19. return E_INVALIDARG;
  20. *ppvObj = NULL;
  21. if (NULL != pUnkOuter)
  22. return CLASS_E_NOAGGREGATION;
  23. if ((pMark = new CMarkTextService) == NULL)
  24. return E_OUTOFMEMORY;
  25. hr = pMark->QueryInterface(riid, ppvObj);
  26. pMark->Release(); // caller still holds ref if hr == S_OK
  27. return hr;
  28. }
  29. //+---------------------------------------------------------------------------
  30. //
  31. // ctor
  32. //
  33. //----------------------------------------------------------------------------
  34. CMarkTextService::CMarkTextService()
  35. {
  36. DllAddRef();
  37. _pThreadMgr = NULL;
  38. _tfClientId = TF_CLIENTID_NULL;
  39. _pComposition = NULL;
  40. _fCleaningUp = FALSE;
  41. _gaDisplayAttribute = TF_INVALID_GUIDATOM;
  42. _pLangBarItem = NULL;
  43. _dwThreadMgrEventSinkCookie = TF_INVALID_COOKIE;
  44. _dwThreadFocusSinkCookie = TF_INVALID_COOKIE;
  45. _dwTextEditSinkCookie = TF_INVALID_COOKIE;
  46. _dwGlobalCompartmentEventSinkCookie = TF_INVALID_COOKIE;
  47. _pTextEditSinkContext = NULL;
  48. _hWorkerWnd = NULL;
  49. _cRef = 1;
  50. }
  51. //+---------------------------------------------------------------------------
  52. //
  53. // dtor
  54. //
  55. //----------------------------------------------------------------------------
  56. CMarkTextService::~CMarkTextService()
  57. {
  58. DllRelease();
  59. }
  60. //+---------------------------------------------------------------------------
  61. //
  62. // QueryInterface
  63. //
  64. //----------------------------------------------------------------------------
  65. STDAPI CMarkTextService::QueryInterface(REFIID riid, void **ppvObj)
  66. {
  67. if (ppvObj == NULL)
  68. return E_INVALIDARG;
  69. *ppvObj = NULL;
  70. if (IsEqualIID(riid, IID_IUnknown) ||
  71. IsEqualIID(riid, IID_ITfTextInputProcessor))
  72. {
  73. *ppvObj = (ITfTextInputProcessor *)this;
  74. }
  75. else if (IsEqualIID(riid, IID_ITfDisplayAttributeProvider))
  76. {
  77. *ppvObj = (ITfDisplayAttributeProvider *)this;
  78. }
  79. else if (IsEqualIID(riid, IID_ITfCreatePropertyStore))
  80. {
  81. *ppvObj = (ITfCreatePropertyStore *)this;
  82. }
  83. else if (IsEqualIID(riid, IID_ITfThreadMgrEventSink))
  84. {
  85. *ppvObj = (ITfThreadMgrEventSink *)this;
  86. }
  87. else if (IsEqualIID(riid, IID_ITfTextEditSink))
  88. {
  89. *ppvObj = (ITfTextEditSink *)this;
  90. }
  91. else if (IsEqualIID(riid, IID_ITfCleanupContextSink))
  92. {
  93. *ppvObj = (ITfCleanupContextSink *)this;
  94. }
  95. else if (IsEqualIID(riid, IID_ITfCleanupContextDurationSink))
  96. {
  97. *ppvObj = (ITfCleanupContextDurationSink *)this;
  98. }
  99. else if (IsEqualIID(riid, IID_ITfCompartmentEventSink))
  100. {
  101. *ppvObj = (ITfCompartmentEventSink *)this;
  102. }
  103. if (*ppvObj)
  104. {
  105. AddRef();
  106. return S_OK;
  107. }
  108. return E_NOINTERFACE;
  109. }
  110. //+---------------------------------------------------------------------------
  111. //
  112. // AddRef
  113. //
  114. //----------------------------------------------------------------------------
  115. STDAPI_(ULONG) CMarkTextService::AddRef()
  116. {
  117. return ++_cRef;
  118. }
  119. //+---------------------------------------------------------------------------
  120. //
  121. // Release
  122. //
  123. //----------------------------------------------------------------------------
  124. STDAPI_(ULONG) CMarkTextService::Release()
  125. {
  126. LONG cr = --_cRef;
  127. assert(_cRef >= 0);
  128. if (_cRef == 0)
  129. {
  130. delete this;
  131. }
  132. return cr;
  133. }
  134. //+---------------------------------------------------------------------------
  135. //
  136. // Activate
  137. //
  138. //----------------------------------------------------------------------------
  139. STDAPI CMarkTextService::Activate(ITfThreadMgr *pThreadMgr, TfClientId tfClientId)
  140. {
  141. _pThreadMgr = pThreadMgr;
  142. _pThreadMgr->AddRef();
  143. _tfClientId = tfClientId;
  144. if (!_InitLanguageBar())
  145. goto ExitError;
  146. if (!_InitThreadMgrSink())
  147. goto ExitError;
  148. if (!_InitDisplayAttributeGuidAtom())
  149. goto ExitError;
  150. if (!_InitCleanupContextDurationSink())
  151. goto ExitError;
  152. if (!_InitGlobalCompartment())
  153. goto ExitError;
  154. if (!_InitWorkerWnd())
  155. goto ExitError;
  156. if (!_InitKeystrokeSink())
  157. goto ExitError;
  158. return S_OK;
  159. ExitError:
  160. Deactivate(); // cleanup any half-finished init
  161. return E_FAIL;
  162. }
  163. //+---------------------------------------------------------------------------
  164. //
  165. // Deactivate
  166. //
  167. //----------------------------------------------------------------------------
  168. STDAPI CMarkTextService::Deactivate()
  169. {
  170. _UninitThreadMgrSink();
  171. _UninitLanguageBar();
  172. _UninitCleanupContextDurationSink();
  173. _UninitGlobalCompartment();
  174. _UninitWorkerWnd();
  175. _UninitKeystrokeSink();
  176. _InitTextEditSink(NULL);
  177. // we MUST release all refs to _pThreadMgr in Deactivate
  178. SafeReleaseClear(_pThreadMgr);
  179. _tfClientId = TF_CLIENTID_NULL;
  180. return S_OK;
  181. }