]> git.saurik.com Git - wxWidgets.git/blame - src/generic/printps.cpp
latest CW additions
[wxWidgets.git] / src / generic / printps.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: printps.cpp
3// Purpose: Postscript print/preview framework
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "printps.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#include "wx/defs.h"
24
25#ifndef WX_PRECOMP
26#include "wx/utils.h"
27#include "wx/dc.h"
28#include "wx/app.h"
29#include "wx/msgdlg.h"
1a5a8367 30#include <wx/intl.h>
c801d85f
KB
31#endif
32
33#include "wx/generic/printps.h"
34#include "wx/dcprint.h"
35#include "wx/printdlg.h"
36#include "wx/generic/prntdlgg.h"
37
38#include <stdlib.h>
39
40#if !USE_SHARED_LIBRARY
41IMPLEMENT_DYNAMIC_CLASS(wxPostScriptPrinter, wxPrinterBase)
42IMPLEMENT_CLASS(wxPostScriptPrintPreview, wxPrintPreviewBase)
43#endif
44
45/*
46 * Printer
47 */
48
49wxPostScriptPrinter::wxPostScriptPrinter(wxPrintData *data):
50 wxPrinterBase(data)
51{
52}
53
54wxPostScriptPrinter::~wxPostScriptPrinter(void)
55{
56}
57
58bool wxPostScriptPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
59{
34da0970
JS
60 sm_abortIt = FALSE;
61 sm_abortWindow = (wxWindow *) NULL;
c801d85f
KB
62
63 if (!printout)
64 return FALSE;
65
66 printout->SetIsPreview(FALSE);
67 printout->OnPreparePrinting();
68
69 // Get some parameters from the printout, if defined
70 int fromPage, toPage;
71 int minPage, maxPage;
72 printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage);
73
74 if (maxPage == 0)
75 return FALSE;
76
34da0970
JS
77 m_printData.SetMinPage(minPage);
78 m_printData.SetMaxPage(maxPage);
c801d85f 79 if (fromPage != 0)
34da0970 80 m_printData.SetFromPage(fromPage);
c801d85f 81 if (toPage != 0)
34da0970 82 m_printData.SetToPage(toPage);
c801d85f
KB
83
84 if (minPage != 0)
85 {
34da0970
JS
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());
c801d85f
KB
95 }
96 else
34da0970
JS
97 m_printData.EnablePageNumbers(FALSE);
98
c801d85f 99 // Create a suitable device context
c67daf87 100 wxDC *dc = (wxDC *) NULL;
c801d85f
KB
101 if (prompt)
102 {
34da0970 103 wxGenericPrintDialog dialog(parent, & m_printData);
c801d85f
KB
104 if (dialog.ShowModal() == wxID_OK)
105 {
106 dc = dialog.GetPrintDC();
34da0970 107 m_printData = dialog.GetPrintData();
c801d85f
KB
108 }
109 }
110 else
111 {
c67daf87 112 dc = new wxPostScriptDC(wxThePrintSetupData->GetPrinterFile(), FALSE, (wxWindow *) NULL);
c801d85f
KB
113 }
114
115 // May have pressed cancel.
116 if (!dc || !dc->Ok())
117 {
118 if (dc) delete dc;
119 return FALSE;
120 }
121
122 int logPPIScreenX = 0;
123 int logPPIScreenY = 0;
124 int logPPIPrinterX = 0;
125 int logPPIPrinterY = 0;
126
c801d85f
KB
127 logPPIScreenX = 100;
128 logPPIScreenY = 100;
ed880dd4
RR
129
130/*
131 // Correct values for X/PostScript?
c801d85f
KB
132 logPPIPrinterX = 100;
133 logPPIPrinterY = 100;
ed880dd4
RR
134*/
135
136 logPPIPrinterX = 72;
137 logPPIPrinterY = 72;
c801d85f
KB
138
139 printout->SetPPIScreen(logPPIScreenX, logPPIScreenY);
140 printout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY);
141
142 // Set printout parameters
143 printout->SetDC(dc);
144
145 int w, h;
146 long ww, hh;
147 dc->GetSize(&w, &h);
148 printout->SetPageSizePixels((int)w, (int)h);
149 dc->GetSizeMM(&ww, &hh);
150 printout->SetPageSizeMM((int)ww, (int)hh);
151
152 // Create an abort window
153 wxBeginBusyCursor();
154
155 printout->OnBeginPrinting();
156
157 bool keepGoing = TRUE;
158
159 int copyCount;
34da0970 160 for (copyCount = 1; copyCount <= m_printData.GetNoCopies(); copyCount ++)
c801d85f 161 {
34da0970 162 if (!printout->OnBeginDocument(m_printData.GetFromPage(), m_printData.GetToPage()))
c801d85f
KB
163 {
164 wxEndBusyCursor();
1a5a8367 165 wxMessageBox(_("Could not start printing."), _("Print Error"), wxOK, parent);
c801d85f
KB
166 break;
167 }
34da0970 168 if (sm_abortIt)
c801d85f
KB
169 break;
170
171 int pn;
34da0970 172 for (pn = m_printData.GetFromPage(); keepGoing && (pn <= m_printData.GetToPage()) && printout->HasPage(pn);
c801d85f
KB
173 pn++)
174 {
34da0970 175 if (sm_abortIt)
c801d85f
KB
176 {
177 keepGoing = FALSE;
178 break;
179 }
180 else
181 {
182 dc->StartPage();
183 printout->OnPrintPage(pn);
184 dc->EndPage();
185 }
186 }
187 printout->OnEndDocument();
188 }
189
190 printout->OnEndPrinting();
191
192 wxEndBusyCursor();
193
194 delete dc;
195
196 return TRUE;
197}
198
199bool wxPostScriptPrinter::PrintDialog(wxWindow *parent)
200{
34da0970 201 wxGenericPrintDialog dialog(parent, & m_printData);
c801d85f
KB
202 return (dialog.ShowModal() == wxID_OK);
203}
204
205bool wxPostScriptPrinter::Setup(wxWindow *parent)
206{
34da0970 207 wxGenericPrintDialog dialog(parent, & m_printData);
c801d85f
KB
208 dialog.GetPrintData().SetSetupDialog(TRUE);
209 return (dialog.ShowModal() == wxID_OK);
210}
211
212/*
213 * Print preview
214 */
215
216wxPostScriptPrintPreview::wxPostScriptPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data):
217 wxPrintPreviewBase(printout, printoutForPrinting, data)
218{
219 // Have to call it here since base constructor can't call it
220 DetermineScaling();
221}
222
223wxPostScriptPrintPreview::~wxPostScriptPrintPreview(void)
224{
225}
226
227bool wxPostScriptPrintPreview::Print(bool interactive)
228{
34da0970 229 if (!m_printPrintout)
c801d85f 230 return FALSE;
34da0970
JS
231 wxPostScriptPrinter printer(&m_printData);
232 return printer.Print(m_previewFrame, m_printPrintout, interactive);
c801d85f
KB
233}
234
235void wxPostScriptPrintPreview::DetermineScaling(void)
236{
36af0bc4 237 const char *paperType = wxThePrintSetupData->GetPaperName();
c801d85f 238 if (!paperType)
1a5a8367 239 paperType = _("A4 210 x 297 mm");
c801d85f
KB
240
241 wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType);
242 if (!paper)
1a5a8367 243 paper = wxThePrintPaperDatabase->FindPaperType(_("A4 210 x 297 mm"));
c801d85f
KB
244 if (paper)
245 {
34da0970 246 m_previewPrintout->SetPPIScreen(100, 100);
ed880dd4
RR
247// m_previewPrintout->SetPPIPrinter(100, 100);
248 m_previewPrintout->SetPPIPrinter(72, 72);
c801d85f
KB
249
250 // If in landscape mode, we need to swap the width and height.
34da0970 251 if ( m_printData.GetOrientation() == wxLANDSCAPE )
c801d85f 252 {
34da0970
JS
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);
c801d85f
KB
257 }
258 else
259 {
34da0970
JS
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);
c801d85f
KB
264 }
265
266 // At 100%, the page should look about page-size on the screen.
34da0970
JS
267 m_previewScale = (float)0.8;
268// m_previewScale = (float)((float)screenWidth/(float)printerWidth);
269// m_previewScale = previewScale * (float)((float)screenXRes/(float)printerYRes);
c801d85f
KB
270 }
271}
272