]> git.saurik.com Git - wxWidgets.git/blame - src/mac/printmac.cpp
Code clanup: removed some useless/unused member
[wxWidgets.git] / src / mac / printmac.cpp
CommitLineData
72e7876b
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: printwin.cpp
3// Purpose: wxMacPrinter framework
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6aa89a22
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
72e7876b
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "printwin.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"
30#endif
31
76a5e5d2
SC
32#include "wx/mac/private.h"
33
72e7876b
SC
34#include "wx/mac/printmac.h"
35#include "wx/dcprint.h"
36#include "wx/printdlg.h"
37
38#include <stdlib.h>
39
2f1ae414 40#if !USE_SHARED_LIBRARY
72e7876b
SC
41IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter, wxPrinterBase)
42IMPLEMENT_CLASS(wxMacPrintPreview, wxPrintPreviewBase)
2f1ae414 43#endif
72e7876b
SC
44
45/*
e40298d5
JS
46* Printer
47*/
48
72e7876b 49wxMacPrinter::wxMacPrinter(wxPrintDialogData *data):
e40298d5 50wxPrinterBase(data)
72e7876b
SC
51{
52}
53
54wxMacPrinter::~wxMacPrinter(void)
55{
56}
57
58bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
59{
e40298d5
JS
60 sm_abortIt = FALSE;
61 sm_abortWindow = NULL;
72e7876b 62
e40298d5
JS
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
77 m_printDialogData.SetMinPage(minPage);
78 m_printDialogData.SetMaxPage(maxPage);
79 if (fromPage != 0)
80 m_printDialogData.SetFromPage(fromPage);
81 if (toPage != 0)
82 m_printDialogData.SetToPage(toPage);
83
84 if (minPage != 0)
85 {
86 m_printDialogData.EnablePageNumbers(TRUE);
87 if (m_printDialogData.GetFromPage() < m_printDialogData.GetMinPage())
88 m_printDialogData.SetFromPage(m_printDialogData.GetMinPage());
89 else if (m_printDialogData.GetFromPage() > m_printDialogData.GetMaxPage())
90 m_printDialogData.SetFromPage(m_printDialogData.GetMaxPage());
91 if (m_printDialogData.GetToPage() > m_printDialogData.GetMaxPage())
92 m_printDialogData.SetToPage(m_printDialogData.GetMaxPage());
93 else if (m_printDialogData.GetToPage() < m_printDialogData.GetMinPage())
94 m_printDialogData.SetToPage(m_printDialogData.GetMinPage());
95 }
96 else
97 m_printDialogData.EnablePageNumbers(FALSE);
98
99 // Create a suitable device context
100 wxDC *dc = NULL;
101 if (prompt)
102 {
2f1ae414
SC
103 wxPrintDialog dialog(parent, & m_printDialogData);
104 if (dialog.ShowModal() == wxID_OK)
e40298d5
JS
105 {
106 dc = dialog.GetPrintDC();
107 m_printDialogData = dialog.GetPrintData();
108 }
109 }
110 else
72e7876b 111 {
e40298d5 112 dc = new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
72e7876b 113 }
e40298d5
JS
114
115
116 // May have pressed cancel.
117 if (!dc || !dc->Ok())
72e7876b 118 {
e40298d5
JS
119 if (dc) delete dc;
120 return FALSE;
72e7876b 121 }
e40298d5
JS
122
123 // on the mac we have always pixels as addressing mode with 72 dpi
124
125 printout->SetPPIScreen(72, 72);
126 printout->SetPPIPrinter(72, 72);
127
128 // Set printout parameters
129 printout->SetDC(dc);
130
131 int w, h;
132 wxCoord ww, hh;
133 dc->GetSize(&w, &h);
134 printout->SetPageSizePixels((int)w, (int)h);
135 dc->GetSizeMM(&ww, &hh);
136 printout->SetPageSizeMM((int)ww, (int)hh);
137
138 // Create an abort window
139 wxBeginBusyCursor();
140
141 wxWindow *win = CreateAbortWindow(parent, printout);
142 wxSafeYield(win,true);
143
144 if (!win)
145 {
146 wxEndBusyCursor();
427ff662 147 wxMessageBox(wxT("Sorry, could not create an abort dialog."), wxT("Print Error"), wxOK, parent);
e40298d5
JS
148 delete dc;
149 return FALSE;
150 }
151 sm_abortWindow = win;
152 sm_abortWindow->Show(TRUE);
153 wxSafeYield(win,true);
154
155 printout->OnBeginPrinting();
156
157 bool keepGoing = TRUE;
158
159 int copyCount;
160 for (copyCount = 1; copyCount <= m_printDialogData.GetNoCopies(); copyCount ++)
161 {
162 if (!printout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage()))
163 {
164 wxEndBusyCursor();
427ff662 165 wxMessageBox(wxT("Could not start printing."), wxT("Print Error"), wxOK, parent);
e40298d5
JS
166 break;
167 }
168 if (sm_abortIt)
169 break;
170
171 int pn;
172 for (pn = m_printDialogData.GetFromPage(); keepGoing && (pn <= m_printDialogData.GetToPage()) && printout->HasPage(pn);
173 pn++)
174 {
175 if (sm_abortIt)
176 {
177 keepGoing = FALSE;
178 break;
179 }
180 else
181 {
182 GrafPtr thePort ;
183 GetPort( &thePort ) ;
184 wxSafeYield(win,true);
185 SetPort( thePort ) ;
186
187 dc->StartPage();
188 keepGoing = printout->OnPrintPage(pn);
189 dc->EndPage();
190 }
191 }
192 printout->OnEndDocument();
193 }
194
195 printout->OnEndPrinting();
196
197 if (sm_abortWindow)
198 {
199 sm_abortWindow->Show(FALSE);
200 delete sm_abortWindow;
201 sm_abortWindow = NULL;
202 }
203
204 wxEndBusyCursor();
205
206 delete dc;
207
208 return TRUE;
72e7876b
SC
209}
210
211wxDC* wxMacPrinter::PrintDialog(wxWindow *parent)
212{
213 wxDC* dc = (wxDC*) NULL;
e40298d5 214
72e7876b
SC
215 wxPrintDialog dialog(parent, & m_printDialogData);
216 int ret = dialog.ShowModal();
e40298d5 217
72e7876b
SC
218 if (ret == wxID_OK)
219 {
220 dc = dialog.GetPrintDC();
221 m_printDialogData = dialog.GetPrintDialogData();
222 }
e40298d5 223
72e7876b
SC
224 return dc;
225}
226
227bool wxMacPrinter::Setup(wxWindow *parent)
228{
229 wxPrintDialog dialog(parent, & m_printDialogData);
230 dialog.GetPrintDialogData().SetSetupDialog(TRUE);
e40298d5 231
72e7876b 232 int ret = dialog.ShowModal();
e40298d5 233
72e7876b
SC
234 if (ret == wxID_OK)
235 {
236 m_printDialogData = dialog.GetPrintDialogData();
237 }
e40298d5 238
72e7876b
SC
239 return (ret == wxID_OK);
240}
241
242/*
e40298d5
JS
243* Print preview
244*/
72e7876b
SC
245
246wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout,
e40298d5
JS
247 wxPrintout *printoutForPrinting,
248 wxPrintDialogData *data)
249 : wxPrintPreviewBase(printout, printoutForPrinting, data)
72e7876b
SC
250{
251 DetermineScaling();
252}
253
254wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data):
e40298d5 255wxPrintPreviewBase(printout, printoutForPrinting, data)
72e7876b 256{
e40298d5 257 DetermineScaling();
72e7876b
SC
258}
259
260wxMacPrintPreview::~wxMacPrintPreview(void)
261{
262}
263
264bool wxMacPrintPreview::Print(bool interactive)
265{
e40298d5
JS
266 if (!m_printPrintout)
267 return FALSE;
268 wxMacPrinter printer(&m_printDialogData);
269 return printer.Print(m_previewFrame, m_printPrintout, interactive);
72e7876b
SC
270}
271
272void wxMacPrintPreview::DetermineScaling(void)
273{
e40298d5
JS
274 int screenWidth , screenHeight ;
275 wxDisplaySize( &screenWidth , &screenHeight ) ;
276
277 m_previewPrintout->SetPPIScreen( 72 , 72 ) ;
278 m_previewPrintout->SetPPIPrinter( 72 , 72 ) ;
279 m_previewPrintout->SetPageSizeMM( (int) (8.0 * 25.6), (int) (11.0 * 25.6) );
280 m_previewPrintout->SetPageSizePixels( 8 * 72 , 11 * 72 ) ;
2f1ae414
SC
281 m_pageWidth = 8 * 72 ;
282 m_pageHeight = 11 * 72 ;
283 m_previewScale = 1 ;
e40298d5 284
72e7876b 285 // Get a device context for the currently selected printer
2f1ae414
SC
286 wxPrinterDC printerDC(m_printDialogData.GetPrintData());
287 if (printerDC.Ok())
72e7876b 288 {
e40298d5
JS
289 int x , y ;
290 wxCoord ww, hh;
291 printerDC.GetSizeMM(&ww, &hh);
292 printerDC.GetSize( &x , &y ) ;
293 m_previewPrintout->SetPageSizeMM((int)ww, (int)hh);
294 m_previewPrintout->SetPageSizePixels( x , y) ;
295 m_pageWidth = x ;
296 m_pageHeight = y ;
297 m_isOk = true ;
298 }
299 else
300 {
301 m_isOk = false ;
302 }
72e7876b 303 // At 100%, the page should look about page-size on the screen.
2f1ae414
SC
304 // m_previewScale = (float)((float)screenWidth/(float)printerWidth);
305 // m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerXRes);
306
307 m_previewScale = 1 ;
72e7876b 308}