]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
cc224d6e | 2 | // Name: src/mac/carbon/printdlg.cpp |
e9576ca5 | 3 | // Purpose: wxPrintDialog, wxPageSetupDialog |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
8e3f3880 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 SC |
12 | #include "wx/wxprec.h" |
13 | ||
179e085f RN |
14 | #if wxUSE_PRINTING_ARCHITECTURE |
15 | ||
246c5004 WS |
16 | #include "wx/printdlg.h" |
17 | ||
b4f4d3dd | 18 | #ifndef WX_PRECOMP |
8e3f3880 | 19 | #include "wx/object.h" |
6d50343d | 20 | #include "wx/dcprint.h" |
246c5004 | 21 | #include "wx/msgdlg.h" |
286f4413 KH |
22 | #include "wx/textctrl.h" |
23 | #include "wx/sizer.h" | |
24 | #include "wx/stattext.h" | |
8e3f3880 WS |
25 | #endif |
26 | ||
08680429 | 27 | #include "wx/mac/printdlg.h" |
746d7582 | 28 | #include "wx/mac/private/print.h" |
f415cab9 | 29 | #include "wx/statline.h" |
a3d3d3bf | 30 | |
cc224d6e | 31 | |
e9576ca5 | 32 | // Use generic page setup dialog: use your own native one if one exists. |
e9576ca5 | 33 | |
c061373d | 34 | IMPLEMENT_DYNAMIC_CLASS(wxMacPrintDialog, wxPrintDialogBase) |
e9576ca5 | 35 | |
cc224d6e | 36 | |
c061373d | 37 | wxMacPrintDialog::wxMacPrintDialog() |
e9576ca5 SC |
38 | { |
39 | m_dialogParent = NULL; | |
e7549107 | 40 | m_printerDC = NULL; |
cc224d6e | 41 | m_destroyDC = true; |
e9576ca5 SC |
42 | } |
43 | ||
cc224d6e | 44 | wxMacPrintDialog::wxMacPrintDialog( wxWindow *p, wxPrintDialogData *data ) |
e9576ca5 | 45 | { |
cc224d6e | 46 | Create( p, data ); |
e9576ca5 SC |
47 | } |
48 | ||
cc224d6e | 49 | wxMacPrintDialog::wxMacPrintDialog( wxWindow *p, wxPrintData *data ) |
e7549107 SC |
50 | { |
51 | wxPrintDialogData data2; | |
cc224d6e | 52 | if (data != NULL) |
e7549107 | 53 | data2 = *data; |
cc224d6e DS |
54 | |
55 | Create( p, &data2 ); | |
e7549107 SC |
56 | } |
57 | ||
cc224d6e | 58 | bool wxMacPrintDialog::Create( wxWindow *p, wxPrintDialogData *data ) |
e9576ca5 SC |
59 | { |
60 | m_dialogParent = p; | |
e7549107 | 61 | m_printerDC = NULL; |
cc224d6e DS |
62 | m_destroyDC = true; |
63 | ||
64 | if (data != NULL) | |
e7549107 | 65 | m_printDialogData = *data; |
cc224d6e DS |
66 | |
67 | return true; | |
e9576ca5 SC |
68 | } |
69 | ||
c061373d | 70 | wxMacPrintDialog::~wxMacPrintDialog() |
e9576ca5 | 71 | { |
cc224d6e DS |
72 | if (m_destroyDC && m_printerDC) |
73 | { | |
e7549107 | 74 | delete m_printerDC; |
f5bb2251 GD |
75 | m_printerDC = NULL; |
76 | } | |
e9576ca5 SC |
77 | } |
78 | ||
c061373d | 79 | int wxMacPrintDialog::ShowModal() |
e9576ca5 | 80 | { |
dc7ccb9c | 81 | m_printDialogData.GetPrintData().ConvertToNative(); |
cc224d6e DS |
82 | ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->TransferFrom( &m_printDialogData ); |
83 | ||
84 | int result = wxID_CANCEL; | |
85 | OSErr err = noErr; | |
86 | Boolean accepted; | |
87 | ||
88 | err = PMSessionPrintDialog( | |
89 | ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->m_macPrintSession, | |
dc7ccb9c SC |
90 | ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->m_macPrintSettings, |
91 | ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->m_macPageFormat, | |
cc224d6e DS |
92 | &accepted ); |
93 | ||
dc7ccb9c SC |
94 | if ((err == noErr) && !accepted) |
95 | { | |
cc224d6e DS |
96 | // user clicked Cancel button |
97 | err = kPMCancel; | |
dc7ccb9c SC |
98 | } |
99 | ||
cc224d6e | 100 | if (err == noErr) |
dc7ccb9c | 101 | { |
cc224d6e | 102 | result = wxID_OK; |
dc7ccb9c SC |
103 | } |
104 | ||
105 | if ((err != noErr) && (err != kPMCancel)) | |
106 | { | |
cc224d6e DS |
107 | wxString message; |
108 | ||
109 | message.Printf( wxT("Print Error %d"), err ); | |
110 | wxMessageDialog dialog( NULL, message, wxEmptyString, wxICON_HAND | wxOK ); | |
dc7ccb9c SC |
111 | dialog.ShowModal(); |
112 | } | |
113 | ||
cc224d6e | 114 | if (result == wxID_OK) |
dc7ccb9c SC |
115 | { |
116 | m_printDialogData.GetPrintData().ConvertFromNative(); | |
cc224d6e | 117 | ((wxMacCarbonPrintData*)m_printDialogData.GetPrintData().GetNativeData())->TransferTo( &m_printDialogData ); |
dc7ccb9c | 118 | } |
cc224d6e DS |
119 | |
120 | return result; | |
e9576ca5 SC |
121 | } |
122 | ||
f415cab9 | 123 | wxDC *wxMacPrintDialog::GetPrintDC() |
e9576ca5 | 124 | { |
cc224d6e | 125 | return new wxPrinterDC( m_printDialogData.GetPrintData() ); |
e9576ca5 SC |
126 | } |
127 | ||
08680429 | 128 | IMPLEMENT_CLASS(wxMacPageSetupDialog, wxPageSetupDialogBase) |
e9576ca5 | 129 | |
f415cab9 | 130 | wxMacPageSetupDialog::wxMacPageSetupDialog( wxWindow *p, wxPageSetupData *data ) |
cc224d6e | 131 | : wxPageSetupDialogBase() |
e9576ca5 | 132 | { |
cc224d6e | 133 | Create( p, data ); |
e9576ca5 SC |
134 | } |
135 | ||
f415cab9 | 136 | bool wxMacPageSetupDialog::Create( wxWindow *p, wxPageSetupData *data ) |
e9576ca5 SC |
137 | { |
138 | m_dialogParent = p; | |
cc224d6e DS |
139 | |
140 | if (data != NULL) | |
e9576ca5 | 141 | m_pageSetupData = (*data); |
cc224d6e DS |
142 | |
143 | return true; | |
e9576ca5 SC |
144 | } |
145 | ||
08680429 | 146 | wxMacPageSetupDialog::~wxMacPageSetupDialog() |
e9576ca5 SC |
147 | { |
148 | } | |
149 | ||
08680429 | 150 | wxPageSetupData& wxMacPageSetupDialog::GetPageSetupDialogData() |
cc224d6e | 151 | { |
08680429 RR |
152 | return m_pageSetupData; |
153 | } | |
154 | ||
155 | int wxMacPageSetupDialog::ShowModal() | |
e9576ca5 | 156 | { |
dc7ccb9c | 157 | m_pageSetupData.GetPrintData().ConvertToNative(); |
cc224d6e | 158 | ((wxMacCarbonPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->TransferFrom( &m_pageSetupData ); |
dc7ccb9c | 159 | |
cc224d6e DS |
160 | int result = wxID_CANCEL; |
161 | OSErr err = noErr; | |
162 | Boolean accepted; | |
dc7ccb9c | 163 | |
cc224d6e DS |
164 | err = PMSessionPageSetupDialog( |
165 | ((wxMacCarbonPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->m_macPrintSession, | |
dc7ccb9c | 166 | ((wxMacCarbonPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->m_macPageFormat, |
cc224d6e DS |
167 | &accepted ); |
168 | ||
dc7ccb9c SC |
169 | if ((err == noErr) && !accepted) |
170 | { | |
cc224d6e DS |
171 | // user clicked Cancel button |
172 | err = kPMCancel; | |
dc7ccb9c SC |
173 | } |
174 | ||
cc224d6e DS |
175 | // If the user did not cancel, flatten and save the PageFormat object |
176 | // with our document. | |
177 | if (err == noErr) | |
dc7ccb9c | 178 | { |
cc224d6e | 179 | result = wxID_OK; |
dc7ccb9c | 180 | } |
cc224d6e | 181 | |
dc7ccb9c SC |
182 | if ((err != noErr) && (err != kPMCancel)) |
183 | { | |
cc224d6e DS |
184 | wxString message; |
185 | ||
186 | message.Printf( wxT("Print Error %d"), err ); | |
187 | wxMessageDialog dialog( NULL, message, wxEmptyString, wxICON_HAND | wxOK ); | |
dc7ccb9c SC |
188 | dialog.ShowModal(); |
189 | } | |
190 | ||
cc224d6e | 191 | if (result == wxID_OK) |
dc7ccb9c SC |
192 | { |
193 | m_pageSetupData.GetPrintData().ConvertFromNative(); | |
cc224d6e DS |
194 | m_pageSetupData.SetPaperSize( m_pageSetupData.GetPrintData().GetPaperSize() ); |
195 | ((wxMacCarbonPrintData*)m_pageSetupData.GetPrintData().GetNativeData())->TransferTo( &m_pageSetupData ); | |
196 | } | |
197 | ||
08680429 | 198 | return result; |
e9576ca5 SC |
199 | } |
200 | ||
f415cab9 JS |
201 | |
202 | IMPLEMENT_CLASS(wxMacPageMarginsDialog, wxDialog) | |
203 | ||
204 | wxMacPageMarginsDialog::wxMacPageMarginsDialog(wxFrame *parent, wxPageSetupData *data) : | |
205 | wxDialog(parent, wxID_ANY, wxString(wxT("Page Margins"))), | |
206 | m_pageSetupDialogData(data) | |
207 | { | |
208 | GetMinMargins(); | |
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)); | |
222 | TransferToWindow(); | |
223 | SetSizerAndFit(colSizer); | |
224 | Center(wxBOTH); | |
225 | } | |
226 | ||
227 | bool wxMacPageMarginsDialog::TransferToWindow() | |
228 | { | |
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(); | |
243 | return true; | |
244 | } | |
245 | ||
246 | bool wxMacPageMarginsDialog::TransferDataFromWindow() | |
247 | { | |
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); | |
255 | return true; | |
256 | } | |
257 | ||
258 | bool wxMacPageMarginsDialog::CheckValue(wxTextCtrl* textCtrl, int *value, int minValue, const wxString& name) | |
259 | { | |
260 | long lvalue; | |
261 | if (!textCtrl->GetValue().ToLong(&lvalue)) | |
262 | { | |
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")); | |
264 | return false; | |
265 | } | |
266 | if (lvalue < minValue) | |
267 | { | |
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(); | |
272 | return false; | |
273 | } | |
274 | *value = int(lvalue); | |
275 | return true; | |
276 | } | |
277 | ||
278 | void wxMacPageMarginsDialog::GetMinMargins() | |
279 | { | |
280 | m_MinMarginTopLeft = m_pageSetupDialogData->GetMinMarginTopLeft(); | |
281 | m_MinMarginBottomRight = m_pageSetupDialogData->GetMinMarginBottomRight(); | |
282 | } | |
283 | ||
284 | ||
285 | ||
179e085f | 286 | #endif |