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.

429 lines
10 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. acscomp.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. 11/05/97 Wei Jiang Created
  12. */
  13. #include "stdafx.h"
  14. #include "acsadmin.h"
  15. #include "acscomp.h"
  16. #include "acshand.h"
  17. #include "acsdata.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. #define ACSSNAP_HELP_FILE_NAME "acssnap.chm"
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CACSComponent implementation
  26. CACSComponent::CACSComponent()
  27. {
  28. }
  29. CACSComponent::~CACSComponent()
  30. {
  31. }
  32. STDMETHODIMP CACSComponent::OnUpdateView(LPDATAOBJECT pDataObject, LPARAM arg, LPARAM param)
  33. {
  34. return TFSComponent::OnUpdateView(pDataObject, arg, param);
  35. }
  36. STDMETHODIMP CACSComponent::InitializeBitmaps(MMC_COOKIE cookie)
  37. {
  38. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  39. ASSERT(m_spImageList != NULL);
  40. HRESULT hr = hrOK;
  41. COM_PROTECT_TRY
  42. {
  43. CBitmap bmp16x16;
  44. CBitmap bmp32x32;
  45. // Load the bitmaps from the dll
  46. bmp16x16.LoadBitmap(IDB_16X16);
  47. bmp32x32.LoadBitmap(IDB_32X32);
  48. // Set the images
  49. m_spImageList->ImageListSetStrip(
  50. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp16x16)),
  51. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp32x32)),
  52. 0, RGB(255,0,255));
  53. }
  54. COM_PROTECT_CATCH;
  55. return hr;
  56. }
  57. /*!--------------------------------------------------------------------------
  58. CACSComponent::OnSnapinHelp
  59. -
  60. ---------------------------------------------------------------------------*/
  61. STDMETHODIMP
  62. CACSComponent::OnSnapinHelp
  63. (
  64. LPDATAOBJECT pDataObject,
  65. long arg,
  66. long param
  67. )
  68. {
  69. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  70. HRESULT hr = hrOK;
  71. // theApp.WinHelp(DHCPSNAP_HELP_SNAPIN, HELP_CONTEXT);
  72. HtmlHelpA(NULL, "acssnap.chm", HH_DISPLAY_TOPIC, 0);
  73. return hr;
  74. }
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CACSComponentData implementation
  77. CACSComponentData::CACSComponentData()
  78. {
  79. }
  80. void CACSComponentData::GetConsoleData()
  81. {
  82. // Init console data
  83. ZeroMemory(&m_ConsoleData, sizeof(CACSConsoleData));
  84. m_ConsoleData.ulSize = sizeof(CACSConsoleData);
  85. m_ConsoleData.ulVersion = ACS_CONSOLE_VERSION;
  86. m_ConsoleData.ulMaxCol = ACS_CONSOLE_MAX_COL;
  87. memcpy(m_ConsoleData.ulPolicyColWidth, g_col_width_policy, g_col_count_policy);
  88. memcpy(m_ConsoleData.ulSubnetColWidth, g_col_width_subnet, g_col_count_subnet);
  89. }
  90. void CACSComponentData::SetConsoleData()
  91. {
  92. // Init console data
  93. memcpy(g_col_width_policy, m_ConsoleData.ulPolicyColWidth, g_col_count_policy);
  94. memcpy(g_col_width_subnet, m_ConsoleData.ulSubnetColWidth, g_col_count_subnet);
  95. }
  96. /*!--------------------------------------------------------------------------
  97. CACSComponentData::OnInitialize
  98. -
  99. Author: EricDav, KennT
  100. ---------------------------------------------------------------------------*/
  101. STDMETHODIMP CACSComponentData::OnInitialize(LPIMAGELIST pScopeImage)
  102. {
  103. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  104. ASSERT(pScopeImage);
  105. HRESULT hr = hrOK;
  106. COM_PROTECT_TRY
  107. {
  108. // add the images for the scope tree
  109. CBitmap bmp16x16;
  110. // Load the bitmaps from the dll
  111. bmp16x16.LoadBitmap(IDB_16X16);
  112. // Set the images
  113. pScopeImage->ImageListSetStrip(
  114. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp16x16)),
  115. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp16x16)),
  116. 0,
  117. RGB(255,0,255));
  118. }
  119. COM_PROTECT_CATCH;
  120. return hr;
  121. }
  122. /*!--------------------------------------------------------------------------
  123. CACSComponentData::OnInitializeNodeMgr
  124. -
  125. Author: KennT
  126. ---------------------------------------------------------------------------*/
  127. STDMETHODIMP CACSComponentData::OnInitializeNodeMgr(ITFSComponentData *pTFSCompData, ITFSNodeMgr *pNodeMgr)
  128. {
  129. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  130. // For now create a new node handler for each new node,
  131. // this is rather bogus as it can get expensive. We can
  132. // consider creating only a single node handler for each
  133. // node type.
  134. CACSRootHandle* pHandler = NULL;
  135. SPITFSNodeHandler spHandler;
  136. SPITFSNode spNode;
  137. HRESULT hr = hrOK;
  138. COM_PROTECT_TRY
  139. {
  140. pHandler = new CACSRootHandle(pTFSCompData, NULL);
  141. // Do this so that it will get released correctly
  142. spHandler = pHandler;
  143. // Create the root node for this sick puppy
  144. CHECK_HR( hr = CreateContainerTFSNode(&spNode,
  145. &CLSID_ACSRootNode,
  146. pHandler,
  147. pHandler /* result handler */,
  148. pNodeMgr) );
  149. // Need to initialize the data for the root node
  150. spNode->SetData(TFS_DATA_IMAGEINDEX, pHandler->m_ulIconIndex);
  151. spNode->SetData(TFS_DATA_OPENIMAGEINDEX, pHandler->m_ulIconIndexOpen);
  152. spNode->SetData(TFS_DATA_SCOPEID, 0);
  153. pTFSCompData->SetHTMLHelpFileName(_T(ACSSNAP_HELP_FILE_NAME));
  154. CHECK_HR(hr = pNodeMgr->SetRootNode(spNode) );
  155. // in general do
  156. // spNode->SetData(TFS_DATA_COOKIE, (DWORD)(ITFSNode *)spNode);
  157. spNode->SetData(TFS_DATA_COOKIE, 0);
  158. }
  159. COM_PROTECT_CATCH;
  160. L_ERR:
  161. if FAILED(hr)
  162. ReportError(hr, IDS_ERR_ROOTNODE, NULL);
  163. return S_OK;
  164. }
  165. /*!--------------------------------------------------------------------------
  166. CACSComponentData::OnCreateComponent
  167. -
  168. Author: EricDav, KennT
  169. ---------------------------------------------------------------------------*/
  170. STDMETHODIMP CACSComponentData::OnCreateComponent(LPCOMPONENT *ppComponent)
  171. {
  172. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  173. ASSERT(ppComponent != NULL);
  174. HRESULT hr = hrOK;
  175. CACSComponent * pComp = NULL;
  176. COM_PROTECT_TRY
  177. {
  178. pComp = new CACSComponent;
  179. if (FHrSucceeded(hr))
  180. {
  181. pComp->Construct(m_spNodeMgr,
  182. static_cast<IComponentData *>(this),
  183. m_spTFSComponentData);
  184. *ppComponent = static_cast<IComponent *>(pComp);
  185. }
  186. }
  187. COM_PROTECT_CATCH;
  188. if FAILED(hr)
  189. ReportError(hr, IDS_ERR_COMPONENT, NULL);
  190. return hr;
  191. }
  192. STDMETHODIMP CACSComponentData::OnDestroy()
  193. {
  194. m_spNodeMgr.Release();
  195. return hrOK;
  196. }
  197. /*!--------------------------------------------------------------------------
  198. CACSComponentData::GetCoClassID
  199. -
  200. Author: KennT
  201. ---------------------------------------------------------------------------*/
  202. STDMETHODIMP_(const CLSID *) CACSComponentData::GetCoClassID()
  203. {
  204. return &CLSID_ACSSnap;
  205. }
  206. /*!--------------------------------------------------------------------------
  207. CACSComponentData::OnCreateDataObject
  208. -
  209. Author: KennT
  210. ---------------------------------------------------------------------------*/
  211. STDMETHODIMP CACSComponentData::OnCreateDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, IDataObject **ppDataObject)
  212. {
  213. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  214. ASSERT(ppDataObject != NULL);
  215. CDSIDataObject * pObject = NULL;
  216. CComPtr<CDSIDataObject> spDataObject;
  217. pObject = new CDSIDataObject;
  218. spDataObject = pObject; // do this so that it gets released correctly
  219. if(pObject)
  220. pObject->Release();
  221. ASSERT(pObject != NULL);
  222. // Save cookie and type for delayed rendering
  223. pObject->SetType(type);
  224. pObject->SetCookie(cookie);
  225. // Store the coclass with the data object
  226. pObject->SetClsid(*GetCoClassID());
  227. pObject->SetTFSComponentData(m_spTFSComponentData);
  228. return pObject->QueryInterface(IID_IDataObject,
  229. reinterpret_cast<void**>(ppDataObject));
  230. }
  231. ///////////////////////////////////////////////////////////////////////////////
  232. //// IPersistStream interface members
  233. STDMETHODIMP CACSComponentData::GetClassID
  234. (
  235. CLSID *pClassID
  236. )
  237. {
  238. ASSERT(pClassID != NULL);
  239. // Copy the CLSID for this snapin
  240. *pClassID = CLSID_ACSSnap;
  241. return hrOK;
  242. }
  243. STDMETHODIMP CACSComponentData::IsDirty()
  244. {
  245. SPITFSNode spNode;
  246. m_spNodeMgr->GetRootNode(&spNode);
  247. return spNode->GetData(TFS_DATA_DIRTY) ? hrOK : hrFalse;
  248. }
  249. STDMETHODIMP CACSComponentData::Load
  250. (
  251. IStream *pStm
  252. )
  253. {
  254. HRESULT hr = S_OK;
  255. ULONG ulDataSize;
  256. CACSConsoleData Data;
  257. ASSERT(pStm);
  258. // Console Data
  259. hr = pStm->Read(&Data, sizeof(CACSConsoleData), &ulDataSize);
  260. if (SUCCEEDED(hr))
  261. {
  262. if(ulDataSize == sizeof(CACSConsoleData) && Data.ulSize == sizeof(CACSConsoleData)
  263. && Data.ulVersion == ACS_CONSOLE_VERSION && Data.ulMaxCol == ACS_CONSOLE_MAX_COL)
  264. {
  265. memcpy(&m_ConsoleData, &Data, sizeof(m_ConsoleData));
  266. SetConsoleData();
  267. }
  268. }
  269. return SUCCEEDED(hr) ? S_OK : E_FAIL;
  270. }
  271. STDMETHODIMP CACSComponentData::Save
  272. (
  273. IStream *pStm,
  274. BOOL fClearDirty
  275. )
  276. {
  277. HRESULT hr = S_OK;
  278. SPITFSNode spNode;
  279. ULONG ulDataSize;
  280. ASSERT(pStm);
  281. // Console Data
  282. GetConsoleData();
  283. hr = pStm->Write(&m_ConsoleData, sizeof(CACSConsoleData), &ulDataSize);
  284. if (SUCCEEDED(hr) && fClearDirty)
  285. {
  286. m_spNodeMgr->GetRootNode(&spNode);
  287. spNode->SetData(TFS_DATA_DIRTY, FALSE);
  288. }
  289. return SUCCEEDED(hr) ? S_OK : STG_E_CANTSAVE;
  290. }
  291. STDMETHODIMP CACSComponentData::GetSizeMax
  292. (
  293. ULARGE_INTEGER *pcbSize
  294. )
  295. {
  296. ASSERT(pcbSize);
  297. // Set the size of the string to be saved
  298. ULISet32(*pcbSize, 500);
  299. return S_OK;
  300. }
  301. STDMETHODIMP CACSComponentData::InitNew()
  302. {
  303. return hrOK;
  304. }
  305. HRESULT CACSComponentData::FinalConstruct()
  306. {
  307. HRESULT hr = hrOK;
  308. hr = CComponentData::FinalConstruct();
  309. if (FHrSucceeded(hr))
  310. {
  311. m_spTFSComponentData->GetNodeMgr(&m_spNodeMgr);
  312. }
  313. return hr;
  314. }
  315. void CACSComponentData::FinalRelease()
  316. {
  317. CComponentData::FinalRelease();
  318. }
  319. STDMETHODIMP CACSComponentData::OnNotifyPropertyChange( LPDATAOBJECT lpDataObject, // pointer to a data object
  320. MMC_NOTIFY_TYPE event, // action taken by a user
  321. LPARAM arg, // depends on event
  322. LPARAM param // depends on event
  323. )
  324. {
  325. return CACSHandle::NotifyDataChange(param);
  326. }
  327. HRESULT CACSComponent::OnNotifyPropertyChange( LPDATAOBJECT lpDataObject, // pointer to a data object
  328. MMC_NOTIFY_TYPE event, // action taken by a user
  329. LPARAM arg, // depends on event
  330. LPARAM param // depends on event
  331. )
  332. {
  333. return CACSHandle::NotifyDataChange(param);
  334. }