]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/printdlg.cpp
Fix wxListCtrl background colour bug Part I
[wxWidgets.git] / src / mac / carbon / printdlg.cpp
... / ...
CommitLineData
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"
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
35IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog)
36IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog)
37#endif
38
39wxPrintDialog::wxPrintDialog()
40{
41 m_dialogParent = NULL;
42 m_printerDC = NULL;
43 m_destroyDC = TRUE;
44}
45
46wxPrintDialog::wxPrintDialog(wxWindow *p, wxPrintDialogData* data)
47{
48 Create(p, data);
49}
50
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)
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
72wxPrintDialog::~wxPrintDialog()
73{
74 if (m_destroyDC && m_printerDC)
75 delete m_printerDC;
76}
77
78int wxPrintDialog::ShowModal()
79{
80 int result = wxID_CANCEL ;
81 OSErr err ;
82 wxString message ;
83
84#if !TARGET_CARBON
85 err = ::UMAPrOpen(NULL) ;
86 if ( err == noErr )
87 {
88 m_printDialogData.ConvertToNative() ;
89 if ( ::PrJobDialog( (THPrint) m_printDialogData.GetPrintData().m_macPrintSettings ) )
90 {
91 m_printDialogData.ConvertFromNative() ;
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) ;
100 dialog.ShowModal();
101 }
102 ::UMAPrClose(NULL) ;
103#else
104 #if PM_USE_SESSION_APIS
105 PMPrintSession macPrintSession = kPMNoReference;
106 Boolean accepted;
107
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 }
134
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) ;
188 #else
189 #pragma warning "TODO: Printing for carbon without session apis"
190 #endif
191#endif
192 return result ;
193}
194
195wxDC *wxPrintDialog::GetPrintDC()
196{
197 return new wxPrinterDC( m_printDialogData.GetPrintData() ) ;
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{
232 int result = wxID_CANCEL ;
233 OSErr err ;
234 wxString message ;
235
236#if !TARGET_CARBON
237 err = ::UMAPrOpen(NULL) ;
238 if ( err == noErr )
239 {
240 m_pageSetupData.ConvertToNative() ;
241 if ( ::PrStlDialog( (THPrint) m_pageSetupData.GetPrintData().m_macPrintSettings ) )
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) ;
252 dialog.ShowModal();
253 }
254 ::UMAPrClose(NULL) ;
255#else
256 #if PM_USE_SESSION_APIS
257 PMPrintSession macPrintSession = kPMNoReference;
258 Boolean accepted;
259
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) ;
314 #else
315 #pragma warning "TODO: Printing for carbon without session apis"
316 #endif
317#endif
318 return result ;
319}
320