]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/printdlg.cpp
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
110 m_printDialogData
.ConvertToNative() ;
112 // Set up a valid PageFormat object.
113 if (m_printDialogData
.GetPrintData().m_macPageFormat
== kPMNoPageFormat
)
115 err
= PMCreatePageFormat((PMPageFormat
*)&m_printDialogData
.GetPrintData().m_macPageFormat
);
117 // Note that PMPageFormat is not session-specific, but calling
118 // PMSessionDefaultPageFormat assigns values specific to the printer
119 // associated with the current printing session.
120 if ((err
== noErr
) &&
121 (m_printDialogData
.GetPrintData().m_macPageFormat
!= kPMNoPageFormat
))
123 err
= PMSessionDefaultPageFormat((PMPrintSession
)m_printDialogData
.GetPrintData().m_macPrintSession
,
124 (PMPageFormat
)m_printDialogData
.GetPrintData().m_macPageFormat
);
129 err
= PMSessionValidatePageFormat((PMPrintSession
)m_printDialogData
.GetPrintData().m_macPrintSession
,
130 (PMPageFormat
)m_printDialogData
.GetPrintData().m_macPageFormat
,
134 // Set up a valid PrintSettings object.
135 if (m_printDialogData
.GetPrintData().m_macPrintSettings
== kPMNoPrintSettings
)
137 err
= PMCreatePrintSettings((PMPrintSettings
*)&m_printDialogData
.GetPrintData().m_macPrintSettings
);
139 // Note that PMPrintSettings is not session-specific, but calling
140 // PMSessionDefaultPrintSettings assigns values specific to the printer
141 // associated with the current printing session.
142 if ((err
== noErr
) &&
143 (m_printDialogData
.GetPrintData().m_macPrintSettings
!= kPMNoPrintSettings
))
145 err
= PMSessionDefaultPrintSettings((PMPrintSession
)m_printDialogData
.GetPrintData().m_macPrintSession
,
146 (PMPrintSettings
)m_printDialogData
.GetPrintData().m_macPrintSettings
);
151 err
= PMSessionValidatePrintSettings((PMPrintSession
)m_printDialogData
.GetPrintData().m_macPrintSession
,
152 (PMPrintSettings
)m_printDialogData
.GetPrintData().m_macPrintSettings
,
155 // Set a valid page range before displaying the Print dialog
158 // err = PMSetPageRange(m_printDialogData.GetPrintData().m_macPrintSettings,
159 // minPage, maxPage);
162 // Display the Print dialog.
165 err
= PMSessionPrintDialog((PMPrintSession
)m_printDialogData
.GetPrintData().m_macPrintSession
,
166 (PMPrintSettings
)m_printDialogData
.GetPrintData().m_macPrintSettings
,
167 (PMPageFormat
)m_printDialogData
.GetPrintData().m_macPageFormat
,
169 if ((err
== noErr
) && !accepted
)
171 err
= kPMCancel
; // user clicked Cancel button
176 m_printDialogData
.ConvertFromNative() ;
180 if ((err
!= noErr
) && (err
!= kPMCancel
))
182 message
.Printf( "Print Error %d", err
) ;
183 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
187 #pragma warning "TODO: Printing for carbon without session apis"
193 wxDC
*wxPrintDialog::GetPrintDC()
195 return new wxPrinterDC( m_printDialogData
.GetPrintData() ) ;
202 wxPageSetupDialog::wxPageSetupDialog():
205 m_dialogParent
= NULL
;
208 wxPageSetupDialog::wxPageSetupDialog(wxWindow
*p
, wxPageSetupData
*data
):
214 bool wxPageSetupDialog::Create(wxWindow
*p
, wxPageSetupData
*data
)
219 m_pageSetupData
= (*data
);
224 wxPageSetupDialog::~wxPageSetupDialog()
228 int wxPageSetupDialog::ShowModal()
230 int result
= wxID_CANCEL
;
235 err
= ::UMAPrOpen(NULL
) ;
238 m_pageSetupData
.ConvertToNative() ;
239 if ( ::PrStlDialog( (THPrint
) m_pageSetupData
.GetPrintData().m_macPrintSettings
) )
241 m_pageSetupData
.ConvertFromNative() ;
248 message
.Printf( "Print Error %d", err
) ;
249 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
254 #if PM_USE_SESSION_APIS
258 m_pageSetupData
.ConvertToNative() ;
260 // Set up a valid PageFormat object.
261 if (m_pageSetupData
.GetPrintData().m_macPageFormat
== kPMNoPageFormat
)
263 err
= PMCreatePageFormat((PMPageFormat
*)&m_pageSetupData
.GetPrintData().m_macPageFormat
);
265 // Note that PMPageFormat is not session-specific, but calling
266 // PMSessionDefaultPageFormat assigns values specific to the printer
267 // associated with the current printing session.
268 if ((err
== noErr
) &&
269 (m_pageSetupData
.GetPrintData().m_macPageFormat
!= kPMNoPageFormat
))
271 err
= PMSessionDefaultPageFormat((PMPrintSession
)m_pageSetupData
.GetPrintData().m_macPrintSession
,
272 (PMPageFormat
)m_pageSetupData
.GetPrintData().m_macPageFormat
);
277 err
= PMSessionValidatePageFormat((PMPrintSession
)m_pageSetupData
.GetPrintData().m_macPrintSession
,
278 (PMPageFormat
)m_pageSetupData
.GetPrintData().m_macPageFormat
,
282 // Display the Page Setup dialog.
285 err
= PMSessionPageSetupDialog((PMPrintSession
)m_pageSetupData
.GetPrintData().m_macPrintSession
,
286 (PMPageFormat
)m_pageSetupData
.GetPrintData().m_macPageFormat
,
288 if ((err
== noErr
) && !accepted
)
290 err
= kPMCancel
; // user clicked Cancel button
294 // If the user did not cancel, flatten and save the PageFormat object
295 // with our document.
297 // err = FlattenAndSavePageFormat(m_pageSetupData.GetPrintData().m_macPageFormat);
298 m_pageSetupData
.ConvertFromNative() ;
302 if ((err
!= noErr
) && (err
!= kPMCancel
))
304 message
.Printf( "Print Error %d", err
) ;
305 wxMessageDialog
dialog( NULL
, message
, "", wxICON_HAND
| wxOK
) ;
309 #pragma warning "TODO: Printing for carbon without session apis"