]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: prntdlgg.cpp | |
3 | // Purpose: Generic print dialogs | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
8826f46f | 9 | // Licence: wxWindows license |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8826f46f VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
c801d85f | 20 | #ifdef __GNUG__ |
8826f46f | 21 | #pragma implementation "prntdlgg.h" |
c801d85f KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
8826f46f | 28 | #pragma hdrstop |
c801d85f KB |
29 | #endif |
30 | ||
ce4169a4 RR |
31 | #if wxUSE_PRINTING_ARCHITECTURE |
32 | ||
c801d85f | 33 | #ifndef WX_PRECOMP |
8826f46f VZ |
34 | #include "wx/utils.h" |
35 | #include "wx/dc.h" | |
36 | #include "wx/app.h" | |
37 | #include "wx/frame.h" | |
38 | #include "wx/stattext.h" | |
39 | #include "wx/statbox.h" | |
40 | #include "wx/button.h" | |
41 | #include "wx/checkbox.h" | |
42 | #include "wx/textctrl.h" | |
43 | #include "wx/radiobox.h" | |
44 | #include "wx/filedlg.h" | |
45 | #include "wx/choice.h" | |
fa12f7e6 | 46 | #include "wx/combobox.h" |
3096bd2f | 47 | #include "wx/intl.h" |
27ea1d8a RR |
48 | #include "wx/sizer.h" |
49 | #endif | |
50 | ||
51 | #if wxUSE_STATLINE | |
52 | #include "wx/statline.h" | |
c801d85f KB |
53 | #endif |
54 | ||
55 | #include "wx/generic/prntdlgg.h" | |
2a47d3c1 JS |
56 | |
57 | #if wxUSE_POSTSCRIPT | |
8826f46f | 58 | #include "wx/generic/dcpsg.h" |
2a47d3c1 JS |
59 | #endif |
60 | ||
c801d85f | 61 | #include "wx/printdlg.h" |
7bcb11d3 | 62 | #include "wx/paper.h" |
c801d85f | 63 | |
2a47d3c1 JS |
64 | // For print paper things |
65 | #include "wx/prntbase.h" | |
66 | ||
c801d85f KB |
67 | #include <stdlib.h> |
68 | #include <string.h> | |
69 | ||
8826f46f VZ |
70 | // ---------------------------------------------------------------------------- |
71 | // wxWin macros | |
72 | // ---------------------------------------------------------------------------- | |
73 | ||
25889d3c | 74 | |
2a47d3c1 JS |
75 | #if wxUSE_POSTSCRIPT |
76 | ||
30862d99 VZ |
77 | IMPLEMENT_CLASS(wxGenericPrintDialog, wxDialog) |
78 | IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog) | |
79 | ||
80 | BEGIN_EVENT_TABLE(wxGenericPrintDialog, wxDialog) | |
81 | EVT_BUTTON(wxID_OK, wxGenericPrintDialog::OnOK) | |
82 | EVT_BUTTON(wxPRINTID_SETUP, wxGenericPrintDialog::OnSetup) | |
83 | EVT_RADIOBOX(wxPRINTID_RANGE, wxGenericPrintDialog::OnRange) | |
84 | END_EVENT_TABLE() | |
25889d3c | 85 | |
30862d99 | 86 | #endif // wxUSE_POSTSCRIPT |
8826f46f | 87 | |
30862d99 VZ |
88 | IMPLEMENT_CLASS(wxGenericPageSetupDialog, wxDialog) |
89 | ||
90 | BEGIN_EVENT_TABLE(wxGenericPageSetupDialog, wxDialog) | |
91 | EVT_BUTTON(wxPRINTID_SETUP, wxGenericPageSetupDialog::OnPrinter) | |
92 | END_EVENT_TABLE() | |
8826f46f VZ |
93 | |
94 | // ---------------------------------------------------------------------------- | |
95 | // global vars | |
96 | // ---------------------------------------------------------------------------- | |
c801d85f KB |
97 | |
98 | extern wxPrintPaperDatabase *wxThePrintPaperDatabase; | |
99 | ||
25889d3c JS |
100 | #if wxUSE_POSTSCRIPT |
101 | ||
8826f46f VZ |
102 | // ============================================================================ |
103 | // implementation | |
104 | // ============================================================================ | |
105 | ||
106 | // ---------------------------------------------------------------------------- | |
107 | // Generic print dialog for non-Windows printing use. | |
108 | // ---------------------------------------------------------------------------- | |
109 | ||
110 | wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent, | |
111 | wxPrintDialogData* data) | |
112 | : wxDialog(parent, -1, _("Print"), | |
113 | wxPoint(0, 0), wxSize(600, 600), | |
114 | wxDEFAULT_DIALOG_STYLE | | |
115 | wxDIALOG_MODAL | | |
116 | wxTAB_TRAVERSAL) | |
117 | { | |
118 | if ( data ) | |
119 | m_printDialogData = *data; | |
c801d85f | 120 | |
8826f46f VZ |
121 | Init(parent); |
122 | } | |
c801d85f | 123 | |
8826f46f VZ |
124 | wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent, |
125 | wxPrintData* data) | |
cb230244 JS |
126 | : wxDialog(parent, -1, _("Print"), |
127 | wxPoint(0, 0), wxSize(600, 600), | |
128 | wxDEFAULT_DIALOG_STYLE | | |
129 | wxDIALOG_MODAL | | |
130 | wxTAB_TRAVERSAL) | |
c801d85f | 131 | { |
7bcb11d3 JS |
132 | if ( data ) |
133 | m_printDialogData = *data; | |
8826f46f VZ |
134 | |
135 | Init(parent); | |
136 | } | |
137 | ||
74e3313b | 138 | void wxGenericPrintDialog::Init(wxWindow * WXUNUSED(parent)) |
8826f46f | 139 | { |
cb230244 JS |
140 | // wxDialog::Create(parent, -1, _("Print"), wxPoint(0, 0), wxSize(600, 600), |
141 | // wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL | wxTAB_TRAVERSAL); | |
8826f46f | 142 | |
27ea1d8a | 143 | wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL ); |
8826f46f | 144 | |
27ea1d8a RR |
145 | // 1) top row |
146 | ||
147 | wxStaticBoxSizer *topsizer = new wxStaticBoxSizer( | |
148 | new wxStaticBox( this, -1, _( "Printer options" ) ), wxHORIZONTAL ); | |
149 | m_printToFileCheckBox = new wxCheckBox( this, wxPRINTID_PRINTTOFILE, _("Print to File") ); | |
150 | topsizer->Add( m_printToFileCheckBox, 0, wxCENTER|wxALL, 5 ); | |
8826f46f | 151 | |
27ea1d8a | 152 | topsizer->Add( 60,2,1 ); |
8826f46f | 153 | |
27ea1d8a RR |
154 | m_setupButton = new wxButton(this, wxPRINTID_SETUP, _("Setup...") ); |
155 | topsizer->Add( m_setupButton, 0, wxCENTER|wxALL, 5 ); | |
156 | ||
157 | mainsizer->Add( topsizer, 0, wxLEFT|wxTOP|wxRIGHT, 10 ); | |
158 | ||
159 | // 2) middle row with radio box | |
160 | ||
7bcb11d3 JS |
161 | wxString *choices = new wxString[2]; |
162 | choices[0] = _("All"); | |
163 | choices[1] = _("Pages"); | |
8826f46f | 164 | |
7bcb11d3 | 165 | m_fromText = (wxTextCtrl*)NULL; |
d14612c6 | 166 | m_toText = (wxTextCtrl*)NULL; |
59e2b19f KB |
167 | m_rangeRadioBox = (wxRadioBox *)NULL; |
168 | ||
7bcb11d3 JS |
169 | if (m_printDialogData.GetFromPage() != 0) |
170 | { | |
171 | m_rangeRadioBox = new wxRadioBox(this, wxPRINTID_RANGE, _("Print Range"), | |
27ea1d8a | 172 | wxDefaultPosition, wxDefaultSize, |
8826f46f VZ |
173 | 2, choices, |
174 | 1, wxRA_VERTICAL); | |
7bcb11d3 | 175 | m_rangeRadioBox->SetSelection(1); |
27ea1d8a RR |
176 | |
177 | mainsizer->Add( m_rangeRadioBox, 0, wxLEFT|wxTOP|wxRIGHT, 10 ); | |
7bcb11d3 | 178 | } |
8826f46f | 179 | |
27ea1d8a RR |
180 | // 3) bottom row |
181 | ||
182 | wxBoxSizer *bottomsizer = new wxBoxSizer( wxHORIZONTAL ); | |
183 | ||
184 | if (m_printDialogData.GetFromPage() != 0) | |
7bcb11d3 | 185 | { |
27ea1d8a RR |
186 | bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("From:") ), 0, wxCENTER|wxALL, 5 ); |
187 | m_fromText = new wxTextCtrl(this, wxPRINTID_FROM, "", wxDefaultPosition, wxSize(40, -1)); | |
188 | bottomsizer->Add( m_fromText, 1, wxCENTER|wxRIGHT, 10 ); | |
8826f46f | 189 | |
27ea1d8a RR |
190 | bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("To:") ), 0, wxCENTER|wxALL, 5); |
191 | m_toText = new wxTextCtrl(this, wxPRINTID_TO, "", wxDefaultPosition, wxSize(40, -1)); | |
192 | bottomsizer->Add( m_toText, 1, wxCENTER|wxRIGHT, 10 ); | |
193 | } | |
8826f46f | 194 | |
27ea1d8a RR |
195 | bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Copies:") ), 0, wxCENTER|wxALL, 5 ); |
196 | m_noCopiesText = new wxTextCtrl(this, wxPRINTID_COPIES, "", wxPoint(252, 130), wxSize(40, -1)); | |
197 | bottomsizer->Add( m_noCopiesText, 1, wxCENTER|wxRIGHT, 10 ); | |
8826f46f | 198 | |
27ea1d8a | 199 | mainsizer->Add( bottomsizer, 0, wxTOP|wxLEFT|wxRIGHT, 12 ); |
8826f46f | 200 | |
27ea1d8a RR |
201 | #if wxUSE_STATLINE |
202 | // 4) static line | |
203 | mainsizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 ); | |
204 | #endif | |
8826f46f | 205 | |
27ea1d8a | 206 | // 5) buttons |
8826f46f | 207 | |
27ea1d8a | 208 | mainsizer->Add( CreateButtonSizer( wxOK|wxCANCEL), 0, wxCENTER|wxALL, 10 ); |
8826f46f | 209 | |
27ea1d8a RR |
210 | SetAutoLayout( TRUE ); |
211 | SetSizer( mainsizer ); | |
212 | ||
213 | mainsizer->Fit( this ); | |
7bcb11d3 | 214 | Centre(wxBOTH); |
8826f46f | 215 | |
7bcb11d3 JS |
216 | // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow |
217 | InitDialog(); | |
218 | delete[] choices; | |
c801d85f KB |
219 | } |
220 | ||
7bcb11d3 | 221 | int wxGenericPrintDialog::ShowModal() |
c801d85f | 222 | { |
7bcb11d3 | 223 | if ( m_printDialogData.GetSetupDialog() ) |
c801d85f | 224 | { |
7bcb11d3 JS |
225 | // Make sure wxPrintData object reflects the settings now, in case the setup dialog |
226 | // changes it. In fact there aren't any common settings at | |
227 | // present, but there might be in future. | |
228 | // TransferDataFromWindow(); | |
229 | ||
c801d85f | 230 | wxGenericPrintSetupDialog *genericPrintSetupDialog = |
7bcb11d3 | 231 | new wxGenericPrintSetupDialog(this, & m_printDialogData.GetPrintData()); |
c801d85f KB |
232 | int ret = genericPrintSetupDialog->ShowModal(); |
233 | if ( ret != wxID_CANCEL ) | |
234 | { | |
7bcb11d3 JS |
235 | // Transfer settings to the global object (for compatibility) and to |
236 | // the print dialog's print data. | |
237 | *wxThePrintSetupData = genericPrintSetupDialog->GetPrintData(); | |
238 | m_printDialogData.GetPrintData() = genericPrintSetupDialog->GetPrintData(); | |
c801d85f | 239 | } |
7bcb11d3 JS |
240 | genericPrintSetupDialog->Destroy(); |
241 | ||
242 | // Restore the wxPrintData settings again (uncomment if any settings become common | |
243 | // to both dialogs) | |
244 | // TransferDataToWindow(); | |
245 | ||
c801d85f KB |
246 | return ret; |
247 | } | |
248 | else | |
249 | { | |
250 | return wxDialog::ShowModal(); | |
251 | } | |
252 | } | |
253 | ||
7bcb11d3 | 254 | wxGenericPrintDialog::~wxGenericPrintDialog() |
c801d85f KB |
255 | { |
256 | } | |
257 | ||
258 | void wxGenericPrintDialog::OnOK(wxCommandEvent& WXUNUSED(event)) | |
259 | { | |
7bcb11d3 | 260 | TransferDataFromWindow(); |
8826f46f | 261 | |
7bcb11d3 JS |
262 | // There are some interactions between the global setup data |
263 | // and the standard print dialog. The global printing 'mode' | |
264 | // is determined by whether the user checks Print to file | |
265 | // or not. | |
266 | if (m_printDialogData.GetPrintToFile()) | |
267 | { | |
268 | m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE); | |
269 | wxThePrintSetupData->SetPrinterMode(wxPRINT_MODE_FILE); | |
8826f46f | 270 | |
7bcb11d3 JS |
271 | wxString f = wxFileSelector(_("PostScript file"), |
272 | wxPathOnly(wxThePrintSetupData->GetPrinterFile()), | |
273 | wxFileNameFromPath(wxThePrintSetupData->GetPrinterFile()), | |
223d09f6 | 274 | wxT("ps"), wxT("*.ps"), 0, this); |
7bcb11d3 JS |
275 | if ( f.IsEmpty() ) |
276 | return; | |
8826f46f | 277 | |
7bcb11d3 JS |
278 | m_printDialogData.GetPrintData().SetFilename(f); |
279 | wxThePrintSetupData->SetPrinterFile(f); | |
280 | } | |
281 | else | |
75737d05 JS |
282 | { |
283 | m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER); | |
7bcb11d3 | 284 | wxThePrintSetupData->SetPrinterMode(wxPRINT_MODE_PRINTER); |
75737d05 | 285 | } |
8826f46f | 286 | |
7bcb11d3 | 287 | EndModal(wxID_OK); |
c801d85f KB |
288 | } |
289 | ||
290 | void wxGenericPrintDialog::OnRange(wxCommandEvent& event) | |
291 | { | |
7bcb11d3 | 292 | if (!m_fromText) return; |
8826f46f | 293 | |
7bcb11d3 JS |
294 | if (event.GetInt() == 0) |
295 | { | |
296 | m_fromText->Enable(FALSE); | |
297 | m_toText->Enable(FALSE); | |
298 | } | |
299 | else if (event.GetInt() == 1) | |
300 | { | |
301 | m_fromText->Enable(TRUE); | |
302 | m_toText->Enable(TRUE); | |
303 | } | |
c801d85f KB |
304 | } |
305 | ||
306 | void wxGenericPrintDialog::OnSetup(wxCommandEvent& WXUNUSED(event)) | |
307 | { | |
e955db19 | 308 | *wxThePrintSetupData = m_printDialogData.GetPrintData(); |
7bcb11d3 JS |
309 | wxGenericPrintSetupDialog *genericPrintSetupDialog = |
310 | new wxGenericPrintSetupDialog(this, wxThePrintSetupData); | |
311 | int ret = genericPrintSetupDialog->ShowModal(); | |
312 | if ( ret != wxID_CANCEL ) | |
313 | { | |
314 | *wxThePrintSetupData = genericPrintSetupDialog->GetPrintData(); | |
315 | m_printDialogData = genericPrintSetupDialog->GetPrintData(); | |
316 | } | |
8826f46f | 317 | |
7bcb11d3 | 318 | genericPrintSetupDialog->Close(TRUE); |
c801d85f KB |
319 | } |
320 | ||
7bcb11d3 | 321 | bool wxGenericPrintDialog::TransferDataToWindow() |
c801d85f | 322 | { |
7bcb11d3 JS |
323 | if(m_printDialogData.GetFromPage() != 0) |
324 | { | |
d14612c6 KB |
325 | if(m_fromText) |
326 | { | |
327 | if (m_printDialogData.GetEnablePageNumbers()) | |
328 | { | |
329 | m_fromText->Enable(TRUE); | |
330 | m_toText->Enable(TRUE); | |
30862d99 VZ |
331 | m_fromText->SetValue( |
332 | wxString::Format(_T("%d"), m_printDialogData.GetFromPage())); | |
333 | m_toText->SetValue( | |
334 | wxString::Format(_T("%d"), m_printDialogData.GetToPage())); | |
59e2b19f KB |
335 | if(m_rangeRadioBox) |
336 | if (m_printDialogData.GetAllPages()) | |
337 | m_rangeRadioBox->SetSelection(0); | |
338 | else | |
339 | m_rangeRadioBox->SetSelection(1); | |
d14612c6 KB |
340 | } |
341 | else | |
342 | { | |
343 | m_fromText->Enable(FALSE); | |
344 | m_toText->Enable(FALSE); | |
59e2b19f KB |
345 | if(m_rangeRadioBox) |
346 | { | |
347 | m_rangeRadioBox->SetSelection(0); | |
348 | m_rangeRadioBox->wxRadioBox::Enable(1, FALSE); | |
349 | } | |
d14612c6 KB |
350 | } |
351 | } | |
7bcb11d3 | 352 | } |
30862d99 VZ |
353 | m_noCopiesText->SetValue( |
354 | wxString::Format(_T("%d"), m_printDialogData.GetNoCopies())); | |
8826f46f | 355 | |
7bcb11d3 JS |
356 | m_printToFileCheckBox->SetValue(m_printDialogData.GetPrintToFile()); |
357 | m_printToFileCheckBox->Enable(m_printDialogData.GetEnablePrintToFile()); | |
358 | return TRUE; | |
c801d85f KB |
359 | } |
360 | ||
7bcb11d3 | 361 | bool wxGenericPrintDialog::TransferDataFromWindow() |
c801d85f | 362 | { |
92980e90 | 363 | long res = 0; |
7bcb11d3 JS |
364 | if(m_printDialogData.GetFromPage() != -1) |
365 | { | |
366 | if (m_printDialogData.GetEnablePageNumbers()) | |
367 | { | |
92980e90 RR |
368 | if(m_fromText) |
369 | { | |
370 | wxString value = m_fromText->GetValue(); | |
371 | if (value.ToLong( &res )) | |
372 | m_printDialogData.SetFromPage( res ); | |
373 | } | |
374 | if(m_toText) | |
375 | { | |
376 | wxString value = m_toText->GetValue(); | |
377 | if (value.ToLong( &res )) | |
378 | m_printDialogData.SetToPage( res ); | |
379 | } | |
7bcb11d3 | 380 | } |
59e2b19f KB |
381 | if(m_rangeRadioBox) |
382 | { | |
383 | if (m_rangeRadioBox->GetSelection() == 0) | |
384 | m_printDialogData.SetAllPages(TRUE); | |
385 | else | |
386 | m_printDialogData.SetAllPages(FALSE); | |
387 | } | |
7bcb11d3 JS |
388 | } |
389 | else | |
390 | { // continuous printing | |
391 | m_printDialogData.SetFromPage(1); | |
392 | m_printDialogData.SetToPage(32000); | |
393 | } | |
92980e90 RR |
394 | |
395 | wxString value = m_noCopiesText->GetValue(); | |
396 | if (value.ToLong( &res )) | |
397 | m_printDialogData.SetNoCopies( res ); | |
398 | ||
7bcb11d3 | 399 | m_printDialogData.SetPrintToFile(m_printToFileCheckBox->GetValue()); |
c801d85f | 400 | |
7bcb11d3 | 401 | return TRUE; |
c801d85f KB |
402 | } |
403 | ||
404 | /* | |
7bcb11d3 JS |
405 | TODO: collate and noCopies should be duplicated across dialog data and print data objects |
406 | (slightly different semantics on Windows but let's ignore this for a bit). | |
407 | */ | |
c801d85f | 408 | |
7bcb11d3 | 409 | wxDC *wxGenericPrintDialog::GetPrintDC() |
c801d85f | 410 | { |
75737d05 JS |
411 | // return new wxPostScriptDC(wxThePrintSetupData->GetPrinterFile(), FALSE, (wxWindow *) NULL); |
412 | return new wxPostScriptDC(GetPrintDialogData().GetPrintData()); | |
7bcb11d3 | 413 | } |
c801d85f | 414 | |
8826f46f VZ |
415 | // ---------------------------------------------------------------------------- |
416 | // Generic print setup dialog | |
417 | // ---------------------------------------------------------------------------- | |
c801d85f | 418 | |
7bcb11d3 JS |
419 | wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintData* data): |
420 | wxDialog(parent, -1, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL) | |
421 | { | |
422 | Init(data); | |
423 | } | |
c801d85f | 424 | |
7bcb11d3 JS |
425 | // Convert wxPrintSetupData to standard wxPrintData object |
426 | wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintSetupData* data): | |
427 | wxDialog(parent, -1, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL) | |
428 | { | |
429 | wxPrintData printData; | |
430 | if (data) | |
431 | printData = * data; | |
432 | else | |
433 | printData = * wxThePrintSetupData; | |
c801d85f | 434 | |
7bcb11d3 JS |
435 | Init(& printData); |
436 | } | |
9838df2c | 437 | |
7bcb11d3 JS |
438 | void wxGenericPrintSetupDialog::Init(wxPrintData* data) |
439 | { | |
440 | if ( data ) | |
441 | m_printData = *data; | |
9838df2c | 442 | |
7bcb11d3 | 443 | int staticBoxWidth = 300; |
8826f46f | 444 | |
7bcb11d3 | 445 | (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(10, 10), wxSize(staticBoxWidth, 60) ); |
8826f46f | 446 | |
7bcb11d3 JS |
447 | int xPos = 20; |
448 | int yPos = 30; | |
449 | m_paperTypeChoice = CreatePaperTypeChoice(&xPos, &yPos); | |
8826f46f | 450 | |
7bcb11d3 JS |
451 | wxString *choices = new wxString[2]; |
452 | choices[0] = _("Portrait"); | |
453 | choices[1] = _("Landscape"); | |
8826f46f | 454 | |
7bcb11d3 JS |
455 | m_orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"), |
456 | wxPoint(10, 80), wxSize(-1, -1), 2, choices, 1, wxRA_VERTICAL ); | |
457 | m_orientationRadioBox->SetSelection(0); | |
8826f46f | 458 | |
7bcb11d3 | 459 | (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Options"), wxPoint(10, 130), wxSize(staticBoxWidth, 50) ); |
8826f46f | 460 | |
7bcb11d3 | 461 | int colourYPos = 145; |
8826f46f | 462 | |
9838df2c | 463 | #ifdef __WXMOTIF__ |
7bcb11d3 | 464 | colourYPos = 150; |
9838df2c | 465 | #endif |
8826f46f | 466 | |
7bcb11d3 | 467 | m_colourCheckBox = new wxCheckBox(this, wxPRINTID_PRINTCOLOUR, _("Print in colour"), wxPoint(15, colourYPos)); |
c801d85f | 468 | |
7bcb11d3 | 469 | (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Print spooling"), wxPoint(330, 10), wxSize(200,170) ); |
8826f46f | 470 | |
7bcb11d3 | 471 | (void) new wxStaticText(this, wxPRINTID_STATIC, _("Printer command:"), wxPoint(340, 30)); |
8826f46f | 472 | |
7bcb11d3 | 473 | m_printerCommandText = new wxTextCtrl(this, wxPRINTID_COMMAND, "", wxPoint(360, 55), wxSize(150, -1)); |
8826f46f | 474 | |
7bcb11d3 | 475 | (void) new wxStaticText(this, wxPRINTID_STATIC, _("Printer options:"), wxPoint(340, 110)); |
8826f46f | 476 | |
7bcb11d3 | 477 | m_printerOptionsText = new wxTextCtrl(this, wxPRINTID_OPTIONS, "", wxPoint(360, 135), wxSize(150, -1)); |
8826f46f | 478 | |
dcf924a3 RR |
479 | wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(130, 200), wxSize(80, -1)); |
480 | (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(320, 200), wxSize(80, -1)); | |
8826f46f | 481 | |
7bcb11d3 JS |
482 | okButton->SetDefault(); |
483 | okButton->SetFocus(); | |
8826f46f | 484 | |
7bcb11d3 JS |
485 | Fit(); |
486 | Centre(wxBOTH); | |
8826f46f | 487 | |
7bcb11d3 JS |
488 | InitDialog(); |
489 | delete[] choices; | |
c801d85f KB |
490 | } |
491 | ||
7bcb11d3 | 492 | wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog() |
c801d85f KB |
493 | { |
494 | } | |
495 | ||
7bcb11d3 | 496 | bool wxGenericPrintSetupDialog::TransferDataToWindow() |
c801d85f | 497 | { |
7bcb11d3 JS |
498 | if (m_printerCommandText && m_printData.GetPrinterCommand()) |
499 | m_printerCommandText->SetValue(m_printData.GetPrinterCommand()); | |
500 | if (m_printerOptionsText && m_printData.GetPrinterOptions()) | |
501 | m_printerOptionsText->SetValue(m_printData.GetPrinterOptions()); | |
502 | if (m_colourCheckBox) | |
503 | m_colourCheckBox->SetValue(m_printData.GetColour()); | |
8826f46f | 504 | |
7bcb11d3 JS |
505 | if (m_orientationRadioBox) |
506 | { | |
507 | if (m_printData.GetOrientation() == wxPORTRAIT) | |
508 | m_orientationRadioBox->SetSelection(0); | |
509 | else | |
510 | m_orientationRadioBox->SetSelection(1); | |
511 | } | |
512 | return TRUE; | |
c801d85f KB |
513 | } |
514 | ||
7bcb11d3 | 515 | bool wxGenericPrintSetupDialog::TransferDataFromWindow() |
c801d85f | 516 | { |
7bcb11d3 JS |
517 | if (m_printerCommandText) |
518 | m_printData.SetPrinterCommand(m_printerCommandText->GetValue()); | |
519 | if (m_printerOptionsText) | |
520 | m_printData.SetPrinterOptions(m_printerOptionsText->GetValue()); | |
521 | if (m_colourCheckBox) | |
522 | m_printData.SetColour(m_colourCheckBox->GetValue()); | |
523 | if (m_orientationRadioBox) | |
524 | { | |
525 | int sel = m_orientationRadioBox->GetSelection(); | |
526 | if (sel == 0) | |
527 | m_printData.SetOrientation(wxPORTRAIT); | |
528 | else | |
529 | m_printData.SetOrientation(wxLANDSCAPE); | |
530 | } | |
531 | if (m_paperTypeChoice) | |
532 | { | |
533 | wxString val(m_paperTypeChoice->GetStringSelection()); | |
534 | if (!val.IsNull() && val != "") | |
535 | m_printData.SetPaperId(wxThePrintPaperDatabase->ConvertNameToId(val)); | |
536 | } | |
537 | ||
538 | // This is for backward compatibility only | |
539 | *wxThePrintSetupData = GetPrintData(); | |
540 | return TRUE; | |
c801d85f KB |
541 | } |
542 | ||
fa12f7e6 | 543 | wxComboBox *wxGenericPrintSetupDialog::CreatePaperTypeChoice(int *x, int *y) |
c801d85f | 544 | { |
7bcb11d3 JS |
545 | /* Should not be necessary |
546 | if (!wxThePrintPaperDatabase) | |
547 | { | |
548 | wxThePrintPaperDatabase = new wxPrintPaperDatabase; | |
549 | wxThePrintPaperDatabase->CreateDatabase(); | |
550 | } | |
551 | */ | |
552 | int n = wxThePrintPaperDatabase->Number(); | |
553 | wxString *choices = new wxString [n]; | |
554 | int sel = 0; | |
555 | int i; | |
556 | for (i = 0; i < n; i++) | |
557 | { | |
558 | wxPrintPaperType *paper = (wxPrintPaperType *)wxThePrintPaperDatabase->Nth(i)->Data(); | |
559 | choices[i] = paper->GetName(); | |
560 | if (m_printData.GetPaperId() == paper->GetId()) | |
561 | sel = i; | |
562 | } | |
8826f46f | 563 | |
7bcb11d3 JS |
564 | int width = 250; |
565 | ||
fa12f7e6 KB |
566 | wxComboBox *choice = new wxComboBox(this, wxPRINTID_PAPERSIZE, |
567 | _("Paper Size"), | |
568 | wxPoint(*x, *y), wxSize(width, -1), n, | |
7bcb11d3 JS |
569 | choices); |
570 | ||
571 | // SetFont(thisFont); | |
c801d85f | 572 | |
7bcb11d3 | 573 | delete[] choices; |
8826f46f | 574 | |
7bcb11d3 JS |
575 | choice->SetSelection(sel); |
576 | return choice; | |
c801d85f | 577 | } |
8826f46f | 578 | #endif // wxUSE_POSTSCRIPT |
c801d85f | 579 | |
8826f46f VZ |
580 | // ---------------------------------------------------------------------------- |
581 | // Generic page setup dialog | |
582 | // ---------------------------------------------------------------------------- | |
c801d85f KB |
583 | |
584 | void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent& WXUNUSED(event)) | |
585 | { | |
9838df2c JS |
586 | // We no longer query GetPrintMode, so we can eliminate the need |
587 | // to call SetPrintMode. | |
588 | // This has the limitation that we can't explicitly call the PostScript | |
589 | // print setup dialog from the generic Page Setup dialog under Windows, | |
590 | // but since this choice would only happen when trying to do PostScript | |
591 | // printing under Windows (and only in 16-bit Windows which | |
592 | // doesn't have a Windows-specific page setup dialog) it's worth it. | |
593 | ||
7bcb11d3 JS |
594 | // First save the current settings, so the wxPrintData object is up to date. |
595 | TransferDataFromWindow(); | |
596 | ||
597 | // Transfer the current print settings from this dialog to the page setup dialog. | |
598 | wxPrintDialogData data; | |
599 | data = GetPageSetupData().GetPrintData(); | |
9838df2c JS |
600 | data.SetSetupDialog(TRUE); |
601 | wxPrintDialog *printDialog = new wxPrintDialog(this, & data); | |
ba681060 | 602 | printDialog->ShowModal(); |
9838df2c | 603 | |
7bcb11d3 JS |
604 | // Transfer the page setup print settings from the page dialog to this dialog again, in case |
605 | // the page setup dialog changed something. | |
606 | GetPageSetupData().GetPrintData() = printDialog->GetPrintDialogData().GetPrintData(); | |
607 | GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData | |
608 | ||
9838df2c | 609 | printDialog->Destroy(); |
7bcb11d3 JS |
610 | |
611 | // Now update the dialog in case the page setup dialog changed some of our settings. | |
612 | TransferDataToWindow(); | |
c801d85f KB |
613 | } |
614 | ||
615 | wxGenericPageSetupDialog::wxGenericPageSetupDialog(wxWindow *parent, wxPageSetupData* data): | |
7bcb11d3 | 616 | wxDialog(parent, -1, _("Page Setup"), wxPoint(0, 0), wxSize(600, 600), wxDIALOG_MODAL|wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL) |
c801d85f | 617 | { |
27ea1d8a | 618 | if (data) |
7bcb11d3 | 619 | m_pageData = *data; |
27ea1d8a RR |
620 | |
621 | int textWidth = 80; | |
622 | ||
623 | wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL ); | |
624 | ||
625 | // 1) top | |
626 | wxStaticBoxSizer *topsizer = new wxStaticBoxSizer( | |
627 | new wxStaticBox(this,wxPRINTID_STATIC, _("Paper size")), wxHORIZONTAL ); | |
628 | ||
629 | int n = wxThePrintPaperDatabase->Number(); | |
630 | wxString *choices = new wxString [n]; | |
631 | int i; | |
632 | for (i = 0; i < n; i++) | |
633 | { | |
634 | wxPrintPaperType *paper = (wxPrintPaperType *)wxThePrintPaperDatabase->Nth(i)->Data(); | |
635 | choices[i] = paper->GetName(); | |
636 | } | |
8826f46f | 637 | |
27ea1d8a RR |
638 | m_paperTypeChoice = new wxComboBox(this, wxPRINTID_PAPERSIZE, _("Paper Size"), |
639 | wxDefaultPosition, wxSize(300, -1), n, choices); | |
640 | topsizer->Add( m_paperTypeChoice, 1, wxEXPAND|wxALL, 5 ); | |
641 | // m_paperTypeChoice->SetSelection(sel); | |
8826f46f | 642 | |
27ea1d8a | 643 | mainsizer->Add( topsizer, 0, wxTOP|wxLEFT|wxRIGHT | wxEXPAND, 10 ); |
8826f46f | 644 | |
27ea1d8a | 645 | // 2) middle sizer with radio box |
8826f46f | 646 | |
27ea1d8a RR |
647 | wxString *choices2 = new wxString[2]; |
648 | choices2[0] = _("Portrait"); | |
649 | choices2[1] = _("Landscape"); | |
7bcb11d3 | 650 | m_orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"), |
27ea1d8a | 651 | wxDefaultPosition, wxDefaultSize, 2, choices2, 2); |
7bcb11d3 | 652 | m_orientationRadioBox->SetSelection(0); |
8826f46f | 653 | |
27ea1d8a | 654 | mainsizer->Add( m_orientationRadioBox, 0, wxTOP|wxLEFT|wxRIGHT, 10 ); |
8826f46f | 655 | |
27ea1d8a | 656 | // 3) margins |
8826f46f | 657 | |
27ea1d8a | 658 | wxBoxSizer *table = new wxBoxSizer( wxHORIZONTAL ); |
8826f46f | 659 | |
27ea1d8a RR |
660 | wxBoxSizer *column1 = new wxBoxSizer( wxVERTICAL ); |
661 | column1->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Left margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 ); | |
662 | column1->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Top margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 ); | |
663 | table->Add( column1, 0, wxALL | wxEXPAND, 5 ); | |
664 | ||
665 | wxBoxSizer *column2 = new wxBoxSizer( wxVERTICAL ); | |
666 | m_marginLeftText = new wxTextCtrl(this, wxPRINTID_LEFTMARGIN, "", wxDefaultPosition, wxSize(textWidth, -1)); | |
667 | m_marginTopText = new wxTextCtrl(this, wxPRINTID_TOPMARGIN, "", wxDefaultPosition, wxSize(textWidth, -1)); | |
668 | column2->Add( m_marginLeftText, 1, wxALL, 5 ); | |
669 | column2->Add( m_marginTopText, 1, wxALL, 5 ); | |
670 | table->Add( column2, 0, wxRIGHT|wxTOP|wxBOTTOM | wxEXPAND, 5 ); | |
671 | ||
672 | wxBoxSizer *column3 = new wxBoxSizer( wxVERTICAL ); | |
673 | column3->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Right margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 ); | |
674 | column3->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Bottom margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 ); | |
675 | table->Add( column3, 0, wxALL | wxEXPAND, 5 ); | |
676 | ||
677 | wxBoxSizer *column4 = new wxBoxSizer( wxVERTICAL ); | |
678 | m_marginRightText = new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN, "", wxDefaultPosition, wxSize(textWidth, -1)); | |
679 | m_marginBottomText = new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN, "", wxDefaultPosition, wxSize(textWidth, -1)); | |
680 | column4->Add( m_marginRightText, 1, wxALL, 5 ); | |
681 | column4->Add( m_marginBottomText, 1, wxALL, 5 ); | |
682 | table->Add( column4, 0, wxRIGHT|wxTOP|wxBOTTOM | wxEXPAND, 5 ); | |
683 | ||
684 | mainsizer->Add( table, 0 ); | |
685 | ||
686 | #if wxUSE_STATLINE | |
687 | // 5) static line | |
688 | mainsizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 ); | |
689 | #endif | |
8826f46f | 690 | |
27ea1d8a RR |
691 | // 6) buttons |
692 | ||
693 | wxSizer* buttonsizer = CreateButtonSizer( wxOK|wxCANCEL); | |
694 | m_printerButton = new wxButton(this, wxPRINTID_SETUP, _("Printer...") ); | |
695 | buttonsizer->Add( m_printerButton, 0, wxLEFT|wxRIGHT, 10 ); | |
696 | if ( !m_pageData.GetEnablePrinter() ) | |
697 | m_printerButton->Enable(FALSE); | |
698 | // if (m_printData.GetEnableHelp()) | |
699 | // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), -1, -1, buttonWidth, buttonHeight); | |
700 | mainsizer->Add( buttonsizer, 0, wxCENTER|wxALL, 10 ); | |
8826f46f | 701 | |
8826f46f | 702 | |
27ea1d8a RR |
703 | SetAutoLayout( TRUE ); |
704 | SetSizer( mainsizer ); | |
8826f46f | 705 | |
27ea1d8a | 706 | mainsizer->Fit( this ); |
7bcb11d3 | 707 | Centre(wxBOTH); |
8826f46f | 708 | |
7bcb11d3 | 709 | InitDialog(); |
27ea1d8a RR |
710 | |
711 | delete[] choices; | |
712 | delete [] choices2; | |
7bcb11d3 | 713 | } |
9838df2c | 714 | |
7bcb11d3 JS |
715 | wxGenericPageSetupDialog::~wxGenericPageSetupDialog() |
716 | { | |
717 | } | |
c801d85f | 718 | |
7bcb11d3 JS |
719 | bool wxGenericPageSetupDialog::TransferDataToWindow() |
720 | { | |
721 | if (m_marginLeftText) | |
722 | m_marginLeftText->SetValue(IntToString((int) m_pageData.GetMarginTopLeft().x)); | |
723 | if (m_marginTopText) | |
724 | m_marginTopText->SetValue(IntToString((int) m_pageData.GetMarginTopLeft().y)); | |
725 | if (m_marginRightText) | |
726 | m_marginRightText->SetValue(IntToString((int) m_pageData.GetMarginBottomRight().x)); | |
727 | if (m_marginBottomText) | |
728 | m_marginBottomText->SetValue(IntToString((int) m_pageData.GetMarginBottomRight().y)); | |
8826f46f | 729 | |
7bcb11d3 JS |
730 | if (m_orientationRadioBox) |
731 | { | |
732 | if (m_pageData.GetPrintData().GetOrientation() == wxPORTRAIT) | |
733 | m_orientationRadioBox->SetSelection(0); | |
734 | else | |
735 | m_orientationRadioBox->SetSelection(1); | |
736 | } | |
c801d85f | 737 | |
7bcb11d3 JS |
738 | // Find the paper type from either the current paper size in the wxPageSetupDialogData, or |
739 | // failing that, the id in the wxPrintData object. | |
c801d85f | 740 | |
7bcb11d3 JS |
741 | wxPrintPaperType* type = wxThePrintPaperDatabase->FindPaperType( |
742 | wxSize(m_pageData.GetPaperSize().x * 10, m_pageData.GetPaperSize().y * 10)); | |
c801d85f | 743 | |
7bcb11d3 JS |
744 | if (!type && m_pageData.GetPrintData().GetPaperId() != wxPAPER_NONE) |
745 | type = wxThePrintPaperDatabase->FindPaperType(m_pageData.GetPrintData().GetPaperId()); | |
c801d85f | 746 | |
7bcb11d3 JS |
747 | if (type) |
748 | { | |
749 | m_paperTypeChoice->SetStringSelection(type->GetName()); | |
750 | } | |
c801d85f | 751 | |
7bcb11d3 | 752 | return TRUE; |
c801d85f KB |
753 | } |
754 | ||
7bcb11d3 | 755 | bool wxGenericPageSetupDialog::TransferDataFromWindow() |
c801d85f | 756 | { |
7bcb11d3 | 757 | if (m_marginLeftText && m_marginTopText) |
87138c52 | 758 | m_pageData.SetMarginTopLeft(wxPoint(wxAtoi((const wxChar *)m_marginLeftText->GetValue()),wxAtoi((const wxChar *)m_marginTopText->GetValue()))); |
7bcb11d3 | 759 | if (m_marginRightText && m_marginBottomText) |
87138c52 | 760 | m_pageData.SetMarginBottomRight(wxPoint(wxAtoi((const wxChar *)m_marginRightText->GetValue()),wxAtoi((const wxChar *)m_marginBottomText->GetValue()))); |
8826f46f | 761 | |
7bcb11d3 | 762 | if (m_orientationRadioBox) |
c801d85f | 763 | { |
7bcb11d3 JS |
764 | int sel = m_orientationRadioBox->GetSelection(); |
765 | if (sel == 0) | |
766 | { | |
2a47d3c1 | 767 | #if wxUSE_POSTSCRIPT |
7bcb11d3 | 768 | wxThePrintSetupData->SetPrinterOrientation(wxPORTRAIT); |
2a47d3c1 | 769 | #endif |
7bcb11d3 JS |
770 | m_pageData.GetPrintData().SetOrientation(wxPORTRAIT); |
771 | } | |
772 | else | |
773 | { | |
2a47d3c1 | 774 | #if wxUSE_POSTSCRIPT |
7bcb11d3 | 775 | wxThePrintSetupData->SetPrinterOrientation(wxLANDSCAPE); |
2a47d3c1 | 776 | #endif |
7bcb11d3 JS |
777 | m_pageData.GetPrintData().SetOrientation(wxLANDSCAPE); |
778 | } | |
c801d85f | 779 | } |
7bcb11d3 | 780 | if (m_paperTypeChoice) |
c801d85f | 781 | { |
7bcb11d3 JS |
782 | wxString val(m_paperTypeChoice->GetStringSelection()); |
783 | if (!val.IsNull() && val != "") | |
c801d85f | 784 | { |
7bcb11d3 JS |
785 | wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType(val); |
786 | if ( paper ) | |
787 | { | |
788 | m_pageData.SetPaperSize(wxSize(paper->GetWidth()/10, paper->GetHeight()/10)); | |
789 | m_pageData.GetPrintData().SetPaperId(paper->GetId()); | |
790 | } | |
c801d85f KB |
791 | } |
792 | } | |
8826f46f | 793 | |
7bcb11d3 | 794 | return TRUE; |
c801d85f KB |
795 | } |
796 | ||
fa12f7e6 | 797 | wxComboBox *wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x, int *y) |
c801d85f | 798 | { |
7bcb11d3 JS |
799 | /* |
800 | if (!wxThePrintPaperDatabase) | |
801 | { | |
802 | wxThePrintPaperDatabase = new wxPrintPaperDatabase; | |
803 | wxThePrintPaperDatabase->CreateDatabase(); | |
804 | } | |
805 | */ | |
806 | ||
807 | int n = wxThePrintPaperDatabase->Number(); | |
808 | wxString *choices = new wxString [n]; | |
809 | int i; | |
810 | for (i = 0; i < n; i++) | |
811 | { | |
812 | wxPrintPaperType *paper = (wxPrintPaperType *)wxThePrintPaperDatabase->Nth(i)->Data(); | |
813 | choices[i] = paper->GetName(); | |
814 | } | |
8826f46f | 815 | |
7bcb11d3 JS |
816 | (void) new wxStaticText(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(*x, *y)); |
817 | *y += 25; | |
8826f46f | 818 | |
fa12f7e6 KB |
819 | wxComboBox *choice = new wxComboBox(this, wxPRINTID_PAPERSIZE, |
820 | _("Paper Size"), | |
821 | wxPoint(*x, *y), wxSize(300, -1), n, | |
7bcb11d3 JS |
822 | choices); |
823 | *y += 35; | |
824 | delete[] choices; | |
8826f46f | 825 | |
7bcb11d3 JS |
826 | // choice->SetSelection(sel); |
827 | return choice; | |
c801d85f KB |
828 | } |
829 | ||
ce4169a4 | 830 | #endif |