]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/printps.cpp
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"
33 #if wxUSE_PRINTING_ARCHITECTURE
39 #include "wx/msgdlg.h"
41 #include "wx/progdlg.h"
44 #include "wx/generic/printps.h"
45 #include "wx/dcprint.h"
46 #include "wx/printdlg.h"
47 #include "wx/generic/prntdlgg.h"
48 #include "wx/generic/progdlgg.h"
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptPrinter
, wxPrinterBase
)
58 IMPLEMENT_CLASS(wxPostScriptPrintPreview
, wxPrintPreviewBase
)
60 // ============================================================================
62 // ============================================================================
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 wxPostScriptPrinter::wxPostScriptPrinter(wxPrintDialogData
*data
)
73 wxPostScriptPrinter::~wxPostScriptPrinter()
77 bool wxPostScriptPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
80 sm_abortWindow
= (wxWindow
*) NULL
;
84 sm_lastError
= wxPRINTER_ERROR
;
88 printout
->SetIsPreview(FALSE
);
90 // 4/9/99, JACS: this is a silly place to allow preparation, considering
91 // the DC and no parameters have been set in the printout object.
92 // Moved further down.
94 // printout->OnPreparePrinting();
96 // Get some parameters from the printout, if defined
99 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
103 sm_lastError
= wxPRINTER_ERROR
;
107 m_printDialogData
.SetMinPage(minPage
);
108 m_printDialogData
.SetMaxPage(maxPage
);
110 m_printDialogData
.SetFromPage(fromPage
);
112 m_printDialogData
.SetToPage(toPage
);
116 m_printDialogData
.EnablePageNumbers(TRUE
);
117 if (m_printDialogData
.GetFromPage() < m_printDialogData
.GetMinPage())
118 m_printDialogData
.SetFromPage(m_printDialogData
.GetMinPage());
119 else if (m_printDialogData
.GetFromPage() > m_printDialogData
.GetMaxPage())
120 m_printDialogData
.SetFromPage(m_printDialogData
.GetMaxPage());
121 if (m_printDialogData
.GetToPage() > m_printDialogData
.GetMaxPage())
122 m_printDialogData
.SetToPage(m_printDialogData
.GetMaxPage());
123 else if (m_printDialogData
.GetToPage() < m_printDialogData
.GetMinPage())
124 m_printDialogData
.SetToPage(m_printDialogData
.GetMinPage());
127 m_printDialogData
.EnablePageNumbers(FALSE
);
130 // Create a suitable device context
131 wxDC
*dc
= (wxDC
*) NULL
;
134 dc
= PrintDialog(parent
);
140 dc
= new wxPostScriptDC(GetPrintDialogData().GetPrintData());
143 // May have pressed cancel.
144 if (!dc
|| !dc
->Ok())
147 sm_lastError
= wxPRINTER_ERROR
;
151 int logPPIScreenX
= 0;
152 int logPPIScreenY
= 0;
153 int logPPIPrinterX
= 0;
154 int logPPIPrinterY
= 0;
160 // Correct values for X/PostScript?
161 logPPIPrinterX = 100;
162 logPPIPrinterY = 100;
165 logPPIPrinterX
= wxPostScriptDC::GetResolution();
166 logPPIPrinterY
= wxPostScriptDC::GetResolution();
168 printout
->SetPPIScreen(logPPIScreenX
, logPPIScreenY
);
169 printout
->SetPPIPrinter(logPPIPrinterX
, logPPIPrinterY
);
171 // Set printout parameters
176 printout
->SetPageSizePixels((int)w
, (int)h
);
177 dc
->GetSizeMM(&w
, &h
);
178 printout
->SetPageSizeMM((int)w
, (int)h
);
180 // Create an abort window
183 printout
->OnPreparePrinting();
186 pagesPerCopy
= m_printDialogData
.GetToPage()-m_printDialogData
.GetFromPage()+1,
187 totalPages
= pagesPerCopy
* m_printDialogData
.GetNoCopies(),
189 // Open the progress bar dialog
190 wxProgressDialog
*progressDialog
= new wxProgressDialog (
191 printout
->GetTitle(),
195 wxPD_CAN_ABORT
|wxPD_AUTO_HIDE
|wxPD_APP_MODAL
);
197 printout
->OnBeginPrinting();
199 sm_lastError
= wxPRINTER_NO_ERROR
;
201 bool keepGoing
= TRUE
;
204 for (copyCount
= 1; copyCount
<= m_printDialogData
.GetNoCopies(); copyCount
++)
206 if (!printout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
209 wxLogError(_("Could not start printing."));
210 sm_lastError
= wxPRINTER_ERROR
;
215 sm_lastError
= wxPRINTER_CANCELLED
;
220 for (pn
= m_printDialogData
.GetFromPage(); keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
226 sm_lastError
= wxPRINTER_CANCELLED
;
232 msg
.Printf(_("Printing page %d..."), printedPages
+1);
233 if(progressDialog
->Update(printedPages
++, msg
))
236 printout
->OnPrintPage(pn
);
242 sm_lastError
= wxPRINTER_CANCELLED
;
248 printout
->OnEndDocument();
251 printout
->OnEndPrinting();
252 delete progressDialog
;
258 return (sm_lastError
== wxPRINTER_NO_ERROR
);
261 wxDC
* wxPostScriptPrinter::PrintDialog(wxWindow
*parent
)
263 wxDC
* dc
= (wxDC
*) NULL
;
264 wxGenericPrintDialog
* dialog
= new wxGenericPrintDialog(parent
, & m_printDialogData
);
265 int ret
= dialog
->ShowModal() ;
268 dc
= dialog
->GetPrintDC();
269 m_printDialogData
= dialog
->GetPrintDialogData();
271 sm_lastError
= wxPRINTER_ERROR
;
273 sm_lastError
= wxPRINTER_NO_ERROR
;
276 sm_lastError
= wxPRINTER_CANCELLED
;
283 bool wxPostScriptPrinter::Setup(wxWindow
*parent
)
285 wxGenericPrintDialog
* dialog
= new wxGenericPrintDialog(parent
, & m_printDialogData
);
286 dialog
->GetPrintDialogData().SetSetupDialog(TRUE
);
288 int ret
= dialog
->ShowModal();
292 m_printDialogData
= dialog
->GetPrintDialogData();
297 return (ret
== wxID_OK
);
300 // ----------------------------------------------------------------------------
302 // ----------------------------------------------------------------------------
304 void wxPostScriptPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
305 wxPrintout
* WXUNUSED(printoutForPrinting
))
307 // Have to call it here since base constructor can't call it
311 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
,
312 wxPrintout
*printoutForPrinting
,
313 wxPrintDialogData
*data
)
314 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
316 Init(printout
, printoutForPrinting
);
319 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
,
320 wxPrintout
*printoutForPrinting
,
322 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
324 Init(printout
, printoutForPrinting
);
327 wxPostScriptPrintPreview::~wxPostScriptPrintPreview()
331 bool wxPostScriptPrintPreview::Print(bool interactive
)
333 if (!m_printPrintout
)
335 wxPostScriptPrinter
printer(& m_printDialogData
);
336 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
339 void wxPostScriptPrintPreview::DetermineScaling()
341 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
342 if (paperType
== wxPAPER_NONE
)
343 paperType
= wxPAPER_NONE
;
345 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
347 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
351 m_previewPrintout
->SetPPIScreen(100, 100);
352 // m_previewPrintout->SetPPIPrinter(100, 100);
353 m_previewPrintout
->SetPPIPrinter(wxPostScriptDC::GetResolution(), wxPostScriptDC::GetResolution());
355 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
356 sizeDevUnits
.x
= (wxCoord
)((float)sizeDevUnits
.x
* wxPostScriptDC::GetResolution() / 72.0);
357 sizeDevUnits
.y
= (wxCoord
)((float)sizeDevUnits
.y
* wxPostScriptDC::GetResolution() / 72.0);
358 wxSize
sizeTenthsMM(paper
->GetSize());
359 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
361 // If in landscape mode, we need to swap the width and height.
362 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
364 m_pageWidth
= sizeDevUnits
.y
;
365 m_pageHeight
= sizeDevUnits
.x
;
366 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
367 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
371 m_pageWidth
= sizeDevUnits
.x
;
372 m_pageHeight
= sizeDevUnits
.y
;
373 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
374 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
377 // At 100%, the page should look about page-size on the screen.
378 m_previewScale
= (float)0.8 * 72.0 / (float)wxPostScriptDC::GetResolution();