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.

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