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