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"
63 #include "wx/tokenzr.h"
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 extern wxPrintPaperDatabase
*wxThePrintPaperDatabase
;
76 //----------------------------------------------------------------------------
77 // wxPostScriptNativeData
78 //----------------------------------------------------------------------------
80 IMPLEMENT_CLASS(wxPostScriptPrintNativeData
, wxPrintNativeDataBase
)
82 wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
84 m_previewCommand
= wxT("");
86 m_printerCommand
= wxT("print");
87 m_printerOptions
= wxT("/nonotify/queue=psqueue");
88 m_afmPath
= wxT("sys$ps_font_metrics:");
92 m_printerCommand
= wxT("print");
93 m_printerOptions
= wxT("");
94 m_afmPath
= wxT("c:\\windows\\system\\");
97 #if !defined(__VMS__) && !defined(__WXMSW__)
98 m_printerCommand
= wxT("lpr");
99 m_printerOptions
= wxT("");
103 m_printerScaleX
= 1.0;
104 m_printerScaleY
= 1.0;
105 m_printerTranslateX
= 0;
106 m_printerTranslateY
= 0;
109 wxPostScriptPrintNativeData::~wxPostScriptPrintNativeData()
113 bool wxPostScriptPrintNativeData::TransferTo( wxPrintData
&data
)
118 bool wxPostScriptPrintNativeData::TransferFrom( const wxPrintData
&data
)
123 // ----------------------------------------------------------------------------
124 // Generic print dialog for non-Windows printing use.
125 // ----------------------------------------------------------------------------
127 IMPLEMENT_CLASS(wxGenericPrintDialog
, wxPrintDialogBase
)
129 BEGIN_EVENT_TABLE(wxGenericPrintDialog
, wxPrintDialogBase
)
130 EVT_BUTTON(wxID_OK
, wxGenericPrintDialog::OnOK
)
131 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPrintDialog::OnSetup
)
132 EVT_RADIOBOX(wxPRINTID_RANGE
, wxGenericPrintDialog::OnRange
)
135 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
,
136 wxPrintDialogData
* data
)
137 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
138 wxPoint(0, 0), wxSize(600, 600),
139 wxDEFAULT_DIALOG_STYLE
|
143 m_printDialogData
= *data
;
148 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
,
150 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
151 wxPoint(0, 0), wxSize(600, 600),
152 wxDEFAULT_DIALOG_STYLE
|
156 m_printDialogData
= *data
;
161 void wxGenericPrintDialog::Init(wxWindow
* WXUNUSED(parent
))
163 // wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0, 0), wxSize(600, 600),
164 // wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL);
166 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
170 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
172 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
173 new wxStaticBox( this, wxID_ANY
, _( "Printer options" ) ), wxHORIZONTAL
);
174 wxFlexGridSizer
*flex
= new wxFlexGridSizer( 2 );
175 flex
->AddGrowableCol( 1 );
176 topsizer
->Add( flex
, 1, wxGROW
);
178 m_printToFileCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTTOFILE
, _("Print to File") );
179 flex
->Add( m_printToFileCheckBox
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
181 m_setupButton
= new wxButton(this, wxPRINTID_SETUP
, _("Setup...") );
182 flex
->Add( m_setupButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALIGN_RIGHT
|wxALL
, 5 );
184 if (!factory
->HasPrintSetupDialog())
185 m_setupButton
->Enable( false );
187 if (factory
->HasPrinterLine())
189 flex
->Add( new wxStaticText( this, -1, _("Printer:") ),
190 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
191 flex
->Add( new wxStaticText( this, -1, factory
->CreatePrinterLine() ),
192 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
195 if (factory
->HasStatusLine())
197 flex
->Add( new wxStaticText( this, -1, _("Status:") ),
198 0, wxALIGN_CENTER_VERTICAL
|wxALL
-wxTOP
, 5 );
199 flex
->Add( new wxStaticText( this, -1, factory
->CreateStatusLine() ),
200 0, wxALIGN_CENTER_VERTICAL
|wxALL
-wxTOP
, 5 );
203 mainsizer
->Add( topsizer
, 0, wxLEFT
|wxTOP
|wxRIGHT
|wxGROW
, 10 );
205 // 2) middle row with radio box
207 wxString
*choices
= new wxString
[2];
208 choices
[0] = _("All");
209 choices
[1] = _("Pages");
211 m_fromText
= (wxTextCtrl
*)NULL
;
212 m_toText
= (wxTextCtrl
*)NULL
;
213 m_rangeRadioBox
= (wxRadioBox
*)NULL
;
215 if (m_printDialogData
.GetFromPage() != 0)
217 m_rangeRadioBox
= new wxRadioBox(this, wxPRINTID_RANGE
, _("Print Range"),
218 wxDefaultPosition
, wxDefaultSize
,
221 m_rangeRadioBox
->SetSelection(1);
223 mainsizer
->Add( m_rangeRadioBox
, 0, wxLEFT
|wxTOP
|wxRIGHT
, 10 );
228 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
230 if (m_printDialogData
.GetFromPage() != 0)
232 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("From:") ), 0, wxCENTER
|wxALL
, 5 );
233 m_fromText
= new wxTextCtrl(this, wxPRINTID_FROM
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
234 bottomsizer
->Add( m_fromText
, 1, wxCENTER
|wxRIGHT
, 10 );
236 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("To:") ), 0, wxCENTER
|wxALL
, 5);
237 m_toText
= new wxTextCtrl(this, wxPRINTID_TO
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
238 bottomsizer
->Add( m_toText
, 1, wxCENTER
|wxRIGHT
, 10 );
241 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Copies:") ), 0, wxCENTER
|wxALL
, 5 );
242 m_noCopiesText
= new wxTextCtrl(this, wxPRINTID_COPIES
, wxEmptyString
, wxPoint(252, 130), wxSize(40, wxDefaultCoord
));
243 bottomsizer
->Add( m_noCopiesText
, 1, wxCENTER
|wxRIGHT
, 10 );
245 mainsizer
->Add( bottomsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 12 );
249 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
254 mainsizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxCENTER
|wxALL
, 10 );
256 SetAutoLayout( true );
257 SetSizer( mainsizer
);
259 mainsizer
->Fit( this );
262 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
267 int wxGenericPrintDialog::ShowModal()
269 return wxDialog::ShowModal();
272 wxGenericPrintDialog::~wxGenericPrintDialog()
276 void wxGenericPrintDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
278 TransferDataFromWindow();
280 // An empty 'to' field signals printing just the
282 if (m_printDialogData
.GetToPage() < 1)
283 m_printDialogData
.SetToPage(m_printDialogData
.GetFromPage());
285 // There are some interactions between the global setup data
286 // and the standard print dialog. The global printing 'mode'
287 // is determined by whether the user checks Print to file
289 if (m_printDialogData
.GetPrintToFile())
291 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE
);
293 wxFileName
fname( m_printDialogData
.GetPrintData().GetFilename() );
295 wxFileDialog
dialog( this, _("PostScript file"),
296 fname
.GetPath(), fname
.GetFullName(), wxT("*.ps"), wxOPEN
| wxOVERWRITE_PROMPT
);
297 if (dialog
.ShowModal() != wxID_OK
) return;
299 m_printDialogData
.GetPrintData().SetFilename( dialog
.GetPath() );
303 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER
);
309 void wxGenericPrintDialog::OnRange(wxCommandEvent
& event
)
311 if (!m_fromText
) return;
313 if (event
.GetInt() == 0)
315 m_fromText
->Enable(false);
316 m_toText
->Enable(false);
318 else if (event
.GetInt() == 1)
320 m_fromText
->Enable(true);
321 m_toText
->Enable(true);
325 void wxGenericPrintDialog::OnSetup(wxCommandEvent
& WXUNUSED(event
))
327 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
329 if (factory
->HasPrintSetupDialog())
331 // The print setup dialog should change the
332 // print data in-place if not cancelled.
333 wxDialog
*dialog
= factory
->CreatePrintSetupDialog( this, &m_printDialogData
.GetPrintData() );
339 bool wxGenericPrintDialog::TransferDataToWindow()
341 if(m_printDialogData
.GetFromPage() != 0)
345 if (m_printDialogData
.GetEnablePageNumbers())
347 m_fromText
->Enable(true);
348 m_toText
->Enable(true);
349 if (m_printDialogData
.GetFromPage() > 0)
350 m_fromText
->SetValue(wxString::Format(_T("%d"), m_printDialogData
.GetFromPage()));
351 if (m_printDialogData
.GetToPage() > 0)
352 m_toText
->SetValue(wxString::Format(_T("%d"), m_printDialogData
.GetToPage()));
354 if (m_printDialogData
.GetAllPages() || m_printDialogData
.GetFromPage() == 0)
355 m_rangeRadioBox
->SetSelection(0);
357 m_rangeRadioBox
->SetSelection(1);
361 m_fromText
->Enable(false);
362 m_toText
->Enable(false);
365 m_rangeRadioBox
->SetSelection(0);
366 m_rangeRadioBox
->wxRadioBox::Enable(1, false);
371 m_noCopiesText
->SetValue(
372 wxString::Format(_T("%d"), m_printDialogData
.GetNoCopies()));
374 m_printToFileCheckBox
->SetValue(m_printDialogData
.GetPrintToFile());
375 m_printToFileCheckBox
->Enable(m_printDialogData
.GetEnablePrintToFile());
379 bool wxGenericPrintDialog::TransferDataFromWindow()
382 if(m_printDialogData
.GetFromPage() != -1)
384 if (m_printDialogData
.GetEnablePageNumbers())
388 wxString value
= m_fromText
->GetValue();
389 if (value
.ToLong( &res
))
390 m_printDialogData
.SetFromPage( res
);
394 wxString value
= m_toText
->GetValue();
395 if (value
.ToLong( &res
))
396 m_printDialogData
.SetToPage( res
);
401 if (m_rangeRadioBox
->GetSelection() == 0)
403 m_printDialogData
.SetAllPages(true);
405 // This means all pages, more or less
406 m_printDialogData
.SetFromPage(1);
407 m_printDialogData
.SetToPage(32000);
410 m_printDialogData
.SetAllPages(false);
414 { // continuous printing
415 m_printDialogData
.SetFromPage(1);
416 m_printDialogData
.SetToPage(32000);
419 wxString value
= m_noCopiesText
->GetValue();
420 if (value
.ToLong( &res
))
421 m_printDialogData
.SetNoCopies( res
);
423 m_printDialogData
.SetPrintToFile(m_printToFileCheckBox
->GetValue());
428 wxDC
*wxGenericPrintDialog::GetPrintDC()
430 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
433 // ----------------------------------------------------------------------------
434 // Generic print setup dialog
435 // ----------------------------------------------------------------------------
437 IMPLEMENT_CLASS(wxGenericPrintSetupDialog
, wxDialog
)
439 BEGIN_EVENT_TABLE(wxGenericPrintSetupDialog
, wxDialog
)
440 EVT_LIST_ITEM_ACTIVATED(wxPRINTID_PRINTER
, wxGenericPrintSetupDialog::OnPrinter
)
443 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow
*parent
, wxPrintData
* data
):
444 wxDialog(parent
, wxID_ANY
, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
450 static char * check_xpm
[] = {
451 /* width height ncolors chars_per_pixel */
477 void wxGenericPrintSetupDialog::Init(wxPrintData
* data
)
484 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
488 wxStaticBoxSizer
*printer_sizer
= new wxStaticBoxSizer( new wxStaticBox( this, -1, _("Printer") ), wxVERTICAL
);
489 main_sizer
->Add( printer_sizer
, 0, wxALL
|wxGROW
, 10 );
491 m_printerListCtrl
= new wxListCtrl( this, wxPRINTID_PRINTER
,
492 wxDefaultPosition
, wxSize(-1,100), wxLC_REPORT
|wxLC_SINGLE_SEL
|wxSUNKEN_BORDER
);
493 wxImageList
*image_list
= new wxImageList
;
494 image_list
->Add( wxBitmap(check_xpm
) );
495 m_printerListCtrl
->AssignImageList( image_list
, wxIMAGE_LIST_SMALL
);
497 m_printerListCtrl
->InsertColumn( 0, wxT(" "), wxLIST_FORMAT_LEFT
, 20 );
498 m_printerListCtrl
->InsertColumn( 1, wxT("Printer"), wxLIST_FORMAT_LEFT
, 150 );
499 m_printerListCtrl
->InsertColumn( 2, wxT("Device"), wxLIST_FORMAT_LEFT
, 150 );
500 m_printerListCtrl
->InsertColumn( 3, wxT("Status"), wxLIST_FORMAT_LEFT
, 80 );
503 item
.SetMask( wxLIST_MASK_TEXT
);
505 item
.SetText( _("Default printer") );
506 item
.SetId( m_printerListCtrl
->InsertItem( item
) );
508 if (data
->GetPrinterName().IsEmpty())
511 item2
.SetId( item
.GetId() );
512 item2
.SetMask( wxLIST_MASK_IMAGE
);
514 m_printerListCtrl
->SetItem( item2
);
517 item
.SetId( 1+ item
.GetId() );
519 wxArrayString errors
;
520 wxArrayString output
;
521 long res
= wxExecute( wxT("lpstat -v"), output
, errors
);
522 if (res
>= 0 && errors
.GetCount() == 0)
525 for (i
= 0; i
< output
.GetCount(); i
++)
527 wxStringTokenizer
tok( output
[i
], wxT(" ") );
528 wxString tmp
= tok
.GetNextToken(); // "device"
529 if (tmp
!= wxT("device"))
530 break; // the lpstat syntax must have changed.
531 tmp
= tok
.GetNextToken(); // "for"
532 if (tmp
!= wxT("for"))
533 break; // the lpstat syntax must have changed.
534 tmp
= tok
.GetNextToken(); // "hp_deskjet930c:"
535 if (tmp
[tmp
.Len()-1] == wxT(':'))
536 tmp
.Remove(tmp
.Len()-1,1);
538 item
.SetText( name
);
539 item
.SetId( m_printerListCtrl
->InsertItem( item
) );
540 tmp
= tok
.GetNextToken(); // "parallel:/dev/lp0"
543 m_printerListCtrl
->SetItem( item
);
544 if (data
->GetPrinterName() == name
)
547 item2
.SetId( item
.GetId() );
548 item2
.SetMask( wxLIST_MASK_IMAGE
);
550 m_printerListCtrl
->SetItem( item2
);
553 wxString command
= wxT("lpstat -p ");
555 wxArrayString errors2
;
556 wxArrayString output2
;
557 res
= wxExecute( command
, output2
, errors2
);
558 if (res
>= 0 && errors2
.GetCount() == 0 && output2
.GetCount() > 0)
560 tmp
= output2
[0]; // "printer hp_deskjet930c is idle. enable since ..."
561 int pos
= tmp
.Find( wxT('.') );
563 tmp
.Remove( (size_t)pos
, tmp
.Len()-(size_t)pos
);
564 wxStringTokenizer
tok2( tmp
, wxT(" ") );
565 tmp
= tok2
.GetNextToken(); // "printer"
566 tmp
= tok2
.GetNextToken(); // "hp_deskjet930c"
568 while (tok2
.HasMoreTokens())
570 tmp
+= tok2
.GetNextToken();
575 m_printerListCtrl
->SetItem( item
);
579 item
.SetId( 1+ item
.GetId() );
584 printer_sizer
->Add( m_printerListCtrl
, 0, wxALL
|wxGROW
, 5 );
586 wxBoxSizer
*item1
= new wxBoxSizer( wxHORIZONTAL
);
587 main_sizer
->Add( item1
, 0, wxALL
, 5 );
589 // printer options (on the left)
591 wxBoxSizer
*item2
= new wxBoxSizer( wxVERTICAL
);
593 wxStaticBox
*item4
= new wxStaticBox( this, wxPRINTID_STATIC
, _("Paper size") );
594 wxStaticBoxSizer
*item3
= new wxStaticBoxSizer( item4
, wxVERTICAL
);
596 m_paperTypeChoice
= CreatePaperTypeChoice();
597 item3
->Add( m_paperTypeChoice
, 0, wxALIGN_CENTER
|wxALL
, 5 );
599 item2
->Add( item3
, 0, wxALIGN_CENTER
|wxALL
, 5 );
606 m_orientationRadioBox
= new wxRadioBox( this, wxPRINTID_ORIENTATION
, _("Orientation"), wxDefaultPosition
, wxDefaultSize
, 2, strs6
, 1, wxRA_SPECIFY_ROWS
);
607 item2
->Add( m_orientationRadioBox
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
609 wxStaticBox
*item8
= new wxStaticBox( this, -1, _("Options") );
610 wxStaticBoxSizer
*item7
= new wxStaticBoxSizer( item8
, wxHORIZONTAL
);
612 m_colourCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTCOLOUR
, _("Print in colour") );
613 item7
->Add( m_colourCheckBox
, 0, wxALIGN_CENTER
|wxALL
, 5 );
615 item2
->Add( item7
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
617 item1
->Add( item2
, 0, wxALIGN_CENTER_HORIZONTAL
, 5 );
619 // spooling options (on the right)
621 wxStaticBox
*item11
= new wxStaticBox( this, -1, _("Print spooling") );
622 wxStaticBoxSizer
*item10
= new wxStaticBoxSizer( item11
, wxVERTICAL
);
624 wxStaticText
*item12
= new wxStaticText( this, -1, _("Printer command:") );
625 item10
->Add( item12
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
627 wxBoxSizer
*item13
= new wxBoxSizer( wxHORIZONTAL
);
629 item13
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
631 m_printerCommandText
= new wxTextCtrl( this, wxPRINTID_COMMAND
, wxT(""), wxDefaultPosition
, wxSize(160,-1) );
632 item13
->Add( m_printerCommandText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
634 item10
->Add( item13
, 0, wxALIGN_CENTER
|wxALL
, 0 );
636 wxStaticText
*item15
= new wxStaticText( this, -1, _("Printer options:") );
637 item10
->Add( item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
639 wxBoxSizer
*item16
= new wxBoxSizer( wxHORIZONTAL
);
641 item16
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
643 m_printerOptionsText
= new wxTextCtrl( this, wxPRINTID_OPTIONS
, wxT(""), wxDefaultPosition
, wxSize(160,-1) );
644 item16
->Add( m_printerOptionsText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
646 item10
->Add( item16
, 0, wxALIGN_CENTER
|wxALL
, 0 );
648 item1
->Add( item10
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5 );
653 main_sizer
->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
658 main_sizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxCENTER
|wxALL
, 10 );
660 SetAutoLayout( true );
661 SetSizer( main_sizer
);
663 main_sizer
->Fit( this );
673 wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
677 void wxGenericPrintSetupDialog::OnPrinter(wxListEvent
& event
)
681 for (item
= 0; item
< m_printerListCtrl
->GetItemCount(); item
++)
682 m_printerListCtrl
->SetItemImage( item
, -1 );
684 m_printerListCtrl
->SetItemImage( event
.GetIndex(), 0 );
686 if (event
.GetIndex() == 0)
688 m_printerCommandText
->SetValue( wxT("lpr") );
692 wxString tmp
= wxT("lpr -P");
695 item
.SetMask( wxLIST_MASK_TEXT
);
696 item
.SetId( event
.GetIndex() );
697 m_printerListCtrl
->GetItem( item
);
698 tmp
+= item
.GetText();
699 m_printerCommandText
->SetValue( tmp
);
703 bool wxGenericPrintSetupDialog::TransferDataToWindow()
705 wxPostScriptPrintNativeData
*data
=
706 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
708 if (m_printerCommandText
&& data
->GetPrinterCommand())
709 m_printerCommandText
->SetValue(data
->GetPrinterCommand());
710 if (m_printerOptionsText
&& data
->GetPrinterOptions())
711 m_printerOptionsText
->SetValue(data
->GetPrinterOptions());
712 if (m_colourCheckBox
)
713 m_colourCheckBox
->SetValue(m_printData
.GetColour());
715 if (m_orientationRadioBox
)
717 if (m_printData
.GetOrientation() == wxPORTRAIT
)
718 m_orientationRadioBox
->SetSelection(0);
720 m_orientationRadioBox
->SetSelection(1);
725 bool wxGenericPrintSetupDialog::TransferDataFromWindow()
727 wxPostScriptPrintNativeData
*data
=
728 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
730 // find selected printer
731 long id
= m_printerListCtrl
->GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
734 m_printData
.SetPrinterName( wxT("") );
740 item
.SetMask( wxLIST_MASK_TEXT
);
742 m_printerListCtrl
->GetItem( item
);
743 m_printData
.SetPrinterName( item
.GetText() );
746 if (m_printerCommandText
)
747 data
->SetPrinterCommand(m_printerCommandText
->GetValue());
748 if (m_printerOptionsText
)
749 data
->SetPrinterOptions(m_printerOptionsText
->GetValue());
750 if (m_colourCheckBox
)
751 m_printData
.SetColour(m_colourCheckBox
->GetValue());
752 if (m_orientationRadioBox
)
754 int sel
= m_orientationRadioBox
->GetSelection();
756 m_printData
.SetOrientation(wxPORTRAIT
);
758 m_printData
.SetOrientation(wxLANDSCAPE
);
760 if (m_paperTypeChoice
)
762 int selectedItem
= m_paperTypeChoice
->GetSelection();
763 if (selectedItem
!= -1)
765 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
767 m_printData
.SetPaperId( paper
->GetId());
772 *m_targetData
= m_printData
;
777 wxComboBox
*wxGenericPrintSetupDialog::CreatePaperTypeChoice()
779 size_t n
= wxThePrintPaperDatabase
->GetCount();
780 wxString
*choices
= new wxString
[n
];
783 for (size_t i
= 0; i
< n
; i
++)
785 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
786 choices
[i
] = paper
->GetName();
787 if (m_printData
.GetPaperId() == paper
->GetId())
793 wxComboBox
*choice
= new wxComboBox( this,
797 wxSize(width
, wxDefaultCoord
),
802 choice
->SetSelection(sel
);
806 #endif // wxUSE_POSTSCRIPT
808 // ----------------------------------------------------------------------------
809 // Generic page setup dialog
810 // ----------------------------------------------------------------------------
812 IMPLEMENT_CLASS(wxGenericPageSetupDialog
, wxDialog
)
814 BEGIN_EVENT_TABLE(wxGenericPageSetupDialog
, wxDialog
)
815 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPageSetupDialog::OnPrinter
)
818 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent
& WXUNUSED(event
))
820 // We no longer query GetPrintMode, so we can eliminate the need
821 // to call SetPrintMode.
822 // This has the limitation that we can't explicitly call the PostScript
823 // print setup dialog from the generic Page Setup dialog under Windows,
824 // but since this choice would only happen when trying to do PostScript
825 // printing under Windows (and only in 16-bit Windows which
826 // doesn't have a Windows-specific page setup dialog) it's worth it.
828 // First save the current settings, so the wxPrintData object is up to date.
829 TransferDataFromWindow();
831 // Transfer the current print settings from this dialog to the page setup dialog.
832 wxPrintDialogData data
;
833 data
= GetPageSetupData().GetPrintData();
834 data
.SetSetupDialog(true);
835 wxPrintDialog
printDialog(this, & data
);
836 printDialog
.ShowModal();
838 // Transfer the page setup print settings from the page dialog to this dialog again, in case
839 // the page setup dialog changed something.
840 GetPageSetupData().GetPrintData() = printDialog
.GetPrintDialogData().GetPrintData();
841 GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData
843 // Now update the dialog in case the page setup dialog changed some of our settings.
844 TransferDataToWindow();
847 wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow
*parent
,
848 wxPageSetupData
* data
)
854 wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
861 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
864 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
865 new wxStaticBox(this,wxPRINTID_STATIC
, _("Paper size")), wxHORIZONTAL
);
867 size_t n
= wxThePrintPaperDatabase
->GetCount();
868 wxString
*choices
= new wxString
[n
];
870 for (size_t i
= 0; i
< n
; i
++)
872 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
873 choices
[i
] = paper
->GetName();
876 m_paperTypeChoice
= new wxComboBox( this,
880 wxSize(300, wxDefaultCoord
),
882 topsizer
->Add( m_paperTypeChoice
, 1, wxEXPAND
|wxALL
, 5 );
883 // m_paperTypeChoice->SetSelection(sel);
885 mainsizer
->Add( topsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
887 // 2) middle sizer with radio box
889 wxString
*choices2
= new wxString
[2];
890 choices2
[0] = _("Portrait");
891 choices2
[1] = _("Landscape");
892 m_orientationRadioBox
= new wxRadioBox(this, wxPRINTID_ORIENTATION
, _("Orientation"),
893 wxDefaultPosition
, wxDefaultSize
, 2, choices2
, 2);
894 m_orientationRadioBox
->SetSelection(0);
896 mainsizer
->Add( m_orientationRadioBox
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 10 );
900 wxBoxSizer
*table
= new wxBoxSizer( wxHORIZONTAL
);
902 wxBoxSizer
*column1
= new wxBoxSizer( wxVERTICAL
);
903 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Left margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
904 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Top margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
905 table
->Add( column1
, 0, wxALL
| wxEXPAND
, 5 );
907 wxBoxSizer
*column2
= new wxBoxSizer( wxVERTICAL
);
908 m_marginLeftText
= new wxTextCtrl(this, wxPRINTID_LEFTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
909 m_marginTopText
= new wxTextCtrl(this, wxPRINTID_TOPMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
910 column2
->Add( m_marginLeftText
, 1, wxALL
, 5 );
911 column2
->Add( m_marginTopText
, 1, wxALL
, 5 );
912 table
->Add( column2
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
914 wxBoxSizer
*column3
= new wxBoxSizer( wxVERTICAL
);
915 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Right margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
916 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Bottom margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
917 table
->Add( column3
, 0, wxALL
| wxEXPAND
, 5 );
919 wxBoxSizer
*column4
= new wxBoxSizer( wxVERTICAL
);
920 m_marginRightText
= new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
921 m_marginBottomText
= new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
922 column4
->Add( m_marginRightText
, 1, wxALL
, 5 );
923 column4
->Add( m_marginBottomText
, 1, wxALL
, 5 );
924 table
->Add( column4
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
926 mainsizer
->Add( table
, 0 );
930 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
935 wxSizer
* buttonsizer
= CreateButtonSizer( wxOK
|wxCANCEL
);
936 m_printerButton
= new wxButton(this, wxPRINTID_SETUP
, _("Printer...") );
937 buttonsizer
->Add( m_printerButton
, 0, wxLEFT
|wxRIGHT
, 10 );
938 if ( !m_pageData
.GetEnablePrinter() )
939 m_printerButton
->Enable(false);
940 // if (m_printData.GetEnableHelp())
941 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight);
942 mainsizer
->Add( buttonsizer
, 0, wxCENTER
|wxALL
, 10 );
945 SetAutoLayout( true );
946 SetSizer( mainsizer
);
948 mainsizer
->Fit( this );
957 wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
961 bool wxGenericPageSetupDialog::TransferDataToWindow()
963 if (m_marginLeftText
)
964 m_marginLeftText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().x
));
966 m_marginTopText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().y
));
967 if (m_marginRightText
)
968 m_marginRightText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().x
));
969 if (m_marginBottomText
)
970 m_marginBottomText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().y
));
972 if (m_orientationRadioBox
)
974 if (m_pageData
.GetPrintData().GetOrientation() == wxPORTRAIT
)
975 m_orientationRadioBox
->SetSelection(0);
977 m_orientationRadioBox
->SetSelection(1);
980 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
981 // failing that, the id in the wxPrintData object.
983 wxPrintPaperType
* type
= wxThePrintPaperDatabase
->FindPaperType(
984 wxSize(m_pageData
.GetPaperSize().x
* 10, m_pageData
.GetPaperSize().y
* 10));
986 if (!type
&& m_pageData
.GetPrintData().GetPaperId() != wxPAPER_NONE
)
987 type
= wxThePrintPaperDatabase
->FindPaperType(m_pageData
.GetPrintData().GetPaperId());
991 m_paperTypeChoice
->SetStringSelection(type
->GetName());
997 bool wxGenericPageSetupDialog::TransferDataFromWindow()
999 if (m_marginLeftText
&& m_marginTopText
)
1001 int left
= wxAtoi( m_marginLeftText
->GetValue().c_str() );
1002 int top
= wxAtoi( m_marginTopText
->GetValue().c_str() );
1003 m_pageData
.SetMarginTopLeft( wxPoint(left
,top
) );
1005 if (m_marginRightText
&& m_marginBottomText
)
1007 int right
= wxAtoi( m_marginRightText
->GetValue().c_str() );
1008 int bottom
= wxAtoi( m_marginBottomText
->GetValue().c_str() );
1009 m_pageData
.SetMarginBottomRight( wxPoint(right
,bottom
) );
1012 if (m_orientationRadioBox
)
1014 int sel
= m_orientationRadioBox
->GetSelection();
1017 m_pageData
.GetPrintData().SetOrientation(wxPORTRAIT
);
1021 m_pageData
.GetPrintData().SetOrientation(wxLANDSCAPE
);
1025 if (m_paperTypeChoice
)
1027 int selectedItem
= m_paperTypeChoice
->GetSelection();
1028 if (selectedItem
!= -1)
1030 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
1033 m_pageData
.SetPaperSize(wxSize(paper
->GetWidth()/10, paper
->GetHeight()/10));
1034 m_pageData
.GetPrintData().SetPaperId(paper
->GetId());
1042 wxComboBox
*wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x
, int *y
)
1045 if (!wxThePrintPaperDatabase)
1047 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
1048 wxThePrintPaperDatabase->CreateDatabase();
1052 size_t n
= wxThePrintPaperDatabase
->GetCount();
1053 wxString
*choices
= new wxString
[n
];
1055 for (size_t i
= 0; i
< n
; i
++)
1057 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
1058 choices
[i
] = paper
->GetName();
1061 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Paper size"), wxPoint(*x
, *y
));
1064 wxComboBox
*choice
= new wxComboBox( this,
1065 wxPRINTID_PAPERSIZE
,
1068 wxSize(300, wxDefaultCoord
),
1073 // choice->SetSelection(sel);