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