]> git.saurik.com Git - wxWidgets.git/blob - src/mac/printdlg.cpp
Changed the pragmas to allow debugging under Linux
[wxWidgets.git] / src / mac / printdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: printdlg.cpp
3 // Purpose: wxPrintDialog, wxPageSetupDialog
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "printdlg.h"
14 #endif
15
16 #include "wx/object.h"
17 #include "wx/printdlg.h"
18 #include "wx/dcprint.h"
19 #include "wx/msgdlg.h"
20 #include "wx/mac/uma.h"
21
22 // Use generic page setup dialog: use your own native one if one exists.
23
24 #if !USE_SHARED_LIBRARY
25 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog)
26 IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog)
27 #endif
28
29 wxPrintDialog::wxPrintDialog()
30 {
31 m_dialogParent = NULL;
32 m_printerDC = NULL;
33 m_destroyDC = TRUE;
34 }
35
36 wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintDialogData* data)
37 {
38 Create(p, data);
39 }
40
41 wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintData* data)
42 {
43 wxPrintDialogData data2;
44 if ( data )
45 data2 = *data;
46
47 Create(p, &data2);
48 }
49
50 bool wxPrintDialog::Create(wxWindow *p, wxPrintDialogData* data)
51 {
52 m_dialogParent = p;
53 m_printerDC = NULL;
54 m_destroyDC = TRUE;
55
56 if ( data )
57 m_printDialogData = *data;
58
59 return TRUE;
60 }
61
62 wxPrintDialog::~wxPrintDialog()
63 {
64 if (m_destroyDC && m_printerDC)
65 delete m_printerDC;
66 }
67
68 int wxPrintDialog::ShowModal()
69 {
70 int result = wxID_CANCEL ;
71 OSErr err ;
72 wxString message ;
73
74 #if !TARGET_CARBON
75 err = ::UMAPrOpen() ;
76 if ( err == noErr )
77 {
78 m_printDialogData.ConvertToNative() ;
79 if ( ::PrJobDialog( m_printDialogData.GetPrintData().m_macPrintInfo ) )
80 {
81 m_printDialogData.ConvertFromNative() ;
82 result = wxID_OK ;
83 }
84
85 }
86 else
87 {
88 message.Printf( "Print Error %d", err ) ;
89 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
90 dialog.ShowModal();
91 }
92 ::UMAPrClose() ;
93 #else
94 #if PM_USE_SESSION_APIS
95 PMPrintSession macPrintSession = kPMNoReference;
96 Boolean accepted;
97
98 err = ::UMAPrOpen(&macPrintSession) ;
99 if ( err == noErr )
100 {
101 m_printDialogData.ConvertToNative() ;
102
103 // Set up a valid PageFormat object.
104 if (m_printDialogData.GetPrintData().m_macPageFormat == kPMNoPageFormat)
105 {
106 err = PMCreatePageFormat(&m_printDialogData.GetPrintData().m_macPageFormat);
107
108 // Note that PMPageFormat is not session-specific, but calling
109 // PMSessionDefaultPageFormat assigns values specific to the printer
110 // associated with the current printing session.
111 if ((err == noErr) &&
112 (m_printDialogData.GetPrintData().m_macPageFormat != kPMNoPageFormat))
113 {
114 err = PMSessionDefaultPageFormat(macPrintSession,
115 m_printDialogData.GetPrintData().m_macPageFormat);
116 }
117 }
118 else
119 {
120 err = PMSessionValidatePageFormat(macPrintSession,
121 m_printDialogData.GetPrintData().m_macPageFormat,
122 kPMDontWantBoolean);
123 }
124
125 // Set up a valid PrintSettings object.
126 if (m_printDialogData.GetPrintData().m_macPrintSettings == kPMNoPrintSettings)
127 {
128 err = PMCreatePrintSettings(&m_printDialogData.GetPrintData().m_macPrintSettings);
129
130 // Note that PMPrintSettings is not session-specific, but calling
131 // PMSessionDefaultPrintSettings assigns values specific to the printer
132 // associated with the current printing session.
133 if ((err == noErr) &&
134 (m_printDialogData.GetPrintData().m_macPrintSettings != kPMNoPrintSettings))
135 {
136 err = PMSessionDefaultPrintSettings(macPrintSession,
137 m_printDialogData.GetPrintData().m_macPrintSettings);
138 }
139 }
140 else
141 {
142 err = PMSessionValidatePrintSettings(macPrintSession,
143 m_printDialogData.GetPrintData().m_macPrintSettings,
144 kPMDontWantBoolean);
145 }
146 // Set a valid page range before displaying the Print dialog
147 if (err == noErr)
148 {
149 // err = PMSetPageRange(m_printDialogData.GetPrintData().m_macPrintSettings,
150 // minPage, maxPage);
151 }
152
153 // Display the Print dialog.
154 if (err == noErr)
155 {
156 err = PMSessionPrintDialog(macPrintSession,
157 m_printDialogData.GetPrintData().m_macPrintSettings,
158 m_printDialogData.GetPrintData().m_macPageFormat,
159 &accepted);
160 if ((err == noErr) && !accepted)
161 {
162 err = kPMCancel; // user clicked Cancel button
163 }
164 }
165 if ( err == noErr )
166 {
167 m_printDialogData.ConvertFromNative() ;
168 result = wxID_OK ;
169 }
170 }
171 if ((err != noErr) && (err != kPMCancel))
172 {
173 message.Printf( "Print Error %d", err ) ;
174 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
175 dialog.ShowModal();
176 }
177 ::UMAPrClose(&macPrintSession) ;
178 #else
179 #pragma warning "TODO: Printing for carbon without session apis"
180 #endif
181 #endif
182 return result ;
183 }
184
185 wxDC *wxPrintDialog::GetPrintDC()
186 {
187 return new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
188 }
189
190 /*
191 * wxPageSetupDialog
192 */
193
194 wxPageSetupDialog::wxPageSetupDialog():
195 wxDialog()
196 {
197 m_dialogParent = NULL;
198 }
199
200 wxPageSetupDialog::wxPageSetupDialog(wxWindow *p, wxPageSetupData *data):
201 wxDialog()
202 {
203 Create(p, data);
204 }
205
206 bool wxPageSetupDialog::Create(wxWindow *p, wxPageSetupData *data)
207 {
208 m_dialogParent = p;
209
210 if (data)
211 m_pageSetupData = (*data);
212
213 return TRUE;
214 }
215
216 wxPageSetupDialog::~wxPageSetupDialog()
217 {
218 }
219
220 int wxPageSetupDialog::ShowModal()
221 {
222 int result = wxID_CANCEL ;
223 OSErr err ;
224 wxString message ;
225
226 #if !TARGET_CARBON
227 err = ::UMAPrOpen() ;
228 if ( err == noErr )
229 {
230 m_pageSetupData.ConvertToNative() ;
231 if ( ::PrStlDialog( m_pageSetupData.GetPrintData().m_macPrintInfo ) )
232 {
233 m_pageSetupData.ConvertFromNative() ;
234 result = wxID_OK ;
235 }
236
237 }
238 else
239 {
240 message.Printf( "Print Error %d", err ) ;
241 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
242 dialog.ShowModal();
243 }
244 ::UMAPrClose() ;
245 #else
246 #if PM_USE_SESSION_APIS
247 PMPrintSession macPrintSession = kPMNoReference;
248 Boolean accepted;
249
250 err = ::UMAPrOpen(&macPrintSession) ;
251 if ( err == noErr )
252 {
253 m_pageSetupData.ConvertToNative() ;
254
255 // Set up a valid PageFormat object.
256 if (m_pageSetupData.GetPrintData().m_macPageFormat == kPMNoPageFormat)
257 {
258 err = PMCreatePageFormat(&m_pageSetupData.GetPrintData().m_macPageFormat);
259
260 // Note that PMPageFormat is not session-specific, but calling
261 // PMSessionDefaultPageFormat assigns values specific to the printer
262 // associated with the current printing session.
263 if ((err == noErr) &&
264 (m_pageSetupData.GetPrintData().m_macPageFormat != kPMNoPageFormat))
265 {
266 err = PMSessionDefaultPageFormat(macPrintSession,
267 m_pageSetupData.GetPrintData().m_macPageFormat);
268 }
269 }
270 else
271 {
272 err = PMSessionValidatePageFormat(macPrintSession,
273 m_pageSetupData.GetPrintData().m_macPageFormat,
274 kPMDontWantBoolean);
275 }
276
277 // Display the Page Setup dialog.
278 if (err == noErr)
279 {
280 err = PMSessionPageSetupDialog(macPrintSession,
281 m_pageSetupData.GetPrintData().m_macPageFormat,
282 &accepted);
283 if ((err == noErr) && !accepted)
284 {
285 err = kPMCancel; // user clicked Cancel button
286 }
287 }
288
289 // If the user did not cancel, flatten and save the PageFormat object
290 // with our document.
291 if (err == noErr) {
292 // err = FlattenAndSavePageFormat(m_pageSetupData.GetPrintData().m_macPageFormat);
293 m_pageSetupData.ConvertFromNative() ;
294 result = wxID_OK ;
295 }
296 }
297 if ((err != noErr) && (err != kPMCancel))
298 {
299 message.Printf( "Print Error %d", err ) ;
300 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
301 dialog.ShowModal();
302 }
303 ::UMAPrClose(&macPrintSession) ;
304 #else
305 #pragma warning "TODO: Printing for carbon without session apis"
306 #endif
307 #endif
308 return result ;
309 }
310