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