]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/printps.cpp
90cae631fb7712866255998501bf109df2f16c1d
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/printps.cpp
3 // Purpose: Postscript print/preview framework
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 // ============================================================================
21 // ============================================================================
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
27 #if wxUSE_PRINTING_ARCHITECTURE && wxUSE_POSTSCRIPT && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
33 #include "wx/msgdlg.h"
35 #include "wx/progdlg.h"
37 #include "wx/dcprint.h"
40 #include "wx/generic/printps.h"
41 #include "wx/printdlg.h"
42 #include "wx/generic/prntdlgg.h"
43 #include "wx/generic/progdlgg.h"
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptPrinter
, wxPrinterBase
)
53 IMPLEMENT_CLASS(wxPostScriptPrintPreview
, wxPrintPreviewBase
)
55 // ============================================================================
57 // ============================================================================
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 wxPostScriptPrinter::wxPostScriptPrinter(wxPrintDialogData
*data
)
68 wxPostScriptPrinter::~wxPostScriptPrinter()
72 bool wxPostScriptPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
75 sm_abortWindow
= (wxWindow
*) NULL
;
79 sm_lastError
= wxPRINTER_ERROR
;
83 printout
->SetIsPreview(false);
85 if (m_printDialogData
.GetMinPage() < 1)
86 m_printDialogData
.SetMinPage(1);
87 if (m_printDialogData
.GetMaxPage() < 1)
88 m_printDialogData
.SetMaxPage(9999);
90 // Create a suitable device context
94 dc
= PrintDialog(parent
);
100 dc
= new wxPostScriptDC(GetPrintDialogData().GetPrintData());
103 // May have pressed cancel.
104 if (!dc
|| !dc
->Ok())
107 sm_lastError
= wxPRINTER_ERROR
;
111 wxSize ScreenPixels
= wxGetDisplaySize();
112 wxSize ScreenMM
= wxGetDisplaySizeMM();
114 printout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
115 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
116 printout
->SetPPIPrinter( wxPostScriptDC::GetResolution(),
117 wxPostScriptDC::GetResolution() );
119 // Set printout parameters
124 printout
->SetPageSizePixels((int)w
, (int)h
);
125 printout
->SetPaperRectPixels(wxRect(0, 0, w
, h
));
127 dc
->GetSizeMM(&mw
, &mh
);
128 printout
->SetPageSizeMM((int)mw
, (int)mh
);
130 // Create an abort window
133 printout
->OnPreparePrinting();
135 // Get some parameters from the printout, if defined
136 int fromPage
, toPage
;
137 int minPage
, maxPage
;
138 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
142 sm_lastError
= wxPRINTER_ERROR
;
147 // Only set min and max, because from and to have been
149 m_printDialogData
.SetMinPage(minPage
);
150 m_printDialogData
.SetMaxPage(maxPage
);
152 if (m_printDialogData
.GetFromPage() < minPage
)
153 m_printDialogData
.SetFromPage( minPage
);
154 if (m_printDialogData
.GetToPage() > maxPage
)
155 m_printDialogData
.SetToPage( maxPage
);
158 pagesPerCopy
= m_printDialogData
.GetToPage()-m_printDialogData
.GetFromPage()+1,
159 totalPages
= pagesPerCopy
* m_printDialogData
.GetNoCopies(),
161 // Open the progress bar dialog
162 wxProgressDialog
*progressDialog
= new wxProgressDialog (
163 printout
->GetTitle(),
167 wxPD_CAN_ABORT
|wxPD_AUTO_HIDE
|wxPD_APP_MODAL
);
169 printout
->OnBeginPrinting();
171 sm_lastError
= wxPRINTER_NO_ERROR
;
173 bool keepGoing
= true;
176 for (copyCount
= 1; copyCount
<= m_printDialogData
.GetNoCopies(); copyCount
++)
178 if (!printout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
181 wxLogError(_("Could not start printing."));
182 sm_lastError
= wxPRINTER_ERROR
;
187 sm_lastError
= wxPRINTER_CANCELLED
;
192 for (pn
= m_printDialogData
.GetFromPage(); keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
198 sm_lastError
= wxPRINTER_CANCELLED
;
204 msg
.Printf(_("Printing page %d..."), printedPages
+1);
205 if(progressDialog
->Update(printedPages
++, msg
))
208 printout
->OnPrintPage(pn
);
214 sm_lastError
= wxPRINTER_CANCELLED
;
220 printout
->OnEndDocument();
223 printout
->OnEndPrinting();
224 delete progressDialog
;
230 return (sm_lastError
== wxPRINTER_NO_ERROR
);
233 wxDC
* wxPostScriptPrinter::PrintDialog(wxWindow
*parent
)
235 wxDC
* dc
= (wxDC
*) NULL
;
237 wxGenericPrintDialog
dialog( parent
, &m_printDialogData
);
238 if (dialog
.ShowModal() == wxID_OK
)
240 dc
= dialog
.GetPrintDC();
241 m_printDialogData
= dialog
.GetPrintDialogData();
244 sm_lastError
= wxPRINTER_ERROR
;
246 sm_lastError
= wxPRINTER_NO_ERROR
;
249 sm_lastError
= wxPRINTER_CANCELLED
;
254 bool wxPostScriptPrinter::Setup(wxWindow
*WXUNUSED(parent
))
257 wxGenericPrintDialog
* dialog
= new wxGenericPrintDialog(parent
, & m_printDialogData
);
258 dialog
->GetPrintDialogData().SetSetupDialog(true);
260 int ret
= dialog
->ShowModal();
264 m_printDialogData
= dialog
->GetPrintDialogData();
269 return (ret
== wxID_OK
);
275 // ----------------------------------------------------------------------------
277 // ----------------------------------------------------------------------------
279 void wxPostScriptPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
280 wxPrintout
* WXUNUSED(printoutForPrinting
))
282 // Have to call it here since base constructor can't call it
286 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
,
287 wxPrintout
*printoutForPrinting
,
288 wxPrintDialogData
*data
)
289 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
291 Init(printout
, printoutForPrinting
);
294 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
,
295 wxPrintout
*printoutForPrinting
,
297 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
299 Init(printout
, printoutForPrinting
);
302 wxPostScriptPrintPreview::~wxPostScriptPrintPreview()
306 bool wxPostScriptPrintPreview::Print(bool interactive
)
308 if (!m_printPrintout
)
311 // Assume that on Unix, the preview may use the PostScript
312 // (generic) version, but printing using the native system is required.
313 // TODO: make a generic print preview class from which wxPostScriptPrintPreview
316 wxPrinter
printer(& m_printDialogData
);
318 wxPostScriptPrinter
printer(& m_printDialogData
);
320 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
323 void wxPostScriptPrintPreview::DetermineScaling()
325 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
326 if (paperType
== wxPAPER_NONE
)
327 paperType
= wxPAPER_NONE
;
329 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
331 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
335 wxSize ScreenPixels
= wxGetDisplaySize();
336 wxSize ScreenMM
= wxGetDisplaySizeMM();
338 m_previewPrintout
->SetPPIScreen( (int) ((ScreenPixels
.GetWidth() * 25.4) / ScreenMM
.GetWidth()),
339 (int) ((ScreenPixels
.GetHeight() * 25.4) / ScreenMM
.GetHeight()) );
340 m_previewPrintout
->SetPPIPrinter(wxPostScriptDC::GetResolution(), wxPostScriptDC::GetResolution());
342 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
343 sizeDevUnits
.x
= (wxCoord
)((float)sizeDevUnits
.x
* wxPostScriptDC::GetResolution() / 72.0);
344 sizeDevUnits
.y
= (wxCoord
)((float)sizeDevUnits
.y
* wxPostScriptDC::GetResolution() / 72.0);
345 wxSize
sizeTenthsMM(paper
->GetSize());
346 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
348 // If in landscape mode, we need to swap the width and height.
349 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
351 m_pageWidth
= sizeDevUnits
.y
;
352 m_pageHeight
= sizeDevUnits
.x
;
353 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
357 m_pageWidth
= sizeDevUnits
.x
;
358 m_pageHeight
= sizeDevUnits
.y
;
359 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
361 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
362 m_previewPrintout
->SetPaperRectPixels(wxRect(0, 0, m_pageWidth
, m_pageHeight
));
364 // At 100%, the page should look about page-size on the screen.
365 m_previewScaleX
= (float)0.8 * 72.0 / (float)wxPostScriptDC::GetResolution();
366 m_previewScaleY
= m_previewScaleX
;