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