]> git.saurik.com Git - wxWidgets.git/blob - src/mac/printdlg.cpp
Acutally use the m_maxChars parameter value instead of ignoring it
[wxWidgets.git] / src / mac / printdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #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 #ifndef __DARWIN__
22 #include "Printing.h"
23 #endif
24
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
32 // Use generic page setup dialog: use your own native one if one exists.
33
34 #if !USE_SHARED_LIBRARY
35 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog)
36 IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog)
37 #endif
38
39 wxPrintDialog::wxPrintDialog()
40 {
41 m_dialogParent = NULL;
42 m_printerDC = NULL;
43 m_destroyDC = TRUE;
44 }
45
46 wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintDialogData* data)
47 {
48 Create(p, data);
49 }
50
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)
61 {
62 m_dialogParent = p;
63 m_printerDC = NULL;
64 m_destroyDC = TRUE;
65
66 if ( data )
67 m_printDialogData = *data;
68
69 return TRUE;
70 }
71
72 wxPrintDialog::~wxPrintDialog()
73 {
74 if (m_destroyDC && m_printerDC) {
75 delete m_printerDC;
76 m_printerDC = NULL;
77 }
78 }
79
80 int wxPrintDialog::ShowModal()
81 {
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 {
100 message.Printf( wxT("Print Error %d"), err ) ;
101 wxMessageDialog dialog( NULL , message , wxT(""), wxICON_HAND | wxOK) ;
102 dialog.ShowModal();
103 }
104 ::UMAPrClose(NULL) ;
105 #else
106 #if PM_USE_SESSION_APIS
107 Boolean accepted;
108
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 {
123 err = PMSessionDefaultPageFormat((PMPrintSession)m_printDialogData.GetPrintData().m_macPrintSession,
124 (PMPageFormat)m_printDialogData.GetPrintData().m_macPageFormat);
125 }
126 }
127 else
128 {
129 err = PMSessionValidatePageFormat((PMPrintSession)m_printDialogData.GetPrintData().m_macPrintSession,
130 (PMPageFormat)m_printDialogData.GetPrintData().m_macPageFormat,
131 kPMDontWantBoolean);
132 }
133
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 {
145 err = PMSessionDefaultPrintSettings((PMPrintSession)m_printDialogData.GetPrintData().m_macPrintSession,
146 (PMPrintSettings)m_printDialogData.GetPrintData().m_macPrintSettings);
147 }
148 }
149 else
150 {
151 err = PMSessionValidatePrintSettings((PMPrintSession)m_printDialogData.GetPrintData().m_macPrintSession,
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 {
165 err = PMSessionPrintDialog((PMPrintSession)m_printDialogData.GetPrintData().m_macPrintSession,
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( wxT("Print Error %d"), err ) ;
183 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
184 dialog.ShowModal();
185 }
186 #else
187 #pragma warning "TODO: Printing for carbon without session apis"
188 #endif
189 #endif
190 return result ;
191 }
192
193 wxDC *wxPrintDialog::GetPrintDC()
194 {
195 return new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
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 {
230 int result = wxID_CANCEL ;
231 OSErr err ;
232 wxString message ;
233
234 #if !TARGET_CARBON
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 {
248 message.Printf( wxT("Print Error %d"), err ) ;
249 wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
250 dialog.ShowModal();
251 }
252 ::UMAPrClose(NULL) ;
253 #else
254 #if PM_USE_SESSION_APIS
255 Boolean accepted;
256
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 {
271 err = PMSessionDefaultPageFormat((PMPrintSession)m_pageSetupData.GetPrintData().m_macPrintSession,
272 (PMPageFormat)m_pageSetupData.GetPrintData().m_macPageFormat);
273 }
274 }
275 else
276 {
277 err = PMSessionValidatePageFormat((PMPrintSession)m_pageSetupData.GetPrintData().m_macPrintSession,
278 (PMPageFormat)m_pageSetupData.GetPrintData().m_macPageFormat,
279 kPMDontWantBoolean);
280 }
281
282 // Display the Page Setup dialog.
283 if (err == noErr)
284 {
285 err = PMSessionPageSetupDialog((PMPrintSession)m_pageSetupData.GetPrintData().m_macPrintSession,
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( wxT("Print Error %d"), err ) ;
305 wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
306 dialog.ShowModal();
307 }
308 #else
309 #pragma warning "TODO: Printing for carbon without session apis"
310 #endif
311 #endif
312 return result ;
313 }
314