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)
32 #include "wx/stattext.h"
33 #include "wx/statbox.h"
34 #include "wx/button.h"
35 #include "wx/checkbox.h"
36 #include "wx/textctrl.h"
37 #include "wx/radiobox.h"
38 #include "wx/filedlg.h"
39 #include "wx/combobox.h"
42 #include "wx/cmndata.h"
46 #include "wx/statline.h"
49 #include "wx/generic/prntdlgg.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
66 #include "wx/html/forcelnk.h"
67 FORCE_LINK(gnome_print
)
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 extern wxPrintPaperDatabase
*wxThePrintPaperDatabase
;
78 //----------------------------------------------------------------------------
79 // wxPostScriptNativeData
80 //----------------------------------------------------------------------------
82 IMPLEMENT_CLASS(wxPostScriptPrintNativeData
, wxPrintNativeDataBase
)
84 wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
86 m_previewCommand
= wxEmptyString
;
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
= wxEmptyString
;
96 m_afmPath
= wxT("c:\\windows\\system\\");
99 #if !defined(__VMS__) && !defined(__WXMSW__)
100 m_printerCommand
= wxT("lpr");
101 m_printerOptions
= wxEmptyString
;
102 m_afmPath
= wxEmptyString
;
105 m_printerScaleX
= 1.0;
106 m_printerScaleY
= 1.0;
107 m_printerTranslateX
= 0;
108 m_printerTranslateY
= 0;
111 wxPostScriptPrintNativeData::~wxPostScriptPrintNativeData()
115 bool wxPostScriptPrintNativeData::TransferTo( wxPrintData
&WXUNUSED(data
) )
120 bool wxPostScriptPrintNativeData::TransferFrom( const wxPrintData
&WXUNUSED(data
) )
125 // ----------------------------------------------------------------------------
126 // Generic print dialog for non-Windows printing use.
127 // ----------------------------------------------------------------------------
129 IMPLEMENT_CLASS(wxGenericPrintDialog
, wxPrintDialogBase
)
131 BEGIN_EVENT_TABLE(wxGenericPrintDialog
, wxPrintDialogBase
)
132 EVT_BUTTON(wxID_OK
, wxGenericPrintDialog::OnOK
)
133 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPrintDialog::OnSetup
)
134 EVT_RADIOBOX(wxPRINTID_RANGE
, wxGenericPrintDialog::OnRange
)
137 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
,
138 wxPrintDialogData
* data
)
139 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
140 wxPoint(0,0), wxSize(600, 600),
141 wxDEFAULT_DIALOG_STYLE
|
145 m_printDialogData
= *data
;
150 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
,
152 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
153 wxPoint(0,0), wxSize(600, 600),
154 wxDEFAULT_DIALOG_STYLE
|
158 m_printDialogData
= *data
;
163 void wxGenericPrintDialog::Init(wxWindow
* WXUNUSED(parent
))
165 // wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0,0), wxSize(600, 600),
166 // wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL);
168 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
172 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
174 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
175 new wxStaticBox( this, wxID_ANY
, _( "Printer options" ) ), wxHORIZONTAL
);
176 wxFlexGridSizer
*flex
= new wxFlexGridSizer( 2 );
177 flex
->AddGrowableCol( 1 );
178 topsizer
->Add( flex
, 1, wxGROW
);
180 m_printToFileCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTTOFILE
, _("Print to File") );
181 flex
->Add( m_printToFileCheckBox
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
183 m_setupButton
= new wxButton(this, wxPRINTID_SETUP
, _("Setup...") );
184 flex
->Add( m_setupButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALIGN_RIGHT
|wxALL
, 5 );
186 if (!factory
->HasPrintSetupDialog())
187 m_setupButton
->Enable( false );
189 if (factory
->HasPrinterLine())
191 flex
->Add( new wxStaticText( this, wxID_ANY
, _("Printer:") ),
192 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
193 flex
->Add( new wxStaticText( this, wxID_ANY
, factory
->CreatePrinterLine() ),
194 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
197 if (factory
->HasStatusLine())
199 flex
->Add( new wxStaticText( this, wxID_ANY
, _("Status:") ),
200 0, wxALIGN_CENTER_VERTICAL
|wxALL
-wxTOP
, 5 );
201 flex
->Add( new wxStaticText( this, wxID_ANY
, factory
->CreateStatusLine() ),
202 0, wxALIGN_CENTER_VERTICAL
|wxALL
-wxTOP
, 5 );
205 mainsizer
->Add( topsizer
, 0, wxLEFT
|wxTOP
|wxRIGHT
|wxGROW
, 10 );
207 // 2) middle row with radio box
209 wxString
*choices
= new wxString
[2];
210 choices
[0] = _("All");
211 choices
[1] = _("Pages");
213 m_fromText
= (wxTextCtrl
*)NULL
;
214 m_toText
= (wxTextCtrl
*)NULL
;
215 m_rangeRadioBox
= (wxRadioBox
*)NULL
;
217 if (m_printDialogData
.GetFromPage() != 0)
219 m_rangeRadioBox
= new wxRadioBox(this, wxPRINTID_RANGE
, _("Print Range"),
220 wxDefaultPosition
, wxDefaultSize
,
223 m_rangeRadioBox
->SetSelection(1);
225 mainsizer
->Add( m_rangeRadioBox
, 0, wxLEFT
|wxTOP
|wxRIGHT
, 10 );
230 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
232 if (m_printDialogData
.GetFromPage() != 0)
234 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("From:") ), 0, wxCENTER
|wxALL
, 5 );
235 m_fromText
= new wxTextCtrl(this, wxPRINTID_FROM
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
236 bottomsizer
->Add( m_fromText
, 1, wxCENTER
|wxRIGHT
, 10 );
238 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("To:") ), 0, wxCENTER
|wxALL
, 5);
239 m_toText
= new wxTextCtrl(this, wxPRINTID_TO
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
240 bottomsizer
->Add( m_toText
, 1, wxCENTER
|wxRIGHT
, 10 );
243 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Copies:") ), 0, wxCENTER
|wxALL
, 5 );
244 m_noCopiesText
= new wxTextCtrl(this, wxPRINTID_COPIES
, wxEmptyString
, wxPoint(252, 130), wxSize(40, wxDefaultCoord
));
245 bottomsizer
->Add( m_noCopiesText
, 1, wxCENTER
|wxRIGHT
, 10 );
247 mainsizer
->Add( bottomsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 12 );
251 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
256 mainsizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxEXPAND
|wxALL
, 10 );
258 SetAutoLayout( true );
259 SetSizer( mainsizer
);
261 mainsizer
->Fit( this );
264 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
269 int wxGenericPrintDialog::ShowModal()
271 return wxDialog::ShowModal();
274 wxGenericPrintDialog::~wxGenericPrintDialog()
278 void wxGenericPrintDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
280 TransferDataFromWindow();
282 // An empty 'to' field signals printing just the
284 if (m_printDialogData
.GetToPage() < 1)
285 m_printDialogData
.SetToPage(m_printDialogData
.GetFromPage());
287 // There are some interactions between the global setup data
288 // and the standard print dialog. The global printing 'mode'
289 // is determined by whether the user checks Print to file
291 if (m_printDialogData
.GetPrintToFile())
293 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE
);
295 wxFileName
fname( m_printDialogData
.GetPrintData().GetFilename() );
297 wxFileDialog
dialog( this, _("PostScript file"),
298 fname
.GetPath(), fname
.GetFullName(), wxT("*.ps"), wxFD_SAVE
| wxFD_OVERWRITE_PROMPT
);
299 if (dialog
.ShowModal() != wxID_OK
) return;
301 m_printDialogData
.GetPrintData().SetFilename( dialog
.GetPath() );
305 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER
);
311 void wxGenericPrintDialog::OnRange(wxCommandEvent
& event
)
313 if (!m_fromText
) return;
315 if (event
.GetInt() == 0)
317 m_fromText
->Enable(false);
318 m_toText
->Enable(false);
320 else if (event
.GetInt() == 1)
322 m_fromText
->Enable(true);
323 m_toText
->Enable(true);
327 void wxGenericPrintDialog::OnSetup(wxCommandEvent
& WXUNUSED(event
))
329 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
331 if (factory
->HasPrintSetupDialog())
333 // The print setup dialog should change the
334 // print data in-place if not cancelled.
335 wxDialog
*dialog
= factory
->CreatePrintSetupDialog( this, &m_printDialogData
.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)
405 m_printDialogData
.SetAllPages(true);
407 // This means all pages, more or less
408 m_printDialogData
.SetFromPage(1);
409 m_printDialogData
.SetToPage(32000);
412 m_printDialogData
.SetAllPages(false);
416 { // continuous printing
417 m_printDialogData
.SetFromPage(1);
418 m_printDialogData
.SetToPage(32000);
421 wxString value
= m_noCopiesText
->GetValue();
422 if (value
.ToLong( &res
))
423 m_printDialogData
.SetNoCopies( res
);
425 m_printDialogData
.SetPrintToFile(m_printToFileCheckBox
->GetValue());
430 wxDC
*wxGenericPrintDialog::GetPrintDC()
432 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
435 // ----------------------------------------------------------------------------
436 // Generic print setup dialog
437 // ----------------------------------------------------------------------------
439 IMPLEMENT_CLASS(wxGenericPrintSetupDialog
, wxDialog
)
441 BEGIN_EVENT_TABLE(wxGenericPrintSetupDialog
, wxDialog
)
442 EVT_LIST_ITEM_ACTIVATED(wxPRINTID_PRINTER
, wxGenericPrintSetupDialog::OnPrinter
)
445 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow
*parent
, wxPrintData
* data
):
446 wxDialog(parent
, wxID_ANY
, _("Print Setup"), wxPoint(0,0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
452 static const char * check_xpm
[] = {
453 /* width height ncolors chars_per_pixel */
479 void wxGenericPrintSetupDialog::Init(wxPrintData
* data
)
486 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
490 wxStaticBoxSizer
*printer_sizer
= new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY
, _("Printer") ), wxVERTICAL
);
491 main_sizer
->Add( printer_sizer
, 0, wxALL
|wxGROW
, 10 );
493 m_printerListCtrl
= new wxListCtrl( this, wxPRINTID_PRINTER
,
494 wxDefaultPosition
, wxSize(wxDefaultCoord
,100), wxLC_REPORT
|wxLC_SINGLE_SEL
|wxSUNKEN_BORDER
);
495 wxImageList
*image_list
= new wxImageList
;
496 image_list
->Add( wxBitmap(check_xpm
) );
497 m_printerListCtrl
->AssignImageList( image_list
, wxIMAGE_LIST_SMALL
);
499 m_printerListCtrl
->InsertColumn( 0, wxT(" "), wxLIST_FORMAT_LEFT
, 20 );
500 m_printerListCtrl
->InsertColumn( 1, wxT("Printer"), wxLIST_FORMAT_LEFT
, 150 );
501 m_printerListCtrl
->InsertColumn( 2, wxT("Device"), wxLIST_FORMAT_LEFT
, 150 );
502 m_printerListCtrl
->InsertColumn( 3, wxT("Status"), wxLIST_FORMAT_LEFT
, 80 );
505 item
.SetMask( wxLIST_MASK_TEXT
);
507 item
.SetText( _("Default printer") );
508 item
.SetId( m_printerListCtrl
->InsertItem( item
) );
510 if (data
->GetPrinterName().empty())
513 item2
.SetId( item
.GetId() );
514 item2
.SetMask( wxLIST_MASK_IMAGE
);
516 m_printerListCtrl
->SetItem( item2
);
518 m_printerListCtrl
->SetItemState( item
.GetId(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
521 item
.SetId( 1+ item
.GetId() );
523 wxArrayString errors
;
524 wxArrayString output
;
525 long res
= wxExecute( wxT("lpstat -v"), output
, errors
, wxEXEC_NODISABLE
);
526 if (res
>= 0 && errors
.GetCount() == 0)
529 for (i
= 0; i
< output
.GetCount(); i
++)
531 wxStringTokenizer
tok( output
[i
], wxT(" ") );
532 wxString tmp
= tok
.GetNextToken(); // "device"
533 if (tmp
!= wxT("device"))
534 break; // the lpstat syntax must have changed.
535 tmp
= tok
.GetNextToken(); // "for"
536 if (tmp
!= wxT("for"))
537 break; // the lpstat syntax must have changed.
538 tmp
= tok
.GetNextToken(); // "hp_deskjet930c:"
539 if (tmp
[tmp
.length()-1] == wxT(':'))
540 tmp
.Remove(tmp
.length()-1,1);
542 item
.SetText( name
);
543 item
.SetId( m_printerListCtrl
->InsertItem( item
) );
544 tmp
= tok
.GetNextToken(); // "parallel:/dev/lp0"
547 m_printerListCtrl
->SetItem( item
);
548 if (data
->GetPrinterName() == name
)
551 item2
.SetId( item
.GetId() );
552 item2
.SetMask( wxLIST_MASK_IMAGE
);
554 m_printerListCtrl
->SetItem( item2
);
556 m_printerListCtrl
->SetItemState( item
.GetId(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
559 wxString command
= wxT("lpstat -p ");
561 wxArrayString errors2
;
562 wxArrayString output2
;
563 res
= wxExecute( command
, output2
, errors2
, wxEXEC_NODISABLE
);
564 if (res
>= 0 && errors2
.GetCount() == 0 && output2
.GetCount() > 0)
566 tmp
= output2
[0]; // "printer hp_deskjet930c is idle. enable since ..."
567 int pos
= tmp
.Find( wxT('.') );
568 if (pos
!= wxNOT_FOUND
)
569 tmp
.Remove( (size_t)pos
, tmp
.length()-(size_t)pos
);
570 wxStringTokenizer
tok2( tmp
, wxT(" ") );
571 tmp
= tok2
.GetNextToken(); // "printer"
572 tmp
= tok2
.GetNextToken(); // "hp_deskjet930c"
574 while (tok2
.HasMoreTokens())
576 tmp
+= tok2
.GetNextToken();
581 m_printerListCtrl
->SetItem( item
);
585 item
.SetId( 1+ item
.GetId() );
590 printer_sizer
->Add( m_printerListCtrl
, 0, wxALL
|wxGROW
, 5 );
592 wxBoxSizer
*item1
= new wxBoxSizer( wxHORIZONTAL
);
593 main_sizer
->Add( item1
, 0, wxALL
, 5 );
595 // printer options (on the left)
597 wxBoxSizer
*item2
= new wxBoxSizer( wxVERTICAL
);
599 wxStaticBox
*item4
= new wxStaticBox( this, wxPRINTID_STATIC
, _("Paper size") );
600 wxStaticBoxSizer
*item3
= new wxStaticBoxSizer( item4
, wxVERTICAL
);
602 m_paperTypeChoice
= CreatePaperTypeChoice();
603 item3
->Add( m_paperTypeChoice
, 0, wxALIGN_CENTER
|wxALL
, 5 );
605 item2
->Add( item3
, 0, wxALIGN_CENTER
|wxALL
, 5 );
612 m_orientationRadioBox
= new wxRadioBox( this, wxPRINTID_ORIENTATION
, _("Orientation"), wxDefaultPosition
, wxDefaultSize
, 2, strs6
, 1, wxRA_SPECIFY_ROWS
);
613 item2
->Add( m_orientationRadioBox
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
615 wxStaticBox
*item8
= new wxStaticBox( this, wxID_ANY
, _("Options") );
616 wxStaticBoxSizer
*item7
= new wxStaticBoxSizer( item8
, wxHORIZONTAL
);
618 m_colourCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTCOLOUR
, _("Print in colour") );
619 item7
->Add( m_colourCheckBox
, 0, wxALIGN_CENTER
|wxALL
, 5 );
621 item2
->Add( item7
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
623 item1
->Add( item2
, 0, wxALIGN_CENTER_HORIZONTAL
, 5 );
625 // spooling options (on the right)
627 wxStaticBox
*item11
= new wxStaticBox( this, wxID_ANY
, _("Print spooling") );
628 wxStaticBoxSizer
*item10
= new wxStaticBoxSizer( item11
, wxVERTICAL
);
630 wxStaticText
*item12
= new wxStaticText( this, wxID_ANY
, _("Printer command:") );
631 item10
->Add( item12
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
633 wxBoxSizer
*item13
= new wxBoxSizer( wxHORIZONTAL
);
635 item13
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
637 m_printerCommandText
= new wxTextCtrl( this, wxPRINTID_COMMAND
, wxEmptyString
, wxDefaultPosition
, wxSize(160,wxDefaultCoord
) );
638 item13
->Add( m_printerCommandText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
640 item10
->Add( item13
, 0, wxALIGN_CENTER
|wxALL
, 0 );
642 wxStaticText
*item15
= new wxStaticText( this, wxID_ANY
, _("Printer options:") );
643 item10
->Add( item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
645 wxBoxSizer
*item16
= new wxBoxSizer( wxHORIZONTAL
);
647 item16
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
649 m_printerOptionsText
= new wxTextCtrl( this, wxPRINTID_OPTIONS
, wxEmptyString
, wxDefaultPosition
, wxSize(160,wxDefaultCoord
) );
650 item16
->Add( m_printerOptionsText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
652 item10
->Add( item16
, 0, wxALIGN_CENTER
|wxALL
, 0 );
654 item1
->Add( item10
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5 );
659 main_sizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
664 main_sizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxEXPAND
|wxALL
, 10 );
666 SetAutoLayout( true );
667 SetSizer( main_sizer
);
669 main_sizer
->Fit( this );
679 wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
683 void wxGenericPrintSetupDialog::OnPrinter(wxListEvent
& event
)
686 for (long item
= 0; item
< m_printerListCtrl
->GetItemCount(); item
++)
687 m_printerListCtrl
->SetItemImage( item
, -1 );
689 m_printerListCtrl
->SetItemImage( event
.GetIndex(), 0 );
691 if (event
.GetIndex() == 0)
693 m_printerCommandText
->SetValue( wxT("lpr") );
699 li
.SetMask( wxLIST_MASK_TEXT
);
700 li
.SetId( event
.GetIndex() );
701 m_printerListCtrl
->GetItem( li
);
702 m_printerCommandText
->SetValue( _T("lpr -P") + li
.GetText() );
706 bool wxGenericPrintSetupDialog::TransferDataToWindow()
708 wxPostScriptPrintNativeData
*data
=
709 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
711 if (m_printerCommandText
&& data
->GetPrinterCommand())
712 m_printerCommandText
->SetValue(data
->GetPrinterCommand());
713 if (m_printerOptionsText
&& data
->GetPrinterOptions())
714 m_printerOptionsText
->SetValue(data
->GetPrinterOptions());
715 if (m_colourCheckBox
)
716 m_colourCheckBox
->SetValue(m_printData
.GetColour());
718 if (m_orientationRadioBox
)
720 if (m_printData
.GetOrientation() == wxPORTRAIT
)
721 m_orientationRadioBox
->SetSelection(0);
723 m_orientationRadioBox
->SetSelection(1);
728 bool wxGenericPrintSetupDialog::TransferDataFromWindow()
730 wxPostScriptPrintNativeData
*data
=
731 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
733 // find selected printer
734 long id
= m_printerListCtrl
->GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
737 m_printData
.SetPrinterName( wxEmptyString
);
743 item
.SetMask( wxLIST_MASK_TEXT
);
745 m_printerListCtrl
->GetItem( item
);
746 m_printData
.SetPrinterName( item
.GetText() );
749 if (m_printerCommandText
)
750 data
->SetPrinterCommand(m_printerCommandText
->GetValue());
751 if (m_printerOptionsText
)
752 data
->SetPrinterOptions(m_printerOptionsText
->GetValue());
753 if (m_colourCheckBox
)
754 m_printData
.SetColour(m_colourCheckBox
->GetValue());
755 if (m_orientationRadioBox
)
757 int sel
= m_orientationRadioBox
->GetSelection();
759 m_printData
.SetOrientation(wxPORTRAIT
);
761 m_printData
.SetOrientation(wxLANDSCAPE
);
763 if (m_paperTypeChoice
)
765 int selectedItem
= m_paperTypeChoice
->GetSelection();
766 if (selectedItem
!= -1)
768 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
770 m_printData
.SetPaperId( paper
->GetId());
775 *m_targetData
= m_printData
;
780 wxComboBox
*wxGenericPrintSetupDialog::CreatePaperTypeChoice()
782 size_t n
= wxThePrintPaperDatabase
->GetCount();
783 wxString
*choices
= new wxString
[n
];
786 for (size_t i
= 0; i
< n
; i
++)
788 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
789 choices
[i
] = paper
->GetName();
790 if (m_printData
.GetPaperId() == paper
->GetId())
796 wxComboBox
*choice
= new wxComboBox( this,
800 wxSize(width
, wxDefaultCoord
),
805 choice
->SetSelection(sel
);
809 #endif // wxUSE_POSTSCRIPT
811 // ----------------------------------------------------------------------------
812 // Generic page setup dialog
813 // ----------------------------------------------------------------------------
815 IMPLEMENT_CLASS(wxGenericPageSetupDialog
, wxPageSetupDialogBase
)
817 BEGIN_EVENT_TABLE(wxGenericPageSetupDialog
, wxPageSetupDialogBase
)
818 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPageSetupDialog::OnPrinter
)
821 wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow
*parent
,
822 wxPageSetupDialogData
* data
)
823 : wxPageSetupDialogBase( parent
,
828 wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
835 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
838 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
839 new wxStaticBox(this,wxPRINTID_STATIC
, _("Paper size")), wxHORIZONTAL
);
841 size_t n
= wxThePrintPaperDatabase
->GetCount();
842 wxString
*choices
= new wxString
[n
];
844 for (size_t i
= 0; i
< n
; i
++)
846 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
847 choices
[i
] = paper
->GetName();
850 m_paperTypeChoice
= new wxComboBox( this,
854 wxSize(300, wxDefaultCoord
),
856 topsizer
->Add( m_paperTypeChoice
, 1, wxEXPAND
|wxALL
, 5 );
857 // m_paperTypeChoice->SetSelection(sel);
859 mainsizer
->Add( topsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
861 // 2) middle sizer with radio box
863 wxString
*choices2
= new wxString
[2];
864 choices2
[0] = _("Portrait");
865 choices2
[1] = _("Landscape");
866 m_orientationRadioBox
= new wxRadioBox(this, wxPRINTID_ORIENTATION
, _("Orientation"),
867 wxDefaultPosition
, wxDefaultSize
, 2, choices2
, 2);
868 m_orientationRadioBox
->SetSelection(0);
870 mainsizer
->Add( m_orientationRadioBox
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 10 );
874 wxBoxSizer
*table
= new wxBoxSizer( wxHORIZONTAL
);
876 wxBoxSizer
*column1
= new wxBoxSizer( wxVERTICAL
);
877 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Left margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
878 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Top margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
879 table
->Add( column1
, 0, wxALL
| wxEXPAND
, 5 );
881 wxBoxSizer
*column2
= new wxBoxSizer( wxVERTICAL
);
882 m_marginLeftText
= new wxTextCtrl(this, wxPRINTID_LEFTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
883 m_marginTopText
= new wxTextCtrl(this, wxPRINTID_TOPMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
884 column2
->Add( m_marginLeftText
, 1, wxALL
, 5 );
885 column2
->Add( m_marginTopText
, 1, wxALL
, 5 );
886 table
->Add( column2
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
888 wxBoxSizer
*column3
= new wxBoxSizer( wxVERTICAL
);
889 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Right margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
890 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Bottom margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
891 table
->Add( column3
, 0, wxALL
| wxEXPAND
, 5 );
893 wxBoxSizer
*column4
= new wxBoxSizer( wxVERTICAL
);
894 m_marginRightText
= new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
895 m_marginBottomText
= new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
896 column4
->Add( m_marginRightText
, 1, wxALL
, 5 );
897 column4
->Add( m_marginBottomText
, 1, wxALL
, 5 );
898 table
->Add( column4
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
900 mainsizer
->Add( table
, 0 );
904 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
909 wxSizer
* buttonsizer
= CreateButtonSizer( wxOK
|wxCANCEL
);
911 if (wxPrintFactory::GetFactory()->HasPrintSetupDialog())
913 m_printerButton
= new wxButton(this, wxPRINTID_SETUP
, _("Printer...") );
914 buttonsizer
->Add( m_printerButton
, 0, wxLEFT
|wxRIGHT
, 10 );
915 if ( !m_pageData
.GetEnablePrinter() )
916 m_printerButton
->Enable(false);
920 m_printerButton
= NULL
;
923 // if (m_printData.GetEnableHelp())
924 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight);
925 mainsizer
->Add( buttonsizer
, 0, wxEXPAND
|wxALL
, 10 );
928 SetAutoLayout( true );
929 SetSizer( mainsizer
);
931 mainsizer
->Fit( this );
940 wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
944 wxPageSetupDialogData
& wxGenericPageSetupDialog::GetPageSetupDialogData()
949 bool wxGenericPageSetupDialog::TransferDataToWindow()
951 if (m_marginLeftText
)
952 m_marginLeftText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().x
));
954 m_marginTopText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().y
));
955 if (m_marginRightText
)
956 m_marginRightText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().x
));
957 if (m_marginBottomText
)
958 m_marginBottomText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().y
));
960 if (m_orientationRadioBox
)
962 if (m_pageData
.GetPrintData().GetOrientation() == wxPORTRAIT
)
963 m_orientationRadioBox
->SetSelection(0);
965 m_orientationRadioBox
->SetSelection(1);
968 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
969 // failing that, the id in the wxPrintData object.
971 wxPrintPaperType
* type
= wxThePrintPaperDatabase
->FindPaperType(
972 wxSize(m_pageData
.GetPaperSize().x
* 10, m_pageData
.GetPaperSize().y
* 10));
974 if (!type
&& m_pageData
.GetPrintData().GetPaperId() != wxPAPER_NONE
)
975 type
= wxThePrintPaperDatabase
->FindPaperType(m_pageData
.GetPrintData().GetPaperId());
979 m_paperTypeChoice
->SetStringSelection(type
->GetName());
985 bool wxGenericPageSetupDialog::TransferDataFromWindow()
987 if (m_marginLeftText
&& m_marginTopText
)
989 int left
= wxAtoi( m_marginLeftText
->GetValue().c_str() );
990 int top
= wxAtoi( m_marginTopText
->GetValue().c_str() );
991 m_pageData
.SetMarginTopLeft( wxPoint(left
,top
) );
993 if (m_marginRightText
&& m_marginBottomText
)
995 int right
= wxAtoi( m_marginRightText
->GetValue().c_str() );
996 int bottom
= wxAtoi( m_marginBottomText
->GetValue().c_str() );
997 m_pageData
.SetMarginBottomRight( wxPoint(right
,bottom
) );
1000 if (m_orientationRadioBox
)
1002 int sel
= m_orientationRadioBox
->GetSelection();
1005 m_pageData
.GetPrintData().SetOrientation(wxPORTRAIT
);
1009 m_pageData
.GetPrintData().SetOrientation(wxLANDSCAPE
);
1013 if (m_paperTypeChoice
)
1015 int selectedItem
= m_paperTypeChoice
->GetSelection();
1016 if (selectedItem
!= -1)
1018 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
1021 m_pageData
.SetPaperSize(wxSize(paper
->GetWidth()/10, paper
->GetHeight()/10));
1022 m_pageData
.GetPrintData().SetPaperId(paper
->GetId());
1030 wxComboBox
*wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x
, int *y
)
1033 if (!wxThePrintPaperDatabase)
1035 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
1036 wxThePrintPaperDatabase->CreateDatabase();
1040 size_t n
= wxThePrintPaperDatabase
->GetCount();
1041 wxString
*choices
= new wxString
[n
];
1043 for (size_t i
= 0; i
< n
; i
++)
1045 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
1046 choices
[i
] = paper
->GetName();
1049 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Paper size"), wxPoint(*x
, *y
));
1052 wxComboBox
*choice
= new wxComboBox( this,
1053 wxPRINTID_PAPERSIZE
,
1056 wxSize(300, wxDefaultCoord
),
1061 // choice->SetSelection(sel);
1065 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent
& WXUNUSED(event
))
1067 // We no longer query GetPrintMode, so we can eliminate the need
1068 // to call SetPrintMode.
1069 // This has the limitation that we can't explicitly call the PostScript
1070 // print setup dialog from the generic Page Setup dialog under Windows,
1071 // but since this choice would only happen when trying to do PostScript
1072 // printing under Windows (and only in 16-bit Windows which
1073 // doesn't have a Windows-specific page setup dialog) it's worth it.
1075 // First save the current settings, so the wxPrintData object is up to date.
1076 TransferDataFromWindow();
1078 // Transfer the current print settings from this dialog to the page setup dialog.
1081 // Use print factory later
1083 wxPrintDialogData data
;
1084 data
= GetPageSetupData().GetPrintData();
1085 data
.SetSetupDialog(true);
1086 wxPrintDialog
printDialog(this, & data
);
1087 printDialog
.ShowModal();
1089 // Transfer the page setup print settings from the page dialog to this dialog again, in case
1090 // the page setup dialog changed something.
1091 GetPageSetupData().GetPrintData() = printDialog
.GetPrintDialogData().GetPrintData();
1092 GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData
1094 // Now update the dialog in case the page setup dialog changed some of our settings.
1095 TransferDataToWindow();