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