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
)
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 wxSizer
*sizerBtn
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
253 mainsizer
->Add(sizerBtn
, 0, wxEXPAND
|wxALL
, 10 );
255 SetAutoLayout( true );
256 SetSizer( mainsizer
);
258 mainsizer
->Fit( this );
261 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
266 int wxGenericPrintDialog::ShowModal()
268 return wxDialog::ShowModal();
271 wxGenericPrintDialog::~wxGenericPrintDialog()
275 void wxGenericPrintDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
277 TransferDataFromWindow();
279 // An empty 'to' field signals printing just the
281 if (m_printDialogData
.GetToPage() < 1)
282 m_printDialogData
.SetToPage(m_printDialogData
.GetFromPage());
284 // There are some interactions between the global setup data
285 // and the standard print dialog. The global printing 'mode'
286 // is determined by whether the user checks Print to file
288 if (m_printDialogData
.GetPrintToFile())
290 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE
);
292 wxFileName
fname( m_printDialogData
.GetPrintData().GetFilename() );
294 wxFileDialog
dialog( this, _("PostScript file"),
295 fname
.GetPath(), fname
.GetFullName(), wxT("*.ps"), wxFD_SAVE
| wxFD_OVERWRITE_PROMPT
);
296 if (dialog
.ShowModal() != wxID_OK
) return;
298 m_printDialogData
.GetPrintData().SetFilename( dialog
.GetPath() );
302 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER
);
308 void wxGenericPrintDialog::OnRange(wxCommandEvent
& event
)
310 if (!m_fromText
) return;
312 if (event
.GetInt() == 0)
314 m_fromText
->Enable(false);
315 m_toText
->Enable(false);
317 else if (event
.GetInt() == 1)
319 m_fromText
->Enable(true);
320 m_toText
->Enable(true);
324 void wxGenericPrintDialog::OnSetup(wxCommandEvent
& WXUNUSED(event
))
326 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
328 if (factory
->HasPrintSetupDialog())
330 // The print setup dialog should change the
331 // print data in-place if not cancelled.
332 wxDialog
*dialog
= factory
->CreatePrintSetupDialog( this, &m_printDialogData
.GetPrintData() );
338 bool wxGenericPrintDialog::TransferDataToWindow()
340 if(m_printDialogData
.GetFromPage() != 0)
344 if (m_printDialogData
.GetEnablePageNumbers())
346 m_fromText
->Enable(true);
347 m_toText
->Enable(true);
348 if (m_printDialogData
.GetFromPage() > 0)
349 m_fromText
->SetValue(wxString::Format(_T("%d"), m_printDialogData
.GetFromPage()));
350 if (m_printDialogData
.GetToPage() > 0)
351 m_toText
->SetValue(wxString::Format(_T("%d"), m_printDialogData
.GetToPage()));
353 if (m_printDialogData
.GetAllPages() || m_printDialogData
.GetFromPage() == 0)
354 m_rangeRadioBox
->SetSelection(0);
356 m_rangeRadioBox
->SetSelection(1);
360 m_fromText
->Enable(false);
361 m_toText
->Enable(false);
364 m_rangeRadioBox
->SetSelection(0);
365 m_rangeRadioBox
->wxRadioBox::Enable(1, false);
370 m_noCopiesText
->SetValue(
371 wxString::Format(_T("%d"), m_printDialogData
.GetNoCopies()));
373 m_printToFileCheckBox
->SetValue(m_printDialogData
.GetPrintToFile());
374 m_printToFileCheckBox
->Enable(m_printDialogData
.GetEnablePrintToFile());
378 bool wxGenericPrintDialog::TransferDataFromWindow()
381 if(m_printDialogData
.GetFromPage() != -1)
383 if (m_printDialogData
.GetEnablePageNumbers())
387 wxString value
= m_fromText
->GetValue();
388 if (value
.ToLong( &res
))
389 m_printDialogData
.SetFromPage( res
);
393 wxString value
= m_toText
->GetValue();
394 if (value
.ToLong( &res
))
395 m_printDialogData
.SetToPage( res
);
400 if (m_rangeRadioBox
->GetSelection() == 0)
402 m_printDialogData
.SetAllPages(true);
404 // This means all pages, more or less
405 m_printDialogData
.SetFromPage(1);
406 m_printDialogData
.SetToPage(32000);
409 m_printDialogData
.SetAllPages(false);
413 { // continuous printing
414 m_printDialogData
.SetFromPage(1);
415 m_printDialogData
.SetToPage(32000);
418 wxString value
= m_noCopiesText
->GetValue();
419 if (value
.ToLong( &res
))
420 m_printDialogData
.SetNoCopies( res
);
422 m_printDialogData
.SetPrintToFile(m_printToFileCheckBox
->GetValue());
427 wxDC
*wxGenericPrintDialog::GetPrintDC()
429 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
432 // ----------------------------------------------------------------------------
433 // Generic print setup dialog
434 // ----------------------------------------------------------------------------
436 IMPLEMENT_CLASS(wxGenericPrintSetupDialog
, wxDialog
)
438 BEGIN_EVENT_TABLE(wxGenericPrintSetupDialog
, wxDialog
)
439 EVT_LIST_ITEM_ACTIVATED(wxPRINTID_PRINTER
, wxGenericPrintSetupDialog::OnPrinter
)
442 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow
*parent
, wxPrintData
* data
):
443 wxDialog(parent
, wxID_ANY
, _("Print Setup"), wxPoint(0,0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
449 static const char * check_xpm
[] = {
450 /* width height ncolors chars_per_pixel */
476 void wxGenericPrintSetupDialog::Init(wxPrintData
* data
)
483 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
487 wxStaticBoxSizer
*printer_sizer
= new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY
, _("Printer") ), wxVERTICAL
);
488 main_sizer
->Add( printer_sizer
, 0, wxALL
|wxGROW
, 10 );
490 m_printerListCtrl
= new wxListCtrl( this, wxPRINTID_PRINTER
,
491 wxDefaultPosition
, wxSize(wxDefaultCoord
,100), wxLC_REPORT
|wxLC_SINGLE_SEL
|wxSUNKEN_BORDER
);
492 wxImageList
*image_list
= new wxImageList
;
493 image_list
->Add( wxBitmap(check_xpm
) );
494 m_printerListCtrl
->AssignImageList( image_list
, wxIMAGE_LIST_SMALL
);
496 m_printerListCtrl
->InsertColumn( 0, wxT(" "), wxLIST_FORMAT_LEFT
, 20 );
497 m_printerListCtrl
->InsertColumn( 1, wxT("Printer"), wxLIST_FORMAT_LEFT
, 150 );
498 m_printerListCtrl
->InsertColumn( 2, wxT("Device"), wxLIST_FORMAT_LEFT
, 150 );
499 m_printerListCtrl
->InsertColumn( 3, wxT("Status"), wxLIST_FORMAT_LEFT
, 80 );
502 item
.SetMask( wxLIST_MASK_TEXT
);
504 item
.SetText( _("Default printer") );
505 item
.SetId( m_printerListCtrl
->InsertItem( item
) );
507 if (data
->GetPrinterName().empty())
510 item2
.SetId( item
.GetId() );
511 item2
.SetMask( wxLIST_MASK_IMAGE
);
513 m_printerListCtrl
->SetItem( item2
);
515 m_printerListCtrl
->SetItemState( item
.GetId(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
518 item
.SetId( 1+ item
.GetId() );
520 wxArrayString errors
;
521 wxArrayString output
;
522 long res
= wxExecute( wxT("lpstat -v"), output
, errors
, wxEXEC_NODISABLE
);
523 if (res
>= 0 && errors
.GetCount() == 0)
526 for (i
= 0; i
< output
.GetCount(); i
++)
528 wxStringTokenizer
tok( output
[i
], wxT(" ") );
529 wxString tmp
= tok
.GetNextToken(); // "device"
530 if (tmp
!= wxT("device"))
531 break; // the lpstat syntax must have changed.
532 tmp
= tok
.GetNextToken(); // "for"
533 if (tmp
!= wxT("for"))
534 break; // the lpstat syntax must have changed.
535 tmp
= tok
.GetNextToken(); // "hp_deskjet930c:"
536 if (tmp
[tmp
.length()-1] == wxT(':'))
537 tmp
.Remove(tmp
.length()-1,1);
539 item
.SetText( name
);
540 item
.SetId( m_printerListCtrl
->InsertItem( item
) );
541 tmp
= tok
.GetNextToken(); // "parallel:/dev/lp0"
544 m_printerListCtrl
->SetItem( item
);
545 if (data
->GetPrinterName() == name
)
548 item2
.SetId( item
.GetId() );
549 item2
.SetMask( wxLIST_MASK_IMAGE
);
551 m_printerListCtrl
->SetItem( item2
);
553 m_printerListCtrl
->SetItemState( item
.GetId(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
556 wxString command
= wxT("lpstat -p ");
558 wxArrayString errors2
;
559 wxArrayString output2
;
560 res
= wxExecute( command
, output2
, errors2
, wxEXEC_NODISABLE
);
561 if (res
>= 0 && errors2
.GetCount() == 0 && output2
.GetCount() > 0)
563 tmp
= output2
[0]; // "printer hp_deskjet930c is idle. enable since ..."
564 int pos
= tmp
.Find( wxT('.') );
565 if (pos
!= wxNOT_FOUND
)
566 tmp
.Remove( (size_t)pos
, tmp
.length()-(size_t)pos
);
567 wxStringTokenizer
tok2( tmp
, wxT(" ") );
568 tmp
= tok2
.GetNextToken(); // "printer"
569 tmp
= tok2
.GetNextToken(); // "hp_deskjet930c"
571 while (tok2
.HasMoreTokens())
573 tmp
+= tok2
.GetNextToken();
578 m_printerListCtrl
->SetItem( item
);
582 item
.SetId( 1+ item
.GetId() );
587 printer_sizer
->Add( m_printerListCtrl
, 0, wxALL
|wxGROW
, 5 );
589 wxBoxSizer
*item1
= new wxBoxSizer( wxHORIZONTAL
);
590 main_sizer
->Add( item1
, 0, wxALL
, 5 );
592 // printer options (on the left)
594 wxBoxSizer
*item2
= new wxBoxSizer( wxVERTICAL
);
596 wxStaticBox
*item4
= new wxStaticBox( this, wxPRINTID_STATIC
, _("Paper size") );
597 wxStaticBoxSizer
*item3
= new wxStaticBoxSizer( item4
, wxVERTICAL
);
599 m_paperTypeChoice
= CreatePaperTypeChoice();
600 item3
->Add( m_paperTypeChoice
, 0, wxALIGN_CENTER
|wxALL
, 5 );
602 item2
->Add( item3
, 0, wxALIGN_CENTER
|wxALL
, 5 );
609 m_orientationRadioBox
= new wxRadioBox( this, wxPRINTID_ORIENTATION
, _("Orientation"), wxDefaultPosition
, wxDefaultSize
, 2, strs6
, 1, wxRA_SPECIFY_ROWS
);
610 item2
->Add( m_orientationRadioBox
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
612 wxStaticBox
*item8
= new wxStaticBox( this, wxID_ANY
, _("Options") );
613 wxStaticBoxSizer
*item7
= new wxStaticBoxSizer( item8
, wxHORIZONTAL
);
615 m_colourCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTCOLOUR
, _("Print in colour") );
616 item7
->Add( m_colourCheckBox
, 0, wxALIGN_CENTER
|wxALL
, 5 );
618 item2
->Add( item7
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
620 item1
->Add( item2
, 0, wxALIGN_CENTER_HORIZONTAL
, 5 );
622 // spooling options (on the right)
624 wxStaticBox
*item11
= new wxStaticBox( this, wxID_ANY
, _("Print spooling") );
625 wxStaticBoxSizer
*item10
= new wxStaticBoxSizer( item11
, wxVERTICAL
);
627 wxStaticText
*item12
= new wxStaticText( this, wxID_ANY
, _("Printer command:") );
628 item10
->Add( item12
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
630 wxBoxSizer
*item13
= new wxBoxSizer( wxHORIZONTAL
);
632 item13
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
634 m_printerCommandText
= new wxTextCtrl( this, wxPRINTID_COMMAND
, wxEmptyString
, wxDefaultPosition
, wxSize(160,wxDefaultCoord
) );
635 item13
->Add( m_printerCommandText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
637 item10
->Add( item13
, 0, wxALIGN_CENTER
|wxALL
, 0 );
639 wxStaticText
*item15
= new wxStaticText( this, wxID_ANY
, _("Printer options:") );
640 item10
->Add( item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
642 wxBoxSizer
*item16
= new wxBoxSizer( wxHORIZONTAL
);
644 item16
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
646 m_printerOptionsText
= new wxTextCtrl( this, wxPRINTID_OPTIONS
, wxEmptyString
, wxDefaultPosition
, wxSize(160,wxDefaultCoord
) );
647 item16
->Add( m_printerOptionsText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
649 item10
->Add( item16
, 0, wxALIGN_CENTER
|wxALL
, 0 );
651 item1
->Add( item10
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5 );
656 main_sizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
661 main_sizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxEXPAND
|wxALL
, 10 );
663 SetAutoLayout( true );
664 SetSizer( main_sizer
);
666 main_sizer
->Fit( this );
676 wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
680 void wxGenericPrintSetupDialog::OnPrinter(wxListEvent
& event
)
683 for (long item
= 0; item
< m_printerListCtrl
->GetItemCount(); item
++)
684 m_printerListCtrl
->SetItemImage( item
, -1 );
686 m_printerListCtrl
->SetItemImage( event
.GetIndex(), 0 );
688 if (event
.GetIndex() == 0)
690 m_printerCommandText
->SetValue( wxT("lpr") );
696 li
.SetMask( wxLIST_MASK_TEXT
);
697 li
.SetId( event
.GetIndex() );
698 m_printerListCtrl
->GetItem( li
);
699 m_printerCommandText
->SetValue( _T("lpr -P") + li
.GetText() );
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( wxEmptyString
);
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
, wxPageSetupDialogBase
)
814 BEGIN_EVENT_TABLE(wxGenericPageSetupDialog
, wxPageSetupDialogBase
)
815 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPageSetupDialog::OnPrinter
)
818 wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow
*parent
,
819 wxPageSetupDialogData
* data
)
820 : wxPageSetupDialogBase( parent
,
825 wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
832 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
835 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
836 new wxStaticBox(this,wxPRINTID_STATIC
, _("Paper size")), wxHORIZONTAL
);
838 size_t n
= wxThePrintPaperDatabase
->GetCount();
839 wxString
*choices
= new wxString
[n
];
841 for (size_t i
= 0; i
< n
; i
++)
843 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
844 choices
[i
] = paper
->GetName();
847 m_paperTypeChoice
= new wxComboBox( this,
851 wxSize(300, wxDefaultCoord
),
853 topsizer
->Add( m_paperTypeChoice
, 1, wxEXPAND
|wxALL
, 5 );
854 // m_paperTypeChoice->SetSelection(sel);
856 mainsizer
->Add( topsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
858 // 2) middle sizer with radio box
860 wxString
*choices2
= new wxString
[2];
861 choices2
[0] = _("Portrait");
862 choices2
[1] = _("Landscape");
863 m_orientationRadioBox
= new wxRadioBox(this, wxPRINTID_ORIENTATION
, _("Orientation"),
864 wxDefaultPosition
, wxDefaultSize
, 2, choices2
, 2);
865 m_orientationRadioBox
->SetSelection(0);
867 mainsizer
->Add( m_orientationRadioBox
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 10 );
871 wxBoxSizer
*table
= new wxBoxSizer( wxHORIZONTAL
);
873 wxBoxSizer
*column1
= new wxBoxSizer( wxVERTICAL
);
874 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Left margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
875 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Top margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
876 table
->Add( column1
, 0, wxALL
| wxEXPAND
, 5 );
878 wxBoxSizer
*column2
= new wxBoxSizer( wxVERTICAL
);
879 m_marginLeftText
= new wxTextCtrl(this, wxPRINTID_LEFTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
880 m_marginTopText
= new wxTextCtrl(this, wxPRINTID_TOPMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
881 column2
->Add( m_marginLeftText
, 1, wxALL
, 5 );
882 column2
->Add( m_marginTopText
, 1, wxALL
, 5 );
883 table
->Add( column2
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
885 wxBoxSizer
*column3
= new wxBoxSizer( wxVERTICAL
);
886 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Right margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
887 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Bottom margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
888 table
->Add( column3
, 0, wxALL
| wxEXPAND
, 5 );
890 wxBoxSizer
*column4
= new wxBoxSizer( wxVERTICAL
);
891 m_marginRightText
= new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
892 m_marginBottomText
= new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
893 column4
->Add( m_marginRightText
, 1, wxALL
, 5 );
894 column4
->Add( m_marginBottomText
, 1, wxALL
, 5 );
895 table
->Add( column4
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
897 mainsizer
->Add( table
, 0 );
901 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
906 wxSizer
* buttonsizer
= CreateButtonSizer( wxOK
|wxCANCEL
);
908 if (wxPrintFactory::GetFactory()->HasPrintSetupDialog())
910 m_printerButton
= new wxButton(this, wxPRINTID_SETUP
, _("Printer...") );
911 buttonsizer
->Add( m_printerButton
, 0, wxLEFT
|wxRIGHT
, 10 );
912 if ( !m_pageData
.GetEnablePrinter() )
913 m_printerButton
->Enable(false);
917 m_printerButton
= NULL
;
920 // if (m_printData.GetEnableHelp())
921 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight);
922 mainsizer
->Add( buttonsizer
, 0, wxEXPAND
|wxALL
, 10 );
925 SetAutoLayout( true );
926 SetSizer( mainsizer
);
928 mainsizer
->Fit( this );
937 wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
941 wxPageSetupDialogData
& wxGenericPageSetupDialog::GetPageSetupDialogData()
946 bool wxGenericPageSetupDialog::TransferDataToWindow()
948 if (m_marginLeftText
)
949 m_marginLeftText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().x
));
951 m_marginTopText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().y
));
952 if (m_marginRightText
)
953 m_marginRightText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().x
));
954 if (m_marginBottomText
)
955 m_marginBottomText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().y
));
957 if (m_orientationRadioBox
)
959 if (m_pageData
.GetPrintData().GetOrientation() == wxPORTRAIT
)
960 m_orientationRadioBox
->SetSelection(0);
962 m_orientationRadioBox
->SetSelection(1);
965 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
966 // failing that, the id in the wxPrintData object.
968 wxPrintPaperType
* type
= wxThePrintPaperDatabase
->FindPaperType(
969 wxSize(m_pageData
.GetPaperSize().x
* 10, m_pageData
.GetPaperSize().y
* 10));
971 if (!type
&& m_pageData
.GetPrintData().GetPaperId() != wxPAPER_NONE
)
972 type
= wxThePrintPaperDatabase
->FindPaperType(m_pageData
.GetPrintData().GetPaperId());
976 m_paperTypeChoice
->SetStringSelection(type
->GetName());
982 bool wxGenericPageSetupDialog::TransferDataFromWindow()
984 if (m_marginLeftText
&& m_marginTopText
)
986 int left
= wxAtoi( m_marginLeftText
->GetValue().c_str() );
987 int top
= wxAtoi( m_marginTopText
->GetValue().c_str() );
988 m_pageData
.SetMarginTopLeft( wxPoint(left
,top
) );
990 if (m_marginRightText
&& m_marginBottomText
)
992 int right
= wxAtoi( m_marginRightText
->GetValue().c_str() );
993 int bottom
= wxAtoi( m_marginBottomText
->GetValue().c_str() );
994 m_pageData
.SetMarginBottomRight( wxPoint(right
,bottom
) );
997 if (m_orientationRadioBox
)
999 int sel
= m_orientationRadioBox
->GetSelection();
1002 m_pageData
.GetPrintData().SetOrientation(wxPORTRAIT
);
1006 m_pageData
.GetPrintData().SetOrientation(wxLANDSCAPE
);
1010 if (m_paperTypeChoice
)
1012 int selectedItem
= m_paperTypeChoice
->GetSelection();
1013 if (selectedItem
!= -1)
1015 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
1018 m_pageData
.SetPaperSize(wxSize(paper
->GetWidth()/10, paper
->GetHeight()/10));
1019 m_pageData
.GetPrintData().SetPaperId(paper
->GetId());
1027 wxComboBox
*wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x
, int *y
)
1030 if (!wxThePrintPaperDatabase)
1032 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
1033 wxThePrintPaperDatabase->CreateDatabase();
1037 size_t n
= wxThePrintPaperDatabase
->GetCount();
1038 wxString
*choices
= new wxString
[n
];
1040 for (size_t i
= 0; i
< n
; i
++)
1042 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
1043 choices
[i
] = paper
->GetName();
1046 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Paper size"), wxPoint(*x
, *y
));
1049 wxComboBox
*choice
= new wxComboBox( this,
1050 wxPRINTID_PAPERSIZE
,
1053 wxSize(300, wxDefaultCoord
),
1058 // choice->SetSelection(sel);
1062 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent
& WXUNUSED(event
))
1064 // We no longer query GetPrintMode, so we can eliminate the need
1065 // to call SetPrintMode.
1066 // This has the limitation that we can't explicitly call the PostScript
1067 // print setup dialog from the generic Page Setup dialog under Windows,
1068 // but since this choice would only happen when trying to do PostScript
1069 // printing under Windows (and only in 16-bit Windows which
1070 // doesn't have a Windows-specific page setup dialog) it's worth it.
1072 // First save the current settings, so the wxPrintData object is up to date.
1073 TransferDataFromWindow();
1075 // Transfer the current print settings from this dialog to the page setup dialog.
1078 // Use print factory later
1080 wxPrintDialogData data
;
1081 data
= GetPageSetupData().GetPrintData();
1082 data
.SetSetupDialog(true);
1083 wxPrintDialog
printDialog(this, & data
);
1084 printDialog
.ShowModal();
1086 // Transfer the page setup print settings from the page dialog to this dialog again, in case
1087 // the page setup dialog changed something.
1088 GetPageSetupData().GetPrintData() = printDialog
.GetPrintDialogData().GetPrintData();
1089 GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData
1091 // Now update the dialog in case the page setup dialog changed some of our settings.
1092 TransferDataToWindow();