]> git.saurik.com Git - wxWidgets.git/blob - src/generic/prntdlgg.cpp
UMADrawControl is not to be used anymore
[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 (m_printDialogData.GetPrintToFile())
265 {
266 m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE);
267
268 wxFileName fname( m_printDialogData.GetPrintData().GetFilename() );
269
270 wxFileDialog dialog( this, _("PostScript file"),
271 fname.GetPath(), fname.GetFullName(), wxT("*.ps"), wxOPEN | wxOVERWRITE_PROMPT );
272 if (dialog.ShowModal() != wxID_OK) return;
273
274 m_printDialogData.GetPrintData().SetFilename( dialog.GetPath() );
275 }
276 else
277 {
278 m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER);
279 }
280
281 EndModal(wxID_OK);
282 }
283
284 void wxGenericPrintDialog::OnRange(wxCommandEvent& event)
285 {
286 if (!m_fromText) return;
287
288 if (event.GetInt() == 0)
289 {
290 m_fromText->Enable(FALSE);
291 m_toText->Enable(FALSE);
292 }
293 else if (event.GetInt() == 1)
294 {
295 m_fromText->Enable(TRUE);
296 m_toText->Enable(TRUE);
297 }
298 }
299
300 void wxGenericPrintDialog::OnSetup(wxCommandEvent& WXUNUSED(event))
301 {
302 wxGenericPrintSetupDialog dialog( this, &m_printDialogData.GetPrintData() );
303 if (dialog.ShowModal() != wxID_CANCEL)
304 {
305 m_printDialogData = dialog.GetPrintData();
306 }
307 }
308
309 bool wxGenericPrintDialog::TransferDataToWindow()
310 {
311 if(m_printDialogData.GetFromPage() != 0)
312 {
313 if(m_fromText)
314 {
315 if (m_printDialogData.GetEnablePageNumbers())
316 {
317 m_fromText->Enable(TRUE);
318 m_toText->Enable(TRUE);
319 if (m_printDialogData.GetFromPage() > 0)
320 m_fromText->SetValue(wxString::Format(_T("%d"), m_printDialogData.GetFromPage()));
321 if (m_printDialogData.GetToPage() > 0)
322 m_toText->SetValue(wxString::Format(_T("%d"), m_printDialogData.GetToPage()));
323 if(m_rangeRadioBox)
324 if (m_printDialogData.GetAllPages() || m_printDialogData.GetFromPage() == 0)
325 m_rangeRadioBox->SetSelection(0);
326 else
327 m_rangeRadioBox->SetSelection(1);
328 }
329 else
330 {
331 m_fromText->Enable(FALSE);
332 m_toText->Enable(FALSE);
333 if(m_rangeRadioBox)
334 {
335 m_rangeRadioBox->SetSelection(0);
336 m_rangeRadioBox->wxRadioBox::Enable(1, FALSE);
337 }
338 }
339 }
340 }
341 m_noCopiesText->SetValue(
342 wxString::Format(_T("%d"), m_printDialogData.GetNoCopies()));
343
344 m_printToFileCheckBox->SetValue(m_printDialogData.GetPrintToFile());
345 m_printToFileCheckBox->Enable(m_printDialogData.GetEnablePrintToFile());
346 return TRUE;
347 }
348
349 bool wxGenericPrintDialog::TransferDataFromWindow()
350 {
351 long res = 0;
352 if(m_printDialogData.GetFromPage() != -1)
353 {
354 if (m_printDialogData.GetEnablePageNumbers())
355 {
356 if(m_fromText)
357 {
358 wxString value = m_fromText->GetValue();
359 if (value.ToLong( &res ))
360 m_printDialogData.SetFromPage( res );
361 }
362 if(m_toText)
363 {
364 wxString value = m_toText->GetValue();
365 if (value.ToLong( &res ))
366 m_printDialogData.SetToPage( res );
367 }
368 }
369 if(m_rangeRadioBox)
370 {
371 if (m_rangeRadioBox->GetSelection() == 0)
372 m_printDialogData.SetAllPages(TRUE);
373 else
374 m_printDialogData.SetAllPages(FALSE);
375 }
376 }
377 else
378 { // continuous printing
379 m_printDialogData.SetFromPage(1);
380 m_printDialogData.SetToPage(32000);
381 }
382
383 wxString value = m_noCopiesText->GetValue();
384 if (value.ToLong( &res ))
385 m_printDialogData.SetNoCopies( res );
386
387 m_printDialogData.SetPrintToFile(m_printToFileCheckBox->GetValue());
388
389 return TRUE;
390 }
391
392 /*
393 TODO: collate and noCopies should be duplicated across dialog data and print data objects
394 (slightly different semantics on Windows but let's ignore this for a bit).
395 */
396
397 wxDC *wxGenericPrintDialog::GetPrintDC()
398 {
399 // return new wxPostScriptDC(wxThePrintSetupData->GetPrinterFile(), FALSE, (wxWindow *) NULL);
400 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
401 }
402
403 // ----------------------------------------------------------------------------
404 // Generic print setup dialog
405 // ----------------------------------------------------------------------------
406
407 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintData* data):
408 wxDialog(parent, -1, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL)
409 {
410 Init(data);
411 }
412
413 void wxGenericPrintSetupDialog::Init(wxPrintData* data)
414 {
415 if ( data )
416 m_printData = *data;
417
418 int staticBoxWidth = 300;
419
420 (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(10, 10), wxSize(staticBoxWidth, 60) );
421
422 int xPos = 20;
423 int yPos = 30;
424 m_paperTypeChoice = CreatePaperTypeChoice(&xPos, &yPos);
425
426 wxString *choices = new wxString[2];
427 choices[0] = _("Portrait");
428 choices[1] = _("Landscape");
429
430 m_orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"),
431 wxPoint(10, 80), wxSize(-1, -1), 2, choices, 1, wxRA_VERTICAL );
432 m_orientationRadioBox->SetSelection(0);
433
434 (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Options"), wxPoint(10, 130), wxSize(staticBoxWidth, 50) );
435
436 int colourYPos = 145;
437
438 #ifdef __WXMOTIF__
439 colourYPos = 150;
440 #endif
441
442 m_colourCheckBox = new wxCheckBox(this, wxPRINTID_PRINTCOLOUR, _("Print in colour"), wxPoint(15, colourYPos));
443
444 (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Print spooling"), wxPoint(330, 10), wxSize(200,170) );
445
446 (void) new wxStaticText(this, wxPRINTID_STATIC, _("Printer command:"), wxPoint(340, 30));
447
448 m_printerCommandText = new wxTextCtrl(this, wxPRINTID_COMMAND, wxT(""), wxPoint(360, 55), wxSize(150, -1));
449
450 (void) new wxStaticText(this, wxPRINTID_STATIC, _("Printer options:"), wxPoint(340, 110));
451
452 m_printerOptionsText = new wxTextCtrl(this, wxPRINTID_OPTIONS, wxT(""), wxPoint(360, 135), wxSize(150, -1));
453
454 wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(130, 200), wxSize(80, -1));
455 (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(320, 200), wxSize(80, -1));
456
457 okButton->SetDefault();
458 okButton->SetFocus();
459
460 Fit();
461 Centre(wxBOTH);
462
463 InitDialog();
464 delete[] choices;
465 }
466
467 wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
468 {
469 }
470
471 bool wxGenericPrintSetupDialog::TransferDataToWindow()
472 {
473 if (m_printerCommandText && m_printData.GetPrinterCommand())
474 m_printerCommandText->SetValue(m_printData.GetPrinterCommand());
475 if (m_printerOptionsText && m_printData.GetPrinterOptions())
476 m_printerOptionsText->SetValue(m_printData.GetPrinterOptions());
477 if (m_colourCheckBox)
478 m_colourCheckBox->SetValue(m_printData.GetColour());
479
480 if (m_orientationRadioBox)
481 {
482 if (m_printData.GetOrientation() == wxPORTRAIT)
483 m_orientationRadioBox->SetSelection(0);
484 else
485 m_orientationRadioBox->SetSelection(1);
486 }
487 return TRUE;
488 }
489
490 bool wxGenericPrintSetupDialog::TransferDataFromWindow()
491 {
492 if (m_printerCommandText)
493 m_printData.SetPrinterCommand(m_printerCommandText->GetValue());
494 if (m_printerOptionsText)
495 m_printData.SetPrinterOptions(m_printerOptionsText->GetValue());
496 if (m_colourCheckBox)
497 m_printData.SetColour(m_colourCheckBox->GetValue());
498 if (m_orientationRadioBox)
499 {
500 int sel = m_orientationRadioBox->GetSelection();
501 if (sel == 0)
502 m_printData.SetOrientation(wxPORTRAIT);
503 else
504 m_printData.SetOrientation(wxLANDSCAPE);
505 }
506 if (m_paperTypeChoice)
507 {
508 int selectedItem = m_paperTypeChoice->GetSelection();
509 if (selectedItem != -1)
510 {
511 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(selectedItem);
512 if (paper != NULL)
513 m_printData.SetPaperId( paper->GetId());
514 }
515 }
516
517 return TRUE;
518 }
519
520 wxComboBox *wxGenericPrintSetupDialog::CreatePaperTypeChoice(int *x, int *y)
521 {
522 /* Should not be necessary
523 if (!wxThePrintPaperDatabase)
524 {
525 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
526 wxThePrintPaperDatabase->CreateDatabase();
527 }
528 */
529 size_t n = wxThePrintPaperDatabase->GetCount();
530 wxString *choices = new wxString [n];
531 size_t sel = 0;
532
533 for (size_t i = 0; i < n; i++)
534 {
535 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
536 choices[i] = paper->GetName();
537 if (m_printData.GetPaperId() == paper->GetId())
538 sel = i;
539 }
540
541 int width = 250;
542
543 wxComboBox *choice = new wxComboBox( this,
544 wxPRINTID_PAPERSIZE,
545 _("Paper Size"),
546 wxPoint(*x, *y),
547 wxSize(width, -1),
548 n, choices );
549
550 // SetFont(thisFont);
551
552 delete[] choices;
553
554 choice->SetSelection(sel);
555 return choice;
556 }
557 #endif // wxUSE_POSTSCRIPT
558
559 // ----------------------------------------------------------------------------
560 // Generic page setup dialog
561 // ----------------------------------------------------------------------------
562
563 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent& WXUNUSED(event))
564 {
565 // We no longer query GetPrintMode, so we can eliminate the need
566 // to call SetPrintMode.
567 // This has the limitation that we can't explicitly call the PostScript
568 // print setup dialog from the generic Page Setup dialog under Windows,
569 // but since this choice would only happen when trying to do PostScript
570 // printing under Windows (and only in 16-bit Windows which
571 // doesn't have a Windows-specific page setup dialog) it's worth it.
572
573 // First save the current settings, so the wxPrintData object is up to date.
574 TransferDataFromWindow();
575
576 // Transfer the current print settings from this dialog to the page setup dialog.
577 wxPrintDialogData data;
578 data = GetPageSetupData().GetPrintData();
579 data.SetSetupDialog(TRUE);
580 wxPrintDialog *printDialog = new wxPrintDialog(this, & data);
581 printDialog->ShowModal();
582
583 // Transfer the page setup print settings from the page dialog to this dialog again, in case
584 // the page setup dialog changed something.
585 GetPageSetupData().GetPrintData() = printDialog->GetPrintDialogData().GetPrintData();
586 GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData
587
588 printDialog->Destroy();
589
590 // Now update the dialog in case the page setup dialog changed some of our settings.
591 TransferDataToWindow();
592 }
593
594 wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow *parent,
595 wxPageSetupData* data)
596 : wxDialog( parent,
597 -1,
598 _("Page Setup"),
599 wxPoint(0, 0),
600 wxSize(600, 600),
601 wxDIALOG_MODAL|wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL )
602 {
603 if (data)
604 m_pageData = *data;
605
606 int textWidth = 80;
607
608 wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
609
610 // 1) top
611 wxStaticBoxSizer *topsizer = new wxStaticBoxSizer(
612 new wxStaticBox(this,wxPRINTID_STATIC, _("Paper size")), wxHORIZONTAL );
613
614 size_t n = wxThePrintPaperDatabase->GetCount();
615 wxString *choices = new wxString [n];
616
617 for (size_t i = 0; i < n; i++)
618 {
619 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
620 choices[i] = paper->GetName();
621 }
622
623 m_paperTypeChoice = new wxComboBox( this,
624 wxPRINTID_PAPERSIZE,
625 _("Paper Size"),
626 wxDefaultPosition,
627 wxSize(300, -1),
628 n, choices );
629 topsizer->Add( m_paperTypeChoice, 1, wxEXPAND|wxALL, 5 );
630 // m_paperTypeChoice->SetSelection(sel);
631
632 mainsizer->Add( topsizer, 0, wxTOP|wxLEFT|wxRIGHT | wxEXPAND, 10 );
633
634 // 2) middle sizer with radio box
635
636 wxString *choices2 = new wxString[2];
637 choices2[0] = _("Portrait");
638 choices2[1] = _("Landscape");
639 m_orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"),
640 wxDefaultPosition, wxDefaultSize, 2, choices2, 2);
641 m_orientationRadioBox->SetSelection(0);
642
643 mainsizer->Add( m_orientationRadioBox, 0, wxTOP|wxLEFT|wxRIGHT, 10 );
644
645 // 3) margins
646
647 wxBoxSizer *table = new wxBoxSizer( wxHORIZONTAL );
648
649 wxBoxSizer *column1 = new wxBoxSizer( wxVERTICAL );
650 column1->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Left margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 );
651 column1->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Top margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 );
652 table->Add( column1, 0, wxALL | wxEXPAND, 5 );
653
654 wxBoxSizer *column2 = new wxBoxSizer( wxVERTICAL );
655 m_marginLeftText = new wxTextCtrl(this, wxPRINTID_LEFTMARGIN, wxT(""), wxDefaultPosition, wxSize(textWidth, -1));
656 m_marginTopText = new wxTextCtrl(this, wxPRINTID_TOPMARGIN, wxT(""), wxDefaultPosition, wxSize(textWidth, -1));
657 column2->Add( m_marginLeftText, 1, wxALL, 5 );
658 column2->Add( m_marginTopText, 1, wxALL, 5 );
659 table->Add( column2, 0, wxRIGHT|wxTOP|wxBOTTOM | wxEXPAND, 5 );
660
661 wxBoxSizer *column3 = new wxBoxSizer( wxVERTICAL );
662 column3->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Right margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 );
663 column3->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Bottom margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 );
664 table->Add( column3, 0, wxALL | wxEXPAND, 5 );
665
666 wxBoxSizer *column4 = new wxBoxSizer( wxVERTICAL );
667 m_marginRightText = new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN, wxT(""), wxDefaultPosition, wxSize(textWidth, -1));
668 m_marginBottomText = new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN, wxT(""), wxDefaultPosition, wxSize(textWidth, -1));
669 column4->Add( m_marginRightText, 1, wxALL, 5 );
670 column4->Add( m_marginBottomText, 1, wxALL, 5 );
671 table->Add( column4, 0, wxRIGHT|wxTOP|wxBOTTOM | wxEXPAND, 5 );
672
673 mainsizer->Add( table, 0 );
674
675 #if wxUSE_STATLINE
676 // 5) static line
677 mainsizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
678 #endif
679
680 // 6) buttons
681
682 wxSizer* buttonsizer = CreateButtonSizer( wxOK|wxCANCEL);
683 m_printerButton = new wxButton(this, wxPRINTID_SETUP, _("Printer...") );
684 buttonsizer->Add( m_printerButton, 0, wxLEFT|wxRIGHT, 10 );
685 if ( !m_pageData.GetEnablePrinter() )
686 m_printerButton->Enable(FALSE);
687 // if (m_printData.GetEnableHelp())
688 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), -1, -1, buttonWidth, buttonHeight);
689 mainsizer->Add( buttonsizer, 0, wxCENTER|wxALL, 10 );
690
691
692 SetAutoLayout( TRUE );
693 SetSizer( mainsizer );
694
695 mainsizer->Fit( this );
696 Centre(wxBOTH);
697
698 InitDialog();
699
700 delete[] choices;
701 delete [] choices2;
702 }
703
704 wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
705 {
706 }
707
708 static inline wxString IntToString( long value )
709 {
710 return wxString::Format(wxT("%ld"), value);
711 }
712
713 bool wxGenericPageSetupDialog::TransferDataToWindow()
714 {
715 if (m_marginLeftText)
716 m_marginLeftText->SetValue(IntToString(m_pageData.GetMarginTopLeft().x));
717 if (m_marginTopText)
718 m_marginTopText->SetValue(IntToString(m_pageData.GetMarginTopLeft().y));
719 if (m_marginRightText)
720 m_marginRightText->SetValue(IntToString(m_pageData.GetMarginBottomRight().x));
721 if (m_marginBottomText)
722 m_marginBottomText->SetValue(IntToString(m_pageData.GetMarginBottomRight().y));
723
724 if (m_orientationRadioBox)
725 {
726 if (m_pageData.GetPrintData().GetOrientation() == wxPORTRAIT)
727 m_orientationRadioBox->SetSelection(0);
728 else
729 m_orientationRadioBox->SetSelection(1);
730 }
731
732 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
733 // failing that, the id in the wxPrintData object.
734
735 wxPrintPaperType* type = wxThePrintPaperDatabase->FindPaperType(
736 wxSize(m_pageData.GetPaperSize().x * 10, m_pageData.GetPaperSize().y * 10));
737
738 if (!type && m_pageData.GetPrintData().GetPaperId() != wxPAPER_NONE)
739 type = wxThePrintPaperDatabase->FindPaperType(m_pageData.GetPrintData().GetPaperId());
740
741 if (type)
742 {
743 m_paperTypeChoice->SetStringSelection(type->GetName());
744 }
745
746 return TRUE;
747 }
748
749 bool wxGenericPageSetupDialog::TransferDataFromWindow()
750 {
751 if (m_marginLeftText && m_marginTopText)
752 {
753 int left = wxAtoi( m_marginLeftText->GetValue().c_str() );
754 int top = wxAtoi( m_marginTopText->GetValue().c_str() );
755 m_pageData.SetMarginTopLeft( wxPoint(left,top) );
756 }
757 if (m_marginRightText && m_marginBottomText)
758 {
759 int right = wxAtoi( m_marginRightText->GetValue().c_str() );
760 int bottom = wxAtoi( m_marginBottomText->GetValue().c_str() );
761 m_pageData.SetMarginBottomRight( wxPoint(right,bottom) );
762 }
763
764 if (m_orientationRadioBox)
765 {
766 int sel = m_orientationRadioBox->GetSelection();
767 if (sel == 0)
768 {
769 m_pageData.GetPrintData().SetOrientation(wxPORTRAIT);
770 }
771 else
772 {
773 m_pageData.GetPrintData().SetOrientation(wxLANDSCAPE);
774 }
775 }
776
777 if (m_paperTypeChoice)
778 {
779 int selectedItem = m_paperTypeChoice->GetSelection();
780 if (selectedItem != -1)
781 {
782 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(selectedItem);
783 if ( paper )
784 {
785 m_pageData.SetPaperSize(wxSize(paper->GetWidth()/10, paper->GetHeight()/10));
786 m_pageData.GetPrintData().SetPaperId(paper->GetId());
787 }
788 }
789 }
790
791 return TRUE;
792 }
793
794 wxComboBox *wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x, int *y)
795 {
796 /*
797 if (!wxThePrintPaperDatabase)
798 {
799 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
800 wxThePrintPaperDatabase->CreateDatabase();
801 }
802 */
803
804 size_t n = wxThePrintPaperDatabase->GetCount();
805 wxString *choices = new wxString [n];
806
807 for (size_t i = 0; i < n; i++)
808 {
809 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
810 choices[i] = paper->GetName();
811 }
812
813 (void) new wxStaticText(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(*x, *y));
814 *y += 25;
815
816 wxComboBox *choice = new wxComboBox( this,
817 wxPRINTID_PAPERSIZE,
818 _("Paper Size"),
819 wxPoint(*x, *y),
820 wxSize(300, -1),
821 n, choices );
822 *y += 35;
823 delete[] choices;
824
825 // choice->SetSelection(sel);
826 return choice;
827 }
828
829 #endif
830