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