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.

815 lines
16 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1995 - 1998
  3. All rights reserved.
  4. Module Name:
  5. F:\nt\private\windows\spooler\printui.pri\procdlg.cxx
  6. Abstract:
  7. Print Processor dialog.
  8. Author:
  9. Steve Kiraly (SteveKi) 11/10/95
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "procdlg.hxx"
  15. #include "psetup.hxx"
  16. #include "drvver.hxx"
  17. /********************************************************************
  18. Print Processor Dialog class
  19. ********************************************************************/
  20. /*++
  21. Routine Name:
  22. TPrintProcessor
  23. Routine Description:
  24. Contstucts the print processor dialog.
  25. Arguments:
  26. hWnd - Parent window handle
  27. strServerName - Currnet printer server name
  28. strPrintProcessor - Current print processor
  29. strDatatype - Current datatype
  30. Return Value:
  31. Nothing. bValid() inidicated valid object.
  32. --*/
  33. TPrintProcessor::
  34. TPrintProcessor(
  35. IN HWND hWnd,
  36. IN LPCTSTR pszServerName,
  37. IN TString &strPrintProcessor,
  38. IN TString &strDatatype,
  39. IN BOOL bAdministrator
  40. ) : _hWnd( hWnd ),
  41. _pPrintProcessors( NULL ),
  42. _cPrintProcessors( 0 ),
  43. _hctlPrintProcessorList( 0 ),
  44. _hctlDatatypeList( 0 ),
  45. _bAdministrator( bAdministrator ),
  46. _bValid( FALSE ),
  47. _pszServerName( pszServerName )
  48. {
  49. DBGMSG( DBG_TRACE, ( "TPrintProcessor::ctor\n") );
  50. DBGMSG( DBG_TRACE, ( "ServerName = " TSTR "\n", DBGSTR( (LPCTSTR)pszServerName ) ) );
  51. DBGMSG( DBG_TRACE, ( "PrintProcessorName = " TSTR "\n", (LPCTSTR)strPrintProcessor ) );
  52. DBGMSG( DBG_TRACE, ( "DataType = " TSTR "\n", (LPCTSTR)strDatatype ) );
  53. //
  54. // Update the string oobjects.
  55. //
  56. if( !_strPrintProcessor.bUpdate( strPrintProcessor ) ||
  57. !_strDatatype.bUpdate( strDatatype ) ){
  58. DBGMSG( DBG_WARN, ( "String update failed with %d\n", GetLastError() ) );
  59. return;
  60. }
  61. //
  62. // Do loading for this object.
  63. //
  64. if( !bLoad( ) ){
  65. return;
  66. }
  67. _bValid = TRUE;
  68. }
  69. /*++
  70. Routine Name:
  71. ~TPrintProcessor
  72. Routine Description:
  73. Destructs the print processor dialog.
  74. Arguments:
  75. None.
  76. Return Value:
  77. Nothing.
  78. --*/
  79. TPrintProcessor::
  80. ~TPrintProcessor(
  81. )
  82. {
  83. DBGMSG( DBG_TRACE, ( "TPrintProcessor::dtor\n") );
  84. FreeMem( _pPrintProcessors );
  85. }
  86. /*++
  87. Routine Name:
  88. bValid
  89. Routine Description:
  90. Returns valid object indicator.
  91. Arguments:
  92. None.
  93. Return Value:
  94. Nothing.
  95. --*/
  96. BOOL
  97. TPrintProcessor::
  98. bValid(
  99. VOID
  100. )
  101. {
  102. return _bValid;
  103. }
  104. /*++
  105. Routine Name:
  106. bDoModal
  107. Routine Description:
  108. Start modal execution of dialog.
  109. Arguments:
  110. None.
  111. Return Value:
  112. TRUE dialog ok button chosen.
  113. FALSE cancel button chosen.
  114. --*/
  115. BOOL
  116. TPrintProcessor::
  117. bDoModal(
  118. VOID
  119. )
  120. {
  121. //
  122. // Create a modal dialog.
  123. //
  124. return (BOOL)DialogBoxParam( ghInst,
  125. MAKEINTRESOURCE( TPrintProcessor::kResourceId ),
  126. _hWnd,
  127. MGenericDialog::SetupDlgProc,
  128. (LPARAM)this );
  129. }
  130. /*++
  131. Routine Name:
  132. bSetUI
  133. Routine Description:
  134. Sets the data on the dialog.
  135. Arguments:
  136. None.
  137. Return Value:
  138. TRUE data set on UI successfully.
  139. FALSE error occurred setting UI data.
  140. --*/
  141. BOOL
  142. TPrintProcessor::
  143. bSetUI(
  144. VOID
  145. )
  146. {
  147. //
  148. // Create local copies of the control ID's this saves
  149. // some execution time and alot of typing.
  150. //
  151. _hctlPrintProcessorList = GetDlgItem( _hDlg, IDC_PRINT_PROCESSOR_LIST );
  152. _hctlDatatypeList = GetDlgItem( _hDlg, IDC_PRINT_DATATYPE_LIST );
  153. //
  154. // Set the UI controls.
  155. //
  156. if( !_hctlPrintProcessorList ||
  157. !_hctlDatatypeList ||
  158. !bSetPrintProcessorList() ||
  159. !bSetDatatypeList() ||
  160. !bDataTypeAssociation( TRUE ) ){
  161. DBGMSG( DBG_WARN, ( "bSetUI failed %d\n", GetLastError( )));
  162. return FALSE;
  163. }
  164. //
  165. // If not an administrator disable the controls.
  166. //
  167. vEnableCtl( _hDlg, IDC_PRINT_PROCESSOR_LIST, _bAdministrator );
  168. vEnableCtl( _hDlg, IDC_PRINT_DATATYPE_LIST, _bAdministrator );
  169. vEnableCtl( _hDlg, IDC_SPOOL_DATATYPE, _bAdministrator );
  170. vEnableCtl( _hDlg, IDOK, _bAdministrator );
  171. vEnableCtl( _hDlg, IDC_PRINT_PROCESSOR_DESC, _bAdministrator );
  172. vEnableCtl( _hDlg, IDC_PRINT_PROCESSOR_TEXT, _bAdministrator );
  173. vEnableCtl( _hDlg, IDC_PRINT_DATATYPE_TEXT, _bAdministrator );
  174. return TRUE;
  175. }
  176. /*++
  177. Routine Name:
  178. bReadUI
  179. Routine Description:
  180. Reads the UI data back into the public members.
  181. Arguments:
  182. None.
  183. Return Value:
  184. TRUE data read ok.
  185. FALSE error reading UI data.
  186. --*/
  187. BOOL
  188. TPrintProcessor::
  189. bReadUI(
  190. VOID
  191. )
  192. {
  193. UINT uSel;
  194. TCHAR szName[kPrinterBufMax];
  195. //
  196. // If we do not have administrator privilages.
  197. //
  198. if ( !_bAdministrator )
  199. return FALSE;
  200. //
  201. // Read the selected print proccessor form the list box.
  202. //
  203. uSel = ListBox_GetCurSel( _hctlPrintProcessorList );
  204. if(( uSel == LB_ERR ) ||
  205. ( ListBox_GetText( _hctlPrintProcessorList, uSel, szName ) == LB_ERR ) ||
  206. !_strPrintProcessor.bUpdate( szName )){
  207. DBGMSG( DBG_WARN, ( "Read print processor listbox failed %d\n", GetLastError( )));
  208. return FALSE;
  209. }
  210. //
  211. // Read the selected datatype form the list box.
  212. //
  213. uSel = ListBox_GetCurSel( _hctlDatatypeList );
  214. if(( uSel == LB_ERR ) ||
  215. ( ListBox_GetText( _hctlDatatypeList, uSel, szName ) == LB_ERR ) ||
  216. !_strDatatype.bUpdate( szName )){
  217. DBGMSG( DBG_WARN, ( "Read datatype listbox failed %d\n", GetLastError( )));
  218. return FALSE;
  219. }
  220. //
  221. // Trace message to display UI data.
  222. //
  223. DBGMSG( DBG_TRACE, ( "PrintProcessorName = " TSTR "\n", (LPCTSTR)strPrintProcessor() ) );
  224. DBGMSG( DBG_TRACE, ( "DataType = " TSTR "\n", (LPCTSTR)strDatatype() ) );
  225. return TRUE;
  226. }
  227. /*++
  228. Routine Name:
  229. bSetPrintProcessorList
  230. Routine Description:
  231. Fills the print processors list box.
  232. Arguments:
  233. None.
  234. Return Value:
  235. TRUE list box fill successfully.
  236. FALSE if error occurred.
  237. --*/
  238. BOOL
  239. TPrintProcessor::
  240. bSetPrintProcessorList(
  241. VOID
  242. )
  243. {
  244. //
  245. // Reset the list box in case we are called to refresh.
  246. //
  247. ListBox_ResetContent( _hctlPrintProcessorList );
  248. //
  249. // Build list of print processors.
  250. //
  251. UINT i;
  252. for( i = 0; i < _cPrintProcessors; i++ ){
  253. ListBox_InsertString( _hctlPrintProcessorList, -1, (LPARAM)_pPrintProcessors[i].pName );
  254. ListBox_SetItemData( _hctlPrintProcessorList, i, 0 );
  255. }
  256. //
  257. // Set the highlight on the current print processor.
  258. //
  259. UINT uSel;
  260. uSel = ListBox_FindString( _hctlPrintProcessorList, -1, _strPrintProcessor );
  261. uSel = ( uSel == LB_ERR ) ? 0 : uSel;
  262. ListBox_SetCurSel( _hctlPrintProcessorList, uSel );
  263. return TRUE;
  264. }
  265. /*++
  266. Routine Name:
  267. bSetDatatypeList
  268. Routine Description:
  269. Fills the datatype list box.
  270. Arguments:
  271. None.
  272. Return Value:
  273. TRUE list box fill successfully.
  274. FALSE if error occurred.
  275. --*/
  276. BOOL
  277. TPrintProcessor::
  278. bSetDatatypeList(
  279. VOID
  280. )
  281. {
  282. BOOL bStatus = FALSE;
  283. TCHAR pszPrintProcessorName[kPrinterBufMax];
  284. UINT uSel;
  285. //
  286. // Get the currently selected print processor name.
  287. //
  288. uSel = ListBox_GetCurSel( _hctlPrintProcessorList );
  289. ListBox_GetText( _hctlPrintProcessorList, uSel, pszPrintProcessorName );
  290. //
  291. // Enumerate the data types.
  292. //
  293. DATATYPES_INFO_1 *pDatatypes = NULL;
  294. DWORD cDatatypes = 0;
  295. bStatus = bEnumPrintProcessorDatatypes( (LPTSTR)_pszServerName,
  296. pszPrintProcessorName,
  297. 1,
  298. (PVOID *)&pDatatypes,
  299. &cDatatypes );
  300. if( bStatus ){
  301. //
  302. // Reset the list box in case we are called to refresh.
  303. //
  304. ListBox_ResetContent( _hctlDatatypeList );
  305. //
  306. // Build list of datatypes.
  307. //
  308. UINT i;
  309. for( i = 0; i < cDatatypes; i++ ){
  310. ListBox_InsertString( _hctlDatatypeList, -1, (LPARAM)pDatatypes[i].pName );
  311. }
  312. }
  313. //
  314. // Clean up any allocated resources.
  315. //
  316. FreeMem( pDatatypes );
  317. //
  318. // Select the correct datatype for the slected print processor.
  319. //
  320. ListBox_SetCurSel( _hctlDatatypeList,
  321. ListBox_GetItemData( _hctlPrintProcessorList,
  322. ListBox_GetCurSel( _hctlPrintProcessorList ) ) );
  323. return bStatus;
  324. }
  325. /*++
  326. Routine Name:
  327. bDataTypeAssociation
  328. Routine Description:
  329. The currently selected datatype item is tracted for
  330. each print processor. The print processor list box item
  331. data contains the index of its corresponding datatype.
  332. Arguments:
  333. TRUE to select the highlight on the default datatype.
  334. FALSE to the association for the currently selected datatype.
  335. Return Value:
  336. Always returns success
  337. --*/
  338. BOOL
  339. TPrintProcessor::
  340. bDataTypeAssociation(
  341. IN BOOL bSetDatatype
  342. )
  343. {
  344. //
  345. // Set the highlight using the current datatype.
  346. //
  347. if( bSetDatatype ){
  348. //
  349. // Locate and select the index of the default datatype. The
  350. // default datatype is the datatype string passed into this object.
  351. //
  352. UINT uSel;
  353. uSel = ListBox_FindString( _hctlDatatypeList, -1, _strDatatype );
  354. uSel = ( uSel == LB_ERR ) ? 0 : uSel;
  355. ListBox_SetCurSel( _hctlDatatypeList, uSel );
  356. }
  357. //
  358. // Get the currently selected print processor and set the item data
  359. // to associated selected data type.
  360. //
  361. ListBox_SetItemData( _hctlPrintProcessorList,
  362. ListBox_GetCurSel( _hctlPrintProcessorList ),
  363. ListBox_GetCurSel( _hctlDatatypeList ) );
  364. return TRUE;
  365. }
  366. /*++
  367. Routine Name:
  368. bLoad
  369. Routine Description:
  370. Gets the list of print processors.
  371. Arguments:
  372. None.
  373. Return Value:
  374. TRUE list box fill successfully.
  375. FALSE if error occurred.
  376. --*/
  377. BOOL
  378. TPrintProcessor::
  379. bLoad(
  380. VOID
  381. )
  382. {
  383. //
  384. // Get the current driver / version.
  385. //
  386. DWORD dwDriverVersion = 0;
  387. if( !bGetCurrentDriver( _pszServerName, &dwDriverVersion ) ){
  388. DBGMSG( DBG_WARN, ( "bGetDriverVersion failed.\n" ) );
  389. return FALSE;
  390. }
  391. DBGMSG( DBG_TRACE, ( "Driver Version %d\n", dwDriverVersion ) );
  392. //
  393. // Convert the driver / version to spooler usable environment string.
  394. //
  395. TString strDriverEnv;
  396. if( !bGetDriverEnv( dwDriverVersion, strDriverEnv ) ){
  397. DBGMSG( DBG_WARN, ( "bGetDriverEnv failed.\n" ) );
  398. return FALSE;
  399. }
  400. DBGMSG( DBG_TRACE, ( "Driver Environment " TSTR "\n", (LPCTSTR)strDriverEnv ) );
  401. //
  402. // Enumerate the currently installed print processors.
  403. //
  404. BOOL bStatus;
  405. bStatus = bEnumPrintProcessors( (LPTSTR)_pszServerName,
  406. (LPTSTR)(LPCTSTR)strDriverEnv,
  407. 1,
  408. (PVOID *)&_pPrintProcessors,
  409. &_cPrintProcessors );
  410. if( !bStatus ){
  411. DBGMSG( DBG_ERROR, ( "bEnumPrintProccessors failed = %d\n", GetLastError () ) );
  412. return FALSE;
  413. }
  414. return TRUE;
  415. }
  416. /*++
  417. Routine Name:
  418. bHandleMesage
  419. Routine Description:
  420. Dialog message handler.
  421. Arguments:
  422. IN UINT uMsg,
  423. IN WPARAM wParam,
  424. IN LPARAM lParam
  425. Return Value:
  426. TRUE message was handled.
  427. FALSE message was not handled.
  428. --*/
  429. BOOL
  430. TPrintProcessor::
  431. bHandleMessage(
  432. UINT uMsg,
  433. WPARAM wParam,
  434. LPARAM lParam
  435. )
  436. {
  437. UNREFERENCED_PARAMETER( lParam );
  438. BOOL bStatus = FALSE;
  439. switch( uMsg ){
  440. case WM_INITDIALOG:
  441. bSetUI( );
  442. bStatus = TRUE;
  443. break;
  444. case WM_HELP:
  445. case WM_CONTEXTMENU:
  446. bStatus = PrintUIHelp( uMsg, _hDlg, wParam, lParam );
  447. break;
  448. case WM_COMMAND:
  449. switch( GET_WM_COMMAND_ID( wParam, lParam )){
  450. //
  451. // Read back the UI data and indicate success.
  452. //
  453. case IDOK:
  454. bStatus = bReadUI();
  455. EndDialog( _hDlg, bStatus );
  456. break;
  457. //
  458. // Indicate cancel request.
  459. //
  460. case IDCANCEL:
  461. bStatus = TRUE;
  462. EndDialog( _hDlg, FALSE );
  463. break;
  464. //
  465. // Handle the print processor list change.
  466. //
  467. case IDC_PRINT_PROCESSOR_LIST:
  468. switch ( GET_WM_COMMAND_CMD( wParam, lParam ) ){
  469. case LBN_SELCHANGE:
  470. bSetDatatypeList();
  471. bStatus = TRUE;
  472. break;
  473. }
  474. break;
  475. //
  476. // Handle the data type list change.
  477. //
  478. case IDC_PRINT_DATATYPE_LIST:
  479. switch ( GET_WM_COMMAND_CMD( wParam, lParam ) ){
  480. case LBN_SELCHANGE:
  481. bDataTypeAssociation( FALSE );
  482. bStatus = TRUE;
  483. break;
  484. }
  485. break;
  486. default:
  487. bStatus = FALSE;
  488. break;
  489. }
  490. default:
  491. bStatus = FALSE;
  492. break;
  493. }
  494. return bStatus;
  495. }
  496. /*++
  497. Routine Name:
  498. bEnumPrintProcessors
  499. Routine Description:
  500. Enumerates the installed print processors.
  501. Arguments:
  502. Return Value:
  503. TRUE list box fill successfully.
  504. FALSE if error occurred.
  505. --*/
  506. BOOL
  507. TPrintProcessor::
  508. bEnumPrintProcessors(
  509. IN LPTSTR pszServerName,
  510. IN LPTSTR pszEnvironment,
  511. IN DWORD dwLevel,
  512. OUT PVOID *ppvBuffer,
  513. OUT PDWORD pcReturned
  514. )
  515. {
  516. DWORD dwNeeded;
  517. DWORD dwReturned;
  518. PBYTE pBuf = NULL;
  519. BOOL bStatus = FALSE;
  520. //
  521. // First query spooler for installed print processors.
  522. //
  523. if ( !EnumPrintProcessors( pszServerName, pszEnvironment, dwLevel, NULL, 0, &dwNeeded, &dwReturned) ) {
  524. if ( GetLastError() != ERROR_INSUFFICIENT_BUFFER ||
  525. ((pBuf = (PBYTE)AllocMem( dwNeeded )) == NULL) ||
  526. !EnumPrintProcessors( pszServerName,
  527. pszEnvironment,
  528. dwLevel,
  529. pBuf,
  530. dwNeeded,
  531. &dwNeeded,
  532. &dwReturned) ) {
  533. bStatus = FALSE;
  534. } else {
  535. bStatus = TRUE;
  536. }
  537. }
  538. //
  539. // If success copy back the data.
  540. //
  541. if( bStatus ){
  542. *ppvBuffer = pBuf;
  543. *pcReturned = dwReturned;
  544. }
  545. return bStatus;
  546. }
  547. /*++
  548. Routine Name:
  549. bEnumPrintProcessorDatatypes
  550. Routine Description:
  551. Enumerates the print processors datatypes.
  552. Arguments:
  553. Return Value:
  554. TRUE list box fill successfully.
  555. FALSE if error occurred.
  556. --*/
  557. BOOL
  558. TPrintProcessor::
  559. bEnumPrintProcessorDatatypes(
  560. IN LPTSTR pszServerName,
  561. IN LPTSTR pszPrintProcessor,
  562. IN DWORD dwLevel,
  563. OUT PVOID *ppvBuffer,
  564. OUT PDWORD pcReturned
  565. )
  566. {
  567. DWORD dwNeeded;
  568. DWORD dwReturned;
  569. PBYTE pBuf = NULL;
  570. BOOL bStatus = FALSE;
  571. //
  572. // First query spooler for installed print processors.
  573. //
  574. if ( !EnumPrintProcessorDatatypes( pszServerName, pszPrintProcessor, dwLevel, NULL, 0, &dwNeeded, &dwReturned) ) {
  575. if ( GetLastError() != ERROR_INSUFFICIENT_BUFFER ||
  576. ((pBuf = (PBYTE)AllocMem( dwNeeded )) == NULL) ||
  577. !EnumPrintProcessorDatatypes( pszServerName,
  578. pszPrintProcessor,
  579. dwLevel,
  580. pBuf,
  581. dwNeeded,
  582. &dwNeeded,
  583. &dwReturned) ) {
  584. bStatus = FALSE;
  585. } else {
  586. bStatus = TRUE;
  587. }
  588. }
  589. //
  590. // If success copy back the data.
  591. //
  592. if( bStatus ){
  593. *ppvBuffer = pBuf;
  594. *pcReturned = dwReturned;
  595. }
  596. return bStatus;
  597. }