1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Generic print dialogs
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "prntdlgg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #if wxUSE_PRINTING_ARCHITECTURE
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"
48 #include "wx/combobox.h"
54 #include "wx/statline.h"
57 #include "wx/generic/prntdlgg.h"
60 #include "wx/generic/dcpsg.h"
63 #include "wx/printdlg.h"
66 // For print paper things
67 #include "wx/prntbase.h"
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 #if !USE_SHARED_LIBRARY
80 IMPLEMENT_CLASS(wxGenericPrintDialog
, wxDialog
)
81 IMPLEMENT_CLASS(wxGenericPrintSetupDialog
, wxDialog
)
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
)
90 IMPLEMENT_CLASS(wxGenericPageSetupDialog
, wxDialog
)
92 BEGIN_EVENT_TABLE(wxGenericPageSetupDialog
, wxDialog
)
93 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPageSetupDialog::OnPrinter
)
95 #endif // USE_SHARED_LIBRARY
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 extern wxPrintPaperDatabase
*wxThePrintPaperDatabase
;
105 // ============================================================================
107 // ============================================================================
109 // ----------------------------------------------------------------------------
110 // Generic print dialog for non-Windows printing use.
111 // ----------------------------------------------------------------------------
113 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
,
114 wxPrintDialogData
* data
)
115 : wxDialog(parent
, -1, _("Print"),
116 wxPoint(0, 0), wxSize(600, 600),
117 wxDEFAULT_DIALOG_STYLE
|
122 m_printDialogData
= *data
;
127 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
,
129 : wxDialog(parent
, -1, _("Print"),
130 wxPoint(0, 0), wxSize(600, 600),
131 wxDEFAULT_DIALOG_STYLE
|
136 m_printDialogData
= *data
;
141 void wxGenericPrintDialog::Init(wxWindow
* WXUNUSED(parent
))
143 // wxDialog::Create(parent, -1, _("Print"), wxPoint(0, 0), wxSize(600, 600),
144 // wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL | wxTAB_TRAVERSAL);
146 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
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 );
155 topsizer
->Add( 60,2,1 );
157 m_setupButton
= new wxButton(this, wxPRINTID_SETUP
, _("Setup...") );
158 topsizer
->Add( m_setupButton
, 0, wxCENTER
|wxALL
, 5 );
160 mainsizer
->Add( topsizer
, 0, wxLEFT
|wxTOP
|wxRIGHT
, 10 );
162 // 2) middle row with radio box
164 wxString
*choices
= new wxString
[2];
165 choices
[0] = _("All");
166 choices
[1] = _("Pages");
168 m_fromText
= (wxTextCtrl
*)NULL
;
169 m_toText
= (wxTextCtrl
*)NULL
;
170 m_rangeRadioBox
= (wxRadioBox
*)NULL
;
172 if (m_printDialogData
.GetFromPage() != 0)
174 m_rangeRadioBox
= new wxRadioBox(this, wxPRINTID_RANGE
, _("Print Range"),
175 wxDefaultPosition
, wxDefaultSize
,
178 m_rangeRadioBox
->SetSelection(1);
180 mainsizer
->Add( m_rangeRadioBox
, 0, wxLEFT
|wxTOP
|wxRIGHT
, 10 );
185 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
187 if (m_printDialogData
.GetFromPage() != 0)
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 );
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 );
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 );
202 mainsizer
->Add( bottomsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 12 );
206 mainsizer
->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
211 mainsizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxCENTER
|wxALL
, 10 );
213 SetAutoLayout( TRUE
);
214 SetSizer( mainsizer
);
216 mainsizer
->Fit( this );
219 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
224 int wxGenericPrintDialog::ShowModal()
226 if ( m_printDialogData
.GetSetupDialog() )
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();
233 wxGenericPrintSetupDialog
*genericPrintSetupDialog
=
234 new wxGenericPrintSetupDialog(this, & m_printDialogData
.GetPrintData());
235 int ret
= genericPrintSetupDialog
->ShowModal();
236 if ( ret
!= wxID_CANCEL
)
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();
243 genericPrintSetupDialog
->Destroy();
245 // Restore the wxPrintData settings again (uncomment if any settings become common
247 // TransferDataToWindow();
253 return wxDialog::ShowModal();
257 wxGenericPrintDialog::~wxGenericPrintDialog()
261 void wxGenericPrintDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
263 TransferDataFromWindow();
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
269 if (m_printDialogData
.GetPrintToFile())
271 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE
);
272 wxThePrintSetupData
->SetPrinterMode(wxPRINT_MODE_FILE
);
274 wxString f
= wxFileSelector(_("PostScript file"),
275 wxPathOnly(wxThePrintSetupData
->GetPrinterFile()),
276 wxFileNameFromPath(wxThePrintSetupData
->GetPrinterFile()),
277 _T("ps"), _T("*.ps"), 0, this);
281 m_printDialogData
.GetPrintData().SetFilename(f
);
282 wxThePrintSetupData
->SetPrinterFile(f
);
286 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER
);
287 wxThePrintSetupData
->SetPrinterMode(wxPRINT_MODE_PRINTER
);
293 void wxGenericPrintDialog::OnRange(wxCommandEvent
& event
)
295 if (!m_fromText
) return;
297 if (event
.GetInt() == 0)
299 m_fromText
->Enable(FALSE
);
300 m_toText
->Enable(FALSE
);
302 else if (event
.GetInt() == 1)
304 m_fromText
->Enable(TRUE
);
305 m_toText
->Enable(TRUE
);
309 void wxGenericPrintDialog::OnSetup(wxCommandEvent
& WXUNUSED(event
))
311 *wxThePrintSetupData
= m_printDialogData
.GetPrintData();
312 wxGenericPrintSetupDialog
*genericPrintSetupDialog
=
313 new wxGenericPrintSetupDialog(this, wxThePrintSetupData
);
314 int ret
= genericPrintSetupDialog
->ShowModal();
315 if ( ret
!= wxID_CANCEL
)
317 *wxThePrintSetupData
= genericPrintSetupDialog
->GetPrintData();
318 m_printDialogData
= genericPrintSetupDialog
->GetPrintData();
321 genericPrintSetupDialog
->Close(TRUE
);
324 bool wxGenericPrintDialog::TransferDataToWindow()
328 if(m_printDialogData
.GetFromPage() != 0)
332 if (m_printDialogData
.GetEnablePageNumbers())
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
);
341 if (m_printDialogData
.GetAllPages())
342 m_rangeRadioBox
->SetSelection(0);
344 m_rangeRadioBox
->SetSelection(1);
348 m_fromText
->Enable(FALSE
);
349 m_toText
->Enable(FALSE
);
352 m_rangeRadioBox
->SetSelection(0);
353 m_rangeRadioBox
->wxRadioBox::Enable(1, FALSE
);
358 sprintf(buf
, "%d", m_printDialogData
.GetNoCopies());
359 m_noCopiesText
->SetValue(buf
);
361 m_printToFileCheckBox
->SetValue(m_printDialogData
.GetPrintToFile());
362 m_printToFileCheckBox
->Enable(m_printDialogData
.GetEnablePrintToFile());
366 bool wxGenericPrintDialog::TransferDataFromWindow()
368 if(m_printDialogData
.GetFromPage() != -1)
370 if (m_printDialogData
.GetEnablePageNumbers())
372 if(m_fromText
) m_printDialogData
.SetFromPage(wxAtoi(m_fromText
->GetValue()));
373 if(m_toText
) m_printDialogData
.SetToPage(wxAtoi(m_toText
->GetValue()));
377 if (m_rangeRadioBox
->GetSelection() == 0)
378 m_printDialogData
.SetAllPages(TRUE
);
380 m_printDialogData
.SetAllPages(FALSE
);
384 { // continuous printing
385 m_printDialogData
.SetFromPage(1);
386 m_printDialogData
.SetToPage(32000);
388 m_printDialogData
.SetNoCopies(wxAtoi(m_noCopiesText
->GetValue()));
389 m_printDialogData
.SetPrintToFile(m_printToFileCheckBox
->GetValue());
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).
399 wxDC
*wxGenericPrintDialog::GetPrintDC()
401 // return new wxPostScriptDC(wxThePrintSetupData->GetPrinterFile(), FALSE, (wxWindow *) NULL);
402 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
405 // ----------------------------------------------------------------------------
406 // Generic print setup dialog
407 // ----------------------------------------------------------------------------
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
)
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
)
419 wxPrintData printData
;
423 printData
= * wxThePrintSetupData
;
428 void wxGenericPrintSetupDialog::Init(wxPrintData
* data
)
433 int staticBoxWidth
= 300;
435 (void) new wxStaticBox(this, wxPRINTID_STATIC
, _("Paper size"), wxPoint(10, 10), wxSize(staticBoxWidth
, 60) );
439 m_paperTypeChoice
= CreatePaperTypeChoice(&xPos
, &yPos
);
441 wxString
*choices
= new wxString
[2];
442 choices
[0] = _("Portrait");
443 choices
[1] = _("Landscape");
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);
449 (void) new wxStaticBox(this, wxPRINTID_STATIC
, _("Options"), wxPoint(10, 130), wxSize(staticBoxWidth
, 50) );
451 int colourYPos
= 145;
457 m_colourCheckBox
= new wxCheckBox(this, wxPRINTID_PRINTCOLOUR
, _("Print in colour"), wxPoint(15, colourYPos
));
459 (void) new wxStaticBox(this, wxPRINTID_STATIC
, _("Print spooling"), wxPoint(330, 10), wxSize(200,170) );
461 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Printer command:"), wxPoint(340, 30));
463 m_printerCommandText
= new wxTextCtrl(this, wxPRINTID_COMMAND
, "", wxPoint(360, 55), wxSize(150, -1));
465 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Printer options:"), wxPoint(340, 110));
467 m_printerOptionsText
= new wxTextCtrl(this, wxPRINTID_OPTIONS
, "", wxPoint(360, 135), wxSize(150, -1));
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));
472 okButton
->SetDefault();
473 okButton
->SetFocus();
482 wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
486 bool wxGenericPrintSetupDialog::TransferDataToWindow()
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());
495 if (m_orientationRadioBox
)
497 if (m_printData
.GetOrientation() == wxPORTRAIT
)
498 m_orientationRadioBox
->SetSelection(0);
500 m_orientationRadioBox
->SetSelection(1);
505 bool wxGenericPrintSetupDialog::TransferDataFromWindow()
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
)
515 int sel
= m_orientationRadioBox
->GetSelection();
517 m_printData
.SetOrientation(wxPORTRAIT
);
519 m_printData
.SetOrientation(wxLANDSCAPE
);
521 if (m_paperTypeChoice
)
523 wxString
val(m_paperTypeChoice
->GetStringSelection());
524 if (!val
.IsNull() && val
!= "")
525 m_printData
.SetPaperId(wxThePrintPaperDatabase
->ConvertNameToId(val
));
528 // This is for backward compatibility only
529 *wxThePrintSetupData
= GetPrintData();
533 wxComboBox
*wxGenericPrintSetupDialog::CreatePaperTypeChoice(int *x
, int *y
)
535 /* Should not be necessary
536 if (!wxThePrintPaperDatabase)
538 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
539 wxThePrintPaperDatabase->CreateDatabase();
542 int n
= wxThePrintPaperDatabase
->Number();
543 wxString
*choices
= new wxString
[n
];
546 for (i
= 0; i
< n
; i
++)
548 wxPrintPaperType
*paper
= (wxPrintPaperType
*)wxThePrintPaperDatabase
->Nth(i
)->Data();
549 choices
[i
] = paper
->GetName();
550 if (m_printData
.GetPaperId() == paper
->GetId())
556 wxComboBox
*choice
= new wxComboBox(this, wxPRINTID_PAPERSIZE
,
558 wxPoint(*x
, *y
), wxSize(width
, -1), n
,
561 // SetFont(thisFont);
565 choice
->SetSelection(sel
);
568 #endif // wxUSE_POSTSCRIPT
570 // ----------------------------------------------------------------------------
571 // Generic page setup dialog
572 // ----------------------------------------------------------------------------
574 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent
& WXUNUSED(event
))
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.
584 // First save the current settings, so the wxPrintData object is up to date.
585 TransferDataFromWindow();
587 // Transfer the current print settings from this dialog to the page setup dialog.
588 wxPrintDialogData data
;
589 data
= GetPageSetupData().GetPrintData();
590 data
.SetSetupDialog(TRUE
);
591 wxPrintDialog
*printDialog
= new wxPrintDialog(this, & data
);
592 printDialog
->ShowModal();
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
599 printDialog
->Destroy();
601 // Now update the dialog in case the page setup dialog changed some of our settings.
602 TransferDataToWindow();
605 wxGenericPageSetupDialog::wxGenericPageSetupDialog(wxWindow
*parent
, wxPageSetupData
* data
):
606 wxDialog(parent
, -1, _("Page Setup"), wxPoint(0, 0), wxSize(600, 600), wxDIALOG_MODAL
|wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
613 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
616 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
617 new wxStaticBox(this,wxPRINTID_STATIC
, _("Paper size")), wxHORIZONTAL
);
619 int n
= wxThePrintPaperDatabase
->Number();
620 wxString
*choices
= new wxString
[n
];
622 for (i
= 0; i
< n
; i
++)
624 wxPrintPaperType
*paper
= (wxPrintPaperType
*)wxThePrintPaperDatabase
->Nth(i
)->Data();
625 choices
[i
] = paper
->GetName();
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);
633 mainsizer
->Add( topsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
635 // 2) middle sizer with radio box
637 wxString
*choices2
= new wxString
[2];
638 choices2
[0] = _("Portrait");
639 choices2
[1] = _("Landscape");
640 m_orientationRadioBox
= new wxRadioBox(this, wxPRINTID_ORIENTATION
, _("Orientation"),
641 wxDefaultPosition
, wxDefaultSize
, 2, choices2
, 2);
642 m_orientationRadioBox
->SetSelection(0);
644 mainsizer
->Add( m_orientationRadioBox
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 10 );
648 wxBoxSizer
*table
= new wxBoxSizer( wxHORIZONTAL
);
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 );
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 );
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 );
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 );
674 mainsizer
->Add( table
, 0 );
678 mainsizer
->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
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 );
693 SetAutoLayout( TRUE
);
694 SetSizer( mainsizer
);
696 mainsizer
->Fit( this );
705 wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
709 bool wxGenericPageSetupDialog::TransferDataToWindow()
711 if (m_marginLeftText
)
712 m_marginLeftText
->SetValue(IntToString((int) m_pageData
.GetMarginTopLeft().x
));
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
));
720 if (m_orientationRadioBox
)
722 if (m_pageData
.GetPrintData().GetOrientation() == wxPORTRAIT
)
723 m_orientationRadioBox
->SetSelection(0);
725 m_orientationRadioBox
->SetSelection(1);
728 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
729 // failing that, the id in the wxPrintData object.
731 wxPrintPaperType
* type
= wxThePrintPaperDatabase
->FindPaperType(
732 wxSize(m_pageData
.GetPaperSize().x
* 10, m_pageData
.GetPaperSize().y
* 10));
734 if (!type
&& m_pageData
.GetPrintData().GetPaperId() != wxPAPER_NONE
)
735 type
= wxThePrintPaperDatabase
->FindPaperType(m_pageData
.GetPrintData().GetPaperId());
739 m_paperTypeChoice
->SetStringSelection(type
->GetName());
745 bool wxGenericPageSetupDialog::TransferDataFromWindow()
747 if (m_marginLeftText
&& m_marginTopText
)
748 m_pageData
.SetMarginTopLeft(wxPoint(wxAtoi((const wxChar
*)m_marginLeftText
->GetValue()),wxAtoi((const wxChar
*)m_marginTopText
->GetValue())));
749 if (m_marginRightText
&& m_marginBottomText
)
750 m_pageData
.SetMarginBottomRight(wxPoint(wxAtoi((const wxChar
*)m_marginRightText
->GetValue()),wxAtoi((const wxChar
*)m_marginBottomText
->GetValue())));
752 if (m_orientationRadioBox
)
754 int sel
= m_orientationRadioBox
->GetSelection();
758 wxThePrintSetupData
->SetPrinterOrientation(wxPORTRAIT
);
760 m_pageData
.GetPrintData().SetOrientation(wxPORTRAIT
);
765 wxThePrintSetupData
->SetPrinterOrientation(wxLANDSCAPE
);
767 m_pageData
.GetPrintData().SetOrientation(wxLANDSCAPE
);
770 if (m_paperTypeChoice
)
772 wxString
val(m_paperTypeChoice
->GetStringSelection());
773 if (!val
.IsNull() && val
!= "")
775 wxPrintPaperType
* paper
= wxThePrintPaperDatabase
->FindPaperType(val
);
778 m_pageData
.SetPaperSize(wxSize(paper
->GetWidth()/10, paper
->GetHeight()/10));
779 m_pageData
.GetPrintData().SetPaperId(paper
->GetId());
787 wxComboBox
*wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x
, int *y
)
790 if (!wxThePrintPaperDatabase)
792 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
793 wxThePrintPaperDatabase->CreateDatabase();
797 int n
= wxThePrintPaperDatabase
->Number();
798 wxString
*choices
= new wxString
[n
];
800 for (i
= 0; i
< n
; i
++)
802 wxPrintPaperType
*paper
= (wxPrintPaperType
*)wxThePrintPaperDatabase
->Nth(i
)->Data();
803 choices
[i
] = paper
->GetName();
806 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Paper size"), wxPoint(*x
, *y
));
809 wxComboBox
*choice
= new wxComboBox(this, wxPRINTID_PAPERSIZE
,
811 wxPoint(*x
, *y
), wxSize(300, -1), n
,
816 // choice->SetSelection(sel);