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.

549 lines
10 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 uLen = 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. _tcscpy( szFileFilter+uLen, strFormat );
  281. uLen = uLen + strFormat.uLen() + 1;
  282. }
  283. }
  284. //
  285. // Null terminate the strings.
  286. //
  287. lstrcpy( szFileFilter+uLen, TEXT("") );
  288. lstrcpy( szFile, TEXT("") );
  289. //
  290. // Get the initial directory.
  291. //
  292. if( !GetSystemDirectory( szInitialDirectory, COUNTOF( szInitialDirectory ) ) )
  293. {
  294. _tcscpy( szInitialDirectory, TEXT("") );
  295. }
  296. //
  297. // Get the open file dialog title string.
  298. //
  299. TString strTitle;
  300. bStatus DBGCHK = strTitle.bLoadString( ghInst, kSeparatorPageTitle );
  301. if( !bStatus )
  302. {
  303. vShowResourceError( _hDlg );
  304. return FALSE;
  305. }
  306. //
  307. // Create the open file structure.
  308. //
  309. OPENFILENAME OpenFileName;
  310. OpenFileName.lStructSize = sizeof(OPENFILENAME);
  311. OpenFileName.hwndOwner = _hDlg;
  312. OpenFileName.hInstance = ghInst;
  313. OpenFileName.lpstrFilter = szFileFilter;
  314. OpenFileName.lpstrCustomFilter = NULL;
  315. OpenFileName.nMaxCustFilter = 0;
  316. OpenFileName.nFilterIndex = 1;
  317. OpenFileName.lpstrFile = szFile;
  318. OpenFileName.nMaxFile = COUNTOF( szFile );
  319. OpenFileName.lpstrFileTitle = NULL;
  320. OpenFileName.nMaxFileTitle = 0;
  321. OpenFileName.lpstrInitialDir = szInitialDirectory;
  322. OpenFileName.lpstrTitle = strTitle;
  323. OpenFileName.nFileOffset = 0;
  324. OpenFileName.nFileExtension = 0;
  325. OpenFileName.lpstrDefExt = NULL;
  326. OpenFileName.lCustData = 0;
  327. OpenFileName.Flags = OFN_PATHMUSTEXIST |
  328. OFN_FILEMUSTEXIST |
  329. OFN_HIDEREADONLY;
  330. //
  331. // If success copy back the selected string.
  332. //
  333. bStatus DBGNOCHK = GetOpenFileName(&OpenFileName);
  334. if( bStatus )
  335. {
  336. bStatus DBGCHK = bSetEditText( _hDlg, IDC_SEPARATOR_PAGE_EDIT, szFile );
  337. }
  338. return bStatus;
  339. }
  340. /*++
  341. Routine Name:
  342. bValidateSeparatorFile
  343. Routine Description:
  344. Validate the name specified in the separator file edit box.
  345. An empty sting is considered a valid separator file, it is defined
  346. as no separator file.
  347. Arguments:
  348. Nothing.
  349. Return Value:
  350. TRUE separator file in edit box is valid.
  351. FALSE separator file is invalid.
  352. --*/
  353. BOOL
  354. TSeparatorPage::
  355. bValidateSeparatorFile(
  356. VOID
  357. )
  358. {
  359. TStatusB bStatus;
  360. TString strTempSeparatorFile;
  361. DBGMSG( DBG_TRACE, ( "bValidSeparatorFile\n" ) );
  362. //
  363. // Get separator file from edit box.
  364. //
  365. bStatus DBGCHK = bGetEditText( _hDlg, IDC_SEPARATOR_PAGE_EDIT, strTempSeparatorFile );
  366. //
  367. // A null string is a valid separator file.
  368. //
  369. if( !lstrlen( strTempSeparatorFile ) || ((LPCTSTR)strTempSeparatorFile == NULL) )
  370. return TRUE;
  371. //
  372. // If we are administrating the separator page remotely then do
  373. // not validate the sparator file name against the local file system.
  374. //
  375. if( bStatus && !_bLocal ){
  376. return TRUE;
  377. }
  378. //
  379. // Check status of reading edit box.
  380. //
  381. if( bStatus ){
  382. //
  383. // Get the file attributes.
  384. //
  385. DWORD dwFileAttributes = GetFileAttributes( strTempSeparatorFile );
  386. //
  387. // If file has some attributes.
  388. //
  389. if( dwFileAttributes != -1 ){
  390. //
  391. // If file has anyone of these attributes then ok and not a directory
  392. //
  393. if( dwFileAttributes & ( FILE_ATTRIBUTE_NORMAL |
  394. FILE_ATTRIBUTE_READONLY |
  395. FILE_ATTRIBUTE_ARCHIVE ) ) {
  396. if( !( dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ){
  397. return TRUE;
  398. }
  399. }
  400. }
  401. }
  402. return FALSE;
  403. }