]>
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/mac/private.h"
30 #include "wx/statline.h"
33 // Use generic page setup dialog: use your own native one if one exists.
35 IMPLEMENT_DYNAMIC_CLASS ( wxMacPrintDialog
, wxPrintDialogBase
)
38 wxMacPrintDialog :: wxMacPrintDialog ()
40 m_dialogParent
= NULL
;
45 wxMacPrintDialog :: wxMacPrintDialog ( wxWindow
* p
, wxPrintDialogData
* data
)
50 wxMacPrintDialog :: wxMacPrintDialog ( wxWindow
* p
, wxPrintData
* data
)
52 wxPrintDialogData data2
;
59 bool wxMacPrintDialog :: Create ( wxWindow
* p
, wxPrintDialogData
* data
)
66 m_printDialogData
= * data
;
71 wxMacPrintDialog ::~ wxMacPrintDialog ()
73 if ( m_destroyDC
&& m_printerDC
)
80 int wxMacPrintDialog :: ShowModal ()
82 m_printDialogData
. GetPrintData (). ConvertToNative ();
83 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> TransferFrom ( & m_printDialogData
);
85 int result
= wxID_CANCEL
;
88 // TODO use NSPrintPanel
92 err
= PMSessionPrintDialog (
93 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> m_macPrintSession
,
94 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> m_macPrintSettings
,
95 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> m_macPageFormat
,
98 if (( err
== noErr
) && ! accepted
)
100 // user clicked Cancel button
109 if (( err
!= noErr
) && ( err
!= kPMCancel
))
113 message
. Printf ( wxT ( "Print Error %d " ), err
);
114 wxMessageDialog
dialog ( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
);
118 if ( result
== wxID_OK
)
120 m_printDialogData
. GetPrintData (). ConvertFromNative ();
121 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> TransferTo ( & m_printDialogData
);
127 wxDC
* wxMacPrintDialog :: GetPrintDC ()
129 return new wxPrinterDC ( m_printDialogData
. GetPrintData () );
132 IMPLEMENT_CLASS ( wxMacPageSetupDialog
, wxPageSetupDialogBase
)
134 wxMacPageSetupDialog :: wxMacPageSetupDialog ( wxWindow
* p
, wxPageSetupData
* data
)
135 : wxPageSetupDialogBase ()
140 bool wxMacPageSetupDialog :: Create ( wxWindow
* p
, wxPageSetupData
* data
)
145 m_pageSetupData
= (* data
);
150 wxMacPageSetupDialog ::~ wxMacPageSetupDialog ()
154 wxPageSetupData
& wxMacPageSetupDialog :: GetPageSetupDialogData ()
156 return m_pageSetupData
;
159 int wxMacPageSetupDialog :: ShowModal ()
161 m_pageSetupData
. GetPrintData (). ConvertToNative ();
162 (( wxMacCarbonPrintData
*) m_pageSetupData
. GetPrintData (). GetNativeData ())-> TransferFrom ( & m_pageSetupData
);
164 int result
= wxID_CANCEL
;
170 err
= PMSessionPageSetupDialog (
171 (( wxMacCarbonPrintData
*) m_pageSetupData
. GetPrintData (). GetNativeData ())-> m_macPrintSession
,
172 (( wxMacCarbonPrintData
*) m_pageSetupData
. GetPrintData (). GetNativeData ())-> m_macPageFormat
,
175 if (( err
== noErr
) && ! accepted
)
177 // user clicked Cancel button
181 // If the user did not cancel, flatten and save the PageFormat object
182 // with our document.
188 if (( err
!= noErr
) && ( err
!= kPMCancel
))
192 message
. Printf ( wxT ( "Print Error %d " ), err
);
193 wxMessageDialog
dialog ( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
);
197 if ( result
== wxID_OK
)
199 m_pageSetupData
. GetPrintData (). ConvertFromNative ();
200 m_pageSetupData
. SetPaperSize ( m_pageSetupData
. GetPrintData (). GetPaperSize () );
201 (( wxMacCarbonPrintData
*) m_pageSetupData
. GetPrintData (). GetNativeData ())-> TransferTo ( & m_pageSetupData
);
208 IMPLEMENT_CLASS ( wxMacPageMarginsDialog
, wxDialog
)
210 wxMacPageMarginsDialog :: wxMacPageMarginsDialog ( wxFrame
* parent
, wxPageSetupData
* data
) :
211 wxDialog ( parent
, wxID_ANY
, wxString ( wxT ( "Page Margins" ))),
212 m_pageSetupDialogData ( data
)
215 wxBoxSizer
* colSizer
= new wxBoxSizer ( wxVERTICAL
);
216 wxFlexGridSizer
* gridSizer
= new wxFlexGridSizer ( 4 , 5 , 5 );
217 colSizer
-> Add ( gridSizer
, wxSizerFlags (). Border ( wxALL
, 5 ));
218 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Left (mm):" )), wxSizerFlags (). Right ());
219 gridSizer
-> Add ( m_LeftMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
220 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Top (mm):" )), wxSizerFlags (). Right ());
221 gridSizer
-> Add ( m_TopMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
222 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Right (mm):" )), wxSizerFlags (). Right ());
223 gridSizer
-> Add ( m_RightMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
224 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Bottom (mm):" )), wxSizerFlags (). Right ());
225 gridSizer
-> Add ( m_BottomMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
226 colSizer
-> Add ( new wxStaticLine ( this ), wxSizerFlags (). Expand (). Border ( wxTOP
| wxBOTTOM
, 5 ));
227 colSizer
-> Add ( CreateButtonSizer ( wxOK
| wxCANCEL
), wxSizerFlags (). Expand (). Border ( wxALL
, 5 ));
229 SetSizerAndFit ( colSizer
);
233 bool wxMacPageMarginsDialog :: TransferToWindow ()
235 wxASSERT ( m_pageSetupDialogData
);
236 wxPoint topLeft
= m_pageSetupDialogData
-> GetMarginTopLeft ();
237 wxPoint bottomRight
= m_pageSetupDialogData
-> GetMarginBottomRight ();
238 wxPoint minTopLeft
= m_pageSetupDialogData
-> GetMinMarginTopLeft ();
239 wxPoint minBottomRight
= m_pageSetupDialogData
-> GetMinMarginBottomRight ();
240 m_LeftMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( topLeft
. x
, minTopLeft
. x
)));
241 m_LeftMargin
-> SetSelection (- 1 , - 1 );
242 m_TopMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( topLeft
. y
, minTopLeft
. y
)));
243 m_TopMargin
-> SetSelection (- 1 , - 1 );
244 m_RightMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( bottomRight
. x
, minBottomRight
. x
)));
245 m_RightMargin
-> SetSelection (- 1 , - 1 );
246 m_BottomMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( bottomRight
. y
, minBottomRight
. y
)));
247 m_BottomMargin
-> SetSelection (- 1 , - 1 );
248 m_LeftMargin
-> SetFocus ();
252 bool wxMacPageMarginsDialog :: TransferDataFromWindow ()
254 wxPoint topLeft
, bottomRight
;
255 if (! CheckValue ( m_LeftMargin
, & topLeft
. x
, m_MinMarginTopLeft
. x
, wxT ( "left margin" ))) return false ;
256 if (! CheckValue ( m_TopMargin
, & topLeft
. y
, m_MinMarginTopLeft
. y
, wxT ( "top margin" ))) return false ;
257 if (! CheckValue ( m_RightMargin
, & bottomRight
. x
, m_MinMarginBottomRight
. x
, wxT ( "right margin" ))) return false ;
258 if (! CheckValue ( m_BottomMargin
, & bottomRight
. y
, m_MinMarginBottomRight
. y
, wxT ( "bottom margin" ))) return false ;
259 m_pageSetupDialogData
-> SetMarginTopLeft ( topLeft
);
260 m_pageSetupDialogData
-> SetMarginBottomRight ( bottomRight
);
264 bool wxMacPageMarginsDialog :: CheckValue ( wxTextCtrl
* textCtrl
, int * value
, int minValue
, const wxString
& name
)
267 if (! textCtrl
-> GetValue (). ToLong (& lvalue
))
269 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" ));
272 if ( lvalue
< minValue
)
274 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" ));
275 textCtrl
-> SetValue ( wxString :: Format ( wxT ( " %d " ), minValue
));
276 textCtrl
-> SetSelection (- 1 , - 1 );
277 textCtrl
-> SetFocus ();
280 * value
= int ( lvalue
);
284 void wxMacPageMarginsDialog :: GetMinMargins ()
286 m_MinMarginTopLeft
= m_pageSetupDialogData
-> GetMinMarginTopLeft ();
287 m_MinMarginBottomRight
= m_pageSetupDialogData
-> GetMinMarginBottomRight ();