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