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