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