OWLNext 7.0
Borland's Object Windows Library for the modern age
|
TPrinter is an encapsulation around the Windows printer device interface, and represents the physical printer device. More...
#include <owl/printer.h>
Classes | |
class | TDevMode |
Contains information about the initialization and environment of a printer device. More... | |
Public Types | |
enum | TCapability { dcBinNames = DC_BINNAMES , dcBins = DC_BINS , dcCollate = DC_COLLATE , dcColorDevice = DC_COLORDEVICE , dcCopies = DC_COPIES , dcDriver = DC_DRIVER , dcDuplex = DC_DUPLEX , dcEnumResolutions = DC_ENUMRESOLUTIONS , dcExtra = DC_EXTRA , dcFields = DC_FIELDS , dcFileDependencies = DC_FILEDEPENDENCIES , dcMaxExtent = DC_MAXEXTENT , dcMediaReady = DC_MEDIAREADY , dcMediaTypeNames = DC_MEDIATYPENAMES , dcMediaTypes = DC_MEDIATYPES , dcMinExtent = DC_MINEXTENT , dcOrientation = DC_ORIENTATION , dcNup = DC_NUP , dcPaperNames = DC_PAPERNAMES , dcPapers = DC_PAPERS , dcPaperSize = DC_PAPERSIZE , dcPersonality = DC_PERSONALITY , dcPrinterMem = DC_PRINTERMEM , dcPrintRate = DC_PRINTRATE , dcPrintRatePpm = DC_PRINTRATEPPM , dcPrintRateUnit = DC_PRINTRATEUNIT , dcSize = DC_SIZE , dcStaple = DC_STAPLE , dcTrueType = DC_TRUETYPE , dcVersion = DC_VERSION } |
Encapsulates the capability constants defined for the Windows API function DeviceCapabilities. More... | |
Return types for capability accessors | |
enum | TPrintRateUnit { pruUnknown = 0 , pruPagesPerMinute = PRINTRATEUNIT_PPM , pruCharactersPerSecond = PRINTRATEUNIT_CPS , pruLinesPerMinute = PRINTRATEUNIT_LPM , pruInchesPerMinute = PRINTRATEUNIT_IPM } |
Return type for GetPrintRateUnit. More... | |
using | TBinNames = std::vector<tstring> |
Return type for GetBinNames. | |
using | TBins = std::vector<WORD> |
Return type for GetBins. | |
using | TResolutions = std::vector<TSize> |
Return type for GetResolutions. | |
using | TFileDependencies = std::vector<tstring> |
Return type for GetDriverDependencies. | |
using | TPaperForms = std::vector<tstring> |
Return type for GetReadyMedia. | |
using | TMediaTypeNames = std::vector<tstring> |
Return type for GetMediaTypeNames. | |
using | TMediaTypes = std::vector<DWORD> |
Return type for GetMediaTypes. | |
using | TNupConfigurations = std::vector<int> |
Return type for GetNupConfigurations. | |
using | TPaperNames = std::vector<tstring> |
Return type for GetPaperNames. | |
using | TPapers = std::vector<WORD> |
Return type for GetPapers. | |
using | TPaperSizes = std::vector<TSize> |
Return type for GetPaperSizes. | |
using | TDescriptionLanguages = std::vector<tstring> |
Return type for GetDescriptionsLanguages. | |
Public Member Functions | |
TPrinter (const tstring &device=GetDefaultPrinter()) | |
Associates this TPrinter object with the given printer device. | |
TPrinter (TPrinter &&other) | |
Move-constructor; enables auto-declaration style. | |
virtual | ~TPrinter () |
Frees the resources allocated to TPrinter. | |
void | SetDevice (const tstring &device) |
Assigns the device to be represented by this TPrinter object. | |
virtual void | ClearDevice () |
Called by the Destructor, ClearDevice disassociates the device with the current printer. | |
virtual void | Setup (TWindow *parent) |
Setup lets the user select and/or configure the currently associated printer. | |
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 box while printing. | |
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 error description and document title. | |
TPrintDialog::TData & | GetSetup () |
Returns a reference to the TPrintDialog data structure. | |
auto | GetSetup () const -> const TPrintDialog::TData & |
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 the device name and device initialization data (DEVMODE). | |
int | GetError () |
Returns the error code from the printer. | |
TPrintDialog::TData * | GetData () |
Returns the common dialog data associated with the printer. | |
void | SetData (TPrintDialog::TData *data) |
Sets the common dialog data; takes ownership. | |
TSize | GetPageSize () const |
Returns the size of the page. | |
void | SetPageSize (const TSize &pagesize) |
Sets the page's size. | |
TSize | GetPageSizeInch () const |
Returns the size of an inch the page. | |
void | SetPageSizeInch (const TSize &pageSizeInch) |
Sets the size of an inch on the page. | |
virtual void | SetPageSizes (const TPrintDC &dc) |
Updates the PageSize variables by querying the device capabilities of the specified device context. | |
auto | GetCapability (TCapability capability, TCHAR *output) const -> DWORD |
Get information about the device. | |
Retrieves/assigns the output file | |
The output file can be set to redirect the print job. Set to blank to disable redirection (default). | |
LPCTSTR | GetOutputFile () const |
Returns the filename for output redirection. | |
void | SetOutputFile (const tstring &outputFile) |
Sets the filename for output redirection. | |
Capability accessors (type-safe encapsulations of GetCapability) | |
| |
auto | GetBinNames () const -> TBinNames |
Retrieves the names of the printer's paper bins. | |
auto | GetBins () const -> TBins |
Retrieves a list of available paper bins. | |
auto | CanCollate () const -> bool |
Returns whether the printer supports collating. | |
auto | IsColorDevice () const -> bool |
Returns whether the printer supports color printing. | |
auto | GetMaxCopies () const -> int |
Return the maximum number of copies the printer can print. | |
auto | GetDriverVersion () const -> DWORD |
Returns the version number of the printer driver. | |
auto | HasDuplexSupport () const -> bool |
Returns whether the printer supports duplex printing. | |
auto | GetResolutions () const -> TResolutions |
Retrieves a list of the resolutions supported by the printer. | |
auto | GetDevModeExtra () const -> int |
Returns the number of bytes required for the device-specific portion of the DEVMODE structure for the printer driver. | |
auto | GetDevModeFields () const -> DWORD |
Returns the dmFields member of the printer driver's DEVMODE structure. | |
auto | GetDriverDependencies () const -> TFileDependencies |
Returns the names of any additional files that need to be loaded for the printer driver. | |
auto | GetMaxExtent () const -> TSize |
Returns the maximum paper size that the printer supports. | |
auto | GetReadyMedia () const -> TPaperForms |
Returns the names of the paper forms that are currently available for use. | |
auto | GetMediaTypeNames () const -> TMediaTypeNames |
Returns the names of the supported media types. | |
auto | GetMediaTypes () const -> TMediaTypes |
Returns a list of supported media types. | |
auto | GetMinExtent () const -> TSize |
Returns the minimum paper size that the printer supports. | |
auto | GetLandscapeOrientation () const -> int |
Returns the angle of rotation between portrait and landscape orientation. | |
auto | GetNupConfigurations () const -> TNupConfigurations |
Retrieves a list of integers that indicate the printers ability to print multiple document pages per printed page. | |
auto | GetPaperNames () const -> TPaperNames |
Returns a list of supported paper names. | |
auto | GetPapers () const -> TPapers |
Returns a list of supported paper sizes. | |
auto | GetPaperSizes () const -> TPaperSizes |
Retrieves the dimensions of each supported paper size. | |
auto | GetDescriptionLanguages () const -> TDescriptionLanguages |
Returns a list of printer description languages supported by the printer. | |
auto | GetMemoryCapacity () const -> int |
Returns the amount of available printer memory, in kilobytes. | |
auto | GetPrintRate () const -> int |
Returns the printer's print rate. | |
auto | GetPrintRatePpm () const -> int |
Returns the printer's print rate in pages per minute. | |
auto | GetPrintRateUnit () const -> TPrintRateUnit |
Returns the printer's print rate units. | |
auto | GetDevModeSize () const -> int |
Returns the dmSize member of the printer driver's DEVMODE structure. | |
auto | CanStaple () const -> bool |
Returns whether the printer supports stapling. | |
auto | GetTrueTypeCapabilities () const -> DWORD |
Retrieves the abilities of the printer to use TrueType fonts. | |
auto | GetDriverSpecificationVersion () const -> DWORD |
Returns the specification version to which the printer driver conforms. | |
Public Member Functions inherited from owl::TStreamableBase | |
virtual | ~TStreamableBase () |
Static Public Member Functions | |
static auto | GetDefaultPrinter () -> tstring |
Retrieves the printer name of the default printer for the current user on the local computer. | |
static void | SetUserAbort (HDC abortDC=HDC(-1)) |
Sets the user abort DC for the printer. | |
static HDC | GetUserAbort () |
Returns the abort DC. | |
Protected Member Functions | |
virtual bool | ExecPrintDialog (TWindow *parent) |
Virtual called from within Print() to construct and execute a print dialog before actual printing occurs. | |
virtual bool | ExecPageSetupDialog (TWindow *parent) |
Page setup dialog for Win95 support. | |
virtual TWindow * | CreateAbortWindow (TWindow *parent, TPrintout &printout) |
Virtual called from withing Print() just before the main printing loop to construct and create the printing status, or abort window. | |
TPrinter is an encapsulation around the Windows printer device interface, and represents the physical printer device.
To print or configure a printer, initialize an instance of TPrinter. To print a TPrintout, send the TPrintout to the TPrinter's Print function.
Examples:
using owl::TPrinter::TBinNames = std::vector<tstring> |
using owl::TPrinter::TBins = std::vector<WORD> |
using owl::TPrinter::TDescriptionLanguages = std::vector<tstring> |
using owl::TPrinter::TFileDependencies = std::vector<tstring> |
using owl::TPrinter::TMediaTypeNames = std::vector<tstring> |
using owl::TPrinter::TMediaTypes = std::vector<DWORD> |
using owl::TPrinter::TNupConfigurations = std::vector<int> |
using owl::TPrinter::TPaperForms = std::vector<tstring> |
using owl::TPrinter::TPaperNames = std::vector<tstring> |
using owl::TPrinter::TPapers = std::vector<WORD> |
using owl::TPrinter::TPaperSizes = std::vector<TSize> |
using owl::TPrinter::TResolutions = std::vector<TSize> |
Encapsulates the capability constants defined for the Windows API function DeviceCapabilities.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd183552.aspx
|
explicit |
Associates this TPrinter object with the given printer device.
If no name is given, the name of the current default printer is used.
Definition at line 417 of file printer.cpp.
References SetDevice().
owl::TPrinter::TPrinter | ( | TPrinter && | other | ) |
Move-constructor; enables auto-declaration style.
Definition at line 426 of file printer.cpp.
|
virtual |
Frees the resources allocated to TPrinter.
Definition at line 437 of file printer.cpp.
Returns whether the printer supports collating.
If the function fails, false
is returned.
Definition at line 622 of file printer.cpp.
References dcCollate, and GetCapability().
Returns whether the printer supports stapling.
If the function fails, false
is returned.
Definition at line 960 of file printer.cpp.
References dcStaple, and GetCapability().
|
virtual |
Called by the Destructor, ClearDevice disassociates the device with the current printer.
ClearDevice changes the current status of the printer to PF_UNASSOCIATED, which causes the object to ignore all calls to Print until the object is reassociated with a printer.
Definition at line 554 of file printer.cpp.
References owl::TPrintDialog::TData::ClearDevMode(), and owl::TPrintDialog::TData::ClearDevNames().
|
protectedvirtual |
Virtual called from withing Print() just before the main printing loop to construct and create the printing status, or abort window.
This window should use the control IDs specified in printer.rh
Definition at line 1046 of file printer.cpp.
References owl::TWindow::Create(), owl::TPrintDialog::TData::GetDeviceName(), owl::TPrintDialog::TData::GetOutputName(), owl::TPrintout::GetPrintDC(), and owl::TPrintout::GetTitle().
Page setup dialog for Win95 support.
Definition at line 1027 of file printer.cpp.
References owl::TPrintDialog::TData::DoPageSetup, and owl::TDialog::Execute().
Virtual called from within Print() to construct and execute a print dialog before actual printing occurs.
Return true to continue printing, false to cancel
Definition at line 1013 of file printer.cpp.
References owl::TDialog::Execute().
Retrieves the names of the printer's paper bins.
If the function fails, an empty vector is returned.
Definition at line 593 of file printer.cpp.
References dcBinNames.
Retrieves a list of available paper bins.
Each element of the returned vector is a bin identifier, e.g. DMBIN_AUTO. See the description of the dmDefaultSource member of the DEVMODE structure. If the function fails, an empty vector is returned.
Definition at line 605 of file printer.cpp.
References CHECK, dcBins, and GetCapability().
|
inline |
Get information about the device.
This is a wrapper for the Windows API function DeviceCapabilities. http://msdn.microsoft.com/en-us/library/windows/desktop/dd183552.aspx
TPrintDialog::TData * owl::TPrinter::GetData | ( | ) |
Returns the common dialog data associated with the printer.
Definition at line 501 of file printer.cpp.
Returns the device context already obtained in our setup data, or if none, creates a new one based on the device name and device initialization data (DEVMODE).
Definition at line 466 of file printer.cpp.
References CHECK.
Retrieves the printer name of the default printer for the current user on the local computer.
Wrapper for the Windows API function GetDefaultPrinter. http://msdn.microsoft.com/en-us/library/windows/desktop/dd144876.aspx Throws TXPrinter if there is no default printer, or if an unexpected error occurs.
Definition at line 386 of file printer.cpp.
References _T, CHECK, and GetDefaultPrinter().
auto owl::TPrinter::GetDescriptionLanguages | ( | ) | const -> TDescriptionLanguages |
Returns a list of printer description languages supported by the printer.
If the function fails, an empty vector is returned.
Definition at line 877 of file printer.cpp.
References dcPersonality.
Returns the number of bytes required for the device-specific portion of the DEVMODE structure for the printer driver.
If the function fails, 0 is returned.
Definition at line 695 of file printer.cpp.
References dcExtra, and GetCapability().
Returns the dmFields
member of the printer driver's DEVMODE structure.
The dmFields
member indicates which members in the device-independent portion of the structure are supported by the printer driver.
Definition at line 708 of file printer.cpp.
References dcFields, and GetCapability().
Returns the dmSize
member of the printer driver's DEVMODE structure.
The dmSize
member indicates the size (and hence version) of the DEVMODE structure. The size excludes the private driver-data that follows the structure. See the dmDriverExtra
member. If the function fails, 0 is returned.
Definition at line 948 of file printer.cpp.
References dcSize, and GetCapability().
auto owl::TPrinter::GetDriverDependencies | ( | ) | const -> TFileDependencies |
Returns the names of any additional files that need to be loaded for the printer driver.
If the function fails, an empty vector is returned.
Definition at line 718 of file printer.cpp.
References dcFileDependencies.
Returns the specification version to which the printer driver conforms.
If the function fails, 0xFFFFFFFF is returned.
Definition at line 983 of file printer.cpp.
References dcVersion, and GetCapability().
Returns the version number of the printer driver.
If the function fails, 0xFFFFFFFF is returned.
Definition at line 654 of file printer.cpp.
References dcDriver, and GetCapability().
int owl::TPrinter::GetError | ( | ) |
Returns the error code from the printer.
Definition at line 493 of file printer.cpp.
Returns the angle of rotation between portrait and landscape orientation.
The result is given in terms of the number of degrees that portrait orientation is rotated counter-clockwise to produce landscape orientation. If landscape orientation is not supported, then 0 is returned. If the function fails, 0 is returned.
Definition at line 794 of file printer.cpp.
References dcOrientation, and GetCapability().
Return the maximum number of copies the printer can print.
If the function fails, 0 is returned.
Definition at line 642 of file printer.cpp.
References dcCopies, and GetCapability().
Returns the maximum paper size that the printer supports.
If the function fails, TSize{0, 0} is returned.
Definition at line 728 of file printer.cpp.
References dcMaxExtent, GetCapability(), owl::HiInt16(), and owl::LoInt16().
auto owl::TPrinter::GetMediaTypeNames | ( | ) | const -> TMediaTypeNames |
Returns the names of the supported media types.
If the function fails, an empty vector is returned.
Definition at line 750 of file printer.cpp.
References dcMediaTypeNames.
auto owl::TPrinter::GetMediaTypes | ( | ) | const -> TMediaTypes |
Returns a list of supported media types.
For a list of possible media type values, see the description of the dmMediaType
member of the DEVMODE structure. If the function fails, an empty vector is returned.
Definition at line 762 of file printer.cpp.
References CHECK, dcMediaTypes, and GetCapability().
Returns the amount of available printer memory, in kilobytes.
If the function fails, 0 is returned.
Definition at line 887 of file printer.cpp.
References dcPrinterMem, and GetCapability().
Returns the minimum paper size that the printer supports.
If the function fails, TSize{0, 0} is returned.
Definition at line 779 of file printer.cpp.
References dcMinExtent, GetCapability(), owl::HiInt16(), and owl::LoInt16().
auto owl::TPrinter::GetNupConfigurations | ( | ) | const -> TNupConfigurations |
Retrieves a list of integers that indicate the printers ability to print multiple document pages per printed page.
Each element of the list represent a supported configuration, given by the number of document pages per printed page. If the function fails, an empty vector is returned.
Definition at line 808 of file printer.cpp.
References CHECK, dcNup, and GetCapability().
LPCTSTR owl::TPrinter::GetOutputFile | ( | ) | const |
Returns the filename for output redirection.
Definition at line 1062 of file printer.cpp.
TSize owl::TPrinter::GetPageSize | ( | ) | const |
Returns the size of the page.
Definition at line 519 of file printer.cpp.
TSize owl::TPrinter::GetPageSizeInch | ( | ) | const |
Returns the size of an inch the page.
Definition at line 535 of file printer.cpp.
auto owl::TPrinter::GetPaperNames | ( | ) | const -> TPaperNames |
Returns a list of supported paper names.
For example, paper names could be "Letter" or "Legal". If the function fails, an empty vector is returned.
Definition at line 827 of file printer.cpp.
References dcPaperNames.
Returns a list of supported paper sizes.
For a list of the possible element values, see the description of the dmPaperSize
member of the DEVMODE structure. If the function fails, an empty vector is returned.
Definition at line 839 of file printer.cpp.
References CHECK, dcPapers, and GetCapability().
auto owl::TPrinter::GetPaperSizes | ( | ) | const -> TPaperSizes |
Retrieves the dimensions of each supported paper size.
The unit is tenths of a millimeter (LOMETRIC). If the function fails, an empty vector is returned.
Definition at line 857 of file printer.cpp.
References CHECK, dcPaperSize, and GetCapability().
Returns the printer's print rate.
Call GetCapability<TPrinter::dcPrintRateUnit> to determine the units of the returned value. If the function fails, 0 is returned.
Definition at line 900 of file printer.cpp.
References dcPrintRate, and GetCapability().
Returns the printer's print rate in pages per minute.
If the function fails, 0 is returned.
Definition at line 912 of file printer.cpp.
References dcPrintRatePpm, and GetCapability().
auto owl::TPrinter::GetPrintRateUnit | ( | ) | const -> TPrintRateUnit |
Returns the printer's print rate units.
The returned value determines the units for the value returned by GetCapability<TPrinter::dcPrintRate>. If the function fails, pruUnknown
is returned.
Definition at line 925 of file printer.cpp.
References dcPrintRateUnit, GetCapability(), pruCharactersPerSecond, pruInchesPerMinute, pruLinesPerMinute, pruPagesPerMinute, and pruUnknown.
auto owl::TPrinter::GetReadyMedia | ( | ) | const -> TPaperForms |
Returns the names of the paper forms that are currently available for use.
If the function fails, an empty vector is returned.
Definition at line 740 of file printer.cpp.
References dcMediaReady.
auto owl::TPrinter::GetResolutions | ( | ) | const -> TResolutions |
Retrieves a list of the resolutions supported by the printer.
If the function fails, an empty vector is returned.
Definition at line 674 of file printer.cpp.
References CHECK, dcEnumResolutions, and GetCapability().
TPrintDialog::TData & owl::TPrinter::GetSetup | ( | ) |
Returns a reference to the TPrintDialog data structure.
Definition at line 457 of file printer.cpp.
|
inline |
Definition at line 204 of file printer.h.
References GetSetup().
Retrieves the abilities of the printer to use TrueType fonts.
The returned value can be a combination of flags DCTT_BITMAP, DCTT_DOWNLOAD and DCTT_SUBDEV. If the function fails, 0 is returned.
Definition at line 971 of file printer.cpp.
References dcTrueType, and GetCapability().
|
static |
Returns the abort DC.
Definition at line 485 of file printer.cpp.
Returns whether the printer supports duplex printing.
If the function fails, false
is returned.
Definition at line 664 of file printer.cpp.
References dcDuplex, and GetCapability().
Returns whether the printer supports color printing.
If the function fails, false
is returned.
Definition at line 632 of file printer.cpp.
References dcColorDevice, and GetCapability().
Print renders the given printout object on the associated printer device and displays an Abort dialog box while printing.
It displays any errors encountered during printing. Prompt allows you to show the user a commdlg print dialog.
Note: The calling sequence here is somewhat of a catch-22 for the printout. The printout cannot compute how many pages the document really has until the page format is known. The printout doesn't get this information until SetPrintParams is called, which cannot happen until the dialog has returned a device context. Unfortunately, the page range information must be provided by GetDialogInfo which has to be called first to set up the dialog.
The problem is that the printer/page options are in the same dialog as the page range selection. The only way to handle this is to implement a custom interactive dialog box that updates the page range in real-time depending on the selected printer/page format. Or deactivate the page range altogether.
Definition at line 1264 of file printer.cpp.
References ClearDevice(), owl::TPrintDialog::TData::Copies, CreateAbortWindow(), owl::TPrintDialog::TData::Error, owl::TXPrinting::Error, ExecPrintDialog(), owl::TPrintDialog::TData::Flags, owl::TPrintDialog::TData::FromPage, owl::TPrintDialog::TData::GetDeviceName(), owl::TPrintDialog::TData::GetDevMode(), owl::TPrintout::GetDialogInfo(), GetPageSize(), owl::TPrintDialog::TData::MaxPage, owl::TPrintDialog::TData::MinPage, PRECONDITION, owl::TXPrinter::Raise(), ReportError(), owl::SetClear(), SetPageSizes(), owl::TPrintout::SetPrintParams(), SetUserAbort(), owl::TPrintDialog::TData::ToPage, owl::TPrinterAbortProc(), owl::TPrintDialog::TData::TransferDC(), and owl::TPrintout::WantBanding().
Reports the current error by bringing up a system message box with an error message composed of the error description and document title.
This function can be overridden to show a custom error dialog box.
Definition at line 1409 of file printer.cpp.
References owl::TWindow::FormatMessageBox(), owl::TXPrinting::GetErrorMessage(), owl::TWindow::GetModule(), owl::TPrintout::GetTitle(), owl::TWindow::LoadString(), and PRECONDITION.
void owl::TPrinter::SetData | ( | TPrintDialog::TData * | data | ) |
Sets the common dialog data; takes ownership.
Definition at line 509 of file printer.cpp.
Assigns the device to be represented by this TPrinter object.
Definition at line 445 of file printer.cpp.
Sets the filename for output redirection.
Definition at line 1071 of file printer.cpp.
Sets the page's size.
Definition at line 527 of file printer.cpp.
Sets the size of an inch on the page.
Definition at line 543 of file printer.cpp.
Updates the PageSize variables by querying the device capabilities of the specified device context.
Definition at line 1081 of file printer.cpp.
Setup lets the user select and/or configure the currently associated printer.
Setup opens a dialog box as a child of the given window. The user then selects one of the buttons in the dialog box to select or configure the printer. The form of the dialog box is based on TPrintDialog, the common dialog printer class. The options button allows the user acces to the specific driver's options.
Definition at line 1398 of file printer.cpp.
References ExecPageSetupDialog().
Sets the user abort DC for the printer.
Definition at line 477 of file printer.cpp.