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.

563 lines
13 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1998
  3. All rights reserved.
  4. Module Name:
  5. driverdt.cxx
  6. Abstract:
  7. Driver details dialog
  8. Author:
  9. Steve Kiraly (SteveKi) 23-Jan-1997
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "driverif.hxx"
  15. #include "driverlv.hxx"
  16. #include "driverdt.hxx"
  17. /********************************************************************
  18. Server Drivers Details Dialog.
  19. ********************************************************************/
  20. TDriverDetails::
  21. TDriverDetails(
  22. IN HWND hwnd,
  23. IN TDriverInfo *pDriverInfo
  24. ) : _hWnd( hwnd ),
  25. _bValid( TRUE ),
  26. _pDriverInfo( pDriverInfo ),
  27. _hwndLV( NULL ),
  28. _ColumnSortState( kMaxColumns ),
  29. _uCurrentColumn( 0 )
  30. {
  31. }
  32. TDriverDetails::
  33. ~TDriverDetails(
  34. VOID
  35. )
  36. {
  37. }
  38. BOOL
  39. TDriverDetails::
  40. bValid(
  41. VOID
  42. )
  43. {
  44. return _bValid;
  45. }
  46. BOOL
  47. TDriverDetails::
  48. bDoModal(
  49. VOID
  50. )
  51. {
  52. BOOL bReturn = FALSE;
  53. UINT iMsg = 0;
  54. if( _pDriverInfo->vGetInfoState() == TDriverInfo::kInstalled )
  55. {
  56. bReturn = (BOOL)DialogBoxParam( ghInst,
  57. MAKEINTRESOURCE( DLG_DRIVER_DETAILS ),
  58. _hWnd,
  59. MGenericDialog::SetupDlgProc,
  60. (LPARAM)this );
  61. }
  62. else if( _pDriverInfo->vGetInfoState() == TDriverInfo::kAdd )
  63. {
  64. iMsg = IDS_DRIVER_ADD_NEEDS_APPLY;
  65. }
  66. else if( _pDriverInfo->vGetInfoState() == TDriverInfo::kUpdate )
  67. {
  68. iMsg = IDS_DRIVER_UPDATE_NEEDS_APPLY;
  69. }
  70. if( iMsg )
  71. {
  72. bReturn = iMessage( _hWnd,
  73. IDS_DRIVER_DETAILS_TITLE,
  74. iMsg,
  75. MB_OK|MB_ICONSTOP,
  76. kMsgNone,
  77. NULL );
  78. }
  79. return bReturn;
  80. }
  81. BOOL
  82. TDriverDetails::
  83. bSetUI(
  84. VOID
  85. )
  86. {
  87. SPLASSERT( _pDriverInfo );
  88. //
  89. // Get handle to the driver file list view.
  90. //
  91. _hwndLV = GetDlgItem( _hDlg, IDC_DRIVER_FILE_LIST_VIEW );
  92. TStatusB bStatus;
  93. TString strString;
  94. LPCTSTR pszFile;
  95. LPCTSTR pszPath;
  96. LPCTSTR pszExt;
  97. TCHAR szScratch[MAX_PATH];
  98. TString strTemp;
  99. //
  100. // Build the list view header.
  101. //
  102. bStatus DBGCHK = bBuildListViewHeader();
  103. //
  104. // Save a flag that indicates this is a win9x printer driver.
  105. //
  106. bStatus DBGCHK = strTemp.bLoadString( ghInst, IDS_ENVIRONMENT_WIN95 );
  107. BOOL bIsWindows9xDriver = !_tcsicmp( _pDriverInfo->strEnv(), strTemp );
  108. //
  109. // Set the edit controls.
  110. //
  111. bStatus DBGCHK = bSetEditText( _hDlg, IDC_DRIVER_DETAIL_NAME, _pDriverInfo->strName() );
  112. bStatus DBGCHK = bSetEditText( _hDlg, IDC_DRIVER_VERSION, _pDriverInfo->strVersion() );
  113. bStatus DBGCHK = bSetEditText( _hDlg, IDC_DRIVER_ENVIRONMENT, _pDriverInfo->strEnvironment() );
  114. bStatus DBGCHK = bSetEditText( _hDlg, IDC_DRIVER_LANGUAGE_MONITOR, _pDriverInfo->strMonitorName() );
  115. bStatus DBGCHK = bSetEditText( _hDlg, IDC_DRIVER_DEFAULT_DATA_TYPE, _pDriverInfo->strDefaultDataType() );
  116. bStatus DBGCHK = bSplitPath( szScratch, NULL, &pszPath, NULL, _pDriverInfo->strDriverPath() );
  117. bStatus DBGCHK = bSetEditText( _hDlg, IDC_DRIVER_PATH, pszPath );
  118. UINT uCount = 0;
  119. bStatus DBGCHK = bSplitPath( szScratch, &pszFile, NULL, NULL, _pDriverInfo->strHelpFile() );
  120. bStatus DBGCHK = bAddListViewItem( IDS_DRIVER_HELP_FILE, pszFile, &uCount );
  121. bStatus DBGCHK = bSplitPath( szScratch, &pszFile, NULL, NULL, _pDriverInfo->strConfigFile() );
  122. bStatus DBGCHK = bAddListViewItem( IDS_DRIVER_CONFIG_FILE, pszFile, &uCount );
  123. bStatus DBGCHK = bSplitPath( szScratch, &pszFile, NULL, NULL, _pDriverInfo->strDataFile() );
  124. bStatus DBGCHK = bAddListViewItem( IDS_DRIVER_DATA_FILE, pszFile, &uCount );
  125. bStatus DBGCHK = bSplitPath( szScratch, &pszFile, NULL, NULL, _pDriverInfo->strDriverPath() );
  126. bStatus DBGCHK = bAddListViewItem( IDS_DRIVER_PATH, pszFile, &uCount );
  127. for( LPCTSTR psz = _pDriverInfo->strDependentFiles(); psz && *psz; psz += _tcslen( psz ) + 1 )
  128. {
  129. bStatus DBGCHK = bSplitPath( szScratch, &pszFile, NULL, &pszExt, psz );
  130. if( bIsWindows9xDriver && pszExt && ( !_tcsicmp( pszExt, TEXT("ICM" ) ) || !_tcsicmp( pszExt, TEXT("ICC" ) ) ) )
  131. {
  132. bStatus DBGCHK = strTemp.bFormat( TEXT("%s\\%s"), TEXT("Color"), pszFile );
  133. }
  134. else
  135. {
  136. bStatus DBGCHK = strTemp.bUpdate( pszFile );
  137. }
  138. bStatus DBGCHK = bAddListViewItem( IDS_DRIVER_DEPENDENT_FILE, strTemp, &uCount );
  139. }
  140. //
  141. // Default is the properties disabled, until an item is selected.
  142. //
  143. vEnableCtl( _hDlg, IDC_DRIVER_PROPERTIES, FALSE );
  144. //
  145. // Select the first item in the list view.
  146. //
  147. ListView_SetItemState( _hwndLV, 0, LVIS_SELECTED | LVIS_FOCUSED, 0x000F );
  148. ListView_EnsureVisible( _hwndLV, 0, FALSE );
  149. return TRUE;
  150. }
  151. BOOL
  152. TDriverDetails::
  153. bBuildListViewHeader(
  154. VOID
  155. )
  156. {
  157. //
  158. // Initialize the LV_COLUMN structure.
  159. //
  160. LV_COLUMN lvc;
  161. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  162. lvc.fmt = LVCFMT_LEFT;
  163. lvc.cx = kDefaultHeaderWidth;
  164. //
  165. // Calculate the header column width.
  166. //
  167. RECT rc;
  168. if( GetClientRect( _hwndLV, &rc ))
  169. {
  170. lvc.cx = rc.right / kHeaderMax;
  171. }
  172. //
  173. // Set the column header text.
  174. //
  175. TStatusB bStatus;
  176. bStatus DBGNOCHK = TRUE;
  177. TString strHeader;
  178. for( INT iCol = 0; iCol < kHeaderMax; ++iCol )
  179. {
  180. bStatus DBGCHK = strHeader.bLoadString( ghInst, IDS_DRIVER_FILE_HEAD_NAME + iCol );
  181. lvc.pszText = const_cast<LPTSTR>( static_cast<LPCTSTR>( strHeader ) );
  182. lvc.iSubItem = iCol;
  183. if( ListView_InsertColumn( _hwndLV, iCol, &lvc ) == -1 )
  184. {
  185. DBGMSG( DBG_WARN, ( "DriverFileLV.bSetUI: LV_Insert failed %d\n", GetLastError( )));
  186. bStatus DBGCHK = FALSE;
  187. }
  188. }
  189. //
  190. // Enable full row selection.
  191. //
  192. if( bStatus )
  193. {
  194. LRESULT dwExStyle = SendMessage( _hwndLV, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0 );
  195. SendMessage( _hwndLV, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwExStyle | LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP );
  196. }
  197. return bStatus;
  198. }
  199. BOOL
  200. TDriverDetails::
  201. bAddListViewItem(
  202. IN UINT uDescription,
  203. IN LPCTSTR pszFileName,
  204. IN UINT *pcItems
  205. )
  206. {
  207. //
  208. // All aguments must be valid.
  209. //
  210. if( !uDescription || !pszFileName || !*pszFileName || !pcItems )
  211. {
  212. return TRUE;
  213. }
  214. TStatusB bStatus;
  215. TString strDescription;
  216. //
  217. // Load the description resource string.
  218. //
  219. bStatus DBGCHK = strDescription.bLoadString( ghInst, uDescription );
  220. //
  221. // Allocate the detail data.
  222. //
  223. DetailData *pDetailData = new DetailData;
  224. if( pDetailData )
  225. {
  226. DBGMSG( DBG_TRACE, ( "New Item %x\n", pDetailData ) );
  227. bStatus DBGCHK = pDetailData->strDescription.bUpdate( strDescription );
  228. bStatus DBGCHK = pDetailData->strFileName.bUpdate( pszFileName );
  229. }
  230. //
  231. // Add information to the listview.
  232. //
  233. LV_ITEM lvi = { 0 };
  234. lvi.mask = LVIF_TEXT | LVIF_PARAM;
  235. lvi.iItem = *pcItems;
  236. lvi.pszText = const_cast<LPTSTR>( static_cast<LPCTSTR>( strDescription ) );
  237. lvi.lParam = (LPARAM)pDetailData;
  238. ListView_InsertItem( _hwndLV, &lvi );
  239. ListView_SetItemText( _hwndLV, *pcItems, 1, const_cast<LPTSTR>( pszFileName ) );
  240. *pcItems = *pcItems + 1;
  241. return TRUE;
  242. }
  243. BOOL
  244. TDriverDetails::
  245. bHandleProperties(
  246. VOID
  247. )
  248. {
  249. TStatusB bStatus;
  250. bStatus DBGNOCHK = FALSE;
  251. //
  252. // Get the selected item.
  253. //
  254. INT iItem = ListView_GetNextItem( _hwndLV, -1, LVNI_SELECTED );
  255. if( iItem != -1 )
  256. {
  257. TCHAR szFileName[MAX_PATH];
  258. //
  259. // Retrieve the selected item text.
  260. //
  261. ListView_GetItemText( _hwndLV, iItem, 1, szFileName, COUNTOF( szFileName ) );
  262. //
  263. // Build the fully qualified file path.
  264. //
  265. TString strFullName;
  266. bStatus DBGCHK = bGetEditText( _hDlg, IDC_DRIVER_PATH, strFullName );
  267. bStatus DBGCHK = strFullName.bCat( gszWack );
  268. bStatus DBGCHK = strFullName.bCat( szFileName );
  269. //
  270. // Show the shell file object properties.
  271. //
  272. TLibrary Lib( gszShellDllName );
  273. if( VALID_OBJ( Lib ) )
  274. {
  275. typedef BOOL ( WINAPI *pfSHObjectProperties)(HWND hwndOwner, DWORD dwType, LPCTSTR lpObject, LPCTSTR lpPage);
  276. pfSHObjectProperties pSHObjectProperties = reinterpret_cast<pfSHObjectProperties>( Lib.pfnGetProc( 178 ) );
  277. if( pSHObjectProperties )
  278. {
  279. pSHObjectProperties( _hDlg, 2, strFullName, 0 );
  280. }
  281. }
  282. bStatus DBGNOCHK = TRUE;
  283. }
  284. return bStatus;
  285. }
  286. BOOL
  287. TDriverDetails::
  288. bSortListView(
  289. IN LPARAM lParam
  290. )
  291. {
  292. //
  293. // Get the column number.
  294. //
  295. _uCurrentColumn = ((NM_LISTVIEW *)lParam)->iSubItem;
  296. //
  297. // Sort the list view items.
  298. //
  299. TStatusB bStatus;
  300. bStatus DBGCHK = ListView_SortItems( _hwndLV, iCompareProc, (LPARAM)this );
  301. //
  302. // Toggle the specified column sort state.
  303. //
  304. _ColumnSortState.bToggle( _uCurrentColumn );
  305. return bStatus;
  306. }
  307. VOID
  308. TDriverDetails::
  309. vDeleteItems(
  310. VOID
  311. )
  312. {
  313. //
  314. // Delete all the items. This is done one at a time
  315. // inorder to see delete item notifications.
  316. //
  317. for( ; ; )
  318. {
  319. if( !ListView_DeleteItem( _hwndLV, 0 ) )
  320. break;
  321. }
  322. }
  323. INT
  324. CALLBACK
  325. TDriverDetails::
  326. iCompareProc(
  327. IN LPARAM lParam1,
  328. IN LPARAM lParam2,
  329. IN LPARAM RefData
  330. )
  331. {
  332. TDriverDetails *pDetails = reinterpret_cast<TDriverDetails *>( RefData );
  333. DetailData *pDetail1 = reinterpret_cast<DetailData *>( lParam1 );
  334. DetailData *pDetail2 = reinterpret_cast<DetailData *>( lParam2 );
  335. LPCTSTR psz1 = NULL;
  336. LPCTSTR psz2 = NULL;
  337. BOOL bStatus = TRUE;
  338. INT iResult = 0;
  339. if( pDetails && pDetail1 && pDetail2 )
  340. {
  341. switch ( pDetails->_uCurrentColumn )
  342. {
  343. case 0:
  344. psz1 = pDetail1->strDescription;
  345. psz2 = pDetail2->strDescription;
  346. break;
  347. case 1:
  348. psz1 = pDetail1->strFileName;
  349. psz2 = pDetail2->strFileName;
  350. break;
  351. default:
  352. bStatus = FALSE;
  353. break;
  354. }
  355. if( bStatus )
  356. {
  357. if( pDetails->_ColumnSortState.bRead( pDetails->_uCurrentColumn ) )
  358. iResult = _tcsicmp( psz1, psz2 );
  359. else
  360. iResult = _tcsicmp( psz2, psz1 );
  361. }
  362. }
  363. return iResult;
  364. }
  365. BOOL
  366. TDriverDetails::
  367. bDeleteDetailData(
  368. IN LPARAM lParam
  369. )
  370. {
  371. NM_LISTVIEW *pnmv = (NM_LISTVIEW *) lParam;
  372. LV_ITEM lvItem = { 0 };
  373. lvItem.mask = LVIF_PARAM;
  374. lvItem.iItem = pnmv->iItem;
  375. BOOL bStatus;
  376. bStatus = ListView_GetItem( _hwndLV, &lvItem );
  377. if( bStatus )
  378. {
  379. DetailData *pDetailData = reinterpret_cast<DetailData *>( lvItem.lParam );
  380. DBGMSG( DBG_TRACE, ( "Delete Item %x\n", pDetailData ) );
  381. delete pDetailData;
  382. }
  383. return bStatus;
  384. }
  385. BOOL
  386. TDriverDetails::
  387. bHandleItemSelected(
  388. VOID
  389. ) const
  390. {
  391. BOOL bState = ListView_GetNextItem( _hwndLV, -1, LVNI_SELECTED | LVNI_FOCUSED ) != -1 ? TRUE : FALSE;
  392. vEnableCtl( _hDlg, IDC_DRIVER_PROPERTIES, bState );
  393. return TRUE;
  394. }
  395. BOOL
  396. TDriverDetails::
  397. bHandleMessage(
  398. IN UINT uMsg,
  399. IN WPARAM wParam,
  400. IN LPARAM lParam
  401. )
  402. {
  403. BOOL bStatus = TRUE;
  404. switch (uMsg)
  405. {
  406. case WM_INITDIALOG:
  407. bSetUI();
  408. break;
  409. //
  410. // Handle help and context help.
  411. //
  412. case WM_HELP:
  413. case WM_CONTEXTMENU:
  414. bStatus = PrintUIHelp( uMsg, _hDlg, wParam, lParam );
  415. break;
  416. case WM_COMMAND:
  417. switch ( LOWORD( wParam ) )
  418. {
  419. case IDOK:
  420. case IDCANCEL:
  421. vDeleteItems();
  422. EndDialog( _hDlg, LOWORD( wParam ) );
  423. break;
  424. case IDC_DRIVER_PROPERTIES:
  425. bStatus = bHandleProperties();
  426. break;
  427. default:
  428. bStatus = FALSE;
  429. break;
  430. }
  431. break;
  432. case WM_NOTIFY:
  433. {
  434. LPNMHDR pnmh = (LPNMHDR)lParam;
  435. switch( pnmh->code )
  436. {
  437. case NM_CLICK:
  438. bStatus = bHandleItemSelected();
  439. break;
  440. case NM_DBLCLK:
  441. bStatus = bHandleProperties();
  442. break;
  443. case LVN_COLUMNCLICK:
  444. bStatus = bSortListView( lParam );
  445. break;
  446. case LVN_DELETEITEM:
  447. bStatus = bDeleteDetailData( lParam );
  448. break;
  449. case LVN_ITEMCHANGED:
  450. bStatus = bHandleItemSelected();
  451. break;
  452. default:
  453. bStatus = FALSE;
  454. break;
  455. }
  456. }
  457. break;
  458. default:
  459. bStatus = FALSE;
  460. break;
  461. }
  462. return bStatus;
  463. }