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