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