]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/printmac.cpp
Fix for menu items not being disabled after a modal dialog is shown
[wxWidgets.git] / src / mac / carbon / printmac.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: printwin.cpp
3 // Purpose: wxMacPrinter framework
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "printwin.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/utils.h"
25 #include "wx/dc.h"
26 #include "wx/app.h"
27 #include "wx/msgdlg.h"
28 #endif
29
30 #include "wx/math.h"
31 #include "wx/mac/uma.h"
32
33 #include "wx/mac/printmac.h"
34 #include "wx/mac/private/print.h"
35
36 #include "wx/dcprint.h"
37 #include "wx/printdlg.h"
38 #include "wx/mac/printdlg.h"
39
40 #include <stdlib.h>
41
42 #if !USE_SHARED_LIBRARY
43 IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter, wxPrinterBase)
44 IMPLEMENT_CLASS(wxMacPrintPreview, wxPrintPreviewBase)
45 #endif
46
47 #if TARGET_CARBON
48
49 wxNativePrintData* wxNativePrintData::Create()
50 {
51 return new wxMacCarbonPrintData() ;
52 }
53
54 wxMacCarbonPrintData::wxMacCarbonPrintData()
55 {
56 m_macPageFormat = kPMNoPageFormat;
57 m_macPrintSettings = kPMNoPrintSettings;
58 m_macPrintSession = kPMNoReference ;
59 ValidateOrCreate() ;
60 }
61
62 wxMacCarbonPrintData::~wxMacCarbonPrintData()
63 {
64 if (m_macPageFormat != kPMNoPageFormat)
65 {
66 (void)PMRelease(m_macPageFormat);
67 m_macPageFormat = kPMNoPageFormat;
68 }
69
70 if (m_macPrintSettings != kPMNoPrintSettings)
71 {
72 (void)PMRelease(m_macPrintSettings);
73 m_macPrintSettings = kPMNoPrintSettings;
74 }
75
76 if ( m_macPrintSession != kPMNoReference )
77 {
78 (void)PMRelease(m_macPrintSession);
79 m_macPrintSession = kPMNoReference;
80 }
81 }
82
83 void wxMacCarbonPrintData::ValidateOrCreate()
84 {
85 OSStatus err = noErr ;
86 if ( m_macPrintSession == kPMNoReference )
87 {
88 err = PMCreateSession( (PMPrintSession *) &m_macPrintSession ) ;
89 }
90 // Set up a valid PageFormat object.
91 if ( m_macPageFormat == kPMNoPageFormat)
92 {
93 err = PMCreatePageFormat((PMPageFormat *) &m_macPageFormat);
94
95 // Note that PMPageFormat is not session-specific, but calling
96 // PMSessionDefaultPageFormat assigns values specific to the printer
97 // associated with the current printing session.
98 if ((err == noErr) &&
99 ( m_macPageFormat != kPMNoPageFormat))
100 {
101 err = PMSessionDefaultPageFormat((PMPrintSession) m_macPrintSession,
102 (PMPageFormat) m_macPageFormat);
103 }
104 }
105 else
106 {
107 err = PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession,
108 (PMPageFormat) m_macPageFormat,
109 kPMDontWantBoolean);
110 }
111
112 // Set up a valid PrintSettings object.
113 if ( m_macPrintSettings == kPMNoPrintSettings)
114 {
115 err = PMCreatePrintSettings((PMPrintSettings *) &m_macPrintSettings);
116
117 // Note that PMPrintSettings is not session-specific, but calling
118 // PMSessionDefaultPrintSettings assigns values specific to the printer
119 // associated with the current printing session.
120 if ((err == noErr) &&
121 ( m_macPrintSettings != kPMNoPrintSettings))
122 {
123 err = PMSessionDefaultPrintSettings((PMPrintSession) m_macPrintSession,
124 (PMPrintSettings) m_macPrintSettings);
125 }
126 }
127 else
128 {
129 err = PMSessionValidatePrintSettings((PMPrintSession) m_macPrintSession,
130 (PMPrintSettings) m_macPrintSettings,
131 kPMDontWantBoolean);
132 }
133 }
134
135 void wxMacCarbonPrintData::TransferFrom( wxPrintData* data )
136 {
137 ValidateOrCreate() ;
138 PMSetCopies( (PMPrintSettings) m_macPrintSettings , data->GetNoCopies() , false ) ;
139 PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data->GetOrientation() == wxLANDSCAPE ) ?
140 kPMLandscape : kPMPortrait , false ) ;
141 // collate cannot be set
142 #if 0 // not yet tested
143 if ( m_printerName.Length() > 0 )
144 PMSessionSetCurrentPrinter( (PMPrintSession) m_macPrintSession , wxMacCFStringHolder( m_printerName , wxFont::GetDefaultEncoding() ) ) ;
145 #endif
146 PMColorMode color ;
147 PMGetColorMode( (PMPrintSettings) m_macPrintSettings, &color ) ;
148 if ( data->GetColour() )
149 {
150 if ( color == kPMBlackAndWhite )
151 PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMColor ) ;
152 }
153 else
154 PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMBlackAndWhite ) ;
155
156 // PMDuplexMode not yet accessible via API
157 // PMQualityMode not yet accessible via API
158 // todo paperSize
159 }
160
161 void wxMacCarbonPrintData::TransferTo( wxPrintData* data )
162 {
163 OSStatus err = noErr ;
164
165 UInt32 copies ;
166 err = PMGetCopies( m_macPrintSettings , &copies ) ;
167 if ( err == noErr )
168 data->SetNoCopies( copies ) ;
169
170 PMOrientation orientation ;
171 err = PMGetOrientation( m_macPageFormat , &orientation ) ;
172 if ( err == noErr )
173 {
174 if ( orientation == kPMPortrait || orientation == kPMReversePortrait )
175 data->SetOrientation( wxPORTRAIT );
176 else
177 data->SetOrientation( wxLANDSCAPE );
178 }
179
180 // collate cannot be set
181 #if 0
182 {
183 wxMacCFStringHolder name ;
184 PMPrinter printer ;
185 PMSessionGetCurrentPrinter( m_macPrintSession ,
186 &printer ) ;
187 m_printerName = name.AsString() ;
188 }
189 #endif
190
191 PMColorMode color ;
192 err = PMGetColorMode( m_macPrintSettings, &color ) ;
193 if ( err == noErr )
194 data->SetColour( !(color == kPMBlackAndWhite) ) ;
195
196 // PMDuplexMode not yet accessible via API
197 // PMQualityMode not yet accessible via API
198 // todo paperSize
199 PMRect rPaper;
200 err = PMGetUnadjustedPaperRect( m_macPageFormat, &rPaper);
201 if ( err == noErr )
202 {
203 data->SetPaperSize( wxSize (
204 (int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) ,
205 (int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ) ) );
206 }
207 }
208
209 void wxMacCarbonPrintData::TransferFrom( wxPageSetupData *data )
210 {
211 // should we setup the page rect here ?
212 // since MacOS sometimes has two same paper rects with different
213 // page rects we could make it roundtrip safe perhaps
214 #if TARGET_CARBON
215 #else
216 #endif
217 }
218
219 void wxMacCarbonPrintData::TransferTo( wxPageSetupData* data )
220 {
221 PMRect rPaper;
222 OSStatus err = PMGetUnadjustedPaperRect(m_macPageFormat, &rPaper);
223 if ( err == noErr )
224 {
225 PMRect rPage ;
226 err = PMGetUnadjustedPageRect(m_macPageFormat , &rPage ) ;
227 if ( err == noErr )
228 {
229 data->SetMinMarginTopLeft( wxPoint (
230 (int)(((double) rPage.left - rPaper.left ) * pt2mm) ,
231 (int)(((double) rPage.top - rPaper.top ) * pt2mm) ) ) ;
232
233 data->SetMinMarginBottomRight( wxPoint (
234 (wxCoord)(((double) rPaper.right - rPage.right ) * pt2mm),
235 (wxCoord)(((double) rPaper.bottom - rPage.bottom ) * pt2mm)) ) ;
236 }
237 }
238 }
239
240 void wxMacCarbonPrintData::TransferTo( wxPrintDialogData* data )
241 {
242 UInt32 minPage , maxPage ;
243 PMGetPageRange( m_macPrintSettings , &minPage , &maxPage ) ;
244 data->SetMinPage( minPage ) ;
245 data->SetMaxPage( maxPage ) ;
246 UInt32 copies ;
247 PMGetCopies( m_macPrintSettings , &copies ) ;
248 data->SetNoCopies( copies ) ;
249 UInt32 from , to ;
250 PMGetFirstPage( m_macPrintSettings , &from ) ;
251 PMGetLastPage( m_macPrintSettings , &to ) ;
252 data->SetFromPage( from ) ;
253 data->SetToPage( to ) ;
254 }
255
256 void wxMacCarbonPrintData::TransferFrom( wxPrintDialogData* data )
257 {
258 PMSetPageRange( m_macPrintSettings , data->GetMinPage() , data->GetMaxPage() ) ;
259 PMSetCopies( m_macPrintSettings , data->GetNoCopies() , false ) ;
260 PMSetFirstPage( m_macPrintSettings , data->GetFromPage() , false ) ;
261
262 int toPage = data->GetToPage();
263 if (toPage < 1)
264 toPage = data->GetFromPage();
265 PMSetLastPage( m_macPrintSettings , toPage , false ) ;
266 }
267
268 void wxMacCarbonPrintData::CopyFrom( wxNativePrintData* d )
269 {
270 wxMacCarbonPrintData *data = (wxMacCarbonPrintData*) d ;
271 if ( data->m_macPrintSession != kPMNoReference )
272 PMRetain( data->m_macPrintSession ) ;
273 if ( m_macPrintSession != kPMNoReference )
274 {
275 PMRelease( m_macPrintSession ) ;
276 m_macPrintSession = kPMNoReference ;
277 }
278 if ( data->m_macPrintSession != kPMNoReference )
279 m_macPrintSession = data->m_macPrintSession ;
280
281 if ( data->m_macPrintSettings != kPMNoPrintSettings )
282 PMRetain( data->m_macPrintSettings ) ;
283 if ( m_macPrintSettings != kPMNoPrintSettings )
284 {
285 PMRelease( m_macPrintSettings ) ;
286 m_macPrintSettings = kPMNoPrintSettings ;
287 }
288 if ( data->m_macPrintSettings != kPMNoPrintSettings )
289 m_macPrintSettings = data->m_macPrintSettings ;
290
291 if ( data->m_macPageFormat != kPMNoPageFormat )
292 PMRetain( data->m_macPageFormat ) ;
293 if ( m_macPageFormat != kPMNoPageFormat )
294 {
295 PMRelease( m_macPageFormat ) ;
296 m_macPageFormat = kPMNoPageFormat ;
297 }
298 if ( data->m_macPageFormat != kPMNoPageFormat )
299 m_macPageFormat = data->m_macPageFormat ;
300 }
301
302 int wxMacCarbonPrintData::ShowPrintDialog()
303 {
304 int result = wxID_CANCEL ;
305 OSErr err = noErr ;
306 wxString message ;
307
308 Boolean accepted;
309
310 {
311 // Display the Print dialog.
312 if (err == noErr)
313 {
314 err = PMSessionPrintDialog( m_macPrintSession,
315 m_macPrintSettings,
316 m_macPageFormat,
317 &accepted);
318 if ((err == noErr) && !accepted)
319 {
320 err = kPMCancel; // user clicked Cancel button
321 }
322 }
323 if ( err == noErr )
324 {
325 result = wxID_OK ;
326 }
327 }
328 if ((err != noErr) && (err != kPMCancel))
329 {
330 message.Printf( wxT("Print Error %d"), err ) ;
331 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
332 dialog.ShowModal();
333 }
334
335 return result ;
336 }
337
338 int wxMacCarbonPrintData::ShowPageSetupDialog()
339 {
340 int result = wxID_CANCEL ;
341 OSErr err = noErr ;
342 wxString message ;
343
344 Boolean accepted;
345 {
346 // Display the Page Setup dialog.
347 if (err == noErr)
348 {
349 err = PMSessionPageSetupDialog( m_macPrintSession,
350 m_macPageFormat,
351 &accepted);
352 if ((err == noErr) && !accepted)
353 {
354 err = kPMCancel; // user clicked Cancel button
355 }
356 }
357
358 // If the user did not cancel, flatten and save the PageFormat object
359 // with our document.
360 if (err == noErr) {
361 result = wxID_OK ;
362 }
363 }
364 if ((err != noErr) && (err != kPMCancel))
365 {
366 message.Printf( wxT("Print Error %d"), err ) ;
367 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
368 dialog.ShowModal();
369 }
370
371 return result ;
372 }
373
374 #else
375
376 wxNativePrintData* wxNativePrintData::Create()
377 {
378 return new wxMacClassicPrintData() ;
379 }
380
381 wxMacClassicPrintData::wxMacClassicPrintData()
382 {
383 m_macPrintSettings = NULL ;
384 ValidateOrCreate() ;
385 }
386
387 wxMacClassicPrintData::~wxMacClassicPrintData()
388 {
389 wxASSERT( m_macPrintSettings );
390 DisposeHandle( (Handle) m_macPrintSettings ) ;
391 }
392
393 void wxMacClassicPrintData::ValidateOrCreate()
394 {
395 if ( m_macPrintSettings == NULL )
396 {
397 m_macPrintSettings = (THPrint) NewHandleClear( sizeof( TPrint ) );
398 (**m_macPrintSettings).iPrVersion = 0; // something invalid
399
400 (**m_macPrintSettings).prInfo.iHRes = 72;
401 (**m_macPrintSettings).prInfo.iVRes = 72;
402 Rect r1 = { 0, 0, 8*72 - 2 * 18, 11*72 - 2 * 36 };
403 (**m_macPrintSettings).prInfo.rPage = r1;// must have its top left & (0,0)
404
405 Rect r2 = { -18, -36, 8*72 - 18, 11*72 - 36 };
406 (**m_macPrintSettings).rPaper = r2;
407 (**m_macPrintSettings).prStl.iPageV = 11 * 120 ; // 11 inches in 120th of an inch
408 (**m_macPrintSettings).prStl.iPageH = 8 * 120 ; // 8 inches in 120th of an inch
409 }
410 else
411 {
412 }
413 }
414
415 void wxMacClassicPrintData::TransferFrom( wxPrintData* data )
416 {
417 ValidateOrCreate() ;
418 (**m_macPrintSettings).prJob.iCopies = data->GetNoCopies() ;
419 // on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0
420 // if all printing data is consolidated in on structure we will be able to set additional infos about pages
421 }
422
423 void wxMacClassicPrintData::TransferTo( wxPrintData* data )
424 {
425 data->SetNoCopies( (**m_macPrintSettings).prJob.iCopies );
426 data->SetPaperSize( wxSize(
427 ((double) (**m_macPrintSettings).rPaper.right - (**m_macPrintSettings).rPaper.left ) * pt2mm ,
428 ((double) (**m_macPrintSettings).rPaper.bottom - (**m_macPrintSettings).rPaper.top ) * pt2mm ) ) ;
429 }
430
431 void wxMacClassicPrintData::TransferFrom( wxPageSetupData *data )
432 {
433 }
434
435 void wxMacClassicPrintData::TransferTo( wxPageSetupData* data )
436 {
437 data->SetMinMarginTopLeft( wxPoint(
438 ((double) (**m_macPrintSettings).prInfo.rPage.left -(**m_macPrintSettings).rPaper.left ) * pt2mm ,
439 ((double) (**m_macPrintSettings).prInfo.rPage.top -(**m_macPrintSettings).rPaper.top ) * pt2mm ) ) ;
440 data->SetMinMarginBottomRight( wxPoint(
441 ((double) (**m_macPrintSettings).rPaper.right - (**m_macPrintSettings).prInfo.rPage.right ) * pt2mm ,
442 ((double)(**m_macPrintSettings).rPaper.bottom - (**m_macPrintSettings).prInfo.rPage.bottom ) * pt2mm ) ) ;
443 }
444
445 void wxMacClassicPrintData::TransferFrom( wxPrintDialogData* data )
446 {
447 int toPage = data->GetToPage();
448 if (toPage < 1)
449 toPage = data->GetFromPage();
450 (**m_macPrintSettings).prJob.iFstPage = data->GetFromPage() ;
451 (**m_macPrintSettings).prJob.iLstPage = toPage;
452 }
453
454 void wxMacClassicPrintData::TransferTo( wxPrintDialogData* data )
455 {
456 data->SetFromPage( (**m_macPrintSettings).prJob.iFstPage ) ;
457 data->SetToPage( (**m_macPrintSettings).prJob.iLstPage ) ;
458 }
459
460 void wxMacClassicPrintData::CopyFrom( wxNativePrintData* data )
461 {
462 DisposeHandle( (Handle) m_macPrintSettings ) ;
463 m_macPrintSettings = ((wxMacClassicPrintData*)data)->m_macPrintSettings;
464 HandToHand( (Handle*) &m_macPrintSettings );
465 }
466
467 int wxMacClassicPrintData::ShowPrintDialog()
468 {
469 int result = wxID_CANCEL ;
470 OSErr err = noErr ;
471 wxString message ;
472
473 err = ::UMAPrOpen() ;
474 if ( err == noErr )
475 {
476 if ( ::PrJobDialog( m_macPrintSettings ) )
477 {
478 result = wxID_OK ;
479 }
480
481 }
482 else
483 {
484 message.Printf( wxT("Print Error %d"), err ) ;
485 wxMessageDialog dialog( NULL , message , wxT(""), wxICON_HAND | wxOK) ;
486 dialog.ShowModal();
487 }
488 ::UMAPrClose() ;
489
490 return result ;
491 }
492
493 int wxMacClassicPrintData::ShowPageSetupDialog()
494 {
495 int result = wxID_CANCEL ;
496 OSErr err = noErr ;
497 wxString message ;
498
499 err = ::UMAPrOpen() ;
500 if ( err == noErr )
501 {
502 if ( ::PrStlDialog( m_macPrintSettings ) )
503 {
504 result = wxID_OK ;
505 }
506
507 }
508 else
509 {
510 message.Printf( wxT("Print Error %d"), err ) ;
511 wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
512 dialog.ShowModal();
513 }
514 ::UMAPrClose() ;
515 return result ;
516 }
517
518 #endif
519
520 /*
521 * Printer
522 */
523
524 wxMacPrinter::wxMacPrinter(wxPrintDialogData *data):
525 wxPrinterBase(data)
526 {
527 }
528
529 wxMacPrinter::~wxMacPrinter(void)
530 {
531 }
532
533 bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
534 {
535 sm_abortIt = FALSE;
536 sm_abortWindow = NULL;
537
538 if (!printout)
539 return FALSE;
540
541 printout->SetIsPreview(FALSE);
542 if (m_printDialogData.GetMinPage() < 1)
543 m_printDialogData.SetMinPage(1);
544 if (m_printDialogData.GetMaxPage() < 1)
545 m_printDialogData.SetMaxPage(9999);
546
547 // Create a suitable device context
548 wxDC *dc = NULL;
549 if (prompt)
550 {
551 wxPrintDialog dialog(parent, & m_printDialogData);
552 if (dialog.ShowModal() == wxID_OK)
553 {
554 dc = dialog.GetPrintDC();
555 m_printDialogData = dialog.GetPrintDialogData();
556 }
557 }
558 else
559 {
560 dc = new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
561 }
562
563
564 // May have pressed cancel.
565 if (!dc || !dc->Ok())
566 {
567 if (dc) delete dc;
568 return FALSE;
569 }
570
571 // on the mac we have always pixels as addressing mode with 72 dpi
572
573 printout->SetPPIScreen(72, 72);
574 printout->SetPPIPrinter(72, 72);
575
576 // Set printout parameters
577 printout->SetDC(dc);
578
579 int w, h;
580 wxCoord ww, hh;
581 dc->GetSize(&w, &h);
582 printout->SetPageSizePixels((int)w, (int)h);
583 dc->GetSizeMM(&ww, &hh);
584 printout->SetPageSizeMM((int)ww, (int)hh);
585
586 // Create an abort window
587 wxBeginBusyCursor();
588
589 printout->OnPreparePrinting();
590
591 // Get some parameters from the printout, if defined
592 int fromPage, toPage;
593 int minPage, maxPage;
594 printout->GetPageInfo(&minPage, &maxPage, &fromPage, &toPage);
595
596 if (maxPage == 0)
597 {
598 wxEndBusyCursor();
599 return FALSE;
600 }
601
602 // Only set min and max, because from and to have been
603 // set by the user
604 m_printDialogData.SetMinPage(minPage);
605 m_printDialogData.SetMaxPage(maxPage);
606
607 wxWindow *win = CreateAbortWindow(parent, printout);
608 wxSafeYield(win,true);
609
610 if (!win)
611 {
612 wxEndBusyCursor();
613 wxMessageBox(wxT("Sorry, could not create an abort dialog."), wxT("Print Error"), wxOK, parent);
614 delete dc;
615 return FALSE;
616 }
617 sm_abortWindow = win;
618 sm_abortWindow->Show(TRUE);
619 wxSafeYield(win,true);
620
621 printout->OnBeginPrinting();
622
623 bool keepGoing = TRUE;
624
625 int copyCount;
626 for (copyCount = 1; copyCount <= m_printDialogData.GetNoCopies(); copyCount ++)
627 {
628 if (!printout->OnBeginDocument(m_printDialogData.GetFromPage(), m_printDialogData.GetToPage()))
629 {
630 wxEndBusyCursor();
631 wxMessageBox(wxT("Could not start printing."), wxT("Print Error"), wxOK, parent);
632 break;
633 }
634 if (sm_abortIt)
635 break;
636
637 int pn;
638 for (pn = m_printDialogData.GetFromPage(); keepGoing && (pn <= m_printDialogData.GetToPage()) && printout->HasPage(pn);
639 pn++)
640 {
641 if (sm_abortIt)
642 {
643 keepGoing = FALSE;
644 break;
645 }
646 else
647 {
648 #if TARGET_CARBON
649 if ( UMAGetSystemVersion() >= 0x1000 )
650 #endif
651 {
652 GrafPtr thePort ;
653 GetPort( &thePort ) ;
654 wxSafeYield(win,true);
655 SetPort( thePort ) ;
656 }
657 dc->StartPage();
658 keepGoing = printout->OnPrintPage(pn);
659 dc->EndPage();
660 }
661 }
662 printout->OnEndDocument();
663 }
664
665 printout->OnEndPrinting();
666
667 if (sm_abortWindow)
668 {
669 sm_abortWindow->Show(FALSE);
670 delete sm_abortWindow;
671 sm_abortWindow = NULL;
672 }
673
674 wxEndBusyCursor();
675
676 delete dc;
677
678 return TRUE;
679 }
680
681 wxDC* wxMacPrinter::PrintDialog(wxWindow *parent)
682 {
683 wxDC* dc = (wxDC*) NULL;
684
685 wxPrintDialog dialog(parent, & m_printDialogData);
686 int ret = dialog.ShowModal();
687
688 if (ret == wxID_OK)
689 {
690 dc = dialog.GetPrintDC();
691 m_printDialogData = dialog.GetPrintDialogData();
692 }
693
694 return dc;
695 }
696
697 bool wxMacPrinter::Setup(wxWindow *parent)
698 {
699 #if 0
700 wxPrintDialog dialog(parent, & m_printDialogData);
701 dialog.GetPrintDialogData().SetSetupDialog(TRUE);
702
703 int ret = dialog.ShowModal();
704
705 if (ret == wxID_OK)
706 {
707 m_printDialogData = dialog.GetPrintDialogData();
708 }
709
710 return (ret == wxID_OK);
711 #endif
712 return wxID_CANCEL;
713 }
714
715 /*
716 * Print preview
717 */
718
719 wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout,
720 wxPrintout *printoutForPrinting,
721 wxPrintDialogData *data)
722 : wxPrintPreviewBase(printout, printoutForPrinting, data)
723 {
724 DetermineScaling();
725 }
726
727 wxMacPrintPreview::wxMacPrintPreview(wxPrintout *printout, wxPrintout *printoutForPrinting, wxPrintData *data):
728 wxPrintPreviewBase(printout, printoutForPrinting, data)
729 {
730 DetermineScaling();
731 }
732
733 wxMacPrintPreview::~wxMacPrintPreview(void)
734 {
735 }
736
737 bool wxMacPrintPreview::Print(bool interactive)
738 {
739 if (!m_printPrintout)
740 return FALSE;
741 wxMacPrinter printer(&m_printDialogData);
742 return printer.Print(m_previewFrame, m_printPrintout, interactive);
743 }
744
745 void wxMacPrintPreview::DetermineScaling(void)
746 {
747 int screenWidth , screenHeight ;
748 wxDisplaySize( &screenWidth , &screenHeight ) ;
749
750 m_previewPrintout->SetPPIScreen( 72 , 72 ) ;
751 m_previewPrintout->SetPPIPrinter( 72 , 72 ) ;
752 m_previewPrintout->SetPageSizeMM( (int) (8.0 * 25.6), (int) (11.0 * 25.6) );
753 m_previewPrintout->SetPageSizePixels( 8 * 72 , 11 * 72 ) ;
754 m_pageWidth = 8 * 72 ;
755 m_pageHeight = 11 * 72 ;
756 m_previewScale = 1 ;
757
758 // Get a device context for the currently selected printer
759 wxPrinterDC printerDC(m_printDialogData.GetPrintData());
760 if (printerDC.Ok())
761 {
762 int x , y ;
763 wxCoord ww, hh;
764 printerDC.GetSizeMM(&ww, &hh);
765 printerDC.GetSize( &x , &y ) ;
766 m_previewPrintout->SetPageSizeMM((int)ww, (int)hh);
767 m_previewPrintout->SetPageSizePixels( x , y) ;
768 m_pageWidth = x ;
769 m_pageHeight = y ;
770 m_isOk = true ;
771 }
772 else
773 {
774 m_isOk = false ;
775 }
776 // At 100%, the page should look about page-size on the screen.
777 // m_previewScale = (float)((float)screenWidth/(float)printerWidth);
778 // m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerXRes);
779
780 m_previewScale = 1 ;
781 }