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