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 m_setupButton
= new wxButton(this, wxPRINTID_SETUP
, _("Setup...") );
181 flex
->Add( m_setupButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALIGN_RIGHT
|wxALL
, 5 );
183 if (!factory
->HasPrintSetupDialog())
184 m_setupButton
->Enable( false );
186 if (factory
->HasPrinterLine())
188 flex
->Add( new wxStaticText( this, -1, _("Printer:") ),
189 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
190 flex
->Add( new wxStaticText( this, -1, factory
->CreatePrinterLine() ),
191 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
194 if (factory
->HasStatusLine())
196 flex
->Add( new wxStaticText( this, -1, _("Status:") ),
197 0, wxALIGN_CENTER_VERTICAL
|wxALL
-wxTOP
, 5 );
198 flex
->Add( new wxStaticText( this, -1, factory
->CreateStatusLine() ),
199 0, wxALIGN_CENTER_VERTICAL
|wxALL
-wxTOP
, 5 );
202 mainsizer
->Add( topsizer
, 0, wxLEFT
|wxTOP
|wxRIGHT
|wxGROW
, 10 );
204 // 2) middle row with radio box
206 wxString
*choices
= new wxString
[2];
207 choices
[0] = _("All");
208 choices
[1] = _("Pages");
210 m_fromText
= (wxTextCtrl
*)NULL
;
211 m_toText
= (wxTextCtrl
*)NULL
;
212 m_rangeRadioBox
= (wxRadioBox
*)NULL
;
214 if (m_printDialogData
.GetFromPage() != 0)
216 m_rangeRadioBox
= new wxRadioBox(this, wxPRINTID_RANGE
, _("Print Range"),
217 wxDefaultPosition
, wxDefaultSize
,
220 m_rangeRadioBox
->SetSelection(1);
222 mainsizer
->Add( m_rangeRadioBox
, 0, wxLEFT
|wxTOP
|wxRIGHT
, 10 );
227 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
229 if (m_printDialogData
.GetFromPage() != 0)
231 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("From:") ), 0, wxCENTER
|wxALL
, 5 );
232 m_fromText
= new wxTextCtrl(this, wxPRINTID_FROM
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
233 bottomsizer
->Add( m_fromText
, 1, wxCENTER
|wxRIGHT
, 10 );
235 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("To:") ), 0, wxCENTER
|wxALL
, 5);
236 m_toText
= new wxTextCtrl(this, wxPRINTID_TO
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
237 bottomsizer
->Add( m_toText
, 1, wxCENTER
|wxRIGHT
, 10 );
240 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Copies:") ), 0, wxCENTER
|wxALL
, 5 );
241 m_noCopiesText
= new wxTextCtrl(this, wxPRINTID_COPIES
, wxEmptyString
, wxPoint(252, 130), wxSize(40, wxDefaultCoord
));
242 bottomsizer
->Add( m_noCopiesText
, 1, wxCENTER
|wxRIGHT
, 10 );
244 mainsizer
->Add( bottomsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 12 );
248 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
253 mainsizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxCENTER
|wxALL
, 10 );
255 SetAutoLayout( true );
256 SetSizer( mainsizer
);
258 mainsizer
->Fit( this );
261 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
266 int wxGenericPrintDialog::ShowModal()
268 return wxDialog::ShowModal();
271 wxGenericPrintDialog::~wxGenericPrintDialog()
275 void wxGenericPrintDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
277 TransferDataFromWindow();
279 // An empty 'to' field signals printing just the
281 if (m_printDialogData
.GetToPage() < 1)
282 m_printDialogData
.SetToPage(m_printDialogData
.GetFromPage());
284 // There are some interactions between the global setup data
285 // and the standard print dialog. The global printing 'mode'
286 // is determined by whether the user checks Print to file
288 if (m_printDialogData
.GetPrintToFile())
290 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE
);
292 wxFileName
fname( m_printDialogData
.GetPrintData().GetFilename() );
294 wxFileDialog
dialog( this, _("PostScript file"),
295 fname
.GetPath(), fname
.GetFullName(), wxT("*.ps"), wxOPEN
| wxOVERWRITE_PROMPT
);
296 if (dialog
.ShowModal() != wxID_OK
) return;
298 m_printDialogData
.GetPrintData().SetFilename( dialog
.GetPath() );
302 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER
);
308 void wxGenericPrintDialog::OnRange(wxCommandEvent
& event
)
310 if (!m_fromText
) return;
312 if (event
.GetInt() == 0)
314 m_fromText
->Enable(false);
315 m_toText
->Enable(false);
317 else if (event
.GetInt() == 1)
319 m_fromText
->Enable(true);
320 m_toText
->Enable(true);
324 void wxGenericPrintDialog::OnSetup(wxCommandEvent
& WXUNUSED(event
))
326 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
328 if (factory
->HasPrintSetupDialog())
330 // The print setup dialog should change the
331 // print data in-place if not cancelled.
332 wxDialog
*dialog
= factory
->CreatePrintSetupDialog( this, &m_printDialogData
.GetPrintData() );
338 bool wxGenericPrintDialog::TransferDataToWindow()
340 if(m_printDialogData
.GetFromPage() != 0)
344 if (m_printDialogData
.GetEnablePageNumbers())
346 m_fromText
->Enable(true);
347 m_toText
->Enable(true);
348 if (m_printDialogData
.GetFromPage() > 0)
349 m_fromText
->SetValue(wxString::Format(_T("%d"), m_printDialogData
.GetFromPage()));
350 if (m_printDialogData
.GetToPage() > 0)
351 m_toText
->SetValue(wxString::Format(_T("%d"), m_printDialogData
.GetToPage()));
353 if (m_printDialogData
.GetAllPages() || m_printDialogData
.GetFromPage() == 0)
354 m_rangeRadioBox
->SetSelection(0);
356 m_rangeRadioBox
->SetSelection(1);
360 m_fromText
->Enable(false);
361 m_toText
->Enable(false);
364 m_rangeRadioBox
->SetSelection(0);
365 m_rangeRadioBox
->wxRadioBox::Enable(1, false);
370 m_noCopiesText
->SetValue(
371 wxString::Format(_T("%d"), m_printDialogData
.GetNoCopies()));
373 m_printToFileCheckBox
->SetValue(m_printDialogData
.GetPrintToFile());
374 m_printToFileCheckBox
->Enable(m_printDialogData
.GetEnablePrintToFile());
378 bool wxGenericPrintDialog::TransferDataFromWindow()
381 if(m_printDialogData
.GetFromPage() != -1)
383 if (m_printDialogData
.GetEnablePageNumbers())
387 wxString value
= m_fromText
->GetValue();
388 if (value
.ToLong( &res
))
389 m_printDialogData
.SetFromPage( res
);
393 wxString value
= m_toText
->GetValue();
394 if (value
.ToLong( &res
))
395 m_printDialogData
.SetToPage( res
);
400 if (m_rangeRadioBox
->GetSelection() == 0)
401 m_printDialogData
.SetAllPages(true);
403 m_printDialogData
.SetAllPages(false);
407 { // continuous printing
408 m_printDialogData
.SetFromPage(1);
409 m_printDialogData
.SetToPage(32000);
412 wxString value
= m_noCopiesText
->GetValue();
413 if (value
.ToLong( &res
))
414 m_printDialogData
.SetNoCopies( res
);
416 m_printDialogData
.SetPrintToFile(m_printToFileCheckBox
->GetValue());
422 TODO: collate and noCopies should be duplicated across dialog data and print data objects
423 (slightly different semantics on Windows but let's ignore this for a bit).
426 wxDC
*wxGenericPrintDialog::GetPrintDC()
428 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
431 // ----------------------------------------------------------------------------
432 // Generic print setup dialog
433 // ----------------------------------------------------------------------------
435 IMPLEMENT_CLASS(wxGenericPrintSetupDialog
, wxDialog
)
437 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow
*parent
, wxPrintData
* data
):
438 wxDialog(parent
, wxID_ANY
, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
443 void wxGenericPrintSetupDialog::Init(wxPrintData
* data
)
449 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
451 wxBoxSizer
*item1
= new wxBoxSizer( wxHORIZONTAL
);
452 main_sizer
->Add( item1
, 0, wxALL
, 5 );
454 // printer options (on the left)
456 wxBoxSizer
*item2
= new wxBoxSizer( wxVERTICAL
);
458 wxStaticBox
*item4
= new wxStaticBox( this, wxPRINTID_STATIC
, _("Paper size") );
459 wxStaticBoxSizer
*item3
= new wxStaticBoxSizer( item4
, wxVERTICAL
);
461 m_paperTypeChoice
= CreatePaperTypeChoice();
462 item3
->Add( m_paperTypeChoice
, 0, wxALIGN_CENTER
|wxALL
, 5 );
464 item2
->Add( item3
, 0, wxALIGN_CENTER
|wxALL
, 5 );
471 m_orientationRadioBox
= new wxRadioBox( this, wxPRINTID_ORIENTATION
, _("Orientation"), wxDefaultPosition
, wxDefaultSize
, 2, strs6
, 1, wxRA_SPECIFY_ROWS
);
472 item2
->Add( m_orientationRadioBox
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
474 wxStaticBox
*item8
= new wxStaticBox( this, -1, _("Options") );
475 wxStaticBoxSizer
*item7
= new wxStaticBoxSizer( item8
, wxHORIZONTAL
);
477 m_colourCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTCOLOUR
, _("Print in colour") );
478 item7
->Add( m_colourCheckBox
, 0, wxALIGN_CENTER
|wxALL
, 5 );
480 item2
->Add( item7
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
482 item1
->Add( item2
, 0, wxALIGN_CENTER_HORIZONTAL
, 5 );
484 // spooling options (on the right)
486 wxStaticBox
*item11
= new wxStaticBox( this, -1, _("Print spooling") );
487 wxStaticBoxSizer
*item10
= new wxStaticBoxSizer( item11
, wxVERTICAL
);
489 wxStaticText
*item12
= new wxStaticText( this, -1, _("Printer command:") );
490 item10
->Add( item12
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
492 wxBoxSizer
*item13
= new wxBoxSizer( wxHORIZONTAL
);
494 item13
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
496 m_printerCommandText
= new wxTextCtrl( this, wxPRINTID_COMMAND
, wxT(""), wxDefaultPosition
, wxSize(160,-1) );
497 item13
->Add( m_printerCommandText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
499 item10
->Add( item13
, 0, wxALIGN_CENTER
|wxALL
, 0 );
501 wxStaticText
*item15
= new wxStaticText( this, -1, _("Printer options:") );
502 item10
->Add( item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
504 wxBoxSizer
*item16
= new wxBoxSizer( wxHORIZONTAL
);
506 item16
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
508 m_printerOptionsText
= new wxTextCtrl( this, wxPRINTID_OPTIONS
, wxT(""), wxDefaultPosition
, wxSize(160,-1) );
509 item16
->Add( m_printerOptionsText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
511 item10
->Add( item16
, 0, wxALIGN_CENTER
|wxALL
, 0 );
513 item1
->Add( item10
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5 );
518 main_sizer
->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
523 main_sizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxCENTER
|wxALL
, 10 );
525 SetAutoLayout( true );
526 SetSizer( main_sizer
);
528 main_sizer
->Fit( this );
538 wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
542 bool wxGenericPrintSetupDialog::TransferDataToWindow()
544 wxPostScriptPrintNativeData
*data
=
545 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
547 if (m_printerCommandText
&& data
->GetPrinterCommand())
548 m_printerCommandText
->SetValue(data
->GetPrinterCommand());
549 if (m_printerOptionsText
&& data
->GetPrinterOptions())
550 m_printerOptionsText
->SetValue(data
->GetPrinterOptions());
551 if (m_colourCheckBox
)
552 m_colourCheckBox
->SetValue(m_printData
.GetColour());
554 if (m_orientationRadioBox
)
556 if (m_printData
.GetOrientation() == wxPORTRAIT
)
557 m_orientationRadioBox
->SetSelection(0);
559 m_orientationRadioBox
->SetSelection(1);
564 bool wxGenericPrintSetupDialog::TransferDataFromWindow()
566 wxPostScriptPrintNativeData
*data
=
567 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
569 if (m_printerCommandText
)
570 data
->SetPrinterCommand(m_printerCommandText
->GetValue());
571 if (m_printerOptionsText
)
572 data
->SetPrinterOptions(m_printerOptionsText
->GetValue());
573 if (m_colourCheckBox
)
574 m_printData
.SetColour(m_colourCheckBox
->GetValue());
575 if (m_orientationRadioBox
)
577 int sel
= m_orientationRadioBox
->GetSelection();
579 m_printData
.SetOrientation(wxPORTRAIT
);
581 m_printData
.SetOrientation(wxLANDSCAPE
);
583 if (m_paperTypeChoice
)
585 int selectedItem
= m_paperTypeChoice
->GetSelection();
586 if (selectedItem
!= -1)
588 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
590 m_printData
.SetPaperId( paper
->GetId());
597 wxComboBox
*wxGenericPrintSetupDialog::CreatePaperTypeChoice()
599 size_t n
= wxThePrintPaperDatabase
->GetCount();
600 wxString
*choices
= new wxString
[n
];
603 for (size_t i
= 0; i
< n
; i
++)
605 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
606 choices
[i
] = paper
->GetName();
607 if (m_printData
.GetPaperId() == paper
->GetId())
613 wxComboBox
*choice
= new wxComboBox( this,
617 wxSize(width
, wxDefaultCoord
),
622 choice
->SetSelection(sel
);
626 #endif // wxUSE_POSTSCRIPT
628 // ----------------------------------------------------------------------------
629 // Generic page setup dialog
630 // ----------------------------------------------------------------------------
632 IMPLEMENT_CLASS(wxGenericPageSetupDialog
, wxDialog
)
634 BEGIN_EVENT_TABLE(wxGenericPageSetupDialog
, wxDialog
)
635 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPageSetupDialog::OnPrinter
)
638 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent
& WXUNUSED(event
))
640 // We no longer query GetPrintMode, so we can eliminate the need
641 // to call SetPrintMode.
642 // This has the limitation that we can't explicitly call the PostScript
643 // print setup dialog from the generic Page Setup dialog under Windows,
644 // but since this choice would only happen when trying to do PostScript
645 // printing under Windows (and only in 16-bit Windows which
646 // doesn't have a Windows-specific page setup dialog) it's worth it.
648 // First save the current settings, so the wxPrintData object is up to date.
649 TransferDataFromWindow();
651 // Transfer the current print settings from this dialog to the page setup dialog.
652 wxPrintDialogData data
;
653 data
= GetPageSetupData().GetPrintData();
654 data
.SetSetupDialog(true);
655 wxPrintDialog
printDialog(this, & data
);
656 printDialog
.ShowModal();
658 // Transfer the page setup print settings from the page dialog to this dialog again, in case
659 // the page setup dialog changed something.
660 GetPageSetupData().GetPrintData() = printDialog
.GetPrintDialogData().GetPrintData();
661 GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData
663 // Now update the dialog in case the page setup dialog changed some of our settings.
664 TransferDataToWindow();
667 wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow
*parent
,
668 wxPageSetupData
* data
)
674 wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
681 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
684 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
685 new wxStaticBox(this,wxPRINTID_STATIC
, _("Paper size")), wxHORIZONTAL
);
687 size_t n
= wxThePrintPaperDatabase
->GetCount();
688 wxString
*choices
= new wxString
[n
];
690 for (size_t i
= 0; i
< n
; i
++)
692 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
693 choices
[i
] = paper
->GetName();
696 m_paperTypeChoice
= new wxComboBox( this,
700 wxSize(300, wxDefaultCoord
),
702 topsizer
->Add( m_paperTypeChoice
, 1, wxEXPAND
|wxALL
, 5 );
703 // m_paperTypeChoice->SetSelection(sel);
705 mainsizer
->Add( topsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
707 // 2) middle sizer with radio box
709 wxString
*choices2
= new wxString
[2];
710 choices2
[0] = _("Portrait");
711 choices2
[1] = _("Landscape");
712 m_orientationRadioBox
= new wxRadioBox(this, wxPRINTID_ORIENTATION
, _("Orientation"),
713 wxDefaultPosition
, wxDefaultSize
, 2, choices2
, 2);
714 m_orientationRadioBox
->SetSelection(0);
716 mainsizer
->Add( m_orientationRadioBox
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 10 );
720 wxBoxSizer
*table
= new wxBoxSizer( wxHORIZONTAL
);
722 wxBoxSizer
*column1
= new wxBoxSizer( wxVERTICAL
);
723 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Left margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
724 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Top margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
725 table
->Add( column1
, 0, wxALL
| wxEXPAND
, 5 );
727 wxBoxSizer
*column2
= new wxBoxSizer( wxVERTICAL
);
728 m_marginLeftText
= new wxTextCtrl(this, wxPRINTID_LEFTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
729 m_marginTopText
= new wxTextCtrl(this, wxPRINTID_TOPMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
730 column2
->Add( m_marginLeftText
, 1, wxALL
, 5 );
731 column2
->Add( m_marginTopText
, 1, wxALL
, 5 );
732 table
->Add( column2
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
734 wxBoxSizer
*column3
= new wxBoxSizer( wxVERTICAL
);
735 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Right margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
736 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Bottom margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
737 table
->Add( column3
, 0, wxALL
| wxEXPAND
, 5 );
739 wxBoxSizer
*column4
= new wxBoxSizer( wxVERTICAL
);
740 m_marginRightText
= new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
741 m_marginBottomText
= new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
742 column4
->Add( m_marginRightText
, 1, wxALL
, 5 );
743 column4
->Add( m_marginBottomText
, 1, wxALL
, 5 );
744 table
->Add( column4
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
746 mainsizer
->Add( table
, 0 );
750 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
755 wxSizer
* buttonsizer
= CreateButtonSizer( wxOK
|wxCANCEL
);
756 m_printerButton
= new wxButton(this, wxPRINTID_SETUP
, _("Printer...") );
757 buttonsizer
->Add( m_printerButton
, 0, wxLEFT
|wxRIGHT
, 10 );
758 if ( !m_pageData
.GetEnablePrinter() )
759 m_printerButton
->Enable(false);
760 // if (m_printData.GetEnableHelp())
761 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight);
762 mainsizer
->Add( buttonsizer
, 0, wxCENTER
|wxALL
, 10 );
765 SetAutoLayout( true );
766 SetSizer( mainsizer
);
768 mainsizer
->Fit( this );
777 wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
781 bool wxGenericPageSetupDialog::TransferDataToWindow()
783 if (m_marginLeftText
)
784 m_marginLeftText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().x
));
786 m_marginTopText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().y
));
787 if (m_marginRightText
)
788 m_marginRightText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().x
));
789 if (m_marginBottomText
)
790 m_marginBottomText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().y
));
792 if (m_orientationRadioBox
)
794 if (m_pageData
.GetPrintData().GetOrientation() == wxPORTRAIT
)
795 m_orientationRadioBox
->SetSelection(0);
797 m_orientationRadioBox
->SetSelection(1);
800 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
801 // failing that, the id in the wxPrintData object.
803 wxPrintPaperType
* type
= wxThePrintPaperDatabase
->FindPaperType(
804 wxSize(m_pageData
.GetPaperSize().x
* 10, m_pageData
.GetPaperSize().y
* 10));
806 if (!type
&& m_pageData
.GetPrintData().GetPaperId() != wxPAPER_NONE
)
807 type
= wxThePrintPaperDatabase
->FindPaperType(m_pageData
.GetPrintData().GetPaperId());
811 m_paperTypeChoice
->SetStringSelection(type
->GetName());
817 bool wxGenericPageSetupDialog::TransferDataFromWindow()
819 if (m_marginLeftText
&& m_marginTopText
)
821 int left
= wxAtoi( m_marginLeftText
->GetValue().c_str() );
822 int top
= wxAtoi( m_marginTopText
->GetValue().c_str() );
823 m_pageData
.SetMarginTopLeft( wxPoint(left
,top
) );
825 if (m_marginRightText
&& m_marginBottomText
)
827 int right
= wxAtoi( m_marginRightText
->GetValue().c_str() );
828 int bottom
= wxAtoi( m_marginBottomText
->GetValue().c_str() );
829 m_pageData
.SetMarginBottomRight( wxPoint(right
,bottom
) );
832 if (m_orientationRadioBox
)
834 int sel
= m_orientationRadioBox
->GetSelection();
837 m_pageData
.GetPrintData().SetOrientation(wxPORTRAIT
);
841 m_pageData
.GetPrintData().SetOrientation(wxLANDSCAPE
);
845 if (m_paperTypeChoice
)
847 int selectedItem
= m_paperTypeChoice
->GetSelection();
848 if (selectedItem
!= -1)
850 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
853 m_pageData
.SetPaperSize(wxSize(paper
->GetWidth()/10, paper
->GetHeight()/10));
854 m_pageData
.GetPrintData().SetPaperId(paper
->GetId());
862 wxComboBox
*wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x
, int *y
)
865 if (!wxThePrintPaperDatabase)
867 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
868 wxThePrintPaperDatabase->CreateDatabase();
872 size_t n
= wxThePrintPaperDatabase
->GetCount();
873 wxString
*choices
= new wxString
[n
];
875 for (size_t i
= 0; i
< n
; i
++)
877 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
878 choices
[i
] = paper
->GetName();
881 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Paper size"), wxPoint(*x
, *y
));
884 wxComboBox
*choice
= new wxComboBox( this,
888 wxSize(300, wxDefaultCoord
),
893 // choice->SetSelection(sel);