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.

349 lines
8.1 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997-1999 **/
  4. /**********************************************************************/
  5. /*
  6. csmplsnp.cpp
  7. This file contains the derived classes for CComponent and
  8. CComponentData. Most of these functions are pure virtual
  9. functions that need to be overridden for snapin functionality.
  10. FILE HISTORY:
  11. */
  12. #include "stdafx.h"
  13. #include "handler.h"
  14. #include <atlimpl.cpp>
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /*---------------------------------------------------------------------------
  21. CSnmpComponent
  22. ---------------------------------------------------------------------------*/
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CSnmpComponent implementation
  25. CSnmpComponent::CSnmpComponent()
  26. {
  27. }
  28. CSnmpComponent::~CSnmpComponent()
  29. {
  30. }
  31. STDMETHODIMP CSnmpComponent::OnUpdateView(LPDATAOBJECT pDataObject, LPARAM arg, LPARAM param)
  32. {
  33. return hrOK;
  34. }
  35. STDMETHODIMP CSnmpComponent::InitializeBitmaps(MMC_COOKIE cookie)
  36. {
  37. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  38. ASSERT(m_spImageList != NULL);
  39. HRESULT hr = hrOK;
  40. COM_PROTECT_TRY
  41. {
  42. CBitmap bmp16x16;
  43. CBitmap bmp32x32;
  44. // Load the bitmaps from the dll
  45. bmp16x16.LoadBitmap(IDB_16x16);
  46. bmp32x32.LoadBitmap(IDB_32x32);
  47. // Set the images
  48. m_spImageList->ImageListSetStrip(
  49. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp16x16)),
  50. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp32x32)),
  51. 0, RGB(255,0,255));
  52. }
  53. COM_PROTECT_CATCH;
  54. return hr;
  55. }
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CSnmpComponentData implementation
  58. STDMETHODIMP_(ULONG) CSnmpComponentData::AddRef() {return InternalAddRef();}
  59. STDMETHODIMP_(ULONG) CSnmpComponentData::Release()
  60. {
  61. ULONG l = InternalRelease();
  62. if (l == 0)
  63. delete this;
  64. return l;
  65. }
  66. CSnmpComponentData::CSnmpComponentData()
  67. {
  68. }
  69. /*!--------------------------------------------------------------------------
  70. CSnmpComponentData::OnInitialize
  71. -
  72. Author: EricDav, KennT
  73. ---------------------------------------------------------------------------*/
  74. STDMETHODIMP CSnmpComponentData::OnInitialize(LPIMAGELIST pScopeImage)
  75. {
  76. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  77. ASSERT(pScopeImage);
  78. HRESULT hr = hrOK;
  79. COM_PROTECT_TRY
  80. {
  81. // add the images for the scope tree
  82. CBitmap bmp16x16;
  83. // Load the bitmaps from the dll
  84. bmp16x16.LoadBitmap(IDB_16x16);
  85. // Set the images
  86. pScopeImage->ImageListSetStrip(
  87. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp16x16)),
  88. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp16x16)),
  89. 0,
  90. RGB(255,0,255));
  91. }
  92. COM_PROTECT_CATCH;
  93. return hr;
  94. }
  95. /*!--------------------------------------------------------------------------
  96. CSnmpComponentData::OnInitializeNodeMgr
  97. -
  98. Author: KennT
  99. ---------------------------------------------------------------------------*/
  100. STDMETHODIMP CSnmpComponentData::OnInitializeNodeMgr(ITFSComponentData *pTFSCompData, ITFSNodeMgr *pNodeMgr)
  101. {
  102. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  103. // For now create a new node handler for each new node,
  104. // this is rather bogus as it can get expensive. We can
  105. // consider creating only a single node handler for each
  106. // node type.
  107. CSnmpRootHandler *pHandler = NULL;
  108. SPITFSNodeHandler spHandler;
  109. SPITFSNode spNode;
  110. HRESULT hr = hrOK;
  111. COM_PROTECT_TRY
  112. {
  113. pHandler = new CSnmpRootHandler(pTFSCompData);
  114. // Do this so that it will get released correctly
  115. spHandler = pHandler;
  116. // Create the root node for this sick puppy
  117. CORg( CreateContainerTFSNode(&spNode,
  118. &GUID_SnmpRootNodeType,
  119. pHandler,
  120. pHandler /* result handler */,
  121. pNodeMgr) );
  122. // Need to initialize the data for the root node
  123. spNode->SetData(TFS_DATA_IMAGEINDEX, IMAGE_IDX_FOLDER_CLOSED);
  124. spNode->SetData(TFS_DATA_OPENIMAGEINDEX, IMAGE_IDX_FOLDER_OPEN);
  125. spNode->SetData(TFS_DATA_SCOPEID, 0);
  126. CORg( pNodeMgr->SetRootNode(spNode) );
  127. // in general do
  128. // spNode->SetData(TFS_DATA_COOKIE, (DWORD)(ITFSNode *)spNode);
  129. spNode->SetData(TFS_DATA_COOKIE, 0);
  130. COM_PROTECT_ERROR_LABEL;
  131. }
  132. COM_PROTECT_CATCH;
  133. return hr;
  134. }
  135. /*!--------------------------------------------------------------------------
  136. CSnmpComponentData::OnCreateComponent
  137. -
  138. Author: EricDav, KennT
  139. ---------------------------------------------------------------------------*/
  140. STDMETHODIMP CSnmpComponentData::OnCreateComponent(LPCOMPONENT *ppComponent)
  141. {
  142. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  143. ASSERT(ppComponent != NULL);
  144. HRESULT hr = hrOK;
  145. CSnmpComponent * pComp = NULL;
  146. COM_PROTECT_TRY
  147. {
  148. pComp = new CSnmpComponent;
  149. if (FHrSucceeded(hr))
  150. {
  151. pComp->Construct(m_spNodeMgr,
  152. static_cast<IComponentData *>(this),
  153. m_spTFSComponentData);
  154. *ppComponent = static_cast<IComponent *>(pComp);
  155. }
  156. }
  157. COM_PROTECT_CATCH;
  158. return hr;
  159. }
  160. STDMETHODIMP CSnmpComponentData::OnDestroy()
  161. {
  162. m_spNodeMgr.Release();
  163. return hrOK;
  164. }
  165. /*!--------------------------------------------------------------------------
  166. CSnmpComponentData::GetCoClassID
  167. -
  168. Author: KennT
  169. ---------------------------------------------------------------------------*/
  170. STDMETHODIMP_(const CLSID *) CSnmpComponentData::GetCoClassID()
  171. {
  172. return &CLSID_SnmpSnapin;
  173. }
  174. /*!--------------------------------------------------------------------------
  175. CSnmpComponentData::OnCreateDataObject
  176. -
  177. Author: KennT
  178. ---------------------------------------------------------------------------*/
  179. STDMETHODIMP CSnmpComponentData::OnCreateDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, IDataObject **ppDataObject)
  180. {
  181. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  182. ASSERT(ppDataObject != NULL);
  183. CDataObject * pObject = NULL;
  184. SPIDataObject spDataObject;
  185. pObject = new CDataObject;
  186. spDataObject = pObject; // do this so that it gets released correctly
  187. ASSERT(pObject != NULL);
  188. // Save cookie and type for delayed rendering
  189. pObject->SetType(type);
  190. pObject->SetCookie(cookie);
  191. // Store the coclass with the data object
  192. pObject->SetClsid(*GetCoClassID());
  193. pObject->SetTFSComponentData(m_spTFSComponentData);
  194. return pObject->QueryInterface(IID_IDataObject,
  195. reinterpret_cast<void**>(ppDataObject));
  196. }
  197. ///////////////////////////////////////////////////////////////////////////////
  198. //// IPersistStream interface members
  199. STDMETHODIMP CSnmpComponentData::GetClassID
  200. (
  201. CLSID *pClassID
  202. )
  203. {
  204. ASSERT(pClassID != NULL);
  205. // Copy the CLSID for this snapin
  206. *pClassID = CLSID_SnmpSnapin;
  207. return hrOK;
  208. }
  209. STDMETHODIMP CSnmpComponentData::IsDirty()
  210. {
  211. SPITFSNode spNode;
  212. m_spNodeMgr->GetRootNode(&spNode);
  213. return spNode->GetData(TFS_DATA_DIRTY) ? hrOK : hrFalse;
  214. }
  215. STDMETHODIMP CSnmpComponentData::Load
  216. (
  217. IStream *pStm
  218. )
  219. {
  220. HRESULT hr = S_OK;
  221. ASSERT(pStm);
  222. return SUCCEEDED(hr) ? S_OK : E_FAIL;
  223. }
  224. STDMETHODIMP CSnmpComponentData::Save
  225. (
  226. IStream *pStm,
  227. BOOL fClearDirty
  228. )
  229. {
  230. HRESULT hr = S_OK;
  231. SPITFSNode spNode;
  232. ASSERT(pStm);
  233. if (fClearDirty)
  234. {
  235. m_spNodeMgr->GetRootNode(&spNode);
  236. spNode->SetData(TFS_DATA_DIRTY, FALSE);
  237. }
  238. return SUCCEEDED(hr) ? S_OK : STG_E_CANTSAVE;
  239. }
  240. STDMETHODIMP CSnmpComponentData::GetSizeMax
  241. (
  242. ULARGE_INTEGER *pcbSize
  243. )
  244. {
  245. ASSERT(pcbSize);
  246. // Set the size of the string to be saved
  247. ULISet32(*pcbSize, 500);
  248. return S_OK;
  249. }
  250. STDMETHODIMP CSnmpComponentData::InitNew()
  251. {
  252. return hrOK;
  253. }
  254. HRESULT CSnmpComponentData::FinalConstruct()
  255. {
  256. HRESULT hr = hrOK;
  257. hr = CComponentData::FinalConstruct();
  258. if (FHrSucceeded(hr))
  259. {
  260. m_spTFSComponentData->GetNodeMgr(&m_spNodeMgr);
  261. }
  262. return hr;
  263. }
  264. void CSnmpComponentData::FinalRelease()
  265. {
  266. CComponentData::FinalRelease();
  267. }