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.

247 lines
6.9 KiB

  1. //==============================================================;
  2. //
  3. // This source code is only intended as a supplement to existing Microsoft documentation.
  4. //
  5. //
  6. //
  7. //
  8. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  9. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  10. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  11. // PURPOSE.
  12. //
  13. // Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  14. //
  15. //
  16. //
  17. //==============================================================;
  18. #include "Comp.h"
  19. #include "DataObj.h"
  20. #include <crtdbg.h>
  21. #include "globals.h"
  22. #include "resource.h"
  23. #include "DeleBase.h"
  24. #include "NameExt.h"
  25. CComponent::CComponent(CComponentData *parent)
  26. : m_pComponentData(parent), m_cref(0), m_ipConsole(NULL), m_ipDisplayHelp(NULL)
  27. {
  28. OBJECT_CREATED
  29. }
  30. CComponent::~CComponent()
  31. {
  32. OBJECT_DESTROYED
  33. }
  34. STDMETHODIMP CComponent::QueryInterface(REFIID riid, LPVOID *ppv)
  35. {
  36. if (!ppv)
  37. return E_FAIL;
  38. *ppv = NULL;
  39. if (IsEqualIID(riid, IID_IUnknown))
  40. *ppv = static_cast<IComponent *>(this);
  41. else if (IsEqualIID(riid, IID_IComponent))
  42. *ppv = static_cast<IComponent *>(this);
  43. else if (IsEqualIID(riid, IID_IExtendContextMenu))
  44. *ppv = static_cast<IExtendContextMenu *>(this);
  45. if (*ppv)
  46. {
  47. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  48. return S_OK;
  49. }
  50. return E_NOINTERFACE;
  51. }
  52. STDMETHODIMP_(ULONG) CComponent::AddRef()
  53. {
  54. return InterlockedIncrement((LONG *)&m_cref);
  55. }
  56. STDMETHODIMP_(ULONG) CComponent::Release()
  57. {
  58. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  59. {
  60. delete this;
  61. return 0;
  62. }
  63. return m_cref;
  64. }
  65. ///////////////////////////////
  66. // Interface IComponent
  67. ///////////////////////////////
  68. STDMETHODIMP CComponent::Initialize(
  69. /* [in] */ LPCONSOLE lpConsole)
  70. {
  71. HRESULT hr = S_OK;
  72. // Save away all the interfaces we'll need.
  73. // Fail if we can't QI the required interfaces.
  74. m_ipConsole = lpConsole;
  75. m_ipConsole->AddRef();
  76. hr = m_ipConsole->QueryInterface(IID_IDisplayHelp, (void **)&m_ipDisplayHelp);
  77. return hr;
  78. }
  79. STDMETHODIMP CComponent::Notify(
  80. /* [in] */ LPDATAOBJECT lpDataObject,
  81. /* [in] */ MMC_NOTIFY_TYPE event,
  82. /* [in] */ LPARAM arg,
  83. /* [in] */ LPARAM param)
  84. {
  85. MMCN_Crack(FALSE, lpDataObject, NULL, this, event, arg, param);
  86. HRESULT hr = S_FALSE;
  87. //Get our data object. If it is NULL, we return with S_FALSE.
  88. //See implementation of GetOurDataObject() to see how to
  89. //handle special data objects.
  90. CDataObject *pDataObject = GetOurDataObject(lpDataObject);
  91. if (NULL == pDataObject)
  92. return S_FALSE;
  93. CDelegationBase *base = pDataObject->GetBaseNodeObject();
  94. switch (event) {
  95. case MMCN_ADD_IMAGES:
  96. hr = base->OnAddImages((IImageList *)arg, (HSCOPEITEM)param);
  97. break;
  98. case MMCN_SHOW:
  99. hr = base->OnShow(m_ipConsole, (BOOL)arg, (HSCOPEITEM)param);
  100. break;
  101. }
  102. return hr;
  103. }
  104. STDMETHODIMP CComponent::Destroy(
  105. /* [in] */ MMC_COOKIE cookie)
  106. {
  107. if (m_ipConsole) {
  108. m_ipConsole->Release();
  109. m_ipConsole = NULL;
  110. }
  111. if (m_ipDisplayHelp) {
  112. m_ipDisplayHelp->Release();
  113. m_ipDisplayHelp = NULL;
  114. }
  115. return S_OK;
  116. }
  117. STDMETHODIMP CComponent::QueryDataObject(
  118. /* [in] */ MMC_COOKIE cookie,
  119. /* [in] */ DATA_OBJECT_TYPES type,
  120. /* [out] */ LPDATAOBJECT __RPC_FAR *ppDataObject)
  121. {
  122. CDataObject *pObj = NULL;
  123. //cookie == 0 not possible in a namespace extension
  124. // if (cookie == 0)
  125. // pObj = new CDataObject((MMC_COOKIE)m_pComponentData->m_pStaticNode, type);
  126. // else
  127. pObj = new CDataObject(cookie, type);
  128. if (!pObj)
  129. return E_OUTOFMEMORY;
  130. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  131. return S_OK;
  132. }
  133. STDMETHODIMP CComponent::GetResultViewType(
  134. /* [in] */ MMC_COOKIE cookie,
  135. /* [out] */ LPOLESTR __RPC_FAR *ppViewType,
  136. /* [out] */ long __RPC_FAR *pViewOptions)
  137. {
  138. CDelegationBase *base = (CDelegationBase *)cookie;
  139. //
  140. // Ask for default listview.
  141. //
  142. if (base == NULL)
  143. {
  144. *pViewOptions = MMC_VIEW_OPTIONS_NONE;
  145. *ppViewType = NULL;
  146. }
  147. else
  148. return base->GetResultViewType(ppViewType, pViewOptions);
  149. return S_OK;
  150. }
  151. STDMETHODIMP CComponent::GetDisplayInfo(
  152. /* [out][in] */ RESULTDATAITEM __RPC_FAR *pResultDataItem)
  153. {
  154. HRESULT hr = S_OK;
  155. CDelegationBase *base = NULL;
  156. // if they are asking for the RDI_STR we have one of those to give
  157. if (pResultDataItem->lParam) {
  158. base = (CDelegationBase *)pResultDataItem->lParam;
  159. if (pResultDataItem->mask & RDI_STR) {
  160. LPCTSTR pszT = base->GetDisplayName(pResultDataItem->nCol);
  161. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  162. pResultDataItem->str = pszW;
  163. }
  164. if (pResultDataItem->mask & RDI_IMAGE) {
  165. pResultDataItem->nImage = base->GetBitmapIndex();
  166. }
  167. }
  168. return hr;
  169. }
  170. STDMETHODIMP CComponent::CompareObjects(
  171. /* [in] */ LPDATAOBJECT lpDataObjectA,
  172. /* [in] */ LPDATAOBJECT lpDataObjectB)
  173. {
  174. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  175. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  176. // compare the object pointers
  177. if (baseA->GetCookie() == baseB->GetCookie())
  178. return S_OK;
  179. return S_FALSE;
  180. }
  181. ///////////////////////////////
  182. // Interface IExtendContextMenu
  183. ///////////////////////////////
  184. HRESULT CComponent::AddMenuItems(
  185. /* [in] */ LPDATAOBJECT piDataObject,
  186. /* [in] */ LPCONTEXTMENUCALLBACK piCallback,
  187. /* [out][in] */ long __RPC_FAR *pInsertionAllowed)
  188. {
  189. CDelegationBase *base = GetOurDataObject(piDataObject)->GetBaseNodeObject();
  190. return base->OnAddMenuItems(piCallback, pInsertionAllowed);
  191. }
  192. HRESULT CComponent::Command(
  193. /* [in] */ long lCommandID,
  194. /* [in] */ LPDATAOBJECT piDataObject)
  195. {
  196. CDelegationBase *base = GetOurDataObject(piDataObject)->GetBaseNodeObject();
  197. return base->OnMenuCommand(m_ipConsole, lCommandID);
  198. }