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