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.

469 lines
11 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.pszText = strName.GetBuffer( strName.GetLength() + 1 );
  82. lvColumn.cx = (int)( rectWnd.Width() * 0.30 );
  83. VERIFY( m_DriversList.InsertColumn( 0, &lvColumn ) != -1 );
  84. strName.ReleaseBuffer();
  85. //
  86. // Column 1
  87. //
  88. lvColumn.iSubItem = 1;
  89. lvColumn.pszText = strDescription.GetBuffer( strDescription.GetLength() + 1 );
  90. lvColumn.cx = (int)( rectWnd.Width() * 0.65 );
  91. VERIFY( m_DriversList.InsertColumn( 1, &lvColumn ) != -1 );
  92. strDescription.ReleaseBuffer();
  93. }
  94. /////////////////////////////////////////////////////////////////////////////
  95. VOID CConfirmDriverListPage::FillTheList()
  96. {
  97. INT_PTR nDriversNo;
  98. INT_PTR nCrtDriverIndex;
  99. CDriverData *pCrtDrvData;
  100. const CDriverDataArray &DrvDataArray = g_NewVerifierSettings.m_DriversSet.m_aDriverData;
  101. m_DriversList.DeleteAllItems();
  102. //
  103. // Parse the driver data array
  104. //
  105. nDriversNo = DrvDataArray.GetSize();
  106. for( nCrtDriverIndex = 0; nCrtDriverIndex < nDriversNo; nCrtDriverIndex += 1)
  107. {
  108. pCrtDrvData = DrvDataArray.GetAt( nCrtDriverIndex );
  109. ASSERT_VALID( pCrtDrvData );
  110. if( g_NewVerifierSettings.m_DriversSet.ShouldDriverBeVerified( pCrtDrvData ) )
  111. {
  112. AddListItem( nCrtDriverIndex,
  113. pCrtDrvData );
  114. }
  115. }
  116. }
  117. /////////////////////////////////////////////////////////////////////////////
  118. VOID CConfirmDriverListPage::AddListItem( INT_PTR nIndexInArray, CDriverData *pCrtDrvData )
  119. {
  120. INT nActualIndex;
  121. LVITEM lvItem;
  122. ASSERT_VALID( pCrtDrvData );
  123. ZeroMemory( &lvItem, sizeof( lvItem ) );
  124. //
  125. // LVITEM's member pszText is not a const pointer
  126. // so we need to GetBuffer here :-(
  127. //
  128. //
  129. // Sub-item 0
  130. //
  131. lvItem.pszText = pCrtDrvData->m_strName.GetBuffer( pCrtDrvData->m_strName.GetLength() + 1 );
  132. if( NULL == lvItem.pszText )
  133. {
  134. goto Done;
  135. }
  136. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  137. lvItem.lParam = nIndexInArray;
  138. lvItem.iItem = m_DriversList.GetItemCount();
  139. lvItem.iSubItem = 0;
  140. nActualIndex = m_DriversList.InsertItem( &lvItem );
  141. pCrtDrvData->m_strName.ReleaseBuffer();
  142. if( nActualIndex < 0 )
  143. {
  144. //
  145. // Could not add an item in the list - give up
  146. //
  147. goto Done;
  148. }
  149. //
  150. // Sub-item 1
  151. //
  152. lvItem.pszText = pCrtDrvData->m_strFileDescription.GetBuffer(
  153. pCrtDrvData->m_strFileDescription.GetLength() + 1 );
  154. if( NULL == lvItem.pszText )
  155. {
  156. goto Done;
  157. }
  158. lvItem.mask = LVIF_TEXT;
  159. lvItem.iItem = nActualIndex;
  160. lvItem.iSubItem = 1;
  161. m_DriversList.SetItem( &lvItem );
  162. pCrtDrvData->m_strFileDescription.ReleaseBuffer();
  163. Done:
  164. //
  165. // All done
  166. //
  167. NOTHING;
  168. }
  169. /////////////////////////////////////////////////////////////////////////////
  170. BOOL CConfirmDriverListPage::SetContextStrings( ULONG uTitleResId )
  171. {
  172. return m_strTitle.LoadString( uTitleResId );
  173. }
  174. /////////////////////////////////////////////////////////////
  175. VOID CConfirmDriverListPage::SortTheList()
  176. {
  177. m_DriversList.SortItems( StringCmpFunc, (LPARAM)this );
  178. }
  179. /////////////////////////////////////////////////////////////
  180. int CALLBACK CConfirmDriverListPage::StringCmpFunc( LPARAM lParam1,
  181. LPARAM lParam2,
  182. LPARAM lParamSort)
  183. {
  184. int nCmpRez = 0;
  185. BOOL bSuccess;
  186. CString strName1;
  187. CString strName2;
  188. CConfirmDriverListPage *pThis = (CConfirmDriverListPage *)lParamSort;
  189. ASSERT_VALID( pThis );
  190. //
  191. // Get the first name
  192. //
  193. bSuccess = pThis->GetColumnStrValue( lParam1,
  194. strName1 );
  195. if( FALSE == bSuccess )
  196. {
  197. goto Done;
  198. }
  199. //
  200. // Get the second name
  201. //
  202. bSuccess = pThis->GetColumnStrValue( lParam2,
  203. strName2 );
  204. if( FALSE == bSuccess )
  205. {
  206. goto Done;
  207. }
  208. //
  209. // Compare the names
  210. //
  211. nCmpRez = strName1.CompareNoCase( strName2 );
  212. if( 0 == pThis->m_nSortColumnIndex )
  213. {
  214. //
  215. // Sort by driver name
  216. //
  217. if( FALSE != pThis->m_bAscendSortDrvName )
  218. {
  219. nCmpRez *= -1;
  220. }
  221. }
  222. else
  223. {
  224. //
  225. // Sort by provider name
  226. //
  227. if( FALSE != pThis->m_bAscendSortProvName )
  228. {
  229. nCmpRez *= -1;
  230. }
  231. }
  232. Done:
  233. return nCmpRez;
  234. }
  235. /////////////////////////////////////////////////////////////
  236. BOOL CConfirmDriverListPage::GetColumnStrValue( LPARAM lItemData,
  237. CString &strName )
  238. {
  239. CDriverData *pCrtDrvData;
  240. pCrtDrvData = g_NewVerifierSettings.m_DriversSet.m_aDriverData.GetAt( (INT_PTR) lItemData );
  241. ASSERT_VALID( pCrtDrvData );
  242. if( 0 == m_nSortColumnIndex )
  243. {
  244. //
  245. // Sort by driver name
  246. //
  247. strName = pCrtDrvData->m_strName;
  248. }
  249. else
  250. {
  251. //
  252. // Sort by provider name
  253. //
  254. strName = pCrtDrvData->m_strCompanyName;
  255. }
  256. return TRUE;
  257. }
  258. /////////////////////////////////////////////////////////////////////////////
  259. BOOL CConfirmDriverListPage::OnSetActive()
  260. {
  261. INT nItemsInList;
  262. BOOL bResult;
  263. m_TitleStatic.SetWindowText( m_strTitle );
  264. FillTheList();
  265. SortTheList();
  266. nItemsInList = m_DriversList.GetItemCount();
  267. if( nItemsInList < 1 )
  268. {
  269. //
  270. // No drivers have been selected to be verified
  271. //
  272. bResult = FALSE;
  273. }
  274. else
  275. {
  276. //
  277. // This is the last step of the wizard
  278. //
  279. m_pParentSheet->SetWizardButtons( PSWIZB_BACK |
  280. PSWIZB_FINISH );
  281. bResult = CVerifierPropertyPage::OnSetActive();
  282. }
  283. return bResult;
  284. }
  285. /////////////////////////////////////////////////////////////////////////////
  286. // CConfirmDriverListPage message handlers
  287. BOOL CConfirmDriverListPage::OnInitDialog()
  288. {
  289. CVerifierPropertyPage::OnInitDialog();
  290. //
  291. // Setup the list
  292. //
  293. m_DriversList.SetExtendedStyle(
  294. LVS_EX_FULLROWSELECT | m_DriversList.GetExtendedStyle() );
  295. SetupListHeader();
  296. VrfSetWindowText( m_NextDescription, IDS_CONFDRV_PAGE_NEXT_DESCR_FINISH );
  297. return TRUE; // return TRUE unless you set the focus to a control
  298. // EXCEPTION: OCX Property Pages should return FALSE
  299. }
  300. /////////////////////////////////////////////////////////////////////////////
  301. BOOL CConfirmDriverListPage::OnWizardFinish()
  302. {
  303. CVerifierPropertyPage::OnWizardFinish();
  304. return g_NewVerifierSettings.SaveToRegistry();
  305. }
  306. /////////////////////////////////////////////////////////////////////////////
  307. void CConfirmDriverListPage::OnColumnclickConfdrvList(NMHDR* pNMHDR, LRESULT* pResult)
  308. {
  309. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  310. if( 0 != pNMListView->iSubItem )
  311. {
  312. //
  313. // Clicked on the provider name column
  314. //
  315. if( m_nSortColumnIndex == pNMListView->iSubItem )
  316. {
  317. //
  318. // Change the current ascend/descend order for this column
  319. //
  320. m_bAscendSortProvName = !m_bAscendSortProvName;
  321. }
  322. }
  323. else
  324. {
  325. //
  326. // Clicked on the driver name column
  327. //
  328. if( m_nSortColumnIndex == pNMListView->iSubItem )
  329. {
  330. //
  331. // Change the current ascend/descend order for this column
  332. //
  333. m_bAscendSortDrvName = !m_bAscendSortDrvName;
  334. }
  335. }
  336. m_nSortColumnIndex = pNMListView->iSubItem;
  337. SortTheList();
  338. *pResult = 0;
  339. }
  340. /////////////////////////////////////////////////////////////
  341. LONG CConfirmDriverListPage::OnHelp( WPARAM wParam, LPARAM lParam )
  342. {
  343. LONG lResult = 0;
  344. LPHELPINFO lpHelpInfo = (LPHELPINFO)lParam;
  345. ::WinHelp(
  346. (HWND) lpHelpInfo->hItemHandle,
  347. g_szVerifierHelpFile,
  348. HELP_WM_HELP,
  349. (DWORD_PTR) MyHelpIds );
  350. return lResult;
  351. }
  352. /////////////////////////////////////////////////////////////////////////////
  353. void CConfirmDriverListPage::OnContextMenu(CWnd* pWnd, CPoint point)
  354. {
  355. ::WinHelp(
  356. pWnd->m_hWnd,
  357. g_szVerifierHelpFile,
  358. HELP_CONTEXTMENU,
  359. (DWORD_PTR) MyHelpIds );
  360. }