]>
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 | |
8826f46f | 9 | // Licence: wxWindows license |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8826f46f VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
c801d85f | 20 | #ifdef __GNUG__ |
8826f46f | 21 | #pragma implementation "prntdlgg.h" |
c801d85f KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
8826f46f | 28 | #pragma hdrstop |
c801d85f KB |
29 | #endif |
30 | ||
31 | #include "wx/defs.h" | |
32 | ||
c801d85f | 33 | #ifndef WX_PRECOMP |
8826f46f VZ |
34 | #include "wx/utils.h" |
35 | #include "wx/dc.h" | |
36 | #include "wx/app.h" | |
37 | #include "wx/frame.h" | |
38 | #include "wx/stattext.h" | |
39 | #include "wx/statbox.h" | |
40 | #include "wx/button.h" | |
41 | #include "wx/checkbox.h" | |
42 | #include "wx/textctrl.h" | |
43 | #include "wx/radiobox.h" | |
44 | #include "wx/filedlg.h" | |
45 | #include "wx/choice.h" | |
46 | #include <wx/intl.h> | |
c801d85f KB |
47 | #endif |
48 | ||
49 | #include "wx/generic/prntdlgg.h" | |
2a47d3c1 JS |
50 | |
51 | #if wxUSE_POSTSCRIPT | |
8826f46f | 52 | #include "wx/generic/dcpsg.h" |
2a47d3c1 JS |
53 | #endif |
54 | ||
c801d85f | 55 | #include "wx/printdlg.h" |
7bcb11d3 | 56 | #include "wx/paper.h" |
c801d85f | 57 | |
2a47d3c1 JS |
58 | // For print paper things |
59 | #include "wx/prntbase.h" | |
60 | ||
c801d85f KB |
61 | #include <stdlib.h> |
62 | #include <string.h> | |
63 | ||
8826f46f VZ |
64 | // ---------------------------------------------------------------------------- |
65 | // wxWin macros | |
66 | // ---------------------------------------------------------------------------- | |
67 | ||
2a47d3c1 JS |
68 | #if wxUSE_POSTSCRIPT |
69 | ||
c801d85f | 70 | #if !USE_SHARED_LIBRARY |
8826f46f VZ |
71 | IMPLEMENT_CLASS(wxGenericPrintDialog, wxDialog) |
72 | IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog) | |
73 | IMPLEMENT_CLASS(wxGenericPageSetupDialog, wxDialog) | |
74 | ||
75 | BEGIN_EVENT_TABLE(wxGenericPrintDialog, wxDialog) | |
76 | EVT_BUTTON(wxID_OK, wxGenericPrintDialog::OnOK) | |
77 | EVT_BUTTON(wxPRINTID_SETUP, wxGenericPrintDialog::OnSetup) | |
78 | EVT_RADIOBOX(wxPRINTID_RANGE, wxGenericPrintDialog::OnRange) | |
79 | END_EVENT_TABLE() | |
80 | ||
81 | BEGIN_EVENT_TABLE(wxGenericPageSetupDialog, wxDialog) | |
82 | EVT_BUTTON(wxPRINTID_SETUP, wxGenericPageSetupDialog::OnPrinter) | |
83 | END_EVENT_TABLE() | |
84 | #endif // USE_SHARED_LIBRARY | |
85 | ||
86 | // ---------------------------------------------------------------------------- | |
87 | // global vars | |
88 | // ---------------------------------------------------------------------------- | |
c801d85f KB |
89 | |
90 | extern wxPrintPaperDatabase *wxThePrintPaperDatabase; | |
91 | ||
8826f46f VZ |
92 | // ============================================================================ |
93 | // implementation | |
94 | // ============================================================================ | |
95 | ||
96 | // ---------------------------------------------------------------------------- | |
97 | // Generic print dialog for non-Windows printing use. | |
98 | // ---------------------------------------------------------------------------- | |
99 | ||
100 | wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent, | |
101 | wxPrintDialogData* data) | |
102 | : wxDialog(parent, -1, _("Print"), | |
103 | wxPoint(0, 0), wxSize(600, 600), | |
104 | wxDEFAULT_DIALOG_STYLE | | |
105 | wxDIALOG_MODAL | | |
106 | wxTAB_TRAVERSAL) | |
107 | { | |
108 | if ( data ) | |
109 | m_printDialogData = *data; | |
c801d85f | 110 | |
8826f46f VZ |
111 | Init(parent); |
112 | } | |
c801d85f | 113 | |
8826f46f VZ |
114 | wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent, |
115 | wxPrintData* data) | |
cb230244 JS |
116 | : wxDialog(parent, -1, _("Print"), |
117 | wxPoint(0, 0), wxSize(600, 600), | |
118 | wxDEFAULT_DIALOG_STYLE | | |
119 | wxDIALOG_MODAL | | |
120 | wxTAB_TRAVERSAL) | |
c801d85f | 121 | { |
7bcb11d3 JS |
122 | if ( data ) |
123 | m_printDialogData = *data; | |
8826f46f VZ |
124 | |
125 | Init(parent); | |
126 | } | |
127 | ||
128 | void wxGenericPrintDialog::Init(wxWindow *parent) | |
129 | { | |
cb230244 JS |
130 | // wxDialog::Create(parent, -1, _("Print"), wxPoint(0, 0), wxSize(600, 600), |
131 | // wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL | wxTAB_TRAVERSAL); | |
8826f46f | 132 | |
7bcb11d3 | 133 | (void)new wxStaticBox( this, -1, _( "Printer options" ), wxPoint( 5, 5), wxSize( 300, 60 ) ); |
8826f46f | 134 | |
7bcb11d3 | 135 | m_printToFileCheckBox = new wxCheckBox(this, wxPRINTID_PRINTTOFILE, _("Print to File"), wxPoint(20, 25) ); |
8826f46f | 136 | |
7bcb11d3 | 137 | m_setupButton = new wxButton(this, wxPRINTID_SETUP, _("Setup..."), wxPoint(160, 25), wxSize(100, -1)); |
8826f46f | 138 | |
7bcb11d3 JS |
139 | wxString *choices = new wxString[2]; |
140 | choices[0] = _("All"); | |
141 | choices[1] = _("Pages"); | |
8826f46f | 142 | |
7bcb11d3 | 143 | m_fromText = (wxTextCtrl*)NULL; |
d14612c6 | 144 | m_toText = (wxTextCtrl*)NULL; |
59e2b19f KB |
145 | m_rangeRadioBox = (wxRadioBox *)NULL; |
146 | ||
7bcb11d3 JS |
147 | if (m_printDialogData.GetFromPage() != 0) |
148 | { | |
149 | m_rangeRadioBox = new wxRadioBox(this, wxPRINTID_RANGE, _("Print Range"), | |
8826f46f VZ |
150 | wxPoint(5, 80), wxSize(-1, -1), |
151 | 2, choices, | |
152 | 1, wxRA_VERTICAL); | |
7bcb11d3 JS |
153 | m_rangeRadioBox->SetSelection(1); |
154 | } | |
8826f46f | 155 | |
7bcb11d3 JS |
156 | if(m_printDialogData.GetFromPage() != 0) |
157 | { | |
158 | (void) new wxStaticText(this, wxPRINTID_STATIC, _("From:"), wxPoint(5, 135)); | |
8826f46f | 159 | |
7bcb11d3 | 160 | m_fromText = new wxTextCtrl(this, wxPRINTID_FROM, "", wxPoint(45, 130), wxSize(40, -1)); |
8826f46f | 161 | |
7bcb11d3 | 162 | (void) new wxStaticText(this, wxPRINTID_STATIC, _("To:"), wxPoint(100, 135)); |
8826f46f | 163 | |
7bcb11d3 JS |
164 | m_toText = new wxTextCtrl(this, wxPRINTID_TO, "", wxPoint(133, 130), wxSize(40, -1)); |
165 | } | |
8826f46f | 166 | |
7bcb11d3 | 167 | (void) new wxStaticText(this, wxPRINTID_STATIC, _("Copies:"), wxPoint(200, 135)); |
8826f46f | 168 | |
7bcb11d3 | 169 | m_noCopiesText = new wxTextCtrl(this, wxPRINTID_COPIES, "", wxPoint(252, 130), wxSize(40, -1)); |
8826f46f | 170 | |
7bcb11d3 JS |
171 | wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(40, 180), wxSize(100, -1)); |
172 | (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(180, 180), wxSize(100, -1)); | |
8826f46f | 173 | |
7bcb11d3 JS |
174 | okButton->SetDefault(); |
175 | okButton->SetFocus(); | |
176 | Fit(); | |
177 | Centre(wxBOTH); | |
8826f46f | 178 | |
7bcb11d3 JS |
179 | // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow |
180 | InitDialog(); | |
181 | delete[] choices; | |
c801d85f KB |
182 | } |
183 | ||
7bcb11d3 | 184 | int wxGenericPrintDialog::ShowModal() |
c801d85f | 185 | { |
7bcb11d3 | 186 | if ( m_printDialogData.GetSetupDialog() ) |
c801d85f | 187 | { |
7bcb11d3 JS |
188 | // Make sure wxPrintData object reflects the settings now, in case the setup dialog |
189 | // changes it. In fact there aren't any common settings at | |
190 | // present, but there might be in future. | |
191 | // TransferDataFromWindow(); | |
192 | ||
c801d85f | 193 | wxGenericPrintSetupDialog *genericPrintSetupDialog = |
7bcb11d3 | 194 | new wxGenericPrintSetupDialog(this, & m_printDialogData.GetPrintData()); |
c801d85f KB |
195 | int ret = genericPrintSetupDialog->ShowModal(); |
196 | if ( ret != wxID_CANCEL ) | |
197 | { | |
7bcb11d3 JS |
198 | // Transfer settings to the global object (for compatibility) and to |
199 | // the print dialog's print data. | |
200 | *wxThePrintSetupData = genericPrintSetupDialog->GetPrintData(); | |
201 | m_printDialogData.GetPrintData() = genericPrintSetupDialog->GetPrintData(); | |
c801d85f | 202 | } |
7bcb11d3 JS |
203 | genericPrintSetupDialog->Destroy(); |
204 | ||
205 | // Restore the wxPrintData settings again (uncomment if any settings become common | |
206 | // to both dialogs) | |
207 | // TransferDataToWindow(); | |
208 | ||
c801d85f KB |
209 | return ret; |
210 | } | |
211 | else | |
212 | { | |
213 | return wxDialog::ShowModal(); | |
214 | } | |
215 | } | |
216 | ||
7bcb11d3 | 217 | wxGenericPrintDialog::~wxGenericPrintDialog() |
c801d85f KB |
218 | { |
219 | } | |
220 | ||
221 | void wxGenericPrintDialog::OnOK(wxCommandEvent& WXUNUSED(event)) | |
222 | { | |
7bcb11d3 | 223 | TransferDataFromWindow(); |
8826f46f | 224 | |
7bcb11d3 JS |
225 | // There are some interactions between the global setup data |
226 | // and the standard print dialog. The global printing 'mode' | |
227 | // is determined by whether the user checks Print to file | |
228 | // or not. | |
229 | if (m_printDialogData.GetPrintToFile()) | |
230 | { | |
231 | m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE); | |
232 | wxThePrintSetupData->SetPrinterMode(wxPRINT_MODE_FILE); | |
8826f46f | 233 | |
7bcb11d3 JS |
234 | wxString f = wxFileSelector(_("PostScript file"), |
235 | wxPathOnly(wxThePrintSetupData->GetPrinterFile()), | |
236 | wxFileNameFromPath(wxThePrintSetupData->GetPrinterFile()), | |
87138c52 | 237 | _T("ps"), _T("*.ps"), 0, this); |
7bcb11d3 JS |
238 | if ( f.IsEmpty() ) |
239 | return; | |
8826f46f | 240 | |
7bcb11d3 JS |
241 | m_printDialogData.GetPrintData().SetFilename(f); |
242 | wxThePrintSetupData->SetPrinterFile(f); | |
243 | } | |
244 | else | |
245 | wxThePrintSetupData->SetPrinterMode(wxPRINT_MODE_PRINTER); | |
8826f46f | 246 | |
7bcb11d3 | 247 | EndModal(wxID_OK); |
c801d85f KB |
248 | } |
249 | ||
250 | void wxGenericPrintDialog::OnRange(wxCommandEvent& event) | |
251 | { | |
7bcb11d3 | 252 | if (!m_fromText) return; |
8826f46f | 253 | |
7bcb11d3 JS |
254 | if (event.GetInt() == 0) |
255 | { | |
256 | m_fromText->Enable(FALSE); | |
257 | m_toText->Enable(FALSE); | |
258 | } | |
259 | else if (event.GetInt() == 1) | |
260 | { | |
261 | m_fromText->Enable(TRUE); | |
262 | m_toText->Enable(TRUE); | |
263 | } | |
c801d85f KB |
264 | } |
265 | ||
266 | void wxGenericPrintDialog::OnSetup(wxCommandEvent& WXUNUSED(event)) | |
267 | { | |
7bcb11d3 JS |
268 | wxGenericPrintSetupDialog *genericPrintSetupDialog = |
269 | new wxGenericPrintSetupDialog(this, wxThePrintSetupData); | |
270 | int ret = genericPrintSetupDialog->ShowModal(); | |
271 | if ( ret != wxID_CANCEL ) | |
272 | { | |
273 | *wxThePrintSetupData = genericPrintSetupDialog->GetPrintData(); | |
274 | m_printDialogData = genericPrintSetupDialog->GetPrintData(); | |
275 | } | |
8826f46f | 276 | |
7bcb11d3 | 277 | genericPrintSetupDialog->Close(TRUE); |
c801d85f KB |
278 | } |
279 | ||
7bcb11d3 | 280 | bool wxGenericPrintDialog::TransferDataToWindow() |
c801d85f | 281 | { |
7bcb11d3 | 282 | char buf[10]; |
8826f46f | 283 | |
7bcb11d3 JS |
284 | if(m_printDialogData.GetFromPage() != 0) |
285 | { | |
d14612c6 KB |
286 | if(m_fromText) |
287 | { | |
288 | if (m_printDialogData.GetEnablePageNumbers()) | |
289 | { | |
290 | m_fromText->Enable(TRUE); | |
291 | m_toText->Enable(TRUE); | |
292 | sprintf(buf, "%d", m_printDialogData.GetFromPage()); | |
293 | m_fromText->SetValue(buf); | |
294 | sprintf(buf, "%d", m_printDialogData.GetToPage()); | |
295 | m_toText->SetValue(buf); | |
59e2b19f KB |
296 | if(m_rangeRadioBox) |
297 | if (m_printDialogData.GetAllPages()) | |
298 | m_rangeRadioBox->SetSelection(0); | |
299 | else | |
300 | m_rangeRadioBox->SetSelection(1); | |
d14612c6 KB |
301 | } |
302 | else | |
303 | { | |
304 | m_fromText->Enable(FALSE); | |
305 | m_toText->Enable(FALSE); | |
59e2b19f KB |
306 | if(m_rangeRadioBox) |
307 | { | |
308 | m_rangeRadioBox->SetSelection(0); | |
309 | m_rangeRadioBox->wxRadioBox::Enable(1, FALSE); | |
310 | } | |
d14612c6 KB |
311 | } |
312 | } | |
7bcb11d3 JS |
313 | } |
314 | sprintf(buf, "%d", m_printDialogData.GetNoCopies()); | |
315 | m_noCopiesText->SetValue(buf); | |
8826f46f | 316 | |
7bcb11d3 JS |
317 | m_printToFileCheckBox->SetValue(m_printDialogData.GetPrintToFile()); |
318 | m_printToFileCheckBox->Enable(m_printDialogData.GetEnablePrintToFile()); | |
319 | return TRUE; | |
c801d85f KB |
320 | } |
321 | ||
7bcb11d3 | 322 | bool wxGenericPrintDialog::TransferDataFromWindow() |
c801d85f | 323 | { |
7bcb11d3 JS |
324 | if(m_printDialogData.GetFromPage() != -1) |
325 | { | |
326 | if (m_printDialogData.GetEnablePageNumbers()) | |
327 | { | |
87138c52 OK |
328 | if(m_fromText) m_printDialogData.SetFromPage(wxAtoi(m_fromText->GetValue())); |
329 | if(m_toText) m_printDialogData.SetToPage(wxAtoi(m_toText->GetValue())); | |
7bcb11d3 | 330 | } |
59e2b19f KB |
331 | if(m_rangeRadioBox) |
332 | { | |
333 | if (m_rangeRadioBox->GetSelection() == 0) | |
334 | m_printDialogData.SetAllPages(TRUE); | |
335 | else | |
336 | m_printDialogData.SetAllPages(FALSE); | |
337 | } | |
7bcb11d3 JS |
338 | } |
339 | else | |
340 | { // continuous printing | |
341 | m_printDialogData.SetFromPage(1); | |
342 | m_printDialogData.SetToPage(32000); | |
343 | } | |
87138c52 | 344 | m_printDialogData.SetNoCopies(wxAtoi(m_noCopiesText->GetValue())); |
7bcb11d3 | 345 | m_printDialogData.SetPrintToFile(m_printToFileCheckBox->GetValue()); |
c801d85f | 346 | |
7bcb11d3 | 347 | return TRUE; |
c801d85f KB |
348 | } |
349 | ||
350 | /* | |
7bcb11d3 JS |
351 | TODO: collate and noCopies should be duplicated across dialog data and print data objects |
352 | (slightly different semantics on Windows but let's ignore this for a bit). | |
353 | */ | |
c801d85f | 354 | |
7bcb11d3 | 355 | wxDC *wxGenericPrintDialog::GetPrintDC() |
c801d85f | 356 | { |
7bcb11d3 JS |
357 | return new wxPostScriptDC(wxThePrintSetupData->GetPrinterFile(), FALSE, (wxWindow *) NULL); |
358 | } | |
c801d85f | 359 | |
8826f46f VZ |
360 | // ---------------------------------------------------------------------------- |
361 | // Generic print setup dialog | |
362 | // ---------------------------------------------------------------------------- | |
c801d85f | 363 | |
7bcb11d3 JS |
364 | wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintData* data): |
365 | wxDialog(parent, -1, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL) | |
366 | { | |
367 | Init(data); | |
368 | } | |
c801d85f | 369 | |
7bcb11d3 JS |
370 | // Convert wxPrintSetupData to standard wxPrintData object |
371 | wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintSetupData* data): | |
372 | wxDialog(parent, -1, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL) | |
373 | { | |
374 | wxPrintData printData; | |
375 | if (data) | |
376 | printData = * data; | |
377 | else | |
378 | printData = * wxThePrintSetupData; | |
c801d85f | 379 | |
7bcb11d3 JS |
380 | Init(& printData); |
381 | } | |
9838df2c | 382 | |
7bcb11d3 JS |
383 | void wxGenericPrintSetupDialog::Init(wxPrintData* data) |
384 | { | |
385 | if ( data ) | |
386 | m_printData = *data; | |
9838df2c | 387 | |
7bcb11d3 | 388 | int staticBoxWidth = 300; |
8826f46f | 389 | |
7bcb11d3 | 390 | (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(10, 10), wxSize(staticBoxWidth, 60) ); |
8826f46f | 391 | |
7bcb11d3 JS |
392 | int xPos = 20; |
393 | int yPos = 30; | |
394 | m_paperTypeChoice = CreatePaperTypeChoice(&xPos, &yPos); | |
8826f46f | 395 | |
7bcb11d3 JS |
396 | wxString *choices = new wxString[2]; |
397 | choices[0] = _("Portrait"); | |
398 | choices[1] = _("Landscape"); | |
8826f46f | 399 | |
7bcb11d3 JS |
400 | m_orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"), |
401 | wxPoint(10, 80), wxSize(-1, -1), 2, choices, 1, wxRA_VERTICAL ); | |
402 | m_orientationRadioBox->SetSelection(0); | |
8826f46f | 403 | |
7bcb11d3 | 404 | (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Options"), wxPoint(10, 130), wxSize(staticBoxWidth, 50) ); |
8826f46f | 405 | |
7bcb11d3 | 406 | int colourYPos = 145; |
8826f46f | 407 | |
9838df2c | 408 | #ifdef __WXMOTIF__ |
7bcb11d3 | 409 | colourYPos = 150; |
9838df2c | 410 | #endif |
8826f46f | 411 | |
7bcb11d3 | 412 | m_colourCheckBox = new wxCheckBox(this, wxPRINTID_PRINTCOLOUR, _("Print in colour"), wxPoint(15, colourYPos)); |
c801d85f | 413 | |
7bcb11d3 | 414 | (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Print spooling"), wxPoint(330, 10), wxSize(200,170) ); |
8826f46f | 415 | |
7bcb11d3 | 416 | (void) new wxStaticText(this, wxPRINTID_STATIC, _("Printer command:"), wxPoint(340, 30)); |
8826f46f | 417 | |
7bcb11d3 | 418 | m_printerCommandText = new wxTextCtrl(this, wxPRINTID_COMMAND, "", wxPoint(360, 55), wxSize(150, -1)); |
8826f46f | 419 | |
7bcb11d3 | 420 | (void) new wxStaticText(this, wxPRINTID_STATIC, _("Printer options:"), wxPoint(340, 110)); |
8826f46f | 421 | |
7bcb11d3 | 422 | m_printerOptionsText = new wxTextCtrl(this, wxPRINTID_OPTIONS, "", wxPoint(360, 135), wxSize(150, -1)); |
8826f46f | 423 | |
7bcb11d3 JS |
424 | wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(130, 200), wxSize(100, -1)); |
425 | (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(320, 200), wxSize(100, -1)); | |
8826f46f | 426 | |
7bcb11d3 JS |
427 | okButton->SetDefault(); |
428 | okButton->SetFocus(); | |
8826f46f | 429 | |
7bcb11d3 JS |
430 | Fit(); |
431 | Centre(wxBOTH); | |
8826f46f | 432 | |
7bcb11d3 JS |
433 | InitDialog(); |
434 | delete[] choices; | |
c801d85f KB |
435 | } |
436 | ||
7bcb11d3 | 437 | wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog() |
c801d85f KB |
438 | { |
439 | } | |
440 | ||
7bcb11d3 | 441 | bool wxGenericPrintSetupDialog::TransferDataToWindow() |
c801d85f | 442 | { |
7bcb11d3 JS |
443 | if (m_printerCommandText && m_printData.GetPrinterCommand()) |
444 | m_printerCommandText->SetValue(m_printData.GetPrinterCommand()); | |
445 | if (m_printerOptionsText && m_printData.GetPrinterOptions()) | |
446 | m_printerOptionsText->SetValue(m_printData.GetPrinterOptions()); | |
447 | if (m_colourCheckBox) | |
448 | m_colourCheckBox->SetValue(m_printData.GetColour()); | |
8826f46f | 449 | |
7bcb11d3 JS |
450 | if (m_orientationRadioBox) |
451 | { | |
452 | if (m_printData.GetOrientation() == wxPORTRAIT) | |
453 | m_orientationRadioBox->SetSelection(0); | |
454 | else | |
455 | m_orientationRadioBox->SetSelection(1); | |
456 | } | |
457 | return TRUE; | |
c801d85f KB |
458 | } |
459 | ||
7bcb11d3 | 460 | bool wxGenericPrintSetupDialog::TransferDataFromWindow() |
c801d85f | 461 | { |
7bcb11d3 JS |
462 | if (m_printerCommandText) |
463 | m_printData.SetPrinterCommand(m_printerCommandText->GetValue()); | |
464 | if (m_printerOptionsText) | |
465 | m_printData.SetPrinterOptions(m_printerOptionsText->GetValue()); | |
466 | if (m_colourCheckBox) | |
467 | m_printData.SetColour(m_colourCheckBox->GetValue()); | |
468 | if (m_orientationRadioBox) | |
469 | { | |
470 | int sel = m_orientationRadioBox->GetSelection(); | |
471 | if (sel == 0) | |
472 | m_printData.SetOrientation(wxPORTRAIT); | |
473 | else | |
474 | m_printData.SetOrientation(wxLANDSCAPE); | |
475 | } | |
476 | if (m_paperTypeChoice) | |
477 | { | |
478 | wxString val(m_paperTypeChoice->GetStringSelection()); | |
479 | if (!val.IsNull() && val != "") | |
480 | m_printData.SetPaperId(wxThePrintPaperDatabase->ConvertNameToId(val)); | |
481 | } | |
482 | ||
483 | // This is for backward compatibility only | |
484 | *wxThePrintSetupData = GetPrintData(); | |
485 | return TRUE; | |
c801d85f KB |
486 | } |
487 | ||
488 | wxChoice *wxGenericPrintSetupDialog::CreatePaperTypeChoice(int *x, int *y) | |
489 | { | |
7bcb11d3 JS |
490 | /* Should not be necessary |
491 | if (!wxThePrintPaperDatabase) | |
492 | { | |
493 | wxThePrintPaperDatabase = new wxPrintPaperDatabase; | |
494 | wxThePrintPaperDatabase->CreateDatabase(); | |
495 | } | |
496 | */ | |
497 | int n = wxThePrintPaperDatabase->Number(); | |
498 | wxString *choices = new wxString [n]; | |
499 | int sel = 0; | |
500 | int i; | |
501 | for (i = 0; i < n; i++) | |
502 | { | |
503 | wxPrintPaperType *paper = (wxPrintPaperType *)wxThePrintPaperDatabase->Nth(i)->Data(); | |
504 | choices[i] = paper->GetName(); | |
505 | if (m_printData.GetPaperId() == paper->GetId()) | |
506 | sel = i; | |
507 | } | |
8826f46f | 508 | |
7bcb11d3 JS |
509 | int width = 250; |
510 | ||
511 | wxChoice *choice = new wxChoice(this, wxPRINTID_PAPERSIZE, wxPoint(*x, *y), wxSize(width, -1), n, | |
512 | choices); | |
513 | ||
514 | // SetFont(thisFont); | |
c801d85f | 515 | |
7bcb11d3 | 516 | delete[] choices; |
8826f46f | 517 | |
7bcb11d3 JS |
518 | choice->SetSelection(sel); |
519 | return choice; | |
c801d85f | 520 | } |
8826f46f | 521 | #endif // wxUSE_POSTSCRIPT |
c801d85f | 522 | |
8826f46f VZ |
523 | // ---------------------------------------------------------------------------- |
524 | // Generic page setup dialog | |
525 | // ---------------------------------------------------------------------------- | |
c801d85f KB |
526 | |
527 | void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent& WXUNUSED(event)) | |
528 | { | |
9838df2c JS |
529 | // We no longer query GetPrintMode, so we can eliminate the need |
530 | // to call SetPrintMode. | |
531 | // This has the limitation that we can't explicitly call the PostScript | |
532 | // print setup dialog from the generic Page Setup dialog under Windows, | |
533 | // but since this choice would only happen when trying to do PostScript | |
534 | // printing under Windows (and only in 16-bit Windows which | |
535 | // doesn't have a Windows-specific page setup dialog) it's worth it. | |
536 | ||
7bcb11d3 JS |
537 | // First save the current settings, so the wxPrintData object is up to date. |
538 | TransferDataFromWindow(); | |
539 | ||
540 | // Transfer the current print settings from this dialog to the page setup dialog. | |
541 | wxPrintDialogData data; | |
542 | data = GetPageSetupData().GetPrintData(); | |
9838df2c JS |
543 | data.SetSetupDialog(TRUE); |
544 | wxPrintDialog *printDialog = new wxPrintDialog(this, & data); | |
ba681060 | 545 | printDialog->ShowModal(); |
9838df2c | 546 | |
7bcb11d3 JS |
547 | // Transfer the page setup print settings from the page dialog to this dialog again, in case |
548 | // the page setup dialog changed something. | |
549 | GetPageSetupData().GetPrintData() = printDialog->GetPrintDialogData().GetPrintData(); | |
550 | GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData | |
551 | ||
9838df2c | 552 | printDialog->Destroy(); |
7bcb11d3 JS |
553 | |
554 | // Now update the dialog in case the page setup dialog changed some of our settings. | |
555 | TransferDataToWindow(); | |
c801d85f KB |
556 | } |
557 | ||
558 | wxGenericPageSetupDialog::wxGenericPageSetupDialog(wxWindow *parent, wxPageSetupData* data): | |
7bcb11d3 | 559 | wxDialog(parent, -1, _("Page Setup"), wxPoint(0, 0), wxSize(600, 600), wxDIALOG_MODAL|wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL) |
c801d85f | 560 | { |
7bcb11d3 JS |
561 | if ( data ) |
562 | m_pageData = *data; | |
8826f46f | 563 | |
7bcb11d3 JS |
564 | int buttonWidth = 75; |
565 | int buttonHeight = 25; | |
566 | int spacing = 5; | |
9838df2c | 567 | #ifdef __WXMOTIF__ |
7bcb11d3 | 568 | spacing = 15; |
9838df2c | 569 | #endif |
8826f46f | 570 | |
7bcb11d3 JS |
571 | int yPos = 5; |
572 | int xPos = 5; | |
8826f46f | 573 | |
7bcb11d3 JS |
574 | wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(5, yPos), wxSize(buttonWidth, buttonHeight)); |
575 | (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(buttonWidth + 5 + spacing, yPos), wxSize(buttonWidth, buttonHeight)); | |
8826f46f | 576 | |
7bcb11d3 | 577 | m_printerButton = new wxButton(this, wxPRINTID_SETUP, _("Printer..."), wxPoint(buttonWidth*2 + 5 + 2*spacing, yPos), wxSize(buttonWidth, buttonHeight)); |
8826f46f | 578 | |
7bcb11d3 JS |
579 | if ( !m_pageData.GetEnablePrinter() ) |
580 | m_printerButton->Enable(FALSE); | |
8826f46f | 581 | |
7bcb11d3 JS |
582 | // if (m_printData.GetEnableHelp()) |
583 | // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), -1, -1, buttonWidth, buttonHeight); | |
8826f46f | 584 | |
7bcb11d3 JS |
585 | okButton->SetDefault(); |
586 | okButton->SetFocus(); | |
8826f46f | 587 | |
7bcb11d3 JS |
588 | xPos = 5; |
589 | yPos += 35; | |
8826f46f | 590 | |
9838df2c | 591 | #ifdef __WXMOTIF__ |
7bcb11d3 | 592 | yPos += 10; |
9838df2c | 593 | #endif |
8826f46f | 594 | |
7bcb11d3 | 595 | m_paperTypeChoice = CreatePaperTypeChoice(&xPos, &yPos); |
8826f46f | 596 | |
7bcb11d3 | 597 | xPos = 5; |
8826f46f | 598 | |
7bcb11d3 JS |
599 | wxString *choices = new wxString[2]; |
600 | choices[0] = _("Portrait"); | |
601 | choices[1] = _("Landscape"); | |
602 | m_orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"), | |
603 | wxPoint(xPos, yPos), wxSize(-1, -1), 2, choices, 2); | |
604 | m_orientationRadioBox->SetSelection(0); | |
8826f46f | 605 | |
7bcb11d3 JS |
606 | xPos = 5; |
607 | yPos += 60; | |
8826f46f | 608 | |
7bcb11d3 | 609 | int staticWidth = 110; |
9838df2c | 610 | #ifdef __WXMOTIF__ |
7bcb11d3 | 611 | staticWidth += 20; |
9838df2c | 612 | #endif |
8826f46f | 613 | |
7bcb11d3 JS |
614 | int textWidth = 60; |
615 | spacing = 10; | |
8826f46f | 616 | |
7bcb11d3 JS |
617 | (void) new wxStaticText(this, wxPRINTID_STATIC, _("Left margin (mm):"), wxPoint(xPos, yPos)); |
618 | xPos += staticWidth; | |
8826f46f | 619 | |
7bcb11d3 JS |
620 | m_marginLeftText = new wxTextCtrl(this, wxPRINTID_LEFTMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1)); |
621 | xPos += textWidth + spacing; | |
8826f46f | 622 | |
7bcb11d3 JS |
623 | (void) new wxStaticText(this, wxPRINTID_STATIC, _("Right margin (mm):"), wxPoint(xPos, yPos)); |
624 | xPos += staticWidth; | |
8826f46f | 625 | |
7bcb11d3 JS |
626 | m_marginRightText = new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1)); |
627 | xPos += textWidth + spacing; | |
8826f46f | 628 | |
7bcb11d3 JS |
629 | yPos += 35; |
630 | xPos = 5; | |
8826f46f | 631 | |
7bcb11d3 JS |
632 | (void) new wxStaticText(this, wxPRINTID_STATIC, _("Top margin (mm):"), wxPoint(xPos, yPos)); |
633 | xPos += staticWidth; | |
8826f46f | 634 | |
7bcb11d3 JS |
635 | m_marginTopText = new wxTextCtrl(this, wxPRINTID_TOPMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1)); |
636 | xPos += textWidth + spacing; | |
8826f46f | 637 | |
7bcb11d3 JS |
638 | (void) new wxStaticText(this, wxPRINTID_STATIC, _("Bottom margin (mm):"), wxPoint(xPos, yPos)); |
639 | xPos += staticWidth; | |
8826f46f | 640 | |
7bcb11d3 | 641 | m_marginBottomText = new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN, "", wxPoint(xPos, yPos), wxSize(textWidth, -1)); |
8826f46f | 642 | |
7bcb11d3 JS |
643 | Fit(); |
644 | Centre(wxBOTH); | |
8826f46f | 645 | |
7bcb11d3 JS |
646 | InitDialog(); |
647 | delete [] choices; | |
648 | } | |
9838df2c | 649 | |
7bcb11d3 JS |
650 | wxGenericPageSetupDialog::~wxGenericPageSetupDialog() |
651 | { | |
652 | } | |
c801d85f | 653 | |
7bcb11d3 JS |
654 | bool wxGenericPageSetupDialog::TransferDataToWindow() |
655 | { | |
656 | if (m_marginLeftText) | |
657 | m_marginLeftText->SetValue(IntToString((int) m_pageData.GetMarginTopLeft().x)); | |
658 | if (m_marginTopText) | |
659 | m_marginTopText->SetValue(IntToString((int) m_pageData.GetMarginTopLeft().y)); | |
660 | if (m_marginRightText) | |
661 | m_marginRightText->SetValue(IntToString((int) m_pageData.GetMarginBottomRight().x)); | |
662 | if (m_marginBottomText) | |
663 | m_marginBottomText->SetValue(IntToString((int) m_pageData.GetMarginBottomRight().y)); | |
8826f46f | 664 | |
7bcb11d3 JS |
665 | if (m_orientationRadioBox) |
666 | { | |
667 | if (m_pageData.GetPrintData().GetOrientation() == wxPORTRAIT) | |
668 | m_orientationRadioBox->SetSelection(0); | |
669 | else | |
670 | m_orientationRadioBox->SetSelection(1); | |
671 | } | |
c801d85f | 672 | |
7bcb11d3 JS |
673 | // Find the paper type from either the current paper size in the wxPageSetupDialogData, or |
674 | // failing that, the id in the wxPrintData object. | |
c801d85f | 675 | |
7bcb11d3 JS |
676 | wxPrintPaperType* type = wxThePrintPaperDatabase->FindPaperType( |
677 | wxSize(m_pageData.GetPaperSize().x * 10, m_pageData.GetPaperSize().y * 10)); | |
c801d85f | 678 | |
7bcb11d3 JS |
679 | if (!type && m_pageData.GetPrintData().GetPaperId() != wxPAPER_NONE) |
680 | type = wxThePrintPaperDatabase->FindPaperType(m_pageData.GetPrintData().GetPaperId()); | |
c801d85f | 681 | |
7bcb11d3 JS |
682 | if (type) |
683 | { | |
684 | m_paperTypeChoice->SetStringSelection(type->GetName()); | |
685 | } | |
c801d85f | 686 | |
7bcb11d3 | 687 | return TRUE; |
c801d85f KB |
688 | } |
689 | ||
7bcb11d3 | 690 | bool wxGenericPageSetupDialog::TransferDataFromWindow() |
c801d85f | 691 | { |
7bcb11d3 | 692 | if (m_marginLeftText && m_marginTopText) |
87138c52 | 693 | m_pageData.SetMarginTopLeft(wxPoint(wxAtoi((const wxChar *)m_marginLeftText->GetValue()),wxAtoi((const wxChar *)m_marginTopText->GetValue()))); |
7bcb11d3 | 694 | if (m_marginRightText && m_marginBottomText) |
87138c52 | 695 | m_pageData.SetMarginBottomRight(wxPoint(wxAtoi((const wxChar *)m_marginRightText->GetValue()),wxAtoi((const wxChar *)m_marginBottomText->GetValue()))); |
8826f46f | 696 | |
7bcb11d3 | 697 | if (m_orientationRadioBox) |
c801d85f | 698 | { |
7bcb11d3 JS |
699 | int sel = m_orientationRadioBox->GetSelection(); |
700 | if (sel == 0) | |
701 | { | |
2a47d3c1 | 702 | #if wxUSE_POSTSCRIPT |
7bcb11d3 | 703 | wxThePrintSetupData->SetPrinterOrientation(wxPORTRAIT); |
2a47d3c1 | 704 | #endif |
7bcb11d3 JS |
705 | m_pageData.GetPrintData().SetOrientation(wxPORTRAIT); |
706 | } | |
707 | else | |
708 | { | |
2a47d3c1 | 709 | #if wxUSE_POSTSCRIPT |
7bcb11d3 | 710 | wxThePrintSetupData->SetPrinterOrientation(wxLANDSCAPE); |
2a47d3c1 | 711 | #endif |
7bcb11d3 JS |
712 | m_pageData.GetPrintData().SetOrientation(wxLANDSCAPE); |
713 | } | |
c801d85f | 714 | } |
7bcb11d3 | 715 | if (m_paperTypeChoice) |
c801d85f | 716 | { |
7bcb11d3 JS |
717 | wxString val(m_paperTypeChoice->GetStringSelection()); |
718 | if (!val.IsNull() && val != "") | |
c801d85f | 719 | { |
7bcb11d3 JS |
720 | wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType(val); |
721 | if ( paper ) | |
722 | { | |
723 | m_pageData.SetPaperSize(wxSize(paper->GetWidth()/10, paper->GetHeight()/10)); | |
724 | m_pageData.GetPrintData().SetPaperId(paper->GetId()); | |
725 | } | |
c801d85f KB |
726 | } |
727 | } | |
8826f46f | 728 | |
7bcb11d3 | 729 | return TRUE; |
c801d85f KB |
730 | } |
731 | ||
732 | wxChoice *wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x, int *y) | |
733 | { | |
7bcb11d3 JS |
734 | /* |
735 | if (!wxThePrintPaperDatabase) | |
736 | { | |
737 | wxThePrintPaperDatabase = new wxPrintPaperDatabase; | |
738 | wxThePrintPaperDatabase->CreateDatabase(); | |
739 | } | |
740 | */ | |
741 | ||
742 | int n = wxThePrintPaperDatabase->Number(); | |
743 | wxString *choices = new wxString [n]; | |
744 | int i; | |
745 | for (i = 0; i < n; i++) | |
746 | { | |
747 | wxPrintPaperType *paper = (wxPrintPaperType *)wxThePrintPaperDatabase->Nth(i)->Data(); | |
748 | choices[i] = paper->GetName(); | |
749 | } | |
8826f46f | 750 | |
7bcb11d3 JS |
751 | (void) new wxStaticText(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(*x, *y)); |
752 | *y += 25; | |
8826f46f | 753 | |
7bcb11d3 JS |
754 | wxChoice *choice = new wxChoice(this, wxPRINTID_PAPERSIZE, wxPoint(*x, *y), wxSize(300, -1), n, |
755 | choices); | |
756 | *y += 35; | |
757 | delete[] choices; | |
8826f46f | 758 | |
7bcb11d3 JS |
759 | // choice->SetSelection(sel); |
760 | return choice; | |
c801d85f KB |
761 | } |
762 |