]>
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 #if !USE_SHARED_LIBRARY
58 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptPrinter
, wxPrinterBase
)
59 IMPLEMENT_CLASS(wxPostScriptPrintPreview
, wxPrintPreviewBase
)
62 // ============================================================================
64 // ============================================================================
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 wxPostScriptPrinter::wxPostScriptPrinter(wxPrintDialogData
*data
)
75 wxPostScriptPrinter::~wxPostScriptPrinter()
79 bool wxPostScriptPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
82 sm_abortWindow
= (wxWindow
*) NULL
;
87 printout
->SetIsPreview(FALSE
);
89 // 4/9/99, JACS: this is a silly place to allow preparation, considering
90 // the DC and no parameters have been set in the printout object.
91 // Moved further down.
93 // printout->OnPreparePrinting();
95 // Get some parameters from the printout, if defined
98 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
103 m_printDialogData
.SetMinPage(minPage
);
104 m_printDialogData
.SetMaxPage(maxPage
);
106 m_printDialogData
.SetFromPage(fromPage
);
108 m_printDialogData
.SetToPage(toPage
);
112 m_printDialogData
.EnablePageNumbers(TRUE
);
113 if (m_printDialogData
.GetFromPage() < m_printDialogData
.GetMinPage())
114 m_printDialogData
.SetFromPage(m_printDialogData
.GetMinPage());
115 else if (m_printDialogData
.GetFromPage() > m_printDialogData
.GetMaxPage())
116 m_printDialogData
.SetFromPage(m_printDialogData
.GetMaxPage());
117 if (m_printDialogData
.GetToPage() > m_printDialogData
.GetMaxPage())
118 m_printDialogData
.SetToPage(m_printDialogData
.GetMaxPage());
119 else if (m_printDialogData
.GetToPage() < m_printDialogData
.GetMinPage())
120 m_printDialogData
.SetToPage(m_printDialogData
.GetMinPage());
123 m_printDialogData
.EnablePageNumbers(FALSE
);
126 // Create a suitable device context
127 wxDC
*dc
= (wxDC
*) NULL
;
130 dc
= PrintDialog(parent
);
136 dc
= new wxPostScriptDC(wxThePrintSetupData
->GetPrinterFile(), FALSE
, (wxWindow
*) NULL
);
139 // May have pressed cancel.
140 if (!dc
|| !dc
->Ok())
146 int logPPIScreenX
= 0;
147 int logPPIScreenY
= 0;
148 int logPPIPrinterX
= 0;
149 int logPPIPrinterY
= 0;
155 // Correct values for X/PostScript?
156 logPPIPrinterX = 100;
157 logPPIPrinterY = 100;
163 printout
->SetPPIScreen(logPPIScreenX
, logPPIScreenY
);
164 printout
->SetPPIPrinter(logPPIPrinterX
, logPPIPrinterY
);
166 // Set printout parameters
171 printout
->SetPageSizePixels((int)w
, (int)h
);
172 dc
->GetSizeMM(&w
, &h
);
173 printout
->SetPageSizeMM((int)w
, (int)h
);
175 // Create an abort window
178 printout
->OnPreparePrinting();
181 pagesPerCopy
= m_printDialogData
.GetToPage()-m_printDialogData
.GetFromPage()+1,
182 totalPages
= pagesPerCopy
* m_printDialogData
.GetNoCopies(),
184 // Open the progress bar dialog
185 wxProgressDialog
*progressDialog
= new wxProgressDialog (
186 printout
->GetTitle(),
190 wxPD_CAN_ABORT
|wxPD_AUTO_HIDE
|wxPD_APP_MODAL
);
192 printout
->OnBeginPrinting();
194 bool keepGoing
= TRUE
;
197 for (copyCount
= 1; copyCount
<= m_printDialogData
.GetNoCopies(); copyCount
++)
199 if (!printout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
202 wxMessageBox(_("Could not start printing."), _("Print Error"), wxOK
, parent
);
209 for (pn
= m_printDialogData
.GetFromPage(); keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
220 msg
.Printf(_("Printing page %d..."), printedPages
+1);
221 if(progressDialog
->Update(printedPages
++, msg
))
224 printout
->OnPrintPage(pn
);
235 printout
->OnEndDocument();
238 printout
->OnEndPrinting();
239 delete progressDialog
;
248 wxDC
* wxPostScriptPrinter::PrintDialog(wxWindow
*parent
)
250 wxDC
* dc
= (wxDC
*) NULL
;
251 wxGenericPrintDialog
* dialog
= new wxGenericPrintDialog(parent
, & m_printDialogData
);
252 int ret
= dialog
->ShowModal() ;
255 dc
= dialog
->GetPrintDC();
256 m_printDialogData
= dialog
->GetPrintDialogData();
263 bool wxPostScriptPrinter::Setup(wxWindow
*parent
)
265 wxGenericPrintDialog
* dialog
= new wxGenericPrintDialog(parent
, & m_printDialogData
);
266 dialog
->GetPrintDialogData().SetSetupDialog(TRUE
);
268 int ret
= dialog
->ShowModal();
272 m_printDialogData
= dialog
->GetPrintDialogData();
277 return (ret
== wxID_OK
);
280 // ----------------------------------------------------------------------------
282 // ----------------------------------------------------------------------------
284 void wxPostScriptPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
285 wxPrintout
* WXUNUSED(printoutForPrinting
))
287 // Have to call it here since base constructor can't call it
291 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
,
292 wxPrintout
*printoutForPrinting
,
293 wxPrintDialogData
*data
)
294 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
296 Init(printout
, printoutForPrinting
);
299 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
,
300 wxPrintout
*printoutForPrinting
,
302 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
304 Init(printout
, printoutForPrinting
);
307 wxPostScriptPrintPreview::~wxPostScriptPrintPreview()
311 bool wxPostScriptPrintPreview::Print(bool interactive
)
313 if (!m_printPrintout
)
315 wxPostScriptPrinter
printer(& m_printDialogData
);
316 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
319 void wxPostScriptPrintPreview::DetermineScaling()
321 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
322 if (paperType
== wxPAPER_NONE
)
323 paperType
= wxPAPER_NONE
;
325 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
327 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
331 m_previewPrintout
->SetPPIScreen(100, 100);
332 // m_previewPrintout->SetPPIPrinter(100, 100);
333 m_previewPrintout
->SetPPIPrinter(72, 72);
335 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
336 wxSize
sizeTenthsMM(paper
->GetSize());
337 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
339 // If in landscape mode, we need to swap the width and height.
340 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
342 m_pageWidth
= sizeDevUnits
.y
;
343 m_pageHeight
= sizeDevUnits
.x
;
344 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
345 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
349 m_pageWidth
= sizeDevUnits
.x
;
350 m_pageHeight
= sizeDevUnits
.y
;
351 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
352 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
355 // At 100%, the page should look about page-size on the screen.
356 m_previewScale
= (float)0.8;