1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Generic print dialogs
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "prntdlgg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 #if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
36 #include "wx/stattext.h"
37 #include "wx/statbox.h"
38 #include "wx/button.h"
39 #include "wx/checkbox.h"
40 #include "wx/textctrl.h"
41 #include "wx/radiobox.h"
42 #include "wx/filedlg.h"
43 #include "wx/combobox.h"
46 #include "wx/cmndata.h"
50 #include "wx/statline.h"
53 #include "wx/generic/prntdlgg.h"
56 #include "wx/generic/dcpsg.h"
59 #include "wx/prntbase.h"
60 #include "wx/printdlg.h"
62 #include "wx/filename.h"
63 #include "wx/tokenzr.h"
64 #include "wx/imaglist.h"
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
73 extern wxPrintPaperDatabase
*wxThePrintPaperDatabase
;
77 //----------------------------------------------------------------------------
78 // wxPostScriptNativeData
79 //----------------------------------------------------------------------------
81 IMPLEMENT_CLASS(wxPostScriptPrintNativeData
, wxPrintNativeDataBase
)
83 wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
85 m_previewCommand
= wxEmptyString
;
87 m_printerCommand
= wxT("print");
88 m_printerOptions
= wxT("/nonotify/queue=psqueue");
89 m_afmPath
= wxT("sys$ps_font_metrics:");
93 m_printerCommand
= wxT("print");
94 m_printerOptions
= wxEmptyString
;
95 m_afmPath
= wxT("c:\\windows\\system\\");
98 #if !defined(__VMS__) && !defined(__WXMSW__)
99 m_printerCommand
= wxT("lpr");
100 m_printerOptions
= wxEmptyString
;
101 m_afmPath
= wxEmptyString
;
104 m_printerScaleX
= 1.0;
105 m_printerScaleY
= 1.0;
106 m_printerTranslateX
= 0;
107 m_printerTranslateY
= 0;
110 wxPostScriptPrintNativeData::~wxPostScriptPrintNativeData()
114 bool wxPostScriptPrintNativeData::TransferTo( wxPrintData
&WXUNUSED(data
) )
119 bool wxPostScriptPrintNativeData::TransferFrom( const wxPrintData
&WXUNUSED(data
) )
124 // ----------------------------------------------------------------------------
125 // Generic print dialog for non-Windows printing use.
126 // ----------------------------------------------------------------------------
128 IMPLEMENT_CLASS(wxGenericPrintDialog
, wxPrintDialogBase
)
130 BEGIN_EVENT_TABLE(wxGenericPrintDialog
, wxPrintDialogBase
)
131 EVT_BUTTON(wxID_OK
, wxGenericPrintDialog::OnOK
)
132 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPrintDialog::OnSetup
)
133 EVT_RADIOBOX(wxPRINTID_RANGE
, wxGenericPrintDialog::OnRange
)
136 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
,
137 wxPrintDialogData
* data
)
138 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
139 wxPoint(0,0), wxSize(600, 600),
140 wxDEFAULT_DIALOG_STYLE
|
144 m_printDialogData
= *data
;
149 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow
*parent
,
151 : wxPrintDialogBase(parent
, wxID_ANY
, _("Print"),
152 wxPoint(0,0), wxSize(600, 600),
153 wxDEFAULT_DIALOG_STYLE
|
157 m_printDialogData
= *data
;
162 void wxGenericPrintDialog::Init(wxWindow
* WXUNUSED(parent
))
164 // wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0,0), wxSize(600, 600),
165 // wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL);
167 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
171 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
173 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
174 new wxStaticBox( this, wxID_ANY
, _( "Printer options" ) ), wxHORIZONTAL
);
175 wxFlexGridSizer
*flex
= new wxFlexGridSizer( 2 );
176 flex
->AddGrowableCol( 1 );
177 topsizer
->Add( flex
, 1, wxGROW
);
179 m_printToFileCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTTOFILE
, _("Print to File") );
180 flex
->Add( m_printToFileCheckBox
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
182 m_setupButton
= new wxButton(this, wxPRINTID_SETUP
, _("Setup...") );
183 flex
->Add( m_setupButton
, 0, wxALIGN_CENTER_VERTICAL
|wxALIGN_RIGHT
|wxALL
, 5 );
185 if (!factory
->HasPrintSetupDialog())
186 m_setupButton
->Enable( false );
188 if (factory
->HasPrinterLine())
190 flex
->Add( new wxStaticText( this, wxID_ANY
, _("Printer:") ),
191 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
192 flex
->Add( new wxStaticText( this, wxID_ANY
, factory
->CreatePrinterLine() ),
193 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
196 if (factory
->HasStatusLine())
198 flex
->Add( new wxStaticText( this, wxID_ANY
, _("Status:") ),
199 0, wxALIGN_CENTER_VERTICAL
|wxALL
-wxTOP
, 5 );
200 flex
->Add( new wxStaticText( this, wxID_ANY
, factory
->CreateStatusLine() ),
201 0, wxALIGN_CENTER_VERTICAL
|wxALL
-wxTOP
, 5 );
204 mainsizer
->Add( topsizer
, 0, wxLEFT
|wxTOP
|wxRIGHT
|wxGROW
, 10 );
206 // 2) middle row with radio box
208 wxString
*choices
= new wxString
[2];
209 choices
[0] = _("All");
210 choices
[1] = _("Pages");
212 m_fromText
= (wxTextCtrl
*)NULL
;
213 m_toText
= (wxTextCtrl
*)NULL
;
214 m_rangeRadioBox
= (wxRadioBox
*)NULL
;
216 if (m_printDialogData
.GetFromPage() != 0)
218 m_rangeRadioBox
= new wxRadioBox(this, wxPRINTID_RANGE
, _("Print Range"),
219 wxDefaultPosition
, wxDefaultSize
,
222 m_rangeRadioBox
->SetSelection(1);
224 mainsizer
->Add( m_rangeRadioBox
, 0, wxLEFT
|wxTOP
|wxRIGHT
, 10 );
229 wxBoxSizer
*bottomsizer
= new wxBoxSizer( wxHORIZONTAL
);
231 if (m_printDialogData
.GetFromPage() != 0)
233 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("From:") ), 0, wxCENTER
|wxALL
, 5 );
234 m_fromText
= new wxTextCtrl(this, wxPRINTID_FROM
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
235 bottomsizer
->Add( m_fromText
, 1, wxCENTER
|wxRIGHT
, 10 );
237 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("To:") ), 0, wxCENTER
|wxALL
, 5);
238 m_toText
= new wxTextCtrl(this, wxPRINTID_TO
, wxEmptyString
, wxDefaultPosition
, wxSize(40, wxDefaultCoord
));
239 bottomsizer
->Add( m_toText
, 1, wxCENTER
|wxRIGHT
, 10 );
242 bottomsizer
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Copies:") ), 0, wxCENTER
|wxALL
, 5 );
243 m_noCopiesText
= new wxTextCtrl(this, wxPRINTID_COPIES
, wxEmptyString
, wxPoint(252, 130), wxSize(40, wxDefaultCoord
));
244 bottomsizer
->Add( m_noCopiesText
, 1, wxCENTER
|wxRIGHT
, 10 );
246 mainsizer
->Add( bottomsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 12 );
250 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
255 mainsizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxEXPAND
|wxALL
, 10 );
257 SetAutoLayout( true );
258 SetSizer( mainsizer
);
260 mainsizer
->Fit( this );
263 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
268 int wxGenericPrintDialog::ShowModal()
270 return wxDialog::ShowModal();
273 wxGenericPrintDialog::~wxGenericPrintDialog()
277 void wxGenericPrintDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
279 TransferDataFromWindow();
281 // An empty 'to' field signals printing just the
283 if (m_printDialogData
.GetToPage() < 1)
284 m_printDialogData
.SetToPage(m_printDialogData
.GetFromPage());
286 // There are some interactions between the global setup data
287 // and the standard print dialog. The global printing 'mode'
288 // is determined by whether the user checks Print to file
290 if (m_printDialogData
.GetPrintToFile())
292 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE
);
294 wxFileName
fname( m_printDialogData
.GetPrintData().GetFilename() );
296 wxFileDialog
dialog( this, _("PostScript file"),
297 fname
.GetPath(), fname
.GetFullName(), wxT("*.ps"), wxSAVE
| wxOVERWRITE_PROMPT
);
298 if (dialog
.ShowModal() != wxID_OK
) return;
300 m_printDialogData
.GetPrintData().SetFilename( dialog
.GetPath() );
304 m_printDialogData
.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER
);
310 void wxGenericPrintDialog::OnRange(wxCommandEvent
& event
)
312 if (!m_fromText
) return;
314 if (event
.GetInt() == 0)
316 m_fromText
->Enable(false);
317 m_toText
->Enable(false);
319 else if (event
.GetInt() == 1)
321 m_fromText
->Enable(true);
322 m_toText
->Enable(true);
326 void wxGenericPrintDialog::OnSetup(wxCommandEvent
& WXUNUSED(event
))
328 wxPrintFactory
* factory
= wxPrintFactory::GetFactory();
330 if (factory
->HasPrintSetupDialog())
332 // The print setup dialog should change the
333 // print data in-place if not cancelled.
334 wxDialog
*dialog
= factory
->CreatePrintSetupDialog( this, &m_printDialogData
.GetPrintData() );
340 bool wxGenericPrintDialog::TransferDataToWindow()
342 if(m_printDialogData
.GetFromPage() != 0)
346 if (m_printDialogData
.GetEnablePageNumbers())
348 m_fromText
->Enable(true);
349 m_toText
->Enable(true);
350 if (m_printDialogData
.GetFromPage() > 0)
351 m_fromText
->SetValue(wxString::Format(_T("%d"), m_printDialogData
.GetFromPage()));
352 if (m_printDialogData
.GetToPage() > 0)
353 m_toText
->SetValue(wxString::Format(_T("%d"), m_printDialogData
.GetToPage()));
355 if (m_printDialogData
.GetAllPages() || m_printDialogData
.GetFromPage() == 0)
356 m_rangeRadioBox
->SetSelection(0);
358 m_rangeRadioBox
->SetSelection(1);
362 m_fromText
->Enable(false);
363 m_toText
->Enable(false);
366 m_rangeRadioBox
->SetSelection(0);
367 m_rangeRadioBox
->wxRadioBox::Enable(1, false);
372 m_noCopiesText
->SetValue(
373 wxString::Format(_T("%d"), m_printDialogData
.GetNoCopies()));
375 m_printToFileCheckBox
->SetValue(m_printDialogData
.GetPrintToFile());
376 m_printToFileCheckBox
->Enable(m_printDialogData
.GetEnablePrintToFile());
380 bool wxGenericPrintDialog::TransferDataFromWindow()
383 if(m_printDialogData
.GetFromPage() != -1)
385 if (m_printDialogData
.GetEnablePageNumbers())
389 wxString value
= m_fromText
->GetValue();
390 if (value
.ToLong( &res
))
391 m_printDialogData
.SetFromPage( res
);
395 wxString value
= m_toText
->GetValue();
396 if (value
.ToLong( &res
))
397 m_printDialogData
.SetToPage( res
);
402 if (m_rangeRadioBox
->GetSelection() == 0)
404 m_printDialogData
.SetAllPages(true);
406 // This means all pages, more or less
407 m_printDialogData
.SetFromPage(1);
408 m_printDialogData
.SetToPage(32000);
411 m_printDialogData
.SetAllPages(false);
415 { // continuous printing
416 m_printDialogData
.SetFromPage(1);
417 m_printDialogData
.SetToPage(32000);
420 wxString value
= m_noCopiesText
->GetValue();
421 if (value
.ToLong( &res
))
422 m_printDialogData
.SetNoCopies( res
);
424 m_printDialogData
.SetPrintToFile(m_printToFileCheckBox
->GetValue());
429 wxDC
*wxGenericPrintDialog::GetPrintDC()
431 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
434 // ----------------------------------------------------------------------------
435 // Generic print setup dialog
436 // ----------------------------------------------------------------------------
438 IMPLEMENT_CLASS(wxGenericPrintSetupDialog
, wxDialog
)
440 BEGIN_EVENT_TABLE(wxGenericPrintSetupDialog
, wxDialog
)
441 EVT_LIST_ITEM_ACTIVATED(wxPRINTID_PRINTER
, wxGenericPrintSetupDialog::OnPrinter
)
444 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow
*parent
, wxPrintData
* data
):
445 wxDialog(parent
, wxID_ANY
, _("Print Setup"), wxPoint(0,0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
451 static char * check_xpm
[] = {
452 /* width height ncolors chars_per_pixel */
478 void wxGenericPrintSetupDialog::Init(wxPrintData
* data
)
485 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
489 wxStaticBoxSizer
*printer_sizer
= new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY
, _("Printer") ), wxVERTICAL
);
490 main_sizer
->Add( printer_sizer
, 0, wxALL
|wxGROW
, 10 );
492 m_printerListCtrl
= new wxListCtrl( this, wxPRINTID_PRINTER
,
493 wxDefaultPosition
, wxSize(wxDefaultCoord
,100), wxLC_REPORT
|wxLC_SINGLE_SEL
|wxSUNKEN_BORDER
);
494 wxImageList
*image_list
= new wxImageList
;
495 image_list
->Add( wxBitmap(check_xpm
) );
496 m_printerListCtrl
->AssignImageList( image_list
, wxIMAGE_LIST_SMALL
);
498 m_printerListCtrl
->InsertColumn( 0, wxT(" "), wxLIST_FORMAT_LEFT
, 20 );
499 m_printerListCtrl
->InsertColumn( 1, wxT("Printer"), wxLIST_FORMAT_LEFT
, 150 );
500 m_printerListCtrl
->InsertColumn( 2, wxT("Device"), wxLIST_FORMAT_LEFT
, 150 );
501 m_printerListCtrl
->InsertColumn( 3, wxT("Status"), wxLIST_FORMAT_LEFT
, 80 );
504 item
.SetMask( wxLIST_MASK_TEXT
);
506 item
.SetText( _("Default printer") );
507 item
.SetId( m_printerListCtrl
->InsertItem( item
) );
509 if (data
->GetPrinterName().empty())
512 item2
.SetId( item
.GetId() );
513 item2
.SetMask( wxLIST_MASK_IMAGE
);
515 m_printerListCtrl
->SetItem( item2
);
517 m_printerListCtrl
->SetItemState( item
.GetId(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
520 item
.SetId( 1+ item
.GetId() );
522 wxArrayString errors
;
523 wxArrayString output
;
524 long res
= wxExecute( wxT("lpstat -v"), output
, errors
, wxEXEC_NODISABLE
);
525 if (res
>= 0 && errors
.GetCount() == 0)
528 for (i
= 0; i
< output
.GetCount(); i
++)
530 wxStringTokenizer
tok( output
[i
], wxT(" ") );
531 wxString tmp
= tok
.GetNextToken(); // "device"
532 if (tmp
!= wxT("device"))
533 break; // the lpstat syntax must have changed.
534 tmp
= tok
.GetNextToken(); // "for"
535 if (tmp
!= wxT("for"))
536 break; // the lpstat syntax must have changed.
537 tmp
= tok
.GetNextToken(); // "hp_deskjet930c:"
538 if (tmp
[tmp
.Len()-1] == wxT(':'))
539 tmp
.Remove(tmp
.Len()-1,1);
541 item
.SetText( name
);
542 item
.SetId( m_printerListCtrl
->InsertItem( item
) );
543 tmp
= tok
.GetNextToken(); // "parallel:/dev/lp0"
546 m_printerListCtrl
->SetItem( item
);
547 if (data
->GetPrinterName() == name
)
550 item2
.SetId( item
.GetId() );
551 item2
.SetMask( wxLIST_MASK_IMAGE
);
553 m_printerListCtrl
->SetItem( item2
);
555 m_printerListCtrl
->SetItemState( item
.GetId(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
558 wxString command
= wxT("lpstat -p ");
560 wxArrayString errors2
;
561 wxArrayString output2
;
562 res
= wxExecute( command
, output2
, errors2
, wxEXEC_NODISABLE
);
563 if (res
>= 0 && errors2
.GetCount() == 0 && output2
.GetCount() > 0)
565 tmp
= output2
[0]; // "printer hp_deskjet930c is idle. enable since ..."
566 int pos
= tmp
.Find( wxT('.') );
567 if (pos
!= wxNOT_FOUND
)
568 tmp
.Remove( (size_t)pos
, tmp
.Len()-(size_t)pos
);
569 wxStringTokenizer
tok2( tmp
, wxT(" ") );
570 tmp
= tok2
.GetNextToken(); // "printer"
571 tmp
= tok2
.GetNextToken(); // "hp_deskjet930c"
573 while (tok2
.HasMoreTokens())
575 tmp
+= tok2
.GetNextToken();
580 m_printerListCtrl
->SetItem( item
);
584 item
.SetId( 1+ item
.GetId() );
589 printer_sizer
->Add( m_printerListCtrl
, 0, wxALL
|wxGROW
, 5 );
591 wxBoxSizer
*item1
= new wxBoxSizer( wxHORIZONTAL
);
592 main_sizer
->Add( item1
, 0, wxALL
, 5 );
594 // printer options (on the left)
596 wxBoxSizer
*item2
= new wxBoxSizer( wxVERTICAL
);
598 wxStaticBox
*item4
= new wxStaticBox( this, wxPRINTID_STATIC
, _("Paper size") );
599 wxStaticBoxSizer
*item3
= new wxStaticBoxSizer( item4
, wxVERTICAL
);
601 m_paperTypeChoice
= CreatePaperTypeChoice();
602 item3
->Add( m_paperTypeChoice
, 0, wxALIGN_CENTER
|wxALL
, 5 );
604 item2
->Add( item3
, 0, wxALIGN_CENTER
|wxALL
, 5 );
611 m_orientationRadioBox
= new wxRadioBox( this, wxPRINTID_ORIENTATION
, _("Orientation"), wxDefaultPosition
, wxDefaultSize
, 2, strs6
, 1, wxRA_SPECIFY_ROWS
);
612 item2
->Add( m_orientationRadioBox
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
614 wxStaticBox
*item8
= new wxStaticBox( this, wxID_ANY
, _("Options") );
615 wxStaticBoxSizer
*item7
= new wxStaticBoxSizer( item8
, wxHORIZONTAL
);
617 m_colourCheckBox
= new wxCheckBox( this, wxPRINTID_PRINTCOLOUR
, _("Print in colour") );
618 item7
->Add( m_colourCheckBox
, 0, wxALIGN_CENTER
|wxALL
, 5 );
620 item2
->Add( item7
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
622 item1
->Add( item2
, 0, wxALIGN_CENTER_HORIZONTAL
, 5 );
624 // spooling options (on the right)
626 wxStaticBox
*item11
= new wxStaticBox( this, wxID_ANY
, _("Print spooling") );
627 wxStaticBoxSizer
*item10
= new wxStaticBoxSizer( item11
, wxVERTICAL
);
629 wxStaticText
*item12
= new wxStaticText( this, wxID_ANY
, _("Printer command:") );
630 item10
->Add( item12
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
632 wxBoxSizer
*item13
= new wxBoxSizer( wxHORIZONTAL
);
634 item13
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
636 m_printerCommandText
= new wxTextCtrl( this, wxPRINTID_COMMAND
, wxEmptyString
, wxDefaultPosition
, wxSize(160,wxDefaultCoord
) );
637 item13
->Add( m_printerCommandText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
639 item10
->Add( item13
, 0, wxALIGN_CENTER
|wxALL
, 0 );
641 wxStaticText
*item15
= new wxStaticText( this, wxID_ANY
, _("Printer options:") );
642 item10
->Add( item15
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
644 wxBoxSizer
*item16
= new wxBoxSizer( wxHORIZONTAL
);
646 item16
->Add( 20, 20, 0, wxALIGN_CENTER
|wxALL
, 5 );
648 m_printerOptionsText
= new wxTextCtrl( this, wxPRINTID_OPTIONS
, wxEmptyString
, wxDefaultPosition
, wxSize(160,wxDefaultCoord
) );
649 item16
->Add( m_printerOptionsText
, 0, wxALIGN_CENTER
|wxALL
, 5 );
651 item10
->Add( item16
, 0, wxALIGN_CENTER
|wxALL
, 0 );
653 item1
->Add( item10
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5 );
658 main_sizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
663 main_sizer
->Add( CreateButtonSizer( wxOK
|wxCANCEL
), 0, wxEXPAND
|wxALL
, 10 );
665 SetAutoLayout( true );
666 SetSizer( main_sizer
);
668 main_sizer
->Fit( this );
678 wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
682 void wxGenericPrintSetupDialog::OnPrinter(wxListEvent
& event
)
686 for (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") );
697 wxString tmp
= wxT("lpr -P");
700 item
.SetMask( wxLIST_MASK_TEXT
);
701 item
.SetId( event
.GetIndex() );
702 m_printerListCtrl
->GetItem( item
);
703 tmp
+= item
.GetText();
704 m_printerCommandText
->SetValue( tmp
);
708 bool wxGenericPrintSetupDialog::TransferDataToWindow()
710 wxPostScriptPrintNativeData
*data
=
711 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
713 if (m_printerCommandText
&& data
->GetPrinterCommand())
714 m_printerCommandText
->SetValue(data
->GetPrinterCommand());
715 if (m_printerOptionsText
&& data
->GetPrinterOptions())
716 m_printerOptionsText
->SetValue(data
->GetPrinterOptions());
717 if (m_colourCheckBox
)
718 m_colourCheckBox
->SetValue(m_printData
.GetColour());
720 if (m_orientationRadioBox
)
722 if (m_printData
.GetOrientation() == wxPORTRAIT
)
723 m_orientationRadioBox
->SetSelection(0);
725 m_orientationRadioBox
->SetSelection(1);
730 bool wxGenericPrintSetupDialog::TransferDataFromWindow()
732 wxPostScriptPrintNativeData
*data
=
733 (wxPostScriptPrintNativeData
*) m_printData
.GetNativeData();
735 // find selected printer
736 long id
= m_printerListCtrl
->GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
739 m_printData
.SetPrinterName( wxEmptyString
);
745 item
.SetMask( wxLIST_MASK_TEXT
);
747 m_printerListCtrl
->GetItem( item
);
748 m_printData
.SetPrinterName( item
.GetText() );
751 if (m_printerCommandText
)
752 data
->SetPrinterCommand(m_printerCommandText
->GetValue());
753 if (m_printerOptionsText
)
754 data
->SetPrinterOptions(m_printerOptionsText
->GetValue());
755 if (m_colourCheckBox
)
756 m_printData
.SetColour(m_colourCheckBox
->GetValue());
757 if (m_orientationRadioBox
)
759 int sel
= m_orientationRadioBox
->GetSelection();
761 m_printData
.SetOrientation(wxPORTRAIT
);
763 m_printData
.SetOrientation(wxLANDSCAPE
);
765 if (m_paperTypeChoice
)
767 int selectedItem
= m_paperTypeChoice
->GetSelection();
768 if (selectedItem
!= -1)
770 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
772 m_printData
.SetPaperId( paper
->GetId());
777 *m_targetData
= m_printData
;
782 wxComboBox
*wxGenericPrintSetupDialog::CreatePaperTypeChoice()
784 size_t n
= wxThePrintPaperDatabase
->GetCount();
785 wxString
*choices
= new wxString
[n
];
788 for (size_t i
= 0; i
< n
; i
++)
790 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
791 choices
[i
] = paper
->GetName();
792 if (m_printData
.GetPaperId() == paper
->GetId())
798 wxComboBox
*choice
= new wxComboBox( this,
802 wxSize(width
, wxDefaultCoord
),
807 choice
->SetSelection(sel
);
811 #endif // wxUSE_POSTSCRIPT
813 // ----------------------------------------------------------------------------
814 // Generic page setup dialog
815 // ----------------------------------------------------------------------------
817 IMPLEMENT_CLASS(wxGenericPageSetupDialog
, wxPageSetupDialogBase
)
819 BEGIN_EVENT_TABLE(wxGenericPageSetupDialog
, wxPageSetupDialogBase
)
820 EVT_BUTTON(wxPRINTID_SETUP
, wxGenericPageSetupDialog::OnPrinter
)
823 wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow
*parent
,
824 wxPageSetupDialogData
* data
)
825 : wxPageSetupDialogBase( parent
,
830 wxDEFAULT_DIALOG_STYLE
|wxTAB_TRAVERSAL
)
837 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
840 wxStaticBoxSizer
*topsizer
= new wxStaticBoxSizer(
841 new wxStaticBox(this,wxPRINTID_STATIC
, _("Paper size")), wxHORIZONTAL
);
843 size_t n
= wxThePrintPaperDatabase
->GetCount();
844 wxString
*choices
= new wxString
[n
];
846 for (size_t i
= 0; i
< n
; i
++)
848 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
849 choices
[i
] = paper
->GetName();
852 m_paperTypeChoice
= new wxComboBox( this,
856 wxSize(300, wxDefaultCoord
),
858 topsizer
->Add( m_paperTypeChoice
, 1, wxEXPAND
|wxALL
, 5 );
859 // m_paperTypeChoice->SetSelection(sel);
861 mainsizer
->Add( topsizer
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxEXPAND
, 10 );
863 // 2) middle sizer with radio box
865 wxString
*choices2
= new wxString
[2];
866 choices2
[0] = _("Portrait");
867 choices2
[1] = _("Landscape");
868 m_orientationRadioBox
= new wxRadioBox(this, wxPRINTID_ORIENTATION
, _("Orientation"),
869 wxDefaultPosition
, wxDefaultSize
, 2, choices2
, 2);
870 m_orientationRadioBox
->SetSelection(0);
872 mainsizer
->Add( m_orientationRadioBox
, 0, wxTOP
|wxLEFT
|wxRIGHT
, 10 );
876 wxBoxSizer
*table
= new wxBoxSizer( wxHORIZONTAL
);
878 wxBoxSizer
*column1
= new wxBoxSizer( wxVERTICAL
);
879 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Left margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
880 column1
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Top margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
881 table
->Add( column1
, 0, wxALL
| wxEXPAND
, 5 );
883 wxBoxSizer
*column2
= new wxBoxSizer( wxVERTICAL
);
884 m_marginLeftText
= new wxTextCtrl(this, wxPRINTID_LEFTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
885 m_marginTopText
= new wxTextCtrl(this, wxPRINTID_TOPMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
886 column2
->Add( m_marginLeftText
, 1, wxALL
, 5 );
887 column2
->Add( m_marginTopText
, 1, wxALL
, 5 );
888 table
->Add( column2
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
890 wxBoxSizer
*column3
= new wxBoxSizer( wxVERTICAL
);
891 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Right margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
892 column3
->Add( new wxStaticText(this, wxPRINTID_STATIC
, _("Bottom margin (mm):")),1,wxALL
|wxALIGN_RIGHT
,5 );
893 table
->Add( column3
, 0, wxALL
| wxEXPAND
, 5 );
895 wxBoxSizer
*column4
= new wxBoxSizer( wxVERTICAL
);
896 m_marginRightText
= new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
897 m_marginBottomText
= new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN
, wxEmptyString
, wxDefaultPosition
, wxSize(textWidth
, wxDefaultCoord
));
898 column4
->Add( m_marginRightText
, 1, wxALL
, 5 );
899 column4
->Add( m_marginBottomText
, 1, wxALL
, 5 );
900 table
->Add( column4
, 0, wxRIGHT
|wxTOP
|wxBOTTOM
| wxEXPAND
, 5 );
902 mainsizer
->Add( table
, 0 );
906 mainsizer
->Add( new wxStaticLine( this, wxID_ANY
), 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
911 wxSizer
* buttonsizer
= CreateButtonSizer( wxOK
|wxCANCEL
);
913 if (wxPrintFactory::GetFactory()->HasPrintSetupDialog())
915 m_printerButton
= new wxButton(this, wxPRINTID_SETUP
, _("Printer...") );
916 buttonsizer
->Add( m_printerButton
, 0, wxLEFT
|wxRIGHT
, 10 );
917 if ( !m_pageData
.GetEnablePrinter() )
918 m_printerButton
->Enable(false);
922 m_printerButton
= NULL
;
925 // if (m_printData.GetEnableHelp())
926 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight);
927 mainsizer
->Add( buttonsizer
, 0, wxEXPAND
|wxALL
, 10 );
930 SetAutoLayout( true );
931 SetSizer( mainsizer
);
933 mainsizer
->Fit( this );
942 wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
946 wxPageSetupDialogData
& wxGenericPageSetupDialog::GetPageSetupDialogData()
951 bool wxGenericPageSetupDialog::TransferDataToWindow()
953 if (m_marginLeftText
)
954 m_marginLeftText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().x
));
956 m_marginTopText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginTopLeft().y
));
957 if (m_marginRightText
)
958 m_marginRightText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().x
));
959 if (m_marginBottomText
)
960 m_marginBottomText
->SetValue(wxString::Format(wxT("%d"), m_pageData
.GetMarginBottomRight().y
));
962 if (m_orientationRadioBox
)
964 if (m_pageData
.GetPrintData().GetOrientation() == wxPORTRAIT
)
965 m_orientationRadioBox
->SetSelection(0);
967 m_orientationRadioBox
->SetSelection(1);
970 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
971 // failing that, the id in the wxPrintData object.
973 wxPrintPaperType
* type
= wxThePrintPaperDatabase
->FindPaperType(
974 wxSize(m_pageData
.GetPaperSize().x
* 10, m_pageData
.GetPaperSize().y
* 10));
976 if (!type
&& m_pageData
.GetPrintData().GetPaperId() != wxPAPER_NONE
)
977 type
= wxThePrintPaperDatabase
->FindPaperType(m_pageData
.GetPrintData().GetPaperId());
981 m_paperTypeChoice
->SetStringSelection(type
->GetName());
987 bool wxGenericPageSetupDialog::TransferDataFromWindow()
989 if (m_marginLeftText
&& m_marginTopText
)
991 int left
= wxAtoi( m_marginLeftText
->GetValue().c_str() );
992 int top
= wxAtoi( m_marginTopText
->GetValue().c_str() );
993 m_pageData
.SetMarginTopLeft( wxPoint(left
,top
) );
995 if (m_marginRightText
&& m_marginBottomText
)
997 int right
= wxAtoi( m_marginRightText
->GetValue().c_str() );
998 int bottom
= wxAtoi( m_marginBottomText
->GetValue().c_str() );
999 m_pageData
.SetMarginBottomRight( wxPoint(right
,bottom
) );
1002 if (m_orientationRadioBox
)
1004 int sel
= m_orientationRadioBox
->GetSelection();
1007 m_pageData
.GetPrintData().SetOrientation(wxPORTRAIT
);
1011 m_pageData
.GetPrintData().SetOrientation(wxLANDSCAPE
);
1015 if (m_paperTypeChoice
)
1017 int selectedItem
= m_paperTypeChoice
->GetSelection();
1018 if (selectedItem
!= -1)
1020 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(selectedItem
);
1023 m_pageData
.SetPaperSize(wxSize(paper
->GetWidth()/10, paper
->GetHeight()/10));
1024 m_pageData
.GetPrintData().SetPaperId(paper
->GetId());
1032 wxComboBox
*wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x
, int *y
)
1035 if (!wxThePrintPaperDatabase)
1037 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
1038 wxThePrintPaperDatabase->CreateDatabase();
1042 size_t n
= wxThePrintPaperDatabase
->GetCount();
1043 wxString
*choices
= new wxString
[n
];
1045 for (size_t i
= 0; i
< n
; i
++)
1047 wxPrintPaperType
*paper
= wxThePrintPaperDatabase
->Item(i
);
1048 choices
[i
] = paper
->GetName();
1051 (void) new wxStaticText(this, wxPRINTID_STATIC
, _("Paper size"), wxPoint(*x
, *y
));
1054 wxComboBox
*choice
= new wxComboBox( this,
1055 wxPRINTID_PAPERSIZE
,
1058 wxSize(300, wxDefaultCoord
),
1063 // choice->SetSelection(sel);
1067 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent
& WXUNUSED(event
))
1069 // We no longer query GetPrintMode, so we can eliminate the need
1070 // to call SetPrintMode.
1071 // This has the limitation that we can't explicitly call the PostScript
1072 // print setup dialog from the generic Page Setup dialog under Windows,
1073 // but since this choice would only happen when trying to do PostScript
1074 // printing under Windows (and only in 16-bit Windows which
1075 // doesn't have a Windows-specific page setup dialog) it's worth it.
1077 // First save the current settings, so the wxPrintData object is up to date.
1078 TransferDataFromWindow();
1080 // Transfer the current print settings from this dialog to the page setup dialog.
1083 // Use print factory later
1085 wxPrintDialogData data
;
1086 data
= GetPageSetupData().GetPrintData();
1087 data
.SetSetupDialog(true);
1088 wxPrintDialog
printDialog(this, & data
);
1089 printDialog
.ShowModal();
1091 // Transfer the page setup print settings from the page dialog to this dialog again, in case
1092 // the page setup dialog changed something.
1093 GetPageSetupData().GetPrintData() = printDialog
.GetPrintDialogData().GetPrintData();
1094 GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData
1096 // Now update the dialog in case the page setup dialog changed some of our settings.
1097 TransferDataToWindow();