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