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