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
) {
80 int wxPrintDialog::ShowModal()
82 int result
= wxID_CANCEL
;
87 err
= ::UMAPrOpen(NULL
) ;
90 m_printDialogData
.ConvertToNative() ;
91 if ( ::PrJobDialog( (THPrint
) m_printDialogData
.GetPrintData().m_macPrintSettings
) )
93 m_printDialogData
.ConvertFromNative() ;
100 message
.Printf( "Print Error %d", err
) ;
101 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
106 #if PM_USE_SESSION_APIS
107 PMPrintSession macPrintSession
= kPMNoReference
;
110 err
= ::UMAPrOpen(&macPrintSession
) ;
113 m_printDialogData
.ConvertToNative() ;
115 // Set up a valid PageFormat object.
116 if (m_printDialogData
.GetPrintData().m_macPageFormat
== kPMNoPageFormat
)
118 err
= PMCreatePageFormat((PMPageFormat
*)&m_printDialogData
.GetPrintData().m_macPageFormat
);
120 // Note that PMPageFormat is not session-specific, but calling
121 // PMSessionDefaultPageFormat assigns values specific to the printer
122 // associated with the current printing session.
123 if ((err
== noErr
) &&
124 (m_printDialogData
.GetPrintData().m_macPageFormat
!= kPMNoPageFormat
))
126 err
= PMSessionDefaultPageFormat((PMPrintSession
)macPrintSession
,
127 (PMPageFormat
)m_printDialogData
.GetPrintData().m_macPageFormat
);
132 err
= PMSessionValidatePageFormat((PMPrintSession
)macPrintSession
,
133 (PMPageFormat
)m_printDialogData
.GetPrintData().m_macPageFormat
,
137 // Set up a valid PrintSettings object.
138 if (m_printDialogData
.GetPrintData().m_macPrintSettings
== kPMNoPrintSettings
)
140 err
= PMCreatePrintSettings((PMPrintSettings
*)&m_printDialogData
.GetPrintData().m_macPrintSettings
);
142 // Note that PMPrintSettings is not session-specific, but calling
143 // PMSessionDefaultPrintSettings assigns values specific to the printer
144 // associated with the current printing session.
145 if ((err
== noErr
) &&
146 (m_printDialogData
.GetPrintData().m_macPrintSettings
!= kPMNoPrintSettings
))
148 err
= PMSessionDefaultPrintSettings((PMPrintSession
)macPrintSession
,
149 (PMPrintSettings
)m_printDialogData
.GetPrintData().m_macPrintSettings
);
154 err
= PMSessionValidatePrintSettings((PMPrintSession
)macPrintSession
,
155 (PMPrintSettings
)m_printDialogData
.GetPrintData().m_macPrintSettings
,
158 // Set a valid page range before displaying the Print dialog
161 // err = PMSetPageRange(m_printDialogData.GetPrintData().m_macPrintSettings,
162 // minPage, maxPage);
165 // Display the Print dialog.
168 err
= PMSessionPrintDialog((PMPrintSession
)macPrintSession
,
169 (PMPrintSettings
)m_printDialogData
.GetPrintData().m_macPrintSettings
,
170 (PMPageFormat
)m_printDialogData
.GetPrintData().m_macPageFormat
,
172 if ((err
== noErr
) && !accepted
)
174 err
= kPMCancel
; // user clicked Cancel button
179 m_printDialogData
.ConvertFromNative() ;
183 if ((err
!= noErr
) && (err
!= kPMCancel
))
185 message
.Printf( "Print Error %d", err
) ;
186 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
189 ::UMAPrClose(&macPrintSession
) ;
191 #pragma warning "TODO: Printing for carbon without session apis"
197 wxDC
*wxPrintDialog::GetPrintDC()
199 return new wxPrinterDC( m_printDialogData
.GetPrintData() ) ;
206 wxPageSetupDialog::wxPageSetupDialog():
209 m_dialogParent
= NULL
;
212 wxPageSetupDialog::wxPageSetupDialog(wxWindow
*p
, wxPageSetupData
*data
):
218 bool wxPageSetupDialog::Create(wxWindow
*p
, wxPageSetupData
*data
)
223 m_pageSetupData
= (*data
);
228 wxPageSetupDialog::~wxPageSetupDialog()
232 int wxPageSetupDialog::ShowModal()
234 int result
= wxID_CANCEL
;
239 err
= ::UMAPrOpen(NULL
) ;
242 m_pageSetupData
.ConvertToNative() ;
243 if ( ::PrStlDialog( (THPrint
) m_pageSetupData
.GetPrintData().m_macPrintSettings
) )
245 m_pageSetupData
.ConvertFromNative() ;
252 message
.Printf( "Print Error %d", err
) ;
253 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
258 #if PM_USE_SESSION_APIS
259 PMPrintSession macPrintSession
= kPMNoReference
;
262 err
= ::UMAPrOpen(&macPrintSession
) ;
265 m_pageSetupData
.ConvertToNative() ;
267 // Set up a valid PageFormat object.
268 if (m_pageSetupData
.GetPrintData().m_macPageFormat
== kPMNoPageFormat
)
270 err
= PMCreatePageFormat((PMPageFormat
*)&m_pageSetupData
.GetPrintData().m_macPageFormat
);
272 // Note that PMPageFormat is not session-specific, but calling
273 // PMSessionDefaultPageFormat assigns values specific to the printer
274 // associated with the current printing session.
275 if ((err
== noErr
) &&
276 (m_pageSetupData
.GetPrintData().m_macPageFormat
!= kPMNoPageFormat
))
278 err
= PMSessionDefaultPageFormat((PMPrintSession
)macPrintSession
,
279 (PMPageFormat
)m_pageSetupData
.GetPrintData().m_macPageFormat
);
284 err
= PMSessionValidatePageFormat((PMPrintSession
)macPrintSession
,
285 (PMPageFormat
)m_pageSetupData
.GetPrintData().m_macPageFormat
,
289 // Display the Page Setup dialog.
292 err
= PMSessionPageSetupDialog((PMPrintSession
)macPrintSession
,
293 (PMPageFormat
)m_pageSetupData
.GetPrintData().m_macPageFormat
,
295 if ((err
== noErr
) && !accepted
)
297 err
= kPMCancel
; // user clicked Cancel button
301 // If the user did not cancel, flatten and save the PageFormat object
302 // with our document.
304 // err = FlattenAndSavePageFormat(m_pageSetupData.GetPrintData().m_macPageFormat);
305 m_pageSetupData
.ConvertFromNative() ;
309 if ((err
!= noErr
) && (err
!= kPMCancel
))
311 message
.Printf( "Print Error %d", err
) ;
312 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
315 ::UMAPrClose(&macPrintSession
) ;
317 #pragma warning "TODO: Printing for carbon without session apis"