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