]>
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"
37 #include "wx/msgdlg.h"
41 #include "wx/generic/printps.h"
42 #include "wx/dcprint.h"
43 #include "wx/printdlg.h"
44 #include "wx/generic/prntdlgg.h"
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 #if !USE_SHARED_LIBRARY
54 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptPrinter
, wxPrinterBase
)
55 IMPLEMENT_CLASS(wxPostScriptPrintPreview
, wxPrintPreviewBase
)
58 // ============================================================================
60 // ============================================================================
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 wxPostScriptPrinter::wxPostScriptPrinter(wxPrintDialogData
*data
)
71 wxPostScriptPrinter::~wxPostScriptPrinter()
75 bool wxPostScriptPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
78 sm_abortWindow
= (wxWindow
*) NULL
;
83 printout
->SetIsPreview(FALSE
);
84 printout
->OnPreparePrinting();
86 // Get some parameters from the printout, if defined
89 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
94 m_printDialogData
.SetMinPage(minPage
);
95 m_printDialogData
.SetMaxPage(maxPage
);
97 m_printDialogData
.SetFromPage(fromPage
);
99 m_printDialogData
.SetToPage(toPage
);
103 m_printDialogData
.EnablePageNumbers(TRUE
);
104 if (m_printDialogData
.GetFromPage() < m_printDialogData
.GetMinPage())
105 m_printDialogData
.SetFromPage(m_printDialogData
.GetMinPage());
106 else if (m_printDialogData
.GetFromPage() > m_printDialogData
.GetMaxPage())
107 m_printDialogData
.SetFromPage(m_printDialogData
.GetMaxPage());
108 if (m_printDialogData
.GetToPage() > m_printDialogData
.GetMaxPage())
109 m_printDialogData
.SetToPage(m_printDialogData
.GetMaxPage());
110 else if (m_printDialogData
.GetToPage() < m_printDialogData
.GetMinPage())
111 m_printDialogData
.SetToPage(m_printDialogData
.GetMinPage());
114 m_printDialogData
.EnablePageNumbers(FALSE
);
116 // Create a suitable device context
117 wxDC
*dc
= (wxDC
*) NULL
;
120 dc
= PrintDialog(parent
);
126 dc
= new wxPostScriptDC(wxThePrintSetupData
->GetPrinterFile(), FALSE
, (wxWindow
*) NULL
);
129 // May have pressed cancel.
130 if (!dc
|| !dc
->Ok())
136 int logPPIScreenX
= 0;
137 int logPPIScreenY
= 0;
138 int logPPIPrinterX
= 0;
139 int logPPIPrinterY
= 0;
145 // Correct values for X/PostScript?
146 logPPIPrinterX = 100;
147 logPPIPrinterY = 100;
153 printout
->SetPPIScreen(logPPIScreenX
, logPPIScreenY
);
154 printout
->SetPPIPrinter(logPPIPrinterX
, logPPIPrinterY
);
156 // Set printout parameters
161 printout
->SetPageSizePixels((int)w
, (int)h
);
162 dc
->GetSizeMM(&w
, &h
);
163 printout
->SetPageSizeMM((int)w
, (int)h
);
165 // Create an abort window
168 printout
->OnBeginPrinting();
170 bool keepGoing
= TRUE
;
173 for (copyCount
= 1; copyCount
<= m_printDialogData
.GetNoCopies(); copyCount
++)
175 if (!printout
->OnBeginDocument(m_printDialogData
.GetFromPage(), m_printDialogData
.GetToPage()))
178 wxMessageBox(_("Could not start printing."), _("Print Error"), wxOK
, parent
);
185 for (pn
= m_printDialogData
.GetFromPage(); keepGoing
&& (pn
<= m_printDialogData
.GetToPage()) && printout
->HasPage(pn
);
196 printout
->OnPrintPage(pn
);
200 printout
->OnEndDocument();
203 printout
->OnEndPrinting();
212 wxDC
* wxPostScriptPrinter::PrintDialog(wxWindow
*parent
)
214 wxDC
* dc
= (wxDC
*) NULL
;
215 wxGenericPrintDialog
* dialog
= new wxGenericPrintDialog(parent
, & m_printDialogData
);
216 int ret
= dialog
->ShowModal() ;
219 dc
= dialog
->GetPrintDC();
220 m_printDialogData
= dialog
->GetPrintDialogData();
227 bool wxPostScriptPrinter::Setup(wxWindow
*parent
)
229 wxGenericPrintDialog
* dialog
= new wxGenericPrintDialog(parent
, & m_printDialogData
);
230 dialog
->GetPrintDialogData().SetSetupDialog(TRUE
);
232 int ret
= dialog
->ShowModal();
236 m_printDialogData
= dialog
->GetPrintDialogData();
241 return (ret
== wxID_OK
);
244 // ----------------------------------------------------------------------------
246 // ----------------------------------------------------------------------------
248 void wxPostScriptPrintPreview::Init(wxPrintout
* WXUNUSED(printout
),
249 wxPrintout
* WXUNUSED(printoutForPrinting
))
251 // Have to call it here since base constructor can't call it
255 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
,
256 wxPrintout
*printoutForPrinting
,
257 wxPrintDialogData
*data
)
258 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
260 Init(printout
, printoutForPrinting
);
263 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
,
264 wxPrintout
*printoutForPrinting
,
266 : wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
268 Init(printout
, printoutForPrinting
);
271 wxPostScriptPrintPreview::~wxPostScriptPrintPreview()
275 bool wxPostScriptPrintPreview::Print(bool interactive
)
277 if (!m_printPrintout
)
279 wxPostScriptPrinter
printer(& m_printDialogData
);
280 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
283 void wxPostScriptPrintPreview::DetermineScaling()
285 wxPaperSize paperType
= m_printDialogData
.GetPrintData().GetPaperId();
286 if (paperType
== wxPAPER_NONE
)
287 paperType
= wxPAPER_NONE
;
289 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
291 paper
= wxThePrintPaperDatabase
->FindPaperType(wxPAPER_A4
);
295 m_previewPrintout
->SetPPIScreen(100, 100);
296 // m_previewPrintout->SetPPIPrinter(100, 100);
297 m_previewPrintout
->SetPPIPrinter(72, 72);
299 wxSize
sizeDevUnits(paper
->GetSizeDeviceUnits());
300 wxSize
sizeTenthsMM(paper
->GetSize());
301 wxSize
sizeMM(sizeTenthsMM
.x
/ 10, sizeTenthsMM
.y
/ 10);
303 // If in landscape mode, we need to swap the width and height.
304 if ( m_printDialogData
.GetPrintData().GetOrientation() == wxLANDSCAPE
)
306 m_pageWidth
= sizeDevUnits
.y
;
307 m_pageHeight
= sizeDevUnits
.x
;
308 m_previewPrintout
->SetPageSizeMM(sizeMM
.y
, sizeMM
.x
);
309 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
313 m_pageWidth
= sizeDevUnits
.x
;
314 m_pageHeight
= sizeDevUnits
.y
;
315 m_previewPrintout
->SetPageSizeMM(sizeMM
.x
, sizeMM
.y
);
316 m_previewPrintout
->SetPageSizePixels(m_pageWidth
, m_pageHeight
);
319 // At 100%, the page should look about page-size on the screen.
320 m_previewScale
= (float)0.8;