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