1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPrintDialog, wxPageSetupDialog
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "printdlg.h"
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"
25 #if defined(TARGET_CARBON) && !defined(__DARWIN__)
26 # if PM_USE_SESSION_APIS
29 # include <PMApplication.h>
32 // Use generic page setup dialog: use your own native one if one exists.
34 #if !USE_SHARED_LIBRARY
35 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog
, wxDialog
)
36 IMPLEMENT_CLASS(wxPageSetupDialog
, wxDialog
)
39 wxPrintDialog::wxPrintDialog()
41 m_dialogParent
= NULL
;
46 wxPrintDialog::wxPrintDialog(wxWindow
*p
, wxPrintDialogData
* data
)
51 wxPrintDialog::wxPrintDialog(wxWindow
*p
, wxPrintData
* data
)
53 wxPrintDialogData data2
;
60 bool wxPrintDialog::Create(wxWindow
*p
, wxPrintDialogData
* data
)
67 m_printDialogData
= *data
;
72 wxPrintDialog::~wxPrintDialog()
74 if (m_destroyDC
&& m_printerDC
)
78 int wxPrintDialog::ShowModal()
80 int result
= wxID_CANCEL
;
85 err
= ::UMAPrOpen(NULL
) ;
88 m_printDialogData
.ConvertToNative() ;
89 if ( ::PrJobDialog( (THPrint
) m_printDialogData
.GetPrintData().m_macPrintSettings
) )
91 m_printDialogData
.ConvertFromNative() ;
98 message
.Printf( "Print Error %d", err
) ;
99 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
104 #if PM_USE_SESSION_APIS
105 PMPrintSession macPrintSession
= kPMNoReference
;
108 err
= ::UMAPrOpen(&macPrintSession
) ;
111 m_printDialogData
.ConvertToNative() ;
113 // Set up a valid PageFormat object.
114 if (m_printDialogData
.GetPrintData().m_macPageFormat
== kPMNoPageFormat
)
116 err
= PMCreatePageFormat((PMPageFormat
*)&m_printDialogData
.GetPrintData().m_macPageFormat
);
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
))
124 err
= PMSessionDefaultPageFormat((PMPrintSession
)macPrintSession
,
125 (PMPageFormat
)m_printDialogData
.GetPrintData().m_macPageFormat
);
130 err
= PMSessionValidatePageFormat((PMPrintSession
)macPrintSession
,
131 (PMPageFormat
)m_printDialogData
.GetPrintData().m_macPageFormat
,
135 // Set up a valid PrintSettings object.
136 if (m_printDialogData
.GetPrintData().m_macPrintSettings
== kPMNoPrintSettings
)
138 err
= PMCreatePrintSettings((PMPrintSettings
*)&m_printDialogData
.GetPrintData().m_macPrintSettings
);
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
))
146 err
= PMSessionDefaultPrintSettings((PMPrintSession
)macPrintSession
,
147 (PMPrintSettings
)m_printDialogData
.GetPrintData().m_macPrintSettings
);
152 err
= PMSessionValidatePrintSettings((PMPrintSession
)macPrintSession
,
153 (PMPrintSettings
)m_printDialogData
.GetPrintData().m_macPrintSettings
,
156 // Set a valid page range before displaying the Print dialog
159 // err = PMSetPageRange(m_printDialogData.GetPrintData().m_macPrintSettings,
160 // minPage, maxPage);
163 // Display the Print dialog.
166 err
= PMSessionPrintDialog((PMPrintSession
)macPrintSession
,
167 (PMPrintSettings
)m_printDialogData
.GetPrintData().m_macPrintSettings
,
168 (PMPageFormat
)m_printDialogData
.GetPrintData().m_macPageFormat
,
170 if ((err
== noErr
) && !accepted
)
172 err
= kPMCancel
; // user clicked Cancel button
177 m_printDialogData
.ConvertFromNative() ;
181 if ((err
!= noErr
) && (err
!= kPMCancel
))
183 message
.Printf( "Print Error %d", err
) ;
184 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
187 ::UMAPrClose(&macPrintSession
) ;
189 #pragma warning "TODO: Printing for carbon without session apis"
195 wxDC
*wxPrintDialog::GetPrintDC()
197 return new wxPrinterDC( m_printDialogData
.GetPrintData() ) ;
204 wxPageSetupDialog::wxPageSetupDialog():
207 m_dialogParent
= NULL
;
210 wxPageSetupDialog::wxPageSetupDialog(wxWindow
*p
, wxPageSetupData
*data
):
216 bool wxPageSetupDialog::Create(wxWindow
*p
, wxPageSetupData
*data
)
221 m_pageSetupData
= (*data
);
226 wxPageSetupDialog::~wxPageSetupDialog()
230 int wxPageSetupDialog::ShowModal()
232 int result
= wxID_CANCEL
;
237 err
= ::UMAPrOpen(NULL
) ;
240 m_pageSetupData
.ConvertToNative() ;
241 if ( ::PrStlDialog( (THPrint
) m_pageSetupData
.GetPrintData().m_macPrintSettings
) )
243 m_pageSetupData
.ConvertFromNative() ;
250 message
.Printf( "Print Error %d", err
) ;
251 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
256 #if PM_USE_SESSION_APIS
257 PMPrintSession macPrintSession
= kPMNoReference
;
260 err
= ::UMAPrOpen(&macPrintSession
) ;
263 m_pageSetupData
.ConvertToNative() ;
265 // Set up a valid PageFormat object.
266 if (m_pageSetupData
.GetPrintData().m_macPageFormat
== kPMNoPageFormat
)
268 err
= PMCreatePageFormat((PMPageFormat
*)&m_pageSetupData
.GetPrintData().m_macPageFormat
);
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
))
276 err
= PMSessionDefaultPageFormat((PMPrintSession
)macPrintSession
,
277 (PMPageFormat
)m_pageSetupData
.GetPrintData().m_macPageFormat
);
282 err
= PMSessionValidatePageFormat((PMPrintSession
)macPrintSession
,
283 (PMPageFormat
)m_pageSetupData
.GetPrintData().m_macPageFormat
,
287 // Display the Page Setup dialog.
290 err
= PMSessionPageSetupDialog((PMPrintSession
)macPrintSession
,
291 (PMPageFormat
)m_pageSetupData
.GetPrintData().m_macPageFormat
,
293 if ((err
== noErr
) && !accepted
)
295 err
= kPMCancel
; // user clicked Cancel button
299 // If the user did not cancel, flatten and save the PageFormat object
300 // with our document.
302 // err = FlattenAndSavePageFormat(m_pageSetupData.GetPrintData().m_macPageFormat);
303 m_pageSetupData
.ConvertFromNative() ;
307 if ((err
!= noErr
) && (err
!= kPMCancel
))
309 message
.Printf( "Print Error %d", err
) ;
310 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
313 ::UMAPrClose(&macPrintSession
) ;
315 #pragma warning "TODO: Printing for carbon without session apis"