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.

547 lines
12 KiB

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