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.

616 lines
14 KiB

  1. //
  2. // Driver Verifier UI
  3. // Copyright (c) Microsoft Corporation, 1999
  4. //
  5. //
  6. //
  7. // module: DiskPage.cpp
  8. // author: DMihai
  9. // created: 11/7/01
  10. //
  11. // Description:
  12. //
  13. #include "stdafx.h"
  14. #include "verifier.h"
  15. #include "DiskPage.h"
  16. #include "VrfUtil.h"
  17. #include "VGlobal.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. //
  24. // Help IDs
  25. //
  26. static DWORD MyHelpIds[] =
  27. {
  28. IDC_DISKLIST_LIST, IDH_DV_DisksEnabled_Disk_FullList,
  29. 0, 0
  30. };
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CDiskListPage property page
  33. IMPLEMENT_DYNCREATE(CDiskListPage, CVerifierPropertyPage)
  34. CDiskListPage::CDiskListPage()
  35. : CVerifierPropertyPage(CDiskListPage::IDD)
  36. {
  37. //{{AFX_DATA_INIT(CDiskListPage)
  38. //}}AFX_DATA_INIT
  39. m_nSortColumnIndex = 1;
  40. m_bAscendSortSelected = FALSE;
  41. m_bAscendSortName = TRUE;
  42. }
  43. CDiskListPage::~CDiskListPage()
  44. {
  45. }
  46. void CDiskListPage::DoDataExchange(CDataExchange* pDX)
  47. {
  48. CVerifierPropertyPage::DoDataExchange(pDX);
  49. //{{AFX_DATA_MAP(CDiskListPage)
  50. DDX_Control(pDX, IDC_DISKLIST_LIST, m_DiskList);
  51. DDX_Control(pDX, IDC_DISKLIST_NEXT_DESCR_STATIC, m_NextDescription);
  52. //}}AFX_DATA_MAP
  53. }
  54. BEGIN_MESSAGE_MAP(CDiskListPage, CVerifierPropertyPage)
  55. //{{AFX_MSG_MAP(CDiskListPage)
  56. ON_NOTIFY(LVN_COLUMNCLICK, IDC_DISKLIST_LIST, OnColumnclickDiskList)
  57. ON_WM_CONTEXTMENU()
  58. ON_MESSAGE( WM_HELP, OnHelp )
  59. //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61. /////////////////////////////////////////////////////////////////////////////
  62. VOID CDiskListPage::SetupListHeader()
  63. {
  64. CString strTitle;
  65. CRect rectWnd;
  66. LVCOLUMN lvColumn;
  67. //
  68. // The list's rectangle
  69. //
  70. m_DiskList.GetClientRect( &rectWnd );
  71. ZeroMemory( &lvColumn,
  72. sizeof( lvColumn ) );
  73. lvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
  74. lvColumn.fmt = LVCFMT_LEFT;
  75. //
  76. // Column 0
  77. //
  78. VERIFY( strTitle.LoadString( IDS_ENABLED_QUESTION ) );
  79. lvColumn.iSubItem = 0;
  80. lvColumn.cx = (int)( rectWnd.Width() * 0.12 );
  81. lvColumn.pszText = strTitle.GetBuffer( strTitle.GetLength() + 1 );
  82. if (NULL != lvColumn.pszText)
  83. {
  84. VERIFY( m_DiskList.InsertColumn( 0, &lvColumn ) != -1 );
  85. strTitle.ReleaseBuffer();
  86. }
  87. else
  88. {
  89. lvColumn.pszText = g_szVoidText;
  90. VERIFY( m_DiskList.InsertColumn( 0, &lvColumn ) != -1 );
  91. }
  92. //
  93. // Column 1
  94. //
  95. VERIFY( strTitle.LoadString( IDS_DISK ) );
  96. lvColumn.iSubItem = 1;
  97. lvColumn.cx = (int)( rectWnd.Width() * 0.87 );
  98. lvColumn.pszText = strTitle.GetBuffer( strTitle.GetLength() + 1 );
  99. if (NULL != lvColumn.pszText)
  100. {
  101. VERIFY( m_DiskList.InsertColumn( 1, &lvColumn ) != -1 );
  102. strTitle.ReleaseBuffer();
  103. }
  104. else
  105. {
  106. lvColumn.pszText = g_szVoidText;
  107. VERIFY( m_DiskList.InsertColumn( 1, &lvColumn ) != -1 );
  108. }
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. VOID CDiskListPage::FillTheList()
  112. {
  113. INT_PTR nDisksNo;
  114. INT_PTR nCrtDiskIndex;
  115. CDiskData *pCrtDiskData;
  116. const CDiskDataArray &DiskDataArray = g_NewVerifierSettings.m_aDiskData;
  117. m_DiskList.DeleteAllItems();
  118. //
  119. // Parse the driver data array
  120. //
  121. nDisksNo = DiskDataArray.GetSize();
  122. for( nCrtDiskIndex = 0; nCrtDiskIndex < nDisksNo; nCrtDiskIndex += 1)
  123. {
  124. pCrtDiskData = DiskDataArray.GetAt( nCrtDiskIndex );
  125. ASSERT_VALID( pCrtDiskData );
  126. AddListItem( nCrtDiskIndex,
  127. pCrtDiskData );
  128. }
  129. }
  130. /////////////////////////////////////////////////////////////////////////////
  131. BOOL CDiskListPage::GetNewVerifiedDisks()
  132. {
  133. INT nListItemCount;
  134. INT nCrtListItem;
  135. INT_PTR nCrtDisksArrayIndex;
  136. BOOL bSomeDisksVerified;
  137. BOOL bVerified;
  138. CDiskData *pCrtDiskData;
  139. CDiskDataArray &DiskDataArray = g_NewVerifierSettings.m_aDiskData;
  140. bSomeDisksVerified = FALSE;
  141. nListItemCount = m_DiskList.GetItemCount();
  142. for( nCrtListItem = 0; nCrtListItem < nListItemCount; nCrtListItem += 1 )
  143. {
  144. //
  145. // Verification status for the current list item
  146. //
  147. bVerified = m_DiskList.GetCheck( nCrtListItem );
  148. if( bVerified )
  149. {
  150. bSomeDisksVerified = TRUE;
  151. }
  152. //
  153. // Set the right verify state in our disk array
  154. //
  155. nCrtDisksArrayIndex = m_DiskList.GetItemData( nCrtListItem );
  156. pCrtDiskData = DiskDataArray.GetAt( nCrtDisksArrayIndex );
  157. ASSERT_VALID( pCrtDiskData );
  158. pCrtDiskData->m_bVerifierEnabled = bVerified;
  159. }
  160. return bSomeDisksVerified;
  161. }
  162. /////////////////////////////////////////////////////////////////////////////
  163. BOOL CDiskListPage::GetCheckFromItemData( INT nItemData )
  164. {
  165. BOOL bChecked = FALSE;
  166. INT nItemIndex;
  167. LVFINDINFO FindInfo;
  168. ZeroMemory( &FindInfo, sizeof( FindInfo ) );
  169. FindInfo.flags = LVFI_PARAM;
  170. FindInfo.lParam = nItemData;
  171. nItemIndex = m_DiskList.FindItem( &FindInfo );
  172. if( nItemIndex >= 0 )
  173. {
  174. bChecked = m_DiskList.GetCheck( nItemIndex );
  175. }
  176. return bChecked;
  177. }
  178. /////////////////////////////////////////////////////////////////////////////
  179. BOOL CDiskListPage::GetBitNameFromItemData( LPARAM lParam,
  180. TCHAR *szName,
  181. ULONG uNameBufferLength )
  182. {
  183. BOOL bSuccess = FALSE;
  184. INT nItemIndex;
  185. LVFINDINFO FindInfo;
  186. LVITEM lvItem;
  187. ZeroMemory( &FindInfo, sizeof( FindInfo ) );
  188. FindInfo.flags = LVFI_PARAM;
  189. FindInfo.lParam = lParam;
  190. nItemIndex = m_DiskList.FindItem( &FindInfo );
  191. if( nItemIndex >= 0 )
  192. {
  193. //
  194. // Found it
  195. //
  196. ZeroMemory( &lvItem, sizeof( lvItem ) );
  197. lvItem.mask = LVIF_TEXT;
  198. lvItem.iItem = nItemIndex;
  199. lvItem.iSubItem = 1;
  200. lvItem.pszText = szName;
  201. lvItem.cchTextMax = uNameBufferLength;
  202. bSuccess = m_DiskList.GetItem( &lvItem );
  203. ASSERT( bSuccess );
  204. }
  205. return bSuccess;
  206. }
  207. /////////////////////////////////////////////////////////////////////////////
  208. VOID CDiskListPage::AddListItem( INT_PTR nItemData,
  209. CDiskData *pDiskData )
  210. {
  211. INT nActualIndex;
  212. LVITEM lvItem;
  213. CString strName;
  214. ASSERT_VALID( pDiskData );
  215. ZeroMemory( &lvItem, sizeof( lvItem ) );
  216. //
  217. // Sub-item 0 - enabled/diabled - empty text and a checkbox
  218. //
  219. lvItem.pszText = g_szVoidText;
  220. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  221. lvItem.lParam = nItemData;
  222. lvItem.iItem = m_DiskList.GetItemCount();
  223. nActualIndex = m_DiskList.InsertItem( &lvItem );
  224. if( nActualIndex < 0 )
  225. {
  226. //
  227. // Could not add an item in the list - give up
  228. //
  229. goto Done;
  230. }
  231. m_DiskList.SetCheck( nActualIndex, pDiskData->m_bVerifierEnabled );
  232. //
  233. // Sub-item 1 - disk name
  234. //
  235. lvItem.pszText = pDiskData->m_strDiskDevicesForDisplay.GetBuffer(
  236. pDiskData->m_strDiskDevicesForDisplay.GetLength() + 1 );
  237. if( NULL == lvItem.pszText )
  238. {
  239. goto Done;
  240. }
  241. lvItem.mask = LVIF_TEXT;
  242. lvItem.iItem = nActualIndex;
  243. lvItem.iSubItem = 1;
  244. VERIFY( m_DiskList.SetItem( &lvItem ) );
  245. pDiskData->m_strDiskDevicesForDisplay.ReleaseBuffer();
  246. Done:
  247. //
  248. // All done
  249. //
  250. NOTHING;
  251. }
  252. /////////////////////////////////////////////////////////////
  253. VOID CDiskListPage::SortTheList()
  254. {
  255. if( 0 != m_nSortColumnIndex )
  256. {
  257. //
  258. // Sort by settings name
  259. //
  260. m_DiskList.SortItems( StringCmpFunc, (LPARAM)this );
  261. }
  262. else
  263. {
  264. //
  265. // Sort by selected status
  266. //
  267. m_DiskList.SortItems( CheckedStatusCmpFunc, (LPARAM)this );
  268. }
  269. }
  270. /////////////////////////////////////////////////////////////
  271. int CALLBACK CDiskListPage::StringCmpFunc( LPARAM lParam1,
  272. LPARAM lParam2,
  273. LPARAM lParamSort)
  274. {
  275. int nCmpRez = 0;
  276. BOOL bSuccess;
  277. TCHAR szBitName1[ _MAX_PATH ];
  278. TCHAR szBitName2[ _MAX_PATH ];
  279. CDiskListPage *pThis = (CDiskListPage *)lParamSort;
  280. ASSERT_VALID( pThis );
  281. ASSERT( 0 != pThis->m_nSortColumnIndex );
  282. //
  283. // Get the first name
  284. //
  285. bSuccess = pThis->GetBitNameFromItemData( lParam1,
  286. szBitName1,
  287. ARRAY_LENGTH( szBitName1 ) );
  288. if( FALSE == bSuccess )
  289. {
  290. goto Done;
  291. }
  292. //
  293. // Get the second name
  294. //
  295. bSuccess = pThis->GetBitNameFromItemData( lParam2,
  296. szBitName2,
  297. ARRAY_LENGTH( szBitName2 ) );
  298. if( FALSE == bSuccess )
  299. {
  300. goto Done;
  301. }
  302. //
  303. // Compare the names
  304. //
  305. nCmpRez = _tcsicmp( szBitName1, szBitName2 );
  306. if( FALSE != pThis->m_bAscendSortName )
  307. {
  308. nCmpRez *= -1;
  309. }
  310. Done:
  311. return nCmpRez;
  312. }
  313. /////////////////////////////////////////////////////////////
  314. int CALLBACK CDiskListPage::CheckedStatusCmpFunc( LPARAM lParam1,
  315. LPARAM lParam2,
  316. LPARAM lParamSort)
  317. {
  318. int nCmpRez = 0;
  319. INT nItemIndex;
  320. BOOL bVerified1;
  321. BOOL bVerified2;
  322. LVFINDINFO FindInfo;
  323. CDiskListPage *pThis = (CDiskListPage *)lParamSort;
  324. ASSERT_VALID( pThis );
  325. ASSERT( 0 == pThis->m_nSortColumnIndex );
  326. //
  327. // Find the first item
  328. //
  329. ZeroMemory( &FindInfo, sizeof( FindInfo ) );
  330. FindInfo.flags = LVFI_PARAM;
  331. FindInfo.lParam = lParam1;
  332. nItemIndex = pThis->m_DiskList.FindItem( &FindInfo );
  333. if( nItemIndex < 0 )
  334. {
  335. ASSERT( FALSE );
  336. goto Done;
  337. }
  338. bVerified1 = pThis->m_DiskList.GetCheck( nItemIndex );
  339. //
  340. // Find the second item
  341. //
  342. FindInfo.flags = LVFI_PARAM;
  343. FindInfo.lParam = lParam2;
  344. nItemIndex = pThis->m_DiskList.FindItem( &FindInfo );
  345. if( nItemIndex < 0 )
  346. {
  347. ASSERT( FALSE );
  348. goto Done;
  349. }
  350. bVerified2 = pThis->m_DiskList.GetCheck( nItemIndex );
  351. //
  352. // Compare them
  353. //
  354. if( bVerified1 != bVerified2 )
  355. {
  356. if( FALSE != bVerified1 )
  357. {
  358. nCmpRez = 1;
  359. }
  360. else
  361. {
  362. nCmpRez = -1;
  363. }
  364. if( FALSE != pThis->m_bAscendSortSelected )
  365. {
  366. nCmpRez *= -1;
  367. }
  368. }
  369. Done:
  370. return nCmpRez;
  371. }
  372. /////////////////////////////////////////////////////////////////////////////
  373. // CDiskListPage message handlers
  374. BOOL CDiskListPage::OnWizardFinish()
  375. {
  376. BOOL bExitTheApp;
  377. bExitTheApp = FALSE;
  378. if( GetNewVerifiedDisks() == TRUE )
  379. {
  380. g_NewVerifierSettings.SaveToRegistry();
  381. //
  382. // Exit the app
  383. //
  384. bExitTheApp = CVerifierPropertyPage::OnWizardFinish();
  385. }
  386. else
  387. {
  388. VrfErrorResourceFormat( IDS_SELECT_AT_LEAST_ONE_DISK );
  389. }
  390. return bExitTheApp;
  391. }
  392. /////////////////////////////////////////////////////////////////////////////
  393. BOOL CDiskListPage::OnInitDialog()
  394. {
  395. CVerifierPropertyPage::OnInitDialog();
  396. //
  397. // setup the list
  398. //
  399. m_DiskList.SetExtendedStyle(
  400. LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES | m_DiskList.GetExtendedStyle() );
  401. SetupListHeader();
  402. FillTheList();
  403. VrfSetWindowText( m_NextDescription, IDS_DISKLIST_PAGE_FINISH_DESCR );
  404. return TRUE; // return TRUE unless you set the focus to a control
  405. // EXCEPTION: OCX Property Pages should return FALSE
  406. }
  407. /////////////////////////////////////////////////////////////////////////////
  408. void CDiskListPage::OnColumnclickDiskList(NMHDR* pNMHDR, LRESULT* pResult)
  409. {
  410. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  411. if( 0 != pNMListView->iSubItem )
  412. {
  413. //
  414. // Clicked on the name column
  415. //
  416. if( m_nSortColumnIndex == pNMListView->iSubItem )
  417. {
  418. //
  419. // Change the current ascend/descend order for this column
  420. //
  421. m_bAscendSortName = !m_bAscendSortName;
  422. }
  423. }
  424. else
  425. {
  426. //
  427. // Clicked on the selected status column
  428. //
  429. if( m_nSortColumnIndex == pNMListView->iSubItem )
  430. {
  431. //
  432. // Change the current ascend/descend order for this column
  433. //
  434. m_bAscendSortSelected = !m_bAscendSortSelected;
  435. }
  436. }
  437. m_nSortColumnIndex = pNMListView->iSubItem;
  438. SortTheList();
  439. *pResult = 0;
  440. }
  441. /////////////////////////////////////////////////////////////////////////////
  442. BOOL CDiskListPage::OnSetActive()
  443. {
  444. //
  445. // This is always the last page of the wizard.
  446. //
  447. m_pParentSheet->SetWizardButtons( PSWIZB_BACK |
  448. PSWIZB_FINISH );
  449. return CVerifierPropertyPage::OnSetActive();
  450. }
  451. /////////////////////////////////////////////////////////////
  452. LONG CDiskListPage::OnHelp( WPARAM wParam, LPARAM lParam )
  453. {
  454. LONG lResult = 0;
  455. LPHELPINFO lpHelpInfo = (LPHELPINFO)lParam;
  456. ::WinHelp(
  457. (HWND) lpHelpInfo->hItemHandle,
  458. g_szVerifierHelpFile,
  459. HELP_WM_HELP,
  460. (DWORD_PTR) MyHelpIds );
  461. return lResult;
  462. }
  463. /////////////////////////////////////////////////////////////////////////////
  464. void CDiskListPage::OnContextMenu(CWnd* pWnd, CPoint point)
  465. {
  466. ::WinHelp(
  467. pWnd->m_hWnd,
  468. g_szVerifierHelpFile,
  469. HELP_CONTEXTMENU,
  470. (DWORD_PTR) MyHelpIds );
  471. }