]>
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
)
66 printout
->SetIsPreview(FALSE
);
67 printout
->OnPreparePrinting();
69 // Get some parameters from the printout, if defined
72 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
77 printData
.SetMinPage(minPage
);
78 printData
.SetMaxPage(maxPage
);
80 printData
.SetFromPage(fromPage
);
82 printData
.SetToPage(toPage
);
86 printData
.EnablePageNumbers(TRUE
);
87 if (printData
.GetFromPage() < printData
.GetMinPage())
88 printData
.SetFromPage(printData
.GetMinPage());
89 else if (printData
.GetFromPage() > printData
.GetMaxPage())
90 printData
.SetFromPage(printData
.GetMaxPage());
91 if (printData
.GetToPage() > printData
.GetMaxPage())
92 printData
.SetToPage(printData
.GetMaxPage());
93 else if (printData
.GetToPage() < printData
.GetMinPage())
94 printData
.SetToPage(printData
.GetMinPage());
97 printData
.EnablePageNumbers(FALSE
);
99 // Create a suitable device context
103 wxGenericPrintDialog
dialog(parent
, & printData
);
104 if (dialog
.ShowModal() == wxID_OK
)
106 dc
= dialog
.GetPrintDC();
107 printData
= dialog
.GetPrintData();
112 dc
= new wxPostScriptDC(wxThePrintSetupData
->GetPrinterFile(), FALSE
, 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;
127 // Correct values for X/PostScript?
130 logPPIPrinterX
= 100;
131 logPPIPrinterY
= 100;
133 printout
->SetPPIScreen(logPPIScreenX
, logPPIScreenY
);
134 printout
->SetPPIPrinter(logPPIPrinterX
, logPPIPrinterY
);
136 // Set printout parameters
142 printout
->SetPageSizePixels((int)w
, (int)h
);
143 dc
->GetSizeMM(&ww
, &hh
);
144 printout
->SetPageSizeMM((int)ww
, (int)hh
);
146 // Create an abort window
149 printout
->OnBeginPrinting();
151 bool keepGoing
= TRUE
;
154 for (copyCount
= 1; copyCount
<= printData
.GetNoCopies(); copyCount
++)
156 if (!printout
->OnBeginDocument(printData
.GetFromPage(), printData
.GetToPage()))
159 wxMessageBox(_("Could not start printing."), _("Print Error"), wxOK
, parent
);
166 for (pn
= printData
.GetFromPage(); keepGoing
&& (pn
<= printData
.GetToPage()) && printout
->HasPage(pn
);
177 printout
->OnPrintPage(pn
);
181 printout
->OnEndDocument();
184 printout
->OnEndPrinting();
193 bool wxPostScriptPrinter::PrintDialog(wxWindow
*parent
)
195 wxGenericPrintDialog
dialog(parent
, & printData
);
196 return (dialog
.ShowModal() == wxID_OK
);
199 bool wxPostScriptPrinter::Setup(wxWindow
*parent
)
201 wxGenericPrintDialog
dialog(parent
, & printData
);
202 dialog
.GetPrintData().SetSetupDialog(TRUE
);
203 return (dialog
.ShowModal() == wxID_OK
);
210 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
, wxPrintData
*data
):
211 wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
213 // Have to call it here since base constructor can't call it
217 wxPostScriptPrintPreview::~wxPostScriptPrintPreview(void)
221 bool wxPostScriptPrintPreview::Print(bool interactive
)
225 wxPostScriptPrinter
printer(&printData
);
226 return printer
.Print(previewFrame
, printPrintout
, interactive
);
229 void wxPostScriptPrintPreview::DetermineScaling(void)
231 const char *paperType
= wxThePrintSetupData
->GetPaperName();
233 paperType
= _("A4 210 x 297 mm");
235 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
237 paper
= wxThePrintPaperDatabase
->FindPaperType(_("A4 210 x 297 mm"));
240 previewPrintout
->SetPPIScreen(100, 100);
241 previewPrintout
->SetPPIPrinter(100, 100);
243 // If in landscape mode, we need to swap the width and height.
244 if ( printData
.GetOrientation() == wxLANDSCAPE
)
246 pageWidth
= paper
->heightPixels
;
247 pageHeight
= paper
->widthPixels
;
248 previewPrintout
->SetPageSizeMM(paper
->heightMM
, paper
->widthMM
);
249 previewPrintout
->SetPageSizePixels(paper
->heightPixels
, paper
->widthPixels
);
253 pageWidth
= paper
->widthPixels
;
254 pageHeight
= paper
->heightPixels
;
255 previewPrintout
->SetPageSizeMM(paper
->widthMM
, paper
->heightMM
);
256 previewPrintout
->SetPageSizePixels(paper
->widthPixels
, paper
->heightPixels
);
259 // At 100%, the page should look about page-size on the screen.
260 previewScale
= (float)0.8;
261 // previewScale = (float)((float)screenWidth/(float)printerWidth);
262 // previewScale = previewScale * (float)((float)screenXRes/(float)printerYRes);