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.

401 lines
12 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 "sky.h"
  20. #include "nameext.h"
  21. #include "DataObj.h"
  22. #include "globals.h"
  23. #include "resource.h"
  24. #include <crtdbg.h>
  25. // we need to do this to get around MMC.IDL - it explicitly defines
  26. // the clipboard formats as WCHAR types...
  27. #define _T_CCF_DISPLAY_NAME _T("CCF_DISPLAY_NAME")
  28. #define _T_CCF_NODETYPE _T("CCF_NODETYPE")
  29. #define _T_CCF_SNAPIN_CLASSID _T("CCF_SNAPIN_CLASSID")
  30. // These are the clipboard formats that we must supply at a minimum.
  31. // mmc.h actually defined these. We can make up our own to use for
  32. // other reasons. We don't need any others at this time.
  33. UINT CComponentData::s_cfDisplayName = RegisterClipboardFormat(_T_CCF_DISPLAY_NAME);
  34. UINT CComponentData::s_cfNodeType = RegisterClipboardFormat(_T_CCF_NODETYPE);
  35. UINT CComponentData::s_cfSnapInCLSID = RegisterClipboardFormat(_T_CCF_SNAPIN_CLASSID);
  36. const GUID CComponentData::skybasedvehicleGuid = { 0x2974380f, 0x4c4b, 0x11d2, { 0x89, 0xd8, 0x0, 0x0, 0x21, 0x47, 0x31, 0x28 } };
  37. HBITMAP CComponentData::m_pBMapSm = NULL;
  38. HBITMAP CComponentData::m_pBMapLg = NULL;
  39. CComponentData::CComponentData()
  40. : m_cref(0), bExpanded(FALSE), m_ipConsoleNameSpace(NULL), m_ipConsole(NULL)
  41. {
  42. if (NULL == m_pBMapSm || NULL == m_pBMapLg)
  43. LoadBitmaps();
  44. OBJECT_CREATED
  45. }
  46. CComponentData::~CComponentData()
  47. {
  48. OBJECT_DESTROYED
  49. }
  50. ///////////////////////
  51. // IUnknown implementation
  52. ///////////////////////
  53. STDMETHODIMP CComponentData::QueryInterface(REFIID riid, LPVOID *ppv)
  54. {
  55. if (!ppv)
  56. return E_FAIL;
  57. *ppv = NULL;
  58. if (IsEqualIID(riid, IID_IUnknown))
  59. *ppv = static_cast<IComponentData *>(this);
  60. else if (IsEqualIID(riid, IID_IComponentData))
  61. *ppv = static_cast<IComponentData *>(this);
  62. else if (IsEqualIID(riid, IID_IExtendContextMenu))
  63. *ppv = static_cast<IExtendContextMenu *>(this);
  64. if (*ppv)
  65. {
  66. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  67. return S_OK;
  68. }
  69. return E_NOINTERFACE;
  70. }
  71. STDMETHODIMP_(ULONG) CComponentData::AddRef()
  72. {
  73. return InterlockedIncrement((LONG *)&m_cref);
  74. }
  75. STDMETHODIMP_(ULONG) CComponentData::Release()
  76. {
  77. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  78. {
  79. // we need to decrement our object count in the DLL
  80. delete this;
  81. return 0;
  82. }
  83. return m_cref;
  84. }
  85. ///////////////////////////////
  86. // Interface IComponentData
  87. ///////////////////////////////
  88. HRESULT CComponentData::Initialize(
  89. /* [in] */ LPUNKNOWN pUnknown)
  90. {
  91. HRESULT hr;
  92. //
  93. // Get pointer to name space interface
  94. //
  95. hr = pUnknown->QueryInterface(IID_IConsoleNameSpace, (void **)&m_ipConsoleNameSpace);
  96. _ASSERT( S_OK == hr );
  97. //
  98. // Get pointer to console interface
  99. //
  100. hr = pUnknown->QueryInterface(IID_IConsole, (void **)&m_ipConsole);
  101. _ASSERT( S_OK == hr );
  102. IImageList *pImageList;
  103. m_ipConsole->QueryScopeImageList(&pImageList);
  104. _ASSERT( S_OK == hr );
  105. hr = pImageList->ImageListSetStrip( (long *)m_pBMapSm, // pointer to a handle
  106. (long *)m_pBMapLg, // pointer to a handle
  107. 0, // index of the first image in the strip
  108. RGB(0, 128, 128) // color of the icon mask
  109. );
  110. pImageList->Release();
  111. return S_OK;
  112. }
  113. HRESULT CComponentData::CreateComponent(
  114. /* [out] */ LPCOMPONENT __RPC_FAR *ppComponent)
  115. {
  116. *ppComponent = NULL;
  117. CComponent *pComponent = new CComponent(this);
  118. if (NULL == pComponent)
  119. return E_OUTOFMEMORY;
  120. return pComponent->QueryInterface(IID_IComponent, (void **)ppComponent);
  121. }
  122. HRESULT CComponentData::Notify(
  123. /* [in] */ LPDATAOBJECT lpDataObject,
  124. /* [in] */ MMC_NOTIFY_TYPE event,
  125. /* [in] */ LPARAM arg,
  126. /* [in] */ LPARAM param)
  127. {
  128. MMCN_Crack(TRUE, lpDataObject, this, NULL, event, arg, param);
  129. HRESULT hr = S_FALSE;
  130. if (NULL == lpDataObject)
  131. return hr;
  132. switch (event)
  133. {
  134. case MMCN_EXPAND:
  135. GUID myGuid;
  136. GUID* pGUID= &myGuid;
  137. // extract GUID of the the currently selected node type from the data object
  138. hr = ExtractObjectTypeGUID(lpDataObject, pGUID);
  139. _ASSERT( S_OK == hr );
  140. // compare node type GUIDs of currently selected node and the node type
  141. // we want to extend. If they are are equal, currently selected node
  142. // is the type we want to extend, so we add our items underneath it
  143. if (IsEqualGUID(*pGUID, getPrimaryNodeType()))
  144. OnExpand(m_ipConsoleNameSpace, m_ipConsole, (HSCOPEITEM)param);
  145. else
  146. // currently selected node is one of ours instead
  147. {
  148. CDelegationBase *base = GetOurDataObject(lpDataObject)->GetBaseNodeObject();
  149. hr = base->OnExpand(m_ipConsoleNameSpace, m_ipConsole, (HSCOPEITEM)param);
  150. }
  151. break;
  152. }
  153. return hr;
  154. }
  155. HRESULT CComponentData::Destroy( void)
  156. {
  157. // Free interfaces
  158. if (m_ipConsoleNameSpace) {
  159. m_ipConsoleNameSpace->Release();
  160. m_ipConsoleNameSpace = NULL;
  161. }
  162. if (m_ipConsole) {
  163. m_ipConsole->Release();
  164. m_ipConsole = NULL;
  165. }
  166. return S_OK;
  167. }
  168. HRESULT CComponentData::QueryDataObject(
  169. /* [in] */ MMC_COOKIE cookie,
  170. /* [in] */ DATA_OBJECT_TYPES type,
  171. /* [out] */ LPDATAOBJECT *ppDataObject)
  172. {
  173. CDataObject *pObj = NULL;
  174. //cookie == 0 not possible in a namespace extension
  175. // if (cookie == 0)
  176. // pObj = new CDataObject((MMC_COOKIE)m_pComponentData->m_pStaticNode, type);
  177. // else
  178. pObj = new CDataObject(cookie, type);
  179. if (!pObj)
  180. return E_OUTOFMEMORY;
  181. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  182. return S_OK;
  183. }
  184. HRESULT CComponentData::GetDisplayInfo(
  185. /* [out][in] */ SCOPEDATAITEM *pScopeDataItem)
  186. {
  187. HRESULT hr = S_FALSE;
  188. // if they are asking for the SDI_STR we have one of those to give
  189. if (pScopeDataItem->lParam) {
  190. CDelegationBase *base = (CDelegationBase *)pScopeDataItem->lParam;
  191. if (pScopeDataItem->mask & SDI_STR) {
  192. LPCTSTR pszT = base->GetDisplayName();
  193. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  194. pScopeDataItem->displayname = pszW;
  195. }
  196. if (pScopeDataItem->mask & SDI_IMAGE) {
  197. pScopeDataItem->nImage = base->GetBitmapIndex();
  198. }
  199. }
  200. return hr;
  201. }
  202. HRESULT CComponentData::CompareObjects(
  203. /* [in] */ LPDATAOBJECT lpDataObjectA,
  204. /* [in] */ LPDATAOBJECT lpDataObjectB)
  205. {
  206. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  207. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  208. // compare the object pointers
  209. if (baseA->GetCookie() == baseB->GetCookie())
  210. return S_OK;
  211. return S_FALSE;
  212. }
  213. ///////////////////////////////
  214. // Interface IExtendContextMenu
  215. ///////////////////////////////
  216. HRESULT CComponentData::AddMenuItems(
  217. /* [in] */ LPDATAOBJECT piDataObject,
  218. /* [in] */ LPCONTEXTMENUCALLBACK piCallback,
  219. /* [out][in] */ long __RPC_FAR *pInsertionAllowed)
  220. {
  221. CDelegationBase *base = GetOurDataObject(piDataObject)->GetBaseNodeObject();
  222. return base->OnAddMenuItems(piCallback, pInsertionAllowed);
  223. }
  224. HRESULT CComponentData::Command(
  225. /* [in] */ long lCommandID,
  226. /* [in] */ LPDATAOBJECT piDataObject)
  227. {
  228. CDelegationBase *base = GetOurDataObject(piDataObject)->GetBaseNodeObject();
  229. return base->OnMenuCommand(m_ipConsole, lCommandID);
  230. }
  231. ///////////////////////////////
  232. // CComponentData::OnExpand
  233. ///////////////////////////////
  234. HRESULT CComponentData::OnExpand(IConsoleNameSpace *pConsoleNameSpace, IConsole *pConsole, HSCOPEITEM parent)
  235. {
  236. //first create the CSkyVehicle objects, one for each inserted item
  237. for (int n = 0; n < NUMBER_OF_CHILDREN; n++) {
  238. children[n] = new CSkyVehicle(n + 1);
  239. }
  240. //now fill an SCOPEDATAITEM for each item and then insert it
  241. SCOPEDATAITEM sdi;
  242. if (!bExpanded) {
  243. // create the child nodes, then expand them
  244. for (int n = 0; n < NUMBER_OF_CHILDREN; n++) {
  245. ZeroMemory(&sdi, sizeof(SCOPEDATAITEM) );
  246. sdi.mask = SDI_STR | // Displayname is valid
  247. SDI_PARAM | // lParam is valid
  248. SDI_IMAGE | // nImage is valid
  249. SDI_OPENIMAGE | // nOpenImage is valid
  250. SDI_PARENT | // relativeID is valid
  251. SDI_CHILDREN; // cChildren is valid
  252. sdi.relativeID = (HSCOPEITEM)parent;
  253. sdi.nImage = children[n]->GetBitmapIndex();
  254. sdi.nOpenImage = INDEX_OPENFOLDER;
  255. sdi.displayname = MMC_CALLBACK;
  256. sdi.lParam = (LPARAM)children[n]; // The cookie
  257. sdi.cChildren = 0;
  258. HRESULT hr = pConsoleNameSpace->InsertItem( &sdi );
  259. _ASSERT( SUCCEEDED(hr) );
  260. }
  261. }
  262. return S_OK;
  263. }
  264. ///////////////////////////////
  265. // Member functions for extracting
  266. // information from a primary's
  267. // data object
  268. ///////////////////////////////
  269. HRESULT CComponentData::ExtractData( IDataObject* piDataObject,
  270. CLIPFORMAT cfClipFormat,
  271. BYTE* pbData,
  272. DWORD cbData )
  273. {
  274. HRESULT hr = S_OK;
  275. FORMATETC formatetc = {cfClipFormat, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  276. STGMEDIUM stgmedium = {TYMED_HGLOBAL, NULL};
  277. stgmedium.hGlobal = ::GlobalAlloc(GPTR, cbData);
  278. do // false loop
  279. {
  280. if (NULL == stgmedium.hGlobal)
  281. {
  282. hr = E_OUTOFMEMORY;
  283. break;
  284. }
  285. hr = piDataObject->GetDataHere( &formatetc, &stgmedium );
  286. if ( FAILED(hr) )
  287. {
  288. break;
  289. }
  290. BYTE* pbNewData = reinterpret_cast<BYTE*>(stgmedium.hGlobal);
  291. if (NULL == pbNewData)
  292. {
  293. hr = E_UNEXPECTED;
  294. break;
  295. }
  296. ::memcpy( pbData, pbNewData, cbData );
  297. } while (FALSE); // false loop
  298. if (NULL != stgmedium.hGlobal)
  299. {
  300. ::GlobalFree(stgmedium.hGlobal);
  301. }
  302. return hr;
  303. } // ExtractData()
  304. HRESULT CComponentData::ExtractString( IDataObject *piDataObject,
  305. CLIPFORMAT cfClipFormat,
  306. _TCHAR *pstr,
  307. DWORD cchMaxLength)
  308. {
  309. return ExtractData( piDataObject, cfClipFormat, (PBYTE)pstr, cchMaxLength );
  310. }
  311. HRESULT CComponentData::ExtractSnapInCLSID( IDataObject* piDataObject, CLSID* pclsidSnapin )
  312. {
  313. return ExtractData( piDataObject, s_cfSnapInCLSID, (PBYTE)pclsidSnapin, sizeof(CLSID) );
  314. }
  315. HRESULT CComponentData::ExtractObjectTypeGUID( IDataObject* piDataObject, GUID* pguidObjectType )
  316. {
  317. return ExtractData( piDataObject, s_cfNodeType, (PBYTE)pguidObjectType, sizeof(GUID) );
  318. }