/[pcsx2_0.9.7]/trunk/3rdparty/wxWidgets/src/generic/prntdlgg.cpp
ViewVC logotype

Contents of /trunk/3rdparty/wxWidgets/src/generic/prntdlgg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (10 years, 1 month ago) by william
File size: 36474 byte(s)
committing r3113 initial commit again...
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: prntdlgg.cpp 55256 2008-08-25 14:39:11Z VZ $
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 #endif // !__WXUNIVERSAL__
73
74 // ----------------------------------------------------------------------------
75 // global vars
76 // ----------------------------------------------------------------------------
77
78 extern wxPrintPaperDatabase *wxThePrintPaperDatabase;
79
80 #if wxUSE_POSTSCRIPT
81
82 //----------------------------------------------------------------------------
83 // wxPostScriptNativeData
84 //----------------------------------------------------------------------------
85
86 IMPLEMENT_CLASS(wxPostScriptPrintNativeData, wxPrintNativeDataBase)
87
88 wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
89 {
90 m_previewCommand = wxEmptyString;
91 #ifdef __VMS__
92 m_printerCommand = wxT("print");
93 m_printerOptions = wxT("/nonotify/queue=psqueue");
94 m_afmPath = wxT("sys$ps_font_metrics:");
95 #endif
96
97 #ifdef __WXMSW__
98 m_printerCommand = wxT("print");
99 m_printerOptions = wxEmptyString;
100 m_afmPath = wxT("c:\\windows\\system\\");
101 #endif
102
103 #if !defined(__VMS__) && !defined(__WXMSW__)
104 m_printerCommand = wxT("lpr");
105 m_printerOptions = wxEmptyString;
106 m_afmPath = wxEmptyString;
107 #endif
108
109 m_printerScaleX = 1.0;
110 m_printerScaleY = 1.0;
111 m_printerTranslateX = 0;
112 m_printerTranslateY = 0;
113 }
114
115 wxPostScriptPrintNativeData::~wxPostScriptPrintNativeData()
116 {
117 }
118
119 bool wxPostScriptPrintNativeData::TransferTo( wxPrintData &WXUNUSED(data) )
120 {
121 return true;
122 }
123
124 bool wxPostScriptPrintNativeData::TransferFrom( const wxPrintData &WXUNUSED(data) )
125 {
126 return true;
127 }
128
129 // ----------------------------------------------------------------------------
130 // Generic print dialog for non-Windows printing use.
131 // ----------------------------------------------------------------------------
132
133 IMPLEMENT_CLASS(wxGenericPrintDialog, wxPrintDialogBase)
134
135 BEGIN_EVENT_TABLE(wxGenericPrintDialog, wxPrintDialogBase)
136 EVT_BUTTON(wxID_OK, wxGenericPrintDialog::OnOK)
137 EVT_BUTTON(wxPRINTID_SETUP, wxGenericPrintDialog::OnSetup)
138 EVT_RADIOBOX(wxPRINTID_RANGE, wxGenericPrintDialog::OnRange)
139 END_EVENT_TABLE()
140
141 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
142 wxPrintDialogData* data)
143 : wxPrintDialogBase(parent, wxID_ANY, _("Print"),
144 wxPoint(0,0), wxSize(600, 600),
145 wxDEFAULT_DIALOG_STYLE |
146 wxTAB_TRAVERSAL)
147 {
148 if ( data )
149 m_printDialogData = *data;
150
151 Init(parent);
152 }
153
154 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
155 wxPrintData* data)
156 : wxPrintDialogBase(parent, wxID_ANY, _("Print"),
157 wxPoint(0,0), wxSize(600, 600),
158 wxDEFAULT_DIALOG_STYLE |
159 wxTAB_TRAVERSAL)
160 {
161 if ( data )
162 m_printDialogData = *data;
163
164 Init(parent);
165 }
166
167 void wxGenericPrintDialog::Init(wxWindow * WXUNUSED(parent))
168 {
169 // wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0,0), wxSize(600, 600),
170 // wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL);
171
172 wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
173
174 // 1) top row
175
176 wxPrintFactory* factory = wxPrintFactory::GetFactory();
177
178 wxStaticBoxSizer *topsizer = new wxStaticBoxSizer(
179 new wxStaticBox( this, wxID_ANY, _( "Printer options" ) ), wxHORIZONTAL );
180 wxFlexGridSizer *flex = new wxFlexGridSizer( 2 );
181 flex->AddGrowableCol( 1 );
182 topsizer->Add( flex, 1, wxGROW );
183
184 m_printToFileCheckBox = new wxCheckBox( this, wxPRINTID_PRINTTOFILE, _("Print to File") );
185 flex->Add( m_printToFileCheckBox, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
186
187 m_setupButton = new wxButton(this, wxPRINTID_SETUP, _("Setup...") );
188 flex->Add( m_setupButton, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
189
190 if (!factory->HasPrintSetupDialog())
191 m_setupButton->Enable( false );
192
193 if (factory->HasPrinterLine())
194 {
195 flex->Add( new wxStaticText( this, wxID_ANY, _("Printer:") ),
196 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
197 flex->Add( new wxStaticText( this, wxID_ANY, factory->CreatePrinterLine() ),
198 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
199 }
200
201 if (factory->HasStatusLine())
202 {
203 flex->Add( new wxStaticText( this, wxID_ANY, _("Status:") ),
204 0, wxALIGN_CENTER_VERTICAL|(wxALL-wxTOP), 5 );
205 flex->Add( new wxStaticText( this, wxID_ANY, factory->CreateStatusLine() ),
206 0, wxALIGN_CENTER_VERTICAL|(wxALL-wxTOP), 5 );
207 }
208
209 mainsizer->Add( topsizer, 0, wxLEFT|wxTOP|wxRIGHT|wxGROW, 10 );
210
211 // 2) middle row with radio box
212
213 wxString *choices = new wxString[2];
214 choices[0] = _("All");
215 choices[1] = _("Pages");
216
217 m_fromText = (wxTextCtrl*)NULL;
218 m_toText = (wxTextCtrl*)NULL;
219 m_rangeRadioBox = (wxRadioBox *)NULL;
220
221 if (m_printDialogData.GetFromPage() != 0)
222 {
223 m_rangeRadioBox = new wxRadioBox(this, wxPRINTID_RANGE, _("Print Range"),
224 wxDefaultPosition, wxDefaultSize,
225 2, choices,
226 1, wxRA_VERTICAL);
227 m_rangeRadioBox->SetSelection(1);
228
229 mainsizer->Add( m_rangeRadioBox, 0, wxLEFT|wxTOP|wxRIGHT, 10 );
230 }
231
232 // 3) bottom row
233
234 wxBoxSizer *bottomsizer = new wxBoxSizer( wxHORIZONTAL );
235
236 if (m_printDialogData.GetFromPage() != 0)
237 {
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 );
241
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 );
245 }
246
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 );
250
251 mainsizer->Add( bottomsizer, 0, wxTOP|wxLEFT|wxRIGHT, 12 );
252
253 // 4) buttons
254
255 wxSizer *sizerBtn = CreateSeparatedButtonSizer( wxOK|wxCANCEL);
256 if ( sizerBtn )
257 mainsizer->Add(sizerBtn, 0, wxEXPAND|wxALL, 10 );
258
259 SetAutoLayout( true );
260 SetSizer( mainsizer );
261
262 mainsizer->Fit( this );
263 Centre(wxBOTH);
264
265 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
266 InitDialog();
267 delete[] choices;
268 }
269
270 int wxGenericPrintDialog::ShowModal()
271 {
272 return wxDialog::ShowModal();
273 }
274
275 wxGenericPrintDialog::~wxGenericPrintDialog()
276 {
277 }
278
279 void wxGenericPrintDialog::OnOK(wxCommandEvent& WXUNUSED(event))
280 {
281 TransferDataFromWindow();
282
283 // An empty 'to' field signals printing just the
284 // 'from' page.
285 if (m_printDialogData.GetToPage() < 1)
286 m_printDialogData.SetToPage(m_printDialogData.GetFromPage());
287
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
291 // or not.
292 if (m_printDialogData.GetPrintToFile())
293 {
294 m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE);
295
296 wxFileName fname( m_printDialogData.GetPrintData().GetFilename() );
297
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;
301
302 m_printDialogData.GetPrintData().SetFilename( dialog.GetPath() );
303 }
304 else
305 {
306 m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER);
307 }
308
309 EndModal(wxID_OK);
310 }
311
312 void wxGenericPrintDialog::OnRange(wxCommandEvent& event)
313 {
314 if (!m_fromText) return;
315
316 if (event.GetInt() == 0)
317 {
318 m_fromText->Enable(false);
319 m_toText->Enable(false);
320 }
321 else if (event.GetInt() == 1)
322 {
323 m_fromText->Enable(true);
324 m_toText->Enable(true);
325 }
326 }
327
328 void wxGenericPrintDialog::OnSetup(wxCommandEvent& WXUNUSED(event))
329 {
330 wxPrintFactory* factory = wxPrintFactory::GetFactory();
331
332 if (factory->HasPrintSetupDialog())
333 {
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() );
337 dialog->ShowModal();
338 dialog->Destroy();
339 }
340 }
341
342 bool wxGenericPrintDialog::TransferDataToWindow()
343 {
344 if(m_printDialogData.GetFromPage() != 0)
345 {
346 if(m_fromText)
347 {
348 if (m_printDialogData.GetEnablePageNumbers())
349 {
350 m_fromText->Enable(true);
351 m_toText->Enable(true);
352 if (m_printDialogData.GetFromPage() > 0)
353 m_fromText->SetValue(wxString::Format(_T("%d"), m_printDialogData.GetFromPage()));
354 if (m_printDialogData.GetToPage() > 0)
355 m_toText->SetValue(wxString::Format(_T("%d"), m_printDialogData.GetToPage()));
356 if(m_rangeRadioBox)
357 {
358 if (m_printDialogData.GetAllPages() || m_printDialogData.GetFromPage() == 0)
359 m_rangeRadioBox->SetSelection(0);
360 else
361 m_rangeRadioBox->SetSelection(1);
362 }
363 }
364 else
365 {
366 m_fromText->Enable(false);
367 m_toText->Enable(false);
368 if(m_rangeRadioBox)
369 {
370 m_rangeRadioBox->SetSelection(0);
371 m_rangeRadioBox->wxRadioBox::Enable(1, false);
372 }
373 }
374 }
375 }
376 m_noCopiesText->SetValue(
377 wxString::Format(_T("%d"), m_printDialogData.GetNoCopies()));
378
379 m_printToFileCheckBox->SetValue(m_printDialogData.GetPrintToFile());
380 m_printToFileCheckBox->Enable(m_printDialogData.GetEnablePrintToFile());
381 return true;
382 }
383
384 bool wxGenericPrintDialog::TransferDataFromWindow()
385 {
386 long res = 0;
387 if(m_printDialogData.GetFromPage() != -1)
388 {
389 if (m_printDialogData.GetEnablePageNumbers())
390 {
391 if(m_fromText)
392 {
393 wxString value = m_fromText->GetValue();
394 if (value.ToLong( &res ))
395 m_printDialogData.SetFromPage( res );
396 }
397 if(m_toText)
398 {
399 wxString value = m_toText->GetValue();
400 if (value.ToLong( &res ))
401 m_printDialogData.SetToPage( res );
402 }
403 }
404 if(m_rangeRadioBox)
405 {
406 if (m_rangeRadioBox->GetSelection() == 0)
407 {
408 m_printDialogData.SetAllPages(true);
409
410 // This means all pages, more or less
411 m_printDialogData.SetFromPage(1);
412 m_printDialogData.SetToPage(32000);
413 }
414 else
415 m_printDialogData.SetAllPages(false);
416 }
417 }
418 else
419 { // continuous printing
420 m_printDialogData.SetFromPage(1);
421 m_printDialogData.SetToPage(32000);
422 }
423
424 wxString value = m_noCopiesText->GetValue();
425 if (value.ToLong( &res ))
426 m_printDialogData.SetNoCopies( res );
427
428 m_printDialogData.SetPrintToFile(m_printToFileCheckBox->GetValue());
429
430 return true;
431 }
432
433 wxDC *wxGenericPrintDialog::GetPrintDC()
434 {
435 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
436 }
437
438 // ----------------------------------------------------------------------------
439 // Generic print setup dialog
440 // ----------------------------------------------------------------------------
441
442 IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog)
443
444 BEGIN_EVENT_TABLE(wxGenericPrintSetupDialog, wxDialog)
445 EVT_LIST_ITEM_ACTIVATED(wxPRINTID_PRINTER, wxGenericPrintSetupDialog::OnPrinter)
446 END_EVENT_TABLE()
447
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)
450 {
451 Init(data);
452 }
453
454 /* XPM */
455 static const char * check_xpm[] = {
456 /* width height ncolors chars_per_pixel */
457 "16 16 3 1",
458 /* colors */
459 " s None c None",
460 "X c #000000",
461 ". c #808080",
462 /* pixels */
463 " ",
464 " ",
465 " ",
466 " .. ",
467 " XX ",
468 " XX. ",
469 " .XX ",
470 " XX ",
471 " X XX. ",
472 " XX .XX ",
473 " XX XX ",
474 " XXXX. ",
475 " XX. ",
476 " . ",
477 " ",
478 " "
479 };
480
481
482 void wxGenericPrintSetupDialog::Init(wxPrintData* data)
483 {
484 if ( data )
485 m_printData = *data;
486
487 m_targetData = data;
488
489 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
490
491 // printer selection
492
493 wxStaticBoxSizer *printer_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Printer") ), wxVERTICAL );
494 main_sizer->Add( printer_sizer, 0, wxALL|wxGROW, 10 );
495
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 );
501
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 );
506
507 wxListItem item;
508 item.SetMask( wxLIST_MASK_TEXT );
509 item.SetColumn( 1 );
510 item.SetText( _("Default printer") );
511 item.SetId( m_printerListCtrl->InsertItem( item ) );
512
513 if (data->GetPrinterName().empty())
514 {
515 wxListItem item2;
516 item2.SetId( item.GetId() );
517 item2.SetMask( wxLIST_MASK_IMAGE );
518 item2.SetImage( 0 );
519 m_printerListCtrl->SetItem( item2 );
520 // also select item
521 m_printerListCtrl->SetItemState( item.GetId(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
522 }
523
524 item.SetId( 1+ item.GetId() );
525
526 wxArrayString errors;
527 wxArrayString output;
528 long res = wxExecute( wxT("lpstat -v"), output, errors, wxEXEC_NODISABLE );
529 if (res >= 0 && errors.GetCount() == 0)
530 {
531 size_t i;
532 for (i = 0; i < output.GetCount(); i++)
533 {
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);
544 wxString name = tmp;
545 item.SetText( name );
546 item.SetId( m_printerListCtrl->InsertItem( item ) );
547 tmp = tok.GetNextToken(); // "parallel:/dev/lp0"
548 item.SetColumn( 2 );
549 item.SetText( tmp );
550 m_printerListCtrl->SetItem( item );
551 if (data->GetPrinterName() == name)
552 {
553 wxListItem item2;
554 item2.SetId( item.GetId() );
555 item2.SetMask( wxLIST_MASK_IMAGE );
556 item2.SetImage( 0 );
557 m_printerListCtrl->SetItem( item2 );
558 // also select item
559 m_printerListCtrl->SetItemState( item.GetId(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
560 }
561
562 wxString command = wxT("lpstat -p ");
563 command += name;
564 wxArrayString errors2;
565 wxArrayString output2;
566 res = wxExecute( command, output2, errors2, wxEXEC_NODISABLE );
567 if (res >= 0 && errors2.GetCount() == 0 && output2.GetCount() > 0)
568 {
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"
576 tmp = wxEmptyString;
577 while (tok2.HasMoreTokens())
578 {
579 tmp += tok2.GetNextToken();
580 tmp += wxT(" ");
581 }
582 item.SetColumn( 3 );
583 item.SetText( tmp );
584 m_printerListCtrl->SetItem( item );
585 }
586
587 item.SetColumn( 1 );
588 item.SetId( 1+ item.GetId() );
589 }
590 }
591
592
593 printer_sizer->Add( m_printerListCtrl, 0, wxALL|wxGROW, 5 );
594
595 wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
596 main_sizer->Add( item1, 0, wxALL, 5 );
597
598 // printer options (on the left)
599
600 wxBoxSizer *item2 = new wxBoxSizer( wxVERTICAL );
601
602 wxStaticBox *item4 = new wxStaticBox( this, wxPRINTID_STATIC, _("Paper size") );
603 wxStaticBoxSizer *item3 = new wxStaticBoxSizer( item4, wxVERTICAL );
604
605 m_paperTypeChoice = CreatePaperTypeChoice();
606 item3->Add( m_paperTypeChoice, 0, wxALIGN_CENTER|wxALL, 5 );
607
608 item2->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
609
610 wxString strs6[] =
611 {
612 _("Portrait"),
613 _("Landscape")
614 };
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 );
617
618 wxStaticBox *item8 = new wxStaticBox( this, wxID_ANY, _("Options") );
619 wxStaticBoxSizer *item7 = new wxStaticBoxSizer( item8, wxHORIZONTAL );
620
621 m_colourCheckBox = new wxCheckBox( this, wxPRINTID_PRINTCOLOUR, _("Print in colour") );
622 item7->Add( m_colourCheckBox, 0, wxALIGN_CENTER|wxALL, 5 );
623
624 item2->Add( item7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
625
626 item1->Add( item2, 0, wxALIGN_CENTER_HORIZONTAL, 5 );
627
628 // spooling options (on the right)
629
630 wxStaticBox *item11 = new wxStaticBox( this, wxID_ANY, _("Print spooling") );
631 wxStaticBoxSizer *item10 = new wxStaticBoxSizer( item11, wxVERTICAL );
632
633 wxStaticText *item12 = new wxStaticText( this, wxID_ANY, _("Printer command:") );
634 item10->Add( item12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
635
636 wxBoxSizer *item13 = new wxBoxSizer( wxHORIZONTAL );
637
638 item13->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
639
640 m_printerCommandText = new wxTextCtrl( this, wxPRINTID_COMMAND, wxEmptyString, wxDefaultPosition, wxSize(160,wxDefaultCoord) );
641 item13->Add( m_printerCommandText, 0, wxALIGN_CENTER|wxALL, 5 );
642
643 item10->Add( item13, 0, wxALIGN_CENTER|wxALL, 0 );
644
645 wxStaticText *item15 = new wxStaticText( this, wxID_ANY, _("Printer options:") );
646 item10->Add( item15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
647
648 wxBoxSizer *item16 = new wxBoxSizer( wxHORIZONTAL );
649
650 item16->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
651
652 m_printerOptionsText = new wxTextCtrl( this, wxPRINTID_OPTIONS, wxEmptyString, wxDefaultPosition, wxSize(160,wxDefaultCoord) );
653 item16->Add( m_printerOptionsText, 0, wxALIGN_CENTER|wxALL, 5 );
654
655 item10->Add( item16, 0, wxALIGN_CENTER|wxALL, 0 );
656
657 item1->Add( item10, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5 );
658
659
660 #if wxUSE_STATLINE
661 // static line
662 main_sizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
663 #endif
664
665 // buttons
666
667 main_sizer->Add( CreateButtonSizer( wxOK|wxCANCEL), 0, wxEXPAND|wxALL, 10 );
668
669 SetAutoLayout( true );
670 SetSizer( main_sizer );
671
672 main_sizer->Fit( this );
673 Centre(wxBOTH);
674
675
676 Fit();
677 Centre(wxBOTH);
678
679 InitDialog();
680 }
681
682 wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
683 {
684 }
685
686 void wxGenericPrintSetupDialog::OnPrinter(wxListEvent& event)
687 {
688 // Delete check mark
689 for (long item = 0; item < m_printerListCtrl->GetItemCount(); item++)
690 m_printerListCtrl->SetItemImage( item, -1 );
691
692 m_printerListCtrl->SetItemImage( event.GetIndex(), 0 );
693
694 if (event.GetIndex() == 0)
695 {
696 m_printerCommandText->SetValue( wxT("lpr") );
697 }
698 else
699 {
700 wxListItem li;
701 li.SetColumn( 1 );
702 li.SetMask( wxLIST_MASK_TEXT );
703 li.SetId( event.GetIndex() );
704 m_printerListCtrl->GetItem( li );
705 m_printerCommandText->SetValue( _T("lpr -P") + li.GetText() );
706 }
707 }
708
709 bool wxGenericPrintSetupDialog::TransferDataToWindow()
710 {
711 wxPostScriptPrintNativeData *data =
712 (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
713
714 if (m_printerCommandText && data->GetPrinterCommand())
715 m_printerCommandText->SetValue(data->GetPrinterCommand());
716 if (m_printerOptionsText && data->GetPrinterOptions())
717 m_printerOptionsText->SetValue(data->GetPrinterOptions());
718 if (m_colourCheckBox)
719 m_colourCheckBox->SetValue(m_printData.GetColour());
720
721 if (m_orientationRadioBox)
722 {
723 if (m_printData.GetOrientation() == wxPORTRAIT)
724 m_orientationRadioBox->SetSelection(0);
725 else
726 m_orientationRadioBox->SetSelection(1);
727 }
728 return true;
729 }
730
731 bool wxGenericPrintSetupDialog::TransferDataFromWindow()
732 {
733 wxPostScriptPrintNativeData *data =
734 (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
735
736 // find selected printer
737 long id = m_printerListCtrl->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
738 if (id == 0)
739 {
740 m_printData.SetPrinterName( wxEmptyString );
741 }
742 else
743 {
744 wxListItem item;
745 item.SetId( id );
746 item.SetMask( wxLIST_MASK_TEXT );
747 item.SetColumn( 1 );
748 m_printerListCtrl->GetItem( item );
749 m_printData.SetPrinterName( item.GetText() );
750 }
751
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)
759 {
760 int sel = m_orientationRadioBox->GetSelection();
761 if (sel == 0)
762 m_printData.SetOrientation(wxPORTRAIT);
763 else
764 m_printData.SetOrientation(wxLANDSCAPE);
765 }
766 if (m_paperTypeChoice)
767 {
768 int selectedItem = m_paperTypeChoice->GetSelection();
769 if (selectedItem != -1)
770 {
771 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(selectedItem);
772 if (paper != NULL)
773 m_printData.SetPaperId( paper->GetId());
774 }
775 }
776
777 if (m_targetData)
778 *m_targetData = m_printData;
779
780 return true;
781 }
782
783 wxComboBox *wxGenericPrintSetupDialog::CreatePaperTypeChoice()
784 {
785 size_t n = wxThePrintPaperDatabase->GetCount();
786 wxString *choices = new wxString [n];
787 size_t sel = 0;
788
789 for (size_t i = 0; i < n; i++)
790 {
791 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
792 choices[i] = paper->GetName();
793 if (m_printData.GetPaperId() == paper->GetId())
794 sel = i;
795 }
796
797 int width = 250;
798
799 wxComboBox *choice = new wxComboBox( this,
800 wxPRINTID_PAPERSIZE,
801 _("Paper Size"),
802 wxDefaultPosition,
803 wxSize(width, wxDefaultCoord),
804 n, choices );
805
806 delete[] choices;
807
808 choice->SetSelection(sel);
809 return choice;
810 }
811
812 #endif // wxUSE_POSTSCRIPT
813
814 // ----------------------------------------------------------------------------
815 // Generic page setup dialog
816 // ----------------------------------------------------------------------------
817
818 IMPLEMENT_CLASS(wxGenericPageSetupDialog, wxPageSetupDialogBase)
819
820 BEGIN_EVENT_TABLE(wxGenericPageSetupDialog, wxPageSetupDialogBase)
821 EVT_BUTTON(wxPRINTID_SETUP, wxGenericPageSetupDialog::OnPrinter)
822 END_EVENT_TABLE()
823
824 wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow *parent,
825 wxPageSetupDialogData* data)
826 : wxPageSetupDialogBase( parent,
827 wxID_ANY,
828 _("Page Setup"),
829 wxPoint(0,0),
830 wxSize(600, 600),
831 wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL )
832 {
833 if (data)
834 m_pageData = *data;
835
836 int textWidth = 80;
837
838 wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
839
840 // 1) top
841 wxStaticBoxSizer *topsizer = new wxStaticBoxSizer(
842 new wxStaticBox(this,wxPRINTID_STATIC, _("Paper size")), wxHORIZONTAL );
843
844 size_t n = wxThePrintPaperDatabase->GetCount();
845 wxString *choices = new wxString [n];
846
847 for (size_t i = 0; i < n; i++)
848 {
849 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
850 choices[i] = paper->GetName();
851 }
852
853 m_paperTypeChoice = new wxComboBox( this,
854 wxPRINTID_PAPERSIZE,
855 _("Paper Size"),
856 wxDefaultPosition,
857 wxSize(300, wxDefaultCoord),
858 n, choices );
859 topsizer->Add( m_paperTypeChoice, 1, wxEXPAND|wxALL, 5 );
860 // m_paperTypeChoice->SetSelection(sel);
861
862 mainsizer->Add( topsizer, 0, wxTOP|wxLEFT|wxRIGHT | wxEXPAND, 10 );
863
864 // 2) middle sizer with radio box
865
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);
872
873 mainsizer->Add( m_orientationRadioBox, 0, wxTOP|wxLEFT|wxRIGHT, 10 );
874
875 // 3) margins
876
877 wxBoxSizer *table = new wxBoxSizer( wxHORIZONTAL );
878
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 );
883
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 );
890
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 );
895
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 );
902
903 mainsizer->Add( table, 0 );
904
905 #if wxUSE_STATLINE
906 // 5) static line
907 mainsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
908 #endif
909
910 // 6) buttons
911
912 wxSizer* buttonsizer = CreateButtonSizer( wxOK|wxCANCEL);
913
914 if (wxPrintFactory::GetFactory()->HasPrintSetupDialog())
915 {
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);
920 }
921 else
922 {
923 m_printerButton = NULL;
924 }
925
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 );
929
930
931 SetAutoLayout( true );
932 SetSizer( mainsizer );
933
934 mainsizer->Fit( this );
935 Centre(wxBOTH);
936
937 InitDialog();
938
939 delete[] choices;
940 delete [] choices2;
941 }
942
943 wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
944 {
945 }
946
947 wxPageSetupDialogData& wxGenericPageSetupDialog::GetPageSetupDialogData()
948 {
949 return m_pageData;
950 }
951
952 bool wxGenericPageSetupDialog::TransferDataToWindow()
953 {
954 if (m_marginLeftText)
955 m_marginLeftText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginTopLeft().x));
956 if (m_marginTopText)
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));
962
963 if (m_orientationRadioBox)
964 {
965 if (m_pageData.GetPrintData().GetOrientation() == wxPORTRAIT)
966 m_orientationRadioBox->SetSelection(0);
967 else
968 m_orientationRadioBox->SetSelection(1);
969 }
970
971 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
972 // failing that, the id in the wxPrintData object.
973
974 wxPrintPaperType* type = wxThePrintPaperDatabase->FindPaperType(
975 wxSize(m_pageData.GetPaperSize().x * 10, m_pageData.GetPaperSize().y * 10));
976
977 if (!type && m_pageData.GetPrintData().GetPaperId() != wxPAPER_NONE)
978 type = wxThePrintPaperDatabase->FindPaperType(m_pageData.GetPrintData().GetPaperId());
979
980 if (type)
981 {
982 m_paperTypeChoice->SetStringSelection(type->GetName());
983 }
984
985 return true;
986 }
987
988 bool wxGenericPageSetupDialog::TransferDataFromWindow()
989 {
990 if (m_marginLeftText && m_marginTopText)
991 {
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) );
995 }
996 if (m_marginRightText && m_marginBottomText)
997 {
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) );
1001 }
1002
1003 if (m_orientationRadioBox)
1004 {
1005 int sel = m_orientationRadioBox->GetSelection();
1006 if (sel == 0)
1007 {
1008 m_pageData.GetPrintData().SetOrientation(wxPORTRAIT);
1009 }
1010 else
1011 {
1012 m_pageData.GetPrintData().SetOrientation(wxLANDSCAPE);
1013 }
1014 }
1015
1016 if (m_paperTypeChoice)
1017 {
1018 int selectedItem = m_paperTypeChoice->GetSelection();
1019 if (selectedItem != -1)
1020 {
1021 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(selectedItem);
1022 if ( paper )
1023 {
1024 m_pageData.SetPaperSize(wxSize(paper->GetWidth()/10, paper->GetHeight()/10));
1025 m_pageData.GetPrintData().SetPaperId(paper->GetId());
1026 }
1027 }
1028 }
1029
1030 return true;
1031 }
1032
1033 wxComboBox *wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x, int *y)
1034 {
1035 /*
1036 if (!wxThePrintPaperDatabase)
1037 {
1038 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
1039 wxThePrintPaperDatabase->CreateDatabase();
1040 }
1041 */
1042
1043 size_t n = wxThePrintPaperDatabase->GetCount();
1044 wxString *choices = new wxString [n];
1045
1046 for (size_t i = 0; i < n; i++)
1047 {
1048 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
1049 choices[i] = paper->GetName();
1050 }
1051
1052 (void) new wxStaticText(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(*x, *y));
1053 *y += 25;
1054
1055 wxComboBox *choice = new wxComboBox( this,
1056 wxPRINTID_PAPERSIZE,
1057 _("Paper Size"),
1058 wxPoint(*x, *y),
1059 wxSize(300, wxDefaultCoord),
1060 n, choices );
1061 *y += 35;
1062 delete[] choices;
1063
1064 // choice->SetSelection(sel);
1065 return choice;
1066 }
1067
1068 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent& WXUNUSED(event))
1069 {
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.
1077
1078 // First save the current settings, so the wxPrintData object is up to date.
1079 TransferDataFromWindow();
1080
1081 // Transfer the current print settings from this dialog to the page setup dialog.
1082
1083 #if 0
1084 // Use print factory later
1085
1086 wxPrintDialogData data;
1087 data = GetPageSetupData().GetPrintData();
1088 data.SetSetupDialog(true);
1089 wxPrintDialog printDialog(this, & data);
1090 printDialog.ShowModal();
1091
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
1096
1097 // Now update the dialog in case the page setup dialog changed some of our settings.
1098 TransferDataToWindow();
1099 #endif
1100 }
1101
1102 #endif

  ViewVC Help
Powered by ViewVC 1.1.22