]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/printdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/printdlg.cpp
3 // Purpose: wxPrintDialog, wxPageSetupDialog
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
15 #include "wx/printdlg.h"
18 #include "wx/object.h"
19 #include "wx/dcprint.h"
20 #include "wx/msgdlg.h"
23 #include "wx/mac/private/print.h"
25 // Use generic page setup dialog: use your own native one if one exists.
27 IMPLEMENT_DYNAMIC_CLASS ( wxPrintDialog
, wxDialog
)
28 IMPLEMENT_CLASS ( wxPageSetupDialog
, wxDialog
)
30 wxPrintDialog :: wxPrintDialog ()
32 m_dialogParent
= NULL
;
37 wxPrintDialog :: wxPrintDialog ( wxWindow
* p
, wxPrintDialogData
* data
)
42 wxPrintDialog :: wxPrintDialog ( wxWindow
* p
, wxPrintData
* data
)
44 wxPrintDialogData data2
;
51 bool wxPrintDialog :: Create ( wxWindow
* p
, wxPrintDialogData
* data
)
58 m_printDialogData
= * data
;
63 wxPrintDialog ::~ wxPrintDialog ()
65 if ( m_destroyDC
&& m_printerDC
) {
71 int wxPrintDialog :: ShowModal ()
73 m_printDialogData
. ConvertToNative () ;
74 int result
= m_printDialogData
. GetPrintData (). m_nativePrintData
-> ShowPrintDialog () ;
75 if ( result
== wxID_OK
)
76 m_printDialogData
. ConvertFromNative () ;
81 wxDC
* wxPrintDialog :: GetPrintDC ()
83 return new wxPrinterDC ( m_printDialogData
. GetPrintData () ) ;
90 wxPageSetupDialog :: wxPageSetupDialog ():
93 m_dialogParent
= NULL
;
96 wxPageSetupDialog :: wxPageSetupDialog ( wxWindow
* p
, wxPageSetupData
* data
):
102 bool wxPageSetupDialog :: Create ( wxWindow
* p
, wxPageSetupData
* data
)
107 m_pageSetupData
= (* data
);
112 wxPageSetupDialog ::~ wxPageSetupDialog ()
116 int wxPageSetupDialog :: ShowModal ()
118 m_pageSetupData
. ConvertToNative () ;
119 int result
= m_pageSetupData
. GetPrintData (). m_nativePrintData
-> ShowPageSetupDialog () ;
120 if ( result
== wxID_OK
)
121 m_pageSetupData
. ConvertFromNative () ;
127 IMPLEMENT_CLASS ( wxMacPageMarginsDialog
, wxDialog
)
129 wxMacPageMarginsDialog :: wxMacPageMarginsDialog ( wxFrame
* parent
, wxPageSetupData
* data
) :
130 wxDialog ( parent
, wxID_ANY
, wxString ( wxT ( "Page Margins" ))),
131 m_pageSetupDialogData ( data
)
134 wxBoxSizer
* colSizer
= new wxBoxSizer ( wxVERTICAL
);
135 wxFlexGridSizer
* gridSizer
= new wxFlexGridSizer ( 4 , 5 , 5 );
136 colSizer
-> Add ( gridSizer
, wxSizerFlags (). Border ( wxALL
, 5 ));
137 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Left (mm):" )), wxSizerFlags (). Right ());
138 gridSizer
-> Add ( m_LeftMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
139 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Top (mm):" )), wxSizerFlags (). Right ());
140 gridSizer
-> Add ( m_TopMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
141 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Right (mm):" )), wxSizerFlags (). Right ());
142 gridSizer
-> Add ( m_RightMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
143 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Bottom (mm):" )), wxSizerFlags (). Right ());
144 gridSizer
-> Add ( m_BottomMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
145 colSizer
-> Add ( new wxStaticLine ( this ), wxSizerFlags (). Expand (). Border ( wxTOP
| wxBOTTOM
, 5 ));
146 colSizer
-> Add ( CreateButtonSizer ( wxOK
| wxCANCEL
), wxSizerFlags (). Expand (). Border ( wxALL
, 5 ));
148 SetSizerAndFit ( colSizer
);
152 bool wxMacPageMarginsDialog :: TransferToWindow ()
154 wxASSERT ( m_pageSetupDialogData
);
155 wxPoint topLeft
= m_pageSetupDialogData
-> GetMarginTopLeft ();
156 wxPoint bottomRight
= m_pageSetupDialogData
-> GetMarginBottomRight ();
157 wxPoint minTopLeft
= m_pageSetupDialogData
-> GetMinMarginTopLeft ();
158 wxPoint minBottomRight
= m_pageSetupDialogData
-> GetMinMarginBottomRight ();
159 m_LeftMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( topLeft
. x
, minTopLeft
. x
)));
160 m_LeftMargin
-> SetSelection (- 1 , - 1 );
161 m_TopMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( topLeft
. y
, minTopLeft
. y
)));
162 m_TopMargin
-> SetSelection (- 1 , - 1 );
163 m_RightMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( bottomRight
. x
, minBottomRight
. x
)));
164 m_RightMargin
-> SetSelection (- 1 , - 1 );
165 m_BottomMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( bottomRight
. y
, minBottomRight
. y
)));
166 m_BottomMargin
-> SetSelection (- 1 , - 1 );
167 m_LeftMargin
-> SetFocus ();
171 bool wxMacPageMarginsDialog :: TransferDataFromWindow ()
173 wxPoint topLeft
, bottomRight
;
174 if (! CheckValue ( m_LeftMargin
, & topLeft
. x
, m_MinMarginTopLeft
. x
, wxT ( "left margin" ))) return false ;
175 if (! CheckValue ( m_TopMargin
, & topLeft
. y
, m_MinMarginTopLeft
. y
, wxT ( "top margin" ))) return false ;
176 if (! CheckValue ( m_RightMargin
, & bottomRight
. x
, m_MinMarginBottomRight
. x
, wxT ( "right margin" ))) return false ;
177 if (! CheckValue ( m_BottomMargin
, & bottomRight
. y
, m_MinMarginBottomRight
. y
, wxT ( "bottom margin" ))) return false ;
178 m_pageSetupDialogData
-> SetMarginTopLeft ( topLeft
);
179 m_pageSetupDialogData
-> SetMarginBottomRight ( bottomRight
);
183 bool wxMacPageMarginsDialog :: CheckValue ( wxTextCtrl
* textCtrl
, int * value
, int minValue
, const wxString
& name
)
186 if (! textCtrl
-> GetValue (). ToLong (& lvalue
))
188 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" ));
191 if ( lvalue
< minValue
)
193 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" ));
194 textCtrl
-> SetValue ( wxString :: Format ( wxT ( " %d " ), minValue
));
195 textCtrl
-> SetSelection (- 1 , - 1 );
196 textCtrl
-> SetFocus ();
199 * value
= int ( lvalue
);
203 void wxMacPageMarginsDialog :: GetMinMargins ()
205 m_MinMarginTopLeft
= m_pageSetupDialogData
-> GetMinMarginTopLeft ();
206 m_MinMarginBottomRight
= m_pageSetupDialogData
-> GetMinMarginBottomRight ();