]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/printmac.cpp
making ref counting behavior consistent, activating QD variante for polygon region...
[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 {
83 err = PMCreateSession( (PMPrintSession *) &m_macPrintSession ) ;
84 }
85 // Set up a valid PageFormat object.
86 if ( m_macPageFormat == kPMNoPageFormat)
87 {
88 err = PMCreatePageFormat((PMPageFormat *) &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 {
96 err = PMSessionDefaultPageFormat((PMPrintSession) m_macPrintSession,
97 (PMPageFormat) m_macPageFormat);
98 }
99 }
100 else
101 {
102 err = PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession,
103 (PMPageFormat) m_macPageFormat,
104 kPMDontWantBoolean);
105 }
670f9935 106
746d7582
SC
107 // Set up a valid PrintSettings object.
108 if ( m_macPrintSettings == kPMNoPrintSettings)
109 {
110 err = PMCreatePrintSettings((PMPrintSettings *) &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 {
118 err = PMSessionDefaultPrintSettings((PMPrintSession) m_macPrintSession,
119 (PMPrintSettings) m_macPrintSettings);
120 }
121 }
122 else
123 {
124 err = PMSessionValidatePrintSettings((PMPrintSession) m_macPrintSession,
125 (PMPrintSettings) m_macPrintSettings,
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);
4f74e0d1
SC
179#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
180 PMPrinterGetOutputResolution( printer,
181 (PMPrintSettings) m_macPrintSettings, &res) ;
182 // TODO transfer ? into page format ?
183#else
184 PMTag tag = kPMMaxSquareResolution;
8b285841
SC
185 PMPrinterGetPrinterResolution(printer, tag, &res);
186 PMSetResolution((PMPageFormat) m_macPageFormat, &res);
4f74e0d1 187#endif
aee23798
SC
188 // after setting the new resolution the format has to be updated, otherwise the page rect remains
189 // at the 'old' scaling
190 PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession,
191 (PMPageFormat) m_macPageFormat,
192 kPMDontWantBoolean) ;
8b285841 193
dc7ccb9c 194 return true ;
746d7582
SC
195}
196
dc7ccb9c 197bool wxMacCarbonPrintData::TransferTo( wxPrintData &data )
746d7582
SC
198{
199 OSStatus err = noErr ;
670f9935 200
746d7582
SC
201 UInt32 copies ;
202 err = PMGetCopies( m_macPrintSettings , &copies ) ;
203 if ( err == noErr )
670f9935
WS
204 data.SetNoCopies( copies ) ;
205
746d7582
SC
206 PMOrientation orientation ;
207 err = PMGetOrientation( m_macPageFormat , &orientation ) ;
208 if ( err == noErr )
209 {
210 if ( orientation == kPMPortrait || orientation == kPMReversePortrait )
01294df0 211 {
dc7ccb9c 212 data.SetOrientation( wxPORTRAIT );
01294df0
SC
213 data.SetOrientationReversed( orientation == kPMReversePortrait );
214 }
746d7582 215 else
01294df0 216 {
dc7ccb9c 217 data.SetOrientation( wxLANDSCAPE );
01294df0
SC
218 data.SetOrientationReversed( orientation == kPMReverseLandscape );
219 }
746d7582
SC
220 }
221
222 // collate cannot be set
223#if 0
224 {
dbe4a80c 225 wxCFStringRef name ;
746d7582
SC
226 PMPrinter printer ;
227 PMSessionGetCurrentPrinter( m_macPrintSession ,
228 &printer ) ;
229 m_printerName = name.AsString() ;
230 }
231#endif
670f9935 232
4f74e0d1 233#ifndef __LP64__
746d7582
SC
234 PMColorMode color ;
235 err = PMGetColorMode( m_macPrintSettings, &color ) ;
236 if ( err == noErr )
dc7ccb9c 237 data.SetColour( !(color == kPMBlackAndWhite) ) ;
4f74e0d1 238#endif
e1673e52
SC
239 PMDuplexMode mode = 0 ;
240 PMGetDuplex( (PMPrintSettings) m_macPrintSettings, &mode ) ;
241 switch( mode )
b64e7047 242 {
e1673e52
SC
243 case kPMDuplexNoTumble :
244 data.SetDuplex(wxDUPLEX_HORIZONTAL);
245 break ;
246 case kPMDuplexTumble :
247 data.SetDuplex(wxDUPLEX_VERTICAL);
248 break ;
249 case kPMDuplexNone :
250 default :
251 data.SetDuplex(wxDUPLEX_SIMPLEX);
252 break ;
b64e7047 253 }
746d7582 254 // PMQualityMode not yet accessible via API
b64e7047
SC
255
256 PMPaper paper ;
257 PMGetPageFormatPaper( m_macPageFormat, &paper );
258
670f9935 259 PMRect rPaper;
746d7582
SC
260 err = PMGetUnadjustedPaperRect( m_macPageFormat, &rPaper);
261 if ( err == noErr )
262 {
b64e7047
SC
263 wxSize sz((int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) ,
264 (int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ));
265 data.SetPaperSize(sz);
266 wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
267 if (id != wxPAPER_NONE)
268 {
269 data.SetPaperId(id);
270 }
746d7582 271 }
dc7ccb9c 272 return true ;
746d7582
SC
273}
274
89954433 275void wxMacCarbonPrintData::TransferFrom( wxPageSetupData *WXUNUSED(data) )
746d7582
SC
276{
277 // should we setup the page rect here ?
278 // since MacOS sometimes has two same paper rects with different
279 // page rects we could make it roundtrip safe perhaps
746d7582
SC
280}
281
282void wxMacCarbonPrintData::TransferTo( wxPageSetupData* data )
283{
1aa7b427 284 PMRect rPaper;
746d7582
SC
285 OSStatus err = PMGetUnadjustedPaperRect(m_macPageFormat, &rPaper);
286 if ( err == noErr )
287 {
b64e7047
SC
288 wxSize sz((int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) ,
289 (int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ));
290 data->SetPaperSize(sz);
291
746d7582
SC
292 PMRect rPage ;
293 err = PMGetUnadjustedPageRect(m_macPageFormat , &rPage ) ;
294 if ( err == noErr )
295 {
296 data->SetMinMarginTopLeft( wxPoint (
670f9935
WS
297 (int)(((double) rPage.left - rPaper.left ) * pt2mm) ,
298 (int)(((double) rPage.top - rPaper.top ) * pt2mm) ) ) ;
299
300 data->SetMinMarginBottomRight( wxPoint (
5be55d56
VZ
301 (wxCoord)(((double) rPaper.right - rPage.right ) * pt2mm),
302 (wxCoord)(((double) rPaper.bottom - rPage.bottom ) * pt2mm)) ) ;
dc7ccb9c
SC
303
304 if ( data->GetMarginTopLeft().x < data->GetMinMarginTopLeft().x )
305 data->SetMarginTopLeft( wxPoint( data->GetMinMarginTopLeft().x ,
306 data->GetMarginTopLeft().y ) ) ;
307
308 if ( data->GetMarginBottomRight().x < data->GetMinMarginBottomRight().x )
309 data->SetMarginBottomRight( wxPoint( data->GetMinMarginBottomRight().x ,
310 data->GetMarginBottomRight().y ) );
311
312 if ( data->GetMarginTopLeft().y < data->GetMinMarginTopLeft().y )
313 data->SetMarginTopLeft( wxPoint( data->GetMarginTopLeft().x , data->GetMinMarginTopLeft().y ) );
314
315 if ( data->GetMarginBottomRight().y < data->GetMinMarginBottomRight().y )
316 data->SetMarginBottomRight( wxPoint( data->GetMarginBottomRight().x ,
317 data->GetMinMarginBottomRight().y) );
670f9935
WS
318 }
319 }
746d7582
SC
320}
321
322void wxMacCarbonPrintData::TransferTo( wxPrintDialogData* data )
323{
324 UInt32 minPage , maxPage ;
325 PMGetPageRange( m_macPrintSettings , &minPage , &maxPage ) ;
326 data->SetMinPage( minPage ) ;
327 data->SetMaxPage( maxPage ) ;
328 UInt32 copies ;
329 PMGetCopies( m_macPrintSettings , &copies ) ;
330 data->SetNoCopies( copies ) ;
331 UInt32 from , to ;
332 PMGetFirstPage( m_macPrintSettings , &from ) ;
333 PMGetLastPage( m_macPrintSettings , &to ) ;
34a4e912
SC
334 if ( to >= 0x7FFFFFFF ) // due to an OS Bug we don't get back kPMPrintAllPages
335 {
336 data->SetAllPages( true ) ;
337 // This means all pages, more or less
338 data->SetFromPage(1);
339 data->SetToPage(32000);
340 }
341 else
342 {
343 data->SetFromPage( from ) ;
344 data->SetToPage( to ) ;
345 data->SetAllPages( false );
346 }
746d7582
SC
347}
348
349void wxMacCarbonPrintData::TransferFrom( wxPrintDialogData* data )
350{
351 PMSetPageRange( m_macPrintSettings , data->GetMinPage() , data->GetMaxPage() ) ;
352 PMSetCopies( m_macPrintSettings , data->GetNoCopies() , false ) ;
353 PMSetFirstPage( m_macPrintSettings , data->GetFromPage() , false ) ;
b386cd7a 354
34a4e912 355 if (data->GetAllPages() || data->GetFromPage() == 0)
1aa7b427
DS
356 PMSetLastPage( m_macPrintSettings , (UInt32) kPMPrintAllPages, true ) ;
357 else
358 PMSetLastPage( m_macPrintSettings , (UInt32) data->GetToPage() , false ) ;
746d7582
SC
359}
360
72e7876b 361/*
e40298d5
JS
362* Printer
363*/
364
72e7876b 365wxMacPrinter::wxMacPrinter(wxPrintDialogData *data):
e40298d5 366wxPrinterBase(data)
72e7876b
SC
367{
368}
369
370wxMacPrinter::~wxMacPrinter(void)
371{
372}
373
374bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
375{
1aa7b427 376 sm_abortIt = false;
e40298d5 377 sm_abortWindow = NULL;
1aa7b427 378
e40298d5 379 if (!printout)
1aa7b427
DS
380 return false;
381
382 printout->SetIsPreview(false);
d2b354f9
JS
383 if (m_printDialogData.GetMinPage() < 1)
384 m_printDialogData.SetMinPage(1);
385 if (m_printDialogData.GetMaxPage() < 1)
386 m_printDialogData.SetMaxPage(9999);
387
670f9935 388 // Create a suitable device context
f415cab9 389 wxPrinterDC *dc = NULL;
e40298d5
JS
390 if (prompt)
391 {
f415cab9 392 wxMacPrintDialog dialog(parent, & m_printDialogData);
2f1ae414 393 if (dialog.ShowModal() == wxID_OK)
e40298d5 394 {
f415cab9
JS
395 dc = wxDynamicCast(dialog.GetPrintDC(), wxPrinterDC);
396 wxASSERT(dc);
ffcd5195 397 m_printDialogData = dialog.GetPrintDialogData();
e40298d5
JS
398 }
399 }
400 else
72e7876b 401 {
e40298d5 402 dc = new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
72e7876b 403 }
1aa7b427 404
e40298d5 405 // May have pressed cancel.
888dde65 406 if (!dc || !dc->IsOk())
72e7876b 407 {
1aa7b427
DS
408 if (dc)
409 delete dc;
410 return false;
72e7876b 411 }
1aa7b427 412
e40298d5 413 // on the mac we have always pixels as addressing mode with 72 dpi
e40298d5 414 printout->SetPPIScreen(72, 72);
8b285841
SC
415 PMResolution res;
416 wxMacCarbonPrintData* nativeData = (wxMacCarbonPrintData*)
417 (m_printDialogData.GetPrintData().GetNativeData());
4f74e0d1
SC
418#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
419 PMPrinter printer;
420 PMSessionGetCurrentPrinter(nativeData->m_macPrintSession, &printer);
421 PMPrinterGetOutputResolution( printer, nativeData->m_macPrintSettings, &res) ;
422#else
8b285841 423 PMGetResolution((PMPageFormat) (nativeData->m_macPageFormat), &res);
4f74e0d1 424#endif
8b285841 425 printout->SetPPIPrinter(int(res.hRes), int(res.vRes));
1aa7b427
DS
426
427 // Set printout parameters
e40298d5 428 printout->SetDC(dc);
1aa7b427 429
e40298d5 430 int w, h;
e40298d5
JS
431 dc->GetSize(&w, &h);
432 printout->SetPageSizePixels((int)w, (int)h);
f415cab9
JS
433 printout->SetPaperRectPixels(dc->GetPaperRect());
434 wxCoord mw, mh;
435 dc->GetSizeMM(&mw, &mh);
436 printout->SetPageSizeMM((int)mw, (int)mh);
1aa7b427 437
e40298d5
JS
438 // Create an abort window
439 wxBeginBusyCursor();
1aa7b427 440
d2b354f9 441 printout->OnPreparePrinting();
1aa7b427 442
d2b354f9
JS
443 // Get some parameters from the printout, if defined
444 int fromPage, toPage;
445 int minPage, maxPage;
446 printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage);
1aa7b427 447
d2b354f9
JS
448 if (maxPage == 0)
449 {
450 wxEndBusyCursor();
1aa7b427 451 return false;
d2b354f9 452 }
1aa7b427 453
d2b354f9
JS
454 // Only set min and max, because from and to have been
455 // set by the user
456 m_printDialogData.SetMinPage(minPage);
457 m_printDialogData.SetMaxPage(maxPage);
1aa7b427 458
e40298d5
JS
459 wxWindow *win = CreateAbortWindow(parent, printout);
460 wxSafeYield(win,true);
1aa7b427 461
e40298d5
JS
462 if (!win)
463 {
464 wxEndBusyCursor();
427ff662 465 wxMessageBox(wxT("Sorry, could not create an abort dialog."), wxT("Print Error"), wxOK, parent);
e40298d5 466 delete dc;
1aa7b427
DS
467
468 return false;
e40298d5 469 }
1aa7b427 470
e40298d5 471 sm_abortWindow = win;
1aa7b427 472 sm_abortWindow->Show(true);
e40298d5 473 wxSafeYield(win,true);
1aa7b427 474
e40298d5 475 printout->OnBeginPrinting();
1aa7b427
DS
476
477 bool keepGoing = true;
478
e40298d5
JS
479 int copyCount;
480 for (copyCount = 1; copyCount <= m_printDialogData.GetNoCopies(); copyCount ++)
481 {
482 if (!printout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage()))
483 {
484 wxEndBusyCursor();
427ff662 485 wxMessageBox(wxT("Could not start printing."), wxT("Print Error"), wxOK, parent);
e40298d5
JS
486 break;
487 }
488 if (sm_abortIt)
489 break;
1aa7b427 490
e40298d5 491 int pn;
670f9935 492 for (pn = m_printDialogData.GetFromPage();
1aa7b427 493 keepGoing && (pn <= m_printDialogData.GetToPage()) && printout->HasPage(pn);
e40298d5
JS
494 pn++)
495 {
496 if (sm_abortIt)
497 {
1aa7b427 498 keepGoing = false;
e40298d5
JS
499 break;
500 }
501 else
502 {
03561a3c 503 wxSafeYield(win,true);
e40298d5
JS
504 dc->StartPage();
505 keepGoing = printout->OnPrintPage(pn);
506 dc->EndPage();
507 }
508 }
509 printout->OnEndDocument();
510 }
670f9935 511
e40298d5 512 printout->OnEndPrinting();
670f9935 513
e40298d5
JS
514 if (sm_abortWindow)
515 {
1aa7b427 516 sm_abortWindow->Show(false);
e40298d5
JS
517 delete sm_abortWindow;
518 sm_abortWindow = NULL;
519 }
670f9935 520
e40298d5 521 wxEndBusyCursor();
670f9935 522
e40298d5 523 delete dc;
670f9935 524
1aa7b427 525 return true;
72e7876b
SC
526}
527
528wxDC* wxMacPrinter::PrintDialog(wxWindow *parent)
529{
530 wxDC* dc = (wxDC*) NULL;
670f9935 531
72e7876b
SC
532 wxPrintDialog dialog(parent, & m_printDialogData);
533 int ret = dialog.ShowModal();
670f9935 534
72e7876b
SC
535 if (ret == wxID_OK)
536 {
537 dc = dialog.GetPrintDC();
538 m_printDialogData = dialog.GetPrintDialogData();
539 }
670f9935 540
72e7876b
SC
541 return dc;
542}
543
89954433 544bool wxMacPrinter::Setup(wxWindow *WXUNUSED(parent))
72e7876b 545{
04a014a5 546#if 0
72e7876b 547 wxPrintDialog dialog(parent, & m_printDialogData);
1aa7b427 548 dialog.GetPrintDialogData().SetSetupDialog(true);
670f9935 549
72e7876b 550 int ret = dialog.ShowModal();
670f9935 551
72e7876b 552 if (ret == wxID_OK)
72e7876b 553 m_printDialogData = dialog.GetPrintDialogData();
670f9935 554
72e7876b 555 return (ret == wxID_OK);
04a014a5 556#endif
1aa7b427 557
04a014a5 558 return wxID_CANCEL;
72e7876b
SC
559}
560
561/*
e40298d5
JS
562* Print preview
563*/
72e7876b
SC
564
565wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout,
e40298d5
JS
566 wxPrintout *printoutForPrinting,
567 wxPrintDialogData *data)
568 : wxPrintPreviewBase(printout, printoutForPrinting, data)
72e7876b
SC
569{
570 DetermineScaling();
571}
572
573wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data):
e40298d5 574wxPrintPreviewBase(printout, printoutForPrinting, data)
72e7876b 575{
e40298d5 576 DetermineScaling();
72e7876b
SC
577}
578
579wxMacPrintPreview::~wxMacPrintPreview(void)
580{
581}
582
583bool wxMacPrintPreview::Print(bool interactive)
584{
e40298d5 585 if (!m_printPrintout)
1aa7b427
DS
586 return false;
587
e40298d5
JS
588 wxMacPrinter printer(&m_printDialogData);
589 return printer.Print(m_previewFrame, m_printPrintout, interactive);
72e7876b
SC
590}
591
592void wxMacPrintPreview::DetermineScaling(void)
593{
e40298d5
JS
594 int screenWidth , screenHeight ;
595 wxDisplaySize( &screenWidth , &screenHeight ) ;
670f9935 596
aee23798
SC
597 wxSize ppiScreen( 72 , 72 ) ;
598 wxSize ppiPrinter( 72 , 72 ) ;
599
f415cab9 600 // Note that with Leopard, screen dpi=72 is no longer a given
aee23798
SC
601 m_previewPrintout->SetPPIScreen( ppiScreen.x , ppiScreen.y ) ;
602
f415cab9 603 wxCoord w , h ;
aee23798 604 wxCoord ww, hh;
f415cab9 605 wxRect paperRect;
670f9935 606
72e7876b 607 // Get a device context for the currently selected printer
2f1ae414 608 wxPrinterDC printerDC(m_printDialogData.GetPrintData());
888dde65 609 if (printerDC.IsOk())
72e7876b 610 {
e40298d5 611 printerDC.GetSizeMM(&ww, &hh);
f415cab9 612 printerDC.GetSize( &w , &h ) ;
aee23798 613 ppiPrinter = printerDC.GetPPI() ;
f415cab9 614 paperRect = printerDC.GetPaperRect();
e40298d5
JS
615 m_isOk = true ;
616 }
617 else
618 {
aee23798 619 // use some defaults
f415cab9
JS
620 w = 8 * 72 ;
621 h = 11 * 72 ;
622 ww = (wxCoord) (w * 25.4 / ppiPrinter.x) ;
623 hh = (wxCoord) (h * 25.4 / ppiPrinter.y) ;
624 paperRect = wxRect(0, 0, w, h);
e40298d5
JS
625 m_isOk = false ;
626 }
f415cab9
JS
627 m_pageWidth = w;
628 m_pageHeight = h;
629
630 m_previewPrintout->SetPageSizePixels(w , h) ;
631 m_previewPrintout->SetPageSizeMM(ww, hh);
632 m_previewPrintout->SetPaperRectPixels(paperRect);
aee23798 633 m_previewPrintout->SetPPIPrinter( ppiPrinter.x , ppiPrinter.y ) ;
1aa7b427 634
f415cab9
JS
635 m_previewScaleX = float(ppiScreen.x) / ppiPrinter.x;
636 m_previewScaleY = float(ppiScreen.y) / ppiPrinter.y;
72e7876b 637}
179e085f
RN
638
639#endif