]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/printdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/printdlg.cpp
3 // Purpose: wxPrintDialog, wxPageSetupDialog
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #if wxUSE_PRINTING_ARCHITECTURE
16 #include "wx/printdlg.h"
19 #include "wx/object.h"
20 #include "wx/dcprint.h"
21 #include "wx/msgdlg.h"
22 #include "wx/textctrl.h"
24 #include "wx/stattext.h"
27 #include "wx/mac/printdlg.h"
28 #include "wx/mac/private/print.h"
29 #include "wx/statline.h"
32 // Use generic page setup dialog: use your own native one if one exists.
34 IMPLEMENT_DYNAMIC_CLASS ( wxMacPrintDialog
, wxPrintDialogBase
)
37 wxMacPrintDialog :: wxMacPrintDialog ()
39 m_dialogParent
= NULL
;
44 wxMacPrintDialog :: wxMacPrintDialog ( wxWindow
* p
, wxPrintDialogData
* data
)
49 wxMacPrintDialog :: wxMacPrintDialog ( wxWindow
* p
, wxPrintData
* data
)
51 wxPrintDialogData data2
;
58 bool wxMacPrintDialog :: Create ( wxWindow
* p
, wxPrintDialogData
* data
)
65 m_printDialogData
= * data
;
70 wxMacPrintDialog ::~ wxMacPrintDialog ()
72 if ( m_destroyDC
&& m_printerDC
)
79 int wxMacPrintDialog :: ShowModal ()
81 m_printDialogData
. GetPrintData (). ConvertToNative ();
82 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> TransferFrom ( & m_printDialogData
);
84 int result
= wxID_CANCEL
;
88 err
= PMSessionPrintDialog (
89 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> m_macPrintSession
,
90 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> m_macPrintSettings
,
91 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> m_macPageFormat
,
94 if (( err
== noErr
) && ! accepted
)
96 // user clicked Cancel button
105 if (( err
!= noErr
) && ( err
!= kPMCancel
))
109 message
. Printf ( wxT ( "Print Error %d " ), err
);
110 wxMessageDialog
dialog ( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
);
114 if ( result
== wxID_OK
)
116 m_printDialogData
. GetPrintData (). ConvertFromNative ();
117 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> TransferTo ( & m_printDialogData
);
123 wxDC
* wxMacPrintDialog :: GetPrintDC ()
125 return new wxPrinterDC ( m_printDialogData
. GetPrintData () );
128 IMPLEMENT_CLASS ( wxMacPageSetupDialog
, wxPageSetupDialogBase
)
130 wxMacPageSetupDialog :: wxMacPageSetupDialog ( wxWindow
* p
, wxPageSetupData
* data
)
131 : wxPageSetupDialogBase ()
136 bool wxMacPageSetupDialog :: Create ( wxWindow
* p
, wxPageSetupData
* data
)
141 m_pageSetupData
= (* data
);
146 wxMacPageSetupDialog ::~ wxMacPageSetupDialog ()
150 wxPageSetupData
& wxMacPageSetupDialog :: GetPageSetupDialogData ()
152 return m_pageSetupData
;
155 int wxMacPageSetupDialog :: ShowModal ()
157 m_pageSetupData
. GetPrintData (). ConvertToNative ();
158 (( wxMacCarbonPrintData
*) m_pageSetupData
. GetPrintData (). GetNativeData ())-> TransferFrom ( & m_pageSetupData
);
160 int result
= wxID_CANCEL
;
164 err
= PMSessionPageSetupDialog (
165 (( wxMacCarbonPrintData
*) m_pageSetupData
. GetPrintData (). GetNativeData ())-> m_macPrintSession
,
166 (( wxMacCarbonPrintData
*) m_pageSetupData
. GetPrintData (). GetNativeData ())-> m_macPageFormat
,
169 if (( err
== noErr
) && ! accepted
)
171 // user clicked Cancel button
175 // If the user did not cancel, flatten and save the PageFormat object
176 // with our document.
182 if (( err
!= noErr
) && ( err
!= kPMCancel
))
186 message
. Printf ( wxT ( "Print Error %d " ), err
);
187 wxMessageDialog
dialog ( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
);
191 if ( result
== wxID_OK
)
193 m_pageSetupData
. GetPrintData (). ConvertFromNative ();
194 m_pageSetupData
. SetPaperSize ( m_pageSetupData
. GetPrintData (). GetPaperSize () );
195 (( wxMacCarbonPrintData
*) m_pageSetupData
. GetPrintData (). GetNativeData ())-> TransferTo ( & m_pageSetupData
);
202 IMPLEMENT_CLASS ( wxMacPageMarginsDialog
, wxDialog
)
204 wxMacPageMarginsDialog :: wxMacPageMarginsDialog ( wxFrame
* parent
, wxPageSetupData
* data
) :
205 wxDialog ( parent
, wxID_ANY
, wxString ( wxT ( "Page Margins" ))),
206 m_pageSetupDialogData ( data
)
209 wxBoxSizer
* colSizer
= new wxBoxSizer ( wxVERTICAL
);
210 wxFlexGridSizer
* gridSizer
= new wxFlexGridSizer ( 4 , 5 , 5 );
211 colSizer
-> Add ( gridSizer
, wxSizerFlags (). Border ( wxALL
, 5 ));
212 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Left (mm):" )), wxSizerFlags (). Right ());
213 gridSizer
-> Add ( m_LeftMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
214 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Top (mm):" )), wxSizerFlags (). Right ());
215 gridSizer
-> Add ( m_TopMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
216 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Right (mm):" )), wxSizerFlags (). Right ());
217 gridSizer
-> Add ( m_RightMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
218 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Bottom (mm):" )), wxSizerFlags (). Right ());
219 gridSizer
-> Add ( m_BottomMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
220 colSizer
-> Add ( new wxStaticLine ( this ), wxSizerFlags (). Expand (). Border ( wxTOP
| wxBOTTOM
, 5 ));
221 colSizer
-> Add ( CreateButtonSizer ( wxOK
| wxCANCEL
), wxSizerFlags (). Expand (). Border ( wxALL
, 5 ));
223 SetSizerAndFit ( colSizer
);
227 bool wxMacPageMarginsDialog :: TransferToWindow ()
229 wxASSERT ( m_pageSetupDialogData
);
230 wxPoint topLeft
= m_pageSetupDialogData
-> GetMarginTopLeft ();
231 wxPoint bottomRight
= m_pageSetupDialogData
-> GetMarginBottomRight ();
232 wxPoint minTopLeft
= m_pageSetupDialogData
-> GetMinMarginTopLeft ();
233 wxPoint minBottomRight
= m_pageSetupDialogData
-> GetMinMarginBottomRight ();
234 m_LeftMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( topLeft
. x
, minTopLeft
. x
)));
235 m_LeftMargin
-> SetSelection (- 1 , - 1 );
236 m_TopMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( topLeft
. y
, minTopLeft
. y
)));
237 m_TopMargin
-> SetSelection (- 1 , - 1 );
238 m_RightMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( bottomRight
. x
, minBottomRight
. x
)));
239 m_RightMargin
-> SetSelection (- 1 , - 1 );
240 m_BottomMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( bottomRight
. y
, minBottomRight
. y
)));
241 m_BottomMargin
-> SetSelection (- 1 , - 1 );
242 m_LeftMargin
-> SetFocus ();
246 bool wxMacPageMarginsDialog :: TransferDataFromWindow ()
248 wxPoint topLeft
, bottomRight
;
249 if (! CheckValue ( m_LeftMargin
, & topLeft
. x
, m_MinMarginTopLeft
. x
, wxT ( "left margin" ))) return false ;
250 if (! CheckValue ( m_TopMargin
, & topLeft
. y
, m_MinMarginTopLeft
. y
, wxT ( "top margin" ))) return false ;
251 if (! CheckValue ( m_RightMargin
, & bottomRight
. x
, m_MinMarginBottomRight
. x
, wxT ( "right margin" ))) return false ;
252 if (! CheckValue ( m_BottomMargin
, & bottomRight
. y
, m_MinMarginBottomRight
. y
, wxT ( "bottom margin" ))) return false ;
253 m_pageSetupDialogData
-> SetMarginTopLeft ( topLeft
);
254 m_pageSetupDialogData
-> SetMarginBottomRight ( bottomRight
);
258 bool wxMacPageMarginsDialog :: CheckValue ( wxTextCtrl
* textCtrl
, int * value
, int minValue
, const wxString
& name
)
261 if (! textCtrl
-> GetValue (). ToLong (& lvalue
))
263 wxMessageBox ( wxString :: Format ( wxT ( "Sorry, \" %s \" is not a valid numerical value for the %s " ), textCtrl
-> GetValue (). c_str (), name
. c_str ()), wxT ( "Page Margin Error" ));
266 if ( lvalue
< minValue
)
268 wxMessageBox ( wxString :: Format ( wxT ( "Sorry, \" %s \" is not a valid value for the %s , which must be >= %d " ), textCtrl
-> GetValue (). c_str (), name
. c_str (), minValue
), wxT ( "Page Margin Error" ));
269 textCtrl
-> SetValue ( wxString :: Format ( wxT ( " %d " ), minValue
));
270 textCtrl
-> SetSelection (- 1 , - 1 );
271 textCtrl
-> SetFocus ();
274 * value
= int ( lvalue
);
278 void wxMacPageMarginsDialog :: GetMinMargins ()
280 m_MinMarginTopLeft
= m_pageSetupDialogData
-> GetMinMarginTopLeft ();
281 m_MinMarginBottomRight
= m_pageSetupDialogData
-> GetMinMarginBottomRight ();