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.

1519 lines
44 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation
  4. Module Name:
  5. PolicyNode.cpp
  6. Abstract:
  7. Implementation file for the CPolicyNode class.
  8. Revision History:
  9. mmaguire 12/15/97 - created
  10. --*/
  11. //////////////////////////////////////////////////////////////////////
  12. //////////////////////////////////////////////////////////////////////////////
  13. // BEGIN INCLUDES
  14. //
  15. // standard includes:
  16. //
  17. #include "Precompiled.h"
  18. //
  19. // where we can find declaration for main class in this file:
  20. //
  21. #include "PolicyNode.h"
  22. #include "Component.h"
  23. #include "SnapinNode.cpp" // Template implementation
  24. //
  25. //
  26. // where we can find declarations needed in this file:
  27. //
  28. #include "PoliciesNode.h"
  29. #include "PolicyPage1.h"
  30. #include "rapwz_name.h"
  31. #include "rapwz_cond.h"
  32. #include "rapwz_allow.h"
  33. #include "rapwz_profile.h"
  34. #include "NapUtil.h"
  35. #include "ChangeNotification.h"
  36. #include "rapwiz.h"
  37. //
  38. // END INCLUDES
  39. //////////////////////////////////////////////////////////////////////////////
  40. //////////////////////////////////////////////////////////////////////////////
  41. /*++
  42. CPolicyNode::CPolicyNode
  43. Constructor
  44. --*/
  45. //////////////////////////////////////////////////////////////////////////////
  46. CPolicyNode::CPolicyNode( CSnapInItem * pParentNode,
  47. LPTSTR pszServerAddress,
  48. CIASAttrList* pAttrList,
  49. BOOL fBrandNewNode,
  50. BOOL fUseActiveDirectory,
  51. bool isWin2k
  52. )
  53. :CSnapinNode<CPolicyNode, CComponentData, CComponent>( pParentNode ),
  54. m_isWin2k(isWin2k)
  55. {
  56. TRACE_FUNCTION("CPolicyNode::CPolicyNode");
  57. _ASSERTE( pAttrList != NULL );
  58. // For the help files
  59. m_helpIndex = (!((CPoliciesNode *)m_pParentNode )->m_fExtendingIAS)?RAS_HELP_INDEX:0;
  60. // Here we store an index to which of these images we
  61. // want to be used to display this node
  62. m_scopeDataItem.nImage = IDBI_NODE_POLICY;
  63. //
  64. // initialize the merit value. This value will be set when the node is added
  65. // to a MeritNodeArray.
  66. // This is handled in call back API: SetMerit()
  67. //
  68. m_nMeritValue = 0;
  69. // initialize the machine name
  70. m_pszServerAddress = pszServerAddress;
  71. // no property page when initialized
  72. m_pPolicyPage1 = NULL ;
  73. //
  74. // initialize the condition attribute list
  75. //
  76. m_pAttrList = pAttrList;
  77. // yes, it is a new node
  78. m_fBrandNewNode = fBrandNewNode;
  79. // are we using active directory
  80. m_fUseActiveDirectory = fUseActiveDirectory;
  81. //
  82. // get the location for the policy
  83. //
  84. TCHAR tszLocationStr[IAS_MAX_STRING];
  85. HINSTANCE hInstance = _Module.GetResourceInstance();
  86. if ( m_fUseActiveDirectory)
  87. {
  88. // active directory
  89. int iRes = LoadString(hInstance,
  90. IDS_POLICY_LOCATION_ACTIVEDS,
  91. tszLocationStr,
  92. IAS_MAX_STRING
  93. );
  94. _ASSERT( iRes > 0 );
  95. }
  96. else
  97. {
  98. // local or remote machine
  99. if (m_pszServerAddress && _tcslen(m_pszServerAddress)>0)
  100. {
  101. _tcscpy(tszLocationStr, m_pszServerAddress);
  102. }
  103. else
  104. {
  105. // local machine
  106. int iRes = LoadString(hInstance,
  107. IDS_POLICY_LOCATION_LOCAL,
  108. tszLocationStr,
  109. IAS_MAX_STRING
  110. );
  111. _ASSERT( iRes > 0 );
  112. if ( !tszLocationStr )
  113. {
  114. // resource has been corrupted -- we hard code it then.
  115. // this way we will guarantee tzLocationStr won't be NULL.
  116. _tcscpy(tszLocationStr, _T("Local Machine"));
  117. }
  118. }
  119. }
  120. m_ptzLocation = new TCHAR[_tcslen(tszLocationStr)+1];
  121. if ( m_ptzLocation )
  122. {
  123. _tcscpy(m_ptzLocation, tszLocationStr);
  124. }
  125. // to remember the object, so can use used within UPdateToolbarBotton
  126. m_pControBarNotifySnapinObj = NULL;
  127. }
  128. //////////////////////////////////////////////////////////////////////////////
  129. /*++
  130. CPolicyNode::~CPolicyNode
  131. Destructor
  132. --*/
  133. //////////////////////////////////////////////////////////////////////////////
  134. CPolicyNode::~CPolicyNode()
  135. {
  136. TRACE_FUNCTION("CPolicyNode::~CPolicyNode");
  137. if ( m_ptzLocation )
  138. {
  139. delete[] m_ptzLocation;
  140. }
  141. }
  142. //////////////////////////////////////////////////////////////////////////////
  143. /*++
  144. CPolicyNode::CreatePropertyPages
  145. See CSnapinNode::CreatePropertyPages (which this method overrides) for detailed info.
  146. --*/
  147. //////////////////////////////////////////////////////////////////////////////
  148. STDMETHODIMP CPolicyNode::CreatePropertyPages (
  149. LPPROPERTYSHEETCALLBACK pPropertySheetCallback
  150. , LONG_PTR hNotificationHandle
  151. , IUnknown* pUnk
  152. , DATA_OBJECT_TYPES type
  153. )
  154. {
  155. TRACE_FUNCTION("CPolicyNode::CreatePropertyPages");
  156. HRESULT hr = S_OK;
  157. #ifndef NO_ADD_POLICY_WIZARD
  158. if( IsBrandNew() )
  159. {
  160. // We are adding a new policy -- use the wizard pages.
  161. // four old pages
  162. CNewRAPWiz_Name * pNewRAPWiz_Name = NULL;
  163. CNewRAPWiz_Condition * pNewRAPWiz_Condition = NULL;
  164. CNewRAPWiz_AllowDeny * pNewRAPWiz_AllowDeny = NULL;
  165. CNewRAPWiz_EditProfile * pNewRAPWiz_EditProfile = NULL;
  166. // four new pages
  167. CPolicyWizard_Start* pNewRAPWiz_Start = NULL;
  168. CPolicyWizard_Scenarios* pNewRAPWiz_Scenarios = NULL;
  169. CPolicyWizard_Groups* pNewRAPWiz_Group = NULL;
  170. CPolicyWizard_Authentication* pNewRAPWiz_Authentication = NULL;
  171. CPolicyWizard_Encryption* pNewRAPWiz_Encryption = NULL;
  172. CPolicyWizard_Encryption_VPN* pNewRAPWiz_Encryption_VPN = NULL;
  173. CPolicyWizard_Encryption_Wireless* pNewRAPWiz_Encryption_Wireless = NULL;
  174. CPolicyWizard_EAP* pNewRAPWiz_EAP = NULL;
  175. CPolicyWizard_Finish* pNewRAPWiz_Finish = NULL;
  176. try
  177. {
  178. TCHAR lpszTabName[IAS_MAX_STRING];
  179. int nLoadStringResult;
  180. //===================================
  181. //
  182. // new pages wizard pages
  183. //
  184. // wizard data object
  185. CComPtr<CRapWizardData> spRapWizData;
  186. CComObject<CRapWizardData>* pRapWizData;
  187. CComObject<CRapWizardData>::CreateInstance(&pRapWizData);
  188. spRapWizData = pRapWizData;
  189. // set context information
  190. spRapWizData->SetInfo(m_pszServerAddress, this, m_spDictionarySdo, m_spPolicySdo, m_spProfileSdo, m_spPoliciesCollectionSdo, m_spProfilesCollectionSdo, m_spSdoServiceControl, m_pAttrList);
  191. //
  192. // Create each of the four old wizard pages.
  193. nLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_ADD_POLICY_WIZ_TAB_NAME, lpszTabName, IAS_MAX_STRING );
  194. _ASSERT( nLoadStringResult > 0 );
  195. // scenario page
  196. pNewRAPWiz_Start = new CPolicyWizard_Start(spRapWizData, hNotificationHandle, lpszTabName);
  197. // scenario page
  198. pNewRAPWiz_Scenarios = new CPolicyWizard_Scenarios(spRapWizData, hNotificationHandle, lpszTabName);
  199. // group page
  200. pNewRAPWiz_Group = new CPolicyWizard_Groups(spRapWizData, hNotificationHandle, lpszTabName);
  201. // authen page
  202. pNewRAPWiz_Authentication = new CPolicyWizard_Authentication(spRapWizData, hNotificationHandle, lpszTabName);
  203. // encryption page
  204. pNewRAPWiz_Encryption = new CPolicyWizard_Encryption(spRapWizData, hNotificationHandle, lpszTabName);
  205. pNewRAPWiz_Encryption_VPN = new CPolicyWizard_Encryption_VPN(spRapWizData, hNotificationHandle, lpszTabName);
  206. pNewRAPWiz_Encryption_Wireless = new CPolicyWizard_Encryption_Wireless(spRapWizData, hNotificationHandle, lpszTabName);
  207. // EAP page
  208. pNewRAPWiz_EAP = new CPolicyWizard_EAP(spRapWizData, hNotificationHandle, lpszTabName);
  209. // finish page
  210. pNewRAPWiz_Finish = new CPolicyWizard_Finish(spRapWizData, hNotificationHandle, lpszTabName);
  211. // These pages will take care of deleting themselves when they
  212. // receive the PSPCB_RELEASE message.
  213. // We specify TRUE for the bOwnsNotificationHandle parameter in one of the pages
  214. // so that this page's destructor will be responsible for freeing the
  215. // notification handle. Only one page per sheet should do this.
  216. pNewRAPWiz_Name = new CNewRAPWiz_Name(spRapWizData, hNotificationHandle, lpszTabName, TRUE );
  217. if( ! pNewRAPWiz_Name ) throw E_OUTOFMEMORY;
  218. pNewRAPWiz_Condition = new CNewRAPWiz_Condition(spRapWizData, hNotificationHandle, m_pAttrList, lpszTabName );
  219. if( ! pNewRAPWiz_Condition) throw E_OUTOFMEMORY;
  220. pNewRAPWiz_AllowDeny = new CNewRAPWiz_AllowDeny(spRapWizData, hNotificationHandle, lpszTabName );
  221. if( ! pNewRAPWiz_AllowDeny ) throw E_OUTOFMEMORY;
  222. pNewRAPWiz_EditProfile = new CNewRAPWiz_EditProfile(
  223. spRapWizData,
  224. hNotificationHandle,
  225. m_pAttrList,
  226. lpszTabName,
  227. m_isWin2k
  228. );
  229. if( ! pNewRAPWiz_EditProfile ) throw E_OUTOFMEMORY;
  230. // Marshall pointers to pNewRAPWiz_Name
  231. // Pass the pages our SDO's. These don't need to be marshalled
  232. // as wizard pages run in the same thread.
  233. // Add each of the pages to the MMC property sheet.
  234. hr = pPropertySheetCallback->AddPage( pNewRAPWiz_Start->Create() );
  235. if( FAILED(hr) ) throw hr;
  236. hr = pPropertySheetCallback->AddPage( pNewRAPWiz_Name->Create() );
  237. if( FAILED(hr) ) throw hr;
  238. hr = pPropertySheetCallback->AddPage( pNewRAPWiz_Scenarios->Create() );
  239. if( FAILED(hr) ) throw hr;
  240. hr = pPropertySheetCallback->AddPage( pNewRAPWiz_Group->Create() );
  241. if( FAILED(hr) ) throw hr;
  242. hr = pPropertySheetCallback->AddPage( pNewRAPWiz_Authentication->Create() );
  243. if( FAILED(hr) ) throw hr;
  244. hr = pPropertySheetCallback->AddPage( pNewRAPWiz_Encryption->Create() );
  245. if( FAILED(hr) ) throw hr;
  246. hr = pPropertySheetCallback->AddPage( pNewRAPWiz_Encryption_VPN->Create() );
  247. if( FAILED(hr) ) throw hr;
  248. hr = pPropertySheetCallback->AddPage( pNewRAPWiz_Encryption_Wireless->Create() );
  249. if( FAILED(hr) ) throw hr;
  250. hr = pPropertySheetCallback->AddPage( pNewRAPWiz_EAP->Create() );
  251. if( FAILED(hr) ) throw hr;
  252. hr = pPropertySheetCallback->AddPage( pNewRAPWiz_Condition->Create() );
  253. if( FAILED(hr) ) throw hr;
  254. hr = pPropertySheetCallback->AddPage( pNewRAPWiz_AllowDeny->Create() );
  255. if( FAILED(hr) ) throw hr;
  256. hr = pPropertySheetCallback->AddPage( pNewRAPWiz_EditProfile->Create() );
  257. if( FAILED(hr) ) throw hr;
  258. hr = pPropertySheetCallback->AddPage( pNewRAPWiz_Finish->Create() );
  259. if( FAILED(hr) ) throw hr;
  260. // This node is no longer new.
  261. SetBrandNew(FALSE);
  262. }
  263. catch(...)
  264. {
  265. // Delete whatever was successfully allocated.
  266. delete pNewRAPWiz_Name;
  267. delete pNewRAPWiz_Condition;
  268. delete pNewRAPWiz_AllowDeny;
  269. delete pNewRAPWiz_EditProfile;
  270. delete pNewRAPWiz_Scenarios;
  271. delete pNewRAPWiz_Authentication;
  272. delete pNewRAPWiz_Encryption;
  273. delete pNewRAPWiz_Encryption_VPN;
  274. delete pNewRAPWiz_Encryption_Wireless;
  275. delete pNewRAPWiz_EAP;
  276. delete pNewRAPWiz_Finish;
  277. ShowErrorDialog( NULL, IDS_ERROR_CANT_CREATE_OBJECT, NULL, hr, USE_DEFAULT, GetComponentData()->m_spConsole );
  278. return E_OUTOFMEMORY;
  279. }
  280. }
  281. else
  282. {
  283. // We are editing an existing policy -- use the property sheet.
  284. // This page will take care of deleting itself when it
  285. // receives the PSPCB_RELEASE message.
  286. //
  287. TCHAR tszTabName[IAS_MAX_STRING];
  288. HINSTANCE hInstance = _Module.GetResourceInstance();
  289. // load tab name, currently "Settings"
  290. int iRes = LoadString(hInstance,
  291. IDS_POLICY_PROPERTY_PAGE_TABNAME,
  292. tszTabName,
  293. IAS_MAX_STRING
  294. );
  295. if ( iRes <= 0 )
  296. {
  297. _tcscpy(tszTabName, _T("Settings"));
  298. }
  299. m_pPolicyPage1 = new CPolicyPage1(
  300. hNotificationHandle,
  301. this,
  302. m_pAttrList,
  303. tszTabName,
  304. TRUE,
  305. m_isWin2k
  306. );
  307. if( NULL == m_pPolicyPage1 )
  308. {
  309. hr = HRESULT_FROM_WIN32(GetLastError());
  310. ErrorTrace(ERROR_NAPMMC_POLICYNODE, ("Can't create property pages, err = %x"), hr);
  311. goto failure;
  312. }
  313. //
  314. // marshall the Policy Sdo pointer
  315. //
  316. hr = CoMarshalInterThreadInterfaceInStream(
  317. IID_ISdo //Reference to the identifier of the interface
  318. , m_spPolicySdo //Pointer to the interface to be marshaled
  319. , &( m_pPolicyPage1->m_pStreamPolicySdoMarshall ) //Address of output variable that receives the IStream interface pointer for the marshaled interface
  320. );
  321. if ( FAILED(hr) )
  322. {
  323. ShowErrorDialog( NULL, IDS_ERROR_MARSHALL, NULL, hr, USE_DEFAULT, GetComponentData()->m_spConsole );
  324. goto failure;
  325. }
  326. //
  327. // marshall the Dictionary Sdo pointer
  328. //
  329. hr = CoMarshalInterThreadInterfaceInStream(
  330. IID_ISdoDictionaryOld
  331. , m_spDictionarySdo
  332. , &( m_pPolicyPage1->m_pStreamDictionarySdoMarshall )
  333. );
  334. if ( FAILED(hr) )
  335. {
  336. ShowErrorDialog( NULL, IDS_ERROR_MARSHALL, NULL, hr, USE_DEFAULT, GetComponentData()->m_spConsole );
  337. goto failure;
  338. }
  339. //
  340. // marshall the Profile Sdo pointer
  341. //
  342. hr = CoMarshalInterThreadInterfaceInStream(
  343. IID_ISdo
  344. , m_spProfileSdo
  345. , &( m_pPolicyPage1->m_pStreamProfileSdoMarshall )
  346. );
  347. if ( FAILED(hr) )
  348. {
  349. ShowErrorDialog( NULL, IDS_ERROR_MARSHALL, NULL, hr, USE_DEFAULT, GetComponentData()->m_spConsole );
  350. goto failure;
  351. }
  352. //
  353. // marshall the Profile collection Sdo pointer
  354. //
  355. hr = CoMarshalInterThreadInterfaceInStream(
  356. IID_ISdoCollection
  357. , m_spProfilesCollectionSdo
  358. , &( m_pPolicyPage1->m_pStreamProfilesCollectionSdoMarshall )
  359. );
  360. if ( FAILED(hr) )
  361. {
  362. ShowErrorDialog( NULL, IDS_ERROR_MARSHALL, NULL, hr, USE_DEFAULT, GetComponentData()->m_spConsole );
  363. goto failure;
  364. }
  365. //
  366. // marshall the Policy collection Sdo pointer
  367. //
  368. hr = CoMarshalInterThreadInterfaceInStream(
  369. IID_ISdoCollection
  370. , m_spPoliciesCollectionSdo
  371. , &( m_pPolicyPage1->m_pStreamPoliciesCollectionSdoMarshall )
  372. );
  373. if ( FAILED(hr) )
  374. {
  375. ShowErrorDialog( NULL, IDS_ERROR_MARSHALL, NULL, hr, USE_DEFAULT, GetComponentData()->m_spConsole );
  376. goto failure;
  377. }
  378. // Marshall the Service Control Sdo pointer.
  379. hr = CoMarshalInterThreadInterfaceInStream(
  380. IID_ISdoServiceControl
  381. , m_spSdoServiceControl
  382. , &( m_pPolicyPage1->m_pStreamSdoServiceControlMarshall )
  383. );
  384. if ( FAILED(hr) )
  385. {
  386. ShowErrorDialog( NULL, IDS_ERROR_MARSHALL, NULL, hr, USE_DEFAULT, GetComponentData()->m_spConsole );
  387. goto failure;
  388. }
  389. // add the property pages
  390. hr = pPropertySheetCallback->AddPage(m_pPolicyPage1->Create());
  391. _ASSERT( SUCCEEDED( hr ) );
  392. return hr;
  393. failure:
  394. if (m_pPolicyPage1)
  395. {
  396. delete m_pPolicyPage1;
  397. m_pPolicyPage1 = NULL;
  398. }
  399. return hr;
  400. }
  401. return hr;
  402. #else // NO_ADD_POLICY_WIZARD
  403. // This page will take care of deleting itself when it
  404. // receives the PSPCB_RELEASE message.
  405. //
  406. TCHAR tszTabName[IAS_MAX_STRING];
  407. HINSTANCE hInstance = _Module.GetResourceInstance();
  408. // load tab name, currently "Settings"
  409. int iRes = LoadString(hInstance,
  410. IDS_POLICY_PROPERTY_PAGE_TABNAME,
  411. tszTabName,
  412. IAS_MAX_STRING
  413. );
  414. if ( iRes <= 0 )
  415. {
  416. _tcscpy(tszTabName, _T("Settings"));
  417. }
  418. m_pPolicyPage1 = new CPolicyPage1(
  419. hNotificationHandle,
  420. this,
  421. m_pAttrList,
  422. tszTabName,
  423. TRUE,
  424. m_isWin2k
  425. );
  426. if( NULL == m_pPolicyPage1 )
  427. {
  428. hr = HRESULT_FROM_WIN32(GetLastError());
  429. ErrorTrace(ERROR_NAPMMC_POLICYNODE, ("Can't create property pages, err = %x"), hr);
  430. goto failure;
  431. }
  432. //
  433. // marshall the Policy Sdo pointer
  434. //
  435. hr = CoMarshalInterThreadInterfaceInStream(
  436. IID_ISdo //Reference to the identifier of the interface
  437. , m_spPolicySdo //Pointer to the interface to be marshaled
  438. , &( m_pPolicyPage1->m_pStreamPolicySdoMarshall ) //Address of output variable that receives the IStream interface pointer for the marshaled interface
  439. );
  440. if ( FAILED(hr) )
  441. {
  442. ShowErrorDialog( NULL, IDS_ERROR_MARSHALL, NULL, hr, USE_DEFAULT, GetComponentData()->m_spConsole );
  443. goto failure;
  444. }
  445. //
  446. // marshall the Dictionary Sdo pointer
  447. //
  448. hr = CoMarshalInterThreadInterfaceInStream(
  449. IID_ISdoDictionaryOld
  450. , m_spDictionarySdo
  451. , &( m_pPolicyPage1->m_pStreamDictionarySdoMarshall )
  452. );
  453. if ( FAILED(hr) )
  454. {
  455. ShowErrorDialog( NULL, IDS_ERROR_MARSHALL, NULL, hr, USE_DEFAULT, GetComponentData()->m_spConsole );
  456. goto failure;
  457. }
  458. //
  459. // marshall the Profile Sdo pointer
  460. //
  461. hr = CoMarshalInterThreadInterfaceInStream(
  462. IID_ISdo
  463. , m_spProfileSdo
  464. , &( m_pPolicyPage1->m_pStreamProfileSdoMarshall )
  465. );
  466. if ( FAILED(hr) )
  467. {
  468. ShowErrorDialog( NULL, IDS_ERROR_MARSHALL, NULL, hr, USE_DEFAULT, GetComponentData()->m_spConsole );
  469. goto failure;
  470. }
  471. //
  472. // marshall the Profile collection Sdo pointer
  473. //
  474. hr = CoMarshalInterThreadInterfaceInStream(
  475. IID_ISdoCollection
  476. , m_spProfilesCollectionSdo
  477. , &( m_pPolicyPage1->m_pStreamProfilesCollectionSdoMarshall )
  478. );
  479. if ( FAILED(hr) )
  480. {
  481. ShowErrorDialog( NULL, IDS_ERROR_MARSHALL, NULL, hr, USE_DEFAULT, GetComponentData()->m_spConsole );
  482. goto failure;
  483. }
  484. //
  485. // marshall the Policy collection Sdo pointer
  486. //
  487. hr = CoMarshalInterThreadInterfaceInStream(
  488. IID_ISdoCollection
  489. , m_spPoliciesCollectionSdo
  490. , &( m_pPolicyPage1->m_pStreamPoliciesCollectionSdoMarshall )
  491. );
  492. if ( FAILED(hr) )
  493. {
  494. ShowErrorDialog( NULL, IDS_ERROR_MARSHALL, NULL, hr, USE_DEFAULT, GetComponentData()->m_spConsole );
  495. goto failure;
  496. }
  497. // add the property pages
  498. hr = pPropertySheetCallback->AddPage(m_pPolicyPage1->Create());
  499. _ASSERT( SUCCEEDED( hr ) );
  500. return hr;
  501. failure:
  502. if (m_pPolicyPage1)
  503. {
  504. delete m_pPolicyPage1;
  505. m_pPolicyPage1 = NULL;
  506. }
  507. return hr;
  508. #endif // NO_ADD_POLICY_WIZARD
  509. }
  510. //////////////////////////////////////////////////////////////////////////////
  511. /*++
  512. CPolicyNode::QueryPagesFor
  513. See CSnapinNode::QueryPagesFor (which this method overrides) for detailed info.
  514. --*/
  515. //////////////////////////////////////////////////////////////////////////////
  516. STDMETHODIMP CPolicyNode::QueryPagesFor ( DATA_OBJECT_TYPES type )
  517. {
  518. TRACE_FUNCTION("CPolicyNode::QueryPagesFor");
  519. // S_OK means we have pages to display
  520. return S_OK;
  521. }
  522. //////////////////////////////////////////////////////////////////////////////
  523. /*++
  524. CPolicyNode::GetResultPaneColInfo
  525. See CSnapinNode::GetResultPaneColInfo (which this method overrides) for detailed info.
  526. --*/
  527. //////////////////////////////////////////////////////////////////////////////
  528. OLECHAR* CPolicyNode::GetResultPaneColInfo(int nCol)
  529. {
  530. TRACE_FUNCTION("CPolicyNode::GetResultPaneColInfo");
  531. if (nCol == 0 && m_bstrDisplayName != NULL)
  532. return m_bstrDisplayName;
  533. switch( nCol )
  534. {
  535. case 0:
  536. return m_bstrDisplayName;
  537. break;
  538. case 1:
  539. // display the merit value for this policy node
  540. wsprintf(m_tszMeritString, L"%d", m_nMeritValue);
  541. return m_tszMeritString;
  542. break;
  543. case 2: return m_ptzLocation;
  544. break;
  545. default:
  546. // ISSUE: error -- should we assert here?
  547. return L"@Invalid column";
  548. }
  549. }
  550. //////////////////////////////////////////////////////////////////////////////
  551. /*++
  552. CPolicyNode::OnRename
  553. See CSnapinNode::OnRename (which this method overrides) for detailed info.
  554. --*/
  555. //////////////////////////////////////////////////////////////////////////////
  556. HRESULT CPolicyNode::OnRename(
  557. LPARAM arg
  558. , LPARAM param
  559. , IComponentData * pComponentData
  560. , IComponent * pComponent
  561. , DATA_OBJECT_TYPES type
  562. )
  563. {
  564. TRACE_FUNCTION("CPolicyNode::OnRename");
  565. // Check for preconditions:
  566. _ASSERTE( pComponentData != NULL || pComponent != NULL );
  567. CComPtr<IConsole> spConsole;
  568. HRESULT hr = S_FALSE;
  569. CComVariant spVariant;
  570. CComBSTR bstrError;
  571. try
  572. {
  573. // We need IConsole
  574. if( pComponentData != NULL )
  575. {
  576. spConsole = ((CComponentData*)pComponentData)->m_spConsole;
  577. }
  578. else
  579. {
  580. spConsole = ((CComponent*)pComponent)->m_spConsole;
  581. }
  582. _ASSERTE( spConsole != NULL );
  583. // This returns S_OK if a property sheet for this object already exists
  584. // and brings that property sheet to the foreground.
  585. // It returns S_FALSE if the property sheet wasn't found.
  586. hr = BringUpPropertySheetForNode(
  587. this
  588. , pComponentData
  589. , pComponent
  590. , spConsole
  591. );
  592. if( FAILED( hr ) )
  593. {
  594. return hr;
  595. }
  596. if( S_OK == hr )
  597. {
  598. // We found a property sheet already up for this node.
  599. ShowErrorDialog( NULL, IDS_ERROR_CLOSE_PROPERTY_SHEET, NULL, S_OK, USE_DEFAULT, GetComponentData()->m_spConsole );
  600. return hr;
  601. }
  602. // We didn't find a property sheet already up for this node.
  603. _ASSERTE( S_FALSE == hr );
  604. {
  605. ::CString str = (OLECHAR *) param;
  606. str.TrimLeft();
  607. str.TrimRight();
  608. if (str.IsEmpty())
  609. {
  610. ShowErrorDialog( NULL, IDS_ERROR__POLICYNAME_EMPTY);
  611. hr = S_FALSE;
  612. return hr;
  613. }
  614. }
  615. // Make a BSTR out of the new name.
  616. spVariant.vt = VT_BSTR;
  617. spVariant.bstrVal = SysAllocString( (OLECHAR *) param );
  618. _ASSERTE( spVariant.bstrVal != NULL );
  619. // Try to change the name of the policy -- pass the new BSTR to the Sdo.
  620. hr = m_spPolicySdo->PutProperty( PROPERTY_SDO_NAME, &spVariant );
  621. if( FAILED( hr ) )
  622. {
  623. ErrorTrace(DEBUG_NAPMMC_POLICYNODE, "Couldn't put policy name, err = %x", hr);
  624. throw hr;
  625. }
  626. // Need to change the name of the associated profile as well.
  627. hr = m_spProfileSdo->PutProperty( PROPERTY_SDO_NAME, &spVariant );
  628. if( FAILED( hr ) )
  629. {
  630. ErrorTrace(DEBUG_NAPMMC_POLICYNODE, "Couldn't put profile name, err = %x", hr);
  631. throw hr;
  632. }
  633. hr = m_spProfileSdo->Apply();
  634. if( FAILED( hr ) )
  635. {
  636. ErrorTrace(DEBUG_NAPMMC_POLICYNODE, "Couldn't apply profile change, err = %x", hr);
  637. throw hr;
  638. }
  639. // Set the profile association in the policy.
  640. hr = m_spPolicySdo->PutProperty(PROPERTY_POLICY_PROFILE_NAME, &spVariant );
  641. if( FAILED(hr) )
  642. {
  643. ErrorTrace(DEBUG_NAPMMC_POLICYNODE, "Couldn't put profile name for this policy, err = %x", hr);
  644. throw hr;
  645. }
  646. hr = m_spPolicySdo->Apply();
  647. if( FAILED( hr ) )
  648. {
  649. ErrorTrace(DEBUG_NAPMMC_POLICYNODE, "Couldn't apply policy change, err = %x", hr);
  650. throw hr;
  651. }
  652. // ISSUE: We will need to invest some time here to make sure that if the two calls above fail,
  653. // we change things back to a state where they will work -- this seems to be mostly a
  654. // limitation of the SDO's here -- what if my attempt to change it back fails?
  655. // Tell the service to reload data.
  656. HRESULT hrTemp = m_spSdoServiceControl->ResetService();
  657. if( FAILED( hrTemp ) )
  658. {
  659. ErrorTrace(ERROR_NAPMMC_POLICYNODE, "ISdoServiceControl::ResetService() failed, err = %x", hrTemp);
  660. }
  661. m_bstrDisplayName = spVariant.bstrVal;
  662. // Insure that MMC refreshes all views of this object
  663. // to reflect the renaming.
  664. CChangeNotification *pChangeNotification = new CChangeNotification();
  665. pChangeNotification->m_dwFlags = CHANGE_UPDATE_RESULT_NODE;
  666. pChangeNotification->m_pNode = this;
  667. hr = spConsole->UpdateAllViews( NULL, (LPARAM) pChangeNotification, 0);
  668. pChangeNotification->Release();
  669. }
  670. catch(...)
  671. {
  672. if(hr == DB_E_NOTABLE) // assume, the RPC connection has problem
  673. {
  674. ShowErrorDialog(NULL, IDS_ERROR__NOTABLE_TO_WRITE_SDO, NULL, S_OK, USE_DEFAULT, GetComponentData()->m_spConsole);
  675. }
  676. else if(hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS) || hr == E_INVALIDARG)
  677. {
  678. ShowErrorDialog(NULL, IDS_ERROR_INVALID_POLICYNAME, NULL, S_OK, USE_DEFAULT, GetComponentData()->m_spConsole);
  679. }
  680. else
  681. {
  682. ShowErrorDialog(NULL, IDS_ERROR_RENAMEPOLICY, NULL, S_OK, USE_DEFAULT, GetComponentData()->m_spConsole);
  683. }
  684. hr = S_FALSE;
  685. }
  686. return hr;
  687. }
  688. //////////////////////////////////////////////////////////////////////////////
  689. /*++
  690. CPolicyNode::OnDelete
  691. See CSnapinNode::OnDelete (which this method overrides) for detailed info.
  692. --*/
  693. //////////////////////////////////////////////////////////////////////////////
  694. HRESULT CPolicyNode::OnDelete(
  695. LPARAM arg
  696. , LPARAM param
  697. , IComponentData * pComponentData
  698. , IComponent * pComponent
  699. , DATA_OBJECT_TYPES type
  700. , BOOL fSilent
  701. )
  702. {
  703. TRACE_FUNCTION("CPolicyNode::OnDelete");
  704. // Check for preconditions:
  705. _ASSERTE( pComponentData != NULL || pComponent != NULL );
  706. _ASSERTE( m_pParentNode != NULL );
  707. HRESULT hr = S_OK;
  708. // First try to see if a property sheet for this node is already up.
  709. // If so, bring it to the foreground.
  710. // It seems to be acceptable to query IPropertySheetCallback for an IPropertySheetProvider.
  711. // But to get that, first we need IConsole
  712. CComPtr<IConsole> spConsole;
  713. if( pComponentData != NULL )
  714. {
  715. spConsole = ((CComponentData*)pComponentData)->m_spConsole;
  716. }
  717. else
  718. {
  719. // We should have a non-null pComponent
  720. spConsole = ((CComponent*)pComponent)->m_spConsole;
  721. }
  722. _ASSERTE( spConsole != NULL );
  723. // This returns S_OK if a property sheet for this object already exists
  724. // and brings that property sheet to the foreground.
  725. // It returns S_FALSE if the property sheet wasn't found.
  726. hr = BringUpPropertySheetForNode(
  727. this
  728. , pComponentData
  729. , pComponent
  730. , spConsole
  731. );
  732. if( FAILED( hr ) )
  733. {
  734. return hr;
  735. }
  736. if( S_OK == hr )
  737. {
  738. // We found a property sheet already up for this node.
  739. ShowErrorDialog( NULL, IDS_ERROR_CLOSE_PROPERTY_SHEET, NULL, S_OK, USE_DEFAULT, GetComponentData()->m_spConsole );
  740. return hr;
  741. }
  742. // We didn't find a property sheet already up for this node.
  743. _ASSERTE( S_FALSE == hr );
  744. if( FALSE == fSilent )
  745. {
  746. // Is this the last policy?
  747. if ( ((CPoliciesNode *)m_pParentNode )->GetChildrenCount() == 1 )
  748. {
  749. int iLoadStringResult;
  750. WCHAR szPolicyDeleteQuery[IAS_MAX_STRING];
  751. WCHAR szTemp[IAS_MAX_STRING];
  752. iLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_ERROR_ZERO_POLICY, szTemp, IAS_MAX_STRING );
  753. _ASSERT( iLoadStringResult > 0 );
  754. swprintf( szPolicyDeleteQuery, szTemp, m_bstrDisplayName );
  755. int iResult = ShowErrorDialog(
  756. NULL
  757. , 1
  758. , szPolicyDeleteQuery
  759. , S_OK
  760. , IDS_POLICY_NODE__DELETE_POLICY__PROMPT_TITLE
  761. , spConsole
  762. , MB_YESNO | MB_ICONQUESTION
  763. );
  764. if( IDYES != iResult )
  765. {
  766. // The user didn't confirm the delete operation.
  767. return S_FALSE;
  768. }
  769. }
  770. else
  771. {
  772. // It is not the last policy, but we want to ask the user
  773. // to confirm the policy deletion anyway.
  774. int iLoadStringResult;
  775. WCHAR szPolicyDeleteQuery[IAS_MAX_STRING];
  776. WCHAR szTemp[IAS_MAX_STRING];
  777. iLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_POLICY_NODE__DELETE_POLICY__PROMPT, szTemp, IAS_MAX_STRING );
  778. _ASSERT( iLoadStringResult > 0 );
  779. swprintf( szPolicyDeleteQuery, szTemp, m_bstrDisplayName );
  780. int iResult = ShowErrorDialog(
  781. NULL
  782. , 1
  783. , szPolicyDeleteQuery
  784. , S_OK
  785. , IDS_POLICY_NODE__DELETE_POLICY__PROMPT_TITLE
  786. , spConsole
  787. , MB_YESNO | MB_ICONQUESTION
  788. );
  789. if( IDYES != iResult )
  790. {
  791. // The user didn't confirm the delete operation.
  792. return S_FALSE;
  793. }
  794. }
  795. }
  796. // Try to delete the underlying data.
  797. hr = ((CPoliciesNode *) m_pParentNode )->RemoveChild( this );
  798. if( SUCCEEDED( hr ) )
  799. {
  800. delete this;
  801. }
  802. // Looks like RemoveChild takes care of putting up an error dialog if anything went wrong.
  803. return hr;
  804. }
  805. //////////////////////////////////////////////////////////////////////////////
  806. /*++
  807. CPolicyNode::SetVerbs
  808. See CSnapinNode::SetVerbs (which this method overrides) for detailed info.
  809. --*/
  810. //////////////////////////////////////////////////////////////////////////////
  811. HRESULT CPolicyNode::SetVerbs( IConsoleVerb * pConsoleVerb )
  812. {
  813. TRACE_FUNCTION("CPolicyNode::SetVerbs");
  814. HRESULT hr = S_OK;
  815. // We want the user to be able to choose Properties on this node
  816. hr = pConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, ENABLED, TRUE );
  817. // We want Properties to be the default
  818. hr = pConsoleVerb->SetDefaultVerb( MMC_VERB_PROPERTIES );
  819. // We want the user to be able to delete this node
  820. hr = pConsoleVerb->SetVerbState( MMC_VERB_DELETE, ENABLED, TRUE );
  821. // We want the user to be able to rename this node
  822. hr = pConsoleVerb->SetVerbState( MMC_VERB_RENAME, ENABLED, TRUE );
  823. // We want to enable copy/paste
  824. hr = pConsoleVerb->SetVerbState( MMC_VERB_COPY, ENABLED, FALSE);
  825. hr = pConsoleVerb->SetVerbState( MMC_VERB_PASTE, ENABLED, FALSE );
  826. return hr;
  827. }
  828. HRESULT CPolicyNode::ControlbarNotify(IControlbar *pControlbar,
  829. IExtendControlbar *pExtendControlbar,
  830. CSimpleMap<UINT, IUnknown*>* pToolbarMap,
  831. MMC_NOTIFY_TYPE event,
  832. LPARAM arg,
  833. LPARAM param,
  834. CSnapInObjectRootBase* pObj,
  835. DATA_OBJECT_TYPES type)
  836. {
  837. m_pControBarNotifySnapinObj = pObj;
  838. return CSnapinNode< CPolicyNode, CComponentData, CComponent >::ControlbarNotify(pControlbar,
  839. pExtendControlbar,
  840. pToolbarMap,
  841. event,
  842. arg,
  843. param,
  844. pObj,
  845. type);
  846. }
  847. //+---------------------------------------------------------------------------
  848. //
  849. // Function: CPolicyNode::OnPolicyMoveUp
  850. //
  851. // Synopsis: move the policy node one level up
  852. //
  853. // Arguments: bool &bHandled - is this command handled?
  854. // CSnapInObjectRoot* pObj -
  855. //
  856. // Returns: HRESULT -
  857. //
  858. // History: Created Header byao 3/5/98 9:56:37 PM
  859. //
  860. //+---------------------------------------------------------------------------
  861. HRESULT CPolicyNode::OnPolicyMoveUp( bool &bHandled, CSnapInObjectRootBase* pObj )
  862. {
  863. // HACK ... HACK -- not supposed to assume this
  864. // but at least we can do something better is this is true
  865. CComponent* pComp = NULL;
  866. try{
  867. pComp = dynamic_cast<CComponent*>(pObj);
  868. }
  869. catch(...)
  870. {
  871. }
  872. if(pComp
  873. && pComp->m_nLastClickedColumn == 1 /* order */
  874. && (pComp->m_dwLastSortOptions & RSI_DESCENDING) != 0) // DESCENDING
  875. {
  876. ((CPoliciesNode *) m_pParentNode )->MoveDownChild( this );
  877. }
  878. else // normal
  879. {
  880. ((CPoliciesNode *) m_pParentNode )->MoveUpChild( this );
  881. }
  882. bHandled = TRUE;
  883. return S_OK;
  884. }
  885. //+---------------------------------------------------------------------------
  886. //
  887. // Function: CPolicyNode::OnPolicyMoveDown
  888. //
  889. // Synopsis: move down the policy node one level
  890. //
  891. // Arguments: bool &bHandled -
  892. // CSnapInObjectRoot* pObj -
  893. //
  894. // Returns: HRESULT -
  895. //
  896. // History: Created Header byao 3/5/98 9:57:31 PM
  897. //
  898. //+---------------------------------------------------------------------------
  899. HRESULT CPolicyNode::OnPolicyMoveDown( bool &bHandled, CSnapInObjectRootBase* pObj )
  900. {
  901. // HACK ... HACK -- not supposed to assume this
  902. // but at least we can do something better is this is true
  903. CComponent* pComp = NULL;
  904. try{
  905. pComp = dynamic_cast<CComponent*>(pObj);
  906. }
  907. catch(...)
  908. {
  909. }
  910. if(pComp
  911. && pComp->m_nLastClickedColumn == 1 /* order */
  912. && (pComp->m_dwLastSortOptions & RSI_DESCENDING) != 0) // DESCENDING
  913. {
  914. ((CPoliciesNode *) m_pParentNode )->MoveUpChild( this );
  915. }
  916. else // normal
  917. {
  918. ((CPoliciesNode *) m_pParentNode )->MoveDownChild( this );
  919. }
  920. bHandled = TRUE;
  921. return S_OK;
  922. }
  923. //////////////////////////////////////////////////////////////////////////////
  924. /*++
  925. CPolicyNode::GetComponentData
  926. This method returns our unique CComponentData object representing the scope
  927. pane of this snapin.
  928. It relies upon the fact that each node has a pointer to its parent,
  929. except for the root node, which instead has a member variable pointing
  930. to CComponentData.
  931. This would be a useful function to use if, for example, you need a reference
  932. to some IConsole but you weren't passed one. You can use GetComponentData
  933. and then use the IConsole pointer which is a member variable of our
  934. CComponentData object.
  935. --*/
  936. //////////////////////////////////////////////////////////////////////////////
  937. CComponentData * CPolicyNode::GetComponentData( void )
  938. {
  939. TRACE_FUNCTION("CPolicyNode::GetComponentData");
  940. return ((CPoliciesNode *) m_pParentNode)->GetComponentData();
  941. }
  942. //+---------------------------------------------------------------------------
  943. //
  944. // Function: SetMerit
  945. //
  946. // Class: CPolicyNode
  947. //
  948. // Synopsis: set the merit value of the policy node
  949. //
  950. // Arguments: int nMeritValue - Merit value
  951. //
  952. // Returns: TRUE : succeed
  953. // FALSE - otherwise
  954. //
  955. // History: Created byao 2/9/98 1:43:37 PM
  956. //
  957. // Note: when this node is added to the array list, the add API will call
  958. // back this function to set the merit value
  959. //+---------------------------------------------------------------------------
  960. BOOL CPolicyNode::SetMerit(int nMeritValue)
  961. {
  962. TRACE_FUNCTION("CPolicyNode::SetMerit");
  963. HRESULT hr = S_OK;
  964. if(m_nMeritValue != nMeritValue)
  965. {
  966. m_nMeritValue = nMeritValue;
  967. //
  968. // set this property in the SDO policy object also
  969. //
  970. CComVariant var;
  971. V_VT(&var) = VT_I4;
  972. V_I4(&var) = m_nMeritValue;
  973. hr = m_spPolicySdo->PutProperty( PROPERTY_POLICY_MERIT, &var);
  974. //
  975. // save this property.
  976. //
  977. m_spPolicySdo->Apply();
  978. }
  979. return (SUCCEEDED(hr));
  980. }
  981. //+---------------------------------------------------------------------------
  982. //
  983. // Function: GetMerit
  984. //
  985. // Class: CPolicyNode
  986. //
  987. // Synopsis: get the merit value of the policy node
  988. //
  989. // Arguments: None
  990. //
  991. // Returns: merit value
  992. //
  993. // History: Created byao 2/9/98 1:43:37 PM
  994. //
  995. //+---------------------------------------------------------------------------
  996. int CPolicyNode::GetMerit()
  997. {
  998. return m_nMeritValue;
  999. }
  1000. //+---------------------------------------------------------------------------
  1001. //
  1002. // Function: SetSdo
  1003. //
  1004. // Class: CPolicyNode
  1005. //
  1006. // Synopsis: Initialize the Sdo pointers in the policy object
  1007. //
  1008. // Arguments: ISdo * pSdoPolicy - pointer to the policy SDO
  1009. //
  1010. // Returns: HRESULT - how does it go?
  1011. //
  1012. // History: Created Header byao 2/15/98 6:08:40 PM
  1013. //
  1014. //+---------------------------------------------------------------------------
  1015. HRESULT CPolicyNode::SetSdo( ISdo * pPolicySdo
  1016. , ISdoDictionaryOld * pDictionarySdo
  1017. , ISdo* pProfileSdo
  1018. , ISdoCollection* pProfilesCollectionSdo
  1019. , ISdoCollection* pPoliciesCollectionSdo
  1020. , ISdoServiceControl * pSdoServiceControl
  1021. )
  1022. {
  1023. TRACE_FUNCTION("CPolicyNode::SetSdo");
  1024. // Check for preconditions:
  1025. _ASSERTE( pPolicySdo != NULL );
  1026. _ASSERTE( pDictionarySdo != NULL );
  1027. _ASSERTE( pProfileSdo != NULL );
  1028. _ASSERTE( pProfilesCollectionSdo != NULL );
  1029. _ASSERTE( pProfilesCollectionSdo != NULL );
  1030. _ASSERTE( pSdoServiceControl != NULL );
  1031. // Save our sdo pointer.
  1032. m_spPolicySdo = pPolicySdo;
  1033. m_spDictionarySdo = pDictionarySdo;
  1034. m_spProfileSdo = pProfileSdo;
  1035. m_spProfilesCollectionSdo = pProfilesCollectionSdo;
  1036. m_spPoliciesCollectionSdo = pPoliciesCollectionSdo;
  1037. m_spSdoServiceControl = pSdoServiceControl;
  1038. return S_OK;
  1039. }
  1040. //+---------------------------------------------------------------------------
  1041. //
  1042. // Function: LoadSdoData
  1043. //
  1044. // Class: CPolicyNode
  1045. //
  1046. // Synopsis: Load data from SDO pointers
  1047. //
  1048. // Returns: HRESULT - how does it go?
  1049. //
  1050. // History: Created Header byao 3/10/98 6:08:40 PM
  1051. //
  1052. //+---------------------------------------------------------------------------
  1053. HRESULT CPolicyNode::LoadSdoData()
  1054. {
  1055. TRACE_FUNCTION("CPolicyNode::LoadSdoData");
  1056. HRESULT hr = S_OK;
  1057. CComVariant var;
  1058. if ( !m_spPolicySdo )
  1059. {
  1060. return E_INVALIDARG;
  1061. }
  1062. // Set the display name for this object.
  1063. hr = m_spPolicySdo->GetProperty( PROPERTY_SDO_NAME, &var );
  1064. if ( FAILED(hr) )
  1065. {
  1066. ShowErrorDialog( NULL, IDS_ERROR_SDO_ERROR_GETPROP_POLICYNAME, NULL, hr, USE_DEFAULT, GetComponentData()->m_spConsole );
  1067. return hr;
  1068. }
  1069. _ASSERTE( V_VT(&var) == VT_BSTR );
  1070. m_bstrDisplayName = V_BSTR(&var);
  1071. var.Clear();
  1072. hr = m_spPolicySdo->GetProperty( PROPERTY_POLICY_MERIT, &var );
  1073. if ( FAILED(hr) )
  1074. {
  1075. ShowErrorDialog( NULL, IDS_ERROR_SDO_ERROR_GETPROP_POLICYMERIT, NULL, hr, USE_DEFAULT, GetComponentData()->m_spConsole );
  1076. return hr;
  1077. }
  1078. _ASSERTE( V_VT(&var) == VT_I4);
  1079. m_nMeritValue = V_I4(&var);
  1080. return hr;
  1081. }
  1082. //+---------------------------------------------------------------------------
  1083. //
  1084. // Function: CPolicyNode::UpdateMenuState
  1085. //
  1086. // Synopsis: update MoveUp/MoveDown menu status according to the policy order
  1087. //
  1088. // Arguments: UINT id -
  1089. // LPTSTR pBuf -
  1090. // UINT *flags -
  1091. //
  1092. // Returns: Nothing
  1093. //
  1094. // History: Created Header byao 6/2/98 5:31:53 PM
  1095. //
  1096. //+---------------------------------------------------------------------------
  1097. void CPolicyNode::UpdateMenuState(UINT id, LPTSTR pBuf, UINT *flags)
  1098. {
  1099. TRACE_FUNCTION("CPolicyNode::UpdateMenuState");
  1100. // Check for preconditions:
  1101. BOOL bReverse = FALSE;
  1102. // need to trap this call ControlBarNotify and remember the component --- in pObj and then ...
  1103. if(m_pControBarNotifySnapinObj)
  1104. {
  1105. CComponent* pComp = NULL;
  1106. try{
  1107. pComp = dynamic_cast<CComponent*>(m_pControBarNotifySnapinObj);
  1108. }
  1109. catch(...)
  1110. {
  1111. }
  1112. if(pComp
  1113. && pComp->m_nLastClickedColumn == 1 /* order */
  1114. && (pComp->m_dwLastSortOptions & RSI_DESCENDING) != 0) // DESCENDING
  1115. {
  1116. bReverse = TRUE;
  1117. }
  1118. }
  1119. // Set the state of the appropriate context menu items.
  1120. if( (id == ID_MENUITEM_POLICY_TOP__MOVE_UP && !bReverse) || (id == ID_MENUITEM_POLICY_TOP__MOVE_DOWN && bReverse))
  1121. {
  1122. if ( 1 == m_nMeritValue )
  1123. {
  1124. //
  1125. // we should disable the MoveUp menu when it's already the first
  1126. //
  1127. *flags = MFS_GRAYED;
  1128. }
  1129. else
  1130. {
  1131. *flags = MFS_ENABLED;
  1132. }
  1133. }
  1134. else
  1135. {
  1136. if( (id == ID_MENUITEM_POLICY_TOP__MOVE_DOWN && !bReverse) || (id == ID_MENUITEM_POLICY_TOP__MOVE_UP && bReverse))
  1137. {
  1138. if ( m_nMeritValue == ((CPoliciesNode *)m_pParentNode)->GetChildrenCount() )
  1139. {
  1140. //
  1141. // we should disable the MoveDown menu when it's already the last
  1142. //
  1143. *flags = MFS_GRAYED;
  1144. }
  1145. else
  1146. {
  1147. *flags = MFS_ENABLED;
  1148. }
  1149. }
  1150. }
  1151. }
  1152. //+---------------------------------------------------------------------------
  1153. //
  1154. // Function: CPolicyNode::UpdateToolbarButton
  1155. //
  1156. // Synopsis: update MoveUp/MoveDown toolbar button
  1157. //
  1158. // Arguments: UINT id -
  1159. // BYTE fsState -
  1160. //
  1161. // Returns: Nothing
  1162. //
  1163. // History: Created Header byao 6/2/98 5:31:53 PM
  1164. //
  1165. //+---------------------------------------------------------------------------
  1166. BOOL CPolicyNode::UpdateToolbarButton(UINT id, BYTE fsState)
  1167. {
  1168. TRACE_FUNCTION("CPolicyNode::UpdateToolbarButton");
  1169. BOOL bReverse = FALSE;
  1170. // need to trap this call ControlBarNotify and remember the component --- in pObj and then ...
  1171. if(m_pControBarNotifySnapinObj)
  1172. {
  1173. CComponent* pComp = NULL;
  1174. try{
  1175. pComp = dynamic_cast<CComponent*>(m_pControBarNotifySnapinObj);
  1176. }
  1177. catch(...)
  1178. {
  1179. }
  1180. if(pComp
  1181. && pComp->m_nLastClickedColumn == 1 /* order */
  1182. && (pComp->m_dwLastSortOptions & RSI_DESCENDING) != 0) // DESCENDING
  1183. {
  1184. bReverse = TRUE;
  1185. }
  1186. }
  1187. // Check for preconditions:
  1188. // None.
  1189. // Set whether the buttons should be enabled.
  1190. if (fsState == ENABLED)
  1191. {
  1192. if(( id == ID_BUTTON_POLICY_MOVEUP && (!bReverse)) || (id == ID_BUTTON_POLICY_MOVEDOWN && bReverse))
  1193. {
  1194. if ( 1 == m_nMeritValue )
  1195. {
  1196. return FALSE;
  1197. }
  1198. else
  1199. {
  1200. return TRUE;
  1201. }
  1202. }
  1203. else
  1204. {
  1205. if(( id == ID_BUTTON_POLICY_MOVEDOWN && (!bReverse)) || (id == ID_BUTTON_POLICY_MOVEUP && bReverse))
  1206. {
  1207. if ( m_nMeritValue == ((CPoliciesNode *)m_pParentNode)->GetChildrenCount() )
  1208. {
  1209. return FALSE;
  1210. }
  1211. else
  1212. {
  1213. return TRUE;
  1214. }
  1215. }
  1216. }
  1217. }
  1218. // For all other possible button ID's and states, the correct answer here is FALSE.
  1219. return FALSE;
  1220. }
  1221. //////////////////////////////////////////////////////////////////////////////
  1222. /*++
  1223. CPolicyNode::OnPropertyChange
  1224. This is our own custom response to the MMCN_PROPERTY_CHANGE notification.
  1225. MMC never actually sends this notification to our snapin with a specific lpDataObject,
  1226. so it would never normally get routed to a particular node but we have arranged it
  1227. so that our property pages can pass the appropriate CSnapInItem pointer as the param
  1228. argument. In our CComponent::Notify override, we map the notification message to
  1229. the appropriate node using the param argument.
  1230. --*/
  1231. //////////////////////////////////////////////////////////////////////////////
  1232. HRESULT CPolicyNode::OnPropertyChange(
  1233. LPARAM arg
  1234. , LPARAM param
  1235. , IComponentData * pComponentData
  1236. , IComponent * pComponent
  1237. , DATA_OBJECT_TYPES type
  1238. )
  1239. {
  1240. TRACE_FUNCTION("CPolicyNode::OnPropertyChange");
  1241. // Check for preconditions:
  1242. // None.
  1243. return LoadSdoData();
  1244. }