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.

210 lines
4.6 KiB

  1. //
  2. // case.cpp
  3. //
  4. // IUnknown, ITfTextInputProcessor implementation.
  5. //
  6. #include "globals.h"
  7. #include "case.h"
  8. //+---------------------------------------------------------------------------
  9. //
  10. // CreateInstance
  11. //
  12. //----------------------------------------------------------------------------
  13. /* static */
  14. HRESULT CCaseTextService::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObj)
  15. {
  16. CCaseTextService *pCase;
  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 ((pCase = new CCaseTextService) == NULL)
  24. return E_OUTOFMEMORY;
  25. hr = pCase->QueryInterface(riid, ppvObj);
  26. pCase->Release(); // caller still holds ref if hr == S_OK
  27. return hr;
  28. }
  29. //+---------------------------------------------------------------------------
  30. //
  31. // ctor
  32. //
  33. //----------------------------------------------------------------------------
  34. CCaseTextService::CCaseTextService()
  35. {
  36. DllAddRef();
  37. _pThreadMgr = NULL;
  38. _tfClientId = TF_CLIENTID_NULL;
  39. _fShowSnoop = FALSE;
  40. _pSnoopWnd = NULL;
  41. _pLangBarItem = NULL;
  42. _fFlipKeys = FALSE;
  43. _dwThreadMgrEventSinkCookie = TF_INVALID_COOKIE;
  44. _dwThreadFocusSinkCookie = TF_INVALID_COOKIE;
  45. _dwTextEditSinkCookie = TF_INVALID_COOKIE;
  46. _pTextEditSinkContext = NULL;
  47. _cRef = 1;
  48. }
  49. //+---------------------------------------------------------------------------
  50. //
  51. // dtor
  52. //
  53. //----------------------------------------------------------------------------
  54. CCaseTextService::~CCaseTextService()
  55. {
  56. DllRelease();
  57. }
  58. //+---------------------------------------------------------------------------
  59. //
  60. // QueryInterface
  61. //
  62. //----------------------------------------------------------------------------
  63. STDAPI CCaseTextService::QueryInterface(REFIID riid, void **ppvObj)
  64. {
  65. if (ppvObj == NULL)
  66. return E_INVALIDARG;
  67. *ppvObj = NULL;
  68. if (IsEqualIID(riid, IID_IUnknown) ||
  69. IsEqualIID(riid, IID_ITfTextInputProcessor))
  70. {
  71. *ppvObj = (ITfTextInputProcessor *)this;
  72. }
  73. else if (IsEqualIID(riid, IID_ITfThreadMgrEventSink))
  74. {
  75. *ppvObj = (ITfThreadMgrEventSink *)this;
  76. }
  77. else if (IsEqualIID(riid, IID_ITfThreadFocusSink))
  78. {
  79. *ppvObj = (ITfThreadFocusSink *)this;
  80. }
  81. else if (IsEqualIID(riid, IID_ITfTextEditSink))
  82. {
  83. *ppvObj = (ITfTextEditSink *)this;
  84. }
  85. else if (IsEqualIID(riid, IID_ITfKeyEventSink))
  86. {
  87. *ppvObj = (ITfKeyEventSink *)this;
  88. }
  89. if (*ppvObj)
  90. {
  91. AddRef();
  92. return S_OK;
  93. }
  94. return E_NOINTERFACE;
  95. }
  96. //+---------------------------------------------------------------------------
  97. //
  98. // AddRef
  99. //
  100. //----------------------------------------------------------------------------
  101. STDAPI_(ULONG) CCaseTextService::AddRef()
  102. {
  103. return ++_cRef;
  104. }
  105. //+---------------------------------------------------------------------------
  106. //
  107. // Release
  108. //
  109. //----------------------------------------------------------------------------
  110. STDAPI_(ULONG) CCaseTextService::Release()
  111. {
  112. LONG cr = --_cRef;
  113. assert(_cRef >= 0);
  114. if (_cRef == 0)
  115. {
  116. delete this;
  117. }
  118. return cr;
  119. }
  120. //+---------------------------------------------------------------------------
  121. //
  122. // Activate
  123. //
  124. //----------------------------------------------------------------------------
  125. STDAPI CCaseTextService::Activate(ITfThreadMgr *pThreadMgr, TfClientId tfClientId)
  126. {
  127. _pThreadMgr = pThreadMgr;
  128. _pThreadMgr->AddRef();
  129. _tfClientId = tfClientId;
  130. if (!_InitLanguageBar())
  131. goto ExitError;
  132. if (!_InitThreadMgrSink())
  133. goto ExitError;
  134. if (!_InitSnoopWnd())
  135. goto ExitError;
  136. if (!_InitKeystrokeSink())
  137. goto ExitError;
  138. if (!_InitPreservedKey())
  139. goto ExitError;
  140. return S_OK;
  141. ExitError:
  142. Deactivate(); // cleanup any half-finished init
  143. return E_FAIL;
  144. }
  145. //+---------------------------------------------------------------------------
  146. //
  147. // Deactivate
  148. //
  149. //----------------------------------------------------------------------------
  150. STDAPI CCaseTextService::Deactivate()
  151. {
  152. _UninitSnoopWnd();
  153. _UninitThreadMgrSink();
  154. _UninitLanguageBar();
  155. _UninitKeystrokeSink();
  156. _UninitPreservedKey();
  157. // we MUST release all refs to _pThreadMgr in Deactivate
  158. SafeReleaseClear(_pThreadMgr);
  159. _tfClientId = TF_CLIENTID_NULL;
  160. return S_OK;
  161. }