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