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"
22 #if defined(TARGET_CARBON) && !defined(__DARWIN__)
23 # if PM_USE_SESSION_APIS
26 # include <PMApplication.h>
29 // Use generic page setup dialog: use your own native one if one exists.
31 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog
, wxDialog
)
33 IMPLEMENT_CLASS(wxPageSetupDialog
, wxDialog
)
36 wxPrintDialog::wxPrintDialog()
38 m_dialogParent
= NULL
;
43 wxPrintDialog::wxPrintDialog(wxWindow
*p
, wxPrintDialogData
* data
)
48 wxPrintDialog::wxPrintDialog(wxWindow
*p
, wxPrintData
* data
)
50 wxPrintDialogData data2
;
57 bool wxPrintDialog::Create(wxWindow
*p
, wxPrintDialogData
* data
)
64 m_printDialogData
= *data
;
69 wxPrintDialog::~wxPrintDialog()
71 if (m_destroyDC
&& m_printerDC
)
75 int wxPrintDialog::ShowModal()
77 int result
= wxID_CANCEL
;
82 err
= ::UMAPrOpen(NULL
) ;
85 m_printDialogData
.ConvertToNative() ;
86 if ( ::PrJobDialog( (THPrint
) m_printDialogData
.GetPrintData().m_macPrintSettings
) )
88 m_printDialogData
.ConvertFromNative() ;
95 message
.Printf( "Print Error %d", err
) ;
96 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
101 #if PM_USE_SESSION_APIS
102 PMPrintSession macPrintSession
= kPMNoReference
;
105 err
= ::UMAPrOpen(&macPrintSession
) ;
108 m_printDialogData
.ConvertToNative() ;
110 // Set up a valid PageFormat object.
111 if (m_printDialogData
.GetPrintData().m_macPageFormat
== kPMNoPageFormat
)
113 err
= PMCreatePageFormat((PMPageFormat
*)&m_printDialogData
.GetPrintData().m_macPageFormat
);
115 // Note that PMPageFormat is not session-specific, but calling
116 // PMSessionDefaultPageFormat assigns values specific to the printer
117 // associated with the current printing session.
118 if ((err
== noErr
) &&
119 (m_printDialogData
.GetPrintData().m_macPageFormat
!= kPMNoPageFormat
))
121 err
= PMSessionDefaultPageFormat((PMPrintSession
)macPrintSession
,
122 (PMPageFormat
)m_printDialogData
.GetPrintData().m_macPageFormat
);
127 err
= PMSessionValidatePageFormat((PMPrintSession
)macPrintSession
,
128 (PMPageFormat
)m_printDialogData
.GetPrintData().m_macPageFormat
,
132 // Set up a valid PrintSettings object.
133 if (m_printDialogData
.GetPrintData().m_macPrintSettings
== kPMNoPrintSettings
)
135 err
= PMCreatePrintSettings((PMPrintSettings
*)&m_printDialogData
.GetPrintData().m_macPrintSettings
);
137 // Note that PMPrintSettings is not session-specific, but calling
138 // PMSessionDefaultPrintSettings assigns values specific to the printer
139 // associated with the current printing session.
140 if ((err
== noErr
) &&
141 (m_printDialogData
.GetPrintData().m_macPrintSettings
!= kPMNoPrintSettings
))
143 err
= PMSessionDefaultPrintSettings((PMPrintSession
)macPrintSession
,
144 (PMPrintSettings
)m_printDialogData
.GetPrintData().m_macPrintSettings
);
149 err
= PMSessionValidatePrintSettings((PMPrintSession
)macPrintSession
,
150 (PMPrintSettings
)m_printDialogData
.GetPrintData().m_macPrintSettings
,
153 // Set a valid page range before displaying the Print dialog
156 // err = PMSetPageRange(m_printDialogData.GetPrintData().m_macPrintSettings,
157 // minPage, maxPage);
160 // Display the Print dialog.
163 err
= PMSessionPrintDialog((PMPrintSession
)macPrintSession
,
164 (PMPrintSettings
)m_printDialogData
.GetPrintData().m_macPrintSettings
,
165 (PMPageFormat
)m_printDialogData
.GetPrintData().m_macPageFormat
,
167 if ((err
== noErr
) && !accepted
)
169 err
= kPMCancel
; // user clicked Cancel button
174 m_printDialogData
.ConvertFromNative() ;
178 if ((err
!= noErr
) && (err
!= kPMCancel
))
180 message
.Printf( "Print Error %d", err
) ;
181 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
184 ::UMAPrClose(&macPrintSession
) ;
186 #pragma warning "TODO: Printing for carbon without session apis"
192 wxDC
*wxPrintDialog::GetPrintDC()
194 return new wxPrinterDC( m_printDialogData
.GetPrintData() ) ;
201 wxPageSetupDialog::wxPageSetupDialog():
204 m_dialogParent
= NULL
;
207 wxPageSetupDialog::wxPageSetupDialog(wxWindow
*p
, wxPageSetupData
*data
):
213 bool wxPageSetupDialog::Create(wxWindow
*p
, wxPageSetupData
*data
)
218 m_pageSetupData
= (*data
);
223 wxPageSetupDialog::~wxPageSetupDialog()
227 int wxPageSetupDialog::ShowModal()
229 int result
= wxID_CANCEL
;
234 err
= ::UMAPrOpen(NULL
) ;
237 m_pageSetupData
.ConvertToNative() ;
238 if ( ::PrStlDialog( (THPrint
) m_pageSetupData
.GetPrintData().m_macPrintSettings
) )
240 m_pageSetupData
.ConvertFromNative() ;
247 message
.Printf( "Print Error %d", err
) ;
248 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
253 #if PM_USE_SESSION_APIS
254 PMPrintSession macPrintSession
= kPMNoReference
;
257 err
= ::UMAPrOpen(&macPrintSession
) ;
260 m_pageSetupData
.ConvertToNative() ;
262 // Set up a valid PageFormat object.
263 if (m_pageSetupData
.GetPrintData().m_macPageFormat
== kPMNoPageFormat
)
265 err
= PMCreatePageFormat((PMPageFormat
*)&m_pageSetupData
.GetPrintData().m_macPageFormat
);
267 // Note that PMPageFormat is not session-specific, but calling
268 // PMSessionDefaultPageFormat assigns values specific to the printer
269 // associated with the current printing session.
270 if ((err
== noErr
) &&
271 (m_pageSetupData
.GetPrintData().m_macPageFormat
!= kPMNoPageFormat
))
273 err
= PMSessionDefaultPageFormat((PMPrintSession
)macPrintSession
,
274 (PMPageFormat
)m_pageSetupData
.GetPrintData().m_macPageFormat
);
279 err
= PMSessionValidatePageFormat((PMPrintSession
)macPrintSession
,
280 (PMPageFormat
)m_pageSetupData
.GetPrintData().m_macPageFormat
,
284 // Display the Page Setup dialog.
287 err
= PMSessionPageSetupDialog((PMPrintSession
)macPrintSession
,
288 (PMPageFormat
)m_pageSetupData
.GetPrintData().m_macPageFormat
,
290 if ((err
== noErr
) && !accepted
)
292 err
= kPMCancel
; // user clicked Cancel button
296 // If the user did not cancel, flatten and save the PageFormat object
297 // with our document.
299 // err = FlattenAndSavePageFormat(m_pageSetupData.GetPrintData().m_macPageFormat);
300 m_pageSetupData
.ConvertFromNative() ;
304 if ((err
!= noErr
) && (err
!= kPMCancel
))
306 message
.Printf( "Print Error %d", err
) ;
307 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
310 ::UMAPrClose(&macPrintSession
) ;
312 #pragma warning "TODO: Printing for carbon without session apis"