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.

529 lines
13 KiB

  1. //
  2. // Driver Verifier UI
  3. // Copyright (c) Microsoft Corporation, 1999
  4. //
  5. //
  6. // module: CDLPage.cpp
  7. // author: DMihai
  8. // created: 11/1/00
  9. //
  10. #include "stdafx.h"
  11. #include "verifier.h"
  12. #include "CDLPage.h"
  13. #include "VrfUtil.h"
  14. #include "VGlobal.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. //
  21. // Help IDs
  22. //
  23. static DWORD MyHelpIds[] =
  24. {
  25. IDC_CONFDRV_LIST, IDH_DV_UnsignedDriversList,
  26. 0, 0
  27. };
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CConfirmDriverListPage property page
  30. IMPLEMENT_DYNCREATE(CConfirmDriverListPage, CVerifierPropertyPage)
  31. CConfirmDriverListPage::CConfirmDriverListPage()
  32. : CVerifierPropertyPage(CConfirmDriverListPage::IDD)
  33. {
  34. //{{AFX_DATA_INIT(CConfirmDriverListPage)
  35. // NOTE: the ClassWizard will add member initialization here
  36. //}}AFX_DATA_INIT
  37. m_pParentSheet = NULL;
  38. m_nSortColumnIndex = 0;
  39. m_bAscendSortDrvName = FALSE;
  40. m_bAscendSortProvName = FALSE;
  41. }
  42. CConfirmDriverListPage::~CConfirmDriverListPage()
  43. {
  44. }
  45. void CConfirmDriverListPage::DoDataExchange(CDataExchange* pDX)
  46. {
  47. CVerifierPropertyPage::DoDataExchange(pDX);
  48. //{{AFX_DATA_MAP(CConfirmDriverListPage)
  49. DDX_Control(pDX, IDC_CONFDRV_NEXT_DESCR_STATIC, m_NextDescription);
  50. DDX_Control(pDX, IDC_CONFDRV_TITLE_STATIC, m_TitleStatic);
  51. DDX_Control(pDX, IDC_CONFDRV_LIST, m_DriversList);
  52. //}}AFX_DATA_MAP
  53. }
  54. BEGIN_MESSAGE_MAP(CConfirmDriverListPage, CVerifierPropertyPage)
  55. //{{AFX_MSG_MAP(CConfirmDriverListPage)
  56. ON_NOTIFY(LVN_COLUMNCLICK, IDC_CONFDRV_LIST, OnColumnclickConfdrvList)
  57. ON_WM_CONTEXTMENU()
  58. ON_MESSAGE( WM_HELP, OnHelp )
  59. //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61. /////////////////////////////////////////////////////////////////////////////
  62. VOID CConfirmDriverListPage::SetupListHeader()
  63. {
  64. LVCOLUMN lvColumn;
  65. CString strName;
  66. CString strDescription;
  67. CRect rectWnd;
  68. VERIFY( strName.LoadString( IDS_NAME ) );
  69. VERIFY( strDescription.LoadString( IDS_DESCRIPTION ) );
  70. //
  71. // list's regtangle
  72. //
  73. m_DriversList.GetClientRect( &rectWnd );
  74. //
  75. // Column 0
  76. //
  77. memset( &lvColumn, 0, sizeof( lvColumn ) );
  78. lvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
  79. lvColumn.fmt = LVCFMT_LEFT;
  80. lvColumn.iSubItem = 0;
  81. lvColumn.cx = (int)( rectWnd.Width() * 0.30 );
  82. lvColumn.pszText = strName.GetBuffer( strName.GetLength() + 1 );
  83. if (NULL != lvColumn.pszText)
  84. {
  85. VERIFY( m_DriversList.InsertColumn( 0, &lvColumn ) != -1 );
  86. strName.ReleaseBuffer();
  87. }
  88. else
  89. {
  90. lvColumn.pszText = g_szVoidText;
  91. VERIFY( m_DriversList.InsertColumn( 0, &lvColumn ) != -1 );
  92. }
  93. //
  94. // Column 1
  95. //
  96. lvColumn.iSubItem = 1;
  97. lvColumn.cx = (int)( rectWnd.Width() * 0.65 );
  98. lvColumn.pszText = strDescription.GetBuffer( strDescription.GetLength() + 1 );
  99. if (NULL != lvColumn.pszText)
  100. {
  101. VERIFY( m_DriversList.InsertColumn( 1, &lvColumn ) != -1 );
  102. strDescription.ReleaseBuffer();
  103. }
  104. else
  105. {
  106. lvColumn.pszText = g_szVoidText;
  107. VERIFY( m_DriversList.InsertColumn( 1, &lvColumn ) != -1 );
  108. }
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. VOID CConfirmDriverListPage::FillTheList()
  112. {
  113. INT_PTR nDriversNo;
  114. INT_PTR nCrtDriverIndex;
  115. CDriverData *pCrtDrvData;
  116. const CDriverDataArray &DrvDataArray = g_NewVerifierSettings.m_DriversSet.m_aDriverData;
  117. m_DriversList.DeleteAllItems();
  118. //
  119. // Parse the driver data array
  120. //
  121. nDriversNo = DrvDataArray.GetSize();
  122. for( nCrtDriverIndex = 0; nCrtDriverIndex < nDriversNo; nCrtDriverIndex += 1)
  123. {
  124. pCrtDrvData = DrvDataArray.GetAt( nCrtDriverIndex );
  125. ASSERT_VALID( pCrtDrvData );
  126. if( g_NewVerifierSettings.m_DriversSet.ShouldDriverBeVerified( pCrtDrvData ) )
  127. {
  128. AddListItem( nCrtDriverIndex,
  129. pCrtDrvData );
  130. }
  131. }
  132. }
  133. /////////////////////////////////////////////////////////////////////////////
  134. VOID CConfirmDriverListPage::AddListItem( INT_PTR nIndexInArray, CDriverData *pCrtDrvData )
  135. {
  136. INT nActualIndex;
  137. LVITEM lvItem;
  138. ASSERT_VALID( pCrtDrvData );
  139. ZeroMemory( &lvItem, sizeof( lvItem ) );
  140. //
  141. // LVITEM's member pszText is not a const pointer
  142. // so we need to GetBuffer here :-(
  143. //
  144. //
  145. // Sub-item 0
  146. //
  147. lvItem.pszText = pCrtDrvData->m_strName.GetBuffer( pCrtDrvData->m_strName.GetLength() + 1 );
  148. if( NULL == lvItem.pszText )
  149. {
  150. goto Done;
  151. }
  152. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  153. lvItem.lParam = nIndexInArray;
  154. lvItem.iItem = m_DriversList.GetItemCount();
  155. lvItem.iSubItem = 0;
  156. nActualIndex = m_DriversList.InsertItem( &lvItem );
  157. pCrtDrvData->m_strName.ReleaseBuffer();
  158. if( nActualIndex < 0 )
  159. {
  160. //
  161. // Could not add an item in the list - give up
  162. //
  163. goto Done;
  164. }
  165. //
  166. // Sub-item 1
  167. //
  168. lvItem.pszText = pCrtDrvData->m_strFileDescription.GetBuffer(
  169. pCrtDrvData->m_strFileDescription.GetLength() + 1 );
  170. if( NULL == lvItem.pszText )
  171. {
  172. goto Done;
  173. }
  174. lvItem.mask = LVIF_TEXT;
  175. lvItem.iItem = nActualIndex;
  176. lvItem.iSubItem = 1;
  177. m_DriversList.SetItem( &lvItem );
  178. pCrtDrvData->m_strFileDescription.ReleaseBuffer();
  179. Done:
  180. //
  181. // All done
  182. //
  183. NOTHING;
  184. }
  185. /////////////////////////////////////////////////////////////////////////////
  186. BOOL CConfirmDriverListPage::SetContextStrings( ULONG uTitleResId )
  187. {
  188. return m_strTitle.LoadString( uTitleResId );
  189. }
  190. /////////////////////////////////////////////////////////////
  191. VOID CConfirmDriverListPage::SortTheList()
  192. {
  193. m_DriversList.SortItems( StringCmpFunc, (LPARAM)this );
  194. }
  195. /////////////////////////////////////////////////////////////
  196. int CALLBACK CConfirmDriverListPage::StringCmpFunc( LPARAM lParam1,
  197. LPARAM lParam2,
  198. LPARAM lParamSort)
  199. {
  200. int nCmpRez = 0;
  201. BOOL bSuccess;
  202. CString strName1;
  203. CString strName2;
  204. CConfirmDriverListPage *pThis = (CConfirmDriverListPage *)lParamSort;
  205. ASSERT_VALID( pThis );
  206. //
  207. // Get the first name
  208. //
  209. bSuccess = pThis->GetColumnStrValue( lParam1,
  210. strName1 );
  211. if( FALSE == bSuccess )
  212. {
  213. goto Done;
  214. }
  215. //
  216. // Get the second name
  217. //
  218. bSuccess = pThis->GetColumnStrValue( lParam2,
  219. strName2 );
  220. if( FALSE == bSuccess )
  221. {
  222. goto Done;
  223. }
  224. //
  225. // Compare the names
  226. //
  227. nCmpRez = strName1.CompareNoCase( strName2 );
  228. if( 0 == pThis->m_nSortColumnIndex )
  229. {
  230. //
  231. // Sort by driver name
  232. //
  233. if( FALSE != pThis->m_bAscendSortDrvName )
  234. {
  235. nCmpRez *= -1;
  236. }
  237. }
  238. else
  239. {
  240. //
  241. // Sort by provider name
  242. //
  243. if( FALSE != pThis->m_bAscendSortProvName )
  244. {
  245. nCmpRez *= -1;
  246. }
  247. }
  248. Done:
  249. return nCmpRez;
  250. }
  251. /////////////////////////////////////////////////////////////
  252. BOOL CConfirmDriverListPage::GetColumnStrValue( LPARAM lItemData,
  253. CString &strName )
  254. {
  255. CDriverData *pCrtDrvData;
  256. pCrtDrvData = g_NewVerifierSettings.m_DriversSet.m_aDriverData.GetAt( (INT_PTR) lItemData );
  257. ASSERT_VALID( pCrtDrvData );
  258. if( 0 == m_nSortColumnIndex )
  259. {
  260. //
  261. // Sort by driver name
  262. //
  263. strName = pCrtDrvData->m_strName;
  264. }
  265. else
  266. {
  267. //
  268. // Sort by provider name
  269. //
  270. strName = pCrtDrvData->m_strCompanyName;
  271. }
  272. return TRUE;
  273. }
  274. /////////////////////////////////////////////////////////////////////////////
  275. BOOL CConfirmDriverListPage::OnSetActive()
  276. {
  277. INT nItemsInList;
  278. BOOL bResult;
  279. m_TitleStatic.SetWindowText( m_strTitle );
  280. FillTheList();
  281. SortTheList();
  282. nItemsInList = m_DriversList.GetItemCount();
  283. if( nItemsInList < 1 )
  284. {
  285. //
  286. // No drivers have been selected to be verified
  287. //
  288. bResult = FALSE;
  289. }
  290. else
  291. {
  292. if( (FALSE == g_bShowDiskPropertyPage) &&
  293. (FALSE == g_NewVerifierSettings.m_aDiskData.VerifyAnyDisk()) )
  294. {
  295. //
  296. // This is the last step of the wizard
  297. //
  298. m_pParentSheet->SetWizardButtons( PSWIZB_BACK |
  299. PSWIZB_FINISH );
  300. VrfSetWindowText( m_NextDescription, IDS_CONFDRV_PAGE_NEXT_DESCR_FINISH );
  301. }
  302. else
  303. {
  304. //
  305. // We need to show the "select disks" page at the end.
  306. //
  307. m_pParentSheet->SetWizardButtons( PSWIZB_BACK |
  308. PSWIZB_NEXT );
  309. VrfSetWindowText( m_NextDescription, IDS_CONFDRV_PAGE_NEXT_DESCR_NEXT );
  310. }
  311. bResult = CVerifierPropertyPage::OnSetActive();
  312. }
  313. return bResult;
  314. }
  315. /////////////////////////////////////////////////////////////////////////////
  316. // CConfirmDriverListPage message handlers
  317. BOOL CConfirmDriverListPage::OnInitDialog()
  318. {
  319. CVerifierPropertyPage::OnInitDialog();
  320. //
  321. // Setup the list
  322. //
  323. m_DriversList.SetExtendedStyle(
  324. LVS_EX_FULLROWSELECT | m_DriversList.GetExtendedStyle() );
  325. SetupListHeader();
  326. return TRUE; // return TRUE unless you set the focus to a control
  327. // EXCEPTION: OCX Property Pages should return FALSE
  328. }
  329. /////////////////////////////////////////////////////////////////////////////
  330. BOOL CConfirmDriverListPage::OnWizardFinish()
  331. {
  332. //
  333. // The disk verifier should be disabled if we got here.
  334. //
  335. ASSERT( FALSE == g_bShowDiskPropertyPage );
  336. ASSERT( FALSE == g_NewVerifierSettings.m_aDiskData.VerifyAnyDisk() );
  337. CVerifierPropertyPage::OnWizardFinish();
  338. return g_NewVerifierSettings.SaveToRegistry();
  339. }
  340. /////////////////////////////////////////////////////////////////////////////
  341. LRESULT CConfirmDriverListPage::OnWizardNext()
  342. {
  343. LRESULT lNextPageId;
  344. //
  345. // The disk verifier should be enabled if we got here.
  346. //
  347. ASSERT( FALSE != g_bShowDiskPropertyPage ||
  348. FALSE != g_NewVerifierSettings.m_aDiskData.VerifyAnyDisk() );
  349. lNextPageId = IDD_DISK_LIST_PAGE;
  350. GoingToNextPageNotify( lNextPageId );
  351. return lNextPageId;
  352. }
  353. /////////////////////////////////////////////////////////////////////////////
  354. void CConfirmDriverListPage::OnColumnclickConfdrvList(NMHDR* pNMHDR, LRESULT* pResult)
  355. {
  356. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  357. if( 0 != pNMListView->iSubItem )
  358. {
  359. //
  360. // Clicked on the provider name column
  361. //
  362. if( m_nSortColumnIndex == pNMListView->iSubItem )
  363. {
  364. //
  365. // Change the current ascend/descend order for this column
  366. //
  367. m_bAscendSortProvName = !m_bAscendSortProvName;
  368. }
  369. }
  370. else
  371. {
  372. //
  373. // Clicked on the driver name column
  374. //
  375. if( m_nSortColumnIndex == pNMListView->iSubItem )
  376. {
  377. //
  378. // Change the current ascend/descend order for this column
  379. //
  380. m_bAscendSortDrvName = !m_bAscendSortDrvName;
  381. }
  382. }
  383. m_nSortColumnIndex = pNMListView->iSubItem;
  384. SortTheList();
  385. *pResult = 0;
  386. }
  387. /////////////////////////////////////////////////////////////
  388. LONG CConfirmDriverListPage::OnHelp( WPARAM wParam, LPARAM lParam )
  389. {
  390. LONG lResult = 0;
  391. LPHELPINFO lpHelpInfo = (LPHELPINFO)lParam;
  392. ::WinHelp(
  393. (HWND) lpHelpInfo->hItemHandle,
  394. g_szVerifierHelpFile,
  395. HELP_WM_HELP,
  396. (DWORD_PTR) MyHelpIds );
  397. return lResult;
  398. }
  399. /////////////////////////////////////////////////////////////////////////////
  400. void CConfirmDriverListPage::OnContextMenu(CWnd* pWnd, CPoint point)
  401. {
  402. ::WinHelp(
  403. pWnd->m_hWnd,
  404. g_szVerifierHelpFile,
  405. HELP_CONTEXTMENU,
  406. (DWORD_PTR) MyHelpIds );
  407. }