]>
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
;
87 // TODO use NSPrintPanel
91 err
= PMSessionPrintDialog (
92 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> m_macPrintSession
,
93 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> m_macPrintSettings
,
94 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> m_macPageFormat
,
97 if (( err
== noErr
) && ! accepted
)
99 // user clicked Cancel button
108 if (( err
!= noErr
) && ( err
!= kPMCancel
))
112 message
. Printf ( wxT ( "Print Error %d " ), err
);
113 wxMessageDialog
dialog ( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
);
117 if ( result
== wxID_OK
)
119 m_printDialogData
. GetPrintData (). ConvertFromNative ();
120 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> TransferTo ( & m_printDialogData
);
126 wxDC
* wxMacPrintDialog :: GetPrintDC ()
128 return new wxPrinterDC ( m_printDialogData
. GetPrintData () );
131 IMPLEMENT_CLASS ( wxMacPageSetupDialog
, wxPageSetupDialogBase
)
133 wxMacPageSetupDialog :: wxMacPageSetupDialog ( wxWindow
* p
, wxPageSetupData
* data
)
134 : wxPageSetupDialogBase ()
139 bool wxMacPageSetupDialog :: Create ( wxWindow
* p
, wxPageSetupData
* data
)
144 m_pageSetupData
= (* data
);
149 wxMacPageSetupDialog ::~ wxMacPageSetupDialog ()
153 wxPageSetupData
& wxMacPageSetupDialog :: GetPageSetupDialogData ()
155 return m_pageSetupData
;
158 int wxMacPageSetupDialog :: ShowModal ()
160 m_pageSetupData
. GetPrintData (). ConvertToNative ();
161 (( wxMacCarbonPrintData
*) m_pageSetupData
. GetPrintData (). GetNativeData ())-> TransferFrom ( & m_pageSetupData
);
163 int result
= wxID_CANCEL
;
169 err
= PMSessionPageSetupDialog (
170 (( wxMacCarbonPrintData
*) m_pageSetupData
. GetPrintData (). GetNativeData ())-> m_macPrintSession
,
171 (( wxMacCarbonPrintData
*) m_pageSetupData
. GetPrintData (). GetNativeData ())-> m_macPageFormat
,
174 if (( err
== noErr
) && ! accepted
)
176 // user clicked Cancel button
180 // If the user did not cancel, flatten and save the PageFormat object
181 // with our document.
187 if (( err
!= noErr
) && ( err
!= kPMCancel
))
191 message
. Printf ( wxT ( "Print Error %d " ), err
);
192 wxMessageDialog
dialog ( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
);
196 if ( result
== wxID_OK
)
198 m_pageSetupData
. GetPrintData (). ConvertFromNative ();
199 m_pageSetupData
. SetPaperSize ( m_pageSetupData
. GetPrintData (). GetPaperSize () );
200 (( wxMacCarbonPrintData
*) m_pageSetupData
. GetPrintData (). GetNativeData ())-> TransferTo ( & m_pageSetupData
);
207 IMPLEMENT_CLASS ( wxMacPageMarginsDialog
, wxDialog
)
209 wxMacPageMarginsDialog :: wxMacPageMarginsDialog ( wxFrame
* parent
, wxPageSetupData
* data
) :
210 wxDialog ( parent
, wxID_ANY
, wxString ( wxT ( "Page Margins" ))),
211 m_pageSetupDialogData ( data
)
214 wxBoxSizer
* colSizer
= new wxBoxSizer ( wxVERTICAL
);
215 wxFlexGridSizer
* gridSizer
= new wxFlexGridSizer ( 4 , 5 , 5 );
216 colSizer
-> Add ( gridSizer
, wxSizerFlags (). Border ( wxALL
, 5 ));
217 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Left (mm):" )), wxSizerFlags (). Right ());
218 gridSizer
-> Add ( m_LeftMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
219 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Top (mm):" )), wxSizerFlags (). Right ());
220 gridSizer
-> Add ( m_TopMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
221 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Right (mm):" )), wxSizerFlags (). Right ());
222 gridSizer
-> Add ( m_RightMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
223 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Bottom (mm):" )), wxSizerFlags (). Right ());
224 gridSizer
-> Add ( m_BottomMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
225 colSizer
-> Add ( new wxStaticLine ( this ), wxSizerFlags (). Expand (). Border ( wxTOP
| wxBOTTOM
, 5 ));
226 colSizer
-> Add ( CreateButtonSizer ( wxOK
| wxCANCEL
), wxSizerFlags (). Expand (). Border ( wxALL
, 5 ));
228 SetSizerAndFit ( colSizer
);
232 bool wxMacPageMarginsDialog :: TransferToWindow ()
234 wxASSERT ( m_pageSetupDialogData
);
235 wxPoint topLeft
= m_pageSetupDialogData
-> GetMarginTopLeft ();
236 wxPoint bottomRight
= m_pageSetupDialogData
-> GetMarginBottomRight ();
237 wxPoint minTopLeft
= m_pageSetupDialogData
-> GetMinMarginTopLeft ();
238 wxPoint minBottomRight
= m_pageSetupDialogData
-> GetMinMarginBottomRight ();
239 m_LeftMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( topLeft
. x
, minTopLeft
. x
)));
240 m_LeftMargin
-> SetSelection (- 1 , - 1 );
241 m_TopMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( topLeft
. y
, minTopLeft
. y
)));
242 m_TopMargin
-> SetSelection (- 1 , - 1 );
243 m_RightMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( bottomRight
. x
, minBottomRight
. x
)));
244 m_RightMargin
-> SetSelection (- 1 , - 1 );
245 m_BottomMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( bottomRight
. y
, minBottomRight
. y
)));
246 m_BottomMargin
-> SetSelection (- 1 , - 1 );
247 m_LeftMargin
-> SetFocus ();
251 bool wxMacPageMarginsDialog :: TransferDataFromWindow ()
253 wxPoint topLeft
, bottomRight
;
254 if (! CheckValue ( m_LeftMargin
, & topLeft
. x
, m_MinMarginTopLeft
. x
, wxT ( "left margin" ))) return false ;
255 if (! CheckValue ( m_TopMargin
, & topLeft
. y
, m_MinMarginTopLeft
. y
, wxT ( "top margin" ))) return false ;
256 if (! CheckValue ( m_RightMargin
, & bottomRight
. x
, m_MinMarginBottomRight
. x
, wxT ( "right margin" ))) return false ;
257 if (! CheckValue ( m_BottomMargin
, & bottomRight
. y
, m_MinMarginBottomRight
. y
, wxT ( "bottom margin" ))) return false ;
258 m_pageSetupDialogData
-> SetMarginTopLeft ( topLeft
);
259 m_pageSetupDialogData
-> SetMarginBottomRight ( bottomRight
);
263 bool wxMacPageMarginsDialog :: CheckValue ( wxTextCtrl
* textCtrl
, int * value
, int minValue
, const wxString
& name
)
266 if (! textCtrl
-> GetValue (). ToLong (& lvalue
))
268 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" ));
271 if ( lvalue
< minValue
)
273 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" ));
274 textCtrl
-> SetValue ( wxString :: Format ( wxT ( " %d " ), minValue
));
275 textCtrl
-> SetSelection (- 1 , - 1 );
276 textCtrl
-> SetFocus ();
279 * value
= int ( lvalue
);
283 void wxMacPageMarginsDialog :: GetMinMargins ()
285 m_MinMarginTopLeft
= m_pageSetupDialogData
-> GetMinMarginTopLeft ();
286 m_MinMarginBottomRight
= m_pageSetupDialogData
-> GetMinMarginBottomRight ();