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