1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Generic print dialogs
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "prntdlgg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 #if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
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"
46 #include "wx/cmndata.h"
50 #include "wx/statline.h"
53 #include "wx/generic/prntdlgg.h"
56 #include "wx/generic/dcpsg.h"
59 #include "wx/prntbase.h"
60 #include "wx/printdlg.h"
62 #include "wx/filename.h"
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 extern wxPrintPaperDatabase
*wxThePrintPaperDatabase
;
75 //----------------------------------------------------------------------------
76 // wxPostScriptNativeData
77 //----------------------------------------------------------------------------
79 IMPLEMENT_CLASS(wxPostScriptPrintNativeData
, wxPrintNativeDataBase
)
81 wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
83 m_previewCommand
= wxT("");
85 m_printerCommand
= wxT("print");
86 m_printerOptions
= wxT("/nonotify/queue=psqueue");
87 m_afmPath
= wxT("sys$ps_font_metrics:");
91 m_printerCommand
= wxT("print");
92 m_printerOptions
= wxT("");
93 m_afmPath
= wxT("c:\\windows\\system\\");
96 #if !defined(__VMS__) && !defined(__WXMSW__)
97 m_printerCommand
= wxT("lpr");
98 m_printerOptions
= wxT("");
102 m_printerScaleX
= 1.0;
103 m_printerScaleY
= 1.0;
104 m_printerTranslateX
= 0;
105 m_printerTranslateY
= 0;
108 wxPostScriptPrintNativeData::~wxPostScriptPrintNativeData()
112 bool wxPostScriptPrintNativeData::TransferTo( wxPrintData
&data
)
117 bool wxPostScriptPrintNativeData::TransferFrom( const wxPrintData
&data
)
122 // ----------------------------------------------------------------------------
123 // Generic print dialog for non-Windows printing use.
124 // ----------------------------------------------------------------------------
126 IMPLEMENT_CLASS(wxGenericPrintDialog
, wxPrintDialogBase
)
128 BEGIN_EVENT_TABLE(wxGenericPrintDialog
, wxPrintDialogBase
)
129 EVT_BUTTON(wxID_OK
, wxGenericPrintDialog::OnOK
)
130 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPrintDialog::OnSetup
)
131 EVT_RADIOBOX(wxPRINTID_RANGE
, wxGenericPrintDialog::OnRange
)
134 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
,
135 wxPrintDialogData
* data
)
136 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
137 wxPoint(0, 0), wxSize(600, 600),
138 wxDEFAULT_DIALOG_STYLE
|
142 m_printDialogData
= *data
;
147 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
,
149 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
150 wxPoint(0, 0), wxSize(600, 600),
151 wxDEFAULT_DIALOG_STYLE
|
155 m_printDialogData
= *data
;
160 void wxGenericPrintDialog::Init(wxWindow
* WXUNUSED(parent
))
162 // wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0, 0), wxSize(600, 600),
163 // wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL);
165 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
169 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
171 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
172 new wxStaticBox( this, wxID_ANY
, _( "Printer options" ) ), wxHORIZONTAL
);
173 wxFlexGridSizer
*flex
= new wxFlexGridSizer( 2 );
174 flex
->AddGrowableCol( 1 );
175 topsizer
->Add( flex
, 1, wxGROW
);
177 m_printToFileCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTTOFILE
, _("Print to File") );
178 flex
->Add( m_printToFileCheckBox
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
180 if (factory
->HasOwnPrintToFile())
181 m_printToFileCheckBox
->Enable( false );
183 m_setupButton
= new wxButton(this, wxPRINTID_SETUP
, _("Setup...") );
184 flex
->Add( m_setupButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALIGN_RIGHT
|wxALL
, 5 );
186 if (!factory
->HasPrintSetupDialog())
187 m_setupButton
->Enable( false );
189 if (factory
->HasPrinterLine())
191 flex
->Add( new wxStaticText( this, -1, _("Printer:") ),
192 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
193 flex
->Add( new wxStaticText( this, -1, factory
->CreatePrinterLine() ),
194 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
197 if (factory
->HasStatusLine())
199 flex
->Add( new wxStaticText( this, -1, _("Status:") ),
200 0, wxALIGN_CENTER_VERTICAL
|wxALL
-wxTOP
, 5 );
201 flex
->Add( new wxStaticText( this, -1, factory
->CreateStatusLine() ),
202 0, wxALIGN_CENTER_VERTICAL
|wxALL
-wxTOP
, 5 );
205 mainsizer
->Add( topsizer
, 0, wxLEFT
|wxTOP
|wxRIGHT
|wxGROW
, 10 );
207 // 2) middle row with radio box
209 wxString
*choices
= new wxString
[2];
210 choices
[0] = _("All");
211 choices
[1] = _("Pages");
213 m_fromText
= (wxTextCtrl
*)NULL
;
214 m_toText
= (wxTextCtrl
*)NULL
;
215 m_rangeRadioBox
= (wxRadioBox
*)NULL
;
217 if (m_printDialogData
.GetFromPage() != 0)
219 m_rangeRadioBox
= new wxRadioBox(this, wxPRINTID_RANGE
, _("Print Range"),
220 wxDefaultPosition
, wxDefaultSize
,
223 m_rangeRadioBox
->SetSelection(1);
225 mainsizer
->Add( m_rangeRadioBox
, 0, wxLEFT
|wxTOP
|wxRIGHT
, 10 );
230 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
232 if (m_printDialogData
.GetFromPage() != 0)
234 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("From:") ), 0, wxCENTER
|wxALL
, 5 );
235 m_fromText
= new wxTextCtrl(this, wxPRINTID_FROM
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
236 bottomsizer
->Add( m_fromText
, 1, wxCENTER
|wxRIGHT
, 10 );
238 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("To:") ), 0, wxCENTER
|wxALL
, 5);
239 m_toText
= new wxTextCtrl(this, wxPRINTID_TO
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
240 bottomsizer
->Add( m_toText
, 1, wxCENTER
|wxRIGHT
, 10 );
243 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Copies:") ), 0, wxCENTER
|wxALL
, 5 );
244 m_noCopiesText
= new wxTextCtrl(this, wxPRINTID_COPIES
, wxEmptyString
, wxPoint(252, 130), wxSize(40, wxDefaultCoord
));
245 bottomsizer
->Add( m_noCopiesText
, 1, wxCENTER
|wxRIGHT
, 10 );
247 mainsizer
->Add( bottomsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 12 );
251 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
256 mainsizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxCENTER
|wxALL
, 10 );
258 SetAutoLayout( true );
259 SetSizer( mainsizer
);
261 mainsizer
->Fit( this );
264 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
269 int wxGenericPrintDialog::ShowModal()
271 return wxDialog::ShowModal();
274 wxGenericPrintDialog::~wxGenericPrintDialog()
278 void wxGenericPrintDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
280 TransferDataFromWindow();
282 // An empty 'to' field signals printing just the
284 if (m_printDialogData
.GetToPage() < 1)
285 m_printDialogData
.SetToPage(m_printDialogData
.GetFromPage());
287 // There are some interactions between the global setup data
288 // and the standard print dialog. The global printing 'mode'
289 // is determined by whether the user checks Print to file
291 if (m_printDialogData
.GetPrintToFile())
293 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE
);
295 wxFileName
fname( m_printDialogData
.GetPrintData().GetFilename() );
297 wxFileDialog
dialog( this, _("PostScript file"),
298 fname
.GetPath(), fname
.GetFullName(), wxT("*.ps"), wxOPEN
| wxOVERWRITE_PROMPT
);
299 if (dialog
.ShowModal() != wxID_OK
) return;
301 m_printDialogData
.GetPrintData().SetFilename( dialog
.GetPath() );
305 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER
);
311 void wxGenericPrintDialog::OnRange(wxCommandEvent
& event
)
313 if (!m_fromText
) return;
315 if (event
.GetInt() == 0)
317 m_fromText
->Enable(false);
318 m_toText
->Enable(false);
320 else if (event
.GetInt() == 1)
322 m_fromText
->Enable(true);
323 m_toText
->Enable(true);
327 void wxGenericPrintDialog::OnSetup(wxCommandEvent
& WXUNUSED(event
))
329 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
331 if (factory
->HasPrintSetupDialog())
333 // The print setup dialog should change the
334 // print data in-place if not cancelled.
335 wxDialog
*dialog
= factory
->CreatePrintSetupDialog( this, &m_printDialogData
.GetPrintData() );
341 bool wxGenericPrintDialog::TransferDataToWindow()
343 if(m_printDialogData
.GetFromPage() != 0)
347 if (m_printDialogData
.GetEnablePageNumbers())
349 m_fromText
->Enable(true);
350 m_toText
->Enable(true);
351 if (m_printDialogData
.GetFromPage() > 0)
352 m_fromText
->SetValue(wxString::Format(_T("%d"), m_printDialogData
.GetFromPage()));
353 if (m_printDialogData
.GetToPage() > 0)
354 m_toText
->SetValue(wxString::Format(_T("%d"), m_printDialogData
.GetToPage()));
356 if (m_printDialogData
.GetAllPages() || m_printDialogData
.GetFromPage() == 0)
357 m_rangeRadioBox
->SetSelection(0);
359 m_rangeRadioBox
->SetSelection(1);
363 m_fromText
->Enable(false);
364 m_toText
->Enable(false);
367 m_rangeRadioBox
->SetSelection(0);
368 m_rangeRadioBox
->wxRadioBox::Enable(1, false);
373 m_noCopiesText
->SetValue(
374 wxString::Format(_T("%d"), m_printDialogData
.GetNoCopies()));
376 m_printToFileCheckBox
->SetValue(m_printDialogData
.GetPrintToFile());
377 m_printToFileCheckBox
->Enable(m_printDialogData
.GetEnablePrintToFile());
381 bool wxGenericPrintDialog::TransferDataFromWindow()
384 if(m_printDialogData
.GetFromPage() != -1)
386 if (m_printDialogData
.GetEnablePageNumbers())
390 wxString value
= m_fromText
->GetValue();
391 if (value
.ToLong( &res
))
392 m_printDialogData
.SetFromPage( res
);
396 wxString value
= m_toText
->GetValue();
397 if (value
.ToLong( &res
))
398 m_printDialogData
.SetToPage( res
);
403 if (m_rangeRadioBox
->GetSelection() == 0)
404 m_printDialogData
.SetAllPages(true);
406 m_printDialogData
.SetAllPages(false);
410 { // continuous printing
411 m_printDialogData
.SetFromPage(1);
412 m_printDialogData
.SetToPage(32000);
415 wxString value
= m_noCopiesText
->GetValue();
416 if (value
.ToLong( &res
))
417 m_printDialogData
.SetNoCopies( res
);
419 m_printDialogData
.SetPrintToFile(m_printToFileCheckBox
->GetValue());
425 TODO: collate and noCopies should be duplicated across dialog data and print data objects
426 (slightly different semantics on Windows but let's ignore this for a bit).
429 wxDC
*wxGenericPrintDialog::GetPrintDC()
431 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
434 // ----------------------------------------------------------------------------
435 // Generic print setup dialog
436 // ----------------------------------------------------------------------------
438 IMPLEMENT_CLASS(wxGenericPrintSetupDialog
, wxDialog
)
440 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow
*parent
, wxPrintData
* data
):
441 wxDialog(parent
, wxID_ANY
, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
446 void wxGenericPrintSetupDialog::Init(wxPrintData
* data
)
452 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
454 wxBoxSizer
*item1
= new wxBoxSizer( wxHORIZONTAL
);
455 main_sizer
->Add( item1
, 0, wxALL
, 5 );
457 // printer options (on the left)
459 wxBoxSizer
*item2
= new wxBoxSizer( wxVERTICAL
);
461 wxStaticBox
*item4
= new wxStaticBox( this, wxPRINTID_STATIC
, _("Paper size") );
462 wxStaticBoxSizer
*item3
= new wxStaticBoxSizer( item4
, wxVERTICAL
);
464 m_paperTypeChoice
= CreatePaperTypeChoice();
465 item3
->Add( m_paperTypeChoice
, 0, wxALIGN_CENTER
|wxALL
, 5 );
467 item2
->Add( item3
, 0, wxALIGN_CENTER
|wxALL
, 5 );
474 m_orientationRadioBox
= new wxRadioBox( this, wxPRINTID_ORIENTATION
, _("Orientation"), wxDefaultPosition
, wxDefaultSize
, 2, strs6
, 1, wxRA_SPECIFY_ROWS
);
475 item2
->Add( m_orientationRadioBox
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
477 wxStaticBox
*item8
= new wxStaticBox( this, -1, _("Options") );
478 wxStaticBoxSizer
*item7
= new wxStaticBoxSizer( item8
, wxHORIZONTAL
);
480 m_colourCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTCOLOUR
, _("Print in colour") );
481 item7
->Add( m_colourCheckBox
, 0, wxALIGN_CENTER
|wxALL
, 5 );
483 item2
->Add( item7
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
485 item1
->Add( item2
, 0, wxALIGN_CENTER_HORIZONTAL
, 5 );
487 // spooling options (on the right)
489 wxStaticBox
*item11
= new wxStaticBox( this, -1, _("Print spooling") );
490 wxStaticBoxSizer
*item10
= new wxStaticBoxSizer( item11
, wxVERTICAL
);
492 wxStaticText
*item12
= new wxStaticText( this, -1, _("Printer command:") );
493 item10
->Add( item12
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
495 wxBoxSizer
*item13
= new wxBoxSizer( wxHORIZONTAL
);
497 item13
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
499 m_printerCommandText
= new wxTextCtrl( this, wxPRINTID_COMMAND
, wxT(""), wxDefaultPosition
, wxSize(160,-1) );
500 item13
->Add( m_printerCommandText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
502 item10
->Add( item13
, 0, wxALIGN_CENTER
|wxALL
, 0 );
504 wxStaticText
*item15
= new wxStaticText( this, -1, _("Printer options:") );
505 item10
->Add( item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
507 wxBoxSizer
*item16
= new wxBoxSizer( wxHORIZONTAL
);
509 item16
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
511 m_printerOptionsText
= new wxTextCtrl( this, wxPRINTID_OPTIONS
, wxT(""), wxDefaultPosition
, wxSize(160,-1) );
512 item16
->Add( m_printerOptionsText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
514 item10
->Add( item16
, 0, wxALIGN_CENTER
|wxALL
, 0 );
516 item1
->Add( item10
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5 );
521 main_sizer
->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
526 main_sizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxCENTER
|wxALL
, 10 );
528 SetAutoLayout( true );
529 SetSizer( main_sizer
);
531 main_sizer
->Fit( this );
541 wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
545 bool wxGenericPrintSetupDialog::TransferDataToWindow()
547 wxPostScriptPrintNativeData
*data
=
548 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
550 if (m_printerCommandText
&& data
->GetPrinterCommand())
551 m_printerCommandText
->SetValue(data
->GetPrinterCommand());
552 if (m_printerOptionsText
&& data
->GetPrinterOptions())
553 m_printerOptionsText
->SetValue(data
->GetPrinterOptions());
554 if (m_colourCheckBox
)
555 m_colourCheckBox
->SetValue(m_printData
.GetColour());
557 if (m_orientationRadioBox
)
559 if (m_printData
.GetOrientation() == wxPORTRAIT
)
560 m_orientationRadioBox
->SetSelection(0);
562 m_orientationRadioBox
->SetSelection(1);
567 bool wxGenericPrintSetupDialog::TransferDataFromWindow()
569 wxPostScriptPrintNativeData
*data
=
570 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
572 if (m_printerCommandText
)
573 data
->SetPrinterCommand(m_printerCommandText
->GetValue());
574 if (m_printerOptionsText
)
575 data
->SetPrinterOptions(m_printerOptionsText
->GetValue());
576 if (m_colourCheckBox
)
577 m_printData
.SetColour(m_colourCheckBox
->GetValue());
578 if (m_orientationRadioBox
)
580 int sel
= m_orientationRadioBox
->GetSelection();
582 m_printData
.SetOrientation(wxPORTRAIT
);
584 m_printData
.SetOrientation(wxLANDSCAPE
);
586 if (m_paperTypeChoice
)
588 int selectedItem
= m_paperTypeChoice
->GetSelection();
589 if (selectedItem
!= -1)
591 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
593 m_printData
.SetPaperId( paper
->GetId());
600 wxComboBox
*wxGenericPrintSetupDialog::CreatePaperTypeChoice()
602 size_t n
= wxThePrintPaperDatabase
->GetCount();
603 wxString
*choices
= new wxString
[n
];
606 for (size_t i
= 0; i
< n
; i
++)
608 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
609 choices
[i
] = paper
->GetName();
610 if (m_printData
.GetPaperId() == paper
->GetId())
616 wxComboBox
*choice
= new wxComboBox( this,
620 wxSize(width
, wxDefaultCoord
),
625 choice
->SetSelection(sel
);
629 #endif // wxUSE_POSTSCRIPT
631 // ----------------------------------------------------------------------------
632 // Generic page setup dialog
633 // ----------------------------------------------------------------------------
635 IMPLEMENT_CLASS(wxGenericPageSetupDialog
, wxDialog
)
637 BEGIN_EVENT_TABLE(wxGenericPageSetupDialog
, wxDialog
)
638 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPageSetupDialog::OnPrinter
)
641 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent
& WXUNUSED(event
))
643 // We no longer query GetPrintMode, so we can eliminate the need
644 // to call SetPrintMode.
645 // This has the limitation that we can't explicitly call the PostScript
646 // print setup dialog from the generic Page Setup dialog under Windows,
647 // but since this choice would only happen when trying to do PostScript
648 // printing under Windows (and only in 16-bit Windows which
649 // doesn't have a Windows-specific page setup dialog) it's worth it.
651 // First save the current settings, so the wxPrintData object is up to date.
652 TransferDataFromWindow();
654 // Transfer the current print settings from this dialog to the page setup dialog.
655 wxPrintDialogData data
;
656 data
= GetPageSetupData().GetPrintData();
657 data
.SetSetupDialog(true);
658 wxPrintDialog
printDialog(this, & data
);
659 printDialog
.ShowModal();
661 // Transfer the page setup print settings from the page dialog to this dialog again, in case
662 // the page setup dialog changed something.
663 GetPageSetupData().GetPrintData() = printDialog
.GetPrintDialogData().GetPrintData();
664 GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData
666 // Now update the dialog in case the page setup dialog changed some of our settings.
667 TransferDataToWindow();
670 wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow
*parent
,
671 wxPageSetupData
* data
)
677 wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
684 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
687 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
688 new wxStaticBox(this,wxPRINTID_STATIC
, _("Paper size")), wxHORIZONTAL
);
690 size_t n
= wxThePrintPaperDatabase
->GetCount();
691 wxString
*choices
= new wxString
[n
];
693 for (size_t i
= 0; i
< n
; i
++)
695 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
696 choices
[i
] = paper
->GetName();
699 m_paperTypeChoice
= new wxComboBox( this,
703 wxSize(300, wxDefaultCoord
),
705 topsizer
->Add( m_paperTypeChoice
, 1, wxEXPAND
|wxALL
, 5 );
706 // m_paperTypeChoice->SetSelection(sel);
708 mainsizer
->Add( topsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
710 // 2) middle sizer with radio box
712 wxString
*choices2
= new wxString
[2];
713 choices2
[0] = _("Portrait");
714 choices2
[1] = _("Landscape");
715 m_orientationRadioBox
= new wxRadioBox(this, wxPRINTID_ORIENTATION
, _("Orientation"),
716 wxDefaultPosition
, wxDefaultSize
, 2, choices2
, 2);
717 m_orientationRadioBox
->SetSelection(0);
719 mainsizer
->Add( m_orientationRadioBox
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 10 );
723 wxBoxSizer
*table
= new wxBoxSizer( wxHORIZONTAL
);
725 wxBoxSizer
*column1
= new wxBoxSizer( wxVERTICAL
);
726 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Left margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
727 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Top margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
728 table
->Add( column1
, 0, wxALL
| wxEXPAND
, 5 );
730 wxBoxSizer
*column2
= new wxBoxSizer( wxVERTICAL
);
731 m_marginLeftText
= new wxTextCtrl(this, wxPRINTID_LEFTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
732 m_marginTopText
= new wxTextCtrl(this, wxPRINTID_TOPMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
733 column2
->Add( m_marginLeftText
, 1, wxALL
, 5 );
734 column2
->Add( m_marginTopText
, 1, wxALL
, 5 );
735 table
->Add( column2
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
737 wxBoxSizer
*column3
= new wxBoxSizer( wxVERTICAL
);
738 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Right margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
739 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Bottom margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
740 table
->Add( column3
, 0, wxALL
| wxEXPAND
, 5 );
742 wxBoxSizer
*column4
= new wxBoxSizer( wxVERTICAL
);
743 m_marginRightText
= new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
744 m_marginBottomText
= new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
745 column4
->Add( m_marginRightText
, 1, wxALL
, 5 );
746 column4
->Add( m_marginBottomText
, 1, wxALL
, 5 );
747 table
->Add( column4
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
749 mainsizer
->Add( table
, 0 );
753 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
758 wxSizer
* buttonsizer
= CreateButtonSizer( wxOK
|wxCANCEL
);
759 m_printerButton
= new wxButton(this, wxPRINTID_SETUP
, _("Printer...") );
760 buttonsizer
->Add( m_printerButton
, 0, wxLEFT
|wxRIGHT
, 10 );
761 if ( !m_pageData
.GetEnablePrinter() )
762 m_printerButton
->Enable(false);
763 // if (m_printData.GetEnableHelp())
764 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight);
765 mainsizer
->Add( buttonsizer
, 0, wxCENTER
|wxALL
, 10 );
768 SetAutoLayout( true );
769 SetSizer( mainsizer
);
771 mainsizer
->Fit( this );
780 wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
784 bool wxGenericPageSetupDialog::TransferDataToWindow()
786 if (m_marginLeftText
)
787 m_marginLeftText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().x
));
789 m_marginTopText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().y
));
790 if (m_marginRightText
)
791 m_marginRightText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().x
));
792 if (m_marginBottomText
)
793 m_marginBottomText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().y
));
795 if (m_orientationRadioBox
)
797 if (m_pageData
.GetPrintData().GetOrientation() == wxPORTRAIT
)
798 m_orientationRadioBox
->SetSelection(0);
800 m_orientationRadioBox
->SetSelection(1);
803 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
804 // failing that, the id in the wxPrintData object.
806 wxPrintPaperType
* type
= wxThePrintPaperDatabase
->FindPaperType(
807 wxSize(m_pageData
.GetPaperSize().x
* 10, m_pageData
.GetPaperSize().y
* 10));
809 if (!type
&& m_pageData
.GetPrintData().GetPaperId() != wxPAPER_NONE
)
810 type
= wxThePrintPaperDatabase
->FindPaperType(m_pageData
.GetPrintData().GetPaperId());
814 m_paperTypeChoice
->SetStringSelection(type
->GetName());
820 bool wxGenericPageSetupDialog::TransferDataFromWindow()
822 if (m_marginLeftText
&& m_marginTopText
)
824 int left
= wxAtoi( m_marginLeftText
->GetValue().c_str() );
825 int top
= wxAtoi( m_marginTopText
->GetValue().c_str() );
826 m_pageData
.SetMarginTopLeft( wxPoint(left
,top
) );
828 if (m_marginRightText
&& m_marginBottomText
)
830 int right
= wxAtoi( m_marginRightText
->GetValue().c_str() );
831 int bottom
= wxAtoi( m_marginBottomText
->GetValue().c_str() );
832 m_pageData
.SetMarginBottomRight( wxPoint(right
,bottom
) );
835 if (m_orientationRadioBox
)
837 int sel
= m_orientationRadioBox
->GetSelection();
840 m_pageData
.GetPrintData().SetOrientation(wxPORTRAIT
);
844 m_pageData
.GetPrintData().SetOrientation(wxLANDSCAPE
);
848 if (m_paperTypeChoice
)
850 int selectedItem
= m_paperTypeChoice
->GetSelection();
851 if (selectedItem
!= -1)
853 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
856 m_pageData
.SetPaperSize(wxSize(paper
->GetWidth()/10, paper
->GetHeight()/10));
857 m_pageData
.GetPrintData().SetPaperId(paper
->GetId());
865 wxComboBox
*wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x
, int *y
)
868 if (!wxThePrintPaperDatabase)
870 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
871 wxThePrintPaperDatabase->CreateDatabase();
875 size_t n
= wxThePrintPaperDatabase
->GetCount();
876 wxString
*choices
= new wxString
[n
];
878 for (size_t i
= 0; i
< n
; i
++)
880 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
881 choices
[i
] = paper
->GetName();
884 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Paper size"), wxPoint(*x
, *y
));
887 wxComboBox
*choice
= new wxComboBox( this,
891 wxSize(300, wxDefaultCoord
),
896 // choice->SetSelection(sel);