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.

183 lines
4.0 KiB

  1. //
  2. // syslbar.cpp
  3. //
  4. #include "private.h"
  5. #include "syslbar.h"
  6. #include "helpers.h"
  7. //////////////////////////////////////////////////////////////////////////////
  8. //
  9. // CSystemLBarSink
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. //+---------------------------------------------------------------------------
  13. //
  14. // IUnknown
  15. //
  16. //----------------------------------------------------------------------------
  17. STDAPI CSystemLBarSink::QueryInterface(REFIID riid, void **ppvObj)
  18. {
  19. *ppvObj = NULL;
  20. if (IsEqualIID(riid, IID_IUnknown) ||
  21. IsEqualIID(riid, IID_ITfSystemLangBarItemSink))
  22. {
  23. *ppvObj = SAFECAST(this, ITfSystemLangBarItemSink *);
  24. }
  25. if (*ppvObj)
  26. {
  27. AddRef();
  28. return S_OK;
  29. }
  30. return E_NOINTERFACE;
  31. }
  32. STDAPI_(ULONG) CSystemLBarSink::AddRef()
  33. {
  34. return ++_cRef;
  35. }
  36. STDAPI_(ULONG) CSystemLBarSink::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. CSystemLBarSink::CSystemLBarSink(SYSLBARCALLBACK pfn, void *pv)
  53. {
  54. _pfn = pfn;
  55. _pv = pv;
  56. _cRef = 1;
  57. }
  58. //+---------------------------------------------------------------------------
  59. //
  60. // dtor
  61. //
  62. //----------------------------------------------------------------------------
  63. CSystemLBarSink::~CSystemLBarSink()
  64. {
  65. }
  66. //+---------------------------------------------------------------------------
  67. //
  68. // Advise
  69. //
  70. //----------------------------------------------------------------------------
  71. HRESULT CSystemLBarSink::_Advise(ITfThreadMgr *ptim, REFGUID rguid)
  72. {
  73. HRESULT hr;
  74. ITfSource *source = NULL;
  75. ITfLangBarItemMgr *plbimgr = NULL;
  76. ITfLangBarItem *plbi = NULL;
  77. _ptim = NULL;
  78. hr = E_FAIL;
  79. if (FAILED(ptim->QueryInterface(IID_ITfLangBarItemMgr, (void **)&plbimgr)))
  80. goto Exit;
  81. if (plbimgr->GetItem(rguid, &plbi) != S_OK)
  82. goto Exit;
  83. if (FAILED(plbi->QueryInterface(IID_ITfSource, (void **)&source)))
  84. goto Exit;
  85. if (FAILED(source->AdviseSink(IID_ITfSystemLangBarItemSink, this, &_dwCookie)))
  86. goto Exit;
  87. hr = S_OK;
  88. _ptim = ptim;
  89. _ptim->AddRef();
  90. _guid = rguid;
  91. Exit:
  92. SafeRelease(source);
  93. SafeRelease(plbimgr);
  94. SafeRelease(plbi);
  95. return hr;
  96. }
  97. //+---------------------------------------------------------------------------
  98. //
  99. // Unadvise
  100. //
  101. //----------------------------------------------------------------------------
  102. HRESULT CSystemLBarSink::_Unadvise()
  103. {
  104. HRESULT hr;
  105. ITfSource *source = NULL;
  106. ITfLangBarItemMgr *plbimgr = NULL;
  107. ITfLangBarItem *plbi = NULL;
  108. hr = E_FAIL;
  109. if (_ptim == NULL)
  110. goto Exit;
  111. if (FAILED(_ptim->QueryInterface(IID_ITfLangBarItemMgr, (void **)&plbimgr)))
  112. goto Exit;
  113. if (FAILED(plbimgr->GetItem(_guid, &plbi)))
  114. goto Exit;
  115. if (FAILED(plbi->QueryInterface(IID_ITfSource, (void **)&source)))
  116. goto Exit;
  117. if (FAILED(source->UnadviseSink(_dwCookie)))
  118. goto Exit;
  119. hr = S_OK;
  120. Exit:
  121. SafeRelease(source);
  122. SafeRelease(plbimgr);
  123. SafeRelease(plbi);
  124. SafeReleaseClear(_ptim);
  125. return hr;
  126. }
  127. //+---------------------------------------------------------------------------
  128. //
  129. // InitMenu
  130. //
  131. //----------------------------------------------------------------------------
  132. STDAPI CSystemLBarSink::InitMenu(ITfMenu *pMenu)
  133. {
  134. return _pfn(IDSLB_INITMENU, _pv, pMenu, -1);
  135. }
  136. //+---------------------------------------------------------------------------
  137. //
  138. // OnMenuSelect
  139. //
  140. //----------------------------------------------------------------------------
  141. STDAPI CSystemLBarSink::OnMenuSelect(UINT wID)
  142. {
  143. return _pfn(IDSLB_ONMENUSELECT, _pv, NULL, wID);
  144. }