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