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 #if wxUSE_LIBGNOMEPRINT
67 wxFORCE_LINK_MODULE(gnome_print
)
72 wxFORCE_LINK_MODULE(gtk_print
)
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 extern wxPrintPaperDatabase
*wxThePrintPaperDatabase
;
83 //----------------------------------------------------------------------------
84 // wxPostScriptNativeData
85 //----------------------------------------------------------------------------
87 IMPLEMENT_CLASS(wxPostScriptPrintNativeData
, wxPrintNativeDataBase
)
89 wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
91 m_previewCommand
= wxEmptyString
;
93 m_printerCommand
= wxT("print");
94 m_printerOptions
= wxT("/nonotify/queue=psqueue");
95 m_afmPath
= wxT("sys$ps_font_metrics:");
99 m_printerCommand
= wxT("print");
100 m_printerOptions
= wxEmptyString
;
101 m_afmPath
= wxT("c:\\windows\\system\\");
104 #if !defined(__VMS__) && !defined(__WXMSW__)
105 m_printerCommand
= wxT("lpr");
106 m_printerOptions
= wxEmptyString
;
107 m_afmPath
= wxEmptyString
;
110 m_printerScaleX
= 1.0;
111 m_printerScaleY
= 1.0;
112 m_printerTranslateX
= 0;
113 m_printerTranslateY
= 0;
116 wxPostScriptPrintNativeData::~wxPostScriptPrintNativeData()
120 bool wxPostScriptPrintNativeData::TransferTo( wxPrintData
&WXUNUSED(data
) )
125 bool wxPostScriptPrintNativeData::TransferFrom( const wxPrintData
&WXUNUSED(data
) )
130 // ----------------------------------------------------------------------------
131 // Generic print dialog for non-Windows printing use.
132 // ----------------------------------------------------------------------------
134 IMPLEMENT_CLASS(wxGenericPrintDialog
, wxPrintDialogBase
)
136 BEGIN_EVENT_TABLE(wxGenericPrintDialog
, wxPrintDialogBase
)
137 EVT_BUTTON(wxID_OK
, wxGenericPrintDialog::OnOK
)
138 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPrintDialog::OnSetup
)
139 EVT_RADIOBOX(wxPRINTID_RANGE
, wxGenericPrintDialog::OnRange
)
142 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
,
143 wxPrintDialogData
* data
)
144 : wxPrintDialogBase(GetParentForModalDialog(parent
),
145 wxID_ANY
, _("Print"),
146 wxPoint(0,0), wxSize(600, 600),
147 wxDEFAULT_DIALOG_STYLE
|
151 m_printDialogData
= *data
;
156 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
,
158 : wxPrintDialogBase(GetParentForModalDialog(parent
),
159 wxID_ANY
, _("Print"),
160 wxPoint(0,0), wxSize(600, 600),
161 wxDEFAULT_DIALOG_STYLE
|
165 m_printDialogData
= *data
;
170 void wxGenericPrintDialog::Init(wxWindow
* WXUNUSED(parent
))
172 // wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0,0), wxSize(600, 600),
173 // wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL);
175 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
179 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
181 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
182 new wxStaticBox( this, wxID_ANY
, _( "Printer options" ) ), wxHORIZONTAL
);
183 wxFlexGridSizer
*flex
= new wxFlexGridSizer( 2 );
184 flex
->AddGrowableCol( 1 );
185 topsizer
->Add( flex
, 1, wxGROW
);
187 m_printToFileCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTTOFILE
, _("Print to File") );
188 flex
->Add( m_printToFileCheckBox
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
190 m_setupButton
= new wxButton(this, wxPRINTID_SETUP
, _("Setup...") );
191 flex
->Add( m_setupButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALIGN_RIGHT
|wxALL
, 5 );
193 if (!factory
->HasPrintSetupDialog())
194 m_setupButton
->Enable( false );
196 if (factory
->HasPrinterLine())
198 flex
->Add( new wxStaticText( this, wxID_ANY
, _("Printer:") ),
199 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
200 flex
->Add( new wxStaticText( this, wxID_ANY
, factory
->CreatePrinterLine() ),
201 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
204 if (factory
->HasStatusLine())
206 flex
->Add( new wxStaticText( this, wxID_ANY
, _("Status:") ),
207 0, wxALIGN_CENTER_VERTICAL
|wxALL
-wxTOP
, 5 );
208 flex
->Add( new wxStaticText( this, wxID_ANY
, factory
->CreateStatusLine() ),
209 0, wxALIGN_CENTER_VERTICAL
|wxALL
-wxTOP
, 5 );
212 mainsizer
->Add( topsizer
, 0, wxLEFT
|wxTOP
|wxRIGHT
|wxGROW
, 10 );
214 // 2) middle row with radio box
216 wxString
*choices
= new wxString
[2];
217 choices
[0] = _("All");
218 choices
[1] = _("Pages");
220 m_fromText
= (wxTextCtrl
*)NULL
;
221 m_toText
= (wxTextCtrl
*)NULL
;
222 m_rangeRadioBox
= (wxRadioBox
*)NULL
;
224 if (m_printDialogData
.GetFromPage() != 0)
226 m_rangeRadioBox
= new wxRadioBox(this, wxPRINTID_RANGE
, _("Print Range"),
227 wxDefaultPosition
, wxDefaultSize
,
230 m_rangeRadioBox
->SetSelection(1);
232 mainsizer
->Add( m_rangeRadioBox
, 0, wxLEFT
|wxTOP
|wxRIGHT
, 10 );
237 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
239 if (m_printDialogData
.GetFromPage() != 0)
241 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("From:") ), 0, wxCENTER
|wxALL
, 5 );
242 m_fromText
= new wxTextCtrl(this, wxPRINTID_FROM
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
243 bottomsizer
->Add( m_fromText
, 1, wxCENTER
|wxRIGHT
, 10 );
245 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("To:") ), 0, wxCENTER
|wxALL
, 5);
246 m_toText
= new wxTextCtrl(this, wxPRINTID_TO
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
247 bottomsizer
->Add( m_toText
, 1, wxCENTER
|wxRIGHT
, 10 );
250 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Copies:") ), 0, wxCENTER
|wxALL
, 5 );
251 m_noCopiesText
= new wxTextCtrl(this, wxPRINTID_COPIES
, wxEmptyString
, wxPoint(252, 130), wxSize(40, wxDefaultCoord
));
252 bottomsizer
->Add( m_noCopiesText
, 1, wxCENTER
|wxRIGHT
, 10 );
254 mainsizer
->Add( bottomsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 12 );
258 wxSizer
*sizerBtn
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
260 mainsizer
->Add(sizerBtn
, 0, wxEXPAND
|wxALL
, 10 );
262 SetAutoLayout( true );
263 SetSizer( mainsizer
);
265 mainsizer
->Fit( this );
268 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
273 int wxGenericPrintDialog::ShowModal()
275 return wxDialog::ShowModal();
278 wxGenericPrintDialog::~wxGenericPrintDialog()
282 void wxGenericPrintDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
284 TransferDataFromWindow();
286 // An empty 'to' field signals printing just the
288 if (m_printDialogData
.GetToPage() < 1)
289 m_printDialogData
.SetToPage(m_printDialogData
.GetFromPage());
291 // There are some interactions between the global setup data
292 // and the standard print dialog. The global printing 'mode'
293 // is determined by whether the user checks Print to file
295 if (m_printDialogData
.GetPrintToFile())
297 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE
);
299 wxFileName
fname( m_printDialogData
.GetPrintData().GetFilename() );
301 wxFileDialog
dialog( this, _("PostScript file"),
302 fname
.GetPath(), fname
.GetFullName(), wxT("*.ps"), wxFD_SAVE
| wxFD_OVERWRITE_PROMPT
);
303 if (dialog
.ShowModal() != wxID_OK
) return;
305 m_printDialogData
.GetPrintData().SetFilename( dialog
.GetPath() );
309 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER
);
315 void wxGenericPrintDialog::OnRange(wxCommandEvent
& event
)
317 if (!m_fromText
) return;
319 if (event
.GetInt() == 0)
321 m_fromText
->Enable(false);
322 m_toText
->Enable(false);
324 else if (event
.GetInt() == 1)
326 m_fromText
->Enable(true);
327 m_toText
->Enable(true);
331 void wxGenericPrintDialog::OnSetup(wxCommandEvent
& WXUNUSED(event
))
333 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
335 if (factory
->HasPrintSetupDialog())
337 // The print setup dialog should change the
338 // print data in-place if not cancelled.
339 wxDialog
*dialog
= factory
->CreatePrintSetupDialog( this, &m_printDialogData
.GetPrintData() );
345 bool wxGenericPrintDialog::TransferDataToWindow()
347 if(m_printDialogData
.GetFromPage() != 0)
351 if (m_printDialogData
.GetEnablePageNumbers())
353 m_fromText
->Enable(true);
354 m_toText
->Enable(true);
355 if (m_printDialogData
.GetFromPage() > 0)
356 m_fromText
->SetValue(wxString::Format(_T("%d"), m_printDialogData
.GetFromPage()));
357 if (m_printDialogData
.GetToPage() > 0)
358 m_toText
->SetValue(wxString::Format(_T("%d"), m_printDialogData
.GetToPage()));
360 if (m_printDialogData
.GetAllPages() || m_printDialogData
.GetFromPage() == 0)
361 m_rangeRadioBox
->SetSelection(0);
363 m_rangeRadioBox
->SetSelection(1);
367 m_fromText
->Enable(false);
368 m_toText
->Enable(false);
371 m_rangeRadioBox
->SetSelection(0);
372 m_rangeRadioBox
->wxRadioBox::Enable(1, false);
377 m_noCopiesText
->SetValue(
378 wxString::Format(_T("%d"), m_printDialogData
.GetNoCopies()));
380 m_printToFileCheckBox
->SetValue(m_printDialogData
.GetPrintToFile());
381 m_printToFileCheckBox
->Enable(m_printDialogData
.GetEnablePrintToFile());
385 bool wxGenericPrintDialog::TransferDataFromWindow()
388 if(m_printDialogData
.GetFromPage() != -1)
390 if (m_printDialogData
.GetEnablePageNumbers())
394 wxString value
= m_fromText
->GetValue();
395 if (value
.ToLong( &res
))
396 m_printDialogData
.SetFromPage( res
);
400 wxString value
= m_toText
->GetValue();
401 if (value
.ToLong( &res
))
402 m_printDialogData
.SetToPage( res
);
407 if (m_rangeRadioBox
->GetSelection() == 0)
409 m_printDialogData
.SetAllPages(true);
411 // This means all pages, more or less
412 m_printDialogData
.SetFromPage(1);
413 m_printDialogData
.SetToPage(32000);
416 m_printDialogData
.SetAllPages(false);
420 { // continuous printing
421 m_printDialogData
.SetFromPage(1);
422 m_printDialogData
.SetToPage(32000);
425 wxString value
= m_noCopiesText
->GetValue();
426 if (value
.ToLong( &res
))
427 m_printDialogData
.SetNoCopies( res
);
429 m_printDialogData
.SetPrintToFile(m_printToFileCheckBox
->GetValue());
434 wxDC
*wxGenericPrintDialog::GetPrintDC()
436 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
439 // ----------------------------------------------------------------------------
440 // Generic print setup dialog
441 // ----------------------------------------------------------------------------
443 IMPLEMENT_CLASS(wxGenericPrintSetupDialog
, wxDialog
)
445 BEGIN_EVENT_TABLE(wxGenericPrintSetupDialog
, wxDialog
)
446 EVT_LIST_ITEM_ACTIVATED(wxPRINTID_PRINTER
, wxGenericPrintSetupDialog::OnPrinter
)
449 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow
*parent
, wxPrintData
* data
):
450 wxDialog(parent
, wxID_ANY
, _("Print Setup"), wxPoint(0,0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
456 static const char * check_xpm
[] = {
457 /* width height ncolors chars_per_pixel */
483 void wxGenericPrintSetupDialog::Init(wxPrintData
* data
)
490 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
494 wxStaticBoxSizer
*printer_sizer
= new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY
, _("Printer") ), wxVERTICAL
);
495 main_sizer
->Add( printer_sizer
, 0, wxALL
|wxGROW
, 10 );
497 m_printerListCtrl
= new wxListCtrl( this, wxPRINTID_PRINTER
,
498 wxDefaultPosition
, wxSize(wxDefaultCoord
,100), wxLC_REPORT
|wxLC_SINGLE_SEL
|wxSUNKEN_BORDER
);
499 wxImageList
*image_list
= new wxImageList
;
500 image_list
->Add( wxBitmap(check_xpm
) );
501 m_printerListCtrl
->AssignImageList( image_list
, wxIMAGE_LIST_SMALL
);
503 m_printerListCtrl
->InsertColumn( 0, wxT(" "), wxLIST_FORMAT_LEFT
, 20 );
504 m_printerListCtrl
->InsertColumn( 1, wxT("Printer"), wxLIST_FORMAT_LEFT
, 150 );
505 m_printerListCtrl
->InsertColumn( 2, wxT("Device"), wxLIST_FORMAT_LEFT
, 150 );
506 m_printerListCtrl
->InsertColumn( 3, wxT("Status"), wxLIST_FORMAT_LEFT
, 80 );
509 item
.SetMask( wxLIST_MASK_TEXT
);
511 item
.SetText( _("Default printer") );
512 item
.SetId( m_printerListCtrl
->InsertItem( item
) );
514 if (data
->GetPrinterName().empty())
517 item2
.SetId( item
.GetId() );
518 item2
.SetMask( wxLIST_MASK_IMAGE
);
520 m_printerListCtrl
->SetItem( item2
);
522 m_printerListCtrl
->SetItemState( item
.GetId(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
525 item
.SetId( 1+ item
.GetId() );
527 wxArrayString errors
;
528 wxArrayString output
;
529 long res
= wxExecute( wxT("lpstat -v"), output
, errors
, wxEXEC_NODISABLE
);
530 if (res
>= 0 && errors
.GetCount() == 0)
533 for (i
= 0; i
< output
.GetCount(); i
++)
535 wxStringTokenizer
tok( output
[i
], wxT(" ") );
536 wxString tmp
= tok
.GetNextToken(); // "device"
537 if (tmp
!= wxT("device"))
538 break; // the lpstat syntax must have changed.
539 tmp
= tok
.GetNextToken(); // "for"
540 if (tmp
!= wxT("for"))
541 break; // the lpstat syntax must have changed.
542 tmp
= tok
.GetNextToken(); // "hp_deskjet930c:"
543 if (tmp
[tmp
.length()-1] == wxT(':'))
544 tmp
.Remove(tmp
.length()-1,1);
546 item
.SetText( name
);
547 item
.SetId( m_printerListCtrl
->InsertItem( item
) );
548 tmp
= tok
.GetNextToken(); // "parallel:/dev/lp0"
551 m_printerListCtrl
->SetItem( item
);
552 if (data
->GetPrinterName() == name
)
555 item2
.SetId( item
.GetId() );
556 item2
.SetMask( wxLIST_MASK_IMAGE
);
558 m_printerListCtrl
->SetItem( item2
);
560 m_printerListCtrl
->SetItemState( item
.GetId(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
563 wxString command
= wxT("lpstat -p ");
565 wxArrayString errors2
;
566 wxArrayString output2
;
567 res
= wxExecute( command
, output2
, errors2
, wxEXEC_NODISABLE
);
568 if (res
>= 0 && errors2
.GetCount() == 0 && output2
.GetCount() > 0)
570 tmp
= output2
[0]; // "printer hp_deskjet930c is idle. enable since ..."
571 int pos
= tmp
.Find( wxT('.') );
572 if (pos
!= wxNOT_FOUND
)
573 tmp
.Remove( (size_t)pos
, tmp
.length()-(size_t)pos
);
574 wxStringTokenizer
tok2( tmp
, wxT(" ") );
575 tmp
= tok2
.GetNextToken(); // "printer"
576 tmp
= tok2
.GetNextToken(); // "hp_deskjet930c"
578 while (tok2
.HasMoreTokens())
580 tmp
+= tok2
.GetNextToken();
585 m_printerListCtrl
->SetItem( item
);
589 item
.SetId( 1+ item
.GetId() );
594 printer_sizer
->Add( m_printerListCtrl
, 0, wxALL
|wxGROW
, 5 );
596 wxBoxSizer
*item1
= new wxBoxSizer( wxHORIZONTAL
);
597 main_sizer
->Add( item1
, 0, wxALL
, 5 );
599 // printer options (on the left)
601 wxBoxSizer
*item2
= new wxBoxSizer( wxVERTICAL
);
603 wxStaticBox
*item4
= new wxStaticBox( this, wxPRINTID_STATIC
, _("Paper size") );
604 wxStaticBoxSizer
*item3
= new wxStaticBoxSizer( item4
, wxVERTICAL
);
606 m_paperTypeChoice
= CreatePaperTypeChoice();
607 item3
->Add( m_paperTypeChoice
, 0, wxALIGN_CENTER
|wxALL
, 5 );
609 item2
->Add( item3
, 0, wxALIGN_CENTER
|wxALL
, 5 );
616 m_orientationRadioBox
= new wxRadioBox( this, wxPRINTID_ORIENTATION
, _("Orientation"), wxDefaultPosition
, wxDefaultSize
, 2, strs6
, 1, wxRA_SPECIFY_ROWS
);
617 item2
->Add( m_orientationRadioBox
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
619 wxStaticBox
*item8
= new wxStaticBox( this, wxID_ANY
, _("Options") );
620 wxStaticBoxSizer
*item7
= new wxStaticBoxSizer( item8
, wxHORIZONTAL
);
622 m_colourCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTCOLOUR
, _("Print in colour") );
623 item7
->Add( m_colourCheckBox
, 0, wxALIGN_CENTER
|wxALL
, 5 );
625 item2
->Add( item7
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
627 item1
->Add( item2
, 0, wxALIGN_CENTER_HORIZONTAL
, 5 );
629 // spooling options (on the right)
631 wxStaticBox
*item11
= new wxStaticBox( this, wxID_ANY
, _("Print spooling") );
632 wxStaticBoxSizer
*item10
= new wxStaticBoxSizer( item11
, wxVERTICAL
);
634 wxStaticText
*item12
= new wxStaticText( this, wxID_ANY
, _("Printer command:") );
635 item10
->Add( item12
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
637 wxBoxSizer
*item13
= new wxBoxSizer( wxHORIZONTAL
);
639 item13
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
641 m_printerCommandText
= new wxTextCtrl( this, wxPRINTID_COMMAND
, wxEmptyString
, wxDefaultPosition
, wxSize(160,wxDefaultCoord
) );
642 item13
->Add( m_printerCommandText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
644 item10
->Add( item13
, 0, wxALIGN_CENTER
|wxALL
, 0 );
646 wxStaticText
*item15
= new wxStaticText( this, wxID_ANY
, _("Printer options:") );
647 item10
->Add( item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
649 wxBoxSizer
*item16
= new wxBoxSizer( wxHORIZONTAL
);
651 item16
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
653 m_printerOptionsText
= new wxTextCtrl( this, wxPRINTID_OPTIONS
, wxEmptyString
, wxDefaultPosition
, wxSize(160,wxDefaultCoord
) );
654 item16
->Add( m_printerOptionsText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
656 item10
->Add( item16
, 0, wxALIGN_CENTER
|wxALL
, 0 );
658 item1
->Add( item10
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5 );
663 main_sizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
668 main_sizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxEXPAND
|wxALL
, 10 );
670 SetAutoLayout( true );
671 SetSizer( main_sizer
);
673 main_sizer
->Fit( this );
683 wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
687 void wxGenericPrintSetupDialog::OnPrinter(wxListEvent
& event
)
690 for (long item
= 0; item
< m_printerListCtrl
->GetItemCount(); item
++)
691 m_printerListCtrl
->SetItemImage( item
, -1 );
693 m_printerListCtrl
->SetItemImage( event
.GetIndex(), 0 );
695 if (event
.GetIndex() == 0)
697 m_printerCommandText
->SetValue( wxT("lpr") );
703 li
.SetMask( wxLIST_MASK_TEXT
);
704 li
.SetId( event
.GetIndex() );
705 m_printerListCtrl
->GetItem( li
);
706 m_printerCommandText
->SetValue( _T("lpr -P") + li
.GetText() );
710 bool wxGenericPrintSetupDialog::TransferDataToWindow()
712 wxPostScriptPrintNativeData
*data
=
713 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
715 if (m_printerCommandText
&& !data
->GetPrinterCommand().empty())
716 m_printerCommandText
->SetValue(data
->GetPrinterCommand());
717 if (m_printerOptionsText
&& !data
->GetPrinterOptions().empty())
718 m_printerOptionsText
->SetValue(data
->GetPrinterOptions());
719 if (m_colourCheckBox
)
720 m_colourCheckBox
->SetValue(m_printData
.GetColour());
722 if (m_orientationRadioBox
)
724 if (m_printData
.GetOrientation() == wxPORTRAIT
)
725 m_orientationRadioBox
->SetSelection(0);
727 m_orientationRadioBox
->SetSelection(1);
732 bool wxGenericPrintSetupDialog::TransferDataFromWindow()
734 wxPostScriptPrintNativeData
*data
=
735 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
737 // find selected printer
738 long id
= m_printerListCtrl
->GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
741 m_printData
.SetPrinterName( wxEmptyString
);
747 item
.SetMask( wxLIST_MASK_TEXT
);
749 m_printerListCtrl
->GetItem( item
);
750 m_printData
.SetPrinterName( item
.GetText() );
753 if (m_printerCommandText
)
754 data
->SetPrinterCommand(m_printerCommandText
->GetValue());
755 if (m_printerOptionsText
)
756 data
->SetPrinterOptions(m_printerOptionsText
->GetValue());
757 if (m_colourCheckBox
)
758 m_printData
.SetColour(m_colourCheckBox
->GetValue());
759 if (m_orientationRadioBox
)
761 int sel
= m_orientationRadioBox
->GetSelection();
763 m_printData
.SetOrientation(wxPORTRAIT
);
765 m_printData
.SetOrientation(wxLANDSCAPE
);
767 if (m_paperTypeChoice
)
769 int selectedItem
= m_paperTypeChoice
->GetSelection();
770 if (selectedItem
!= -1)
772 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
774 m_printData
.SetPaperId( paper
->GetId());
779 *m_targetData
= m_printData
;
784 wxComboBox
*wxGenericPrintSetupDialog::CreatePaperTypeChoice()
786 size_t n
= wxThePrintPaperDatabase
->GetCount();
787 wxString
*choices
= new wxString
[n
];
790 for (size_t i
= 0; i
< n
; i
++)
792 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
793 choices
[i
] = paper
->GetName();
794 if (m_printData
.GetPaperId() == paper
->GetId())
800 wxComboBox
*choice
= new wxComboBox( this,
804 wxSize(width
, wxDefaultCoord
),
809 choice
->SetSelection(sel
);
813 #endif // wxUSE_POSTSCRIPT
815 // ----------------------------------------------------------------------------
816 // Generic page setup dialog
817 // ----------------------------------------------------------------------------
819 IMPLEMENT_CLASS(wxGenericPageSetupDialog
, wxPageSetupDialogBase
)
821 BEGIN_EVENT_TABLE(wxGenericPageSetupDialog
, wxPageSetupDialogBase
)
822 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPageSetupDialog::OnPrinter
)
825 wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow
*parent
,
826 wxPageSetupDialogData
* data
)
827 : wxPageSetupDialogBase( parent
,
832 wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
839 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
842 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
843 new wxStaticBox(this,wxPRINTID_STATIC
, _("Paper size")), wxHORIZONTAL
);
845 size_t n
= wxThePrintPaperDatabase
->GetCount();
846 wxString
*choices
= new wxString
[n
];
848 for (size_t i
= 0; i
< n
; i
++)
850 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
851 choices
[i
] = paper
->GetName();
854 m_paperTypeChoice
= new wxComboBox( this,
858 wxSize(300, wxDefaultCoord
),
860 topsizer
->Add( m_paperTypeChoice
, 1, wxEXPAND
|wxALL
, 5 );
861 // m_paperTypeChoice->SetSelection(sel);
863 mainsizer
->Add( topsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
865 // 2) middle sizer with radio box
867 wxString
*choices2
= new wxString
[2];
868 choices2
[0] = _("Portrait");
869 choices2
[1] = _("Landscape");
870 m_orientationRadioBox
= new wxRadioBox(this, wxPRINTID_ORIENTATION
, _("Orientation"),
871 wxDefaultPosition
, wxDefaultSize
, 2, choices2
, 2);
872 m_orientationRadioBox
->SetSelection(0);
874 mainsizer
->Add( m_orientationRadioBox
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 10 );
878 wxBoxSizer
*table
= new wxBoxSizer( wxHORIZONTAL
);
880 wxBoxSizer
*column1
= new wxBoxSizer( wxVERTICAL
);
881 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Left margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
882 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Top margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
883 table
->Add( column1
, 0, wxALL
| wxEXPAND
, 5 );
885 wxBoxSizer
*column2
= new wxBoxSizer( wxVERTICAL
);
886 m_marginLeftText
= new wxTextCtrl(this, wxPRINTID_LEFTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
887 m_marginTopText
= new wxTextCtrl(this, wxPRINTID_TOPMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
888 column2
->Add( m_marginLeftText
, 1, wxALL
, 5 );
889 column2
->Add( m_marginTopText
, 1, wxALL
, 5 );
890 table
->Add( column2
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
892 wxBoxSizer
*column3
= new wxBoxSizer( wxVERTICAL
);
893 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Right margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
894 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Bottom margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
895 table
->Add( column3
, 0, wxALL
| wxEXPAND
, 5 );
897 wxBoxSizer
*column4
= new wxBoxSizer( wxVERTICAL
);
898 m_marginRightText
= new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
899 m_marginBottomText
= new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
900 column4
->Add( m_marginRightText
, 1, wxALL
, 5 );
901 column4
->Add( m_marginBottomText
, 1, wxALL
, 5 );
902 table
->Add( column4
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
904 mainsizer
->Add( table
, 0 );
908 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
913 wxSizer
* buttonsizer
= CreateButtonSizer( wxOK
|wxCANCEL
);
915 if (wxPrintFactory::GetFactory()->HasPrintSetupDialog())
917 m_printerButton
= new wxButton(this, wxPRINTID_SETUP
, _("Printer...") );
918 buttonsizer
->Add( m_printerButton
, 0, wxLEFT
|wxRIGHT
, 10 );
919 if ( !m_pageData
.GetEnablePrinter() )
920 m_printerButton
->Enable(false);
924 m_printerButton
= NULL
;
927 // if (m_printData.GetEnableHelp())
928 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight);
929 mainsizer
->Add( buttonsizer
, 0, wxEXPAND
|wxALL
, 10 );
932 SetAutoLayout( true );
933 SetSizer( mainsizer
);
935 mainsizer
->Fit( this );
944 wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
948 wxPageSetupDialogData
& wxGenericPageSetupDialog::GetPageSetupDialogData()
953 bool wxGenericPageSetupDialog::TransferDataToWindow()
955 if (m_marginLeftText
)
956 m_marginLeftText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().x
));
958 m_marginTopText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().y
));
959 if (m_marginRightText
)
960 m_marginRightText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().x
));
961 if (m_marginBottomText
)
962 m_marginBottomText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().y
));
964 if (m_orientationRadioBox
)
966 if (m_pageData
.GetPrintData().GetOrientation() == wxPORTRAIT
)
967 m_orientationRadioBox
->SetSelection(0);
969 m_orientationRadioBox
->SetSelection(1);
972 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
973 // failing that, the id in the wxPrintData object.
975 wxPrintPaperType
* type
= wxThePrintPaperDatabase
->FindPaperType(
976 wxSize(m_pageData
.GetPaperSize().x
* 10, m_pageData
.GetPaperSize().y
* 10));
978 if (!type
&& m_pageData
.GetPrintData().GetPaperId() != wxPAPER_NONE
)
979 type
= wxThePrintPaperDatabase
->FindPaperType(m_pageData
.GetPrintData().GetPaperId());
983 m_paperTypeChoice
->SetStringSelection(type
->GetName());
989 bool wxGenericPageSetupDialog::TransferDataFromWindow()
991 if (m_marginLeftText
&& m_marginTopText
)
993 int left
= wxAtoi( m_marginLeftText
->GetValue().c_str() );
994 int top
= wxAtoi( m_marginTopText
->GetValue().c_str() );
995 m_pageData
.SetMarginTopLeft( wxPoint(left
,top
) );
997 if (m_marginRightText
&& m_marginBottomText
)
999 int right
= wxAtoi( m_marginRightText
->GetValue().c_str() );
1000 int bottom
= wxAtoi( m_marginBottomText
->GetValue().c_str() );
1001 m_pageData
.SetMarginBottomRight( wxPoint(right
,bottom
) );
1004 if (m_orientationRadioBox
)
1006 int sel
= m_orientationRadioBox
->GetSelection();
1009 m_pageData
.GetPrintData().SetOrientation(wxPORTRAIT
);
1013 m_pageData
.GetPrintData().SetOrientation(wxLANDSCAPE
);
1017 if (m_paperTypeChoice
)
1019 int selectedItem
= m_paperTypeChoice
->GetSelection();
1020 if (selectedItem
!= -1)
1022 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
1025 m_pageData
.SetPaperSize(wxSize(paper
->GetWidth()/10, paper
->GetHeight()/10));
1026 m_pageData
.GetPrintData().SetPaperId(paper
->GetId());
1034 wxComboBox
*wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x
, int *y
)
1037 if (!wxThePrintPaperDatabase)
1039 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
1040 wxThePrintPaperDatabase->CreateDatabase();
1044 size_t n
= wxThePrintPaperDatabase
->GetCount();
1045 wxString
*choices
= new wxString
[n
];
1047 for (size_t i
= 0; i
< n
; i
++)
1049 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
1050 choices
[i
] = paper
->GetName();
1053 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Paper size"), wxPoint(*x
, *y
));
1056 wxComboBox
*choice
= new wxComboBox( this,
1057 wxPRINTID_PAPERSIZE
,
1060 wxSize(300, wxDefaultCoord
),
1065 // choice->SetSelection(sel);
1069 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent
& WXUNUSED(event
))
1071 // We no longer query GetPrintMode, so we can eliminate the need
1072 // to call SetPrintMode.
1073 // This has the limitation that we can't explicitly call the PostScript
1074 // print setup dialog from the generic Page Setup dialog under Windows,
1075 // but since this choice would only happen when trying to do PostScript
1076 // printing under Windows (and only in 16-bit Windows which
1077 // doesn't have a Windows-specific page setup dialog) it's worth it.
1079 // First save the current settings, so the wxPrintData object is up to date.
1080 TransferDataFromWindow();
1082 // Transfer the current print settings from this dialog to the page setup dialog.
1085 // Use print factory later
1087 wxPrintDialogData data
;
1088 data
= GetPageSetupData().GetPrintData();
1089 data
.SetSetupDialog(true);
1090 wxPrintDialog
printDialog(this, & data
);
1091 printDialog
.ShowModal();
1093 // Transfer the page setup print settings from the page dialog to this dialog again, in case
1094 // the page setup dialog changed something.
1095 GetPageSetupData().GetPrintData() = printDialog
.GetPrintDialogData().GetPrintData();
1096 GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData
1098 // Now update the dialog in case the page setup dialog changed some of our settings.
1099 TransferDataToWindow();