]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
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" | |
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 SC |
21 | #ifndef __DARWIN__ |
22 | #include "Printing.h" | |
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; | |
56 | ||
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; | |
e9576ca5 SC |
65 | |
66 | if ( data ) | |
e7549107 | 67 | m_printDialogData = *data; |
e9576ca5 SC |
68 | |
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 | { | |
519cb848 SC |
82 | int result = wxID_CANCEL ; |
83 | OSErr err ; | |
84 | wxString message ; | |
0bec761d GD |
85 | |
86 | #if !TARGET_CARBON | |
a3d3d3bf | 87 | err = ::UMAPrOpen(NULL) ; |
0bec761d | 88 | if ( err == noErr ) |
519cb848 | 89 | { |
e7549107 | 90 | m_printDialogData.ConvertToNative() ; |
24885e9b | 91 | if ( ::PrJobDialog( (THPrint) m_printDialogData.GetPrintData().m_macPrintSettings ) ) |
519cb848 | 92 | { |
e7549107 | 93 | m_printDialogData.ConvertFromNative() ; |
519cb848 SC |
94 | result = wxID_OK ; |
95 | } | |
96 | ||
97 | } | |
98 | else | |
99 | { | |
100 | message.Printf( "Print Error %d", err ) ; | |
101 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
0bec761d | 102 | dialog.ShowModal(); |
519cb848 | 103 | } |
a3d3d3bf | 104 | ::UMAPrClose(NULL) ; |
03e11df5 | 105 | #else |
0bec761d | 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, |
962cbf2e GD |
124 | (PMPageFormat)m_printDialogData.GetPrintData().m_macPageFormat); |
125 | } | |
126 | } | |
127 | else | |
128 | { | |
2b5f62a0 | 129 | err = PMSessionValidatePageFormat((PMPrintSession)m_printDialogData.GetPrintData().m_macPrintSession, |
962cbf2e GD |
130 | (PMPageFormat)m_printDialogData.GetPrintData().m_macPageFormat, |
131 | kPMDontWantBoolean); | |
132 | } | |
0bec761d | 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, |
962cbf2e GD |
146 | (PMPrintSettings)m_printDialogData.GetPrintData().m_macPrintSettings); |
147 | } | |
148 | } | |
149 | else | |
150 | { | |
2b5f62a0 | 151 | err = PMSessionValidatePrintSettings((PMPrintSession)m_printDialogData.GetPrintData().m_macPrintSession, |
962cbf2e GD |
152 | (PMPrintSettings)m_printDialogData.GetPrintData().m_macPrintSettings, |
153 | kPMDontWantBoolean); | |
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, |
962cbf2e GD |
166 | (PMPrintSettings)m_printDialogData.GetPrintData().m_macPrintSettings, |
167 | (PMPageFormat)m_printDialogData.GetPrintData().m_macPageFormat, | |
168 | &accepted); | |
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 | { | |
182 | message.Printf( "Print Error %d", err ) ; | |
183 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
184 | dialog.ShowModal(); | |
185 | } | |
03e11df5 | 186 | #else |
0bec761d | 187 | #pragma warning "TODO: Printing for carbon without session apis" |
03e11df5 GD |
188 | #endif |
189 | #endif | |
519cb848 | 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 | /* | |
199 | * wxPageSetupDialog | |
200 | */ | |
201 | ||
202 | wxPageSetupDialog::wxPageSetupDialog(): | |
203 | wxDialog() | |
204 | { | |
205 | m_dialogParent = NULL; | |
206 | } | |
207 | ||
208 | wxPageSetupDialog::wxPageSetupDialog(wxWindow *p, wxPageSetupData *data): | |
209 | wxDialog() | |
210 | { | |
211 | Create(p, data); | |
212 | } | |
213 | ||
214 | bool wxPageSetupDialog::Create(wxWindow *p, wxPageSetupData *data) | |
215 | { | |
216 | m_dialogParent = p; | |
217 | ||
218 | if (data) | |
219 | m_pageSetupData = (*data); | |
220 | ||
221 | return TRUE; | |
222 | } | |
223 | ||
224 | wxPageSetupDialog::~wxPageSetupDialog() | |
225 | { | |
226 | } | |
227 | ||
228 | int wxPageSetupDialog::ShowModal() | |
229 | { | |
0bec761d GD |
230 | int result = wxID_CANCEL ; |
231 | OSErr err ; | |
519cb848 | 232 | wxString message ; |
0bec761d GD |
233 | |
234 | #if !TARGET_CARBON | |
a3d3d3bf | 235 | err = ::UMAPrOpen(NULL) ; |
0bec761d | 236 | if ( err == noErr ) |
519cb848 SC |
237 | { |
238 | m_pageSetupData.ConvertToNative() ; | |
24885e9b | 239 | if ( ::PrStlDialog( (THPrint) m_pageSetupData.GetPrintData().m_macPrintSettings ) ) |
519cb848 SC |
240 | { |
241 | m_pageSetupData.ConvertFromNative() ; | |
242 | result = wxID_OK ; | |
243 | } | |
244 | ||
245 | } | |
246 | else | |
247 | { | |
248 | message.Printf( "Print Error %d", err ) ; | |
249 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
0bec761d | 250 | dialog.ShowModal(); |
519cb848 | 251 | } |
a3d3d3bf | 252 | ::UMAPrClose(NULL) ; |
2f1ae414 | 253 | #else |
0bec761d | 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, |
962cbf2e GD |
272 | (PMPageFormat)m_pageSetupData.GetPrintData().m_macPageFormat); |
273 | } | |
274 | } | |
275 | else | |
276 | { | |
2b5f62a0 | 277 | err = PMSessionValidatePageFormat((PMPrintSession)m_pageSetupData.GetPrintData().m_macPrintSession, |
962cbf2e GD |
278 | (PMPageFormat)m_pageSetupData.GetPrintData().m_macPageFormat, |
279 | kPMDontWantBoolean); | |
280 | } | |
281 | ||
282 | // Display the Page Setup dialog. | |
283 | if (err == noErr) | |
284 | { | |
2b5f62a0 | 285 | err = PMSessionPageSetupDialog((PMPrintSession)m_pageSetupData.GetPrintData().m_macPrintSession, |
962cbf2e GD |
286 | (PMPageFormat)m_pageSetupData.GetPrintData().m_macPageFormat, |
287 | &accepted); | |
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 | { | |
304 | message.Printf( "Print Error %d", err ) ; | |
305 | wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; | |
306 | dialog.ShowModal(); | |
307 | } | |
03e11df5 | 308 | #else |
0bec761d | 309 | #pragma warning "TODO: Printing for carbon without session apis" |
03e11df5 | 310 | #endif |
2f1ae414 | 311 | #endif |
519cb848 | 312 | return result ; |
e9576ca5 SC |
313 | } |
314 |