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