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
, 0),
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
, 0),
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
,
233 m_rangeRadioBox
->SetSelection(1);
235 mainsizer
->Add( m_rangeRadioBox
, 0, wxLEFT
|wxTOP
|wxRIGHT
, 10 );
240 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
242 if (m_printDialogData
.GetFromPage() != 0)
244 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("From:") ), 0, wxCENTER
|wxALL
, 5 );
245 m_fromText
= new wxTextCtrl(this, wxPRINTID_FROM
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
246 bottomsizer
->Add( m_fromText
, 1, wxCENTER
|wxRIGHT
, 10 );
248 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("To:") ), 0, wxCENTER
|wxALL
, 5);
249 m_toText
= new wxTextCtrl(this, wxPRINTID_TO
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
250 bottomsizer
->Add( m_toText
, 1, wxCENTER
|wxRIGHT
, 10 );
253 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Copies:") ), 0, wxCENTER
|wxALL
, 5 );
254 m_noCopiesText
= new wxTextCtrl(this, wxPRINTID_COPIES
, wxEmptyString
, wxPoint(252, 130), wxSize(40, wxDefaultCoord
));
255 bottomsizer
->Add( m_noCopiesText
, 1, wxCENTER
|wxRIGHT
, 10 );
257 mainsizer
->Add( bottomsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 12 );
261 wxSizer
*sizerBtn
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
263 mainsizer
->Add(sizerBtn
, 0, wxEXPAND
|wxALL
, 10 );
265 SetAutoLayout( true );
266 SetSizer( mainsizer
);
268 mainsizer
->Fit( this );
271 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
276 int wxGenericPrintDialog::ShowModal()
278 return wxDialog::ShowModal();
281 wxGenericPrintDialog::~wxGenericPrintDialog()
285 void wxGenericPrintDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
287 TransferDataFromWindow();
289 // An empty 'to' field signals printing just the
291 if (m_printDialogData
.GetToPage() < 1)
292 m_printDialogData
.SetToPage(m_printDialogData
.GetFromPage());
294 // There are some interactions between the global setup data
295 // and the standard print dialog. The global printing 'mode'
296 // is determined by whether the user checks Print to file
298 if (m_printDialogData
.GetPrintToFile())
300 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE
);
302 wxFileName
fname( m_printDialogData
.GetPrintData().GetFilename() );
304 wxFileDialog
dialog( this, _("PostScript file"),
305 fname
.GetPath(), fname
.GetFullName(), wxT("*.ps"), wxFD_SAVE
| wxFD_OVERWRITE_PROMPT
);
306 if (dialog
.ShowModal() != wxID_OK
) return;
308 m_printDialogData
.GetPrintData().SetFilename( dialog
.GetPath() );
312 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER
);
318 void wxGenericPrintDialog::OnRange(wxCommandEvent
& event
)
320 if (!m_fromText
) return;
322 if (event
.GetInt() == 0)
324 m_fromText
->Enable(false);
325 m_toText
->Enable(false);
327 else if (event
.GetInt() == 1)
329 m_fromText
->Enable(true);
330 m_toText
->Enable(true);
334 void wxGenericPrintDialog::OnSetup(wxCommandEvent
& WXUNUSED(event
))
336 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
338 if (factory
->HasPrintSetupDialog())
340 // The print setup dialog should change the
341 // print data in-place if not cancelled.
342 wxDialog
*dialog
= factory
->CreatePrintSetupDialog( this, &m_printDialogData
.GetPrintData() );
348 bool wxGenericPrintDialog::TransferDataToWindow()
350 if(m_printDialogData
.GetFromPage() != 0)
354 if (m_printDialogData
.GetEnablePageNumbers())
356 m_fromText
->Enable(true);
357 m_toText
->Enable(true);
358 if (m_printDialogData
.GetFromPage() > 0)
359 m_fromText
->SetValue(wxString::Format(wxT("%d"), m_printDialogData
.GetFromPage()));
360 if (m_printDialogData
.GetToPage() > 0)
361 m_toText
->SetValue(wxString::Format(wxT("%d"), m_printDialogData
.GetToPage()));
364 if (m_printDialogData
.GetAllPages() || m_printDialogData
.GetFromPage() == 0)
365 m_rangeRadioBox
->SetSelection(0);
367 m_rangeRadioBox
->SetSelection(1);
372 m_fromText
->Enable(false);
373 m_toText
->Enable(false);
376 m_rangeRadioBox
->SetSelection(0);
377 m_rangeRadioBox
->wxRadioBox::Enable(1, false);
382 m_noCopiesText
->SetValue(
383 wxString::Format(wxT("%d"), m_printDialogData
.GetNoCopies()));
385 m_printToFileCheckBox
->SetValue(m_printDialogData
.GetPrintToFile());
386 m_printToFileCheckBox
->Enable(m_printDialogData
.GetEnablePrintToFile());
390 bool wxGenericPrintDialog::TransferDataFromWindow()
393 if(m_printDialogData
.GetFromPage() != -1)
395 if (m_printDialogData
.GetEnablePageNumbers())
399 wxString value
= m_fromText
->GetValue();
400 if (value
.ToLong( &res
))
401 m_printDialogData
.SetFromPage( res
);
405 wxString value
= m_toText
->GetValue();
406 if (value
.ToLong( &res
))
407 m_printDialogData
.SetToPage( res
);
412 if (m_rangeRadioBox
->GetSelection() == 0)
414 m_printDialogData
.SetAllPages(true);
416 // This means all pages, more or less
417 m_printDialogData
.SetFromPage(1);
418 m_printDialogData
.SetToPage(32000);
421 m_printDialogData
.SetAllPages(false);
425 { // continuous printing
426 m_printDialogData
.SetFromPage(1);
427 m_printDialogData
.SetToPage(32000);
430 wxString value
= m_noCopiesText
->GetValue();
431 if (value
.ToLong( &res
))
432 m_printDialogData
.SetNoCopies( res
);
434 m_printDialogData
.SetPrintToFile(m_printToFileCheckBox
->GetValue());
439 wxDC
*wxGenericPrintDialog::GetPrintDC()
441 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
444 // ----------------------------------------------------------------------------
445 // Generic print setup dialog
446 // ----------------------------------------------------------------------------
448 IMPLEMENT_CLASS(wxGenericPrintSetupDialog
, wxDialog
)
450 BEGIN_EVENT_TABLE(wxGenericPrintSetupDialog
, wxDialog
)
451 EVT_LIST_ITEM_ACTIVATED(wxPRINTID_PRINTER
, wxGenericPrintSetupDialog::OnPrinter
)
454 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow
*parent
, wxPrintData
* data
):
455 wxDialog(parent
, wxID_ANY
, _("Print Setup"), wxPoint(0,0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
461 static const char* const check_xpm
[] = {
462 /* width height ncolors chars_per_pixel */
488 void wxGenericPrintSetupDialog::Init(wxPrintData
* data
)
495 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
499 wxStaticBoxSizer
*printer_sizer
= new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY
, _("Printer") ), wxVERTICAL
);
500 main_sizer
->Add( printer_sizer
, 0, wxALL
|wxGROW
, 10 );
502 m_printerListCtrl
= new wxListCtrl( this, wxPRINTID_PRINTER
,
503 wxDefaultPosition
, wxSize(wxDefaultCoord
,100), wxLC_REPORT
|wxLC_SINGLE_SEL
|wxSUNKEN_BORDER
);
504 wxImageList
*image_list
= new wxImageList
;
505 image_list
->Add( wxBitmap(check_xpm
) );
506 m_printerListCtrl
->AssignImageList( image_list
, wxIMAGE_LIST_SMALL
);
508 m_printerListCtrl
->InsertColumn( 0, wxT(" "), wxLIST_FORMAT_LEFT
, 20 );
509 m_printerListCtrl
->InsertColumn( 1, wxT("Printer"), wxLIST_FORMAT_LEFT
, 150 );
510 m_printerListCtrl
->InsertColumn( 2, wxT("Device"), wxLIST_FORMAT_LEFT
, 150 );
511 m_printerListCtrl
->InsertColumn( 3, wxT("Status"), wxLIST_FORMAT_LEFT
, 80 );
514 item
.SetMask( wxLIST_MASK_TEXT
);
516 item
.SetText( _("Default printer") );
517 item
.SetId( m_printerListCtrl
->InsertItem( item
) );
519 if (data
->GetPrinterName().empty())
522 item2
.SetId( item
.GetId() );
523 item2
.SetMask( wxLIST_MASK_IMAGE
);
525 m_printerListCtrl
->SetItem( item2
);
527 m_printerListCtrl
->SetItemState( item
.GetId(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
530 item
.SetId( 1+ item
.GetId() );
532 wxArrayString errors
;
533 wxArrayString output
;
534 long res
= wxExecute( wxT("lpstat -v"), output
, errors
, wxEXEC_NODISABLE
);
535 if (res
>= 0 && errors
.GetCount() == 0)
538 for (i
= 0; i
< output
.GetCount(); i
++)
540 wxStringTokenizer
tok( output
[i
], wxT(" ") );
541 wxString tmp
= tok
.GetNextToken(); // "device"
542 if (tmp
!= wxT("device"))
543 break; // the lpstat syntax must have changed.
544 tmp
= tok
.GetNextToken(); // "for"
545 if (tmp
!= wxT("for"))
546 break; // the lpstat syntax must have changed.
547 tmp
= tok
.GetNextToken(); // "hp_deskjet930c:"
548 if (tmp
[tmp
.length()-1] == wxT(':'))
549 tmp
.Remove(tmp
.length()-1,1);
551 item
.SetText( name
);
552 item
.SetId( m_printerListCtrl
->InsertItem( item
) );
553 tmp
= tok
.GetNextToken(); // "parallel:/dev/lp0"
556 m_printerListCtrl
->SetItem( item
);
557 if (data
->GetPrinterName() == name
)
560 item2
.SetId( item
.GetId() );
561 item2
.SetMask( wxLIST_MASK_IMAGE
);
563 m_printerListCtrl
->SetItem( item2
);
565 m_printerListCtrl
->SetItemState( item
.GetId(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
568 wxString command
= wxT("lpstat -p ");
570 wxArrayString errors2
;
571 wxArrayString output2
;
572 res
= wxExecute( command
, output2
, errors2
, wxEXEC_NODISABLE
);
573 if (res
>= 0 && errors2
.GetCount() == 0 && output2
.GetCount() > 0)
575 tmp
= output2
[0]; // "printer hp_deskjet930c is idle. enable since ..."
576 int pos
= tmp
.Find( wxT('.') );
577 if (pos
!= wxNOT_FOUND
)
578 tmp
.Remove( (size_t)pos
, tmp
.length()-(size_t)pos
);
579 wxStringTokenizer
tok2( tmp
, wxT(" ") );
580 tmp
= tok2
.GetNextToken(); // "printer"
581 tmp
= tok2
.GetNextToken(); // "hp_deskjet930c"
583 while (tok2
.HasMoreTokens())
585 tmp
+= tok2
.GetNextToken();
590 m_printerListCtrl
->SetItem( item
);
594 item
.SetId( 1+ item
.GetId() );
599 printer_sizer
->Add( m_printerListCtrl
, 0, wxALL
|wxGROW
, 5 );
601 wxBoxSizer
*item1
= new wxBoxSizer( wxHORIZONTAL
);
602 main_sizer
->Add( item1
, 0, wxALL
, 5 );
604 // printer options (on the left)
606 wxBoxSizer
*item2
= new wxBoxSizer( wxVERTICAL
);
608 wxStaticBox
*item4
= new wxStaticBox( this, wxPRINTID_STATIC
, _("Paper size") );
609 wxStaticBoxSizer
*item3
= new wxStaticBoxSizer( item4
, wxVERTICAL
);
611 m_paperTypeChoice
= CreatePaperTypeChoice();
612 item3
->Add( m_paperTypeChoice
, 0, wxALIGN_CENTER
|wxALL
, 5 );
614 item2
->Add( item3
, 0, wxALIGN_CENTER
|wxALL
, 5 );
621 m_orientationRadioBox
= new wxRadioBox( this, wxPRINTID_ORIENTATION
, _("Orientation"), wxDefaultPosition
, wxDefaultSize
, 2, strs6
, 1, wxRA_SPECIFY_ROWS
);
622 item2
->Add( m_orientationRadioBox
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
624 wxStaticBox
*item8
= new wxStaticBox( this, wxID_ANY
, _("Options") );
625 wxStaticBoxSizer
*item7
= new wxStaticBoxSizer( item8
, wxHORIZONTAL
);
627 m_colourCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTCOLOUR
, _("Print in colour") );
628 item7
->Add( m_colourCheckBox
, 0, wxALIGN_CENTER
|wxALL
, 5 );
630 item2
->Add( item7
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
632 item1
->Add( item2
, 0, wxALIGN_CENTER_HORIZONTAL
, 5 );
634 // spooling options (on the right)
636 wxStaticBox
*item11
= new wxStaticBox( this, wxID_ANY
, _("Print spooling") );
637 wxStaticBoxSizer
*item10
= new wxStaticBoxSizer( item11
, wxVERTICAL
);
639 wxStaticText
*item12
= new wxStaticText( this, wxID_ANY
, _("Printer command:") );
640 item10
->Add( item12
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
642 wxBoxSizer
*item13
= new wxBoxSizer( wxHORIZONTAL
);
644 item13
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
646 m_printerCommandText
= new wxTextCtrl( this, wxPRINTID_COMMAND
, wxEmptyString
, wxDefaultPosition
, wxSize(160,wxDefaultCoord
) );
647 item13
->Add( m_printerCommandText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
649 item10
->Add( item13
, 0, wxALIGN_CENTER
|wxALL
, 0 );
651 wxStaticText
*item15
= new wxStaticText( this, wxID_ANY
, _("Printer options:") );
652 item10
->Add( item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
654 wxBoxSizer
*item16
= new wxBoxSizer( wxHORIZONTAL
);
656 item16
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
658 m_printerOptionsText
= new wxTextCtrl( this, wxPRINTID_OPTIONS
, wxEmptyString
, wxDefaultPosition
, wxSize(160,wxDefaultCoord
) );
659 item16
->Add( m_printerOptionsText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
661 item10
->Add( item16
, 0, wxALIGN_CENTER
|wxALL
, 0 );
663 item1
->Add( item10
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5 );
668 main_sizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
673 main_sizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxEXPAND
|wxALL
, 10 );
675 SetAutoLayout( true );
676 SetSizer( main_sizer
);
678 main_sizer
->Fit( this );
688 wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
692 void wxGenericPrintSetupDialog::OnPrinter(wxListEvent
& event
)
695 for (long item
= 0; item
< m_printerListCtrl
->GetItemCount(); item
++)
696 m_printerListCtrl
->SetItemImage( item
, -1 );
698 m_printerListCtrl
->SetItemImage( event
.GetIndex(), 0 );
700 if (event
.GetIndex() == 0)
702 m_printerCommandText
->SetValue( wxT("lpr") );
708 li
.SetMask( wxLIST_MASK_TEXT
);
709 li
.SetId( event
.GetIndex() );
710 m_printerListCtrl
->GetItem( li
);
711 m_printerCommandText
->SetValue( wxT("lpr -P") + li
.GetText() );
715 bool wxGenericPrintSetupDialog::TransferDataToWindow()
717 wxPostScriptPrintNativeData
*data
=
718 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
720 if (m_printerCommandText
&& !data
->GetPrinterCommand().empty())
721 m_printerCommandText
->SetValue(data
->GetPrinterCommand());
722 if (m_printerOptionsText
&& !data
->GetPrinterOptions().empty())
723 m_printerOptionsText
->SetValue(data
->GetPrinterOptions());
724 if (m_colourCheckBox
)
725 m_colourCheckBox
->SetValue(m_printData
.GetColour());
727 if (m_orientationRadioBox
)
729 if (m_printData
.GetOrientation() == wxPORTRAIT
)
730 m_orientationRadioBox
->SetSelection(0);
732 m_orientationRadioBox
->SetSelection(1);
737 bool wxGenericPrintSetupDialog::TransferDataFromWindow()
739 wxPostScriptPrintNativeData
*data
=
740 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
742 // find selected printer
743 long id
= m_printerListCtrl
->GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
746 m_printData
.SetPrinterName( wxEmptyString
);
752 item
.SetMask( wxLIST_MASK_TEXT
);
754 m_printerListCtrl
->GetItem( item
);
755 m_printData
.SetPrinterName( item
.GetText() );
758 if (m_printerCommandText
)
759 data
->SetPrinterCommand(m_printerCommandText
->GetValue());
760 if (m_printerOptionsText
)
761 data
->SetPrinterOptions(m_printerOptionsText
->GetValue());
762 if (m_colourCheckBox
)
763 m_printData
.SetColour(m_colourCheckBox
->GetValue());
764 if (m_orientationRadioBox
)
766 int sel
= m_orientationRadioBox
->GetSelection();
768 m_printData
.SetOrientation(wxPORTRAIT
);
770 m_printData
.SetOrientation(wxLANDSCAPE
);
772 if (m_paperTypeChoice
)
774 int selectedItem
= m_paperTypeChoice
->GetSelection();
775 if (selectedItem
!= -1)
777 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
779 m_printData
.SetPaperId( paper
->GetId());
784 *m_targetData
= m_printData
;
789 wxComboBox
*wxGenericPrintSetupDialog::CreatePaperTypeChoice()
791 size_t n
= wxThePrintPaperDatabase
->GetCount();
792 wxString
*choices
= new wxString
[n
];
795 for (size_t i
= 0; i
< n
; i
++)
797 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
798 choices
[i
] = paper
->GetName();
799 if (m_printData
.GetPaperId() == paper
->GetId())
805 wxComboBox
*choice
= new wxComboBox( this,
809 wxSize(width
, wxDefaultCoord
),
814 choice
->SetSelection(sel
);
818 #endif // wxUSE_POSTSCRIPT
820 // ----------------------------------------------------------------------------
821 // Generic page setup dialog
822 // ----------------------------------------------------------------------------
824 IMPLEMENT_CLASS(wxGenericPageSetupDialog
, wxPageSetupDialogBase
)
826 BEGIN_EVENT_TABLE(wxGenericPageSetupDialog
, wxPageSetupDialogBase
)
827 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPageSetupDialog::OnPrinter
)
830 wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow
*parent
,
831 wxPageSetupDialogData
* data
)
832 : wxPageSetupDialogBase( parent
,
837 wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
844 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
847 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
848 new wxStaticBox(this,wxPRINTID_STATIC
, _("Paper size")), wxHORIZONTAL
);
850 size_t n
= wxThePrintPaperDatabase
->GetCount();
851 wxString
*choices
= new wxString
[n
];
853 for (size_t i
= 0; i
< n
; i
++)
855 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
856 choices
[i
] = paper
->GetName();
859 m_paperTypeChoice
= new wxComboBox( this,
863 wxSize(300, wxDefaultCoord
),
865 topsizer
->Add( m_paperTypeChoice
, 1, wxEXPAND
|wxALL
, 5 );
866 // m_paperTypeChoice->SetSelection(sel);
868 mainsizer
->Add( topsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
870 // 2) middle sizer with radio box
872 wxString
*choices2
= new wxString
[2];
873 choices2
[0] = _("Portrait");
874 choices2
[1] = _("Landscape");
875 m_orientationRadioBox
= new wxRadioBox(this, wxPRINTID_ORIENTATION
, _("Orientation"),
876 wxDefaultPosition
, wxDefaultSize
, 2, choices2
, 2);
877 m_orientationRadioBox
->SetSelection(0);
879 mainsizer
->Add( m_orientationRadioBox
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 10 );
883 wxBoxSizer
*table
= new wxBoxSizer( wxHORIZONTAL
);
885 wxBoxSizer
*column1
= new wxBoxSizer( wxVERTICAL
);
886 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Left margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
887 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Top margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
888 table
->Add( column1
, 0, wxALL
| wxEXPAND
, 5 );
890 wxBoxSizer
*column2
= new wxBoxSizer( wxVERTICAL
);
891 m_marginLeftText
= new wxTextCtrl(this, wxPRINTID_LEFTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
892 m_marginTopText
= new wxTextCtrl(this, wxPRINTID_TOPMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
893 column2
->Add( m_marginLeftText
, 1, wxALL
, 5 );
894 column2
->Add( m_marginTopText
, 1, wxALL
, 5 );
895 table
->Add( column2
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
897 wxBoxSizer
*column3
= new wxBoxSizer( wxVERTICAL
);
898 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Right margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
899 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Bottom margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
900 table
->Add( column3
, 0, wxALL
| wxEXPAND
, 5 );
902 wxBoxSizer
*column4
= new wxBoxSizer( wxVERTICAL
);
903 m_marginRightText
= new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
904 m_marginBottomText
= new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
905 column4
->Add( m_marginRightText
, 1, wxALL
, 5 );
906 column4
->Add( m_marginBottomText
, 1, wxALL
, 5 );
907 table
->Add( column4
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
909 mainsizer
->Add( table
, 0 );
913 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
918 wxSizer
* buttonsizer
= CreateButtonSizer( wxOK
|wxCANCEL
);
920 if (wxPrintFactory::GetFactory()->HasPrintSetupDialog())
922 m_printerButton
= new wxButton(this, wxPRINTID_SETUP
, _("Printer...") );
923 buttonsizer
->Add( m_printerButton
, 0, wxLEFT
|wxRIGHT
, 10 );
924 if ( !m_pageData
.GetEnablePrinter() )
925 m_printerButton
->Enable(false);
929 m_printerButton
= NULL
;
932 // if (m_printData.GetEnableHelp())
933 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight);
934 mainsizer
->Add( buttonsizer
, 0, wxEXPAND
|wxALL
, 10 );
937 SetAutoLayout( true );
938 SetSizer( mainsizer
);
940 mainsizer
->Fit( this );
949 wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
953 wxPageSetupDialogData
& wxGenericPageSetupDialog::GetPageSetupDialogData()
958 bool wxGenericPageSetupDialog::TransferDataToWindow()
960 if (m_marginLeftText
)
961 m_marginLeftText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().x
));
963 m_marginTopText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().y
));
964 if (m_marginRightText
)
965 m_marginRightText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().x
));
966 if (m_marginBottomText
)
967 m_marginBottomText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().y
));
969 if (m_orientationRadioBox
)
971 if (m_pageData
.GetPrintData().GetOrientation() == wxPORTRAIT
)
972 m_orientationRadioBox
->SetSelection(0);
974 m_orientationRadioBox
->SetSelection(1);
977 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
978 // failing that, the id in the wxPrintData object.
980 wxPrintPaperType
* type
= wxThePrintPaperDatabase
->FindPaperType(
981 wxSize(m_pageData
.GetPaperSize().x
* 10, m_pageData
.GetPaperSize().y
* 10));
983 if (!type
&& m_pageData
.GetPrintData().GetPaperId() != wxPAPER_NONE
)
984 type
= wxThePrintPaperDatabase
->FindPaperType(m_pageData
.GetPrintData().GetPaperId());
988 m_paperTypeChoice
->SetStringSelection(type
->GetName());
994 bool wxGenericPageSetupDialog::TransferDataFromWindow()
996 if (m_marginLeftText
&& m_marginTopText
)
998 int left
= wxAtoi( m_marginLeftText
->GetValue().c_str() );
999 int top
= wxAtoi( m_marginTopText
->GetValue().c_str() );
1000 m_pageData
.SetMarginTopLeft( wxPoint(left
,top
) );
1002 if (m_marginRightText
&& m_marginBottomText
)
1004 int right
= wxAtoi( m_marginRightText
->GetValue().c_str() );
1005 int bottom
= wxAtoi( m_marginBottomText
->GetValue().c_str() );
1006 m_pageData
.SetMarginBottomRight( wxPoint(right
,bottom
) );
1009 if (m_orientationRadioBox
)
1011 int sel
= m_orientationRadioBox
->GetSelection();
1014 m_pageData
.GetPrintData().SetOrientation(wxPORTRAIT
);
1018 m_pageData
.GetPrintData().SetOrientation(wxLANDSCAPE
);
1022 if (m_paperTypeChoice
)
1024 int selectedItem
= m_paperTypeChoice
->GetSelection();
1025 if (selectedItem
!= -1)
1027 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
1030 m_pageData
.SetPaperSize(wxSize(paper
->GetWidth()/10, paper
->GetHeight()/10));
1031 m_pageData
.GetPrintData().SetPaperId(paper
->GetId());
1039 wxComboBox
*wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x
, int *y
)
1042 if (!wxThePrintPaperDatabase)
1044 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
1045 wxThePrintPaperDatabase->CreateDatabase();
1049 size_t n
= wxThePrintPaperDatabase
->GetCount();
1050 wxString
*choices
= new wxString
[n
];
1052 for (size_t i
= 0; i
< n
; i
++)
1054 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
1055 choices
[i
] = paper
->GetName();
1058 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Paper size"), wxPoint(*x
, *y
));
1061 wxComboBox
*choice
= new wxComboBox( this,
1062 wxPRINTID_PAPERSIZE
,
1065 wxSize(300, wxDefaultCoord
),
1070 // choice->SetSelection(sel);
1074 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent
& WXUNUSED(event
))
1076 // We no longer query GetPrintMode, so we can eliminate the need
1077 // to call SetPrintMode.
1078 // This has the limitation that we can't explicitly call the PostScript
1079 // print setup dialog from the generic Page Setup dialog under Windows,
1080 // but since this choice would only happen when trying to do PostScript
1081 // printing under Windows (and only in 16-bit Windows which
1082 // doesn't have a Windows-specific page setup dialog) it's worth it.
1084 // First save the current settings, so the wxPrintData object is up to date.
1085 TransferDataFromWindow();
1087 // Transfer the current print settings from this dialog to the page setup dialog.
1090 // Use print factory later
1092 wxPrintDialogData data
;
1093 data
= GetPageSetupData().GetPrintData();
1094 data
.SetSetupDialog(true);
1095 wxPrintDialog
printDialog(this, & data
);
1096 printDialog
.ShowModal();
1098 // Transfer the page setup print settings from the page dialog to this dialog again, in case
1099 // the page setup dialog changed something.
1100 GetPageSetupData().GetPrintData() = printDialog
.GetPrintDialogData().GetPrintData();
1101 GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData
1103 // Now update the dialog in case the page setup dialog changed some of our settings.
1104 TransferDataToWindow();