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