Source code of Windows XP (NT5)
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.

576 lines
13 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 "ipxcomp.h"
  14. #include "ipxroot.h"
  15. #include <atlimpl.cpp>
  16. #include "ipxstrm.h"
  17. #include "summary.h"
  18. #include "nbview.h"
  19. #include "srview.h"
  20. #include "ssview.h"
  21. #include "snview.h"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. /*---------------------------------------------------------------------------
  28. CIPXComponent
  29. ---------------------------------------------------------------------------*/
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CIPXComponent implementation
  32. CIPXComponent::CIPXComponent()
  33. {
  34. extern const ContainerColumnInfo s_rgIfViewColumnInfo[];
  35. extern const ContainerColumnInfo s_rgNBViewColumnInfo[];
  36. extern const ContainerColumnInfo s_rgSRViewColumnInfo[];
  37. extern const ContainerColumnInfo s_rgSSViewColumnInfo[];
  38. extern const ContainerColumnInfo s_rgSNViewColumnInfo[];
  39. m_ComponentConfig.Init(COLUMNS_MAX_COUNT);
  40. m_ComponentConfig.InitViewInfo(COLUMNS_SUMMARY,
  41. FALSE /*fConfigurableColumns*/,
  42. IPXSUM_MAX_COLUMNS,
  43. TRUE,
  44. s_rgIfViewColumnInfo);
  45. m_ComponentConfig.InitViewInfo(COLUMNS_NBBROADCASTS,
  46. FALSE /*fConfigurableColumns*/,
  47. IPXNB_MAX_COLUMNS,
  48. TRUE,
  49. s_rgNBViewColumnInfo);
  50. m_ComponentConfig.InitViewInfo(COLUMNS_STATICROUTES,
  51. FALSE /*fConfigurableColumns*/,
  52. IPX_SR_MAX_COLUMNS,
  53. TRUE,
  54. s_rgSRViewColumnInfo);
  55. m_ComponentConfig.InitViewInfo(COLUMNS_STATICSERVICES,
  56. FALSE /*fConfigurableColumns*/,
  57. IPX_SS_MAX_COLUMNS,
  58. TRUE,
  59. s_rgSSViewColumnInfo);
  60. m_ComponentConfig.InitViewInfo(COLUMNS_STATICNETBIOSNAMES,
  61. FALSE /*fConfigurableColumns*/,
  62. IPX_SN_MAX_COLUMNS,
  63. TRUE,
  64. s_rgSNViewColumnInfo);
  65. m_ulUserData = reinterpret_cast<LONG_PTR>(&m_ComponentConfig);
  66. }
  67. CIPXComponent::~CIPXComponent()
  68. {
  69. }
  70. STDMETHODIMP_(ULONG) CIPXComponent::AddRef()
  71. {
  72. return TFSComponent::AddRef();
  73. }
  74. STDMETHODIMP_(ULONG) CIPXComponent::Release()
  75. {
  76. return TFSComponent::Release();
  77. }
  78. STDMETHODIMP CIPXComponent::QueryInterface(REFIID riid, LPVOID *ppv)
  79. {
  80. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  81. // Is the pointer bad?
  82. if (ppv == NULL)
  83. return E_INVALIDARG;
  84. // Place NULL in *ppv in case of failure
  85. *ppv = NULL;
  86. if (riid == IID_IPersistStreamInit)
  87. *ppv = static_cast<IPersistStreamInit *>(this);
  88. // If we're going to return an interface, AddRef it first
  89. if (*ppv)
  90. {
  91. ((LPUNKNOWN) *ppv)->AddRef();
  92. return hrOK;
  93. }
  94. else
  95. return TFSComponent::QueryInterface(riid, ppv);
  96. }
  97. STDMETHODIMP CIPXComponent::OnUpdateView(LPDATAOBJECT pDataObject,
  98. LPARAM arg, LPARAM param)
  99. {
  100. return TFSComponent::OnUpdateView(pDataObject, arg, param);
  101. }
  102. STDMETHODIMP CIPXComponent::InitializeBitmaps(MMC_COOKIE cookie)
  103. {
  104. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  105. ASSERT(m_spImageList != NULL);
  106. CBitmap bmp16x16;
  107. CBitmap bmp32x32;
  108. HRESULT hr = hrOK;
  109. COM_PROTECT_TRY
  110. {
  111. // Load the bitmaps from the dll
  112. bmp16x16.LoadBitmap(IDB_16x16);
  113. bmp32x32.LoadBitmap(IDB_32x32);
  114. // Set the images
  115. m_spImageList->ImageListSetStrip(
  116. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp16x16)),
  117. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp32x32)),
  118. 0, RGB(255,0,255));
  119. }
  120. COM_PROTECT_CATCH;
  121. return hr;
  122. }
  123. /*!--------------------------------------------------------------------------
  124. CIPXComponent::OnSnapinHelp
  125. -
  126. Author: MikeG (a-migall)
  127. ---------------------------------------------------------------------------*/
  128. STDMETHODIMP
  129. CIPXComponent::OnSnapinHelp(
  130. LPDATAOBJECT pDataObject,
  131. LPARAM arg,
  132. LPARAM param)
  133. {
  134. UNREFERENCED_PARAMETER(pDataObject);
  135. UNREFERENCED_PARAMETER(arg);
  136. UNREFERENCED_PARAMETER(param);
  137. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  138. HtmlHelpA(NULL, // caller
  139. c_sazIPXSnapHelpFile, // help file
  140. HH_DISPLAY_TOPIC, // command
  141. 0); // data
  142. return hrOK;
  143. }
  144. STDMETHODIMP CIPXComponent::QueryDataObject(MMC_COOKIE cookie,
  145. DATA_OBJECT_TYPES type,
  146. LPDATAOBJECT *ppDataObject)
  147. {
  148. HRESULT hr = hrOK;
  149. SPITFSNode spNode;
  150. SPITFSResultHandler spResultHandler;
  151. COM_PROTECT_TRY
  152. {
  153. CORg( m_spNodeMgr->FindNode(cookie, &spNode) );
  154. CORg( spNode->GetResultHandler(&spResultHandler) );
  155. CORg( spResultHandler->OnCreateDataObject(this, cookie,
  156. type, ppDataObject) );
  157. COM_PROTECT_ERROR_LABEL;
  158. }
  159. COM_PROTECT_CATCH;
  160. return hr;
  161. }
  162. STDMETHODIMP CIPXComponent::GetClassID(LPCLSID lpClassID)
  163. {
  164. ASSERT(lpClassID != NULL);
  165. // Copy the CLSID for this snapin
  166. *lpClassID = CLSID_IPXAdminExtension;
  167. return hrOK;
  168. }
  169. STDMETHODIMP CIPXComponent::IsDirty()
  170. {
  171. HRESULT hr = hrOK;
  172. COM_PROTECT_TRY
  173. {
  174. hr = m_ComponentConfig.GetDirty() ? hrOK : hrFalse;
  175. }
  176. COM_PROTECT_CATCH;
  177. return hr;
  178. }
  179. STDMETHODIMP CIPXComponent::Load(LPSTREAM pStm)
  180. {
  181. HRESULT hr = hrOK;
  182. COM_PROTECT_TRY
  183. {
  184. hr = m_ComponentConfig.LoadFrom(pStm);
  185. }
  186. COM_PROTECT_CATCH;
  187. return hr;
  188. }
  189. STDMETHODIMP CIPXComponent::Save(LPSTREAM pStm, BOOL fClearDirty)
  190. {
  191. HRESULT hr = hrOK;
  192. SPITFSResultHandler spResultHandler;
  193. COM_PROTECT_TRY
  194. {
  195. // Need to see if we can save the selected node
  196. // -------------------------------------------------------------
  197. if (m_spSelectedNode)
  198. {
  199. m_spSelectedNode->GetResultHandler(&spResultHandler);
  200. if (spResultHandler)
  201. spResultHandler->UserResultNotify(m_spSelectedNode,
  202. RRAS_ON_SAVE, (LPARAM)(ITFSComponent *) this);
  203. }
  204. hr = m_ComponentConfig.SaveTo(pStm);
  205. if (FHrSucceeded(hr) && fClearDirty)
  206. m_ComponentConfig.SetDirty(FALSE);
  207. }
  208. COM_PROTECT_CATCH;
  209. return hr;
  210. }
  211. STDMETHODIMP CIPXComponent::GetSizeMax(ULARGE_INTEGER FAR *pcbSize)
  212. {
  213. Assert(pcbSize);
  214. HRESULT hr = hrOK;
  215. ULONG cbSize = 0;
  216. COM_PROTECT_TRY
  217. {
  218. hr = m_ComponentConfig.GetSize(&cbSize);
  219. if (FHrSucceeded(hr))
  220. {
  221. pcbSize->HighPart = 0;
  222. pcbSize->LowPart = cbSize;
  223. }
  224. }
  225. COM_PROTECT_CATCH;
  226. return hr;
  227. }
  228. STDMETHODIMP CIPXComponent::InitNew()
  229. {
  230. HRESULT hr = hrOK;
  231. COM_PROTECT_TRY
  232. {
  233. hr = m_ComponentConfig.InitNew();
  234. }
  235. COM_PROTECT_CATCH;
  236. return hr;
  237. }
  238. /////////////////////////////////////////////////////////////////////////////
  239. // CIPXComponentData implementation
  240. CIPXComponentData::CIPXComponentData()
  241. {
  242. }
  243. /*!--------------------------------------------------------------------------
  244. CIPXComponentData::OnInitialize
  245. -
  246. Author: EricDav, KennT
  247. ---------------------------------------------------------------------------*/
  248. STDMETHODIMP CIPXComponentData::OnInitialize(LPIMAGELIST pScopeImage)
  249. {
  250. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  251. Assert(pScopeImage);
  252. // add the images for the scope tree
  253. CBitmap bmp16x16;
  254. HRESULT hr = hrOK;
  255. COM_PROTECT_TRY
  256. {
  257. // Load the bitmaps from the dll
  258. bmp16x16.LoadBitmap(IDB_16x16);
  259. // Set the images
  260. pScopeImage->ImageListSetStrip(
  261. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp16x16)),
  262. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp16x16)),
  263. 0,
  264. RGB(255,0,255));
  265. }
  266. COM_PROTECT_CATCH;
  267. return hr;
  268. }
  269. /*!--------------------------------------------------------------------------
  270. CIPXComponentData::OnInitializeNodeMgr
  271. -
  272. Author: KennT
  273. ---------------------------------------------------------------------------*/
  274. STDMETHODIMP CIPXComponentData::OnInitializeNodeMgr(ITFSComponentData *pTFSCompData, ITFSNodeMgr *pNodeMgr)
  275. {
  276. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  277. // For now create a new node handler for each new node,
  278. // this is rather bogus as it can get expensive. We can
  279. // consider creating only a single node handler for each
  280. // node type.
  281. IPXRootHandler * pHandler = NULL;
  282. SPITFSNodeHandler spHandler;
  283. SPITFSNode spNode;
  284. HRESULT hr = hrOK;
  285. COM_PROTECT_TRY
  286. {
  287. pHandler = new IPXRootHandler(pTFSCompData);
  288. // Do this so that it will get released correctly
  289. spHandler = pHandler;
  290. pHandler->Init();
  291. // Create the root node for this sick puppy
  292. CORg( CreateContainerTFSNode(&spNode,
  293. &GUID_IPXRootNodeType,
  294. pHandler,
  295. pHandler /* result handler */,
  296. pNodeMgr) );
  297. // Construct the node
  298. CORg( pHandler->ConstructNode(spNode) );
  299. CORg( pNodeMgr->SetRootNode(spNode) );
  300. // Reference the help file name.
  301. pTFSCompData->SetHTMLHelpFileName(c_szIPXSnapHelpFile);
  302. COM_PROTECT_ERROR_LABEL;
  303. }
  304. COM_PROTECT_CATCH;
  305. return hr;
  306. }
  307. /*!--------------------------------------------------------------------------
  308. CIPXComponentData::OnCreateComponent
  309. -
  310. Author: EricDav, KennT
  311. ---------------------------------------------------------------------------*/
  312. STDMETHODIMP CIPXComponentData::OnCreateComponent(LPCOMPONENT *ppComponent)
  313. {
  314. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  315. ASSERT(ppComponent != NULL);
  316. HRESULT hr = hrOK;
  317. CIPXComponent * pComp = NULL;
  318. COM_PROTECT_TRY
  319. {
  320. pComp = new CIPXComponent;
  321. if (FHrSucceeded(hr))
  322. {
  323. pComp->Construct(m_spNodeMgr,
  324. static_cast<IComponentData *>(this),
  325. m_spTFSComponentData);
  326. *ppComponent = static_cast<IComponent *>(pComp);
  327. }
  328. }
  329. COM_PROTECT_CATCH;
  330. return hr;
  331. }
  332. STDMETHODIMP CIPXComponentData::OnDestroy()
  333. {
  334. m_spNodeMgr.Release();
  335. return hrOK;
  336. }
  337. /*!--------------------------------------------------------------------------
  338. CIPXComponentData::GetCoClassID
  339. -
  340. Author: KennT
  341. ---------------------------------------------------------------------------*/
  342. STDMETHODIMP_(const CLSID *) CIPXComponentData::GetCoClassID()
  343. {
  344. return &CLSID_IPXAdminExtension;
  345. }
  346. /*!--------------------------------------------------------------------------
  347. CIPXComponentData::OnCreateDataObject
  348. -
  349. Author: KennT
  350. ---------------------------------------------------------------------------*/
  351. STDMETHODIMP CIPXComponentData::OnCreateDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, IDataObject **ppDataObject)
  352. {
  353. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  354. Assert(ppDataObject != NULL);
  355. CDataObject * pObject = NULL;
  356. SPIDataObject spDataObject;
  357. HRESULT hr = hrOK;
  358. SPITFSNode spNode;
  359. SPITFSNodeHandler spHandler;
  360. COM_PROTECT_TRY
  361. {
  362. CORg( m_spNodeMgr->FindNode(cookie, &spNode) );
  363. CORg( spNode->GetHandler(&spHandler) );
  364. CORg( spHandler->OnCreateDataObject(cookie, type, &spDataObject) );
  365. *ppDataObject = spDataObject.Transfer();
  366. COM_PROTECT_ERROR_LABEL;
  367. }
  368. COM_PROTECT_CATCH;
  369. return hr;
  370. }
  371. ///////////////////////////////////////////////////////////////////////////////
  372. //// IPXersistStream interface members
  373. STDMETHODIMP CIPXComponentData::GetClassID
  374. (
  375. CLSID *pClassID
  376. )
  377. {
  378. ASSERT(pClassID != NULL);
  379. // Copy the CLSID for this snapin
  380. *pClassID = CLSID_IPXAdminExtension;
  381. return hrOK;
  382. }
  383. STDMETHODIMP CIPXComponentData::IsDirty()
  384. {
  385. SPITFSNode spNode;
  386. SPITFSNodeHandler spHandler;
  387. SPIPersistStreamInit spStm;
  388. m_spNodeMgr->GetRootNode(&spNode);
  389. spNode->GetHandler(&spHandler);
  390. spStm.Query(spHandler);
  391. Assert(spStm);
  392. return (spNode->GetData(TFS_DATA_DIRTY) || spStm->IsDirty()) ? hrOK : hrFalse;
  393. }
  394. STDMETHODIMP CIPXComponentData::Load
  395. (
  396. IStream *pStm
  397. )
  398. {
  399. SPITFSNode spNode;
  400. SPITFSNodeHandler spHandler;
  401. SPIPersistStreamInit spStm;
  402. m_spNodeMgr->GetRootNode(&spNode);
  403. spNode->GetHandler(&spHandler);
  404. spStm.Query(spHandler);
  405. Assert(spStm);
  406. return spStm->Load(pStm);
  407. }
  408. STDMETHODIMP CIPXComponentData::Save
  409. (
  410. IStream *pStm,
  411. BOOL fClearDirty
  412. )
  413. {
  414. SPITFSNode spNode;
  415. SPITFSNodeHandler spHandler;
  416. SPIPersistStreamInit spStm;
  417. m_spNodeMgr->GetRootNode(&spNode);
  418. spNode->GetHandler(&spHandler);
  419. spStm.Query(spHandler);
  420. Assert(spStm);
  421. return spStm->Save(pStm, fClearDirty);
  422. }
  423. STDMETHODIMP CIPXComponentData::GetSizeMax
  424. (
  425. ULARGE_INTEGER *pcbSize
  426. )
  427. {
  428. SPITFSNode spNode;
  429. SPITFSNodeHandler spHandler;
  430. SPIPersistStreamInit spStm;
  431. m_spNodeMgr->GetRootNode(&spNode);
  432. spNode->GetHandler(&spHandler);
  433. spStm.Query(spHandler);
  434. Assert(spStm);
  435. return spStm->GetSizeMax(pcbSize);
  436. }
  437. STDMETHODIMP CIPXComponentData::InitNew()
  438. {
  439. SPITFSNode spNode;
  440. SPITFSNodeHandler spHandler;
  441. SPIPersistStreamInit spStm;
  442. m_spNodeMgr->GetRootNode(&spNode);
  443. spNode->GetHandler(&spHandler);
  444. spStm.Query(spHandler);
  445. Assert(spStm);
  446. return spStm->InitNew();
  447. }
  448. HRESULT CIPXComponentData::FinalConstruct()
  449. {
  450. HRESULT hr = hrOK;
  451. hr = CComponentData::FinalConstruct();
  452. if (FHrSucceeded(hr))
  453. {
  454. m_spTFSComponentData->GetNodeMgr(&m_spNodeMgr);
  455. }
  456. return hr;
  457. }
  458. void CIPXComponentData::FinalRelease()
  459. {
  460. CComponentData::FinalRelease();
  461. }