]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/printdlg.cpp
switched to MacOS 8.5+ implementation for submenus
[wxWidgets.git] / src / mac / carbon / printdlg.cpp
CommitLineData
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
35IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog)
36IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog)
2f1ae414 37#endif
e9576ca5 38
e7549107 39wxPrintDialog::wxPrintDialog()
e9576ca5
SC
40{
41 m_dialogParent = NULL;
e7549107
SC
42 m_printerDC = NULL;
43 m_destroyDC = TRUE;
e9576ca5
SC
44}
45
e7549107 46wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintDialogData* data)
e9576ca5
SC
47{
48 Create(p, data);
49}
50
e7549107
SC
51wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintData* data)
52{
53 wxPrintDialogData data2;
54 if ( data )
55 data2 = *data;
56
57 Create(p, &data2);
58}
59
60bool 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
72wxPrintDialog::~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
80int 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
GD
106 #if PM_USE_SESSION_APIS
107 PMPrintSession macPrintSession = kPMNoReference;
108 Boolean accepted;
109
962cbf2e
GD
110 err = ::UMAPrOpen(&macPrintSession) ;
111 if ( err == noErr )
112 {
113 m_printDialogData.ConvertToNative() ;
114
115 // Set up a valid PageFormat object.
116 if (m_printDialogData.GetPrintData().m_macPageFormat == kPMNoPageFormat)
117 {
118 err = PMCreatePageFormat((PMPageFormat *)&m_printDialogData.GetPrintData().m_macPageFormat);
119
120 // Note that PMPageFormat is not session-specific, but calling
121 // PMSessionDefaultPageFormat assigns values specific to the printer
122 // associated with the current printing session.
123 if ((err == noErr) &&
124 (m_printDialogData.GetPrintData().m_macPageFormat != kPMNoPageFormat))
125 {
126 err = PMSessionDefaultPageFormat((PMPrintSession)macPrintSession,
127 (PMPageFormat)m_printDialogData.GetPrintData().m_macPageFormat);
128 }
129 }
130 else
131 {
132 err = PMSessionValidatePageFormat((PMPrintSession)macPrintSession,
133 (PMPageFormat)m_printDialogData.GetPrintData().m_macPageFormat,
134 kPMDontWantBoolean);
135 }
0bec761d 136
962cbf2e
GD
137 // Set up a valid PrintSettings object.
138 if (m_printDialogData.GetPrintData().m_macPrintSettings == kPMNoPrintSettings)
139 {
140 err = PMCreatePrintSettings((PMPrintSettings *)&m_printDialogData.GetPrintData().m_macPrintSettings);
141
142 // Note that PMPrintSettings is not session-specific, but calling
143 // PMSessionDefaultPrintSettings assigns values specific to the printer
144 // associated with the current printing session.
145 if ((err == noErr) &&
146 (m_printDialogData.GetPrintData().m_macPrintSettings != kPMNoPrintSettings))
147 {
148 err = PMSessionDefaultPrintSettings((PMPrintSession)macPrintSession,
149 (PMPrintSettings)m_printDialogData.GetPrintData().m_macPrintSettings);
150 }
151 }
152 else
153 {
154 err = PMSessionValidatePrintSettings((PMPrintSession)macPrintSession,
155 (PMPrintSettings)m_printDialogData.GetPrintData().m_macPrintSettings,
156 kPMDontWantBoolean);
157 }
158 // Set a valid page range before displaying the Print dialog
159 if (err == noErr)
160 {
161 // err = PMSetPageRange(m_printDialogData.GetPrintData().m_macPrintSettings,
162 // minPage, maxPage);
163 }
164
165 // Display the Print dialog.
166 if (err == noErr)
167 {
168 err = PMSessionPrintDialog((PMPrintSession)macPrintSession,
169 (PMPrintSettings)m_printDialogData.GetPrintData().m_macPrintSettings,
170 (PMPageFormat)m_printDialogData.GetPrintData().m_macPageFormat,
171 &accepted);
172 if ((err == noErr) && !accepted)
173 {
174 err = kPMCancel; // user clicked Cancel button
175 }
176 }
177 if ( err == noErr )
178 {
179 m_printDialogData.ConvertFromNative() ;
180 result = wxID_OK ;
181 }
182 }
183 if ((err != noErr) && (err != kPMCancel))
184 {
185 message.Printf( "Print Error %d", err ) ;
186 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
187 dialog.ShowModal();
188 }
189 ::UMAPrClose(&macPrintSession) ;
03e11df5 190 #else
0bec761d 191 #pragma warning "TODO: Printing for carbon without session apis"
03e11df5
GD
192 #endif
193#endif
519cb848 194 return result ;
e9576ca5
SC
195}
196
197wxDC *wxPrintDialog::GetPrintDC()
198{
e7549107 199 return new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
e9576ca5
SC
200}
201
202/*
203 * wxPageSetupDialog
204 */
205
206wxPageSetupDialog::wxPageSetupDialog():
207 wxDialog()
208{
209 m_dialogParent = NULL;
210}
211
212wxPageSetupDialog::wxPageSetupDialog(wxWindow *p, wxPageSetupData *data):
213 wxDialog()
214{
215 Create(p, data);
216}
217
218bool wxPageSetupDialog::Create(wxWindow *p, wxPageSetupData *data)
219{
220 m_dialogParent = p;
221
222 if (data)
223 m_pageSetupData = (*data);
224
225 return TRUE;
226}
227
228wxPageSetupDialog::~wxPageSetupDialog()
229{
230}
231
232int wxPageSetupDialog::ShowModal()
233{
0bec761d
GD
234 int result = wxID_CANCEL ;
235 OSErr err ;
519cb848 236 wxString message ;
0bec761d
GD
237
238#if !TARGET_CARBON
a3d3d3bf 239 err = ::UMAPrOpen(NULL) ;
0bec761d 240 if ( err == noErr )
519cb848
SC
241 {
242 m_pageSetupData.ConvertToNative() ;
24885e9b 243 if ( ::PrStlDialog( (THPrint) m_pageSetupData.GetPrintData().m_macPrintSettings ) )
519cb848
SC
244 {
245 m_pageSetupData.ConvertFromNative() ;
246 result = wxID_OK ;
247 }
248
249 }
250 else
251 {
252 message.Printf( "Print Error %d", err ) ;
253 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
0bec761d 254 dialog.ShowModal();
519cb848 255 }
a3d3d3bf 256 ::UMAPrClose(NULL) ;
2f1ae414 257#else
0bec761d
GD
258 #if PM_USE_SESSION_APIS
259 PMPrintSession macPrintSession = kPMNoReference;
260 Boolean accepted;
261
962cbf2e
GD
262 err = ::UMAPrOpen(&macPrintSession) ;
263 if ( err == noErr )
264 {
265 m_pageSetupData.ConvertToNative() ;
266
267 // Set up a valid PageFormat object.
268 if (m_pageSetupData.GetPrintData().m_macPageFormat == kPMNoPageFormat)
269 {
270 err = PMCreatePageFormat((PMPageFormat *)&m_pageSetupData.GetPrintData().m_macPageFormat);
271
272 // Note that PMPageFormat is not session-specific, but calling
273 // PMSessionDefaultPageFormat assigns values specific to the printer
274 // associated with the current printing session.
275 if ((err == noErr) &&
276 (m_pageSetupData.GetPrintData().m_macPageFormat != kPMNoPageFormat))
277 {
278 err = PMSessionDefaultPageFormat((PMPrintSession)macPrintSession,
279 (PMPageFormat)m_pageSetupData.GetPrintData().m_macPageFormat);
280 }
281 }
282 else
283 {
284 err = PMSessionValidatePageFormat((PMPrintSession)macPrintSession,
285 (PMPageFormat)m_pageSetupData.GetPrintData().m_macPageFormat,
286 kPMDontWantBoolean);
287 }
288
289 // Display the Page Setup dialog.
290 if (err == noErr)
291 {
292 err = PMSessionPageSetupDialog((PMPrintSession)macPrintSession,
293 (PMPageFormat)m_pageSetupData.GetPrintData().m_macPageFormat,
294 &accepted);
295 if ((err == noErr) && !accepted)
296 {
297 err = kPMCancel; // user clicked Cancel button
298 }
299 }
300
301 // If the user did not cancel, flatten and save the PageFormat object
302 // with our document.
303 if (err == noErr) {
304 // err = FlattenAndSavePageFormat(m_pageSetupData.GetPrintData().m_macPageFormat);
305 m_pageSetupData.ConvertFromNative() ;
306 result = wxID_OK ;
307 }
308 }
309 if ((err != noErr) && (err != kPMCancel))
310 {
311 message.Printf( "Print Error %d", err ) ;
312 wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ;
313 dialog.ShowModal();
314 }
315 ::UMAPrClose(&macPrintSession) ;
03e11df5 316 #else
0bec761d 317 #pragma warning "TODO: Printing for carbon without session apis"
03e11df5 318 #endif
2f1ae414 319#endif
519cb848 320 return result ;
e9576ca5
SC
321}
322