]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/printps.cpp
e9b819b6fc44b49b62529c94a9b226f72e9b5a22
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Postscript print/preview framework
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "printps.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
37 #include "wx/msgdlg.h"
39 #include "wx/progdlg.h"
42 #include "wx/generic/printps.h"
43 #include "wx/dcprint.h"
44 #include "wx/printdlg.h"
45 #include "wx/generic/prntdlgg.h"
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 #if !USE_SHARED_LIBRARY
55 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptPrinter
, wxPrinterBase
)
56 IMPLEMENT_CLASS(wxPostScriptPrintPreview
, wxPrintPreviewBase
)
59 // ============================================================================
61 // ============================================================================
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 wxPostScriptPrinter::wxPostScriptPrinter(wxPrintDialogData
*data
)
72 wxPostScriptPrinter::~wxPostScriptPrinter()
76 bool wxPostScriptPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
79 sm_abortWindow
= (wxWindow
*) NULL
;
84 printout
->SetIsPreview(FALSE
);
85 printout
->OnPreparePrinting();
87 // Get some parameters from the printout, if defined
90 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
95 m_printDialogData
.SetMinPage(minPage
);
96 m_printDialogData
.SetMaxPage(maxPage
);
98 m_printDialogData
.SetFromPage(fromPage
);
100 m_printDialogData
.SetToPage(toPage
);
104 m_printDialogData
.EnablePageNumbers(TRUE
);
105 if (m_printDialogData
.GetFromPage() < m_printDialogData
.GetMinPage())
106 m_printDialogData
.SetFromPage(m_printDialogData
.GetMinPage());
107 else if (m_printDialogData
.GetFromPage() > m_printDialogData
.GetMaxPage())
108 m_printDialogData
.SetFromPage(m_printDialogData
.GetMaxPage());
109 if (m_printDialogData
.GetToPage() > m_printDialogData
.GetMaxPage())
110 m_printDialogData
.SetToPage(m_printDialogData
.GetMaxPage());
111 else if (m_printDialogData
.GetToPage() < m_printDialogData
.GetMinPage())
112 m_printDialogData
.SetToPage(m_printDialogData
.GetMinPage());
115 m_printDialogData
.EnablePageNumbers(FALSE
);
118 // Create a suitable device context
119 wxDC
*dc
= (wxDC
*) NULL
;
122 dc
= PrintDialog(parent
);
128 dc
= new wxPostScriptDC(wxThePrintSetupData
->GetPrinterFile(), FALSE
, (wxWindow
*) NULL
);
131 // May have pressed cancel.
132 if (!dc
|| !dc
->Ok())
138 int logPPIScreenX
= 0;
139 int logPPIScreenY
= 0;
140 int logPPIPrinterX
= 0;
141 int logPPIPrinterY
= 0;
147 // Correct values for X/PostScript?
148 logPPIPrinterX = 100;
149 logPPIPrinterY = 100;
155 printout
->SetPPIScreen(logPPIScreenX
, logPPIScreenY
);
156 printout
->SetPPIPrinter(logPPIPrinterX
, logPPIPrinterY
);
158 // Set printout parameters
163 printout
->SetPageSizePixels((int)w
, (int)h
);
164 dc
->GetSizeMM(&w
, &h
);
165 printout
->SetPageSizeMM((int)w
, (int)h
);
167 // Create an abort window
171 pagesPerCopy
= m_printDialogData
.GetToPage()-m_printDialogData
.GetFromPage()+1,
172 totalPages
= pagesPerCopy
* m_printDialogData
.GetNoCopies(),
174 // Open the progress bar dialog
175 wxProgressDialog
*progressDialog
= new wxProgressDialog (
176 printout
->GetTitle(),
181 printout
->OnBeginPrinting();
183 bool keepGoing
= TRUE
;
186 for (copyCount
= 1; copyCount
<= m_printDialogData
.GetNoCopies(); copyCount
++)
188 if (!printout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
191 wxMessageBox(_("Could not start printing."), _("Print Error"), wxOK
, parent
);
198 for (pn
= m_printDialogData
.GetFromPage(); keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
209 msg
.Printf(_("Printing page %d..."), printedPages
+1);
210 if(progressDialog
->Update(printedPages
++, msg
))
213 printout
->OnPrintPage(pn
);
223 printout
->OnEndDocument();
226 printout
->OnEndPrinting();
227 delete progressDialog
;
236 wxDC
* wxPostScriptPrinter::PrintDialog(wxWindow
*parent
)
238 wxDC
* dc
= (wxDC
*) NULL
;
239 wxGenericPrintDialog
* dialog
= new wxGenericPrintDialog(parent
, & m_printDialogData
);
240 int ret
= dialog
->ShowModal() ;
243 dc
= dialog
->GetPrintDC();
244 m_printDialogData
= dialog
->GetPrintDialogData();
251 bool wxPostScriptPrinter::Setup(wxWindow
*parent
)
253 wxGenericPrintDialog
* dialog
= new wxGenericPrintDialog(parent
, & m_printDialogData
);
254 dialog
->GetPrintDialogData().SetSetupDialog(TRUE
);
256 int ret
= dialog
->ShowModal();
260 m_printDialogData
= dialog
->GetPrintDialogData();
265 return (ret
== wxID_OK
);
268 // ----------------------------------------------------------------------------
270 // ----------------------------------------------------------------------------
272 void wxPostScriptPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
273 wxPrintout
* WXUNUSED(printoutForPrinting
))
275 // Have to call it here since base constructor can't call it
279 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
,
280 wxPrintout
*printoutForPrinting
,
281 wxPrintDialogData
*data
)
282 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
284 Init(printout
, printoutForPrinting
);
287 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
,
288 wxPrintout
*printoutForPrinting
,
290 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
292 Init(printout
, printoutForPrinting
);
295 wxPostScriptPrintPreview::~wxPostScriptPrintPreview()
299 bool wxPostScriptPrintPreview::Print(bool interactive
)
301 if (!m_printPrintout
)
303 wxPostScriptPrinter
printer(& m_printDialogData
);
304 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
307 void wxPostScriptPrintPreview::DetermineScaling()
309 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
310 if (paperType
== wxPAPER_NONE
)
311 paperType
= wxPAPER_NONE
;
313 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
315 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
319 m_previewPrintout
->SetPPIScreen(100, 100);
320 // m_previewPrintout->SetPPIPrinter(100, 100);
321 m_previewPrintout
->SetPPIPrinter(72, 72);
323 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
324 wxSize
sizeTenthsMM(paper
->GetSize());
325 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
327 // If in landscape mode, we need to swap the width and height.
328 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
330 m_pageWidth
= sizeDevUnits
.y
;
331 m_pageHeight
= sizeDevUnits
.x
;
332 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
333 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
337 m_pageWidth
= sizeDevUnits
.x
;
338 m_pageHeight
= sizeDevUnits
.y
;
339 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
340 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
343 // At 100%, the page should look about page-size on the screen.
344 m_previewScale
= (float)0.8;