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