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