]>
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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "printps.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
29 #include "wx/msgdlg.h"
33 #include "wx/generic/printps.h"
34 #include "wx/dcprint.h"
35 #include "wx/printdlg.h"
36 #include "wx/generic/prntdlgg.h"
40 #if !USE_SHARED_LIBRARY
41 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptPrinter
, wxPrinterBase
)
42 IMPLEMENT_CLASS(wxPostScriptPrintPreview
, wxPrintPreviewBase
)
49 wxPostScriptPrinter::wxPostScriptPrinter(wxPrintData
*data
):
54 wxPostScriptPrinter::~wxPostScriptPrinter(void)
58 bool wxPostScriptPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
61 sm_abortWindow
= (wxWindow
*) NULL
;
66 printout
->SetIsPreview(FALSE
);
67 printout
->OnPreparePrinting();
69 // Get some parameters from the printout, if defined
72 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
77 m_printData
.SetMinPage(minPage
);
78 m_printData
.SetMaxPage(maxPage
);
80 m_printData
.SetFromPage(fromPage
);
82 m_printData
.SetToPage(toPage
);
86 m_printData
.EnablePageNumbers(TRUE
);
87 if (m_printData
.GetFromPage() < m_printData
.GetMinPage())
88 m_printData
.SetFromPage(m_printData
.GetMinPage());
89 else if (m_printData
.GetFromPage() > m_printData
.GetMaxPage())
90 m_printData
.SetFromPage(m_printData
.GetMaxPage());
91 if (m_printData
.GetToPage() > m_printData
.GetMaxPage())
92 m_printData
.SetToPage(m_printData
.GetMaxPage());
93 else if (m_printData
.GetToPage() < m_printData
.GetMinPage())
94 m_printData
.SetToPage(m_printData
.GetMinPage());
97 m_printData
.EnablePageNumbers(FALSE
);
99 // Create a suitable device context
100 wxDC
*dc
= (wxDC
*) NULL
;
103 wxGenericPrintDialog
dialog(parent
, & m_printData
);
104 if (dialog
.ShowModal() == wxID_OK
)
106 dc
= dialog
.GetPrintDC();
107 m_printData
= dialog
.GetPrintData();
112 dc
= new wxPostScriptDC(wxThePrintSetupData
->GetPrinterFile(), FALSE
, (wxWindow
*) NULL
);
115 // May have pressed cancel.
116 if (!dc
|| !dc
->Ok())
122 int logPPIScreenX
= 0;
123 int logPPIScreenY
= 0;
124 int logPPIPrinterX
= 0;
125 int logPPIPrinterY
= 0;
131 // Correct values for X/PostScript?
132 logPPIPrinterX = 100;
133 logPPIPrinterY = 100;
139 printout
->SetPPIScreen(logPPIScreenX
, logPPIScreenY
);
140 printout
->SetPPIPrinter(logPPIPrinterX
, logPPIPrinterY
);
142 // Set printout parameters
148 printout
->SetPageSizePixels((int)w
, (int)h
);
149 dc
->GetSizeMM(&ww
, &hh
);
150 printout
->SetPageSizeMM((int)ww
, (int)hh
);
152 // Create an abort window
155 printout
->OnBeginPrinting();
157 bool keepGoing
= TRUE
;
160 for (copyCount
= 1; copyCount
<= m_printData
.GetNoCopies(); copyCount
++)
162 if (!printout
->OnBeginDocument(m_printData
.GetFromPage(), m_printData
.GetToPage()))
165 wxMessageBox(_("Could not start printing."), _("Print Error"), wxOK
, parent
);
172 for (pn
= m_printData
.GetFromPage(); keepGoing
&& (pn
<= m_printData
.GetToPage()) && printout
->HasPage(pn
);
183 printout
->OnPrintPage(pn
);
187 printout
->OnEndDocument();
190 printout
->OnEndPrinting();
199 bool wxPostScriptPrinter::PrintDialog(wxWindow
*parent
)
201 wxGenericPrintDialog
dialog(parent
, & m_printData
);
202 return (dialog
.ShowModal() == wxID_OK
);
205 bool wxPostScriptPrinter::Setup(wxWindow
*parent
)
207 wxGenericPrintDialog
dialog(parent
, & m_printData
);
208 dialog
.GetPrintData().SetSetupDialog(TRUE
);
209 return (dialog
.ShowModal() == wxID_OK
);
216 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
, wxPrintData
*data
):
217 wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
219 // Have to call it here since base constructor can't call it
223 wxPostScriptPrintPreview::~wxPostScriptPrintPreview(void)
227 bool wxPostScriptPrintPreview::Print(bool interactive
)
229 if (!m_printPrintout
)
231 wxPostScriptPrinter
printer(&m_printData
);
232 return printer
.Print(m_previewFrame
, m_printPrintout
, interactive
);
235 void wxPostScriptPrintPreview::DetermineScaling(void)
237 const char *paperType
= wxThePrintSetupData
->GetPaperName();
239 paperType
= _("A4 210 x 297 mm");
241 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
243 paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
246 m_previewPrintout
->SetPPIScreen(100, 100);
247 // m_previewPrintout->SetPPIPrinter(100, 100);
248 m_previewPrintout
->SetPPIPrinter(72, 72);
250 // If in landscape mode, we need to swap the width and height.
251 if ( m_printData
.GetOrientation() == wxLANDSCAPE
)
253 m_pageWidth
= paper
->heightPixels
;
254 m_pageHeight
= paper
->widthPixels
;
255 m_previewPrintout
->SetPageSizeMM(paper
->heightMM
, paper
->widthMM
);
256 m_previewPrintout
->SetPageSizePixels(paper
->heightPixels
, paper
->widthPixels
);
260 m_pageWidth
= paper
->widthPixels
;
261 m_pageHeight
= paper
->heightPixels
;
262 m_previewPrintout
->SetPageSizeMM(paper
->widthMM
, paper
->heightMM
);
263 m_previewPrintout
->SetPageSizePixels(paper
->widthPixels
, paper
->heightPixels
);
266 // At 100%, the page should look about page-size on the screen.
267 m_previewScale
= (float)0.8;
268 // m_previewScale = (float)((float)screenWidth/(float)printerWidth);
269 // m_previewScale = previewScale * (float)((float)screenXRes/(float)printerYRes);