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