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