]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/printmac.cpp
pen.h depends from brush.h in compat mode
[wxWidgets.git] / src / mac / carbon / printmac.cpp
CommitLineData
72e7876b 1/////////////////////////////////////////////////////////////////////////////
670f9935 2// Name: src/mac/carbon/printwin.cpp
72e7876b
SC
3// Purpose: wxMacPrinter framework
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6aa89a22 8// Copyright: (c) Julian Smart
670f9935 9// Licence: wxWindows licence
72e7876b
SC
10/////////////////////////////////////////////////////////////////////////////
11
72e7876b
SC
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
179e085f
RN
15#if wxUSE_PRINTING_ARCHITECTURE
16
72e7876b 17#ifdef __BORLANDC__
670f9935 18 #pragma hdrstop
72e7876b
SC
19#endif
20
72e7876b 21#ifndef WX_PRECOMP
670f9935
WS
22 #include "wx/utils.h"
23 #include "wx/dc.h"
24 #include "wx/app.h"
25 #include "wx/msgdlg.h"
6d50343d 26 #include "wx/dcprint.h"
18680f86 27 #include "wx/math.h"
72e7876b
SC
28#endif
29
746d7582 30#include "wx/mac/uma.h"
76a5e5d2 31
72e7876b 32#include "wx/mac/printmac.h"
746d7582
SC
33#include "wx/mac/private/print.h"
34
72e7876b 35#include "wx/printdlg.h"
b64e7047 36#include "wx/paper.h"
08680429 37#include "wx/mac/printdlg.h"
72e7876b
SC
38
39#include <stdlib.h>
40
dc7ccb9c 41IMPLEMENT_DYNAMIC_CLASS(wxMacCarbonPrintData, wxPrintNativeDataBase)
72e7876b
SC
42IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter, wxPrinterBase)
43IMPLEMENT_CLASS(wxMacPrintPreview, wxPrintPreviewBase)
72e7876b 44
b7cacb43 45bool wxMacCarbonPrintData::IsOk() const
746d7582 46{
dc7ccb9c 47 return (m_macPageFormat != kPMNoPageFormat) && (m_macPrintSettings != kPMNoPrintSettings) && (m_macPrintSession != kPMNoReference);
746d7582 48}
746d7582
SC
49wxMacCarbonPrintData::wxMacCarbonPrintData()
50{
51 m_macPageFormat = kPMNoPageFormat;
52 m_macPrintSettings = kPMNoPrintSettings;
53 m_macPrintSession = kPMNoReference ;
54 ValidateOrCreate() ;
55}
56
57wxMacCarbonPrintData::~wxMacCarbonPrintData()
58{
59 if (m_macPageFormat != kPMNoPageFormat)
60 {
61 (void)PMRelease(m_macPageFormat);
62 m_macPageFormat = kPMNoPageFormat;
63 }
64
65 if (m_macPrintSettings != kPMNoPrintSettings)
66 {
67 (void)PMRelease(m_macPrintSettings);
68 m_macPrintSettings = kPMNoPrintSettings;
69 }
670f9935 70
746d7582
SC
71 if ( m_macPrintSession != kPMNoReference )
72 {
73 (void)PMRelease(m_macPrintSession);
74 m_macPrintSession = kPMNoReference;
75 }
76}
77
670f9935 78void wxMacCarbonPrintData::ValidateOrCreate()
746d7582
SC
79{
80 OSStatus err = noErr ;
81 if ( m_macPrintSession == kPMNoReference )
82 {
fdf3ce59 83 err = PMCreateSession( &m_macPrintSession ) ;
746d7582
SC
84 }
85 // Set up a valid PageFormat object.
86 if ( m_macPageFormat == kPMNoPageFormat)
87 {
fdf3ce59 88 err = PMCreatePageFormat(&m_macPageFormat);
670f9935 89
746d7582
SC
90 // Note that PMPageFormat is not session-specific, but calling
91 // PMSessionDefaultPageFormat assigns values specific to the printer
92 // associated with the current printing session.
93 if ((err == noErr) &&
94 ( m_macPageFormat != kPMNoPageFormat))
95 {
fdf3ce59
SC
96 err = PMSessionDefaultPageFormat(m_macPrintSession,
97 m_macPageFormat);
746d7582
SC
98 }
99 }
100 else
101 {
fdf3ce59
SC
102 err = PMSessionValidatePageFormat(m_macPrintSession,
103 m_macPageFormat,
746d7582
SC
104 kPMDontWantBoolean);
105 }
670f9935 106
746d7582
SC
107 // Set up a valid PrintSettings object.
108 if ( m_macPrintSettings == kPMNoPrintSettings)
109 {
fdf3ce59 110 err = PMCreatePrintSettings( &m_macPrintSettings);
670f9935 111
746d7582
SC
112 // Note that PMPrintSettings is not session-specific, but calling
113 // PMSessionDefaultPrintSettings assigns values specific to the printer
114 // associated with the current printing session.
115 if ((err == noErr) &&
116 ( m_macPrintSettings != kPMNoPrintSettings))
117 {
fdf3ce59
SC
118 err = PMSessionDefaultPrintSettings(m_macPrintSession,
119 m_macPrintSettings);
746d7582
SC
120 }
121 }
122 else
123 {
fdf3ce59
SC
124 err = PMSessionValidatePrintSettings( m_macPrintSession,
125 m_macPrintSettings,
746d7582
SC
126 kPMDontWantBoolean);
127 }
128}
129
dc7ccb9c 130bool wxMacCarbonPrintData::TransferFrom( const wxPrintData &data )
746d7582
SC
131{
132 ValidateOrCreate() ;
dc7ccb9c 133 PMSetCopies( (PMPrintSettings) m_macPrintSettings , data.GetNoCopies() , false ) ;
01294df0
SC
134 if ( data.IsOrientationReversed() )
135 PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
136 kPMReverseLandscape : kPMReversePortrait , false ) ;
137 else
138 PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
139 kPMLandscape : kPMPortrait , false ) ;
746d7582
SC
140 // collate cannot be set
141#if 0 // not yet tested
670f9935 142 if ( !m_printerName.empty() )
dbe4a80c 143 PMSessionSetCurrentPrinter( (PMPrintSession) m_macPrintSession , wxCFStringRef( m_printerName , wxFont::GetDefaultEncoding() ) ) ;
746d7582 144#endif
4f74e0d1 145#ifndef __LP64__
746d7582
SC
146 PMColorMode color ;
147 PMGetColorMode( (PMPrintSettings) m_macPrintSettings, &color ) ;
dc7ccb9c 148 if ( data.GetColour() )
746d7582
SC
149 {
150 if ( color == kPMBlackAndWhite )
151 PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMColor ) ;
152 }
153 else
154 PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMBlackAndWhite ) ;
4f74e0d1 155#endif
670f9935 156
e1673e52
SC
157 PMDuplexMode mode = 0 ;
158 switch( data.GetDuplex() )
b64e7047 159 {
e1673e52
SC
160 case wxDUPLEX_HORIZONTAL :
161 mode = kPMDuplexNoTumble ;
162 break ;
163 case wxDUPLEX_VERTICAL :
164 mode = kPMDuplexTumble ;
165 break ;
166 case wxDUPLEX_SIMPLEX :
167 default :
168 mode = kPMDuplexNone ;
169 break ;
b64e7047 170 }
e1673e52
SC
171 PMSetDuplex( (PMPrintSettings) m_macPrintSettings, mode ) ;
172
746d7582
SC
173 // PMQualityMode not yet accessible via API
174 // todo paperSize
4f74e0d1 175
8b285841
SC
176 PMResolution res;
177 PMPrinter printer;
8b285841 178 PMSessionGetCurrentPrinter(m_macPrintSession, &printer);
cfc65f26 179#if 0 // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
4f74e0d1
SC
180 PMPrinterGetOutputResolution( printer,
181 (PMPrintSettings) m_macPrintSettings, &res) ;
182 // TODO transfer ? into page format ?
cfc65f26 183 // may fail !
4f74e0d1
SC
184#else
185 PMTag tag = kPMMaxSquareResolution;
8b285841
SC
186 PMPrinterGetPrinterResolution(printer, tag, &res);
187 PMSetResolution((PMPageFormat) m_macPageFormat, &res);
4f74e0d1 188#endif
aee23798
SC
189 // after setting the new resolution the format has to be updated, otherwise the page rect remains
190 // at the 'old' scaling
191 PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession,
192 (PMPageFormat) m_macPageFormat,
193 kPMDontWantBoolean) ;
8b285841 194
dc7ccb9c 195 return true ;
746d7582
SC
196}
197
dc7ccb9c 198bool wxMacCarbonPrintData::TransferTo( wxPrintData &data )
746d7582
SC
199{
200 OSStatus err = noErr ;
670f9935 201
746d7582
SC
202 UInt32 copies ;
203 err = PMGetCopies( m_macPrintSettings , &copies ) ;
204 if ( err == noErr )
670f9935
WS
205 data.SetNoCopies( copies ) ;
206
746d7582
SC
207 PMOrientation orientation ;
208 err = PMGetOrientation( m_macPageFormat , &orientation ) ;
209 if ( err == noErr )
210 {
211 if ( orientation == kPMPortrait || orientation == kPMReversePortrait )
01294df0 212 {
dc7ccb9c 213 data.SetOrientation( wxPORTRAIT );
01294df0
SC
214 data.SetOrientationReversed( orientation == kPMReversePortrait );
215 }
746d7582 216 else
01294df0 217 {
dc7ccb9c 218 data.SetOrientation( wxLANDSCAPE );
01294df0
SC
219 data.SetOrientationReversed( orientation == kPMReverseLandscape );
220 }
746d7582
SC
221 }
222
223 // collate cannot be set
224#if 0
225 {
dbe4a80c 226 wxCFStringRef name ;
746d7582
SC
227 PMPrinter printer ;
228 PMSessionGetCurrentPrinter( m_macPrintSession ,
229 &printer ) ;
230 m_printerName = name.AsString() ;
231 }
232#endif
670f9935 233
4f74e0d1 234#ifndef __LP64__
746d7582
SC
235 PMColorMode color ;
236 err = PMGetColorMode( m_macPrintSettings, &color ) ;
237 if ( err == noErr )
dc7ccb9c 238 data.SetColour( !(color == kPMBlackAndWhite) ) ;
4f74e0d1 239#endif
e1673e52
SC
240 PMDuplexMode mode = 0 ;
241 PMGetDuplex( (PMPrintSettings) m_macPrintSettings, &mode ) ;
242 switch( mode )
b64e7047 243 {
e1673e52
SC
244 case kPMDuplexNoTumble :
245 data.SetDuplex(wxDUPLEX_HORIZONTAL);
246 break ;
247 case kPMDuplexTumble :
248 data.SetDuplex(wxDUPLEX_VERTICAL);
249 break ;
250 case kPMDuplexNone :
251 default :
252 data.SetDuplex(wxDUPLEX_SIMPLEX);
253 break ;
b64e7047 254 }
746d7582 255 // PMQualityMode not yet accessible via API
b64e7047
SC
256
257 PMPaper paper ;
258 PMGetPageFormatPaper( m_macPageFormat, &paper );
259
670f9935 260 PMRect rPaper;
746d7582
SC
261 err = PMGetUnadjustedPaperRect( m_macPageFormat, &rPaper);
262 if ( err == noErr )
263 {
b64e7047
SC
264 wxSize sz((int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) ,
265 (int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ));
266 data.SetPaperSize(sz);
267 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
268 if (id != wxPAPER_NONE)
269 {
270 data.SetPaperId(id);
271 }
746d7582 272 }
dc7ccb9c 273 return true ;
746d7582
SC
274}
275
89954433 276void wxMacCarbonPrintData::TransferFrom( wxPageSetupData *WXUNUSED(data) )
746d7582
SC
277{
278 // should we setup the page rect here ?
279 // since MacOS sometimes has two same paper rects with different
280 // page rects we could make it roundtrip safe perhaps
746d7582
SC
281}
282
283void wxMacCarbonPrintData::TransferTo( wxPageSetupData* data )
284{
1aa7b427 285 PMRect rPaper;
746d7582
SC
286 OSStatus err = PMGetUnadjustedPaperRect(m_macPageFormat, &rPaper);
287 if ( err == noErr )
288 {
b64e7047
SC
289 wxSize sz((int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) ,
290 (int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ));
291 data->SetPaperSize(sz);
292
746d7582
SC
293 PMRect rPage ;
294 err = PMGetUnadjustedPageRect(m_macPageFormat , &rPage ) ;
295 if ( err == noErr )
296 {
297 data->SetMinMarginTopLeft( wxPoint (
670f9935
WS
298 (int)(((double) rPage.left - rPaper.left ) * pt2mm) ,
299 (int)(((double) rPage.top - rPaper.top ) * pt2mm) ) ) ;
300
301 data->SetMinMarginBottomRight( wxPoint (
5be55d56
VZ
302 (wxCoord)(((double) rPaper.right - rPage.right ) * pt2mm),
303 (wxCoord)(((double) rPaper.bottom - rPage.bottom ) * pt2mm)) ) ;
dc7ccb9c
SC
304
305 if ( data->GetMarginTopLeft().x < data->GetMinMarginTopLeft().x )
306 data->SetMarginTopLeft( wxPoint( data->GetMinMarginTopLeft().x ,
307 data->GetMarginTopLeft().y ) ) ;
308
309 if ( data->GetMarginBottomRight().x < data->GetMinMarginBottomRight().x )
310 data->SetMarginBottomRight( wxPoint( data->GetMinMarginBottomRight().x ,
311 data->GetMarginBottomRight().y ) );
312
313 if ( data->GetMarginTopLeft().y < data->GetMinMarginTopLeft().y )
314 data->SetMarginTopLeft( wxPoint( data->GetMarginTopLeft().x , data->GetMinMarginTopLeft().y ) );
315
316 if ( data->GetMarginBottomRight().y < data->GetMinMarginBottomRight().y )
317 data->SetMarginBottomRight( wxPoint( data->GetMarginBottomRight().x ,
318 data->GetMinMarginBottomRight().y) );
670f9935
WS
319 }
320 }
746d7582
SC
321}
322
323void wxMacCarbonPrintData::TransferTo( wxPrintDialogData* data )
324{
325 UInt32 minPage , maxPage ;
326 PMGetPageRange( m_macPrintSettings , &minPage , &maxPage ) ;
327 data->SetMinPage( minPage ) ;
328 data->SetMaxPage( maxPage ) ;
329 UInt32 copies ;
330 PMGetCopies( m_macPrintSettings , &copies ) ;
331 data->SetNoCopies( copies ) ;
332 UInt32 from , to ;
333 PMGetFirstPage( m_macPrintSettings , &from ) ;
334 PMGetLastPage( m_macPrintSettings , &to ) ;
34a4e912
SC
335 if ( to >= 0x7FFFFFFF ) // due to an OS Bug we don't get back kPMPrintAllPages
336 {
337 data->SetAllPages( true ) ;
338 // This means all pages, more or less
339 data->SetFromPage(1);
340 data->SetToPage(32000);
341 }
342 else
343 {
344 data->SetFromPage( from ) ;
345 data->SetToPage( to ) ;
346 data->SetAllPages( false );
347 }
746d7582
SC
348}
349
350void wxMacCarbonPrintData::TransferFrom( wxPrintDialogData* data )
351{
352 PMSetPageRange( m_macPrintSettings , data->GetMinPage() , data->GetMaxPage() ) ;
353 PMSetCopies( m_macPrintSettings , data->GetNoCopies() , false ) ;
354 PMSetFirstPage( m_macPrintSettings , data->GetFromPage() , false ) ;
b386cd7a 355
34a4e912 356 if (data->GetAllPages() || data->GetFromPage() == 0)
1aa7b427
DS
357 PMSetLastPage( m_macPrintSettings , (UInt32) kPMPrintAllPages, true ) ;
358 else
359 PMSetLastPage( m_macPrintSettings , (UInt32) data->GetToPage() , false ) ;
746d7582
SC
360}
361
72e7876b 362/*
e40298d5
JS
363* Printer
364*/
365
72e7876b 366wxMacPrinter::wxMacPrinter(wxPrintDialogData *data):
e40298d5 367wxPrinterBase(data)
72e7876b
SC
368{
369}
370
371wxMacPrinter::~wxMacPrinter(void)
372{
373}
374
375bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
376{
1aa7b427 377 sm_abortIt = false;
e40298d5 378 sm_abortWindow = NULL;
1aa7b427 379
e40298d5 380 if (!printout)
1aa7b427
DS
381 return false;
382
383 printout->SetIsPreview(false);
d2b354f9
JS
384 if (m_printDialogData.GetMinPage() < 1)
385 m_printDialogData.SetMinPage(1);
386 if (m_printDialogData.GetMaxPage() < 1)
387 m_printDialogData.SetMaxPage(9999);
388
670f9935 389 // Create a suitable device context
f415cab9 390 wxPrinterDC *dc = NULL;
e40298d5
JS
391 if (prompt)
392 {
f415cab9 393 wxMacPrintDialog dialog(parent, & m_printDialogData);
2f1ae414 394 if (dialog.ShowModal() == wxID_OK)
e40298d5 395 {
f415cab9
JS
396 dc = wxDynamicCast(dialog.GetPrintDC(), wxPrinterDC);
397 wxASSERT(dc);
ffcd5195 398 m_printDialogData = dialog.GetPrintDialogData();
e40298d5
JS
399 }
400 }
401 else
72e7876b 402 {
e40298d5 403 dc = new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
72e7876b 404 }
1aa7b427 405
e40298d5 406 // May have pressed cancel.
888dde65 407 if (!dc || !dc->IsOk())
72e7876b 408 {
1aa7b427
DS
409 if (dc)
410 delete dc;
411 return false;
72e7876b 412 }
1aa7b427 413
e40298d5 414 // on the mac we have always pixels as addressing mode with 72 dpi
e40298d5 415 printout->SetPPIScreen(72, 72);
8b285841
SC
416 PMResolution res;
417 wxMacCarbonPrintData* nativeData = (wxMacCarbonPrintData*)
418 (m_printDialogData.GetPrintData().GetNativeData());
cfc65f26 419#if 0 // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
4f74e0d1
SC
420 PMPrinter printer;
421 PMSessionGetCurrentPrinter(nativeData->m_macPrintSession, &printer);
422 PMPrinterGetOutputResolution( printer, nativeData->m_macPrintSettings, &res) ;
423#else
8b285841 424 PMGetResolution((PMPageFormat) (nativeData->m_macPageFormat), &res);
4f74e0d1 425#endif
8b285841 426 printout->SetPPIPrinter(int(res.hRes), int(res.vRes));
1aa7b427
DS
427
428 // Set printout parameters
e40298d5 429 printout->SetDC(dc);
1aa7b427 430
e40298d5 431 int w, h;
e40298d5
JS
432 dc->GetSize(&w, &h);
433 printout->SetPageSizePixels((int)w, (int)h);
f415cab9
JS
434 printout->SetPaperRectPixels(dc->GetPaperRect());
435 wxCoord mw, mh;
436 dc->GetSizeMM(&mw, &mh);
437 printout->SetPageSizeMM((int)mw, (int)mh);
1aa7b427 438
e40298d5
JS
439 // Create an abort window
440 wxBeginBusyCursor();
1aa7b427 441
d2b354f9 442 printout->OnPreparePrinting();
1aa7b427 443
d2b354f9
JS
444 // Get some parameters from the printout, if defined
445 int fromPage, toPage;
446 int minPage, maxPage;
447 printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage);
1aa7b427 448
d2b354f9
JS
449 if (maxPage == 0)
450 {
451 wxEndBusyCursor();
1aa7b427 452 return false;
d2b354f9 453 }
1aa7b427 454
d2b354f9
JS
455 // Only set min and max, because from and to have been
456 // set by the user
457 m_printDialogData.SetMinPage(minPage);
458 m_printDialogData.SetMaxPage(maxPage);
1aa7b427 459
e40298d5
JS
460 wxWindow *win = CreateAbortWindow(parent, printout);
461 wxSafeYield(win,true);
1aa7b427 462
e40298d5
JS
463 if (!win)
464 {
465 wxEndBusyCursor();
427ff662 466 wxMessageBox(wxT("Sorry, could not create an abort dialog."), wxT("Print Error"), wxOK, parent);
e40298d5 467 delete dc;
1aa7b427
DS
468
469 return false;
e40298d5 470 }
1aa7b427 471
e40298d5 472 sm_abortWindow = win;
1aa7b427 473 sm_abortWindow->Show(true);
e40298d5 474 wxSafeYield(win,true);
1aa7b427 475
e40298d5 476 printout->OnBeginPrinting();
1aa7b427
DS
477
478 bool keepGoing = true;
479
e40298d5
JS
480 int copyCount;
481 for (copyCount = 1; copyCount <= m_printDialogData.GetNoCopies(); copyCount ++)
482 {
483 if (!printout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage()))
484 {
485 wxEndBusyCursor();
427ff662 486 wxMessageBox(wxT("Could not start printing."), wxT("Print Error"), wxOK, parent);
e40298d5
JS
487 break;
488 }
489 if (sm_abortIt)
490 break;
1aa7b427 491
e40298d5 492 int pn;
670f9935 493 for (pn = m_printDialogData.GetFromPage();
1aa7b427 494 keepGoing && (pn <= m_printDialogData.GetToPage()) && printout->HasPage(pn);
e40298d5
JS
495 pn++)
496 {
497 if (sm_abortIt)
498 {
1aa7b427 499 keepGoing = false;
e40298d5
JS
500 break;
501 }
502 else
503 {
03561a3c 504 wxSafeYield(win,true);
e40298d5
JS
505 dc->StartPage();
506 keepGoing = printout->OnPrintPage(pn);
507 dc->EndPage();
508 }
509 }
510 printout->OnEndDocument();
511 }
670f9935 512
e40298d5 513 printout->OnEndPrinting();
670f9935 514
e40298d5
JS
515 if (sm_abortWindow)
516 {
1aa7b427 517 sm_abortWindow->Show(false);
e40298d5
JS
518 delete sm_abortWindow;
519 sm_abortWindow = NULL;
520 }
670f9935 521
e40298d5 522 wxEndBusyCursor();
670f9935 523
e40298d5 524 delete dc;
670f9935 525
1aa7b427 526 return true;
72e7876b
SC
527}
528
529wxDC* wxMacPrinter::PrintDialog(wxWindow *parent)
530{
531 wxDC* dc = (wxDC*) NULL;
670f9935 532
72e7876b
SC
533 wxPrintDialog dialog(parent, & m_printDialogData);
534 int ret = dialog.ShowModal();
670f9935 535
72e7876b
SC
536 if (ret == wxID_OK)
537 {
538 dc = dialog.GetPrintDC();
539 m_printDialogData = dialog.GetPrintDialogData();
540 }
670f9935 541
72e7876b
SC
542 return dc;
543}
544
89954433 545bool wxMacPrinter::Setup(wxWindow *WXUNUSED(parent))
72e7876b 546{
04a014a5 547#if 0
72e7876b 548 wxPrintDialog dialog(parent, & m_printDialogData);
1aa7b427 549 dialog.GetPrintDialogData().SetSetupDialog(true);
670f9935 550
72e7876b 551 int ret = dialog.ShowModal();
670f9935 552
72e7876b 553 if (ret == wxID_OK)
72e7876b 554 m_printDialogData = dialog.GetPrintDialogData();
670f9935 555
72e7876b 556 return (ret == wxID_OK);
04a014a5 557#endif
1aa7b427 558
04a014a5 559 return wxID_CANCEL;
72e7876b
SC
560}
561
562/*
e40298d5
JS
563* Print preview
564*/
72e7876b
SC
565
566wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout,
e40298d5
JS
567 wxPrintout *printoutForPrinting,
568 wxPrintDialogData *data)
569 : wxPrintPreviewBase(printout, printoutForPrinting, data)
72e7876b
SC
570{
571 DetermineScaling();
572}
573
574wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data):
e40298d5 575wxPrintPreviewBase(printout, printoutForPrinting, data)
72e7876b 576{
e40298d5 577 DetermineScaling();
72e7876b
SC
578}
579
580wxMacPrintPreview::~wxMacPrintPreview(void)
581{
582}
583
584bool wxMacPrintPreview::Print(bool interactive)
585{
e40298d5 586 if (!m_printPrintout)
1aa7b427
DS
587 return false;
588
e40298d5
JS
589 wxMacPrinter printer(&m_printDialogData);
590 return printer.Print(m_previewFrame, m_printPrintout, interactive);
72e7876b
SC
591}
592
593void wxMacPrintPreview::DetermineScaling(void)
594{
e40298d5
JS
595 int screenWidth , screenHeight ;
596 wxDisplaySize( &screenWidth , &screenHeight ) ;
670f9935 597
aee23798
SC
598 wxSize ppiScreen( 72 , 72 ) ;
599 wxSize ppiPrinter( 72 , 72 ) ;
600
f415cab9 601 // Note that with Leopard, screen dpi=72 is no longer a given
aee23798
SC
602 m_previewPrintout->SetPPIScreen( ppiScreen.x , ppiScreen.y ) ;
603
f415cab9 604 wxCoord w , h ;
aee23798 605 wxCoord ww, hh;
f415cab9 606 wxRect paperRect;
670f9935 607
72e7876b 608 // Get a device context for the currently selected printer
2f1ae414 609 wxPrinterDC printerDC(m_printDialogData.GetPrintData());
888dde65 610 if (printerDC.IsOk())
72e7876b 611 {
e40298d5 612 printerDC.GetSizeMM(&ww, &hh);
f415cab9 613 printerDC.GetSize( &w , &h ) ;
aee23798 614 ppiPrinter = printerDC.GetPPI() ;
f415cab9 615 paperRect = printerDC.GetPaperRect();
e40298d5
JS
616 m_isOk = true ;
617 }
618 else
619 {
aee23798 620 // use some defaults
f415cab9
JS
621 w = 8 * 72 ;
622 h = 11 * 72 ;
623 ww = (wxCoord) (w * 25.4 / ppiPrinter.x) ;
624 hh = (wxCoord) (h * 25.4 / ppiPrinter.y) ;
625 paperRect = wxRect(0, 0, w, h);
e40298d5
JS
626 m_isOk = false ;
627 }
f415cab9
JS
628 m_pageWidth = w;
629 m_pageHeight = h;
630
631 m_previewPrintout->SetPageSizePixels(w , h) ;
632 m_previewPrintout->SetPageSizeMM(ww, hh);
633 m_previewPrintout->SetPaperRectPixels(paperRect);
aee23798 634 m_previewPrintout->SetPPIPrinter( ppiPrinter.x , ppiPrinter.y ) ;
1aa7b427 635
f415cab9
JS
636 m_previewScaleX = float(ppiScreen.x) / ppiPrinter.x;
637 m_previewScaleY = float(ppiScreen.y) / ppiPrinter.y;
72e7876b 638}
179e085f
RN
639
640#endif