]>
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
;
85 printout
->SetIsPreview(FALSE
);
87 // 4/9/99, JACS: this is a silly place to allow preparation, considering
88 // the DC and no parameters have been set in the printout object.
89 // Moved further down.
91 // printout->OnPreparePrinting();
93 // Get some parameters from the printout, if defined
96 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
101 m_printDialogData
.SetMinPage(minPage
);
102 m_printDialogData
.SetMaxPage(maxPage
);
104 m_printDialogData
.SetFromPage(fromPage
);
106 m_printDialogData
.SetToPage(toPage
);
110 m_printDialogData
.EnablePageNumbers(TRUE
);
111 if (m_printDialogData
.GetFromPage() < m_printDialogData
.GetMinPage())
112 m_printDialogData
.SetFromPage(m_printDialogData
.GetMinPage());
113 else if (m_printDialogData
.GetFromPage() > m_printDialogData
.GetMaxPage())
114 m_printDialogData
.SetFromPage(m_printDialogData
.GetMaxPage());
115 if (m_printDialogData
.GetToPage() > m_printDialogData
.GetMaxPage())
116 m_printDialogData
.SetToPage(m_printDialogData
.GetMaxPage());
117 else if (m_printDialogData
.GetToPage() < m_printDialogData
.GetMinPage())
118 m_printDialogData
.SetToPage(m_printDialogData
.GetMinPage());
121 m_printDialogData
.EnablePageNumbers(FALSE
);
124 // Create a suitable device context
125 wxDC
*dc
= (wxDC
*) NULL
;
128 dc
= PrintDialog(parent
);
134 dc
= new wxPostScriptDC(wxThePrintSetupData
->GetPrinterFile(), FALSE
, (wxWindow
*) NULL
);
137 // May have pressed cancel.
138 if (!dc
|| !dc
->Ok())
144 int logPPIScreenX
= 0;
145 int logPPIScreenY
= 0;
146 int logPPIPrinterX
= 0;
147 int logPPIPrinterY
= 0;
153 // Correct values for X/PostScript?
154 logPPIPrinterX = 100;
155 logPPIPrinterY = 100;
161 printout
->SetPPIScreen(logPPIScreenX
, logPPIScreenY
);
162 printout
->SetPPIPrinter(logPPIPrinterX
, logPPIPrinterY
);
164 // Set printout parameters
169 printout
->SetPageSizePixels((int)w
, (int)h
);
170 dc
->GetSizeMM(&w
, &h
);
171 printout
->SetPageSizeMM((int)w
, (int)h
);
173 // Create an abort window
176 printout
->OnPreparePrinting();
179 pagesPerCopy
= m_printDialogData
.GetToPage()-m_printDialogData
.GetFromPage()+1,
180 totalPages
= pagesPerCopy
* m_printDialogData
.GetNoCopies(),
182 // Open the progress bar dialog
183 wxProgressDialog
*progressDialog
= new wxProgressDialog (
184 printout
->GetTitle(),
188 wxPD_CAN_ABORT
|wxPD_AUTO_HIDE
|wxPD_APP_MODAL
);
190 printout
->OnBeginPrinting();
192 bool keepGoing
= TRUE
;
195 for (copyCount
= 1; copyCount
<= m_printDialogData
.GetNoCopies(); copyCount
++)
197 if (!printout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
200 wxMessageBox(_("Could not start printing."), _("Print Error"), wxOK
, parent
);
207 for (pn
= m_printDialogData
.GetFromPage(); keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
218 msg
.Printf(_("Printing page %d..."), printedPages
+1);
219 if(progressDialog
->Update(printedPages
++, msg
))
222 printout
->OnPrintPage(pn
);
233 printout
->OnEndDocument();
236 printout
->OnEndPrinting();
237 delete progressDialog
;
246 wxDC
* wxPostScriptPrinter::PrintDialog(wxWindow
*parent
)
248 wxDC
* dc
= (wxDC
*) NULL
;
249 wxGenericPrintDialog
* dialog
= new wxGenericPrintDialog(parent
, & m_printDialogData
);
250 int ret
= dialog
->ShowModal() ;
253 dc
= dialog
->GetPrintDC();
254 m_printDialogData
= dialog
->GetPrintDialogData();
261 bool wxPostScriptPrinter::Setup(wxWindow
*parent
)
263 wxGenericPrintDialog
* dialog
= new wxGenericPrintDialog(parent
, & m_printDialogData
);
264 dialog
->GetPrintDialogData().SetSetupDialog(TRUE
);
266 int ret
= dialog
->ShowModal();
270 m_printDialogData
= dialog
->GetPrintDialogData();
275 return (ret
== wxID_OK
);
278 // ----------------------------------------------------------------------------
280 // ----------------------------------------------------------------------------
282 void wxPostScriptPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
283 wxPrintout
* WXUNUSED(printoutForPrinting
))
285 // Have to call it here since base constructor can't call it
289 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
,
290 wxPrintout
*printoutForPrinting
,
291 wxPrintDialogData
*data
)
292 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
294 Init(printout
, printoutForPrinting
);
297 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
,
298 wxPrintout
*printoutForPrinting
,
300 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
302 Init(printout
, printoutForPrinting
);
305 wxPostScriptPrintPreview::~wxPostScriptPrintPreview()
309 bool wxPostScriptPrintPreview::Print(bool interactive
)
311 if (!m_printPrintout
)
313 wxPostScriptPrinter
printer(& m_printDialogData
);
314 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
317 void wxPostScriptPrintPreview::DetermineScaling()
319 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
320 if (paperType
== wxPAPER_NONE
)
321 paperType
= wxPAPER_NONE
;
323 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
325 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
329 m_previewPrintout
->SetPPIScreen(100, 100);
330 // m_previewPrintout->SetPPIPrinter(100, 100);
331 m_previewPrintout
->SetPPIPrinter(72, 72);
333 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
334 wxSize
sizeTenthsMM(paper
->GetSize());
335 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
337 // If in landscape mode, we need to swap the width and height.
338 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
340 m_pageWidth
= sizeDevUnits
.y
;
341 m_pageHeight
= sizeDevUnits
.x
;
342 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
343 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
347 m_pageWidth
= sizeDevUnits
.x
;
348 m_pageHeight
= sizeDevUnits
.y
;
349 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
350 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
353 // At 100%, the page should look about page-size on the screen.
354 m_previewScale
= (float)0.8;