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