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