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.

309 lines
8.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 "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. else if (IsEqualIID(riid, IID_IExtendPropertySheet) ||
  49. IsEqualIID(riid, IID_IExtendPropertySheet2))
  50. *ppv = static_cast<IExtendPropertySheet2 *>(this);
  51. //else if (IsEqualIID(riid, IID_IExtendPropertySheet))
  52. // *ppv = static_cast<IExtendPropertySheet *>(this);
  53. else if (IsEqualIID(riid, IID_IPersistStream))
  54. *ppv = static_cast<IPersistStream *>(this);
  55. if (*ppv)
  56. {
  57. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  58. return S_OK;
  59. }
  60. return E_NOINTERFACE;
  61. }
  62. STDMETHODIMP_(ULONG) CComponentData::AddRef()
  63. {
  64. return InterlockedIncrement((LONG *)&m_cref);
  65. }
  66. STDMETHODIMP_(ULONG) CComponentData::Release()
  67. {
  68. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  69. {
  70. // we need to decrement our object count in the DLL
  71. delete this;
  72. return 0;
  73. }
  74. return m_cref;
  75. }
  76. ///////////////////////////////
  77. // Interface IComponentData
  78. ///////////////////////////////
  79. HRESULT CComponentData::Initialize(
  80. /* [in] */ LPUNKNOWN pUnknown)
  81. {
  82. HRESULT hr;
  83. //
  84. // Get pointer to name space interface
  85. //
  86. hr = pUnknown->QueryInterface(IID_IConsoleNameSpace, (void **)&m_ipConsoleNameSpace);
  87. _ASSERT( S_OK == hr );
  88. //
  89. // Get pointer to console interface
  90. //
  91. hr = pUnknown->QueryInterface(IID_IConsole, (void **)&m_ipConsole);
  92. _ASSERT( S_OK == hr );
  93. IImageList *pImageList;
  94. m_ipConsole->QueryScopeImageList(&pImageList);
  95. _ASSERT( S_OK == hr );
  96. hr = pImageList->ImageListSetStrip( (long *)m_pStaticNode->m_pBMapSm, // pointer to a handle
  97. (long *)m_pStaticNode->m_pBMapLg, // pointer to a handle
  98. 0, // index of the first image in the strip
  99. RGB(0, 128, 128) // color of the icon mask
  100. );
  101. pImageList->Release();
  102. return S_OK;
  103. }
  104. HRESULT CComponentData::CreateComponent(
  105. /* [out] */ LPCOMPONENT __RPC_FAR *ppComponent)
  106. {
  107. *ppComponent = NULL;
  108. CComponent *pComponent = new CComponent(this);
  109. if (NULL == pComponent)
  110. return E_OUTOFMEMORY;
  111. return pComponent->QueryInterface(IID_IComponent, (void **)ppComponent);
  112. }
  113. HRESULT CComponentData::Notify(
  114. /* [in] */ LPDATAOBJECT lpDataObject,
  115. /* [in] */ MMC_NOTIFY_TYPE event,
  116. /* [in] */ LPARAM arg,
  117. /* [in] */ LPARAM param)
  118. {
  119. MMCN_Crack(TRUE, lpDataObject, this, NULL, event, arg, param);
  120. HRESULT hr = S_FALSE;
  121. //Get our data object. If it is NULL, we return with S_FALSE.
  122. //See implementation of GetOurDataObject() to see how to
  123. //handle special data objects.
  124. CDataObject *pDataObject = GetOurDataObject(lpDataObject);
  125. if (NULL == pDataObject)
  126. return S_FALSE;
  127. CDelegationBase *base = pDataObject->GetBaseNodeObject();
  128. switch (event)
  129. {
  130. case MMCN_EXPAND:
  131. hr = base->OnExpand(m_ipConsoleNameSpace, m_ipConsole, (HSCOPEITEM)param);
  132. break;
  133. }
  134. return hr;
  135. }
  136. HRESULT CComponentData::Destroy( void)
  137. {
  138. // Free interfaces
  139. if (m_ipConsoleNameSpace) {
  140. m_ipConsoleNameSpace->Release();
  141. m_ipConsoleNameSpace = NULL;
  142. }
  143. if (m_ipConsole) {
  144. m_ipConsole->Release();
  145. m_ipConsole = NULL;
  146. }
  147. return S_OK;
  148. }
  149. HRESULT CComponentData::QueryDataObject(
  150. /* [in] */ MMC_COOKIE cookie,
  151. /* [in] */ DATA_OBJECT_TYPES type,
  152. /* [out] */ LPDATAOBJECT *ppDataObject)
  153. {
  154. CDataObject *pObj = NULL;
  155. if (cookie == 0)
  156. pObj = new CDataObject((MMC_COOKIE)m_pStaticNode, type);
  157. else
  158. pObj = new CDataObject(cookie, type);
  159. if (!pObj)
  160. return E_OUTOFMEMORY;
  161. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  162. return S_OK;
  163. }
  164. HRESULT CComponentData::GetDisplayInfo(
  165. /* [out][in] */ SCOPEDATAITEM *pScopeDataItem)
  166. {
  167. HRESULT hr = S_FALSE;
  168. // if they are asking for the SDI_STR we have one of those to give
  169. if (pScopeDataItem->lParam) {
  170. CDelegationBase *base = (CDelegationBase *)pScopeDataItem->lParam;
  171. if (pScopeDataItem->mask & SDI_STR) {
  172. LPCTSTR pszT = base->GetDisplayName();
  173. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  174. pScopeDataItem->displayname = pszW;
  175. }
  176. if (pScopeDataItem->mask & SDI_IMAGE) {
  177. pScopeDataItem->nImage = base->GetBitmapIndex();
  178. }
  179. }
  180. return hr;
  181. }
  182. HRESULT CComponentData::CompareObjects(
  183. /* [in] */ LPDATAOBJECT lpDataObjectA,
  184. /* [in] */ LPDATAOBJECT lpDataObjectB)
  185. {
  186. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  187. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  188. // compare the object pointers
  189. if (baseA->GetCookie() == baseB->GetCookie())
  190. return S_OK;
  191. return S_FALSE;
  192. }
  193. ///////////////////////////////////
  194. // Interface IExtendPropertySheet2
  195. ///////////////////////////////////
  196. HRESULT CComponentData::CreatePropertyPages(
  197. /* [in] */ LPPROPERTYSHEETCALLBACK lpProvider,
  198. /* [in] */ LONG_PTR handle,
  199. /* [in] */ LPDATAOBJECT lpIDataObject)
  200. {
  201. return m_pStaticNode->CreatePropertyPages(lpProvider, handle);
  202. }
  203. HRESULT CComponentData::QueryPagesFor(
  204. /* [in] */ LPDATAOBJECT lpDataObject)
  205. {
  206. return m_pStaticNode->HasPropertySheets();
  207. }
  208. HRESULT CComponentData::GetWatermarks(
  209. /* [in] */ LPDATAOBJECT lpIDataObject,
  210. /* [out] */ HBITMAP __RPC_FAR *lphWatermark,
  211. /* [out] */ HBITMAP __RPC_FAR *lphHeader,
  212. /* [out] */ HPALETTE __RPC_FAR *lphPalette,
  213. /* [out] */ BOOL __RPC_FAR *bStretch)
  214. {
  215. return m_pStaticNode->GetWatermarks(lphWatermark, lphHeader, lphPalette, bStretch);
  216. }
  217. ///////////////////////////////
  218. // Interface IPersistStream
  219. ///////////////////////////////
  220. HRESULT CComponentData::GetClassID(
  221. /* [out] */ CLSID __RPC_FAR *pClassID)
  222. {
  223. *pClassID = m_pStaticNode->getNodeType();
  224. return S_OK;
  225. }
  226. HRESULT CComponentData::IsDirty( void)
  227. {
  228. return m_pStaticNode->isDirty() == true ? S_OK : S_FALSE;
  229. }
  230. HRESULT CComponentData::Load(
  231. /* [unique][in] */ IStream __RPC_FAR *pStm)
  232. {
  233. void *snapInData = m_pStaticNode->getData();
  234. ULONG dataSize = m_pStaticNode->getDataSize();
  235. return pStm->Read(snapInData, dataSize, NULL);
  236. }
  237. HRESULT CComponentData::Save(
  238. /* [unique][in] */ IStream __RPC_FAR *pStm,
  239. /* [in] */ BOOL fClearDirty)
  240. {
  241. void *snapInData = m_pStaticNode->getData();
  242. ULONG dataSize = m_pStaticNode->getDataSize();
  243. if (fClearDirty)
  244. m_pStaticNode->clearDirty();
  245. return pStm->Write(snapInData, dataSize, NULL);
  246. }
  247. HRESULT CComponentData::GetSizeMax(
  248. /* [out] */ ULARGE_INTEGER __RPC_FAR *pcbSize)
  249. {
  250. return m_pStaticNode->getDataSize();
  251. }