1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/prntdlgg.cpp
3 // Purpose: Generic print dialogs
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
28 #include "wx/generic/prntdlgg.h"
33 #include "wx/stattext.h"
34 #include "wx/statbox.h"
35 #include "wx/button.h"
36 #include "wx/checkbox.h"
37 #include "wx/textctrl.h"
38 #include "wx/radiobox.h"
39 #include "wx/filedlg.h"
40 #include "wx/combobox.h"
43 #include "wx/cmndata.h"
47 #include "wx/statline.h"
51 #include "wx/generic/dcpsg.h"
54 #include "wx/prntbase.h"
55 #include "wx/printdlg.h"
57 #include "wx/filename.h"
58 #include "wx/tokenzr.h"
59 #include "wx/imaglist.h"
64 #ifndef __WXUNIVERSAL__
68 wxFORCE_LINK_MODULE(gtk_print
)
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 extern wxPrintPaperDatabase
*wxThePrintPaperDatabase
;
81 //----------------------------------------------------------------------------
82 // wxPostScriptNativeData
83 //----------------------------------------------------------------------------
85 IMPLEMENT_CLASS(wxPostScriptPrintNativeData
, wxPrintNativeDataBase
)
87 wxPostScriptPrintNativeData
::wxPostScriptPrintNativeData()
89 m_previewCommand
= wxEmptyString
;
91 m_printerCommand
= wxT("print");
92 m_printerOptions
= wxT("/nonotify/queue=psqueue");
93 m_afmPath
= wxT("sys$ps_font_metrics:");
97 m_printerCommand
= wxT("print");
98 m_printerOptions
= wxEmptyString
;
99 m_afmPath
= wxT("c:\\windows\\system\\");
102 #if !defined(__VMS__) && !defined(__WXMSW__)
103 m_printerCommand
= wxT("lpr");
104 m_printerOptions
= wxEmptyString
;
105 m_afmPath
= wxEmptyString
;
108 m_printerScaleX
= 1.0;
109 m_printerScaleY
= 1.0;
110 m_printerTranslateX
= 0;
111 m_printerTranslateY
= 0;
114 wxPostScriptPrintNativeData
::~wxPostScriptPrintNativeData()
118 bool wxPostScriptPrintNativeData
::TransferTo( wxPrintData
&WXUNUSED(data
) )
123 bool wxPostScriptPrintNativeData
::TransferFrom( const wxPrintData
&WXUNUSED(data
) )
128 // ----------------------------------------------------------------------------
129 // Generic print dialog for non-Windows printing use.
130 // ----------------------------------------------------------------------------
132 IMPLEMENT_CLASS(wxGenericPrintDialog
, wxPrintDialogBase
)
134 BEGIN_EVENT_TABLE(wxGenericPrintDialog
, wxPrintDialogBase
)
135 EVT_BUTTON(wxID_OK
, wxGenericPrintDialog
::OnOK
)
136 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPrintDialog
::OnSetup
)
137 EVT_RADIOBOX(wxPRINTID_RANGE
, wxGenericPrintDialog
::OnRange
)
140 wxGenericPrintDialog
::wxGenericPrintDialog(wxWindow
*parent
,
141 wxPrintDialogData
* data
)
142 : wxPrintDialogBase(GetParentForModalDialog(parent
, 0),
143 wxID_ANY
, _("Print"),
144 wxPoint(0,0), wxSize(600, 600),
145 wxDEFAULT_DIALOG_STYLE
|
149 m_printDialogData
= *data
;
154 wxGenericPrintDialog
::wxGenericPrintDialog(wxWindow
*parent
,
156 : wxPrintDialogBase(GetParentForModalDialog(parent
, 0),
157 wxID_ANY
, _("Print"),
158 wxPoint(0,0), wxSize(600, 600),
159 wxDEFAULT_DIALOG_STYLE
|
163 m_printDialogData
= *data
;
168 void wxGenericPrintDialog
::Init(wxWindow
* WXUNUSED(parent
))
170 // wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0,0), wxSize(600, 600),
171 // wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL);
173 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
177 wxPrintFactory
* factory
= wxPrintFactory
::GetFactory();
179 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
180 new wxStaticBox( this, wxID_ANY
, _( "Printer options" ) ), wxHORIZONTAL
);
181 wxFlexGridSizer
*flex
= new wxFlexGridSizer( 2 );
182 flex
->AddGrowableCol( 1 );
183 topsizer
->Add( flex
, 1, wxGROW
);
185 m_printToFileCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTTOFILE
, _("Print to File") );
186 flex
->Add( m_printToFileCheckBox
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
188 m_setupButton
= new wxButton(this, wxPRINTID_SETUP
, _("Setup...") );
189 flex
->Add( m_setupButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALIGN_RIGHT
|wxALL
, 5 );
191 if (!factory
->HasPrintSetupDialog())
192 m_setupButton
->Enable( false );
194 if (factory
->HasPrinterLine())
196 flex
->Add( new wxStaticText( this, wxID_ANY
, _("Printer:") ),
197 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
198 flex
->Add( new wxStaticText( this, wxID_ANY
, factory
->CreatePrinterLine() ),
199 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
202 if (factory
->HasStatusLine())
204 flex
->Add( new wxStaticText( this, wxID_ANY
, _("Status:") ),
205 0, wxALIGN_CENTER_VERTICAL
|(wxALL
-wxTOP
), 5 );
206 flex
->Add( new wxStaticText( this, wxID_ANY
, factory
->CreateStatusLine() ),
207 0, wxALIGN_CENTER_VERTICAL
|(wxALL
-wxTOP
), 5 );
210 mainsizer
->Add( topsizer
, 0, wxLEFT
|wxTOP
|wxRIGHT
|wxGROW
, 10 );
212 // 2) middle row with radio box
214 wxString
*choices
= new wxString
[2];
215 choices
[0] = _("All");
216 choices
[1] = _("Pages");
220 m_rangeRadioBox
= NULL
;
222 if (m_printDialogData
.GetFromPage() != 0)
224 m_rangeRadioBox
= new wxRadioBox(this, wxPRINTID_RANGE
, _("Print Range"),
225 wxDefaultPosition
, wxDefaultSize
,
227 m_rangeRadioBox
->SetSelection(1);
229 mainsizer
->Add( m_rangeRadioBox
, 0, wxLEFT
|wxTOP
|wxRIGHT
, 10 );
234 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
236 if (m_printDialogData
.GetFromPage() != 0)
238 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("From:") ), 0, wxCENTER
|wxALL
, 5 );
239 m_fromText
= new wxTextCtrl(this, wxPRINTID_FROM
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
240 bottomsizer
->Add( m_fromText
, 1, wxCENTER
|wxRIGHT
, 10 );
242 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("To:") ), 0, wxCENTER
|wxALL
, 5);
243 m_toText
= new wxTextCtrl(this, wxPRINTID_TO
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
244 bottomsizer
->Add( m_toText
, 1, wxCENTER
|wxRIGHT
, 10 );
247 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Copies:") ), 0, wxCENTER
|wxALL
, 5 );
248 m_noCopiesText
= new wxTextCtrl(this, wxPRINTID_COPIES
, wxEmptyString
, wxPoint(252, 130), wxSize(40, wxDefaultCoord
));
249 bottomsizer
->Add( m_noCopiesText
, 1, wxCENTER
|wxRIGHT
, 10 );
251 mainsizer
->Add( bottomsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 12 );
255 wxSizer
*sizerBtn
= CreateSeparatedButtonSizer( wxOK
|wxCANCEL
);
257 mainsizer
->Add(sizerBtn
, 0, wxEXPAND
|wxALL
, 10 );
259 SetAutoLayout( true );
260 SetSizer( mainsizer
);
262 mainsizer
->Fit( this );
265 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
270 int wxGenericPrintDialog
::ShowModal()
272 return wxDialog
::ShowModal();
275 wxGenericPrintDialog
::~wxGenericPrintDialog()
279 void wxGenericPrintDialog
::OnOK(wxCommandEvent
& WXUNUSED(event
))
281 TransferDataFromWindow();
283 // An empty 'to' field signals printing just the
285 if (m_printDialogData
.GetToPage() < 1)
286 m_printDialogData
.SetToPage(m_printDialogData
.GetFromPage());
288 // There are some interactions between the global setup data
289 // and the standard print dialog. The global printing 'mode'
290 // is determined by whether the user checks Print to file
292 if (m_printDialogData
.GetPrintToFile())
294 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE
);
296 wxFileName
fname( m_printDialogData
.GetPrintData().GetFilename() );
298 wxFileDialog
dialog( this, _("PostScript file"),
299 fname
.GetPath(), fname
.GetFullName(), wxT("*.ps"), wxFD_SAVE
| wxFD_OVERWRITE_PROMPT
);
300 if (dialog
.ShowModal() != wxID_OK
) return;
302 m_printDialogData
.GetPrintData().SetFilename( dialog
.GetPath() );
306 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER
);
312 void wxGenericPrintDialog
::OnRange(wxCommandEvent
& event
)
314 if (!m_fromText
) return;
316 if (event
.GetInt() == 0)
318 m_fromText
->Enable(false);
319 m_toText
->Enable(false);
321 else if (event
.GetInt() == 1)
323 m_fromText
->Enable(true);
324 m_toText
->Enable(true);
328 void wxGenericPrintDialog
::OnSetup(wxCommandEvent
& WXUNUSED(event
))
330 wxPrintFactory
* factory
= wxPrintFactory
::GetFactory();
332 if (factory
->HasPrintSetupDialog())
334 // The print setup dialog should change the
335 // print data in-place if not cancelled.
336 wxDialog
*dialog
= factory
->CreatePrintSetupDialog( this, &m_printDialogData
.GetPrintData() );
342 bool wxGenericPrintDialog
::TransferDataToWindow()
344 if(m_printDialogData
.GetFromPage() != 0)
348 if (m_printDialogData
.GetEnablePageNumbers())
350 m_fromText
->Enable(true);
351 m_toText
->Enable(true);
352 if (m_printDialogData
.GetFromPage() > 0)
353 m_fromText
->SetValue(wxString
::Format(wxT("%d"), m_printDialogData
.GetFromPage()));
354 if (m_printDialogData
.GetToPage() > 0)
355 m_toText
->SetValue(wxString
::Format(wxT("%d"), m_printDialogData
.GetToPage()));
358 if (m_printDialogData
.GetAllPages() || m_printDialogData
.GetFromPage() == 0)
359 m_rangeRadioBox
->SetSelection(0);
361 m_rangeRadioBox
->SetSelection(1);
366 m_fromText
->Enable(false);
367 m_toText
->Enable(false);
370 m_rangeRadioBox
->SetSelection(0);
371 m_rangeRadioBox
->wxRadioBox
::Enable(1, false);
376 m_noCopiesText
->SetValue(
377 wxString
::Format(wxT("%d"), m_printDialogData
.GetNoCopies()));
379 m_printToFileCheckBox
->SetValue(m_printDialogData
.GetPrintToFile());
380 m_printToFileCheckBox
->Enable(m_printDialogData
.GetEnablePrintToFile());
384 bool wxGenericPrintDialog
::TransferDataFromWindow()
387 if(m_printDialogData
.GetFromPage() != -1)
389 if (m_printDialogData
.GetEnablePageNumbers())
393 wxString value
= m_fromText
->GetValue();
394 if (value
.ToLong( &res
))
395 m_printDialogData
.SetFromPage( res
);
399 wxString value
= m_toText
->GetValue();
400 if (value
.ToLong( &res
))
401 m_printDialogData
.SetToPage( res
);
406 if (m_rangeRadioBox
->GetSelection() == 0)
408 m_printDialogData
.SetAllPages(true);
410 // This means all pages, more or less
411 m_printDialogData
.SetFromPage(1);
412 m_printDialogData
.SetToPage(32000);
415 m_printDialogData
.SetAllPages(false);
419 { // continuous printing
420 m_printDialogData
.SetFromPage(1);
421 m_printDialogData
.SetToPage(32000);
424 wxString value
= m_noCopiesText
->GetValue();
425 if (value
.ToLong( &res
))
426 m_printDialogData
.SetNoCopies( res
);
428 m_printDialogData
.SetPrintToFile(m_printToFileCheckBox
->GetValue());
433 wxDC
*wxGenericPrintDialog
::GetPrintDC()
435 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
438 // ----------------------------------------------------------------------------
439 // Generic print setup dialog
440 // ----------------------------------------------------------------------------
442 IMPLEMENT_CLASS(wxGenericPrintSetupDialog
, wxDialog
)
444 BEGIN_EVENT_TABLE(wxGenericPrintSetupDialog
, wxDialog
)
445 EVT_LIST_ITEM_ACTIVATED(wxPRINTID_PRINTER
, wxGenericPrintSetupDialog
::OnPrinter
)
448 wxGenericPrintSetupDialog
::wxGenericPrintSetupDialog(wxWindow
*parent
, wxPrintData
* data
):
449 wxDialog(parent
, wxID_ANY
, _("Print Setup"), wxPoint(0,0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
455 static const char* const check_xpm
[] = {
456 /* width height ncolors chars_per_pixel */
482 void wxGenericPrintSetupDialog
::Init(wxPrintData
* data
)
489 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
493 wxStaticBoxSizer
*printer_sizer
= new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY
, _("Printer") ), wxVERTICAL
);
494 main_sizer
->Add( printer_sizer
, 0, wxALL
|wxGROW
, 10 );
496 m_printerListCtrl
= new wxListCtrl( this, wxPRINTID_PRINTER
,
497 wxDefaultPosition
, wxSize(wxDefaultCoord
,100), wxLC_REPORT
|wxLC_SINGLE_SEL
|wxSUNKEN_BORDER
);
498 wxImageList
*image_list
= new wxImageList
;
499 image_list
->Add( wxBitmap(check_xpm
) );
500 m_printerListCtrl
->AssignImageList( image_list
, wxIMAGE_LIST_SMALL
);
502 m_printerListCtrl
->InsertColumn( 0, wxT(" "), wxLIST_FORMAT_LEFT
, 20 );
503 m_printerListCtrl
->InsertColumn( 1, wxT("Printer"), wxLIST_FORMAT_LEFT
, 150 );
504 m_printerListCtrl
->InsertColumn( 2, wxT("Device"), wxLIST_FORMAT_LEFT
, 150 );
505 m_printerListCtrl
->InsertColumn( 3, wxT("Status"), wxLIST_FORMAT_LEFT
, 80 );
508 item
.SetMask( wxLIST_MASK_TEXT
);
510 item
.SetText( _("Default printer") );
511 item
.SetId( m_printerListCtrl
->InsertItem( item
) );
513 if (data
->GetPrinterName().empty())
516 item2
.SetId( item
.GetId() );
517 item2
.SetMask( wxLIST_MASK_IMAGE
);
519 m_printerListCtrl
->SetItem( item2
);
521 m_printerListCtrl
->SetItemState( item
.GetId(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
524 item
.SetId( 1+ item
.GetId() );
526 wxArrayString errors
;
527 wxArrayString output
;
528 long res
= wxExecute( wxT("lpstat -v"), output
, errors
, wxEXEC_NODISABLE
);
529 if (res
>= 0 && errors
.GetCount() == 0)
532 for (i
= 0; i
< output
.GetCount(); i
++)
534 wxStringTokenizer
tok( output
[i
], wxT(" ") );
535 wxString tmp
= tok
.GetNextToken(); // "device"
536 if (tmp
!= wxT("device"))
537 break; // the lpstat syntax must have changed.
538 tmp
= tok
.GetNextToken(); // "for"
539 if (tmp
!= wxT("for"))
540 break; // the lpstat syntax must have changed.
541 tmp
= tok
.GetNextToken(); // "hp_deskjet930c:"
542 if (tmp
[tmp
.length()-1] == wxT(':'))
543 tmp
.Remove(tmp
.length()-1,1);
545 item
.SetText( name
);
546 item
.SetId( m_printerListCtrl
->InsertItem( item
) );
547 tmp
= tok
.GetNextToken(); // "parallel:/dev/lp0"
550 m_printerListCtrl
->SetItem( item
);
551 if (data
->GetPrinterName() == name
)
554 item2
.SetId( item
.GetId() );
555 item2
.SetMask( wxLIST_MASK_IMAGE
);
557 m_printerListCtrl
->SetItem( item2
);
559 m_printerListCtrl
->SetItemState( item
.GetId(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
562 wxString command
= wxT("lpstat -p ");
564 wxArrayString errors2
;
565 wxArrayString output2
;
566 res
= wxExecute( command
, output2
, errors2
, wxEXEC_NODISABLE
);
567 if (res
>= 0 && errors2
.GetCount() == 0 && output2
.GetCount() > 0)
569 tmp
= output2
[0]; // "printer hp_deskjet930c is idle. enable since ..."
570 int pos
= tmp
.Find( wxT('.') );
571 if (pos
!= wxNOT_FOUND
)
572 tmp
.Remove( (size_t)pos
, tmp
.length()-(size_t)pos
);
573 wxStringTokenizer
tok2( tmp
, wxT(" ") );
574 tmp
= tok2
.GetNextToken(); // "printer"
575 tmp
= tok2
.GetNextToken(); // "hp_deskjet930c"
577 while (tok2
.HasMoreTokens())
579 tmp
+= tok2
.GetNextToken();
584 m_printerListCtrl
->SetItem( item
);
588 item
.SetId( 1+ item
.GetId() );
593 printer_sizer
->Add( m_printerListCtrl
, 0, wxALL
|wxGROW
, 5 );
595 wxBoxSizer
*item1
= new wxBoxSizer( wxHORIZONTAL
);
596 main_sizer
->Add( item1
, 0, wxALL
, 5 );
598 // printer options (on the left)
600 wxBoxSizer
*item2
= new wxBoxSizer( wxVERTICAL
);
602 wxStaticBox
*item4
= new wxStaticBox( this, wxPRINTID_STATIC
, _("Paper size") );
603 wxStaticBoxSizer
*item3
= new wxStaticBoxSizer( item4
, wxVERTICAL
);
605 m_paperTypeChoice
= CreatePaperTypeChoice();
606 item3
->Add( m_paperTypeChoice
, 0, wxALIGN_CENTER
|wxALL
, 5 );
608 item2
->Add( item3
, 0, wxALIGN_CENTER
|wxALL
, 5 );
615 m_orientationRadioBox
= new wxRadioBox( this, wxPRINTID_ORIENTATION
, _("Orientation"), wxDefaultPosition
, wxDefaultSize
, 2, strs6
, 1, wxRA_SPECIFY_ROWS
);
616 item2
->Add( m_orientationRadioBox
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
618 wxStaticBox
*item8
= new wxStaticBox( this, wxID_ANY
, _("Options") );
619 wxStaticBoxSizer
*item7
= new wxStaticBoxSizer( item8
, wxHORIZONTAL
);
621 m_colourCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTCOLOUR
, _("Print in colour") );
622 item7
->Add( m_colourCheckBox
, 0, wxALIGN_CENTER
|wxALL
, 5 );
624 item2
->Add( item7
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
626 item1
->Add( item2
, 0, wxALIGN_CENTER_HORIZONTAL
, 5 );
628 // spooling options (on the right)
630 wxStaticBox
*item11
= new wxStaticBox( this, wxID_ANY
, _("Print spooling") );
631 wxStaticBoxSizer
*item10
= new wxStaticBoxSizer( item11
, wxVERTICAL
);
633 wxStaticText
*item12
= new wxStaticText( this, wxID_ANY
, _("Printer command:") );
634 item10
->Add( item12
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
636 wxBoxSizer
*item13
= new wxBoxSizer( wxHORIZONTAL
);
638 item13
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
640 m_printerCommandText
= new wxTextCtrl( this, wxPRINTID_COMMAND
, wxEmptyString
, wxDefaultPosition
, wxSize(160,wxDefaultCoord
) );
641 item13
->Add( m_printerCommandText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
643 item10
->Add( item13
, 0, wxALIGN_CENTER
|wxALL
, 0 );
645 wxStaticText
*item15
= new wxStaticText( this, wxID_ANY
, _("Printer options:") );
646 item10
->Add( item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
648 wxBoxSizer
*item16
= new wxBoxSizer( wxHORIZONTAL
);
650 item16
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
652 m_printerOptionsText
= new wxTextCtrl( this, wxPRINTID_OPTIONS
, wxEmptyString
, wxDefaultPosition
, wxSize(160,wxDefaultCoord
) );
653 item16
->Add( m_printerOptionsText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
655 item10
->Add( item16
, 0, wxALIGN_CENTER
|wxALL
, 0 );
657 item1
->Add( item10
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5 );
662 main_sizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
667 main_sizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxEXPAND
|wxALL
, 10 );
669 SetAutoLayout( true );
670 SetSizer( main_sizer
);
672 main_sizer
->Fit( this );
682 wxGenericPrintSetupDialog
::~wxGenericPrintSetupDialog()
686 void wxGenericPrintSetupDialog
::OnPrinter(wxListEvent
& event
)
689 for (long item
= 0; item
< m_printerListCtrl
->GetItemCount(); item
++)
690 m_printerListCtrl
->SetItemImage( item
, -1 );
692 m_printerListCtrl
->SetItemImage( event
.GetIndex(), 0 );
694 if (event
.GetIndex() == 0)
696 m_printerCommandText
->SetValue( wxT("lpr") );
702 li
.SetMask( wxLIST_MASK_TEXT
);
703 li
.SetId( event
.GetIndex() );
704 m_printerListCtrl
->GetItem( li
);
705 m_printerCommandText
->SetValue( wxT("lpr -P") + li
.GetText() );
709 bool wxGenericPrintSetupDialog
::TransferDataToWindow()
711 wxPostScriptPrintNativeData
*data
=
712 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
714 if (m_printerCommandText
&& !data
->GetPrinterCommand().empty())
715 m_printerCommandText
->SetValue(data
->GetPrinterCommand());
716 if (m_printerOptionsText
&& !data
->GetPrinterOptions().empty())
717 m_printerOptionsText
->SetValue(data
->GetPrinterOptions());
718 if (m_colourCheckBox
)
719 m_colourCheckBox
->SetValue(m_printData
.GetColour());
721 if (m_orientationRadioBox
)
723 if (m_printData
.GetOrientation() == wxPORTRAIT
)
724 m_orientationRadioBox
->SetSelection(0);
726 m_orientationRadioBox
->SetSelection(1);
731 bool wxGenericPrintSetupDialog
::TransferDataFromWindow()
733 wxPostScriptPrintNativeData
*data
=
734 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
736 // find selected printer
737 long id
= m_printerListCtrl
->GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
740 m_printData
.SetPrinterName( wxEmptyString
);
746 item
.SetMask( wxLIST_MASK_TEXT
);
748 m_printerListCtrl
->GetItem( item
);
749 m_printData
.SetPrinterName( item
.GetText() );
752 if (m_printerCommandText
)
753 data
->SetPrinterCommand(m_printerCommandText
->GetValue());
754 if (m_printerOptionsText
)
755 data
->SetPrinterOptions(m_printerOptionsText
->GetValue());
756 if (m_colourCheckBox
)
757 m_printData
.SetColour(m_colourCheckBox
->GetValue());
758 if (m_orientationRadioBox
)
760 int sel
= m_orientationRadioBox
->GetSelection();
762 m_printData
.SetOrientation(wxPORTRAIT
);
764 m_printData
.SetOrientation(wxLANDSCAPE
);
766 if (m_paperTypeChoice
)
768 int selectedItem
= m_paperTypeChoice
->GetSelection();
769 if (selectedItem
!= -1)
771 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
773 m_printData
.SetPaperId( paper
->GetId());
778 *m_targetData
= m_printData
;
783 wxComboBox
*wxGenericPrintSetupDialog
::CreatePaperTypeChoice()
785 size_t n
= wxThePrintPaperDatabase
->GetCount();
786 wxString
*choices
= new wxString
[n
];
789 for (size_t i
= 0; i
< n
; i
++)
791 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
792 choices
[i
] = paper
->GetName();
793 if (m_printData
.GetPaperId() == paper
->GetId())
799 wxComboBox
*choice
= new wxComboBox( this,
803 wxSize(width
, wxDefaultCoord
),
808 choice
->SetSelection(sel
);
812 #endif // wxUSE_POSTSCRIPT
814 // ----------------------------------------------------------------------------
815 // Generic page setup dialog
816 // ----------------------------------------------------------------------------
818 IMPLEMENT_CLASS(wxGenericPageSetupDialog
, wxPageSetupDialogBase
)
820 BEGIN_EVENT_TABLE(wxGenericPageSetupDialog
, wxPageSetupDialogBase
)
821 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPageSetupDialog
::OnPrinter
)
824 wxGenericPageSetupDialog
::wxGenericPageSetupDialog( wxWindow
*parent
,
825 wxPageSetupDialogData
* data
)
826 : wxPageSetupDialogBase( parent
,
831 wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
838 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
841 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
842 new wxStaticBox(this,wxPRINTID_STATIC
, _("Paper size")), wxHORIZONTAL
);
844 size_t n
= wxThePrintPaperDatabase
->GetCount();
845 wxString
*choices
= new wxString
[n
];
847 for (size_t i
= 0; i
< n
; i
++)
849 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
850 choices
[i
] = paper
->GetName();
853 m_paperTypeChoice
= new wxComboBox( this,
857 wxSize(300, wxDefaultCoord
),
859 topsizer
->Add( m_paperTypeChoice
, 1, wxEXPAND
|wxALL
, 5 );
860 // m_paperTypeChoice->SetSelection(sel);
862 mainsizer
->Add( topsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
864 // 2) middle sizer with radio box
866 wxString
*choices2
= new wxString
[2];
867 choices2
[0] = _("Portrait");
868 choices2
[1] = _("Landscape");
869 m_orientationRadioBox
= new wxRadioBox(this, wxPRINTID_ORIENTATION
, _("Orientation"),
870 wxDefaultPosition
, wxDefaultSize
, 2, choices2
, 2);
871 m_orientationRadioBox
->SetSelection(0);
873 mainsizer
->Add( m_orientationRadioBox
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 10 );
877 wxBoxSizer
*table
= new wxBoxSizer( wxHORIZONTAL
);
879 wxBoxSizer
*column1
= new wxBoxSizer( wxVERTICAL
);
880 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Left margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
881 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Top margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
882 table
->Add( column1
, 0, wxALL
| wxEXPAND
, 5 );
884 wxBoxSizer
*column2
= new wxBoxSizer( wxVERTICAL
);
885 m_marginLeftText
= new wxTextCtrl(this, wxPRINTID_LEFTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
886 m_marginTopText
= new wxTextCtrl(this, wxPRINTID_TOPMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
887 column2
->Add( m_marginLeftText
, 1, wxALL
, 5 );
888 column2
->Add( m_marginTopText
, 1, wxALL
, 5 );
889 table
->Add( column2
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
891 wxBoxSizer
*column3
= new wxBoxSizer( wxVERTICAL
);
892 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Right margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
893 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Bottom margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
894 table
->Add( column3
, 0, wxALL
| wxEXPAND
, 5 );
896 wxBoxSizer
*column4
= new wxBoxSizer( wxVERTICAL
);
897 m_marginRightText
= new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
898 m_marginBottomText
= new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
899 column4
->Add( m_marginRightText
, 1, wxALL
, 5 );
900 column4
->Add( m_marginBottomText
, 1, wxALL
, 5 );
901 table
->Add( column4
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
903 mainsizer
->Add( table
, 0 );
907 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
912 wxSizer
* buttonsizer
= CreateButtonSizer( wxOK
|wxCANCEL
);
914 if (wxPrintFactory
::GetFactory()->HasPrintSetupDialog())
916 m_printerButton
= new wxButton(this, wxPRINTID_SETUP
, _("Printer...") );
917 buttonsizer
->Add( m_printerButton
, 0, wxLEFT
|wxRIGHT
, 10 );
918 if ( !m_pageData
.GetEnablePrinter() )
919 m_printerButton
->Enable(false);
923 m_printerButton
= NULL
;
926 // if (m_printData.GetEnableHelp())
927 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight);
928 mainsizer
->Add( buttonsizer
, 0, wxEXPAND
|wxALL
, 10 );
931 SetAutoLayout( true );
932 SetSizer( mainsizer
);
934 mainsizer
->Fit( this );
943 wxGenericPageSetupDialog
::~wxGenericPageSetupDialog()
947 wxPageSetupDialogData
& wxGenericPageSetupDialog
::GetPageSetupDialogData()
952 bool wxGenericPageSetupDialog
::TransferDataToWindow()
954 if (m_marginLeftText
)
955 m_marginLeftText
->SetValue(wxString
::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().x
));
957 m_marginTopText
->SetValue(wxString
::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().y
));
958 if (m_marginRightText
)
959 m_marginRightText
->SetValue(wxString
::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().x
));
960 if (m_marginBottomText
)
961 m_marginBottomText
->SetValue(wxString
::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().y
));
963 if (m_orientationRadioBox
)
965 if (m_pageData
.GetPrintData().GetOrientation() == wxPORTRAIT
)
966 m_orientationRadioBox
->SetSelection(0);
968 m_orientationRadioBox
->SetSelection(1);
971 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
972 // failing that, the id in the wxPrintData object.
974 wxPrintPaperType
* type
= wxThePrintPaperDatabase
->FindPaperType(
975 wxSize(m_pageData
.GetPaperSize().x
* 10, m_pageData
.GetPaperSize().y
* 10));
977 if (!type
&& m_pageData
.GetPrintData().GetPaperId() != wxPAPER_NONE
)
978 type
= wxThePrintPaperDatabase
->FindPaperType(m_pageData
.GetPrintData().GetPaperId());
982 m_paperTypeChoice
->SetStringSelection(type
->GetName());
988 bool wxGenericPageSetupDialog
::TransferDataFromWindow()
990 if (m_marginLeftText
&& m_marginTopText
)
992 int left
= wxAtoi( m_marginLeftText
->GetValue().c_str() );
993 int top
= wxAtoi( m_marginTopText
->GetValue().c_str() );
994 m_pageData
.SetMarginTopLeft( wxPoint(left
,top
) );
996 if (m_marginRightText
&& m_marginBottomText
)
998 int right
= wxAtoi( m_marginRightText
->GetValue().c_str() );
999 int bottom
= wxAtoi( m_marginBottomText
->GetValue().c_str() );
1000 m_pageData
.SetMarginBottomRight( wxPoint(right
,bottom
) );
1003 if (m_orientationRadioBox
)
1005 int sel
= m_orientationRadioBox
->GetSelection();
1008 m_pageData
.GetPrintData().SetOrientation(wxPORTRAIT
);
1012 m_pageData
.GetPrintData().SetOrientation(wxLANDSCAPE
);
1016 if (m_paperTypeChoice
)
1018 int selectedItem
= m_paperTypeChoice
->GetSelection();
1019 if (selectedItem
!= -1)
1021 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
1024 m_pageData
.SetPaperSize(wxSize(paper
->GetWidth()/10, paper
->GetHeight()/10));
1025 m_pageData
.GetPrintData().SetPaperId(paper
->GetId());
1033 wxComboBox
*wxGenericPageSetupDialog
::CreatePaperTypeChoice(int *x
, int *y
)
1036 if (!wxThePrintPaperDatabase)
1038 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
1039 wxThePrintPaperDatabase->CreateDatabase();
1043 size_t n
= wxThePrintPaperDatabase
->GetCount();
1044 wxString
*choices
= new wxString
[n
];
1046 for (size_t i
= 0; i
< n
; i
++)
1048 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
1049 choices
[i
] = paper
->GetName();
1052 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Paper size"), wxPoint(*x
, *y
));
1055 wxComboBox
*choice
= new wxComboBox( this,
1056 wxPRINTID_PAPERSIZE
,
1059 wxSize(300, wxDefaultCoord
),
1064 // choice->SetSelection(sel);
1068 void wxGenericPageSetupDialog
::OnPrinter(wxCommandEvent
& WXUNUSED(event
))
1070 // We no longer query GetPrintMode, so we can eliminate the need
1071 // to call SetPrintMode.
1072 // This has the limitation that we can't explicitly call the PostScript
1073 // print setup dialog from the generic Page Setup dialog under Windows,
1074 // but since this choice would only happen when trying to do PostScript
1075 // printing under Windows (and only in 16-bit Windows which
1076 // doesn't have a Windows-specific page setup dialog) it's worth it.
1078 // First save the current settings, so the wxPrintData object is up to date.
1079 TransferDataFromWindow();
1081 // Transfer the current print settings from this dialog to the page setup dialog.
1084 // Use print factory later
1086 wxPrintDialogData data
;
1087 data
= GetPageSetupData().GetPrintData();
1088 data
.SetSetupDialog(true);
1089 wxPrintDialog
printDialog(this, & data
);
1090 printDialog
.ShowModal();
1092 // Transfer the page setup print settings from the page dialog to this dialog again, in case
1093 // the page setup dialog changed something.
1094 GetPageSetupData().GetPrintData() = printDialog
.GetPrintDialogData().GetPrintData();
1095 GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData
1097 // Now update the dialog in case the page setup dialog changed some of our settings.
1098 TransferDataToWindow();