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.

532 lines
12 KiB

  1. //
  2. // Application Verifier UI
  3. // Copyright (c) Microsoft Corporation, 2001
  4. //
  5. //
  6. //
  7. // module: ViewSett.cpp
  8. // author: DMihai
  9. // created: 02/22/2001
  10. //
  11. // Description:
  12. //
  13. // "View current registry settings" wizard page class.
  14. //
  15. #include "stdafx.h"
  16. #include "appverif.h"
  17. #include "ViewSett.h"
  18. #include "AVUtil.h"
  19. #include "Setting.h"
  20. #include "AVGlobal.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. //
  27. // Help IDs
  28. //
  29. static DWORD MyHelpIds[] =
  30. {
  31. 0, 0
  32. };
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CViewSettPage property page
  35. IMPLEMENT_DYNCREATE(CViewSettPage, CAppverifPage)
  36. CViewSettPage::CViewSettPage() : CAppverifPage(CViewSettPage::IDD)
  37. {
  38. //{{AFX_DATA_INIT(CViewSettPage)
  39. // NOTE: the ClassWizard will add member initialization here
  40. //}}AFX_DATA_INIT
  41. }
  42. CViewSettPage::~CViewSettPage()
  43. {
  44. }
  45. void CViewSettPage::DoDataExchange(CDataExchange* pDX)
  46. {
  47. CAppverifPage::DoDataExchange(pDX);
  48. //{{AFX_DATA_MAP(CViewSettPage)
  49. DDX_Control(pDX, IDC_VIEWSETT_UPPER_STATIC, m_UpperStatic);
  50. DDX_Control(pDX, IDC_VIEWSETT_NEXTDESCR_STATIC, m_NextDescription);
  51. DDX_Control(pDX, IDC_VIEWSETT_BITS_LIST, m_BitsList);
  52. DDX_Control(pDX, IDC_VIEWSETT_APPS_LIST, m_AppsList);
  53. //}}AFX_DATA_MAP
  54. }
  55. BEGIN_MESSAGE_MAP(CViewSettPage, CAppverifPage)
  56. //{{AFX_MSG_MAP(CViewSettPage)
  57. ON_MESSAGE( WM_HELP, OnHelp )
  58. ON_WM_CONTEXTMENU()
  59. ON_NOTIFY(LVN_ITEMCHANGED, IDC_VIEWSETT_APPS_LIST, OnItemchangedAppsList)
  60. //}}AFX_MSG_MAP
  61. END_MESSAGE_MAP()
  62. /////////////////////////////////////////////////////////////////////////////
  63. ULONG CViewSettPage::GetDialogId() const
  64. {
  65. return IDD_VIEWSETT_PAGE;
  66. }
  67. /////////////////////////////////////////////////////////////////////////////
  68. VOID CViewSettPage::SetupListHeaderApps()
  69. {
  70. CString strTitle;
  71. CRect rectWnd;
  72. LVCOLUMN lvColumn;
  73. //
  74. // The list's rectangle
  75. //
  76. m_AppsList.GetClientRect( &rectWnd );
  77. ZeroMemory( &lvColumn,
  78. sizeof( lvColumn ) );
  79. lvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
  80. lvColumn.fmt = LVCFMT_LEFT;
  81. //
  82. // Column 0 - enabled or not
  83. //
  84. VERIFY( strTitle.LoadString( IDS_FILE_NAME ) );
  85. lvColumn.pszText = strTitle.GetBuffer( strTitle.GetLength() + 1 );
  86. if( NULL == lvColumn.pszText )
  87. {
  88. goto Done;
  89. }
  90. lvColumn.iSubItem = 0;
  91. lvColumn.cx = (int)( rectWnd.Width() * 0.98 );
  92. VERIFY( m_AppsList.InsertColumn( 0, &lvColumn ) != -1 );
  93. strTitle.ReleaseBuffer();
  94. Done:
  95. NOTHING;
  96. }
  97. /////////////////////////////////////////////////////////////////////////////
  98. VOID CViewSettPage::SetupListHeaderBits()
  99. {
  100. CString strTitle;
  101. CRect rectWnd;
  102. LVCOLUMN lvColumn;
  103. //
  104. // The list's rectangle
  105. //
  106. m_BitsList.GetClientRect( &rectWnd );
  107. ZeroMemory( &lvColumn,
  108. sizeof( lvColumn ) );
  109. lvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
  110. lvColumn.fmt = LVCFMT_LEFT;
  111. //
  112. // Column 0 - Bit name
  113. //
  114. VERIFY( strTitle.LoadString( IDS_TEST_TYPE ) );
  115. lvColumn.pszText = strTitle.GetBuffer( strTitle.GetLength() + 1 );
  116. if( NULL == lvColumn.pszText )
  117. {
  118. goto Done;
  119. }
  120. lvColumn.iSubItem = 0;
  121. lvColumn.cx = (int)( rectWnd.Width() * 0.70 );
  122. VERIFY( m_BitsList.InsertColumn( 0, &lvColumn ) != -1 );
  123. strTitle.ReleaseBuffer();
  124. //
  125. // Column 0 - Enabled?
  126. //
  127. VERIFY( strTitle.LoadString( IDS_ENABLED_QUESTION ) );
  128. lvColumn.pszText = strTitle.GetBuffer( strTitle.GetLength() + 1 );
  129. if( NULL == lvColumn.pszText )
  130. {
  131. goto Done;
  132. }
  133. lvColumn.iSubItem = 1;
  134. lvColumn.cx = (int)( rectWnd.Width() * 0.29 );
  135. VERIFY( m_BitsList.InsertColumn( 1, &lvColumn ) != -1 );
  136. strTitle.ReleaseBuffer();
  137. Done:
  138. NOTHING;
  139. }
  140. /////////////////////////////////////////////////////////////////////////////
  141. VOID CViewSettPage::FillTheLists()
  142. {
  143. INT_PTR nAppsNo;
  144. INT_PTR nCrtAppAppsIndex;
  145. CAppAndBits *pCrtPair;
  146. m_AppsList.DeleteAllItems();
  147. nAppsNo = g_aAppsAndBitsFromRegistry.GetSize();
  148. if( 0 == nAppsNo )
  149. {
  150. //
  151. /// No apps are verified
  152. //
  153. m_BitsList.DeleteAllItems();
  154. AVSetWindowText( m_UpperStatic, IDS_NO_APPS_VERIFIED );
  155. }
  156. else
  157. {
  158. AVSetWindowText( m_UpperStatic, IDS_VERIFIED_APPS );
  159. }
  160. for( nCrtAppAppsIndex = 0; nCrtAppAppsIndex < nAppsNo; nCrtAppAppsIndex += 1 )
  161. {
  162. pCrtPair = g_aAppsAndBitsFromRegistry.GetAt( nCrtAppAppsIndex );
  163. ASSERT_VALID( pCrtPair );
  164. AddListItemApps( pCrtPair,
  165. nCrtAppAppsIndex );
  166. }
  167. if( nAppsNo > 0 )
  168. {
  169. m_AppsList.SetItemState( 0,
  170. LVIS_FOCUSED | LVIS_SELECTED,
  171. LVIS_FOCUSED | LVIS_SELECTED );
  172. }
  173. }
  174. /////////////////////////////////////////////////////////////////////////////
  175. VOID CViewSettPage::UpdateBitsList( CAppAndBits *pCrtPair )
  176. {
  177. INT nItemsInList;
  178. INT nCrtItem;
  179. ASSERT_VALID( pCrtPair );
  180. nItemsInList = m_BitsList.GetItemCount();
  181. if( nItemsInList != ARRAY_LENGTH( g_AllNamesAndBits ) )
  182. {
  183. //
  184. // The bits list is empty - fill it out first
  185. //
  186. if( FillBitsList() != TRUE )
  187. {
  188. //
  189. // Could not fill the list?!?
  190. //
  191. goto Done;
  192. }
  193. }
  194. for( nCrtItem = 0; nCrtItem < ARRAY_LENGTH( g_AllNamesAndBits ); nCrtItem += 1)
  195. {
  196. UpdateListItemBits( pCrtPair,
  197. nCrtItem );
  198. }
  199. Done:
  200. NOTHING;
  201. }
  202. /////////////////////////////////////////////////////////////////////////////
  203. VOID CViewSettPage::UpdateListItemBits( CAppAndBits *pCrtPair,
  204. INT nCrtItem )
  205. {
  206. LVITEM lvItem;
  207. CString strEnabled;
  208. ZeroMemory( &lvItem, sizeof( lvItem ) );
  209. ASSERT( nCrtItem >= 0 && nCrtItem < ARRAY_LENGTH( g_AllNamesAndBits ) );
  210. ASSERT( nCrtItem < m_BitsList.GetItemCount() );
  211. if( ( pCrtPair->m_dwEnabledBits & g_AllNamesAndBits[ nCrtItem ].m_dwBit ) != 0 )
  212. {
  213. //
  214. // This bit is enabled
  215. //
  216. VERIFY( AVLoadString( IDS_YES,
  217. strEnabled ) );
  218. }
  219. else
  220. {
  221. //
  222. // This bit is disabled
  223. //
  224. VERIFY( AVLoadString( IDS_NO,
  225. strEnabled ) );
  226. }
  227. //
  228. // Sub-item 1 - enabled/disabled
  229. //
  230. lvItem.pszText = strEnabled.GetBuffer( strEnabled.GetLength() + 1 );
  231. if( NULL == lvItem.pszText )
  232. {
  233. goto Done;
  234. }
  235. lvItem.mask = LVIF_TEXT;
  236. lvItem.iItem = nCrtItem;
  237. lvItem.iSubItem = 1;
  238. VERIFY( m_BitsList.SetItem( &lvItem ) );
  239. strEnabled.ReleaseBuffer();
  240. Done:
  241. NOTHING;
  242. }
  243. /////////////////////////////////////////////////////////////////////////////
  244. VOID CViewSettPage::UpdateBitsListFromSelectedApp()
  245. {
  246. INT nItems;
  247. INT nCrtItem;
  248. INT_PTR nCrtAppIndex;
  249. BOOL bUpdated;
  250. CAppAndBits *pCrtPair;
  251. bUpdated = FALSE;
  252. nItems = m_AppsList.GetItemCount();
  253. for( nCrtItem = 0; nCrtItem < nItems; nCrtItem += 1 )
  254. {
  255. if( m_AppsList.GetItemState( nCrtItem, LVIS_SELECTED ) & LVIS_SELECTED )
  256. {
  257. nCrtAppIndex = (INT_PTR) m_AppsList.GetItemData( nCrtItem );
  258. pCrtPair = g_aAppsAndBitsFromRegistry.GetAt( nCrtAppIndex );
  259. ASSERT_VALID( pCrtPair );
  260. UpdateBitsList( pCrtPair );
  261. bUpdated = TRUE;
  262. break;
  263. }
  264. }
  265. if( FALSE == bUpdated )
  266. {
  267. m_BitsList.DeleteAllItems();
  268. }
  269. }
  270. /////////////////////////////////////////////////////////////////////////////
  271. BOOL CViewSettPage::FillBitsList()
  272. {
  273. BOOL bSuccess;
  274. INT_PTR nCrtBitIndex;
  275. INT nActualItemIndex;
  276. LVITEM lvItem;
  277. TCHAR szBitName[ 64 ];
  278. bSuccess = FALSE;
  279. ZeroMemory( &lvItem, sizeof( lvItem ) );
  280. m_BitsList.DeleteAllItems();
  281. for( nCrtBitIndex = 0; nCrtBitIndex < ARRAY_LENGTH( g_AllNamesAndBits ); nCrtBitIndex += 1 )
  282. {
  283. if( AVLoadString( g_AllNamesAndBits[ nCrtBitIndex ].m_uNameStringId,
  284. szBitName,
  285. ARRAY_LENGTH( szBitName ) ) != TRUE )
  286. {
  287. goto Done;
  288. }
  289. lvItem.pszText = szBitName;
  290. lvItem.mask = LVIF_TEXT;
  291. lvItem.iItem = m_BitsList.GetItemCount();
  292. nActualItemIndex = m_BitsList.InsertItem( &lvItem );
  293. if( nActualItemIndex != lvItem.iItem )
  294. {
  295. //
  296. // Could not insert the item?!?
  297. //
  298. m_BitsList.DeleteAllItems();
  299. goto Done;
  300. }
  301. }
  302. bSuccess = TRUE;
  303. Done:
  304. return bSuccess;
  305. }
  306. /////////////////////////////////////////////////////////////////////////////
  307. INT CViewSettPage::AddListItemApps( CAppAndBits *pCrtPair,
  308. INT_PTR nIndexInArray )
  309. {
  310. INT nActualIndex;
  311. LVITEM lvItem;
  312. nActualIndex = -1;
  313. ZeroMemory( &lvItem, sizeof( lvItem ) );
  314. //
  315. // LVITEM's member pszText is not a const pointer
  316. // so we need to GetBuffer here :-(
  317. //
  318. //
  319. // Sub-item 0 - the name of the app
  320. //
  321. lvItem.pszText = pCrtPair->m_strAppName.GetBuffer( pCrtPair->m_strAppName.GetLength() + 1 );
  322. if( NULL == lvItem.pszText )
  323. {
  324. goto Done;
  325. }
  326. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  327. lvItem.lParam = nIndexInArray;
  328. lvItem.iItem = m_BitsList.GetItemCount();
  329. nActualIndex = m_AppsList.InsertItem( &lvItem );
  330. pCrtPair->m_strAppName.ReleaseBuffer();
  331. Done:
  332. //
  333. // All done
  334. //
  335. return nActualIndex;
  336. }
  337. /////////////////////////////////////////////////////////////////////////////
  338. // CViewSettPage message handlers
  339. /////////////////////////////////////////////////////////////
  340. LONG CViewSettPage::OnHelp( WPARAM wParam, LPARAM lParam )
  341. {
  342. LONG lResult = 0;
  343. LPHELPINFO lpHelpInfo = (LPHELPINFO)lParam;
  344. ::WinHelp(
  345. (HWND) lpHelpInfo->hItemHandle,
  346. g_szAVHelpFile,
  347. HELP_WM_HELP,
  348. (DWORD_PTR) MyHelpIds );
  349. return lResult;
  350. }
  351. /////////////////////////////////////////////////////////////////////////////
  352. void CViewSettPage::OnContextMenu(CWnd* pWnd, CPoint point)
  353. {
  354. ::WinHelp(
  355. pWnd->m_hWnd,
  356. g_szAVHelpFile,
  357. HELP_CONTEXTMENU,
  358. (DWORD_PTR) MyHelpIds );
  359. }
  360. /////////////////////////////////////////////////////////////////////////////
  361. BOOL CViewSettPage::OnSetActive()
  362. {
  363. ASSERT_VALID( m_pParentSheet );
  364. m_pParentSheet->SetWizardButtons(
  365. PSWIZB_BACK | PSWIZB_FINISH );
  366. //
  367. // Read the current registry settings and fille out the lists
  368. //
  369. AVReadCrtRegistrySettings();
  370. FillTheLists();
  371. return CAppverifPage::OnSetActive();
  372. }
  373. /////////////////////////////////////////////////////////////////////////////
  374. BOOL CViewSettPage::OnInitDialog()
  375. {
  376. CAppverifPage::OnInitDialog();
  377. m_BitsList.SetExtendedStyle(
  378. LVS_EX_FULLROWSELECT );
  379. m_AppsList.SetExtendedStyle(
  380. LVS_EX_FULLROWSELECT );
  381. //
  382. // Setup our list and fill it out if we already have something in the app names array
  383. //
  384. SetupListHeaderApps();
  385. SetupListHeaderBits();
  386. //
  387. // Display the description of the next step
  388. //
  389. AVSetWindowText( m_NextDescription, IDS_VIEWSETT_NEXT_DESCR );
  390. return TRUE; // return TRUE unless you set the focus to a control
  391. // EXCEPTION: OCX Property Pages should return FALSE
  392. }
  393. /////////////////////////////////////////////////////////////////////////////
  394. void CViewSettPage::OnItemchangedAppsList(NMHDR* pNMHDR, LRESULT* pResult)
  395. {
  396. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  397. if( ( pNMListView->uChanged & LVIF_STATE ) != 0 &&
  398. ( pNMListView->uNewState & LVIS_SELECTED) != ( pNMListView->uOldState & LVIS_SELECTED) )
  399. {
  400. UpdateBitsListFromSelectedApp();
  401. }
  402. *pResult = 0;
  403. }