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