]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/printdlg.cpp
should have been part of r74664: Avoid calling gtk_window_get_position() from "config...
[wxWidgets.git] / src / osx / carbon / printdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/printdlg.cpp
3 // Purpose: wxPrintDialog, wxPageSetupDialog
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #if wxUSE_PRINTING_ARCHITECTURE
14
15 #include "wx/printdlg.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/object.h"
19 #include "wx/dcprint.h"
20 #include "wx/msgdlg.h"
21 #include "wx/textctrl.h"
22 #include "wx/sizer.h"
23 #include "wx/stattext.h"
24 #endif
25
26 #include "wx/osx/printdlg.h"
27 #include "wx/osx/private/print.h"
28 #include "wx/osx/private.h"
29 #include "wx/statline.h"
30 #include "wx/modalhook.h"
31
32 int wxMacPrintDialog::ShowModal()
33 {
34 WX_HOOK_MODAL_DIALOG();
35
36 m_printDialogData.GetPrintData().ConvertToNative();
37 ((wxOSXPrintData*)m_printDialogData.GetPrintData().GetNativeData())->TransferFrom( &m_printDialogData );
38
39 int result = wxID_CANCEL;
40
41 OSErr err = noErr;
42 Boolean accepted;
43 wxOSXPrintData* nativeData = (wxOSXPrintData*)m_printDialogData.GetPrintData().GetNativeData();
44 wxDialog::OSXBeginModalDialog();
45 err = PMSessionPrintDialog(nativeData->GetPrintSession(), nativeData->GetPrintSettings(),
46 nativeData->GetPageFormat(), &accepted );
47 wxDialog::OSXEndModalDialog();
48
49 if ((err == noErr) && !accepted)
50 {
51 // user clicked Cancel button
52 err = kPMCancel;
53 }
54
55 if (err == noErr)
56 {
57 result = wxID_OK;
58 }
59
60 if ((err != noErr) && (err != kPMCancel))
61 {
62 wxString message;
63
64 message.Printf( wxT("Print Error %d"), err );
65 wxMessageDialog dialog( NULL, message, wxEmptyString, wxICON_HAND | wxOK );
66 dialog.ShowModal();
67 }
68
69 if (result == wxID_OK)
70 {
71 m_printDialogData.GetPrintData().ConvertFromNative();
72 ((wxOSXPrintData*)m_printDialogData.GetPrintData().GetNativeData())->TransferTo( &m_printDialogData );
73 }
74 return result;
75 }
76
77 int wxMacPageSetupDialog::ShowModal()
78 {
79 WX_HOOK_MODAL_DIALOG();
80
81 m_pageSetupData.GetPrintData().ConvertToNative();
82 wxOSXPrintData* nativeData = (wxOSXPrintData*)m_pageSetupData.GetPrintData().GetNativeData();
83 nativeData->TransferFrom( &m_pageSetupData );
84
85 int result = wxID_CANCEL;
86 OSErr err = noErr;
87 Boolean accepted;
88
89 wxDialog::OSXBeginModalDialog();
90 err = PMSessionPageSetupDialog( nativeData->GetPrintSession(), nativeData->GetPageFormat(),
91 &accepted );
92 wxDialog::OSXEndModalDialog();
93
94 if ((err == noErr) && !accepted)
95 {
96 // user clicked Cancel button
97 err = kPMCancel;
98 }
99
100 // If the user did not cancel, flatten and save the PageFormat object
101 // with our document.
102 if (err == noErr)
103 {
104 result = wxID_OK;
105 }
106
107 if ((err != noErr) && (err != kPMCancel))
108 {
109 wxString message;
110
111 message.Printf( wxT("Print Error %d"), err );
112 wxMessageDialog dialog( NULL, message, wxEmptyString, wxICON_HAND | wxOK );
113 dialog.ShowModal();
114 }
115
116 if (result == wxID_OK)
117 {
118 m_pageSetupData.GetPrintData().ConvertFromNative();
119 m_pageSetupData.SetPaperSize( m_pageSetupData.GetPrintData().GetPaperSize() );
120 nativeData->TransferTo( &m_pageSetupData );
121 }
122 return result;
123 }
124
125 #endif