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