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.

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