From 7bcb11d30764df47144189e164f53d8171ed4a63 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Thu, 25 Mar 1999 23:06:01 +0000 Subject: [PATCH] Many changes to the printing classes. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1981 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/category.tex | 6 +- docs/latex/wx/pagedlg.tex | 188 +-- docs/latex/wx/postscpt.tex | 7 + docs/latex/wx/print.tex | 517 +++++++-- docs/latex/wx/tprint.tex | 14 +- docs/latex/wx/wxPython.tex | 2 +- include/wx/cmndata.h | 499 +++++--- include/wx/defs.h | 115 +- include/wx/gdicmn.h | 3 + include/wx/generic/dcpsg.h | 130 ++- include/wx/generic/printps.h | 50 +- include/wx/generic/prntdlgg.h | 171 +-- include/wx/gtk/dc.h | 10 +- include/wx/gtk/dcclient.h | 3 + include/wx/gtk1/dc.h | 10 +- include/wx/gtk1/dcclient.h | 3 + include/wx/motif/dc.h | 14 +- include/wx/motif/dcclient.h | 3 + include/wx/motif/setup.h | 14 +- include/wx/msw/dc.h | 9 +- include/wx/msw/dcprint.h | 30 +- include/wx/msw/printdlg.h | 23 +- include/wx/msw/printwin.h | 6 +- include/wx/prntbase.h | 56 +- samples/printing/printing.cpp | 656 ++++++----- src/common/cmndata.cpp | 1045 +++++++++++++---- src/common/docview.cpp | 4 +- src/common/prntbase.cpp | 1077 ++++++++--------- src/generic/dcpsg.cpp | 455 +++----- src/generic/gridg.cpp | 3 +- src/generic/printps.cpp | 381 +++--- src/generic/prntdlgg.cpp | 942 ++++++++------- src/gtk.inc | 1 + src/gtk/dc.cpp | 13 +- src/gtk/dcclient.cpp | 5 + src/gtk1/dc.cpp | 13 +- src/gtk1/dcclient.cpp | 5 + src/motif.inc | 1 + src/motif/app.cpp | 7 +- src/motif/bitmap.cpp | 6 +- src/motif/dc.cpp | 13 +- src/motif/dcclient.cpp | 6 + src/motif/makefile.unx | 6 +- src/msw/dc.cpp | 2036 ++++++++++++++++----------------- src/msw/dcprint.cpp | 355 ++++-- src/msw/makefile.b32 | 3 + src/msw/makefile.bcc | 3 + src/msw/makefile.dos | 6 + src/msw/makefile.g95 | 1 + src/msw/makefile.sc | 1 + src/msw/makefile.sl | 4 + src/msw/makefile.twn | 1 + src/msw/makefile.vc | 1 + src/msw/makefile.wat | 4 + src/msw/printdlg.cpp | 135 +-- src/msw/printwin.cpp | 450 ++++---- src/stubs.inc | 1 + src/unix/threadpsx.cpp | 13 +- src/unix/utilsunx.cpp | 9 +- 59 files changed, 5470 insertions(+), 4075 deletions(-) diff --git a/docs/latex/wx/category.tex b/docs/latex/wx/category.tex index e932b2072e..4a35341b60 100644 --- a/docs/latex/wx/category.tex +++ b/docs/latex/wx/category.tex @@ -57,6 +57,7 @@ in an application. \twocolitem{\helpref{wxFontDialog}{wxfontdialog}}{Font chooser dialog} \twocolitem{\helpref{wxPageSetupDialog}{wxpagesetupdialog}}{Standard page setup dialog} \twocolitem{\helpref{wxPrintDialog}{wxprintdialog}}{Standard print dialog} +\twocolitem{\helpref{wxPageSetupDialog}{wxpagesetupdialog}}{Standard page setup dialog} \twocolitem{\helpref{wxMessageDialog}{wxmessagedialog}}{Simple message box dialog} \end{twocollist} @@ -308,12 +309,15 @@ facilities. \twocolitem{\helpref{wxPreviewFrame}{wxpreviewframe}}{Frame for displaying a print preview} \twocolitem{\helpref{wxPreviewCanvas}{wxpreviewcanvas}}{Canvas for displaying a print preview} \twocolitem{\helpref{wxPreviewControlBar}{wxpreviewcontrolbar}}{Standard control bar for a print preview} -\twocolitem{\helpref{wxPrintData}{wxprintdata}}{Represents information about the document being printed} \twocolitem{\helpref{wxPrintDialog}{wxprintdialog}}{Standard print dialog} +\twocolitem{\helpref{wxPageSetupDialog}{wxpagesetupdialog}}{Standard page setup dialog} \twocolitem{\helpref{wxPrinter}{wxprinter}}{Class representing the printer} \twocolitem{\helpref{wxPrinterDC}{wxprinterdc}}{Printer device context} \twocolitem{\helpref{wxPrintout}{wxprintout}}{Class representing a particular printout} \twocolitem{\helpref{wxPrintPreview}{wxprintpreview}}{Class representing a print preview} +\twocolitem{\helpref{wxPrintData}{wxprintdata}}{Represents information about the document being printed} +\twocolitem{\helpref{wxPrintDialogData}{wxprintdialogdata}}{Represents information about the print dialog} +\twocolitem{\helpref{wxPageSetupDialogData}{wxpagesetupdialogdata}}{Represents information about the page setup dialog} \end{twocollist} {\large {\bf Database classes}} diff --git a/docs/latex/wx/pagedlg.tex b/docs/latex/wx/pagedlg.tex index f02df12794..7cd42caf5f 100644 --- a/docs/latex/wx/pagedlg.tex +++ b/docs/latex/wx/pagedlg.tex @@ -1,7 +1,10 @@ -\section{\class{wxPageSetupData}}\label{wxpagesetupdata} +\section{\class{wxPageSetupDialogData}}\label{wxpagesetupdialogdata} This class holds a variety of information related to \helpref{wxPageSetupDialog}{wxpagesetupdialog}. +It contains a \helpref{wxPrintData}{wxprintdata} member which is used to hold basic printer configuration data (as opposed to the +user-interface configuration settings stored by wxPageSetupDialogData). + \wxheading{Derived from} \helpref{wxObject}{wxobject} @@ -16,177 +19,212 @@ This class holds a variety of information related to \helpref{wxPageSetupDialog} \latexignore{\rtfignore{\wxheading{Members}}} -\membersection{wxPageSetupData::wxPageSetupData} +\membersection{wxPageSetupDialogData::wxPageSetupDialogData} + +\func{}{wxPageSetupDialogData}{\void} + +Default constructor. + +\func{}{wxPageSetupDialogData}{\param{wxPageSetupDialogData\&}{ data}} -\func{}{wxPageSetupData}{\void} +Copy constructor. -Constructor. +\func{}{wxPrintDialogData}{\param{wxPrintData\&}{ printData}} -\membersection{wxPageSetupData::\destruct{wxPageSetupData}} +Construct an object from a print dialog data object. -\func{}{\destruct{wxPageSetupData}}{\void} +\membersection{wxPageSetupDialogData::\destruct{wxPageSetupDialogData}} + +\func{}{\destruct{wxPageSetupDialogData}}{\void} Destructor. -\membersection{wxPageSetupData::EnableHelp}\label{wxpagesetupdataenablehelp} +\membersection{wxPageSetupDialogData::EnableHelp}\label{wxpagesetupdialogdataenablehelp} \func{void}{EnableHelp}{\param{bool }{flag}} Enables or disables the `Help' button (Windows only). -\membersection{wxPageSetupData::EnableMargins}\label{wxpagesetupdataenablemargins} +\membersection{wxPageSetupDialogData::EnableMargins}\label{wxpagesetupdialogdataenablemargins} \func{void}{EnableMargins}{\param{bool }{flag}} Enables or disables the margin controls (Windows only). -\membersection{wxPageSetupData::EnableOrientation}\label{wxpagesetupdataenableorientation} +\membersection{wxPageSetupDialogData::EnableOrientation}\label{wxpagesetupdialogdataenableorientation} \func{void}{EnableOrientation}{\param{bool }{flag}} Enables or disables the orientation control (Windows only). -\membersection{wxPageSetupData::EnablePaper}\label{wxpagesetupdataenablepaper} +\membersection{wxPageSetupDialogData::EnablePaper}\label{wxpagesetupdialogdataenablepaper} \func{void}{EnablePaper}{\param{bool }{flag}} Enables or disables the paper size control (Windows only). -\membersection{wxPageSetupData::EnablePrinter}\label{wxpagesetupdataenableprinter} +\membersection{wxPageSetupDialogData::EnablePrinter}\label{wxpagesetupdialogdataenableprinter} \func{void}{EnablePrinter}{\param{bool }{flag}} Enables or disables the {\bf Printer} button, which invokes a printer setup dialog. -\membersection{wxPageSetupData::GetPaperSize}\label{wxpagesetupdatagetpapersize} +\membersection{wxPageSetupDialogData::GetDefaultMinMargins}\label{wxpagesetupdialogdatagetdefaultminmargins} -\func{wxPoint}{GetPaperSize}{\void} +\constfunc{bool}{GetDefaultMinMargins}{\void} -Returns the paper size in millimetres. +Returns TRUE if the page setup dialog will take its minimum margin values from the currently +selected printer properties. Windows only. -\membersection{wxPageSetupData::GetMarginTopLeft}\label{wxpagesetupdatagetmargintopleft} +\membersection{wxPageSetupDialogData::GetEnableMargins}\label{wxpagesetupdialogdatagetenablemargins} -\func{wxPoint}{GetMarginTopLeft}{\void} +\constfunc{bool}{GetEnableMargins}{\void} -Returns the left (x) and top (y) margins. +Returns TRUE if the margin controls are enabled (Windows only). -\membersection{wxPageSetupData::GetMarginBottomRight}\label{wxpagesetupdatagetmarginbottomright} +\membersection{wxPageSetupDialogData::GetEnableOrientation}\label{wxpagesetupdialogdatagetenableorientation} -\func{wxPoint}{GetMarginBottomRight}{\void} +\constfunc{bool}{GetEnableOrientation}{\void} -Returns the right (x) and bottom (y) margins. +Returns TRUE if the orientation control is enabled (Windows only). -\membersection{wxPageSetupData::GetMinMarginTopLeft}\label{wxpagesetupdatagetminmargintopleft} +\membersection{wxPageSetupDialogData::GetEnablePaper}\label{wxpagesetupdialogdatagetenablepaper} -\func{wxPoint}{GetMinMarginTopLeft}{\void} +\constfunc{bool}{GetEnablePaper}{\void} -Returns the left (x) and top (y) minimum margins the user can enter (Windows only). +Returns TRUE if the paper size control is enabled (Windows only). -\membersection{wxPageSetupData::GetMinMarginBottomRight}\label{wxpagesetupdatagetminmarginbottomright} +\membersection{wxPageSetupDialogData::GetEnablePrinter}\label{wxpagesetupdialogdatagetenableprinter} -\func{wxPoint}{GetMinMarginBottomRight}{\void} +\constfunc{bool}{GetEnablePrinter}{\void} -Returns the right (x) and bottom (y) minimum margins the user can enter (Windows only). +Returns TRUE if the printer setup button is enabled. -\membersection{wxPageSetupData::GetOrientation}\label{wxpagesetupdatagetorientation} +\membersection{wxPageSetupDialogData::GetEnableHelp}\label{wxpagesetupdialogdatagetenablehelp} -\func{int}{GetOrientation}{\void} +\constfunc{bool}{GetEnableHelp}{\void} -Returns the orientation, which can be wxPORTRAIT or wxLANDSCAPE. +Returns TRUE if the printer setup button is enabled. -\membersection{wxPageSetupData::GetDefaultMinMargins}\label{wxpagesetupdatagetdefaultminmargins} +\membersection{wxPageSetupDialogData::GetDefaultInfo}\label{wxpagesetupdialogdatagetdefaultinfo} -\func{bool}{GetDefaultMinMargins}{\void} +\constfunc{bool}{GetDefaultInfo}{\void} -Returns TRUE if the page setup dialog will take its minimum margin values from the currently -selected printer properties. Windows only. +Returns TRUE if the dialog will simply return default printer information (such as orientation) +instead of showing a dialog. Windows only. -\membersection{wxPageSetupData::GetEnableMargins}\label{wxpagesetupdatagetenablemargins} +\membersection{wxPageSetupDialogData::GetMarginTopLeft}\label{wxpagesetupdialogdatagetmargintopleft} -\func{bool}{GetEnableMargins}{\void} +\constfunc{wxPoint}{GetMarginTopLeft}{\void} -Returns TRUE if the margin controls are enabled (Windows only). +Returns the left (x) and top (y) margins. -\membersection{wxPageSetupData::GetEnableOrientation}\label{wxpagesetupdatagetenableorientation} +\membersection{wxPageSetupDialogData::GetMarginBottomRight}\label{wxpagesetupdialogdatagetmarginbottomright} -\func{bool}{GetEnableOrientation}{\void} +\constfunc{wxPoint}{GetMarginBottomRight}{\void} -Returns TRUE if the orientation control is enabled (Windows only). +Returns the right (x) and bottom (y) margins. -\membersection{wxPageSetupData::GetEnablePaper}\label{wxpagesetupdatagetenablepaper} +\membersection{wxPageSetupDialogData::GetMinMarginTopLeft}\label{wxpagesetupdialogdatagetminmargintopleft} -\func{bool}{GetEnablePaper}{\void} +\constfunc{wxPoint}{GetMinMarginTopLeft}{\void} -Returns TRUE if the paper size control is enabled (Windows only). +Returns the left (x) and top (y) minimum margins the user can enter (Windows only). -\membersection{wxPageSetupData::GetEnablePrinter}\label{wxpagesetupdatagetenableprinter} +\membersection{wxPageSetupDialogData::GetMinMarginBottomRight}\label{wxpagesetupdialogdatagetminmarginbottomright} -\func{bool}{GetEnablePrinter}{\void} +\constfunc{wxPoint}{GetMinMarginBottomRight}{\void} -Returns TRUE if the printer setup button is enabled. +Returns the right (x) and bottom (y) minimum margins the user can enter (Windows only). -\membersection{wxPageSetupData::GetEnableHelp}\label{wxpagesetupdatagetenablehelp} +\membersection{wxPageSetupDialogData::GetPaperId}\label{wxpagesetupdialogdatagetpaperid} -\func{bool}{GetEnableHelp}{\void} +\constfunc{wxPaperSize}{GetPaperId}{\void} -Returns TRUE if the printer setup button is enabled. +Returns the paper id (stored in the internal wxPrintData object). -\membersection{wxPageSetupData::GetDefaultInfo}\label{wxpagesetupdatagetdefaultinfo} +For further information, see \helpref{wxPrintData::SetPaperId}{wxprintdatasetpaperid}. -\func{bool}{GetDefaultInfo}{\void} +\membersection{wxPageSetupDialogData::GetPaperSize}\label{wxpagesetupdialogdatagetpapersize} -Returns TRUE if the dialog will simply return default printer information (such as orientation) +\constfunc{wxSize}{GetPaperSize}{\void} + +Returns the paper size in millimetres. + +\membersection{wxPageSetupDialogData::GetPrintData}\label{wxpagesetupdialogdatagetprintdata} + +\func{wxPrintData\&}{GetPrintData}{\void} + +Returns a reference to the \helpref{print data}{wxprintdata} associated with this object. + +\membersection{wxPageSetupDialogData::SetDefaultInfo}\label{wxpagesetupdialogdatasetdefaultinfo} + +\func{void}{SetDefaultInfo}{\param{bool}{ flag}} + +Pass TRUE if the dialog will simply return default printer information (such as orientation) instead of showing a dialog. Windows only. -\membersection{wxPageSetupData::SetPaperSize}\label{wxpagesetupdatasetpapersize} +\membersection{wxPageSetupDialogData::SetDefaultMinMargins}\label{wxpagesetupdialogdatasetdefaultminmargins} -\func{void}{SetPaperSize}{\param{const wxPoint\& }{size}} +\func{void}{SetDefaultMinMargins}{\param{bool}{ flag}} -Sets the paper size in millimetres. +Pass TRUE if the page setup dialog will take its minimum margin values from the currently +selected printer properties. Windows only. -\membersection{wxPageSetupData::SetMarginTopLeft}\label{wxpagesetupdatasetmargintopleft} +\membersection{wxPageSetupDialogData::SetMarginTopLeft}\label{wxpagesetupdialogdatasetmargintopleft} \func{void}{GetMarginTopLeft}{\param{const wxPoint\& }{pt}} Sets the left (x) and top (y) margins. -\membersection{wxPageSetupData::SetMarginBottomRight}\label{wxpagesetupdatasetmarginbottomright} +\membersection{wxPageSetupDialogData::SetMarginBottomRight}\label{wxpagesetupdialogdatasetmarginbottomright} \func{void}{SetMarginBottomRight}{\param{const wxPoint\& }{pt}} Sets the right (x) and bottom (y) margins. -\membersection{wxPageSetupData::SetMinMarginTopLeft}\label{wxpagesetupdatasetminmargintopleft} +\membersection{wxPageSetupDialogData::SetMinMarginTopLeft}\label{wxpagesetupdialogdatasetminmargintopleft} \func{void}{SetMinMarginTopLeft}{\param{const wxPoint\& }{pt}} Sets the left (x) and top (y) minimum margins the user can enter (Windows only). -\membersection{wxPageSetupData::SetMinMarginBottomRight}\label{wxpagesetupdatasetminmarginbottomright} +\membersection{wxPageSetupDialogData::SetMinMarginBottomRight}\label{wxpagesetupdialogdatasetminmarginbottomright} \func{void}{SetMinMarginBottomRight}{\param{const wxPoint\& }{pt}} Sets the right (x) and bottom (y) minimum margins the user can enter (Windows only). -\membersection{wxPageSetupData::SetOrientation}\label{wxpagesetupdatasetorientation} +\membersection{wxPageSetupDialogData::SetPaperId}\label{wxpagesetupdialogdatasetpaperid} -\func{void}{SetOrientation}{\param{int }{orientation}} +\func{void}{SetPaperId}{\param{wxPaperSize\& }{id}} -Sets the orientation, which can be wxPORTRAIT or wxLANDSCAPE. +Sets the paper size id. For further information, see \helpref{wxPrintData::SetPaperId}{wxprintdatasetpaperid}. -\membersection{wxPageSetupData::SetDefaultMinMargins}\label{wxpagesetupdatasetdefaultminmargins} +Calling this function overrides the explicit paper dimensions passed in \helpref{wxPageSetupDialogData::SetPaperSize}{wxpagesetupdialogdatasetpapersize}. -\func{void}{SetDefaultMinMargins}{\param{bool}{ flag}} +\membersection{wxPageSetupDialogData::SetPaperSize}\label{wxpagesetupdialogdatasetpapersize} -Pass TRUE if the page setup dialog will take its minimum margin values from the currently -selected printer properties. Windows only. +\func{void}{SetPaperSize}{\param{const wxSize\& }{size}} -\membersection{wxPageSetupData::SetDefaultInfo}\label{wxpagesetupdatasetdefaultinfo} +Sets the paper size in millimetres. If a corresponding paper id is found, it will be set in the +internal wxPrintData object, otherwise the paper size overrides the paper id. -\func{void}{SetDefaultInfo}{\param{bool}{ flag}} +\membersection{wxPageSetupDialogData::SetPrintData}\label{wxpagesetupdialogdatasetprintdata} -Pass TRUE if the dialog will simply return default printer information (such as orientation) -instead of showing a dialog. Windows only. +\func{void}{SetPrintData}{\param{const wxPrintData\&}{ printData}} + +Sets the \helpref{print data}{wxprintdata} associated with this object. + +\membersection{wxPageSetupDialogData::operator $=$}\label{wxpagesetupdialogdataassign} + +\func{void}{operator $=$}{\param{const wxPrintData\&}{ data}} + +Assigns print data to this object. + +\func{void}{operator $=$}{\param{const wxPageSetupDialogData\&}{ data}} + +Assigns page setup data to this object. \section{\class{wxPageSetupDialog}}\label{wxpagesetupdialog} @@ -197,8 +235,8 @@ native to the windowing system, otherwise it is emulated. The page setup dialog contains controls for paper size (A4, A5 etc.), orientation (landscape or portrait), and controls for setting left, top, right and bottom margin sizes in millimetres. -The page setup dialog does not set any global information (the exception being orientation -for PostScript printing) so you need to query the \helpref{wxPageSetupData}{wxpagesetupdata} object + +When the dialog has been closed, you need to query the \helpref{wxPageSetupDialogData}{wxpagesetupdialogdata} object associated with the dialog. Note that the OK and Cancel buttons do not destroy the dialog; this must be done by the @@ -217,13 +255,13 @@ application. \wxheading{See also} -\helpref{wxPrintDialog}{wxprintdialog}, \helpref{wxPageSetupData}{wxpagesetupdata} +\helpref{wxPrintDialog}{wxprintdialog}, \helpref{wxPageSetupDialogData}{wxpagesetupdialogdata} \latexignore{\rtfignore{\wxheading{Members}}} \membersection{wxPageSetupDialog::wxPageSetupDialog} -\func{}{wxPageSetupDialog}{\param{wxWindow* }{parent}, \param{wxPageSetupData* }{data = NULL}} +\func{}{wxPageSetupDialog}{\param{wxWindow* }{parent}, \param{wxPageSetupDialogData* }{data = NULL}} Constructor. Pass a parent window, and optionally a pointer to a block of page setup data, which will be copied to the print dialog's internal data. @@ -236,9 +274,9 @@ Destructor. \membersection{wxPageSetupDialog::GetPageSetupData}\label{wxpagesetupdialoggetpagesetupdata} -\func{wxPageSetupData\&}{GetPageSetupData}{\void} +\func{wxPageSetupDialogData\&}{GetPageSetupData}{\void} -Returns the \helpref{page setup data}{wxpagesetupdata} associated with the dialog. +Returns the \helpref{page setup data}{wxpagesetupdialogdata} associated with the dialog. \membersection{wxPageSetupDialog::ShowModal}\label{wxpagesetupdialogshowmodal} diff --git a/docs/latex/wx/postscpt.tex b/docs/latex/wx/postscpt.tex index c1d5e45eb1..b1bd9adda5 100644 --- a/docs/latex/wx/postscpt.tex +++ b/docs/latex/wx/postscpt.tex @@ -15,6 +15,10 @@ descriptions of the member functions. \membersection{wxPostScriptDC::wxPostScriptDC} +\func{}{wxPostScriptDC}{\param{const wxPrintData\&}{ printData}} + +Constructs a PostScript printer device context from a \helpref{wxPrintData}{wxprintdata} object. + \func{}{wxPostScriptDC}{\param{const wxString\& }{output}, \param{bool }{interactive = TRUE},\\ \param{wxWindow *}{parent}} @@ -28,6 +32,9 @@ in creating a useable device context. See \helpref{Printer settings}{printersettings} for functions to set and get PostScript printing settings. +This constructor and the global printer settings are now deprecated; +use the wxPrintData constructor instead. + \membersection{wxPostScriptDC::GetStream} \func{ostream *}{GetStream}{\void} diff --git a/docs/latex/wx/print.tex b/docs/latex/wx/print.tex index f576dd3f8e..ba16f85b95 100644 --- a/docs/latex/wx/print.tex +++ b/docs/latex/wx/print.tex @@ -1,6 +1,10 @@ \section{\class{wxPrintData}}\label{wxprintdata} -This class holds a variety of information related to print dialogs. +This class holds a variety of information related to printers and +printer device contexts. This class is used to create a wxPrinterDC +and a wxPostScriptDC. It is also used as a data member of wxPrintDialogData +and wxPageSetupDialogData, as part of the mechanism for transferring data +between the print dialogs and the application. \wxheading{Derived from} @@ -12,7 +16,45 @@ This class holds a variety of information related to print dialogs. \wxheading{See also} -\helpref{wxPrintDialog}{wxprintdialog}, \helpref{wxPrintDialog Overview}{wxprintdialogoverview} +\helpref{wxPrintDialog}{wxprintdialog}, +\helpref{wxPageSetupDialog}{wxpagesetupdialog}, +\helpref{wxPrintDialogData}{wxprintdialogdata}, +\helpref{wxPageSetupDialogData}{wxpagesetupdialogdata}, +\helpref{wxPrintDialog Overview}{wxprintdialogoverview}, +\helpref{wxPrinterDC}{wxprinterdc}, +\helpref{wxPostScriptDC}{wxpostscriptdc} + +\wxheading{Remarks} + +The following functions are specific to PostScript printing +and have not yet been documented: + +\begin{verbatim} +const wxString& GetPrinterCommand() const ; +const wxString& GetPrinterOptions() const ; +const wxString& GetPreviewCommand() const ; +const wxString& GetFilename() const ; +const wxString& GetFontMetricPath() const ; +double GetPrinterScaleX() const ; +double GetPrinterScaleY() const ; +long GetPrinterTranslateX() const ; +long GetPrinterTranslateY() const ; +// wxPRINT_MODE_PREVIEW, wxPRINT_MODE_FILE, wxPRINT_MODE_PRINTER +wxPrintMode GetPrintMode() const ; + +void SetPrinterCommand(const wxString& command) ; +void SetPrinterOptions(const wxString& options) ; +void SetPreviewCommand(const wxString& command) ; +void SetFilename(const wxString& filename) ; +void SetFontMetricPath(const wxString& path) ; +void SetPrinterScaleX(double x) ; +void SetPrinterScaleY(double y) ; +void SetPrinterScaling(double x, double y) ; +void SetPrinterTranslateX(long x) ; +void SetPrinterTranslateY(long y) ; +void SetPrinterTranslation(long x, long y) ; +void SetPrintMode(wxPrintMode printMode) ; +\end{verbatim} \latexignore{\rtfignore{\wxheading{Members}}} @@ -20,7 +62,11 @@ This class holds a variety of information related to print dialogs. \func{}{wxPrintData}{\void} -Constructor. +Default constructor. + +\func{}{wxPrintData}{\param{const wxPrintData\&}{ data}} + +Copy constructor. \membersection{wxPrintData::\destruct{wxPrintData}} @@ -28,107 +74,83 @@ Constructor. Destructor. -\membersection{wxPrintData::EnableHelp}\label{wxprintdataenablehelp} - -\func{void}{EnableHelp}{\param{bool }{flag}} - -Enables or disables the `Help' button. - -\membersection{wxPrintData::EnablePageNumbers}\label{wxprintdataenablepagenumbers} - -\func{void}{EnablePageNumbers}{\param{bool }{flag}} - -Enables or disables the `Page numbers' controls. - -\membersection{wxPrintData::EnablePrintToFile}\label{wxprintdataenableprinttofile} - -\func{void}{EnablePrintToFile}{\param{bool }{flag}} - -Enables or disables the `Print to file' checkbox. - -\membersection{wxPrintData::EnableSelection}\label{wxprintdataenableselection} - -\func{void}{EnableSelection}{\param{bool }{flag}} - -Enables or disables the `Selection' radio button. - -\membersection{wxPrintData::GetAllPages}\label{wxprintdatagetallpages} - -\func{bool}{GetAllPages}{\void} - -Returns TRUE if the user requested that all pages be printed. - \membersection{wxPrintData::GetCollate}\label{wxprintdatagetcollate} -\func{bool}{GetCollate}{\void} +\constfunc{bool}{GetCollate}{\void} -Returns TRUE if the user requested that the document(s) be collated. +Returns TRUE if collation is on. -\membersection{wxPrintData::GetFromPage}\label{wxprintdatagetfrompage} +\membersection{wxPrintData::GetColour}\label{wxprintdatagetcolour} -\func{int}{GetFromPage}{\void} +\constfunc{bool}{GetColour}{\void} -Returns the {\it from} page number, as entered by the user. +Returns TRUE if colour printing is on. -\membersection{wxPrintData::GetMaxPage}\label{wxprintdatagetmaxpage} +\membersection{wxPrintData::GetDuplex}\label{wxprintdatagetduplex} -\func{int}{GetMaxPage}{\void} +\constfunc{wxDuplexMode}{GetDuplex}{\void} -Returns the {\it maximum} page number. - -\membersection{wxPrintData::GetMinPage}\label{wxprintdatagetminpage} - -\func{int}{GetMinPage}{\void} - -Returns the {\it minimum} page number. +Returns the duplex mode. One of wxDUPLEX\_SIMPLEX, wxDUPLEX\_HORIZONTAL, wxDUPLEX\_VERTICAL. \membersection{wxPrintData::GetNoCopies}\label{wxprintdatagetnocopies} -\func{int}{GetNoCopies}{\void} +\constfunc{int}{GetNoCopies}{\void} Returns the number of copies requested by the user. \membersection{wxPrintData::GetOrientation}\label{wxprintdatagetorientation} -\func{int}{GetOrientation}{\void} +\constfunc{int}{GetOrientation}{\void} Gets the orientation. This can be wxLANDSCAPE or wxPORTRAIT. -\membersection{wxPrintData::GetToPage}\label{wxprintdatagettopage} +\membersection{wxPrintData::GetPaperId}\label{wxprintdatagetpaperid} -\func{int}{GetToPage}{\void} +\constfunc{wxPaperSize}{GetPaperId}{\void} -Returns the {\it to} page number, as entered by the user. +Returns the paper size id. For more information, see \helpref{wxPrintData::SetPaperId}{wxprintdatasetpaperid}. -\membersection{wxPrintData::SetCollate}\label{wxprintdatasetcollate} +\membersection{wxPrintData::GetPrinterName}\label{wxprintdatagetprintername} -\func{void}{SetCollate}{\param{bool }{flag}} +\constfunc{const wxString\&}{GetPrinterName}{\void} -Sets the 'Collate' checkbox to TRUE or FALSE. +Returns the printer name. If the printer name is the empty string, it indicates that the default +printer should be used. -\membersection{wxPrintData::SetFromPage}\label{wxprintdatasetfrompage} +\membersection{wxPrintData::GetQuality}\label{wxprintdatagetquality} -\func{void}{SetFromPage}{\param{int }{page}} +\constfunc{wxPaperQuality}{GetQuality}{\void} -Sets the {\it from} page number. +Returns the current print quality. This can be a positive integer, denoting the number of dots per inch, or +one of the following identifiers: -\membersection{wxPrintData::SetMaxPage}\label{wxprintdatasetmaxpage} +\begin{verbatim} +wxPRINT\_QUALITY\_HIGH +wxPRINT\_QUALITY\_MEDIUM +wxPRINT\_QUALITY\_LOW +wxPRINT\_QUALITY\_DRAFT +\end{verbatim} -\func{void}{SetMaxPage}{\param{int }{page}} +On input you should pass one of these identifiers, but on return you may get back a positive integer +indicating the current resolution setting. -Sets the {\it maximum} page number. +\membersection{wxPrintData::SetCollate}\label{wxprintdatasetcollate} -\membersection{wxPrintData::SetMinPage}\label{wxprintdatasetminpage} +\func{void}{SetCollate}{\param{bool }{flag}} -\func{void}{SetMinPage}{\param{int }{page}} +Sets collation to on or off. -Sets the {\it minimum} page number. +\membersection{wxPrintData::SetColour}\label{wxprintdatasetcolour} -\membersection{wxPrintData::SetOrientation}\label{wxprintdatasetorientation} +\func{void}{SetColour}{\param{bool }{flag}} -\func{void}{SetOrientation}{\param{int }{orientation}} +Sets colour printing on or off. -Sets the orientation. This can be wxLANDSCAPE or wxPORTRAIT. +\membersection{wxPrintData::SetDuplex}\label{wxprintdatasetduplex} + +\func{void}{SetDuplex}{\param{wxDuplexMode}{ mode}} + +Returns the duplex mode. One of wxDUPLEX\_SIMPLEX, wxDUPLEX\_HORIZONTAL, wxDUPLEX\_VERTICAL. \membersection{wxPrintData::SetNoCopies}\label{wxprintdatasetnocopies} @@ -136,27 +158,129 @@ Sets the orientation. This can be wxLANDSCAPE or wxPORTRAIT. Sets the default number of copies to be printed out. -\membersection{wxPrintData::SetPrintToFile}\label{wxprintdatasetprinttofile} - -\func{void}{SetPrintToFile}{\param{bool }{flag}} - -Sets the 'Print to file' checkbox to TRUE or FALSE. - -\membersection{wxPrintData::SetSetupDialog}\label{wxprintdatasetsetupdialog} - -\func{void}{SetSetupDialog}{\param{bool }{flag}} - -Determines whether the dialog to be shown will be the Print dialog -(pass FALSE) or Print Setup dialog (pass TRUE). - -Note that the setup dialog is obsolete from -Windows 95, though retained for backward compatibility. +\membersection{wxPrintData::SetOrientation}\label{wxprintdatasetorientation} -\membersection{wxPrintData::SetToPage}\label{wxprintdatasettopage} +\func{void}{SetOrientation}{\param{int }{orientation}} -\func{void}{SetToPage}{\param{int }{page}} +Sets the orientation. This can be wxLANDSCAPE or wxPORTRAIT. -Sets the {\it to} page number. +\membersection{wxPrintData::SetPaperId}\label{wxprintdatasetpaperid} + +\func{void}{SetPaperId}{\param{wxPaperSize}{ paperId}} + +\index{wxPaperSize}Sets the paper id. This indicates the type of paper to be used. For a mapping between +paper id, paper size and string name, see wxPrintPaperDatabase in {\tt paper.h} (not yet documented). + +{\it paperId} can be one of: + +{\small +\begin{verbatim} + wxPAPER_NONE, // Use specific dimensions + wxPAPER_LETTER, // Letter, 8 1/2 by 11 inches + wxPAPER_LEGAL, // Legal, 8 1/2 by 14 inches + wxPAPER_A4, // A4 Sheet, 210 by 297 millimeters + wxPAPER_CSHEET, // C Sheet, 17 by 22 inches + wxPAPER_DSHEET, // D Sheet, 22 by 34 inches + wxPAPER_ESHEET, // E Sheet, 34 by 44 inches + wxPAPER_LETTERSMALL, // Letter Small, 8 1/2 by 11 inches + wxPAPER_TABLOID, // Tabloid, 11 by 17 inches + wxPAPER_LEDGER, // Ledger, 17 by 11 inches + wxPAPER_STATEMENT, // Statement, 5 1/2 by 8 1/2 inches + wxPAPER_EXECUTIVE, // Executive, 7 1/4 by 10 1/2 inches + wxPAPER_A3, // A3 sheet, 297 by 420 millimeters + wxPAPER_A4SMALL, // A4 small sheet, 210 by 297 millimeters + wxPAPER_A5, // A5 sheet, 148 by 210 millimeters + wxPAPER_B4, // B4 sheet, 250 by 354 millimeters + wxPAPER_B5, // B5 sheet, 182-by-257-millimeter paper + wxPAPER_FOLIO, // Folio, 8-1/2-by-13-inch paper + wxPAPER_QUARTO, // Quarto, 215-by-275-millimeter paper + wxPAPER_10X14, // 10-by-14-inch sheet + wxPAPER_11X17, // 11-by-17-inch sheet + wxPAPER_NOTE, // Note, 8 1/2 by 11 inches + wxPAPER_ENV_9, // #9 Envelope, 3 7/8 by 8 7/8 inches + wxPAPER_ENV_10, // #10 Envelope, 4 1/8 by 9 1/2 inches + wxPAPER_ENV_11, // #11 Envelope, 4 1/2 by 10 3/8 inches + wxPAPER_ENV_12, // #12 Envelope, 4 3/4 by 11 inches + wxPAPER_ENV_14, // #14 Envelope, 5 by 11 1/2 inches + wxPAPER_ENV_DL, // DL Envelope, 110 by 220 millimeters + wxPAPER_ENV_C5, // C5 Envelope, 162 by 229 millimeters + wxPAPER_ENV_C3, // C3 Envelope, 324 by 458 millimeters + wxPAPER_ENV_C4, // C4 Envelope, 229 by 324 millimeters + wxPAPER_ENV_C6, // C6 Envelope, 114 by 162 millimeters + wxPAPER_ENV_C65, // C65 Envelope, 114 by 229 millimeters + wxPAPER_ENV_B4, // B4 Envelope, 250 by 353 millimeters + wxPAPER_ENV_B5, // B5 Envelope, 176 by 250 millimeters + wxPAPER_ENV_B6, // B6 Envelope, 176 by 125 millimeters + wxPAPER_ENV_ITALY, // Italy Envelope, 110 by 230 millimeters + wxPAPER_ENV_MONARCH, // Monarch Envelope, 3 7/8 by 7 1/2 inches + wxPAPER_ENV_PERSONAL, // 6 3/4 Envelope, 3 5/8 by 6 1/2 inches + wxPAPER_FANFOLD_US, // US Std Fanfold, 14 7/8 by 11 inches + wxPAPER_FANFOLD_STD_GERMAN, // German Std Fanfold, 8 1/2 by 12 inches + wxPAPER_FANFOLD_LGL_GERMAN, // German Legal Fanfold, 8 1/2 by 13 inches + +Windows 95 only: + wxPAPER_ISO_B4, // B4 (ISO) 250 x 353 mm + wxPAPER_JAPANESE_POSTCARD, // Japanese Postcard 100 x 148 mm + wxPAPER_9X11, // 9 x 11 in + wxPAPER_10X11, // 10 x 11 in + wxPAPER_15X11, // 15 x 11 in + wxPAPER_ENV_INVITE, // Envelope Invite 220 x 220 mm + wxPAPER_LETTER_EXTRA, // Letter Extra 9 \275 x 12 in + wxPAPER_LEGAL_EXTRA, // Legal Extra 9 \275 x 15 in + wxPAPER_TABLOID_EXTRA, // Tabloid Extra 11.69 x 18 in + wxPAPER_A4_EXTRA, // A4 Extra 9.27 x 12.69 in + wxPAPER_LETTER_TRANSVERSE, // Letter Transverse 8 \275 x 11 in + wxPAPER_A4_TRANSVERSE, // A4 Transverse 210 x 297 mm + wxPAPER_LETTER_EXTRA_TRANSVERSE, // Letter Extra Transverse 9\275 x 12 in + wxPAPER_A_PLUS, // SuperA/SuperA/A4 227 x 356 mm + wxPAPER_B_PLUS, // SuperB/SuperB/A3 305 x 487 mm + wxPAPER_LETTER_PLUS, // Letter Plus 8.5 x 12.69 in + wxPAPER_A4_PLUS, // A4 Plus 210 x 330 mm + wxPAPER_A5_TRANSVERSE, // A5 Transverse 148 x 210 mm + wxPAPER_B5_TRANSVERSE, // B5 (JIS) Transverse 182 x 257 mm + wxPAPER_A3_EXTRA, // A3 Extra 322 x 445 mm + wxPAPER_A5_EXTRA, // A5 Extra 174 x 235 mm + wxPAPER_B5_EXTRA, // B5 (ISO) Extra 201 x 276 mm + wxPAPER_A2, // A2 420 x 594 mm + wxPAPER_A3_TRANSVERSE, // A3 Transverse 297 x 420 mm + wxPAPER_A3_EXTRA_TRANSVERSE // A3 Extra Transverse 322 x 445 mm +\end{verbatim} +} + +\membersection{wxPrintData::SetPrinterName}\label{wxprintdatasetprintername} + +\func{void}{SetPrinterName}{\param{const wxString\& }{printerName}} + +Sets the printer name. This can be the empty string to indicate that the default +printer should be used. + +\membersection{wxPrintData::SetQuality}\label{wxprintdatasetquality} + +\func{void}{SetQuality}{\param{wxPaperQuality}{ quality}} + +Sets the desired print quality. This can be a positive integer, denoting the number of dots per inch, or +one of the following identifiers: + +\begin{verbatim} +wxPRINT\_QUALITY\_HIGH +wxPRINT\_QUALITY\_MEDIUM +wxPRINT\_QUALITY\_LOW +wxPRINT\_QUALITY\_DRAFT +\end{verbatim} + +On input you should pass one of these identifiers, but on return you may get back a positive integer +indicating the current resolution setting. + +\membersection{wxPrintData::operator $=$}\label{wxprintdataassign} + +\func{void}{operator $=$}{\param{const wxPrintData\&}{ data}} + +Assigns print data to this object. + +\func{void}{operator $=$}{\param{const wxPrintSetupData\&}{ data}} + +Assigns print setup data to this object. wxPrintSetupData is deprecated, +but retained for backward compatibility. \section{\class{wxPrintDialog}}\label{wxprintdialog} @@ -183,14 +307,14 @@ a successfully dismissed print dialog. \membersection{wxPrintDialog::wxPrintDialog} -\func{}{wxPrintDialog}{\param{wxWindow* }{parent}, \param{wxPrintData* }{data = NULL}} +\func{}{wxPrintDialog}{\param{wxWindow* }{parent}, \param{wxPrintDialogData* }{data = NULL}} Constructor. Pass a parent window, and optionally a pointer to a block of print data, which will be copied to the print dialog's print data. \wxheading{See also} -\helpref{wxPrintData}{wxprintdata} +\helpref{wxPrintDialogData}{wxprintdialogdata} \membersection{wxPrintDialog::\destruct{wxPrintDialog}} @@ -199,11 +323,11 @@ data, which will be copied to the print dialog's print data. Destructor. If wxPrintDialog::GetPrintDC has {\it not} been called, the device context obtained by the dialog (if any) will be deleted. -\membersection{wxPrintDialog::GetPrintData}\label{wxprintdialoggetprintdata} +\membersection{wxPrintDialog::GetPrintDialogData}\label{wxprintdialoggetprintdialogdata} -\func{wxPrintData\&}{GetPrintData}{\void} +\func{wxPrintDialogData\&}{GetPrintDialogData}{\void} -Returns the \helpref{print data}{wxprintdata} associated with the print dialog. +Returns the \helpref{print dialog data}{wxprintdialogdata} associated with the print dialog. \membersection{wxPrintDialog::GetPrintDC}\label{wxprintdialoggetprintdc} @@ -222,6 +346,191 @@ Shows the dialog, returning wxID\_OK if the user pressed OK, and wxID\_CANCEL otherwise. After this function is called, a device context may be retrievable using \helpref{wxPrintDialog::GetPrintDC}{wxprintdialoggetprintdc}. +\section{\class{wxPrintDialogData}}\label{wxprintdialogdata} + +This class holds information related to the visual characteristics of wxPrintDialog. +It contains a wxPrintData object with underlying printing settings. + +\wxheading{Derived from} + +\helpref{wxObject}{wxobject} + +\wxheading{Include files} + + + +\wxheading{See also} + +\helpref{wxPrintDialog}{wxprintdialog}, \helpref{wxPrintDialog Overview}{wxprintdialogoverview} + +\latexignore{\rtfignore{\wxheading{Members}}} + +\membersection{wxPrintDialogData::wxPrintDialogData} + +\func{}{wxPrintDialogData}{\void} + +Default constructor. + +\func{}{wxPrintDialogData}{\param{wxPrintDialogData\&}{ dialogData}} + +Copy constructor. + +\func{}{wxPrintDialogData}{\param{wxPrintData\&}{ printData}} + +Construct an object from a print dialog data object. + +\membersection{wxPrintDialogData::\destruct{wxprintdialogdata}} + +\func{}{\destruct{wxPrintDialogData}}{\void} + +Destructor. + +\membersection{wxPrintDialogData::EnableHelp}\label{wxprintdialogdataenablehelp} + +\func{void}{EnableHelp}{\param{bool }{flag}} + +Enables or disables the `Help' button. + +\membersection{wxPrintDialogData::EnablePageNumbers}\label{wxprintdialogdataenablepagenumbers} + +\func{void}{EnablePageNumbers}{\param{bool }{flag}} + +Enables or disables the `Page numbers' controls. + +\membersection{wxPrintDialogData::EnablePrintToFile}\label{wxprintdialogdataenableprinttofile} + +\func{void}{EnablePrintToFile}{\param{bool }{flag}} + +Enables or disables the `Print to file' checkbox. + +\membersection{wxPrintDialogData::EnableSelection}\label{wxprintdialogdataenableselection} + +\func{void}{EnableSelection}{\param{bool }{flag}} + +Enables or disables the `Selection' radio button. + +\membersection{wxPrintDialogData::GetAllPages}\label{wxprintdialogdatagetallpages} + +\constfunc{bool}{GetAllPages}{\void} + +Returns TRUE if the user requested that all pages be printed. + +\membersection{wxPrintDialogData::GetCollate}\label{wxprintdialogdatagetcollate} + +\constfunc{bool}{GetCollate}{\void} + +Returns TRUE if the user requested that the document(s) be collated. + +\membersection{wxPrintDialogData::GetFromPage}\label{wxprintdialogdatagetfrompage} + +\constfunc{int}{GetFromPage}{\void} + +Returns the {\it from} page number, as entered by the user. + +\membersection{wxPrintDialogData::GetMaxPage}\label{wxprintdialogdatagetmaxpage} + +\constfunc{int}{GetMaxPage}{\void} + +Returns the {\it maximum} page number. + +\membersection{wxPrintDialogData::GetMinPage}\label{wxprintdialogdatagetminpage} + +\constfunc{int}{GetMinPage}{\void} + +Returns the {\it minimum} page number. + +\membersection{wxPrintDialogData::GetNoCopies}\label{wxprintdialogdatagetnocopies} + +\constfunc{int}{GetNoCopies}{\void} + +Returns the number of copies requested by the user. + +\membersection{wxPrintDialogData::GetPrintData}\label{wxprintdialogdatagetprintdata} + +\func{wxPrintData\&}{GetPrintData}{\void} + +Returns a reference to the internal wxPrintData object. + +\membersection{wxPrintDialogData::GetPrintToFile}\label{wxprintdialogdatagetprinttofile} + +\constfunc{bool}{GetPrintToFile}{\void} + +Returns TRUE if the user has selected printing to a file. + +\membersection{wxPrintDialogData::GetToPage}\label{wxprintdialogdatagettopage} + +\constfunc{int}{GetToPage}{\void} + +Returns the {\it to} page number, as entered by the user. + +\membersection{wxPrintDialogData::SetCollate}\label{wxprintdialogdatasetcollate} + +\func{void}{SetCollate}{\param{bool }{flag}} + +Sets the 'Collate' checkbox to TRUE or FALSE. + +\membersection{wxPrintDialogData::SetFromPage}\label{wxprintdialogdatasetfrompage} + +\func{void}{SetFromPage}{\param{int }{page}} + +Sets the {\it from} page number. + +\membersection{wxPrintDialogData::SetMaxPage}\label{wxprintdialogdatasetmaxpage} + +\func{void}{SetMaxPage}{\param{int }{page}} + +Sets the {\it maximum} page number. + +\membersection{wxPrintDialogData::SetMinPage}\label{wxprintdialogdatasetminpage} + +\func{void}{SetMinPage}{\param{int }{page}} + +Sets the {\it minimum} page number. + +\membersection{wxPrintDialogData::SetNoCopies}\label{wxprintdialogdatasetnocopies} + +\func{void}{SetNoCopies}{\param{int }{n}} + +Sets the default number of copies the user has requested to be printed out. + +\membersection{wxPrintDialogData::SetPrintData}\label{wxprintdialogdatasetprintdata} + +\func{void}{SetPrintData}{\param{const wxPrintData\& }{printData}} + +Sets the internal wxPrintData. + +\membersection{wxPrintDialogData::SetPrintToFile}\label{wxprintdialogdatasetprinttofile} + +\func{void}{SetPrintToFile}{\param{bool }{flag}} + +Sets the 'Print to file' checkbox to TRUE or FALSE. + +\membersection{wxPrintDialogData::SetSetupDialog}\label{wxprintdialogdatasetsetupdialog} + +\func{void}{SetSetupDialog}{\param{bool }{flag}} + +Determines whether the dialog to be shown will be the Print dialog +(pass FALSE) or Print Setup dialog (pass TRUE). + +Note that the setup dialog is (according to Microsoft) obsolete from +Windows 95, though retained for backward compatibility. + +\membersection{wxPrintDialogData::SetToPage}\label{wxprintdialogdatasettopage} + +\func{void}{SetToPage}{\param{int }{page}} + +Sets the {\it to} page number. + +\membersection{wxPrintDialogData::operator $=$}\label{wxprintdialogdataassign} + +\func{void}{operator $=$}{\param{const wxPrintData\&}{ data}} + +Assigns print data to this object. + +\func{void}{operator $=$}{\param{const wxPrintDialogData\&}{ data}} + +Assigns another print dialog data object to this object. + \section{\class{wxPrinter}}\label{wxprinter} This class represents the Windows or PostScript printer, and is the vehicle through @@ -247,13 +556,14 @@ method of printing. \membersection{wxPrinter::wxPrinter} -\func{}{wxPrinter}{\param{wxPrintData* }{data = NULL}} +\func{}{wxPrinter}{\param{wxPrintDialogData* }{data = NULL}} Constructor. Pass an optional pointer to a block of print -data, which will be copied to the printer object's print data. +dialog data, which will be copied to the printer object's local data. \wxheading{See also} +\helpref{wxPrintDialogData}{wxprintdialogdata}, \helpref{wxPrintData}{wxprintdata} \membersection{wxPrinter::\destruct{wxPrinter}} @@ -274,9 +584,9 @@ Returns TRUE if the user has aborted the print job. Creates the default printing abort window, with a cancel button. -\membersection{wxPrinter::GetPrintData}\label{wxprintergetprintdata} +\membersection{wxPrinter::GetPrintDialogData}\label{wxprintergetprintdialogdata} -\func{wxPrintData\&}{GetPrintData}{\void} +\func{wxPrintDialogData\&}{GetPrintDialogData}{\void} Returns the \helpref{print data}{wxprintdata} associated with the printer object. @@ -292,9 +602,13 @@ Print could return FALSE if there was a problem initializing the printer device \membersection{wxPrinter::PrintDialog}\label{wxprinterprintdialog} -\func{bool}{PrintDialog}{\param{wxWindow *}{parent}} +\func{wxDC*}{PrintDialog}{\param{wxWindow *}{parent}} + +Invokes the print dialog. If successful (the user did not press Cancel +and no error occurred), a suitable device context will be returned +(otherwise NULL is returned). -Invokes the print dialog. +The application must delete this device context to avoid a memory leak. \membersection{wxPrinter::ReportError}\label{wxprinterreporterror} @@ -304,7 +618,7 @@ Default error-reporting function. \membersection{wxPrinter::Setup}\label{wxprintersetup} -\func{void}{Setup}{\param{wxWindow *}{parent}} +\func{bool}{Setup}{\param{wxWindow *}{parent}} Invokes the print setup dialog. Note that the setup dialog is obsolete from Windows 95, though retained for backward compatibility. @@ -333,6 +647,12 @@ achieving the correct scaling for the page. \membersection{wxPrinterDC::wxPrinterDC} +\func{}{wxPrinterDC}{\param{const wxPrintData\& }{printData}} + +Pass a \helpref{wxPrintData}{wxprintdata} object with information +necessary for setting up a suitable printer device context. This +is the recommended way to construct a wxPrinterDC. + \func{}{wxPrinterDC}{\param{const wxString\& }{driver}, \param{const wxString\& }{device}, \param{const wxString\& }{output}, \param{const bool }{interactive = TRUE}, \param{int }{orientation = wxPORTRAIT}} @@ -342,6 +662,8 @@ is an optional file for printing to. The {\it driver} parameter is currently unused. Use the {\it Ok} member to test whether the constructor was successful in creating a useable device context. +This constructor is deprecated and retained only for backward compatibility. + \section{\class{wxPrintout}}\label{wxprintout} This class encapsulates the functionality of printing out an @@ -671,4 +993,3 @@ Associates a printout object with the wxPrintPreview object. Sets the percentage preview zoom, and refreshes the preview canvas accordingly. - diff --git a/docs/latex/wx/tprint.tex b/docs/latex/wx/tprint.tex index 6588e312c4..e6f672c936 100644 --- a/docs/latex/wx/tprint.tex +++ b/docs/latex/wx/tprint.tex @@ -1,8 +1,14 @@ \section{Printing overview}\label{printingoverview} -Classes: \helpref{wxPrintout}{wxprintout}, \helpref{wxPrinter}{wxprinter},\rtfsp -\helpref{wxPrintPreview}{wxprintpreview}, \helpref{wxPrinterDC}{wxprinterdc},\rtfsp -\helpref{wxPrintDialog}{wxprintdialog}. +Classes: \helpref{wxPrintout}{wxprintout}, +\helpref{wxPrinter}{wxprinter}, +\helpref{wxPrintPreview}{wxprintpreview}, +\helpref{wxPrinterDC}{wxprinterdc}, +\helpref{wxPrintDialog}{wxprintdialog}, +\helpref{wxPrintData}{wxprintdata}, +\helpref{wxPrintDialogData}{wxprintdialogdata}, +\helpref{wxPageSetupDialog}{wxpagesetupdialog}, +\helpref{wxPageSetupDialogData}{wxpagesetupdialogdata} The printing framework relies on the application to provide classes whose member functions can respond to particular requests, such @@ -11,8 +17,6 @@ This method allows wxWindows to take over the housekeeping duties of turning preview pages, calling the print dialog box, creating the printer device context, and so on: the application can concentrate on the rendering of the information onto a device context. -The printing framework is mainly a Windows feature; PostScript -support under non-Windows platforms is emerging but has not been rigorously tested. The \helpref{document/view framework}{docviewoverview} creates a default wxPrintout object for every view, calling wxView::OnDraw to achieve a diff --git a/docs/latex/wx/wxPython.tex b/docs/latex/wx/wxPython.tex index 7561ae8d3d..28c0f1ecc7 100644 --- a/docs/latex/wx/wxPython.tex +++ b/docs/latex/wx/wxPython.tex @@ -438,7 +438,7 @@ as possible to the C++ spec over time. \item \helpref{wxMoveEvent}{wxmoveevent} \item \helpref{wxNotebookEvent}{wxnotebookevent} \item \helpref{wxNotebook}{wxnotebook} -\item \helpref{wxPageSetupData}{wxpagesetupdata} +\item \helpref{wxPageSetupDialogData}{wxpagesetupdialogdata} \item \helpref{wxPageSetupDialog}{wxpagesetupdialog} \item \helpref{wxPaintDC}{wxpaintdc} \item \helpref{wxPaintEvent}{wxpaintevent} diff --git a/include/wx/cmndata.h b/include/wx/cmndata.h index dc4eeb3ee0..9a1c0c5da9 100644 --- a/include/wx/cmndata.h +++ b/include/wx/cmndata.h @@ -19,208 +19,363 @@ #include "wx/font.h" #include "wx/colour.h" +#if (defined(__WXMOTIF__) || defined(__WXGTK__)) && wxUSE_POSTSCRIPT +class WXDLLEXPORT wxPrintSetupData; +#endif + class WXDLLEXPORT wxColourData: public wxObject { - DECLARE_DYNAMIC_CLASS(wxColourData) - public: - wxColour dataColour; - wxColour custColours[16]; - bool chooseFull; - - wxColourData(void); - ~wxColourData(void); - - inline void SetChooseFull(bool flag) { chooseFull = flag; } - inline bool GetChooseFull(void) { return chooseFull; } - inline void SetColour(wxColour& colour) { dataColour = colour; } - inline wxColour &GetColour(void) { return dataColour; } - - // Array of 16 custom colours - void SetCustomColour(int i, wxColour& colour); - wxColour GetCustomColour(int i); - - void operator=(const wxColourData& data); + DECLARE_DYNAMIC_CLASS(wxColourData) +public: + wxColourData(); + wxColourData(const wxColourData& data); + ~wxColourData(); + + inline void SetChooseFull(bool flag) { chooseFull = flag; } + inline bool GetChooseFull() const { return chooseFull; } + inline void SetColour(wxColour& colour) { dataColour = colour; } + inline wxColour &GetColour() { return dataColour; } + + // Array of 16 custom colours + void SetCustomColour(int i, wxColour& colour); + wxColour GetCustomColour(int i); + + void operator=(const wxColourData& data); + +public: + wxColour dataColour; + wxColour custColours[16]; + bool chooseFull; }; class WXDLLEXPORT wxFontData: public wxObject { - DECLARE_DYNAMIC_CLASS(wxFontData) - public: - wxColour fontColour; - bool showHelp; - bool allowSymbols; - bool enableEffects; - wxFont initialFont; - wxFont chosenFont; - int minSize; - int maxSize; - - wxFontData(void); - ~wxFontData(void); - - inline void SetAllowSymbols(bool flag) { allowSymbols = flag; } - inline bool GetAllowSymbols(void) { return allowSymbols; } - inline void SetColour(const wxColour& colour) { fontColour = colour; } - inline wxColour &GetColour(void) { return fontColour; } - inline void SetShowHelp(bool flag) { showHelp = flag; } - inline bool GetShowHelp(void) { return showHelp; } - inline void EnableEffects(bool flag) { enableEffects = flag; } - inline bool GetEnableEffects(void) { return enableEffects; } - inline void SetInitialFont(const wxFont& font) { initialFont = font; } - inline wxFont GetInitialFont(void) { return initialFont; } - inline void SetChosenFont(const wxFont& font) { chosenFont = font; } - inline wxFont GetChosenFont(void) { return chosenFont; } - inline void SetRange(int minRange, int maxRange) { minSize = minRange; maxSize = maxRange; } - - void operator=(const wxFontData& data); + DECLARE_DYNAMIC_CLASS(wxFontData) +public: + wxFontData(); + wxFontData(const wxFontData& fontData); + ~wxFontData(); + + inline void SetAllowSymbols(bool flag) { allowSymbols = flag; } + inline bool GetAllowSymbols() const { return allowSymbols; } + + inline void SetColour(const wxColour& colour) { fontColour = colour; } + inline wxColour &GetColour() { return fontColour; } + + inline void SetShowHelp(bool flag) { showHelp = flag; } + inline bool GetShowHelp() const { return showHelp; } + + inline void EnableEffects(bool flag) { enableEffects = flag; } + inline bool GetEnableEffects() const { return enableEffects; } + + inline void SetInitialFont(const wxFont& font) { initialFont = font; } + inline wxFont GetInitialFont() const { return initialFont; } + + inline void SetChosenFont(const wxFont& font) { chosenFont = font; } + inline wxFont GetChosenFont() const { return chosenFont; } + + inline void SetRange(int minRange, int maxRange) { minSize = minRange; maxSize = maxRange; } + + void operator=(const wxFontData& data); + +public: + wxColour fontColour; + bool showHelp; + bool allowSymbols; + bool enableEffects; + wxFont initialFont; + wxFont chosenFont; + int minSize; + int maxSize; }; /* * wxPrintData - * Encapsulates information displayed and edited in the printer dialog box. + * Encapsulates printer information (not printer dialog information) */ - + class WXDLLEXPORT wxPrintData: public wxObject { - DECLARE_DYNAMIC_CLASS(wxPrintData) - - public: + DECLARE_DYNAMIC_CLASS(wxPrintData) + + wxPrintData(); + wxPrintData(const wxPrintData& printData); + ~wxPrintData(); + + inline int GetNoCopies() const { return m_printNoCopies; }; + inline bool GetCollate() const { return m_printCollate; }; + inline int GetOrientation() const { return m_printOrientation; }; + + inline const wxString& GetPrinterName() const { return m_printerName; } + inline bool GetColour() const { return m_colour; } + inline wxDuplexMode GetDuplex() const { return m_duplexMode; } + inline wxPaperSize GetPaperId() const { return m_paperId; } + inline const wxSize& GetPaperSize() const { return m_paperSize; } // Not used yet: confusable with paper size + // in wxPageSetupDialogData + inline wxPrintQuality GetQuality() const { return m_printQuality; } + + inline void SetNoCopies(int v) { m_printNoCopies = v; }; + inline void SetCollate(bool flag) { m_printCollate = flag; }; + inline void SetOrientation(int orient) { m_printOrientation = orient; }; + + inline void SetPrinterName(const wxString& name) { m_printerName = name; } + inline void SetColour(bool colour) { m_colour = colour; } + inline void SetDuplex(wxDuplexMode duplex) { m_duplexMode = duplex; } + inline void SetPaperId(wxPaperSize sizeId) { m_paperId = sizeId; } + inline void SetPaperSize(const wxSize& sz) { m_paperSize = sz; } + inline void SetQuality(wxPrintQuality quality) { m_printQuality = quality; } + + // PostScript-specific data + inline const wxString& GetPrinterCommand() const { return m_printerCommand; } + inline const wxString& GetPrinterOptions() const { return m_printerOptions; } + inline const wxString& GetPreviewCommand() const { return m_previewCommand; } + inline const wxString& GetFilename() const { return m_filename; } + inline const wxString& GetFontMetricPath() const { return m_afmPath; } + inline double GetPrinterScaleX() const { return m_printerScaleX; } + inline double GetPrinterScaleY() const { return m_printerScaleY; } + inline long GetPrinterTranslateX() const { return m_printerTranslateX; } + inline long GetPrinterTranslateY() const { return m_printerTranslateY; } + inline wxPrintMode GetPrintMode() const { return m_printMode; } + + inline void SetPrinterCommand(const wxString& command) { m_printerCommand = command; } + inline void SetPrinterOptions(const wxString& options) { m_printerOptions = options; } + inline void SetPreviewCommand(const wxString& command) { m_previewCommand = command; } + inline void SetFilename(const wxString& filename) { m_filename = filename; } + inline void SetFontMetricPath(const wxString& path) { m_afmPath = path; } + inline void SetPrinterScaleX(double x) { m_printerScaleX = x; } + inline void SetPrinterScaleY(double y) { m_printerScaleY = y; } + inline void SetPrinterScaling(double x, double y) { m_printerScaleX = x; m_printerScaleY = y; } + inline void SetPrinterTranslateX(long x) { m_printerTranslateX = x; } + inline void SetPrinterTranslateY(long y) { m_printerTranslateY = y; } + inline void SetPrinterTranslation(long x, long y) { m_printerTranslateX = x; m_printerTranslateY = y; } + inline void SetPrintMode(wxPrintMode printMode) { m_printMode = printMode; } + + void operator=(const wxPrintData& data); + + // For compatibility +#if (defined(__WXMOTIF__) || defined(__WXGTK__)) && wxUSE_POSTSCRIPT + void operator=(const wxPrintSetupData& setupData); +#endif + #ifdef __WXMSW__ - void *printData; + // Convert to/from the DEVMODE structure + void ConvertToNative(); + void ConvertFromNative(); + inline void* GetNativeData() const { return m_devMode; } + inline void SetNativeData(void* data) { m_devMode = data; } #endif - int printFromPage; - int printToPage; - int printMinPage; - int printMaxPage; - int printNoCopies; - int printOrientation; - bool printAllPages; - bool printCollate; - bool printToFile; - bool printEnableSelection; - bool printEnablePageNumbers; - bool printEnableHelp; - bool printEnablePrintToFile; - bool printSetupDialog; - - wxPrintData(void); - ~wxPrintData(void); - - inline int GetFromPage(void) { return printFromPage; }; - inline int GetToPage(void) { return printToPage; }; - inline int GetMinPage(void) { return printMinPage; }; - inline int GetMaxPage(void) { return printMaxPage; }; - inline int GetNoCopies(void) { return printNoCopies; }; - inline bool GetAllPages(void) { return printAllPages; }; - inline bool GetCollate(void) { return printCollate; }; - inline bool GetPrintToFile(void) { return printToFile; }; - inline bool GetSetupDialog(void) { return printSetupDialog; }; - inline int GetOrientation(void) { return printOrientation; }; - - inline void SetFromPage(int v) { printFromPage = v; }; - inline void SetToPage(int v) { printToPage = v; }; - inline void SetMinPage(int v) { printMinPage = v; }; - inline void SetMaxPage(int v) { printMaxPage = v; }; - inline void SetNoCopies(int v) { printNoCopies = v; }; - inline void SetAllPages(bool flag) { printAllPages = flag; }; - inline void SetCollate(bool flag) { printCollate = flag; }; - inline void SetPrintToFile(bool flag) { printToFile = flag; }; - inline void SetSetupDialog(bool flag) { printSetupDialog = flag; }; - inline void SetOrientation(int orient) { printOrientation = orient; }; - - inline void EnablePrintToFile(bool flag) { printEnablePrintToFile = flag; }; - inline void EnableSelection(bool flag) { printEnableSelection = flag; }; - inline void EnablePageNumbers(bool flag) { printEnablePageNumbers = flag; }; - inline void EnableHelp(bool flag) { printEnableHelp = flag; }; - - inline bool GetEnablePrintToFile(void) { return printEnablePrintToFile; }; - inline bool GetEnableSelection(void) { return printEnableSelection; }; - inline bool GetEnablePageNumbers(void) { return printEnablePageNumbers; }; - inline bool GetEnableHelp(void) { return printEnableHelp; }; - - void operator=(const wxPrintData& data); - + +public: #ifdef __WXMSW__ - // Convert to/from the PRINTDLG structure - void ConvertToNative(void); - void ConvertFromNative(void); - void SetOwnerWindow(wxWindow* win); - inline void* GetNativeData(void) { return printData; } + void* m_devMode; #endif + +private: + + int m_printNoCopies; + int m_printOrientation; + bool m_printCollate; + + // New members, 24/3/99 + wxString m_printerName; + bool m_colour; + wxDuplexMode m_duplexMode; + wxPrintQuality m_printQuality; + wxPaperSize m_paperId; + wxSize m_paperSize; + + // PostScript-specific data + wxString m_printerCommand; + wxString m_previewCommand; + wxString m_printerOptions; + wxString m_filename; + wxString m_afmPath; + double m_printerScaleX; + double m_printerScaleY; + long m_printerTranslateX; + long m_printerTranslateY; + wxPrintMode m_printMode; }; /* - * This is the data used (and returned) by the wxPageSetupDialog. + * wxPrintDialogData + * Encapsulates information displayed and edited in the printer dialog box. + * Contains a wxPrintData object which is filled in according to the values retrieved + * from the dialog. */ -class WXDLLEXPORT wxPageSetupData: public wxObject +class WXDLLEXPORT wxPrintDialogData: public wxObject { - DECLARE_DYNAMIC_CLASS(wxPageSetupData) + DECLARE_DYNAMIC_CLASS(wxPrintDialogData) + + wxPrintDialogData(); + wxPrintDialogData(const wxPrintDialogData& dialogData); + wxPrintDialogData(const wxPrintData& printData); + ~wxPrintDialogData(); + + inline int GetFromPage() const { return m_printFromPage; }; + inline int GetToPage() const { return m_printToPage; }; + inline int GetMinPage() const { return m_printMinPage; }; + inline int GetMaxPage() const { return m_printMaxPage; }; + inline int GetNoCopies() const { return m_printNoCopies; }; + inline bool GetAllPages() const { return m_printAllPages; }; + inline bool GetCollate() const { return m_printCollate; }; + inline bool GetPrintToFile() const { return m_printToFile; }; + inline bool GetSetupDialog() const { return m_printSetupDialog; }; + + inline void SetFromPage(int v) { m_printFromPage = v; }; + inline void SetToPage(int v) { m_printToPage = v; }; + inline void SetMinPage(int v) { m_printMinPage = v; }; + inline void SetMaxPage(int v) { m_printMaxPage = v; }; + inline void SetNoCopies(int v) { m_printNoCopies = v; }; + inline void SetAllPages(bool flag) { m_printAllPages = flag; }; + inline void SetCollate(bool flag) { m_printCollate = flag; }; + inline void SetPrintToFile(bool flag) { m_printToFile = flag; }; + inline void SetSetupDialog(bool flag) { m_printSetupDialog = flag; }; + + inline void EnablePrintToFile(bool flag) { m_printEnablePrintToFile = flag; }; + inline void EnableSelection(bool flag) { m_printEnableSelection = flag; }; + inline void EnablePageNumbers(bool flag) { m_printEnablePageNumbers = flag; }; + inline void EnableHelp(bool flag) { m_printEnableHelp = flag; }; + + inline bool GetEnablePrintToFile() const { return m_printEnablePrintToFile; }; + inline bool GetEnableSelection() const { return m_printEnableSelection; }; + inline bool GetEnablePageNumbers() const { return m_printEnablePageNumbers; }; + inline bool GetEnableHelp() const { return m_printEnableHelp; }; + + inline wxPrintData& GetPrintData() { return m_printData; } + inline void SetPrintData(const wxPrintData& printData) { m_printData = printData; } + + void operator=(const wxPrintDialogData& data); + void operator=(const wxPrintData& data); // Sets internal m_printData member + +#ifdef __WXMSW__ + // Convert to/from the PRINTDLG structure + void ConvertToNative(); + void ConvertFromNative(); + void SetOwnerWindow(wxWindow* win); + inline void* GetNativeData() const { return m_printDlgData; } +#endif + +#ifdef __WXMSW__ + void* m_printDlgData; +#endif + +private: + + int m_printFromPage; + int m_printToPage; + int m_printMinPage; + int m_printMaxPage; + int m_printNoCopies; + bool m_printAllPages; + bool m_printCollate; + bool m_printToFile; + bool m_printEnableSelection; + bool m_printEnablePageNumbers; + bool m_printEnableHelp; + bool m_printEnablePrintToFile; + bool m_printSetupDialog; + + wxPrintData m_printData; +}; + +/* +* This is the data used (and returned) by the wxPageSetupDialog. +*/ + +// Compatibility with old name +#define wxPageSetupData wxPageSetupDialogData - public: +class WXDLLEXPORT wxPageSetupDialogData: public wxObject +{ + DECLARE_DYNAMIC_CLASS(wxPageSetupDialogData) + +public: + wxPageSetupDialogData(); + wxPageSetupDialogData(const wxPageSetupDialogData& dialogData); + wxPageSetupDialogData(const wxPrintData& printData); + ~wxPageSetupDialogData(); + + inline wxSize GetPaperSize() const { return m_paperSize; }; + inline wxPaperSize GetPaperId() const { return m_printData.GetPaperId(); }; + inline wxPoint GetMinMarginTopLeft() const { return m_minMarginTopLeft; }; + inline wxPoint GetMinMarginBottomRight() const { return m_minMarginBottomRight; }; + inline wxPoint GetMarginTopLeft() const { return m_marginTopLeft; }; + inline wxPoint GetMarginBottomRight() const { return m_marginBottomRight; }; + + inline bool GetDefaultMinMargins() const { return m_defaultMinMargins; }; + inline bool GetEnableMargins() const { return m_enableMargins; }; + inline bool GetEnableOrientation() const { return m_enableOrientation; }; + inline bool GetEnablePaper() const { return m_enablePaper; }; + inline bool GetEnablePrinter() const { return m_enablePrinter; }; + inline bool GetDefaultInfo() const { return m_getDefaultInfo; }; + inline bool GetEnableHelp() const { return m_enableHelp; }; + + // If a corresponding paper type is found in the paper database, will set the m_printData + // paper size id member as well. + void SetPaperSize(const wxSize& sz); + + // Sets the wxPrintData id, plus the paper width/height if found in the paper database. + void SetPaperSize(wxPaperSize id); + + inline void SetMinMarginTopLeft(const wxPoint& pt) { m_minMarginTopLeft = pt; }; + inline void SetMinMarginBottomRight(const wxPoint& pt) { m_minMarginBottomRight = pt; }; + inline void SetMarginTopLeft(const wxPoint& pt) { m_marginTopLeft = pt; }; + inline void SetMarginBottomRight(const wxPoint& pt) { m_marginBottomRight = pt; }; + inline void SetDefaultMinMargins(bool flag) { m_defaultMinMargins = flag; }; + inline void SetDefaultInfo(bool flag) { m_getDefaultInfo = flag; }; + + inline void EnableMargins(bool flag) { m_enableMargins = flag; }; + inline void EnableOrientation(bool flag) { m_enableOrientation = flag; }; + inline void EnablePaper(bool flag) { m_enablePaper = flag; }; + inline void EnablePrinter(bool flag) { m_enablePrinter = flag; }; + inline void EnableHelp(bool flag) { m_enableHelp = flag; }; + #if defined(__WIN95__) - void* m_pageSetupData; + // Convert to/from the PAGESETUPDLG structure + void ConvertToNative(); + void ConvertFromNative(); + void SetOwnerWindow(wxWindow* win); + inline void* GetNativeData() const { return m_pageSetupData; } #endif - wxPoint m_paperSize; - wxPoint m_minMarginTopLeft; - wxPoint m_minMarginBottomRight; - wxPoint m_marginTopLeft; - wxPoint m_marginBottomRight; - int m_orientation; - - // Flags - bool m_defaultMinMargins; - bool m_enableMargins; - bool m_enableOrientation; - bool m_enablePaper; - bool m_enablePrinter; - bool m_getDefaultInfo; // Equiv. to PSD_RETURNDEFAULT - bool m_enableHelp; - - wxPageSetupData(void); - ~wxPageSetupData(void); - - inline wxPoint GetPaperSize(void) { return m_paperSize; }; - inline wxPoint GetMinMarginTopLeft(void) { return m_minMarginTopLeft; }; - inline wxPoint GetMinMarginBottomRight(void) { return m_minMarginBottomRight; }; - inline wxPoint GetMarginTopLeft(void) { return m_marginTopLeft; }; - inline wxPoint GetMarginBottomRight(void) { return m_marginBottomRight; }; - inline int GetOrientation(void) { return m_orientation; }; - - inline bool GetDefaultMinMargins(void) { return m_defaultMinMargins; }; - inline bool GetEnableMargins(void) { return m_enableMargins; }; - inline bool GetEnableOrientation(void) { return m_enableOrientation; }; - inline bool GetEnablePaper(void) { return m_enablePaper; }; - inline bool GetEnablePrinter(void) { return m_enablePrinter; }; - inline bool GetDefaultInfo(void) { return m_getDefaultInfo; }; - inline bool GetEnableHelp(void) { return m_enableHelp; }; - - inline void SetPaperSize(const wxPoint& pt) { m_paperSize = pt; }; - inline void SetMinMarginTopLeft(const wxPoint& pt) { m_minMarginTopLeft = pt; }; - inline void SetMinMarginBottomRight(const wxPoint& pt) { m_minMarginBottomRight = pt; }; - inline void SetMarginTopLeft(const wxPoint& pt) { m_marginTopLeft = pt; }; - inline void SetMarginBottomRight(const wxPoint& pt) { m_marginBottomRight = pt; }; - inline void SetOrientation(int orient) { m_orientation = orient; }; - inline void SetDefaultMinMargins(bool flag) { m_defaultMinMargins = flag; }; - inline void SetDefaultInfo(bool flag) { m_getDefaultInfo = flag; }; - - inline void EnableMargins(bool flag) { m_enableMargins = flag; }; - inline void EnableOrientation(bool flag) { m_enableOrientation = flag; }; - inline void EnablePaper(bool flag) { m_enablePaper = flag; }; - inline void EnablePrinter(bool flag) { m_enablePrinter = flag; }; - inline void EnableHelp(bool flag) { m_enableHelp = flag; }; + + // Use paper size defined in this object to set the wxPrintData + // paper id + void CalculateIdFromPaperSize(); + + // Use paper id in wxPrintData to set this object's paper size + void CalculatePaperSizeFromId(); + + void operator=(const wxPageSetupData& data); + void operator=(const wxPrintData& data); + + inline wxPrintData& GetPrintData() { return m_printData; } + inline void SetPrintData(const wxPrintData& printData) { m_printData = printData; } #if defined(__WIN95__) - // Convert to/from the PAGESETUPDLG structure - void ConvertToNative(void); - void ConvertFromNative(void); - void SetOwnerWindow(wxWindow* win); - inline void* GetNativeData(void) { return m_pageSetupData; } + void* m_pageSetupData; #endif - void operator=(const wxPageSetupData& data); -}; +private: + wxSize m_paperSize; // The dimensions selected by the user (on return, same as in wxPrintData?) + wxPoint m_minMarginTopLeft; + wxPoint m_minMarginBottomRight; + wxPoint m_marginTopLeft; + wxPoint m_marginBottomRight; + + // Flags + bool m_defaultMinMargins; + bool m_enableMargins; + bool m_enableOrientation; + bool m_enablePaper; + bool m_enablePrinter; + bool m_getDefaultInfo; // Equiv. to PSD_RETURNDEFAULT + bool m_enableHelp; + + wxPrintData m_printData; +}; #endif - // _WX_CMNDATA_H_BASE_ +// _WX_CMNDATA_H_BASE_ diff --git a/include/wx/defs.h b/include/wx/defs.h index f5777c1ee9..baf3c4acca 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -868,12 +868,6 @@ enum wxWIN386 // Watcom 32-bit supervisor modus }; -/* Printing */ -#ifndef wxPORTRAIT -#define wxPORTRAIT 1 -#define wxLANDSCAPE 2 -#endif - /* Standard menu identifiers */ #define wxID_LOWEST 4999 @@ -939,6 +933,115 @@ enum /* Shortcut for easier dialog-unit-to-pixel conversion */ #define wxDLG_UNIT(parent, pt) parent->ConvertDialogToPixels(pt) +/* Paper types */ +typedef enum { + wxPAPER_NONE, // Use specific dimensions + wxPAPER_LETTER, // Letter, 8 1/2 by 11 inches + wxPAPER_LEGAL, // Legal, 8 1/2 by 14 inches + wxPAPER_A4, // A4 Sheet, 210 by 297 millimeters + wxPAPER_CSHEET, // C Sheet, 17 by 22 inches + wxPAPER_DSHEET, // D Sheet, 22 by 34 inches + wxPAPER_ESHEET, // E Sheet, 34 by 44 inches + wxPAPER_LETTERSMALL, // Letter Small, 8 1/2 by 11 inches + wxPAPER_TABLOID, // Tabloid, 11 by 17 inches + wxPAPER_LEDGER, // Ledger, 17 by 11 inches + wxPAPER_STATEMENT, // Statement, 5 1/2 by 8 1/2 inches + wxPAPER_EXECUTIVE, // Executive, 7 1/4 by 10 1/2 inches + wxPAPER_A3, // A3 sheet, 297 by 420 millimeters + wxPAPER_A4SMALL, // A4 small sheet, 210 by 297 millimeters + wxPAPER_A5, // A5 sheet, 148 by 210 millimeters + wxPAPER_B4, // B4 sheet, 250 by 354 millimeters + wxPAPER_B5, // B5 sheet, 182-by-257-millimeter paper + wxPAPER_FOLIO, // Folio, 8-1/2-by-13-inch paper + wxPAPER_QUARTO, // Quarto, 215-by-275-millimeter paper + wxPAPER_10X14, // 10-by-14-inch sheet + wxPAPER_11X17, // 11-by-17-inch sheet + wxPAPER_NOTE, // Note, 8 1/2 by 11 inches + wxPAPER_ENV_9, // #9 Envelope, 3 7/8 by 8 7/8 inches + wxPAPER_ENV_10, // #10 Envelope, 4 1/8 by 9 1/2 inches + wxPAPER_ENV_11, // #11 Envelope, 4 1/2 by 10 3/8 inches + wxPAPER_ENV_12, // #12 Envelope, 4 3/4 by 11 inches + wxPAPER_ENV_14, // #14 Envelope, 5 by 11 1/2 inches + wxPAPER_ENV_DL, // DL Envelope, 110 by 220 millimeters + wxPAPER_ENV_C5, // C5 Envelope, 162 by 229 millimeters + wxPAPER_ENV_C3, // C3 Envelope, 324 by 458 millimeters + wxPAPER_ENV_C4, // C4 Envelope, 229 by 324 millimeters + wxPAPER_ENV_C6, // C6 Envelope, 114 by 162 millimeters + wxPAPER_ENV_C65, // C65 Envelope, 114 by 229 millimeters + wxPAPER_ENV_B4, // B4 Envelope, 250 by 353 millimeters + wxPAPER_ENV_B5, // B5 Envelope, 176 by 250 millimeters + wxPAPER_ENV_B6, // B6 Envelope, 176 by 125 millimeters + wxPAPER_ENV_ITALY, // Italy Envelope, 110 by 230 millimeters + wxPAPER_ENV_MONARCH, // Monarch Envelope, 3 7/8 by 7 1/2 inches + wxPAPER_ENV_PERSONAL, // 6 3/4 Envelope, 3 5/8 by 6 1/2 inches + wxPAPER_FANFOLD_US, // US Std Fanfold, 14 7/8 by 11 inches + wxPAPER_FANFOLD_STD_GERMAN, // German Std Fanfold, 8 1/2 by 12 inches + wxPAPER_FANFOLD_LGL_GERMAN, // German Legal Fanfold, 8 1/2 by 13 inches + + wxPAPER_ISO_B4, // B4 (ISO) 250 x 353 mm + wxPAPER_JAPANESE_POSTCARD, // Japanese Postcard 100 x 148 mm + wxPAPER_9X11, // 9 x 11 in + wxPAPER_10X11, // 10 x 11 in + wxPAPER_15X11, // 15 x 11 in + wxPAPER_ENV_INVITE, // Envelope Invite 220 x 220 mm + wxPAPER_LETTER_EXTRA, // Letter Extra 9 \275 x 12 in + wxPAPER_LEGAL_EXTRA, // Legal Extra 9 \275 x 15 in + wxPAPER_TABLOID_EXTRA, // Tabloid Extra 11.69 x 18 in + wxPAPER_A4_EXTRA, // A4 Extra 9.27 x 12.69 in + wxPAPER_LETTER_TRANSVERSE, // Letter Transverse 8 \275 x 11 in + wxPAPER_A4_TRANSVERSE, // A4 Transverse 210 x 297 mm + wxPAPER_LETTER_EXTRA_TRANSVERSE, // Letter Extra Transverse 9\275 x 12 in + wxPAPER_A_PLUS, // SuperA/SuperA/A4 227 x 356 mm + wxPAPER_B_PLUS, // SuperB/SuperB/A3 305 x 487 mm + wxPAPER_LETTER_PLUS, // Letter Plus 8.5 x 12.69 in + wxPAPER_A4_PLUS, // A4 Plus 210 x 330 mm + wxPAPER_A5_TRANSVERSE, // A5 Transverse 148 x 210 mm + wxPAPER_B5_TRANSVERSE, // B5 (JIS) Transverse 182 x 257 mm + wxPAPER_A3_EXTRA, // A3 Extra 322 x 445 mm + wxPAPER_A5_EXTRA, // A5 Extra 174 x 235 mm + wxPAPER_B5_EXTRA, // B5 (ISO) Extra 201 x 276 mm + wxPAPER_A2, // A2 420 x 594 mm + wxPAPER_A3_TRANSVERSE, // A3 Transverse 297 x 420 mm + wxPAPER_A3_EXTRA_TRANSVERSE // A3 Extra Transverse 322 x 445 mm + +} wxPaperSize ; + +/* Printing orientation */ +#ifndef wxPORTRAIT +#define wxPORTRAIT 1 +#define wxLANDSCAPE 2 +#endif + +/* Duplex printing modes + */ + +typedef enum { + wxDUPLEX_SIMPLEX, // Non-duplex + wxDUPLEX_HORIZONTAL, + wxDUPLEX_VERTICAL +} wxDuplexMode; + +/* Print quality. + */ + +#define wxPRINT_QUALITY_HIGH -1 +#define wxPRINT_QUALITY_MEDIUM -2 +#define wxPRINT_QUALITY_LOW -3 +#define wxPRINT_QUALITY_DRAFT -4 + +typedef int wxPrintQuality; + +/* Print mode (currently PostScript only) + */ + +typedef enum { + wxPRINT_MODE_NONE = 0, + wxPRINT_MODE_PREVIEW = 1, // Preview in external application + wxPRINT_MODE_FILE = 2, // Print to file + wxPRINT_MODE_PRINTER = 3 // Send to printer +} wxPrintMode; + + #ifdef __WXMSW__ /* Stand-ins for Windows types, to avoid * #including all of windows.h */ diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index 9b97b7d0f8..6cb9556039 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -69,6 +69,7 @@ public: inline wxSize(long xx, long yy) { x = xx; y = yy; } inline wxSize(const wxSize& sz) { x = sz.x; y = sz.y; } inline void operator = (const wxSize& sz) { x = sz.x; y = sz.y; } + inline bool operator == (const wxSize& sz) const { return (x == sz.x && y == sz.y); } inline wxSize operator + (const wxSize& sz) { return wxSize(x + sz.x, y + sz.y); } inline wxSize operator - (const wxSize& sz) { return wxSize(x - sz.x, y - sz.y); } inline void Set(long xx, long yy) { x = xx; y = yy; } @@ -88,6 +89,7 @@ class WXDLLEXPORT wxRealPoint inline wxRealPoint operator - (const wxRealPoint& pt) { return wxRealPoint(x - pt.x, y - pt.y); } inline void operator = (const wxRealPoint& pt) { x = pt.x; y = pt.y; } + inline bool operator == (const wxRealPoint& pt) const { return (x == pt.x && y == pt.y); } }; class WXDLLEXPORT wxPoint @@ -106,6 +108,7 @@ class WXDLLEXPORT wxPoint wxPoint(const wxPoint& pt) { x = pt.x; y = pt.y; }; inline void operator = (const wxPoint& pt) { x = pt.x; y = pt.y; } + inline bool operator == (const wxPoint& pt) const { return (x == pt.x && y == pt.y); } inline wxPoint operator + (const wxPoint& pt) { return wxPoint(x + pt.x, y + pt.y); } inline wxPoint operator - (const wxPoint& pt) { return wxPoint(x - pt.x, y - pt.y); } }; diff --git a/include/wx/generic/dcpsg.h b/include/wx/generic/dcpsg.h index 69ad11d1fb..78ab542bdf 100644 --- a/include/wx/generic/dcpsg.h +++ b/include/wx/generic/dcpsg.h @@ -21,6 +21,7 @@ #include "wx/dialog.h" #include "wx/module.h" +#include "wx/cmndata.h" #include @@ -41,14 +42,21 @@ class WXDLLEXPORT wxPostScriptDC: public wxDC public: wxPostScriptDC(); + + // Deprecated constructor wxPostScriptDC(const wxString& output, bool interactive = TRUE, wxWindow *parent = (wxWindow *) NULL); + // Recommended constructor + wxPostScriptDC(const wxPrintData& printData); + ~wxPostScriptDC(); + // Deprecated bool Create(const wxString& output, bool interactive = TRUE, wxWindow *parent = (wxWindow *) NULL); virtual bool Ok() const; + // Deprecated: use wxGenericPrintDialog instead virtual bool PrinterDialog(wxWindow *parent = (wxWindow *) NULL); virtual void BeginDrawing() {} @@ -112,7 +120,10 @@ public: wxFont *theFont = (wxFont *) NULL, bool use16 = FALSE); void GetSize(int* width, int* height) const; - void GetSizeMM(long *width, long *height) const; + void GetSizeMM(int *width, int *height) const; + + // Resolution in pixels per logical inch + wxSize GetPPI(void) const; void SetAxisOrientation( bool xLeftRight, bool yBottomUp ); void SetDeviceOrigin( long x, long y ); @@ -122,6 +133,9 @@ public: inline ofstream *GetStream(void) const { return m_pstream; } + inline wxPrintData& GetPrintData() { return m_printData; } + inline void SetPrintData(const wxPrintData& data) { m_printData = data; } + protected: ofstream * m_pstream; // PostScript output stream @@ -133,9 +147,10 @@ protected: bool m_clipping; double m_underlinePosition; double m_underlineThickness; + wxPrintData m_printData; }; -// TODO Needed? Should perhaps use wxGenericPrintDialog instead. +// Deprecated: should use wxGenericPrintDialog instead. #if 1 #define wxID_PRINTER_COMMAND 1 #define wxID_PRINTER_OPTIONS 2 @@ -166,89 +181,94 @@ enum { // Print Actions enum { - PS_PRINTER, + PS_NONE, + PS_PREVIEW, PS_FILE, - PS_PREVIEW + PS_PRINTER };// ps_action = PS_PREVIEW; // PostScript printer settings -WXDLLEXPORT void wxSetPrinterCommand(const char *cmd); -WXDLLEXPORT void wxSetPrintPreviewCommand(const char *cmd); -WXDLLEXPORT void wxSetPrinterOptions(const char *flags); +WXDLLEXPORT void wxSetPrinterCommand(const wxString& cmd); +WXDLLEXPORT void wxSetPrintPreviewCommand(const wxString& cmd); +WXDLLEXPORT void wxSetPrinterOptions(const wxString& flags); WXDLLEXPORT void wxSetPrinterOrientation(int orientation); WXDLLEXPORT void wxSetPrinterScaling(double x, double y); WXDLLEXPORT void wxSetPrinterTranslation(long x, long y); WXDLLEXPORT void wxSetPrinterMode(int mode); -WXDLLEXPORT void wxSetPrinterFile(const char *f); -WXDLLEXPORT void wxSetAFMPath(const char *f); +WXDLLEXPORT void wxSetPrinterFile(const wxString& f); +WXDLLEXPORT void wxSetAFMPath(const wxString& f); // Get current values -WXDLLEXPORT char* wxGetPrinterCommand(); -WXDLLEXPORT char* wxGetPrintPreviewCommand(); -WXDLLEXPORT char* wxGetPrinterOptions(); +WXDLLEXPORT wxString wxGetPrinterCommand(); +WXDLLEXPORT wxString wxGetPrintPreviewCommand(); +WXDLLEXPORT wxString wxGetPrinterOptions(); WXDLLEXPORT int wxGetPrinterOrientation(); WXDLLEXPORT void wxGetPrinterScaling(double* x, double* y); WXDLLEXPORT void wxGetPrinterTranslation(long *x, long *y); WXDLLEXPORT int wxGetPrinterMode(); -WXDLLEXPORT char* wxGetPrinterFile(); -WXDLLEXPORT char* wxGetAFMPath(); +WXDLLEXPORT wxString wxGetPrinterFile(); +WXDLLEXPORT wxString wxGetAFMPath(); /* - * PostScript print setup information + * PostScript print setup information. + * This is now obsolete, but retained for a while for compatibility */ class WXDLLEXPORT wxPrintSetupData: public wxObject { -public: - char *printerCommand; - char *previewCommand; - char *printerFlags; - char *printerFile; - int printerOrient; - double printerScaleX; - double printerScaleY; - long printerTranslateX; - long printerTranslateY; - // 1 = Preview, 2 = print to file, 3 = send to printer - int printerMode; - char *afmPath; - // A name in the paper database (see wx_print.h: the printing framework) - char *paperName; - bool printColour; - public: wxPrintSetupData(); ~wxPrintSetupData(); - void SetPrinterCommand(const char *cmd); - void SetPaperName(const char *paper); - void SetPrintPreviewCommand(const char *cmd); - void SetPrinterOptions(const char *flags); - void SetPrinterFile(const char *f); - void SetPrinterOrientation(int orient); - void SetPrinterScaling(double x, double y); - void SetPrinterTranslation(long x, long y); + void SetPrinterCommand(const wxString& cmd) { m_printerCommand = cmd; }; + void SetPaperName(const wxString& paper) { m_paperName = paper; }; + void SetPrintPreviewCommand(const wxString& cmd) { m_previewCommand = cmd; }; + void SetPrinterOptions(const wxString& flags) { m_printerFlags = flags; }; + void SetPrinterFile(const wxString& f) { m_printerFile = f; }; + void SetPrinterOrientation(int orient) { m_printerOrient = orient; }; + void SetPrinterScaling(double x, double y) { m_printerScaleX = x; m_printerScaleY = y; }; + void SetPrinterTranslation(long x, long y) { m_printerTranslateX = x; m_printerTranslateY = y; }; // 1 = Preview, 2 = print to file, 3 = send to printer - void SetPrinterMode(int mode); - void SetAFMPath(const char *f); - void SetColour(bool col); + void SetPrinterMode(int mode) { m_printerMode = mode; }; + void SetAFMPath(const wxString& f) { m_afmPath = f; }; + void SetColour(bool col) { m_printColour = col; }; // Get current values - char *GetPrinterCommand(); - char *GetPrintPreviewCommand(); - char *GetPrinterOptions(); - char *GetPrinterFile(); - char *GetPaperName(); - int GetPrinterOrientation(); - void GetPrinterScaling(double* x, double* y); - void GetPrinterTranslation(long *x, long *y); - int GetPrinterMode(); - char *GetAFMPath(); - bool GetColour(); + wxString GetPrinterCommand() const { return m_printerCommand; } ; + wxString GetPrintPreviewCommand() const { return m_previewCommand; } ; + wxString GetPrinterOptions() const { return m_printerFlags; }; + wxString GetPrinterFile() const { return m_printerFile; }; + wxString GetPaperName() const { return m_paperName; } + int GetPrinterOrientation() const { return m_printerOrient; }; + void GetPrinterScaling(double* x, double* y) const { *x = m_printerScaleX; *y = m_printerScaleY; }; + void GetPrinterTranslation(long *x, long *y) const { *x = m_printerTranslateX; *y = m_printerTranslateY; }; + int GetPrinterMode() const { return m_printerMode; }; + wxString GetAFMPath() const { return m_afmPath; }; + bool GetColour() const { return m_printColour; }; void operator=(wxPrintSetupData& data); -private: + // Initialize from a wxPrintData object (wxPrintData should now be used instead of wxPrintSetupData). + // There is also an operator for initializing a wxPrintData from a wxPrintSetupData. + void operator=(const wxPrintData& data); + +public: + wxString m_printerCommand; + wxString m_previewCommand; + wxString m_printerFlags; + wxString m_printerFile; + int m_printerOrient; + double m_printerScaleX; + double m_printerScaleY; + long m_printerTranslateX; + long m_printerTranslateY; + // 1 = Preview, 2 = print to file, 3 = send to printer + int m_printerMode; + wxString m_afmPath; + // A name in the paper database (see paper.h) + wxString m_paperName; + bool m_printColour; + DECLARE_DYNAMIC_CLASS(wxPrintSetupData) }; diff --git a/include/wx/generic/printps.h b/include/wx/generic/printps.h index 15213b91a0..8248fc7893 100644 --- a/include/wx/generic/printps.h +++ b/include/wx/generic/printps.h @@ -20,38 +20,38 @@ #include "wx/prntbase.h" /* - * Represents the printer: manages printing a wxPrintout object - */ - +* Represents the printer: manages printing a wxPrintout object +*/ + class WXDLLEXPORT wxPostScriptPrinter: public wxPrinterBase { - DECLARE_DYNAMIC_CLASS(wxPostScriptPrinter) - - public: - wxPostScriptPrinter(wxPrintData *data = (wxPrintData *) NULL); - ~wxPostScriptPrinter(void); - - virtual bool Print(wxWindow *parent, wxPrintout *printout, bool prompt = TRUE); - virtual bool PrintDialog(wxWindow *parent); - virtual bool Setup(wxWindow *parent); + DECLARE_DYNAMIC_CLASS(wxPostScriptPrinter) + +public: + wxPostScriptPrinter(wxPrintDialogData *data = (wxPrintDialogData *) NULL); + ~wxPostScriptPrinter(void); + + virtual bool Print(wxWindow *parent, wxPrintout *printout, bool prompt = TRUE); + virtual wxDC* PrintDialog(wxWindow *parent); + virtual bool Setup(wxWindow *parent); }; /* - * wxPrintPreview - * Programmer creates an object of this class to preview a wxPrintout. - */ - +* wxPrintPreview +* Programmer creates an object of this class to preview a wxPrintout. +*/ + class WXDLLEXPORT wxPostScriptPrintPreview: public wxPrintPreviewBase { - DECLARE_CLASS(wxPostScriptPrintPreview) - - public: - wxPostScriptPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting = (wxPrintout *) NULL, wxPrintData *data = (wxPrintData *) NULL); - ~wxPostScriptPrintPreview(void); - - virtual bool Print(bool interactive); - virtual void DetermineScaling(void); + DECLARE_CLASS(wxPostScriptPrintPreview) + +public: + wxPostScriptPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting = (wxPrintout *) NULL, wxPrintDialogData *data = (wxPrintDialogData *) NULL); + ~wxPostScriptPrintPreview(void); + + virtual bool Print(bool interactive); + virtual void DetermineScaling(void); }; #endif - // __PRINTPSH__ +// __PRINTPSH__ diff --git a/include/wx/generic/prntdlgg.h b/include/wx/generic/prntdlgg.h index be7cf5c5e4..67889251f7 100644 --- a/include/wx/generic/prntdlgg.h +++ b/include/wx/generic/prntdlgg.h @@ -36,9 +36,9 @@ class WXDLLEXPORT wxRadioBox; class WXDLLEXPORT wxPrintSetupData; /* - * Simulated Print and Print Setup dialogs - * for non-Windows platforms (and Windows using PostScript print/preview) - */ +* Simulated Print and Print Setup dialogs +* for non-Windows platforms (and Windows using PostScript print/preview) +*/ #define wxPRINTID_STATIC 10 #define wxPRINTID_RANGE 11 @@ -50,36 +50,39 @@ class WXDLLEXPORT wxPrintSetupData; class WXDLLEXPORT wxGenericPrintDialog: public wxDialog { - DECLARE_DYNAMIC_CLASS(wxGenericPrintDialog) - - public: - wxStaticText *printerMessage; - wxButton *setupButton; - wxButton *helpButton; - wxRadioBox *rangeRadioBox; - wxTextCtrl *fromText; - wxTextCtrl *toText; - wxTextCtrl *noCopiesText; - wxCheckBox *printToFileCheckBox; - wxCheckBox *collateCopiesCheckBox; - - wxPrintData printData; - wxGenericPrintDialog(wxWindow *parent, wxPrintData* data); - ~wxGenericPrintDialog(void); - - void OnSetup(wxCommandEvent& event); - void OnRange(wxCommandEvent& event); - void OnOK(wxCommandEvent& event); - - virtual bool TransferDataFromWindow(void); - virtual bool TransferDataToWindow(void); - - virtual int ShowModal(void); - - inline wxPrintData& GetPrintData(void) { return printData; } - wxDC *GetPrintDC(void); - -DECLARE_EVENT_TABLE() + DECLARE_DYNAMIC_CLASS(wxGenericPrintDialog) + +public: + wxGenericPrintDialog(wxWindow *parent, wxPrintDialogData* data = (wxPrintDialogData*) NULL); + ~wxGenericPrintDialog(); + + void OnSetup(wxCommandEvent& event); + void OnRange(wxCommandEvent& event); + void OnOK(wxCommandEvent& event); + + virtual bool TransferDataFromWindow(); + virtual bool TransferDataToWindow(); + + virtual int ShowModal(); + + inline wxPrintDialogData& GetPrintDialogData() { return m_printDialogData; } + wxDC *GetPrintDC(); + +public: + wxStaticText* m_printerMessage; + wxButton* m_setupButton; + wxButton* m_helpButton; + wxRadioBox* m_rangeRadioBox; + wxTextCtrl* m_fromText; + wxTextCtrl* m_toText; + wxTextCtrl* m_noCopiesText; + wxCheckBox* m_printToFileCheckBox; + wxCheckBox* m_collateCopiesCheckBox; + + wxPrintDialogData m_printDialogData; + + + DECLARE_EVENT_TABLE() }; #define wxPRINTID_PRINTCOLOUR 10 @@ -90,27 +93,34 @@ DECLARE_EVENT_TABLE() class WXDLLEXPORT wxGenericPrintSetupDialog: public wxDialog { - DECLARE_CLASS(wxGenericPrintSetupDialog) - - public: - wxRadioBox *orientationRadioBox; - wxTextCtrl *printerCommandText; - wxTextCtrl *printerOptionsText; - wxCheckBox *colourCheckBox; - wxChoice *paperTypeChoice; - + DECLARE_CLASS(wxGenericPrintSetupDialog) + +public: + // There are no configuration options for the dialog, so we + // just pass the wxPrintData object (no wxPrintSetupDialogData class needed) + wxGenericPrintSetupDialog(wxWindow *parent, wxPrintData* data); + wxGenericPrintSetupDialog(wxWindow *parent, wxPrintSetupData* data); + ~wxGenericPrintSetupDialog(); + + void Init(wxPrintData* data); + + virtual bool TransferDataFromWindow(); + virtual bool TransferDataToWindow(); + + wxChoice *CreatePaperTypeChoice(int* x, int* y); + +public: + wxRadioBox* m_orientationRadioBox; + wxTextCtrl* m_printerCommandText; + wxTextCtrl* m_printerOptionsText; + wxCheckBox* m_colourCheckBox; + wxChoice* m_paperTypeChoice; + #if wxUSE_POSTSCRIPT - wxPrintSetupData printData; - inline wxPrintSetupData& GetPrintData(void) { return printData; } + wxPrintData m_printData; + inline wxPrintData& GetPrintData() { return m_printData; } #endif - - wxGenericPrintSetupDialog(wxWindow *parent, wxPrintSetupData* data); - ~wxGenericPrintSetupDialog(void); - - virtual bool TransferDataFromWindow(void); - virtual bool TransferDataToWindow(void); - - wxChoice *CreatePaperTypeChoice(int* x, int* y); + }; #define wxPRINTID_LEFTMARGIN 30 @@ -120,34 +130,35 @@ class WXDLLEXPORT wxGenericPrintSetupDialog: public wxDialog class WXDLLEXPORT wxGenericPageSetupDialog: public wxDialog { - DECLARE_CLASS(wxGenericPageSetupDialog) - - public: - wxButton *printerButton; - wxRadioBox *orientationRadioBox; - wxTextCtrl *marginLeftText; - wxTextCtrl *marginTopText; - wxTextCtrl *marginRightText; - wxTextCtrl *marginBottomText; - wxChoice *paperTypeChoice; - - static bool pageSetupDialogCancelled; - - wxPageSetupData pageData; - - wxGenericPageSetupDialog(wxWindow *parent, wxPageSetupData* data = (wxPageSetupData*) NULL); - ~wxGenericPageSetupDialog(void); - - virtual bool TransferDataFromWindow(void); - virtual bool TransferDataToWindow(void); - - void OnPrinter(wxCommandEvent& event); - - wxChoice *CreatePaperTypeChoice(int* x, int* y); - inline wxPageSetupData& GetPageSetupData(void) { return pageData; } - -DECLARE_EVENT_TABLE() + DECLARE_CLASS(wxGenericPageSetupDialog) + +public: + wxGenericPageSetupDialog(wxWindow *parent, wxPageSetupData* data = (wxPageSetupData*) NULL); + ~wxGenericPageSetupDialog(); + + virtual bool TransferDataFromWindow(); + virtual bool TransferDataToWindow(); + + void OnPrinter(wxCommandEvent& event); + + wxChoice *CreatePaperTypeChoice(int* x, int* y); + inline wxPageSetupData& GetPageSetupData() { return m_pageData; } + +public: + wxButton* m_printerButton; + wxRadioBox* m_orientationRadioBox; + wxTextCtrl* m_marginLeftText; + wxTextCtrl* m_marginTopText; + wxTextCtrl* m_marginRightText; + wxTextCtrl* m_marginBottomText; + wxChoice* m_paperTypeChoice; + + static bool m_pageSetupDialogCancelled; + + wxPageSetupData m_pageData; + + DECLARE_EVENT_TABLE() }; #endif - // __PRINTDLGH_G__ +// __PRINTDLGH_G__ diff --git a/include/wx/gtk/dc.h b/include/wx/gtk/dc.h index 7f4503fb6e..581fc16482 100644 --- a/include/wx/gtk/dc.h +++ b/include/wx/gtk/dc.h @@ -225,9 +225,16 @@ public: virtual long MinY() const { return m_minY; } virtual long MaxY() const { return m_maxY; } + // Size in device units virtual void GetSize( int* width, int* height ) const; inline wxSize GetSize(void) const { int w, h; GetSize(&w, &h); return wxSize(w, h); } - virtual void GetSizeMM( long* width, long* height ) const; + + // Size in millimetres + virtual void GetSizeMM( int* width, int* height ) const; + inline wxSize GetSizeMM(void) const { int w, h; GetSizeMM(&w, &h); return wxSize(w, h); } + + // Resolution in pixels per logical inch + virtual wxSize GetPPI(void) const; virtual bool StartDoc( const wxString& WXUNUSED(message) ) { return TRUE; } virtual void EndDoc() {} @@ -339,7 +346,6 @@ public: bool m_autoSetting; // wxMSW only ? bool m_dontDelete; // wxMSW only ? bool m_optimize; // wxMSW only ? - wxString m_filename; // Not sure where this belongs. wxPen m_pen; wxBrush m_brush; diff --git a/include/wx/gtk/dcclient.h b/include/wx/gtk/dcclient.h index eb2ed88ec7..ae99362c13 100644 --- a/include/wx/gtk/dcclient.h +++ b/include/wx/gtk/dcclient.h @@ -92,6 +92,9 @@ public: virtual void DrawSpline( wxList *points ); + // Resolution in pixels per logical inch + wxSize GetPPI(void) const; + // implementation GdkWindow *m_window; diff --git a/include/wx/gtk1/dc.h b/include/wx/gtk1/dc.h index 7f4503fb6e..581fc16482 100644 --- a/include/wx/gtk1/dc.h +++ b/include/wx/gtk1/dc.h @@ -225,9 +225,16 @@ public: virtual long MinY() const { return m_minY; } virtual long MaxY() const { return m_maxY; } + // Size in device units virtual void GetSize( int* width, int* height ) const; inline wxSize GetSize(void) const { int w, h; GetSize(&w, &h); return wxSize(w, h); } - virtual void GetSizeMM( long* width, long* height ) const; + + // Size in millimetres + virtual void GetSizeMM( int* width, int* height ) const; + inline wxSize GetSizeMM(void) const { int w, h; GetSizeMM(&w, &h); return wxSize(w, h); } + + // Resolution in pixels per logical inch + virtual wxSize GetPPI(void) const; virtual bool StartDoc( const wxString& WXUNUSED(message) ) { return TRUE; } virtual void EndDoc() {} @@ -339,7 +346,6 @@ public: bool m_autoSetting; // wxMSW only ? bool m_dontDelete; // wxMSW only ? bool m_optimize; // wxMSW only ? - wxString m_filename; // Not sure where this belongs. wxPen m_pen; wxBrush m_brush; diff --git a/include/wx/gtk1/dcclient.h b/include/wx/gtk1/dcclient.h index eb2ed88ec7..ae99362c13 100644 --- a/include/wx/gtk1/dcclient.h +++ b/include/wx/gtk1/dcclient.h @@ -92,6 +92,9 @@ public: virtual void DrawSpline( wxList *points ); + // Resolution in pixels per logical inch + wxSize GetPPI(void) const; + // implementation GdkWindow *m_window; diff --git a/include/wx/motif/dc.h b/include/wx/motif/dc.h index 35842b1095..06abfad626 100644 --- a/include/wx/motif/dc.h +++ b/include/wx/motif/dc.h @@ -211,10 +211,17 @@ class WXDLLEXPORT wxDC: public wxObject virtual inline long MinY(void) const { return m_minY; } virtual inline long MaxY(void) const { return m_maxY; } + // Size in device units virtual void GetSize( int* width, int* height ) const; inline wxSize GetSize(void) const { int w, h; GetSize(&w, &h); return wxSize(w, h); } - virtual void GetSizeMM( long* width, long* height ) const; - + + // Size in millimetres + virtual void GetSizeMM( int* width, int* height ) const; + inline wxSize GetSizeMM(void) const { int w, h; GetSizeMM(&w, &h); return wxSize(w, h); } + + // Resolution in pixels per logical inch + wxSize GetPPI(void) const ; + virtual bool StartDoc( const wxString& WXUNUSED(message) ) { return TRUE; }; virtual void EndDoc(void) {}; virtual void StartPage(void) {}; @@ -342,8 +349,7 @@ class WXDLLEXPORT wxDC: public wxObject bool m_clipping; // Is clipping on right now ? bool m_optimize; // wxMSW only ? bool m_isInteractive; // For wxPostScriptDC - wxString m_filename; // Ditto - + wxPen m_pen; wxBrush m_brush; wxBrush m_backgroundBrush; diff --git a/include/wx/motif/dcclient.h b/include/wx/motif/dcclient.h index 7ea3f30681..dda2341ae1 100644 --- a/include/wx/motif/dcclient.h +++ b/include/wx/motif/dcclient.h @@ -172,6 +172,9 @@ class WXDLLEXPORT wxWindowDC: public wxDC virtual void DrawSpline( int n, wxPoint points[] ) { wxDC::DrawSpline(n, points); } + // Resolution in pixels per logical inch + wxSize GetPPI(void) const; + // Motif-specific void SetDCClipping (); // Helper function for setting clipping diff --git a/include/wx/motif/setup.h b/include/wx/motif/setup.h index aa93ec059a..8fe235aafe 100644 --- a/include/wx/motif/setup.h +++ b/include/wx/motif/setup.h @@ -68,7 +68,7 @@ /* * Use Threads */ -#define wxUSE_THREADS 1 +#define wxUSE_THREADS 0 /* * Have glibc2 */ @@ -78,6 +78,8 @@ */ #define wxHAVE_LIB_XPM 0 +#define wxUSE_XPM 1 + /* ------------------------------------------------------------------------ */ /* GUI control options (always enabled in wxGTK) */ /* ------------------------------------------------------------------------ */ @@ -199,11 +201,11 @@ /* * Use tooltips */ -#define wxUSE_TOOLTIPS 1 +#define wxUSE_TOOLTIPS 0 /* * Use dnd */ -#define wxUSE_DRAG_AND_DROP 1 +#define wxUSE_DRAG_AND_DROP 0 /* * Use wxLibrary class */ @@ -387,7 +389,7 @@ /* #undef HAVE_DOPRNT */ /* Define if you have sched.h */ -#define HAVE_SCHED_H 1 +#define HAVE_SCHED_H 0 /* Define if you have strings.h */ #define HAVE_STRINGS_H 1 @@ -405,10 +407,10 @@ #define HAVE_VSNPRINTF 1 /* Define if you have usleep() */ -/* #undef HAVE_USLEEP */ +#define HAVE_USLEEP 1 /* Define if you have nanosleep() */ -#define HAVE_NANOSLEEP 1 +#define HAVE_NANOSLEEP 0 /* Define if you have vfork() */ #define HAVE_VFORK 1 diff --git a/include/wx/msw/dc.h b/include/wx/msw/dc.h index 29a3ca1acb..07d81cb653 100644 --- a/include/wx/msw/dc.h +++ b/include/wx/msw/dc.h @@ -199,10 +199,14 @@ public: // Size in device units virtual void GetSize(int* width, int* height) const; - inline wxSize GetSize(void) const { int w, h; GetSize(&w, &h); return wxSize(w, h); } + inline wxSize GetSize() const { int w, h; GetSize(&w, &h); return wxSize(w, h); } // Size in mm - virtual void GetSizeMM(long* width, long* height) const ; + virtual void GetSizeMM(int* width, int* height) const ; + inline wxSize GetSizeMM() const { int w, h; GetSizeMM(&w, &h); return wxSize(w, h); } + + // Resolution in Pixels per inch + virtual wxSize GetPPI(void) const ; // Compatibility #if WXWIN_COMPATIBILITY @@ -351,7 +355,6 @@ protected: wxWindow * m_canvas; wxBitmap m_selectedBitmap; - wxString m_filename; // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it bool m_bOwnsDC; diff --git a/include/wx/msw/dcprint.h b/include/wx/msw/dcprint.h index 8ad3c3574b..3dcf523f55 100644 --- a/include/wx/msw/dcprint.h +++ b/include/wx/msw/dcprint.h @@ -17,21 +17,37 @@ #endif #include "wx/dc.h" +#include "wx/cmndata.h" class WXDLLEXPORT wxPrinterDC: public wxDC { - public: - DECLARE_CLASS(wxPrinterDC) +public: +DECLARE_CLASS(wxPrinterDC) - // Create a printer DC - wxPrinterDC(const wxString& driver, const wxString& device, const wxString& output, bool interactive = TRUE, int orientation = wxPORTRAIT); - wxPrinterDC(WXHDC theDC); + // Create a printer DC (obsolete function: use wxPrintData version now) + wxPrinterDC(const wxString& driver, const wxString& device, const wxString& output, bool interactive = TRUE, int orientation = wxPORTRAIT); - ~wxPrinterDC(void); + // Create from print data + wxPrinterDC(const wxPrintData& data); + + wxPrinterDC(WXHDC theDC); + + ~wxPrinterDC(void); + + bool StartDoc(const wxString& message); + void EndDoc(void); + void StartPage(void); + void EndPage(void); + +protected: + wxPrintData m_printData; }; // Gets an HDC for the default printer configuration -WXHDC WXDLLEXPORT wxGetPrinterDC(int orientation); +// WXHDC WXDLLEXPORT wxGetPrinterDC(int orientation); + +// Gets an HDC for the specified printer configuration +WXHDC WXDLLEXPORT wxGetPrinterDC(const wxPrintData& data); #endif // _WX_DCPRINT_H_ diff --git a/include/wx/msw/printdlg.h b/include/wx/msw/printdlg.h index cf14ef75b0..655a1ad3d6 100644 --- a/include/wx/msw/printdlg.h +++ b/include/wx/msw/printdlg.h @@ -29,24 +29,23 @@ class WXDLLEXPORT wxPrintDialog: public wxDialog { DECLARE_DYNAMIC_CLASS(wxPrintDialog) - private: - wxPrintData printData; - wxDC *printerDC; - bool destroyDC; - char *deviceName; - char *driverName; - char *portName; - wxWindow *dialogParent; - public: +public: wxPrintDialog(void); - wxPrintDialog(wxWindow *parent, wxPrintData* data = NULL); + wxPrintDialog(wxWindow *parent, wxPrintDialogData* data = NULL); ~wxPrintDialog(void); - bool Create(wxWindow *parent, wxPrintData* data = NULL); + bool Create(wxWindow *parent, wxPrintDialogData* data = NULL); virtual int ShowModal(void); - inline wxPrintData& GetPrintData(void) { return printData; } + inline wxPrintDialogData& GetPrintDialogData(void) { return m_printDialogData; } + inline wxPrintData& GetPrintData(void) { return m_printDialogData.GetPrintData(); } virtual wxDC *GetPrintDC(void); + +private: + wxPrintDialogData m_printDialogData; + wxDC* m_printerDC; + bool m_destroyDC; + wxWindow* m_dialogParent; }; class WXDLLEXPORT wxPageSetupDialog: public wxDialog diff --git a/include/wx/msw/printwin.h b/include/wx/msw/printwin.h index 2f92fa3ca9..00abaf710d 100644 --- a/include/wx/msw/printwin.h +++ b/include/wx/msw/printwin.h @@ -27,11 +27,11 @@ class WXDLLEXPORT wxWindowsPrinter: public wxPrinterBase DECLARE_DYNAMIC_CLASS(wxWindowsPrinter) public: - wxWindowsPrinter(wxPrintData *data = NULL); + wxWindowsPrinter(wxPrintDialogData *data = NULL); ~wxWindowsPrinter(void); virtual bool Print(wxWindow *parent, wxPrintout *printout, bool prompt = TRUE); - virtual bool PrintDialog(wxWindow *parent); + virtual wxDC* PrintDialog(wxWindow *parent); virtual bool Setup(wxWindow *parent); private: @@ -48,7 +48,7 @@ class WXDLLEXPORT wxWindowsPrintPreview: public wxPrintPreviewBase DECLARE_CLASS(wxWindowsPrintPreview) public: - wxWindowsPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting = NULL, wxPrintData *data = NULL); + wxWindowsPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting = NULL, wxPrintDialogData *data = NULL); ~wxWindowsPrintPreview(void); virtual bool Print(bool interactive); diff --git a/include/wx/prntbase.h b/include/wx/prntbase.h index 6861da9218..4d8699eca1 100644 --- a/include/wx/prntbase.h +++ b/include/wx/prntbase.h @@ -44,12 +44,12 @@ class WXDLLEXPORT wxPrinterBase: public wxObject DECLARE_CLASS(wxPrinterBase) public: - wxPrinterBase(wxPrintData *data = (wxPrintData *) NULL); + wxPrinterBase(wxPrintDialogData *data = (wxPrintDialogData *) NULL); ~wxPrinterBase(); virtual wxWindow *CreateAbortWindow(wxWindow *parent, wxPrintout *printout); virtual void ReportError(wxWindow *parent, wxPrintout *printout, char *message); - inline wxPrintData& GetPrintData() const { return (wxPrintData&) m_printData; }; + inline wxPrintDialogData& GetPrintDialogData() const { return (wxPrintDialogData&) m_printDialogData; }; inline bool GetAbort() const { return sm_abortIt; } /////////////////////////////////////////////////////////////////////////// @@ -57,10 +57,10 @@ public: virtual bool Setup(wxWindow *parent) = 0; virtual bool Print(wxWindow *parent, wxPrintout *printout, bool prompt = TRUE) = 0; - virtual bool PrintDialog(wxWindow *parent) = 0; + virtual wxDC* PrintDialog(wxWindow *parent) = 0; protected: - wxPrintData m_printData; + wxPrintDialogData m_printDialogData; wxPrintout* m_currentPrintout; public: static wxWindow* sm_abortWindow; @@ -251,7 +251,7 @@ class WXDLLEXPORT wxPrintPreviewBase: public wxObject DECLARE_CLASS(wxPrintPreviewBase) public: - wxPrintPreviewBase(wxPrintout *printout, wxPrintout *printoutForPrinting = (wxPrintout *) NULL, wxPrintData *data = (wxPrintData *) NULL); + wxPrintPreviewBase(wxPrintout *printout, wxPrintout *printoutForPrinting = (wxPrintout *) NULL, wxPrintDialogData *data = (wxPrintDialogData *) NULL); ~wxPrintPreviewBase(); virtual bool SetCurrentPage(int pageNum); @@ -277,7 +277,7 @@ public: // a wxMemoryDC. virtual bool RenderPage(int pageNum); - inline wxPrintData& GetPrintData() { return m_printData; } + inline wxPrintDialogData& GetPrintDialogData() { return m_printDialogData; } virtual void SetZoom(int percent); inline int GetZoom() const { return m_currentZoom; }; @@ -302,7 +302,7 @@ public: virtual void DetermineScaling() = 0; protected: - wxPrintData m_printData; + wxPrintDialogData m_printDialogData; wxWindow* m_previewCanvas; wxFrame* m_previewFrame; wxBitmap* m_previewBitmap; @@ -340,47 +340,5 @@ public: DECLARE_EVENT_TABLE() }; -/* - * Again, this only really needed for non-Windows platforms - * or if you want to test the PostScript printing under Windows, - * or if you're using the generic page setup dialog under e.g. Win16. - */ - -class WXDLLEXPORT wxPrintPaperType: public wxObject -{ -public: - wxPrintPaperType(const char *name = (const char *) NULL, int wmm = 0, int hmm = 0, int wp = 0, int hp = 0); - ~wxPrintPaperType(); - -public: - int widthMM; - int heightMM; - int widthPixels; - int heightPixels; - char *pageName; - -private: - DECLARE_DYNAMIC_CLASS(wxPrintPaperType) -}; - -class WXDLLEXPORT wxPrintPaperDatabase: public wxList -{ -public: - wxPrintPaperDatabase(); - ~wxPrintPaperDatabase(); - - void CreateDatabase(); - void ClearDatabase(); - - void AddPaperType(const char *name, int wmm, int hmm, int wp, int hp); - wxPrintPaperType *FindPaperType(const char *name); - -private: - DECLARE_DYNAMIC_CLASS(wxPrintPaperDatabase) -}; - -WXDLLEXPORT_DATA(extern wxPrintPaperDatabase*) wxThePrintPaperDatabase; - - #endif // _WX_PRNTBASEH__ diff --git a/samples/printing/printing.cpp b/samples/printing/printing.cpp index 2deb53b0fd..f76894eb4f 100644 --- a/samples/printing/printing.cpp +++ b/samples/printing/printing.cpp @@ -1,11 +1,11 @@ /* - * File: printing.cc - * Purpose: Printing demo for wxWindows class library - * Author: Julian Smart - * Created: 1995 - * Updated: - * Copyright: (c) 1995, AIAI, University of Edinburgh - */ +* File: printing.cc +* Purpose: Printing demo for wxWindows class library +* Author: Julian Smart +* Created: 1995 +* Updated: +* Copyright: (c) 1995, AIAI, University of Edinburgh +*/ /* static const char sccsid[] = "%W% %G%"; */ @@ -52,7 +52,13 @@ // Declare a frame MyFrame *frame = (MyFrame *) NULL; -int orientation = wxPORTRAIT; +// int orientation = wxPORTRAIT; + +// Global print data, to remember settings during the session +wxPrintData *g_printData = (wxPrintData*) NULL ; + +// Global page setup data +wxPageSetupData* g_pageSetupData = (wxPageSetupData*) NULL; // Main proc IMPLEMENT_APP(MyApp) @@ -68,25 +74,36 @@ MyApp::MyApp() // main frame bool MyApp::OnInit(void) { - m_testFont = new wxFont(10, wxSWISS, wxNORMAL, wxNORMAL); - - // Create the main frame window - frame = new MyFrame((wxFrame *) NULL, (char *) "wxWindows Printing Demo", wxPoint(0, 0), wxSize(400, 400)); - - // Give it a status line - frame->CreateStatusBar(2); - - // Load icon and bitmap - frame->SetIcon( wxICON( mondrian) ); - - // Make a menubar - wxMenu *file_menu = new wxMenu; + m_testFont = new wxFont(10, wxSWISS, wxNORMAL, wxNORMAL); + + g_printData = new wxPrintData; + g_pageSetupData = new wxPageSetupDialogData; - file_menu->Append(WXPRINT_PRINT, "&Print...", "Print"); - file_menu->Append(WXPRINT_PRINT_SETUP, "Print &Setup...", "Setup printer properties"); - file_menu->Append(WXPRINT_PAGE_SETUP, "Page Set&up...", "Page setup"); - file_menu->Append(WXPRINT_PREVIEW, "Print Pre&view", "Preview"); + // Compatibility with old system. In fact, we might keep wxThePrintSetupData + // just for useful default values which we can optionally assign to our + // own print data object. +#if defined(__WXGTK__) || defined(__WXMOTIF__) + (*g_printData) = * wxThePrintSetupData; +#endif + + // Create the main frame window + frame = new MyFrame((wxFrame *) NULL, (char *) "wxWindows Printing Demo", wxPoint(0, 0), wxSize(400, 400)); + + // Give it a status line + frame->CreateStatusBar(2); + + // Load icon and bitmap + frame->SetIcon( wxICON( mondrian) ); + + // Make a menubar + wxMenu *file_menu = new wxMenu; + + file_menu->Append(WXPRINT_PRINT, "&Print...", "Print"); + file_menu->Append(WXPRINT_PRINT_SETUP, "Print &Setup...", "Setup printer properties"); + file_menu->Append(WXPRINT_PAGE_SETUP, "Page Set&up...", "Page setup"); + file_menu->Append(WXPRINT_PREVIEW, "Print Pre&view", "Preview"); + // Accelerators wxAcceleratorEntry entries[1]; entries[0].Set(wxACCEL_CTRL, (int) 'V', WXPRINT_PREVIEW); @@ -94,204 +111,206 @@ bool MyApp::OnInit(void) frame->SetAcceleratorTable(accel); #if defined(__WXMSW__) && wxTEST_POSTSCRIPT_IN_MSW - file_menu->AppendSeparator(); - file_menu->Append(WXPRINT_PRINT_PS, "Print PostScript...", "Print (PostScript)"); - file_menu->Append(WXPRINT_PRINT_SETUP_PS, "Print Setup PostScript...", "Setup printer properties (PostScript)"); - file_menu->Append(WXPRINT_PAGE_SETUP_PS, "Page Setup PostScript...", "Page setup (PostScript)"); - file_menu->Append(WXPRINT_PREVIEW_PS, "Print Preview PostScript", "Preview (PostScript)"); + file_menu->AppendSeparator(); + file_menu->Append(WXPRINT_PRINT_PS, "Print PostScript...", "Print (PostScript)"); + file_menu->Append(WXPRINT_PRINT_SETUP_PS, "Print Setup PostScript...", "Setup printer properties (PostScript)"); + file_menu->Append(WXPRINT_PAGE_SETUP_PS, "Page Setup PostScript...", "Page setup (PostScript)"); + file_menu->Append(WXPRINT_PREVIEW_PS, "Print Preview PostScript", "Preview (PostScript)"); #endif - file_menu->AppendSeparator(); - file_menu->Append(WXPRINT_QUIT, "E&xit", "Exit program"); - - wxMenu *help_menu = new wxMenu; - help_menu->Append(WXPRINT_ABOUT, "&About", "About this demo"); - - wxMenuBar *menu_bar = new wxMenuBar; - - menu_bar->Append(file_menu, "&File"); - menu_bar->Append(help_menu, "&Help"); - - // Associate the menu bar with the frame - frame->SetMenuBar(menu_bar); - - MyCanvas *canvas = new MyCanvas(frame, wxPoint(0, 0), wxSize(100, 100), wxRETAINED|wxHSCROLL|wxVSCROLL); - - // Give it scrollbars: the virtual canvas is 20 * 50 = 1000 pixels in each direction - canvas->SetScrollbars(20, 20, 50, 50); - - frame->canvas = canvas; - - frame->Centre(wxBOTH); - frame->Show(TRUE); - - frame->SetStatusText("Printing demo"); - - SetTopWindow(frame); - - return TRUE; + file_menu->AppendSeparator(); + file_menu->Append(WXPRINT_QUIT, "E&xit", "Exit program"); + + wxMenu *help_menu = new wxMenu; + help_menu->Append(WXPRINT_ABOUT, "&About", "About this demo"); + + wxMenuBar *menu_bar = new wxMenuBar; + + menu_bar->Append(file_menu, "&File"); + menu_bar->Append(help_menu, "&Help"); + + // Associate the menu bar with the frame + frame->SetMenuBar(menu_bar); + + MyCanvas *canvas = new MyCanvas(frame, wxPoint(0, 0), wxSize(100, 100), wxRETAINED|wxHSCROLL|wxVSCROLL); + + // Give it scrollbars: the virtual canvas is 20 * 50 = 1000 pixels in each direction + canvas->SetScrollbars(20, 20, 50, 50); + + frame->canvas = canvas; + + frame->Centre(wxBOTH); + frame->Show(TRUE); + + frame->SetStatusText("Printing demo"); + + SetTopWindow(frame); + + return TRUE; } int MyApp::OnExit() { - delete wxGetApp().m_testFont; - return 1; + delete wxGetApp().m_testFont; + delete g_printData; + delete g_pageSetupData; + return 1; } BEGIN_EVENT_TABLE(MyFrame, wxFrame) - EVT_MENU(WXPRINT_QUIT, MyFrame::OnExit) - EVT_MENU(WXPRINT_PRINT, MyFrame::OnPrint) - EVT_MENU(WXPRINT_PREVIEW, MyFrame::OnPrintPreview) - EVT_MENU(WXPRINT_PRINT_SETUP, MyFrame::OnPrintSetup) - EVT_MENU(WXPRINT_PAGE_SETUP, MyFrame::OnPageSetup) - EVT_MENU(WXPRINT_ABOUT, MyFrame::OnPrintAbout) +EVT_MENU(WXPRINT_QUIT, MyFrame::OnExit) +EVT_MENU(WXPRINT_PRINT, MyFrame::OnPrint) +EVT_MENU(WXPRINT_PREVIEW, MyFrame::OnPrintPreview) +EVT_MENU(WXPRINT_PRINT_SETUP, MyFrame::OnPrintSetup) +EVT_MENU(WXPRINT_PAGE_SETUP, MyFrame::OnPageSetup) +EVT_MENU(WXPRINT_ABOUT, MyFrame::OnPrintAbout) #if defined(__WXMSW__) && wxTEST_POSTSCRIPT_IN_MSW - EVT_MENU(WXPRINT_PRINT_PS, MyFrame::OnPrintPS) - EVT_MENU(WXPRINT_PREVIEW_PS, MyFrame::OnPrintPreviewPS) - EVT_MENU(WXPRINT_PRINT_SETUP_PS, MyFrame::OnPrintSetupPS) - EVT_MENU(WXPRINT_PAGE_SETUP_PS, MyFrame::OnPageSetupPS) +EVT_MENU(WXPRINT_PRINT_PS, MyFrame::OnPrintPS) +EVT_MENU(WXPRINT_PREVIEW_PS, MyFrame::OnPrintPreviewPS) +EVT_MENU(WXPRINT_PRINT_SETUP_PS, MyFrame::OnPrintSetupPS) +EVT_MENU(WXPRINT_PAGE_SETUP_PS, MyFrame::OnPageSetupPS) #endif END_EVENT_TABLE() // Define my frame constructor MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size): - wxFrame(frame, -1, title, pos, size) +wxFrame(frame, -1, title, pos, size) { - canvas = (MyCanvas *) NULL; + canvas = (MyCanvas *) NULL; } void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event)) { - Close(TRUE); + Close(TRUE); } void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event)) { - wxPrinter printer; - MyPrintout printout("My printout"); - if (!printer.Print(this, &printout, TRUE)) + wxPrintDialogData printDialogData(* g_printData); + + wxPrinter printer(& printDialogData); + MyPrintout printout("My printout"); + if (!printer.Print(this, &printout, TRUE)) wxMessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wxOK); + else + { + (*g_printData) = printer.GetPrintDialogData().GetPrintData(); + } } void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event)) { - wxPrintData printData; - printData.SetOrientation(orientation); - - // Pass two printout objects: for preview, and possible printing. - wxPrintPreview *preview = new wxPrintPreview(new MyPrintout, new MyPrintout, & printData); - if (!preview->Ok()) - { + // Pass two printout objects: for preview, and possible printing. + wxPrintDialogData printDialogData(* g_printData); + wxPrintPreview *preview = new wxPrintPreview(new MyPrintout, new MyPrintout, & printDialogData); + if (!preview->Ok()) + { delete preview; wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK); return; - } - - wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650)); - frame->Centre(wxBOTH); - frame->Initialize(); - frame->Show(TRUE); + } + + wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650)); + frame->Centre(wxBOTH); + frame->Initialize(); + frame->Show(TRUE); } void MyFrame::OnPrintSetup(wxCommandEvent& WXUNUSED(event)) { - wxPrintData data; - data.SetOrientation(orientation); - - wxPrintDialog printerDialog(this, & data); - - printerDialog.GetPrintData().SetSetupDialog(TRUE); - printerDialog.ShowModal(); + wxPrintDialogData printDialogData(* g_printData); + wxPrintDialog printerDialog(this, & printDialogData); + + printerDialog.GetPrintDialogData().SetSetupDialog(TRUE); + printerDialog.ShowModal(); - orientation = printerDialog.GetPrintData().GetOrientation(); + (*g_printData) = printerDialog.GetPrintDialogData().GetPrintData(); } void MyFrame::OnPageSetup(wxCommandEvent& WXUNUSED(event)) { - wxPageSetupData data; - data.SetOrientation(orientation); - - wxPageSetupDialog pageSetupDialog(this, & data); - pageSetupDialog.ShowModal(); + (*g_pageSetupData) = * g_printData; - data = pageSetupDialog.GetPageSetupData(); - orientation = data.GetOrientation(); + wxPageSetupDialog pageSetupDialog(this, g_pageSetupData); + pageSetupDialog.ShowModal(); + + (*g_printData) = pageSetupDialog.GetPageSetupData().GetPrintData(); + (*g_pageSetupData) = pageSetupDialog.GetPageSetupData(); } #if defined(__WXMSW__) && wxTEST_POSTSCRIPT_IN_MSW void MyFrame::OnPrintPS(wxCommandEvent& WXUNUSED(event)) { - wxPostScriptPrinter printer; - MyPrintout printout("My printout"); - printer.Print(this, &printout, TRUE); + wxPostScriptPrinter printer(g_printData); + MyPrintout printout("My printout"); + printer.Print(this, &printout, TRUE); + + (*g_printData) = printer.GetPrintData(); } void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event)) { - wxPrintData printData; - printData.SetOrientation(orientation); - - // Pass two printout objects: for preview, and possible printing. - wxPrintPreview *preview = new wxPrintPreview(new MyPrintout, new MyPrintout, & printData); - wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650)); - frame->Centre(wxBOTH); - frame->Initialize(); - frame->Show(TRUE); + // Pass two printout objects: for preview, and possible printing. + wxPrintDialogData printDialogData(* g_printData); + wxPrintPreview *preview = new wxPrintPreview(new MyPrintout, new MyPrintout, & printDialogData); + wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650)); + frame->Centre(wxBOTH); + frame->Initialize(); + frame->Show(TRUE); } void MyFrame::OnPrintSetupPS(wxCommandEvent& WXUNUSED(event)) { - wxPrintData data; - data.SetOrientation(orientation); + wxPrintDialogData printDialogData(* g_printData); + wxGenericPrintDialog printerDialog(this, & printDialogData); - wxGenericPrintDialog printerDialog(this, & data); - printerDialog.GetPrintData().SetSetupDialog(TRUE); - printerDialog.ShowModal(); + printerDialog.GetPrintDialogData().SetSetupDialog(TRUE); + printerDialog.ShowModal(); - orientation = printerDialog.GetPrintData().GetOrientation(); + (*g_printData) = printerDialog.GetPrintDialogData().GetPrintData(); } void MyFrame::OnPageSetupPS(wxCommandEvent& WXUNUSED(event)) { - wxPageSetupData data; - data.SetOrientation(orientation); + (*g_pageSetupData) = * g_printData; - wxGenericPageSetupDialog pageSetupDialog(this, & data); - pageSetupDialog.ShowModal(); + wxGenericPageSetupDialog pageSetupDialog(this, g_pageSetupData); + pageSetupDialog.ShowModal(); - orientation = pageSetupDialog.GetPageSetupData().GetOrientation(); + (*g_printData) = pageSetupDialog.GetPageSetupData().GetPrintData(); + (*g_pageSetupData) = pageSetupDialog.GetPageSetupData(); } #endif void MyFrame::OnPrintAbout(wxCommandEvent& WXUNUSED(event)) { - (void)wxMessageBox("wxWindows printing demo\nAuthor: Julian Smart julian.smart@ukonline.co.uk", - "About wxWindows printing demo", wxOK|wxCENTRE); + (void)wxMessageBox("wxWindows printing demo\nAuthor: Julian Smart julian.smart@ukonline.co.uk", + "About wxWindows printing demo", wxOK|wxCENTRE); } void MyFrame::Draw(wxDC& dc) { - dc.SetFont(* wxGetApp().m_testFont); - - dc.SetBackgroundMode(wxTRANSPARENT); - - dc.SetBrush(* wxCYAN_BRUSH); - dc.SetPen(* wxRED_PEN); - - dc.DrawRectangle(0, 30, 200, 100); - dc.DrawText("Rectangle 200 by 100", 40, 40); - - dc.DrawEllipse(50, 140, 100, 50); - - dc.DrawText("Test message: this is in 10 point text", 10, 180); - - dc.SetPen(* wxBLACK_PEN); - dc.DrawLine(0, 0, 200, 200); - dc.DrawLine(200, 0, 0, 200); - - wxIcon my_icon = wxICON(mondrian) ; - - dc.DrawIcon( my_icon, 100, 100); + dc.SetFont(* wxGetApp().m_testFont); + + dc.SetBackgroundMode(wxTRANSPARENT); + + dc.SetBrush(* wxCYAN_BRUSH); + dc.SetPen(* wxRED_PEN); + + dc.DrawRectangle(0, 30, 200, 100); + dc.DrawText("Rectangle 200 by 100", 40, 40); + + dc.DrawEllipse(50, 140, 100, 50); + + dc.DrawText("Test message: this is in 10 point text", 10, 180); + + dc.SetPen(* wxBLACK_PEN); + dc.DrawLine(0, 0, 200, 200); + dc.DrawLine(200, 0, 0, 200); + + wxIcon my_icon = wxICON(mondrian) ; + + dc.DrawIcon( my_icon, 100, 100); } void MyFrame::OnSize(wxSizeEvent& event ) @@ -300,13 +319,14 @@ void MyFrame::OnSize(wxSizeEvent& event ) } BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) - EVT_MOUSE_EVENTS(MyCanvas::OnEvent) +EVT_MOUSE_EVENTS(MyCanvas::OnEvent) END_EVENT_TABLE() // Define a constructor for my canvas MyCanvas::MyCanvas(wxFrame *frame, const wxPoint& pos, const wxSize& size, long style): - wxScrolledWindow(frame, -1, pos, size, style) + wxScrolledWindow(frame, -1, pos, size, style) { + SetBackgroundColour(* wxWHITE); } MyCanvas::~MyCanvas(void) @@ -316,7 +336,7 @@ MyCanvas::~MyCanvas(void) // Define the repainting behaviour void MyCanvas::OnDraw(wxDC& dc) { - frame->Draw(dc); + frame->Draw(dc); } void MyCanvas::OnEvent(wxMouseEvent& WXUNUSED(event)) @@ -325,196 +345,196 @@ void MyCanvas::OnEvent(wxMouseEvent& WXUNUSED(event)) bool MyPrintout::OnPrintPage(int page) { - wxDC *dc = GetDC(); - if (dc) - { - if (page == 1) - DrawPageOne(dc); - else if (page == 2) - DrawPageTwo(dc); - - dc->SetDeviceOrigin(0, 0); - dc->SetUserScale(1.0, 1.0); - - char buf[200]; - sprintf(buf, "PAGE %d", page); - dc->DrawText(buf, 10, 10); - - return TRUE; - } - else - return FALSE; + wxDC *dc = GetDC(); + if (dc) + { + if (page == 1) + DrawPageOne(dc); + else if (page == 2) + DrawPageTwo(dc); + + dc->SetDeviceOrigin(0, 0); + dc->SetUserScale(1.0, 1.0); + + char buf[200]; + sprintf(buf, "PAGE %d", page); + dc->DrawText(buf, 10, 10); + + return TRUE; + } + else + return FALSE; } bool MyPrintout::OnBeginDocument(int startPage, int endPage) { - if (!wxPrintout::OnBeginDocument(startPage, endPage)) - return FALSE; - - return TRUE; + if (!wxPrintout::OnBeginDocument(startPage, endPage)) + return FALSE; + + return TRUE; } void MyPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) { - *minPage = 1; - *maxPage = 2; - *selPageFrom = 1; - *selPageTo = 2; + *minPage = 1; + *maxPage = 2; + *selPageFrom = 1; + *selPageTo = 2; } bool MyPrintout::HasPage(int pageNum) { - return (pageNum == 1 || pageNum == 2); + return (pageNum == 1 || pageNum == 2); } void MyPrintout::DrawPageOne(wxDC *dc) { /* You might use THIS code if you were scaling - * graphics of known size to fit on the page. - */ - int w, h; - - // We know the graphic is 200x200. If we didn't know this, - // we'd need to calculate it. - float maxX = 200; - float maxY = 200; - - // Let's have at least 50 device units margin - float marginX = 50; - float marginY = 50; - - // Add the margin to the graphic size - maxX += (2*marginX); - maxY += (2*marginY); - - // Get the size of the DC in pixels - dc->GetSize(&w, &h); - - // Calculate a suitable scaling factor - float scaleX=(float)(w/maxX); - float scaleY=(float)(h/maxY); - - // Use x or y scaling factor, whichever fits on the DC - float actualScale = wxMin(scaleX,scaleY); - - // Calculate the position on the DC for centring the graphic - float posX = (float)((w - (200*actualScale))/2.0); - float posY = (float)((h - (200*actualScale))/2.0); - - // Set the scale and origin - dc->SetUserScale(actualScale, actualScale); - dc->SetDeviceOrigin( (long)posX, (long)posY ); - - frame->Draw(*dc); +* graphics of known size to fit on the page. + */ + int w, h; + + // We know the graphic is 200x200. If we didn't know this, + // we'd need to calculate it. + float maxX = 200; + float maxY = 200; + + // Let's have at least 50 device units margin + float marginX = 50; + float marginY = 50; + + // Add the margin to the graphic size + maxX += (2*marginX); + maxY += (2*marginY); + + // Get the size of the DC in pixels + dc->GetSize(&w, &h); + + // Calculate a suitable scaling factor + float scaleX=(float)(w/maxX); + float scaleY=(float)(h/maxY); + + // Use x or y scaling factor, whichever fits on the DC + float actualScale = wxMin(scaleX,scaleY); + + // Calculate the position on the DC for centring the graphic + float posX = (float)((w - (200*actualScale))/2.0); + float posY = (float)((h - (200*actualScale))/2.0); + + // Set the scale and origin + dc->SetUserScale(actualScale, actualScale); + dc->SetDeviceOrigin( (long)posX, (long)posY ); + + frame->Draw(*dc); } void MyPrintout::DrawPageTwo(wxDC *dc) { /* You might use THIS code to set the printer DC to ROUGHLY reflect - * the screen text size. This page also draws lines of actual length 5cm - * on the page. - */ - // Get the logical pixels per inch of screen and printer - int ppiScreenX, ppiScreenY; - GetPPIScreen(&ppiScreenX, &ppiScreenY); - int ppiPrinterX, ppiPrinterY; - GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); - - // This scales the DC so that the printout roughly represents the - // the screen scaling. The text point size _should_ be the right size - // but in fact is too small for some reason. This is a detail that will - // need to be addressed at some point but can be fudged for the - // moment. - float scale = (float)((float)ppiPrinterX/(float)ppiScreenX); - - // Now we have to check in case our real page size is reduced - // (e.g. because we're drawing to a print preview memory DC) - int pageWidth, pageHeight; - int w, h; - dc->GetSize(&w, &h); - GetPageSizePixels(&pageWidth, &pageHeight); - - // If printer pageWidth == current DC width, then this doesn't - // change. But w might be the preview bitmap width, so scale down. - float overallScale = scale * (float)(w/(float)pageWidth); - dc->SetUserScale(overallScale, overallScale); - - // Calculate conversion factor for converting millimetres into - // logical units. - // There are approx. 25.1 mm to the inch. There are ppi - // device units to the inch. Therefore 1 mm corresponds to - // ppi/25.1 device units. We also divide by the - // screen-to-printer scaling factor, because we need to - // unscale to pass logical units to DrawLine. - - // Draw 50 mm by 50 mm L shape - float logUnitsFactor = (float)(ppiPrinterX/(scale*25.1)); - float logUnits = (float)(50*logUnitsFactor); - dc->SetPen(* wxBLACK_PEN); - dc->DrawLine(50, 250, (long)(50.0 + logUnits), 250); - dc->DrawLine(50, 250, 50, (long)(250.0 + logUnits)); - - dc->SetFont(* wxGetApp().m_testFont); - dc->SetBackgroundMode(wxTRANSPARENT); - - dc->DrawText("Some test text", 200, 200 ); - - // TESTING - - int leftMargin = 20; - int rightMargin = 20; - int topMargin = 20; - int bottomMargin = 20; - - int pageWidthMM, pageHeightMM; - GetPageSizeMM(&pageWidthMM, &pageHeightMM); - - float leftMarginLogical = (float)(logUnitsFactor*leftMargin); - float topMarginLogical = (float)(logUnitsFactor*topMargin); - float bottomMarginLogical = (float)(logUnitsFactor*(pageHeightMM - bottomMargin)); - float rightMarginLogical = (float)(logUnitsFactor*(pageWidthMM - rightMargin)); - - dc->SetPen(* wxRED_PEN); - dc->DrawLine( (long)leftMarginLogical, (long)topMarginLogical, - (long)rightMarginLogical, (long)topMarginLogical); - dc->DrawLine( (long)leftMarginLogical, (long)bottomMarginLogical, - (long)rightMarginLogical, (long)bottomMarginLogical); - - WritePageHeader(this, dc, "A header", logUnitsFactor); +* the screen text size. This page also draws lines of actual length 5cm +* on the page. + */ + // Get the logical pixels per inch of screen and printer + int ppiScreenX, ppiScreenY; + GetPPIScreen(&ppiScreenX, &ppiScreenY); + int ppiPrinterX, ppiPrinterY; + GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); + + // This scales the DC so that the printout roughly represents the + // the screen scaling. The text point size _should_ be the right size + // but in fact is too small for some reason. This is a detail that will + // need to be addressed at some point but can be fudged for the + // moment. + float scale = (float)((float)ppiPrinterX/(float)ppiScreenX); + + // Now we have to check in case our real page size is reduced + // (e.g. because we're drawing to a print preview memory DC) + int pageWidth, pageHeight; + int w, h; + dc->GetSize(&w, &h); + GetPageSizePixels(&pageWidth, &pageHeight); + + // If printer pageWidth == current DC width, then this doesn't + // change. But w might be the preview bitmap width, so scale down. + float overallScale = scale * (float)(w/(float)pageWidth); + dc->SetUserScale(overallScale, overallScale); + + // Calculate conversion factor for converting millimetres into + // logical units. + // There are approx. 25.1 mm to the inch. There are ppi + // device units to the inch. Therefore 1 mm corresponds to + // ppi/25.1 device units. We also divide by the + // screen-to-printer scaling factor, because we need to + // unscale to pass logical units to DrawLine. + + // Draw 50 mm by 50 mm L shape + float logUnitsFactor = (float)(ppiPrinterX/(scale*25.1)); + float logUnits = (float)(50*logUnitsFactor); + dc->SetPen(* wxBLACK_PEN); + dc->DrawLine(50, 250, (long)(50.0 + logUnits), 250); + dc->DrawLine(50, 250, 50, (long)(250.0 + logUnits)); + + dc->SetFont(* wxGetApp().m_testFont); + dc->SetBackgroundMode(wxTRANSPARENT); + + dc->DrawText("Some test text", 200, 200 ); + + // TESTING + + int leftMargin = 20; + int rightMargin = 20; + int topMargin = 20; + int bottomMargin = 20; + + int pageWidthMM, pageHeightMM; + GetPageSizeMM(&pageWidthMM, &pageHeightMM); + + float leftMarginLogical = (float)(logUnitsFactor*leftMargin); + float topMarginLogical = (float)(logUnitsFactor*topMargin); + float bottomMarginLogical = (float)(logUnitsFactor*(pageHeightMM - bottomMargin)); + float rightMarginLogical = (float)(logUnitsFactor*(pageWidthMM - rightMargin)); + + dc->SetPen(* wxRED_PEN); + dc->DrawLine( (long)leftMarginLogical, (long)topMarginLogical, + (long)rightMarginLogical, (long)topMarginLogical); + dc->DrawLine( (long)leftMarginLogical, (long)bottomMarginLogical, + (long)rightMarginLogical, (long)bottomMarginLogical); + + WritePageHeader(this, dc, "A header", logUnitsFactor); } // Writes a header on a page. Margin units are in millimetres. bool WritePageHeader(wxPrintout *printout, wxDC *dc, char *text, float mmToLogical) { /* - static wxFont *headerFont = (wxFont *) NULL; - if (!headerFont) - { - headerFont = wxTheFontList->FindOrCreateFont(16, wxSWISS, wxNORMAL, wxBOLD); - } - dc->SetFont(headerFont); -*/ - - int pageWidthMM, pageHeightMM; - - printout->GetPageSizeMM(&pageWidthMM, &pageHeightMM); - - int leftMargin = 10; - int topMargin = 10; - int rightMargin = 10; - - float leftMarginLogical = (float)(mmToLogical*leftMargin); - float topMarginLogical = (float)(mmToLogical*topMargin); - float rightMarginLogical = (float)(mmToLogical*(pageWidthMM - rightMargin)); - - long xExtent, yExtent; - dc->GetTextExtent(text, &xExtent, &yExtent); - float xPos = (float)(((((pageWidthMM - leftMargin - rightMargin)/2.0)+leftMargin)*mmToLogical) - (xExtent/2.0)); - dc->DrawText(text, (long)xPos, (long)topMarginLogical); - - dc->SetPen(* wxBLACK_PEN); - dc->DrawLine( (long)leftMarginLogical, (long)(topMarginLogical+yExtent), - (long)rightMarginLogical, (long)topMarginLogical+yExtent ); - - return TRUE; +static wxFont *headerFont = (wxFont *) NULL; +if (!headerFont) +{ +headerFont = wxTheFontList->FindOrCreateFont(16, wxSWISS, wxNORMAL, wxBOLD); +} +dc->SetFont(headerFont); + */ + + int pageWidthMM, pageHeightMM; + + printout->GetPageSizeMM(&pageWidthMM, &pageHeightMM); + + int leftMargin = 10; + int topMargin = 10; + int rightMargin = 10; + + float leftMarginLogical = (float)(mmToLogical*leftMargin); + float topMarginLogical = (float)(mmToLogical*topMargin); + float rightMarginLogical = (float)(mmToLogical*(pageWidthMM - rightMargin)); + + long xExtent, yExtent; + dc->GetTextExtent(text, &xExtent, &yExtent); + float xPos = (float)(((((pageWidthMM - leftMargin - rightMargin)/2.0)+leftMargin)*mmToLogical) - (xExtent/2.0)); + dc->DrawText(text, (long)xPos, (long)topMarginLogical); + + dc->SetPen(* wxBLACK_PEN); + dc->DrawLine( (long)leftMarginLogical, (long)(topMarginLogical+yExtent), + (long)rightMarginLogical, (long)topMarginLogical+yExtent ); + + return TRUE; } diff --git a/src/common/cmndata.cpp b/src/common/cmndata.cpp index 07fd3cd826..08bd0fa4de 100644 --- a/src/common/cmndata.cpp +++ b/src/common/cmndata.cpp @@ -29,6 +29,12 @@ #include "wx/gdicmn.h" #include "wx/cmndata.h" +#include "wx/paper.h" + +// For compatibility +#if (defined(__WXMOTIF__) || defined(__WXGTK__)) && wxUSE_POSTSCRIPT +#include "wx/generic/dcpsg.h" +#endif #ifdef __WXMSW__ #include @@ -47,23 +53,29 @@ #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject) -IMPLEMENT_DYNAMIC_CLASS(wxPageSetupData, wxObject) +IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject) +IMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject) #endif /* - * wxColourData - */ +* wxColourData +*/ wxColourData::wxColourData() { - int i; - for (i = 0; i < 16; i++) - custColours[i].Set(255, 255, 255); + int i; + for (i = 0; i < 16; i++) + custColours[i].Set(255, 255, 255); + + chooseFull = FALSE; + dataColour.Set(0,0,0); +} - chooseFull = FALSE; - dataColour.Set(0,0,0); +wxColourData::wxColourData(const wxColourData& data) +{ + (*this) = data; } wxColourData::~wxColourData() @@ -72,44 +84,49 @@ wxColourData::~wxColourData() void wxColourData::SetCustomColour(int i, wxColour& colour) { - if (i > 15 || i < 0) - return; - - custColours[i] = colour; + if (i > 15 || i < 0) + return; + + custColours[i] = colour; } wxColour wxColourData::GetCustomColour(int i) { - if (i > 15 || i < 0) - return wxColour(0,0,0); - - return custColours[i]; + if (i > 15 || i < 0) + return wxColour(0,0,0); + + return custColours[i]; } void wxColourData::operator=(const wxColourData& data) { - int i; - for (i = 0; i < 16; i++) - custColours[i] = data.custColours[i]; - - dataColour = (wxColour&)data.dataColour; - chooseFull = data.chooseFull; + int i; + for (i = 0; i < 16; i++) + custColours[i] = data.custColours[i]; + + dataColour = (wxColour&)data.dataColour; + chooseFull = data.chooseFull; } /* - * Font data - */ +* Font data +*/ wxFontData::wxFontData() { - // Intialize colour to black. - fontColour.Set(0, 0, 0); + // Intialize colour to black. + fontColour.Set(0, 0, 0); + + showHelp = FALSE; + allowSymbols = TRUE; + enableEffects = TRUE; + minSize = 0; + maxSize = 0; +} - showHelp = FALSE; - allowSymbols = TRUE; - enableEffects = TRUE; - minSize = 0; - maxSize = 0; +wxFontData::wxFontData(const wxFontData& data) +{ + (*this) = data; } wxFontData::~wxFontData() @@ -118,71 +135,97 @@ wxFontData::~wxFontData() void wxFontData::operator=(const wxFontData& data) { - fontColour = data.fontColour; - showHelp = data.showHelp; - allowSymbols = data.allowSymbols; - enableEffects = data.enableEffects; - initialFont = data.initialFont; - chosenFont = data.chosenFont; - minSize = data.minSize; - maxSize = data.maxSize; + fontColour = data.fontColour; + showHelp = data.showHelp; + allowSymbols = data.allowSymbols; + enableEffects = data.enableEffects; + initialFont = data.initialFont; + chosenFont = data.chosenFont; + minSize = data.minSize; + maxSize = data.maxSize; } /* - * Print data - */ +* Print data +*/ wxPrintData::wxPrintData() { #ifdef __WXMSW__ - printData = NULL; + m_devMode = NULL; #endif - printOrientation = wxPORTRAIT; - printFromPage = 0; - printToPage = 0; - printMinPage = 0; - printMaxPage = 0; - printNoCopies = 1; - printAllPages = FALSE; - printCollate = FALSE; - printToFile = FALSE; - printEnableSelection = FALSE; - printEnablePageNumbers = TRUE; - printEnablePrintToFile = TRUE; - printEnableHelp = FALSE; - printSetupDialog = FALSE; + m_printOrientation = wxPORTRAIT; + m_printNoCopies = 1; + m_printCollate = FALSE; + + // New, 24/3/99 + m_printerName = ""; + m_colour = TRUE; + m_duplexMode = wxDUPLEX_SIMPLEX; + m_printQuality = wxPRINT_QUALITY_HIGH; + m_paperId = wxPAPER_A4; + m_paperSize = wxSize(210, 297); + + // PostScript-specific data + m_printerCommand = ""; + m_previewCommand = ""; + m_printerOptions = ""; + m_filename = ""; + m_afmPath = ""; + m_printerScaleX = 1.0; + m_printerScaleY = 1.0; + m_printerTranslateX = 0; + m_printerTranslateY = 0; + m_printMode = wxPRINT_MODE_FILE; +} + +wxPrintData::wxPrintData(const wxPrintData& printData) +{ + (*this) = printData; } wxPrintData::~wxPrintData() { #ifdef __WXMSW__ - PRINTDLG *pd = (PRINTDLG *)printData; - if ( pd && pd->hDevMode ) + HGLOBAL hDevMode = (HGLOBAL) hDevMode; + if (hDevMode ) + GlobalFree(hDevMode); + /* + PRINTDLG *pd = (PRINTDLG *) m_printData; + if ( pd && pd->hDevMode ) GlobalFree(pd->hDevMode); - if ( pd ) + if ( pd ) delete pd; + */ #endif } #ifdef __WXMSW__ + void wxPrintData::ConvertToNative() { - PRINTDLG *pd = (PRINTDLG*) printData; - if ( pd == NULL ) + HGLOBAL hDevMode = (HGLOBAL) m_devMode; + if (!hDevMode) { - pd = new PRINTDLG; - printData = (void*) pd; - + // Use PRINTDLG as a way of creating a DEVMODE object + PRINTDLG *pd = new PRINTDLG; + // GNU-WIN32 has the wrong size PRINTDLG - can't work out why. -// pd->lStructSize = sizeof(PRINTDLG); +#ifdef __GNUWIN32__ pd->lStructSize = 66 ; + memset(pd, 0, sizeof(PRINTDLG)); +#else + pd->lStructSize = sizeof(PRINTDLG); + memset(pd, 0, sizeof(PRINTDLG)); +#endif + pd->hwndOwner = (HWND)NULL; pd->hDevMode = NULL; // Will be created by PrintDlg pd->hDevNames = NULL; // Ditto - + pd->Flags = PD_RETURNDEFAULT; pd->nCopies = 1; - + // Fill out the DEVMODE structure // so we can use it as input in the 'real' PrintDlg if (!PrintDlg(pd)) @@ -199,26 +242,462 @@ void wxPrintData::ConvertToNative() if ( pd->hDevNames ) GlobalFree(pd->hDevNames); pd->hDevNames = NULL; + + hDevMode = pd->hDevMode; + m_devMode = (void*) hDevMode; + pd->hDevMode = NULL; } - } - if ( pd->hDevMode ) + delete pd; + } + + if ( hDevMode ) { - DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode); - devMode->dmOrientation = printOrientation; + DEVMODE *devMode = (DEVMODE*) GlobalLock(hDevMode); + + //// Orientation + + devMode->dmOrientation = m_printOrientation; devMode->dmFields = DM_ORIENTATION; - GlobalUnlock(pd->hDevMode); + + //// Collation + + devMode->dmCollate = (m_printCollate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE); + devMode->dmFields |= DM_COLLATE; + + //// Number of copies + + devMode->dmCopies = m_printNoCopies; + devMode->dmFields |= DM_COPIES; + + //// Printer name + + if (m_printerName != "") + { + // TODO: make this Unicode compatible + int len = wxMin(31, m_printerName.Len()); + int i; + for (i = 0; i < len; i++) + devMode->dmDeviceName[i] = m_printerName.GetChar(i); + devMode->dmDeviceName[i] = 0; + } + + //// Colour + + if (m_colour) + devMode->dmColor = DMCOLOR_COLOR; + else + devMode->dmColor = DMCOLOR_MONOCHROME; + + devMode->dmFields |= DM_COLOR; + + //// Paper size + + if (m_paperId == wxPAPER_NONE) + { + devMode->dmPaperWidth = m_paperSize.x * 10; + devMode->dmPaperLength = m_paperSize.y * 10; + devMode->dmFields |= DM_PAPERWIDTH; + devMode->dmFields |= DM_PAPERLENGTH; + } + else + { + if (wxThePrintPaperDatabase) + { + wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType(m_paperId); + if (paper) + { + devMode->dmPaperSize = paper->GetPlatformId(); + devMode->dmFields |= DM_PAPERSIZE; + } + } + } + + //// Duplex + + int duplex; + switch (m_duplexMode) + { + case wxDUPLEX_HORIZONTAL: { + duplex = DMDUP_HORIZONTAL; break; + } + case wxDUPLEX_VERTICAL: { + duplex = DMDUP_VERTICAL; break; + } + default: + case wxDUPLEX_SIMPLEX: { + duplex = DMDUP_SIMPLEX; break; + } + } + devMode->dmDuplex = duplex; + devMode->dmFields |= DM_DUPLEX; + + //// Quality + + int quality; + switch (m_printQuality) + { + case wxPRINT_QUALITY_MEDIUM: { + quality = DMRES_MEDIUM; break; + } + case wxPRINT_QUALITY_LOW: { + quality = DMRES_LOW; break; + } + case wxPRINT_QUALITY_DRAFT: { + quality = DMRES_DRAFT; break; + } + case wxPRINT_QUALITY_HIGH: { + quality = DMRES_HIGH; break; + } + default: { + quality = m_printQuality; break; + } + } + devMode->dmPrintQuality = quality; + devMode->dmFields |= DM_PRINTQUALITY; + + GlobalUnlock(hDevMode); } - pd->hDC = (HDC) NULL; - pd->nFromPage = (UINT)printFromPage; - pd->nToPage = (UINT)printToPage; - pd->nMinPage = (UINT)printMinPage; - pd->nMaxPage = (UINT)printMaxPage; - pd->nCopies = (UINT)printNoCopies; +} + +void wxPrintData::ConvertFromNative() +{ + HGLOBAL hDevMode = (HGLOBAL) m_devMode; + + if (!hDevMode) + return; + + if ( hDevMode ) + { + DEVMODE *devMode = (DEVMODE*) GlobalLock(hDevMode); + + //// Orientation + + if (devMode->dmFields & DM_ORIENTATION) + m_printOrientation = devMode->dmOrientation; + + //// Collation + + if (devMode->dmFields & DM_COLLATE) + { + if (devMode->dmCollate == DMCOLLATE_TRUE) + m_printCollate = TRUE; + else + m_printCollate = FALSE; + } + + //// Number of copies + + if (devMode->dmFields & DM_COPIES) + { + m_printNoCopies = devMode->dmCopies; + } + + //// Printer name + + if (devMode->dmDeviceName[0] != 0) + { + // TODO: make this Unicode compatible + char buf[32]; + int i = 0; + while (devMode->dmDeviceName[i] != 0) + { + buf[i] = devMode->dmDeviceName[i]; + i ++; + } + buf[i] = 0; + + m_printerName = buf; + } + + //// Colour + + if (devMode->dmFields & DM_COLOR) + { + if (devMode->dmColor == DMCOLOR_COLOR) + m_colour = TRUE; + else + m_colour = FALSE; + } + else + m_colour = TRUE; + + //// Paper size + + if (devMode->dmFields & DM_PAPERSIZE) + { + if (wxThePrintPaperDatabase) + { + wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize); + if (paper) + { + m_paperId = paper->GetId(); + m_paperSize.x = paper->GetWidth() / 10 ; + m_paperSize.y = paper->GetHeight() / 10 ; + } + else + { + // Shouldn't really get here + wxFAIL_MSG("Couldn't find paper size in paper database."); + + m_paperId = wxPAPER_NONE; + m_paperSize.x = 0; + m_paperSize.y = 0; + } + } + else + { + // Shouldn't really get here + wxFAIL_MSG("Paper database wasn't initialized in wxPrintData::ConvertFromNative."); + + m_paperId = wxPAPER_NONE; + m_paperSize.x = 0; + m_paperSize.y = 0; + } + } + else if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH)) + { + m_paperSize.x = devMode->dmPaperWidth / 10; + m_paperSize.y = devMode->dmPaperLength / 10; + m_paperId = wxPAPER_NONE; + } + else + { + // Shouldn't really get here + wxFAIL_MSG("Couldn't find paper size from DEVMODE."); + + m_paperSize.x = 0; + m_paperSize.y = 0; + m_paperId = wxPAPER_NONE; + } + + + //// Duplex + + if (devMode->dmFields & DM_DUPLEX) + { + switch (devMode->dmDuplex) + { + case DMDUP_HORIZONTAL: { + m_duplexMode = wxDUPLEX_HORIZONTAL; break; + } + case DMDUP_VERTICAL: { + m_duplexMode = wxDUPLEX_VERTICAL; break; + } + default: + case DMDUP_SIMPLEX: { + m_duplexMode = wxDUPLEX_SIMPLEX; break; + } + } + } + else + m_duplexMode = wxDUPLEX_SIMPLEX; + + //// Quality + + if (devMode->dmFields & DM_PRINTQUALITY) + { + switch (devMode->dmPrintQuality) + { + case DMRES_MEDIUM: { + m_printQuality = wxPRINT_QUALITY_MEDIUM; break; + } + case DMRES_LOW: { + m_printQuality = wxPRINT_QUALITY_LOW; break; + } + case DMRES_DRAFT: { + m_printQuality = wxPRINT_QUALITY_DRAFT; break; + } + case DMRES_HIGH: { + m_printQuality = wxPRINT_QUALITY_HIGH; break; + } + default: + { + // TODO: if the printer fills in the resolution in DPI, how + // will the application know if it's high, low, draft etc.?? + // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values."); + m_printQuality = devMode->dmPrintQuality; break; + + } + } + } + else + m_printQuality = wxPRINT_QUALITY_HIGH; + + GlobalUnlock(hDevMode); + } +} +#endif + +void wxPrintData::operator=(const wxPrintData& data) +{ + m_printNoCopies = data.m_printNoCopies; + m_printCollate = data.m_printCollate; + m_printOrientation = data.m_printOrientation; + m_printerName = data.m_printerName; + m_colour = data.m_colour; + m_duplexMode = data.m_duplexMode; + m_printQuality = data.m_printQuality; + m_paperId = data.m_paperId; + m_paperSize = data.m_paperSize; + + // PostScript-specific data + m_printerCommand = data.m_printerCommand; + m_previewCommand = data.m_previewCommand; + m_printerOptions = data.m_printerOptions; + m_filename = data.m_filename; + m_afmPath = data.m_afmPath; + m_printerScaleX = data.m_printerScaleX; + m_printerScaleY = data.m_printerScaleY; + m_printerTranslateX = data.m_printerTranslateX; + m_printerTranslateY = data.m_printerTranslateY; + m_printMode = data.m_printMode; +} + +// For compatibility +#if (defined(__WXMOTIF__) || defined(__WXGTK__)) && wxUSE_POSTSCRIPT +void wxPrintData::operator=(const wxPrintSetupData& setupData) +{ + SetPrinterCommand(setupData.GetPrinterCommand()); + SetPreviewCommand(setupData.GetPrintPreviewCommand()); + SetPrinterOptions(setupData.GetPrinterOptions()); + + long xt, yt; + setupData.GetPrinterTranslation(& xt, & yt); + SetPrinterTranslation(xt, yt); + + double xs, ys; + setupData.GetPrinterScaling(& xs, & ys); + SetPrinterScaling(xs, ys); + + SetOrientation(setupData.GetPrinterOrientation()); + SetPrintMode((wxPrintMode) setupData.GetPrinterMode()); + SetFontMetricPath(setupData.GetAFMPath()); + if (setupData.GetPaperName() != "") + SetPaperId(wxThePrintPaperDatabase->ConvertNameToId(setupData.GetPaperName())); + SetColour(setupData.GetColour()); + SetFilename(setupData.GetPrinterFile()); +} +#endif + + +/* + * Print dialog data + */ + +wxPrintDialogData::wxPrintDialogData() +{ +#ifdef __WXMSW__ + m_printDlgData = NULL; +#endif + m_printFromPage = 0; + m_printToPage = 0; + m_printMinPage = 0; + m_printMaxPage = 0; + m_printNoCopies = 1; + m_printAllPages = FALSE; + m_printCollate = FALSE; + m_printToFile = FALSE; + m_printEnableSelection = FALSE; + m_printEnablePageNumbers = TRUE; + m_printEnablePrintToFile = TRUE; + m_printEnableHelp = FALSE; + m_printSetupDialog = FALSE; +} + +wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData) +{ + (*this) = dialogData; +} + +wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData) +{ +#ifdef __WXMSW__ + m_printDlgData = NULL; +#endif + m_printFromPage = 0; + m_printToPage = 0; + m_printMinPage = 0; + m_printMaxPage = 0; + m_printNoCopies = 1; + m_printAllPages = FALSE; + m_printCollate = FALSE; + m_printToFile = FALSE; + m_printEnableSelection = FALSE; + m_printEnablePageNumbers = TRUE; + m_printEnablePrintToFile = TRUE; + m_printEnableHelp = FALSE; + m_printSetupDialog = FALSE; + + m_printData = printData; +} + +wxPrintDialogData::~wxPrintDialogData() +{ +#ifdef __WXMSW__ + PRINTDLG *pd = (PRINTDLG *) m_printDlgData; + if ( pd && pd->hDevMode ) + GlobalFree(pd->hDevMode); + if ( pd ) + delete pd; +#endif +} + +#ifdef __WXMSW__ +void wxPrintDialogData::ConvertToNative() +{ + m_printData.ConvertToNative(); + + PRINTDLG *pd = (PRINTDLG*) m_printDlgData; + + if (!pd) + { + pd = new PRINTDLG; + m_printDlgData = (void*) pd; + + // GNU-WIN32 has the wrong size PRINTDLG - can't work out why. +#ifdef __GNUWIN32__ + pd->lStructSize = 66 ; +#else +#endif + pd->lStructSize = sizeof(PRINTDLG); + pd->hwndOwner = (HWND)NULL; + pd->hDevMode = NULL; // Will be created by PrintDlg + pd->hDevNames = NULL; // Ditto + + pd->Flags = PD_RETURNDEFAULT; + pd->nCopies = 1; + } + + // Pass the devmode data to the PRINTDLG structure, since it'll + // be needed when PrintDlg is called. + if (pd->hDevMode) + { + GlobalFree(pd->hDevMode); + } + + pd->hDevMode = (HGLOBAL) m_printData.GetNativeData(); + + m_printData.SetNativeData((void*) NULL); + + wxASSERT_MSG( (pd->hDevMode), "hDevMode must be non-NULL in ConvertToNative!"); + + pd->hDC = (HDC) NULL; + pd->nFromPage = (UINT)m_printFromPage; + pd->nToPage = (UINT)m_printToPage; + pd->nMinPage = (UINT)m_printMinPage; + pd->nMaxPage = (UINT)m_printMaxPage; + pd->nCopies = (UINT)m_printNoCopies; + pd->Flags = PD_RETURNDC ; -// pd->lStructSize = sizeof( PRINTDLG ); + +#ifdef __GNUWIN32__ pd->lStructSize = 66 ; +#else + pd->lStructSize = sizeof( PRINTDLG ); +#endif + pd->hwndOwner=(HWND)NULL; pd->hDevNames=(HANDLE)NULL; pd->hInstance=(HINSTANCE)NULL; @@ -229,111 +708,176 @@ void wxPrintData::ConvertToNative() pd->lpSetupTemplateName = NULL; pd->hPrintTemplate = (HGLOBAL) NULL; pd->hSetupTemplate = (HGLOBAL) NULL; - - if ( printAllPages ) + + if ( m_printAllPages ) pd->Flags |= PD_ALLPAGES; - if ( printCollate ) + if ( m_printCollate ) pd->Flags |= PD_COLLATE; - if ( printToFile ) + if ( m_printToFile ) pd->Flags |= PD_PRINTTOFILE; - if ( !printEnablePrintToFile ) + if ( !m_printEnablePrintToFile ) pd->Flags |= PD_DISABLEPRINTTOFILE; - if ( !printEnableSelection ) - pd->Flags |= PD_NOSELECTION; - if ( !printEnablePageNumbers ) - pd->Flags |= PD_NOPAGENUMS; - if ( printEnableHelp ) - pd->Flags |= PD_SHOWHELP; - if ( printSetupDialog ) - pd->Flags |= PD_PRINTSETUP; + if ( !m_printEnableSelection ) + pd->Flags |= PD_NOSELECTION; + if ( !m_printEnablePageNumbers ) + pd->Flags |= PD_NOPAGENUMS; + if ( m_printEnableHelp ) + pd->Flags |= PD_SHOWHELP; + if ( m_printSetupDialog ) + pd->Flags |= PD_PRINTSETUP; } -void wxPrintData::ConvertFromNative() +void wxPrintDialogData::ConvertFromNative() { - PRINTDLG *pd = (PRINTDLG*) printData; + PRINTDLG *pd = (PRINTDLG*) m_printDlgData; if ( pd == NULL ) return; - if ( pd->hDevMode ) + // Pass the devmode data back to the wxPrintData structure where it really belongs. + if (pd->hDevMode) { - DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode); - printOrientation = devMode->dmOrientation; - GlobalUnlock(pd->hDevMode); + if (m_printData.GetNativeData()) + { + // Make sure we don't leak memory + GlobalFree((HGLOBAL) m_printData.GetNativeData()); + } + m_printData.SetNativeData((void*) pd->hDevMode); + pd->hDevMode = NULL; } - printFromPage = pd->nFromPage ; - printToPage = pd->nToPage ; - printMinPage = pd->nMinPage ; - printMaxPage = pd->nMaxPage ; - printNoCopies = pd->nCopies ; - printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES); - printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE); - printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE); - printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE); - printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION); - printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS); - printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP); - printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP); + // Now convert the DEVMODE object, passed down from the PRINTDLG object, + // into wxWindows form. + m_printData.ConvertFromNative(); + + m_printFromPage = pd->nFromPage ; + m_printToPage = pd->nToPage ; + m_printMinPage = pd->nMinPage ; + m_printMaxPage = pd->nMaxPage ; + m_printNoCopies = pd->nCopies ; + + m_printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES); + m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE); + m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE); + m_printEnablePrintToFile = ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE); + m_printEnableSelection = ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION); + m_printEnablePageNumbers = ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS); + m_printEnableHelp = ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP); + m_printSetupDialog = ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP); + +/* port is obsolete in WIN32 + // Get the port name + if (pd->hDevNames) + { + LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(pd->hDevNames); + if (lpDevNames) { + m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset); + wxString devName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset; + GlobalUnlock(pd->hDevNames); + +// wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!"); + } + } +*/ } -void wxPrintData::SetOwnerWindow(wxWindow* win) +void wxPrintDialogData::SetOwnerWindow(wxWindow* win) { - if ( printData == NULL ) + if ( m_printDlgData == NULL ) ConvertToNative(); - - if ( printData != NULL && win != NULL) + + if ( m_printDlgData != NULL && win != NULL) { - PRINTDLG *pd = (PRINTDLG *) printData ; - pd->hwndOwner=(HWND) win->GetHWND(); + PRINTDLG *pd = (PRINTDLG *) m_printDlgData ; + pd->hwndOwner=(HWND) win->GetHWND(); } } #endif -void wxPrintData::operator=(const wxPrintData& data) +void wxPrintDialogData::operator=(const wxPrintDialogData& data) { - printFromPage = data.printFromPage; - printToPage = data.printToPage; - printMinPage = data.printMinPage; - printMaxPage = data.printMaxPage; - printNoCopies = data.printNoCopies; - printAllPages = data.printAllPages; - printCollate = data.printCollate; - printToFile = data.printToFile; - printEnableSelection = data.printEnableSelection; - printEnablePageNumbers = data.printEnablePageNumbers; - printEnableHelp = data.printEnableHelp; - printEnablePrintToFile = data.printEnablePrintToFile; - printSetupDialog = data.printSetupDialog; - printOrientation = data.printOrientation; + m_printFromPage = data.m_printFromPage; + m_printToPage = data.m_printToPage; + m_printMinPage = data.m_printMinPage; + m_printMaxPage = data.m_printMaxPage; + m_printNoCopies = data.m_printNoCopies; + m_printAllPages = data.m_printAllPages; + m_printCollate = data.m_printCollate; + m_printToFile = data.m_printToFile; + m_printEnableSelection = data.m_printEnableSelection; + m_printEnablePageNumbers = data.m_printEnablePageNumbers; + m_printEnableHelp = data.m_printEnableHelp; + m_printEnablePrintToFile = data.m_printEnablePrintToFile; + m_printSetupDialog = data.m_printSetupDialog; + + m_printData = data.m_printData; +} + +void wxPrintDialogData::operator=(const wxPrintData& data) +{ + m_printData = data; } /* - * wxPageSetupData + * wxPageSetupDialogData */ -wxPageSetupData::wxPageSetupData() +wxPageSetupDialogData::wxPageSetupDialogData() { #if defined(__WIN95__) - m_pageSetupData = NULL; + m_pageSetupData = NULL; #endif - m_paperSize = wxPoint(0, 0); - m_minMarginTopLeft = wxPoint(0, 0); - m_minMarginBottomRight = wxPoint(0, 0); - m_marginTopLeft = wxPoint(0, 0); - m_marginBottomRight = wxPoint(0, 0); - m_orientation = wxPORTRAIT; + m_paperSize = wxSize(0, 0); + + CalculatePaperSizeFromId(); + + m_minMarginTopLeft = wxPoint(0, 0); + m_minMarginBottomRight = wxPoint(0, 0); + m_marginTopLeft = wxPoint(0, 0); + m_marginBottomRight = wxPoint(0, 0); + + // Flags + m_defaultMinMargins = FALSE; + m_enableMargins = TRUE; + m_enableOrientation = TRUE; + m_enablePaper = TRUE; + m_enablePrinter = TRUE; + m_enableHelp = FALSE; + m_getDefaultInfo = FALSE; +} - // Flags - m_defaultMinMargins = FALSE; - m_enableMargins = TRUE; - m_enableOrientation = TRUE; - m_enablePaper = TRUE; - m_enablePrinter = TRUE; - m_enableHelp = FALSE; - m_getDefaultInfo = FALSE; +wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData) +{ + (*this) = dialogData; +} + +wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData) +{ +#if defined(__WIN95__) + m_pageSetupData = NULL; +#endif + m_paperSize = wxSize(0, 0); + m_minMarginTopLeft = wxPoint(0, 0); + m_minMarginBottomRight = wxPoint(0, 0); + m_marginTopLeft = wxPoint(0, 0); + m_marginBottomRight = wxPoint(0, 0); + + // Flags + m_defaultMinMargins = FALSE; + m_enableMargins = TRUE; + m_enableOrientation = TRUE; + m_enablePaper = TRUE; + m_enablePrinter = TRUE; + m_enableHelp = FALSE; + m_getDefaultInfo = FALSE; + + m_printData = printData; + + // The wxPrintData paper size overrides these values, unless the size cannot + // be found. + CalculatePaperSizeFromId(); } -wxPageSetupData::~wxPageSetupData() +wxPageSetupDialogData::~wxPageSetupDialogData() { #if defined(__WIN95__) && defined(__WXMSW__) PAGESETUPDLG *pd = (PAGESETUPDLG *)m_pageSetupData; @@ -344,37 +888,64 @@ wxPageSetupData::~wxPageSetupData() #endif } -void wxPageSetupData::operator=(const wxPageSetupData& data) +void wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data) { - m_paperSize = data.m_paperSize; - m_minMarginTopLeft = data.m_minMarginTopLeft; - m_minMarginBottomRight = data.m_minMarginBottomRight; - m_marginTopLeft = data.m_marginTopLeft; - m_marginBottomRight = data.m_marginBottomRight; - m_orientation = data.m_orientation; + m_paperSize = data.m_paperSize; + m_minMarginTopLeft = data.m_minMarginTopLeft; + m_minMarginBottomRight = data.m_minMarginBottomRight; + m_marginTopLeft = data.m_marginTopLeft; + m_marginBottomRight = data.m_marginBottomRight; + m_defaultMinMargins = data.m_defaultMinMargins; + m_enableMargins = data.m_enableMargins; + m_enableOrientation = data.m_enableOrientation; + m_enablePaper = data.m_enablePaper; + m_enablePrinter = data.m_enablePrinter; + m_getDefaultInfo = data.m_getDefaultInfo;; + m_enableHelp = data.m_enableHelp; + + m_printData = data.m_printData; +} - m_defaultMinMargins = data.m_defaultMinMargins; - m_enableMargins = data.m_enableMargins; - m_enableOrientation = data.m_enableOrientation; - m_enablePaper = data.m_enablePaper; - m_enablePrinter = data.m_enablePrinter; - m_getDefaultInfo = data.m_getDefaultInfo;; - m_enableHelp = data.m_enableHelp; +void wxPageSetupDialogData::operator=(const wxPrintData& data) +{ + m_printData = data; } #if defined(__WXMSW__) && defined(__WIN95__) -void wxPageSetupData::ConvertToNative() +void wxPageSetupDialogData::ConvertToNative() { + m_printData.ConvertToNative(); + PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData; + if ( m_pageSetupData == NULL ) { - pd = new PAGESETUPDLG; - pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE)); - m_pageSetupData = (void *)pd; + pd = new PAGESETUPDLG; + pd->hDevMode = NULL; + m_pageSetupData = (void *)pd; } - pd->Flags = PSD_MARGINS|PSD_MINMARGINS; + // Pass the devmode data (created in m_printData.ConvertToNative) + // to the PRINTDLG structure, since it'll + // be needed when PrintDlg is called. + + if (pd->hDevMode) + { + GlobalFree(pd->hDevMode); + pd->hDevMode = NULL; + } + + + pd->hDevMode = (HGLOBAL) m_printData.GetNativeData(); + + m_printData.SetNativeData((void*) NULL); + + wxASSERT_MSG( (pd->hDevMode), "hDevMode must be non-NULL in ConvertToNative!"); + +// pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE)); + pd->Flags = PSD_MARGINS|PSD_MINMARGINS; + if ( m_defaultMinMargins ) pd->Flags |= PSD_DEFAULTMINMARGINS; if ( !m_enableMargins ) @@ -390,30 +961,34 @@ void wxPageSetupData::ConvertToNative() if ( m_enableHelp ) pd->Flags |= PSD_SHOWHELP; + // We want the units to be in hundredths of a millimetre + pd->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS; + pd->lStructSize = sizeof( PAGESETUPDLG ); pd->hwndOwner=(HWND)NULL; pd->hDevNames=(HWND)NULL; pd->hInstance=(HINSTANCE)NULL; - - pd->ptPaperSize.x = m_paperSize.x; - pd->ptPaperSize.y = m_paperSize.y; - - pd->rtMinMargin.left = m_minMarginTopLeft.x; - pd->rtMinMargin.top = m_minMarginTopLeft.y; - pd->rtMinMargin.right = m_minMarginBottomRight.x; - pd->rtMinMargin.bottom = m_minMarginBottomRight.y; - - pd->rtMargin.left = m_marginTopLeft.x; - pd->rtMargin.top = m_marginTopLeft.y; - pd->rtMargin.right = m_marginBottomRight.x; - pd->rtMargin.bottom = m_marginBottomRight.y; - + + pd->ptPaperSize.x = m_paperSize.x * 100; + pd->ptPaperSize.y = m_paperSize.y * 100; + + pd->rtMinMargin.left = m_minMarginTopLeft.x * 100; + pd->rtMinMargin.top = m_minMarginTopLeft.y * 100; + pd->rtMinMargin.right = m_minMarginBottomRight.x * 100; + pd->rtMinMargin.bottom = m_minMarginBottomRight.y * 100; + + pd->rtMargin.left = m_marginTopLeft.x * 100; + pd->rtMargin.top = m_marginTopLeft.y * 100; + pd->rtMargin.right = m_marginBottomRight.x * 100; + pd->rtMargin.bottom = m_marginBottomRight.y * 100; + pd->lCustData = 0; pd->lpfnPageSetupHook = NULL; pd->lpfnPagePaintHook = NULL; pd->hPageSetupTemplate = NULL; pd->lpPageSetupTemplateName = NULL; +/* if ( pd->hDevMode ) { DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode); @@ -423,16 +998,31 @@ void wxPageSetupData::ConvertToNative() devMode->dmFields = DM_ORIENTATION; GlobalUnlock(pd->hDevMode); } +*/ } -void wxPageSetupData::ConvertFromNative() +void wxPageSetupDialogData::ConvertFromNative() { PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ; if ( !pd ) return; + + // Pass the devmode data back to the wxPrintData structure where it really belongs. + if (pd->hDevMode) + { + if (m_printData.GetNativeData()) + { + // Make sure we don't leak memory + GlobalFree((HGLOBAL) m_printData.GetNativeData()); + } + m_printData.SetNativeData((void*) pd->hDevMode); + pd->hDevMode = NULL; + } - pd->Flags = PSD_MARGINS|PSD_MINMARGINS; + m_printData.ConvertFromNative(); + pd->Flags = PSD_MARGINS|PSD_MINMARGINS; + m_defaultMinMargins = ((pd->Flags & PSD_DEFAULTMINMARGINS) == PSD_DEFAULTMINMARGINS); m_enableMargins = ((pd->Flags & PSD_DISABLEMARGINS) != PSD_DISABLEMARGINS); m_enableOrientation = ((pd->Flags & PSD_DISABLEORIENTATION) != PSD_DISABLEORIENTATION); @@ -440,38 +1030,77 @@ void wxPageSetupData::ConvertFromNative() m_enablePrinter = ((pd->Flags & PSD_DISABLEPRINTER) != PSD_DISABLEPRINTER); m_getDefaultInfo = ((pd->Flags & PSD_RETURNDEFAULT) == PSD_RETURNDEFAULT); m_enableHelp = ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP); + + m_paperSize.x = pd->ptPaperSize.x / 100; + m_paperSize.y = pd->ptPaperSize.y / 100; + + m_minMarginTopLeft.x = pd->rtMinMargin.left / 100; + m_minMarginTopLeft.y = pd->rtMinMargin.top / 100; + m_minMarginBottomRight.x = pd->rtMinMargin.right / 100; + m_minMarginBottomRight.y = pd->rtMinMargin.bottom / 100; + + m_marginTopLeft.x = pd->rtMargin.left / 100 ; + m_marginTopLeft.y = pd->rtMargin.top / 100 ; + m_marginBottomRight.x = pd->rtMargin.right / 100 ; + m_marginBottomRight.y = pd->rtMargin.bottom / 100 ; +} - m_paperSize.x = pd->ptPaperSize.x ; - m_paperSize.y = pd->ptPaperSize.y ; +void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win) +{ + if ( m_pageSetupData == NULL ) + ConvertToNative(); + + if ( m_pageSetupData != NULL && win != NULL) + { + PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ; + pd->hwndOwner=(HWND) win->GetHWND(); + } +} +#endif - m_minMarginTopLeft.x = pd->rtMinMargin.left ; - m_minMarginTopLeft.y = pd->rtMinMargin.top ; - m_minMarginBottomRight.x = pd->rtMinMargin.right ; - m_minMarginBottomRight.y = pd->rtMinMargin.bottom ; +// If a corresponding paper type is found in the paper database, will set the m_printData +// paper size id member as well. +void wxPageSetupDialogData::SetPaperSize(const wxSize& sz) +{ + m_paperSize = sz; - m_marginTopLeft.x = pd->rtMargin.left ; - m_marginTopLeft.y = pd->rtMargin.top ; - m_marginBottomRight.x = pd->rtMargin.right ; - m_marginBottomRight.y = pd->rtMargin.bottom ; + CalculateIdFromPaperSize(); +} - if ( pd->hDevMode ) - { - DEVMODE *devMode = (DEVMODE*) GlobalLock(pd->hDevMode); - m_orientation = devMode->dmOrientation ; - GlobalUnlock(pd->hDevMode); - } +// Sets the wxPrintData id, plus the paper width/height if found in the paper database. +void wxPageSetupDialogData::SetPaperSize(wxPaperSize id) +{ + m_printData.SetPaperId(id); + + CalculatePaperSizeFromId(); } -void wxPageSetupData::SetOwnerWindow(wxWindow* win) +// Use paper size defined in this object to set the wxPrintData +// paper id +void wxPageSetupDialogData::CalculateIdFromPaperSize() { - if ( m_pageSetupData == NULL ) - ConvertToNative(); + wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL), "wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects." ); - if ( m_pageSetupData != NULL && win != NULL) + wxSize sz = GetPaperSize(); + + wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10)); + if (id != wxPAPER_NONE) { - PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageSetupData ; - pd->hwndOwner=(HWND) win->GetHWND(); + m_printData.SetPaperId(id); } } -#endif + +// Use paper id in wxPrintData to set this object's paper size +void wxPageSetupDialogData::CalculatePaperSizeFromId() +{ + wxASSERT_MSG( (wxThePrintPaperDatabase != (wxPrintPaperDatabase*) NULL), "wxThePrintPaperDatabase should not be NULL. Do not create global print dialog data objects." ); + + wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId()); + if (sz.x != 0) + { + // sz is in 10ths of a mm, so multiply by 10. + m_paperSize.x = sz.x * 10; + m_paperSize.y = sz.y * 10; + } +} diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 01f8ebe21a..e1cebc28d1 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -762,10 +762,10 @@ void wxDocManager::OnPrintSetup(wxCommandEvent& WXUNUSED(event)) if (view) parentWin = view->GetFrame(); - wxPrintData data; + wxPrintDialogData data; wxPrintDialog printerDialog(parentWin, & data); - printerDialog.GetPrintData().SetSetupDialog(TRUE); + printerDialog.GetPrintDialogData().SetSetupDialog(TRUE); printerDialog.ShowModal(); } diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index c85848e897..be9ab9a52f 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -58,7 +58,7 @@ #endif #endif - // End __WXMSW__ +// End __WXMSW__ #if !USE_SHARED_LIBRARY IMPLEMENT_CLASS(wxPrinterBase, wxObject) @@ -67,29 +67,28 @@ IMPLEMENT_CLASS(wxPreviewCanvas, wxWindow) IMPLEMENT_CLASS(wxPreviewControlBar, wxWindow) IMPLEMENT_CLASS(wxPreviewFrame, wxFrame) IMPLEMENT_CLASS(wxPrintPreviewBase, wxObject) -IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType, wxObject) BEGIN_EVENT_TABLE(wxPrintAbortDialog, wxDialog) - EVT_BUTTON(wxID_CANCEL, wxPrintAbortDialog::OnCancel) +EVT_BUTTON(wxID_CANCEL, wxPrintAbortDialog::OnCancel) END_EVENT_TABLE() BEGIN_EVENT_TABLE(wxPreviewCanvas, wxScrolledWindow) - EVT_PAINT(wxPreviewCanvas::OnPaint) - EVT_SYS_COLOUR_CHANGED(wxPreviewCanvas::OnSysColourChanged) +EVT_PAINT(wxPreviewCanvas::OnPaint) +EVT_SYS_COLOUR_CHANGED(wxPreviewCanvas::OnSysColourChanged) END_EVENT_TABLE() #endif /* - * Printer - */ - -wxPrinterBase::wxPrinterBase(wxPrintData *data) +* Printer +*/ + +wxPrinterBase::wxPrinterBase(wxPrintDialogData *data) { - m_currentPrintout = (wxPrintout *) NULL; - sm_abortWindow = (wxWindow *) NULL; - sm_abortIt = FALSE; - if (data) - m_printData = (*data); + m_currentPrintout = (wxPrintout *) NULL; + sm_abortWindow = (wxWindow *) NULL; + sm_abortIt = FALSE; + if (data) + m_printDialogData = (*data); } wxWindow *wxPrinterBase::sm_abortWindow = (wxWindow *) NULL; @@ -101,48 +100,48 @@ wxPrinterBase::~wxPrinterBase() void wxPrintAbortDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) { - wxPrinterBase::sm_abortIt = TRUE; - wxPrinterBase::sm_abortWindow->Show(FALSE); - wxPrinterBase::sm_abortWindow->Close(TRUE); - wxPrinterBase::sm_abortWindow = (wxWindow *) NULL; + wxPrinterBase::sm_abortIt = TRUE; + wxPrinterBase::sm_abortWindow->Show(FALSE); + wxPrinterBase::sm_abortWindow->Close(TRUE); + wxPrinterBase::sm_abortWindow = (wxWindow *) NULL; } wxWindow *wxPrinterBase::CreateAbortWindow(wxWindow *parent, wxPrintout *WXUNUSED(printout)) { - wxPrintAbortDialog *dialog = new wxPrintAbortDialog(parent, _("Printing"), wxPoint(0, 0), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE); - (void) new wxStaticText(dialog, -1, _("Please wait..."), wxPoint(5, 5)); - - wxButton *button = new wxButton(dialog, wxID_CANCEL, _("Cancel"), wxPoint(5, 30)); - - dialog->Fit(); - button->Centre(wxHORIZONTAL); - - dialog->Centre(); - return dialog; + wxPrintAbortDialog *dialog = new wxPrintAbortDialog(parent, _("Printing"), wxPoint(0, 0), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE); + (void) new wxStaticText(dialog, -1, _("Please wait..."), wxPoint(5, 5)); + + wxButton *button = new wxButton(dialog, wxID_CANCEL, _("Cancel"), wxPoint(5, 30)); + + dialog->Fit(); + button->Centre(wxHORIZONTAL); + + dialog->Centre(); + return dialog; } void wxPrinterBase::ReportError(wxWindow *parent, wxPrintout *WXUNUSED(printout), char *message) { - wxMessageBox(message, _("Printing Error"), wxOK, parent); + wxMessageBox(message, _("Printing Error"), wxOK, parent); } /* - * Printout class - */ - +* Printout class +*/ + wxPrintout::wxPrintout(const wxString& title) { - m_printoutTitle = title ; - m_printoutDC = (wxDC *) NULL; - m_pageWidthMM = 0; - m_pageHeightMM = 0; - m_pageWidthPixels = 0; - m_pageHeightPixels = 0; - m_PPIScreenX = 0; - m_PPIScreenY = 0; - m_PPIPrinterX = 0; - m_PPIPrinterY = 0; - m_isPreview = FALSE; + m_printoutTitle = title ; + m_printoutDC = (wxDC *) NULL; + m_pageWidthMM = 0; + m_pageHeightMM = 0; + m_pageWidthPixels = 0; + m_pageHeightPixels = 0; + m_PPIScreenX = 0; + m_PPIScreenY = 0; + m_PPIPrinterX = 0; + m_PPIPrinterY = 0; + m_isPreview = FALSE; } wxPrintout::~wxPrintout() @@ -151,12 +150,12 @@ wxPrintout::~wxPrintout() bool wxPrintout::OnBeginDocument(int WXUNUSED(startPage), int WXUNUSED(endPage)) { - return GetDC()->StartDoc(_("Printing")); + return GetDC()->StartDoc(_("Printing")); } void wxPrintout::OnEndDocument() { - GetDC()->EndDoc(); + GetDC()->EndDoc(); } void wxPrintout::OnBeginPrinting() @@ -169,29 +168,29 @@ void wxPrintout::OnEndPrinting() bool wxPrintout::HasPage(int page) { - return (page == 1); + return (page == 1); } void wxPrintout::GetPageInfo(int *minPage, int *maxPage, int *fromPage, int *toPage) { - *minPage = 1; - *maxPage = 32000; - *fromPage = 1; - *toPage = 1; + *minPage = 1; + *maxPage = 32000; + *fromPage = 1; + *toPage = 1; } /* - * Preview canvas - */ - +* Preview canvas +*/ + wxPreviewCanvas::wxPreviewCanvas(wxPrintPreviewBase *preview, wxWindow *parent, - const wxPoint& pos, const wxSize& size, long style, const wxString& name): - wxScrolledWindow(parent, -1, pos, size, style, name) + const wxPoint& pos, const wxSize& size, long style, const wxString& name): +wxScrolledWindow(parent, -1, pos, size, style, name) { - m_printPreview = preview; - SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); - - SetScrollbars(15, 18, 100, 100); + m_printPreview = preview; + SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); + + SetScrollbars(15, 18, 100, 100); } wxPreviewCanvas::~wxPreviewCanvas() @@ -200,50 +199,50 @@ wxPreviewCanvas::~wxPreviewCanvas() void wxPreviewCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { - wxPaintDC dc(this); - PrepareDC( dc ); - - if (m_printPreview) - { - m_printPreview->PaintPage(this, dc); - } + wxPaintDC dc(this); + PrepareDC( dc ); + + if (m_printPreview) + { + m_printPreview->PaintPage(this, dc); + } } // Responds to colour changes, and passes event on to children. void wxPreviewCanvas::OnSysColourChanged(wxSysColourChangedEvent& event) { - SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); - Refresh(); - - // Propagate the event to the non-top-level children - wxWindow::OnSysColourChanged(event); + SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); + Refresh(); + + // Propagate the event to the non-top-level children + wxWindow::OnSysColourChanged(event); } /* - * Preview control bar - */ +* Preview control bar +*/ BEGIN_EVENT_TABLE(wxPreviewControlBar, wxPanel) - EVT_BUTTON(wxID_PREVIEW_CLOSE, wxPreviewControlBar::OnWindowClose) - EVT_BUTTON(wxID_PREVIEW_PRINT, wxPreviewControlBar::OnPrint) - EVT_BUTTON(wxID_PREVIEW_PREVIOUS, wxPreviewControlBar::OnPrevious) - EVT_BUTTON(wxID_PREVIEW_NEXT, wxPreviewControlBar::OnNext) - EVT_CHOICE(wxID_PREVIEW_ZOOM, wxPreviewControlBar::OnZoom) - EVT_PAINT(wxPreviewControlBar::OnPaint) +EVT_BUTTON(wxID_PREVIEW_CLOSE, wxPreviewControlBar::OnWindowClose) +EVT_BUTTON(wxID_PREVIEW_PRINT, wxPreviewControlBar::OnPrint) +EVT_BUTTON(wxID_PREVIEW_PREVIOUS, wxPreviewControlBar::OnPrevious) +EVT_BUTTON(wxID_PREVIEW_NEXT, wxPreviewControlBar::OnNext) +EVT_CHOICE(wxID_PREVIEW_ZOOM, wxPreviewControlBar::OnZoom) +EVT_PAINT(wxPreviewControlBar::OnPaint) END_EVENT_TABLE() - + wxPreviewControlBar::wxPreviewControlBar(wxPrintPreviewBase *preview, long buttons, - wxWindow *parent, const wxPoint& pos, const wxSize& size, - long style, const wxString& name): - wxPanel(parent, -1, pos, size, style, name) + wxWindow *parent, const wxPoint& pos, const wxSize& size, + long style, const wxString& name): +wxPanel(parent, -1, pos, size, style, name) { - m_printPreview = preview; - m_closeButton = (wxButton *) NULL; - m_nextPageButton = (wxButton *) NULL; - m_previousPageButton = (wxButton *) NULL; - m_printButton = (wxButton *) NULL; - m_zoomControl = (wxChoice *) NULL; - m_buttonFlags = buttons; + m_printPreview = preview; + m_closeButton = (wxButton *) NULL; + m_nextPageButton = (wxButton *) NULL; + m_previousPageButton = (wxButton *) NULL; + m_printButton = (wxButton *) NULL; + m_zoomControl = (wxChoice *) NULL; + m_buttonFlags = buttons; } wxPreviewControlBar::~wxPreviewControlBar() @@ -252,196 +251,196 @@ wxPreviewControlBar::~wxPreviewControlBar() void wxPreviewControlBar::OnPaint(wxPaintEvent& WXUNUSED(event)) { - wxPaintDC dc(this); - - int w, h; - GetSize(&w, &h); - dc.SetPen(*wxBLACK_PEN); - dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.DrawLine( 0, h-1, w, h-1 ); + wxPaintDC dc(this); + + int w, h; + GetSize(&w, &h); + dc.SetPen(*wxBLACK_PEN); + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.DrawLine( 0, h-1, w, h-1 ); } void wxPreviewControlBar::OnWindowClose(wxCommandEvent& WXUNUSED(event)) { - wxPreviewFrame *frame = (wxPreviewFrame *)GetParent(); - frame->Close(TRUE); + wxPreviewFrame *frame = (wxPreviewFrame *)GetParent(); + frame->Close(TRUE); } void wxPreviewControlBar::OnPrint(wxCommandEvent& WXUNUSED(event)) { - wxPrintPreviewBase *preview = GetPrintPreview(); - preview->Print(TRUE); + wxPrintPreviewBase *preview = GetPrintPreview(); + preview->Print(TRUE); } void wxPreviewControlBar::OnNext(wxCommandEvent& WXUNUSED(event)) { - wxPrintPreviewBase *preview = GetPrintPreview(); - if (preview) - { - int currentPage = preview->GetCurrentPage(); - if ((preview->GetMaxPage() > 0) && - (currentPage < preview->GetMaxPage()) && - preview->GetPrintout()->HasPage(currentPage + 1)) + wxPrintPreviewBase *preview = GetPrintPreview(); + if (preview) { - preview->SetCurrentPage(currentPage + 1); + int currentPage = preview->GetCurrentPage(); + if ((preview->GetMaxPage() > 0) && + (currentPage < preview->GetMaxPage()) && + preview->GetPrintout()->HasPage(currentPage + 1)) + { + preview->SetCurrentPage(currentPage + 1); + } } - } } void wxPreviewControlBar::OnPrevious(wxCommandEvent& WXUNUSED(event)) { - wxPrintPreviewBase *preview = GetPrintPreview(); - if (preview) - { - int currentPage = preview->GetCurrentPage(); - if ((preview->GetMinPage() > 0) && - (currentPage > preview->GetMinPage()) && - preview->GetPrintout()->HasPage(currentPage - 1)) + wxPrintPreviewBase *preview = GetPrintPreview(); + if (preview) { - preview->SetCurrentPage(currentPage - 1); + int currentPage = preview->GetCurrentPage(); + if ((preview->GetMinPage() > 0) && + (currentPage > preview->GetMinPage()) && + preview->GetPrintout()->HasPage(currentPage - 1)) + { + preview->SetCurrentPage(currentPage - 1); + } } - } } void wxPreviewControlBar::OnZoom(wxCommandEvent& WXUNUSED(event)) { - int zoom = GetZoomControl(); - if (GetPrintPreview()) - GetPrintPreview()->SetZoom(zoom); + int zoom = GetZoomControl(); + if (GetPrintPreview()) + GetPrintPreview()->SetZoom(zoom); } void wxPreviewControlBar::CreateButtons() { - SetSize(0, 0, 400, 40); - - /* -#ifdef __WXMSW__ - int fontSize = 9; -#else - int fontSize = 10; -#endif - - wxFont buttonFont(fontSize, wxSWISS, wxNORMAL, wxBOLD); - SetFont(buttonFont); - */ - - int buttonWidth = 65; + SetSize(0, 0, 400, 40); + + /* + #ifdef __WXMSW__ + int fontSize = 9; + #else + int fontSize = 10; + #endif + + wxFont buttonFont(fontSize, wxSWISS, wxNORMAL, wxBOLD); + SetFont(buttonFont); + */ + + int buttonWidth = 65; #ifdef __WXGTK__ int buttonHeight = -1; #else int buttonHeight = 24; #endif - - int x = 5; - int y = 5; - + + int x = 5; + int y = 5; + #ifdef __WXMOTIF__ - int gap = 15; + int gap = 15; #else - int gap = 5; + int gap = 5; #endif - - m_closeButton = new wxButton(this, wxID_PREVIEW_CLOSE, _("Close"), - wxPoint(x, y), wxSize(buttonWidth, buttonHeight)); - - x += gap + buttonWidth; - - if (m_buttonFlags & wxPREVIEW_PRINT) - { - m_printButton = new wxButton(this, wxID_PREVIEW_PRINT, _("Print..."), wxPoint(x, y), - wxSize(buttonWidth, buttonHeight)); - x += gap + buttonWidth; - } - - if (m_buttonFlags & wxPREVIEW_PREVIOUS) - { - m_previousPageButton = new wxButton(this, wxID_PREVIEW_PREVIOUS, "<<", wxPoint(x, y), - wxSize(buttonWidth, buttonHeight)); - x += gap + buttonWidth; - } - - if (m_buttonFlags & wxPREVIEW_NEXT) - { - m_nextPageButton = new wxButton(this, wxID_PREVIEW_NEXT, ">>", - wxPoint(x, y), wxSize(buttonWidth, buttonHeight)); - x += gap + buttonWidth; - } - - // Yes, this look stupid, but this is because gcc gives up otherwise. - wxString *choices = new wxString[23]; - choices[0] = "10%"; - choices[1] = "15%"; - choices[2] = "20%"; - choices[3] = "25%"; - choices[4] = "30%"; - choices[5] = "35%"; - choices[6] = "40%"; - choices[7] = "45%"; - choices[8] = "50%"; - choices[9] = "55%"; - choices[10] = "60%"; - choices[11] = "65%"; - choices[12] = "70%"; - choices[13] = "75%"; - choices[14] = "80%"; - choices[15] = "85%"; - choices[16] = "90%"; - choices[17] = "95%"; - choices[18] = "100%"; - choices[19] = "110%"; - choices[20] = "120%"; - choices[21] = "150%"; - choices[22] = "200%"; - - int n = 23; - if (m_buttonFlags & wxPREVIEW_ZOOM) - { - m_zoomControl = new wxChoice(this, wxID_PREVIEW_ZOOM, wxPoint(x, y), - wxSize(100, -1), n, (wxString *)choices); - SetZoomControl(m_printPreview->GetZoom()); - } - - delete[] choices; - - // m_closeButton->SetDefault(); + + m_closeButton = new wxButton(this, wxID_PREVIEW_CLOSE, _("Close"), + wxPoint(x, y), wxSize(buttonWidth, buttonHeight)); + + x += gap + buttonWidth; + + if (m_buttonFlags & wxPREVIEW_PRINT) + { + m_printButton = new wxButton(this, wxID_PREVIEW_PRINT, _("Print..."), wxPoint(x, y), + wxSize(buttonWidth, buttonHeight)); + x += gap + buttonWidth; + } + + if (m_buttonFlags & wxPREVIEW_PREVIOUS) + { + m_previousPageButton = new wxButton(this, wxID_PREVIEW_PREVIOUS, "<<", wxPoint(x, y), + wxSize(buttonWidth, buttonHeight)); + x += gap + buttonWidth; + } + + if (m_buttonFlags & wxPREVIEW_NEXT) + { + m_nextPageButton = new wxButton(this, wxID_PREVIEW_NEXT, ">>", + wxPoint(x, y), wxSize(buttonWidth, buttonHeight)); + x += gap + buttonWidth; + } + + // Yes, this look stupid, but this is because gcc gives up otherwise. + wxString *choices = new wxString[23]; + choices[0] = "10%"; + choices[1] = "15%"; + choices[2] = "20%"; + choices[3] = "25%"; + choices[4] = "30%"; + choices[5] = "35%"; + choices[6] = "40%"; + choices[7] = "45%"; + choices[8] = "50%"; + choices[9] = "55%"; + choices[10] = "60%"; + choices[11] = "65%"; + choices[12] = "70%"; + choices[13] = "75%"; + choices[14] = "80%"; + choices[15] = "85%"; + choices[16] = "90%"; + choices[17] = "95%"; + choices[18] = "100%"; + choices[19] = "110%"; + choices[20] = "120%"; + choices[21] = "150%"; + choices[22] = "200%"; + + int n = 23; + if (m_buttonFlags & wxPREVIEW_ZOOM) + { + m_zoomControl = new wxChoice(this, wxID_PREVIEW_ZOOM, wxPoint(x, y), + wxSize(100, -1), n, (wxString *)choices); + SetZoomControl(m_printPreview->GetZoom()); + } + + delete[] choices; + + // m_closeButton->SetDefault(); } void wxPreviewControlBar::SetZoomControl(int zoom) { - char buf[20]; - sprintf(buf, "%d%%", zoom); - if (m_zoomControl) - m_zoomControl->SetStringSelection(buf); + char buf[20]; + sprintf(buf, "%d%%", zoom); + if (m_zoomControl) + m_zoomControl->SetStringSelection(buf); } int wxPreviewControlBar::GetZoomControl() { - char buf[20]; - if (m_zoomControl && (m_zoomControl->GetStringSelection() != "")) - { - strcpy(buf, m_zoomControl->GetStringSelection()); - buf[strlen(buf) - 1] = 0; - return (int)atoi(buf); - } - else return 0; + char buf[20]; + if (m_zoomControl && (m_zoomControl->GetStringSelection() != "")) + { + strcpy(buf, m_zoomControl->GetStringSelection()); + buf[strlen(buf) - 1] = 0; + return (int)atoi(buf); + } + else return 0; } /* - * Preview frame - */ +* Preview frame +*/ BEGIN_EVENT_TABLE(wxPreviewFrame, wxFrame) - EVT_CLOSE(wxPreviewFrame::OnCloseWindow) +EVT_CLOSE(wxPreviewFrame::OnCloseWindow) END_EVENT_TABLE() wxPreviewFrame::wxPreviewFrame(wxPrintPreviewBase *preview, wxFrame *parent, const wxString& title, - const wxPoint& pos, const wxSize& size, long style, const wxString& name): - wxFrame(parent, -1, title, pos, size, style, name) + const wxPoint& pos, const wxSize& size, long style, const wxString& name): +wxFrame(parent, -1, title, pos, size, style, name) { - m_printPreview = preview; - m_controlBar = NULL; - m_previewCanvas = NULL; + m_printPreview = preview; + m_controlBar = NULL; + m_previewCanvas = NULL; } wxPreviewFrame::~wxPreviewFrame() @@ -450,431 +449,313 @@ wxPreviewFrame::~wxPreviewFrame() void wxPreviewFrame::OnCloseWindow(wxCloseEvent& event) { - MakeModal(FALSE); - - // Need to delete the printout and the print preview - wxPrintout *printout = m_printPreview->GetPrintout(); - if (printout) - { - delete printout; - m_printPreview->SetPrintout(NULL); - m_printPreview->SetCanvas(NULL); - m_printPreview->SetFrame(NULL); - } - delete m_printPreview; - - Destroy(); + MakeModal(FALSE); + + // Need to delete the printout and the print preview + wxPrintout *printout = m_printPreview->GetPrintout(); + if (printout) + { + delete printout; + m_printPreview->SetPrintout(NULL); + m_printPreview->SetCanvas(NULL); + m_printPreview->SetFrame(NULL); + } + delete m_printPreview; + + Destroy(); } void wxPreviewFrame::Initialize() { - CreateStatusBar(); - - CreateCanvas(); - CreateControlBar(); - - m_printPreview->SetCanvas(m_previewCanvas); - m_printPreview->SetFrame(this); - - // Set layout constraints here - - // Control bar constraints - wxLayoutConstraints *c1 = new wxLayoutConstraints; -// int w, h; -// m_controlBar->GetSize(&w, &h); - int h; + CreateStatusBar(); + + CreateCanvas(); + CreateControlBar(); + + m_printPreview->SetCanvas(m_previewCanvas); + m_printPreview->SetFrame(this); + + // Set layout constraints here + + // Control bar constraints + wxLayoutConstraints *c1 = new wxLayoutConstraints; + // int w, h; + // m_controlBar->GetSize(&w, &h); + int h; #if (defined(__WXMSW__) || defined(__WXGTK__)) - h = 40; + h = 40; #else - h = 60; + h = 60; #endif - - c1->left.SameAs (this, wxLeft); - c1->top.SameAs (this, wxTop); - c1->right.SameAs (this, wxRight); - c1->height.Absolute (h); - - m_controlBar->SetConstraints(c1); - - // Canvas constraints - wxLayoutConstraints *c2 = new wxLayoutConstraints; - - c2->left.SameAs (this, wxLeft); - c2->top.Below (m_controlBar); - c2->right.SameAs (this, wxRight); - c2->bottom.SameAs (this, wxBottom); - - m_previewCanvas->SetConstraints(c2); - - SetAutoLayout(TRUE); - - MakeModal(TRUE); - - Layout(); + + c1->left.SameAs (this, wxLeft); + c1->top.SameAs (this, wxTop); + c1->right.SameAs (this, wxRight); + c1->height.Absolute (h); + + m_controlBar->SetConstraints(c1); + + // Canvas constraints + wxLayoutConstraints *c2 = new wxLayoutConstraints; + + c2->left.SameAs (this, wxLeft); + c2->top.Below (m_controlBar); + c2->right.SameAs (this, wxRight); + c2->bottom.SameAs (this, wxBottom); + + m_previewCanvas->SetConstraints(c2); + + SetAutoLayout(TRUE); + + MakeModal(TRUE); + + Layout(); } void wxPreviewFrame::CreateCanvas() { - m_previewCanvas = new wxPreviewCanvas(m_printPreview, this); + m_previewCanvas = new wxPreviewCanvas(m_printPreview, this); } void wxPreviewFrame::CreateControlBar() { - long buttons = wxPREVIEW_DEFAULT; - if (m_printPreview->GetPrintoutForPrinting()) - buttons |= wxPREVIEW_PRINT; + long buttons = wxPREVIEW_DEFAULT; + if (m_printPreview->GetPrintoutForPrinting()) + buttons |= wxPREVIEW_PRINT; - m_controlBar = new wxPreviewControlBar(m_printPreview, buttons, this, wxPoint(0, 0), wxSize(400, 40)); - m_controlBar->CreateButtons(); + m_controlBar = new wxPreviewControlBar(m_printPreview, buttons, this, wxPoint(0, 0), wxSize(400, 40)); + m_controlBar->CreateButtons(); } - + /* - * Print preview - */ +* Print preview +*/ -wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data) +wxPrintPreviewBase::wxPrintPreviewBase(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintDialogData *data) { - m_isOk = TRUE; - m_previewPrintout = printout; - if (m_previewPrintout) - m_previewPrintout->SetIsPreview(TRUE); + m_isOk = TRUE; + m_previewPrintout = printout; + if (m_previewPrintout) + m_previewPrintout->SetIsPreview(TRUE); - m_printPrintout = printoutForPrinting; - if (data) - m_printData = (*data); - - m_previewCanvas = NULL; - m_previewFrame = NULL; - m_previewBitmap = NULL; - m_currentPage = 1; - m_currentZoom = 30; - m_topMargin = 40; - m_leftMargin = 40; - m_pageWidth = 0; - m_pageHeight = 0; - - printout->OnPreparePrinting(); - - // Get some parameters from the printout, if defined - int selFrom, selTo; - printout->GetPageInfo(&m_minPage, &m_maxPage, &selFrom, &selTo); + m_printPrintout = printoutForPrinting; + if (data) + m_printDialogData = (*data); + + m_previewCanvas = NULL; + m_previewFrame = NULL; + m_previewBitmap = NULL; + m_currentPage = 1; + m_currentZoom = 30; + m_topMargin = 40; + m_leftMargin = 40; + m_pageWidth = 0; + m_pageHeight = 0; + + printout->OnPreparePrinting(); + + // Get some parameters from the printout, if defined + int selFrom, selTo; + printout->GetPageInfo(&m_minPage, &m_maxPage, &selFrom, &selTo); } wxPrintPreviewBase::~wxPrintPreviewBase() { - if (m_previewPrintout) - delete m_previewPrintout; - if (m_previewBitmap) - delete m_previewBitmap; - if (m_printPrintout) - delete m_printPrintout; + if (m_previewPrintout) + delete m_previewPrintout; + if (m_previewBitmap) + delete m_previewBitmap; + if (m_printPrintout) + delete m_printPrintout; } bool wxPrintPreviewBase::SetCurrentPage(int pageNum) { - if (m_currentPage == pageNum) + if (m_currentPage == pageNum) + return TRUE; + + m_currentPage = pageNum; + if (m_previewBitmap) + { + delete m_previewBitmap; + m_previewBitmap = NULL; + } + + if (m_previewCanvas) + { + RenderPage(pageNum); + m_previewCanvas->Refresh(); + } return TRUE; - - m_currentPage = pageNum; - if (m_previewBitmap) - { - delete m_previewBitmap; - m_previewBitmap = NULL; - } - - if (m_previewCanvas) - { - RenderPage(pageNum); - m_previewCanvas->Refresh(); - } - return TRUE; } bool wxPrintPreviewBase::PaintPage(wxWindow *canvas, wxDC& dc) { - DrawBlankPage(canvas, dc); - - if (!m_previewBitmap) - RenderPage(m_currentPage); + DrawBlankPage(canvas, dc); - if (!m_previewBitmap) - return FALSE; - - if (!canvas) - return FALSE; - - int canvasWidth, canvasHeight; - canvas->GetSize(&canvasWidth, &canvasHeight); - - double zoomScale = ((float)m_currentZoom/(float)100); - double actualWidth = (zoomScale*m_pageWidth*m_previewScale); -// float actualHeight = (float)(zoomScale*m_pageHeight*m_previewScale); - - int x = (int) ((canvasWidth - actualWidth)/2.0); - if (x < m_leftMargin) - x = m_leftMargin; - int y = m_topMargin; - - wxMemoryDC temp_dc; - temp_dc.SelectObject(*m_previewBitmap); - - dc.Blit(x, y, m_previewBitmap->GetWidth(), m_previewBitmap->GetHeight(), &temp_dc, 0, 0); - - temp_dc.SelectObject(wxNullBitmap); - - return TRUE; + if (!m_previewBitmap) + RenderPage(m_currentPage); + + if (!m_previewBitmap) + return FALSE; + + if (!canvas) + return FALSE; + + int canvasWidth, canvasHeight; + canvas->GetSize(&canvasWidth, &canvasHeight); + + double zoomScale = ((float)m_currentZoom/(float)100); + double actualWidth = (zoomScale*m_pageWidth*m_previewScale); + // float actualHeight = (float)(zoomScale*m_pageHeight*m_previewScale); + + int x = (int) ((canvasWidth - actualWidth)/2.0); + if (x < m_leftMargin) + x = m_leftMargin; + int y = m_topMargin; + + wxMemoryDC temp_dc; + temp_dc.SelectObject(*m_previewBitmap); + + dc.Blit(x, y, m_previewBitmap->GetWidth(), m_previewBitmap->GetHeight(), &temp_dc, 0, 0); + + temp_dc.SelectObject(wxNullBitmap); + + return TRUE; } bool wxPrintPreviewBase::RenderPage(int pageNum) { - int canvasWidth, canvasHeight; - - if (!m_previewCanvas) - { - wxMessageBox(_("wxPrintPreviewBase::RenderPage: must use wxPrintPreviewBase::SetCanvas to let me know about the canvas!"), - _("Print Preview Failure"), wxOK); - return FALSE; - } - m_previewCanvas->GetSize(&canvasWidth, &canvasHeight); - - double zoomScale = (m_currentZoom/100.0); - int actualWidth = (int)(zoomScale*m_pageWidth*m_previewScale); - int actualHeight = (int)(zoomScale*m_pageHeight*m_previewScale); - - int x = (int)((canvasWidth - actualWidth)/2.0); - if (x < m_leftMargin) - x = m_leftMargin; -// int y = m_topMargin; - - - if (!m_previewBitmap) - { - m_previewBitmap = new wxBitmap((int)actualWidth, (int)actualHeight); - if (!m_previewBitmap || !m_previewBitmap->Ok()) + int canvasWidth, canvasHeight; + + if (!m_previewCanvas) { - if (m_previewBitmap) - delete m_previewBitmap; - wxMessageBox(_("Sorry, not enough memory to create a preview."), _("Print Preview Failure"), wxOK); - return FALSE; + wxMessageBox(_("wxPrintPreviewBase::RenderPage: must use wxPrintPreviewBase::SetCanvas to let me know about the canvas!"), + _("Print Preview Failure"), wxOK); + return FALSE; } - } - - wxMemoryDC memoryDC; - memoryDC.SelectObject(*m_previewBitmap); - - memoryDC.Clear(); - - m_previewPrintout->SetDC(&memoryDC); - m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); - - m_previewPrintout->OnBeginPrinting(); - + m_previewCanvas->GetSize(&canvasWidth, &canvasHeight); + + double zoomScale = (m_currentZoom/100.0); + int actualWidth = (int)(zoomScale*m_pageWidth*m_previewScale); + int actualHeight = (int)(zoomScale*m_pageHeight*m_previewScale); + + int x = (int)((canvasWidth - actualWidth)/2.0); + if (x < m_leftMargin) + x = m_leftMargin; + // int y = m_topMargin; + + + if (!m_previewBitmap) + { + m_previewBitmap = new wxBitmap((int)actualWidth, (int)actualHeight); + if (!m_previewBitmap || !m_previewBitmap->Ok()) + { + if (m_previewBitmap) + delete m_previewBitmap; + wxMessageBox(_("Sorry, not enough memory to create a preview."), _("Print Preview Failure"), wxOK); + return FALSE; + } + } + + wxMemoryDC memoryDC; + memoryDC.SelectObject(*m_previewBitmap); + + memoryDC.Clear(); + + m_previewPrintout->SetDC(&memoryDC); + m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); + + m_previewPrintout->OnBeginPrinting(); - if (!m_previewPrintout->OnBeginDocument(m_printData.GetFromPage(), m_printData.GetToPage())) - { - wxMessageBox(_("Could not start document preview."), _("Print Preview Failure"), wxOK); + if (!m_previewPrintout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage())) + { + wxMessageBox(_("Could not start document preview."), _("Print Preview Failure"), wxOK); + + memoryDC.SelectObject(wxNullBitmap); + + delete m_previewBitmap; + return FALSE; + } + + m_previewPrintout->OnPrintPage(pageNum); + m_previewPrintout->OnEndDocument(); + m_previewPrintout->OnEndPrinting(); + + m_previewPrintout->SetDC(NULL); memoryDC.SelectObject(wxNullBitmap); - - delete m_previewBitmap; - return FALSE; - } - - m_previewPrintout->OnPrintPage(pageNum); - m_previewPrintout->OnEndDocument(); - m_previewPrintout->OnEndPrinting(); - - m_previewPrintout->SetDC(NULL); - - memoryDC.SelectObject(wxNullBitmap); - - char buf[200]; - if (m_maxPage != 0) - sprintf(buf, _("Page %d of %d"), pageNum, m_maxPage); - else - sprintf(buf, _("Page %d"), pageNum); - - if (m_previewFrame) - m_previewFrame->SetStatusText(buf); - - return TRUE; + + char buf[200]; + if (m_maxPage != 0) + sprintf(buf, _("Page %d of %d"), pageNum, m_maxPage); + else + sprintf(buf, _("Page %d"), pageNum); + + if (m_previewFrame) + m_previewFrame->SetStatusText(buf); + + return TRUE; } bool wxPrintPreviewBase::DrawBlankPage(wxWindow *canvas, wxDC& dc) { - int canvasWidth, canvasHeight; - canvas->GetSize(&canvasWidth, &canvasHeight); - - float zoomScale = (float)((float)m_currentZoom/(float)100); - float actualWidth = zoomScale*m_pageWidth*m_previewScale; - float actualHeight = zoomScale*m_pageHeight*m_previewScale; - - float x = (float)((canvasWidth - actualWidth)/2.0); - if (x < m_leftMargin) - x = (float)m_leftMargin; - float y = (float)m_topMargin; - - // Draw shadow, allowing for 1-pixel border AROUND the actual page - int shadowOffset = 4; - dc.SetPen(*wxBLACK_PEN); - dc.SetBrush(*wxBLACK_BRUSH); -/* - dc.DrawRectangle((int)(x-1 + shadowOffset), (int)(y-1 + shadowOffset), (int)(actualWidth+2), (int)(actualHeight+2)); -*/ - dc.DrawRectangle((int)(x + shadowOffset), (int)(y + actualHeight+1), (int)(actualWidth), shadowOffset); - dc.DrawRectangle((int)(x + actualWidth), (int)(y + shadowOffset), shadowOffset, (int)(actualHeight)); - - // Draw blank page allowing for 1-pixel border AROUND the actual page - dc.SetPen(*wxBLACK_PEN); - dc.SetBrush(*wxWHITE_BRUSH); - -/* - wxRegion update_region = canvas->GetUpdateRegion(); - wxRect r = update_region.GetBox(); - - printf( "x: %d y: %d w: %d h: %d.\n", (int)r.x, (int)r.y, (int)r.width, (int)r.height ); -*/ - - dc.DrawRectangle((int)(x-2), (int)(y-1), (int)(actualWidth+3), (int)(actualHeight+2)); - - return TRUE; -} - -void wxPrintPreviewBase::SetZoom(int percent) -{ - if (m_currentZoom == percent) - return; + int canvasWidth, canvasHeight; + canvas->GetSize(&canvasWidth, &canvasHeight); + + float zoomScale = (float)((float)m_currentZoom/(float)100); + float actualWidth = zoomScale*m_pageWidth*m_previewScale; + float actualHeight = zoomScale*m_pageHeight*m_previewScale; + + float x = (float)((canvasWidth - actualWidth)/2.0); + if (x < m_leftMargin) + x = (float)m_leftMargin; + float y = (float)m_topMargin; + + // Draw shadow, allowing for 1-pixel border AROUND the actual page + int shadowOffset = 4; + dc.SetPen(*wxBLACK_PEN); + dc.SetBrush(*wxBLACK_BRUSH); + /* + dc.DrawRectangle((int)(x-1 + shadowOffset), (int)(y-1 + shadowOffset), (int)(actualWidth+2), (int)(actualHeight+2)); + */ + dc.DrawRectangle((int)(x + shadowOffset), (int)(y + actualHeight+1), (int)(actualWidth), shadowOffset); + dc.DrawRectangle((int)(x + actualWidth), (int)(y + shadowOffset), shadowOffset, (int)(actualHeight)); + + // Draw blank page allowing for 1-pixel border AROUND the actual page + dc.SetPen(*wxBLACK_PEN); + dc.SetBrush(*wxWHITE_BRUSH); + + /* + wxRegion update_region = canvas->GetUpdateRegion(); + wxRect r = update_region.GetBox(); + + printf( "x: %d y: %d w: %d h: %d.\n", (int)r.x, (int)r.y, (int)r.width, (int)r.height ); + */ + + dc.DrawRectangle((int)(x-2), (int)(y-1), (int)(actualWidth+3), (int)(actualHeight+2)); - m_currentZoom = percent; - if (m_previewBitmap) - { - delete m_previewBitmap; - m_previewBitmap = NULL; - } - RenderPage(m_currentPage); - - if (m_previewCanvas) - { - m_previewCanvas->Clear(); - m_previewCanvas->Refresh(); - } -} - -/* - * Paper size database for PostScript or where the generic page setup dialog is - * needed - */ - -wxPrintPaperType::wxPrintPaperType(const char *name, int wmm, int hmm, int wp, int hp) -{ - widthMM = wmm; - heightMM = hmm; - widthPixels = wp; - heightPixels = hp; - pageName = copystring(name); -} - -wxPrintPaperType::~wxPrintPaperType() -{ - delete[] pageName; -} - -/* - * Print paper database for PostScript - */ - -wxPrintPaperDatabase* wxThePrintPaperDatabase = (wxPrintPaperDatabase*) NULL; - -#if !USE_SHARED_LIBRARIES -IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase, wxList) -#endif - -wxPrintPaperDatabase::wxPrintPaperDatabase():wxList(wxKEY_STRING) -{ - DeleteContents(TRUE); -} - -wxPrintPaperDatabase::~wxPrintPaperDatabase() -{ -} - -void wxPrintPaperDatabase::CreateDatabase() -{ - // Need correct values for page size in pixels. - // Each unit is one 'point' = 1/72 of an inch. - // NOTE: WE NEED ALSO TO MAKE ADJUSTMENTS WHEN TRANSLATING - // in wxPostScriptDC code, so we can start from top left. - // So access this database and translate by appropriate number - // of points for this paper size. OR IS IT OK ALREADY? - // Can't remember where the PostScript origin is by default. - // Heck, someone will know how to make it hunky-dory... - // JACS 25/5/95 - - AddPaperType(_("A4 210 x 297 mm"), 210, 297, 595, 842); - AddPaperType(_("A3 297 x 420 mm"), 297, 420, 842, 1191); - AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 612, 791); - AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 612, 1009); - -/* - This is for 100 ppi - - AddPaperType(_("A4 210 x 297 mm"), 210, 297, 210*4, 297*4 ); - AddPaperType(_("A3 297 x 420 mm"), 297, 420, 297*4, 420*4 ); - AddPaperType(_("Letter 8 1/2 x 11 in"), 216, 279, 216*4, 279*4 ); - AddPaperType(_("Legal 8 1/2 x 14 in"), 216, 356, 216*4, 356*4 ); -*/ -} - -void wxPrintPaperDatabase::ClearDatabase() -{ - Clear(); -} - -void wxPrintPaperDatabase::AddPaperType(const char *name, int wmm, int hmm, int wp, int hp) -{ - Append(name, new wxPrintPaperType(name, wmm, hmm, wp, hp)); -} - -wxPrintPaperType *wxPrintPaperDatabase::FindPaperType(const char *name) -{ - wxNode *node = Find(name); - if (node) - return (wxPrintPaperType *)node->Data(); - else - return (wxPrintPaperType *) NULL; -} - -// A module to allow initialization/cleanup of print paper -// things without calling these functions from app.cpp. - -class WXDLLEXPORT wxPrintBaseModule: public wxModule -{ -DECLARE_DYNAMIC_CLASS(wxPrintBaseModule) -public: - wxPrintBaseModule() {} - bool OnInit(); - void OnExit(); -}; - -IMPLEMENT_DYNAMIC_CLASS(wxPrintBaseModule, wxModule) - -/* - * Initialization/cleanup module - */ - -bool wxPrintBaseModule::OnInit() -{ - wxThePrintPaperDatabase = new wxPrintPaperDatabase; - wxThePrintPaperDatabase->CreateDatabase(); - return TRUE; } -void wxPrintBaseModule::OnExit() +void wxPrintPreviewBase::SetZoom(int percent) { - delete wxThePrintPaperDatabase; - wxThePrintPaperDatabase = NULL; + if (m_currentZoom == percent) + return; + + m_currentZoom = percent; + if (m_previewBitmap) + { + delete m_previewBitmap; + m_previewBitmap = NULL; + } + RenderPage(m_currentPage); + + if (m_previewCanvas) + { + m_previewCanvas->Clear(); + m_previewCanvas->Refresh(); + } } - diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index 883b7665b1..725f9565be 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -42,6 +42,7 @@ #include "wx/radiobox.h" #include "wx/textctrl.h" #include "wx/prntbase.h" +#include "wx/paper.h" #include @@ -245,6 +246,9 @@ wxPostScriptDC::wxPostScriptDC () m_signX = 1; // default x-axis left to right m_signY = -1; // default y-axis bottom up -> top down + + // Compatibility only + m_printData = * wxThePrintSetupData; } wxPostScriptDC::wxPostScriptDC (const wxString& file, bool interactive, wxWindow *parent) @@ -273,11 +277,11 @@ bool wxPostScriptDC::Create(const wxString& file, bool interactive, wxWindow *pa m_isInteractive = interactive; m_title = ""; - m_filename = file; + m_printData.SetFilename(file); #ifdef __WXMSW__ // Can only send to file in Windows - wxThePrintSetupData->SetPrinterMode(PS_FILE); + m_printData.SetPrintMode(wxPRINT_MODE_FILE); #endif if (m_isInteractive) @@ -292,6 +296,27 @@ bool wxPostScriptDC::Create(const wxString& file, bool interactive, wxWindow *pa return m_ok; } +wxPostScriptDC::wxPostScriptDC (const wxPrintData& printData) +{ + m_pstream = (ofstream*) NULL; + + m_currentRed = 0; + m_currentGreen = 0; + m_currentBlue = 0; + + m_pageNumber = 0; + + m_clipping = FALSE; + + m_underlinePosition = 0.0; + m_underlineThickness = 0.0; + + m_signX = 1; // default x-axis left to right + m_signY = -1; // default y-axis bottom up -> top down + + m_printData = printData; +} + wxPostScriptDC::~wxPostScriptDC () { if (m_pstream) delete m_pstream; @@ -302,6 +327,7 @@ bool wxPostScriptDC::Ok() const return m_ok; } +// This dialog is deprecated now: use wxGenericPrintDialog or the printing framework bool wxPostScriptDC::PrinterDialog(wxWindow *parent) { wxPostScriptPrintDialog dialog( parent, _("Printer Settings"), wxPoint(150, 150), wxSize(400, 400), @@ -310,13 +336,13 @@ bool wxPostScriptDC::PrinterDialog(wxWindow *parent) if (!m_ok) return FALSE; - if ((m_filename == "") && - (wxThePrintSetupData->GetPrinterMode() == PS_PREVIEW || - wxThePrintSetupData->GetPrinterMode() == PS_PRINTER)) + if ((m_printData.GetFilename() == "") && + (m_printData.GetPrintMode() == wxPRINT_MODE_PREVIEW || + m_printData.GetPrintMode() == wxPRINT_MODE_PRINTER)) { // steve, 05.09.94 #ifdef __VMS__ - wxThePrintSetupData->SetPrinterFile("preview"); + m_printData.SetFilename("preview"); #else // For PS_PRINTER action this depends on a Unix-style print spooler // since the wx_printer_file can be destroyed during a session @@ -326,15 +352,14 @@ bool wxPostScriptDC::PrinterDialog(wxWindow *parent) char tmp[256]; strcpy (tmp, "/tmp/preview_"); strcat (tmp, userId); - wxThePrintSetupData->SetPrinterFile(tmp); + m_printData.SetFilename(tmp); #endif char tmp2[256]; - strcpy(tmp2, wxThePrintSetupData->GetPrinterFile()); + strcpy(tmp2, m_printData.GetFilename()); strcat (tmp2, ".ps"); - wxThePrintSetupData->SetPrinterFile(tmp2); - m_filename = tmp2; + m_printData.SetFilename(tmp2); } - else if ((m_filename == "") && (wxThePrintSetupData->GetPrinterMode() == PS_FILE)) + else if ((m_printData.GetFilename() == "") && (m_printData.GetPrintMode() == wxPRINT_MODE_FILE)) { wxString file = wxSaveFileSelector (_("PostScript"), "ps"); if ( file.IsEmpty() ) @@ -343,8 +368,7 @@ bool wxPostScriptDC::PrinterDialog(wxWindow *parent) return FALSE; } - wxThePrintSetupData->SetPrinterFile(file); - m_filename = file; + m_printData.SetFilename(file); m_ok = TRUE; } @@ -1206,18 +1230,16 @@ void wxPostScriptDC::SetDeviceOrigin( long x, long y ) void wxPostScriptDC::GetSize(int* width, int* height) const { - const char *paperType = wxThePrintSetupData->GetPaperName(); - - if (!paperType) paperType = _("A4 210 x 297 mm"); + wxPaperSize id = m_printData.GetPaperId(); - wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType); + wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(id); - if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(_("A4 210 x 297 mm")); + if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); if (paper) { - if (width) *width = paper->widthPixels; - if (height) *height = paper->heightPixels; + if (width) *width = paper->GetSizeDeviceUnits().x; + if (height) *height = paper->GetSizeDeviceUnits().y; } else { @@ -1226,28 +1248,52 @@ void wxPostScriptDC::GetSize(int* width, int* height) const } } -bool wxPostScriptDC::StartDoc (const wxString& message) +void wxPostScriptDC::GetSizeMM(int *width, int *height) const { - wxCHECK_MSG( m_ok, FALSE, "invalid postscript dc" ); + wxPaperSize id = m_printData.GetPaperId(); + + wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(id); - if (m_filename == "") + if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); + + if (paper) { - m_filename = wxGetTempFileName("ps"); - wxThePrintSetupData->SetPrinterFile((char *)(const char *)m_filename); - m_ok = TRUE; + if (width) *width = paper->GetWidth() / 10; + if (height) *height = paper->GetHeight() / 10; } else { - wxThePrintSetupData->SetPrinterFile((char *)(const char *)m_filename); + if (width) *width = 210; + if (height) *height = 297; } +} + +// Resolution in pixels per logical inch +wxSize wxPostScriptDC::GetPPI(void) const +{ + return wxSize(72, 72); +} - m_pstream = new ofstream (wxThePrintSetupData->GetPrinterFile()); + +bool wxPostScriptDC::StartDoc (const wxString& message) +{ + wxCHECK_MSG( m_ok, FALSE, "invalid postscript dc" ); + + if (m_printData.GetFilename() == "") + { + wxString filename = wxGetTempFileName("ps"); + m_printData.SetFilename(filename); + + m_ok = TRUE; + } + + m_pstream = new ofstream (m_printData.GetFilename()); if (!m_pstream || !m_pstream->good()) { - wxMessageBox (_("Cannot open file!"), _("Error"), wxOK); - m_ok = FALSE; - return FALSE; + wxMessageBox (_("Cannot open file!"), _("Error"), wxOK); + m_ok = FALSE; + return FALSE; } m_ok = TRUE; @@ -1309,12 +1355,16 @@ void wxPostScriptDC::EndDoc () long wx_printer_translate_x, wx_printer_translate_y; double wx_printer_scale_x, wx_printer_scale_y; - wxThePrintSetupData->GetPrinterTranslation(&wx_printer_translate_x, &wx_printer_translate_y); - wxThePrintSetupData->GetPrinterScaling(&wx_printer_scale_x, &wx_printer_scale_y); - if (wxThePrintSetupData->GetPrinterOrientation() == PS_LANDSCAPE) + wx_printer_translate_x = m_printData.GetPrinterTranslateX(); + wx_printer_translate_y = m_printData.GetPrinterTranslateY(); + + wx_printer_scale_x = m_printData.GetPrinterScaleX(); + wx_printer_scale_y = m_printData.GetPrinterScaleY(); + + if (m_printData.GetOrientation() == wxLANDSCAPE) { - *m_pstream << "%%Orientation: Landscape\n"; + *m_pstream << "%%Orientation: Landscape\n"; } else { @@ -1329,7 +1379,7 @@ void wxPostScriptDC::EndDoc () long ury = (long) ((YLOG2DEV(m_maxY)+wx_printer_translate_y)*wx_printer_scale_y); // If we're landscape, our sense of "x" and "y" is reversed. - if (wxThePrintSetupData->GetPrinterOrientation() == PS_LANDSCAPE) + if (m_printData.GetOrientation() == wxLANDSCAPE) { long tmp; tmp = llx; llx = lly; lly = tmp; @@ -1378,46 +1428,53 @@ void wxPostScriptDC::EndDoc () char *tmp_file = wxGetTempFileName("ps"); // Paste header Before wx_printer_file - wxConcatFiles (header_file, wxThePrintSetupData->GetPrinterFile(), tmp_file); + wxConcatFiles (header_file, m_printData.GetFilename(), tmp_file); wxRemoveFile (header_file); - wxRemoveFile (wxThePrintSetupData->GetPrinterFile()); - wxRenameFile(tmp_file, wxThePrintSetupData->GetPrinterFile()); + wxRemoveFile (m_printData.GetFilename()); + wxRenameFile(tmp_file, m_printData.GetFilename()); #if defined(__X__) || defined(__WXGTK__) if (m_ok) { - switch (wxThePrintSetupData->GetPrinterMode()) { - case PS_PREVIEW: + wxString previewCommand(m_printData.GetPreviewCommand()); + wxString printerCommand(m_printData.GetPrinterCommand()); + wxString printerOptions(m_printData.GetPrinterOptions()); + wxString filename(m_printData.GetFilename()); + + switch (m_printData.GetPrintMode()) { + + case wxPRINT_MODE_PREVIEW: { char *argv[3]; - argv[0] = wxThePrintSetupData->GetPrintPreviewCommand(); - argv[1] = wxThePrintSetupData->GetPrinterFile(); - argv[2] = (char *) NULL; - wxExecute (argv, TRUE); - wxRemoveFile(wxThePrintSetupData->GetPrinterFile()); + argv[0] = (char*) (const char*) previewCommand; + argv[1] = (char*) (const char*) filename; + argv[2] = (char*) (char *) NULL; + wxExecute (argv, TRUE); + wxRemoveFile(m_printData.GetFilename()); } break; - case PS_PRINTER: + case wxPRINT_MODE_PRINTER: { char *argv[4]; int argc = 0; - argv[argc++] = wxThePrintSetupData->GetPrinterCommand(); + argv[argc++] = (char*) (const char*) printerCommand; // !SM! If we simply assign to argv[1] here, if printer options // are blank, we get an annoying and confusing message from lpr. - char * opts = wxThePrintSetupData->GetPrinterOptions(); + char * opts = (char*) (const char*) printerOptions; if (opts && *opts) argv[argc++] = opts; - argv[argc++] = wxThePrintSetupData->GetPrinterFile(); + argv[argc++] = (char*) (const char*) filename; argv[argc++] = (char *) NULL; - wxExecute (argv, TRUE); - wxRemoveFile(wxThePrintSetupData->GetPrinterFile()); + wxExecute (argv, TRUE); + wxRemoveFile(filename); } break; - case PS_FILE: + case wxPRINT_MODE_FILE: + case wxPRINT_MODE_NONE: break; } } @@ -1446,10 +1503,14 @@ void wxPostScriptDC::StartPage () // Output scaling long translate_x, translate_y; double scale_x, scale_y; - wxThePrintSetupData->GetPrinterTranslation(&translate_x, &translate_y); - wxThePrintSetupData->GetPrinterScaling(&scale_x, &scale_y); - if (wxThePrintSetupData->GetPrinterOrientation() == PS_LANDSCAPE) + translate_x = m_printData.GetPrinterTranslateX(); + translate_y = m_printData.GetPrinterTranslateY(); + + scale_x = m_printData.GetPrinterScaleX(); + scale_y = m_printData.GetPrinterScaleY(); + + if (m_printData.GetOrientation() == wxLANDSCAPE) { translate_y -= m_maxY; *m_pstream << "90 rotate\n"; @@ -1621,7 +1682,8 @@ void wxPostScriptDC::GetTextExtent( const wxString& string, long *x, long *y, /* get the directory of the AFM files */ char afmName[256]; afmName[0] = 0; - if (wxGetAFMPath()) strcpy( afmName, wxGetAFMPath() ); + wxString fmPath(m_printData.GetFontMetricPath()); + if (fmPath != "") strcpy( afmName, (const char*) fmPath ); /* 2. open and process the file / a short explanation of the AFM format: @@ -1794,28 +1856,6 @@ void wxPostScriptDC::GetTextExtent( const wxString& string, long *x, long *y, #endif } -void wxPostScriptDC::GetSizeMM(long *width, long *height) const -{ - const char *paperType = wxThePrintSetupData->GetPaperName(); - - if (!paperType) paperType = _("A4 210 x 297 mm"); - - wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType); - - if (!paper) paper = wxThePrintPaperDatabase->FindPaperType(_("A4 210 x 297 mm")); - - if (paper) - { - if (width) *width = paper->widthMM; - if (height) *height = paper->heightMM; - } - else - { - if (width) *width = 210; - if (height) *height = 297; - } -} - // Determine the Default Postscript Previewer // available on the platform #if defined(__SUN__) && defined(__XVIEW__) @@ -1898,7 +1938,7 @@ wxPostScriptPrintDialog::wxPostScriptPrintDialog (wxWindow *parent, const wxStri if (wxThePrintSetupData->GetPrintPreviewCommand() == NULL) wxThePrintSetupData->SetPrintPreviewCommand(PS_VIEWER_PROG); - wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData->previewCommand); + // wxGetResource ("wxWindows", "PSView", &wxThePrintSetupData->m_previewCommand); features = (wxThePrintSetupData->GetPrintPreviewCommand() && *wxThePrintSetupData->GetPrintPreviewCommand()) ? 3 : 2; @@ -1959,17 +1999,17 @@ int wxPostScriptPrintDialog::ShowModal () wxRadioBox *radio0 = (wxRadioBox *)FindWindow(wxID_PRINTER_ORIENTATION); wxRadioBox *radio1 = (wxRadioBox *)FindWindow(wxID_PRINTER_MODES); - StringToDouble (WXSTRINGCAST text1->GetValue (), &wxThePrintSetupData->printerScaleX); - StringToDouble (WXSTRINGCAST text2->GetValue (), &wxThePrintSetupData->printerScaleY); - StringToLong (WXSTRINGCAST text3->GetValue (), &wxThePrintSetupData->printerTranslateX); - StringToLong (WXSTRINGCAST text4->GetValue (), &wxThePrintSetupData->printerTranslateY); + StringToDouble (WXSTRINGCAST text1->GetValue (), &wxThePrintSetupData->m_printerScaleX); + StringToDouble (WXSTRINGCAST text2->GetValue (), &wxThePrintSetupData->m_printerScaleY); + StringToLong (WXSTRINGCAST text3->GetValue (), &wxThePrintSetupData->m_printerTranslateX); + StringToLong (WXSTRINGCAST text4->GetValue (), &wxThePrintSetupData->m_printerTranslateY); #ifdef __X__ // wxThePrintSetupData->SetPrinterOptions(WXSTRINGCAST text0->GetValue ()); // wxThePrintSetupData->SetPrinterCommand(WXSTRINGCAST text_prt->GetValue ()); #endif - wxThePrintSetupData->SetPrinterOrientation((radio0->GetSelection() == 1 ? PS_LANDSCAPE : PS_PORTRAIT)); + wxThePrintSetupData->SetPrinterOrientation((radio0->GetSelection() == 1 ? wxLANDSCAPE : wxPORTRAIT)); // C++ wants this switch ( radio1->GetSelection() ) { @@ -1986,22 +2026,22 @@ int wxPostScriptPrintDialog::ShowModal () // PostScript printer settings // RETAINED FOR BACKWARD COMPATIBILITY -void wxSetPrinterCommand(const char *cmd) +void wxSetPrinterCommand(const wxString& cmd) { wxThePrintSetupData->SetPrinterCommand(cmd); } -void wxSetPrintPreviewCommand(const char *cmd) +void wxSetPrintPreviewCommand(const wxString& cmd) { wxThePrintSetupData->SetPrintPreviewCommand(cmd); } -void wxSetPrinterOptions(const char *flags) +void wxSetPrinterOptions(const wxString& flags) { wxThePrintSetupData->SetPrinterOptions(flags); } -void wxSetPrinterFile(const char *f) +void wxSetPrinterFile(const wxString& f) { wxThePrintSetupData->SetPrinterFile(f); } @@ -2027,28 +2067,28 @@ void wxSetPrinterMode(int mode) wxThePrintSetupData->SetPrinterMode(mode); } -void wxSetAFMPath(const char *f) +void wxSetAFMPath(const wxString& f) { wxThePrintSetupData->SetAFMPath(f); } // Get current values -char *wxGetPrinterCommand() +wxString wxGetPrinterCommand() { return wxThePrintSetupData->GetPrinterCommand(); } -char *wxGetPrintPreviewCommand() +wxString wxGetPrintPreviewCommand() { return wxThePrintSetupData->GetPrintPreviewCommand(); } -char *wxGetPrinterOptions() +wxString wxGetPrinterOptions() { return wxThePrintSetupData->GetPrinterOptions(); } -char *wxGetPrinterFile() +wxString wxGetPrinterFile() { return wxThePrintSetupData->GetPrinterFile(); } @@ -2073,7 +2113,7 @@ int wxGetPrinterMode() return wxThePrintSetupData->GetPrinterMode(); } -char *wxGetAFMPath() +wxString wxGetAFMPath() { return wxThePrintSetupData->GetAFMPath(); } @@ -2084,200 +2124,17 @@ char *wxGetAFMPath() wxPrintSetupData::wxPrintSetupData() { - printerCommand = (char *) NULL; - previewCommand = (char *) NULL; - printerFlags = (char *) NULL; - printerOrient = PS_PORTRAIT; - printerScaleX = (double)1.0; - printerScaleY = (double)1.0; - printerTranslateX = 0; - printerTranslateY = 0; - // 1 = Preview, 2 = print to file, 3 = send to printer - printerMode = 3; - afmPath = (char *) NULL; - paperName = (char *) NULL; - printColour = TRUE; - printerFile = (char *) NULL; + m_printerOrient = wxPORTRAIT; + m_printerScaleX = (double)1.0; + m_printerScaleY = (double)1.0; + m_printerTranslateX = 0; + m_printerTranslateY = 0; + m_printerMode = wxPRINT_MODE_FILE; + m_printColour = TRUE; } wxPrintSetupData::~wxPrintSetupData() { - if (printerCommand) - delete[] printerCommand; - if (previewCommand) - delete[] previewCommand; - if (printerFlags) - delete[] printerFlags; - if (afmPath) - delete[] afmPath; - if (paperName) - delete[] paperName; - if (printerFile) - delete[] printerFile; -} - -void wxPrintSetupData::SetPrinterCommand(const char *cmd) -{ - if (cmd == printerCommand) - return; - - if (printerCommand) - delete[] printerCommand; - if (cmd) - printerCommand = copystring(cmd); - else - printerCommand = (char *) NULL; -} - -void wxPrintSetupData::SetPrintPreviewCommand(const char *cmd) -{ - if (cmd == previewCommand) - return; - - if (previewCommand) - delete[] previewCommand; - if (cmd) - previewCommand = copystring(cmd); - else - previewCommand = (char *) NULL; -} - -void wxPrintSetupData::SetPaperName(const char *name) -{ - if (name == paperName) - return; - - if (paperName) - delete[] paperName; - if (name) - paperName = copystring(name); - else - paperName = (char *) NULL; -} - -void wxPrintSetupData::SetPrinterOptions(const char *flags) -{ - if (printerFlags == flags) - return; - - if (printerFlags) - delete[] printerFlags; - if (flags) - printerFlags = copystring(flags); - else - printerFlags = (char *) NULL; -} - -void wxPrintSetupData::SetPrinterFile(const char *f) -{ - if (f == printerFile) - return; - - if (printerFile) - delete[] printerFile; - if (f) - printerFile = copystring(f); - else - printerFile = (char *) NULL; -} - -void wxPrintSetupData::SetPrinterOrientation(int orient) -{ - printerOrient = orient; -} - -void wxPrintSetupData::SetPrinterScaling(double x, double y) -{ - printerScaleX = x; - printerScaleY = y; -} - -void wxPrintSetupData::SetPrinterTranslation(long x, long y) -{ - printerTranslateX = x; - printerTranslateY = y; -} - -// 1 = Preview, 2 = print to file, 3 = send to printer -void wxPrintSetupData::SetPrinterMode(int mode) -{ - printerMode = mode; -} - -void wxPrintSetupData::SetAFMPath(const char *f) -{ - if (f == afmPath) - return; - - if (afmPath) - delete[] afmPath; - if (f) - afmPath = copystring(f); - else - afmPath = (char *) NULL; -} - -void wxPrintSetupData::SetColour(bool col) -{ - printColour = col; -} - -// Get current values -char *wxPrintSetupData::GetPrinterCommand() -{ - return printerCommand; -} - -char *wxPrintSetupData::GetPrintPreviewCommand() -{ - return previewCommand; -} - -char *wxPrintSetupData::GetPrinterOptions() -{ - return printerFlags; -} - -char *wxPrintSetupData::GetPrinterFile() -{ - return printerFile; -} - -char *wxPrintSetupData::GetPaperName() -{ - return paperName; -} - -int wxPrintSetupData::GetPrinterOrientation() -{ - return printerOrient; -} - -void wxPrintSetupData::GetPrinterScaling(double *x, double *y) -{ - *x = printerScaleX; - *y = printerScaleY; -} - -void wxPrintSetupData::GetPrinterTranslation(long *x, long *y) -{ - *x = printerTranslateX; - *y = printerTranslateY; -} - -int wxPrintSetupData::GetPrinterMode() -{ - return printerMode; -} - -char *wxPrintSetupData::GetAFMPath() -{ - return afmPath; -} - -bool wxPrintSetupData::GetColour() -{ - return printColour; } void wxPrintSetupData::operator=(wxPrintSetupData& data) @@ -2300,6 +2157,22 @@ void wxPrintSetupData::operator=(wxPrintSetupData& data) SetColour(data.GetColour()); } +// Initialize from a wxPrintData object (wxPrintData should now be used instead of wxPrintSetupData). +void wxPrintSetupData::operator=(const wxPrintData& data) +{ + SetPrinterCommand(data.GetPrinterCommand()); + SetPrintPreviewCommand(data.GetPreviewCommand()); + SetPrinterOptions(data.GetPrinterOptions()); + SetPrinterTranslation(data.GetPrinterTranslateX(), data.GetPrinterTranslateY()); + SetPrinterScaling(data.GetPrinterScaleX(), data.GetPrinterScaleY()); + SetPrinterOrientation(data.GetOrientation()); + SetPrinterMode((int) data.GetPrintMode()); + SetAFMPath(data.GetFontMetricPath()); + SetPaperName(wxThePrintPaperDatabase->ConvertIdToName(data.GetPaperId())); + SetColour(data.GetColour()); + SetPrinterFile(data.GetFilename()); +} + void wxInitializePrintSetupData(bool init) { if (init) @@ -2307,9 +2180,9 @@ void wxInitializePrintSetupData(bool init) wxThePrintSetupData = new wxPrintSetupData; wxThePrintSetupData->SetPrintPreviewCommand(PS_VIEWER_PROG); - wxThePrintSetupData->SetPrinterOrientation(PS_PORTRAIT); - wxThePrintSetupData->SetPrinterMode(PS_PREVIEW); - wxThePrintSetupData->SetPaperName(_("A4 210 x 297 mm")); + wxThePrintSetupData->SetPrinterOrientation(wxPORTRAIT); + wxThePrintSetupData->SetPrinterMode(wxPRINT_MODE_PREVIEW); + wxThePrintSetupData->SetPaperName(_("A4 sheet, 210 x 297 mm")); // Could have a .ini file to read in some defaults // - and/or use environment variables, e.g. WXWIN @@ -2321,12 +2194,12 @@ void wxInitializePrintSetupData(bool init) #ifdef __WXMSW__ wxThePrintSetupData->SetPrinterCommand("print"); wxThePrintSetupData->SetAFMPath("c:\\windows\\system\\"); - wxThePrintSetupData->SetPrinterOptions(NULL); + wxThePrintSetupData->SetPrinterOptions(""); #endif #if !defined(__VMS__) && !defined(__WXMSW__) wxThePrintSetupData->SetPrinterCommand("lpr"); - wxThePrintSetupData->SetPrinterOptions((char *) NULL); - wxThePrintSetupData->SetAFMPath((char *) NULL); + wxThePrintSetupData->SetPrinterOptions(""); + wxThePrintSetupData->SetAFMPath(""); #endif } else diff --git a/src/generic/gridg.cpp b/src/generic/gridg.cpp index 858c320c01..9be30909b7 100644 --- a/src/generic/gridg.cpp +++ b/src/generic/gridg.cpp @@ -1417,9 +1417,10 @@ void wxGenericGrid::OnSelectCellImplementation(wxDC *dc, int row, int col) // Probably because of the SetValue?? JS. // 2) Arrrrrgh. This isn't needed anywhere, // of course. One hour of debugging... RR. + // Put back for Motif only on advice of Michael Bedward #ifdef __WXMOTIF__ HighlightCell(dc); -#endif // motif +#endif dc->DestroyClippingRegion(); diff --git a/src/generic/printps.cpp b/src/generic/printps.cpp index e288b2cd5c..f64a03b5e4 100644 --- a/src/generic/printps.cpp +++ b/src/generic/printps.cpp @@ -34,6 +34,7 @@ #include "wx/dcprint.h" #include "wx/printdlg.h" #include "wx/generic/prntdlgg.h" +#include "wx/paper.h" #include @@ -43,11 +44,11 @@ IMPLEMENT_CLASS(wxPostScriptPrintPreview, wxPrintPreviewBase) #endif /* - * Printer - */ - -wxPostScriptPrinter::wxPostScriptPrinter(wxPrintData *data): - wxPrinterBase(data) +* Printer +*/ + +wxPostScriptPrinter::wxPostScriptPrinter(wxPrintDialogData *data): +wxPrinterBase(data) { } @@ -57,167 +58,182 @@ wxPostScriptPrinter::~wxPostScriptPrinter(void) bool wxPostScriptPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) { - sm_abortIt = FALSE; - sm_abortWindow = (wxWindow *) NULL; - - if (!printout) - return FALSE; + sm_abortIt = FALSE; + sm_abortWindow = (wxWindow *) NULL; - printout->SetIsPreview(FALSE); - printout->OnPreparePrinting(); - - // Get some parameters from the printout, if defined - int fromPage, toPage; - int minPage, maxPage; - printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); - - if (maxPage == 0) - return FALSE; - - m_printData.SetMinPage(minPage); - m_printData.SetMaxPage(maxPage); - if (fromPage != 0) - m_printData.SetFromPage(fromPage); - if (toPage != 0) - m_printData.SetToPage(toPage); - - if (minPage != 0) - { - m_printData.EnablePageNumbers(TRUE); - if (m_printData.GetFromPage() < m_printData.GetMinPage()) - m_printData.SetFromPage(m_printData.GetMinPage()); - else if (m_printData.GetFromPage() > m_printData.GetMaxPage()) - m_printData.SetFromPage(m_printData.GetMaxPage()); - if (m_printData.GetToPage() > m_printData.GetMaxPage()) - m_printData.SetToPage(m_printData.GetMaxPage()); - else if (m_printData.GetToPage() < m_printData.GetMinPage()) - m_printData.SetToPage(m_printData.GetMinPage()); - } - else - m_printData.EnablePageNumbers(FALSE); - - // Create a suitable device context - wxDC *dc = (wxDC *) NULL; - if (prompt) - { - wxGenericPrintDialog dialog(parent, & m_printData); - if (dialog.ShowModal() == wxID_OK) - { - dc = dialog.GetPrintDC(); - m_printData = dialog.GetPrintData(); - } - } - else - { - dc = new wxPostScriptDC(wxThePrintSetupData->GetPrinterFile(), FALSE, (wxWindow *) NULL); - } - - // May have pressed cancel. - if (!dc || !dc->Ok()) - { - if (dc) delete dc; - return FALSE; - } - - int logPPIScreenX = 0; - int logPPIScreenY = 0; - int logPPIPrinterX = 0; - int logPPIPrinterY = 0; - - logPPIScreenX = 100; - logPPIScreenY = 100; - -/* - // Correct values for X/PostScript? - logPPIPrinterX = 100; - logPPIPrinterY = 100; -*/ - - logPPIPrinterX = 72; - logPPIPrinterY = 72; - - printout->SetPPIScreen(logPPIScreenX, logPPIScreenY); - printout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY); - - // Set printout parameters - printout->SetDC(dc); - - int w, h; - long ww, hh; - dc->GetSize(&w, &h); - printout->SetPageSizePixels((int)w, (int)h); - dc->GetSizeMM(&ww, &hh); - printout->SetPageSizeMM((int)ww, (int)hh); - - // Create an abort window - wxBeginBusyCursor(); - - printout->OnBeginPrinting(); - - bool keepGoing = TRUE; - - int copyCount; - for (copyCount = 1; copyCount <= m_printData.GetNoCopies(); copyCount ++) - { - if (!printout->OnBeginDocument(m_printData.GetFromPage(), m_printData.GetToPage())) + if (!printout) + return FALSE; + + printout->SetIsPreview(FALSE); + printout->OnPreparePrinting(); + + // Get some parameters from the printout, if defined + int fromPage, toPage; + int minPage, maxPage; + printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); + + if (maxPage == 0) + return FALSE; + + m_printDialogData.SetMinPage(minPage); + m_printDialogData.SetMaxPage(maxPage); + if (fromPage != 0) + m_printDialogData.SetFromPage(fromPage); + if (toPage != 0) + m_printDialogData.SetToPage(toPage); + + if (minPage != 0) { - wxEndBusyCursor(); - wxMessageBox(_("Could not start printing."), _("Print Error"), wxOK, parent); - break; + m_printDialogData.EnablePageNumbers(TRUE); + if (m_printDialogData.GetFromPage() < m_printDialogData.GetMinPage()) + m_printDialogData.SetFromPage(m_printDialogData.GetMinPage()); + else if (m_printDialogData.GetFromPage() > m_printDialogData.GetMaxPage()) + m_printDialogData.SetFromPage(m_printDialogData.GetMaxPage()); + if (m_printDialogData.GetToPage() > m_printDialogData.GetMaxPage()) + m_printDialogData.SetToPage(m_printDialogData.GetMaxPage()); + else if (m_printDialogData.GetToPage() < m_printDialogData.GetMinPage()) + m_printDialogData.SetToPage(m_printDialogData.GetMinPage()); } - if (sm_abortIt) - break; + else + m_printDialogData.EnablePageNumbers(FALSE); - int pn; - for (pn = m_printData.GetFromPage(); keepGoing && (pn <= m_printData.GetToPage()) && printout->HasPage(pn); - pn++) + // Create a suitable device context + wxDC *dc = (wxDC *) NULL; + if (prompt) { - if (sm_abortIt) - { - keepGoing = FALSE; - break; - } - else - { - dc->StartPage(); - printout->OnPrintPage(pn); - dc->EndPage(); - } + dc = PrintDialog(parent); + if (!dc) + return FALSE; } - printout->OnEndDocument(); - } - - printout->OnEndPrinting(); - - wxEndBusyCursor(); - - delete dc; - - return TRUE; + else + { + dc = new wxPostScriptDC(wxThePrintSetupData->GetPrinterFile(), FALSE, (wxWindow *) NULL); + } + + // May have pressed cancel. + if (!dc || !dc->Ok()) + { + if (dc) delete dc; + return FALSE; + } + + int logPPIScreenX = 0; + int logPPIScreenY = 0; + int logPPIPrinterX = 0; + int logPPIPrinterY = 0; + + logPPIScreenX = 100; + logPPIScreenY = 100; + + /* + // Correct values for X/PostScript? + logPPIPrinterX = 100; + logPPIPrinterY = 100; + */ + + logPPIPrinterX = 72; + logPPIPrinterY = 72; + + printout->SetPPIScreen(logPPIScreenX, logPPIScreenY); + printout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY); + + // Set printout parameters + printout->SetDC(dc); + + int w, h; + dc->GetSize(&w, &h); + printout->SetPageSizePixels((int)w, (int)h); + dc->GetSizeMM(&w, &h); + printout->SetPageSizeMM((int)w, (int)h); + + // Create an abort window + wxBeginBusyCursor(); + + printout->OnBeginPrinting(); + + bool keepGoing = TRUE; + + int copyCount; + for (copyCount = 1; copyCount <= m_printDialogData.GetNoCopies(); copyCount ++) + { + if (!printout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage())) + { + wxEndBusyCursor(); + wxMessageBox(_("Could not start printing."), _("Print Error"), wxOK, parent); + break; + } + if (sm_abortIt) + break; + + int pn; + for (pn = m_printDialogData.GetFromPage(); keepGoing && (pn <= m_printDialogData.GetToPage()) && printout->HasPage(pn); + pn++) + { + if (sm_abortIt) + { + keepGoing = FALSE; + break; + } + else + { + dc->StartPage(); + printout->OnPrintPage(pn); + dc->EndPage(); + } + } + printout->OnEndDocument(); + } + + printout->OnEndPrinting(); + + wxEndBusyCursor(); + + delete dc; + + return TRUE; } -bool wxPostScriptPrinter::PrintDialog(wxWindow *parent) +wxDC* wxPostScriptPrinter::PrintDialog(wxWindow *parent) { - wxGenericPrintDialog dialog(parent, & m_printData); - return (dialog.ShowModal() == wxID_OK); + wxDC* dc = (wxDC*) NULL; + wxGenericPrintDialog* dialog = new wxGenericPrintDialog(parent, & m_printDialogData); + int ret = dialog->ShowModal() ; + if (ret == wxID_OK) + { + dc = dialog->GetPrintDC(); + m_printDialogData = dialog->GetPrintDialogData(); + } + dialog->Destroy(); + + return dc; } bool wxPostScriptPrinter::Setup(wxWindow *parent) { - wxGenericPrintDialog dialog(parent, & m_printData); - dialog.GetPrintData().SetSetupDialog(TRUE); - return (dialog.ShowModal() == wxID_OK); + wxGenericPrintDialog* dialog = new wxGenericPrintDialog(parent, & m_printDialogData); + dialog->GetPrintDialogData().SetSetupDialog(TRUE); + + int ret = dialog->ShowModal(); + + if (ret == wxID_OK) + { + m_printDialogData = dialog->GetPrintDialogData(); + } + + dialog->Destroy(); + + return (ret == wxID_OK); } /* - * Print preview - */ +* Print preview +*/ -wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data): - wxPrintPreviewBase(printout, printoutForPrinting, data) +wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintDialogData *data): +wxPrintPreviewBase(printout, printoutForPrinting, data) { - // Have to call it here since base constructor can't call it - DetermineScaling(); + // Have to call it here since base constructor can't call it + DetermineScaling(); } wxPostScriptPrintPreview::~wxPostScriptPrintPreview(void) @@ -226,47 +242,50 @@ wxPostScriptPrintPreview::~wxPostScriptPrintPreview(void) bool wxPostScriptPrintPreview::Print(bool interactive) { - if (!m_printPrintout) - return FALSE; - wxPostScriptPrinter printer(&m_printData); - return printer.Print(m_previewFrame, m_printPrintout, interactive); + if (!m_printPrintout) + return FALSE; + wxPostScriptPrinter printer(& m_printDialogData); + return printer.Print(m_previewFrame, m_printPrintout, interactive); } void wxPostScriptPrintPreview::DetermineScaling(void) { - const char *paperType = wxThePrintSetupData->GetPaperName(); - if (!paperType) - paperType = _("A4 210 x 297 mm"); - + wxPaperSize paperType = m_printDialogData.GetPrintData().GetPaperId(); + if (paperType == wxPAPER_NONE) + paperType = wxPAPER_NONE; + wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType); if (!paper) - paper = wxThePrintPaperDatabase->FindPaperType(_("A4 210 x 297 mm")); + paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4); + if (paper) { - m_previewPrintout->SetPPIScreen(100, 100); -// m_previewPrintout->SetPPIPrinter(100, 100); - m_previewPrintout->SetPPIPrinter(72, 72); - - // If in landscape mode, we need to swap the width and height. - if ( m_printData.GetOrientation() == wxLANDSCAPE ) - { - m_pageWidth = paper->heightPixels; - m_pageHeight = paper->widthPixels; - m_previewPrintout->SetPageSizeMM(paper->heightMM, paper->widthMM); - m_previewPrintout->SetPageSizePixels(paper->heightPixels, paper->widthPixels); - } - else - { - m_pageWidth = paper->widthPixels; - m_pageHeight = paper->heightPixels; - m_previewPrintout->SetPageSizeMM(paper->widthMM, paper->heightMM); - m_previewPrintout->SetPageSizePixels(paper->widthPixels, paper->heightPixels); - } - - // At 100%, the page should look about page-size on the screen. - m_previewScale = (float)0.8; -// m_previewScale = (float)((float)screenWidth/(float)printerWidth); -// m_previewScale = previewScale * (float)((float)screenXRes/(float)printerYRes); + m_previewPrintout->SetPPIScreen(100, 100); + // m_previewPrintout->SetPPIPrinter(100, 100); + m_previewPrintout->SetPPIPrinter(72, 72); + + wxSize sizeDevUnits(paper->GetSizeDeviceUnits()); + wxSize sizeTenthsMM(paper->GetSize()); + wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10); + + // If in landscape mode, we need to swap the width and height. + if ( m_printDialogData.GetPrintData().GetOrientation() == wxLANDSCAPE ) + { + m_pageWidth = sizeDevUnits.y; + m_pageHeight = sizeDevUnits.x; + m_previewPrintout->SetPageSizeMM(sizeMM.y, sizeMM.x); + m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); + } + else + { + m_pageWidth = sizeDevUnits.x; + m_pageHeight = sizeDevUnits.y; + m_previewPrintout->SetPageSizeMM(sizeMM.x, sizeMM.y); + m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight); + } + + // At 100%, the page should look about page-size on the screen. + m_previewScale = (float)0.8; } } diff --git a/src/generic/prntdlgg.cpp b/src/generic/prntdlgg.cpp index b1ff434de5..688edb11da 100644 --- a/src/generic/prntdlgg.cpp +++ b/src/generic/prntdlgg.cpp @@ -45,6 +45,7 @@ #endif #include "wx/printdlg.h" +#include "wx/paper.h" // For print paper things #include "wx/prntbase.h" @@ -60,88 +61,101 @@ IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog) IMPLEMENT_CLASS(wxGenericPageSetupDialog, wxDialog) BEGIN_EVENT_TABLE(wxGenericPrintDialog, wxDialog) - EVT_BUTTON(wxID_OK, wxGenericPrintDialog::OnOK) - EVT_BUTTON(wxPRINTID_SETUP, wxGenericPrintDialog::OnSetup) - EVT_RADIOBOX(wxPRINTID_RANGE, wxGenericPrintDialog::OnRange) +EVT_BUTTON(wxID_OK, wxGenericPrintDialog::OnOK) +EVT_BUTTON(wxPRINTID_SETUP, wxGenericPrintDialog::OnSetup) +EVT_RADIOBOX(wxPRINTID_RANGE, wxGenericPrintDialog::OnRange) END_EVENT_TABLE() BEGIN_EVENT_TABLE(wxGenericPageSetupDialog, wxDialog) - EVT_BUTTON(wxPRINTID_SETUP, wxGenericPageSetupDialog::OnPrinter) +EVT_BUTTON(wxPRINTID_SETUP, wxGenericPageSetupDialog::OnPrinter) END_EVENT_TABLE() #endif extern wxPrintPaperDatabase *wxThePrintPaperDatabase; /* - * Generic print dialog for non-Windows printing use. - */ +* Generic print dialog for non-Windows printing use. +*/ -wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent, wxPrintData* data): - wxDialog(parent, -1, _("Print"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL) +wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent, wxPrintDialogData* data): +wxDialog(parent, -1, _("Print"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL) { - if ( data ) - printData = *data; - - (void)new wxStaticBox( this, -1, _( "Printer options" ), wxPoint( 5, 5), wxSize( 300, 60 ) ); - - printToFileCheckBox = new wxCheckBox(this, wxPRINTID_PRINTTOFILE, _("Print to File"), wxPoint(20, 25) ); - - setupButton = new wxButton(this, wxPRINTID_SETUP, _("Setup..."), wxPoint(160, 25), wxSize(100, -1)); - - wxString *choices = new wxString[2]; - choices[0] = _("All"); - choices[1] = _("Pages"); - - fromText = (wxTextCtrl*)NULL; - - if(printData.GetFromPage() != 0) - { - rangeRadioBox = new wxRadioBox(this, wxPRINTID_RANGE, _("Print Range"), - wxPoint(5, 80), wxSize(-1, -1), 2, choices, 1, wxRA_VERTICAL); - rangeRadioBox->SetSelection(1); - } - - if(printData.GetFromPage() != 0) - { - (void) new wxStaticText(this, wxPRINTID_STATIC, _("From:"), wxPoint(5, 135)); - - fromText = new wxTextCtrl(this, wxPRINTID_FROM, "", wxPoint(45, 130), wxSize(40, -1)); - - (void) new wxStaticText(this, wxPRINTID_STATIC, _("To:"), wxPoint(100, 135)); - - toText = new wxTextCtrl(this, wxPRINTID_TO, "", wxPoint(133, 130), wxSize(40, -1)); - } - - (void) new wxStaticText(this, wxPRINTID_STATIC, _("Copies:"), wxPoint(200, 135)); - - noCopiesText = new wxTextCtrl(this, wxPRINTID_COPIES, "", wxPoint(252, 130), wxSize(40, -1)); - - wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(40, 180), wxSize(100, -1)); - (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(180, 180), wxSize(100, -1)); - - okButton->SetDefault(); - okButton->SetFocus(); - Fit(); - Centre(wxBOTH); - - // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow - InitDialog(); - delete[] choices; + if ( data ) + m_printDialogData = *data; + + (void)new wxStaticBox( this, -1, _( "Printer options" ), wxPoint( 5, 5), wxSize( 300, 60 ) ); + + m_printToFileCheckBox = new wxCheckBox(this, wxPRINTID_PRINTTOFILE, _("Print to File"), wxPoint(20, 25) ); + + m_setupButton = new wxButton(this, wxPRINTID_SETUP, _("Setup..."), wxPoint(160, 25), wxSize(100, -1)); + + wxString *choices = new wxString[2]; + choices[0] = _("All"); + choices[1] = _("Pages"); + + m_fromText = (wxTextCtrl*)NULL; + + if (m_printDialogData.GetFromPage() != 0) + { + m_rangeRadioBox = new wxRadioBox(this, wxPRINTID_RANGE, _("Print Range"), + wxPoint(5, 80), wxSize(-1, -1), 2, choices, 1, wxRA_VERTICAL); + m_rangeRadioBox->SetSelection(1); + } + + if(m_printDialogData.GetFromPage() != 0) + { + (void) new wxStaticText(this, wxPRINTID_STATIC, _("From:"), wxPoint(5, 135)); + + m_fromText = new wxTextCtrl(this, wxPRINTID_FROM, "", wxPoint(45, 130), wxSize(40, -1)); + + (void) new wxStaticText(this, wxPRINTID_STATIC, _("To:"), wxPoint(100, 135)); + + m_toText = new wxTextCtrl(this, wxPRINTID_TO, "", wxPoint(133, 130), wxSize(40, -1)); + } + + (void) new wxStaticText(this, wxPRINTID_STATIC, _("Copies:"), wxPoint(200, 135)); + + m_noCopiesText = new wxTextCtrl(this, wxPRINTID_COPIES, "", wxPoint(252, 130), wxSize(40, -1)); + + wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(40, 180), wxSize(100, -1)); + (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(180, 180), wxSize(100, -1)); + + okButton->SetDefault(); + okButton->SetFocus(); + Fit(); + Centre(wxBOTH); + + // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow + InitDialog(); + delete[] choices; } -int wxGenericPrintDialog::ShowModal(void) +int wxGenericPrintDialog::ShowModal() { - if ( printData.GetSetupDialog() ) + if ( m_printDialogData.GetSetupDialog() ) { + // Make sure wxPrintData object reflects the settings now, in case the setup dialog + // changes it. In fact there aren't any common settings at + // present, but there might be in future. + // TransferDataFromWindow(); + wxGenericPrintSetupDialog *genericPrintSetupDialog = - new wxGenericPrintSetupDialog(GetParent(), wxThePrintSetupData); + new wxGenericPrintSetupDialog(this, & m_printDialogData.GetPrintData()); int ret = genericPrintSetupDialog->ShowModal(); if ( ret != wxID_CANCEL ) { - *wxThePrintSetupData = genericPrintSetupDialog->printData; + // Transfer settings to the global object (for compatibility) and to + // the print dialog's print data. + *wxThePrintSetupData = genericPrintSetupDialog->GetPrintData(); + m_printDialogData.GetPrintData() = genericPrintSetupDialog->GetPrintData(); } - genericPrintSetupDialog->Close(TRUE); + genericPrintSetupDialog->Destroy(); + + // Restore the wxPrintData settings again (uncomment if any settings become common + // to both dialogs) + // TransferDataToWindow(); + return ret; } else @@ -150,275 +164,304 @@ int wxGenericPrintDialog::ShowModal(void) } } -wxGenericPrintDialog::~wxGenericPrintDialog(void) +wxGenericPrintDialog::~wxGenericPrintDialog() { } void wxGenericPrintDialog::OnOK(wxCommandEvent& WXUNUSED(event)) { - TransferDataFromWindow(); - - // There are some interactions between the global setup data - // and the standard print dialog. The global printing 'mode' - // is determined by whether the user checks Print to file - // or not. - if (printData.GetPrintToFile()) - { - wxThePrintSetupData->SetPrinterMode(PS_FILE); - - wxString f = wxFileSelector(_("PostScript file"), - wxPathOnly(wxThePrintSetupData->GetPrinterFile()), - wxFileNameFromPath(wxThePrintSetupData->GetPrinterFile()), - "ps", "*.ps", 0, this); - if ( f.IsEmpty() ) - return; - - wxThePrintSetupData->SetPrinterFile(f); - } - else - wxThePrintSetupData->SetPrinterMode(PS_PRINTER); - - EndModal(wxID_OK); + TransferDataFromWindow(); + + // There are some interactions between the global setup data + // and the standard print dialog. The global printing 'mode' + // is determined by whether the user checks Print to file + // or not. + if (m_printDialogData.GetPrintToFile()) + { + m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE); + wxThePrintSetupData->SetPrinterMode(wxPRINT_MODE_FILE); + + wxString f = wxFileSelector(_("PostScript file"), + wxPathOnly(wxThePrintSetupData->GetPrinterFile()), + wxFileNameFromPath(wxThePrintSetupData->GetPrinterFile()), + "ps", "*.ps", 0, this); + if ( f.IsEmpty() ) + return; + + m_printDialogData.GetPrintData().SetFilename(f); + wxThePrintSetupData->SetPrinterFile(f); + } + else + wxThePrintSetupData->SetPrinterMode(wxPRINT_MODE_PRINTER); + + EndModal(wxID_OK); } void wxGenericPrintDialog::OnRange(wxCommandEvent& event) { - if (!fromText) return; - - if (event.GetInt() == 0) - { - fromText->Enable(FALSE); - toText->Enable(FALSE); - } - else if (event.GetInt() == 1) - { - fromText->Enable(TRUE); - toText->Enable(TRUE); - } + if (!m_fromText) return; + + if (event.GetInt() == 0) + { + m_fromText->Enable(FALSE); + m_toText->Enable(FALSE); + } + else if (event.GetInt() == 1) + { + m_fromText->Enable(TRUE); + m_toText->Enable(TRUE); + } } void wxGenericPrintDialog::OnSetup(wxCommandEvent& WXUNUSED(event)) { - wxGenericPrintSetupDialog *genericPrintSetupDialog = - new wxGenericPrintSetupDialog(this, wxThePrintSetupData); - int ret = genericPrintSetupDialog->ShowModal(); - if ( ret != wxID_CANCEL ) - { - *wxThePrintSetupData = genericPrintSetupDialog->printData; - printData.SetOrientation(wxThePrintSetupData->GetPrinterOrientation()); - } - - genericPrintSetupDialog->Close(TRUE); + wxGenericPrintSetupDialog *genericPrintSetupDialog = + new wxGenericPrintSetupDialog(this, wxThePrintSetupData); + int ret = genericPrintSetupDialog->ShowModal(); + if ( ret != wxID_CANCEL ) + { + *wxThePrintSetupData = genericPrintSetupDialog->GetPrintData(); + m_printDialogData = genericPrintSetupDialog->GetPrintData(); + } + + genericPrintSetupDialog->Close(TRUE); } -bool wxGenericPrintDialog::TransferDataToWindow(void) +bool wxGenericPrintDialog::TransferDataToWindow() { - char buf[10]; - - if(printData.GetFromPage() != 0) - { - if (printData.GetEnablePageNumbers()) - { - fromText->Enable(TRUE); - toText->Enable(TRUE); - - sprintf(buf, "%d", printData.GetFromPage()); - fromText->SetValue(buf); - sprintf(buf, "%d", printData.GetToPage()); - toText->SetValue(buf); - - if (printData.GetAllPages()) - rangeRadioBox->SetSelection(0); - else - rangeRadioBox->SetSelection(1); - } - else - { - fromText->Enable(FALSE); - toText->Enable(FALSE); - rangeRadioBox->SetSelection(0); - rangeRadioBox->wxRadioBox::Enable(1, FALSE); - } - } - sprintf(buf, "%d", printData.GetNoCopies()); - noCopiesText->SetValue(buf); - - printToFileCheckBox->SetValue(printData.GetPrintToFile()); - printToFileCheckBox->Enable(printData.GetEnablePrintToFile()); - return TRUE; + char buf[10]; + + if(m_printDialogData.GetFromPage() != 0) + { + if (m_printDialogData.GetEnablePageNumbers()) + { + m_fromText->Enable(TRUE); + m_toText->Enable(TRUE); + + sprintf(buf, "%d", m_printDialogData.GetFromPage()); + m_fromText->SetValue(buf); + sprintf(buf, "%d", m_printDialogData.GetToPage()); + m_toText->SetValue(buf); + + if (m_printDialogData.GetAllPages()) + m_rangeRadioBox->SetSelection(0); + else + m_rangeRadioBox->SetSelection(1); + } + else + { + m_fromText->Enable(FALSE); + m_toText->Enable(FALSE); + m_rangeRadioBox->SetSelection(0); + m_rangeRadioBox->wxRadioBox::Enable(1, FALSE); + } + } + sprintf(buf, "%d", m_printDialogData.GetNoCopies()); + m_noCopiesText->SetValue(buf); + + m_printToFileCheckBox->SetValue(m_printDialogData.GetPrintToFile()); + m_printToFileCheckBox->Enable(m_printDialogData.GetEnablePrintToFile()); + return TRUE; } -bool wxGenericPrintDialog::TransferDataFromWindow(void) +bool wxGenericPrintDialog::TransferDataFromWindow() { - if(printData.GetFromPage() != -1) - { - if (printData.GetEnablePageNumbers()) - { - printData.SetFromPage(atoi(fromText->GetValue())); - printData.SetToPage(atoi(toText->GetValue())); - } - if (rangeRadioBox->GetSelection() == 0) - printData.SetAllPages(TRUE); - else - printData.SetAllPages(FALSE); - } - else - { // continuous printing - printData.SetFromPage(1); - printData.SetToPage(32000); - } - printData.SetNoCopies(atoi(noCopiesText->GetValue())); - printData.SetPrintToFile(printToFileCheckBox->GetValue()); - - return TRUE; -} + if(m_printDialogData.GetFromPage() != -1) + { + if (m_printDialogData.GetEnablePageNumbers()) + { + m_printDialogData.SetFromPage(atoi(m_fromText->GetValue())); + m_printDialogData.SetToPage(atoi(m_toText->GetValue())); + } + if (m_rangeRadioBox->GetSelection() == 0) + m_printDialogData.SetAllPages(TRUE); + else + m_printDialogData.SetAllPages(FALSE); + } + else + { // continuous printing + m_printDialogData.SetFromPage(1); + m_printDialogData.SetToPage(32000); + } + m_printDialogData.SetNoCopies(atoi(m_noCopiesText->GetValue())); + m_printDialogData.SetPrintToFile(m_printToFileCheckBox->GetValue()); -wxDC *wxGenericPrintDialog::GetPrintDC(void) -{ - return new wxPostScriptDC(wxThePrintSetupData->GetPrinterFile(), FALSE, (wxWindow *) NULL); + return TRUE; } /* - * Generic print setup dialog - */ +TODO: collate and noCopies should be duplicated across dialog data and print data objects +(slightly different semantics on Windows but let's ignore this for a bit). +*/ -wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintSetupData* data): - wxDialog(parent, -1, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL) +wxDC *wxGenericPrintDialog::GetPrintDC() { - if ( data ) - printData = *data; - - (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(10, 10), wxSize(200,60) ); + return new wxPostScriptDC(wxThePrintSetupData->GetPrinterFile(), FALSE, (wxWindow *) NULL); +} - int xPos = 20; - int yPos = 30; - paperTypeChoice = CreatePaperTypeChoice(&xPos, &yPos); +/* +* Generic print setup dialog +*/ - wxString *choices = new wxString[2]; - choices[0] = _("Portrait"); - choices[1] = _("Landscape"); +wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintData* data): +wxDialog(parent, -1, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL) +{ + Init(data); +} - orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"), - wxPoint(10, 80), wxSize(-1, -1), 2, choices, 1, wxRA_VERTICAL ); - orientationRadioBox->SetSelection(0); +// Convert wxPrintSetupData to standard wxPrintData object +wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintSetupData* data): +wxDialog(parent, -1, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL) +{ + wxPrintData printData; + if (data) + printData = * data; + else + printData = * wxThePrintSetupData; - (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Options"), wxPoint(10, 130), wxSize(200,50) ); + Init(& printData); +} - int colourXPos = 145; +void wxGenericPrintSetupDialog::Init(wxPrintData* data) +{ + if ( data ) + m_printData = *data; + int staticBoxWidth = 300; + + (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(10, 10), wxSize(staticBoxWidth, 60) ); + + int xPos = 20; + int yPos = 30; + m_paperTypeChoice = CreatePaperTypeChoice(&xPos, &yPos); + + wxString *choices = new wxString[2]; + choices[0] = _("Portrait"); + choices[1] = _("Landscape"); + + m_orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"), + wxPoint(10, 80), wxSize(-1, -1), 2, choices, 1, wxRA_VERTICAL ); + m_orientationRadioBox->SetSelection(0); + + (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Options"), wxPoint(10, 130), wxSize(staticBoxWidth, 50) ); + + int colourYPos = 145; + #ifdef __WXMOTIF__ - colourXPos = 150; + colourYPos = 150; #endif - - colourCheckBox = new wxCheckBox(this, wxPRINTID_PRINTCOLOUR, _("Print in colour"), wxPoint(15, colourXPos)); - - - (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Print spooling"), wxPoint(230, 10), wxSize(200,170) ); - - (void) new wxStaticText(this, wxPRINTID_STATIC, _("Printer command:"), wxPoint(240, 30)); - - printerCommandText = new wxTextCtrl(this, wxPRINTID_COMMAND, "", wxPoint(260, 55), wxSize(150, -1)); - - (void) new wxStaticText(this, wxPRINTID_STATIC, _("Printer options:"), wxPoint(240, 110)); - - printerOptionsText = new wxTextCtrl(this, wxPRINTID_OPTIONS, "", wxPoint(260, 135), wxSize(150, -1)); - - wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(80, 200), wxSize(100, -1)); - (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(270, 200), wxSize(100, -1)); - - okButton->SetDefault(); - okButton->SetFocus(); - - Fit(); - Centre(wxBOTH); + + m_colourCheckBox = new wxCheckBox(this, wxPRINTID_PRINTCOLOUR, _("Print in colour"), wxPoint(15, colourYPos)); - InitDialog(); - delete[] choices; + (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Print spooling"), wxPoint(330, 10), wxSize(200,170) ); + + (void) new wxStaticText(this, wxPRINTID_STATIC, _("Printer command:"), wxPoint(340, 30)); + + m_printerCommandText = new wxTextCtrl(this, wxPRINTID_COMMAND, "", wxPoint(360, 55), wxSize(150, -1)); + + (void) new wxStaticText(this, wxPRINTID_STATIC, _("Printer options:"), wxPoint(340, 110)); + + m_printerOptionsText = new wxTextCtrl(this, wxPRINTID_OPTIONS, "", wxPoint(360, 135), wxSize(150, -1)); + + wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(130, 200), wxSize(100, -1)); + (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(320, 200), wxSize(100, -1)); + + okButton->SetDefault(); + okButton->SetFocus(); + + Fit(); + Centre(wxBOTH); + + InitDialog(); + delete[] choices; } -wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog(void) +wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog() { } -bool wxGenericPrintSetupDialog::TransferDataToWindow(void) +bool wxGenericPrintSetupDialog::TransferDataToWindow() { - if (printerCommandText && printData.GetPrinterCommand()) - printerCommandText->SetValue(printData.GetPrinterCommand()); - if (printerOptionsText && printData.GetPrinterOptions()) - printerOptionsText->SetValue(printData.GetPrinterOptions()); - if (colourCheckBox) - colourCheckBox->SetValue(printData.GetColour()); - - if (orientationRadioBox) - { - if (printData.GetPrinterOrientation() == PS_PORTRAIT) - orientationRadioBox->SetSelection(0); - else - orientationRadioBox->SetSelection(1); - } - return TRUE; + if (m_printerCommandText && m_printData.GetPrinterCommand()) + m_printerCommandText->SetValue(m_printData.GetPrinterCommand()); + if (m_printerOptionsText && m_printData.GetPrinterOptions()) + m_printerOptionsText->SetValue(m_printData.GetPrinterOptions()); + if (m_colourCheckBox) + m_colourCheckBox->SetValue(m_printData.GetColour()); + + if (m_orientationRadioBox) + { + if (m_printData.GetOrientation() == wxPORTRAIT) + m_orientationRadioBox->SetSelection(0); + else + m_orientationRadioBox->SetSelection(1); + } + return TRUE; } -bool wxGenericPrintSetupDialog::TransferDataFromWindow(void) +bool wxGenericPrintSetupDialog::TransferDataFromWindow() { - if (printerCommandText) - printData.SetPrinterCommand(WXSTRINGCAST printerCommandText->GetValue()); - if (printerOptionsText) - printData.SetPrinterOptions(WXSTRINGCAST printerOptionsText->GetValue()); - if (colourCheckBox) - printData.SetColour(colourCheckBox->GetValue()); - if (orientationRadioBox) - { - int sel = orientationRadioBox->GetSelection(); - if (sel == 0) - printData.SetPrinterOrientation(PS_PORTRAIT); - else - printData.SetPrinterOrientation(PS_LANDSCAPE); - } - if (paperTypeChoice) - { - wxString val(paperTypeChoice->GetStringSelection()); - if (!val.IsNull() && val != "") - printData.SetPaperName((char *)(const char *)val); - } - *wxThePrintSetupData = GetPrintData(); - return TRUE; + if (m_printerCommandText) + m_printData.SetPrinterCommand(m_printerCommandText->GetValue()); + if (m_printerOptionsText) + m_printData.SetPrinterOptions(m_printerOptionsText->GetValue()); + if (m_colourCheckBox) + m_printData.SetColour(m_colourCheckBox->GetValue()); + if (m_orientationRadioBox) + { + int sel = m_orientationRadioBox->GetSelection(); + if (sel == 0) + m_printData.SetOrientation(wxPORTRAIT); + else + m_printData.SetOrientation(wxLANDSCAPE); + } + if (m_paperTypeChoice) + { + wxString val(m_paperTypeChoice->GetStringSelection()); + if (!val.IsNull() && val != "") + m_printData.SetPaperId(wxThePrintPaperDatabase->ConvertNameToId(val)); + } + + // This is for backward compatibility only + *wxThePrintSetupData = GetPrintData(); + return TRUE; } wxChoice *wxGenericPrintSetupDialog::CreatePaperTypeChoice(int *x, int *y) { - if (!wxThePrintPaperDatabase) - { - wxThePrintPaperDatabase = new wxPrintPaperDatabase; - wxThePrintPaperDatabase->CreateDatabase(); - } - int n = wxThePrintPaperDatabase->Number(); - wxString *choices = new wxString [n]; - int sel = 0; - int i; - for (i = 0; i < n; i++) - { - wxPrintPaperType *paper = (wxPrintPaperType *)wxThePrintPaperDatabase->Nth(i)->Data(); - choices[i] = paper->pageName; - if (printData.GetPaperName() && choices[i] == printData.GetPaperName()) - sel = i; - } - - int width = 170; -#ifdef __WXMOTIF__ - width = 150; -#endif - - wxChoice *choice = new wxChoice(this, wxPRINTID_PAPERSIZE, wxPoint(*x, *y), wxSize(width, -1), n, - choices); +/* Should not be necessary + if (!wxThePrintPaperDatabase) + { + wxThePrintPaperDatabase = new wxPrintPaperDatabase; + wxThePrintPaperDatabase->CreateDatabase(); + } +*/ + int n = wxThePrintPaperDatabase->Number(); + wxString *choices = new wxString [n]; + int sel = 0; + int i; + for (i = 0; i < n; i++) + { + wxPrintPaperType *paper = (wxPrintPaperType *)wxThePrintPaperDatabase->Nth(i)->Data(); + choices[i] = paper->GetName(); + if (m_printData.GetPaperId() == paper->GetId()) + sel = i; + } - delete[] choices; + int width = 250; + + wxChoice *choice = new wxChoice(this, wxPRINTID_PAPERSIZE, wxPoint(*x, *y), wxSize(width, -1), n, + choices); + + // SetFont(thisFont); - choice->SetSelection(sel); - return choice; + delete[] choices; + + choice->SetSelection(sel); + return choice; } #endif - // wxUSE_POSTSCRIPT +// wxUSE_POSTSCRIPT /* * Generic page setup dialog @@ -434,200 +477,229 @@ void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent& WXUNUSED(event)) // printing under Windows (and only in 16-bit Windows which // doesn't have a Windows-specific page setup dialog) it's worth it. - wxPrintData data; + // First save the current settings, so the wxPrintData object is up to date. + TransferDataFromWindow(); + + // Transfer the current print settings from this dialog to the page setup dialog. + wxPrintDialogData data; + data = GetPageSetupData().GetPrintData(); data.SetSetupDialog(TRUE); wxPrintDialog *printDialog = new wxPrintDialog(this, & data); printDialog->ShowModal(); + // Transfer the page setup print settings from the page dialog to this dialog again, in case + // the page setup dialog changed something. + GetPageSetupData().GetPrintData() = printDialog->GetPrintDialogData().GetPrintData(); + GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData + printDialog->Destroy(); + + // Now update the dialog in case the page setup dialog changed some of our settings. + TransferDataToWindow(); } wxGenericPageSetupDialog::wxGenericPageSetupDialog(wxWindow *parent, wxPageSetupData* data): - wxDialog(parent, -1, _("Page Setup"), wxPoint(0, 0), wxSize(600, 600), wxDIALOG_MODAL|wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL) +wxDialog(parent, -1, _("Page Setup"), wxPoint(0, 0), wxSize(600, 600), wxDIALOG_MODAL|wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL) { - if ( data ) - pageData = *data; - - int buttonWidth = 75; - int buttonHeight = 25; - int spacing = 5; + if ( data ) + m_pageData = *data; + + int buttonWidth = 75; + int buttonHeight = 25; + int spacing = 5; #ifdef __WXMOTIF__ - spacing = 15; + spacing = 15; #endif - - int yPos = 5; - int xPos = 5; - - wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(5, yPos), wxSize(buttonWidth, buttonHeight)); - (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(buttonWidth + 5 + spacing, yPos), wxSize(buttonWidth, buttonHeight)); - - printerButton = new wxButton(this, wxPRINTID_SETUP, _("Printer..."), wxPoint(buttonWidth*2 + 5 + 2*spacing, yPos), wxSize(buttonWidth, buttonHeight)); - - if ( !pageData.GetEnablePrinter() ) - printerButton->Enable(FALSE); - -// if (printData.GetEnableHelp()) -// wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), -1, -1, buttonWidth, buttonHeight); - - okButton->SetDefault(); - okButton->SetFocus(); - - xPos = 5; - yPos += 35; - + + int yPos = 5; + int xPos = 5; + + wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(5, yPos), wxSize(buttonWidth, buttonHeight)); + (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(buttonWidth + 5 + spacing, yPos), wxSize(buttonWidth, buttonHeight)); + + m_printerButton = new wxButton(this, wxPRINTID_SETUP, _("Printer..."), wxPoint(buttonWidth*2 + 5 + 2*spacing, yPos), wxSize(buttonWidth, buttonHeight)); + + if ( !m_pageData.GetEnablePrinter() ) + m_printerButton->Enable(FALSE); + + // if (m_printData.GetEnableHelp()) + // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), -1, -1, buttonWidth, buttonHeight); + + okButton->SetDefault(); + okButton->SetFocus(); + + xPos = 5; + yPos += 35; + #ifdef __WXMOTIF__ - yPos += 10; + yPos += 10; #endif - - paperTypeChoice = CreatePaperTypeChoice(&xPos, &yPos); - - xPos = 5; - - wxString *choices = new wxString[2]; - choices[0] = _("Portrait"); - choices[1] = _("Landscape"); - orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"), - wxPoint(xPos, yPos), wxSize(-1, -1), 2, choices, 2); - orientationRadioBox->SetSelection(0); - - xPos = 5; - yPos += 60; - - int staticWidth = 110; + + m_paperTypeChoice = CreatePaperTypeChoice(&xPos, &yPos); + + xPos = 5; + + wxString *choices = new wxString[2]; + choices[0] = _("Portrait"); + choices[1] = _("Landscape"); + m_orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"), + wxPoint(xPos, yPos), wxSize(-1, -1), 2, choices, 2); + m_orientationRadioBox->SetSelection(0); + + xPos = 5; + yPos += 60; + + int staticWidth = 110; #ifdef __WXMOTIF__ - staticWidth += 20; + staticWidth += 20; #endif + + int textWidth = 60; + spacing = 10; + + (void) new wxStaticText(this, wxPRINTID_STATIC, _("Left margin (mm):"), wxPoint(xPos, yPos)); + xPos += staticWidth; + + m_marginLeftText = new wxTextCtrl(this, wxPRINTID_LEFTMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1)); + xPos += textWidth + spacing; + + (void) new wxStaticText(this, wxPRINTID_STATIC, _("Right margin (mm):"), wxPoint(xPos, yPos)); + xPos += staticWidth; + + m_marginRightText = new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1)); + xPos += textWidth + spacing; + + yPos += 35; + xPos = 5; + + (void) new wxStaticText(this, wxPRINTID_STATIC, _("Top margin (mm):"), wxPoint(xPos, yPos)); + xPos += staticWidth; + + m_marginTopText = new wxTextCtrl(this, wxPRINTID_TOPMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1)); + xPos += textWidth + spacing; + + (void) new wxStaticText(this, wxPRINTID_STATIC, _("Bottom margin (mm):"), wxPoint(xPos, yPos)); + xPos += staticWidth; + + m_marginBottomText = new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1)); + + Fit(); + Centre(wxBOTH); + + InitDialog(); + delete [] choices; +} - int textWidth = 60; - spacing = 10; - - (void) new wxStaticText(this, wxPRINTID_STATIC, _("Left margin (mm):"), wxPoint(xPos, yPos)); - xPos += staticWidth; - - marginLeftText = new wxTextCtrl(this, wxPRINTID_LEFTMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1)); - xPos += textWidth + spacing; - - (void) new wxStaticText(this, wxPRINTID_STATIC, _("Right margin (mm):"), wxPoint(xPos, yPos)); - xPos += staticWidth; - - marginRightText = new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1)); - xPos += textWidth + spacing; - - yPos += 35; - xPos = 5; - - (void) new wxStaticText(this, wxPRINTID_STATIC, _("Top margin (mm):"), wxPoint(xPos, yPos)); - xPos += staticWidth; - - marginTopText = new wxTextCtrl(this, wxPRINTID_TOPMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1)); - xPos += textWidth + spacing; +wxGenericPageSetupDialog::~wxGenericPageSetupDialog() +{ +} - (void) new wxStaticText(this, wxPRINTID_STATIC, _("Bottom margin (mm):"), wxPoint(xPos, yPos)); - xPos += staticWidth; +bool wxGenericPageSetupDialog::TransferDataToWindow() +{ + if (m_marginLeftText) + m_marginLeftText->SetValue(IntToString((int) m_pageData.GetMarginTopLeft().x)); + if (m_marginTopText) + m_marginTopText->SetValue(IntToString((int) m_pageData.GetMarginTopLeft().y)); + if (m_marginRightText) + m_marginRightText->SetValue(IntToString((int) m_pageData.GetMarginBottomRight().x)); + if (m_marginBottomText) + m_marginBottomText->SetValue(IntToString((int) m_pageData.GetMarginBottomRight().y)); + + if (m_orientationRadioBox) + { + if (m_pageData.GetPrintData().GetOrientation() == wxPORTRAIT) + m_orientationRadioBox->SetSelection(0); + else + m_orientationRadioBox->SetSelection(1); + } - marginBottomText = new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1)); + // Find the paper type from either the current paper size in the wxPageSetupDialogData, or + // failing that, the id in the wxPrintData object. - Fit(); - Centre(wxBOTH); + wxPrintPaperType* type = wxThePrintPaperDatabase->FindPaperType( + wxSize(m_pageData.GetPaperSize().x * 10, m_pageData.GetPaperSize().y * 10)); - InitDialog(); - delete [] choices; -} + if (!type && m_pageData.GetPrintData().GetPaperId() != wxPAPER_NONE) + type = wxThePrintPaperDatabase->FindPaperType(m_pageData.GetPrintData().GetPaperId()); -wxGenericPageSetupDialog::~wxGenericPageSetupDialog(void) -{ -} + if (type) + { + m_paperTypeChoice->SetStringSelection(type->GetName()); + } -bool wxGenericPageSetupDialog::TransferDataToWindow(void) -{ - if (marginLeftText) - marginLeftText->SetValue(IntToString((int) pageData.GetMarginTopLeft().x)); - if (marginTopText) - marginTopText->SetValue(IntToString((int) pageData.GetMarginTopLeft().y)); - if (marginRightText) - marginRightText->SetValue(IntToString((int) pageData.GetMarginBottomRight().x)); - if (marginBottomText) - marginBottomText->SetValue(IntToString((int) pageData.GetMarginBottomRight().y)); - - if (orientationRadioBox) - { - if (pageData.GetOrientation() == wxPORTRAIT) - orientationRadioBox->SetSelection(0); - else - orientationRadioBox->SetSelection(1); - } - return TRUE; + return TRUE; } -bool wxGenericPageSetupDialog::TransferDataFromWindow(void) +bool wxGenericPageSetupDialog::TransferDataFromWindow() { - if (marginLeftText && marginTopText) - pageData.SetMarginTopLeft(wxPoint(atoi((const char *)marginLeftText->GetValue()),atoi((const char *)marginTopText->GetValue()))); - if (marginRightText && marginBottomText) - pageData.SetMarginBottomRight(wxPoint(atoi((const char *)marginRightText->GetValue()),atoi((const char *)marginBottomText->GetValue()))); - - if (orientationRadioBox) - { - int sel = orientationRadioBox->GetSelection(); - if (sel == 0) + if (m_marginLeftText && m_marginTopText) + m_pageData.SetMarginTopLeft(wxPoint(atoi((const char *)m_marginLeftText->GetValue()),atoi((const char *)m_marginTopText->GetValue()))); + if (m_marginRightText && m_marginBottomText) + m_pageData.SetMarginBottomRight(wxPoint(atoi((const char *)m_marginRightText->GetValue()),atoi((const char *)m_marginBottomText->GetValue()))); + + if (m_orientationRadioBox) { + int sel = m_orientationRadioBox->GetSelection(); + if (sel == 0) + { #if wxUSE_POSTSCRIPT - wxThePrintSetupData->SetPrinterOrientation(wxPORTRAIT); + wxThePrintSetupData->SetPrinterOrientation(wxPORTRAIT); #endif - pageData.SetOrientation(wxPORTRAIT); - } - else - { + m_pageData.GetPrintData().SetOrientation(wxPORTRAIT); + } + else + { #if wxUSE_POSTSCRIPT - wxThePrintSetupData->SetPrinterOrientation(wxLANDSCAPE); + wxThePrintSetupData->SetPrinterOrientation(wxLANDSCAPE); #endif - pageData.SetOrientation(wxLANDSCAPE); + m_pageData.GetPrintData().SetOrientation(wxLANDSCAPE); + } } - } - if (paperTypeChoice) - { - wxString val(paperTypeChoice->GetStringSelection()); - if (!val.IsNull() && val != "") + if (m_paperTypeChoice) { - wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType((char*) (const char *)val); - if ( paper ) + wxString val(m_paperTypeChoice->GetStringSelection()); + if (!val.IsNull() && val != "") { - pageData.SetPaperSize(wxPoint(paper->widthMM, paper->heightMM)); + wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType(val); + if ( paper ) + { + m_pageData.SetPaperSize(wxSize(paper->GetWidth()/10, paper->GetHeight()/10)); + m_pageData.GetPrintData().SetPaperId(paper->GetId()); + } } } - } - - return TRUE; + + return TRUE; } wxChoice *wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x, int *y) { - if (!wxThePrintPaperDatabase) - { - wxThePrintPaperDatabase = new wxPrintPaperDatabase; - wxThePrintPaperDatabase->CreateDatabase(); - } - int n = wxThePrintPaperDatabase->Number(); - wxString *choices = new wxString [n]; - int sel = 0; - int i; - for (i = 0; i < n; i++) - { - wxPrintPaperType *paper = (wxPrintPaperType *)wxThePrintPaperDatabase->Nth(i)->Data(); - choices[i] = paper->pageName; - if (pageData.GetPaperSize().x == paper->widthMM && pageData.GetPaperSize().y == paper->heightMM) - sel = i; - } - - (void) new wxStaticText(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(*x, *y)); - *y += 25; - - wxChoice *choice = new wxChoice(this, wxPRINTID_PAPERSIZE, wxPoint(*x, *y), wxSize(300, -1), n, - choices); - *y += 35; - delete[] choices; - - choice->SetSelection(sel); - return choice; +/* + if (!wxThePrintPaperDatabase) + { + wxThePrintPaperDatabase = new wxPrintPaperDatabase; + wxThePrintPaperDatabase->CreateDatabase(); + } +*/ + + int n = wxThePrintPaperDatabase->Number(); + wxString *choices = new wxString [n]; + int i; + for (i = 0; i < n; i++) + { + wxPrintPaperType *paper = (wxPrintPaperType *)wxThePrintPaperDatabase->Nth(i)->Data(); + choices[i] = paper->GetName(); + } + + (void) new wxStaticText(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(*x, *y)); + *y += 25; + + wxChoice *choice = new wxChoice(this, wxPRINTID_PAPERSIZE, wxPoint(*x, *y), wxSize(300, -1), n, + choices); + *y += 35; + delete[] choices; + +// choice->SetSelection(sel); + return choice; } diff --git a/src/gtk.inc b/src/gtk.inc index 96d9e38020..85ab1775eb 100644 --- a/src/gtk.inc +++ b/src/gtk.inc @@ -39,6 +39,7 @@ LIB_CPP_SRC=\ common/dbtable.cpp \ common/prntbase.cpp \ common/serbase.cpp \ + common/paper.cpp \ common/string.cpp \ common/textfile.cpp \ common/time.cpp \ diff --git a/src/gtk/dc.cpp b/src/gtk/dc.cpp index 2f287d17ad..f101829e97 100644 --- a/src/gtk/dc.cpp +++ b/src/gtk/dc.cpp @@ -194,13 +194,20 @@ void wxDC::GetSize( int* width, int* height ) const if (height) *height = m_maxY-m_minY; } -void wxDC::GetSizeMM( long* width, long* height ) const +void wxDC::GetSizeMM( int* width, int* height ) const { int w = 0; int h = 0; GetSize( &w, &h ); - if (width) *width = long( double(w) / (m_scaleX*m_mm_to_pix_x) ); - if (height) *height = long( double(h) / (m_scaleY*m_mm_to_pix_y) ); + if (width) *width = int( double(w) / (m_scaleX*m_mm_to_pix_x) ); + if (height) *height = int( double(h) / (m_scaleY*m_mm_to_pix_y) ); +} + +// Resolution in pixels per logical inch +wxSize wxDC::GetPPI(void) const +{ + // TODO (should probably be pure virtual) + return wxSize(0, 0); } void wxDC::SetTextForeground( const wxColour &col ) diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 7f5e5e5a8d..b6044d4b6c 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -1370,6 +1370,11 @@ void wxWindowDC::DrawSpline( wxList *points ) wx_spline_draw_point_array( this ); } +// Resolution in pixels per logical inch +wxSize wxWindowDC::GetPPI(void) const +{ + return wxSize(100, 100); +} //----------------------------------------------------------------------------- // wxPaintDC diff --git a/src/gtk1/dc.cpp b/src/gtk1/dc.cpp index 2f287d17ad..f101829e97 100644 --- a/src/gtk1/dc.cpp +++ b/src/gtk1/dc.cpp @@ -194,13 +194,20 @@ void wxDC::GetSize( int* width, int* height ) const if (height) *height = m_maxY-m_minY; } -void wxDC::GetSizeMM( long* width, long* height ) const +void wxDC::GetSizeMM( int* width, int* height ) const { int w = 0; int h = 0; GetSize( &w, &h ); - if (width) *width = long( double(w) / (m_scaleX*m_mm_to_pix_x) ); - if (height) *height = long( double(h) / (m_scaleY*m_mm_to_pix_y) ); + if (width) *width = int( double(w) / (m_scaleX*m_mm_to_pix_x) ); + if (height) *height = int( double(h) / (m_scaleY*m_mm_to_pix_y) ); +} + +// Resolution in pixels per logical inch +wxSize wxDC::GetPPI(void) const +{ + // TODO (should probably be pure virtual) + return wxSize(0, 0); } void wxDC::SetTextForeground( const wxColour &col ) diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index 7f5e5e5a8d..b6044d4b6c 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -1370,6 +1370,11 @@ void wxWindowDC::DrawSpline( wxList *points ) wx_spline_draw_point_array( this ); } +// Resolution in pixels per logical inch +wxSize wxWindowDC::GetPPI(void) const +{ + return wxSize(100, 100); +} //----------------------------------------------------------------------------- // wxPaintDC diff --git a/src/motif.inc b/src/motif.inc index 7fd1c95a06..9429866884 100644 --- a/src/motif.inc +++ b/src/motif.inc @@ -35,6 +35,7 @@ LIB_CPP_SRC=\ common/mimetype.cpp \ common/module.cpp \ common/object.cpp \ + common/paper.cpp \ common/prntbase.cpp \ common/resource.cpp \ common/serbase.cpp \ diff --git a/src/motif/app.cpp b/src/motif/app.cpp index c8b0dff704..ba8f0da012 100644 --- a/src/motif/app.cpp +++ b/src/motif/app.cpp @@ -29,7 +29,9 @@ #include "wx/module.h" #include "wx/memory.h" +#if wxUSE_THREADS #include "wx/thread.h" +#endif #if wxUSE_WX_RESOURCES #include "wx/resource.h" @@ -297,11 +299,13 @@ int wxApp::MainLoop() { if (!ProcessIdle()) { +#if wxUSE_THREADS // leave the main loop to give other threads a chance to // perform their GUI work wxMutexGuiLeave(); wxUsleep(20); wxMutexGuiEnter(); +#endif } } @@ -509,8 +513,9 @@ bool wxApp::OnInitGui() argv); if (!dpy) { + wxString className(wxTheApp->GetClassName()); wxLogError(_("wxWindows could not open display for '%s': exiting."), - wxTheApp->GetClassName()); + (const char*) className); exit(-1); } m_initialDisplay = (WXDisplay*) dpy; diff --git a/src/motif/bitmap.cpp b/src/motif/bitmap.cpp index 2f1b0e5218..0f6bb1a7a5 100644 --- a/src/motif/bitmap.cpp +++ b/src/motif/bitmap.cpp @@ -197,7 +197,7 @@ bool wxBitmap::LoadFile(const wxString& filename, long type) wxBitmapHandler *handler = FindHandler(type); if ( handler == NULL ) { - wxLogWarning("no bitmap handler for type %d defined.", type); + wxLogWarning("%s: no bitmap handler for type %d defined.", (const char*) filename, type); return FALSE; } @@ -214,7 +214,7 @@ bool wxBitmap::Create(void *data, long type, int width, int height, int depth) wxBitmapHandler *handler = FindHandler(type); if ( handler == NULL ) { - wxLogWarning("no bitmap handler for type %d defined.", type); + wxLogWarning("no data bitmap handler for type %d defined.", type); return FALSE; } @@ -790,7 +790,7 @@ void wxBitmap::InitStandardHandlers() AddHandler(new wxXBMFileHandler); AddHandler(new wxXBMDataHandler); - // XPM is considered standard for Moif, although it can be omitted if absolutely + // XPM is considered standard for Motif, although it can be omitted if absolutely // necessary. #if wxUSE_XPM AddHandler(new wxXPMFileHandler); diff --git a/src/motif/dc.cpp b/src/motif/dc.cpp index 319fe79b5f..3e822c4836 100644 --- a/src/motif/dc.cpp +++ b/src/motif/dc.cpp @@ -213,15 +213,22 @@ void wxDC::GetSize( int* width, int* height ) const *height = m_maxY-m_minY; }; -void wxDC::GetSizeMM( long* width, long* height ) const +void wxDC::GetSizeMM( int* width, int* height ) const { int w = 0; int h = 0; GetSize( &w, &h ); - *width = long( double(w) / (m_scaleX*m_mm_to_pix_x) ); - *height = long( double(h) / (m_scaleY*m_mm_to_pix_y) ); + *width = int( double(w) / (m_scaleX*m_mm_to_pix_x) ); + *height = int( double(h) / (m_scaleY*m_mm_to_pix_y) ); }; +// Resolution in pixels per logical inch +wxSize wxDC::GetPPI(void) const +{ + // TODO (should probably be pure virtual) + return wxSize(0, 0); +} + void wxDC::SetTextForeground( const wxColour &col ) { if (!Ok()) return; diff --git a/src/motif/dcclient.cpp b/src/motif/dcclient.cpp index 7d0d99e08f..c2945cd6dd 100644 --- a/src/motif/dcclient.cpp +++ b/src/motif/dcclient.cpp @@ -2323,6 +2323,12 @@ void wxWindowDC::DrawSpline( wxList *points ) wx_spline_draw_point_array( this ); }; +// Resolution in pixels per logical inch +wxSize wxWindowDC::GetPPI(void) const +{ + return wxSize(100, 100); +} + /* * wxPaintDC */ diff --git a/src/motif/makefile.unx b/src/motif/makefile.unx index 15b53d06b8..84fb0d06bc 100644 --- a/src/motif/makefile.unx +++ b/src/motif/makefile.unx @@ -42,6 +42,7 @@ LIB_CPP_SRC=\ ../common/prntbase.cpp \ ../common/resource.cpp \ ../common/serbase.cpp \ + ../common/paper.cpp \ ../common/string.cpp \ ../common/textfile.cpp \ ../common/tbarbase.cpp \ @@ -71,6 +72,9 @@ LIB_CPP_SRC=\ ../common/http.cpp \ ../common/url.cpp \ ../common/tokenzr.cpp \ +\ + ../unix/threadpsx.cpp \ + ../unix/utilsunx.cpp \ \ accel.cpp \ app.cpp \ @@ -121,11 +125,9 @@ LIB_CPP_SRC=\ stattext.cpp \ taskbar.cpp \ textctrl.cpp \ - thread.cpp \ timer.cpp \ toolbar.cpp \ utils.cpp \ - utilsexc.cpp \ wave.cpp \ window.cpp \ \ diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 970a074492..6372787796 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -69,61 +69,60 @@ IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) // Default constructor wxDC::wxDC(void) { - m_minX = 0; m_minY = 0; m_maxX = 0; m_maxY = 0; - m_clipping = FALSE; - - m_filename = ""; - m_canvas = NULL; - m_oldBitmap = 0; - m_oldPen = 0; - m_oldBrush = 0; - m_oldFont = 0; - m_oldPalette = 0; - m_minX = 0; m_minY = 0; m_maxX = 0; m_maxY = 0; - m_logicalOriginX = 0; - m_logicalOriginY = 0; - m_deviceOriginX = 0; - m_deviceOriginY = 0; - m_logicalScaleX = 1.0; - m_logicalScaleY = 1.0; - m_userScaleX = 1.0; - m_userScaleY = 1.0; - m_signX = 1; - m_signY = 1; - m_systemScaleX = 1.0; - m_systemScaleY = 1.0; - m_mappingMode = wxMM_TEXT; - m_bOwnsDC = FALSE; - m_hDC = 0; - m_clipping = FALSE; - m_ok = TRUE; - m_windowExtX = VIEWPORT_EXTENT; - m_windowExtY = VIEWPORT_EXTENT; - m_logicalFunction = -1; - - m_backgroundBrush = *wxWHITE_BRUSH; - - m_textForegroundColour = *wxBLACK; - m_textBackgroundColour = *wxWHITE; - - m_colour = wxColourDisplay(); - - m_hDCCount = 0; + m_minX = 0; m_minY = 0; m_maxX = 0; m_maxY = 0; + m_clipping = FALSE; + + m_canvas = NULL; + m_oldBitmap = 0; + m_oldPen = 0; + m_oldBrush = 0; + m_oldFont = 0; + m_oldPalette = 0; + m_minX = 0; m_minY = 0; m_maxX = 0; m_maxY = 0; + m_logicalOriginX = 0; + m_logicalOriginY = 0; + m_deviceOriginX = 0; + m_deviceOriginY = 0; + m_logicalScaleX = 1.0; + m_logicalScaleY = 1.0; + m_userScaleX = 1.0; + m_userScaleY = 1.0; + m_signX = 1; + m_signY = 1; + m_systemScaleX = 1.0; + m_systemScaleY = 1.0; + m_mappingMode = wxMM_TEXT; + m_bOwnsDC = FALSE; + m_hDC = 0; + m_clipping = FALSE; + m_ok = TRUE; + m_windowExtX = VIEWPORT_EXTENT; + m_windowExtY = VIEWPORT_EXTENT; + m_logicalFunction = -1; + + m_backgroundBrush = *wxWHITE_BRUSH; + + m_textForegroundColour = *wxBLACK; + m_textBackgroundColour = *wxWHITE; + + m_colour = wxColourDisplay(); + + m_hDCCount = 0; } wxDC::~wxDC(void) { - if ( m_hDC != 0 ) { - SelectOldObjects(m_hDC); - if ( m_bOwnsDC ) { - if ( m_canvas == NULL ) - ::DeleteDC((HDC)m_hDC); - else - ::ReleaseDC((HWND)m_canvas->GetHWND(), (HDC)m_hDC); + if ( m_hDC != 0 ) { + SelectOldObjects(m_hDC); + if ( m_bOwnsDC ) { + if ( m_canvas == NULL ) + ::DeleteDC((HDC)m_hDC); + else + ::ReleaseDC((HWND)m_canvas->GetHWND(), (HDC)m_hDC); + } } - } - + } // This will select current objects out of the DC, @@ -131,496 +130,496 @@ wxDC::~wxDC(void) // DC. void wxDC::SelectOldObjects(WXHDC dc) { - if (dc) - { - if (m_oldBitmap) - { - ::SelectObject((HDC) dc, (HBITMAP) m_oldBitmap); - if (m_selectedBitmap.Ok()) - { - m_selectedBitmap.SetSelectedInto(NULL); - } - } - m_oldBitmap = 0 ; - if (m_oldPen) + if (dc) { - ::SelectObject((HDC) dc, (HPEN) m_oldPen); - } - m_oldPen = 0 ; - if (m_oldBrush) - { - ::SelectObject((HDC) dc, (HBRUSH) m_oldBrush); - } - m_oldBrush = 0 ; - if (m_oldFont) - { - ::SelectObject((HDC) dc, (HFONT) m_oldFont); - } - m_oldFont = 0 ; - if (m_oldPalette) - { - ::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, TRUE); + if (m_oldBitmap) + { + ::SelectObject((HDC) dc, (HBITMAP) m_oldBitmap); + if (m_selectedBitmap.Ok()) + { + m_selectedBitmap.SetSelectedInto(NULL); + } + } + m_oldBitmap = 0 ; + if (m_oldPen) + { + ::SelectObject((HDC) dc, (HPEN) m_oldPen); + } + m_oldPen = 0 ; + if (m_oldBrush) + { + ::SelectObject((HDC) dc, (HBRUSH) m_oldBrush); + } + m_oldBrush = 0 ; + if (m_oldFont) + { + ::SelectObject((HDC) dc, (HFONT) m_oldFont); + } + m_oldFont = 0 ; + if (m_oldPalette) + { + ::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, TRUE); + } + m_oldPalette = 0 ; } - m_oldPalette = 0 ; - } - - m_brush = wxNullBrush ; - m_pen = wxNullPen; - m_palette = wxNullPalette; - m_font = wxNullFont; - m_backgroundBrush = wxNullBrush; - m_selectedBitmap = wxNullBitmap; + + m_brush = wxNullBrush ; + m_pen = wxNullPen; + m_palette = wxNullPalette; + m_font = wxNullFont; + m_backgroundBrush = wxNullBrush; + m_selectedBitmap = wxNullBitmap; } void wxDC::SetClippingRegion(long cx, long cy, long cw, long ch) { - m_clipping = TRUE; - m_clipX1 = (int)cx; - m_clipY1 = (int)cy; - m_clipX2 = (int)(cx + cw); - m_clipY2 = (int)(cy + ch); - - DoClipping((WXHDC) m_hDC); + m_clipping = TRUE; + m_clipX1 = (int)cx; + m_clipY1 = (int)cy; + m_clipX2 = (int)(cx + cw); + m_clipY2 = (int)(cy + ch); + + DoClipping((WXHDC) m_hDC); } void wxDC::SetClippingRegion(const wxRegion& region) { - if (!region.GetHRGN()) - return; - - wxRect box = region.GetBox(); - - m_clipping = TRUE; - m_clipX1 = box.x; - m_clipY1 = box.y; - m_clipX2 = box.x + box.width; - m_clipY2 = box.y + box.height; - + if (!region.GetHRGN()) + return; + + wxRect box = region.GetBox(); + + m_clipping = TRUE; + m_clipX1 = box.x; + m_clipY1 = box.y; + m_clipX2 = box.x + box.width; + m_clipY2 = box.y + box.height; + #ifdef __WIN16__ - SelectClipRgn((HDC) m_hDC, (HRGN) region.GetHRGN()); + SelectClipRgn((HDC) m_hDC, (HRGN) region.GetHRGN()); #else - ExtSelectClipRgn((HDC) m_hDC, (HRGN) region.GetHRGN(), RGN_AND); + ExtSelectClipRgn((HDC) m_hDC, (HRGN) region.GetHRGN(), RGN_AND); #endif } void wxDC::DoClipping(WXHDC dc) { - if (m_clipping && dc) - { - IntersectClipRect((HDC) dc, XLOG2DEV(m_clipX1), YLOG2DEV(m_clipY1), - XLOG2DEV(m_clipX2), YLOG2DEV(m_clipY2)); - } + if (m_clipping && dc) + { + IntersectClipRect((HDC) dc, XLOG2DEV(m_clipX1), YLOG2DEV(m_clipY1), + XLOG2DEV(m_clipX2), YLOG2DEV(m_clipY2)); + } } void wxDC::DestroyClippingRegion(void) { - if (m_clipping && m_hDC) - { - // TODO: this should restore the previous clipping region, - // so that OnPaint processing works correctly, and the update clipping region - // doesn't get destroyed after the first DestroyClippingRegion. - HRGN rgn = CreateRectRgn(0, 0, 32000, 32000); - SelectClipRgn((HDC) m_hDC, rgn); - DeleteObject(rgn); - } - m_clipping = FALSE; + if (m_clipping && m_hDC) + { + // TODO: this should restore the previous clipping region, + // so that OnPaint processing works correctly, and the update clipping region + // doesn't get destroyed after the first DestroyClippingRegion. + HRGN rgn = CreateRectRgn(0, 0, 32000, 32000); + SelectClipRgn((HDC) m_hDC, rgn); + DeleteObject(rgn); + } + m_clipping = FALSE; } bool wxDC::CanDrawBitmap(void) const { - return TRUE; + return TRUE; } bool wxDC::CanGetTextExtent(void) const { - // What sort of display is it? - int technology = ::GetDeviceCaps((HDC) m_hDC, TECHNOLOGY); - - bool ok; - - if (technology != DT_RASDISPLAY && technology != DT_RASPRINTER) - ok = FALSE; - else ok = TRUE; - - return ok; + // What sort of display is it? + int technology = ::GetDeviceCaps((HDC) m_hDC, TECHNOLOGY); + + bool ok; + + if (technology != DT_RASDISPLAY && technology != DT_RASPRINTER) + ok = FALSE; + else ok = TRUE; + + return ok; } void wxDC::SetPalette(const wxPalette& palette) { - // Set the old object temporarily, in case the assignment deletes an object - // that's not yet selected out. - if (m_oldPalette) - { - ::SelectPalette((HDC) m_hDC, (HPALETTE) m_oldPalette, TRUE); - m_oldPalette = 0; - } - - m_palette = palette; - - if (!m_palette.Ok()) - { - // Setting a NULL colourmap is a way of restoring - // the original colourmap + // Set the old object temporarily, in case the assignment deletes an object + // that's not yet selected out. if (m_oldPalette) { - ::SelectPalette((HDC) m_hDC, (HPALETTE) m_oldPalette, TRUE); - m_oldPalette = 0; + ::SelectPalette((HDC) m_hDC, (HPALETTE) m_oldPalette, TRUE); + m_oldPalette = 0; } - - return; - } - if (m_palette.Ok() && m_palette.GetHPALETTE()) - { - HPALETTE oldPal = ::SelectPalette((HDC) m_hDC, (HPALETTE) m_palette.GetHPALETTE(), TRUE); - if (!m_oldPalette) - m_oldPalette = (WXHPALETTE) oldPal; - - ::RealizePalette((HDC) m_hDC); - } + m_palette = palette; + + if (!m_palette.Ok()) + { + // Setting a NULL colourmap is a way of restoring + // the original colourmap + if (m_oldPalette) + { + ::SelectPalette((HDC) m_hDC, (HPALETTE) m_oldPalette, TRUE); + m_oldPalette = 0; + } + + return; + } + + if (m_palette.Ok() && m_palette.GetHPALETTE()) + { + HPALETTE oldPal = ::SelectPalette((HDC) m_hDC, (HPALETTE) m_palette.GetHPALETTE(), TRUE); + if (!m_oldPalette) + m_oldPalette = (WXHPALETTE) oldPal; + + ::RealizePalette((HDC) m_hDC); + } } void wxDC::Clear(void) { - RECT rect; - if (m_canvas) - GetClientRect((HWND) m_canvas->GetHWND(), &rect); - else if (m_selectedBitmap.Ok()) - { - rect.left = 0; rect.top = 0; - rect.right = m_selectedBitmap.GetWidth(); - rect.bottom = m_selectedBitmap.GetHeight(); - } - (void) ::SetMapMode((HDC) m_hDC, MM_TEXT); - - DWORD colour = GetBkColor((HDC) m_hDC); - HBRUSH brush = CreateSolidBrush(colour); - FillRect((HDC) m_hDC, &rect, brush); - DeleteObject(brush); - - ::SetMapMode((HDC) m_hDC, MM_ANISOTROPIC); - ::SetViewportExtEx((HDC) m_hDC, VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL); - ::SetWindowExtEx((HDC) m_hDC, m_windowExtX, m_windowExtY, NULL); - ::SetViewportOrgEx((HDC) m_hDC, (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); - ::SetWindowOrgEx((HDC) m_hDC, (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); + RECT rect; + if (m_canvas) + GetClientRect((HWND) m_canvas->GetHWND(), &rect); + else if (m_selectedBitmap.Ok()) + { + rect.left = 0; rect.top = 0; + rect.right = m_selectedBitmap.GetWidth(); + rect.bottom = m_selectedBitmap.GetHeight(); + } + (void) ::SetMapMode((HDC) m_hDC, MM_TEXT); + + DWORD colour = GetBkColor((HDC) m_hDC); + HBRUSH brush = CreateSolidBrush(colour); + FillRect((HDC) m_hDC, &rect, brush); + DeleteObject(brush); + + ::SetMapMode((HDC) m_hDC, MM_ANISOTROPIC); + ::SetViewportExtEx((HDC) m_hDC, VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL); + ::SetWindowExtEx((HDC) m_hDC, m_windowExtX, m_windowExtY, NULL); + ::SetViewportOrgEx((HDC) m_hDC, (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); + ::SetWindowOrgEx((HDC) m_hDC, (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); } void wxDC::FloodFill(long x, long y, const wxColour& col, int style) { - (void)ExtFloodFill((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), - col.GetPixel(), - style==wxFLOOD_SURFACE? - FLOODFILLSURFACE:FLOODFILLBORDER - ); - - CalcBoundingBox(x, y); + (void)ExtFloodFill((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), + col.GetPixel(), + style==wxFLOOD_SURFACE? +FLOODFILLSURFACE:FLOODFILLBORDER + ); + + CalcBoundingBox(x, y); } bool wxDC::GetPixel(long x, long y, wxColour *col) const { - // added by steve 29.12.94 (copied from DrawPoint) - // returns TRUE for pixels in the color of the current pen - // and FALSE for all other pixels colors - // if col is non-NULL return the color of the pixel - - // get the color of the pixel - COLORREF pixelcolor = ::GetPixel((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y)); - // get the color of the pen - COLORREF pencolor = 0x00ffffff; - if (m_pen.Ok()) - { - pencolor = m_pen.GetColour().GetPixel() ; - } - - // return the color of the pixel - if(col) - col->Set(GetRValue(pixelcolor),GetGValue(pixelcolor),GetBValue(pixelcolor)); - - // check, if color of the pixels is the same as the color - // of the current pen - return(pixelcolor==pencolor); + // added by steve 29.12.94 (copied from DrawPoint) + // returns TRUE for pixels in the color of the current pen + // and FALSE for all other pixels colors + // if col is non-NULL return the color of the pixel + + // get the color of the pixel + COLORREF pixelcolor = ::GetPixel((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y)); + // get the color of the pen + COLORREF pencolor = 0x00ffffff; + if (m_pen.Ok()) + { + pencolor = m_pen.GetColour().GetPixel() ; + } + + // return the color of the pixel + if(col) + col->Set(GetRValue(pixelcolor),GetGValue(pixelcolor),GetBValue(pixelcolor)); + + // check, if color of the pixels is the same as the color + // of the current pen + return(pixelcolor==pencolor); } void wxDC::CrossHair(long x, long y) { - // We suppose that our screen is 2000x2000 max. - long x1 = x-2000; - long y1 = y-2000; - long x2 = x+2000; - long y2 = y+2000; - - (void)MoveToEx((HDC) m_hDC, XLOG2DEV(x1), YLOG2DEV(y), NULL); - (void)LineTo((HDC) m_hDC, XLOG2DEV(x2), YLOG2DEV(y)); - - (void)MoveToEx((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y1), NULL); - (void)LineTo((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y2)); - - CalcBoundingBox(x1, y1); - CalcBoundingBox(x2, y2); + // We suppose that our screen is 2000x2000 max. + long x1 = x-2000; + long y1 = y-2000; + long x2 = x+2000; + long y2 = y+2000; + + (void)MoveToEx((HDC) m_hDC, XLOG2DEV(x1), YLOG2DEV(y), NULL); + (void)LineTo((HDC) m_hDC, XLOG2DEV(x2), YLOG2DEV(y)); + + (void)MoveToEx((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y1), NULL); + (void)LineTo((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y2)); + + CalcBoundingBox(x1, y1); + CalcBoundingBox(x2, y2); } void wxDC::DrawLine(long x1, long y1, long x2, long y2) { - (void)MoveToEx((HDC) m_hDC, XLOG2DEV(x1), YLOG2DEV(y1), NULL); - (void)LineTo((HDC) m_hDC, XLOG2DEV(x2), YLOG2DEV(y2)); - - /* MATTHEW: [6] New normalization */ + (void)MoveToEx((HDC) m_hDC, XLOG2DEV(x1), YLOG2DEV(y1), NULL); + (void)LineTo((HDC) m_hDC, XLOG2DEV(x2), YLOG2DEV(y2)); + + /* MATTHEW: [6] New normalization */ #if WX_STANDARD_GRAPHICS - (void)LineTo((HDC) m_hDC, XLOG2DEV(x2) + 1, YLOG2DEV(y2)); + (void)LineTo((HDC) m_hDC, XLOG2DEV(x2) + 1, YLOG2DEV(y2)); #endif - - CalcBoundingBox(x1, y1); - CalcBoundingBox(x2, y2); + + CalcBoundingBox(x1, y1); + CalcBoundingBox(x2, y2); } void wxDC::DrawArc(long x1,long y1,long x2,long y2, long xc, long yc) { - double dx = xc-x1 ; - double dy = yc-y1 ; - double radius = (double)sqrt(dx*dx+dy*dy) ;; - if (x1==x2 && x2==y2) - { - DrawEllipse(xc,yc,(long)(radius*2.0),(long)(radius*2.0)) ; - return ; - } - - long xx1 = XLOG2DEV(x1) ; - long yy1 = YLOG2DEV(y1) ; - long xx2 = XLOG2DEV(x2) ; - long yy2 = YLOG2DEV(y2) ; - long xxc = XLOG2DEV(xc) ; - long yyc = YLOG2DEV(yc) ; - long ray = (long) sqrt(double((xxc-xx1)*(xxc-xx1)+(yyc-yy1)*(yyc-yy1))) ; - - (void)MoveToEx((HDC) m_hDC, (int) xx1, (int) yy1, NULL); - long xxx1 = (long) (xxc-ray); - long yyy1 = (long) (yyc-ray); - long xxx2 = (long) (xxc+ray); - long yyy2 = (long) (yyc+ray); - if (m_brush.Ok() && m_brush.GetStyle() !=wxTRANSPARENT) - { - // Have to add 1 to bottom-right corner of rectangle - // to make semi-circles look right (crooked line otherwise). - // Unfortunately this is not a reliable method, depends - // on the size of shape. - // TODO: figure out why this happens! - Pie((HDC) m_hDC,xxx1,yyy1,xxx2+1,yyy2+1, - xx1,yy1,xx2,yy2) ; - } - else - Arc((HDC) m_hDC,xxx1,yyy1,xxx2,yyy2, + double dx = xc-x1 ; + double dy = yc-y1 ; + double radius = (double)sqrt(dx*dx+dy*dy) ;; + if (x1==x2 && x2==y2) + { + DrawEllipse(xc,yc,(long)(radius*2.0),(long)(radius*2.0)) ; + return ; + } + + long xx1 = XLOG2DEV(x1) ; + long yy1 = YLOG2DEV(y1) ; + long xx2 = XLOG2DEV(x2) ; + long yy2 = YLOG2DEV(y2) ; + long xxc = XLOG2DEV(xc) ; + long yyc = YLOG2DEV(yc) ; + long ray = (long) sqrt(double((xxc-xx1)*(xxc-xx1)+(yyc-yy1)*(yyc-yy1))) ; + + (void)MoveToEx((HDC) m_hDC, (int) xx1, (int) yy1, NULL); + long xxx1 = (long) (xxc-ray); + long yyy1 = (long) (yyc-ray); + long xxx2 = (long) (xxc+ray); + long yyy2 = (long) (yyc+ray); + if (m_brush.Ok() && m_brush.GetStyle() !=wxTRANSPARENT) + { + // Have to add 1 to bottom-right corner of rectangle + // to make semi-circles look right (crooked line otherwise). + // Unfortunately this is not a reliable method, depends + // on the size of shape. + // TODO: figure out why this happens! + Pie((HDC) m_hDC,xxx1,yyy1,xxx2+1,yyy2+1, + xx1,yy1,xx2,yy2) ; + } + else + Arc((HDC) m_hDC,xxx1,yyy1,xxx2,yyy2, xx1,yy1,xx2,yy2) ; - - CalcBoundingBox((xc-radius), (yc-radius)); - CalcBoundingBox((xc+radius), (yc+radius)); + + CalcBoundingBox((xc-radius), (yc-radius)); + CalcBoundingBox((xc+radius), (yc+radius)); } void wxDC::DrawPoint(long x, long y) { - COLORREF color = 0x00ffffff; - if (m_pen.Ok()) - { - color = m_pen.GetColour().GetPixel() ; - } - - SetPixel((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), color); - - CalcBoundingBox(x, y); + COLORREF color = 0x00ffffff; + if (m_pen.Ok()) + { + color = m_pen.GetColour().GetPixel() ; + } + + SetPixel((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), color); + + CalcBoundingBox(x, y); } void wxDC::DrawPolygon(int n, wxPoint points[], long xoffset, long yoffset,int fillStyle) { - // Do things less efficiently if we have offsets - if (xoffset != 0 || yoffset != 0) - { - POINT *cpoints = new POINT[n]; - int i; - for (i = 0; i < n; i++) + // Do things less efficiently if we have offsets + if (xoffset != 0 || yoffset != 0) { - cpoints[i].x = (int)(points[i].x + xoffset); - cpoints[i].y = (int)(points[i].y + yoffset); - - CalcBoundingBox(cpoints[i].x, cpoints[i].y); + POINT *cpoints = new POINT[n]; + int i; + for (i = 0; i < n; i++) + { + cpoints[i].x = (int)(points[i].x + xoffset); + cpoints[i].y = (int)(points[i].y + yoffset); + + CalcBoundingBox(cpoints[i].x, cpoints[i].y); + } + int prev = SetPolyFillMode((HDC) m_hDC,fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING) ; + (void)Polygon((HDC) m_hDC, cpoints, n); + SetPolyFillMode((HDC) m_hDC,prev) ; + delete[] cpoints; + } + else + { + int i; + for (i = 0; i < n; i++) + CalcBoundingBox(points[i].x, points[i].y); + + int prev = SetPolyFillMode((HDC) m_hDC,fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING) ; + (void)Polygon((HDC) m_hDC, (POINT*) points, n); + SetPolyFillMode((HDC) m_hDC,prev) ; } - int prev = SetPolyFillMode((HDC) m_hDC,fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING) ; - (void)Polygon((HDC) m_hDC, cpoints, n); - SetPolyFillMode((HDC) m_hDC,prev) ; - delete[] cpoints; - } - else - { - int i; - for (i = 0; i < n; i++) - CalcBoundingBox(points[i].x, points[i].y); - - int prev = SetPolyFillMode((HDC) m_hDC,fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING) ; - (void)Polygon((HDC) m_hDC, (POINT*) points, n); - SetPolyFillMode((HDC) m_hDC,prev) ; - } } void wxDC::DrawLines(int n, wxPoint points[], long xoffset, long yoffset) { - // Do things less efficiently if we have offsets - if (xoffset != 0 || yoffset != 0) - { - POINT *cpoints = new POINT[n]; - int i; - for (i = 0; i < n; i++) + // Do things less efficiently if we have offsets + if (xoffset != 0 || yoffset != 0) { - cpoints[i].x = (int)(points[i].x + xoffset); - cpoints[i].y = (int)(points[i].y + yoffset); - - CalcBoundingBox(cpoints[i].x, cpoints[i].y); + POINT *cpoints = new POINT[n]; + int i; + for (i = 0; i < n; i++) + { + cpoints[i].x = (int)(points[i].x + xoffset); + cpoints[i].y = (int)(points[i].y + yoffset); + + CalcBoundingBox(cpoints[i].x, cpoints[i].y); + } + (void)Polyline((HDC) m_hDC, cpoints, n); + delete[] cpoints; + } + else + { + int i; + for (i = 0; i < n; i++) + CalcBoundingBox(points[i].x, points[i].y); + + (void)Polyline((HDC) m_hDC, (POINT*) points, n); } - (void)Polyline((HDC) m_hDC, cpoints, n); - delete[] cpoints; - } - else - { - int i; - for (i = 0; i < n; i++) - CalcBoundingBox(points[i].x, points[i].y); - - (void)Polyline((HDC) m_hDC, (POINT*) points, n); - } } void wxDC::DrawRectangle(long x, long y, long width, long height) { - long x2 = x + width; - long y2 = y + height; - -/* MATTHEW: [6] new normalization */ + long x2 = x + width; + long y2 = y + height; + + /* MATTHEW: [6] new normalization */ #if WX_STANDARD_GRAPHICS - bool do_brush, do_pen; - - do_brush = m_brush.Ok() && m_brush.GetStyle() != wxTRANSPARENT; - do_pen = m_pen.Ok() && m_pen.GetStyle() != wxTRANSPARENT; - - if (do_brush) { - HPEN orig_pen = NULL; - - if (do_pen || !m_pen.Ok()) - orig_pen = (HPEN) ::SelectObject((HDC) m_hDC, (HPEN) ::GetStockObject(NULL_PEN)); - - (void)Rectangle((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), - XLOG2DEV(x2) + 1, YLOG2DEV(y2) + 1); - - if (do_pen || !m_pen.Ok()) - ::SelectObject((HDC) m_hDC , orig_pen); - } - if (do_pen) { - HBRUSH orig_brush = NULL; - - if (do_brush || !m_brush.Ok()) - orig_brush = (HBRUSH) ::SelectObject((HDC) m_hDC, (HBRUSH) ::GetStockObject(NULL_BRUSH)); - - (void)Rectangle((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), - XLOG2DEV(x2), YLOG2DEV(y2)); - - if (do_brush || !m_brush.Ok()) - ::SelectObject((HDC) m_hDC, orig_brush); - } + bool do_brush, do_pen; + + do_brush = m_brush.Ok() && m_brush.GetStyle() != wxTRANSPARENT; + do_pen = m_pen.Ok() && m_pen.GetStyle() != wxTRANSPARENT; + + if (do_brush) { + HPEN orig_pen = NULL; + + if (do_pen || !m_pen.Ok()) + orig_pen = (HPEN) ::SelectObject((HDC) m_hDC, (HPEN) ::GetStockObject(NULL_PEN)); + + (void)Rectangle((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), + XLOG2DEV(x2) + 1, YLOG2DEV(y2) + 1); + + if (do_pen || !m_pen.Ok()) + ::SelectObject((HDC) m_hDC , orig_pen); + } + if (do_pen) { + HBRUSH orig_brush = NULL; + + if (do_brush || !m_brush.Ok()) + orig_brush = (HBRUSH) ::SelectObject((HDC) m_hDC, (HBRUSH) ::GetStockObject(NULL_BRUSH)); + + (void)Rectangle((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), + XLOG2DEV(x2), YLOG2DEV(y2)); + + if (do_brush || !m_brush.Ok()) + ::SelectObject((HDC) m_hDC, orig_brush); + } #else - (void)Rectangle((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); + (void)Rectangle((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); #endif - - CalcBoundingBox(x, y); - CalcBoundingBox(x2, y2); + + CalcBoundingBox(x, y); + CalcBoundingBox(x2, y2); } void wxDC::DrawRoundedRectangle(long x, long y, long width, long height, double radius) { - // Now, a negative radius value is interpreted to mean - // 'the proportion of the smallest X or Y dimension' - - if (radius < 0.0) - { - double smallest = 0.0; - if (width < height) - smallest = width; - else - smallest = height; - radius = (- radius * smallest); - } - - long x2 = (x+width); - long y2 = (y+height); - - (void)RoundRect((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), - YLOG2DEV(y2), 2*XLOG2DEV(radius), 2*YLOG2DEV(radius)); - - CalcBoundingBox(x, y); - CalcBoundingBox(x2, y2); + // Now, a negative radius value is interpreted to mean + // 'the proportion of the smallest X or Y dimension' + + if (radius < 0.0) + { + double smallest = 0.0; + if (width < height) + smallest = width; + else + smallest = height; + radius = (- radius * smallest); + } + + long x2 = (x+width); + long y2 = (y+height); + + (void)RoundRect((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), + YLOG2DEV(y2), 2*XLOG2DEV(radius), 2*YLOG2DEV(radius)); + + CalcBoundingBox(x, y); + CalcBoundingBox(x2, y2); } void wxDC::DrawEllipse(long x, long y, long width, long height) { - long x2 = (x+width); - long y2 = (y+height); - - (void)Ellipse((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); - - CalcBoundingBox(x, y); - CalcBoundingBox(x2, y2); + long x2 = (x+width); + long y2 = (y+height); + + (void)Ellipse((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); + + CalcBoundingBox(x, y); + CalcBoundingBox(x2, y2); } // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows void wxDC::DrawEllipticArc(long x,long y,long w,long h,double sa,double ea) { - long x2 = (x+w); - long y2 = (y+h); - - const double deg2rad = 3.14159265359 / 180.0; - int rx1 = XLOG2DEV(x+w/2); - int ry1 = YLOG2DEV(y+h/2); - int rx2 = rx1; - int ry2 = ry1; - rx1 += (int)(100.0 * abs(w) * cos(sa * deg2rad)); - ry1 -= (int)(100.0 * abs(h) * m_signY * sin(sa * deg2rad)); - rx2 += (int)(100.0 * abs(w) * cos(ea * deg2rad)); - ry2 -= (int)(100.0 * abs(h) * m_signY * sin(ea * deg2rad)); - - // draw pie with NULL_PEN first and then outline otherwise a line is - // drawn from the start and end points to the centre - HPEN orig_pen = (HPEN) ::SelectObject((HDC) m_hDC, (HPEN) ::GetStockObject(NULL_PEN)); - if (m_signY > 0) - { - (void)Pie((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2)+1, YLOG2DEV(y2)+1, + long x2 = (x+w); + long y2 = (y+h); + + const double deg2rad = 3.14159265359 / 180.0; + int rx1 = XLOG2DEV(x+w/2); + int ry1 = YLOG2DEV(y+h/2); + int rx2 = rx1; + int ry2 = ry1; + rx1 += (int)(100.0 * abs(w) * cos(sa * deg2rad)); + ry1 -= (int)(100.0 * abs(h) * m_signY * sin(sa * deg2rad)); + rx2 += (int)(100.0 * abs(w) * cos(ea * deg2rad)); + ry2 -= (int)(100.0 * abs(h) * m_signY * sin(ea * deg2rad)); + + // draw pie with NULL_PEN first and then outline otherwise a line is + // drawn from the start and end points to the centre + HPEN orig_pen = (HPEN) ::SelectObject((HDC) m_hDC, (HPEN) ::GetStockObject(NULL_PEN)); + if (m_signY > 0) + { + (void)Pie((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2)+1, YLOG2DEV(y2)+1, + rx1, ry1, rx2, ry2); + } + else + { + (void)Pie((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y)-1, XLOG2DEV(x2)+1, YLOG2DEV(y2), + rx1, ry1-1, rx2, ry2-1); + } + ::SelectObject((HDC) m_hDC, orig_pen); + (void)Arc((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2), rx1, ry1, rx2, ry2); - } - else - { - (void)Pie((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y)-1, XLOG2DEV(x2)+1, YLOG2DEV(y2), - rx1, ry1-1, rx2, ry2-1); - } - ::SelectObject((HDC) m_hDC, orig_pen); - (void)Arc((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2), - rx1, ry1, rx2, ry2); - - CalcBoundingBox(x, y); - CalcBoundingBox(x2, y2); + + CalcBoundingBox(x, y); + CalcBoundingBox(x2, y2); } void wxDC::DrawIcon(const wxIcon& icon, long x, long y) { #if defined(__WIN32__) && !defined(__SC__) && !defined(__TWIN32__) - ::DrawIconEx((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON(), - icon.GetWidth(), icon.GetHeight(), 0, 0, DI_NORMAL); + ::DrawIconEx((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON(), + icon.GetWidth(), icon.GetHeight(), 0, 0, DI_NORMAL); #else - ::DrawIcon((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON()); + ::DrawIcon((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON()); #endif - - CalcBoundingBox(x, y); - CalcBoundingBox(x+icon.GetWidth(), y+icon.GetHeight()); + + CalcBoundingBox(x, y); + CalcBoundingBox(x+icon.GetWidth(), y+icon.GetHeight()); } void wxDC::DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) { if (!bmp.Ok()) return; - + // If we're not drawing transparently, and not drawing to a printer, // optimize this function to use Windows functions. if (!useMask && !IsKindOf(CLASSINFO(wxPrinterDC))) @@ -638,221 +637,221 @@ void wxDC::DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) // Rather than reproduce wxDC::Blit, let's do it at the wxWin API level wxMemoryDC memDC; memDC.SelectObject(bmp); - + /* Not sure if we need this. The mask should leave the - * masked areas as per the original background of this DC. - */ -/* + * masked areas as per the original background of this DC. + */ + /* // There might be transparent areas, so make these // the same colour as this DC memDC.SetBackground(* GetBackground()); memDC.Clear(); -*/ - + */ + Blit(x, y, bmp.GetWidth(), bmp.GetHeight(), & memDC, 0, 0, wxCOPY, useMask); - + memDC.SelectObject(wxNullBitmap); } } void wxDC::SetFont(const wxFont& the_font) { - // Set the old object temporarily, in case the assignment deletes an object - // that's not yet selected out. - if (m_oldFont) - { - ::SelectObject((HDC) m_hDC, (HFONT) m_oldFont); - m_oldFont = 0; - } - - m_font = the_font; - - if (!the_font.Ok()) - { + // Set the old object temporarily, in case the assignment deletes an object + // that's not yet selected out. if (m_oldFont) - ::SelectObject((HDC) m_hDC, (HFONT) m_oldFont); - m_oldFont = 0 ; - } - - if (m_font.Ok() && m_font.GetResourceHandle()) - { - HFONT f = (HFONT) ::SelectObject((HDC) m_hDC, (HFONT) m_font.GetResourceHandle()); - if (f == (HFONT) NULL) { - wxDebugMsg("::SelectObject failed in wxDC::SetFont."); + ::SelectObject((HDC) m_hDC, (HFONT) m_oldFont); + m_oldFont = 0; + } + + m_font = the_font; + + if (!the_font.Ok()) + { + if (m_oldFont) + ::SelectObject((HDC) m_hDC, (HFONT) m_oldFont); + m_oldFont = 0 ; + } + + if (m_font.Ok() && m_font.GetResourceHandle()) + { + HFONT f = (HFONT) ::SelectObject((HDC) m_hDC, (HFONT) m_font.GetResourceHandle()); + if (f == (HFONT) NULL) + { + wxDebugMsg("::SelectObject failed in wxDC::SetFont."); + } + if (!m_oldFont) + m_oldFont = (WXHFONT) f; } - if (!m_oldFont) - m_oldFont = (WXHFONT) f; - } } void wxDC::SetPen(const wxPen& pen) { - // Set the old object temporarily, in case the assignment deletes an object - // that's not yet selected out. - if (m_oldPen) - { - ::SelectObject((HDC) m_hDC, (HPEN) m_oldPen); - m_oldPen = 0; - } - - m_pen = pen; - - if (!m_pen.Ok()) - { + // Set the old object temporarily, in case the assignment deletes an object + // that's not yet selected out. if (m_oldPen) - ::SelectObject((HDC) m_hDC, (HPEN) m_oldPen); - m_oldPen = 0 ; - } - - if (m_pen.Ok()) - { - if (m_pen.GetResourceHandle()) { - HPEN p = (HPEN) ::SelectObject((HDC) m_hDC, (HPEN)m_pen.GetResourceHandle()) ; - if (!m_oldPen) - m_oldPen = (WXHPEN) p; + ::SelectObject((HDC) m_hDC, (HPEN) m_oldPen); + m_oldPen = 0; + } + + m_pen = pen; + + if (!m_pen.Ok()) + { + if (m_oldPen) + ::SelectObject((HDC) m_hDC, (HPEN) m_oldPen); + m_oldPen = 0 ; + } + + if (m_pen.Ok()) + { + if (m_pen.GetResourceHandle()) + { + HPEN p = (HPEN) ::SelectObject((HDC) m_hDC, (HPEN)m_pen.GetResourceHandle()) ; + if (!m_oldPen) + m_oldPen = (WXHPEN) p; + } } - } } void wxDC::SetBrush(const wxBrush& brush) { - // Set the old object temporarily, in case the assignment deletes an object - // that's not yet selected out. - if (m_oldBrush) - { - ::SelectObject((HDC) m_hDC, (HBRUSH) m_oldBrush); - m_oldBrush = 0; - } - - m_brush = brush; - - if (!m_brush.Ok()) - { + // Set the old object temporarily, in case the assignment deletes an object + // that's not yet selected out. if (m_oldBrush) - ::SelectObject((HDC) m_hDC, (HBRUSH) m_oldBrush); - m_oldBrush = 0 ; - } - - if (m_brush.Ok()) - { - if (m_brush.GetResourceHandle()) { - HBRUSH b = 0; - b = (HBRUSH) ::SelectObject((HDC) m_hDC, (HBRUSH)m_brush.GetResourceHandle()) ; - if (!m_oldBrush) - m_oldBrush = (WXHBRUSH) b; + ::SelectObject((HDC) m_hDC, (HBRUSH) m_oldBrush); + m_oldBrush = 0; + } + + m_brush = brush; + + if (!m_brush.Ok()) + { + if (m_oldBrush) + ::SelectObject((HDC) m_hDC, (HBRUSH) m_oldBrush); + m_oldBrush = 0 ; + } + + if (m_brush.Ok()) + { + if (m_brush.GetResourceHandle()) + { + HBRUSH b = 0; + b = (HBRUSH) ::SelectObject((HDC) m_hDC, (HBRUSH)m_brush.GetResourceHandle()) ; + if (!m_oldBrush) + m_oldBrush = (WXHBRUSH) b; + } } - } } void wxDC::DrawText(const wxString& text, long x, long y, bool use16bit) { // Should be unnecessary: SetFont should have done this already. #if 0 - if (m_font.Ok() && m_font.GetResourceHandle()) - { - HFONT f = (HFONT) ::SelectObject((HDC) m_hDC, (HFONT) m_font.GetResourceHandle()); - if (!m_oldFont) - m_oldFont = (WXHFONT) f; - } + if (m_font.Ok() && m_font.GetResourceHandle()) + { + HFONT f = (HFONT) ::SelectObject((HDC) m_hDC, (HFONT) m_font.GetResourceHandle()); + if (!m_oldFont) + m_oldFont = (WXHFONT) f; + } #endif - - if (m_textForegroundColour.Ok()) - SetTextColor((HDC) m_hDC, m_textForegroundColour.GetPixel() ) ; - - DWORD old_background = 0; - if (m_textBackgroundColour.Ok()) - { - old_background = SetBkColor((HDC) m_hDC, m_textBackgroundColour.GetPixel() ) ; - } - - if (m_backgroundMode == wxTRANSPARENT) - SetBkMode((HDC) m_hDC, TRANSPARENT); - else - SetBkMode((HDC) m_hDC, OPAQUE); - - (void)TextOut((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), (char *) (const char *)text, strlen((const char *)text)); - - if (m_textBackgroundColour.Ok()) - (void)SetBkColor((HDC) m_hDC, old_background); - - CalcBoundingBox(x, y); - - long w, h; - GetTextExtent(text, &w, &h); - CalcBoundingBox((x + w), (y + h)); + + if (m_textForegroundColour.Ok()) + SetTextColor((HDC) m_hDC, m_textForegroundColour.GetPixel() ) ; + + DWORD old_background = 0; + if (m_textBackgroundColour.Ok()) + { + old_background = SetBkColor((HDC) m_hDC, m_textBackgroundColour.GetPixel() ) ; + } + + if (m_backgroundMode == wxTRANSPARENT) + SetBkMode((HDC) m_hDC, TRANSPARENT); + else + SetBkMode((HDC) m_hDC, OPAQUE); + + (void)TextOut((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), (char *) (const char *)text, strlen((const char *)text)); + + if (m_textBackgroundColour.Ok()) + (void)SetBkColor((HDC) m_hDC, old_background); + + CalcBoundingBox(x, y); + + long w, h; + GetTextExtent(text, &w, &h); + CalcBoundingBox((x + w), (y + h)); } void wxDC::SetBackground(const wxBrush& brush) { - m_backgroundBrush = brush; - - if (!m_backgroundBrush.Ok()) - return; - - if (m_canvas) - { - bool customColours = TRUE; - // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to - // change background colours from the control-panel specified colours. - if (m_canvas->IsKindOf(CLASSINFO(wxWindow)) && ((m_canvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS)) - customColours = FALSE; - - if (customColours) + m_backgroundBrush = brush; + + if (!m_backgroundBrush.Ok()) + return; + + if (m_canvas) { - if (m_backgroundBrush.GetStyle()==wxTRANSPARENT) - { - m_canvas->m_backgroundTransparent = TRUE; - } - else - { - // New behaviour, 10/2/99: setting the background brush of a DC - // doesn't affect the window background colour. However, - // I'm leaving in the transparency setting because it's needed by - // various controls (e.g. wxStaticText) to determine whether to draw - // transparently or not. TODO: maybe this should be a new function - // wxWindow::SetTransparency(). Should that apply to the child itself, or the - // parent? -// m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour()); - m_canvas->m_backgroundTransparent = FALSE; - } + bool customColours = TRUE; + // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to + // change background colours from the control-panel specified colours. + if (m_canvas->IsKindOf(CLASSINFO(wxWindow)) && ((m_canvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS)) + customColours = FALSE; + + if (customColours) + { + if (m_backgroundBrush.GetStyle()==wxTRANSPARENT) + { + m_canvas->m_backgroundTransparent = TRUE; + } + else + { + // New behaviour, 10/2/99: setting the background brush of a DC + // doesn't affect the window background colour. However, + // I'm leaving in the transparency setting because it's needed by + // various controls (e.g. wxStaticText) to determine whether to draw + // transparently or not. TODO: maybe this should be a new function + // wxWindow::SetTransparency(). Should that apply to the child itself, or the + // parent? + // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour()); + m_canvas->m_backgroundTransparent = FALSE; + } + } + } + COLORREF new_color = m_backgroundBrush.GetColour().GetPixel() ; + { + (void)SetBkColor((HDC) m_hDC, new_color); } - } - COLORREF new_color = m_backgroundBrush.GetColour().GetPixel() ; - { - (void)SetBkColor((HDC) m_hDC, new_color); - } } void wxDC::SetBackgroundMode(int mode) { - m_backgroundMode = mode; - - if (m_backgroundMode == wxTRANSPARENT) - ::SetBkMode((HDC) m_hDC, TRANSPARENT); - else - ::SetBkMode((HDC) m_hDC, OPAQUE); + m_backgroundMode = mode; + + if (m_backgroundMode == wxTRANSPARENT) + ::SetBkMode((HDC) m_hDC, TRANSPARENT); + else + ::SetBkMode((HDC) m_hDC, OPAQUE); } void wxDC::SetLogicalFunction(int function) { - m_logicalFunction = function; - - SetRop((WXHDC) m_hDC); + m_logicalFunction = function; + + SetRop((WXHDC) m_hDC); } void wxDC::SetRop(WXHDC dc) { - if (!dc || m_logicalFunction < 0) - return; - - int c_rop; - // These may be wrong - switch (m_logicalFunction) - { -// case wxXOR: c_rop = R2_XORPEN; break; + if (!dc || m_logicalFunction < 0) + return; + + int c_rop; + // These may be wrong + switch (m_logicalFunction) + { + // case wxXOR: c_rop = R2_XORPEN; break; case wxXOR: c_rop = R2_NOTXORPEN; break; case wxINVERT: c_rop = R2_NOT; break; case wxOR_REVERSE: c_rop = R2_MERGEPENNOT; break; @@ -868,225 +867,172 @@ void wxDC::SetRop(WXHDC dc) case wxNAND: case wxCOPY: default: - c_rop = R2_COPYPEN; break; - } - SetROP2((HDC) dc, c_rop); + c_rop = R2_COPYPEN; break; + } + SetROP2((HDC) dc, c_rop); } bool wxDC::StartDoc(const wxString& message) { - if (!this->IsKindOf(CLASSINFO(wxPrinterDC))) + // We might be previewing, so return TRUE to let it continue. return TRUE; - - DOCINFO docinfo; - docinfo.cbSize = sizeof(DOCINFO); - docinfo.lpszDocName = (const char *)message; - - if (m_filename.IsEmpty()) - docinfo.lpszOutput = NULL; - else - docinfo.lpszOutput = (const char *)m_filename; - -#if defined(__WIN95__) - docinfo.lpszDatatype = NULL; - docinfo.fwType = 0; -#endif - - if (!m_hDC) - return FALSE; - - int ret = -#ifndef __WIN32__ - ::StartDoc((HDC) m_hDC, &docinfo); -#else -#ifdef UNICODE - ::StartDocW((HDC) m_hDC, &docinfo); -#else -#ifdef __TWIN32__ - ::StartDoc((HDC) m_hDC, &docinfo); -#else - ::StartDocA((HDC) m_hDC, &docinfo); -#endif -#endif -#endif - -#ifndef __WIN16__ - if (ret <= 0) - { - DWORD lastError = GetLastError(); - wxDebugMsg("wxDC::StartDoc failed with error: %d\n", lastError); - } -#endif - - return (ret > 0); } void wxDC::EndDoc(void) { - if (!this->IsKindOf(CLASSINFO(wxPrinterDC))) - return; - if (m_hDC) ::EndDoc((HDC) m_hDC); } void wxDC::StartPage(void) { - if (!this->IsKindOf(CLASSINFO(wxPrinterDC))) - return; - if (m_hDC) - ::StartPage((HDC) m_hDC); } void wxDC::EndPage(void) { - if (!this->IsKindOf(CLASSINFO(wxPrinterDC))) - return; - if (m_hDC) - ::EndPage((HDC) m_hDC); } long wxDC::GetCharHeight(void) const { - TEXTMETRIC lpTextMetric; - - GetTextMetrics((HDC) m_hDC, &lpTextMetric); - - return YDEV2LOGREL(lpTextMetric.tmHeight); + TEXTMETRIC lpTextMetric; + + GetTextMetrics((HDC) m_hDC, &lpTextMetric); + + return YDEV2LOGREL(lpTextMetric.tmHeight); } long wxDC::GetCharWidth(void) const { - TEXTMETRIC lpTextMetric; - - GetTextMetrics((HDC) m_hDC, &lpTextMetric); - - return XDEV2LOGREL(lpTextMetric.tmAveCharWidth); + TEXTMETRIC lpTextMetric; + + GetTextMetrics((HDC) m_hDC, &lpTextMetric); + + return XDEV2LOGREL(lpTextMetric.tmAveCharWidth); } void wxDC::GetTextExtent(const wxString& string, long *x, long *y, long *descent, long *externalLeading, wxFont *theFont, bool use16bit) const { - wxFont *fontToUse = (wxFont*) theFont; - if (!fontToUse) - fontToUse = (wxFont*) &m_font; - - SIZE sizeRect; - TEXTMETRIC tm; - - GetTextExtentPoint((HDC) m_hDC, (char *)(const char *) string, strlen((char *)(const char *) string), &sizeRect); - GetTextMetrics((HDC) m_hDC, &tm); - - if (x) *x = XDEV2LOGREL(sizeRect.cx); - if (y) *y = YDEV2LOGREL(sizeRect.cy); - if (descent) *descent = tm.tmDescent; - if (externalLeading) *externalLeading = tm.tmExternalLeading; + wxFont *fontToUse = (wxFont*) theFont; + if (!fontToUse) + fontToUse = (wxFont*) &m_font; + + SIZE sizeRect; + TEXTMETRIC tm; + + GetTextExtentPoint((HDC) m_hDC, (char *)(const char *) string, strlen((char *)(const char *) string), &sizeRect); + GetTextMetrics((HDC) m_hDC, &tm); + + if (x) *x = XDEV2LOGREL(sizeRect.cx); + if (y) *y = YDEV2LOGREL(sizeRect.cy); + if (descent) *descent = tm.tmDescent; + if (externalLeading) *externalLeading = tm.tmExternalLeading; } void wxDC::SetMapMode(int mode) { - m_mappingMode = mode; - - int pixel_width = 0; - int pixel_height = 0; - int mm_width = 0; - int mm_height = 0; - - pixel_width = GetDeviceCaps((HDC) m_hDC, HORZRES); - pixel_height = GetDeviceCaps((HDC) m_hDC, VERTRES); - mm_width = GetDeviceCaps((HDC) m_hDC, HORZSIZE); - mm_height = GetDeviceCaps((HDC) m_hDC, VERTSIZE); - - if ((pixel_width == 0) || (pixel_height == 0) || (mm_width == 0) || (mm_height == 0)) - { - return; - } - - double mm2pixelsX = pixel_width/mm_width; - double mm2pixelsY = pixel_height/mm_height; - - switch (mode) - { - case wxMM_TWIPS: + m_mappingMode = mode; + + int pixel_width = 0; + int pixel_height = 0; + int mm_width = 0; + int mm_height = 0; + + pixel_width = GetDeviceCaps((HDC) m_hDC, HORZRES); + pixel_height = GetDeviceCaps((HDC) m_hDC, VERTRES); + mm_width = GetDeviceCaps((HDC) m_hDC, HORZSIZE); + mm_height = GetDeviceCaps((HDC) m_hDC, VERTSIZE); + + if ((pixel_width == 0) || (pixel_height == 0) || (mm_width == 0) || (mm_height == 0)) { - m_logicalScaleX = (twips2mm * mm2pixelsX); - m_logicalScaleY = (twips2mm * mm2pixelsY); - break; + return; } - case wxMM_POINTS: + + double mm2pixelsX = pixel_width/mm_width; + double mm2pixelsY = pixel_height/mm_height; + + switch (mode) { - m_logicalScaleX = (pt2mm * mm2pixelsX); - m_logicalScaleY = (pt2mm * mm2pixelsY); - break; - } + case wxMM_TWIPS: + { + m_logicalScaleX = (twips2mm * mm2pixelsX); + m_logicalScaleY = (twips2mm * mm2pixelsY); + break; + } + case wxMM_POINTS: + { + m_logicalScaleX = (pt2mm * mm2pixelsX); + m_logicalScaleY = (pt2mm * mm2pixelsY); + break; + } case wxMM_METRIC: - { - m_logicalScaleX = mm2pixelsX; - m_logicalScaleY = mm2pixelsY; - break; - } + { + m_logicalScaleX = mm2pixelsX; + m_logicalScaleY = mm2pixelsY; + break; + } case wxMM_LOMETRIC: - { - m_logicalScaleX = (mm2pixelsX/10.0); - m_logicalScaleY = (mm2pixelsY/10.0); - break; - } + { + m_logicalScaleX = (mm2pixelsX/10.0); + m_logicalScaleY = (mm2pixelsY/10.0); + break; + } default: case wxMM_TEXT: - { - m_logicalScaleX = 1.0; - m_logicalScaleY = 1.0; - break; + { + m_logicalScaleX = 1.0; + m_logicalScaleY = 1.0; + break; + } } - } - - if (::GetMapMode((HDC) m_hDC) != MM_ANISOTROPIC) - ::SetMapMode((HDC) m_hDC, MM_ANISOTROPIC); - - SetViewportExtEx((HDC) m_hDC, VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL); - m_windowExtX = (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT); - m_windowExtY = (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT); - ::SetWindowExtEx((HDC) m_hDC, m_windowExtX, m_windowExtY, NULL); - ::SetViewportOrgEx((HDC) m_hDC, (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); - ::SetWindowOrgEx((HDC) m_hDC, (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); + + if (::GetMapMode((HDC) m_hDC) != MM_ANISOTROPIC) + ::SetMapMode((HDC) m_hDC, MM_ANISOTROPIC); + + SetViewportExtEx((HDC) m_hDC, VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL); + m_windowExtX = (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT); + m_windowExtY = (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT); + ::SetWindowExtEx((HDC) m_hDC, m_windowExtX, m_windowExtY, NULL); + ::SetViewportOrgEx((HDC) m_hDC, (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); + ::SetWindowOrgEx((HDC) m_hDC, (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); } void wxDC::SetUserScale(double x, double y) { - m_userScaleX = x; - m_userScaleY = y; - - SetMapMode(m_mappingMode); + m_userScaleX = x; + m_userScaleY = y; + + SetMapMode(m_mappingMode); } void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp) { - m_signX = xLeftRight ? 1 : -1; - m_signY = yBottomUp ? -1 : 1; - - SetMapMode(m_mappingMode); + m_signX = xLeftRight ? 1 : -1; + m_signY = yBottomUp ? -1 : 1; + + SetMapMode(m_mappingMode); } void wxDC::SetSystemScale(double x, double y) { - m_systemScaleX = x; - m_systemScaleY = y; - - SetMapMode(m_mappingMode); + m_systemScaleX = x; + m_systemScaleY = y; + + SetMapMode(m_mappingMode); } void wxDC::SetLogicalOrigin(long x, long y) { - m_logicalOriginX = x; - m_logicalOriginY = y; - - ::SetWindowOrgEx((HDC) m_hDC, (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); + m_logicalOriginX = x; + m_logicalOriginY = y; + + ::SetWindowOrgEx((HDC) m_hDC, (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); } void wxDC::SetDeviceOrigin(long x, long y) { - m_deviceOriginX = x; - m_deviceOriginY = y; - - ::SetViewportOrgEx((HDC) m_hDC, (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); + m_deviceOriginX = x; + m_deviceOriginY = y; + + ::SetViewportOrgEx((HDC) m_hDC, (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); } long wxDC::DeviceToLogicalX(long x) const @@ -1135,265 +1081,273 @@ long wxDC::LogicalToDeviceYRel(long y) const long wxDC::ImplDeviceToLogicalX(long x) const { -// return (m_scaleGDI ? x : DeviceToLogicalX(x)); + // return (m_scaleGDI ? x : DeviceToLogicalX(x)); return x; } long wxDC::ImplDeviceToLogicalY(long y) const { -// return (m_scaleGDI ? y : DeviceToLogicalY(y)); + // return (m_scaleGDI ? y : DeviceToLogicalY(y)); return y; } long wxDC::ImplDeviceToLogicalXRel(long x) const { -// return (m_scaleGDI ? x : DeviceToLogicalXRel(x)); + // return (m_scaleGDI ? x : DeviceToLogicalXRel(x)); return x; } long wxDC::ImplDeviceToLogicalYRel(long y) const { -// return (m_scaleGDI ? y : DeviceToLogicalYRel(y)); + // return (m_scaleGDI ? y : DeviceToLogicalYRel(y)); return y; } long wxDC::ImplLogicalToDeviceX(long x) const { -// return (m_scaleGDI ? (floor(double(x))) : LogicalToDeviceX(x)); + // return (m_scaleGDI ? (floor(double(x))) : LogicalToDeviceX(x)); return x; } long wxDC::ImplLogicalToDeviceY(long y) const { -// return (m_scaleGDI ? (floor(double(y))) : LogicalToDeviceY(y)); + // return (m_scaleGDI ? (floor(double(y))) : LogicalToDeviceY(y)); return y; } long wxDC::ImplLogicalToDeviceXRel(long x) const { -// return (m_scaleGDI ? (floor(double(x))) : LogicalToDeviceXRel(x)); + // return (m_scaleGDI ? (floor(double(x))) : LogicalToDeviceXRel(x)); return x; } long wxDC::ImplLogicalToDeviceYRel(long y) const { -// return (m_scaleGDI ? (floor(double(y))) : LogicalToDeviceYRel(y)); + // return (m_scaleGDI ? (floor(double(y))) : LogicalToDeviceYRel(y)); return y; } bool wxDC::Blit(long xdest, long ydest, long width, long height, wxDC *source, long xsrc, long ysrc, int rop, bool useMask) { - long xdest1 = xdest; - long ydest1 = ydest; - long xsrc1 = xsrc; - long ysrc1 = ysrc; - - // Chris Breeze 18/5/98: use text foreground/background colours - // when blitting from 1-bit bitmaps - COLORREF old_textground = ::GetTextColor((HDC)m_hDC); - COLORREF old_background = ::GetBkColor((HDC)m_hDC); - if (m_textForegroundColour.Ok()) - { - ::SetTextColor((HDC) m_hDC, m_textForegroundColour.GetPixel() ) ; - } - if (m_textBackgroundColour.Ok()) - { - ::SetBkColor((HDC) m_hDC, m_textBackgroundColour.GetPixel() ) ; - } - - DWORD dwRop = rop == wxCOPY ? SRCCOPY : - rop == wxCLEAR ? WHITENESS : - rop == wxSET ? BLACKNESS : - rop == wxINVERT ? DSTINVERT : - rop == wxAND ? MERGECOPY : - rop == wxOR ? MERGEPAINT : - rop == wxSRC_INVERT ? NOTSRCCOPY : - rop == wxXOR ? SRCINVERT : - rop == wxOR_REVERSE ? MERGEPAINT : - rop == wxAND_REVERSE ? SRCERASE : - rop == wxSRC_OR ? SRCPAINT : - rop == wxSRC_AND ? SRCAND : - SRCCOPY; - - bool success = TRUE; - if (useMask && source->m_selectedBitmap.Ok() && source->m_selectedBitmap.GetMask()) - { - + long xdest1 = xdest; + long ydest1 = ydest; + long xsrc1 = xsrc; + long ysrc1 = ysrc; + + // Chris Breeze 18/5/98: use text foreground/background colours + // when blitting from 1-bit bitmaps + COLORREF old_textground = ::GetTextColor((HDC)m_hDC); + COLORREF old_background = ::GetBkColor((HDC)m_hDC); + if (m_textForegroundColour.Ok()) + { + ::SetTextColor((HDC) m_hDC, m_textForegroundColour.GetPixel() ) ; + } + if (m_textBackgroundColour.Ok()) + { + ::SetBkColor((HDC) m_hDC, m_textBackgroundColour.GetPixel() ) ; + } + + DWORD dwRop = rop == wxCOPY ? SRCCOPY : + rop == wxCLEAR ? WHITENESS : + rop == wxSET ? BLACKNESS : + rop == wxINVERT ? DSTINVERT : + rop == wxAND ? MERGECOPY : + rop == wxOR ? MERGEPAINT : + rop == wxSRC_INVERT ? NOTSRCCOPY : + rop == wxXOR ? SRCINVERT : + rop == wxOR_REVERSE ? MERGEPAINT : + rop == wxAND_REVERSE ? SRCERASE : + rop == wxSRC_OR ? SRCPAINT : + rop == wxSRC_AND ? SRCAND : + SRCCOPY; + + bool success = TRUE; + if (useMask && source->m_selectedBitmap.Ok() && source->m_selectedBitmap.GetMask()) + { + #if 0 // __WIN32__ - // Not implemented under Win95 (or maybe a specific device?) - if (MaskBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, + // Not implemented under Win95 (or maybe a specific device?) + if (MaskBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, (HDC) source->m_hDC, xsrc1, ysrc1, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap(), 0, 0, 0xAACC0020)) - { - // Success - } - else + { + // Success + } + else #endif - { - // Old code + { + // Old code #if 0 - HDC dc_mask = CreateCompatibleDC((HDC) source->m_hDC); - ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap()); - success = (BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, - dc_mask, xsrc1, ysrc1, 0x00220326 /* NOTSRCAND */) != 0); - success = (BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, - (HDC) source->m_hDC, xsrc1, ysrc1, SRCPAINT) != 0); - ::SelectObject(dc_mask, 0); - ::DeleteDC(dc_mask); + HDC dc_mask = CreateCompatibleDC((HDC) source->m_hDC); + ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap()); + success = (BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, + dc_mask, xsrc1, ysrc1, 0x00220326 /* NOTSRCAND */) != 0); + success = (BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, + (HDC) source->m_hDC, xsrc1, ysrc1, SRCPAINT) != 0); + ::SelectObject(dc_mask, 0); + ::DeleteDC(dc_mask); #endif - // New code from Chris Breeze, 15/7/98 - // Blit bitmap with mask - + // New code from Chris Breeze, 15/7/98 + // Blit bitmap with mask + + if (IsKindOf(CLASSINFO(wxPrinterDC))) + { + // If we are printing source colours are screen colours + // not printer colours and so we need copy the bitmap + // pixel by pixel. + RECT rect; + HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC); + HDC dc_src = (HDC) source->m_hDC; + + ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap()); + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + COLORREF cref = ::GetPixel(dc_mask, x, y); + if (cref) + { + HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y)); + rect.left = xdest1 + x; rect.right = rect.left + 1; + rect.top = ydest1 + y; rect.bottom = rect.top + 1; + ::FillRect((HDC) m_hDC, &rect, brush); + ::DeleteObject(brush); + } + } + } + ::SelectObject(dc_mask, 0); + ::DeleteDC(dc_mask); + } + else + { + // create a temp buffer bitmap and DCs to access it and the mask + HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC); + HDC dc_buffer = ::CreateCompatibleDC((HDC) m_hDC); + HBITMAP buffer_bmap = ::CreateCompatibleBitmap((HDC) m_hDC, width, height); + ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap()); + ::SelectObject(dc_buffer, buffer_bmap); + + // copy dest to buffer + ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, + (HDC) m_hDC, xdest1, ydest1, SRCCOPY); + + // copy src to buffer using selected raster op + ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, + (HDC) source->m_hDC, xsrc1, ysrc1, dwRop); + + // set masked area in buffer to BLACK (pixel value 0) + COLORREF prevBkCol = ::SetBkColor((HDC) m_hDC, RGB(255, 255, 255)); + COLORREF prevCol = ::SetTextColor((HDC) m_hDC, RGB(0, 0, 0)); + ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, + dc_mask, xsrc1, ysrc1, SRCAND); + + // set unmasked area in dest to BLACK + ::SetBkColor((HDC) m_hDC, RGB(0, 0, 0)); + ::SetTextColor((HDC) m_hDC, RGB(255, 255, 255)); + ::BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, + dc_mask, xsrc1, ysrc1, SRCAND); + ::SetBkColor((HDC) m_hDC, prevBkCol); // restore colours to original values + ::SetTextColor((HDC) m_hDC, prevCol); + + // OR buffer to dest + success = (::BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, + dc_buffer, 0, 0, SRCPAINT) != 0); + + // tidy up temporary DCs and bitmap + ::SelectObject(dc_mask, 0); + ::DeleteDC(dc_mask); + ::SelectObject(dc_buffer, 0); + ::DeleteDC(dc_buffer); + ::DeleteObject(buffer_bmap); + } + } + } + else + { if (IsKindOf(CLASSINFO(wxPrinterDC))) { - // If we are printing source colours are screen colours + // If we are printing, source colours are screen colours // not printer colours and so we need copy the bitmap // pixel by pixel. - RECT rect; - HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC); HDC dc_src = (HDC) source->m_hDC; - - ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap()); + RECT rect; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { - COLORREF cref = ::GetPixel(dc_mask, x, y); - if (cref) - { - HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y)); - rect.left = xdest1 + x; rect.right = rect.left + 1; - rect.top = ydest1 + y; rect.bottom = rect.top + 1; - ::FillRect((HDC) m_hDC, &rect, brush); - ::DeleteObject(brush); - } + HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y)); + rect.left = xdest1 + x; rect.right = rect.left + 1; + rect.top = ydest1 + y; rect.bottom = rect.top + 1; + ::FillRect((HDC) m_hDC, &rect, brush); + ::DeleteObject(brush); } } - ::SelectObject(dc_mask, 0); - ::DeleteDC(dc_mask); } else { - // create a temp buffer bitmap and DCs to access it and the mask - HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC); - HDC dc_buffer = ::CreateCompatibleDC((HDC) m_hDC); - HBITMAP buffer_bmap = ::CreateCompatibleBitmap((HDC) m_hDC, width, height); - ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap()); - ::SelectObject(dc_buffer, buffer_bmap); - - // copy dest to buffer - ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, - (HDC) m_hDC, xdest1, ydest1, SRCCOPY); - - // copy src to buffer using selected raster op - ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, - (HDC) source->m_hDC, xsrc1, ysrc1, dwRop); - - // set masked area in buffer to BLACK (pixel value 0) - COLORREF prevBkCol = ::SetBkColor((HDC) m_hDC, RGB(255, 255, 255)); - COLORREF prevCol = ::SetTextColor((HDC) m_hDC, RGB(0, 0, 0)); - ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, - dc_mask, xsrc1, ysrc1, SRCAND); - - // set unmasked area in dest to BLACK - ::SetBkColor((HDC) m_hDC, RGB(0, 0, 0)); - ::SetTextColor((HDC) m_hDC, RGB(255, 255, 255)); - ::BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, - dc_mask, xsrc1, ysrc1, SRCAND); - ::SetBkColor((HDC) m_hDC, prevBkCol); // restore colours to original values - ::SetTextColor((HDC) m_hDC, prevCol); - - // OR buffer to dest - success = (::BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, - dc_buffer, 0, 0, SRCPAINT) != 0); - - // tidy up temporary DCs and bitmap - ::SelectObject(dc_mask, 0); - ::DeleteDC(dc_mask); - ::SelectObject(dc_buffer, 0); - ::DeleteDC(dc_buffer); - ::DeleteObject(buffer_bmap); - } - } - } - else - { - if (IsKindOf(CLASSINFO(wxPrinterDC))) - { - // If we are printing, source colours are screen colours - // not printer colours and so we need copy the bitmap - // pixel by pixel. - HDC dc_src = (HDC) source->m_hDC; - RECT rect; - for (int x = 0; x < width; x++) - { - for (int y = 0; y < height; y++) - { - HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y)); - rect.left = xdest1 + x; rect.right = rect.left + 1; - rect.top = ydest1 + y; rect.bottom = rect.top + 1; - ::FillRect((HDC) m_hDC, &rect, brush); - ::DeleteObject(brush); + success = (BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, (HDC) source->m_hDC, + xsrc1, ysrc1, dwRop) != 0); } - } } - else - { - success = (BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, (HDC) source->m_hDC, - xsrc1, ysrc1, dwRop) != 0); - } - } - ::SetTextColor((HDC)m_hDC, old_textground); - ::SetBkColor((HDC)m_hDC, old_background); - - return success; + ::SetTextColor((HDC)m_hDC, old_textground); + ::SetBkColor((HDC)m_hDC, old_background); + + return success; } void wxDC::GetSize(int* width, int* height) const { - long w=::GetDeviceCaps((HDC) m_hDC,HORZRES); - long h=::GetDeviceCaps((HDC) m_hDC,VERTRES); - *width = w; - *height = h; + long w=::GetDeviceCaps((HDC) m_hDC,HORZRES); + long h=::GetDeviceCaps((HDC) m_hDC,VERTRES); + *width = w; + *height = h; } -void wxDC::GetSizeMM(long *width, long *height) const +void wxDC::GetSizeMM(int *width, int *height) const { - long w=::GetDeviceCaps((HDC) m_hDC,HORZSIZE); - long h=::GetDeviceCaps((HDC) m_hDC,VERTSIZE); - *width = w; - *height = h; + int w=::GetDeviceCaps((HDC) m_hDC,HORZSIZE); + int h=::GetDeviceCaps((HDC) m_hDC,VERTSIZE); + *width = w; + *height = h; } -void wxDC::DrawPolygon(wxList *list, long xoffset, long yoffset,int fillStyle) +// Resolution in Pixels per inch +wxSize wxDC::GetPPI(void) const { - int n = list->Number(); - wxPoint *points = new wxPoint[n]; + int x=::GetDeviceCaps((HDC) m_hDC,LOGPIXELSX); + int y=::GetDeviceCaps((HDC) m_hDC,LOGPIXELSY); + return wxSize(x, y); +} - int i = 0; - for(wxNode *node = list->First(); node; node = node->Next()) { - wxPoint *point = (wxPoint *)node->Data(); - points[i].x = point->x; - points[i++].y = point->y; - } - DrawPolygon(n, points, xoffset, yoffset,fillStyle); - delete[] points; +void wxDC::DrawPolygon(wxList *list, long xoffset, long yoffset,int fillStyle) +{ + int n = list->Number(); + wxPoint *points = new wxPoint[n]; + + int i = 0; + for(wxNode *node = list->First(); node; node = node->Next()) { + wxPoint *point = (wxPoint *)node->Data(); + points[i].x = point->x; + points[i++].y = point->y; + } + DrawPolygon(n, points, xoffset, yoffset,fillStyle); + delete[] points; } void wxDC::DrawLines(wxList *list, long xoffset, long yoffset) { - int n = list->Number(); - wxPoint *points = new wxPoint[n]; - - int i = 0; - for(wxNode *node = list->First(); node; node = node->Next()) { - wxPoint *point = (wxPoint *)node->Data(); - points[i].x = point->x; - points[i++].y = point->y; - } - DrawLines(n, points, xoffset, yoffset); - delete []points; + int n = list->Number(); + wxPoint *points = new wxPoint[n]; + + int i = 0; + for(wxNode *node = list->First(); node; node = node->Next()) { + wxPoint *point = (wxPoint *)node->Data(); + points[i].x = point->x; + points[i++].y = point->y; + } + DrawLines(n, points, xoffset, yoffset); + delete []points; } void wxDC::SetTextForeground(const wxColour& colour) @@ -1409,35 +1363,35 @@ void wxDC::SetTextBackground(const wxColour& colour) // For use by wxWindows only, unless custom units are required. void wxDC::SetLogicalScale(double x, double y) { - m_logicalScaleX = x; - m_logicalScaleY = y; + m_logicalScaleX = x; + m_logicalScaleY = y; } void wxDC::CalcBoundingBox(long x, long y) { - if (x < m_minX) m_minX = x; - if (y < m_minY) m_minY = y; - if (x > m_maxX) m_maxX = x; - if (y > m_maxY) m_maxY = y; + if (x < m_minX) m_minX = x; + if (y < m_minY) m_minY = y; + if (x > m_maxX) m_maxX = x; + if (y > m_maxY) m_maxY = y; } void wxDC::GetClippingBox(long *x,long *y,long *w,long *h) const { - if (m_clipping) - { - *x = m_clipX1 ; - *y = m_clipY1 ; - *w = (m_clipX2 - m_clipX1) ; - *h = (m_clipY2 - m_clipY1) ; - } - else - *x = *y = *w = *h = 0 ; + if (m_clipping) + { + *x = m_clipX1 ; + *y = m_clipY1 ; + *w = (m_clipX2 - m_clipX1) ; + *h = (m_clipY2 - m_clipY1) ; + } + else + *x = *y = *w = *h = 0 ; } #if WXWIN_COMPATIBILITY void wxDC::GetTextExtent(const wxString& string, float *x, float *y, - float *descent, float *externalLeading, - wxFont *theFont, bool use16bit) const + float *descent, float *externalLeading, + wxFont *theFont, bool use16bit) const { long x1, y1, descent1, externalLeading1; GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit); @@ -1451,7 +1405,7 @@ void wxDC::GetTextExtent(const wxString& string, float *x, float *y, int wxDC::GetDepth(void) const { - return (int) ::GetDeviceCaps((HDC) m_hDC,BITSPIXEL); + return (int) ::GetDeviceCaps((HDC) m_hDC,BITSPIXEL); } #if wxUSE_SPLINES @@ -1459,27 +1413,27 @@ int wxDC::GetDepth(void) const // Make a 3-point spline void wxDC::DrawSpline(long x1, long y1, long x2, long y2, long x3, long y3) { - wxList *point_list = new wxList; - - wxPoint *point1 = new wxPoint; - point1->x = x1; point1->y = y1; - point_list->Append((wxObject*)point1); - - wxPoint *point2 = new wxPoint; - point2->x = x2; point2->y = y2; - point_list->Append((wxObject*)point2); - - wxPoint *point3 = new wxPoint; - point3->x = x3; point3->y = y3; - point_list->Append((wxObject*)point3); - - DrawSpline(point_list); - - for(wxNode *node = point_list->First(); node; node = node->Next()) { - wxPoint *p = (wxPoint *)node->Data(); - delete p; - } - delete point_list; + wxList *point_list = new wxList; + + wxPoint *point1 = new wxPoint; + point1->x = x1; point1->y = y1; + point_list->Append((wxObject*)point1); + + wxPoint *point2 = new wxPoint; + point2->x = x2; point2->y = y2; + point_list->Append((wxObject*)point2); + + wxPoint *point3 = new wxPoint; + point3->x = x3; point3->y = y3; + point_list->Append((wxObject*)point3); + + DrawSpline(point_list); + + for(wxNode *node = point_list->First(); node; node = node->Next()) { + wxPoint *p = (wxPoint *)node->Data(); + delete p; + } + delete point_list; } ////#define wx_round(a) (int)((a)+.5) @@ -1487,24 +1441,24 @@ void wxDC::DrawSpline(long x1, long y1, long x2, long y2, long x3, long y3) class wxSpline: public wxObject { - public: - int type; - wxList *points; - - wxSpline(wxList *list); - void DeletePoints(void); - - // Doesn't delete points - ~wxSpline(void); +public: + int type; + wxList *points; + + wxSpline(wxList *list); + void DeletePoints(void); + + // Doesn't delete points + ~wxSpline(void); }; void wxDC::DrawSpline(int n, wxPoint points[]) { - wxList list; - int i; - for (i =0; i < n; i++) - list.Append((wxObject*)&points[i]); - DrawSpline((wxList *)&list); + wxList list; + int i; + for (i =0; i < n; i++) + list.Append((wxObject*)&points[i]); + DrawSpline((wxList *)&list); } void wx_draw_open_spline(wxDC *dc, wxSpline *spline); @@ -1513,18 +1467,18 @@ void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4, double b4); void wx_clear_stack(void); int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3, - double *y3, double *x4, double *y4); + double *y3, double *x4, double *y4); void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, - double x4, double y4); + double x4, double y4); static bool wx_spline_add_point(double x, double y); static void wx_spline_draw_point_array(wxDC *dc); wxSpline *wx_make_spline(int x1, int y1, int x2, int y2, int x3, int y3); void wxDC::DrawSpline(wxList *list) { - wxSpline spline(list); - - wx_draw_open_spline(this, &spline); + wxSpline spline(list); + + wx_draw_open_spline(this, &spline); } @@ -1535,67 +1489,67 @@ void wx_draw_open_spline(wxDC *dc, wxSpline *spline) wxPoint *p; double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4; double x1, y1, x2, y2; - + wxNode *node = spline->points->First(); p = (wxPoint *)node->Data(); - + x1 = p->x; y1 = p->y; - + node = node->Next(); p = (wxPoint *)node->Data(); - + x2 = p->x; y2 = p->y; cx1 = (double)((x1 + x2) / 2); cy1 = (double)((y1 + y2) / 2); cx2 = (double)((cx1 + x2) / 2); cy2 = (double)((cy1 + y2) / 2); - + wx_spline_add_point(x1, y1); - + while ((node = node->Next()) != NULL) { p = (wxPoint *)node->Data(); - x1 = x2; - y1 = y2; - x2 = p->x; - y2 = p->y; + x1 = x2; + y1 = y2; + x2 = p->x; + y2 = p->y; cx4 = (double)(x1 + x2) / 2; cy4 = (double)(y1 + y2) / 2; cx3 = (double)(x1 + cx4) / 2; cy3 = (double)(y1 + cy4) / 2; - + wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4); - - cx1 = cx4; - cy1 = cy4; + + cx1 = cx4; + cy1 = cy4; cx2 = (double)(cx1 + x2) / 2; cy2 = (double)(cy1 + y2) / 2; } - + wx_spline_add_point((double)wx_round(cx1), (double)wx_round(cy1)); wx_spline_add_point(x2, y2); - + wx_spline_draw_point_array(dc); - + } /********************* CURVES FOR SPLINES ***************************** - The following spline drawing routine is from - + The following spline drawing routine is from + "An Algorithm for High-Speed Curve Generation" by George Merrill Chaikin, Computer Graphics and Image Processing, 3, Academic Press, 1974, 346-349. - - and - - "On Chaikin's Algorithm" by R. F. Riesenfeld, - Computer Graphics and Image Processing, 4, Academic Press, - 1975, 304-310. - + + and + + "On Chaikin's Algorithm" by R. F. Riesenfeld, + Computer Graphics and Image Processing, 4, Academic Press, + 1975, 304-310. + ***********************************************************************/ #define half(z1, z2) ((z1+z2)/2.0) @@ -1604,27 +1558,27 @@ void wx_draw_open_spline(wxDC *dc, wxSpline *spline) /* iterative version */ void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4, - double b4) + double b4) { register double xmid, ymid; double x1, y1, x2, y2, x3, y3, x4, y4; - + wx_clear_stack(); wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4); - + while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) { xmid = (double)half(x2, x3); ymid = (double)half(y2, y3); - if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD && - fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) { + if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD && + fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) { wx_spline_add_point((double)wx_round(x1), (double)wx_round(y1)); wx_spline_add_point((double)wx_round(xmid), (double)wx_round(ymid)); - } else { + } else { wx_spline_push(xmid, ymid, (double)half(xmid, x3), (double)half(ymid, y3), - (double)half(x3, x4), (double)half(y3, y4), x4, y4); + (double)half(x3, x4), (double)half(y3, y4), x4, y4); wx_spline_push(x1, y1, (double)half(x1, x2), (double)half(y1, y2), - (double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid); - } + (double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid); + } } } @@ -1635,7 +1589,7 @@ void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, typedef struct wx_spline_stack_struct { double x1, y1, x2, y2, x3, y3, x4, y4; } - Stack; +Stack; #define SPLINE_STACK_DEPTH 20 static Stack wx_spline_stack[SPLINE_STACK_DEPTH]; @@ -1666,7 +1620,7 @@ int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3, double *y3, double *x4, double *y4) { if (wx_stack_count == 0) - return (0); + return (0); wx_stack_top--; wx_stack_count--; *x1 = wx_stack_top->x1; @@ -1682,29 +1636,29 @@ int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, static bool wx_spline_add_point(double x, double y) { - wxPoint *point = new wxPoint ; - point->x = (int) x; - point->y = (int) y; - wx_spline_point_list.Append((wxObject*)point); - return TRUE; + wxPoint *point = new wxPoint ; + point->x = (int) x; + point->y = (int) y; + wx_spline_point_list.Append((wxObject*)point); + return TRUE; } static void wx_spline_draw_point_array(wxDC *dc) { - dc->DrawLines(&wx_spline_point_list, 0, 0); - wxNode *node = wx_spline_point_list.First(); - while (node) - { - wxPoint *point = (wxPoint *)node->Data(); - delete point; - delete node; - node = wx_spline_point_list.First(); - } + dc->DrawLines(&wx_spline_point_list, 0, 0); + wxNode *node = wx_spline_point_list.First(); + while (node) + { + wxPoint *point = (wxPoint *)node->Data(); + delete point; + delete node; + node = wx_spline_point_list.First(); + } } wxSpline::wxSpline(wxList *list) { - points = list; + points = list; } wxSpline::~wxSpline(void) @@ -1713,13 +1667,13 @@ wxSpline::~wxSpline(void) void wxSpline::DeletePoints(void) { - for(wxNode *node = points->First(); node; node = points->First()) - { - wxPoint *point = (wxPoint *)node->Data(); - delete point; - delete node; - } - delete points; + for(wxNode *node = points->First(); node; node = points->First()) + { + wxPoint *point = (wxPoint *)node->Data(); + delete point; + delete node; + } + delete points; } diff --git a/src/msw/dcprint.cpp b/src/msw/dcprint.cpp index 23593c665a..d304d8bbc9 100644 --- a/src/msw/dcprint.cpp +++ b/src/msw/dcprint.cpp @@ -52,88 +52,232 @@ IMPLEMENT_CLASS(wxPrinterDC, wxDC) #endif +// This form is deprecated wxPrinterDC::wxPrinterDC(const wxString& driver_name, const wxString& device_name, const wxString& file, bool interactive, int orientation) { - m_isInteractive = interactive; - - if (!file.IsNull() && file != "") - m_filename = file; - + m_isInteractive = interactive; + + if (!file.IsNull() && file != "") + m_printData.SetFilename(file); + #if wxUSE_COMMON_DIALOGS - if (interactive) - { - PRINTDLG pd; - - pd.lStructSize = sizeof( PRINTDLG ); - pd.hwndOwner=(HWND) NULL; - pd.hDevMode=(HANDLE)NULL; - pd.hDevNames=(HANDLE)NULL; - pd.Flags=PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS; - pd.nFromPage=0; - pd.nToPage=0; - pd.nMinPage=0; - pd.nMaxPage=0; - pd.nCopies=1; - pd.hInstance=(HINSTANCE)NULL; - - if ( PrintDlg( &pd ) != 0 ) - { - m_hDC = (WXHDC) pd.hDC; - m_ok = TRUE; - } - else - { - m_ok = FALSE; - return; - } - -// m_dontDelete = TRUE; - } - else -#endif - if ((!driver_name.IsNull() && driver_name != "") && - (!device_name.IsNull() && device_name != "") && - (!file.IsNull() && file != "")) - { - m_hDC = (WXHDC) CreateDC((char *) (const char *) driver_name, (char *) (const char *) device_name, (char *) (const char *) file, NULL); - m_ok = m_hDC ? TRUE: FALSE; - } - else - { - m_hDC = wxGetPrinterDC(orientation); - m_ok = m_hDC ? TRUE: FALSE; - } - - if (m_hDC) - { -// int width = GetDeviceCaps(m_hDC, VERTRES); -// int height = GetDeviceCaps(m_hDC, HORZRES); - SetMapMode(wxMM_TEXT); - } - SetBrush(*wxBLACK_BRUSH); - SetPen(*wxBLACK_PEN); + if (interactive) + { + PRINTDLG pd; + + pd.lStructSize = sizeof( PRINTDLG ); + pd.hwndOwner=(HWND) NULL; + pd.hDevMode=(HANDLE)NULL; + pd.hDevNames=(HANDLE)NULL; + pd.Flags=PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS; + pd.nFromPage=0; + pd.nToPage=0; + pd.nMinPage=0; + pd.nMaxPage=0; + pd.nCopies=1; + pd.hInstance=(HINSTANCE)NULL; + + if ( PrintDlg( &pd ) != 0 ) + { + m_hDC = (WXHDC) pd.hDC; + m_ok = TRUE; + } + else + { + m_ok = FALSE; + return; + } + + // m_dontDelete = TRUE; + } + else +#endif + if ((!driver_name.IsNull() && driver_name != "") && + (!device_name.IsNull() && device_name != "") && + (!file.IsNull() && file != "")) + { + m_hDC = (WXHDC) CreateDC((char *) (const char *) driver_name, (char *) (const char *) device_name, (char *) (const char *) file, NULL); + m_ok = m_hDC ? TRUE: FALSE; + } + else + { + wxPrintData printData; + printData.SetOrientation(orientation); + m_hDC = wxGetPrinterDC(printData); + m_ok = m_hDC ? TRUE: FALSE; + } + + if (m_hDC) + { + // int width = GetDeviceCaps(m_hDC, VERTRES); + // int height = GetDeviceCaps(m_hDC, HORZRES); + SetMapMode(wxMM_TEXT); + } + SetBrush(*wxBLACK_BRUSH); + SetPen(*wxBLACK_PEN); +} + +wxPrinterDC::wxPrinterDC(const wxPrintData& printData) +{ + m_printData = printData; + + m_isInteractive = FALSE; + + m_hDC = wxGetPrinterDC(printData); + m_ok = (m_hDC != 0); + + if (m_hDC) + SetMapMode(wxMM_TEXT); + + SetBrush(*wxBLACK_BRUSH); + SetPen(*wxBLACK_PEN); } + wxPrinterDC::wxPrinterDC(WXHDC theDC) { - m_isInteractive = FALSE; - - m_hDC = theDC; - m_ok = TRUE; - if (m_hDC) - { -// int width = GetDeviceCaps(m_hDC, VERTRES); -// int height = GetDeviceCaps(m_hDC, HORZRES); - SetMapMode(wxMM_TEXT); - } - SetBrush(*wxBLACK_BRUSH); - SetPen(*wxBLACK_PEN); + m_isInteractive = FALSE; + + m_hDC = theDC; + m_ok = TRUE; + if (m_hDC) + { + // int width = GetDeviceCaps(m_hDC, VERTRES); + // int height = GetDeviceCaps(m_hDC, HORZRES); + SetMapMode(wxMM_TEXT); + } + SetBrush(*wxBLACK_BRUSH); + SetPen(*wxBLACK_PEN); } wxPrinterDC::~wxPrinterDC(void) { } +bool wxPrinterDC::StartDoc(const wxString& message) +{ + DOCINFO docinfo; + docinfo.cbSize = sizeof(DOCINFO); + docinfo.lpszDocName = (const char *)message; + + wxString filename(m_printData.GetFilename()); + + if (filename.IsEmpty()) + docinfo.lpszOutput = NULL; + else + docinfo.lpszOutput = (const char *) filename; + +#if defined(__WIN95__) + docinfo.lpszDatatype = NULL; + docinfo.fwType = 0; +#endif + + if (!m_hDC) + return FALSE; + + int ret = +#ifndef __WIN32__ + ::StartDoc((HDC) m_hDC, &docinfo); +#else +#ifdef UNICODE + ::StartDocW((HDC) m_hDC, &docinfo); +#else +#ifdef __TWIN32__ + ::StartDoc((HDC) m_hDC, &docinfo); +#else + ::StartDocA((HDC) m_hDC, &docinfo); +#endif +#endif +#endif + +#ifndef __WIN16__ + if (ret <= 0) + { + DWORD lastError = GetLastError(); + wxDebugMsg("wxDC::StartDoc failed with error: %d\n", lastError); + } +#endif + + return (ret > 0); +} + +void wxPrinterDC::EndDoc(void) +{ + if (m_hDC) ::EndDoc((HDC) m_hDC); +} + +void wxPrinterDC::StartPage(void) +{ + if (m_hDC) + ::StartPage((HDC) m_hDC); +} + +void wxPrinterDC::EndPage(void) +{ + if (m_hDC) + ::EndPage((HDC) m_hDC); +} + +// Returns default device and port names +static bool wxGetDefaultDeviceName(wxString& deviceName, wxString& portName) +{ + deviceName = ""; + + LPDEVNAMES lpDevNames; + LPSTR lpszDriverName; + LPSTR lpszDeviceName; + LPSTR lpszPortName; + + PRINTDLG pd; + + // Cygwin has trouble believing PRINTDLG is 66 bytes - thinks it is 68 +#ifdef __GNUWIN32__ + pd.lStructSize = 66; // sizeof(PRINTDLG); +#else + pd.lStructSize = sizeof(PRINTDLG); +#endif + + pd.hwndOwner = (HWND)NULL; + pd.hDevMode = NULL; // Will be created by PrintDlg + pd.hDevNames = NULL; // Ditto + pd.Flags = PD_RETURNDEFAULT; + pd.nCopies = 1; + + if (!PrintDlg((LPPRINTDLG)&pd)) + { + if ( pd.hDevMode ) + GlobalFree(pd.hDevMode); + if (pd.hDevNames) + GlobalFree(pd.hDevNames); + + return FALSE; + } + + if (pd.hDevNames) + { + lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames); + lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset; + lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset; + lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset; + GlobalUnlock(pd.hDevNames); + GlobalFree(pd.hDevNames); + pd.hDevNames=NULL; + + deviceName = lpszDeviceName; + portName = lpszPortName; + } + + if (pd.hDevMode) + { + GlobalFree(pd.hDevMode); + pd.hDevMode=NULL; + } + return ( deviceName != "" ); +} + +#if 0 +// This uses defaults, except for orientation, so we should eliminate this function +// and use the 2nd form (passing wxPrintData) instead. WXHDC wxGetPrinterDC(int orientation) { HDC hDC; @@ -142,58 +286,62 @@ WXHDC wxGetPrinterDC(int orientation) LPSTR lpszDriverName; LPSTR lpszDeviceName; LPSTR lpszPortName; - + PRINTDLG pd; // __GNUWIN32__ has trouble believing PRINTDLG is 66 bytes - thinks it is 68 +#ifdef __GNUWIN32__ pd.lStructSize = 66; // sizeof(PRINTDLG); +#else + pd.lStructSize = sizeof(PRINTDLG); +#endif pd.hwndOwner = (HWND)NULL; pd.hDevMode = NULL; // Will be created by PrintDlg pd.hDevNames = NULL; // Ditto pd.Flags = PD_RETURNDEFAULT; pd.nCopies = 1; - + if (!PrintDlg((LPPRINTDLG)&pd)) { if ( pd.hDevMode ) GlobalFree(pd.hDevMode); if (pd.hDevNames) GlobalFree(pd.hDevNames); - + return(0); } - + if (!pd.hDevNames) { if ( pd.hDevMode ) GlobalFree(pd.hDevMode); } - + lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames); lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset; lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset; lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset; GlobalUnlock(pd.hDevNames); - + if ( pd.hDevMode ) { lpDevMode = (DEVMODE*) GlobalLock(pd.hDevMode); lpDevMode->dmOrientation = orientation; lpDevMode->dmFields |= DM_ORIENTATION; } - + #ifdef __WIN32__ hDC = CreateDC(lpszDriverName, lpszDeviceName, lpszPortName, (DEVMODE *)lpDevMode); #else hDC = CreateDC(lpszDriverName, lpszDeviceName, lpszPortName, (LPSTR)lpDevMode); #endif - + if (pd.hDevMode && lpDevMode) GlobalUnlock(pd.hDevMode); - + if (pd.hDevNames) { - GlobalFree(pd.hDevNames); - pd.hDevNames=NULL; + GlobalFree(pd.hDevNames); + pd.hDevNames=NULL; } if (pd.hDevMode) { @@ -202,5 +350,52 @@ WXHDC wxGetPrinterDC(int orientation) } return (WXHDC) hDC; } +#endif + +// Gets an HDC for the specified printer configuration +WXHDC WXDLLEXPORT wxGetPrinterDC(const wxPrintData& printDataConst) +{ + wxPrintData printData = printDataConst; + printData.ConvertToNative(); + + char* driverName = (char*) NULL; + + wxString devNameStr = printData.GetPrinterName(); + char* deviceName; + char* portName = (char*) NULL; // Obsolete in WIN32 + + if (devNameStr == "") + deviceName = (char*) NULL; + else + deviceName = (char*) (const char*) devNameStr; + + LPDEVMODE lpDevMode = (LPDEVMODE) NULL; + + HGLOBAL hDevMode = (HGLOBAL) printData.GetNativeData(); + + if ( hDevMode ) + lpDevMode = (DEVMODE*) GlobalLock(hDevMode); + + if (devNameStr == "") + { + // Retrieve the default device name + wxString portName; + bool ret = wxGetDefaultDeviceName(devNameStr, portName); + + wxASSERT_MSG( ret, "Could not get default device name." ); + deviceName = (char*) (const char*) devNameStr; + } + +#ifdef __WIN32__ + HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode); +#else + HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode); +#endif + + if (hDevMode && lpDevMode) + GlobalUnlock(hDevMode); + + return (WXHDC) hDC; +} diff --git a/src/msw/makefile.b32 b/src/msw/makefile.b32 index fdf3da93d0..b69f905ac6 100644 --- a/src/msw/makefile.b32 +++ b/src/msw/makefile.b32 @@ -132,6 +132,7 @@ COMMONOBJS = \ $(MSWDIR)\date.obj \ $(MSWDIR)\hash.obj \ $(MSWDIR)\list.obj \ + $(MSWDIR)\paper.obj \ $(MSWDIR)\string.obj \ $(MSWDIR)\time.obj \ $(MSWDIR)\wxexpr.obj \ @@ -551,6 +552,8 @@ $(MSWDIR)\hash.obj: $(COMMDIR)\hash.$(SRCSUFF) $(MSWDIR)\list.obj: $(COMMDIR)\list.$(SRCSUFF) +$(MSWDIR)\paper.obj: $(COMMDIR)\paper.$(SRCSUFF) + $(MSWDIR)\string.obj: $(COMMDIR)\string.$(SRCSUFF) $(MSWDIR)\variant.obj: $(COMMDIR)\variant.$(SRCSUFF) diff --git a/src/msw/makefile.bcc b/src/msw/makefile.bcc index 9c9ec91f4e..26c0230cb9 100644 --- a/src/msw/makefile.bcc +++ b/src/msw/makefile.bcc @@ -130,6 +130,7 @@ COMMONOBJS = \ $(MSWDIR)\date.obj \ $(MSWDIR)\hash.obj \ $(MSWDIR)\list.obj \ + $(MSWDIR)\paper.obj \ $(MSWDIR)\string.obj \ $(MSWDIR)\time.obj \ $(MSWDIR)\wxexpr.obj \ @@ -539,6 +540,8 @@ $(MSWDIR)\hash.obj: $(COMMDIR)\hash.$(SRCSUFF) $(MSWDIR)\list.obj: $(COMMDIR)\list.$(SRCSUFF) +$(MSWDIR)\paper.obj: $(COMMDIR)\paper.$(SRCSUFF) + $(MSWDIR)\string.obj: $(COMMDIR)\string.$(SRCSUFF) $(MSWDIR)\variant.obj: $(COMMDIR)\variant.$(SRCSUFF) diff --git a/src/msw/makefile.dos b/src/msw/makefile.dos index 1efd525aeb..ad57928f17 100644 --- a/src/msw/makefile.dos +++ b/src/msw/makefile.dos @@ -116,6 +116,7 @@ COMMONOBJS = \ $(COMMDIR)\hash.obj \ $(COMMDIR)\list.obj \ $(COMMDIR)\variant.obj \ + $(COMMDIR)\paper.obj \ $(COMMDIR)\string.obj \ $(COMMDIR)\time.obj \ $(COMMDIR)\y_tab.obj \ @@ -873,6 +874,11 @@ $(COMMDIR)/variant.obj: $*.$(SRCSUFF) $(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) << +$(COMMDIR)/paper.obj: $*.$(SRCSUFF) + cl @<< +$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) +<< + $(COMMDIR)/string.obj: $*.$(SRCSUFF) cl @<< $(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) diff --git a/src/msw/makefile.g95 b/src/msw/makefile.g95 index c078f9370c..509a47543e 100644 --- a/src/msw/makefile.g95 +++ b/src/msw/makefile.g95 @@ -114,6 +114,7 @@ COMMONOBJS = \ $(COMMDIR)/hash.$(OBJSUFF) \ $(COMMDIR)/list.$(OBJSUFF) \ $(COMMDIR)/variant.$(OBJSUFF) \ + $(COMMDIR)/paper.$(OBJSUFF) \ $(COMMDIR)/string.$(OBJSUFF) \ $(COMMDIR)/time.$(OBJSUFF) \ $(COMMDIR)/tokenzr.$(OBJSUFF) \ diff --git a/src/msw/makefile.sc b/src/msw/makefile.sc index 2bea2b583c..cc87d85112 100644 --- a/src/msw/makefile.sc +++ b/src/msw/makefile.sc @@ -88,6 +88,7 @@ COMMONOBJS = \ $(COMMDIR)\date.obj \ $(COMMDIR)\hash.obj \ $(COMMDIR)\list.obj \ + $(COMMDIR)\paper.obj \ $(COMMDIR)\string.obj \ $(COMMDIR)\time.obj \ $(COMMDIR)\tokenzr.obj \ diff --git a/src/msw/makefile.sl b/src/msw/makefile.sl index ffe534970a..94e47f423d 100644 --- a/src/msw/makefile.sl +++ b/src/msw/makefile.sl @@ -74,6 +74,7 @@ COMMONOBJS = cmndata.obj \ date.obj \ hash.obj \ list.obj \ + paper.obj \ string.obj \ socket.obj \ sckaddr.obj \ @@ -617,6 +618,9 @@ hash.obj: $(COMMDIR)\hash.cpp list.obj: $(COMMDIR)\list.cpp $(CCC) $(CPPFLAGS) $(IFLAGS) $(COMMDIR)\list.cpp /BINARY list.obj +paper.obj: $(COMMDIR)\paper.cpp + $(CCC) $(CPPFLAGS) $(IFLAGS) $(COMMDIR)\paper.cpp /BINARY paper.obj + string.obj: $(COMMDIR)\string.cpp $(CCC) $(CPPFLAGS) $(IFLAGS) $(COMMDIR)\string.cpp /BINARY string.obj diff --git a/src/msw/makefile.twn b/src/msw/makefile.twn index 4046a4ca6f..069d86af37 100644 --- a/src/msw/makefile.twn +++ b/src/msw/makefile.twn @@ -116,6 +116,7 @@ COMMONOBJS = \ $(COMMDIR)/hash.$(OBJSUFF) \ $(COMMDIR)/list.$(OBJSUFF) \ $(COMMDIR)/variant.$(OBJSUFF) \ + $(COMMDIR)/paper.$(OBJSUFF) \ $(COMMDIR)/string.$(OBJSUFF) \ $(COMMDIR)/time.$(OBJSUFF) \ $(COMMDIR)/tokenzr.$(OBJSUFF) \ diff --git a/src/msw/makefile.vc b/src/msw/makefile.vc index 185f64258d..d92ad76e67 100644 --- a/src/msw/makefile.vc +++ b/src/msw/makefile.vc @@ -135,6 +135,7 @@ COMMONOBJS = \ ..\common\$D\date.obj \ ..\common\$D\hash.obj \ ..\common\$D\list.obj \ + ..\common\$D\paper.obj \ ..\common\$D\string.obj \ ..\common\$D\socket.obj \ ..\common\$D\sckaddr.obj \ diff --git a/src/msw/makefile.wat b/src/msw/makefile.wat index 5646f3eb97..a3d1c73d82 100644 --- a/src/msw/makefile.wat +++ b/src/msw/makefile.wat @@ -84,6 +84,7 @@ COMMONOBJS = cmndata.obj & date.obj & hash.obj & list.obj & + paper.obj & string.obj & socket.obj & sckaddr.obj & @@ -629,6 +630,9 @@ hash.obj: $(COMMDIR)\hash.cpp list.obj: $(COMMDIR)\list.cpp *$(CCC) $(CPPFLAGS) $(IFLAGS) $< +paper.obj: $(COMMDIR)\paper.cpp + *$(CCC) $(CPPFLAGS) $(IFLAGS) $< + string.obj: $(COMMDIR)\string.cpp *$(CCC) $(CPPFLAGS) $(IFLAGS) $< diff --git a/src/msw/printdlg.cpp b/src/msw/printdlg.cpp index c48762e3c2..2d0eb79e6c 100644 --- a/src/msw/printdlg.cpp +++ b/src/msw/printdlg.cpp @@ -50,112 +50,101 @@ IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog) #endif wxPrintDialog::wxPrintDialog(void): - wxDialog() +wxDialog() { - dialogParent = NULL; - printerDC = NULL; - destroyDC = TRUE; - deviceName = NULL; - driverName = NULL; - portName = NULL; + m_dialogParent = NULL; + m_printerDC = NULL; + m_destroyDC = TRUE; } -wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintData* data): - wxDialog() +wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintDialogData* data): +wxDialog() { - Create(p, data); + Create(p, data); } -bool wxPrintDialog::Create(wxWindow *p, wxPrintData* data) +bool wxPrintDialog::Create(wxWindow *p, wxPrintDialogData* data) { - dialogParent = p; - printerDC = NULL; - destroyDC = TRUE; - deviceName = NULL; - driverName = NULL; - portName = NULL; - - if ( data ) - printData = *data; - -#ifdef __WXMSW__ - printData.SetOwnerWindow(p); -#endif + m_dialogParent = p; + m_printerDC = NULL; + m_destroyDC = TRUE; + + if ( data ) + m_printDialogData = *data; + + m_printDialogData.SetOwnerWindow(p); - return TRUE; + return TRUE; } wxPrintDialog::~wxPrintDialog(void) { - if (destroyDC && printerDC) - delete printerDC; - if (deviceName) delete[] deviceName; - if (driverName) delete[] driverName; - if (portName) delete[] portName; + if (m_destroyDC && m_printerDC) + delete m_printerDC; } int wxPrintDialog::ShowModal(void) { - printData.ConvertToNative(); - - bool ret = (PrintDlg( (PRINTDLG *)printData.printData ) != 0); - if ( ret != FALSE && ((PRINTDLG *)printData.printData)->hDC) - { - wxPrinterDC *pdc = new wxPrinterDC((WXHDC) ((PRINTDLG *)printData.printData)->hDC); - printerDC = pdc; - printData.ConvertFromNative(); - return wxID_OK; - } - else - { -/* - char buf[256]; - DWORD exError = CommDlgExtendedError(); - sprintf(buf, "ret = %d, ex error = %d", (int) ret, (int) exError); - wxMessageBox(buf); -*/ - return wxID_CANCEL; - } + m_printDialogData.ConvertToNative(); + + bool ret = (PrintDlg( (PRINTDLG *)m_printDialogData.GetNativeData() ) != 0); + if ( ret != FALSE && ((PRINTDLG *)m_printDialogData.GetNativeData())->hDC) + { + wxPrinterDC *pdc = new wxPrinterDC((WXHDC) ((PRINTDLG *)m_printDialogData.GetNativeData())->hDC); + m_printerDC = pdc; + m_printDialogData.ConvertFromNative(); + return wxID_OK; + } + else + { + /* + char buf[256]; + DWORD exError = CommDlgExtendedError(); + sprintf(buf, "ret = %d, ex error = %d", (int) ret, (int) exError); + wxMessageBox(buf); + */ + return wxID_CANCEL; + } } wxDC *wxPrintDialog::GetPrintDC(void) { - if (printerDC) - { - destroyDC = FALSE; - return printerDC; - } - else - return NULL; + if (m_printerDC) + { + m_destroyDC = FALSE; + return m_printerDC; + } + else + return (wxDC*) NULL; } /* - * wxPageSetupDialog - */ +* wxPageSetupDialog +*/ wxPageSetupDialog::wxPageSetupDialog(void): - wxDialog() +wxDialog() { - m_dialogParent = NULL; + m_dialogParent = NULL; } wxPageSetupDialog::wxPageSetupDialog(wxWindow *p, wxPageSetupData *data): - wxDialog() +wxDialog() { - Create(p, data); + Create(p, data); } bool wxPageSetupDialog::Create(wxWindow *p, wxPageSetupData *data) { - m_dialogParent = p; - - if (data) - m_pageSetupData = (*data); - + m_dialogParent = p; + + if (data) + m_pageSetupData = (*data); + #if defined(__WIN95__) - m_pageSetupData.SetOwnerWindow(p); + m_pageSetupData.SetOwnerWindow(p); #endif - return TRUE; + return TRUE; } wxPageSetupDialog::~wxPageSetupDialog(void) @@ -168,11 +157,11 @@ int wxPageSetupDialog::ShowModal(void) m_pageSetupData.ConvertToNative(); if (PageSetupDlg( (PAGESETUPDLG *)m_pageSetupData.GetNativeData() )) { - m_pageSetupData.ConvertFromNative(); - return wxID_OK; + m_pageSetupData.ConvertFromNative(); + return wxID_OK; } else - return wxID_CANCEL; + return wxID_CANCEL; #else wxGenericPageSetupDialog *genericPageSetupDialog = new wxGenericPageSetupDialog(GetParent(), & m_pageSetupData); int ret = genericPageSetupDialog->ShowModal(); diff --git a/src/msw/printwin.cpp b/src/msw/printwin.cpp index 3171efe667..f65d3e7431 100644 --- a/src/msw/printwin.cpp +++ b/src/msw/printwin.cpp @@ -55,11 +55,11 @@ IMPLEMENT_CLASS(wxWindowsPrintPreview, wxPrintPreviewBase) #endif /* - * Printer - */ - -wxWindowsPrinter::wxWindowsPrinter(wxPrintData *data): - wxPrinterBase(data) +* Printer +*/ + +wxWindowsPrinter::wxWindowsPrinter(wxPrintDialogData *data): +wxPrinterBase(data) { m_lpAbortProc = (WXFARPROC) MakeProcInstance((FARPROC) wxAbortProc, wxGetInstance()); } @@ -71,204 +71,218 @@ wxWindowsPrinter::~wxWindowsPrinter(void) bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) { - sm_abortIt = FALSE; - sm_abortWindow = NULL; - - if (!printout) - return FALSE; - - printout->SetIsPreview(FALSE); - printout->OnPreparePrinting(); - - // Get some parameters from the printout, if defined - int fromPage, toPage; - int minPage, maxPage; - printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); - - if (maxPage == 0) - return FALSE; - - m_printData.SetMinPage(minPage); - m_printData.SetMaxPage(maxPage); - if (fromPage != 0) - m_printData.SetFromPage(fromPage); - if (toPage != 0) - m_printData.SetToPage(toPage); - - if (minPage != 0) - { - m_printData.EnablePageNumbers(TRUE); - if (m_printData.GetFromPage() < m_printData.GetMinPage()) - m_printData.SetFromPage(m_printData.GetMinPage()); - else if (m_printData.GetFromPage() > m_printData.GetMaxPage()) - m_printData.SetFromPage(m_printData.GetMaxPage()); - if (m_printData.GetToPage() > m_printData.GetMaxPage()) - m_printData.SetToPage(m_printData.GetMaxPage()); - else if (m_printData.GetToPage() < m_printData.GetMinPage()) - m_printData.SetToPage(m_printData.GetMinPage()); - } - else - m_printData.EnablePageNumbers(FALSE); - - // Create a suitable device context - wxDC *dc = NULL; - if (prompt) - { - wxPrintDialog dialog(parent, & m_printData); - if (dialog.ShowModal() == wxID_OK) - { - dc = dialog.GetPrintDC(); - m_printData = dialog.GetPrintData(); - } - } - else - { - dc = new wxPrinterDC("", "", "", FALSE, m_printData.GetOrientation()); - } - - // May have pressed cancel. - if (!dc || !dc->Ok()) - { - if (dc) delete dc; - return FALSE; - } - - int logPPIScreenX = 0; - int logPPIScreenY = 0; - int logPPIPrinterX = 0; - int logPPIPrinterY = 0; - - HDC hdc = ::GetDC(NULL); - logPPIScreenX = ::GetDeviceCaps(hdc, LOGPIXELSX); - logPPIScreenY = ::GetDeviceCaps(hdc, LOGPIXELSY); - ::ReleaseDC(NULL, hdc); - - logPPIPrinterX = ::GetDeviceCaps((HDC) dc->GetHDC(), LOGPIXELSX); - logPPIPrinterY = ::GetDeviceCaps((HDC) dc->GetHDC(), LOGPIXELSY); - if (logPPIPrinterX == 0 || logPPIPrinterY == 0) - { - delete dc; - return FALSE; - } - - printout->SetPPIScreen(logPPIScreenX, logPPIScreenY); - printout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY); - - // Set printout parameters - printout->SetDC(dc); - - int w, h; - long ww, hh; - dc->GetSize(&w, &h); - printout->SetPageSizePixels((int)w, (int)h); - dc->GetSizeMM(&ww, &hh); - printout->SetPageSizeMM((int)ww, (int)hh); - - // Create an abort window - wxBeginBusyCursor(); + sm_abortIt = FALSE; + sm_abortWindow = NULL; + + if (!printout) + return FALSE; + + printout->SetIsPreview(FALSE); + printout->OnPreparePrinting(); + + // Get some parameters from the printout, if defined + int fromPage, toPage; + int minPage, maxPage; + printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage); + + if (maxPage == 0) + return FALSE; + + m_printDialogData.SetMinPage(minPage); + m_printDialogData.SetMaxPage(maxPage); + if (fromPage != 0) + m_printDialogData.SetFromPage(fromPage); + if (toPage != 0) + m_printDialogData.SetToPage(toPage); + + if (minPage != 0) + { + m_printDialogData.EnablePageNumbers(TRUE); + if (m_printDialogData.GetFromPage() < m_printDialogData.GetMinPage()) + m_printDialogData.SetFromPage(m_printDialogData.GetMinPage()); + else if (m_printDialogData.GetFromPage() > m_printDialogData.GetMaxPage()) + m_printDialogData.SetFromPage(m_printDialogData.GetMaxPage()); + if (m_printDialogData.GetToPage() > m_printDialogData.GetMaxPage()) + m_printDialogData.SetToPage(m_printDialogData.GetMaxPage()); + else if (m_printDialogData.GetToPage() < m_printDialogData.GetMinPage()) + m_printDialogData.SetToPage(m_printDialogData.GetMinPage()); + } + else + m_printDialogData.EnablePageNumbers(FALSE); - wxWindow *win = CreateAbortWindow(parent, printout); - wxYield(); + // Create a suitable device context + wxDC *dc = NULL; + if (prompt) + { + dc = PrintDialog(parent); + if (!dc) + return FALSE; + } + else + { + // dc = new wxPrinterDC("", "", "", FALSE, m_printData.GetOrientation()); + dc = new wxPrinterDC(m_printDialogData.GetPrintData()); + } + + // May have pressed cancel. + if (!dc || !dc->Ok()) + { + if (dc) delete dc; + return FALSE; + } + + int logPPIScreenX = 0; + int logPPIScreenY = 0; + int logPPIPrinterX = 0; + int logPPIPrinterY = 0; + + HDC hdc = ::GetDC(NULL); + logPPIScreenX = ::GetDeviceCaps(hdc, LOGPIXELSX); + logPPIScreenY = ::GetDeviceCaps(hdc, LOGPIXELSY); + ::ReleaseDC(NULL, hdc); + + logPPIPrinterX = ::GetDeviceCaps((HDC) dc->GetHDC(), LOGPIXELSX); + logPPIPrinterY = ::GetDeviceCaps((HDC) dc->GetHDC(), LOGPIXELSY); + if (logPPIPrinterX == 0 || logPPIPrinterY == 0) + { + delete dc; + return FALSE; + } + + printout->SetPPIScreen(logPPIScreenX, logPPIScreenY); + printout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY); + + // Set printout parameters + printout->SetDC(dc); + + int w, h; + dc->GetSize(&w, &h); + printout->SetPageSizePixels((int)w, (int)h); + dc->GetSizeMM(&w, &h); + printout->SetPageSizeMM((int)w, (int)h); + + // Create an abort window + wxBeginBusyCursor(); + + wxWindow *win = CreateAbortWindow(parent, printout); + wxYield(); + #if defined(__BORLANDC__) || defined(__GNUWIN32__) || defined(__SALFORDC__) || !defined(__WIN32__) - ::SetAbortProc((HDC) dc->GetHDC(), (FARPROC) m_lpAbortProc); + ::SetAbortProc((HDC) dc->GetHDC(), (FARPROC) m_lpAbortProc); +#else + ::SetAbortProc((HDC) dc->GetHDC(), (int (_stdcall *) + // cast it to right type only if required + // @@@ it's really cdecl and we're casting it to stdcall - either there is + // something I don't understand or it will crash at first usage +#ifdef STRICT + (HDC, int) #else - ::SetAbortProc((HDC) dc->GetHDC(), (int (_stdcall *) - // cast it to right type only if required - // @@@ it's really cdecl and we're casting it to stdcall - either there is - // something I don't understand or it will crash at first usage - #ifdef STRICT - (HDC, int) - #else - () - #endif - )m_lpAbortProc); + () #endif - - if (!win) - { - wxEndBusyCursor(); - wxMessageBox("Sorry, could not create an abort dialog.", "Print Error", wxOK, parent); - delete dc; - } - sm_abortWindow = win; - sm_abortWindow->Show(TRUE); - wxYield(); - - printout->OnBeginPrinting(); - - bool keepGoing = TRUE; - - int copyCount; - for (copyCount = 1; copyCount <= m_printData.GetNoCopies(); copyCount ++) - { - if (!printout->OnBeginDocument(m_printData.GetFromPage(), m_printData.GetToPage())) + )m_lpAbortProc); +#endif + + if (!win) { - wxEndBusyCursor(); - wxMessageBox("Could not start printing.", "Print Error", wxOK, parent); - break; + wxEndBusyCursor(); + wxMessageBox("Sorry, could not create an abort dialog.", "Print Error", wxOK, parent); + delete dc; } - if (sm_abortIt) - break; - - int pn; - for (pn = m_printData.GetFromPage(); keepGoing && (pn <= m_printData.GetToPage()) && printout->HasPage(pn); - pn++) + sm_abortWindow = win; + sm_abortWindow->Show(TRUE); + wxYield(); + + printout->OnBeginPrinting(); + + bool keepGoing = TRUE; + + int copyCount; + for (copyCount = 1; copyCount <= m_printDialogData.GetNoCopies(); copyCount ++) + { + if (!printout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage())) + { + wxEndBusyCursor(); + wxMessageBox("Could not start printing.", "Print Error", wxOK, parent); + break; + } + if (sm_abortIt) + break; + + int pn; + for (pn = m_printDialogData.GetFromPage(); keepGoing && (pn <= m_printDialogData.GetToPage()) && printout->HasPage(pn); + pn++) + { + if (sm_abortIt) + { + keepGoing = FALSE; + break; + } + else + { + dc->StartPage(); + printout->OnPrintPage(pn); + dc->EndPage(); + } + } + printout->OnEndDocument(); + } + + printout->OnEndPrinting(); + + if (sm_abortWindow) { - if (sm_abortIt) - { - keepGoing = FALSE; - break; - } - else - { -// int dcID = ::SaveDC(dc->GetHDC()); - dc->StartPage(); - printout->OnPrintPage(pn); - dc->EndPage(); -// ::RestoreDC(dc->GetHDC(), dcID); - } + sm_abortWindow->Show(FALSE); + delete sm_abortWindow; + sm_abortWindow = NULL; } - printout->OnEndDocument(); - } - - printout->OnEndPrinting(); + + wxEndBusyCursor(); + + delete dc; + + return TRUE; +} - if (sm_abortWindow) - { - sm_abortWindow->Show(FALSE); - delete sm_abortWindow; - sm_abortWindow = NULL; - } +wxDC* wxWindowsPrinter::PrintDialog(wxWindow *parent) +{ + wxDC* dc = (wxDC*) NULL; - wxEndBusyCursor(); + wxPrintDialog dialog(parent, & m_printDialogData); + int ret = dialog.ShowModal(); - delete dc; - - return TRUE; -} + if (ret == wxID_OK) + { + dc = dialog.GetPrintDC(); + m_printDialogData = dialog.GetPrintDialogData(); + } -bool wxWindowsPrinter::PrintDialog(wxWindow *parent) -{ - wxPrintDialog dialog(parent, & m_printData); - return (dialog.ShowModal() == wxID_OK); + return dc; } bool wxWindowsPrinter::Setup(wxWindow *parent) { - wxPrintDialog dialog(parent, & m_printData); - dialog.GetPrintData().SetSetupDialog(TRUE); - return (dialog.ShowModal() == wxID_OK); + wxPrintDialog dialog(parent, & m_printDialogData); + dialog.GetPrintDialogData().SetSetupDialog(TRUE); + + int ret = dialog.ShowModal(); + + if (ret == wxID_OK) + { + m_printDialogData = dialog.GetPrintDialogData(); + } + + return (ret == wxID_OK); } /* - * Print preview - */ +* Print preview +*/ -wxWindowsPrintPreview::wxWindowsPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data): - wxPrintPreviewBase(printout, printoutForPrinting, data) +wxWindowsPrintPreview::wxWindowsPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintDialogData *data): +wxPrintPreviewBase(printout, printoutForPrinting, data) { - DetermineScaling(); + DetermineScaling(); } wxWindowsPrintPreview::~wxWindowsPrintPreview(void) @@ -277,55 +291,55 @@ wxWindowsPrintPreview::~wxWindowsPrintPreview(void) bool wxWindowsPrintPreview::Print(bool interactive) { - if (!m_printPrintout) - return FALSE; - wxWindowsPrinter printer(&m_printData); - return printer.Print(m_previewFrame, m_printPrintout, interactive); + if (!m_printPrintout) + return FALSE; + wxWindowsPrinter printer(&m_printDialogData); + return printer.Print(m_previewFrame, m_printPrintout, interactive); } void wxWindowsPrintPreview::DetermineScaling(void) { HDC dc = ::GetDC(NULL); int screenWidth = ::GetDeviceCaps(dc, HORZSIZE); -// int screenHeight = ::GetDeviceCaps(dc, VERTSIZE); + // int screenHeight = ::GetDeviceCaps(dc, VERTSIZE); int screenXRes = ::GetDeviceCaps(dc, HORZRES); -// int screenYRes = ::GetDeviceCaps(dc, VERTRES); + // int screenYRes = ::GetDeviceCaps(dc, VERTRES); int logPPIScreenX = ::GetDeviceCaps(dc, LOGPIXELSX); int logPPIScreenY = ::GetDeviceCaps(dc, LOGPIXELSY); m_previewPrintout->SetPPIScreen(logPPIScreenX, logPPIScreenY); - + ::ReleaseDC(NULL, dc); - + // Get a device context for the currently selected printer - wxPrinterDC printerDC("", "", "", FALSE, m_printData.GetOrientation()); - + wxPrinterDC printerDC(m_printDialogData.GetPrintData()); + int printerWidth = 150; int printerHeight = 250; int printerXRes = 1500; int printerYRes = 2500; - + if (printerDC.GetHDC()) { - printerWidth = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZSIZE); - printerHeight = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTSIZE); - printerXRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZRES); - printerYRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTRES); - - int logPPIPrinterX = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSX); - int logPPIPrinterY = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSY); - - m_previewPrintout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY); - m_previewPrintout->SetPageSizeMM(printerWidth, printerHeight); - - if (logPPIPrinterX == 0 || logPPIPrinterY == 0 || printerWidth == 0 || printerHeight == 0) - m_isOk = FALSE; + printerWidth = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZSIZE); + printerHeight = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTSIZE); + printerXRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZRES); + printerYRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTRES); + + int logPPIPrinterX = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSX); + int logPPIPrinterY = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSY); + + m_previewPrintout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY); + m_previewPrintout->SetPageSizeMM(printerWidth, printerHeight); + + if (logPPIPrinterX == 0 || logPPIPrinterY == 0 || printerWidth == 0 || printerHeight == 0) + m_isOk = FALSE; } else - m_isOk = FALSE; - + m_isOk = FALSE; + m_pageWidth = printerXRes; m_pageHeight = printerYRes; - + // At 100%, the page should look about page-size on the screen. m_previewScale = (float)((float)screenWidth/(float)printerWidth); m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerYRes); @@ -333,29 +347,29 @@ void wxWindowsPrintPreview::DetermineScaling(void) /**************************************************************************** - FUNCTION: wxAbortProc() - + FUNCTION: wxAbortProc() + PURPOSE: Processes messages for the Abort Dialog box - + ****************************************************************************/ LONG APIENTRY _EXPORT wxAbortProc(HDC WXUNUSED(hPr), int WXUNUSED(Code)) { MSG msg; - + if (!wxPrinterBase::sm_abortWindow) /* If the abort dialog isn't up yet */ return(TRUE); - + /* Process messages intended for the abort dialog box */ - + while (!wxPrinterBase::sm_abortIt && PeekMessage(&msg, 0, 0, 0, TRUE)) if (!IsDialogMessage((HWND) wxPrinterBase::sm_abortWindow->GetHWND(), &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } - - /* bAbort is TRUE (return is FALSE) if the user has aborted */ - - return (!wxPrinterBase::sm_abortIt); + + /* bAbort is TRUE (return is FALSE) if the user has aborted */ + + return (!wxPrinterBase::sm_abortIt); } diff --git a/src/stubs.inc b/src/stubs.inc index 20543be921..2b9b930ef4 100644 --- a/src/stubs.inc +++ b/src/stubs.inc @@ -34,6 +34,7 @@ LIB_CPP_SRC=\ common/module.cpp \ common/object.cpp \ common/odbc.cpp \ + common/paper.cpp \ common/prntbase.cpp \ common/resource.cpp \ common/serbase.cpp \ diff --git a/src/unix/threadpsx.cpp b/src/unix/threadpsx.cpp index bb105415ce..5895f57d77 100644 --- a/src/unix/threadpsx.cpp +++ b/src/unix/threadpsx.cpp @@ -24,12 +24,13 @@ #pragma implementation "thread.h" #endif -#include "wx/thread.h" +// With simple makefiles, we must ignore the file body if not using +// threads. +#include "wx/setup.h" -#if !wxUSE_THREADS - #error This file needs wxUSE_THREADS -#endif +#if wxUSE_THREADS +#include "wx/thread.h" #include "wx/module.h" #include "wx/utils.h" #include "wx/log.h" @@ -42,7 +43,7 @@ #include #include -#ifdef HAVE_SCHED_H +#if HAVE_SCHED_H #include #endif @@ -793,3 +794,5 @@ void wxMutexGuiLeave() gs_mutexGui->Unlock(); } +#endif + // wxUSE_THREADS diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index 9e8865a5ec..9a213ff4c0 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -41,7 +41,10 @@ #include // nanosleep() and/or usleep() #include // isspace() -#ifdef HAVE_UNAME +// JACS: needed for FD_SETSIZE +#include + +#if HAVE_UNAME #include // for uname() #endif // HAVE_UNAME @@ -81,14 +84,14 @@ void wxSleep(int nSecs) void wxUsleep(unsigned long milliseconds) { -#if defined(HAVE_NANOSLEEP) +#if HAVE_NANOSLEEP timespec tmReq; tmReq.tv_sec = milliseconds / 1000; tmReq.tv_nsec = (milliseconds % 1000) * 1000 * 1000; // we're not interested in remaining time nor in return value (void)nanosleep(&tmReq, (timespec *)NULL); -#elif defined(HAVE_USLEEP) +#elif HAVE_USLEEP // uncomment this if you feel brave or if you are sure that your version // of Solaris has a safe usleep() function but please notice that usleep() // is known to lead to crashes in MT programs in Solaris 2.[67] and is not -- 2.45.2