]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/printdlg.cpp
Commented out call that breaks metal style setting before Create
[wxWidgets.git] / src / mac / carbon / printdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/printdlg.cpp
3 // Purpose: wxPrintDialog, wxPageSetupDialog
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #if wxUSE_PRINTING_ARCHITECTURE
15
16 #include "wx/object.h"
17 #include "wx/printdlg.h"
18 #include "wx/mac/printdlg.h"
19 #include "wx/dcprint.h"
20 #include "wx/msgdlg.h"
21 #include "wx/mac/private/print.h"
22
23
24 // Use generic page setup dialog: use your own native one if one exists.
25
26 IMPLEMENT_DYNAMIC_CLASS(wxMacPrintDialog, wxPrintDialogBase)
27
28
29 wxMacPrintDialog::wxMacPrintDialog()
30 {
31 m_dialogParent = NULL;
32 m_printerDC = NULL;
33 m_destroyDC = true;
34 }
35
36 wxMacPrintDialog::wxMacPrintDialog( wxWindow *p, wxPrintDialogData *data )
37 {
38 Create( p, data );
39 }
40
41 wxMacPrintDialog::wxMacPrintDialog( wxWindow *p, wxPrintData *data )
42 {
43 wxPrintDialogData data2;
44 if (data != NULL)
45 data2 = *data;
46
47 Create( p, &data2 );
48 }
49
50 bool wxMacPrintDialog::Create( wxWindow *p, wxPrintDialogData *data )
51 {
52 m_dialogParent = p;
53 m_printerDC = NULL;
54 m_destroyDC = true;
55
56 if (data != NULL)
57 m_printDialogData = *data;
58
59 return true;
60 }
61
62 wxMacPrintDialog::~wxMacPrintDialog()
63 {
64 if (m_destroyDC && m_printerDC)
65 {
66 delete m_printerDC;
67 m_printerDC = NULL;
68 }
69 }
70
71 int wxMacPrintDialog::ShowModal()
72 {
73 m_printDialogData.GetPrintData().ConvertToNative();
74 ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->TransferFrom( &m_printDialogData );
75
76 int result = wxID_CANCEL;
77 OSErr err = noErr;
78 Boolean accepted;
79
80 err = PMSessionPrintDialog(
81 ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->m_macPrintSession,
82 ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->m_macPrintSettings,
83 ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->m_macPageFormat,
84 &accepted );
85
86 if ((err == noErr) && !accepted)
87 {
88 // user clicked Cancel button
89 err = kPMCancel;
90 }
91
92 if (err == noErr)
93 {
94 result = wxID_OK;
95 }
96
97 if ((err != noErr) && (err != kPMCancel))
98 {
99 wxString message;
100
101 message.Printf( wxT("Print Error %d"), err );
102 wxMessageDialog dialog( NULL, message, wxEmptyString, wxICON_HAND | wxOK );
103 dialog.ShowModal();
104 }
105
106 if (result == wxID_OK)
107 {
108 m_printDialogData.GetPrintData().ConvertFromNative();
109 ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->TransferTo( &m_printDialogData );
110 }
111
112 return result;
113 }
114
115 wxDC * wxMacPrintDialog::GetPrintDC()
116 {
117 return new wxPrinterDC( m_printDialogData.GetPrintData() );
118 }
119
120 IMPLEMENT_CLASS(wxMacPageSetupDialog, wxPageSetupDialogBase)
121
122 wxMacPageSetupDialog::wxMacPageSetupDialog( wxWindow *p, wxPageSetupDialogData *data )
123 : wxPageSetupDialogBase()
124 {
125 Create( p, data );
126 }
127
128 bool wxMacPageSetupDialog::Create( wxWindow *p, wxPageSetupDialogData *data )
129 {
130 m_dialogParent = p;
131
132 if (data != NULL)
133 m_pageSetupData = (*data);
134
135 return true;
136 }
137
138 wxMacPageSetupDialog::~wxMacPageSetupDialog()
139 {
140 }
141
142 wxPageSetupData& wxMacPageSetupDialog::GetPageSetupDialogData()
143 {
144 return m_pageSetupData;
145 }
146
147 int wxMacPageSetupDialog::ShowModal()
148 {
149 m_pageSetupData.GetPrintData().ConvertToNative();
150 ((wxMacCarbonPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->TransferFrom( &m_pageSetupData );
151
152 int result = wxID_CANCEL;
153 OSErr err = noErr;
154 Boolean accepted;
155
156 err = PMSessionPageSetupDialog(
157 ((wxMacCarbonPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->m_macPrintSession,
158 ((wxMacCarbonPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->m_macPageFormat,
159 &accepted );
160
161 if ((err == noErr) && !accepted)
162 {
163 // user clicked Cancel button
164 err = kPMCancel;
165 }
166
167 // If the user did not cancel, flatten and save the PageFormat object
168 // with our document.
169 if (err == noErr)
170 {
171 result = wxID_OK;
172 }
173
174 if ((err != noErr) && (err != kPMCancel))
175 {
176 wxString message;
177
178 message.Printf( wxT("Print Error %d"), err );
179 wxMessageDialog dialog( NULL, message, wxEmptyString, wxICON_HAND | wxOK );
180 dialog.ShowModal();
181 }
182
183 if (result == wxID_OK)
184 {
185 m_pageSetupData.GetPrintData().ConvertFromNative();
186 m_pageSetupData.SetPaperSize( m_pageSetupData.GetPrintData().GetPaperSize() );
187 ((wxMacCarbonPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->TransferTo( &m_pageSetupData );
188 }
189
190 return result;
191 }
192
193 #endif