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