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.

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