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