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 // Use generic page setup dialog: use your own native one if one exists.
24 #if !USE_SHARED_LIBRARY
25 IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog
, wxDialog
)
26 IMPLEMENT_CLASS(wxPageSetupDialog
, wxDialog
)
29 wxPrintDialog::wxPrintDialog()
31 m_dialogParent
= NULL
;
36 wxPrintDialog::wxPrintDialog(wxWindow
*p
, wxPrintDialogData
* data
)
41 wxPrintDialog::wxPrintDialog(wxWindow
*p
, wxPrintData
* data
)
43 wxPrintDialogData data2
;
50 bool wxPrintDialog::Create(wxWindow
*p
, wxPrintDialogData
* data
)
57 m_printDialogData
= *data
;
62 wxPrintDialog::~wxPrintDialog()
64 if (m_destroyDC
&& m_printerDC
)
68 int wxPrintDialog::ShowModal()
70 int result
= wxID_CANCEL
;
78 m_printDialogData
.ConvertToNative() ;
79 if ( ::PrJobDialog( (THPrint
) m_printDialogData
.GetPrintData().m_macPrintInfo
) )
81 m_printDialogData
.ConvertFromNative() ;
88 message
.Printf( "Print Error %d", err
) ;
89 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
94 #if PM_USE_SESSION_APIS
95 PMPrintSession macPrintSession
= kPMNoReference
;
98 err
= ::UMAPrOpen(&macPrintSession
) ;
101 m_printDialogData
.ConvertToNative() ;
103 // Set up a valid PageFormat object.
104 if (m_printDialogData
.GetPrintData().m_macPageFormat
== kPMNoPageFormat
)
106 err
= PMCreatePageFormat(&m_printDialogData
.GetPrintData().m_macPageFormat
);
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
))
114 err
= PMSessionDefaultPageFormat(macPrintSession
,
115 m_printDialogData
.GetPrintData().m_macPageFormat
);
120 err
= PMSessionValidatePageFormat(macPrintSession
,
121 m_printDialogData
.GetPrintData().m_macPageFormat
,
125 // Set up a valid PrintSettings object.
126 if (m_printDialogData
.GetPrintData().m_macPrintSettings
== kPMNoPrintSettings
)
128 err
= PMCreatePrintSettings(&m_printDialogData
.GetPrintData().m_macPrintSettings
);
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
))
136 err
= PMSessionDefaultPrintSettings(macPrintSession
,
137 m_printDialogData
.GetPrintData().m_macPrintSettings
);
142 err
= PMSessionValidatePrintSettings(macPrintSession
,
143 m_printDialogData
.GetPrintData().m_macPrintSettings
,
146 // Set a valid page range before displaying the Print dialog
149 // err = PMSetPageRange(m_printDialogData.GetPrintData().m_macPrintSettings,
150 // minPage, maxPage);
153 // Display the Print dialog.
156 err
= PMSessionPrintDialog(macPrintSession
,
157 m_printDialogData
.GetPrintData().m_macPrintSettings
,
158 m_printDialogData
.GetPrintData().m_macPageFormat
,
160 if ((err
== noErr
) && !accepted
)
162 err
= kPMCancel
; // user clicked Cancel button
167 m_printDialogData
.ConvertFromNative() ;
171 if ((err
!= noErr
) && (err
!= kPMCancel
))
173 message
.Printf( "Print Error %d", err
) ;
174 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
177 ::UMAPrClose(&macPrintSession
) ;
179 #pragma warning "TODO: Printing for carbon without session apis"
185 wxDC
*wxPrintDialog::GetPrintDC()
187 return new wxPrinterDC( m_printDialogData
.GetPrintData() ) ;
194 wxPageSetupDialog::wxPageSetupDialog():
197 m_dialogParent
= NULL
;
200 wxPageSetupDialog::wxPageSetupDialog(wxWindow
*p
, wxPageSetupData
*data
):
206 bool wxPageSetupDialog::Create(wxWindow
*p
, wxPageSetupData
*data
)
211 m_pageSetupData
= (*data
);
216 wxPageSetupDialog::~wxPageSetupDialog()
220 int wxPageSetupDialog::ShowModal()
222 int result
= wxID_CANCEL
;
227 err
= ::UMAPrOpen() ;
230 m_pageSetupData
.ConvertToNative() ;
231 if ( ::PrStlDialog( (THPrint
) m_pageSetupData
.GetPrintData().m_macPrintInfo
) )
233 m_pageSetupData
.ConvertFromNative() ;
240 message
.Printf( "Print Error %d", err
) ;
241 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
246 #if PM_USE_SESSION_APIS
247 PMPrintSession macPrintSession
= kPMNoReference
;
250 err
= ::UMAPrOpen(&macPrintSession
) ;
253 m_pageSetupData
.ConvertToNative() ;
255 // Set up a valid PageFormat object.
256 if (m_pageSetupData
.GetPrintData().m_macPageFormat
== kPMNoPageFormat
)
258 err
= PMCreatePageFormat(&m_pageSetupData
.GetPrintData().m_macPageFormat
);
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
))
266 err
= PMSessionDefaultPageFormat(macPrintSession
,
267 m_pageSetupData
.GetPrintData().m_macPageFormat
);
272 err
= PMSessionValidatePageFormat(macPrintSession
,
273 m_pageSetupData
.GetPrintData().m_macPageFormat
,
277 // Display the Page Setup dialog.
280 err
= PMSessionPageSetupDialog(macPrintSession
,
281 m_pageSetupData
.GetPrintData().m_macPageFormat
,
283 if ((err
== noErr
) && !accepted
)
285 err
= kPMCancel
; // user clicked Cancel button
289 // If the user did not cancel, flatten and save the PageFormat object
290 // with our document.
292 // err = FlattenAndSavePageFormat(m_pageSetupData.GetPrintData().m_macPageFormat);
293 m_pageSetupData
.ConvertFromNative() ;
297 if ((err
!= noErr
) && (err
!= kPMCancel
))
299 message
.Printf( "Print Error %d", err
) ;
300 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
303 ::UMAPrClose(&macPrintSession
) ;
305 #pragma warning "TODO: Printing for carbon without session apis"