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