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