]>
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$ | |
6aa89a22 | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8826f46f VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
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 | ||
aba17e09 | 31 | #if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW) |
ce4169a4 | 32 | |
c801d85f | 33 | #ifndef WX_PRECOMP |
8826f46f VZ |
34 | #include "wx/utils.h" |
35 | #include "wx/dc.h" | |
8826f46f VZ |
36 | #include "wx/stattext.h" |
37 | #include "wx/statbox.h" | |
38 | #include "wx/button.h" | |
39 | #include "wx/checkbox.h" | |
40 | #include "wx/textctrl.h" | |
41 | #include "wx/radiobox.h" | |
42 | #include "wx/filedlg.h" | |
fa12f7e6 | 43 | #include "wx/combobox.h" |
3096bd2f | 44 | #include "wx/intl.h" |
27ea1d8a | 45 | #include "wx/sizer.h" |
ebb7606e | 46 | #include "wx/cmndata.h" |
27ea1d8a RR |
47 | #endif |
48 | ||
49 | #if wxUSE_STATLINE | |
50 | #include "wx/statline.h" | |
c801d85f KB |
51 | #endif |
52 | ||
53 | #include "wx/generic/prntdlgg.h" | |
2a47d3c1 JS |
54 | |
55 | #if wxUSE_POSTSCRIPT | |
8826f46f | 56 | #include "wx/generic/dcpsg.h" |
2a47d3c1 JS |
57 | #endif |
58 | ||
8850cbd3 | 59 | #include "wx/prntbase.h" |
c801d85f | 60 | #include "wx/printdlg.h" |
7bcb11d3 | 61 | #include "wx/paper.h" |
eba33006 | 62 | #include "wx/filename.h" |
2c84e0c2 | 63 | #include "wx/tokenzr.h" |
f68535b0 | 64 | #include "wx/imaglist.h" |
c801d85f KB |
65 | |
66 | #include <stdlib.h> | |
67 | #include <string.h> | |
68 | ||
8826f46f | 69 | // ---------------------------------------------------------------------------- |
8850cbd3 | 70 | // global vars |
8826f46f VZ |
71 | // ---------------------------------------------------------------------------- |
72 | ||
8850cbd3 | 73 | extern wxPrintPaperDatabase *wxThePrintPaperDatabase; |
25889d3c | 74 | |
2a47d3c1 JS |
75 | #if wxUSE_POSTSCRIPT |
76 | ||
8850cbd3 RR |
77 | //---------------------------------------------------------------------------- |
78 | // wxPostScriptNativeData | |
79 | //---------------------------------------------------------------------------- | |
30862d99 | 80 | |
8850cbd3 | 81 | IMPLEMENT_CLASS(wxPostScriptPrintNativeData, wxPrintNativeDataBase) |
8826f46f | 82 | |
8850cbd3 RR |
83 | wxPostScriptPrintNativeData::wxPostScriptPrintNativeData() |
84 | { | |
9548f380 | 85 | m_previewCommand = wxEmptyString; |
8850cbd3 RR |
86 | #ifdef __VMS__ |
87 | m_printerCommand = wxT("print"); | |
88 | m_printerOptions = wxT("/nonotify/queue=psqueue"); | |
89 | m_afmPath = wxT("sys$ps_font_metrics:"); | |
90 | #endif | |
30862d99 | 91 | |
8850cbd3 RR |
92 | #ifdef __WXMSW__ |
93 | m_printerCommand = wxT("print"); | |
9548f380 | 94 | m_printerOptions = wxEmptyString; |
8850cbd3 RR |
95 | m_afmPath = wxT("c:\\windows\\system\\"); |
96 | #endif | |
8826f46f | 97 | |
8850cbd3 RR |
98 | #if !defined(__VMS__) && !defined(__WXMSW__) |
99 | m_printerCommand = wxT("lpr"); | |
9548f380 | 100 | m_printerOptions = wxEmptyString; |
f69fc95c | 101 | m_afmPath = wxEmptyString; |
8850cbd3 | 102 | #endif |
c801d85f | 103 | |
8850cbd3 RR |
104 | m_printerScaleX = 1.0; |
105 | m_printerScaleY = 1.0; | |
106 | m_printerTranslateX = 0; | |
107 | m_printerTranslateY = 0; | |
8850cbd3 | 108 | } |
c801d85f | 109 | |
8850cbd3 RR |
110 | wxPostScriptPrintNativeData::~wxPostScriptPrintNativeData() |
111 | { | |
112 | } | |
113 | ||
4e4528f6 | 114 | bool wxPostScriptPrintNativeData::TransferTo( wxPrintData &WXUNUSED(data) ) |
8850cbd3 RR |
115 | { |
116 | return true; | |
117 | } | |
118 | ||
4e4528f6 | 119 | bool wxPostScriptPrintNativeData::TransferFrom( const wxPrintData &WXUNUSED(data) ) |
8850cbd3 RR |
120 | { |
121 | return true; | |
122 | } | |
25889d3c | 123 | |
8826f46f VZ |
124 | // ---------------------------------------------------------------------------- |
125 | // Generic print dialog for non-Windows printing use. | |
126 | // ---------------------------------------------------------------------------- | |
127 | ||
c061373d RR |
128 | IMPLEMENT_CLASS(wxGenericPrintDialog, wxPrintDialogBase) |
129 | ||
130 | BEGIN_EVENT_TABLE(wxGenericPrintDialog, wxPrintDialogBase) | |
131 | EVT_BUTTON(wxID_OK, wxGenericPrintDialog::OnOK) | |
132 | EVT_BUTTON(wxPRINTID_SETUP, wxGenericPrintDialog::OnSetup) | |
133 | EVT_RADIOBOX(wxPRINTID_RANGE, wxGenericPrintDialog::OnRange) | |
134 | END_EVENT_TABLE() | |
135 | ||
8826f46f VZ |
136 | wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent, |
137 | wxPrintDialogData* data) | |
c061373d | 138 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), |
c47addef | 139 | wxPoint(0,0), wxSize(600, 600), |
8826f46f | 140 | wxDEFAULT_DIALOG_STYLE | |
8826f46f VZ |
141 | wxTAB_TRAVERSAL) |
142 | { | |
143 | if ( data ) | |
144 | m_printDialogData = *data; | |
c801d85f | 145 | |
8826f46f VZ |
146 | Init(parent); |
147 | } | |
c801d85f | 148 | |
8826f46f VZ |
149 | wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent, |
150 | wxPrintData* data) | |
c061373d | 151 | : wxPrintDialogBase(parent, wxID_ANY, _("Print"), |
c47addef | 152 | wxPoint(0,0), wxSize(600, 600), |
cb230244 | 153 | wxDEFAULT_DIALOG_STYLE | |
cb230244 | 154 | wxTAB_TRAVERSAL) |
c801d85f | 155 | { |
7bcb11d3 JS |
156 | if ( data ) |
157 | m_printDialogData = *data; | |
2312c9e1 | 158 | |
8826f46f VZ |
159 | Init(parent); |
160 | } | |
161 | ||
74e3313b | 162 | void wxGenericPrintDialog::Init(wxWindow * WXUNUSED(parent)) |
8826f46f | 163 | { |
c47addef | 164 | // wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0,0), wxSize(600, 600), |
2a21ac15 | 165 | // wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL); |
8826f46f | 166 | |
27ea1d8a | 167 | wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL ); |
2312c9e1 | 168 | |
ca65c044 WS |
169 | // 1) top row |
170 | ||
6038ec8e RR |
171 | wxPrintFactory* factory = wxPrintFactory::GetFactory(); |
172 | ||
ca65c044 WS |
173 | wxStaticBoxSizer *topsizer = new wxStaticBoxSizer( |
174 | new wxStaticBox( this, wxID_ANY, _( "Printer options" ) ), wxHORIZONTAL ); | |
6038ec8e RR |
175 | wxFlexGridSizer *flex = new wxFlexGridSizer( 2 ); |
176 | flex->AddGrowableCol( 1 ); | |
177 | topsizer->Add( flex, 1, wxGROW ); | |
2312c9e1 | 178 | |
27ea1d8a | 179 | m_printToFileCheckBox = new wxCheckBox( this, wxPRINTID_PRINTTOFILE, _("Print to File") ); |
6038ec8e | 180 | flex->Add( m_printToFileCheckBox, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); |
2312c9e1 | 181 | |
27ea1d8a | 182 | m_setupButton = new wxButton(this, wxPRINTID_SETUP, _("Setup...") ); |
6038ec8e | 183 | flex->Add( m_setupButton, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 ); |
2312c9e1 | 184 | |
6038ec8e RR |
185 | if (!factory->HasPrintSetupDialog()) |
186 | m_setupButton->Enable( false ); | |
2312c9e1 | 187 | |
6038ec8e RR |
188 | if (factory->HasPrinterLine()) |
189 | { | |
2312c9e1 | 190 | flex->Add( new wxStaticText( this, wxID_ANY, _("Printer:") ), |
6038ec8e | 191 | 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); |
2312c9e1 | 192 | flex->Add( new wxStaticText( this, wxID_ANY, factory->CreatePrinterLine() ), |
6038ec8e RR |
193 | 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); |
194 | } | |
ca65c044 | 195 | |
6038ec8e RR |
196 | if (factory->HasStatusLine()) |
197 | { | |
2312c9e1 | 198 | flex->Add( new wxStaticText( this, wxID_ANY, _("Status:") ), |
6038ec8e | 199 | 0, wxALIGN_CENTER_VERTICAL|wxALL-wxTOP, 5 ); |
2312c9e1 | 200 | flex->Add( new wxStaticText( this, wxID_ANY, factory->CreateStatusLine() ), |
6038ec8e RR |
201 | 0, wxALIGN_CENTER_VERTICAL|wxALL-wxTOP, 5 ); |
202 | } | |
203 | ||
204 | mainsizer->Add( topsizer, 0, wxLEFT|wxTOP|wxRIGHT|wxGROW, 10 ); | |
ca65c044 | 205 | |
27ea1d8a | 206 | // 2) middle row with radio box |
ca65c044 | 207 | |
7bcb11d3 JS |
208 | wxString *choices = new wxString[2]; |
209 | choices[0] = _("All"); | |
210 | choices[1] = _("Pages"); | |
8826f46f | 211 | |
7bcb11d3 | 212 | m_fromText = (wxTextCtrl*)NULL; |
d14612c6 | 213 | m_toText = (wxTextCtrl*)NULL; |
59e2b19f | 214 | m_rangeRadioBox = (wxRadioBox *)NULL; |
ca65c044 | 215 | |
7bcb11d3 JS |
216 | if (m_printDialogData.GetFromPage() != 0) |
217 | { | |
218 | m_rangeRadioBox = new wxRadioBox(this, wxPRINTID_RANGE, _("Print Range"), | |
27ea1d8a | 219 | wxDefaultPosition, wxDefaultSize, |
8826f46f VZ |
220 | 2, choices, |
221 | 1, wxRA_VERTICAL); | |
7bcb11d3 | 222 | m_rangeRadioBox->SetSelection(1); |
b1d4dd7a | 223 | |
eba33006 | 224 | mainsizer->Add( m_rangeRadioBox, 0, wxLEFT|wxTOP|wxRIGHT, 10 ); |
7bcb11d3 | 225 | } |
8826f46f | 226 | |
27ea1d8a | 227 | // 3) bottom row |
ca65c044 | 228 | |
27ea1d8a RR |
229 | wxBoxSizer *bottomsizer = new wxBoxSizer( wxHORIZONTAL ); |
230 | ||
231 | if (m_printDialogData.GetFromPage() != 0) | |
7bcb11d3 | 232 | { |
27ea1d8a | 233 | bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("From:") ), 0, wxCENTER|wxALL, 5 ); |
422d0ff0 | 234 | m_fromText = new wxTextCtrl(this, wxPRINTID_FROM, wxEmptyString, wxDefaultPosition, wxSize(40, wxDefaultCoord)); |
eba33006 | 235 | bottomsizer->Add( m_fromText, 1, wxCENTER|wxRIGHT, 10 ); |
8826f46f | 236 | |
27ea1d8a | 237 | bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("To:") ), 0, wxCENTER|wxALL, 5); |
422d0ff0 | 238 | m_toText = new wxTextCtrl(this, wxPRINTID_TO, wxEmptyString, wxDefaultPosition, wxSize(40, wxDefaultCoord)); |
eba33006 | 239 | bottomsizer->Add( m_toText, 1, wxCENTER|wxRIGHT, 10 ); |
27ea1d8a | 240 | } |
8826f46f | 241 | |
27ea1d8a | 242 | bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Copies:") ), 0, wxCENTER|wxALL, 5 ); |
422d0ff0 | 243 | m_noCopiesText = new wxTextCtrl(this, wxPRINTID_COPIES, wxEmptyString, wxPoint(252, 130), wxSize(40, wxDefaultCoord)); |
27ea1d8a | 244 | bottomsizer->Add( m_noCopiesText, 1, wxCENTER|wxRIGHT, 10 ); |
8826f46f | 245 | |
27ea1d8a | 246 | mainsizer->Add( bottomsizer, 0, wxTOP|wxLEFT|wxRIGHT, 12 ); |
8826f46f | 247 | |
27ea1d8a RR |
248 | #if wxUSE_STATLINE |
249 | // 4) static line | |
ca65c044 | 250 | mainsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 ); |
27ea1d8a | 251 | #endif |
8826f46f | 252 | |
27ea1d8a | 253 | // 5) buttons |
8826f46f | 254 | |
acf2ac37 | 255 | mainsizer->Add( CreateButtonSizer( wxOK|wxCANCEL), 0, wxEXPAND|wxALL, 10 ); |
8826f46f | 256 | |
ca65c044 | 257 | SetAutoLayout( true ); |
27ea1d8a RR |
258 | SetSizer( mainsizer ); |
259 | ||
260 | mainsizer->Fit( this ); | |
7bcb11d3 | 261 | Centre(wxBOTH); |
8826f46f | 262 | |
7bcb11d3 JS |
263 | // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow |
264 | InitDialog(); | |
265 | delete[] choices; | |
c801d85f KB |
266 | } |
267 | ||
7bcb11d3 | 268 | int wxGenericPrintDialog::ShowModal() |
c801d85f | 269 | { |
6038ec8e | 270 | return wxDialog::ShowModal(); |
c801d85f KB |
271 | } |
272 | ||
7bcb11d3 | 273 | wxGenericPrintDialog::~wxGenericPrintDialog() |
c801d85f KB |
274 | { |
275 | } | |
276 | ||
277 | void wxGenericPrintDialog::OnOK(wxCommandEvent& WXUNUSED(event)) | |
278 | { | |
7bcb11d3 | 279 | TransferDataFromWindow(); |
8826f46f | 280 | |
b386cd7a JS |
281 | // An empty 'to' field signals printing just the |
282 | // 'from' page. | |
283 | if (m_printDialogData.GetToPage() < 1) | |
284 | m_printDialogData.SetToPage(m_printDialogData.GetFromPage()); | |
285 | ||
7bcb11d3 JS |
286 | // There are some interactions between the global setup data |
287 | // and the standard print dialog. The global printing 'mode' | |
288 | // is determined by whether the user checks Print to file | |
289 | // or not. | |
290 | if (m_printDialogData.GetPrintToFile()) | |
291 | { | |
6038ec8e | 292 | m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE); |
ca65c044 | 293 | |
eba33006 | 294 | wxFileName fname( m_printDialogData.GetPrintData().GetFilename() ); |
ca65c044 | 295 | |
eba33006 | 296 | wxFileDialog dialog( this, _("PostScript file"), |
2312c9e1 | 297 | fname.GetPath(), fname.GetFullName(), wxT("*.ps"), wxSAVE | wxOVERWRITE_PROMPT ); |
eba33006 | 298 | if (dialog.ShowModal() != wxID_OK) return; |
2312c9e1 | 299 | |
eba33006 | 300 | m_printDialogData.GetPrintData().SetFilename( dialog.GetPath() ); |
7bcb11d3 JS |
301 | } |
302 | else | |
75737d05 | 303 | { |
6038ec8e | 304 | m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER); |
75737d05 | 305 | } |
2312c9e1 | 306 | |
7bcb11d3 | 307 | EndModal(wxID_OK); |
c801d85f KB |
308 | } |
309 | ||
310 | void wxGenericPrintDialog::OnRange(wxCommandEvent& event) | |
311 | { | |
7bcb11d3 | 312 | if (!m_fromText) return; |
8826f46f | 313 | |
7bcb11d3 JS |
314 | if (event.GetInt() == 0) |
315 | { | |
ca65c044 WS |
316 | m_fromText->Enable(false); |
317 | m_toText->Enable(false); | |
7bcb11d3 JS |
318 | } |
319 | else if (event.GetInt() == 1) | |
320 | { | |
ca65c044 WS |
321 | m_fromText->Enable(true); |
322 | m_toText->Enable(true); | |
7bcb11d3 | 323 | } |
c801d85f KB |
324 | } |
325 | ||
326 | void wxGenericPrintDialog::OnSetup(wxCommandEvent& WXUNUSED(event)) | |
327 | { | |
6038ec8e RR |
328 | wxPrintFactory* factory = wxPrintFactory::GetFactory(); |
329 | ||
330 | if (factory->HasPrintSetupDialog()) | |
7bcb11d3 | 331 | { |
6038ec8e RR |
332 | // The print setup dialog should change the |
333 | // print data in-place if not cancelled. | |
334 | wxDialog *dialog = factory->CreatePrintSetupDialog( this, &m_printDialogData.GetPrintData() ); | |
335 | dialog->ShowModal(); | |
336 | dialog->Destroy(); | |
7bcb11d3 | 337 | } |
c801d85f KB |
338 | } |
339 | ||
7bcb11d3 | 340 | bool wxGenericPrintDialog::TransferDataToWindow() |
c801d85f | 341 | { |
7bcb11d3 JS |
342 | if(m_printDialogData.GetFromPage() != 0) |
343 | { | |
d14612c6 KB |
344 | if(m_fromText) |
345 | { | |
346 | if (m_printDialogData.GetEnablePageNumbers()) | |
347 | { | |
ca65c044 WS |
348 | m_fromText->Enable(true); |
349 | m_toText->Enable(true); | |
b386cd7a JS |
350 | if (m_printDialogData.GetFromPage() > 0) |
351 | m_fromText->SetValue(wxString::Format(_T("%d"), m_printDialogData.GetFromPage())); | |
352 | if (m_printDialogData.GetToPage() > 0) | |
353 | m_toText->SetValue(wxString::Format(_T("%d"), m_printDialogData.GetToPage())); | |
59e2b19f | 354 | if(m_rangeRadioBox) |
b386cd7a | 355 | if (m_printDialogData.GetAllPages() || m_printDialogData.GetFromPage() == 0) |
59e2b19f KB |
356 | m_rangeRadioBox->SetSelection(0); |
357 | else | |
358 | m_rangeRadioBox->SetSelection(1); | |
d14612c6 KB |
359 | } |
360 | else | |
361 | { | |
ca65c044 WS |
362 | m_fromText->Enable(false); |
363 | m_toText->Enable(false); | |
59e2b19f KB |
364 | if(m_rangeRadioBox) |
365 | { | |
366 | m_rangeRadioBox->SetSelection(0); | |
ca65c044 | 367 | m_rangeRadioBox->wxRadioBox::Enable(1, false); |
59e2b19f | 368 | } |
d14612c6 KB |
369 | } |
370 | } | |
7bcb11d3 | 371 | } |
30862d99 VZ |
372 | m_noCopiesText->SetValue( |
373 | wxString::Format(_T("%d"), m_printDialogData.GetNoCopies())); | |
8826f46f | 374 | |
7bcb11d3 JS |
375 | m_printToFileCheckBox->SetValue(m_printDialogData.GetPrintToFile()); |
376 | m_printToFileCheckBox->Enable(m_printDialogData.GetEnablePrintToFile()); | |
ca65c044 | 377 | return true; |
c801d85f KB |
378 | } |
379 | ||
7bcb11d3 | 380 | bool wxGenericPrintDialog::TransferDataFromWindow() |
c801d85f | 381 | { |
92980e90 | 382 | long res = 0; |
7bcb11d3 JS |
383 | if(m_printDialogData.GetFromPage() != -1) |
384 | { | |
385 | if (m_printDialogData.GetEnablePageNumbers()) | |
386 | { | |
92980e90 RR |
387 | if(m_fromText) |
388 | { | |
389 | wxString value = m_fromText->GetValue(); | |
390 | if (value.ToLong( &res )) | |
391 | m_printDialogData.SetFromPage( res ); | |
392 | } | |
393 | if(m_toText) | |
ca65c044 | 394 | { |
92980e90 RR |
395 | wxString value = m_toText->GetValue(); |
396 | if (value.ToLong( &res )) | |
397 | m_printDialogData.SetToPage( res ); | |
398 | } | |
7bcb11d3 | 399 | } |
59e2b19f KB |
400 | if(m_rangeRadioBox) |
401 | { | |
01b5396f RR |
402 | if (m_rangeRadioBox->GetSelection() == 0) |
403 | { | |
404 | m_printDialogData.SetAllPages(true); | |
2312c9e1 | 405 | |
01b5396f RR |
406 | // This means all pages, more or less |
407 | m_printDialogData.SetFromPage(1); | |
408 | m_printDialogData.SetToPage(32000); | |
409 | } | |
410 | else | |
411 | m_printDialogData.SetAllPages(false); | |
59e2b19f | 412 | } |
7bcb11d3 JS |
413 | } |
414 | else | |
415 | { // continuous printing | |
416 | m_printDialogData.SetFromPage(1); | |
417 | m_printDialogData.SetToPage(32000); | |
418 | } | |
ca65c044 | 419 | |
92980e90 RR |
420 | wxString value = m_noCopiesText->GetValue(); |
421 | if (value.ToLong( &res )) | |
422 | m_printDialogData.SetNoCopies( res ); | |
ca65c044 | 423 | |
7bcb11d3 | 424 | m_printDialogData.SetPrintToFile(m_printToFileCheckBox->GetValue()); |
2312c9e1 | 425 | |
ca65c044 | 426 | return true; |
c801d85f KB |
427 | } |
428 | ||
7bcb11d3 | 429 | wxDC *wxGenericPrintDialog::GetPrintDC() |
c801d85f | 430 | { |
6038ec8e | 431 | return new wxPostScriptDC(GetPrintDialogData().GetPrintData()); |
7bcb11d3 | 432 | } |
c801d85f | 433 | |
8826f46f VZ |
434 | // ---------------------------------------------------------------------------- |
435 | // Generic print setup dialog | |
436 | // ---------------------------------------------------------------------------- | |
c801d85f | 437 | |
8850cbd3 RR |
438 | IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog) |
439 | ||
2c84e0c2 RR |
440 | BEGIN_EVENT_TABLE(wxGenericPrintSetupDialog, wxDialog) |
441 | EVT_LIST_ITEM_ACTIVATED(wxPRINTID_PRINTER, wxGenericPrintSetupDialog::OnPrinter) | |
442 | END_EVENT_TABLE() | |
443 | ||
7bcb11d3 | 444 | wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintData* data): |
c47addef | 445 | wxDialog(parent, wxID_ANY, _("Print Setup"), wxPoint(0,0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL) |
7bcb11d3 JS |
446 | { |
447 | Init(data); | |
448 | } | |
c801d85f | 449 | |
2c84e0c2 RR |
450 | /* XPM */ |
451 | static char * check_xpm[] = { | |
452 | /* width height ncolors chars_per_pixel */ | |
453 | "16 16 3 1", | |
454 | /* colors */ | |
455 | " s None c None", | |
456 | "X c #000000", | |
457 | ". c #808080", | |
458 | /* pixels */ | |
459 | " ", | |
460 | " ", | |
461 | " ", | |
462 | " .. ", | |
463 | " XX ", | |
464 | " XX. ", | |
465 | " .XX ", | |
466 | " XX ", | |
467 | " X XX. ", | |
468 | " XX .XX ", | |
469 | " XX XX ", | |
470 | " XXXX. ", | |
471 | " XX. ", | |
472 | " . ", | |
473 | " ", | |
474 | " " | |
475 | }; | |
476 | ||
477 | ||
7bcb11d3 JS |
478 | void wxGenericPrintSetupDialog::Init(wxPrintData* data) |
479 | { | |
480 | if ( data ) | |
481 | m_printData = *data; | |
9838df2c | 482 | |
2c84e0c2 | 483 | m_targetData = data; |
8826f46f | 484 | |
6038ec8e | 485 | wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL ); |
8826f46f | 486 | |
2c84e0c2 | 487 | // printer selection |
2312c9e1 WS |
488 | |
489 | wxStaticBoxSizer *printer_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Printer") ), wxVERTICAL ); | |
2c84e0c2 | 490 | main_sizer->Add( printer_sizer, 0, wxALL|wxGROW, 10 ); |
2312c9e1 WS |
491 | |
492 | m_printerListCtrl = new wxListCtrl( this, wxPRINTID_PRINTER, | |
493 | wxDefaultPosition, wxSize(wxDefaultCoord,100), wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER ); | |
2c84e0c2 RR |
494 | wxImageList *image_list = new wxImageList; |
495 | image_list->Add( wxBitmap(check_xpm) ); | |
496 | m_printerListCtrl->AssignImageList( image_list, wxIMAGE_LIST_SMALL ); | |
2312c9e1 | 497 | |
2c84e0c2 RR |
498 | m_printerListCtrl->InsertColumn( 0, wxT(" "), wxLIST_FORMAT_LEFT, 20 ); |
499 | m_printerListCtrl->InsertColumn( 1, wxT("Printer"), wxLIST_FORMAT_LEFT, 150 ); | |
500 | m_printerListCtrl->InsertColumn( 2, wxT("Device"), wxLIST_FORMAT_LEFT, 150 ); | |
501 | m_printerListCtrl->InsertColumn( 3, wxT("Status"), wxLIST_FORMAT_LEFT, 80 ); | |
502 | ||
503 | wxListItem item; | |
504 | item.SetMask( wxLIST_MASK_TEXT ); | |
505 | item.SetColumn( 1 ); | |
506 | item.SetText( _("Default printer") ); | |
507 | item.SetId( m_printerListCtrl->InsertItem( item ) ); | |
508 | ||
2312c9e1 | 509 | if (data->GetPrinterName().empty()) |
2c84e0c2 RR |
510 | { |
511 | wxListItem item2; | |
512 | item2.SetId( item.GetId() ); | |
513 | item2.SetMask( wxLIST_MASK_IMAGE ); | |
514 | item2.SetImage( 0 ); | |
515 | m_printerListCtrl->SetItem( item2 ); | |
f36a04a7 RR |
516 | // also select item |
517 | m_printerListCtrl->SetItemState( item.GetId(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); | |
2c84e0c2 RR |
518 | } |
519 | ||
520 | item.SetId( 1+ item.GetId() ); | |
521 | ||
522 | wxArrayString errors; | |
523 | wxArrayString output; | |
b357f3fc | 524 | long res = wxExecute( wxT("lpstat -v"), output, errors, wxEXEC_NODISABLE ); |
2c84e0c2 RR |
525 | if (res >= 0 && errors.GetCount() == 0) |
526 | { | |
527 | size_t i; | |
528 | for (i = 0; i < output.GetCount(); i++) | |
529 | { | |
530 | wxStringTokenizer tok( output[i], wxT(" ") ); | |
531 | wxString tmp = tok.GetNextToken(); // "device" | |
532 | if (tmp != wxT("device")) | |
533 | break; // the lpstat syntax must have changed. | |
534 | tmp = tok.GetNextToken(); // "for" | |
535 | if (tmp != wxT("for")) | |
536 | break; // the lpstat syntax must have changed. | |
537 | tmp = tok.GetNextToken(); // "hp_deskjet930c:" | |
538 | if (tmp[tmp.Len()-1] == wxT(':')) | |
539 | tmp.Remove(tmp.Len()-1,1); | |
540 | wxString name = tmp; | |
541 | item.SetText( name ); | |
542 | item.SetId( m_printerListCtrl->InsertItem( item ) ); | |
543 | tmp = tok.GetNextToken(); // "parallel:/dev/lp0" | |
544 | item.SetColumn( 2 ); | |
545 | item.SetText( tmp ); | |
546 | m_printerListCtrl->SetItem( item ); | |
547 | if (data->GetPrinterName() == name) | |
548 | { | |
549 | wxListItem item2; | |
550 | item2.SetId( item.GetId() ); | |
551 | item2.SetMask( wxLIST_MASK_IMAGE ); | |
552 | item2.SetImage( 0 ); | |
553 | m_printerListCtrl->SetItem( item2 ); | |
f36a04a7 RR |
554 | // also select item |
555 | m_printerListCtrl->SetItemState( item.GetId(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); | |
2c84e0c2 | 556 | } |
2312c9e1 | 557 | |
2c84e0c2 RR |
558 | wxString command = wxT("lpstat -p "); |
559 | command += name; | |
560 | wxArrayString errors2; | |
561 | wxArrayString output2; | |
b357f3fc | 562 | res = wxExecute( command, output2, errors2, wxEXEC_NODISABLE ); |
2c84e0c2 RR |
563 | if (res >= 0 && errors2.GetCount() == 0 && output2.GetCount() > 0) |
564 | { | |
565 | tmp = output2[0]; // "printer hp_deskjet930c is idle. enable since ..." | |
566 | int pos = tmp.Find( wxT('.') ); | |
2312c9e1 | 567 | if (pos != wxNOT_FOUND) |
2c84e0c2 RR |
568 | tmp.Remove( (size_t)pos, tmp.Len()-(size_t)pos ); |
569 | wxStringTokenizer tok2( tmp, wxT(" ") ); | |
570 | tmp = tok2.GetNextToken(); // "printer" | |
571 | tmp = tok2.GetNextToken(); // "hp_deskjet930c" | |
9548f380 | 572 | tmp = wxEmptyString; |
2c84e0c2 RR |
573 | while (tok2.HasMoreTokens()) |
574 | { | |
575 | tmp += tok2.GetNextToken(); | |
576 | tmp += wxT(" "); | |
577 | } | |
578 | item.SetColumn( 3 ); | |
579 | item.SetText( tmp ); | |
580 | m_printerListCtrl->SetItem( item ); | |
581 | } | |
2312c9e1 | 582 | |
2c84e0c2 RR |
583 | item.SetColumn( 1 ); |
584 | item.SetId( 1+ item.GetId() ); | |
585 | } | |
586 | } | |
587 | ||
2312c9e1 | 588 | |
2c84e0c2 RR |
589 | printer_sizer->Add( m_printerListCtrl, 0, wxALL|wxGROW, 5 ); |
590 | ||
6038ec8e RR |
591 | wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL ); |
592 | main_sizer->Add( item1, 0, wxALL, 5 ); | |
8826f46f | 593 | |
6038ec8e | 594 | // printer options (on the left) |
8826f46f | 595 | |
6038ec8e | 596 | wxBoxSizer *item2 = new wxBoxSizer( wxVERTICAL ); |
8826f46f | 597 | |
6038ec8e RR |
598 | wxStaticBox *item4 = new wxStaticBox( this, wxPRINTID_STATIC, _("Paper size") ); |
599 | wxStaticBoxSizer *item3 = new wxStaticBoxSizer( item4, wxVERTICAL ); | |
8826f46f | 600 | |
6038ec8e RR |
601 | m_paperTypeChoice = CreatePaperTypeChoice(); |
602 | item3->Add( m_paperTypeChoice, 0, wxALIGN_CENTER|wxALL, 5 ); | |
8826f46f | 603 | |
6038ec8e RR |
604 | item2->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 ); |
605 | ||
2312c9e1 | 606 | wxString strs6[] = |
6038ec8e | 607 | { |
2312c9e1 | 608 | _("Portrait"), |
6038ec8e RR |
609 | _("Landscape") |
610 | }; | |
611 | m_orientationRadioBox= new wxRadioBox( this, wxPRINTID_ORIENTATION, _("Orientation"), wxDefaultPosition, wxDefaultSize, 2, strs6, 1, wxRA_SPECIFY_ROWS ); | |
612 | item2->Add( m_orientationRadioBox, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); | |
8826f46f | 613 | |
2312c9e1 | 614 | wxStaticBox *item8 = new wxStaticBox( this, wxID_ANY, _("Options") ); |
6038ec8e | 615 | wxStaticBoxSizer *item7 = new wxStaticBoxSizer( item8, wxHORIZONTAL ); |
c801d85f | 616 | |
6038ec8e RR |
617 | m_colourCheckBox = new wxCheckBox( this, wxPRINTID_PRINTCOLOUR, _("Print in colour") ); |
618 | item7->Add( m_colourCheckBox, 0, wxALIGN_CENTER|wxALL, 5 ); | |
8826f46f | 619 | |
6038ec8e | 620 | item2->Add( item7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); |
8826f46f | 621 | |
6038ec8e | 622 | item1->Add( item2, 0, wxALIGN_CENTER_HORIZONTAL, 5 ); |
8826f46f | 623 | |
6038ec8e | 624 | // spooling options (on the right) |
8826f46f | 625 | |
2312c9e1 | 626 | wxStaticBox *item11 = new wxStaticBox( this, wxID_ANY, _("Print spooling") ); |
6038ec8e | 627 | wxStaticBoxSizer *item10 = new wxStaticBoxSizer( item11, wxVERTICAL ); |
8826f46f | 628 | |
2312c9e1 | 629 | wxStaticText *item12 = new wxStaticText( this, wxID_ANY, _("Printer command:") ); |
6038ec8e RR |
630 | item10->Add( item12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); |
631 | ||
632 | wxBoxSizer *item13 = new wxBoxSizer( wxHORIZONTAL ); | |
633 | ||
634 | item13->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 ); | |
635 | ||
9548f380 | 636 | m_printerCommandText = new wxTextCtrl( this, wxPRINTID_COMMAND, wxEmptyString, wxDefaultPosition, wxSize(160,wxDefaultCoord) ); |
6038ec8e RR |
637 | item13->Add( m_printerCommandText, 0, wxALIGN_CENTER|wxALL, 5 ); |
638 | ||
639 | item10->Add( item13, 0, wxALIGN_CENTER|wxALL, 0 ); | |
640 | ||
2312c9e1 | 641 | wxStaticText *item15 = new wxStaticText( this, wxID_ANY, _("Printer options:") ); |
6038ec8e RR |
642 | item10->Add( item15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); |
643 | ||
644 | wxBoxSizer *item16 = new wxBoxSizer( wxHORIZONTAL ); | |
645 | ||
646 | item16->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 ); | |
647 | ||
9548f380 | 648 | m_printerOptionsText = new wxTextCtrl( this, wxPRINTID_OPTIONS, wxEmptyString, wxDefaultPosition, wxSize(160,wxDefaultCoord) ); |
6038ec8e RR |
649 | item16->Add( m_printerOptionsText, 0, wxALIGN_CENTER|wxALL, 5 ); |
650 | ||
651 | item10->Add( item16, 0, wxALIGN_CENTER|wxALL, 0 ); | |
652 | ||
653 | item1->Add( item10, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5 ); | |
654 | ||
655 | ||
656 | #if wxUSE_STATLINE | |
657 | // static line | |
2312c9e1 | 658 | main_sizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 ); |
6038ec8e RR |
659 | #endif |
660 | ||
661 | // buttons | |
662 | ||
acf2ac37 | 663 | main_sizer->Add( CreateButtonSizer( wxOK|wxCANCEL), 0, wxEXPAND|wxALL, 10 ); |
6038ec8e RR |
664 | |
665 | SetAutoLayout( true ); | |
666 | SetSizer( main_sizer ); | |
667 | ||
668 | main_sizer->Fit( this ); | |
669 | Centre(wxBOTH); | |
8826f46f | 670 | |
ca65c044 | 671 | |
7bcb11d3 JS |
672 | Fit(); |
673 | Centre(wxBOTH); | |
8826f46f | 674 | |
7bcb11d3 | 675 | InitDialog(); |
c801d85f KB |
676 | } |
677 | ||
7bcb11d3 | 678 | wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog() |
c801d85f KB |
679 | { |
680 | } | |
681 | ||
2c84e0c2 RR |
682 | void wxGenericPrintSetupDialog::OnPrinter(wxListEvent& event) |
683 | { | |
684 | // Delete check mark | |
685 | long item; | |
686 | for (item = 0; item < m_printerListCtrl->GetItemCount(); item++) | |
687 | m_printerListCtrl->SetItemImage( item, -1 ); | |
2312c9e1 | 688 | |
2c84e0c2 | 689 | m_printerListCtrl->SetItemImage( event.GetIndex(), 0 ); |
2312c9e1 | 690 | |
2c84e0c2 RR |
691 | if (event.GetIndex() == 0) |
692 | { | |
693 | m_printerCommandText->SetValue( wxT("lpr") ); | |
694 | } | |
695 | else | |
696 | { | |
697 | wxString tmp = wxT("lpr -P"); | |
698 | wxListItem item; | |
699 | item.SetColumn( 1 ); | |
700 | item.SetMask( wxLIST_MASK_TEXT ); | |
701 | item.SetId( event.GetIndex() ); | |
702 | m_printerListCtrl->GetItem( item ); | |
703 | tmp += item.GetText(); | |
704 | m_printerCommandText->SetValue( tmp ); | |
705 | } | |
706 | } | |
707 | ||
7bcb11d3 | 708 | bool wxGenericPrintSetupDialog::TransferDataToWindow() |
c801d85f | 709 | { |
2312c9e1 | 710 | wxPostScriptPrintNativeData *data = |
8850cbd3 RR |
711 | (wxPostScriptPrintNativeData *) m_printData.GetNativeData(); |
712 | ||
713 | if (m_printerCommandText && data->GetPrinterCommand()) | |
714 | m_printerCommandText->SetValue(data->GetPrinterCommand()); | |
715 | if (m_printerOptionsText && data->GetPrinterOptions()) | |
716 | m_printerOptionsText->SetValue(data->GetPrinterOptions()); | |
7bcb11d3 JS |
717 | if (m_colourCheckBox) |
718 | m_colourCheckBox->SetValue(m_printData.GetColour()); | |
8826f46f | 719 | |
7bcb11d3 JS |
720 | if (m_orientationRadioBox) |
721 | { | |
722 | if (m_printData.GetOrientation() == wxPORTRAIT) | |
723 | m_orientationRadioBox->SetSelection(0); | |
724 | else | |
725 | m_orientationRadioBox->SetSelection(1); | |
726 | } | |
ca65c044 | 727 | return true; |
c801d85f KB |
728 | } |
729 | ||
7bcb11d3 | 730 | bool wxGenericPrintSetupDialog::TransferDataFromWindow() |
c801d85f | 731 | { |
2312c9e1 | 732 | wxPostScriptPrintNativeData *data = |
8850cbd3 RR |
733 | (wxPostScriptPrintNativeData *) m_printData.GetNativeData(); |
734 | ||
2c84e0c2 RR |
735 | // find selected printer |
736 | long id = m_printerListCtrl->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); | |
737 | if (id == 0) | |
738 | { | |
9548f380 | 739 | m_printData.SetPrinterName( wxEmptyString ); |
2c84e0c2 RR |
740 | } |
741 | else | |
742 | { | |
743 | wxListItem item; | |
744 | item.SetId( id ); | |
745 | item.SetMask( wxLIST_MASK_TEXT ); | |
746 | item.SetColumn( 1 ); | |
747 | m_printerListCtrl->GetItem( item ); | |
748 | m_printData.SetPrinterName( item.GetText() ); | |
749 | } | |
750 | ||
7bcb11d3 | 751 | if (m_printerCommandText) |
8850cbd3 | 752 | data->SetPrinterCommand(m_printerCommandText->GetValue()); |
7bcb11d3 | 753 | if (m_printerOptionsText) |
8850cbd3 | 754 | data->SetPrinterOptions(m_printerOptionsText->GetValue()); |
7bcb11d3 JS |
755 | if (m_colourCheckBox) |
756 | m_printData.SetColour(m_colourCheckBox->GetValue()); | |
757 | if (m_orientationRadioBox) | |
758 | { | |
759 | int sel = m_orientationRadioBox->GetSelection(); | |
760 | if (sel == 0) | |
761 | m_printData.SetOrientation(wxPORTRAIT); | |
762 | else | |
763 | m_printData.SetOrientation(wxLANDSCAPE); | |
764 | } | |
765 | if (m_paperTypeChoice) | |
766 | { | |
17dd9caa VZ |
767 | int selectedItem = m_paperTypeChoice->GetSelection(); |
768 | if (selectedItem != -1) | |
769 | { | |
222ed1d6 | 770 | wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(selectedItem); |
17dd9caa VZ |
771 | if (paper != NULL) |
772 | m_printData.SetPaperId( paper->GetId()); | |
773 | } | |
7bcb11d3 JS |
774 | } |
775 | ||
2c84e0c2 RR |
776 | if (m_targetData) |
777 | *m_targetData = m_printData; | |
778 | ||
ca65c044 | 779 | return true; |
c801d85f KB |
780 | } |
781 | ||
6038ec8e | 782 | wxComboBox *wxGenericPrintSetupDialog::CreatePaperTypeChoice() |
c801d85f | 783 | { |
6038ec8e RR |
784 | size_t n = wxThePrintPaperDatabase->GetCount(); |
785 | wxString *choices = new wxString [n]; | |
786 | size_t sel = 0; | |
b1d4dd7a RL |
787 | |
788 | for (size_t i = 0; i < n; i++) | |
7bcb11d3 | 789 | { |
222ed1d6 | 790 | wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i); |
7bcb11d3 JS |
791 | choices[i] = paper->GetName(); |
792 | if (m_printData.GetPaperId() == paper->GetId()) | |
793 | sel = i; | |
794 | } | |
8826f46f | 795 | |
7bcb11d3 JS |
796 | int width = 250; |
797 | ||
b1d4dd7a RL |
798 | wxComboBox *choice = new wxComboBox( this, |
799 | wxPRINTID_PAPERSIZE, | |
800 | _("Paper Size"), | |
6038ec8e | 801 | wxDefaultPosition, |
422d0ff0 | 802 | wxSize(width, wxDefaultCoord), |
b1d4dd7a | 803 | n, choices ); |
7bcb11d3 | 804 | |
7bcb11d3 | 805 | delete[] choices; |
8826f46f | 806 | |
7bcb11d3 JS |
807 | choice->SetSelection(sel); |
808 | return choice; | |
c801d85f | 809 | } |
6038ec8e | 810 | |
8826f46f | 811 | #endif // wxUSE_POSTSCRIPT |
c801d85f | 812 | |
8826f46f VZ |
813 | // ---------------------------------------------------------------------------- |
814 | // Generic page setup dialog | |
815 | // ---------------------------------------------------------------------------- | |
c801d85f | 816 | |
08680429 | 817 | IMPLEMENT_CLASS(wxGenericPageSetupDialog, wxPageSetupDialogBase) |
8850cbd3 | 818 | |
08680429 | 819 | BEGIN_EVENT_TABLE(wxGenericPageSetupDialog, wxPageSetupDialogBase) |
8850cbd3 RR |
820 | EVT_BUTTON(wxPRINTID_SETUP, wxGenericPageSetupDialog::OnPrinter) |
821 | END_EVENT_TABLE() | |
822 | ||
b1d4dd7a | 823 | wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow *parent, |
08680429 RR |
824 | wxPageSetupDialogData* data) |
825 | : wxPageSetupDialogBase( parent, | |
ca65c044 | 826 | wxID_ANY, |
b1d4dd7a | 827 | _("Page Setup"), |
c47addef | 828 | wxPoint(0,0), |
b1d4dd7a | 829 | wxSize(600, 600), |
2a21ac15 | 830 | wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL ) |
c801d85f | 831 | { |
27ea1d8a | 832 | if (data) |
7bcb11d3 | 833 | m_pageData = *data; |
b1d4dd7a | 834 | |
27ea1d8a | 835 | int textWidth = 80; |
b1d4dd7a | 836 | |
27ea1d8a | 837 | wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL ); |
b1d4dd7a | 838 | |
27ea1d8a | 839 | // 1) top |
ca65c044 | 840 | wxStaticBoxSizer *topsizer = new wxStaticBoxSizer( |
27ea1d8a | 841 | new wxStaticBox(this,wxPRINTID_STATIC, _("Paper size")), wxHORIZONTAL ); |
b1d4dd7a RL |
842 | |
843 | size_t n = wxThePrintPaperDatabase->GetCount(); | |
844 | wxString *choices = new wxString [n]; | |
845 | ||
846 | for (size_t i = 0; i < n; i++) | |
27ea1d8a | 847 | { |
222ed1d6 | 848 | wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i); |
27ea1d8a RR |
849 | choices[i] = paper->GetName(); |
850 | } | |
8826f46f | 851 | |
b1d4dd7a RL |
852 | m_paperTypeChoice = new wxComboBox( this, |
853 | wxPRINTID_PAPERSIZE, | |
854 | _("Paper Size"), | |
855 | wxDefaultPosition, | |
422d0ff0 | 856 | wxSize(300, wxDefaultCoord), |
b1d4dd7a | 857 | n, choices ); |
27ea1d8a RR |
858 | topsizer->Add( m_paperTypeChoice, 1, wxEXPAND|wxALL, 5 ); |
859 | // m_paperTypeChoice->SetSelection(sel); | |
8826f46f | 860 | |
27ea1d8a | 861 | mainsizer->Add( topsizer, 0, wxTOP|wxLEFT|wxRIGHT | wxEXPAND, 10 ); |
8826f46f | 862 | |
27ea1d8a | 863 | // 2) middle sizer with radio box |
8826f46f | 864 | |
27ea1d8a RR |
865 | wxString *choices2 = new wxString[2]; |
866 | choices2[0] = _("Portrait"); | |
867 | choices2[1] = _("Landscape"); | |
7bcb11d3 | 868 | m_orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"), |
27ea1d8a | 869 | wxDefaultPosition, wxDefaultSize, 2, choices2, 2); |
7bcb11d3 | 870 | m_orientationRadioBox->SetSelection(0); |
8826f46f | 871 | |
27ea1d8a | 872 | mainsizer->Add( m_orientationRadioBox, 0, wxTOP|wxLEFT|wxRIGHT, 10 ); |
8826f46f | 873 | |
27ea1d8a | 874 | // 3) margins |
8826f46f | 875 | |
27ea1d8a | 876 | wxBoxSizer *table = new wxBoxSizer( wxHORIZONTAL ); |
8826f46f | 877 | |
27ea1d8a RR |
878 | wxBoxSizer *column1 = new wxBoxSizer( wxVERTICAL ); |
879 | column1->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Left margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 ); | |
880 | column1->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Top margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 ); | |
881 | table->Add( column1, 0, wxALL | wxEXPAND, 5 ); | |
ca65c044 | 882 | |
27ea1d8a | 883 | wxBoxSizer *column2 = new wxBoxSizer( wxVERTICAL ); |
422d0ff0 WS |
884 | m_marginLeftText = new wxTextCtrl(this, wxPRINTID_LEFTMARGIN, wxEmptyString, wxDefaultPosition, wxSize(textWidth, wxDefaultCoord)); |
885 | m_marginTopText = new wxTextCtrl(this, wxPRINTID_TOPMARGIN, wxEmptyString, wxDefaultPosition, wxSize(textWidth, wxDefaultCoord)); | |
27ea1d8a RR |
886 | column2->Add( m_marginLeftText, 1, wxALL, 5 ); |
887 | column2->Add( m_marginTopText, 1, wxALL, 5 ); | |
888 | table->Add( column2, 0, wxRIGHT|wxTOP|wxBOTTOM | wxEXPAND, 5 ); | |
ca65c044 | 889 | |
27ea1d8a RR |
890 | wxBoxSizer *column3 = new wxBoxSizer( wxVERTICAL ); |
891 | column3->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Right margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 ); | |
892 | column3->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Bottom margin (mm):")),1,wxALL|wxALIGN_RIGHT,5 ); | |
893 | table->Add( column3, 0, wxALL | wxEXPAND, 5 ); | |
ca65c044 | 894 | |
27ea1d8a | 895 | wxBoxSizer *column4 = new wxBoxSizer( wxVERTICAL ); |
422d0ff0 WS |
896 | m_marginRightText = new wxTextCtrl(this, wxPRINTID_RIGHTMARGIN, wxEmptyString, wxDefaultPosition, wxSize(textWidth, wxDefaultCoord)); |
897 | m_marginBottomText = new wxTextCtrl(this, wxPRINTID_BOTTOMMARGIN, wxEmptyString, wxDefaultPosition, wxSize(textWidth, wxDefaultCoord)); | |
27ea1d8a RR |
898 | column4->Add( m_marginRightText, 1, wxALL, 5 ); |
899 | column4->Add( m_marginBottomText, 1, wxALL, 5 ); | |
900 | table->Add( column4, 0, wxRIGHT|wxTOP|wxBOTTOM | wxEXPAND, 5 ); | |
901 | ||
902 | mainsizer->Add( table, 0 ); | |
903 | ||
904 | #if wxUSE_STATLINE | |
905 | // 5) static line | |
ca65c044 | 906 | mainsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 ); |
27ea1d8a | 907 | #endif |
8826f46f | 908 | |
27ea1d8a | 909 | // 6) buttons |
ca65c044 | 910 | |
27ea1d8a | 911 | wxSizer* buttonsizer = CreateButtonSizer( wxOK|wxCANCEL); |
2312c9e1 | 912 | |
08680429 RR |
913 | if (wxPrintFactory::GetFactory()->HasPrintSetupDialog()) |
914 | { | |
915 | m_printerButton = new wxButton(this, wxPRINTID_SETUP, _("Printer...") ); | |
916 | buttonsizer->Add( m_printerButton, 0, wxLEFT|wxRIGHT, 10 ); | |
917 | if ( !m_pageData.GetEnablePrinter() ) | |
918 | m_printerButton->Enable(false); | |
919 | } | |
920 | else | |
921 | { | |
922 | m_printerButton = NULL; | |
923 | } | |
2312c9e1 | 924 | |
27ea1d8a | 925 | // if (m_printData.GetEnableHelp()) |
422d0ff0 | 926 | // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight); |
acf2ac37 | 927 | mainsizer->Add( buttonsizer, 0, wxEXPAND|wxALL, 10 ); |
8826f46f | 928 | |
8826f46f | 929 | |
ca65c044 | 930 | SetAutoLayout( true ); |
27ea1d8a | 931 | SetSizer( mainsizer ); |
8826f46f | 932 | |
27ea1d8a | 933 | mainsizer->Fit( this ); |
7bcb11d3 | 934 | Centre(wxBOTH); |
8826f46f | 935 | |
7bcb11d3 | 936 | InitDialog(); |
ca65c044 | 937 | |
27ea1d8a RR |
938 | delete[] choices; |
939 | delete [] choices2; | |
7bcb11d3 | 940 | } |
9838df2c | 941 | |
7bcb11d3 JS |
942 | wxGenericPageSetupDialog::~wxGenericPageSetupDialog() |
943 | { | |
944 | } | |
c801d85f | 945 | |
08680429 | 946 | wxPageSetupDialogData& wxGenericPageSetupDialog::GetPageSetupDialogData() |
2312c9e1 | 947 | { |
08680429 RR |
948 | return m_pageData; |
949 | } | |
950 | ||
7bcb11d3 JS |
951 | bool wxGenericPageSetupDialog::TransferDataToWindow() |
952 | { | |
953 | if (m_marginLeftText) | |
963907fa | 954 | m_marginLeftText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginTopLeft().x)); |
7bcb11d3 | 955 | if (m_marginTopText) |
963907fa | 956 | m_marginTopText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginTopLeft().y)); |
7bcb11d3 | 957 | if (m_marginRightText) |
963907fa | 958 | m_marginRightText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginBottomRight().x)); |
7bcb11d3 | 959 | if (m_marginBottomText) |
963907fa | 960 | m_marginBottomText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginBottomRight().y)); |
8826f46f | 961 | |
7bcb11d3 JS |
962 | if (m_orientationRadioBox) |
963 | { | |
964 | if (m_pageData.GetPrintData().GetOrientation() == wxPORTRAIT) | |
965 | m_orientationRadioBox->SetSelection(0); | |
966 | else | |
967 | m_orientationRadioBox->SetSelection(1); | |
968 | } | |
c801d85f | 969 | |
7bcb11d3 JS |
970 | // Find the paper type from either the current paper size in the wxPageSetupDialogData, or |
971 | // failing that, the id in the wxPrintData object. | |
c801d85f | 972 | |
7bcb11d3 JS |
973 | wxPrintPaperType* type = wxThePrintPaperDatabase->FindPaperType( |
974 | wxSize(m_pageData.GetPaperSize().x * 10, m_pageData.GetPaperSize().y * 10)); | |
c801d85f | 975 | |
7bcb11d3 JS |
976 | if (!type && m_pageData.GetPrintData().GetPaperId() != wxPAPER_NONE) |
977 | type = wxThePrintPaperDatabase->FindPaperType(m_pageData.GetPrintData().GetPaperId()); | |
c801d85f | 978 | |
7bcb11d3 JS |
979 | if (type) |
980 | { | |
981 | m_paperTypeChoice->SetStringSelection(type->GetName()); | |
982 | } | |
c801d85f | 983 | |
ca65c044 | 984 | return true; |
c801d85f KB |
985 | } |
986 | ||
7bcb11d3 | 987 | bool wxGenericPageSetupDialog::TransferDataFromWindow() |
c801d85f | 988 | { |
7bcb11d3 | 989 | if (m_marginLeftText && m_marginTopText) |
eba33006 RR |
990 | { |
991 | int left = wxAtoi( m_marginLeftText->GetValue().c_str() ); | |
992 | int top = wxAtoi( m_marginTopText->GetValue().c_str() ); | |
993 | m_pageData.SetMarginTopLeft( wxPoint(left,top) ); | |
994 | } | |
7bcb11d3 | 995 | if (m_marginRightText && m_marginBottomText) |
eba33006 RR |
996 | { |
997 | int right = wxAtoi( m_marginRightText->GetValue().c_str() ); | |
998 | int bottom = wxAtoi( m_marginBottomText->GetValue().c_str() ); | |
999 | m_pageData.SetMarginBottomRight( wxPoint(right,bottom) ); | |
1000 | } | |
8826f46f | 1001 | |
7bcb11d3 | 1002 | if (m_orientationRadioBox) |
c801d85f | 1003 | { |
7bcb11d3 JS |
1004 | int sel = m_orientationRadioBox->GetSelection(); |
1005 | if (sel == 0) | |
1006 | { | |
7bcb11d3 JS |
1007 | m_pageData.GetPrintData().SetOrientation(wxPORTRAIT); |
1008 | } | |
1009 | else | |
1010 | { | |
7bcb11d3 JS |
1011 | m_pageData.GetPrintData().SetOrientation(wxLANDSCAPE); |
1012 | } | |
c801d85f | 1013 | } |
ca65c044 | 1014 | |
7bcb11d3 | 1015 | if (m_paperTypeChoice) |
c801d85f | 1016 | { |
17dd9caa VZ |
1017 | int selectedItem = m_paperTypeChoice->GetSelection(); |
1018 | if (selectedItem != -1) | |
c801d85f | 1019 | { |
222ed1d6 | 1020 | wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(selectedItem); |
7bcb11d3 JS |
1021 | if ( paper ) |
1022 | { | |
1023 | m_pageData.SetPaperSize(wxSize(paper->GetWidth()/10, paper->GetHeight()/10)); | |
1024 | m_pageData.GetPrintData().SetPaperId(paper->GetId()); | |
1025 | } | |
c801d85f KB |
1026 | } |
1027 | } | |
8826f46f | 1028 | |
ca65c044 | 1029 | return true; |
c801d85f KB |
1030 | } |
1031 | ||
fa12f7e6 | 1032 | wxComboBox *wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x, int *y) |
c801d85f | 1033 | { |
7bcb11d3 JS |
1034 | /* |
1035 | if (!wxThePrintPaperDatabase) | |
1036 | { | |
1037 | wxThePrintPaperDatabase = new wxPrintPaperDatabase; | |
1038 | wxThePrintPaperDatabase->CreateDatabase(); | |
1039 | } | |
1040 | */ | |
1041 | ||
b1d4dd7a RL |
1042 | size_t n = wxThePrintPaperDatabase->GetCount(); |
1043 | wxString *choices = new wxString [n]; | |
1044 | ||
1045 | for (size_t i = 0; i < n; i++) | |
7bcb11d3 | 1046 | { |
222ed1d6 | 1047 | wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i); |
7bcb11d3 JS |
1048 | choices[i] = paper->GetName(); |
1049 | } | |
8826f46f | 1050 | |
7bcb11d3 JS |
1051 | (void) new wxStaticText(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(*x, *y)); |
1052 | *y += 25; | |
8826f46f | 1053 | |
b1d4dd7a RL |
1054 | wxComboBox *choice = new wxComboBox( this, |
1055 | wxPRINTID_PAPERSIZE, | |
1056 | _("Paper Size"), | |
1057 | wxPoint(*x, *y), | |
422d0ff0 | 1058 | wxSize(300, wxDefaultCoord), |
b1d4dd7a | 1059 | n, choices ); |
7bcb11d3 JS |
1060 | *y += 35; |
1061 | delete[] choices; | |
8826f46f | 1062 | |
7bcb11d3 JS |
1063 | // choice->SetSelection(sel); |
1064 | return choice; | |
c801d85f KB |
1065 | } |
1066 | ||
08680429 RR |
1067 | void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent& WXUNUSED(event)) |
1068 | { | |
1069 | // We no longer query GetPrintMode, so we can eliminate the need | |
1070 | // to call SetPrintMode. | |
1071 | // This has the limitation that we can't explicitly call the PostScript | |
1072 | // print setup dialog from the generic Page Setup dialog under Windows, | |
1073 | // but since this choice would only happen when trying to do PostScript | |
1074 | // printing under Windows (and only in 16-bit Windows which | |
1075 | // doesn't have a Windows-specific page setup dialog) it's worth it. | |
1076 | ||
1077 | // First save the current settings, so the wxPrintData object is up to date. | |
1078 | TransferDataFromWindow(); | |
1079 | ||
1080 | // Transfer the current print settings from this dialog to the page setup dialog. | |
2312c9e1 | 1081 | |
08680429 | 1082 | #if 0 |
2312c9e1 WS |
1083 | // Use print factory later |
1084 | ||
08680429 RR |
1085 | wxPrintDialogData data; |
1086 | data = GetPageSetupData().GetPrintData(); | |
1087 | data.SetSetupDialog(true); | |
1088 | wxPrintDialog printDialog(this, & data); | |
1089 | printDialog.ShowModal(); | |
1090 | ||
1091 | // Transfer the page setup print settings from the page dialog to this dialog again, in case | |
1092 | // the page setup dialog changed something. | |
1093 | GetPageSetupData().GetPrintData() = printDialog.GetPrintDialogData().GetPrintData(); | |
1094 | GetPageSetupData().CalculatePaperSizeFromId(); // Make sure page size reflects the id in wxPrintData | |
1095 | ||
1096 | // Now update the dialog in case the page setup dialog changed some of our settings. | |
1097 | TransferDataToWindow(); | |
1098 | #endif | |
1099 | } | |
1100 | ||
ce4169a4 | 1101 | #endif |
eba33006 | 1102 |