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