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"
64 // For print paper things
65 #include "wx/prntbase.h"
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 extern wxPrintPaperDatabase
*wxThePrintPaperDatabase
;
78 //----------------------------------------------------------------------------
79 // wxPostScriptNativeData
80 //----------------------------------------------------------------------------
82 IMPLEMENT_CLASS(wxPostScriptPrintNativeData
, wxPrintNativeDataBase
)
84 wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
86 m_previewCommand
= wxT("");
88 m_printerCommand
= wxT("print");
89 m_printerOptions
= wxT("/nonotify/queue=psqueue");
90 m_afmPath
= wxT("sys$ps_font_metrics:");
94 m_printerCommand
= wxT("print");
95 m_printerOptions
= wxT("");
96 m_afmPath
= wxT("c:\\windows\\system\\");
99 #if !defined(__VMS__) && !defined(__WXMSW__)
100 m_printerCommand
= wxT("lpr");
101 m_printerOptions
= wxT("");
105 m_printerScaleX
= 1.0;
106 m_printerScaleY
= 1.0;
107 m_printerTranslateX
= 0;
108 m_printerTranslateY
= 0;
109 m_printMode
= wxPRINT_MODE_FILE
;
112 wxPostScriptPrintNativeData::~wxPostScriptPrintNativeData()
116 bool wxPostScriptPrintNativeData::TransferTo( wxPrintData
&data
)
121 bool wxPostScriptPrintNativeData::TransferFrom( const wxPrintData
&data
)
126 // ----------------------------------------------------------------------------
127 // Generic print dialog for non-Windows printing use.
128 // ----------------------------------------------------------------------------
130 IMPLEMENT_CLASS(wxGenericPrintDialog
, wxPrintDialogBase
)
132 BEGIN_EVENT_TABLE(wxGenericPrintDialog
, wxPrintDialogBase
)
133 EVT_BUTTON(wxID_OK
, wxGenericPrintDialog::OnOK
)
134 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPrintDialog::OnSetup
)
135 EVT_RADIOBOX(wxPRINTID_RANGE
, wxGenericPrintDialog::OnRange
)
138 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
,
139 wxPrintDialogData
* data
)
140 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
141 wxPoint(0, 0), wxSize(600, 600),
142 wxDEFAULT_DIALOG_STYLE
|
146 m_printDialogData
= *data
;
151 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
,
153 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
154 wxPoint(0, 0), wxSize(600, 600),
155 wxDEFAULT_DIALOG_STYLE
|
159 m_printDialogData
= *data
;
164 void wxGenericPrintDialog::Init(wxWindow
* WXUNUSED(parent
))
166 // wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0, 0), wxSize(600, 600),
167 // wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL);
169 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
173 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
174 new wxStaticBox( this, wxID_ANY
, _( "Printer options" ) ), wxHORIZONTAL
);
175 m_printToFileCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTTOFILE
, _("Print to File") );
176 topsizer
->Add( m_printToFileCheckBox
, 0, wxCENTER
|wxALL
, 5 );
178 topsizer
->Add( 60,2,1 );
180 m_setupButton
= new wxButton(this, wxPRINTID_SETUP
, _("Setup...") );
181 topsizer
->Add( m_setupButton
, 0, wxCENTER
|wxALL
, 5 );
183 mainsizer
->Add( topsizer
, 0, wxLEFT
|wxTOP
|wxRIGHT
, 10 );
185 // 2) middle row with radio box
187 wxString
*choices
= new wxString
[2];
188 choices
[0] = _("All");
189 choices
[1] = _("Pages");
191 m_fromText
= (wxTextCtrl
*)NULL
;
192 m_toText
= (wxTextCtrl
*)NULL
;
193 m_rangeRadioBox
= (wxRadioBox
*)NULL
;
195 if (m_printDialogData
.GetFromPage() != 0)
197 m_rangeRadioBox
= new wxRadioBox(this, wxPRINTID_RANGE
, _("Print Range"),
198 wxDefaultPosition
, wxDefaultSize
,
201 m_rangeRadioBox
->SetSelection(1);
203 mainsizer
->Add( m_rangeRadioBox
, 0, wxLEFT
|wxTOP
|wxRIGHT
, 10 );
208 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
210 if (m_printDialogData
.GetFromPage() != 0)
212 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("From:") ), 0, wxCENTER
|wxALL
, 5 );
213 m_fromText
= new wxTextCtrl(this, wxPRINTID_FROM
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
214 bottomsizer
->Add( m_fromText
, 1, wxCENTER
|wxRIGHT
, 10 );
216 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("To:") ), 0, wxCENTER
|wxALL
, 5);
217 m_toText
= new wxTextCtrl(this, wxPRINTID_TO
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
218 bottomsizer
->Add( m_toText
, 1, wxCENTER
|wxRIGHT
, 10 );
221 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Copies:") ), 0, wxCENTER
|wxALL
, 5 );
222 m_noCopiesText
= new wxTextCtrl(this, wxPRINTID_COPIES
, wxEmptyString
, wxPoint(252, 130), wxSize(40, wxDefaultCoord
));
223 bottomsizer
->Add( m_noCopiesText
, 1, wxCENTER
|wxRIGHT
, 10 );
225 mainsizer
->Add( bottomsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 12 );
229 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
234 mainsizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxCENTER
|wxALL
, 10 );
236 SetAutoLayout( true );
237 SetSizer( mainsizer
);
239 mainsizer
->Fit( this );
242 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
247 int wxGenericPrintDialog::ShowModal()
249 if ( m_printDialogData
.GetSetupDialog() )
251 // Make sure wxPrintData object reflects the settings now, in case the setup dialog
252 // changes it. In fact there aren't any common settings at
253 // present, but there might be in future.
254 // TransferDataFromWindow();
256 wxGenericPrintSetupDialog
genericPrintSetupDialog( this, &m_printDialogData
.GetPrintData() );
257 int ret
= genericPrintSetupDialog
.ShowModal();
258 if (ret
!= wxID_CANCEL
)
260 // Transfer settings to the print dialog's print data.
261 m_printDialogData
.GetPrintData() = genericPrintSetupDialog
.GetPrintData();
264 // Restore the wxPrintData settings again (uncomment if any settings become
265 // common to both dialogs)
266 // TransferDataToWindow();
272 return wxDialog::ShowModal();
276 wxGenericPrintDialog::~wxGenericPrintDialog()
280 void wxGenericPrintDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
282 TransferDataFromWindow();
284 // An empty 'to' field signals printing just the
286 if (m_printDialogData
.GetToPage() < 1)
287 m_printDialogData
.SetToPage(m_printDialogData
.GetFromPage());
289 wxPostScriptPrintNativeData
*data
=
290 (wxPostScriptPrintNativeData
*) m_printDialogData
.GetPrintData().GetNativeData();
292 // There are some interactions between the global setup data
293 // and the standard print dialog. The global printing 'mode'
294 // is determined by whether the user checks Print to file
296 if (m_printDialogData
.GetPrintToFile())
298 data
->SetPrintMode(wxPRINT_MODE_FILE
);
300 wxFileName
fname( m_printDialogData
.GetPrintData().GetFilename() );
302 wxFileDialog
dialog( this, _("PostScript file"),
303 fname
.GetPath(), fname
.GetFullName(), wxT("*.ps"), wxOPEN
| wxOVERWRITE_PROMPT
);
304 if (dialog
.ShowModal() != wxID_OK
) return;
306 m_printDialogData
.GetPrintData().SetFilename( dialog
.GetPath() );
310 data
->SetPrintMode(wxPRINT_MODE_PRINTER
);
316 void wxGenericPrintDialog::OnRange(wxCommandEvent
& event
)
318 if (!m_fromText
) return;
320 if (event
.GetInt() == 0)
322 m_fromText
->Enable(false);
323 m_toText
->Enable(false);
325 else if (event
.GetInt() == 1)
327 m_fromText
->Enable(true);
328 m_toText
->Enable(true);
332 void wxGenericPrintDialog::OnSetup(wxCommandEvent
& WXUNUSED(event
))
334 wxGenericPrintSetupDialog
dialog( this, &m_printDialogData
.GetPrintData() );
335 if (dialog
.ShowModal() != wxID_CANCEL
)
337 m_printDialogData
= dialog
.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(wxThePrintSetupData->GetPrinterFile(), false, (wxWindow *) NULL);
432 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
435 // ----------------------------------------------------------------------------
436 // Generic print setup dialog
437 // ----------------------------------------------------------------------------
439 IMPLEMENT_CLASS(wxGenericPrintSetupDialog
, wxDialog
)
441 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow
*parent
, wxPrintData
* data
):
442 wxDialog(parent
, wxID_ANY
, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
447 void wxGenericPrintSetupDialog::Init(wxPrintData
* data
)
452 int staticBoxWidth
= 300;
454 (void) new wxStaticBox(this, wxPRINTID_STATIC
, _("Paper size"), wxPoint(10, 10), wxSize(staticBoxWidth
, 60) );
458 m_paperTypeChoice
= CreatePaperTypeChoice(&xPos
, &yPos
);
460 wxString
*choices
= new wxString
[2];
461 choices
[0] = _("Portrait");
462 choices
[1] = _("Landscape");
464 m_orientationRadioBox
= new wxRadioBox(this, wxPRINTID_ORIENTATION
, _("Orientation"),
465 wxPoint(10, 80), wxDefaultSize
, 2, choices
, 1, wxRA_VERTICAL
);
466 m_orientationRadioBox
->SetSelection(0);
468 (void) new wxStaticBox(this, wxPRINTID_STATIC
, _("Options"), wxPoint(10, 130), wxSize(staticBoxWidth
, 50) );
470 int colourYPos
= 145;
476 m_colourCheckBox
= new wxCheckBox(this, wxPRINTID_PRINTCOLOUR
, _("Print in colour"), wxPoint(15, colourYPos
));
478 (void) new wxStaticBox(this, wxPRINTID_STATIC
, _("Print spooling"), wxPoint(330, 10), wxSize(200,170) );
480 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Printer command:"), wxPoint(340, 30));
482 m_printerCommandText
= new wxTextCtrl(this, wxPRINTID_COMMAND
, wxEmptyString
, wxPoint(360, 55), wxSize(150, wxDefaultCoord
));
484 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Printer options:"), wxPoint(340, 110));
486 m_printerOptionsText
= new wxTextCtrl(this, wxPRINTID_OPTIONS
, wxEmptyString
, wxPoint(360, 135), wxSize(150, wxDefaultCoord
));
488 wxButton
*okButton
= new wxButton(this, wxID_OK
, _("OK"), wxPoint(130, 200), wxSize(80, wxDefaultCoord
));
489 (void) new wxButton(this, wxID_CANCEL
, _("Cancel"), wxPoint(320, 200), wxSize(80, wxDefaultCoord
));
491 okButton
->SetDefault();
492 okButton
->SetFocus();
501 wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
505 bool wxGenericPrintSetupDialog::TransferDataToWindow()
507 wxPostScriptPrintNativeData
*data
=
508 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
510 if (m_printerCommandText
&& data
->GetPrinterCommand())
511 m_printerCommandText
->SetValue(data
->GetPrinterCommand());
512 if (m_printerOptionsText
&& data
->GetPrinterOptions())
513 m_printerOptionsText
->SetValue(data
->GetPrinterOptions());
514 if (m_colourCheckBox
)
515 m_colourCheckBox
->SetValue(m_printData
.GetColour());
517 if (m_orientationRadioBox
)
519 if (m_printData
.GetOrientation() == wxPORTRAIT
)
520 m_orientationRadioBox
->SetSelection(0);
522 m_orientationRadioBox
->SetSelection(1);
527 bool wxGenericPrintSetupDialog::TransferDataFromWindow()
529 wxPostScriptPrintNativeData
*data
=
530 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
532 if (m_printerCommandText
)
533 data
->SetPrinterCommand(m_printerCommandText
->GetValue());
534 if (m_printerOptionsText
)
535 data
->SetPrinterOptions(m_printerOptionsText
->GetValue());
536 if (m_colourCheckBox
)
537 m_printData
.SetColour(m_colourCheckBox
->GetValue());
538 if (m_orientationRadioBox
)
540 int sel
= m_orientationRadioBox
->GetSelection();
542 m_printData
.SetOrientation(wxPORTRAIT
);
544 m_printData
.SetOrientation(wxLANDSCAPE
);
546 if (m_paperTypeChoice
)
548 int selectedItem
= m_paperTypeChoice
->GetSelection();
549 if (selectedItem
!= -1)
551 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
553 m_printData
.SetPaperId( paper
->GetId());
560 wxComboBox
*wxGenericPrintSetupDialog::CreatePaperTypeChoice(int *x
, int *y
)
562 /* Should not be necessary
563 if (!wxThePrintPaperDatabase)
565 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
566 wxThePrintPaperDatabase->CreateDatabase();
569 size_t n
= wxThePrintPaperDatabase
->GetCount();
570 wxString
*choices
= new wxString
[n
];
573 for (size_t i
= 0; i
< n
; i
++)
575 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
576 choices
[i
] = paper
->GetName();
577 if (m_printData
.GetPaperId() == paper
->GetId())
583 wxComboBox
*choice
= new wxComboBox( this,
587 wxSize(width
, wxDefaultCoord
),
590 // SetFont(thisFont);
594 choice
->SetSelection(sel
);
597 #endif // wxUSE_POSTSCRIPT
599 // ----------------------------------------------------------------------------
600 // Generic page setup dialog
601 // ----------------------------------------------------------------------------
603 IMPLEMENT_CLASS(wxGenericPageSetupDialog
, wxDialog
)
605 BEGIN_EVENT_TABLE(wxGenericPageSetupDialog
, wxDialog
)
606 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPageSetupDialog::OnPrinter
)
609 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent
& WXUNUSED(event
))
611 // We no longer query GetPrintMode, so we can eliminate the need
612 // to call SetPrintMode.
613 // This has the limitation that we can't explicitly call the PostScript
614 // print setup dialog from the generic Page Setup dialog under Windows,
615 // but since this choice would only happen when trying to do PostScript
616 // printing under Windows (and only in 16-bit Windows which
617 // doesn't have a Windows-specific page setup dialog) it's worth it.
619 // First save the current settings, so the wxPrintData object is up to date.
620 TransferDataFromWindow();
622 // Transfer the current print settings from this dialog to the page setup dialog.
623 wxPrintDialogData data
;
624 data
= GetPageSetupData().GetPrintData();
625 data
.SetSetupDialog(true);
626 wxPrintDialog
printDialog(this, & data
);
627 printDialog
.ShowModal();
629 // Transfer the page setup print settings from the page dialog to this dialog again, in case
630 // the page setup dialog changed something.
631 GetPageSetupData().GetPrintData() = printDialog
.GetPrintDialogData().GetPrintData();
632 GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData
634 // Now update the dialog in case the page setup dialog changed some of our settings.
635 TransferDataToWindow();
638 wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow
*parent
,
639 wxPageSetupData
* data
)
645 wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
652 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
655 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
656 new wxStaticBox(this,wxPRINTID_STATIC
, _("Paper size")), wxHORIZONTAL
);
658 size_t n
= wxThePrintPaperDatabase
->GetCount();
659 wxString
*choices
= new wxString
[n
];
661 for (size_t i
= 0; i
< n
; i
++)
663 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
664 choices
[i
] = paper
->GetName();
667 m_paperTypeChoice
= new wxComboBox( this,
671 wxSize(300, wxDefaultCoord
),
673 topsizer
->Add( m_paperTypeChoice
, 1, wxEXPAND
|wxALL
, 5 );
674 // m_paperTypeChoice->SetSelection(sel);
676 mainsizer
->Add( topsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
678 // 2) middle sizer with radio box
680 wxString
*choices2
= new wxString
[2];
681 choices2
[0] = _("Portrait");
682 choices2
[1] = _("Landscape");
683 m_orientationRadioBox
= new wxRadioBox(this, wxPRINTID_ORIENTATION
, _("Orientation"),
684 wxDefaultPosition
, wxDefaultSize
, 2, choices2
, 2);
685 m_orientationRadioBox
->SetSelection(0);
687 mainsizer
->Add( m_orientationRadioBox
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 10 );
691 wxBoxSizer
*table
= new wxBoxSizer( wxHORIZONTAL
);
693 wxBoxSizer
*column1
= new wxBoxSizer( wxVERTICAL
);
694 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Left margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
695 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Top margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
696 table
->Add( column1
, 0, wxALL
| wxEXPAND
, 5 );
698 wxBoxSizer
*column2
= new wxBoxSizer( wxVERTICAL
);
699 m_marginLeftText
= new wxTextCtrl(this, wxPRINTID_LEFTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
700 m_marginTopText
= new wxTextCtrl(this, wxPRINTID_TOPMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
701 column2
->Add( m_marginLeftText
, 1, wxALL
, 5 );
702 column2
->Add( m_marginTopText
, 1, wxALL
, 5 );
703 table
->Add( column2
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
705 wxBoxSizer
*column3
= new wxBoxSizer( wxVERTICAL
);
706 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Right margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
707 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Bottom margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
708 table
->Add( column3
, 0, wxALL
| wxEXPAND
, 5 );
710 wxBoxSizer
*column4
= new wxBoxSizer( wxVERTICAL
);
711 m_marginRightText
= new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
712 m_marginBottomText
= new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
713 column4
->Add( m_marginRightText
, 1, wxALL
, 5 );
714 column4
->Add( m_marginBottomText
, 1, wxALL
, 5 );
715 table
->Add( column4
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
717 mainsizer
->Add( table
, 0 );
721 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
726 wxSizer
* buttonsizer
= CreateButtonSizer( wxOK
|wxCANCEL
);
727 m_printerButton
= new wxButton(this, wxPRINTID_SETUP
, _("Printer...") );
728 buttonsizer
->Add( m_printerButton
, 0, wxLEFT
|wxRIGHT
, 10 );
729 if ( !m_pageData
.GetEnablePrinter() )
730 m_printerButton
->Enable(false);
731 // if (m_printData.GetEnableHelp())
732 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight);
733 mainsizer
->Add( buttonsizer
, 0, wxCENTER
|wxALL
, 10 );
736 SetAutoLayout( true );
737 SetSizer( mainsizer
);
739 mainsizer
->Fit( this );
748 wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
752 bool wxGenericPageSetupDialog::TransferDataToWindow()
754 if (m_marginLeftText
)
755 m_marginLeftText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().x
));
757 m_marginTopText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().y
));
758 if (m_marginRightText
)
759 m_marginRightText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().x
));
760 if (m_marginBottomText
)
761 m_marginBottomText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().y
));
763 if (m_orientationRadioBox
)
765 if (m_pageData
.GetPrintData().GetOrientation() == wxPORTRAIT
)
766 m_orientationRadioBox
->SetSelection(0);
768 m_orientationRadioBox
->SetSelection(1);
771 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
772 // failing that, the id in the wxPrintData object.
774 wxPrintPaperType
* type
= wxThePrintPaperDatabase
->FindPaperType(
775 wxSize(m_pageData
.GetPaperSize().x
* 10, m_pageData
.GetPaperSize().y
* 10));
777 if (!type
&& m_pageData
.GetPrintData().GetPaperId() != wxPAPER_NONE
)
778 type
= wxThePrintPaperDatabase
->FindPaperType(m_pageData
.GetPrintData().GetPaperId());
782 m_paperTypeChoice
->SetStringSelection(type
->GetName());
788 bool wxGenericPageSetupDialog::TransferDataFromWindow()
790 if (m_marginLeftText
&& m_marginTopText
)
792 int left
= wxAtoi( m_marginLeftText
->GetValue().c_str() );
793 int top
= wxAtoi( m_marginTopText
->GetValue().c_str() );
794 m_pageData
.SetMarginTopLeft( wxPoint(left
,top
) );
796 if (m_marginRightText
&& m_marginBottomText
)
798 int right
= wxAtoi( m_marginRightText
->GetValue().c_str() );
799 int bottom
= wxAtoi( m_marginBottomText
->GetValue().c_str() );
800 m_pageData
.SetMarginBottomRight( wxPoint(right
,bottom
) );
803 if (m_orientationRadioBox
)
805 int sel
= m_orientationRadioBox
->GetSelection();
808 m_pageData
.GetPrintData().SetOrientation(wxPORTRAIT
);
812 m_pageData
.GetPrintData().SetOrientation(wxLANDSCAPE
);
816 if (m_paperTypeChoice
)
818 int selectedItem
= m_paperTypeChoice
->GetSelection();
819 if (selectedItem
!= -1)
821 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
824 m_pageData
.SetPaperSize(wxSize(paper
->GetWidth()/10, paper
->GetHeight()/10));
825 m_pageData
.GetPrintData().SetPaperId(paper
->GetId());
833 wxComboBox
*wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x
, int *y
)
836 if (!wxThePrintPaperDatabase)
838 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
839 wxThePrintPaperDatabase->CreateDatabase();
843 size_t n
= wxThePrintPaperDatabase
->GetCount();
844 wxString
*choices
= new wxString
[n
];
846 for (size_t i
= 0; i
< n
; i
++)
848 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
849 choices
[i
] = paper
->GetName();
852 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Paper size"), wxPoint(*x
, *y
));
855 wxComboBox
*choice
= new wxComboBox( this,
859 wxSize(300, wxDefaultCoord
),
864 // choice->SetSelection(sel);