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