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.

146 lines
3.3 KiB

  1. //
  2. // ats.cpp
  3. //
  4. #include "private.h"
  5. #include "ats.h"
  6. #include "helpers.h"
  7. //////////////////////////////////////////////////////////////////////////////
  8. //
  9. // CActiveLanguageProfileNotifySink
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. //+---------------------------------------------------------------------------
  13. //
  14. // IUnknown
  15. //
  16. //----------------------------------------------------------------------------
  17. STDAPI CActiveLanguageProfileNotifySink::QueryInterface(REFIID riid, void **ppvObj)
  18. {
  19. *ppvObj = NULL;
  20. if (IsEqualIID(riid, IID_IUnknown) ||
  21. IsEqualIID(riid, IID_ITfActiveLanguageProfileNotifySink))
  22. {
  23. *ppvObj = SAFECAST(this, CActiveLanguageProfileNotifySink *);
  24. }
  25. if (*ppvObj)
  26. {
  27. AddRef();
  28. return S_OK;
  29. }
  30. return E_NOINTERFACE;
  31. }
  32. STDAPI_(ULONG) CActiveLanguageProfileNotifySink::AddRef()
  33. {
  34. return ++_cRef;
  35. }
  36. STDAPI_(ULONG) CActiveLanguageProfileNotifySink::Release()
  37. {
  38. long cr;
  39. cr = --_cRef;
  40. Assert(cr >= 0);
  41. if (cr == 0)
  42. {
  43. delete this;
  44. }
  45. return cr;
  46. }
  47. //+---------------------------------------------------------------------------
  48. //
  49. // ctor
  50. //
  51. //----------------------------------------------------------------------------
  52. CActiveLanguageProfileNotifySink::CActiveLanguageProfileNotifySink(ALSCALLBACK pfn, void *pv)
  53. {
  54. Dbg_MemSetThisName(TEXT("CActiveLanguageProfileNotifySink"));
  55. _cRef = 1;
  56. _dwCookie = ALS_INVALID_COOKIE;
  57. _pfn = pfn;
  58. _pv = pv;
  59. }
  60. //+---------------------------------------------------------------------------
  61. //
  62. // OnUpdated
  63. //
  64. //----------------------------------------------------------------------------
  65. STDAPI CActiveLanguageProfileNotifySink::OnActivated(REFCLSID clsid, REFGUID guidProfile, BOOL bActivated)
  66. {
  67. return _pfn ? _pfn(clsid, guidProfile, bActivated, _pv) : S_OK;
  68. }
  69. //+---------------------------------------------------------------------------
  70. //
  71. // CActiveLanguageProfileNotifySink::Advise
  72. //
  73. //----------------------------------------------------------------------------
  74. HRESULT CActiveLanguageProfileNotifySink::_Advise(ITfThreadMgr *ptim)
  75. {
  76. HRESULT hr;
  77. ITfSource *source = NULL;
  78. _ptim = NULL;
  79. hr = E_FAIL;
  80. if (FAILED(ptim->QueryInterface(IID_ITfSource, (void **)&source)))
  81. goto Exit;
  82. if (FAILED(source->AdviseSink(IID_ITfActiveLanguageProfileNotifySink, this, &_dwCookie)))
  83. goto Exit;
  84. _ptim = ptim;
  85. _ptim->AddRef();
  86. hr = S_OK;
  87. Exit:
  88. SafeRelease(source);
  89. return hr;
  90. }
  91. //+---------------------------------------------------------------------------
  92. //
  93. // CActiveLanguageProfileNotifySink::Unadvise
  94. //
  95. //----------------------------------------------------------------------------
  96. HRESULT CActiveLanguageProfileNotifySink::_Unadvise()
  97. {
  98. HRESULT hr;
  99. ITfSource *source = NULL;
  100. hr = E_FAIL;
  101. if (_ptim == NULL)
  102. goto Exit;
  103. if (FAILED(_ptim->QueryInterface(IID_ITfSource, (void **)&source)))
  104. goto Exit;
  105. if (FAILED(source->UnadviseSink(_dwCookie)))
  106. goto Exit;
  107. hr = S_OK;
  108. Exit:
  109. SafeRelease(source);
  110. SafeReleaseClear(_ptim);
  111. return hr;
  112. }