]> git.saurik.com Git - wxWidgets.git/blob - src/generic/prntdlgg.cpp
Fixed player dialog listbox size and app icon on wxGTK
[wxWidgets.git] / src / generic / prntdlgg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/prntdlgg.cpp
3 // Purpose: Generic print dialogs
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
28
29 #include "wx/generic/prntdlgg.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/utils.h"
33 #include "wx/dc.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"
42 #include "wx/intl.h"
43 #include "wx/sizer.h"
44 #include "wx/cmndata.h"
45 #endif
46
47 #if wxUSE_STATLINE
48 #include "wx/statline.h"
49 #endif
50
51 #if wxUSE_POSTSCRIPT
52 #include "wx/generic/dcpsg.h"
53 #endif
54
55 #include "wx/prntbase.h"
56 #include "wx/printdlg.h"
57 #include "wx/paper.h"
58 #include "wx/filename.h"
59 #include "wx/tokenzr.h"
60 #include "wx/imaglist.h"
61
62 #include <stdlib.h>
63 #include <string.h>
64
65 #ifndef __WXUNIVERSAL__
66
67 #if wxUSE_LIBGNOMEPRINT
68 #include "wx/link.h"
69 wxFORCE_LINK_MODULE(gnome_print)
70 #endif
71
72 #if wxUSE_GTKPRINT
73 #include "wx/link.h"
74 wxFORCE_LINK_MODULE(gtk_print)
75 #endif
76
77 #endif // !wxUniv
78
79 // ----------------------------------------------------------------------------
80 // global vars
81 // ----------------------------------------------------------------------------
82
83 extern wxPrintPaperDatabase *wxThePrintPaperDatabase;
84
85 #if wxUSE_POSTSCRIPT
86
87 //----------------------------------------------------------------------------
88 // wxPostScriptNativeData
89 //----------------------------------------------------------------------------
90
91 IMPLEMENT_CLASS(wxPostScriptPrintNativeData, wxPrintNativeDataBase)
92
93 wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
94 {
95 m_previewCommand = wxEmptyString;
96 #ifdef __VMS__
97 m_printerCommand = wxT("print");
98 m_printerOptions = wxT("/nonotify/queue=psqueue");
99 m_afmPath = wxT("sys$ps_font_metrics:");
100 #endif
101
102 #ifdef __WXMSW__
103 m_printerCommand = wxT("print");
104 m_printerOptions = wxEmptyString;
105 m_afmPath = wxT("c:\\windows\\system\\");
106 #endif
107
108 #if !defined(__VMS__) && !defined(__WXMSW__)
109 m_printerCommand = wxT("lpr");
110 m_printerOptions = wxEmptyString;
111 m_afmPath = wxEmptyString;
112 #endif
113
114 m_printerScaleX = 1.0;
115 m_printerScaleY = 1.0;
116 m_printerTranslateX = 0;
117 m_printerTranslateY = 0;
118 }
119
120 wxPostScriptPrintNativeData::~wxPostScriptPrintNativeData()
121 {
122 }
123
124 bool wxPostScriptPrintNativeData::TransferTo( wxPrintData &WXUNUSED(data) )
125 {
126 return true;
127 }
128
129 bool wxPostScriptPrintNativeData::TransferFrom( const wxPrintData &WXUNUSED(data) )
130 {
131 return true;
132 }
133
134 // ----------------------------------------------------------------------------
135 // Generic print dialog for non-Windows printing use.
136 // ----------------------------------------------------------------------------
137
138 IMPLEMENT_CLASS(wxGenericPrintDialog, wxPrintDialogBase)
139
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)
144 END_EVENT_TABLE()
145
146 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
147 wxPrintDialogData* data)
148 : wxPrintDialogBase(GetParentForModalDialog(parent),
149 wxID_ANY, _("Print"),
150 wxPoint(0,0), wxSize(600, 600),
151 wxDEFAULT_DIALOG_STYLE |
152 wxTAB_TRAVERSAL)
153 {
154 if ( data )
155 m_printDialogData = *data;
156
157 Init(parent);
158 }
159
160 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
161 wxPrintData* data)
162 : wxPrintDialogBase(GetParentForModalDialog(parent),
163 wxID_ANY, _("Print"),
164 wxPoint(0,0), wxSize(600, 600),
165 wxDEFAULT_DIALOG_STYLE |
166 wxTAB_TRAVERSAL)
167 {
168 if ( data )
169 m_printDialogData = *data;
170
171 Init(parent);
172 }
173
174 void wxGenericPrintDialog::Init(wxWindow * WXUNUSED(parent))
175 {
176 // wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0,0), wxSize(600, 600),
177 // wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL);
178
179 wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
180
181 // 1) top row
182
183 wxPrintFactory* factory = wxPrintFactory::GetFactory();
184
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 );
190
191 m_printToFileCheckBox = new wxCheckBox( this, wxPRINTID_PRINTTOFILE, _("Print to File") );
192 flex->Add( m_printToFileCheckBox, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
193
194 m_setupButton = new wxButton(this, wxPRINTID_SETUP, _("Setup...") );
195 flex->Add( m_setupButton, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
196
197 if (!factory->HasPrintSetupDialog())
198 m_setupButton->Enable( false );
199
200 if (factory->HasPrinterLine())
201 {
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 );
206 }
207
208 if (factory->HasStatusLine())
209 {
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 );
214 }
215
216 mainsizer->Add( topsizer, 0, wxLEFT|wxTOP|wxRIGHT|wxGROW, 10 );
217
218 // 2) middle row with radio box
219
220 wxString *choices = new wxString[2];
221 choices[0] = _("All");
222 choices[1] = _("Pages");
223
224 m_fromText = (wxTextCtrl*)NULL;
225 m_toText = (wxTextCtrl*)NULL;
226 m_rangeRadioBox = (wxRadioBox *)NULL;
227
228 if (m_printDialogData.GetFromPage() != 0)
229 {
230 m_rangeRadioBox = new wxRadioBox(this, wxPRINTID_RANGE, _("Print Range"),
231 wxDefaultPosition, wxDefaultSize,
232 2, choices,
233 1, wxRA_VERTICAL);
234 m_rangeRadioBox->SetSelection(1);
235
236 mainsizer->Add( m_rangeRadioBox, 0, wxLEFT|wxTOP|wxRIGHT, 10 );
237 }
238
239 // 3) bottom row
240
241 wxBoxSizer *bottomsizer = new wxBoxSizer( wxHORIZONTAL );
242
243 if (m_printDialogData.GetFromPage() != 0)
244 {
245 bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("From:") ), 0, wxCENTER|wxALL, 5 );
246 m_fromText = new wxTextCtrl(this, wxPRINTID_FROM, wxEmptyString, wxDefaultPosition, wxSize(40, wxDefaultCoord));
247 bottomsizer->Add( m_fromText, 1, wxCENTER|wxRIGHT, 10 );
248
249 bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("To:") ), 0, wxCENTER|wxALL, 5);
250 m_toText = new wxTextCtrl(this, wxPRINTID_TO, wxEmptyString, wxDefaultPosition, wxSize(40, wxDefaultCoord));
251 bottomsizer->Add( m_toText, 1, wxCENTER|wxRIGHT, 10 );
252 }
253
254 bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Copies:") ), 0, wxCENTER|wxALL, 5 );
255 m_noCopiesText = new wxTextCtrl(this, wxPRINTID_COPIES, wxEmptyString, wxPoint(252, 130), wxSize(40, wxDefaultCoord));
256 bottomsizer->Add( m_noCopiesText, 1, wxCENTER|wxRIGHT, 10 );
257
258 mainsizer->Add( bottomsizer, 0, wxTOP|wxLEFT|wxRIGHT, 12 );
259
260 // 4) buttons
261
262 wxSizer *sizerBtn = CreateSeparatedButtonSizer( wxOK|wxCANCEL);
263 if ( sizerBtn )
264 mainsizer->Add(sizerBtn, 0, wxEXPAND|wxALL, 10 );
265
266 SetAutoLayout( true );
267 SetSizer( mainsizer );
268
269 mainsizer->Fit( this );
270 Centre(wxBOTH);
271
272 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
273 InitDialog();
274 delete[] choices;
275 }
276
277 int wxGenericPrintDialog::ShowModal()
278 {
279 return wxDialog::ShowModal();
280 }
281
282 wxGenericPrintDialog::~wxGenericPrintDialog()
283 {
284 }
285
286 void wxGenericPrintDialog::OnOK(wxCommandEvent& WXUNUSED(event))
287 {
288 TransferDataFromWindow();
289
290 // An empty 'to' field signals printing just the
291 // 'from' page.
292 if (m_printDialogData.GetToPage() < 1)
293 m_printDialogData.SetToPage(m_printDialogData.GetFromPage());
294
295 // There are some interactions between the global setup data
296 // and the standard print dialog. The global printing 'mode'
297 // is determined by whether the user checks Print to file
298 // or not.
299 if (m_printDialogData.GetPrintToFile())
300 {
301 m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE);
302
303 wxFileName fname( m_printDialogData.GetPrintData().GetFilename() );
304
305 wxFileDialog dialog( this, _("PostScript file"),
306 fname.GetPath(), fname.GetFullName(), wxT("*.ps"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
307 if (dialog.ShowModal() != wxID_OK) return;
308
309 m_printDialogData.GetPrintData().SetFilename( dialog.GetPath() );
310 }
311 else
312 {
313 m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER);
314 }
315
316 EndModal(wxID_OK);
317 }
318
319 void wxGenericPrintDialog::OnRange(wxCommandEvent& event)
320 {
321 if (!m_fromText) return;
322
323 if (event.GetInt() == 0)
324 {
325 m_fromText->Enable(false);
326 m_toText->Enable(false);
327 }
328 else if (event.GetInt() == 1)
329 {
330 m_fromText->Enable(true);
331 m_toText->Enable(true);
332 }
333 }
334
335 void wxGenericPrintDialog::OnSetup(wxCommandEvent& WXUNUSED(event))
336 {
337 wxPrintFactory* factory = wxPrintFactory::GetFactory();
338
339 if (factory->HasPrintSetupDialog())
340 {
341 // The print setup dialog should change the
342 // print data in-place if not cancelled.
343 wxDialog *dialog = factory->CreatePrintSetupDialog( this, &m_printDialogData.GetPrintData() );
344 dialog->ShowModal();
345 dialog->Destroy();
346 }
347 }
348
349 bool wxGenericPrintDialog::TransferDataToWindow()
350 {
351 if(m_printDialogData.GetFromPage() != 0)
352 {
353 if(m_fromText)
354 {
355 if (m_printDialogData.GetEnablePageNumbers())
356 {
357 m_fromText->Enable(true);
358 m_toText->Enable(true);
359 if (m_printDialogData.GetFromPage() > 0)
360 m_fromText->SetValue(wxString::Format(_T("%d"), m_printDialogData.GetFromPage()));
361 if (m_printDialogData.GetToPage() > 0)
362 m_toText->SetValue(wxString::Format(_T("%d"), m_printDialogData.GetToPage()));
363 if(m_rangeRadioBox)
364 if (m_printDialogData.GetAllPages() || m_printDialogData.GetFromPage() == 0)
365 m_rangeRadioBox->SetSelection(0);
366 else
367 m_rangeRadioBox->SetSelection(1);
368 }
369 else
370 {
371 m_fromText->Enable(false);
372 m_toText->Enable(false);
373 if(m_rangeRadioBox)
374 {
375 m_rangeRadioBox->SetSelection(0);
376 m_rangeRadioBox->wxRadioBox::Enable(1, false);
377 }
378 }
379 }
380 }
381 m_noCopiesText->SetValue(
382 wxString::Format(_T("%d"), m_printDialogData.GetNoCopies()));
383
384 m_printToFileCheckBox->SetValue(m_printDialogData.GetPrintToFile());
385 m_printToFileCheckBox->Enable(m_printDialogData.GetEnablePrintToFile());
386 return true;
387 }
388
389 bool wxGenericPrintDialog::TransferDataFromWindow()
390 {
391 long res = 0;
392 if(m_printDialogData.GetFromPage() != -1)
393 {
394 if (m_printDialogData.GetEnablePageNumbers())
395 {
396 if(m_fromText)
397 {
398 wxString value = m_fromText->GetValue();
399 if (value.ToLong( &res ))
400 m_printDialogData.SetFromPage( res );
401 }
402 if(m_toText)
403 {
404 wxString value = m_toText->GetValue();
405 if (value.ToLong( &res ))
406 m_printDialogData.SetToPage( res );
407 }
408 }
409 if(m_rangeRadioBox)
410 {
411 if (m_rangeRadioBox->GetSelection() == 0)
412 {
413 m_printDialogData.SetAllPages(true);
414
415 // This means all pages, more or less
416 m_printDialogData.SetFromPage(1);
417 m_printDialogData.SetToPage(32000);
418 }
419 else
420 m_printDialogData.SetAllPages(false);
421 }
422 }
423 else
424 { // continuous printing
425 m_printDialogData.SetFromPage(1);
426 m_printDialogData.SetToPage(32000);
427 }
428
429 wxString value = m_noCopiesText->GetValue();
430 if (value.ToLong( &res ))
431 m_printDialogData.SetNoCopies( res );
432
433 m_printDialogData.SetPrintToFile(m_printToFileCheckBox->GetValue());
434
435 return true;
436 }
437
438 wxDC *wxGenericPrintDialog::GetPrintDC()
439 {
440 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
441 }
442
443 // ----------------------------------------------------------------------------
444 // Generic print setup dialog
445 // ----------------------------------------------------------------------------
446
447 IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog)
448
449 BEGIN_EVENT_TABLE(wxGenericPrintSetupDialog, wxDialog)
450 EVT_LIST_ITEM_ACTIVATED(wxPRINTID_PRINTER, wxGenericPrintSetupDialog::OnPrinter)
451 END_EVENT_TABLE()
452
453 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintData* data):
454 wxDialog(parent, wxID_ANY, _("Print Setup"), wxPoint(0,0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL)
455 {
456 Init(data);
457 }
458
459 /* XPM */
460 static const char * check_xpm[] = {
461 /* width height ncolors chars_per_pixel */
462 "16 16 3 1",
463 /* colors */
464 " s None c None",
465 "X c #000000",
466 ". c #808080",
467 /* pixels */
468 " ",
469 " ",
470 " ",
471 " .. ",
472 " XX ",
473 " XX. ",
474 " .XX ",
475 " XX ",
476 " X XX. ",
477 " XX .XX ",
478 " XX XX ",
479 " XXXX. ",
480 " XX. ",
481 " . ",
482 " ",
483 " "
484 };
485
486
487 void wxGenericPrintSetupDialog::Init(wxPrintData* data)
488 {
489 if ( data )
490 m_printData = *data;
491
492 m_targetData = data;
493
494 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
495
496 // printer selection
497
498 wxStaticBoxSizer *printer_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Printer") ), wxVERTICAL );
499 main_sizer->Add( printer_sizer, 0, wxALL|wxGROW, 10 );
500
501 m_printerListCtrl = new wxListCtrl( this, wxPRINTID_PRINTER,
502 wxDefaultPosition, wxSize(wxDefaultCoord,100), wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER );
503 wxImageList *image_list = new wxImageList;
504 image_list->Add( wxBitmap(check_xpm) );
505 m_printerListCtrl->AssignImageList( image_list, wxIMAGE_LIST_SMALL );
506
507 m_printerListCtrl->InsertColumn( 0, wxT(" "), wxLIST_FORMAT_LEFT, 20 );
508 m_printerListCtrl->InsertColumn( 1, wxT("Printer"), wxLIST_FORMAT_LEFT, 150 );
509 m_printerListCtrl->InsertColumn( 2, wxT("Device"), wxLIST_FORMAT_LEFT, 150 );
510 m_printerListCtrl->InsertColumn( 3, wxT("Status"), wxLIST_FORMAT_LEFT, 80 );
511
512 wxListItem item;
513 item.SetMask( wxLIST_MASK_TEXT );
514 item.SetColumn( 1 );
515 item.SetText( _("Default printer") );
516 item.SetId( m_printerListCtrl->InsertItem( item ) );
517
518 if (data->GetPrinterName().empty())
519 {
520 wxListItem item2;
521 item2.SetId( item.GetId() );
522 item2.SetMask( wxLIST_MASK_IMAGE );
523 item2.SetImage( 0 );
524 m_printerListCtrl->SetItem( item2 );
525 // also select item
526 m_printerListCtrl->SetItemState( item.GetId(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
527 }
528
529 item.SetId( 1+ item.GetId() );
530
531 wxArrayString errors;
532 wxArrayString output;
533 long res = wxExecute( wxT("lpstat -v"), output, errors, wxEXEC_NODISABLE );
534 if (res >= 0 && errors.GetCount() == 0)
535 {
536 size_t i;
537 for (i = 0; i < output.GetCount(); i++)
538 {
539 wxStringTokenizer tok( output[i], wxT(" ") );
540 wxString tmp = tok.GetNextToken(); // "device"
541 if (tmp != wxT("device"))
542 break; // the lpstat syntax must have changed.
543 tmp = tok.GetNextToken(); // "for"
544 if (tmp != wxT("for"))
545 break; // the lpstat syntax must have changed.
546 tmp = tok.GetNextToken(); // "hp_deskjet930c:"
547 if (tmp[tmp.length()-1] == wxT(':'))
548 tmp.Remove(tmp.length()-1,1);
549 wxString name = tmp;
550 item.SetText( name );
551 item.SetId( m_printerListCtrl->InsertItem( item ) );
552 tmp = tok.GetNextToken(); // "parallel:/dev/lp0"
553 item.SetColumn( 2 );
554 item.SetText( tmp );
555 m_printerListCtrl->SetItem( item );
556 if (data->GetPrinterName() == name)
557 {
558 wxListItem item2;
559 item2.SetId( item.GetId() );
560 item2.SetMask( wxLIST_MASK_IMAGE );
561 item2.SetImage( 0 );
562 m_printerListCtrl->SetItem( item2 );
563 // also select item
564 m_printerListCtrl->SetItemState( item.GetId(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
565 }
566
567 wxString command = wxT("lpstat -p ");
568 command += name;
569 wxArrayString errors2;
570 wxArrayString output2;
571 res = wxExecute( command, output2, errors2, wxEXEC_NODISABLE );
572 if (res >= 0 && errors2.GetCount() == 0 && output2.GetCount() > 0)
573 {
574 tmp = output2[0]; // "printer hp_deskjet930c is idle. enable since ..."
575 int pos = tmp.Find( wxT('.') );
576 if (pos != wxNOT_FOUND)
577 tmp.Remove( (size_t)pos, tmp.length()-(size_t)pos );
578 wxStringTokenizer tok2( tmp, wxT(" ") );
579 tmp = tok2.GetNextToken(); // "printer"
580 tmp = tok2.GetNextToken(); // "hp_deskjet930c"
581 tmp = wxEmptyString;
582 while (tok2.HasMoreTokens())
583 {
584 tmp += tok2.GetNextToken();
585 tmp += wxT(" ");
586 }
587 item.SetColumn( 3 );
588 item.SetText( tmp );
589 m_printerListCtrl->SetItem( item );
590 }
591
592 item.SetColumn( 1 );
593 item.SetId( 1+ item.GetId() );
594 }
595 }
596
597
598 printer_sizer->Add( m_printerListCtrl, 0, wxALL|wxGROW, 5 );
599
600 wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
601 main_sizer->Add( item1, 0, wxALL, 5 );
602
603 // printer options (on the left)
604
605 wxBoxSizer *item2 = new wxBoxSizer( wxVERTICAL );
606
607 wxStaticBox *item4 = new wxStaticBox( this, wxPRINTID_STATIC, _("Paper size") );
608 wxStaticBoxSizer *item3 = new wxStaticBoxSizer( item4, wxVERTICAL );
609
610 m_paperTypeChoice = CreatePaperTypeChoice();
611 item3->Add( m_paperTypeChoice, 0, wxALIGN_CENTER|wxALL, 5 );
612
613 item2->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
614
615 wxString strs6[] =
616 {
617 _("Portrait"),
618 _("Landscape")
619 };
620 m_orientationRadioBox= new wxRadioBox( this, wxPRINTID_ORIENTATION, _("Orientation"), wxDefaultPosition, wxDefaultSize, 2, strs6, 1, wxRA_SPECIFY_ROWS );
621 item2->Add( m_orientationRadioBox, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
622
623 wxStaticBox *item8 = new wxStaticBox( this, wxID_ANY, _("Options") );
624 wxStaticBoxSizer *item7 = new wxStaticBoxSizer( item8, wxHORIZONTAL );
625
626 m_colourCheckBox = new wxCheckBox( this, wxPRINTID_PRINTCOLOUR, _("Print in colour") );
627 item7->Add( m_colourCheckBox, 0, wxALIGN_CENTER|wxALL, 5 );
628
629 item2->Add( item7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
630
631 item1->Add( item2, 0, wxALIGN_CENTER_HORIZONTAL, 5 );
632
633 // spooling options (on the right)
634
635 wxStaticBox *item11 = new wxStaticBox( this, wxID_ANY, _("Print spooling") );
636 wxStaticBoxSizer *item10 = new wxStaticBoxSizer( item11, wxVERTICAL );
637
638 wxStaticText *item12 = new wxStaticText( this, wxID_ANY, _("Printer command:") );
639 item10->Add( item12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
640
641 wxBoxSizer *item13 = new wxBoxSizer( wxHORIZONTAL );
642
643 item13->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
644
645 m_printerCommandText = new wxTextCtrl( this, wxPRINTID_COMMAND, wxEmptyString, wxDefaultPosition, wxSize(160,wxDefaultCoord) );
646 item13->Add( m_printerCommandText, 0, wxALIGN_CENTER|wxALL, 5 );
647
648 item10->Add( item13, 0, wxALIGN_CENTER|wxALL, 0 );
649
650 wxStaticText *item15 = new wxStaticText( this, wxID_ANY, _("Printer options:") );
651 item10->Add( item15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
652
653 wxBoxSizer *item16 = new wxBoxSizer( wxHORIZONTAL );
654
655 item16->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
656
657 m_printerOptionsText = new wxTextCtrl( this, wxPRINTID_OPTIONS, wxEmptyString, wxDefaultPosition, wxSize(160,wxDefaultCoord) );
658 item16->Add( m_printerOptionsText, 0, wxALIGN_CENTER|wxALL, 5 );
659
660 item10->Add( item16, 0, wxALIGN_CENTER|wxALL, 0 );
661
662 item1->Add( item10, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5 );
663
664
665 #if wxUSE_STATLINE
666 // static line
667 main_sizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
668 #endif
669
670 // buttons
671
672 main_sizer->Add( CreateButtonSizer( wxOK|wxCANCEL), 0, wxEXPAND|wxALL, 10 );
673
674 SetAutoLayout( true );
675 SetSizer( main_sizer );
676
677 main_sizer->Fit( this );
678 Centre(wxBOTH);
679
680
681 Fit();
682 Centre(wxBOTH);
683
684 InitDialog();
685 }
686
687 wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
688 {
689 }
690
691 void wxGenericPrintSetupDialog::OnPrinter(wxListEvent& event)
692 {
693 // Delete check mark
694 for (long item = 0; item < m_printerListCtrl->GetItemCount(); item++)
695 m_printerListCtrl->SetItemImage( item, -1 );
696
697 m_printerListCtrl->SetItemImage( event.GetIndex(), 0 );
698
699 if (event.GetIndex() == 0)
700 {
701 m_printerCommandText->SetValue( wxT("lpr") );
702 }
703 else
704 {
705 wxListItem li;
706 li.SetColumn( 1 );
707 li.SetMask( wxLIST_MASK_TEXT );
708 li.SetId( event.GetIndex() );
709 m_printerListCtrl->GetItem( li );
710 m_printerCommandText->SetValue( _T("lpr -P") + li.GetText() );
711 }
712 }
713
714 bool wxGenericPrintSetupDialog::TransferDataToWindow()
715 {
716 wxPostScriptPrintNativeData *data =
717 (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
718
719 if (m_printerCommandText && !data->GetPrinterCommand().empty())
720 m_printerCommandText->SetValue(data->GetPrinterCommand());
721 if (m_printerOptionsText && !data->GetPrinterOptions().empty())
722 m_printerOptionsText->SetValue(data->GetPrinterOptions());
723 if (m_colourCheckBox)
724 m_colourCheckBox->SetValue(m_printData.GetColour());
725
726 if (m_orientationRadioBox)
727 {
728 if (m_printData.GetOrientation() == wxPORTRAIT)
729 m_orientationRadioBox->SetSelection(0);
730 else
731 m_orientationRadioBox->SetSelection(1);
732 }
733 return true;
734 }
735
736 bool wxGenericPrintSetupDialog::TransferDataFromWindow()
737 {
738 wxPostScriptPrintNativeData *data =
739 (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
740
741 // find selected printer
742 long id = m_printerListCtrl->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
743 if (id == 0)
744 {
745 m_printData.SetPrinterName( wxEmptyString );
746 }
747 else
748 {
749 wxListItem item;
750 item.SetId( id );
751 item.SetMask( wxLIST_MASK_TEXT );
752 item.SetColumn( 1 );
753 m_printerListCtrl->GetItem( item );
754 m_printData.SetPrinterName( item.GetText() );
755 }
756
757 if (m_printerCommandText)
758 data->SetPrinterCommand(m_printerCommandText->GetValue());
759 if (m_printerOptionsText)
760 data->SetPrinterOptions(m_printerOptionsText->GetValue());
761 if (m_colourCheckBox)
762 m_printData.SetColour(m_colourCheckBox->GetValue());
763 if (m_orientationRadioBox)
764 {
765 int sel = m_orientationRadioBox->GetSelection();
766 if (sel == 0)
767 m_printData.SetOrientation(wxPORTRAIT);
768 else
769 m_printData.SetOrientation(wxLANDSCAPE);
770 }
771 if (m_paperTypeChoice)
772 {
773 int selectedItem = m_paperTypeChoice->GetSelection();
774 if (selectedItem != -1)
775 {
776 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(selectedItem);
777 if (paper != NULL)
778 m_printData.SetPaperId( paper->GetId());
779 }
780 }
781
782 if (m_targetData)
783 *m_targetData = m_printData;
784
785 return true;
786 }
787
788 wxComboBox *wxGenericPrintSetupDialog::CreatePaperTypeChoice()
789 {
790 size_t n = wxThePrintPaperDatabase->GetCount();
791 wxString *choices = new wxString [n];
792 size_t sel = 0;
793
794 for (size_t i = 0; i < n; i++)
795 {
796 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
797 choices[i] = paper->GetName();
798 if (m_printData.GetPaperId() == paper->GetId())
799 sel = i;
800 }
801
802 int width = 250;
803
804 wxComboBox *choice = new wxComboBox( this,
805 wxPRINTID_PAPERSIZE,
806 _("Paper Size"),
807 wxDefaultPosition,
808 wxSize(width, wxDefaultCoord),
809 n, choices );
810
811 delete[] choices;
812
813 choice->SetSelection(sel);
814 return choice;
815 }
816
817 #endif // wxUSE_POSTSCRIPT
818
819 // ----------------------------------------------------------------------------
820 // Generic page setup dialog
821 // ----------------------------------------------------------------------------
822
823 IMPLEMENT_CLASS(wxGenericPageSetupDialog, wxPageSetupDialogBase)
824
825 BEGIN_EVENT_TABLE(wxGenericPageSetupDialog, wxPageSetupDialogBase)
826 EVT_BUTTON(wxPRINTID_SETUP, wxGenericPageSetupDialog::OnPrinter)
827 END_EVENT_TABLE()
828
829 wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow *parent,
830 wxPageSetupDialogData* data)
831 : wxPageSetupDialogBase( parent,
832 wxID_ANY,
833 _("Page Setup"),
834 wxPoint(0,0),
835 wxSize(600, 600),
836 wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL )
837 {
838 if (data)
839 m_pageData = *data;
840
841 int textWidth = 80;
842
843 wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
844
845 // 1) top
846 wxStaticBoxSizer *topsizer = new wxStaticBoxSizer(
847 new wxStaticBox(this,wxPRINTID_STATIC, _("Paper size")), wxHORIZONTAL );
848
849 size_t n = wxThePrintPaperDatabase->GetCount();
850 wxString *choices = new wxString [n];
851
852 for (size_t i = 0; i < n; i++)
853 {
854 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
855 choices[i] = paper->GetName();
856 }
857
858 m_paperTypeChoice = new wxComboBox( this,
859 wxPRINTID_PAPERSIZE,
860 _("Paper Size"),
861 wxDefaultPosition,
862 wxSize(300, wxDefaultCoord),
863 n, choices );
864 topsizer->Add( m_paperTypeChoice, 1, wxEXPAND|wxALL, 5 );
865 // m_paperTypeChoice->SetSelection(sel);
866
867 mainsizer->Add( topsizer, 0, wxTOP|wxLEFT|wxRIGHT | wxEXPAND, 10 );
868
869 // 2) middle sizer with radio box
870
871 wxString *choices2 = new wxString[2];
872 choices2[0] = _("Portrait");
873 choices2[1] = _("Landscape");
874 m_orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"),
875 wxDefaultPosition, wxDefaultSize, 2, choices2, 2);
876 m_orientationRadioBox->SetSelection(0);
877
878 mainsizer->Add( m_orientationRadioBox, 0, wxTOP|wxLEFT|wxRIGHT, 10 );
879
880 // 3) margins
881
882 wxBoxSizer *table = new wxBoxSizer( wxHORIZONTAL );
883
884 wxBoxSizer *column1 = new wxBoxSizer( wxVERTICAL );
885 column1->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Left margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 );
886 column1->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Top margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 );
887 table->Add( column1, 0, wxALL | wxEXPAND, 5 );
888
889 wxBoxSizer *column2 = new wxBoxSizer( wxVERTICAL );
890 m_marginLeftText = new wxTextCtrl(this, wxPRINTID_LEFTMARGIN, wxEmptyString, wxDefaultPosition, wxSize(textWidth, wxDefaultCoord));
891 m_marginTopText = new wxTextCtrl(this, wxPRINTID_TOPMARGIN, wxEmptyString, wxDefaultPosition, wxSize(textWidth, wxDefaultCoord));
892 column2->Add( m_marginLeftText, 1, wxALL, 5 );
893 column2->Add( m_marginTopText, 1, wxALL, 5 );
894 table->Add( column2, 0, wxRIGHT|wxTOP|wxBOTTOM | wxEXPAND, 5 );
895
896 wxBoxSizer *column3 = new wxBoxSizer( wxVERTICAL );
897 column3->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Right margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 );
898 column3->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Bottom margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 );
899 table->Add( column3, 0, wxALL | wxEXPAND, 5 );
900
901 wxBoxSizer *column4 = new wxBoxSizer( wxVERTICAL );
902 m_marginRightText = new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN, wxEmptyString, wxDefaultPosition, wxSize(textWidth, wxDefaultCoord));
903 m_marginBottomText = new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN, wxEmptyString, wxDefaultPosition, wxSize(textWidth, wxDefaultCoord));
904 column4->Add( m_marginRightText, 1, wxALL, 5 );
905 column4->Add( m_marginBottomText, 1, wxALL, 5 );
906 table->Add( column4, 0, wxRIGHT|wxTOP|wxBOTTOM | wxEXPAND, 5 );
907
908 mainsizer->Add( table, 0 );
909
910 #if wxUSE_STATLINE
911 // 5) static line
912 mainsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
913 #endif
914
915 // 6) buttons
916
917 wxSizer* buttonsizer = CreateButtonSizer( wxOK|wxCANCEL);
918
919 if (wxPrintFactory::GetFactory()->HasPrintSetupDialog())
920 {
921 m_printerButton = new wxButton(this, wxPRINTID_SETUP, _("Printer...") );
922 buttonsizer->Add( m_printerButton, 0, wxLEFT|wxRIGHT, 10 );
923 if ( !m_pageData.GetEnablePrinter() )
924 m_printerButton->Enable(false);
925 }
926 else
927 {
928 m_printerButton = NULL;
929 }
930
931 // if (m_printData.GetEnableHelp())
932 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight);
933 mainsizer->Add( buttonsizer, 0, wxEXPAND|wxALL, 10 );
934
935
936 SetAutoLayout( true );
937 SetSizer( mainsizer );
938
939 mainsizer->Fit( this );
940 Centre(wxBOTH);
941
942 InitDialog();
943
944 delete[] choices;
945 delete [] choices2;
946 }
947
948 wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
949 {
950 }
951
952 wxPageSetupDialogData& wxGenericPageSetupDialog::GetPageSetupDialogData()
953 {
954 return m_pageData;
955 }
956
957 bool wxGenericPageSetupDialog::TransferDataToWindow()
958 {
959 if (m_marginLeftText)
960 m_marginLeftText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginTopLeft().x));
961 if (m_marginTopText)
962 m_marginTopText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginTopLeft().y));
963 if (m_marginRightText)
964 m_marginRightText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginBottomRight().x));
965 if (m_marginBottomText)
966 m_marginBottomText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginBottomRight().y));
967
968 if (m_orientationRadioBox)
969 {
970 if (m_pageData.GetPrintData().GetOrientation() == wxPORTRAIT)
971 m_orientationRadioBox->SetSelection(0);
972 else
973 m_orientationRadioBox->SetSelection(1);
974 }
975
976 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
977 // failing that, the id in the wxPrintData object.
978
979 wxPrintPaperType* type = wxThePrintPaperDatabase->FindPaperType(
980 wxSize(m_pageData.GetPaperSize().x * 10, m_pageData.GetPaperSize().y * 10));
981
982 if (!type && m_pageData.GetPrintData().GetPaperId() != wxPAPER_NONE)
983 type = wxThePrintPaperDatabase->FindPaperType(m_pageData.GetPrintData().GetPaperId());
984
985 if (type)
986 {
987 m_paperTypeChoice->SetStringSelection(type->GetName());
988 }
989
990 return true;
991 }
992
993 bool wxGenericPageSetupDialog::TransferDataFromWindow()
994 {
995 if (m_marginLeftText && m_marginTopText)
996 {
997 int left = wxAtoi( m_marginLeftText->GetValue().c_str() );
998 int top = wxAtoi( m_marginTopText->GetValue().c_str() );
999 m_pageData.SetMarginTopLeft( wxPoint(left,top) );
1000 }
1001 if (m_marginRightText && m_marginBottomText)
1002 {
1003 int right = wxAtoi( m_marginRightText->GetValue().c_str() );
1004 int bottom = wxAtoi( m_marginBottomText->GetValue().c_str() );
1005 m_pageData.SetMarginBottomRight( wxPoint(right,bottom) );
1006 }
1007
1008 if (m_orientationRadioBox)
1009 {
1010 int sel = m_orientationRadioBox->GetSelection();
1011 if (sel == 0)
1012 {
1013 m_pageData.GetPrintData().SetOrientation(wxPORTRAIT);
1014 }
1015 else
1016 {
1017 m_pageData.GetPrintData().SetOrientation(wxLANDSCAPE);
1018 }
1019 }
1020
1021 if (m_paperTypeChoice)
1022 {
1023 int selectedItem = m_paperTypeChoice->GetSelection();
1024 if (selectedItem != -1)
1025 {
1026 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(selectedItem);
1027 if ( paper )
1028 {
1029 m_pageData.SetPaperSize(wxSize(paper->GetWidth()/10, paper->GetHeight()/10));
1030 m_pageData.GetPrintData().SetPaperId(paper->GetId());
1031 }
1032 }
1033 }
1034
1035 return true;
1036 }
1037
1038 wxComboBox *wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x, int *y)
1039 {
1040 /*
1041 if (!wxThePrintPaperDatabase)
1042 {
1043 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
1044 wxThePrintPaperDatabase->CreateDatabase();
1045 }
1046 */
1047
1048 size_t n = wxThePrintPaperDatabase->GetCount();
1049 wxString *choices = new wxString [n];
1050
1051 for (size_t i = 0; i < n; i++)
1052 {
1053 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
1054 choices[i] = paper->GetName();
1055 }
1056
1057 (void) new wxStaticText(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(*x, *y));
1058 *y += 25;
1059
1060 wxComboBox *choice = new wxComboBox( this,
1061 wxPRINTID_PAPERSIZE,
1062 _("Paper Size"),
1063 wxPoint(*x, *y),
1064 wxSize(300, wxDefaultCoord),
1065 n, choices );
1066 *y += 35;
1067 delete[] choices;
1068
1069 // choice->SetSelection(sel);
1070 return choice;
1071 }
1072
1073 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent& WXUNUSED(event))
1074 {
1075 // We no longer query GetPrintMode, so we can eliminate the need
1076 // to call SetPrintMode.
1077 // This has the limitation that we can't explicitly call the PostScript
1078 // print setup dialog from the generic Page Setup dialog under Windows,
1079 // but since this choice would only happen when trying to do PostScript
1080 // printing under Windows (and only in 16-bit Windows which
1081 // doesn't have a Windows-specific page setup dialog) it's worth it.
1082
1083 // First save the current settings, so the wxPrintData object is up to date.
1084 TransferDataFromWindow();
1085
1086 // Transfer the current print settings from this dialog to the page setup dialog.
1087
1088 #if 0
1089 // Use print factory later
1090
1091 wxPrintDialogData data;
1092 data = GetPageSetupData().GetPrintData();
1093 data.SetSetupDialog(true);
1094 wxPrintDialog printDialog(this, & data);
1095 printDialog.ShowModal();
1096
1097 // Transfer the page setup print settings from the page dialog to this dialog again, in case
1098 // the page setup dialog changed something.
1099 GetPageSetupData().GetPrintData() = printDialog.GetPrintDialogData().GetPrintData();
1100 GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData
1101
1102 // Now update the dialog in case the page setup dialog changed some of our settings.
1103 TransferDataToWindow();
1104 #endif
1105 }
1106
1107 #endif