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