]>
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"
32 #include "wx/generic/printps.h"
33 #include "wx/dcprint.h"
34 #include "wx/printdlg.h"
35 #include "wx/generic/prntdlgg.h"
39 #if !USE_SHARED_LIBRARY
40 IMPLEMENT_DYNAMIC_CLASS(wxPostScriptPrinter
, wxPrinterBase
)
41 IMPLEMENT_CLASS(wxPostScriptPrintPreview
, wxPrintPreviewBase
)
48 wxPostScriptPrinter::wxPostScriptPrinter(wxPrintData
*data
):
53 wxPostScriptPrinter::~wxPostScriptPrinter(void)
57 bool wxPostScriptPrinter::Print(wxWindow
*parent
, wxPrintout
*printout
, bool prompt
)
65 printout
->SetIsPreview(FALSE
);
66 printout
->OnPreparePrinting();
68 // Get some parameters from the printout, if defined
71 printout
->GetPageInfo(&minPage
, &maxPage
, &fromPage
, &toPage
);
76 printData
.SetMinPage(minPage
);
77 printData
.SetMaxPage(maxPage
);
79 printData
.SetFromPage(fromPage
);
81 printData
.SetToPage(toPage
);
85 printData
.EnablePageNumbers(TRUE
);
86 if (printData
.GetFromPage() < printData
.GetMinPage())
87 printData
.SetFromPage(printData
.GetMinPage());
88 else if (printData
.GetFromPage() > printData
.GetMaxPage())
89 printData
.SetFromPage(printData
.GetMaxPage());
90 if (printData
.GetToPage() > printData
.GetMaxPage())
91 printData
.SetToPage(printData
.GetMaxPage());
92 else if (printData
.GetToPage() < printData
.GetMinPage())
93 printData
.SetToPage(printData
.GetMinPage());
96 printData
.EnablePageNumbers(FALSE
);
98 // Create a suitable device context
102 wxGenericPrintDialog
dialog(parent
, & printData
);
103 if (dialog
.ShowModal() == wxID_OK
)
105 dc
= dialog
.GetPrintDC();
106 printData
= dialog
.GetPrintData();
111 dc
= new wxPostScriptDC(wxThePrintSetupData
->GetPrinterFile(), FALSE
, NULL
);
114 // May have pressed cancel.
115 if (!dc
|| !dc
->Ok())
121 int logPPIScreenX
= 0;
122 int logPPIScreenY
= 0;
123 int logPPIPrinterX
= 0;
124 int logPPIPrinterY
= 0;
126 // Correct values for X/PostScript?
129 logPPIPrinterX
= 100;
130 logPPIPrinterY
= 100;
132 printout
->SetPPIScreen(logPPIScreenX
, logPPIScreenY
);
133 printout
->SetPPIPrinter(logPPIPrinterX
, logPPIPrinterY
);
135 // Set printout parameters
141 printout
->SetPageSizePixels((int)w
, (int)h
);
142 dc
->GetSizeMM(&ww
, &hh
);
143 printout
->SetPageSizeMM((int)ww
, (int)hh
);
145 // Create an abort window
148 printout
->OnBeginPrinting();
150 bool keepGoing
= TRUE
;
153 for (copyCount
= 1; copyCount
<= printData
.GetNoCopies(); copyCount
++)
155 if (!printout
->OnBeginDocument(printData
.GetFromPage(), printData
.GetToPage()))
158 wxMessageBox("Could not start printing.", "Print Error", wxOK
, parent
);
165 for (pn
= printData
.GetFromPage(); keepGoing
&& (pn
<= printData
.GetToPage()) && printout
->HasPage(pn
);
176 printout
->OnPrintPage(pn
);
180 printout
->OnEndDocument();
183 printout
->OnEndPrinting();
192 bool wxPostScriptPrinter::PrintDialog(wxWindow
*parent
)
194 wxGenericPrintDialog
dialog(parent
, & printData
);
195 return (dialog
.ShowModal() == wxID_OK
);
198 bool wxPostScriptPrinter::Setup(wxWindow
*parent
)
200 wxGenericPrintDialog
dialog(parent
, & printData
);
201 dialog
.GetPrintData().SetSetupDialog(TRUE
);
202 return (dialog
.ShowModal() == wxID_OK
);
209 wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout
*printout
, wxPrintout
*printoutForPrinting
, wxPrintData
*data
):
210 wxPrintPreviewBase(printout
, printoutForPrinting
, data
)
212 // Have to call it here since base constructor can't call it
216 wxPostScriptPrintPreview::~wxPostScriptPrintPreview(void)
220 bool wxPostScriptPrintPreview::Print(bool interactive
)
224 wxPostScriptPrinter
printer(&printData
);
225 return printer
.Print(previewFrame
, printPrintout
, interactive
);
228 void wxPostScriptPrintPreview::DetermineScaling(void)
230 char *paperType
= wxThePrintSetupData
->GetPaperName();
232 paperType
= "A4 210 x 297 mm";
234 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->FindPaperType(paperType
);
236 paper
= wxThePrintPaperDatabase
->FindPaperType("A4 210 x 297 mm");
239 previewPrintout
->SetPPIScreen(100, 100);
240 previewPrintout
->SetPPIPrinter(100, 100);
242 // If in landscape mode, we need to swap the width and height.
243 if ( printData
.GetOrientation() == wxLANDSCAPE
)
245 pageWidth
= paper
->heightPixels
;
246 pageHeight
= paper
->widthPixels
;
247 previewPrintout
->SetPageSizeMM(paper
->heightMM
, paper
->widthMM
);
248 previewPrintout
->SetPageSizePixels(paper
->heightPixels
, paper
->widthPixels
);
252 pageWidth
= paper
->widthPixels
;
253 pageHeight
= paper
->heightPixels
;
254 previewPrintout
->SetPageSizeMM(paper
->widthMM
, paper
->heightMM
);
255 previewPrintout
->SetPageSizePixels(paper
->widthPixels
, paper
->heightPixels
);
258 // At 100%, the page should look about page-size on the screen.
259 previewScale
= (float)0.8;
260 // previewScale = (float)((float)screenWidth/(float)printerWidth);
261 // previewScale = previewScale * (float)((float)screenXRes/(float)printerYRes);