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