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