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