]>
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"
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 #if !USE_SHARED_LIBRARY
57 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptPrinter
, wxPrinterBase
)
58 IMPLEMENT_CLASS(wxPostScriptPrintPreview
, wxPrintPreviewBase
)
61 // ============================================================================
63 // ============================================================================
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 wxPostScriptPrinter::wxPostScriptPrinter(wxPrintDialogData
*data
)
74 wxPostScriptPrinter::~wxPostScriptPrinter()
78 bool wxPostScriptPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
81 sm_abortWindow
= (wxWindow
*) NULL
;
86 printout
->SetIsPreview(FALSE
);
87 printout
->OnPreparePrinting();
89 // Get some parameters from the printout, if defined
92 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
97 m_printDialogData
.SetMinPage(minPage
);
98 m_printDialogData
.SetMaxPage(maxPage
);
100 m_printDialogData
.SetFromPage(fromPage
);
102 m_printDialogData
.SetToPage(toPage
);
106 m_printDialogData
.EnablePageNumbers(TRUE
);
107 if (m_printDialogData
.GetFromPage() < m_printDialogData
.GetMinPage())
108 m_printDialogData
.SetFromPage(m_printDialogData
.GetMinPage());
109 else if (m_printDialogData
.GetFromPage() > m_printDialogData
.GetMaxPage())
110 m_printDialogData
.SetFromPage(m_printDialogData
.GetMaxPage());
111 if (m_printDialogData
.GetToPage() > m_printDialogData
.GetMaxPage())
112 m_printDialogData
.SetToPage(m_printDialogData
.GetMaxPage());
113 else if (m_printDialogData
.GetToPage() < m_printDialogData
.GetMinPage())
114 m_printDialogData
.SetToPage(m_printDialogData
.GetMinPage());
117 m_printDialogData
.EnablePageNumbers(FALSE
);
120 // Create a suitable device context
121 wxDC
*dc
= (wxDC
*) NULL
;
124 dc
= PrintDialog(parent
);
130 dc
= new wxPostScriptDC(wxThePrintSetupData
->GetPrinterFile(), FALSE
, (wxWindow
*) NULL
);
133 // May have pressed cancel.
134 if (!dc
|| !dc
->Ok())
140 int logPPIScreenX
= 0;
141 int logPPIScreenY
= 0;
142 int logPPIPrinterX
= 0;
143 int logPPIPrinterY
= 0;
149 // Correct values for X/PostScript?
150 logPPIPrinterX = 100;
151 logPPIPrinterY = 100;
157 printout
->SetPPIScreen(logPPIScreenX
, logPPIScreenY
);
158 printout
->SetPPIPrinter(logPPIPrinterX
, logPPIPrinterY
);
160 // Set printout parameters
165 printout
->SetPageSizePixels((int)w
, (int)h
);
166 dc
->GetSizeMM(&w
, &h
);
167 printout
->SetPageSizeMM((int)w
, (int)h
);
169 // Create an abort window
173 pagesPerCopy
= m_printDialogData
.GetToPage()-m_printDialogData
.GetFromPage()+1,
174 totalPages
= pagesPerCopy
* m_printDialogData
.GetNoCopies(),
176 // Open the progress bar dialog
177 wxProgressDialog
*progressDialog
= new wxProgressDialog (
178 printout
->GetTitle(),
182 wxPD_CAN_ABORT
|wxPD_AUTO_HIDE
|wxPD_APP_MODAL
);
184 printout
->OnBeginPrinting();
186 bool keepGoing
= TRUE
;
189 for (copyCount
= 1; copyCount
<= m_printDialogData
.GetNoCopies(); copyCount
++)
191 if (!printout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
194 wxMessageBox(_("Could not start printing."), _("Print Error"), wxOK
, parent
);
201 for (pn
= m_printDialogData
.GetFromPage(); keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
212 msg
.Printf(_("Printing page %d..."), printedPages
+1);
213 if(progressDialog
->Update(printedPages
++, msg
))
216 printout
->OnPrintPage(pn
);
227 printout
->OnEndDocument();
230 printout
->OnEndPrinting();
231 delete progressDialog
;
240 wxDC
* wxPostScriptPrinter::PrintDialog(wxWindow
*parent
)
242 wxDC
* dc
= (wxDC
*) NULL
;
243 wxGenericPrintDialog
* dialog
= new wxGenericPrintDialog(parent
, & m_printDialogData
);
244 int ret
= dialog
->ShowModal() ;
247 dc
= dialog
->GetPrintDC();
248 m_printDialogData
= dialog
->GetPrintDialogData();
255 bool wxPostScriptPrinter::Setup(wxWindow
*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
);
272 // ----------------------------------------------------------------------------
274 // ----------------------------------------------------------------------------
276 void wxPostScriptPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
277 wxPrintout
* WXUNUSED(printoutForPrinting
))
279 // Have to call it here since base constructor can't call it
283 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
,
284 wxPrintout
*printoutForPrinting
,
285 wxPrintDialogData
*data
)
286 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
288 Init(printout
, printoutForPrinting
);
291 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
,
292 wxPrintout
*printoutForPrinting
,
294 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
296 Init(printout
, printoutForPrinting
);
299 wxPostScriptPrintPreview::~wxPostScriptPrintPreview()
303 bool wxPostScriptPrintPreview::Print(bool interactive
)
305 if (!m_printPrintout
)
307 wxPostScriptPrinter
printer(& m_printDialogData
);
308 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
311 void wxPostScriptPrintPreview::DetermineScaling()
313 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
314 if (paperType
== wxPAPER_NONE
)
315 paperType
= wxPAPER_NONE
;
317 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
319 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
323 m_previewPrintout
->SetPPIScreen(100, 100);
324 // m_previewPrintout->SetPPIPrinter(100, 100);
325 m_previewPrintout
->SetPPIPrinter(72, 72);
327 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
328 wxSize
sizeTenthsMM(paper
->GetSize());
329 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
331 // If in landscape mode, we need to swap the width and height.
332 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
334 m_pageWidth
= sizeDevUnits
.y
;
335 m_pageHeight
= sizeDevUnits
.x
;
336 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
337 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
341 m_pageWidth
= sizeDevUnits
.x
;
342 m_pageHeight
= sizeDevUnits
.y
;
343 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
344 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
347 // At 100%, the page should look about page-size on the screen.
348 m_previewScale
= (float)0.8;