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