Removed Pango homemade implementation and
[wxWidgets.git] / src / generic / prntdlgg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "prntdlgg.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
32
33 #ifndef WX_PRECOMP
34 #include "wx/utils.h"
35 #include "wx/dc.h"
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"
44 #include "wx/intl.h"
45 #include "wx/sizer.h"
46 #include "wx/cmndata.h"
47 #endif
48
49 #if wxUSE_STATLINE
50 #include "wx/statline.h"
51 #endif
52
53 #include "wx/generic/prntdlgg.h"
54
55 #if wxUSE_POSTSCRIPT
56 #include "wx/generic/dcpsg.h"
57 #endif
58
59 #include "wx/prntbase.h"
60 #include "wx/printdlg.h"
61 #include "wx/paper.h"
62 #include "wx/filename.h"
63
64 #include <stdlib.h>
65 #include <string.h>
66
67 // ----------------------------------------------------------------------------
68 // global vars
69 // ----------------------------------------------------------------------------
70
71 extern wxPrintPaperDatabase *wxThePrintPaperDatabase;
72
73 #if wxUSE_POSTSCRIPT
74
75 //----------------------------------------------------------------------------
76 // wxPostScriptNativeData
77 //----------------------------------------------------------------------------
78
79 IMPLEMENT_CLASS(wxPostScriptPrintNativeData, wxPrintNativeDataBase)
80
81 wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
82 {
83 m_previewCommand = wxT("");
84 #ifdef __VMS__
85 m_printerCommand = wxT("print");
86 m_printerOptions = wxT("/nonotify/queue=psqueue");
87 m_afmPath = wxT("sys$ps_font_metrics:");
88 #endif
89
90 #ifdef __WXMSW__
91 m_printerCommand = wxT("print");
92 m_printerOptions = wxT("");
93 m_afmPath = wxT("c:\\windows\\system\\");
94 #endif
95
96 #if !defined(__VMS__) && !defined(__WXMSW__)
97 m_printerCommand = wxT("lpr");
98 m_printerOptions = wxT("");
99 m_afmPath = wxT("");
100 #endif
101
102 m_printerScaleX = 1.0;
103 m_printerScaleY = 1.0;
104 m_printerTranslateX = 0;
105 m_printerTranslateY = 0;
106 }
107
108 wxPostScriptPrintNativeData::~wxPostScriptPrintNativeData()
109 {
110 }
111
112 bool wxPostScriptPrintNativeData::TransferTo( wxPrintData &data )
113 {
114 return true;
115 }
116
117 bool wxPostScriptPrintNativeData::TransferFrom( const wxPrintData &data )
118 {
119 return true;
120 }
121
122 // ----------------------------------------------------------------------------
123 // Generic print dialog for non-Windows printing use.
124 // ----------------------------------------------------------------------------
125
126 IMPLEMENT_CLASS(wxGenericPrintDialog, wxPrintDialogBase)
127
128 BEGIN_EVENT_TABLE(wxGenericPrintDialog, wxPrintDialogBase)
129 EVT_BUTTON(wxID_OK, wxGenericPrintDialog::OnOK)
130 EVT_BUTTON(wxPRINTID_SETUP, wxGenericPrintDialog::OnSetup)
131 EVT_RADIOBOX(wxPRINTID_RANGE, wxGenericPrintDialog::OnRange)
132 END_EVENT_TABLE()
133
134 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
135 wxPrintDialogData* data)
136 : wxPrintDialogBase(parent, wxID_ANY, _("Print"),
137 wxPoint(0, 0), wxSize(600, 600),
138 wxDEFAULT_DIALOG_STYLE |
139 wxTAB_TRAVERSAL)
140 {
141 if ( data )
142 m_printDialogData = *data;
143
144 Init(parent);
145 }
146
147 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
148 wxPrintData* data)
149 : wxPrintDialogBase(parent, 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 void wxGenericPrintDialog::Init(wxWindow * WXUNUSED(parent))
161 {
162 // wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0, 0), wxSize(600, 600),
163 // wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL);
164
165 wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
166
167 // 1) top row
168
169 wxPrintFactory* factory = wxPrintFactory::GetFactory();
170
171 wxStaticBoxSizer *topsizer = new wxStaticBoxSizer(
172 new wxStaticBox( this, wxID_ANY, _( "Printer options" ) ), wxHORIZONTAL );
173 wxFlexGridSizer *flex = new wxFlexGridSizer( 2 );
174 flex->AddGrowableCol( 1 );
175 topsizer->Add( flex, 1, wxGROW );
176
177 m_printToFileCheckBox = new wxCheckBox( this, wxPRINTID_PRINTTOFILE, _("Print to File") );
178 flex->Add( m_printToFileCheckBox, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
179
180 m_setupButton = new wxButton(this, wxPRINTID_SETUP, _("Setup...") );
181 flex->Add( m_setupButton, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
182
183 if (!factory->HasPrintSetupDialog())
184 m_setupButton->Enable( false );
185
186 if (factory->HasPrinterLine())
187 {
188 flex->Add( new wxStaticText( this, -1, _("Printer:") ),
189 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
190 flex->Add( new wxStaticText( this, -1, factory->CreatePrinterLine() ),
191 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
192 }
193
194 if (factory->HasStatusLine())
195 {
196 flex->Add( new wxStaticText( this, -1, _("Status:") ),
197 0, wxALIGN_CENTER_VERTICAL|wxALL-wxTOP, 5 );
198 flex->Add( new wxStaticText( this, -1, factory->CreateStatusLine() ),
199 0, wxALIGN_CENTER_VERTICAL|wxALL-wxTOP, 5 );
200 }
201
202 mainsizer->Add( topsizer, 0, wxLEFT|wxTOP|wxRIGHT|wxGROW, 10 );
203
204 // 2) middle row with radio box
205
206 wxString *choices = new wxString[2];
207 choices[0] = _("All");
208 choices[1] = _("Pages");
209
210 m_fromText = (wxTextCtrl*)NULL;
211 m_toText = (wxTextCtrl*)NULL;
212 m_rangeRadioBox = (wxRadioBox *)NULL;
213
214 if (m_printDialogData.GetFromPage() != 0)
215 {
216 m_rangeRadioBox = new wxRadioBox(this, wxPRINTID_RANGE, _("Print Range"),
217 wxDefaultPosition, wxDefaultSize,
218 2, choices,
219 1, wxRA_VERTICAL);
220 m_rangeRadioBox->SetSelection(1);
221
222 mainsizer->Add( m_rangeRadioBox, 0, wxLEFT|wxTOP|wxRIGHT, 10 );
223 }
224
225 // 3) bottom row
226
227 wxBoxSizer *bottomsizer = new wxBoxSizer( wxHORIZONTAL );
228
229 if (m_printDialogData.GetFromPage() != 0)
230 {
231 bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("From:") ), 0, wxCENTER|wxALL, 5 );
232 m_fromText = new wxTextCtrl(this, wxPRINTID_FROM, wxEmptyString, wxDefaultPosition, wxSize(40, wxDefaultCoord));
233 bottomsizer->Add( m_fromText, 1, wxCENTER|wxRIGHT, 10 );
234
235 bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("To:") ), 0, wxCENTER|wxALL, 5);
236 m_toText = new wxTextCtrl(this, wxPRINTID_TO, wxEmptyString, wxDefaultPosition, wxSize(40, wxDefaultCoord));
237 bottomsizer->Add( m_toText, 1, wxCENTER|wxRIGHT, 10 );
238 }
239
240 bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Copies:") ), 0, wxCENTER|wxALL, 5 );
241 m_noCopiesText = new wxTextCtrl(this, wxPRINTID_COPIES, wxEmptyString, wxPoint(252, 130), wxSize(40, wxDefaultCoord));
242 bottomsizer->Add( m_noCopiesText, 1, wxCENTER|wxRIGHT, 10 );
243
244 mainsizer->Add( bottomsizer, 0, wxTOP|wxLEFT|wxRIGHT, 12 );
245
246 #if wxUSE_STATLINE
247 // 4) static line
248 mainsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
249 #endif
250
251 // 5) buttons
252
253 mainsizer->Add( CreateButtonSizer( wxOK|wxCANCEL), 0, wxCENTER|wxALL, 10 );
254
255 SetAutoLayout( true );
256 SetSizer( mainsizer );
257
258 mainsizer->Fit( this );
259 Centre(wxBOTH);
260
261 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
262 InitDialog();
263 delete[] choices;
264 }
265
266 int wxGenericPrintDialog::ShowModal()
267 {
268 return wxDialog::ShowModal();
269 }
270
271 wxGenericPrintDialog::~wxGenericPrintDialog()
272 {
273 }
274
275 void wxGenericPrintDialog::OnOK(wxCommandEvent& WXUNUSED(event))
276 {
277 TransferDataFromWindow();
278
279 // An empty 'to' field signals printing just the
280 // 'from' page.
281 if (m_printDialogData.GetToPage() < 1)
282 m_printDialogData.SetToPage(m_printDialogData.GetFromPage());
283
284 // There are some interactions between the global setup data
285 // and the standard print dialog. The global printing 'mode'
286 // is determined by whether the user checks Print to file
287 // or not.
288 if (m_printDialogData.GetPrintToFile())
289 {
290 m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE);
291
292 wxFileName fname( m_printDialogData.GetPrintData().GetFilename() );
293
294 wxFileDialog dialog( this, _("PostScript file"),
295 fname.GetPath(), fname.GetFullName(), wxT("*.ps"), wxOPEN | wxOVERWRITE_PROMPT );
296 if (dialog.ShowModal() != wxID_OK) return;
297
298 m_printDialogData.GetPrintData().SetFilename( dialog.GetPath() );
299 }
300 else
301 {
302 m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER);
303 }
304
305 EndModal(wxID_OK);
306 }
307
308 void wxGenericPrintDialog::OnRange(wxCommandEvent& event)
309 {
310 if (!m_fromText) return;
311
312 if (event.GetInt() == 0)
313 {
314 m_fromText->Enable(false);
315 m_toText->Enable(false);
316 }
317 else if (event.GetInt() == 1)
318 {
319 m_fromText->Enable(true);
320 m_toText->Enable(true);
321 }
322 }
323
324 void wxGenericPrintDialog::OnSetup(wxCommandEvent& WXUNUSED(event))
325 {
326 wxPrintFactory* factory = wxPrintFactory::GetFactory();
327
328 if (factory->HasPrintSetupDialog())
329 {
330 // The print setup dialog should change the
331 // print data in-place if not cancelled.
332 wxDialog *dialog = factory->CreatePrintSetupDialog( this, &m_printDialogData.GetPrintData() );
333 dialog->ShowModal();
334 dialog->Destroy();
335 }
336 }
337
338 bool wxGenericPrintDialog::TransferDataToWindow()
339 {
340 if(m_printDialogData.GetFromPage() != 0)
341 {
342 if(m_fromText)
343 {
344 if (m_printDialogData.GetEnablePageNumbers())
345 {
346 m_fromText->Enable(true);
347 m_toText->Enable(true);
348 if (m_printDialogData.GetFromPage() > 0)
349 m_fromText->SetValue(wxString::Format(_T("%d"), m_printDialogData.GetFromPage()));
350 if (m_printDialogData.GetToPage() > 0)
351 m_toText->SetValue(wxString::Format(_T("%d"), m_printDialogData.GetToPage()));
352 if(m_rangeRadioBox)
353 if (m_printDialogData.GetAllPages() || m_printDialogData.GetFromPage() == 0)
354 m_rangeRadioBox->SetSelection(0);
355 else
356 m_rangeRadioBox->SetSelection(1);
357 }
358 else
359 {
360 m_fromText->Enable(false);
361 m_toText->Enable(false);
362 if(m_rangeRadioBox)
363 {
364 m_rangeRadioBox->SetSelection(0);
365 m_rangeRadioBox->wxRadioBox::Enable(1, false);
366 }
367 }
368 }
369 }
370 m_noCopiesText->SetValue(
371 wxString::Format(_T("%d"), m_printDialogData.GetNoCopies()));
372
373 m_printToFileCheckBox->SetValue(m_printDialogData.GetPrintToFile());
374 m_printToFileCheckBox->Enable(m_printDialogData.GetEnablePrintToFile());
375 return true;
376 }
377
378 bool wxGenericPrintDialog::TransferDataFromWindow()
379 {
380 long res = 0;
381 if(m_printDialogData.GetFromPage() != -1)
382 {
383 if (m_printDialogData.GetEnablePageNumbers())
384 {
385 if(m_fromText)
386 {
387 wxString value = m_fromText->GetValue();
388 if (value.ToLong( &res ))
389 m_printDialogData.SetFromPage( res );
390 }
391 if(m_toText)
392 {
393 wxString value = m_toText->GetValue();
394 if (value.ToLong( &res ))
395 m_printDialogData.SetToPage( res );
396 }
397 }
398 if(m_rangeRadioBox)
399 {
400 if (m_rangeRadioBox->GetSelection() == 0)
401 {
402 m_printDialogData.SetAllPages(true);
403
404 // This means all pages, more or less
405 m_printDialogData.SetFromPage(1);
406 m_printDialogData.SetToPage(32000);
407 }
408 else
409 m_printDialogData.SetAllPages(false);
410 }
411 }
412 else
413 { // continuous printing
414 m_printDialogData.SetFromPage(1);
415 m_printDialogData.SetToPage(32000);
416 }
417
418 wxString value = m_noCopiesText->GetValue();
419 if (value.ToLong( &res ))
420 m_printDialogData.SetNoCopies( res );
421
422 m_printDialogData.SetPrintToFile(m_printToFileCheckBox->GetValue());
423
424 return true;
425 }
426
427 wxDC *wxGenericPrintDialog::GetPrintDC()
428 {
429 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
430 }
431
432 // ----------------------------------------------------------------------------
433 // Generic print setup dialog
434 // ----------------------------------------------------------------------------
435
436 IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog)
437
438 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintData* data):
439 wxDialog(parent, wxID_ANY, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL)
440 {
441 Init(data);
442 }
443
444 void wxGenericPrintSetupDialog::Init(wxPrintData* data)
445 {
446 if ( data )
447 m_printData = *data;
448
449
450 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
451
452 wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
453 main_sizer->Add( item1, 0, wxALL, 5 );
454
455 // printer options (on the left)
456
457 wxBoxSizer *item2 = new wxBoxSizer( wxVERTICAL );
458
459 wxStaticBox *item4 = new wxStaticBox( this, wxPRINTID_STATIC, _("Paper size") );
460 wxStaticBoxSizer *item3 = new wxStaticBoxSizer( item4, wxVERTICAL );
461
462 m_paperTypeChoice = CreatePaperTypeChoice();
463 item3->Add( m_paperTypeChoice, 0, wxALIGN_CENTER|wxALL, 5 );
464
465 item2->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
466
467 wxString strs6[] =
468 {
469 _("Portrait"),
470 _("Landscape")
471 };
472 m_orientationRadioBox= new wxRadioBox( this, wxPRINTID_ORIENTATION, _("Orientation"), wxDefaultPosition, wxDefaultSize, 2, strs6, 1, wxRA_SPECIFY_ROWS );
473 item2->Add( m_orientationRadioBox, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
474
475 wxStaticBox *item8 = new wxStaticBox( this, -1, _("Options") );
476 wxStaticBoxSizer *item7 = new wxStaticBoxSizer( item8, wxHORIZONTAL );
477
478 m_colourCheckBox = new wxCheckBox( this, wxPRINTID_PRINTCOLOUR, _("Print in colour") );
479 item7->Add( m_colourCheckBox, 0, wxALIGN_CENTER|wxALL, 5 );
480
481 item2->Add( item7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
482
483 item1->Add( item2, 0, wxALIGN_CENTER_HORIZONTAL, 5 );
484
485 // spooling options (on the right)
486
487 wxStaticBox *item11 = new wxStaticBox( this, -1, _("Print spooling") );
488 wxStaticBoxSizer *item10 = new wxStaticBoxSizer( item11, wxVERTICAL );
489
490 wxStaticText *item12 = new wxStaticText( this, -1, _("Printer command:") );
491 item10->Add( item12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
492
493 wxBoxSizer *item13 = new wxBoxSizer( wxHORIZONTAL );
494
495 item13->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
496
497 m_printerCommandText = new wxTextCtrl( this, wxPRINTID_COMMAND, wxT(""), wxDefaultPosition, wxSize(160,-1) );
498 item13->Add( m_printerCommandText, 0, wxALIGN_CENTER|wxALL, 5 );
499
500 item10->Add( item13, 0, wxALIGN_CENTER|wxALL, 0 );
501
502 wxStaticText *item15 = new wxStaticText( this, -1, _("Printer options:") );
503 item10->Add( item15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
504
505 wxBoxSizer *item16 = new wxBoxSizer( wxHORIZONTAL );
506
507 item16->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
508
509 m_printerOptionsText = new wxTextCtrl( this, wxPRINTID_OPTIONS, wxT(""), wxDefaultPosition, wxSize(160,-1) );
510 item16->Add( m_printerOptionsText, 0, wxALIGN_CENTER|wxALL, 5 );
511
512 item10->Add( item16, 0, wxALIGN_CENTER|wxALL, 0 );
513
514 item1->Add( item10, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5 );
515
516
517 #if wxUSE_STATLINE
518 // static line
519 main_sizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
520 #endif
521
522 // buttons
523
524 main_sizer->Add( CreateButtonSizer( wxOK|wxCANCEL), 0, wxCENTER|wxALL, 10 );
525
526 SetAutoLayout( true );
527 SetSizer( main_sizer );
528
529 main_sizer->Fit( this );
530 Centre(wxBOTH);
531
532
533 Fit();
534 Centre(wxBOTH);
535
536 InitDialog();
537 }
538
539 wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
540 {
541 }
542
543 bool wxGenericPrintSetupDialog::TransferDataToWindow()
544 {
545 wxPostScriptPrintNativeData *data =
546 (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
547
548 if (m_printerCommandText && data->GetPrinterCommand())
549 m_printerCommandText->SetValue(data->GetPrinterCommand());
550 if (m_printerOptionsText && data->GetPrinterOptions())
551 m_printerOptionsText->SetValue(data->GetPrinterOptions());
552 if (m_colourCheckBox)
553 m_colourCheckBox->SetValue(m_printData.GetColour());
554
555 if (m_orientationRadioBox)
556 {
557 if (m_printData.GetOrientation() == wxPORTRAIT)
558 m_orientationRadioBox->SetSelection(0);
559 else
560 m_orientationRadioBox->SetSelection(1);
561 }
562 return true;
563 }
564
565 bool wxGenericPrintSetupDialog::TransferDataFromWindow()
566 {
567 wxPostScriptPrintNativeData *data =
568 (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
569
570 if (m_printerCommandText)
571 data->SetPrinterCommand(m_printerCommandText->GetValue());
572 if (m_printerOptionsText)
573 data->SetPrinterOptions(m_printerOptionsText->GetValue());
574 if (m_colourCheckBox)
575 m_printData.SetColour(m_colourCheckBox->GetValue());
576 if (m_orientationRadioBox)
577 {
578 int sel = m_orientationRadioBox->GetSelection();
579 if (sel == 0)
580 m_printData.SetOrientation(wxPORTRAIT);
581 else
582 m_printData.SetOrientation(wxLANDSCAPE);
583 }
584 if (m_paperTypeChoice)
585 {
586 int selectedItem = m_paperTypeChoice->GetSelection();
587 if (selectedItem != -1)
588 {
589 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(selectedItem);
590 if (paper != NULL)
591 m_printData.SetPaperId( paper->GetId());
592 }
593 }
594
595 return true;
596 }
597
598 wxComboBox *wxGenericPrintSetupDialog::CreatePaperTypeChoice()
599 {
600 size_t n = wxThePrintPaperDatabase->GetCount();
601 wxString *choices = new wxString [n];
602 size_t sel = 0;
603
604 for (size_t i = 0; i < n; i++)
605 {
606 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
607 choices[i] = paper->GetName();
608 if (m_printData.GetPaperId() == paper->GetId())
609 sel = i;
610 }
611
612 int width = 250;
613
614 wxComboBox *choice = new wxComboBox( this,
615 wxPRINTID_PAPERSIZE,
616 _("Paper Size"),
617 wxDefaultPosition,
618 wxSize(width, wxDefaultCoord),
619 n, choices );
620
621 delete[] choices;
622
623 choice->SetSelection(sel);
624 return choice;
625 }
626
627 #endif // wxUSE_POSTSCRIPT
628
629 // ----------------------------------------------------------------------------
630 // Generic page setup dialog
631 // ----------------------------------------------------------------------------
632
633 IMPLEMENT_CLASS(wxGenericPageSetupDialog, wxDialog)
634
635 BEGIN_EVENT_TABLE(wxGenericPageSetupDialog, wxDialog)
636 EVT_BUTTON(wxPRINTID_SETUP, wxGenericPageSetupDialog::OnPrinter)
637 END_EVENT_TABLE()
638
639 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent& WXUNUSED(event))
640 {
641 // We no longer query GetPrintMode, so we can eliminate the need
642 // to call SetPrintMode.
643 // This has the limitation that we can't explicitly call the PostScript
644 // print setup dialog from the generic Page Setup dialog under Windows,
645 // but since this choice would only happen when trying to do PostScript
646 // printing under Windows (and only in 16-bit Windows which
647 // doesn't have a Windows-specific page setup dialog) it's worth it.
648
649 // First save the current settings, so the wxPrintData object is up to date.
650 TransferDataFromWindow();
651
652 // Transfer the current print settings from this dialog to the page setup dialog.
653 wxPrintDialogData data;
654 data = GetPageSetupData().GetPrintData();
655 data.SetSetupDialog(true);
656 wxPrintDialog printDialog(this, & data);
657 printDialog.ShowModal();
658
659 // Transfer the page setup print settings from the page dialog to this dialog again, in case
660 // the page setup dialog changed something.
661 GetPageSetupData().GetPrintData() = printDialog.GetPrintDialogData().GetPrintData();
662 GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData
663
664 // Now update the dialog in case the page setup dialog changed some of our settings.
665 TransferDataToWindow();
666 }
667
668 wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow *parent,
669 wxPageSetupData* data)
670 : wxDialog( parent,
671 wxID_ANY,
672 _("Page Setup"),
673 wxPoint(0, 0),
674 wxSize(600, 600),
675 wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL )
676 {
677 if (data)
678 m_pageData = *data;
679
680 int textWidth = 80;
681
682 wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
683
684 // 1) top
685 wxStaticBoxSizer *topsizer = new wxStaticBoxSizer(
686 new wxStaticBox(this,wxPRINTID_STATIC, _("Paper size")), wxHORIZONTAL );
687
688 size_t n = wxThePrintPaperDatabase->GetCount();
689 wxString *choices = new wxString [n];
690
691 for (size_t i = 0; i < n; i++)
692 {
693 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
694 choices[i] = paper->GetName();
695 }
696
697 m_paperTypeChoice = new wxComboBox( this,
698 wxPRINTID_PAPERSIZE,
699 _("Paper Size"),
700 wxDefaultPosition,
701 wxSize(300, wxDefaultCoord),
702 n, choices );
703 topsizer->Add( m_paperTypeChoice, 1, wxEXPAND|wxALL, 5 );
704 // m_paperTypeChoice->SetSelection(sel);
705
706 mainsizer->Add( topsizer, 0, wxTOP|wxLEFT|wxRIGHT | wxEXPAND, 10 );
707
708 // 2) middle sizer with radio box
709
710 wxString *choices2 = new wxString[2];
711 choices2[0] = _("Portrait");
712 choices2[1] = _("Landscape");
713 m_orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"),
714 wxDefaultPosition, wxDefaultSize, 2, choices2, 2);
715 m_orientationRadioBox->SetSelection(0);
716
717 mainsizer->Add( m_orientationRadioBox, 0, wxTOP|wxLEFT|wxRIGHT, 10 );
718
719 // 3) margins
720
721 wxBoxSizer *table = new wxBoxSizer( wxHORIZONTAL );
722
723 wxBoxSizer *column1 = new wxBoxSizer( wxVERTICAL );
724 column1->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Left margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 );
725 column1->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Top margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 );
726 table->Add( column1, 0, wxALL | wxEXPAND, 5 );
727
728 wxBoxSizer *column2 = new wxBoxSizer( wxVERTICAL );
729 m_marginLeftText = new wxTextCtrl(this, wxPRINTID_LEFTMARGIN, wxEmptyString, wxDefaultPosition, wxSize(textWidth, wxDefaultCoord));
730 m_marginTopText = new wxTextCtrl(this, wxPRINTID_TOPMARGIN, wxEmptyString, wxDefaultPosition, wxSize(textWidth, wxDefaultCoord));
731 column2->Add( m_marginLeftText, 1, wxALL, 5 );
732 column2->Add( m_marginTopText, 1, wxALL, 5 );
733 table->Add( column2, 0, wxRIGHT|wxTOP|wxBOTTOM | wxEXPAND, 5 );
734
735 wxBoxSizer *column3 = new wxBoxSizer( wxVERTICAL );
736 column3->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Right margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 );
737 column3->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Bottom margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 );
738 table->Add( column3, 0, wxALL | wxEXPAND, 5 );
739
740 wxBoxSizer *column4 = new wxBoxSizer( wxVERTICAL );
741 m_marginRightText = new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN, wxEmptyString, wxDefaultPosition, wxSize(textWidth, wxDefaultCoord));
742 m_marginBottomText = new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN, wxEmptyString, wxDefaultPosition, wxSize(textWidth, wxDefaultCoord));
743 column4->Add( m_marginRightText, 1, wxALL, 5 );
744 column4->Add( m_marginBottomText, 1, wxALL, 5 );
745 table->Add( column4, 0, wxRIGHT|wxTOP|wxBOTTOM | wxEXPAND, 5 );
746
747 mainsizer->Add( table, 0 );
748
749 #if wxUSE_STATLINE
750 // 5) static line
751 mainsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
752 #endif
753
754 // 6) buttons
755
756 wxSizer* buttonsizer = CreateButtonSizer( wxOK|wxCANCEL);
757 m_printerButton = new wxButton(this, wxPRINTID_SETUP, _("Printer...") );
758 buttonsizer->Add( m_printerButton, 0, wxLEFT|wxRIGHT, 10 );
759 if ( !m_pageData.GetEnablePrinter() )
760 m_printerButton->Enable(false);
761 // if (m_printData.GetEnableHelp())
762 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight);
763 mainsizer->Add( buttonsizer, 0, wxCENTER|wxALL, 10 );
764
765
766 SetAutoLayout( true );
767 SetSizer( mainsizer );
768
769 mainsizer->Fit( this );
770 Centre(wxBOTH);
771
772 InitDialog();
773
774 delete[] choices;
775 delete [] choices2;
776 }
777
778 wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
779 {
780 }
781
782 bool wxGenericPageSetupDialog::TransferDataToWindow()
783 {
784 if (m_marginLeftText)
785 m_marginLeftText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginTopLeft().x));
786 if (m_marginTopText)
787 m_marginTopText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginTopLeft().y));
788 if (m_marginRightText)
789 m_marginRightText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginBottomRight().x));
790 if (m_marginBottomText)
791 m_marginBottomText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginBottomRight().y));
792
793 if (m_orientationRadioBox)
794 {
795 if (m_pageData.GetPrintData().GetOrientation() == wxPORTRAIT)
796 m_orientationRadioBox->SetSelection(0);
797 else
798 m_orientationRadioBox->SetSelection(1);
799 }
800
801 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
802 // failing that, the id in the wxPrintData object.
803
804 wxPrintPaperType* type = wxThePrintPaperDatabase->FindPaperType(
805 wxSize(m_pageData.GetPaperSize().x * 10, m_pageData.GetPaperSize().y * 10));
806
807 if (!type && m_pageData.GetPrintData().GetPaperId() != wxPAPER_NONE)
808 type = wxThePrintPaperDatabase->FindPaperType(m_pageData.GetPrintData().GetPaperId());
809
810 if (type)
811 {
812 m_paperTypeChoice->SetStringSelection(type->GetName());
813 }
814
815 return true;
816 }
817
818 bool wxGenericPageSetupDialog::TransferDataFromWindow()
819 {
820 if (m_marginLeftText && m_marginTopText)
821 {
822 int left = wxAtoi( m_marginLeftText->GetValue().c_str() );
823 int top = wxAtoi( m_marginTopText->GetValue().c_str() );
824 m_pageData.SetMarginTopLeft( wxPoint(left,top) );
825 }
826 if (m_marginRightText && m_marginBottomText)
827 {
828 int right = wxAtoi( m_marginRightText->GetValue().c_str() );
829 int bottom = wxAtoi( m_marginBottomText->GetValue().c_str() );
830 m_pageData.SetMarginBottomRight( wxPoint(right,bottom) );
831 }
832
833 if (m_orientationRadioBox)
834 {
835 int sel = m_orientationRadioBox->GetSelection();
836 if (sel == 0)
837 {
838 m_pageData.GetPrintData().SetOrientation(wxPORTRAIT);
839 }
840 else
841 {
842 m_pageData.GetPrintData().SetOrientation(wxLANDSCAPE);
843 }
844 }
845
846 if (m_paperTypeChoice)
847 {
848 int selectedItem = m_paperTypeChoice->GetSelection();
849 if (selectedItem != -1)
850 {
851 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(selectedItem);
852 if ( paper )
853 {
854 m_pageData.SetPaperSize(wxSize(paper->GetWidth()/10, paper->GetHeight()/10));
855 m_pageData.GetPrintData().SetPaperId(paper->GetId());
856 }
857 }
858 }
859
860 return true;
861 }
862
863 wxComboBox *wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x, int *y)
864 {
865 /*
866 if (!wxThePrintPaperDatabase)
867 {
868 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
869 wxThePrintPaperDatabase->CreateDatabase();
870 }
871 */
872
873 size_t n = wxThePrintPaperDatabase->GetCount();
874 wxString *choices = new wxString [n];
875
876 for (size_t i = 0; i < n; i++)
877 {
878 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
879 choices[i] = paper->GetName();
880 }
881
882 (void) new wxStaticText(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(*x, *y));
883 *y += 25;
884
885 wxComboBox *choice = new wxComboBox( this,
886 wxPRINTID_PAPERSIZE,
887 _("Paper Size"),
888 wxPoint(*x, *y),
889 wxSize(300, wxDefaultCoord),
890 n, choices );
891 *y += 35;
892 delete[] choices;
893
894 // choice->SetSelection(sel);
895 return choice;
896 }
897
898 #endif
899