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