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.

245 lines
6.5 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 "CompData.h"
  20. #include "DataObj.h"
  21. #include "Space.h"
  22. #include "resource.h"
  23. #include <crtdbg.h>
  24. CComponentData::CComponentData()
  25. : m_cref(0), m_ipConsoleNameSpace(NULL), m_ipConsole(NULL)
  26. {
  27. OBJECT_CREATED
  28. m_pStaticNode = new CStaticNode;
  29. }
  30. CComponentData::~CComponentData()
  31. {
  32. if (m_pStaticNode) {
  33. delete m_pStaticNode;
  34. }
  35. OBJECT_DESTROYED
  36. }
  37. ///////////////////////
  38. // IUnknown implementation
  39. ///////////////////////
  40. STDMETHODIMP CComponentData::QueryInterface(REFIID riid, LPVOID *ppv)
  41. {
  42. if (!ppv)
  43. return E_FAIL;
  44. *ppv = NULL;
  45. if (IsEqualIID(riid, IID_IUnknown))
  46. *ppv = static_cast<IComponentData *>(this);
  47. else if (IsEqualIID(riid, IID_IComponentData))
  48. *ppv = static_cast<IComponentData *>(this);
  49. if (*ppv)
  50. {
  51. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  52. return S_OK;
  53. }
  54. return E_NOINTERFACE;
  55. }
  56. STDMETHODIMP_(ULONG) CComponentData::AddRef()
  57. {
  58. return InterlockedIncrement((LONG *)&m_cref);
  59. }
  60. STDMETHODIMP_(ULONG) CComponentData::Release()
  61. {
  62. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  63. {
  64. // we need to decrement our object count in the DLL
  65. delete this;
  66. return 0;
  67. }
  68. return m_cref;
  69. }
  70. ///////////////////////////////
  71. // Interface IComponentData
  72. ///////////////////////////////
  73. HRESULT CComponentData::Initialize(
  74. /* [in] */ LPUNKNOWN pUnknown)
  75. {
  76. HRESULT hr;
  77. //
  78. // Get pointer to name space interface
  79. //
  80. hr = pUnknown->QueryInterface(IID_IConsoleNameSpace, (void **)&m_ipConsoleNameSpace);
  81. _ASSERT( S_OK == hr );
  82. //
  83. // Get pointer to console interface
  84. //
  85. hr = pUnknown->QueryInterface(IID_IConsole, (void **)&m_ipConsole);
  86. _ASSERT( S_OK == hr );
  87. IImageList *pImageList;
  88. m_ipConsole->QueryScopeImageList(&pImageList);
  89. _ASSERT( S_OK == hr );
  90. hr = pImageList->ImageListSetStrip( (long *)m_pStaticNode->m_pBMapSm, // pointer to a handle
  91. (long *)m_pStaticNode->m_pBMapLg, // pointer to a handle
  92. 0, // index of the first image in the strip
  93. RGB(0, 128, 128) // color of the icon mask
  94. );
  95. pImageList->Release();
  96. return S_OK;
  97. }
  98. HRESULT CComponentData::CreateComponent(
  99. /* [out] */ LPCOMPONENT __RPC_FAR *ppComponent)
  100. {
  101. *ppComponent = NULL;
  102. CComponent *pComponent = new CComponent(this);
  103. if (NULL == pComponent)
  104. return E_OUTOFMEMORY;
  105. return pComponent->QueryInterface(IID_IComponent, (void **)ppComponent);
  106. }
  107. HRESULT CComponentData::Notify(
  108. /* [in] */ LPDATAOBJECT lpDataObject,
  109. /* [in] */ MMC_NOTIFY_TYPE event,
  110. /* [in] */ LPARAM arg,
  111. /* [in] */ LPARAM param)
  112. {
  113. MMCN_Crack(TRUE, lpDataObject, this, NULL, event, arg, param);
  114. HRESULT hr = S_FALSE;
  115. //Get our data object. If it is NULL, we return with S_FALSE.
  116. //See implementation of GetOurDataObject() to see how to
  117. //handle special data objects.
  118. CDataObject *pDataObject = GetOurDataObject(lpDataObject);
  119. if (NULL == pDataObject)
  120. return S_FALSE;
  121. CDelegationBase *base = pDataObject->GetBaseNodeObject();
  122. switch (event)
  123. {
  124. case MMCN_EXPAND:
  125. hr = base->OnExpand(m_ipConsoleNameSpace, m_ipConsole, (HSCOPEITEM)param);
  126. break;
  127. case MMCN_ADD_IMAGES:
  128. hr = base->OnAddImages((IImageList *)arg, (HSCOPEITEM)param);
  129. break;
  130. case MMCN_DELETE:
  131. CSpaceStation* pSpaceStn = dynamic_cast<CSpaceStation*>(base);
  132. if (NULL != pSpaceStn)
  133. {
  134. hr = pSpaceStn->OnDeleteScopeItem(m_ipConsoleNameSpace);
  135. }
  136. break;
  137. }
  138. return hr;
  139. }
  140. HRESULT CComponentData::Destroy( void)
  141. {
  142. // Free interfaces
  143. if (m_ipConsoleNameSpace) {
  144. m_ipConsoleNameSpace->Release();
  145. m_ipConsoleNameSpace = NULL;
  146. }
  147. if (m_ipConsole) {
  148. m_ipConsole->Release();
  149. m_ipConsole = NULL;
  150. }
  151. return S_OK;
  152. }
  153. HRESULT CComponentData::QueryDataObject(
  154. /* [in] */ MMC_COOKIE cookie,
  155. /* [in] */ DATA_OBJECT_TYPES type,
  156. /* [out] */ LPDATAOBJECT *ppDataObject)
  157. {
  158. CDataObject *pObj = NULL;
  159. if (cookie == 0)
  160. pObj = new CDataObject((MMC_COOKIE)m_pStaticNode, type);
  161. else
  162. pObj = new CDataObject(cookie, type);
  163. if (!pObj)
  164. return E_OUTOFMEMORY;
  165. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  166. return S_OK;
  167. }
  168. HRESULT CComponentData::GetDisplayInfo(
  169. /* [out][in] */ SCOPEDATAITEM *pScopeDataItem)
  170. {
  171. HRESULT hr = S_FALSE;
  172. // if they are asking for the SDI_STR we have one of those to give
  173. if (pScopeDataItem->lParam) {
  174. CDelegationBase *base = (CDelegationBase *)pScopeDataItem->lParam;
  175. if (pScopeDataItem->mask & SDI_STR) {
  176. LPCTSTR pszT = base->GetDisplayName();
  177. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  178. pScopeDataItem->displayname = pszW;
  179. }
  180. if (pScopeDataItem->mask & SDI_IMAGE) {
  181. pScopeDataItem->nImage = base->GetBitmapIndex();
  182. }
  183. }
  184. return hr;
  185. }
  186. HRESULT CComponentData::CompareObjects(
  187. /* [in] */ LPDATAOBJECT lpDataObjectA,
  188. /* [in] */ LPDATAOBJECT lpDataObjectB)
  189. {
  190. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  191. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  192. // compare the object pointers
  193. if (baseA->GetCookie() == baseB->GetCookie())
  194. return S_OK;
  195. return S_FALSE;
  196. }