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