1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/prntdlgg.cpp
3 // Purpose: Generic print dialogs
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
29 #include "wx/generic/prntdlgg.h"
34 #include "wx/stattext.h"
35 #include "wx/statbox.h"
36 #include "wx/button.h"
37 #include "wx/checkbox.h"
38 #include "wx/textctrl.h"
39 #include "wx/radiobox.h"
40 #include "wx/filedlg.h"
41 #include "wx/combobox.h"
44 #include "wx/cmndata.h"
48 #include "wx/statline.h"
52 #include "wx/generic/dcpsg.h"
55 #include "wx/prntbase.h"
56 #include "wx/printdlg.h"
58 #include "wx/filename.h"
59 #include "wx/tokenzr.h"
60 #include "wx/imaglist.h"
65 #ifndef __WXUNIVERSAL__
67 #if wxUSE_LIBGNOMEPRINT
69 wxFORCE_LINK_MODULE(gnome_print
)
74 wxFORCE_LINK_MODULE(gtk_print
)
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
83 extern wxPrintPaperDatabase
*wxThePrintPaperDatabase
;
87 //----------------------------------------------------------------------------
88 // wxPostScriptNativeData
89 //----------------------------------------------------------------------------
91 IMPLEMENT_CLASS(wxPostScriptPrintNativeData
, wxPrintNativeDataBase
)
93 wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
95 m_previewCommand
= wxEmptyString
;
97 m_printerCommand
= wxT("print");
98 m_printerOptions
= wxT("/nonotify/queue=psqueue");
99 m_afmPath
= wxT("sys$ps_font_metrics:");
103 m_printerCommand
= wxT("print");
104 m_printerOptions
= wxEmptyString
;
105 m_afmPath
= wxT("c:\\windows\\system\\");
108 #if !defined(__VMS__) && !defined(__WXMSW__)
109 m_printerCommand
= wxT("lpr");
110 m_printerOptions
= wxEmptyString
;
111 m_afmPath
= wxEmptyString
;
114 m_printerScaleX
= 1.0;
115 m_printerScaleY
= 1.0;
116 m_printerTranslateX
= 0;
117 m_printerTranslateY
= 0;
120 wxPostScriptPrintNativeData::~wxPostScriptPrintNativeData()
124 bool wxPostScriptPrintNativeData::TransferTo( wxPrintData
&WXUNUSED(data
) )
129 bool wxPostScriptPrintNativeData::TransferFrom( const wxPrintData
&WXUNUSED(data
) )
134 // ----------------------------------------------------------------------------
135 // Generic print dialog for non-Windows printing use.
136 // ----------------------------------------------------------------------------
138 IMPLEMENT_CLASS(wxGenericPrintDialog
, wxPrintDialogBase
)
140 BEGIN_EVENT_TABLE(wxGenericPrintDialog
, wxPrintDialogBase
)
141 EVT_BUTTON(wxID_OK
, wxGenericPrintDialog::OnOK
)
142 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPrintDialog::OnSetup
)
143 EVT_RADIOBOX(wxPRINTID_RANGE
, wxGenericPrintDialog::OnRange
)
146 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
,
147 wxPrintDialogData
* data
)
148 : wxPrintDialogBase(GetParentForModalDialog(parent
),
149 wxID_ANY
, _("Print"),
150 wxPoint(0,0), wxSize(600, 600),
151 wxDEFAULT_DIALOG_STYLE
|
155 m_printDialogData
= *data
;
160 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
,
162 : wxPrintDialogBase(GetParentForModalDialog(parent
),
163 wxID_ANY
, _("Print"),
164 wxPoint(0,0), wxSize(600, 600),
165 wxDEFAULT_DIALOG_STYLE
|
169 m_printDialogData
= *data
;
174 void wxGenericPrintDialog::Init(wxWindow
* WXUNUSED(parent
))
176 // wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0,0), wxSize(600, 600),
177 // wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL);
179 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
183 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
185 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
186 new wxStaticBox( this, wxID_ANY
, _( "Printer options" ) ), wxHORIZONTAL
);
187 wxFlexGridSizer
*flex
= new wxFlexGridSizer( 2 );
188 flex
->AddGrowableCol( 1 );
189 topsizer
->Add( flex
, 1, wxGROW
);
191 m_printToFileCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTTOFILE
, _("Print to File") );
192 flex
->Add( m_printToFileCheckBox
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
194 m_setupButton
= new wxButton(this, wxPRINTID_SETUP
, _("Setup...") );
195 flex
->Add( m_setupButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALIGN_RIGHT
|wxALL
, 5 );
197 if (!factory
->HasPrintSetupDialog())
198 m_setupButton
->Enable( false );
200 if (factory
->HasPrinterLine())
202 flex
->Add( new wxStaticText( this, wxID_ANY
, _("Printer:") ),
203 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
204 flex
->Add( new wxStaticText( this, wxID_ANY
, factory
->CreatePrinterLine() ),
205 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
208 if (factory
->HasStatusLine())
210 flex
->Add( new wxStaticText( this, wxID_ANY
, _("Status:") ),
211 0, wxALIGN_CENTER_VERTICAL
|(wxALL
-wxTOP
), 5 );
212 flex
->Add( new wxStaticText( this, wxID_ANY
, factory
->CreateStatusLine() ),
213 0, wxALIGN_CENTER_VERTICAL
|(wxALL
-wxTOP
), 5 );
216 mainsizer
->Add( topsizer
, 0, wxLEFT
|wxTOP
|wxRIGHT
|wxGROW
, 10 );
218 // 2) middle row with radio box
220 wxString
*choices
= new wxString
[2];
221 choices
[0] = _("All");
222 choices
[1] = _("Pages");
226 m_rangeRadioBox
= NULL
;
228 if (m_printDialogData
.GetFromPage() != 0)
230 m_rangeRadioBox
= new wxRadioBox(this, wxPRINTID_RANGE
, _("Print Range"),
231 wxDefaultPosition
, wxDefaultSize
,
234 m_rangeRadioBox
->SetSelection(1);
236 mainsizer
->Add( m_rangeRadioBox
, 0, wxLEFT
|wxTOP
|wxRIGHT
, 10 );
241 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
243 if (m_printDialogData
.GetFromPage() != 0)
245 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("From:") ), 0, wxCENTER
|wxALL
, 5 );
246 m_fromText
= new wxTextCtrl(this, wxPRINTID_FROM
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
247 bottomsizer
->Add( m_fromText
, 1, wxCENTER
|wxRIGHT
, 10 );
249 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("To:") ), 0, wxCENTER
|wxALL
, 5);
250 m_toText
= new wxTextCtrl(this, wxPRINTID_TO
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
251 bottomsizer
->Add( m_toText
, 1, wxCENTER
|wxRIGHT
, 10 );
254 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Copies:") ), 0, wxCENTER
|wxALL
, 5 );
255 m_noCopiesText
= new wxTextCtrl(this, wxPRINTID_COPIES
, wxEmptyString
, wxPoint(252, 130), wxSize(40, wxDefaultCoord
));
256 bottomsizer
->Add( m_noCopiesText
, 1, wxCENTER
|wxRIGHT
, 10 );
258 mainsizer
->Add( bottomsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 12 );
262 wxSizer
*sizerBtn
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
264 mainsizer
->Add(sizerBtn
, 0, wxEXPAND
|wxALL
, 10 );
266 SetAutoLayout( true );
267 SetSizer( mainsizer
);
269 mainsizer
->Fit( this );
272 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
277 int wxGenericPrintDialog::ShowModal()
279 return wxDialog::ShowModal();
282 wxGenericPrintDialog::~wxGenericPrintDialog()
286 void wxGenericPrintDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
288 TransferDataFromWindow();
290 // An empty 'to' field signals printing just the
292 if (m_printDialogData
.GetToPage() < 1)
293 m_printDialogData
.SetToPage(m_printDialogData
.GetFromPage());
295 // There are some interactions between the global setup data
296 // and the standard print dialog. The global printing 'mode'
297 // is determined by whether the user checks Print to file
299 if (m_printDialogData
.GetPrintToFile())
301 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE
);
303 wxFileName
fname( m_printDialogData
.GetPrintData().GetFilename() );
305 wxFileDialog
dialog( this, _("PostScript file"),
306 fname
.GetPath(), fname
.GetFullName(), wxT("*.ps"), wxFD_SAVE
| wxFD_OVERWRITE_PROMPT
);
307 if (dialog
.ShowModal() != wxID_OK
) return;
309 m_printDialogData
.GetPrintData().SetFilename( dialog
.GetPath() );
313 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER
);
319 void wxGenericPrintDialog::OnRange(wxCommandEvent
& event
)
321 if (!m_fromText
) return;
323 if (event
.GetInt() == 0)
325 m_fromText
->Enable(false);
326 m_toText
->Enable(false);
328 else if (event
.GetInt() == 1)
330 m_fromText
->Enable(true);
331 m_toText
->Enable(true);
335 void wxGenericPrintDialog::OnSetup(wxCommandEvent
& WXUNUSED(event
))
337 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
339 if (factory
->HasPrintSetupDialog())
341 // The print setup dialog should change the
342 // print data in-place if not cancelled.
343 wxDialog
*dialog
= factory
->CreatePrintSetupDialog( this, &m_printDialogData
.GetPrintData() );
349 bool wxGenericPrintDialog::TransferDataToWindow()
351 if(m_printDialogData
.GetFromPage() != 0)
355 if (m_printDialogData
.GetEnablePageNumbers())
357 m_fromText
->Enable(true);
358 m_toText
->Enable(true);
359 if (m_printDialogData
.GetFromPage() > 0)
360 m_fromText
->SetValue(wxString::Format(_T("%d"), m_printDialogData
.GetFromPage()));
361 if (m_printDialogData
.GetToPage() > 0)
362 m_toText
->SetValue(wxString::Format(_T("%d"), m_printDialogData
.GetToPage()));
365 if (m_printDialogData
.GetAllPages() || m_printDialogData
.GetFromPage() == 0)
366 m_rangeRadioBox
->SetSelection(0);
368 m_rangeRadioBox
->SetSelection(1);
373 m_fromText
->Enable(false);
374 m_toText
->Enable(false);
377 m_rangeRadioBox
->SetSelection(0);
378 m_rangeRadioBox
->wxRadioBox::Enable(1, false);
383 m_noCopiesText
->SetValue(
384 wxString::Format(_T("%d"), m_printDialogData
.GetNoCopies()));
386 m_printToFileCheckBox
->SetValue(m_printDialogData
.GetPrintToFile());
387 m_printToFileCheckBox
->Enable(m_printDialogData
.GetEnablePrintToFile());
391 bool wxGenericPrintDialog::TransferDataFromWindow()
394 if(m_printDialogData
.GetFromPage() != -1)
396 if (m_printDialogData
.GetEnablePageNumbers())
400 wxString value
= m_fromText
->GetValue();
401 if (value
.ToLong( &res
))
402 m_printDialogData
.SetFromPage( res
);
406 wxString value
= m_toText
->GetValue();
407 if (value
.ToLong( &res
))
408 m_printDialogData
.SetToPage( res
);
413 if (m_rangeRadioBox
->GetSelection() == 0)
415 m_printDialogData
.SetAllPages(true);
417 // This means all pages, more or less
418 m_printDialogData
.SetFromPage(1);
419 m_printDialogData
.SetToPage(32000);
422 m_printDialogData
.SetAllPages(false);
426 { // continuous printing
427 m_printDialogData
.SetFromPage(1);
428 m_printDialogData
.SetToPage(32000);
431 wxString value
= m_noCopiesText
->GetValue();
432 if (value
.ToLong( &res
))
433 m_printDialogData
.SetNoCopies( res
);
435 m_printDialogData
.SetPrintToFile(m_printToFileCheckBox
->GetValue());
440 wxDC
*wxGenericPrintDialog::GetPrintDC()
442 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
445 // ----------------------------------------------------------------------------
446 // Generic print setup dialog
447 // ----------------------------------------------------------------------------
449 IMPLEMENT_CLASS(wxGenericPrintSetupDialog
, wxDialog
)
451 BEGIN_EVENT_TABLE(wxGenericPrintSetupDialog
, wxDialog
)
452 EVT_LIST_ITEM_ACTIVATED(wxPRINTID_PRINTER
, wxGenericPrintSetupDialog::OnPrinter
)
455 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow
*parent
, wxPrintData
* data
):
456 wxDialog(parent
, wxID_ANY
, _("Print Setup"), wxPoint(0,0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
462 static const char * check_xpm
[] = {
463 /* width height ncolors chars_per_pixel */
489 void wxGenericPrintSetupDialog::Init(wxPrintData
* data
)
496 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
500 wxStaticBoxSizer
*printer_sizer
= new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY
, _("Printer") ), wxVERTICAL
);
501 main_sizer
->Add( printer_sizer
, 0, wxALL
|wxGROW
, 10 );
503 m_printerListCtrl
= new wxListCtrl( this, wxPRINTID_PRINTER
,
504 wxDefaultPosition
, wxSize(wxDefaultCoord
,100), wxLC_REPORT
|wxLC_SINGLE_SEL
|wxSUNKEN_BORDER
);
505 wxImageList
*image_list
= new wxImageList
;
506 image_list
->Add( wxBitmap(check_xpm
) );
507 m_printerListCtrl
->AssignImageList( image_list
, wxIMAGE_LIST_SMALL
);
509 m_printerListCtrl
->InsertColumn( 0, wxT(" "), wxLIST_FORMAT_LEFT
, 20 );
510 m_printerListCtrl
->InsertColumn( 1, wxT("Printer"), wxLIST_FORMAT_LEFT
, 150 );
511 m_printerListCtrl
->InsertColumn( 2, wxT("Device"), wxLIST_FORMAT_LEFT
, 150 );
512 m_printerListCtrl
->InsertColumn( 3, wxT("Status"), wxLIST_FORMAT_LEFT
, 80 );
515 item
.SetMask( wxLIST_MASK_TEXT
);
517 item
.SetText( _("Default printer") );
518 item
.SetId( m_printerListCtrl
->InsertItem( item
) );
520 if (data
->GetPrinterName().empty())
523 item2
.SetId( item
.GetId() );
524 item2
.SetMask( wxLIST_MASK_IMAGE
);
526 m_printerListCtrl
->SetItem( item2
);
528 m_printerListCtrl
->SetItemState( item
.GetId(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
531 item
.SetId( 1+ item
.GetId() );
533 wxArrayString errors
;
534 wxArrayString output
;
535 long res
= wxExecute( wxT("lpstat -v"), output
, errors
, wxEXEC_NODISABLE
);
536 if (res
>= 0 && errors
.GetCount() == 0)
539 for (i
= 0; i
< output
.GetCount(); i
++)
541 wxStringTokenizer
tok( output
[i
], wxT(" ") );
542 wxString tmp
= tok
.GetNextToken(); // "device"
543 if (tmp
!= wxT("device"))
544 break; // the lpstat syntax must have changed.
545 tmp
= tok
.GetNextToken(); // "for"
546 if (tmp
!= wxT("for"))
547 break; // the lpstat syntax must have changed.
548 tmp
= tok
.GetNextToken(); // "hp_deskjet930c:"
549 if (tmp
[tmp
.length()-1] == wxT(':'))
550 tmp
.Remove(tmp
.length()-1,1);
552 item
.SetText( name
);
553 item
.SetId( m_printerListCtrl
->InsertItem( item
) );
554 tmp
= tok
.GetNextToken(); // "parallel:/dev/lp0"
557 m_printerListCtrl
->SetItem( item
);
558 if (data
->GetPrinterName() == name
)
561 item2
.SetId( item
.GetId() );
562 item2
.SetMask( wxLIST_MASK_IMAGE
);
564 m_printerListCtrl
->SetItem( item2
);
566 m_printerListCtrl
->SetItemState( item
.GetId(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
569 wxString command
= wxT("lpstat -p ");
571 wxArrayString errors2
;
572 wxArrayString output2
;
573 res
= wxExecute( command
, output2
, errors2
, wxEXEC_NODISABLE
);
574 if (res
>= 0 && errors2
.GetCount() == 0 && output2
.GetCount() > 0)
576 tmp
= output2
[0]; // "printer hp_deskjet930c is idle. enable since ..."
577 int pos
= tmp
.Find( wxT('.') );
578 if (pos
!= wxNOT_FOUND
)
579 tmp
.Remove( (size_t)pos
, tmp
.length()-(size_t)pos
);
580 wxStringTokenizer
tok2( tmp
, wxT(" ") );
581 tmp
= tok2
.GetNextToken(); // "printer"
582 tmp
= tok2
.GetNextToken(); // "hp_deskjet930c"
584 while (tok2
.HasMoreTokens())
586 tmp
+= tok2
.GetNextToken();
591 m_printerListCtrl
->SetItem( item
);
595 item
.SetId( 1+ item
.GetId() );
600 printer_sizer
->Add( m_printerListCtrl
, 0, wxALL
|wxGROW
, 5 );
602 wxBoxSizer
*item1
= new wxBoxSizer( wxHORIZONTAL
);
603 main_sizer
->Add( item1
, 0, wxALL
, 5 );
605 // printer options (on the left)
607 wxBoxSizer
*item2
= new wxBoxSizer( wxVERTICAL
);
609 wxStaticBox
*item4
= new wxStaticBox( this, wxPRINTID_STATIC
, _("Paper size") );
610 wxStaticBoxSizer
*item3
= new wxStaticBoxSizer( item4
, wxVERTICAL
);
612 m_paperTypeChoice
= CreatePaperTypeChoice();
613 item3
->Add( m_paperTypeChoice
, 0, wxALIGN_CENTER
|wxALL
, 5 );
615 item2
->Add( item3
, 0, wxALIGN_CENTER
|wxALL
, 5 );
622 m_orientationRadioBox
= new wxRadioBox( this, wxPRINTID_ORIENTATION
, _("Orientation"), wxDefaultPosition
, wxDefaultSize
, 2, strs6
, 1, wxRA_SPECIFY_ROWS
);
623 item2
->Add( m_orientationRadioBox
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
625 wxStaticBox
*item8
= new wxStaticBox( this, wxID_ANY
, _("Options") );
626 wxStaticBoxSizer
*item7
= new wxStaticBoxSizer( item8
, wxHORIZONTAL
);
628 m_colourCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTCOLOUR
, _("Print in colour") );
629 item7
->Add( m_colourCheckBox
, 0, wxALIGN_CENTER
|wxALL
, 5 );
631 item2
->Add( item7
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
633 item1
->Add( item2
, 0, wxALIGN_CENTER_HORIZONTAL
, 5 );
635 // spooling options (on the right)
637 wxStaticBox
*item11
= new wxStaticBox( this, wxID_ANY
, _("Print spooling") );
638 wxStaticBoxSizer
*item10
= new wxStaticBoxSizer( item11
, wxVERTICAL
);
640 wxStaticText
*item12
= new wxStaticText( this, wxID_ANY
, _("Printer command:") );
641 item10
->Add( item12
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
643 wxBoxSizer
*item13
= new wxBoxSizer( wxHORIZONTAL
);
645 item13
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
647 m_printerCommandText
= new wxTextCtrl( this, wxPRINTID_COMMAND
, wxEmptyString
, wxDefaultPosition
, wxSize(160,wxDefaultCoord
) );
648 item13
->Add( m_printerCommandText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
650 item10
->Add( item13
, 0, wxALIGN_CENTER
|wxALL
, 0 );
652 wxStaticText
*item15
= new wxStaticText( this, wxID_ANY
, _("Printer options:") );
653 item10
->Add( item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
655 wxBoxSizer
*item16
= new wxBoxSizer( wxHORIZONTAL
);
657 item16
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
659 m_printerOptionsText
= new wxTextCtrl( this, wxPRINTID_OPTIONS
, wxEmptyString
, wxDefaultPosition
, wxSize(160,wxDefaultCoord
) );
660 item16
->Add( m_printerOptionsText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
662 item10
->Add( item16
, 0, wxALIGN_CENTER
|wxALL
, 0 );
664 item1
->Add( item10
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5 );
669 main_sizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
674 main_sizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxEXPAND
|wxALL
, 10 );
676 SetAutoLayout( true );
677 SetSizer( main_sizer
);
679 main_sizer
->Fit( this );
689 wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
693 void wxGenericPrintSetupDialog::OnPrinter(wxListEvent
& event
)
696 for (long item
= 0; item
< m_printerListCtrl
->GetItemCount(); item
++)
697 m_printerListCtrl
->SetItemImage( item
, -1 );
699 m_printerListCtrl
->SetItemImage( event
.GetIndex(), 0 );
701 if (event
.GetIndex() == 0)
703 m_printerCommandText
->SetValue( wxT("lpr") );
709 li
.SetMask( wxLIST_MASK_TEXT
);
710 li
.SetId( event
.GetIndex() );
711 m_printerListCtrl
->GetItem( li
);
712 m_printerCommandText
->SetValue( _T("lpr -P") + li
.GetText() );
716 bool wxGenericPrintSetupDialog::TransferDataToWindow()
718 wxPostScriptPrintNativeData
*data
=
719 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
721 if (m_printerCommandText
&& !data
->GetPrinterCommand().empty())
722 m_printerCommandText
->SetValue(data
->GetPrinterCommand());
723 if (m_printerOptionsText
&& !data
->GetPrinterOptions().empty())
724 m_printerOptionsText
->SetValue(data
->GetPrinterOptions());
725 if (m_colourCheckBox
)
726 m_colourCheckBox
->SetValue(m_printData
.GetColour());
728 if (m_orientationRadioBox
)
730 if (m_printData
.GetOrientation() == wxPORTRAIT
)
731 m_orientationRadioBox
->SetSelection(0);
733 m_orientationRadioBox
->SetSelection(1);
738 bool wxGenericPrintSetupDialog::TransferDataFromWindow()
740 wxPostScriptPrintNativeData
*data
=
741 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
743 // find selected printer
744 long id
= m_printerListCtrl
->GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
747 m_printData
.SetPrinterName( wxEmptyString
);
753 item
.SetMask( wxLIST_MASK_TEXT
);
755 m_printerListCtrl
->GetItem( item
);
756 m_printData
.SetPrinterName( item
.GetText() );
759 if (m_printerCommandText
)
760 data
->SetPrinterCommand(m_printerCommandText
->GetValue());
761 if (m_printerOptionsText
)
762 data
->SetPrinterOptions(m_printerOptionsText
->GetValue());
763 if (m_colourCheckBox
)
764 m_printData
.SetColour(m_colourCheckBox
->GetValue());
765 if (m_orientationRadioBox
)
767 int sel
= m_orientationRadioBox
->GetSelection();
769 m_printData
.SetOrientation(wxPORTRAIT
);
771 m_printData
.SetOrientation(wxLANDSCAPE
);
773 if (m_paperTypeChoice
)
775 int selectedItem
= m_paperTypeChoice
->GetSelection();
776 if (selectedItem
!= -1)
778 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
780 m_printData
.SetPaperId( paper
->GetId());
785 *m_targetData
= m_printData
;
790 wxComboBox
*wxGenericPrintSetupDialog::CreatePaperTypeChoice()
792 size_t n
= wxThePrintPaperDatabase
->GetCount();
793 wxString
*choices
= new wxString
[n
];
796 for (size_t i
= 0; i
< n
; i
++)
798 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
799 choices
[i
] = paper
->GetName();
800 if (m_printData
.GetPaperId() == paper
->GetId())
806 wxComboBox
*choice
= new wxComboBox( this,
810 wxSize(width
, wxDefaultCoord
),
815 choice
->SetSelection(sel
);
819 #endif // wxUSE_POSTSCRIPT
821 // ----------------------------------------------------------------------------
822 // Generic page setup dialog
823 // ----------------------------------------------------------------------------
825 IMPLEMENT_CLASS(wxGenericPageSetupDialog
, wxPageSetupDialogBase
)
827 BEGIN_EVENT_TABLE(wxGenericPageSetupDialog
, wxPageSetupDialogBase
)
828 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPageSetupDialog::OnPrinter
)
831 wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow
*parent
,
832 wxPageSetupDialogData
* data
)
833 : wxPageSetupDialogBase( parent
,
838 wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
845 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
848 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
849 new wxStaticBox(this,wxPRINTID_STATIC
, _("Paper size")), wxHORIZONTAL
);
851 size_t n
= wxThePrintPaperDatabase
->GetCount();
852 wxString
*choices
= new wxString
[n
];
854 for (size_t i
= 0; i
< n
; i
++)
856 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
857 choices
[i
] = paper
->GetName();
860 m_paperTypeChoice
= new wxComboBox( this,
864 wxSize(300, wxDefaultCoord
),
866 topsizer
->Add( m_paperTypeChoice
, 1, wxEXPAND
|wxALL
, 5 );
867 // m_paperTypeChoice->SetSelection(sel);
869 mainsizer
->Add( topsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
871 // 2) middle sizer with radio box
873 wxString
*choices2
= new wxString
[2];
874 choices2
[0] = _("Portrait");
875 choices2
[1] = _("Landscape");
876 m_orientationRadioBox
= new wxRadioBox(this, wxPRINTID_ORIENTATION
, _("Orientation"),
877 wxDefaultPosition
, wxDefaultSize
, 2, choices2
, 2);
878 m_orientationRadioBox
->SetSelection(0);
880 mainsizer
->Add( m_orientationRadioBox
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 10 );
884 wxBoxSizer
*table
= new wxBoxSizer( wxHORIZONTAL
);
886 wxBoxSizer
*column1
= new wxBoxSizer( wxVERTICAL
);
887 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Left margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
888 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Top margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
889 table
->Add( column1
, 0, wxALL
| wxEXPAND
, 5 );
891 wxBoxSizer
*column2
= new wxBoxSizer( wxVERTICAL
);
892 m_marginLeftText
= new wxTextCtrl(this, wxPRINTID_LEFTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
893 m_marginTopText
= new wxTextCtrl(this, wxPRINTID_TOPMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
894 column2
->Add( m_marginLeftText
, 1, wxALL
, 5 );
895 column2
->Add( m_marginTopText
, 1, wxALL
, 5 );
896 table
->Add( column2
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
898 wxBoxSizer
*column3
= new wxBoxSizer( wxVERTICAL
);
899 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Right margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
900 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Bottom margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
901 table
->Add( column3
, 0, wxALL
| wxEXPAND
, 5 );
903 wxBoxSizer
*column4
= new wxBoxSizer( wxVERTICAL
);
904 m_marginRightText
= new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
905 m_marginBottomText
= new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
906 column4
->Add( m_marginRightText
, 1, wxALL
, 5 );
907 column4
->Add( m_marginBottomText
, 1, wxALL
, 5 );
908 table
->Add( column4
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
910 mainsizer
->Add( table
, 0 );
914 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
919 wxSizer
* buttonsizer
= CreateButtonSizer( wxOK
|wxCANCEL
);
921 if (wxPrintFactory::GetFactory()->HasPrintSetupDialog())
923 m_printerButton
= new wxButton(this, wxPRINTID_SETUP
, _("Printer...") );
924 buttonsizer
->Add( m_printerButton
, 0, wxLEFT
|wxRIGHT
, 10 );
925 if ( !m_pageData
.GetEnablePrinter() )
926 m_printerButton
->Enable(false);
930 m_printerButton
= NULL
;
933 // if (m_printData.GetEnableHelp())
934 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight);
935 mainsizer
->Add( buttonsizer
, 0, wxEXPAND
|wxALL
, 10 );
938 SetAutoLayout( true );
939 SetSizer( mainsizer
);
941 mainsizer
->Fit( this );
950 wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
954 wxPageSetupDialogData
& wxGenericPageSetupDialog::GetPageSetupDialogData()
959 bool wxGenericPageSetupDialog::TransferDataToWindow()
961 if (m_marginLeftText
)
962 m_marginLeftText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().x
));
964 m_marginTopText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().y
));
965 if (m_marginRightText
)
966 m_marginRightText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().x
));
967 if (m_marginBottomText
)
968 m_marginBottomText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().y
));
970 if (m_orientationRadioBox
)
972 if (m_pageData
.GetPrintData().GetOrientation() == wxPORTRAIT
)
973 m_orientationRadioBox
->SetSelection(0);
975 m_orientationRadioBox
->SetSelection(1);
978 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
979 // failing that, the id in the wxPrintData object.
981 wxPrintPaperType
* type
= wxThePrintPaperDatabase
->FindPaperType(
982 wxSize(m_pageData
.GetPaperSize().x
* 10, m_pageData
.GetPaperSize().y
* 10));
984 if (!type
&& m_pageData
.GetPrintData().GetPaperId() != wxPAPER_NONE
)
985 type
= wxThePrintPaperDatabase
->FindPaperType(m_pageData
.GetPrintData().GetPaperId());
989 m_paperTypeChoice
->SetStringSelection(type
->GetName());
995 bool wxGenericPageSetupDialog::TransferDataFromWindow()
997 if (m_marginLeftText
&& m_marginTopText
)
999 int left
= wxAtoi( m_marginLeftText
->GetValue().c_str() );
1000 int top
= wxAtoi( m_marginTopText
->GetValue().c_str() );
1001 m_pageData
.SetMarginTopLeft( wxPoint(left
,top
) );
1003 if (m_marginRightText
&& m_marginBottomText
)
1005 int right
= wxAtoi( m_marginRightText
->GetValue().c_str() );
1006 int bottom
= wxAtoi( m_marginBottomText
->GetValue().c_str() );
1007 m_pageData
.SetMarginBottomRight( wxPoint(right
,bottom
) );
1010 if (m_orientationRadioBox
)
1012 int sel
= m_orientationRadioBox
->GetSelection();
1015 m_pageData
.GetPrintData().SetOrientation(wxPORTRAIT
);
1019 m_pageData
.GetPrintData().SetOrientation(wxLANDSCAPE
);
1023 if (m_paperTypeChoice
)
1025 int selectedItem
= m_paperTypeChoice
->GetSelection();
1026 if (selectedItem
!= -1)
1028 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
1031 m_pageData
.SetPaperSize(wxSize(paper
->GetWidth()/10, paper
->GetHeight()/10));
1032 m_pageData
.GetPrintData().SetPaperId(paper
->GetId());
1040 wxComboBox
*wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x
, int *y
)
1043 if (!wxThePrintPaperDatabase)
1045 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
1046 wxThePrintPaperDatabase->CreateDatabase();
1050 size_t n
= wxThePrintPaperDatabase
->GetCount();
1051 wxString
*choices
= new wxString
[n
];
1053 for (size_t i
= 0; i
< n
; i
++)
1055 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
1056 choices
[i
] = paper
->GetName();
1059 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Paper size"), wxPoint(*x
, *y
));
1062 wxComboBox
*choice
= new wxComboBox( this,
1063 wxPRINTID_PAPERSIZE
,
1066 wxSize(300, wxDefaultCoord
),
1071 // choice->SetSelection(sel);
1075 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent
& WXUNUSED(event
))
1077 // We no longer query GetPrintMode, so we can eliminate the need
1078 // to call SetPrintMode.
1079 // This has the limitation that we can't explicitly call the PostScript
1080 // print setup dialog from the generic Page Setup dialog under Windows,
1081 // but since this choice would only happen when trying to do PostScript
1082 // printing under Windows (and only in 16-bit Windows which
1083 // doesn't have a Windows-specific page setup dialog) it's worth it.
1085 // First save the current settings, so the wxPrintData object is up to date.
1086 TransferDataFromWindow();
1088 // Transfer the current print settings from this dialog to the page setup dialog.
1091 // Use print factory later
1093 wxPrintDialogData data
;
1094 data
= GetPageSetupData().GetPrintData();
1095 data
.SetSetupDialog(true);
1096 wxPrintDialog
printDialog(this, & data
);
1097 printDialog
.ShowModal();
1099 // Transfer the page setup print settings from the page dialog to this dialog again, in case
1100 // the page setup dialog changed something.
1101 GetPageSetupData().GetPrintData() = printDialog
.GetPrintDialogData().GetPrintData();
1102 GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData
1104 // Now update the dialog in case the page setup dialog changed some of our settings.
1105 TransferDataToWindow();