OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
printer.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
4//
5//----------------------------------------------------------------------------
6#include <owl/pch.h>
7#include <owl/applicat.h>
8#include <owl/appdict.h>
9#include <owl/window.h>
10#include <owl/framewin.h>
11#include <owl/dc.h>
12#include <owl/static.h>
13#include <owl/printer.h>
14
15using namespace std;
16
17#if defined(__BORLANDC__)
18# pragma option -w-ccc // Disable "Condition is always true/false"
19#endif
20
21namespace owl {
22
24
25
26//
27// Template used to set and clear a bunch of flags at once
28//
29template <class T1, class T2>
30inline void SetClear(T1& var, T2 bitsOn, T2 bitsOff) {
31 var &= ~bitsOff;
32 var |= bitsOn;
33}
34
35// Define 'MANUAL_ABORT_CALL to enable the explicit abort proc call
36//
37// #define MANUAL_ABORT_CALL
38
39
40//----------------------------------------------------------------------------
41
42//
43// class TFormattedStatic
44// ~~~~~ ~~~~~~~~~~~~~~~~
45// Static control that uses its resource title as a printf format string to
46// format one or two text strings provided in the constructor
47//
48class TFormattedStatic: public TStatic {
49 public:
50 TFormattedStatic(TWindow* parent, int resId, const tstring& text, const tstring& text2 = tstring());
51
52 protected:
53 void SetupWindow();
54
55 private:
56 tstring Text; // Text to display
57 tstring Text2;
58};
59
60//
61// Construct the object.
62// Copy the two strings passed.
63// Second string is optional.
64//
65TFormattedStatic::TFormattedStatic(TWindow* parent, int resId, const tstring& text, const tstring& text2)
66: TStatic(parent, resId, 0),
67 Text(text),
68 Text2(text2)
69{}
70
71//
72// Override SetupWindow to set the text for the static control.
73//
74void
75TFormattedStatic::SetupWindow()
76{
77 TStatic::SetupWindow();
78
79 // Use the text retrieved from the resource as a printf template for
80 // the one or two text strings, then update the control text with the result.
81 //
82 tstring c = GetText();
83 int len = static_cast<int>(c.length() + Text.length() + Text2.length() + 5);
84 TAPointer<tchar> buff(new tchar[len]);
85 _stprintf(buff, c.c_str(), Text.c_str(), Text2.c_str());
86 SetText(buff);
87}
88
89//
90// class TNumericStatic
91// ~~~~~ ~~~~~~~~~~~~~~
92// Static control that uses its resource title as a printf format string to
93// format one or two text strings provided in the constructor
94//
95class TNumericStatic: public TStatic
96{
97 public:
98 TNumericStatic(TWindow* parent, int resId, int number);
99
100 protected:
101 TResult EvSetNumber(TParam1, TParam2);
102
103 private:
104 int Number; // Number to display
105
106 DECLARE_RESPONSE_TABLE(TNumericStatic);
107};
108
109#define WM_SETNUMBER WM_USER+100
110
111DEFINE_RESPONSE_TABLE1(TNumericStatic, TStatic)
114
115//
116// Construct the object and remember the number to display.
117//
118TNumericStatic::TNumericStatic(TWindow* parent, int resId, int number)
119: TStatic(parent, resId, 0),
120 Number(number)
121{}
122
123//
124// Handle our user defined message to set the number displayed in the %d part
125// of the Title format string. If the number is <= 0, then hide this window
126//
127TResult
128TNumericStatic::EvSetNumber(TParam1 param1, TParam2)
129{
130 Number = static_cast<int>(param1);
131 if (Number > 0) {
132 LPCTSTR c = GetCaption();
133 CHECK(c);
134 if (c)
135 {
136 int len = static_cast<int>(::_tcslen(c) + sizeof(Number) + 5);
137 TAPointer<tchar> buff(new tchar[len]);
138 wsprintf(buff, c, Number);
139 SetText(buff);
140 }
141 }
142 THandle hWndDefault = GetParentO()->GetDlgItem(-1);
143 if (Number > 0)
144 {
146 SetWindowPos(HWND_TOP, 0, 0, 0, 0, flags);
147 if (hWndDefault)
148 ::ShowWindow(hWndDefault, SW_HIDE);
149 UpdateWindow();
150 }
151 return 0;
152}
153
154
155//----------------------------------------------------------------------------
156
157DEFINE_RESPONSE_TABLE1(TPrinterAbortDlg, TDialog)
158 EV_COMMAND(IDCANCEL, CmCancel),
160
161
162//
163/// Constructs an Abort dialog box that contains a Cancel button and displays the
164/// given title, device, and port.
165//
166TPrinterAbortDlg::TPrinterAbortDlg(TWindow* parent, TResId resId, const tstring& title, const tstring& device, const tstring& port, HDC prnDC)
167:
168 TDialog(parent, resId),
169 PrnDC(prnDC)
170{
171 new TNumericStatic(this, ID_PAGE, 0);
172 new TFormattedStatic(this, ID_TITLE, title);
173 new TFormattedStatic(this, ID_DEVICE, device, port);
174 new TNumericStatic(this, ID_TOPAGE, 0);
175}
176
177//
178/// Overrides SetupWindow. This function disables the Close system menu option.
179//
180void
182{
183 // Ignore missing controls, resource may be different.
184 //
185 // While needlessly flexible, previous versions of OWL allowed a derived
186 // dialog to ommit the controls required by this base dialog class, and/or
187 // to redefine the control identifiers.
188 //
189 // Note that doing so will cause the dialog to lack the corresponding
190 // functionality of these controls, as the printing code relies on these
191 // controls being present with the identifiers defined by the
192 // IDD_ABORTDIALOG dialog resource (i.e. ID_PAGE and ID_TOPAGE).
193 // Otherwise no page number progress will be reported by TPrinter::Print.
194 //
195 // The updated code below still allows redefinition for backwards
196 // compatibility, but it logs a warning and uses more stringent exception
197 // handling to filter out exceptions caused by other issues.
198 // The original code used a "catch all" handler that did nothing.
199 //
200 // Note that this code depends on our controls being last in the children
201 // list. This can be assumed since TWindow::AddChild inserts children at
202 // the front of the list, i.e. any additional controls defined by a subclass
203 // will have already been constructed if and when our controls should fail to
204 // create due to a missing or redefined resource. Hence the state of the
205 // derived class is unaffected in this case, and we can safely ignore the
206 // failed controls. It is also vital that no code relies on these controls
207 // to function. TPrinter::Print currently passes messages to these controls
208 // but doesn't rely on that succeeding.
209 //
210 try {
212 }
213 catch (const TXWindow& x) {
214 const TWindow* w = x.GetWindow();
215 int id = w ? w->GetId() : 0;
216 switch (id) {
217 case ID_PAGE:
218 case ID_TITLE:
219 case ID_DEVICE:
220 case ID_TOPAGE:
221 WARN(true, _T("TPrinterAbortDlg control failure [id=") << id << _T("]: ") << x.what());
222 break; // Do nothing. Let these controls fail silently.
223
224 default:
225 throw; // The cause is unknown. Rethrow the exception.
226 }
227 }
228 EnableMenuItem(GetSystemMenu(false), SC_CLOSE, MF_GRAYED);
229}
230
231//
232/// Handles the print-cancel button by setting the user print abort flag in the
233/// application.
234//
235void
243
244//----------------------------------------------------------------------------
245
246//
247/// Constructs a TXPrinter object with a default IDS_PRINTERERROR message.
248//
254
255//
256/// Clone the exception object for safe throwing across stack frames.
257//
260{
261 return new TXPrinter(*this);
262}
263
264//
265/// Throws the exception.
266//
267void
269{
270 throw *this;
271}
272
273//
274/// Creates the exception object and throws it.
275//
276void
278{
279 TXPrinter(resId).Throw();
280}
281
282//----------------------------------------------------------------------------
283
284//
285/// Constructs a TXPrinting object with a default IDS_PRINTERERROR message.
286//
288:
289 TXOwl(IDS_PRINTERERROR), // TODO: Create specific string for this exception?
290 Error(error)
291{
292}
293
294//
295/// Throws the exception.
296//
297void
299{
300 throw *this;
301}
302
303//
304/// Creates the exception object and throws it.
305//
306void
308{
309 TXPrinting(error).Throw();
310}
311
312//
313/// Returns the error message for the current error code.
314/// If the given module is null, the message is loaded from the global module.
315//
318{
319 TModule& module = m ? *m : GetGlobalModule();
321 switch (Error)
322 {
323 case SP_APPABORT:
325 break;
326 case SP_USERABORT:
328 break;
329 case SP_OUTOFDISK:
331 break;
332 case SP_OUTOFMEMORY:
334 break;
335 case SP_ERROR:
336 default:
338 break;
339 }
340 return module.LoadString(errorMsgId);
341}
342
343//----------------------------------------------------------------------------
344
345namespace {
346
348{
349 // Get the size required for this device's DEVMODE structure.
350 //
351 const auto n = const_cast<LPTSTR>(device.c_str());
352 const auto s = DocumentProperties(nullptr, nullptr, n, nullptr, nullptr, 0);
353 if (s <= 0) throw TXPrinter{};
354
355 // Now, create a buffer of the required size and get the device data.
356 //
357 auto buffer = vector<char>(s);
358 const auto p = reinterpret_cast<PDEVMODE>(buffer.data());
359 const auto r = DocumentProperties(nullptr, nullptr, n, p, nullptr, DM_OUT_BUFFER);
360 if (r != IDOK) throw TXPrinter{};
361 return buffer;
362}
363
364} // namespace
365
366//
367/// Retrieves the DEVMODE device data for the given device.
368//
372
373//----------------------------------------------------------------------------
374
375//
376/// Set by printing dialog if user cancels.
377//
378HDC TPrinter::UserAbortDC = nullptr;
379
380//
381/// Retrieves the printer name of the default printer for the current user on the local computer.
382/// Wrapper for the Windows API function GetDefaultPrinter.
383/// http://msdn.microsoft.com/en-us/library/windows/desktop/dd144876.aspx
384/// Throws TXPrinter if there is no default printer, or if an unexpected error occurs.
385//
387{
388 auto b = tstring(15, _T('\0')); // Intentionally small to allow Small String Optimization.
389 b.resize(b.capacity()); // Ensures we use the full size of our buffer.
390 auto n = static_cast<DWORD>(b.size()) + 1; // The buffer includes the null-terminator as well.
391
392 // We retry calls to ::GetDefaultPrinter in a loop since the initial buffer may be insufficient.
393 // Also, although unlikely, the printer may change between calls to ::GetDefaultPrinter, asking
394 // for a larger and larger buffer for each iteration around the loop.
395 //
396 while (!::GetDefaultPrinter(&b[0], &n))
397 switch (GetLastError())
398 {
400 CHECK(n > b.size() + 1);
401 b.resize(n - 1); // String size excludes the null-terminator.
402 break;
403
404 case ERROR_FILE_NOT_FOUND: // There is no default printer.
405 default:
406 throw TXPrinter{};
407 }
408 CHECK(n > 0); // We should at least have a null-terminator.
409 b.resize(n - 1);
410 return b;
411}
412
413//
414/// Associates this TPrinter object with the given printer device.
415/// If no name is given, the name of the current default printer is used.
416//
418 : Error{0}, Data{nullptr}, PageSize{}, PageSizeInch{}, OutputFile{}
419{
421}
422
423//
424/// Move-constructor; enables auto-declaration style.
425//
427 : Error{other.Error}, Data{other.Data},
428 PageSize{other.PageSize}, PageSizeInch{other.PageSizeInch},
429 OutputFile{move(other.OutputFile)}
430{
431 other.Data = nullptr;
432}
433
434//
435/// Frees the resources allocated to TPrinter.
436//
438{
439 delete Data;
440}
441
442//
443/// Assigns the device to be represented by this TPrinter object.
444//
446{
448 d->SetDevNames(_T(""), device, _T(""));
449 d->SetDevMode(TDevMode{device}.GetData());
450 SetData(d.get());
451 d.release(); // We took ownership.
452}
453
454//
455/// Returns a reference to the TPrintDialog data structure.
456//
458{
459 return *Data;
460}
461
462//
463/// Returns the device context already obtained in our setup data, or if none, creates a new
464/// one based on the device name and device initialization data (DEVMODE).
465//
467{
468 const auto d = GetData(); CHECK(d);
469 const auto dc = d->TransferDC();
470 return dc ? unique_ptr<TPrintDC>(dc) :
471 make_unique<TPrintDC>(d->GetDeviceName(), d->GetDevMode());
472}
473
474//
475/// Sets the user abort DC for the printer.
476//
478{
479 UserAbortDC = abortDC;
480}
481
482//
483/// Returns the abort DC.
484//
486{
487 return UserAbortDC;
488}
489
490//
491/// Returns the error code from the printer.
492//
494{
495 return Error;
496}
497
498//
499/// Returns the common dialog data associated with the printer.
500//
502{
503 return Data;
504}
505
506//
507/// Sets the common dialog data; takes ownership.
508//
510{
511 if (data == Data) return;
512 if (Data) delete Data;
513 Data = data;
514}
515
516//
517/// Returns the size of the page.
518//
520{
521 return PageSize;
522}
523
524//
525/// Sets the page's size.
526//
528{
529 PageSize = pagesize;
530}
531
532//
533/// Returns the size of an inch the page.
534//
536{
537 return PageSizeInch;
538}
539
540//
541/// Sets the size of an inch on the page.
542//
544{
545 PageSizeInch = pageSizeInch;
546}
547
548//
549/// Called by the Destructor, ClearDevice disassociates the device
550/// with the current printer. ClearDevice changes the current status of the printer
551/// to PF_UNASSOCIATED, which causes the object to ignore all calls to Print until
552/// the object is reassociated with a printer.
553//
555{
556 Data->ClearDevMode();
557 Data->ClearDevNames();
558}
559
560namespace {
561
562//
563// Common implementation of GetCapability for capabilities that return a vector of strings.
564//
566{
569 auto r = vector<tstring>{};
570 const auto n = p.GetCapability(c, nullptr);
571 if (n == static_cast<DWORD>(-1)) return r;
573 const auto m = p.GetCapability(c, reinterpret_cast<LPTSTR>(b.data()));
574 if (m == static_cast<DWORD>(-1)) return r;
575 CHECK(m <= n); // If there are more elements since the last call, we had a buffer overflow!
576 for (auto i = 0; i != min(m, n); ++i)
577 {
578 // The string buffers may not be null-terminated, hence the two-step construction.
579 //
580 const auto p = &b[i * stringBufferSize];
581 r.emplace_back(tstring{p, static_cast<size_t>(stringBufferSize)}.c_str());
582 }
583 return r;
584}
585
586} // namespace
587
588//
589/// Retrieves the names of the printer's paper bins.
590/// If the function fails, an empty vector is returned.
591/// \sa TCapability::dcBinNames
592//
594{
595 return GetCapabilityStrings_(*this, dcBinNames, 24);
596}
597
598//
599/// Retrieves a list of available paper bins.
600/// Each element of the returned vector is a bin identifier, e.g. DMBIN_AUTO.
601/// See the description of the dmDefaultSource member of the DEVMODE structure.
602/// If the function fails, an empty vector is returned.
603/// \sa TCapability::dcBins
604//
606{
607 auto f = [&](LPTSTR s) { return GetCapability(dcBins, s); };
608 const auto n = f(nullptr);
609 if (n == static_cast<DWORD>(-1)) return TBins{};
610 auto r = TBins(n);
611 const auto m = f(reinterpret_cast<LPTSTR>(r.data()));
612 if (m == static_cast<DWORD>(-1)) return TBins{};
613 CHECK(m <= n); // If there are more elements since the last call, we had a buffer overflow!
614 return r;
615}
616
617//
618/// Returns whether the printer supports collating.
619/// If the function fails, `false` is returned.
620/// \sa TCapability::dcCollate
621//
622auto TPrinter::CanCollate() const -> bool
623{
624 return GetCapability(dcCollate, nullptr) == 1;
625}
626
627//
628/// Returns whether the printer supports color printing.
629/// If the function fails, `false` is returned.
630/// \sa TCapability::dcColorDevice
631//
632auto TPrinter::IsColorDevice() const -> bool
633{
634 return GetCapability(dcColorDevice, nullptr) == 1;
635}
636
637//
638/// Return the maximum number of copies the printer can print.
639/// If the function fails, 0 is returned.
640/// \sa TCapability::dcCopies
641//
642auto TPrinter::GetMaxCopies() const -> int
643{
644 const auto n = GetCapability(dcCopies, nullptr);
645 if (n == static_cast<DWORD>(-1)) return 0;
646 return static_cast<int>(n);
647}
648
649//
650/// Returns the version number of the printer driver.
651/// If the function fails, 0xFFFFFFFF is returned.
652/// \sa TCapability::dcDriver
653//
655{
656 return GetCapability(dcDriver, nullptr);
657}
658
659//
660/// Returns whether the printer supports duplex printing.
661/// If the function fails, `false` is returned.
662/// \sa TCapability::dcDuplex
663//
664auto TPrinter::HasDuplexSupport() const -> bool
665{
666 return GetCapability(dcDuplex, nullptr) == 1;
667}
668
669//
670/// Retrieves a list of the resolutions supported by the printer.
671/// If the function fails, an empty vector is returned.
672/// \sa TCapability::dcEnumResolutions
673//
675{
676 auto r = TResolutions{};
677 auto f = [&](LPTSTR s) { return GetCapability(dcEnumResolutions, s); };
678 const auto n = f(nullptr);
679 if (n == static_cast<DWORD>(-1)) return r;
680 auto b = vector<LONG>(2 * n);
681 const auto m = f(reinterpret_cast<LPTSTR>(b.data()));
682 if (m == static_cast<DWORD>(-1)) return r;
683 CHECK(m <= n); // If there are more elements since the last call, we had a buffer overflow!
684 for (auto i = 0; i != 2 * min(m, n); i += 2)
685 r.emplace_back(b[i], b[i + 1]);
686 return r;
687}
688
689//
690/// Returns the number of bytes required for the device-specific portion of the DEVMODE
691/// structure for the printer driver.
692/// If the function fails, 0 is returned.
693/// \sa TCapability::dcExtra
694//
695auto TPrinter::GetDevModeExtra() const -> int
696{
697 const auto n = GetCapability(dcExtra, nullptr);
698 if (n == static_cast<DWORD>(-1)) return 0;
699 return static_cast<int>(n);
700}
701
702//
703/// Returns the `dmFields` member of the printer driver's DEVMODE structure.
704/// The `dmFields` member indicates which members in the device-independent portion of the
705/// structure are supported by the printer driver.
706/// \sa TCapability::dcFields
707//
709{
710 return GetCapability(dcFields, nullptr);
711}
712
713//
714/// Returns the names of any additional files that need to be loaded for the printer driver.
715/// If the function fails, an empty vector is returned.
716/// \sa TCapability::dcFileDependencies
717//
722
723//
724/// Returns the maximum paper size that the printer supports.
725/// If the function fails, TSize{0, 0} is returned.
726/// \sa TCapability::dcMaxExtent, TCapability::dcMinExtent
727//
729{
730 const auto m = GetCapability(dcMaxExtent, nullptr);
731 if (m == static_cast<DWORD>(-1)) return TSize{0, 0};
732 return TSize{LoInt16(m), HiInt16(m)};
733}
734
735//
736/// Returns the names of the paper forms that are currently available for use.
737/// If the function fails, an empty vector is returned.
738/// \sa TCapability::dcMediaReady
739//
741{
742 return GetCapabilityStrings_(*this, dcMediaReady, 64);
743}
744
745//
746/// Returns the names of the supported media types.
747/// If the function fails, an empty vector is returned.
748/// \sa TCapability::dcMediaTypeNames
749//
754
755//
756/// Returns a list of supported media types.
757/// For a list of possible media type values, see the description of the `dmMediaType` member
758/// of the DEVMODE structure.
759/// If the function fails, an empty vector is returned.
760/// \sa TCapability::dcMediaTypes
761//
763{
764 auto f = [&](LPTSTR s) { return GetCapability(dcMediaTypes, s); };
765 const auto n = f(nullptr);
766 if (n == static_cast<DWORD>(-1)) return TMediaTypes{};
767 auto r = TMediaTypes(n);
768 const auto m = f(reinterpret_cast<LPTSTR>(r.data()));
769 if (m == static_cast<DWORD>(-1)) return TMediaTypes{};
770 CHECK(m <= n); // If there are more elements since the last call, we had a buffer overflow!
771 return r;
772}
773
774//
775/// Returns the minimum paper size that the printer supports.
776/// If the function fails, TSize{0, 0} is returned.
777/// \sa TCapability::dcMinExtent, TCapability::dcMaxExtent
778//
780{
781 const auto m = GetCapability(dcMinExtent, nullptr);
782 if (m == static_cast<DWORD>(-1)) return TSize{0, 0};
783 return TSize{LoInt16(m), HiInt16(m)};
784}
785
786//
787/// Returns the angle of rotation between portrait and landscape orientation.
788/// The result is given in terms of the number of degrees that portrait orientation is rotated
789/// counter-clockwise to produce landscape orientation. If landscape orientation is not
790/// supported, then 0 is returned.
791/// If the function fails, 0 is returned.
792/// \sa TCapability::dcOrientation
793//
795{
796 const auto r = GetCapability(dcOrientation, nullptr);
797 if (r == static_cast<DWORD>(-1)) return 0;
798 return static_cast<int>(r);
799}
800
801//
802/// Retrieves a list of integers that indicate the printers ability to print multiple document
803/// pages per printed page. Each element of the list represent a supported configuration, given
804/// by the number of document pages per printed page.
805/// If the function fails, an empty vector is returned.
806/// \sa TCapability::dcNup
807//
809{
810 auto f = [&](LPTSTR s) { return GetCapability(dcNup, s); };
811 const auto n = f(nullptr);
812 if (n == static_cast<DWORD>(-1)) return TNupConfigurations{};
813 auto r = TNupConfigurations(n);
814 CHECK(sizeof(TNupConfigurations::value_type) == sizeof(DWORD));
815 const auto m = f(reinterpret_cast<LPTSTR>(r.data()));
816 if (m == static_cast<DWORD>(-1)) return TNupConfigurations{};
817 CHECK(m <= n); // If there are more elements since the last call, we had a buffer overflow!
818 return r;
819}
820
821//
822/// Returns a list of supported paper names.
823/// For example, paper names could be "Letter" or "Legal".
824/// If the function fails, an empty vector is returned.
825/// \sa TCapability::dcPaperNames
826//
828{
829 return GetCapabilityStrings_(*this, dcPaperNames, 64);
830}
831
832//
833/// Returns a list of supported paper sizes.
834/// For a list of the possible element values, see the description of the `dmPaperSize` member
835/// of the DEVMODE structure.
836/// If the function fails, an empty vector is returned.
837/// \sa TCapability::dcPapers
838//
840{
841 auto f = [&](LPTSTR s) { return GetCapability(dcPapers, s); };
842 const auto n = f(nullptr);
843 if (n == static_cast<DWORD>(-1)) return TPapers{};
844 auto r = TPapers(n);
845 const auto m = f(reinterpret_cast<LPTSTR>(r.data()));
846 if (m == static_cast<DWORD>(-1)) return TPapers{};
847 CHECK(m <= n); // If there are more elements since the last call, we had a buffer overflow!
848 return r;
849}
850
851//
852/// Retrieves the dimensions of each supported paper size.
853/// The unit is tenths of a millimeter (LOMETRIC).
854/// If the function fails, an empty vector is returned.
855/// \sa TCapability::dcPaperSize
856//
858{
859 auto r = TPaperSizes{};
860 auto f = [&](LPTSTR s) { return GetCapability(dcPaperSize, s); };
861 const auto n = f(nullptr);
862 if (n == static_cast<DWORD>(-1)) return r;
863 auto b = vector<POINT>(n);
864 const auto m = f(reinterpret_cast<LPTSTR>(b.data()));
865 if (m == static_cast<DWORD>(-1)) return r;
866 CHECK(m <= n); // If there are more elements since the last call, we had a buffer overflow!
867 for (auto i = 0; i != min(m, n); ++i)
868 r.emplace_back(b[i].x, b[i].y);
869 return r;
870}
871
872//
873/// Returns a list of printer description languages supported by the printer.
874/// If the function fails, an empty vector is returned.
875/// \sa TCapability::dcPersonality
876//
881
882//
883/// Returns the amount of available printer memory, in kilobytes.
884/// If the function fails, 0 is returned.
885/// \sa TCapability::dcPrinterMem
886//
888{
889 const auto r = GetCapability(dcPrinterMem, nullptr);
890 if (r == static_cast<int>(-1)) return 0;
891 return static_cast<int>(r);
892}
893
894//
895/// Returns the printer's print rate.
896/// Call GetCapability<TPrinter::dcPrintRateUnit> to determine the units of the returned value.
897/// If the function fails, 0 is returned.
898/// \sa TCapability::dcPrintRate, TCapability::dcPrintRateUnit, TPrintRateUnit
899//
900auto TPrinter::GetPrintRate() const -> int
901{
902 const auto r = GetCapability(dcPrintRate, nullptr);
903 if (r == static_cast<int>(-1)) return 0;
904 return static_cast<int>(r);
905}
906
907//
908/// Returns the printer's print rate in pages per minute.
909/// If the function fails, 0 is returned.
910/// \sa TCapability::dcPrintRatePpm
911//
912auto TPrinter::GetPrintRatePpm() const -> int
913{
914 const auto r = GetCapability(dcPrintRatePpm, nullptr);
915 if (r == static_cast<int>(-1)) return 0;
916 return static_cast<int>(r);
917}
918
919//
920/// Returns the printer's print rate units.
921/// The returned value determines the units for the value returned by GetCapability<TPrinter::dcPrintRate>.
922/// If the function fails, `pruUnknown` is returned.
923/// \sa TCapability::dcPrintRateUnit, TCapability::dcPrintRate, TPrintRateUnit
924//
926{
927 const auto r = GetCapability(dcPrintRateUnit, nullptr);
928 switch (r)
929 {
934 return static_cast<TPrintRateUnit>(r);
935
936 default:
937 return pruUnknown;
938 }
939}
940
941//
942/// Returns the `dmSize` member of the printer driver's DEVMODE structure.
943/// The `dmSize` member indicates the size (and hence version) of the DEVMODE structure.
944/// The size excludes the private driver-data that follows the structure. See the `dmDriverExtra` member.
945/// If the function fails, 0 is returned.
946/// \sa TCapability::dcSize
947//
948auto TPrinter::GetDevModeSize() const -> int
949{
950 const auto n = GetCapability(dcSize, nullptr);
951 if (n == static_cast<DWORD>(-1)) return 0;
952 return static_cast<int>(n);
953}
954
955//
956/// Returns whether the printer supports stapling.
957/// If the function fails, `false` is returned.
958/// \sa TCapability::dcStaple
959//
960auto TPrinter::CanStaple() const -> bool
961{
962 return GetCapability(dcStaple, nullptr) == 1;
963}
964
965//
966/// Retrieves the abilities of the printer to use TrueType fonts.
967/// The returned value can be a combination of flags DCTT_BITMAP, DCTT_DOWNLOAD and DCTT_SUBDEV.
968/// If the function fails, 0 is returned.
969/// \sa TCapability::dcTrueType
970//
972{
973 const auto r = GetCapability(dcTrueType, nullptr);
974 if (r == static_cast<DWORD>(-1)) return 0;
975 return r;
976}
977
978//
979/// Returns the specification version to which the printer driver conforms.
980/// If the function fails, 0xFFFFFFFF is returned.
981/// \sa TCapability::dcVersion
982//
984{
985 return GetCapability(dcVersion, nullptr);
986}
987
988// Abort procedure used during printing, called by windows. Returns true to
989// continue the print job, false to cancel.
990//
991int CALLBACK
993{
995 if(appl)
996 appl->PumpWaitingMessages();
997
998 // UserAbortDC will have been set by the AbortDialog
999 //
1001 TPrinter::SetUserAbort(nullptr);
1002 return false;
1003 }
1004 return code == 0 || code == SP_OUTOFDISK;
1005}
1006
1007//
1008/// Virtual called from within Print() to construct and execute a print dialog
1009/// before actual printing occurs. Return true to continue printing, false to
1010/// cancel
1011//
1012bool
1014{
1015 return TPrintDialog(parent, *Data).Execute() == IDOK;
1016}
1017
1018//
1019// Page setup dialog for Win95 support.
1020//
1021#if !defined(__GNUC__) //JJH added removal of pragma warn for gcc
1022#pragma warn -par
1023#endif
1024
1025/// Page setup dialog for Win95 support.
1026bool
1028{
1029 Data->DoPageSetup = true;
1030 bool ret = TPrintDialog(parent, *Data).Execute() == IDOK;
1031 Data->DoPageSetup = false;
1032 return ret;
1033}
1034
1035#if !defined(__GNUC__) //JJH added removal of pragma warn for gcc
1036#pragma warn .par
1037#endif
1038
1039
1040//
1041/// Virtual called from withing Print() just before the main printing loop to
1042/// construct and create the printing status, or abort window. This window
1043/// should use the control IDs specified in printer.rh
1044//
1045TWindow*
1047{
1048 TDC* dc = printout.GetPrintDC();
1049 TWindow* win = new TPrinterAbortDlg(parent, IDD_ABORTDIALOG,
1050 printout.GetTitle(),
1051 Data->GetDeviceName(),
1052 Data->GetOutputName(),
1053 dc ? HDC(*dc) : HDC(-1));
1054 win->Create();
1055 return win;
1056}
1057
1058//
1059/// Returns the filename for output redirection.
1060//
1061LPCTSTR
1063{
1064 return OutputFile.c_str();
1065}
1066
1067//
1068/// Sets the filename for output redirection.
1069//
1070void
1072{
1073 OutputFile = outputFile;
1074}
1075
1076//
1077/// Updates the PageSize variables by querying the device capabilities of the
1078/// specified device context.
1079//
1080void
1082{
1083 // !BB Should we try PHYSICALWIDTH and PHYSICALHEIGHT first and then
1084 // !BB fallback on HORZRES and VERTRES
1085 PageSize.cx = prnDC.GetDeviceCaps(HORZRES);
1086 PageSize.cy = prnDC.GetDeviceCaps(VERTRES);
1087 PageSizeInch.cx = prnDC.GetDeviceCaps(LOGPIXELSX);
1088 PageSizeInch.cy = prnDC.GetDeviceCaps(LOGPIXELSY);
1089}
1090
1091namespace
1092{
1093
1094 struct TPrintErrorHandler
1095 {
1096 friend int operator %(int r, const TPrintErrorHandler&)
1097 {
1098 if (r <= 0) TXPrinting::Raise(r);
1099 return r;
1100 }
1101 };
1102
1103 //
1104 // Calculate flags based on band info from the driver.
1105 // If a driver does not support BANDINFO the Microsoft recommended way
1106 // of determining text only bands is if the first band is the full page,
1107 // all others are graphics only or both.
1108 //
1109 uint CalculateBandFlags(TPrintout& printout, const TRect& bandRect)
1110 {
1111 PRECONDITION(printout.GetPrintDC());
1112 TPrintErrorHandler eh;
1113
1114 TPrintDC& dc = *printout.GetPrintDC();
1115 if (!ToBool(dc.QueryEscSupport(BANDINFO)))
1116 {
1117 const TRect pageRect(TPoint(0, 0), printout.GetPageSize());
1118 return (bandRect == pageRect) ? pfText : pfGraphics;
1119 }
1120 TBandInfo bandInfo;
1121 dc.BandInfo(bandInfo) %eh;
1122 return (bandInfo.HasGraphics ? pfGraphics : 0) |
1123 (bandInfo.HasText ? pfText : 0);
1124 }
1125
1126 //
1127 // Prints a page using the deprecated banding mechanism.
1128 // TODO: Review the necessity of this code.
1129 //
1130 void PrintBandPage(TPrintout& printout, int pageNum)
1131 {
1132 PRECONDITION(printout.GetPrintDC());
1133 TPrintErrorHandler eh;
1134 TPrintDC& dc = *printout.GetPrintDC();
1135 TRect bandRect(TPoint(0, 0), printout.GetPageSize());
1136 while (!bandRect.IsEmpty())
1137 {
1138 dc.NextBand(bandRect) %eh;
1140 if (printout.WantForceAllBands() && (bandFlags & pfBoth) == pfGraphics)
1141 dc.SetPixel(TPoint(0, 0), TColor::Black); // Some old drivers need this.
1142 dc.DPtoLP(bandRect, 2);
1143 printout.PrintPage(pageNum, bandRect, bandFlags);
1144 }
1145 }
1146
1147 //
1148 // Sets up the device context and forwards the call to the printout.
1149 //
1150 void PrintPlainPage(TPrintout& printout, int pageNum)
1151 {
1152 PRECONDITION(printout.GetPrintDC());
1153 TPrintErrorHandler eh;
1154 TPrintDC& dc = *printout.GetPrintDC();
1155 dc.StartPage() %eh;
1156 TRect pageRect(TPoint(0, 0), printout.GetPageSize());
1157 printout.PrintPage(pageNum, pageRect, pfBoth);
1158 dc.EndPage() %eh;
1159 }
1160
1161 //
1162 // Function type for the inner body of the print loop
1163 //
1164 typedef void (*TPageFunc)(TPrintout&, int pagenum);
1165
1166 //
1167 // Exception-safe begin and end code for a print job
1168 //
1169 struct TPrintingScope
1170 {
1171 TWindow& parent;
1172 TPrintout& printout;
1173
1174 TPrintingScope(TWindow& p, TPrintout& po) : parent(p), printout(po)
1175 {
1176 parent.EnableWindow(false);
1177 printout.BeginPrinting();
1178 }
1179
1180 ~TPrintingScope()
1181 {
1182 printout.EndPrinting();
1183 parent.EnableWindow(true);
1184 }
1185 };
1186
1187 //
1188 // Exception-safe begin and end code for printing a document
1189 //
1190 struct TDocumentScope
1191 {
1192 TPrintout& printout;
1193
1194 TDocumentScope(TPrintout& p, int fromPage, int toPage) : printout(p)
1195 {
1196 printout.BeginDocument(fromPage, toPage, pfBoth);
1197 }
1198
1199 ~TDocumentScope()
1200 {
1201 printout.EndDocument();
1202 }
1203 };
1204
1205 //
1206 // Prints all the pages in the given document.
1207 // If copies are requested, then repeatedly prints the document (for collated copies) or
1208 // pages (for non-collated copies) for the number of copies specified.
1209 //
1210 // TODO: Review the calling sequence in case of exceptions. The code currently calls TPrintout::EndDocument and
1211 // TPrintout::EndPrinting even if printing fails (exceptions). On the other hand, TPrintDC::EndPage and
1212 // TPrintDC::EndDoc are not called if printing fails (exceptions). This is consistent with the original code,
1213 // but the logic of this should be reviewed.
1214 //
1215 void PrintLoop(TPrintout& printout, int fromPage, int toPage, int copies, bool collated, LPCTSTR out,
1216 TWindow& abortWin, TPageFunc printPage)
1217 {
1218 PRECONDITION(printout.GetPrintDC());
1219 PRECONDITION(abortWin.GetParentO());
1221 PRECONDITION(copies >= 0);
1222 TPrintErrorHandler eh;
1223 TPrintDC& dc = *printout.GetPrintDC();
1224 TPrintingScope printingScope(*abortWin.GetParentO(), printout);
1225
1226 const int documentCopyCount = collated ? copies : 1;
1228 {
1229 TDocumentScope documentScope(printout, fromPage, toPage);
1230
1231 dc.StartDoc(printout.GetTitle(), out) %eh;
1232 abortWin.SendDlgItemMessage(ID_TOPAGE, WM_SETNUMBER, toPage);
1233 const int pageCopyCount = collated ? 1 : copies;
1234 for (int pageNum = fromPage; pageNum <= toPage && printout.HasPage(pageNum); ++pageNum)
1235 {
1236 abortWin.SendDlgItemMessage(ID_PAGE, WM_SETNUMBER, pageNum);
1238 printPage(printout, pageNum);
1239 }
1240 dc.EndDoc() %eh;
1241 }
1242 }
1243
1244} // namespace
1245
1246//
1247/// Print renders the given printout object on the associated printer device and
1248/// displays an Abort dialog box while printing. It displays any errors encountered
1249/// during printing. Prompt allows you to show the user a commdlg print dialog.
1250///
1251/// Note: The calling sequence here is somewhat of a catch-22 for the printout.
1252/// The printout cannot compute how many pages the document really has until the page
1253/// format is known. The printout doesn't get this information until SetPrintParams is
1254/// called, which cannot happen until the dialog has returned a device context.
1255/// Unfortunately, the page range information must be provided by GetDialogInfo which
1256/// has to be called first to set up the dialog.
1257///
1258/// The problem is that the printer/page options are in the same dialog as the page
1259/// range selection. The only way to handle this is to implement a custom interactive
1260/// dialog box that updates the page range in real-time depending on the selected
1261/// printer/page format. Or deactivate the page range altogether.
1262//
1263bool
1264TPrinter::Print(TWindow* parent, TPrintout& printout, bool prompt)
1265{
1266 PRECONDITION(parent);
1267
1268 //
1269 // Get page range & selection range (if any) from the document.
1270 //
1271 int selFromPage = 0;
1272 int selToPage = 0;
1273 printout.GetDialogInfo(Data->MinPage, Data->MaxPage, selFromPage, selToPage);
1274 if (selFromPage != 0)
1275 {
1276 Data->Flags &= ~PD_NOSELECTION;
1277 Data->FromPage = selFromPage;
1278 Data->ToPage = selToPage;
1279 }
1280 else {
1281 Data->Flags |= PD_NOSELECTION;
1282 Data->FromPage = 0;
1283 Data->ToPage = 999;
1284 }
1285 if (Data->MinPage != 0)
1286 {
1287 Data->Flags &= ~PD_NOPAGENUMS;
1288 if (Data->FromPage < Data->MinPage)
1289 Data->FromPage = Data->MinPage;
1290 else if (Data->FromPage > Data->MaxPage)
1291 Data->FromPage = Data->MaxPage;
1292 if (Data->ToPage < Data->MinPage)
1293 Data->ToPage = Data->MinPage;
1294 else if (Data->ToPage > Data->MaxPage)
1295 Data->ToPage = Data->MaxPage;
1296 }
1297 else
1298 Data->Flags |= PD_NOPAGENUMS;
1299
1300 //
1301 // Create & execute a TPrintDialog (or derived) and have it return a usable
1302 // DC if prompt is enabled. If the dialog fails because the default printer
1303 // changed, clear our device information & try again.
1304 //
1305 TPointer<TPrintDC> prnDC (nullptr); // Pointer to printer DC created by Printer Object
1306 if (prompt)
1307 {
1309 bool ok = ExecPrintDialog(parent);
1310 if (!ok && Data->Error == PDERR_DEFAULTDIFFERENT)
1311 {
1312 ClearDevice();
1313 ok = ExecPrintDialog(parent);
1314 }
1315 if (!ok)
1316 return false;
1317 prnDC = Data->TransferDC(); // We now own the DC, let prnDC manage it
1318 if (!prnDC)
1320 }
1321 else
1322 {
1323 // Construct the DC directly if prompting was not enabled.
1324 //
1325 prnDC = new TPrintDC{Data->GetDeviceName(), Data->GetDevMode()};
1326 }
1327
1328 // Update the device page format and forward the DC and page size to the printout.
1329 //
1331 printout.SetPrintParams(prnDC, GetPageSize());
1332
1333 // Figure out which page range to use: Selection, Dialog's from/to, whole document
1334 // range or all possible pages.
1335 //
1336 int fromPage;
1337 int toPage;
1338 if ((prompt && (Data->Flags & PD_SELECTION)) || selFromPage)
1339 {
1341 toPage = selToPage;
1342 }
1343 else if (prompt && (Data->Flags & PD_PAGENUMS))
1344 {
1345 fromPage = Data->FromPage;
1346 toPage = Data->ToPage;
1347 }
1348 else if (Data->MinPage)
1349 {
1350 fromPage = Data->MinPage;
1351 toPage = Data->MaxPage;
1352 }
1353 else
1354 {
1355 fromPage = 1;
1356 toPage = INT_MAX;
1357 }
1358
1359 // Redirect output if requested.
1360 //
1361 LPCTSTR out = OutputFile.length() == 0 ? nullptr : OutputFile.c_str();
1362
1363 // Only band if the user requests banding and the printer supports banding.
1364 // TODO: Banding is obsolete. Review the necessity of this code.
1365 //
1366 bool banding = printout.WantBanding() && (prnDC->GetDeviceCaps(RASTERCAPS) & RC_BANDING);
1367
1368 // Create modeless abort dialog and start printing.
1369 //
1370 try
1371 {
1372 TPointer<TWindow> abortWin(CreateAbortWindow(parent, printout));
1373 prnDC->SetAbortProc(TPrinterAbortProc);
1374 SetUserAbort(nullptr);
1375 PrintLoop(printout, fromPage, toPage, Data->Copies, Data->Flags & PD_COLLATE, out, *abortWin,
1377 }
1378 catch (const TXPrinting& x)
1379 {
1380 // Report error if not already reported.
1381 //
1382 Error = x.Error;
1383 if (x.Error & SP_NOTREPORTED)
1384 ReportError(parent, printout);
1385 return false;
1386 }
1387 return true;
1388}
1389
1390//
1391/// Setup lets the user select and/or configure the currently associated printer.
1392/// Setup opens a dialog box as a child of the given window. The user then selects
1393/// one of the buttons in the dialog box to select or configure the printer. The
1394/// form of the dialog box is based on TPrintDialog, the common dialog printer
1395/// class.
1396/// The options button allows the user acces to the specific driver's options.
1397//
1399{
1400 ExecPageSetupDialog(parent);
1401}
1402
1403//
1404/// Reports the current error by bringing up a system message box with an error message
1405/// composed of the error description and document title.
1406/// This function can be overridden to show a custom error dialog box.
1407//
1408void
1410{
1411 PRECONDITION(parent);
1412 const auto errorCaption = parent->LoadString(IDS_PRNERRORCAPTION);
1413 const auto errorStr = TXPrinting(Error).GetErrorMessage(parent->GetModule());
1414 const auto formatStr = parent->LoadString(IDS_PRNERRORTEMPLATE);
1415 parent->FormatMessageBox(formatStr, errorCaption, MB_OK | MB_ICONSTOP, printout.GetTitle(), errorStr.c_str());
1416}
1417
1418//----------------------------------------------------------------------------
1419
1420
1422
1423#if OWL_PERSISTENT_STREAMS
1424
1425//
1426/// Restores the printer object from the persistent stream.
1427//
1428void*
1429TPrinter::Streamer::Read(ipstream& is, uint32 version) const
1430{
1431 GetObject()->Data->Read(is, version);
1432 return GetObject();
1433}
1434
1435//
1436/// Saves the object into the persistent stream.
1437//
1438void
1439TPrinter::Streamer::Write(opstream& os) const
1440{
1441 GetObject()->Data->Write(os);
1442}
1443
1444#endif
1445
1446
1447
1448} // OWL namespace
1449/* ========================================================================== */
1450
Definition of class TAppDictionary.
Definition of class TApplication.
#define CHECK(condition)
Definition checks.h:239
#define WARN(condition, message)
Definition checks.h:273
#define PRECONDITION(condition)
Definition checks.h:227
TApplication * GetApplication(uint pid=0)
Looks up and returns the application associated with a given process ID.
Definition appdict.cpp:192
Derived from TModule and TMsgThread and virtually derived from TEventHandler, TApplication acts as an...
Definition applicat.h:141
static const TColor Black
Static TColor object with fixed Value set by RGB(0, 0, 0).
Definition color.h:305
TDC is the root class for GDI DC wrappers.
Definition dc.h:64
Typically used to obtain information from a user, a dialog box is a window inside of which other cont...
Definition dialog.h:85
auto Execute() -> int override
Creates and executes a modal dialog box interface element associated with the TDialog object.
Definition dialog.cpp:595
void SetupWindow() override
Overrides the virtual function defined in TWindow.
Definition dialog.cpp:825
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
LPCTSTR GetOutputName() const
Gets the name of the physical output medium.
Definition printdia.cpp:538
const DEVMODE * GetDevMode() const
Gets a pointer to a DEVMODE structure (a structure containing information necessary to initialize the...
Definition printdia.cpp:406
uint32 Error
If the dialog box is successfully executed, Error returns 0.
Definition printdia.h:132
int MaxPage
MaxPage indicates the maximum number of pages that can be printed.
Definition printdia.h:137
TPrintDC * TransferDC()
Transfers the printers device context.
Definition printdia.cpp:586
void ClearDevNames()
Accessors and mutators for the internal Win32 DEVNAMES structure.
Definition printdia.cpp:505
int FromPage
FromPage indicates the beginning page to print.
Definition printdia.h:134
LPCTSTR GetDeviceName() const
Gets the name of the output device.
Definition printdia.cpp:529
uint32 Flags
Flags , which are used to initialize the printer dialog box, can be one or more of the following valu...
Definition printdia.h:97
int ToPage
ToPage indicates the ending page to print.
Definition printdia.h:135
int MinPage
MinPage indicates the minimum number of pages that can be printed.
Definition printdia.h:136
void ClearDevMode()
Accessors and mutators for the internal Win32 DEVMODE structure.
Definition printdia.cpp:473
int Copies
Copies indicates the actual number of pages to be printed.
Definition printdia.h:138
bool DoPageSetup
Flag to do page setup?
Definition printdia.h:144
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
TDevMode(const tstring &device)
Retrieves the DEVMODE device data for the given device.
Definition printer.cpp:369
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
void SetupWindow() override
Overrides SetupWindow. This function disables the Close system menu option.
Definition printer.cpp:181
void CmCancel()
Handles the print-cancel button by setting the user print abort flag in the application.
Definition printer.cpp:236
TPrinter is an encapsulation around the Windows printer device interface, and represents the physical...
Definition printer.h:164
static void SetUserAbort(HDC abortDC=HDC(-1))
Sets the user abort DC for the printer.
Definition printer.cpp:477
TSize GetPageSize() const
Returns the size of the page.
Definition printer.cpp:519
virtual ~TPrinter()
Frees the resources allocated to TPrinter.
Definition printer.cpp:437
auto GetPapers() const -> TPapers
Returns a list of supported paper sizes.
Definition printer.cpp:839
auto GetPrintRateUnit() const -> TPrintRateUnit
Returns the printer's print rate units.
Definition printer.cpp:925
void SetData(TPrintDialog::TData *data)
Sets the common dialog data; takes ownership.
Definition printer.cpp:509
std::vector< tstring > TDescriptionLanguages
Return type for GetDescriptionsLanguages.
Definition printer.h:298
std::vector< tstring > TPaperNames
Return type for GetPaperNames.
Definition printer.h:295
void SetDevice(const tstring &device)
Assigns the device to be represented by this TPrinter object.
Definition printer.cpp:445
int GetError()
Returns the error code from the printer.
Definition printer.cpp:493
auto GetLandscapeOrientation() const -> int
Returns the angle of rotation between portrait and landscape orientation.
Definition printer.cpp:794
std::vector< tstring > TPaperForms
Return type for GetReadyMedia.
Definition printer.h:291
auto CanStaple() const -> bool
Returns whether the printer supports stapling.
Definition printer.cpp:960
auto GetResolutions() const -> TResolutions
Retrieves a list of the resolutions supported by the printer.
Definition printer.cpp:674
auto HasDuplexSupport() const -> bool
Returns whether the printer supports duplex printing.
Definition printer.cpp:664
TPrintDialog::TData * GetData()
Returns the common dialog data associated with the printer.
Definition printer.cpp:501
auto GetDescriptionLanguages() const -> TDescriptionLanguages
Returns a list of printer description languages supported by the printer.
Definition printer.cpp:877
virtual TWindow * CreateAbortWindow(TWindow *parent, TPrintout &printout)
Virtual called from withing Print() just before the main printing loop to construct and create the pr...
Definition printer.cpp:1046
TPrinter(const tstring &device=GetDefaultPrinter())
Associates this TPrinter object with the given printer device.
Definition printer.cpp:417
auto GetPrintRate() const -> int
Returns the printer's print rate.
Definition printer.cpp:900
virtual void SetPageSizes(const TPrintDC &dc)
Updates the PageSize variables by querying the device capabilities of the specified device context.
Definition printer.cpp:1081
auto GetMaxCopies() const -> int
Return the maximum number of copies the printer can print.
Definition printer.cpp:642
TPrintDialog::TData & GetSetup()
Returns a reference to the TPrintDialog data structure.
Definition printer.cpp:457
auto GetReadyMedia() const -> TPaperForms
Returns the names of the paper forms that are currently available for use.
Definition printer.cpp:740
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
auto GetTrueTypeCapabilities() const -> DWORD
Retrieves the abilities of the printer to use TrueType fonts.
Definition printer.cpp:971
TPrintRateUnit
Return type for GetPrintRateUnit.
Definition printer.h:304
@ pruInchesPerMinute
Definition printer.h:309
@ pruLinesPerMinute
Definition printer.h:308
@ pruCharactersPerSecond
Definition printer.h:307
@ pruPagesPerMinute
Definition printer.h:306
virtual void Setup(TWindow *parent)
Setup lets the user select and/or configure the currently associated printer.
Definition printer.cpp:1398
static auto GetDefaultPrinter() -> tstring
Retrieves the printer name of the default printer for the current user on the local computer.
Definition printer.cpp:386
auto GetMinExtent() const -> TSize
Returns the minimum paper size that the printer supports.
Definition printer.cpp:779
LPCTSTR GetOutputFile() const
Returns the filename for output redirection.
Definition printer.cpp:1062
std::vector< int > TNupConfigurations
Return type for GetNupConfigurations.
Definition printer.h:294
auto GetMediaTypeNames() const -> TMediaTypeNames
Returns the names of the supported media types.
Definition printer.cpp:750
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
@ dcEnumResolutions
Definition printer.h:247
@ dcFileDependencies
Definition printer.h:250
virtual bool ExecPrintDialog(TWindow *parent)
Virtual called from within Print() to construct and execute a print dialog before actual printing occ...
Definition printer.cpp:1013
std::vector< TSize > TPaperSizes
Return type for GetPaperSizes.
Definition printer.h:297
auto GetDevModeFields() const -> DWORD
Returns the dmFields member of the printer driver's DEVMODE structure.
Definition printer.cpp:708
auto GetMaxExtent() const -> TSize
Returns the maximum paper size that the printer supports.
Definition printer.cpp:728
auto GetDevModeSize() const -> int
Returns the dmSize member of the printer driver's DEVMODE structure.
Definition printer.cpp:948
virtual void ClearDevice()
Called by the Destructor, ClearDevice disassociates the device with the current printer.
Definition printer.cpp:554
virtual bool Print(TWindow *parent, TPrintout &printout, bool prompt)
Print renders the given printout object on the associated printer device and displays an Abort dialog...
Definition printer.cpp:1264
auto GetMediaTypes() const -> TMediaTypes
Returns a list of supported media types.
Definition printer.cpp:762
std::vector< WORD > TPapers
Return type for GetPapers.
Definition printer.h:296
auto GetDriverSpecificationVersion() const -> DWORD
Returns the specification version to which the printer driver conforms.
Definition printer.cpp:983
auto GetMemoryCapacity() const -> int
Returns the amount of available printer memory, in kilobytes.
Definition printer.cpp:887
auto GetBins() const -> TBins
Retrieves a list of available paper bins.
Definition printer.cpp:605
auto GetDriverDependencies() const -> TFileDependencies
Returns the names of any additional files that need to be loaded for the printer driver.
Definition printer.cpp:718
auto GetNupConfigurations() const -> TNupConfigurations
Retrieves a list of integers that indicate the printers ability to print multiple document pages per ...
Definition printer.cpp:808
auto GetDriverVersion() const -> DWORD
Returns the version number of the printer driver.
Definition printer.cpp:654
auto GetDevModeExtra() const -> int
Returns the number of bytes required for the device-specific portion of the DEVMODE structure for the...
Definition printer.cpp:695
void SetOutputFile(const tstring &outputFile)
Sets the filename for output redirection.
Definition printer.cpp:1071
auto GetPaperNames() const -> TPaperNames
Returns a list of supported paper names.
Definition printer.cpp:827
virtual bool ExecPageSetupDialog(TWindow *parent)
Page setup dialog for Win95 support.
Definition printer.cpp:1027
auto CanCollate() const -> bool
Returns whether the printer supports collating.
Definition printer.cpp:622
auto GetPaperSizes() const -> TPaperSizes
Retrieves the dimensions of each supported paper size.
Definition printer.cpp:857
auto GetBinNames() const -> TBinNames
Retrieves the names of the printer's paper bins.
Definition printer.cpp:593
auto GetDC() -> std::unique_ptr< TPrintDC >
Returns the device context already obtained in our setup data, or if none, creates a new one based on...
Definition printer.cpp:466
auto GetCapability(TCapability capability, TCHAR *output) const -> DWORD
Get information about the device.
Definition printer.h:278
void SetPageSizeInch(const TSize &pageSizeInch)
Sets the size of an inch on the page.
Definition printer.cpp:543
std::vector< TSize > TResolutions
Return type for GetResolutions.
Definition printer.h:289
auto IsColorDevice() const -> bool
Returns whether the printer supports color printing.
Definition printer.cpp:632
virtual void ReportError(TWindow *parent, TPrintout &printout)
Reports the current error by bringing up a system message box with an error message composed of the e...
Definition printer.cpp:1409
void SetPageSize(const TSize &pagesize)
Sets the page's size.
Definition printer.cpp:527
auto GetPrintRatePpm() const -> int
Returns the printer's print rate in pages per minute.
Definition printer.cpp:912
static HDC GetUserAbort()
Returns the abort DC.
Definition printer.cpp:485
TSize GetPageSizeInch() const
Returns the size of an inch the page.
Definition printer.cpp:535
TPrintout represents the physical printed document that is to sent to a printer to be printed.
Definition printer.h:76
LPCTSTR GetTitle() const
Returns the title of the current printout.
Definition printout.cpp:46
TPrintDC * GetPrintDC()
Returns the DC associated with the printout.
Definition printout.cpp:70
virtual void SetPrintParams(TPrintDC *dc, TSize pageSize)
SetPrintParams sets DC to dc and PageSize to pageSize.
Definition printout.cpp:122
bool WantBanding() const
Returns true if banding is desired.
Definition printout.cpp:54
virtual void GetDialogInfo(int &minPage, int &maxPage, int &selFromPage, int &selToPage)
Retrieves information needed to allow the printing of selected pages of the document and returns true...
Definition printout.cpp:136
The tagSIZE struct is defined as.
Definition geometry.h:234
An interface object that represents a static text interface element.
Definition static.h:36
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
tstring LoadString(uint id) const
Definition window.h:608
TWindow()
Protected constructor for use by immediate virtually derived classes.
Definition window.cpp:392
virtual bool EnableWindow(bool enable)
Allows the given window to receive input from the keyboard of mouse.
Definition window.h:2172
HWND GetDlgItem(int childId) const
Retrieves the handle of a control specified by childId.
Definition window.h:3108
virtual bool Create()
Creates the window interface element to be associated with this ObjectWindows interface element.
Definition window.cpp:2399
auto FormatMessageBox(const tstring &formatStr, const tstring &caption, uint flags,...) const -> int
Definition window.cpp:4361
TModule * GetModule() const
Returns a pointer to the module object.
Definition window.h:1841
HMENU GetSystemMenu(bool revert=false) const
Returns a handle to the system menu so that an application can access the system menu.
Definition window.h:3256
const char * what() const noexcept
Definition exbase.cpp:155
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
TXPrinter * Clone()
Clone the exception object for safe throwing across stack frames.
Definition printer.cpp:259
void Throw()
Throws the exception.
Definition printer.cpp:268
TXPrinter(uint resId=IDS_PRINTERERROR)
Constructs a TXPrinter object with a default IDS_PRINTERERROR message.
Definition printer.cpp:249
static void Raise(uint resId=IDS_PRINTERERROR)
Creates the exception object and throws it.
Definition printer.cpp:277
TXPrinting describes an exception that indicates that printing failed.
Definition printer.h:396
tstring GetErrorMessage(TModule *=0) const
Returns the error message for the current error code.
Definition printer.cpp:317
TXPrinting(int error=SP_ERROR)
Constructs a TXPrinting object with a default IDS_PRINTERERROR message.
Definition printer.cpp:287
void Throw()
Throws the exception.
Definition printer.cpp:298
static void Raise(int error=SP_ERROR)
Creates the exception object and throws it.
Definition printer.cpp:307
A nested class, TXWindow describes an exception that results from trying to create an invalid window.
Definition window.h:1647
TWindow * GetWindow() const
Definition window.cpp:4621
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
#define _stprintf
Definition cygwin.h:88
#define _tcslen
Definition cygwin.h:74
#define _T(x)
Definition cygwin.h:51
Definition of GDI DC encapsulation classes: TDC, TWindowDC, TScreenDC, TDesktopDC,...
#define DECLARE_RESPONSE_TABLE(cls)
Definition eventhan.h:436
#define END_RESPONSE_TABLE
Definition eventhan.h:466
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
Definition of class TFrameWindow.
#define IMPLEMENT_STREAMABLE(cls)
Definition objstrm.h:1724
@ 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
int CALLBACK TPrinterAbortProc(HDC hDC, int code)
Definition printer.cpp:992
bool ToBool(const T &t)
Definition defs.h:291
TAppDictionary & OWLGetAppDictionary()
Global exported TAppDictionary in Owl.
Definition appdict.cpp:35
OWL_DIAGINFO
Definition animctrl.cpp:14
LRESULT TResult
Result type.
Definition dispatch.h:52
std::string tstring
Definition defs.h:79
int16 LoInt16(LRESULT r)
Definition defs.h:267
unsigned int uint
Definition number.h:25
void SetClear(T1 &var, T2 bitsOn, T2 bitsOff)
Definition printer.cpp:30
int16 HiInt16(LRESULT r)
Definition defs.h:273
#define WM_SETNUMBER
Definition printer.cpp:109
Definition of class TStatic, the class for static controls and base for any control that manages simp...
Base window class TWindow definition, including HWND encapsulation.
#define EV_MESSAGE(message, method)
Response table entry for raw message handling Uses a dispatcher that just forwards WPARAM and LPARAM.
Definition windowev.h:113
#define EV_COMMAND(id, method)
Response table entry for a menu/accelerator/push button message.
Definition windowev.h:171