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