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