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