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.

483 lines
8.5 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1995 - 1998
  3. All rights reserved.
  4. Module Name:
  5. docdata.cxx
  6. Abstract:
  7. Document Data Property Sheet Data Set
  8. Author:
  9. Steve Kiraly (SteveKi) 10/25/95
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "docdata.hxx"
  15. /*++
  16. Routine Name:
  17. TDocumentData
  18. Routine Description:
  19. Document data property sheet constructor.
  20. Arguments:
  21. pszPrinterName - Name of printer or queue where jobs reside.
  22. JobId - Job id to display properties of.
  23. iCmdShow - Show dialog style.
  24. lParam - Indicates which page to display initialy
  25. Return Value:
  26. Nothing.
  27. --*/
  28. TDocumentData::
  29. TDocumentData(
  30. IN LPCTSTR pszPrinterName,
  31. IN IDENT JobId,
  32. IN INT iCmdShow,
  33. IN LPARAM lParam
  34. ) : MSingletonWin( pszPrinterName ),
  35. _JobId( JobId ),
  36. _iCmdShow( iCmdShow ),
  37. _strNotifyName( TEXT( "" ) ),
  38. _uStartPage( (UINT)lParam ),
  39. _bIsDataStored( FALSE ),
  40. _bErrorSaving( TRUE ),
  41. _bAdministrator( TRUE ),
  42. _pJobInfo( NULL ),
  43. _hPrinter( NULL ),
  44. _dwAccess( 0 )
  45. {
  46. // DBGMSG( DBG_TRACE, ( "TDocumentData::ctor\n") );
  47. _bValid = MSingletonWin::bValid() && VALID_OBJ( _strNotifyName );
  48. }
  49. /*++
  50. Routine Name:
  51. ~TDocumentData
  52. Routine Description:
  53. Stores the document data back to the server.
  54. Arguments:
  55. None.
  56. Return Value:
  57. Nothing.
  58. --*/
  59. TDocumentData::
  60. ~TDocumentData(
  61. VOID
  62. )
  63. {
  64. // DBGMSG( DBG_TRACE, ( "TDocumentData::dtor\n") );
  65. //
  66. // If we have allocated the job info structure, release it.
  67. //
  68. if( _pJobInfo ){
  69. delete [] _pJobInfo;
  70. }
  71. //
  72. // If we have valid printer handle, close printer.
  73. //
  74. if( _hPrinter ){
  75. ClosePrinter( _hPrinter );
  76. }
  77. }
  78. /*++
  79. Routine Name:
  80. bLoad
  81. Routine Description:
  82. Loads all the document property specific data.
  83. Arguments:
  84. None.
  85. Return Value:
  86. TRUE - Document data loaded successfully,
  87. FALSE - if document data was not loaded.
  88. --*/
  89. BOOL
  90. TDocumentData::
  91. bLoad(
  92. VOID
  93. )
  94. {
  95. // DBGMSG( DBG_TRACE, ( "TDocumentData::bLoad\n") );
  96. //
  97. // Open the specified printer.
  98. //
  99. TStatus Status( DBG_WARN );
  100. Status DBGCHK = TPrinter::sOpenPrinter( _strPrinterName, &_dwAccess, &_hPrinter );
  101. if( Status ){
  102. return FALSE;
  103. }
  104. //
  105. // Release any old job information.
  106. //
  107. if( _pJobInfo ) {
  108. delete _pJobInfo;
  109. }
  110. //
  111. // Get the job specific information.
  112. //
  113. BOOL bStatus;
  114. bStatus = bGetJobInfo( _hPrinter, _JobId, &_pJobInfo );
  115. if( !bStatus ){
  116. return FALSE;
  117. }
  118. //
  119. // Make a copy of the job info - apply button.
  120. //
  121. bStatus = _JobInfo.bUpdate( _pJobInfo );
  122. if( !bStatus ) {
  123. return FALSE;
  124. }
  125. return TRUE;
  126. }
  127. /*++
  128. Routine Name:
  129. bStore
  130. Routine Description:
  131. Stores the document data from back to the printer system.
  132. Arguments:
  133. None.
  134. Return Value:
  135. TRUE - Document data stored successfully,
  136. FALSE - if document data was not stored.
  137. --*/
  138. BOOL
  139. TDocumentData::
  140. bStore(
  141. VOID
  142. )
  143. {
  144. SPLASSERT( _JobId );
  145. SPLASSERT( _pJobInfo );
  146. SPLASSERT( _hPrinter );
  147. // DBGMSG( DBG_TRACE, ( "TDocumentData::bStore\n") );
  148. TStatusB bStatus;
  149. bStatus DBGNOCHK = TRUE;
  150. //
  151. // Only do a set job is the data has changed.
  152. //
  153. if( bCheckForChange() )
  154. {
  155. //
  156. // Attempt to set the document data.
  157. //
  158. bStatus DBGCHK = bSetJobInfo( _hPrinter, _JobId, _pJobInfo );
  159. if( bStatus ) {
  160. //
  161. // Update the copy of the job info - apply button.
  162. //
  163. (VOID)_JobInfo.bUpdate( _pJobInfo );
  164. }
  165. //
  166. // Indicate the data has now been stored.
  167. //
  168. _bIsDataStored = TRUE;
  169. }
  170. return bStatus;
  171. }
  172. /*++
  173. Routine Name:
  174. bGetJobInfo
  175. Routine Description:
  176. Read the job information from the specified printer.
  177. Arguments:
  178. hPrinter - Opened printer handle.
  179. JobId - Job Id of job to get info level 2 information
  180. pJob - Pointer where to return pointer to job info level 2.
  181. Return Value:
  182. TRUE valid information and pJop points to JOB_INFO_2 structure.
  183. FALSE failure reading job information.
  184. --*/
  185. BOOL
  186. TDocumentData::
  187. bGetJobInfo(
  188. HANDLE hPrinter,
  189. DWORD JobId,
  190. LPJOB_INFO_2 *xpJob
  191. )
  192. {
  193. DWORD cbNeeded = 0;
  194. BOOL bStatus = FALSE;
  195. LPJOB_INFO_2 pJob = NULL;
  196. SPLASSERT( JobId );
  197. // DBGMSG( DBG_TRACE, ( "TDocumentData::bGetJobInfo\n") );
  198. //
  199. // Attempt to retrieve the buffer needed for the job info.
  200. //
  201. if( !GetJob( hPrinter, JobId, 2, NULL, 0, &cbNeeded ) ){
  202. //
  203. // If error is too small buffer contine.
  204. //
  205. if( GetLastError() == ERROR_INSUFFICIENT_BUFFER ){
  206. //
  207. // Allocate job info buffer
  208. //
  209. pJob = (LPJOB_INFO_2)new BYTE [cbNeeded];
  210. //
  211. // If buffer allocated
  212. //
  213. if( pJob ){
  214. //
  215. // Fill in the job info buffer.
  216. //
  217. if( GetJob( hPrinter, JobId, 2, (LPBYTE)pJob, cbNeeded, &cbNeeded ) ){
  218. bStatus = TRUE;
  219. }
  220. //
  221. // Buffer allocation failure.
  222. //
  223. } else {
  224. bStatus = FALSE;
  225. }
  226. //
  227. // Some other get job error occurred.
  228. //
  229. } else {
  230. bStatus = FALSE;
  231. }
  232. }
  233. //
  234. // If error occurred clean up.
  235. //
  236. if( !bStatus ){
  237. if( pJob ){
  238. delete [] pJob;
  239. }
  240. //
  241. // Success copy back the job info buffer.
  242. //
  243. } else {
  244. *xpJob = pJob;
  245. }
  246. return bStatus;
  247. }
  248. /*++
  249. Routine Name:
  250. bSetJobInfo
  251. Routine Description:
  252. Write the job informationto the specified printer.
  253. Arguments:
  254. hPrinter - Opened printer handle.
  255. JobId - Job Id of job to get info level 2 information
  256. pJob - Pointer where to return pointer to job info level 2.
  257. Return Value:
  258. TRUE if job informaton was set, FALSE error writing job information.
  259. --*/
  260. BOOL
  261. TDocumentData::
  262. bSetJobInfo(
  263. HANDLE hPrinter,
  264. DWORD JobId,
  265. LPJOB_INFO_2 pJob
  266. )
  267. {
  268. // DBGMSG( DBG_TRACE, ( "TDocumentData::bSetJobInfo\n") );
  269. //
  270. // Attempt to set the job information.
  271. //
  272. return SetJob( hPrinter, JobId, 2, (LPBYTE)pJob, 0 );
  273. }
  274. /*++
  275. Routine Name:
  276. bCheckForChange
  277. Routine Description:
  278. Checks if anything changed on the dialog.
  279. Arguments:
  280. None.
  281. Return Value:
  282. FALSE something changed, TRUE no change.
  283. --*/
  284. BOOL
  285. TDocumentData::
  286. bCheckForChange(
  287. VOID
  288. )
  289. {
  290. if( !_tcscmp( _strNotifyName, _JobInfo._strNotifyName ) &&
  291. _pJobInfo->Priority == _JobInfo._dwPriority &&
  292. _pJobInfo->StartTime == _JobInfo._dwStartTime &&
  293. _pJobInfo->UntilTime == _JobInfo._dwUntilTime )
  294. {
  295. return FALSE;
  296. }
  297. #if DBG
  298. DBGMSG( DBG_TRACE, ("Item changed:\n" ));
  299. if( _tcscmp( _strNotifyName, _JobInfo._strNotifyName ) )
  300. DBGMSG( DBG_TRACE, ("NotifyName: "TSTR " " TSTR "\n", (LPCTSTR)_strNotifyName, (LPCTSTR)_JobInfo._strNotifyName ));
  301. if( _pJobInfo->Priority != _JobInfo._dwPriority )
  302. DBGMSG( DBG_TRACE, ("Priority: %x %x\n", _pJobInfo->Priority, _JobInfo._dwPriority ));
  303. if( _pJobInfo->StartTime != _JobInfo._dwStartTime )
  304. DBGMSG( DBG_TRACE, ("StartTime: %x %x\n", _pJobInfo->StartTime, _JobInfo._dwStartTime ));
  305. if( _pJobInfo->UntilTime != _JobInfo._dwUntilTime )
  306. DBGMSG( DBG_TRACE, ("UntilTime: %x %x\n", _pJobInfo->UntilTime, _JobInfo._dwUntilTime ));
  307. #endif
  308. return TRUE;
  309. }
  310. /********************************************************************
  311. Job info class used for the apply button.
  312. ********************************************************************/
  313. TDocumentData::TJobInfo::
  314. TJobInfo(
  315. VOID
  316. ) : _dwPriority( 0 ),
  317. _dwStartTime( 0 ),
  318. _dwUntilTime( 0 )
  319. {
  320. }
  321. TDocumentData::TJobInfo::
  322. ~TJobInfo(
  323. VOID
  324. )
  325. {
  326. }
  327. BOOL
  328. TDocumentData::TJobInfo::
  329. bUpdate(
  330. IN LPJOB_INFO_2 pJobInfo
  331. )
  332. {
  333. SPLASSERT( pJobInfo );
  334. TStatusB bStatus;
  335. bStatus DBGNOCHK = FALSE;
  336. if( pJobInfo ) {
  337. bStatus DBGCHK = _strNotifyName.bUpdate( pJobInfo->pNotifyName );
  338. _dwPriority = pJobInfo->Priority;
  339. _dwStartTime = pJobInfo->StartTime;
  340. _dwUntilTime = pJobInfo->UntilTime;
  341. }
  342. return bStatus;
  343. }