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.

189 lines
4.1 KiB

  1. //
  2. // syshelp.cpp
  3. //
  4. #include "precomp.h"
  5. #include "syshelp.h"
  6. #define SAFECASTLOCAL(_obj, _type) (((_type)(_obj)==(_obj)?0:0), (_type)(_obj))
  7. #define SafeReleaseLocal(punk) \
  8. { \
  9. if ((punk) != NULL) \
  10. { \
  11. (punk)->Release(); \
  12. } \
  13. }
  14. #define SafeReleaseLocalClear(punk) \
  15. { \
  16. if ((punk) != NULL) \
  17. { \
  18. (punk)->Release(); \
  19. punk = NULL; \
  20. } \
  21. }
  22. STDAPI CSysHelpSink::QueryInterface(REFIID riid, void **ppvObj)
  23. {
  24. if (ppvObj == NULL)
  25. return E_POINTER;
  26. *ppvObj = NULL;
  27. if (IsEqualIID(riid, IID_IUnknown) ||
  28. IsEqualIID(riid, IID_ITfSystemLangBarItemSink))
  29. {
  30. *ppvObj = SAFECASTLOCAL(this, ITfSystemLangBarItemSink *);
  31. }
  32. if (*ppvObj)
  33. {
  34. AddRef();
  35. return S_OK;
  36. }
  37. return E_NOINTERFACE;
  38. }
  39. STDAPI_(ULONG) CSysHelpSink::AddRef()
  40. {
  41. return ++_cRef;
  42. }
  43. STDAPI_(ULONG) CSysHelpSink::Release()
  44. {
  45. long cr;
  46. cr = --_cRef;
  47. if (cr == 0)
  48. {
  49. delete this;
  50. }
  51. return cr;
  52. }
  53. //+---------------------------------------------------------------------------
  54. //
  55. // ctor
  56. //
  57. //----------------------------------------------------------------------------
  58. CSysHelpSink::CSysHelpSink(SYSHELPINITMENU pfnInitMenu, SYSHELPMENUSELECT pfnMenuSelect, void *pv)
  59. {
  60. _pfnInitMenu = pfnInitMenu;
  61. _pfnMenuSelect = pfnMenuSelect;
  62. _pv = pv;
  63. _cRef = 1;
  64. }
  65. //+---------------------------------------------------------------------------
  66. //
  67. // dtor
  68. //
  69. //----------------------------------------------------------------------------
  70. CSysHelpSink::~CSysHelpSink()
  71. {
  72. }
  73. //+---------------------------------------------------------------------------
  74. //
  75. // Advise
  76. //
  77. //----------------------------------------------------------------------------
  78. HRESULT CSysHelpSink::_Advise(ITfLangBarItemMgr *plbimgr, REFGUID rguid)
  79. {
  80. HRESULT hr;
  81. ITfSource *source = NULL;
  82. ITfLangBarItem *plbi = NULL;
  83. hr = E_FAIL;
  84. if (plbimgr == NULL) {
  85. goto Exit;
  86. }
  87. if (plbimgr->GetItem(rguid, &plbi) != S_OK)
  88. goto Exit;
  89. // Satori#3713 ; plbi can be NULL
  90. if (plbi == NULL) {
  91. goto Exit;
  92. }
  93. if (FAILED(plbi->QueryInterface(IID_ITfSource, (void **)&source)))
  94. goto Exit;
  95. if (FAILED(source->AdviseSink(IID_ITfSystemLangBarItemSink, this, &_dwCookie)))
  96. goto Exit;
  97. hr = S_OK;
  98. _guid = rguid;
  99. Exit:
  100. SafeReleaseLocal(source);
  101. SafeReleaseLocal(plbi);
  102. return hr;
  103. }
  104. //+---------------------------------------------------------------------------
  105. //
  106. // Unadvise
  107. //
  108. //----------------------------------------------------------------------------
  109. HRESULT CSysHelpSink::_Unadvise(ITfLangBarItemMgr *plbimgr)
  110. {
  111. HRESULT hr;
  112. ITfSource *source = NULL;
  113. ITfLangBarItem *plbi = NULL;
  114. hr = E_FAIL;
  115. if (FAILED(plbimgr->GetItem(_guid, &plbi)))
  116. goto Exit;
  117. // Satori#3713 ; plbi can be NULL
  118. if (plbi == NULL) {
  119. goto Exit;
  120. }
  121. if (FAILED(plbi->QueryInterface(IID_ITfSource, (void **)&source)))
  122. goto Exit;
  123. if (FAILED(source->UnadviseSink(_dwCookie)))
  124. goto Exit;
  125. hr = S_OK;
  126. Exit:
  127. SafeReleaseLocal(source);
  128. SafeReleaseLocal(plbi);
  129. return hr;
  130. }
  131. //+---------------------------------------------------------------------------
  132. //
  133. // InitMenu
  134. //
  135. //----------------------------------------------------------------------------
  136. STDAPI CSysHelpSink::InitMenu(ITfMenu *pMenu)
  137. {
  138. return _pfnInitMenu(_pv, pMenu);
  139. }
  140. //+---------------------------------------------------------------------------
  141. //
  142. // OnMenuSelect
  143. //
  144. //----------------------------------------------------------------------------
  145. STDAPI CSysHelpSink::OnMenuSelect(UINT wID)
  146. {
  147. return _pfnMenuSelect(_pv, wID);
  148. }