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