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.

575 lines
11 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1995 - 1998
  3. All rights reserved.
  4. Module Name:
  5. F:\nt\private\windows\spooler\printui.pri\sepdlg.cxx
  6. Abstract:
  7. Separator page dialog.
  8. Author:
  9. Steve Kiraly (SteveKi) 11/10/95
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "sepdlg.hxx"
  15. /*++
  16. Routine Name:
  17. TSeparatorPage
  18. Routine Description:
  19. TSeparatorPage constructor
  20. Arguments:
  21. hWnd - Parent window handle
  22. TString - String or current separator page.
  23. Return Value:
  24. Nothing.
  25. --*/
  26. TSeparatorPage::
  27. TSeparatorPage(
  28. IN const HWND hWnd,
  29. IN const TString &strSeparatorPage,
  30. IN const BOOL bAdministrator,
  31. IN const BOOL bLocal
  32. ) : _hWnd( hWnd ),
  33. _bAdministrator( bAdministrator ),
  34. _bValid( FALSE ),
  35. _bLocal( bLocal )
  36. {
  37. //
  38. // Copy the separator page string.
  39. //
  40. if( !_strSeparatorPage.bUpdate( strSeparatorPage ) ){
  41. DBGMSG( DBG_WARN, ( "_strSeparatorPage failed update with %d.\n", GetLastError() ) );
  42. return;
  43. }
  44. _bValid = TRUE;
  45. }
  46. /*++
  47. Routine Name:
  48. TSeparatorPage
  49. Routine Description:
  50. TSeparatorPage destructor
  51. Arguments:
  52. None.
  53. Return Value:
  54. Nothing.
  55. --*/
  56. TSeparatorPage::
  57. ~TSeparatorPage(
  58. )
  59. {
  60. }
  61. /*++
  62. Routine Name:
  63. bValid
  64. Routine Description:
  65. Valid object member function.
  66. Arguments:
  67. None.
  68. Return Value:
  69. TRUE valid object constructor successful
  70. FALSE error during construction.
  71. --*/
  72. BOOL
  73. TSeparatorPage::
  74. bValid(
  75. VOID
  76. ) const
  77. {
  78. return _bValid;
  79. }
  80. /*++
  81. Routine Name:
  82. bDoModal
  83. Routine Description:
  84. Create and starts modal execution of this dialog.
  85. Arguments:
  86. None.
  87. Return Value:
  88. TRUE Separator page changed.
  89. FALSE no separator page change, or error occurred.
  90. --*/
  91. BOOL
  92. TSeparatorPage::
  93. bDoModal(
  94. VOID
  95. )
  96. {
  97. //
  98. // Create a modal dialog.
  99. //
  100. return (BOOL)DialogBoxParam( ghInst,
  101. MAKEINTRESOURCE( TSeparatorPage::kResourceId ),
  102. _hWnd,
  103. MGenericDialog::SetupDlgProc,
  104. (LPARAM)this );
  105. }
  106. /*++
  107. Routine Name:
  108. bSetUI
  109. Routine Description:
  110. Set the data on the user interface.
  111. Arguments:
  112. None.
  113. Return Value:
  114. TRUE UI data is set.
  115. FALSE error setting UI data.
  116. --*/
  117. BOOL
  118. TSeparatorPage::
  119. bSetUI(
  120. VOID
  121. )
  122. {
  123. BOOL bStatus = bSetEditText( _hDlg, IDC_SEPARATOR_PAGE_EDIT, _strSeparatorPage );
  124. vEnableCtl( _hDlg, IDC_SEPARATOR_PAGE_EDIT, _bAdministrator );
  125. vEnableCtl( _hDlg, IDC_SEPARATOR_PAGE_BROWSE, _bAdministrator );
  126. vEnableCtl( _hDlg, IDOK, _bAdministrator );
  127. vEnableCtl( _hDlg, IDC_SEPARATOR_PAGE_DESC, _bAdministrator );
  128. vEnableCtl( _hDlg, IDC_SEPARATOR_PAGE_TEXT, _bAdministrator );
  129. //
  130. // Browse button disable for remote machines. Common dialogs
  131. // cannot look at files on a remote machine.
  132. //
  133. if( !_bLocal )
  134. vEnableCtl( _hDlg, IDC_SEPARATOR_PAGE_BROWSE, FALSE );
  135. return bStatus;
  136. }
  137. /*++
  138. Routine Name:
  139. bReadUI
  140. Routine Description:
  141. Read the data from the user interface.
  142. Arguments:
  143. None.
  144. Return Value:
  145. TRUE UI data read ok.
  146. FALSE UI data could not be read.
  147. --*/
  148. BOOL
  149. TSeparatorPage::
  150. bReadUI(
  151. VOID
  152. )
  153. {
  154. TStatusB bStatus;
  155. //
  156. // If not an administration return with out reading the UI.
  157. //
  158. if( !_bAdministrator )
  159. return FALSE;
  160. //
  161. // Ensure the separator file is a valid file or null.
  162. //
  163. bStatus DBGCHK = bValidateSeparatorFile();
  164. if( !bStatus )
  165. return FALSE;
  166. //
  167. // Get the Separator page text.
  168. //
  169. bStatus DBGCHK = bGetEditText( _hDlg, IDC_SEPARATOR_PAGE_EDIT, _strSeparatorPage );
  170. return bStatus;
  171. }
  172. /*++
  173. Routine Name:
  174. bHandleMesage
  175. Routine Description:
  176. Dialog message handler.
  177. Arguments:
  178. IN UINT uMsg,
  179. IN WPARAM wParam,
  180. IN LPARAM lParam
  181. Return Value:
  182. TRUE message was handled.
  183. FALSE message was not handled.
  184. --*/
  185. BOOL
  186. TSeparatorPage::
  187. bHandleMessage(
  188. IN UINT uMsg,
  189. IN WPARAM wParam,
  190. IN LPARAM lParam
  191. )
  192. {
  193. UNREFERENCED_PARAMETER( lParam );
  194. BOOL bStatus = FALSE;
  195. switch( uMsg ){
  196. case WM_INITDIALOG:
  197. bStatus = bSetUI();
  198. break;
  199. case WM_HELP:
  200. case WM_CONTEXTMENU:
  201. bStatus = PrintUIHelp( uMsg, _hDlg, wParam, lParam );
  202. break;
  203. case WM_COMMAND:
  204. switch( GET_WM_COMMAND_ID( wParam, lParam )){
  205. case IDOK:
  206. if( !bReadUI() ){
  207. iMessage( _hDlg,
  208. kSeparatorPageTitle,
  209. kErrorSeparatorDoesNotExist,
  210. MB_OK|MB_ICONSTOP,
  211. kMsgNone,
  212. NULL );
  213. } else {
  214. EndDialog( _hDlg, TRUE );
  215. }
  216. bStatus = TRUE;
  217. break;
  218. case IDCANCEL:
  219. EndDialog( _hDlg, FALSE );
  220. bStatus = TRUE;
  221. break;
  222. case IDC_SEPARATOR_PAGE_BROWSE:
  223. bSelectSeparatorFile();
  224. bStatus = TRUE;
  225. break;
  226. default:
  227. bStatus = FALSE;
  228. break;
  229. }
  230. default:
  231. bStatus = FALSE;
  232. break;
  233. }
  234. return bStatus;
  235. }
  236. /*++
  237. Routine Name:
  238. bSelectSeparatorFile
  239. Routine Description:
  240. Display file selection dialog to chose a separator file.
  241. Arguments:
  242. Nothing.
  243. Return Value:
  244. TRUE separator file was chosen ok.
  245. FALSE error or canceled separator selection.
  246. --*/
  247. BOOL
  248. TSeparatorPage::
  249. bSelectSeparatorFile(
  250. VOID
  251. )
  252. {
  253. TCHAR szFile[MAX_PATH];
  254. TCHAR szInitialDirectory[MAX_PATH];
  255. TCHAR szFileFilter[kStrMax];
  256. TString strFormat;
  257. TStatusB bStatus;
  258. UINT uPos = 0;
  259. //
  260. // Define filter string initializer structure.
  261. //
  262. struct FilterInitializer {
  263. UINT Id;
  264. };
  265. //
  266. // Declare filter string initializer structure.
  267. //
  268. FilterInitializer aFilterInit [] = {
  269. IDS_SEPARATOR_PAGE_DESC, IDS_SEPARATOR_PAGE_EXT,
  270. IDS_SEPARATOR_PAGE_ALL, IDS_SEPARATOR_PAGE_ALL_EXT
  271. };
  272. //
  273. // Initialize all the filters
  274. //
  275. for( UINT i = 0; i < COUNTOF( aFilterInit ); i++ )
  276. {
  277. bStatus DBGCHK = strFormat.bLoadString( ghInst, aFilterInit[i].Id );
  278. if( bStatus )
  279. {
  280. if( uPos < ARRAYSIZE(szFileFilter) )
  281. {
  282. StringCchCopy( szFileFilter + uPos, ARRAYSIZE(szFileFilter) - uPos, strFormat );
  283. uPos += (strFormat.uLen() + 1);
  284. }
  285. else
  286. {
  287. //
  288. // This should never happen.
  289. //
  290. ASSERT(FALSE);
  291. SetLastError(ERROR_INSUFFICIENT_BUFFER);
  292. bStatus DBGCHK = FALSE;
  293. return FALSE;
  294. }
  295. }
  296. }
  297. //
  298. // Null terminate the strings.
  299. //
  300. if( uPos < ARRAYSIZE(szFileFilter) )
  301. {
  302. szFileFilter[uPos++] = 0;
  303. szFile[0] = 0;
  304. }
  305. else
  306. {
  307. //
  308. // This should never happen.
  309. //
  310. ASSERT(FALSE);
  311. SetLastError(ERROR_INSUFFICIENT_BUFFER);
  312. bStatus DBGCHK = FALSE;
  313. return FALSE;
  314. }
  315. //
  316. // Get the initial directory.
  317. //
  318. if( !GetSystemDirectory( szInitialDirectory, COUNTOF( szInitialDirectory ) ) )
  319. {
  320. szInitialDirectory[0] = 0;
  321. }
  322. //
  323. // Get the open file dialog title string.
  324. //
  325. TString strTitle;
  326. bStatus DBGCHK = strTitle.bLoadString( ghInst, kSeparatorPageTitle );
  327. if( !bStatus )
  328. {
  329. vShowResourceError( _hDlg );
  330. return FALSE;
  331. }
  332. //
  333. // Create the open file structure.
  334. //
  335. OPENFILENAME OpenFileName;
  336. OpenFileName.lStructSize = sizeof(OPENFILENAME);
  337. OpenFileName.hwndOwner = _hDlg;
  338. OpenFileName.hInstance = ghInst;
  339. OpenFileName.lpstrFilter = szFileFilter;
  340. OpenFileName.lpstrCustomFilter = NULL;
  341. OpenFileName.nMaxCustFilter = 0;
  342. OpenFileName.nFilterIndex = 1;
  343. OpenFileName.lpstrFile = szFile;
  344. OpenFileName.nMaxFile = COUNTOF( szFile );
  345. OpenFileName.lpstrFileTitle = NULL;
  346. OpenFileName.nMaxFileTitle = 0;
  347. OpenFileName.lpstrInitialDir = szInitialDirectory;
  348. OpenFileName.lpstrTitle = strTitle;
  349. OpenFileName.nFileOffset = 0;
  350. OpenFileName.nFileExtension = 0;
  351. OpenFileName.lpstrDefExt = NULL;
  352. OpenFileName.lCustData = 0;
  353. OpenFileName.Flags = OFN_PATHMUSTEXIST |
  354. OFN_FILEMUSTEXIST |
  355. OFN_HIDEREADONLY;
  356. //
  357. // If success copy back the selected string.
  358. //
  359. bStatus DBGNOCHK = GetOpenFileName(&OpenFileName);
  360. if( bStatus )
  361. {
  362. bStatus DBGCHK = bSetEditText( _hDlg, IDC_SEPARATOR_PAGE_EDIT, szFile );
  363. }
  364. return bStatus;
  365. }
  366. /*++
  367. Routine Name:
  368. bValidateSeparatorFile
  369. Routine Description:
  370. Validate the name specified in the separator file edit box.
  371. An empty sting is considered a valid separator file, it is defined
  372. as no separator file.
  373. Arguments:
  374. Nothing.
  375. Return Value:
  376. TRUE separator file in edit box is valid.
  377. FALSE separator file is invalid.
  378. --*/
  379. BOOL
  380. TSeparatorPage::
  381. bValidateSeparatorFile(
  382. VOID
  383. )
  384. {
  385. TStatusB bStatus;
  386. TString strTempSeparatorFile;
  387. DBGMSG( DBG_TRACE, ( "bValidSeparatorFile\n" ) );
  388. //
  389. // Get separator file from edit box.
  390. //
  391. bStatus DBGCHK = bGetEditText( _hDlg, IDC_SEPARATOR_PAGE_EDIT, strTempSeparatorFile );
  392. //
  393. // A null string is a valid separator file.
  394. //
  395. if( !lstrlen( strTempSeparatorFile ) || ((LPCTSTR)strTempSeparatorFile == NULL) )
  396. return TRUE;
  397. //
  398. // If we are administrating the separator page remotely then do
  399. // not validate the sparator file name against the local file system.
  400. //
  401. if( bStatus && !_bLocal ){
  402. return TRUE;
  403. }
  404. //
  405. // Check status of reading edit box.
  406. //
  407. if( bStatus ){
  408. //
  409. // Get the file attributes.
  410. //
  411. DWORD dwFileAttributes = GetFileAttributes( strTempSeparatorFile );
  412. //
  413. // If file has some attributes.
  414. //
  415. if( dwFileAttributes != -1 ){
  416. //
  417. // If file has anyone of these attributes then ok and not a directory
  418. //
  419. if( dwFileAttributes & ( FILE_ATTRIBUTE_NORMAL |
  420. FILE_ATTRIBUTE_READONLY |
  421. FILE_ATTRIBUTE_ARCHIVE ) ) {
  422. if( !( dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ){
  423. return TRUE;
  424. }
  425. }
  426. }
  427. }
  428. return FALSE;
  429. }