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.

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