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.

861 lines
26 KiB

  1. // MapWPge.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include <iadmw.h>
  5. #include "certmap.h"
  6. extern "C"
  7. {
  8. #include <wincrypt.h>
  9. #include <sslsp.h>
  10. }
  11. #include "Iismap.hxx"
  12. #include "Iiscmr.hxx"
  13. #include "brwsdlg.h"
  14. #include "ListRow.h"
  15. #include "ChkLstCt.h"
  16. #include "MapWPge.h"
  17. #include "Ed11Maps.h"
  18. #include "EdWldRul.h"
  19. #include <iiscnfgp.h>
  20. #include "wrapmb.h"
  21. #include "WWzOne.h"
  22. #include "WWzTwo.h"
  23. #include "WWzThree.h"
  24. #include <lmcons.h>
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. #define COL_NUM_ENABLED 0
  31. #define COL_NUM_DESCRIPTION 1
  32. #define COL_NUM_NTACCOUNT 2
  33. #define MB_EXTEND_KEY "CertW"
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CMapWildcardsPge property page
  36. IMPLEMENT_DYNCREATE(CMapWildcardsPge, CPropertyPage)
  37. //---------------------------------------------------------------------------
  38. CMapWildcardsPge::CMapWildcardsPge() : CPropertyPage(CMapWildcardsPge::IDD),
  39. m_fDirty(FALSE)
  40. {
  41. //{{AFX_DATA_INIT(CMapWildcardsPge)
  42. m_bool_enable = FALSE;
  43. //}}AFX_DATA_INIT
  44. }
  45. //---------------------------------------------------------------------------
  46. CMapWildcardsPge::~CMapWildcardsPge()
  47. {
  48. }
  49. //---------------------------------------------------------------------------
  50. void CMapWildcardsPge::DoDataExchange(CDataExchange* pDX)
  51. {
  52. CPropertyPage::DoDataExchange(pDX);
  53. //{{AFX_DATA_MAP(CMapWildcardsPge)
  54. DDX_Control(pDX, IDC_LIST, m_clistctrl_list);
  55. DDX_Control(pDX, IDC_MOVE_UP, m_cbutton_up);
  56. DDX_Control(pDX, IDC_MOVE_DOWN, m_cbutton_down);
  57. DDX_Control(pDX, IDC_ADD, m_cbutton_add);
  58. DDX_Control(pDX, IDC_DELETE, m_cbutton_delete);
  59. DDX_Control(pDX, IDC_EDIT, m_cbutton_editrule);
  60. DDX_Check(pDX, IDC_ENABLE, m_bool_enable);
  61. //}}AFX_DATA_MAP
  62. }
  63. //---------------------------------------------------------------------------
  64. BEGIN_MESSAGE_MAP(CMapWildcardsPge, CPropertyPage)
  65. //{{AFX_MSG_MAP(CMapWildcardsPge)
  66. ON_BN_CLICKED(IDC_MOVE_DOWN, OnMoveDown)
  67. ON_BN_CLICKED(IDC_MOVE_UP, OnMoveUp)
  68. ON_BN_CLICKED(IDC_ADD, OnAdd)
  69. ON_BN_CLICKED(IDC_DELETE, OnDelete)
  70. ON_BN_CLICKED(IDC_EDIT, OnEdit)
  71. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST, OnItemchangedList)
  72. ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
  73. ON_BN_CLICKED(IDC_ENABLE, OnEnable)
  74. //}}AFX_MSG_MAP
  75. ON_COMMAND(ID_HELP_FINDER, DoHelp)
  76. ON_COMMAND(ID_HELP, DoHelp)
  77. ON_COMMAND(ID_CONTEXT_HELP, DoHelp)
  78. ON_COMMAND(ID_DEFAULT_HELP, DoHelp)
  79. END_MESSAGE_MAP()
  80. //---------------------------------------------------------------------------
  81. void CMapWildcardsPge::DoHelp()
  82. {
  83. WinHelp( HIDD_CERTMAP_MAIN_ADVANCED );
  84. }
  85. /////////////////////////////////////////////////////////////////////////////
  86. // initialization routines
  87. //---------------------------------------------------------------------------
  88. // FInitMapper is called by the routine instantiating this page. After the object
  89. // is first created is when it is called. It allows us to fail gracefully.
  90. BOOL CMapWildcardsPge::FInit(IMSAdminBase* pMB)
  91. {
  92. BOOL fAnswer = FALSE;
  93. PVOID pData = NULL;
  94. DWORD cbData = 0;
  95. BOOL f;
  96. m_pMB = pMB;
  97. // before messing with the metabase, prepare the strings we will need
  98. CString szBasePath = m_szMBPath;
  99. CString szRelativePath = MB_EXTEND_KEY;
  100. CString szObjectPath = m_szMBPath + _T('/') + szRelativePath;
  101. // prepare the metabase wrapper
  102. CWrapMetaBase mbWrap;
  103. f = mbWrap.FInit(m_pMB);
  104. if ( !f ) return FALSE;
  105. // attempt to open the object we want to store into
  106. f = mbWrap.Open( szObjectPath, METADATA_PERMISSION_READ );
  107. // if that worked, load the data
  108. if ( f )
  109. {
  110. // first, get the size of the data that we are looking for
  111. pData = mbWrap.GetData( _T(""), MD_SERIAL_CERTW, IIS_MD_UT_SERVER, BINARY_METADATA, &cbData );
  112. // if we successfully got the data, unserialize it
  113. // WARNING: m_mapper.Unserialize changes the value of the pointer that is passed in. Pass
  114. // in a copy of the pointer
  115. PUCHAR pDataCopy = (PUCHAR)pData;
  116. if ( pData )
  117. fAnswer = m_mapper.Unserialize( (PUCHAR*)&pDataCopy, &cbData );
  118. // close the object
  119. f = mbWrap.Close();
  120. // cleanup
  121. if ( pData )
  122. mbWrap.FreeWrapData( pData );
  123. }
  124. // return the answer
  125. return fAnswer;
  126. }
  127. //---------------------------------------------------------------------------
  128. BOOL CMapWildcardsPge::OnInitDialog()
  129. {
  130. //call the parental oninitdialog
  131. BOOL f = CPropertyPage::OnInitDialog();
  132. // if the initinalization (sp?) succeeded, init the list and other items
  133. if ( f )
  134. {
  135. // init the contents of the list
  136. FInitRulesList();
  137. // Fill the mapping list with the stored items
  138. FillRulesList();
  139. // set the initial button states
  140. EnableDependantButtons();
  141. }
  142. // set the initial state of the enable button
  143. // get the globals object
  144. CCertGlobalRuleInfo* pGlob = m_mapper.GetGlobalRulesInfo();
  145. m_bool_enable = pGlob->GetRulesEnabled();
  146. // set any changes in the info into place
  147. UpdateData(FALSE);
  148. // return the answer
  149. return f;
  150. }
  151. //---------------------------------------------------------------------------
  152. BOOL CMapWildcardsPge::FInitRulesList()
  153. {
  154. CString sz;
  155. int i;
  156. // setup the friendly name column
  157. sz.Empty();
  158. i = m_clistctrl_list.InsertColumn( COL_NUM_ENABLED, sz, LVCFMT_LEFT, 20 );
  159. // setup the description column
  160. sz.LoadString( IDS_WILD_DESCRIPTION );
  161. i = m_clistctrl_list.InsertColumn( COL_NUM_DESCRIPTION, sz, LVCFMT_LEFT, 238 );
  162. // setup the account column
  163. sz.LoadString( IDS_WILD_ACCOUNT );
  164. i = m_clistctrl_list.InsertColumn( COL_NUM_NTACCOUNT, sz, LVCFMT_LEFT, 220 );
  165. return TRUE;
  166. }
  167. //---------------------------------------------------------------------------
  168. // fill in the rules. Get the order for the rules from the globals object. That
  169. // way there is no need to sort them later
  170. BOOL CMapWildcardsPge::FillRulesList()
  171. {
  172. // get the globals object
  173. CCertGlobalRuleInfo* pGlob = m_mapper.GetGlobalRulesInfo();
  174. // get the number of rules (actually its a number of rule order - but they are the same thing)
  175. DWORD cbRules = m_mapper.GetRuleCount();
  176. // get the pointer to the order array
  177. DWORD* pOrder = pGlob->GetRuleOrderArray();
  178. // for each item in the mapper object, add it to the list control
  179. for ( DWORD j = 0; j < cbRules; j++ )
  180. {
  181. CCertMapRule* pRule;
  182. DWORD iRule = pOrder[j];
  183. // get the mapping
  184. pRule = m_mapper.GetRule( iRule );
  185. // if that worked, add it to the list
  186. if ( pRule )
  187. {
  188. // add it to the list
  189. AddRuleToList( pRule, iRule, 0xffffffff );
  190. }
  191. }
  192. // it worked - so ok.
  193. return TRUE;
  194. }
  195. //---------------------------------------------------------------------------
  196. int CMapWildcardsPge::AddRuleToList( CCertMapRule* pRule, DWORD iRule, int iInsert )
  197. {
  198. CString sz;
  199. int i;
  200. if ( !pRule )
  201. return -1;
  202. // if the item to be inserted is to be the last, set it up
  203. if ( iInsert == 0xffffffff )
  204. iInsert = m_clistctrl_list.GetItemCount();
  205. // get the appropriate "enabled" string
  206. BOOL fEnabled = pRule->GetRuleEnabled();
  207. if ( fEnabled )
  208. sz.LoadString( IDS_ENABLED );
  209. else
  210. sz.Empty();
  211. // add the friendly name of the mapping
  212. // create the new entry in the list box. Do not sort on this entry - yet
  213. i = m_clistctrl_list.InsertItem( iInsert, sz );
  214. // add the friendly name of the rule
  215. sz = pRule->GetRuleName();
  216. // create the new entry in the list box. Do not sort on this entry - yet
  217. m_clistctrl_list.SetItemText( i, COL_NUM_DESCRIPTION, sz );
  218. // add the account name of the mapping
  219. if ( pRule->GetRuleDenyAccess() )
  220. sz.LoadString( IDS_DENYACCESS );
  221. else
  222. sz = pRule->GetRuleAccount();
  223. m_clistctrl_list.SetItemText( i, COL_NUM_NTACCOUNT, sz );
  224. // attach the mapper index to the item in the list - it may have a different
  225. // list index after the list has been sorted.
  226. m_clistctrl_list.SetItemData( i, iRule );
  227. // return whether or not the insertion succeeded
  228. return i;
  229. }
  230. //---------------------------------------------------------------------------
  231. // Note: supposedly, the order of the items in the list and the odrder
  232. // of the items in the globals object should be the same
  233. void CMapWildcardsPge::UpdateRuleInDispList( DWORD iList, CCertMapRule* pRule )
  234. {
  235. CString sz;
  236. // get the appropriate "enabled" string
  237. BOOL fEnabled = pRule->GetRuleEnabled();
  238. if ( fEnabled )
  239. sz.LoadString( IDS_ENABLED );
  240. else
  241. sz.Empty();
  242. // update the "Enabled" indicator
  243. m_clistctrl_list.SetItemText( iList, COL_NUM_ENABLED, sz );
  244. // update the mapping name
  245. sz = pRule->GetRuleName();
  246. m_clistctrl_list.SetItemText( iList, COL_NUM_DESCRIPTION, sz );
  247. // update the account name
  248. if ( pRule->GetRuleDenyAccess() )
  249. sz.LoadString( IDS_DENYACCESS );
  250. else
  251. sz = pRule->GetRuleAccount();
  252. m_clistctrl_list.SetItemText( iList, COL_NUM_NTACCOUNT, sz );
  253. }
  254. //---------------------------------------------------------------------------
  255. // editing a wildcard rule is rather complex, thus I am seperating that code
  256. // out into that for the dialog itself. All we do is pass in the rule pointer
  257. // and let it go at that.
  258. BOOL CMapWildcardsPge::EditOneRule( CCertMapRule* pRule, BOOL fAsWizard )
  259. {
  260. // edit the item using a tabbed dialog / wizard
  261. CPropertySheet propSheet;
  262. CWildWizOne wwOne;
  263. CWildWizTwo wwTwo;
  264. CWildWizThree wwThree;
  265. // set the params
  266. wwOne.m_pMB = m_pMB;
  267. // fill in the data for the pages
  268. wwOne.m_pRule = pRule;
  269. wwOne.m_szMBPath = m_szMBPath;
  270. wwOne.m_fIsWizard = fAsWizard;
  271. wwOne.m_pPropSheet = &propSheet;
  272. wwTwo.m_pRule = pRule;
  273. wwTwo.m_szMBPath = m_szMBPath;
  274. wwTwo.m_fIsWizard = fAsWizard;
  275. wwTwo.m_pPropSheet = &propSheet;
  276. wwThree.m_pRule = pRule;
  277. wwThree.m_szMBPath = m_szMBPath;
  278. wwThree.m_fIsWizard = fAsWizard;
  279. wwThree.m_pPropSheet = &propSheet;
  280. // add the pages
  281. propSheet.AddPage( &wwOne );
  282. propSheet.AddPage( &wwTwo );
  283. propSheet.AddPage( &wwThree );
  284. // turn it into a wizard if necessary
  285. if ( fAsWizard )
  286. propSheet.SetWizardMode();
  287. // set the title of the wizard/tabbed dialog thing
  288. CString szTitle;
  289. szTitle.LoadString( IDS_WILDWIZ_TITLE );
  290. propSheet.SetTitle( szTitle );
  291. // turn on help
  292. propSheet.m_psh.dwFlags |= PSH_HASHELP;
  293. wwOne.m_psp.dwFlags |= PSP_HASHELP;
  294. wwTwo.m_psp.dwFlags |= PSP_HASHELP;
  295. wwThree.m_psp.dwFlags |= PSP_HASHELP;
  296. // run the wizard and return if it ended with IDOK
  297. INT_PTR id = propSheet.DoModal();
  298. return ( (id == IDOK) || (id == ID_WIZFINISH) );
  299. /*
  300. CEditWildcardRule ruleDlg;
  301. // prepare
  302. ruleDlg.m_pRule = pRule;
  303. ruleDlg.m_szMBPath = m_szMBPath;
  304. // run the dialog and return if it ended with IDOK
  305. return (ruleDlg.DoModal() == IDOK);
  306. */
  307. }
  308. //---------------------------------------------------------------------------
  309. // Yeah! the CEdit11Mappings works equally well for multiple rules! - just
  310. // some modifications in this routine!
  311. BOOL CMapWildcardsPge::EditMultipleRules()
  312. {
  313. CEdit11Mappings mapdlg;
  314. CCertMapRule* pRule;
  315. BOOL fSetInitialState = FALSE;
  316. BOOL fEnable;
  317. // scan the list of seleted items for the proper initial enable button state
  318. // loop through the selected items, setting each one's mapping
  319. int iList = -1;
  320. while( (iList = m_clistctrl_list.GetNextItem( iList, LVNI_SELECTED )) >= 0 )
  321. {
  322. // get the mapper index for the item
  323. // IA64 - this is OK to cast to DWORD as it is just an index
  324. DWORD iMapper = (DWORD)m_clistctrl_list.GetItemData( iList );
  325. // get the mapping item for updating purposes
  326. pRule = m_mapper.GetRule( iMapper );
  327. if ( !pRule )
  328. {
  329. AfxMessageBox( IDS_ERR_ACCESS_MAPPING );
  330. break;
  331. }
  332. // get the enable state of the mapping
  333. fEnable = pRule->GetRuleEnabled();
  334. // if this is the first time, just set the initial state
  335. if ( !fSetInitialState )
  336. {
  337. mapdlg.m_int_enable = fEnable;
  338. fSetInitialState = TRUE;
  339. }
  340. else
  341. {
  342. // if it is different, then go indeterminate and break
  343. if ( fEnable != mapdlg.m_int_enable )
  344. {
  345. mapdlg.m_int_enable = 2;
  346. break;
  347. }
  348. }
  349. }
  350. //
  351. // ANSI/UNICODE conversion - RonaldM
  352. //
  353. USES_CONVERSION;
  354. // run the mapping dialog
  355. if ( mapdlg.DoModal() == IDOK )
  356. {
  357. // loop through the selected items, setting each one's mapping
  358. int iList = -1;
  359. while( (iList = m_clistctrl_list.GetNextItem( iList, LVNI_SELECTED )) >= 0 )
  360. {
  361. // get the mapper index for the item
  362. // IA64 - this is OK to cast to DWORD as it is just an index
  363. DWORD iMapper = (DWORD)m_clistctrl_list.GetItemData( iList );
  364. // get the mapping item for updating purposes
  365. pRule = m_mapper.GetRule( iMapper );
  366. if ( !pRule )
  367. {
  368. AfxMessageBox( IDS_ERR_ACCESS_MAPPING );
  369. break;
  370. }
  371. // set the enable flag if requested
  372. switch ( mapdlg.m_int_enable )
  373. {
  374. case 0: // disable
  375. pRule->SetRuleEnabled( FALSE );
  376. break;
  377. case 1: // enable
  378. pRule->SetRuleEnabled( TRUE );
  379. break;
  380. }
  381. // set the NT account field of the mapping object
  382. pRule->SetRuleAccount( T2A ((LPTSTR)(LPCTSTR)mapdlg.m_sz_accountname) );
  383. // update it in the list control too
  384. UpdateRuleInDispList( iList, pRule );
  385. }
  386. // activate the apply button
  387. SetModified();
  388. m_fDirty = TRUE;
  389. // return true because the user said "OK"
  390. return TRUE;
  391. }
  392. // return FALSE because the user did not say "OK"
  393. return FALSE;
  394. }
  395. //---------------------------------------------------------------------------
  396. void CMapWildcardsPge::EnableDependantButtons()
  397. {
  398. // the whole purpose of this routine is to gray or activate
  399. // the edit and delete buttons depending on whether or not anything
  400. // is selected. So start by getting the selection count
  401. UINT cItemsSel = m_clistctrl_list.GetSelectedCount();
  402. // if there is only one item selected, then possibly activate the up/down buttons
  403. if ( cItemsSel == 1 )
  404. {
  405. m_cbutton_up.EnableWindow( TRUE );
  406. m_cbutton_down.EnableWindow( TRUE );
  407. }
  408. else
  409. {
  410. m_cbutton_up.EnableWindow( FALSE );
  411. m_cbutton_down.EnableWindow( FALSE );
  412. }
  413. // now the more general case of multiple selections
  414. if ( cItemsSel > 0 )
  415. {
  416. // there are items selected
  417. m_cbutton_editrule.EnableWindow( TRUE );
  418. m_cbutton_delete.EnableWindow( TRUE );
  419. }
  420. else
  421. {
  422. // nope. Nothing selected
  423. m_cbutton_editrule.EnableWindow( FALSE );
  424. m_cbutton_delete.EnableWindow( FALSE );
  425. }
  426. // always enable the add button
  427. m_cbutton_add.EnableWindow( TRUE );
  428. }
  429. /////////////////////////////////////////////////////////////////////////////
  430. // CMapWildcardsPge message handlers
  431. //---------------------------------------------------------------------------
  432. BOOL CMapWildcardsPge::OnApply()
  433. {
  434. BOOL f;
  435. CStoreXBF xbf;
  436. METADATA_HANDLE hm;
  437. // if no changes have been made, then don't do anything
  438. if ( !m_fDirty )
  439. return TRUE;
  440. UpdateData( TRUE );
  441. CWaitCursor wait;
  442. // set the current value of enable into place
  443. // get the globals object
  444. CCertGlobalRuleInfo* pGlob = m_mapper.GetGlobalRulesInfo();
  445. pGlob->SetRulesEnabled( m_bool_enable );
  446. // serialize the reference to the mapper itself
  447. f = m_mapper.Serialize( &xbf );
  448. // before messing with the metabase, prepare the strings we will need
  449. CString szBasePath = m_szMBPath;
  450. CString szRelativePath = MB_EXTEND_KEY;
  451. CString szObjectPath = m_szMBPath + _T('/') + szRelativePath;
  452. // prepare the metabase wrapper
  453. CWrapMetaBase mbWrap;
  454. f = mbWrap.FInit(m_pMB);
  455. // attempt to open the object we want to store into
  456. f = mbWrap.Open( szObjectPath, METADATA_PERMISSION_WRITE );
  457. // if that did not work, we need to add the object
  458. if ( !f )
  459. {
  460. // need a slash after the namespace extention now
  461. szBasePath += _T('/');
  462. // open the base object
  463. f = mbWrap.Open( szBasePath, METADATA_PERMISSION_WRITE );
  464. if ( !f )
  465. {
  466. AfxMessageBox(IDS_ERR_ACCESS_MAPPING);
  467. return FALSE;
  468. }
  469. // add the object we want
  470. f = mbWrap.AddObject( szRelativePath );
  471. if ( !f )
  472. {
  473. AfxMessageBox(IDS_ERR_ACCESS_MAPPING);
  474. mbWrap.Close();
  475. return FALSE;
  476. }
  477. // close the base object
  478. f = mbWrap.Close();
  479. // attempt to open the object we want to store into
  480. f = mbWrap.Open( szObjectPath, METADATA_PERMISSION_WRITE );
  481. }
  482. // set the data into place in the object - IF we were ablt to open it
  483. if ( f )
  484. mbWrap.SetData( _T(""), MD_SERIAL_CERTW, IIS_MD_UT_SERVER, BINARY_METADATA, xbf.GetBuff(), xbf.GetUsed(), METADATA_SECURE );
  485. // close the object
  486. f = mbWrap.Close();
  487. // save the changes to the metabase
  488. f = mbWrap.Save();
  489. // tell the persistence object to tuck away the reference so that we may find it later
  490. // f = m_persist.FSave( xbf.GetBuff(), xbf.GetUsed() );
  491. // deactivate the apply button
  492. SetModified( FALSE );
  493. m_fDirty = FALSE;
  494. // return f;
  495. return TRUE;
  496. }
  497. //---------------------------------------------------------------------------
  498. void CMapWildcardsPge::OnMove( int delta )
  499. {
  500. int iList;
  501. ASSERT( delta != 0 );
  502. // make sure there is only one item selected
  503. ASSERT( m_clistctrl_list.GetSelectedCount() == 1 );
  504. // Get the list index of the item in question.
  505. // this is also the index into the rule order array
  506. iList = m_clistctrl_list.GetNextItem( -1, LVNI_SELECTED );
  507. // get the globals object
  508. CCertGlobalRuleInfo* pGlob = m_mapper.GetGlobalRulesInfo();
  509. // get the number of rules (actually its a number of rule order - but they are the same thing)
  510. int cbRules = pGlob->GetRuleOrderCount();
  511. // test against the edge conditions
  512. if ( ((iList == 0) && (delta < 0)) | ((iList == (cbRules - 1)) && (delta > 0)) )
  513. return;
  514. // get the pointer to the order array
  515. DWORD * pOrder = pGlob->GetRuleOrderArray();
  516. // calculate the new position in the array
  517. int iNewPosition = iList + delta;
  518. // store away the mapper's iIndex (not the position) of the item
  519. UINT iIndex = pOrder[iList];
  520. // swap the positions
  521. DWORD itemp = pOrder[iNewPosition];
  522. pOrder[iNewPosition] = pOrder[iList];
  523. pOrder[iList] = itemp;
  524. ASSERT( pOrder[iNewPosition] == iIndex );
  525. // unfortunately, we can't just do that with the display list. We have to remove the
  526. // the item, then re-insert it. Its a flaw in the CListCtrl object. Arg.
  527. // we have to get the item too
  528. CCertMapRule* pRule = m_mapper.GetRule( iIndex );
  529. // delete the item from the display list
  530. m_clistctrl_list.DeleteItem( iList );
  531. // re-insert it
  532. int iNew = AddRuleToList( pRule, iIndex, iNewPosition );
  533. // make sure it is visible in the list
  534. m_clistctrl_list.EnsureVisible( iNew, FALSE );
  535. // finally, because its been removed and re-inserted, we need to
  536. // re-select it as well - CListCtrl is such a pain at this
  537. LV_ITEM lv;
  538. ZeroMemory( &lv, sizeof(lv) );
  539. lv.mask = LVIF_STATE;
  540. lv.iItem = iNew;
  541. lv.state = LVIS_SELECTED;
  542. lv.stateMask = LVIS_SELECTED;
  543. m_clistctrl_list.SetItem( &lv );
  544. // activate the apply button
  545. SetModified();
  546. m_fDirty = TRUE;
  547. }
  548. //---------------------------------------------------------------------------
  549. void CMapWildcardsPge::OnMoveDown()
  550. {
  551. OnMove( 1 );
  552. }
  553. //---------------------------------------------------------------------------
  554. void CMapWildcardsPge::OnMoveUp()
  555. {
  556. OnMove( -1 );
  557. }
  558. //---------------------------------------------------------------------------
  559. void CMapWildcardsPge::OnAdd()
  560. {
  561. CHAR sz[256];
  562. // create the new rule
  563. CCertMapRule * pNewRule = new CCertMapRule();
  564. if (pNewRule == NULL)
  565. return;
  566. // give the new rule some defaults
  567. LoadStringA(::AfxGetInstanceHandle(), IDS_DEFAULT_RULE, sz, 255 );
  568. pNewRule->SetRuleName( sz );
  569. pNewRule->SetRuleEnabled( TRUE );
  570. // Edit the rule. If it fails, remove it from the list
  571. if ( !EditOneRule( pNewRule, TRUE ) )
  572. {
  573. // kill the rule and return
  574. delete pNewRule;
  575. return;
  576. }
  577. // make a new mapper & get its index
  578. DWORD iNewRule = m_mapper.AddRule( pNewRule );
  579. // add the rule to the end of the display list. - It is added to the
  580. // end of the rule list by default
  581. AddRuleToList( pNewRule, iNewRule );
  582. // make sure it is visible in the list
  583. m_clistctrl_list.EnsureVisible( iNewRule, FALSE );
  584. // activate the apply button
  585. SetModified();
  586. m_fDirty = TRUE;
  587. }
  588. //---------------------------------------------------------------------------
  589. void CMapWildcardsPge::OnDelete()
  590. {
  591. // ask the user to confirm this decision
  592. if ( AfxMessageBox(IDS_CONFIRM_DELETE, MB_OKCANCEL) != IDOK )
  593. return;
  594. CWaitCursor wait;
  595. // loop through the selected items, setting each one's mapping
  596. int iList = -1;
  597. while( (iList = m_clistctrl_list.GetNextItem( -1, LVNI_SELECTED )) >= 0 )
  598. {
  599. // get the mapper index for the item
  600. // IA64 - this is OK to cast to DWORD as it is just an index
  601. DWORD iMapper = (DWORD)m_clistctrl_list.GetItemData( iList );
  602. // delete the mapping from the mapper
  603. m_mapper.DeleteRule( iMapper );
  604. // delete the entry from the list box
  605. m_clistctrl_list.DeleteItem( iList );
  606. // because the index in the mapper for all the items below this
  607. // one changes when it is deleted, we must go and fix them all.
  608. DWORD numItems = m_clistctrl_list.GetItemCount();
  609. for ( DWORD iFix = iList; iFix < numItems; iFix++ )
  610. {
  611. // get the mapper index for the item to be fixed
  612. // IA64 - this is OK to cast to DWORD as it is just an index
  613. iMapper = (DWORD)m_clistctrl_list.GetItemData( iFix );
  614. // decrement it to reflect the change
  615. iMapper--;
  616. // put it back.
  617. m_clistctrl_list.SetItemData( iFix, iMapper );
  618. }
  619. }
  620. // activate the apply button
  621. SetModified();
  622. m_fDirty = TRUE;
  623. }
  624. //---------------------------------------------------------------------------
  625. void CMapWildcardsPge::OnEdit()
  626. {
  627. int iList;
  628. DWORD iRule;
  629. CCertMapRule* pUpdateRule;
  630. // what happens here depends on if just one mapping is selected, or many
  631. switch( m_clistctrl_list.GetSelectedCount() )
  632. {
  633. case 0: // do nothing - should not get here because button grays out
  634. ASSERT( FALSE );
  635. break;
  636. case 1: // get the mapping for update and run single edit dialog
  637. // get index of the selected list item
  638. iList = m_clistctrl_list.GetNextItem( -1, LVNI_SELECTED );
  639. ASSERT( iList >= 0 );
  640. // get the mapper index for the item
  641. // IA64 - this is OK to cast to DWORD as it is just an index
  642. iRule = (DWORD)m_clistctrl_list.GetItemData( iList );
  643. // get the mapping item for updating purposes
  644. pUpdateRule = m_mapper.GetRule( iRule );
  645. if ( !pUpdateRule )
  646. {
  647. AfxMessageBox( IDS_ERR_ACCESS_MAPPING );
  648. break;
  649. }
  650. // edit the mapping, update it if successful, delete if not
  651. if ( EditOneRule(pUpdateRule) )
  652. {
  653. UpdateRuleInDispList( iList, pUpdateRule );
  654. // activate the apply button
  655. SetModified();
  656. m_fDirty = TRUE;
  657. }
  658. break;
  659. default: // run the multi edit dialog
  660. EditMultipleRules();
  661. break;
  662. }
  663. }
  664. //---------------------------------------------------------------------------
  665. void CMapWildcardsPge::OnItemchangedList(NMHDR* pNMHDR, LRESULT* pResult)
  666. {
  667. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  668. *pResult = 0;
  669. // enable the correct items
  670. EnableDependantButtons();
  671. }
  672. //---------------------------------------------------------------------------
  673. void CMapWildcardsPge::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
  674. {
  675. *pResult = 0;
  676. // if something in the list was double clicked, edit it
  677. if ( m_clistctrl_list.GetSelectedCount() > 0 )
  678. OnEdit();
  679. }
  680. //---------------------------------------------------------------------------
  681. void CMapWildcardsPge::OnEnable()
  682. {
  683. // activate the apply button
  684. SetModified();
  685. m_fDirty = TRUE;
  686. }