OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
printer.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4//----------------------------------------------------------------------------
5
6#if !defined(OWL_PRINTER_H)
7#define OWL_PRINTER_H
8
9#include <owl/private/defs.h>
10#if defined(BI_HAS_PRAGMA_ONCE)
11# pragma once
12#endif
13
14#include <owl/dialog.h>
15#include <owl/printdia.h>
16
17#pragma pack(push, 8)
18#include <winspool.h>
19#pragma pack(pop)
20
21#include <vector>
22#include <memory>
23#include <owl/printer.rh>
24
25namespace owl {
26
27class _OWLCLASS TPrintDC;
28
29#include <owl/preclass.h>
30
31/// \addtogroup print
32/// @{
33
34//
35/// \class TPrinterAbortDlg
36/// TPrinterAbortDlg is the object type of the default printer-abort dialog box.
37/// This dialog box is initialized to display the title of the current printout, as
38/// well as the device and port currently used for printing.
39///
40/// TPrinterAbortDlg expects to have three static text controls, with control IDs of
41/// 101 for the title, 102 for the device, and 103 for the port. These controls must
42/// have "%s" somewhere in the text strings so that they can be replaced by the
43/// title, device, and port. The dialog-box controls can be in any position and tab
44/// order.
45//
47{
48 public:
49 TPrinterAbortDlg(TWindow* parent, TResId, const tstring& title, const tstring& device, const tstring& port, HDC = HDC(-1));
50
51 protected:
52 void SetupWindow() override;
53 void CmCancel();
54
55 HDC PrnDC; ///< Device context to print on
56
58};
59
60//
61/// TPrintout banding flags
62//
64{
65 pfGraphics = 0x01, ///< Current band accepts graphics
66 pfText = 0x02, ///< Current band accepts text
67 pfBoth = (pfGraphics|pfText) ///< Current band accepts both text and graphics
68};
69
70//
71/// \class TPrintout
72/// TPrintout represents the physical printed document that is to sent to a printer
73/// to be printed. TPrintout does the rendering of the document onto the printer.
74/// Because this object type is abstract, it cannot be used to print anything by
75/// itself. For every document, or document type, a class derived from TPrintout
76/// must be created and its PrintPage function must be overridden.
77//
79{
80 public:
81 explicit TPrintout(LPCTSTR title);
82 TPrintout(const tstring& title);
83 virtual ~TPrintout();
84
85 virtual void SetPrintParams(TPrintDC* dc, TSize pageSize);
86 virtual void GetDialogInfo(int& minPage, int& maxPage, int& selFromPage, int& selToPage);
87 virtual void BeginPrinting();
88 virtual void BeginDocument(int startPage, int endPage, uint flags);
89 virtual bool HasPage(int pageNumber);
90 virtual void PrintPage(int page, TRect& rect, uint flags);
91 virtual void EndDocument();
92 virtual void EndPrinting();
93
94 // Accessors to data members of printout object
95 //
96 TSize GetPageSize() const;
97 LPCTSTR GetTitle() const;
98 bool WantBanding() const;
99 void SetBanding(bool banding=true);
100 bool WantForceAllBands() const;
101 void SetForceAllBands(bool force=true);
102 TPrintDC* GetPrintDC();
103
104 protected:
105
106 void SetTitle(LPCTSTR title);
107 void SetTitle(const tstring& title);
108 void SetPrintDC(TPrintDC* dc);
109 void SetPageSize(const TSize& pagesize);
110
112
113 /// Title is the current title to use for the printout. By default, this title
114 /// appears in the Abort dialog box and as the name of the job in the Print Manager.
115 //
116 tstring Title;
117
118 /// If Banding is true, the printout is banded and the PrintPage function is called
119 /// once for every band. Otherwise, PrintPage is called only once for every page.
120 /// Banding a printout is more memory- and time-efficient than not banding. By
121 /// default, Banding is set to false.
122 //
123 bool Banding;
124
125 /// Many device drivers do not provide all printer bands if both text and graphics
126 /// are not performed on the first band (which is typically a text-only band).
127 /// Leaving ForceAllBands true forces the printer driver to provide all bands
128 /// regardless of what calls are made in the PrintPage function. If PrintPage does
129 /// nothing but display text, it is more efficient for ForceAllBands to be false. By
130 /// default, it is true. ForceAllBands takes effect only if Banding is true.
131 //
132 bool ForceAllBands;
133
134 TPrintDC* DC; ///< pointer to DC created amd owned by our TPrinter
135 TSize PageSize; ///< dimensions of the printout page
136
137 private:
138
139 // Hidden to prevent accidental copying or assignment
140 //
141 TPrintout(const TPrintout&);
143
145};
146
148
149//
150/// \class TPrinter
151/// TPrinter is an encapsulation around the Windows printer device interface,
152/// and represents the physical printer device.
153///
154/// To print or configure a printer, initialize an instance of TPrinter.
155/// To print a TPrintout, send the TPrintout to the TPrinter's Print function.
156///
157/// Examples:
158///
159/// \code
160/// auto defaultPrinter = TPrinter{};
161/// defaultPrinter.Print(parent, printout, true); // Prompt.
162/// auto pdfPrinter = TPrinter{"Microsoft Print to PDF"};
163/// pdfPrinter.Print(nullptr, printout, false); // Do not prompt.
164/// \endcode
165//
167{
168 public:
169
170 //
171 /// Contains information about the initialization and environment of a printer device.
172 /// Encapsulates the DEVMODE structure in the Windows API.
173 /// http://msdn.microsoft.com/en-gb/library/windows/desktop/dd183565.aspx
174 //
176 {
177 public:
178 TDevMode(const tstring& device);
179
180 //
181 /// Returns a pointer to the device data (const).
182 //
183 auto GetData() const -> const DEVMODE* { return reinterpret_cast<const DEVMODE*>(Buffer.data()); }
184
185 //
186 /// Returns a pointer to the device data.
187 //
188 auto GetData() -> DEVMODE* { return reinterpret_cast<DEVMODE*>(Buffer.data()); }
189
190 private:
191 std::vector<char> Buffer;
192 };
193
194 static auto GetDefaultPrinter() -> tstring;
195
196 explicit TPrinter(const tstring& device = GetDefaultPrinter());
198 virtual ~TPrinter();
199
200 void SetDevice(const tstring& device);
201 virtual void ClearDevice();
202 virtual void Setup(TWindow* parent);
203 virtual bool Print(TWindow* parent, TPrintout& printout, bool prompt);
204 virtual void ReportError(TWindow* parent, TPrintout& printout);
205
206 TPrintDialog::TData& GetSetup();
207 auto GetSetup() const -> const TPrintDialog::TData& { return const_cast<TPrinter*>(this)->GetSetup(); }
208 auto GetDC() -> std::unique_ptr<TPrintDC>;
209
210 static void SetUserAbort(HDC abortDC = HDC(-1));
211 static HDC GetUserAbort();
212
213 // Accessors to protected state data
214 //
215 int GetError();
216
217 TPrintDialog::TData* GetData();
218 void SetData(TPrintDialog::TData* data);
219
220 TSize GetPageSize() const;
221 void SetPageSize(const TSize& pagesize);
222 TSize GetPageSizeInch() const;
223 void SetPageSizeInch(const TSize& pageSizeInch);
224
225 /// \name Retrieves/assigns the output file
226 /// The output file can be set to redirect the print job.
227 /// Set to blank to disable redirection (default).
228 //
229 /// @{
230 LPCTSTR GetOutputFile() const;
231 void SetOutputFile(const tstring& outputFile);
232 /// @}
233
234 virtual void SetPageSizes(const TPrintDC& dc);
235
236 //
237 /// Encapsulates the capability constants defined for the Windows API function DeviceCapabilities.
238 /// http://msdn.microsoft.com/en-us/library/windows/desktop/dd183552.aspx
239 /// \sa GetCapability()
240 //
242 {
243 dcBinNames = DC_BINNAMES,
244 dcBins = DC_BINS,
245 dcCollate = DC_COLLATE,
246 dcColorDevice = DC_COLORDEVICE,
247 dcCopies = DC_COPIES,
248 dcDriver = DC_DRIVER,
249 dcDuplex = DC_DUPLEX,
250 dcEnumResolutions = DC_ENUMRESOLUTIONS,
251 dcExtra = DC_EXTRA,
252 dcFields = DC_FIELDS,
253 dcFileDependencies = DC_FILEDEPENDENCIES,
254 dcMaxExtent = DC_MAXEXTENT,
255 dcMediaReady = DC_MEDIAREADY,
256 dcMediaTypeNames = DC_MEDIATYPENAMES,
257 dcMediaTypes = DC_MEDIATYPES,
258 dcMinExtent = DC_MINEXTENT,
259 dcOrientation = DC_ORIENTATION,
260 dcNup = DC_NUP,
261 dcPaperNames = DC_PAPERNAMES,
262 dcPapers = DC_PAPERS,
263 dcPaperSize = DC_PAPERSIZE,
264 dcPersonality = DC_PERSONALITY,
265 dcPrinterMem = DC_PRINTERMEM,
266 dcPrintRate = DC_PRINTRATE,
267 dcPrintRatePpm = DC_PRINTRATEPPM,
268 dcPrintRateUnit = DC_PRINTRATEUNIT,
269 dcSize = DC_SIZE,
270 dcStaple = DC_STAPLE,
271 dcTrueType = DC_TRUETYPE,
272 dcVersion = DC_VERSION
273 };
274
275 //
276 /// Get information about the device.
277 /// This is a wrapper for the Windows API function DeviceCapabilities.
278 /// http://msdn.microsoft.com/en-us/library/windows/desktop/dd183552.aspx
279 /// \note This function is not type-safe. Prefer the type-safe accessors instead.
280 //
282 {
283 auto& s = GetSetup();
284 return DeviceCapabilities(s.GetDeviceName(), s.GetOutputName(), capability, output, s.GetDevMode());
285 }
286
287 /// \name Return types for capability accessors
288 /// @{
289
290 using TBinNames = std::vector<tstring>; ///< Return type for GetBinNames.
291 using TBins = std::vector<WORD>; ///< Return type for GetBins.
292 using TResolutions = std::vector<TSize>; ///< Return type for GetResolutions.
293 using TFileDependencies = std::vector<tstring>; ///< Return type for GetDriverDependencies.
294 using TPaperForms = std::vector<tstring>; ///< Return type for GetReadyMedia.
295 using TMediaTypeNames = std::vector<tstring>; ///< Return type for GetMediaTypeNames.
296 using TMediaTypes = std::vector<DWORD>; ///< Return type for GetMediaTypes.
297 using TNupConfigurations = std::vector<int>; ///< Return type for GetNupConfigurations.
298 using TPaperNames = std::vector<tstring>; ///< Return type for GetPaperNames.
299 using TPapers = std::vector<WORD>; ///< Return type for GetPapers.
300 using TPaperSizes = std::vector<TSize>; ///< Return type for GetPaperSizes.
301 using TDescriptionLanguages = std::vector<tstring>; ///< Return type for GetDescriptionsLanguages.
302
303 //
304 /// Return type for GetPrintRateUnit.
305 //
307 {
308 pruUnknown = 0,
309 pruPagesPerMinute = PRINTRATEUNIT_PPM,
310 pruCharactersPerSecond = PRINTRATEUNIT_CPS,
311 pruLinesPerMinute = PRINTRATEUNIT_LPM,
312 pruInchesPerMinute = PRINTRATEUNIT_IPM
313 };
314
315 /// @}
316 /// \name Capability accessors (type-safe encapsulations of GetCapability)
317 /// @{
318
319 auto GetBinNames() const -> TBinNames;
320 auto GetBins() const -> TBins;
321 auto CanCollate() const -> bool;
322 auto IsColorDevice() const -> bool;
323 auto GetMaxCopies() const -> int;
324 auto GetDriverVersion() const -> DWORD;
325 auto HasDuplexSupport() const -> bool;
326 auto GetResolutions() const -> TResolutions;
327 auto GetDevModeExtra() const -> int;
328 auto GetDevModeFields() const -> DWORD;
329 auto GetDriverDependencies() const -> TFileDependencies;
330 auto GetMaxExtent() const -> TSize;
331 auto GetReadyMedia() const -> TPaperForms;
332 auto GetMediaTypeNames() const -> TMediaTypeNames;
333 auto GetMediaTypes() const -> TMediaTypes;
334 auto GetMinExtent() const -> TSize;
335 auto GetLandscapeOrientation() const -> int;
336 auto GetNupConfigurations() const -> TNupConfigurations;
337 auto GetPaperNames() const -> TPaperNames;
338 auto GetPapers() const -> TPapers;
339 auto GetPaperSizes() const -> TPaperSizes;
340 auto GetDescriptionLanguages() const -> TDescriptionLanguages;
341 auto GetMemoryCapacity() const -> int;
342 auto GetPrintRate() const -> int;
343 auto GetPrintRatePpm() const -> int;
344 auto GetPrintRateUnit() const -> TPrintRateUnit;
345 auto GetDevModeSize() const -> int;
346 auto CanStaple() const -> bool;
347 auto GetTrueTypeCapabilities() const -> DWORD;
348 auto GetDriverSpecificationVersion() const -> DWORD;
349
350 /// @}
351
352 protected:
353 virtual bool ExecPrintDialog(TWindow* parent);
354 virtual bool ExecPageSetupDialog(TWindow* parent);
355 virtual TWindow* CreateAbortWindow(TWindow* parent, TPrintout& printout);
356
358 int Error; ///< negative if error occurred during print
359 TPrintDialog::TData* Data; ///< printer setup information
360
361 TSize PageSize; ///< size of the page
362 TSize PageSizeInch; ///< size of an inch on the page
363 tstring OutputFile; ///< filename for output redirection (see request #3044058)
364
365 private:
366 static HDC UserAbortDC; ///< Set by print dialog to prntDC if user cancels. Set to -1 cancels all print jobs.
367
368 // Hidden to prevent accidental copying or assignment
369 //
370 TPrinter(const TPrinter&);
371 TPrinter& operator =(const TPrinter&);
372
374};
375
377
378//
379/// \class TXPrinter
380/// TXPrinter describes an exception that results from an invalid printer object.
381/// This type of error can occur when printing to the physical printer.
382//
384{
385 public:
387
388 TXPrinter* Clone();
389 void Throw();
390 static void Raise(uint resId = IDS_PRINTERERROR);
391};
392
393//
394/// \class TXPrinting
395/// TXPrinting describes an exception that indicates that printing failed.
396/// See GetErrorMessage for error codes.
397//
399{
400 public:
402
403 void Throw();
404 static void Raise(int error = SP_ERROR);
405
406 int Error;
407 tstring GetErrorMessage(TModule* = 0) const;
408};
409
410/// @}
411
412#include <owl/posclass.h>
413
414} // OWL namespace
415
416#endif // OWL_PRINTER_H
Typically used to obtain information from a user, a dialog box is a window inside of which other cont...
Definition dialog.h:85
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:78
A DC class that provides access to a printer.
Definition dc.h:874
TPrintDialog::TData contains information required to initialize the printer dialog box with the user'...
Definition printdia.h:58
TPrintDialog displays a modal print or a page setup dialog.
Definition printdia.h:39
Contains information about the initialization and environment of a printer device.
Definition printer.h:176
auto GetData() const -> const DEVMODE *
Returns a pointer to the device data (const).
Definition printer.h:183
auto GetData() -> DEVMODE *
Returns a pointer to the device data.
Definition printer.h:188
TPrinterAbortDlg is the object type of the default printer-abort dialog box.
Definition printer.h:47
HDC PrnDC
Device context to print on.
Definition printer.h:55
DECLARE_RESPONSE_TABLE(TPrinterAbortDlg)
TPrinter is an encapsulation around the Windows printer device interface, and represents the physical...
Definition printer.h:167
std::vector< tstring > TDescriptionLanguages
Return type for GetDescriptionsLanguages.
Definition printer.h:301
std::vector< tstring > TPaperNames
Return type for GetPaperNames.
Definition printer.h:298
std::vector< tstring > TPaperForms
Return type for GetReadyMedia.
Definition printer.h:294
auto GetSetup() const -> const TPrintDialog::TData &
Definition printer.h:207
std::vector< WORD > TBins
Return type for GetBins.
Definition printer.h:291
std::vector< tstring > TMediaTypeNames
Return type for GetMediaTypeNames.
Definition printer.h:295
std::vector< tstring > TBinNames
Return type for GetBinNames.
Definition printer.h:290
std::vector< tstring > TFileDependencies
Return type for GetDriverDependencies.
Definition printer.h:293
TPrintRateUnit
Return type for GetPrintRateUnit.
Definition printer.h:307
std::vector< int > TNupConfigurations
Return type for GetNupConfigurations.
Definition printer.h:297
std::vector< DWORD > TMediaTypes
Return type for GetMediaTypes.
Definition printer.h:296
TCapability
Encapsulates the capability constants defined for the Windows API function DeviceCapabilities.
Definition printer.h:242
std::vector< TSize > TPaperSizes
Return type for GetPaperSizes.
Definition printer.h:300
std::vector< WORD > TPapers
Return type for GetPapers.
Definition printer.h:299
auto GetCapability(TCapability capability, TCHAR *output) const -> DWORD
Get information about the device.
Definition printer.h:281
std::vector< TSize > TResolutions
Return type for GetResolutions.
Definition printer.h:292
TPrintout represents the physical printed document that is to sent to a printer to be printed.
Definition printer.h:79
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
The tagSIZE struct is defined as.
Definition geometry.h:234
Classes that inherit from TStreamableBase are known as streamable classes (their objects can be writt...
Definition objstrm.h:108
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
TXOwl is root class of the ObjectWindows exception hierarchy.
Definition except.h:38
TXPrinter describes an exception that results from an invalid printer object.
Definition printer.h:384
TXPrinting describes an exception that indicates that printing failed.
Definition printer.h:399
Definition of TDialog class and TDialogAttr struct.
#define DECLARE_STREAMABLE_OWL(cls, ver)
Definition objstrm.h:1529
#define DECLARE_STREAMABLE_INLINES(cls)
Definition objstrm.h:1538
TPrintoutFlags
TPrintout banding flags.
Definition printer.h:64
@ pfText
Current band accepts text.
Definition printer.h:66
@ pfBoth
Current band accepts both text and graphics.
Definition printer.h:67
@ pfGraphics
Current band accepts graphics.
Definition printer.h:65
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
#define protected_data
Definition defs.h:208
#define _OWLCLASS
Definition defs.h:338
Definition of Print and PrintSetup common Dialogs classes.