]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/printps.cpp
f64a03b5e4dfd75716eeba66842159ca9cf55629
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Postscript print/preview framework
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "printps.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
29 #include "wx/msgdlg.h"
33 #include "wx/generic/printps.h"
34 #include "wx/dcprint.h"
35 #include "wx/printdlg.h"
36 #include "wx/generic/prntdlgg.h"
41 #if !USE_SHARED_LIBRARY
42 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptPrinter
, wxPrinterBase
)
43 IMPLEMENT_CLASS(wxPostScriptPrintPreview
, wxPrintPreviewBase
)
50 wxPostScriptPrinter::wxPostScriptPrinter(wxPrintDialogData
*data
):
55 wxPostScriptPrinter::~wxPostScriptPrinter(void)
59 bool wxPostScriptPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
62 sm_abortWindow
= (wxWindow
*) NULL
;
67 printout
->SetIsPreview(FALSE
);
68 printout
->OnPreparePrinting();
70 // Get some parameters from the printout, if defined
73 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
78 m_printDialogData
.SetMinPage(minPage
);
79 m_printDialogData
.SetMaxPage(maxPage
);
81 m_printDialogData
.SetFromPage(fromPage
);
83 m_printDialogData
.SetToPage(toPage
);
87 m_printDialogData
.EnablePageNumbers(TRUE
);
88 if (m_printDialogData
.GetFromPage() < m_printDialogData
.GetMinPage())
89 m_printDialogData
.SetFromPage(m_printDialogData
.GetMinPage());
90 else if (m_printDialogData
.GetFromPage() > m_printDialogData
.GetMaxPage())
91 m_printDialogData
.SetFromPage(m_printDialogData
.GetMaxPage());
92 if (m_printDialogData
.GetToPage() > m_printDialogData
.GetMaxPage())
93 m_printDialogData
.SetToPage(m_printDialogData
.GetMaxPage());
94 else if (m_printDialogData
.GetToPage() < m_printDialogData
.GetMinPage())
95 m_printDialogData
.SetToPage(m_printDialogData
.GetMinPage());
98 m_printDialogData
.EnablePageNumbers(FALSE
);
100 // Create a suitable device context
101 wxDC
*dc
= (wxDC
*) NULL
;
104 dc
= PrintDialog(parent
);
110 dc
= new wxPostScriptDC(wxThePrintSetupData
->GetPrinterFile(), FALSE
, (wxWindow
*) NULL
);
113 // May have pressed cancel.
114 if (!dc
|| !dc
->Ok())
120 int logPPIScreenX
= 0;
121 int logPPIScreenY
= 0;
122 int logPPIPrinterX
= 0;
123 int logPPIPrinterY
= 0;
129 // Correct values for X/PostScript?
130 logPPIPrinterX = 100;
131 logPPIPrinterY = 100;
137 printout
->SetPPIScreen(logPPIScreenX
, logPPIScreenY
);
138 printout
->SetPPIPrinter(logPPIPrinterX
, logPPIPrinterY
);
140 // Set printout parameters
145 printout
->SetPageSizePixels((int)w
, (int)h
);
146 dc
->GetSizeMM(&w
, &h
);
147 printout
->SetPageSizeMM((int)w
, (int)h
);
149 // Create an abort window
152 printout
->OnBeginPrinting();
154 bool keepGoing
= TRUE
;
157 for (copyCount
= 1; copyCount
<= m_printDialogData
.GetNoCopies(); copyCount
++)
159 if (!printout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
162 wxMessageBox(_("Could not start printing."), _("Print Error"), wxOK
, parent
);
169 for (pn
= m_printDialogData
.GetFromPage(); keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
180 printout
->OnPrintPage(pn
);
184 printout
->OnEndDocument();
187 printout
->OnEndPrinting();
196 wxDC
* wxPostScriptPrinter::PrintDialog(wxWindow
*parent
)
198 wxDC
* dc
= (wxDC
*) NULL
;
199 wxGenericPrintDialog
* dialog
= new wxGenericPrintDialog(parent
, & m_printDialogData
);
200 int ret
= dialog
->ShowModal() ;
203 dc
= dialog
->GetPrintDC();
204 m_printDialogData
= dialog
->GetPrintDialogData();
211 bool wxPostScriptPrinter::Setup(wxWindow
*parent
)
213 wxGenericPrintDialog
* dialog
= new wxGenericPrintDialog(parent
, & m_printDialogData
);
214 dialog
->GetPrintDialogData().SetSetupDialog(TRUE
);
216 int ret
= dialog
->ShowModal();
220 m_printDialogData
= dialog
->GetPrintDialogData();
225 return (ret
== wxID_OK
);
232 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
, wxPrintDialogData
*data
):
233 wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
235 // Have to call it here since base constructor can't call it
239 wxPostScriptPrintPreview::~wxPostScriptPrintPreview(void)
243 bool wxPostScriptPrintPreview::Print(bool interactive
)
245 if (!m_printPrintout
)
247 wxPostScriptPrinter
printer(& m_printDialogData
);
248 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
251 void wxPostScriptPrintPreview::DetermineScaling(void)
253 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
254 if (paperType
== wxPAPER_NONE
)
255 paperType
= wxPAPER_NONE
;
257 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
259 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
263 m_previewPrintout
->SetPPIScreen(100, 100);
264 // m_previewPrintout->SetPPIPrinter(100, 100);
265 m_previewPrintout
->SetPPIPrinter(72, 72);
267 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
268 wxSize
sizeTenthsMM(paper
->GetSize());
269 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
271 // If in landscape mode, we need to swap the width and height.
272 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
274 m_pageWidth
= sizeDevUnits
.y
;
275 m_pageHeight
= sizeDevUnits
.x
;
276 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
277 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
281 m_pageWidth
= sizeDevUnits
.x
;
282 m_pageHeight
= sizeDevUnits
.y
;
283 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
284 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
287 // At 100%, the page should look about page-size on the screen.
288 m_previewScale
= (float)0.8;