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