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