]>
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
);
88 printout
->OnPreparePrinting();
90 // Get some parameters from the printout, if defined
93 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
98 m_printDialogData
.SetMinPage(minPage
);
99 m_printDialogData
.SetMaxPage(maxPage
);
101 m_printDialogData
.SetFromPage(fromPage
);
103 m_printDialogData
.SetToPage(toPage
);
107 m_printDialogData
.EnablePageNumbers(TRUE
);
108 if (m_printDialogData
.GetFromPage() < m_printDialogData
.GetMinPage())
109 m_printDialogData
.SetFromPage(m_printDialogData
.GetMinPage());
110 else if (m_printDialogData
.GetFromPage() > m_printDialogData
.GetMaxPage())
111 m_printDialogData
.SetFromPage(m_printDialogData
.GetMaxPage());
112 if (m_printDialogData
.GetToPage() > m_printDialogData
.GetMaxPage())
113 m_printDialogData
.SetToPage(m_printDialogData
.GetMaxPage());
114 else if (m_printDialogData
.GetToPage() < m_printDialogData
.GetMinPage())
115 m_printDialogData
.SetToPage(m_printDialogData
.GetMinPage());
118 m_printDialogData
.EnablePageNumbers(FALSE
);
121 // Create a suitable device context
122 wxDC
*dc
= (wxDC
*) NULL
;
125 dc
= PrintDialog(parent
);
131 dc
= new wxPostScriptDC(wxThePrintSetupData
->GetPrinterFile(), FALSE
, (wxWindow
*) NULL
);
134 // May have pressed cancel.
135 if (!dc
|| !dc
->Ok())
141 int logPPIScreenX
= 0;
142 int logPPIScreenY
= 0;
143 int logPPIPrinterX
= 0;
144 int logPPIPrinterY
= 0;
150 // Correct values for X/PostScript?
151 logPPIPrinterX = 100;
152 logPPIPrinterY = 100;
158 printout
->SetPPIScreen(logPPIScreenX
, logPPIScreenY
);
159 printout
->SetPPIPrinter(logPPIPrinterX
, logPPIPrinterY
);
161 // Set printout parameters
166 printout
->SetPageSizePixels((int)w
, (int)h
);
167 dc
->GetSizeMM(&w
, &h
);
168 printout
->SetPageSizeMM((int)w
, (int)h
);
170 // Create an abort window
174 pagesPerCopy
= m_printDialogData
.GetToPage()-m_printDialogData
.GetFromPage()+1,
175 totalPages
= pagesPerCopy
* m_printDialogData
.GetNoCopies(),
177 // Open the progress bar dialog
178 wxProgressDialog
*progressDialog
= new wxProgressDialog (
179 printout
->GetTitle(),
183 wxPD_CAN_ABORT
|wxPD_AUTO_HIDE
|wxPD_APP_MODAL
);
185 printout
->OnBeginPrinting();
187 bool keepGoing
= TRUE
;
190 for (copyCount
= 1; copyCount
<= m_printDialogData
.GetNoCopies(); copyCount
++)
192 if (!printout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
195 wxMessageBox(_("Could not start printing."), _("Print Error"), wxOK
, parent
);
202 for (pn
= m_printDialogData
.GetFromPage(); keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
213 msg
.Printf(_("Printing page %d..."), printedPages
+1);
214 if(progressDialog
->Update(printedPages
++, msg
))
217 printout
->OnPrintPage(pn
);
228 printout
->OnEndDocument();
231 printout
->OnEndPrinting();
232 delete progressDialog
;
241 wxDC
* wxPostScriptPrinter::PrintDialog(wxWindow
*parent
)
243 wxDC
* dc
= (wxDC
*) NULL
;
244 wxGenericPrintDialog
* dialog
= new wxGenericPrintDialog(parent
, & m_printDialogData
);
245 int ret
= dialog
->ShowModal() ;
248 dc
= dialog
->GetPrintDC();
249 m_printDialogData
= dialog
->GetPrintDialogData();
256 bool wxPostScriptPrinter::Setup(wxWindow
*parent
)
258 wxGenericPrintDialog
* dialog
= new wxGenericPrintDialog(parent
, & m_printDialogData
);
259 dialog
->GetPrintDialogData().SetSetupDialog(TRUE
);
261 int ret
= dialog
->ShowModal();
265 m_printDialogData
= dialog
->GetPrintDialogData();
270 return (ret
== wxID_OK
);
273 // ----------------------------------------------------------------------------
275 // ----------------------------------------------------------------------------
277 void wxPostScriptPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
278 wxPrintout
* WXUNUSED(printoutForPrinting
))
280 // Have to call it here since base constructor can't call it
284 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
,
285 wxPrintout
*printoutForPrinting
,
286 wxPrintDialogData
*data
)
287 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
289 Init(printout
, printoutForPrinting
);
292 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
,
293 wxPrintout
*printoutForPrinting
,
295 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
297 Init(printout
, printoutForPrinting
);
300 wxPostScriptPrintPreview::~wxPostScriptPrintPreview()
304 bool wxPostScriptPrintPreview::Print(bool interactive
)
306 if (!m_printPrintout
)
308 wxPostScriptPrinter
printer(& m_printDialogData
);
309 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
312 void wxPostScriptPrintPreview::DetermineScaling()
314 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
315 if (paperType
== wxPAPER_NONE
)
316 paperType
= wxPAPER_NONE
;
318 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
320 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
324 m_previewPrintout
->SetPPIScreen(100, 100);
325 // m_previewPrintout->SetPPIPrinter(100, 100);
326 m_previewPrintout
->SetPPIPrinter(72, 72);
328 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
329 wxSize
sizeTenthsMM(paper
->GetSize());
330 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
332 // If in landscape mode, we need to swap the width and height.
333 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
335 m_pageWidth
= sizeDevUnits
.y
;
336 m_pageHeight
= sizeDevUnits
.x
;
337 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
338 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
342 m_pageWidth
= sizeDevUnits
.x
;
343 m_pageHeight
= sizeDevUnits
.y
;
344 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
345 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
348 // At 100%, the page should look about page-size on the screen.
349 m_previewScale
= (float)0.8;