]> git.saurik.com Git - wxWidgets.git/blame - src/generic/prntdlgg.cpp
CW Win32 and Mac adaptions
[wxWidgets.git] / src / generic / prntdlgg.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: prntdlgg.cpp
3// Purpose: Generic print dialogs
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "prntdlgg.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#include "wx/defs.h"
24
c801d85f
KB
25#ifndef WX_PRECOMP
26#include "wx/utils.h"
27#include "wx/dc.h"
28#include "wx/app.h"
29#include "wx/frame.h"
30#include "wx/stattext.h"
b527aac5 31#include "wx/statbox.h"
c801d85f
KB
32#include "wx/button.h"
33#include "wx/checkbox.h"
34#include "wx/textctrl.h"
35#include "wx/radiobox.h"
36#include "wx/filedlg.h"
37#include "wx/choice.h"
1a5a8367 38#include <wx/intl.h>
c801d85f
KB
39#endif
40
41#include "wx/generic/prntdlgg.h"
42#include "wx/printdlg.h"
43
44#include <stdlib.h>
45#include <string.h>
46
47#if !USE_SHARED_LIBRARY
48IMPLEMENT_CLASS(wxGenericPrintDialog, wxDialog)
49IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog)
50IMPLEMENT_CLASS(wxGenericPageSetupDialog, wxDialog)
51
52BEGIN_EVENT_TABLE(wxGenericPrintDialog, wxDialog)
53 EVT_BUTTON(wxID_OK, wxGenericPrintDialog::OnOK)
54 EVT_BUTTON(wxPRINTID_SETUP, wxGenericPrintDialog::OnSetup)
55 EVT_RADIOBOX(wxPRINTID_RANGE, wxGenericPrintDialog::OnRange)
56END_EVENT_TABLE()
57
58BEGIN_EVENT_TABLE(wxGenericPageSetupDialog, wxDialog)
59 EVT_BUTTON(wxPRINTID_SETUP, wxGenericPageSetupDialog::OnPrinter)
60END_EVENT_TABLE()
61#endif
62
63extern wxPrintPaperDatabase *wxThePrintPaperDatabase;
64
65/*
66 * Generic print dialog for non-Windows printing use.
67 */
68
69
70wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent, wxPrintData* data):
1a5a8367 71 wxDialog(parent, -1, _("Print"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
c801d85f
KB
72{
73 if ( data )
74 printData = *data;
64a14515 75
1ecc4d80 76 (void)new wxStaticBox( this, -1, _( "Printer options" ), wxPoint( 5, 5), wxSize( 300, 60 ) );
c801d85f 77
1ecc4d80
RR
78 printToFileCheckBox = new wxCheckBox(this, wxPRINTID_PRINTTOFILE, _("Print to File"), wxPoint(20, 25) );
79
80 setupButton = new wxButton(this, wxPRINTID_SETUP, _("Setup..."), wxPoint(160, 25), wxSize(100, -1));
81
7ba2eb42 82 wxString *choices = new wxString[2];
1a5a8367
DP
83 choices[0] = _("All");
84 choices[1] = _("Pages");
86b29a61
RR
85
86 fromText = (wxTextCtrl*)NULL;
87
64a14515
KB
88 if(printData.GetFromPage() != 0)
89 {
90 rangeRadioBox = new wxRadioBox(this, wxPRINTID_RANGE, _("Print Range"),
1ecc4d80 91 wxPoint(5, 80), wxSize(-1, -1), 2, choices, 1, wxRA_VERTICAL);
64a14515
KB
92 rangeRadioBox->SetSelection(1);
93 }
94
64a14515
KB
95 if(printData.GetFromPage() != 0)
96 {
1ecc4d80 97 (void) new wxStaticText(this, wxPRINTID_STATIC, _("From:"), wxPoint(5, 135));
64a14515 98
1ecc4d80 99 fromText = new wxTextCtrl(this, wxPRINTID_FROM, "", wxPoint(45, 130), wxSize(40, -1));
64a14515 100
1ecc4d80 101 (void) new wxStaticText(this, wxPRINTID_STATIC, _("To:"), wxPoint(100, 135));
64a14515 102
1ecc4d80 103 toText = new wxTextCtrl(this, wxPRINTID_TO, "", wxPoint(133, 130), wxSize(40, -1));
64a14515
KB
104 }
105
1ecc4d80 106 (void) new wxStaticText(this, wxPRINTID_STATIC, _("Copies:"), wxPoint(200, 135));
c801d85f 107
1ecc4d80 108 noCopiesText = new wxTextCtrl(this, wxPRINTID_COPIES, "", wxPoint(252, 130), wxSize(40, -1));
c801d85f 109
1ecc4d80
RR
110 wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(40, 180), wxSize(100, -1));
111 (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(180, 180), wxSize(100, -1));
c801d85f 112
1ecc4d80
RR
113 okButton->SetDefault();
114 okButton->SetFocus();
c801d85f
KB
115 Fit();
116 Centre(wxBOTH);
117
118 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
119 InitDialog();
7ba2eb42 120 delete[] choices;
c801d85f
KB
121}
122
123int wxGenericPrintDialog::ShowModal(void)
124{
125 if ( printData.GetSetupDialog() )
126 {
127 wxGenericPrintSetupDialog *genericPrintSetupDialog =
128 new wxGenericPrintSetupDialog(GetParent(), wxThePrintSetupData);
129 int ret = genericPrintSetupDialog->ShowModal();
130 if ( ret != wxID_CANCEL )
131 {
132 *wxThePrintSetupData = genericPrintSetupDialog->printData;
133 }
134 genericPrintSetupDialog->Close(TRUE);
135 return ret;
136 }
137 else
138 {
139 return wxDialog::ShowModal();
140 }
141}
142
143wxGenericPrintDialog::~wxGenericPrintDialog(void)
144{
145}
146
147void wxGenericPrintDialog::OnOK(wxCommandEvent& WXUNUSED(event))
148{
149 TransferDataFromWindow();
150
151 // There are some interactions between the global setup data
152 // and the standard print dialog. The global printing 'mode'
153 // is determined by whether the user checks Print to file
154 // or not.
155 if (printData.GetPrintToFile())
156 {
157 wxThePrintSetupData->SetPrinterMode(PS_FILE);
158
ba681060
VZ
159 wxString f = wxFileSelector(_("PostScript file"),
160 wxPathOnly(wxThePrintSetupData->GetPrinterFile()),
161 wxFileNameFromPath(wxThePrintSetupData->GetPrinterFile()),
162 "ps", "*.ps", 0, this);
163 if ( f.IsEmpty() )
164 return;
165
166 wxThePrintSetupData->SetPrinterFile(f);
c801d85f
KB
167 }
168 else
169 wxThePrintSetupData->SetPrinterMode(PS_PRINTER);
170
171 EndModal(wxID_OK);
172}
173
174void wxGenericPrintDialog::OnRange(wxCommandEvent& event)
175{
86b29a61
RR
176 if (!fromText) return;
177
f04371f0 178 if (event.GetInt() == 0)
c801d85f
KB
179 {
180 fromText->Enable(FALSE);
181 toText->Enable(FALSE);
182 }
f04371f0 183 else if (event.GetInt() == 1)
c801d85f
KB
184 {
185 fromText->Enable(TRUE);
186 toText->Enable(TRUE);
187 }
188}
189
190void wxGenericPrintDialog::OnSetup(wxCommandEvent& WXUNUSED(event))
191{
192 wxGenericPrintSetupDialog *genericPrintSetupDialog =
193 new wxGenericPrintSetupDialog(this, wxThePrintSetupData);
194 int ret = genericPrintSetupDialog->ShowModal();
195 if ( ret != wxID_CANCEL )
196 {
197 *wxThePrintSetupData = genericPrintSetupDialog->printData;
198 printData.SetOrientation(wxThePrintSetupData->GetPrinterOrientation());
199 }
200
201 genericPrintSetupDialog->Close(TRUE);
202}
203
204bool wxGenericPrintDialog::TransferDataToWindow(void)
205{
64a14515
KB
206 char buf[10];
207
208 if(printData.GetFromPage() != 0)
209 {
210 if (printData.GetEnablePageNumbers())
211 {
212 fromText->Enable(TRUE);
213 toText->Enable(TRUE);
214
215 sprintf(buf, "%d", printData.GetFromPage());
216 fromText->SetValue(buf);
db828ab4 217 sprintf(buf, "%d", printData.GetToPage());
64a14515
KB
218 toText->SetValue(buf);
219
220 if (printData.GetAllPages())
221 rangeRadioBox->SetSelection(0);
222 else
223 rangeRadioBox->SetSelection(1);
224 }
225 else
226 {
227 fromText->Enable(FALSE);
228 toText->Enable(FALSE);
229 rangeRadioBox->SetSelection(0);
230 rangeRadioBox->wxRadioBox::Enable(1, FALSE);
231 }
232 }
c801d85f
KB
233 sprintf(buf, "%d", printData.GetNoCopies());
234 noCopiesText->SetValue(buf);
235
236 printToFileCheckBox->SetValue(printData.GetPrintToFile());
237 printToFileCheckBox->Enable(printData.GetEnablePrintToFile());
238 return TRUE;
239}
240
241bool wxGenericPrintDialog::TransferDataFromWindow(void)
242{
64a14515
KB
243 if(printData.GetFromPage() != -1)
244 {
245 if (printData.GetEnablePageNumbers())
246 {
247 printData.SetFromPage(atoi(fromText->GetValue()));
248 printData.SetToPage(atoi(toText->GetValue()));
249 }
250 if (rangeRadioBox->GetSelection() == 0)
251 printData.SetAllPages(TRUE);
252 else
253 printData.SetAllPages(FALSE);
254 }
255 else
256 { // continuous printing
257 printData.SetFromPage(1);
258 printData.SetToPage(32000);
259 }
260 printData.SetNoCopies(atoi(noCopiesText->GetValue()));
261 printData.SetPrintToFile(printToFileCheckBox->GetValue());
c801d85f
KB
262
263 return TRUE;
264}
265
266wxDC *wxGenericPrintDialog::GetPrintDC(void)
267{
c67daf87 268 return new wxPostScriptDC(wxThePrintSetupData->GetPrinterFile(), FALSE, (wxWindow *) NULL);
c801d85f
KB
269}
270
271/*
272 * Generic print setup dialog
273 */
274
275wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintSetupData* data):
1a5a8367 276 wxDialog(parent, -1, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
c801d85f
KB
277{
278 if ( data )
279 printData = *data;
280
b527aac5 281 (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(10, 10), wxSize(200,60) );
c801d85f 282
b527aac5
RR
283 int xPos = 20;
284 int yPos = 30;
c801d85f
KB
285 paperTypeChoice = CreatePaperTypeChoice(&xPos, &yPos);
286
7ba2eb42 287 wxString *choices = new wxString[2];
1a5a8367
DP
288 choices[0] = _("Portrait");
289 choices[1] = _("Landscape");
c801d85f 290
1a5a8367 291 orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"),
1ecc4d80 292 wxPoint(10, 80), wxSize(-1, -1), 2, choices, 1, wxRA_VERTICAL );
c801d85f
KB
293 orientationRadioBox->SetSelection(0);
294
b527aac5 295 (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Options"), wxPoint(10, 130), wxSize(200,50) );
9838df2c
JS
296
297 int colourXPos = 145;
298
299#ifdef __WXMOTIF__
300 colourXPos = 150;
301#endif
b527aac5 302
9838df2c 303 colourCheckBox = new wxCheckBox(this, wxPRINTID_PRINTCOLOUR, _("Print in colour"), wxPoint(15, colourXPos));
b527aac5 304
c801d85f 305
b527aac5
RR
306 (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Print spooling"), wxPoint(230, 10), wxSize(200,170) );
307
308 (void) new wxStaticText(this, wxPRINTID_STATIC, _("Printer command:"), wxPoint(240, 30));
c801d85f 309
b527aac5 310 printerCommandText = new wxTextCtrl(this, wxPRINTID_COMMAND, "", wxPoint(260, 55), wxSize(150, -1));
c801d85f 311
b527aac5 312 (void) new wxStaticText(this, wxPRINTID_STATIC, _("Printer options:"), wxPoint(240, 110));
c801d85f 313
b527aac5 314 printerOptionsText = new wxTextCtrl(this, wxPRINTID_OPTIONS, "", wxPoint(260, 135), wxSize(150, -1));
c801d85f 315
1ecc4d80
RR
316 wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(80, 200), wxSize(100, -1));
317 (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(270, 200), wxSize(100, -1));
c801d85f 318
b527aac5
RR
319 okButton->SetDefault();
320 okButton->SetFocus();
c801d85f
KB
321
322 Fit();
323 Centre(wxBOTH);
324
325 InitDialog();
7ba2eb42 326 delete[] choices;
c801d85f
KB
327}
328
329wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog(void)
330{
331}
332
333bool wxGenericPrintSetupDialog::TransferDataToWindow(void)
334{
335 if (printerCommandText && printData.GetPrinterCommand())
336 printerCommandText->SetValue(printData.GetPrinterCommand());
337 if (printerOptionsText && printData.GetPrinterOptions())
338 printerOptionsText->SetValue(printData.GetPrinterOptions());
339 if (colourCheckBox)
340 colourCheckBox->SetValue(printData.GetColour());
341
342 if (orientationRadioBox)
343 {
344 if (printData.GetPrinterOrientation() == PS_PORTRAIT)
345 orientationRadioBox->SetSelection(0);
346 else
347 orientationRadioBox->SetSelection(1);
348 }
349 return TRUE;
350}
351
352bool wxGenericPrintSetupDialog::TransferDataFromWindow(void)
353{
354 if (printerCommandText)
355 printData.SetPrinterCommand(WXSTRINGCAST printerCommandText->GetValue());
356 if (printerOptionsText)
357 printData.SetPrinterOptions(WXSTRINGCAST printerOptionsText->GetValue());
358 if (colourCheckBox)
359 printData.SetColour(colourCheckBox->GetValue());
360 if (orientationRadioBox)
361 {
362 int sel = orientationRadioBox->GetSelection();
363 if (sel == 0)
364 printData.SetPrinterOrientation(PS_PORTRAIT);
365 else
366 printData.SetPrinterOrientation(PS_LANDSCAPE);
367 }
368 if (paperTypeChoice)
369 {
370 wxString val(paperTypeChoice->GetStringSelection());
371 if (!val.IsNull() && val != "")
372 printData.SetPaperName((char *)(const char *)val);
373 }
9838df2c 374 *wxThePrintSetupData = GetPrintData();
c801d85f
KB
375 return TRUE;
376}
377
378wxChoice *wxGenericPrintSetupDialog::CreatePaperTypeChoice(int *x, int *y)
379{
380 if (!wxThePrintPaperDatabase)
381 {
382 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
383 wxThePrintPaperDatabase->CreateDatabase();
384 }
385 int n = wxThePrintPaperDatabase->Number();
386 wxString *choices = new wxString [n];
387 int sel = 0;
388 int i;
389 for (i = 0; i < n; i++)
390 {
391 wxPrintPaperType *paper = (wxPrintPaperType *)wxThePrintPaperDatabase->Nth(i)->Data();
392 choices[i] = paper->pageName;
393 if (printData.GetPaperName() && choices[i] == printData.GetPaperName())
394 sel = i;
395 }
396
9838df2c
JS
397 int width = 170;
398#ifdef __WXMOTIF__
399 width = 150;
400#endif
401
402 wxChoice *choice = new wxChoice(this, wxPRINTID_PAPERSIZE, wxPoint(*x, *y), wxSize(width, -1), n,
c801d85f 403 choices);
b527aac5 404
c801d85f
KB
405 delete[] choices;
406
407 choice->SetSelection(sel);
408 return choice;
409}
410
411/*
412 * Generic page setup dialog
413 */
414
415void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent& WXUNUSED(event))
416{
9838df2c
JS
417 // We no longer query GetPrintMode, so we can eliminate the need
418 // to call SetPrintMode.
419 // This has the limitation that we can't explicitly call the PostScript
420 // print setup dialog from the generic Page Setup dialog under Windows,
421 // but since this choice would only happen when trying to do PostScript
422 // printing under Windows (and only in 16-bit Windows which
423 // doesn't have a Windows-specific page setup dialog) it's worth it.
424
425 wxPrintData data;
426 data.SetSetupDialog(TRUE);
427 wxPrintDialog *printDialog = new wxPrintDialog(this, & data);
ba681060 428 printDialog->ShowModal();
9838df2c
JS
429
430 printDialog->Destroy();
431
432#if 0
c801d85f
KB
433 if (wxTheApp->GetPrintMode() == wxPRINT_POSTSCRIPT)
434 {
435 wxGenericPrintSetupDialog *genericPrintSetupDialog =
436 new wxGenericPrintSetupDialog(this, wxThePrintSetupData);
437 int ret = genericPrintSetupDialog->ShowModal();
438 if (ret == wxID_OK)
439 *wxThePrintSetupData = genericPrintSetupDialog->GetPrintData();
440
441 genericPrintSetupDialog->Close(TRUE);
442 }
2049ba38 443#ifdef __WXMSW__
c801d85f
KB
444 else
445 {
446 wxPrintData data;
447 data.SetSetupDialog(TRUE);
448 wxPrintDialog printDialog(this, & data);
9838df2c 449 printDialog.ShowModal();
c801d85f
KB
450 }
451#endif
9838df2c
JS
452#endif
453 // 0
c801d85f
KB
454}
455
456wxGenericPageSetupDialog::wxGenericPageSetupDialog(wxWindow *parent, wxPageSetupData* data):
1a5a8367 457 wxDialog(parent, -1, _("Page Setup"), wxPoint(0, 0), wxSize(600, 600), wxDIALOG_MODAL|wxDEFAULT_DIALOG_STYLE)
c801d85f
KB
458{
459 if ( data )
460 pageData = *data;
461
462 int buttonWidth = 75;
463 int buttonHeight = 25;
464 int spacing = 5;
9838df2c
JS
465#ifdef __WXMOTIF__
466 spacing = 15;
467#endif
468
c801d85f
KB
469 int yPos = 5;
470 int xPos = 5;
471
1a5a8367
DP
472 wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(5, yPos), wxSize(buttonWidth, buttonHeight));
473 (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(buttonWidth + 5 + spacing, yPos), wxSize(buttonWidth, buttonHeight));
c801d85f 474
1a5a8367 475 printerButton = new wxButton(this, wxPRINTID_SETUP, _("Printer..."), wxPoint(buttonWidth*2 + 5 + 2*spacing, yPos), wxSize(buttonWidth, buttonHeight));
c801d85f
KB
476
477 if ( !pageData.GetEnablePrinter() )
478 printerButton->Enable(FALSE);
479
480// if (printData.GetEnableHelp())
1a5a8367 481// wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), -1, -1, buttonWidth, buttonHeight);
c801d85f
KB
482
483 okButton->SetDefault();
484 okButton->SetFocus();
485
486 xPos = 5;
487 yPos += 35;
488
9838df2c
JS
489#ifdef __WXMOTIF__
490 yPos += 10;
491#endif
492
c801d85f
KB
493 paperTypeChoice = CreatePaperTypeChoice(&xPos, &yPos);
494
495 xPos = 5;
496
55c1b531 497 wxString *choices = new wxString[2];
1a5a8367
DP
498 choices[0] = _("Portrait");
499 choices[1] = _("Landscape");
500 orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"),
c801d85f
KB
501 wxPoint(xPos, yPos), wxSize(-1, -1), 2, choices, 2);
502 orientationRadioBox->SetSelection(0);
503
504 xPos = 5;
505 yPos += 60;
506
507 int staticWidth = 110;
9838df2c
JS
508#ifdef __WXMOTIF__
509 staticWidth += 20;
510#endif
511
c801d85f
KB
512 int textWidth = 60;
513 spacing = 10;
514
1a5a8367 515 (void) new wxStaticText(this, wxPRINTID_STATIC, _("Left margin (mm):"), wxPoint(xPos, yPos));
c801d85f
KB
516 xPos += staticWidth;
517
518 marginLeftText = new wxTextCtrl(this, wxPRINTID_LEFTMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
519 xPos += textWidth + spacing;
520
1a5a8367 521 (void) new wxStaticText(this, wxPRINTID_STATIC, _("Right margin (mm):"), wxPoint(xPos, yPos));
c801d85f
KB
522 xPos += staticWidth;
523
524 marginRightText = new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
525 xPos += textWidth + spacing;
526
527 yPos += 35;
528 xPos = 5;
529
1a5a8367 530 (void) new wxStaticText(this, wxPRINTID_STATIC, _("Top margin (mm):"), wxPoint(xPos, yPos));
c801d85f
KB
531 xPos += staticWidth;
532
533 marginTopText = new wxTextCtrl(this, wxPRINTID_TOPMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
534 xPos += textWidth + spacing;
535
1a5a8367 536 (void) new wxStaticText(this, wxPRINTID_STATIC, _("Bottom margin (mm):"), wxPoint(xPos, yPos));
c801d85f
KB
537 xPos += staticWidth;
538
539 marginBottomText = new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
540
541 Fit();
542 Centre(wxBOTH);
543
544 InitDialog();
55c1b531 545 delete [] choices;
c801d85f
KB
546}
547
548wxGenericPageSetupDialog::~wxGenericPageSetupDialog(void)
549{
550}
551
552bool wxGenericPageSetupDialog::TransferDataToWindow(void)
553{
554 if (marginLeftText)
555 marginLeftText->SetValue(IntToString((int) pageData.GetMarginTopLeft().x));
556 if (marginTopText)
557 marginTopText->SetValue(IntToString((int) pageData.GetMarginTopLeft().y));
558 if (marginRightText)
559 marginRightText->SetValue(IntToString((int) pageData.GetMarginBottomRight().x));
560 if (marginBottomText)
561 marginBottomText->SetValue(IntToString((int) pageData.GetMarginBottomRight().y));
562
563 if (orientationRadioBox)
564 {
565 if (pageData.GetOrientation() == wxPORTRAIT)
566 orientationRadioBox->SetSelection(0);
567 else
568 orientationRadioBox->SetSelection(1);
569 }
570 return TRUE;
571}
572
573bool wxGenericPageSetupDialog::TransferDataFromWindow(void)
574{
575 if (marginLeftText && marginTopText)
576 pageData.SetMarginTopLeft(wxPoint(atoi((const char *)marginLeftText->GetValue()),atoi((const char *)marginTopText->GetValue())));
577 if (marginRightText && marginBottomText)
578 pageData.SetMarginBottomRight(wxPoint(atoi((const char *)marginRightText->GetValue()),atoi((const char *)marginBottomText->GetValue())));
579
580 if (orientationRadioBox)
581 {
582 int sel = orientationRadioBox->GetSelection();
583 if (sel == 0)
584 {
585 wxThePrintSetupData->SetPrinterOrientation(wxPORTRAIT);
586 pageData.SetOrientation(wxPORTRAIT);
587 }
588 else
589 {
590 wxThePrintSetupData->SetPrinterOrientation(wxLANDSCAPE);
591 pageData.SetOrientation(wxLANDSCAPE);
592 }
593 }
594 if (paperTypeChoice)
595 {
596 wxString val(paperTypeChoice->GetStringSelection());
597 if (!val.IsNull() && val != "")
598 {
599 wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType((char*) (const char *)val);
600 if ( paper )
601 {
602 pageData.SetPaperSize(wxPoint(paper->widthMM, paper->heightMM));
603 }
604 }
605 }
9838df2c 606
c801d85f
KB
607 return TRUE;
608}
609
610wxChoice *wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x, int *y)
611{
612 if (!wxThePrintPaperDatabase)
613 {
614 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
615 wxThePrintPaperDatabase->CreateDatabase();
616 }
617 int n = wxThePrintPaperDatabase->Number();
618 wxString *choices = new wxString [n];
619 int sel = 0;
620 int i;
621 for (i = 0; i < n; i++)
622 {
623 wxPrintPaperType *paper = (wxPrintPaperType *)wxThePrintPaperDatabase->Nth(i)->Data();
624 choices[i] = paper->pageName;
625 if (pageData.GetPaperSize().x == paper->widthMM && pageData.GetPaperSize().y == paper->heightMM)
626 sel = i;
627 }
628
1a5a8367 629 (void) new wxStaticText(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(*x, *y));
c801d85f
KB
630 *y += 25;
631
632 wxChoice *choice = new wxChoice(this, wxPRINTID_PAPERSIZE, wxPoint(*x, *y), wxSize(300, -1), n,
633 choices);
634 *y += 35;
635 delete[] choices;
636
637 choice->SetSelection(sel);
638 return choice;
639}
640