]>
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"
24 #include "wx/mac/printdlg.h"
25 #include "wx/mac/private/print.h"
26 #include "wx/statline.h"
29 // Use generic page setup dialog: use your own native one if one exists.
31 IMPLEMENT_DYNAMIC_CLASS ( wxMacPrintDialog
, wxPrintDialogBase
)
34 wxMacPrintDialog :: wxMacPrintDialog ()
36 m_dialogParent
= NULL
;
41 wxMacPrintDialog :: wxMacPrintDialog ( wxWindow
* p
, wxPrintDialogData
* data
)
46 wxMacPrintDialog :: wxMacPrintDialog ( wxWindow
* p
, wxPrintData
* data
)
48 wxPrintDialogData data2
;
55 bool wxMacPrintDialog :: Create ( wxWindow
* p
, wxPrintDialogData
* data
)
62 m_printDialogData
= * data
;
67 wxMacPrintDialog ::~ wxMacPrintDialog ()
69 if ( m_destroyDC
&& m_printerDC
)
76 int wxMacPrintDialog :: ShowModal ()
78 m_printDialogData
. GetPrintData (). ConvertToNative ();
79 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> TransferFrom ( & m_printDialogData
);
81 int result
= wxID_CANCEL
;
85 err
= PMSessionPrintDialog (
86 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> m_macPrintSession
,
87 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> m_macPrintSettings
,
88 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> m_macPageFormat
,
91 if (( err
== noErr
) && ! accepted
)
93 // user clicked Cancel button
102 if (( err
!= noErr
) && ( err
!= kPMCancel
))
106 message
. Printf ( wxT ( "Print Error %d " ), err
);
107 wxMessageDialog
dialog ( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
);
111 if ( result
== wxID_OK
)
113 m_printDialogData
. GetPrintData (). ConvertFromNative ();
114 (( wxMacCarbonPrintData
*) m_printDialogData
. GetPrintData (). GetNativeData ())-> TransferTo ( & m_printDialogData
);
120 wxDC
* wxMacPrintDialog :: GetPrintDC ()
122 return new wxPrinterDC ( m_printDialogData
. GetPrintData () );
125 IMPLEMENT_CLASS ( wxMacPageSetupDialog
, wxPageSetupDialogBase
)
127 wxMacPageSetupDialog :: wxMacPageSetupDialog ( wxWindow
* p
, wxPageSetupData
* data
)
128 : wxPageSetupDialogBase ()
133 bool wxMacPageSetupDialog :: Create ( wxWindow
* p
, wxPageSetupData
* data
)
138 m_pageSetupData
= (* data
);
143 wxMacPageSetupDialog ::~ wxMacPageSetupDialog ()
147 wxPageSetupData
& wxMacPageSetupDialog :: GetPageSetupDialogData ()
149 return m_pageSetupData
;
152 int wxMacPageSetupDialog :: ShowModal ()
154 m_pageSetupData
. GetPrintData (). ConvertToNative ();
155 (( wxMacCarbonPrintData
*) m_pageSetupData
. GetPrintData (). GetNativeData ())-> TransferFrom ( & m_pageSetupData
);
157 int result
= wxID_CANCEL
;
161 err
= PMSessionPageSetupDialog (
162 (( wxMacCarbonPrintData
*) m_pageSetupData
. GetPrintData (). GetNativeData ())-> m_macPrintSession
,
163 (( wxMacCarbonPrintData
*) m_pageSetupData
. GetPrintData (). GetNativeData ())-> m_macPageFormat
,
166 if (( err
== noErr
) && ! accepted
)
168 // user clicked Cancel button
172 // If the user did not cancel, flatten and save the PageFormat object
173 // with our document.
179 if (( err
!= noErr
) && ( err
!= kPMCancel
))
183 message
. Printf ( wxT ( "Print Error %d " ), err
);
184 wxMessageDialog
dialog ( NULL
, message
, wxEmptyString
, wxICON_HAND
| wxOK
);
188 if ( result
== wxID_OK
)
190 m_pageSetupData
. GetPrintData (). ConvertFromNative ();
191 m_pageSetupData
. SetPaperSize ( m_pageSetupData
. GetPrintData (). GetPaperSize () );
192 (( wxMacCarbonPrintData
*) m_pageSetupData
. GetPrintData (). GetNativeData ())-> TransferTo ( & m_pageSetupData
);
199 IMPLEMENT_CLASS ( wxMacPageMarginsDialog
, wxDialog
)
201 wxMacPageMarginsDialog :: wxMacPageMarginsDialog ( wxFrame
* parent
, wxPageSetupData
* data
) :
202 wxDialog ( parent
, wxID_ANY
, wxString ( wxT ( "Page Margins" ))),
203 m_pageSetupDialogData ( data
)
206 wxBoxSizer
* colSizer
= new wxBoxSizer ( wxVERTICAL
);
207 wxFlexGridSizer
* gridSizer
= new wxFlexGridSizer ( 4 , 5 , 5 );
208 colSizer
-> Add ( gridSizer
, wxSizerFlags (). Border ( wxALL
, 5 ));
209 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Left (mm):" )), wxSizerFlags (). Right ());
210 gridSizer
-> Add ( m_LeftMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
211 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Top (mm):" )), wxSizerFlags (). Right ());
212 gridSizer
-> Add ( m_TopMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
213 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Right (mm):" )), wxSizerFlags (). Right ());
214 gridSizer
-> Add ( m_RightMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
215 gridSizer
-> Add ( new wxStaticText ( this , wxID_ANY
, wxT ( "Bottom (mm):" )), wxSizerFlags (). Right ());
216 gridSizer
-> Add ( m_BottomMargin
= new wxTextCtrl ( this , wxID_ANY
), wxSizerFlags (). Left ());
217 colSizer
-> Add ( new wxStaticLine ( this ), wxSizerFlags (). Expand (). Border ( wxTOP
| wxBOTTOM
, 5 ));
218 colSizer
-> Add ( CreateButtonSizer ( wxOK
| wxCANCEL
), wxSizerFlags (). Expand (). Border ( wxALL
, 5 ));
220 SetSizerAndFit ( colSizer
);
224 bool wxMacPageMarginsDialog :: TransferToWindow ()
226 wxASSERT ( m_pageSetupDialogData
);
227 wxPoint topLeft
= m_pageSetupDialogData
-> GetMarginTopLeft ();
228 wxPoint bottomRight
= m_pageSetupDialogData
-> GetMarginBottomRight ();
229 wxPoint minTopLeft
= m_pageSetupDialogData
-> GetMinMarginTopLeft ();
230 wxPoint minBottomRight
= m_pageSetupDialogData
-> GetMinMarginBottomRight ();
231 m_LeftMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( topLeft
. x
, minTopLeft
. x
)));
232 m_LeftMargin
-> SetSelection (- 1 , - 1 );
233 m_TopMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( topLeft
. y
, minTopLeft
. y
)));
234 m_TopMargin
-> SetSelection (- 1 , - 1 );
235 m_RightMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( bottomRight
. x
, minBottomRight
. x
)));
236 m_RightMargin
-> SetSelection (- 1 , - 1 );
237 m_BottomMargin
-> SetValue ( wxString :: Format ( wxT ( " %d " ), wxMax ( bottomRight
. y
, minBottomRight
. y
)));
238 m_BottomMargin
-> SetSelection (- 1 , - 1 );
239 m_LeftMargin
-> SetFocus ();
243 bool wxMacPageMarginsDialog :: TransferDataFromWindow ()
245 wxPoint topLeft
, bottomRight
;
246 if (! CheckValue ( m_LeftMargin
, & topLeft
. x
, m_MinMarginTopLeft
. x
, wxT ( "left margin" ))) return false ;
247 if (! CheckValue ( m_TopMargin
, & topLeft
. y
, m_MinMarginTopLeft
. y
, wxT ( "top margin" ))) return false ;
248 if (! CheckValue ( m_RightMargin
, & bottomRight
. x
, m_MinMarginBottomRight
. x
, wxT ( "right margin" ))) return false ;
249 if (! CheckValue ( m_BottomMargin
, & bottomRight
. y
, m_MinMarginBottomRight
. y
, wxT ( "bottom margin" ))) return false ;
250 m_pageSetupDialogData
-> SetMarginTopLeft ( topLeft
);
251 m_pageSetupDialogData
-> SetMarginBottomRight ( bottomRight
);
255 bool wxMacPageMarginsDialog :: CheckValue ( wxTextCtrl
* textCtrl
, int * value
, int minValue
, const wxString
& name
)
258 if (! textCtrl
-> GetValue (). ToLong (& lvalue
))
260 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" ));
263 if ( lvalue
< minValue
)
265 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" ));
266 textCtrl
-> SetValue ( wxString :: Format ( wxT ( " %d " ), minValue
));
267 textCtrl
-> SetSelection (- 1 , - 1 );
268 textCtrl
-> SetFocus ();
271 * value
= int ( lvalue
);
275 void wxMacPageMarginsDialog :: GetMinMargins ()
277 m_MinMarginTopLeft
= m_pageSetupDialogData
-> GetMinMarginTopLeft ();
278 m_MinMarginBottomRight
= m_pageSetupDialogData
-> GetMinMarginBottomRight ();