]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/generic/prntdlgg.cpp
gdk_window_copy_area(drawable,gc,x,y,source_drawable,source_x,source_y,width,height) ->
[wxWidgets.git] / src / generic / prntdlgg.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: prntdlgg.cpp
3// Purpose: Generic print dialogs
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
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#ifndef WX_PRECOMP
30 #include "wx/utils.h"
31 #include "wx/dc.h"
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"
39 #include "wx/combobox.h"
40 #include "wx/intl.h"
41 #include "wx/sizer.h"
42 #include "wx/cmndata.h"
43#endif
44
45#if wxUSE_STATLINE
46 #include "wx/statline.h"
47#endif
48
49#include "wx/generic/prntdlgg.h"
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/html/forcelnk.h"
67FORCE_LINK(gnome_print)
68#endif
69
70// ----------------------------------------------------------------------------
71// global vars
72// ----------------------------------------------------------------------------
73
74extern wxPrintPaperDatabase *wxThePrintPaperDatabase;
75
76#if wxUSE_POSTSCRIPT
77
78//----------------------------------------------------------------------------
79// wxPostScriptNativeData
80//----------------------------------------------------------------------------
81
82IMPLEMENT_CLASS(wxPostScriptPrintNativeData, wxPrintNativeDataBase)
83
84wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
85{
86 m_previewCommand = wxEmptyString;
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
92
93#ifdef __WXMSW__
94 m_printerCommand = wxT("print");
95 m_printerOptions = wxEmptyString;
96 m_afmPath = wxT("c:\\windows\\system\\");
97#endif
98
99#if !defined(__VMS__) && !defined(__WXMSW__)
100 m_printerCommand = wxT("lpr");
101 m_printerOptions = wxEmptyString;
102 m_afmPath = wxEmptyString;
103#endif
104
105 m_printerScaleX = 1.0;
106 m_printerScaleY = 1.0;
107 m_printerTranslateX = 0;
108 m_printerTranslateY = 0;
109}
110
111wxPostScriptPrintNativeData::~wxPostScriptPrintNativeData()
112{
113}
114
115bool wxPostScriptPrintNativeData::TransferTo( wxPrintData &WXUNUSED(data) )
116{
117 return true;
118}
119
120bool wxPostScriptPrintNativeData::TransferFrom( const wxPrintData &WXUNUSED(data) )
121{
122 return true;
123}
124
125// ----------------------------------------------------------------------------
126// Generic print dialog for non-Windows printing use.
127// ----------------------------------------------------------------------------
128
129IMPLEMENT_CLASS(wxGenericPrintDialog, wxPrintDialogBase)
130
131BEGIN_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)
135END_EVENT_TABLE()
136
137wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
138 wxPrintDialogData* data)
139 : wxPrintDialogBase(parent, wxID_ANY, _("Print"),
140 wxPoint(0,0), wxSize(600, 600),
141 wxDEFAULT_DIALOG_STYLE |
142 wxTAB_TRAVERSAL)
143{
144 if ( data )
145 m_printDialogData = *data;
146
147 Init(parent);
148}
149
150wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
151 wxPrintData* data)
152 : wxPrintDialogBase(parent, wxID_ANY, _("Print"),
153 wxPoint(0,0), wxSize(600, 600),
154 wxDEFAULT_DIALOG_STYLE |
155 wxTAB_TRAVERSAL)
156{
157 if ( data )
158 m_printDialogData = *data;
159
160 Init(parent);
161}
162
163void wxGenericPrintDialog::Init(wxWindow * WXUNUSED(parent))
164{
165 // wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0,0), wxSize(600, 600),
166 // wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL);
167
168 wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
169
170 // 1) top row
171
172 wxPrintFactory* factory = wxPrintFactory::GetFactory();
173
174 wxStaticBoxSizer *topsizer = new wxStaticBoxSizer(
175 new wxStaticBox( this, wxID_ANY, _( "Printer options" ) ), wxHORIZONTAL );
176 wxFlexGridSizer *flex = new wxFlexGridSizer( 2 );
177 flex->AddGrowableCol( 1 );
178 topsizer->Add( flex, 1, wxGROW );
179
180 m_printToFileCheckBox = new wxCheckBox( this, wxPRINTID_PRINTTOFILE, _("Print to File") );
181 flex->Add( m_printToFileCheckBox, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
182
183 m_setupButton = new wxButton(this, wxPRINTID_SETUP, _("Setup...") );
184 flex->Add( m_setupButton, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
185
186 if (!factory->HasPrintSetupDialog())
187 m_setupButton->Enable( false );
188
189 if (factory->HasPrinterLine())
190 {
191 flex->Add( new wxStaticText( this, wxID_ANY, _("Printer:") ),
192 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
193 flex->Add( new wxStaticText( this, wxID_ANY, factory->CreatePrinterLine() ),
194 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
195 }
196
197 if (factory->HasStatusLine())
198 {
199 flex->Add( new wxStaticText( this, wxID_ANY, _("Status:") ),
200 0, wxALIGN_CENTER_VERTICAL|wxALL-wxTOP, 5 );
201 flex->Add( new wxStaticText( this, wxID_ANY, factory->CreateStatusLine() ),
202 0, wxALIGN_CENTER_VERTICAL|wxALL-wxTOP, 5 );
203 }
204
205 mainsizer->Add( topsizer, 0, wxLEFT|wxTOP|wxRIGHT|wxGROW, 10 );
206
207 // 2) middle row with radio box
208
209 wxString *choices = new wxString[2];
210 choices[0] = _("All");
211 choices[1] = _("Pages");
212
213 m_fromText = (wxTextCtrl*)NULL;
214 m_toText = (wxTextCtrl*)NULL;
215 m_rangeRadioBox = (wxRadioBox *)NULL;
216
217 if (m_printDialogData.GetFromPage() != 0)
218 {
219 m_rangeRadioBox = new wxRadioBox(this, wxPRINTID_RANGE, _("Print Range"),
220 wxDefaultPosition, wxDefaultSize,
221 2, choices,
222 1, wxRA_VERTICAL);
223 m_rangeRadioBox->SetSelection(1);
224
225 mainsizer->Add( m_rangeRadioBox, 0, wxLEFT|wxTOP|wxRIGHT, 10 );
226 }
227
228 // 3) bottom row
229
230 wxBoxSizer *bottomsizer = new wxBoxSizer( wxHORIZONTAL );
231
232 if (m_printDialogData.GetFromPage() != 0)
233 {
234 bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("From:") ), 0, wxCENTER|wxALL, 5 );
235 m_fromText = new wxTextCtrl(this, wxPRINTID_FROM, wxEmptyString, wxDefaultPosition, wxSize(40, wxDefaultCoord));
236 bottomsizer->Add( m_fromText, 1, wxCENTER|wxRIGHT, 10 );
237
238 bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("To:") ), 0, wxCENTER|wxALL, 5);
239 m_toText = new wxTextCtrl(this, wxPRINTID_TO, wxEmptyString, wxDefaultPosition, wxSize(40, wxDefaultCoord));
240 bottomsizer->Add( m_toText, 1, wxCENTER|wxRIGHT, 10 );
241 }
242
243 bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Copies:") ), 0, wxCENTER|wxALL, 5 );
244 m_noCopiesText = new wxTextCtrl(this, wxPRINTID_COPIES, wxEmptyString, wxPoint(252, 130), wxSize(40, wxDefaultCoord));
245 bottomsizer->Add( m_noCopiesText, 1, wxCENTER|wxRIGHT, 10 );
246
247 mainsizer->Add( bottomsizer, 0, wxTOP|wxLEFT|wxRIGHT, 12 );
248
249#if wxUSE_STATLINE
250 // 4) static line
251 mainsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
252#endif
253
254 // 5) buttons
255
256 mainsizer->Add( CreateButtonSizer( wxOK|wxCANCEL), 0, wxEXPAND|wxALL, 10 );
257
258 SetAutoLayout( true );
259 SetSizer( mainsizer );
260
261 mainsizer->Fit( this );
262 Centre(wxBOTH);
263
264 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
265 InitDialog();
266 delete[] choices;
267}
268
269int wxGenericPrintDialog::ShowModal()
270{
271 return wxDialog::ShowModal();
272}
273
274wxGenericPrintDialog::~wxGenericPrintDialog()
275{
276}
277
278void wxGenericPrintDialog::OnOK(wxCommandEvent& WXUNUSED(event))
279{
280 TransferDataFromWindow();
281
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
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 {
293 m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE);
294
295 wxFileName fname( m_printDialogData.GetPrintData().GetFilename() );
296
297 wxFileDialog dialog( this, _("PostScript file"),
298 fname.GetPath(), fname.GetFullName(), wxT("*.ps"), wxSAVE | wxOVERWRITE_PROMPT );
299 if (dialog.ShowModal() != wxID_OK) return;
300
301 m_printDialogData.GetPrintData().SetFilename( dialog.GetPath() );
302 }
303 else
304 {
305 m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER);
306 }
307
308 EndModal(wxID_OK);
309}
310
311void wxGenericPrintDialog::OnRange(wxCommandEvent& event)
312{
313 if (!m_fromText) return;
314
315 if (event.GetInt() == 0)
316 {
317 m_fromText->Enable(false);
318 m_toText->Enable(false);
319 }
320 else if (event.GetInt() == 1)
321 {
322 m_fromText->Enable(true);
323 m_toText->Enable(true);
324 }
325}
326
327void wxGenericPrintDialog::OnSetup(wxCommandEvent& WXUNUSED(event))
328{
329 wxPrintFactory* factory = wxPrintFactory::GetFactory();
330
331 if (factory->HasPrintSetupDialog())
332 {
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();
338 }
339}
340
341bool wxGenericPrintDialog::TransferDataToWindow()
342{
343 if(m_printDialogData.GetFromPage() != 0)
344 {
345 if(m_fromText)
346 {
347 if (m_printDialogData.GetEnablePageNumbers())
348 {
349 m_fromText->Enable(true);
350 m_toText->Enable(true);
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()));
355 if(m_rangeRadioBox)
356 if (m_printDialogData.GetAllPages() || m_printDialogData.GetFromPage() == 0)
357 m_rangeRadioBox->SetSelection(0);
358 else
359 m_rangeRadioBox->SetSelection(1);
360 }
361 else
362 {
363 m_fromText->Enable(false);
364 m_toText->Enable(false);
365 if(m_rangeRadioBox)
366 {
367 m_rangeRadioBox->SetSelection(0);
368 m_rangeRadioBox->wxRadioBox::Enable(1, false);
369 }
370 }
371 }
372 }
373 m_noCopiesText->SetValue(
374 wxString::Format(_T("%d"), m_printDialogData.GetNoCopies()));
375
376 m_printToFileCheckBox->SetValue(m_printDialogData.GetPrintToFile());
377 m_printToFileCheckBox->Enable(m_printDialogData.GetEnablePrintToFile());
378 return true;
379}
380
381bool wxGenericPrintDialog::TransferDataFromWindow()
382{
383 long res = 0;
384 if(m_printDialogData.GetFromPage() != -1)
385 {
386 if (m_printDialogData.GetEnablePageNumbers())
387 {
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)
395 {
396 wxString value = m_toText->GetValue();
397 if (value.ToLong( &res ))
398 m_printDialogData.SetToPage( res );
399 }
400 }
401 if(m_rangeRadioBox)
402 {
403 if (m_rangeRadioBox->GetSelection() == 0)
404 {
405 m_printDialogData.SetAllPages(true);
406
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);
413 }
414 }
415 else
416 { // continuous printing
417 m_printDialogData.SetFromPage(1);
418 m_printDialogData.SetToPage(32000);
419 }
420
421 wxString value = m_noCopiesText->GetValue();
422 if (value.ToLong( &res ))
423 m_printDialogData.SetNoCopies( res );
424
425 m_printDialogData.SetPrintToFile(m_printToFileCheckBox->GetValue());
426
427 return true;
428}
429
430wxDC *wxGenericPrintDialog::GetPrintDC()
431{
432 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
433}
434
435// ----------------------------------------------------------------------------
436// Generic print setup dialog
437// ----------------------------------------------------------------------------
438
439IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog)
440
441BEGIN_EVENT_TABLE(wxGenericPrintSetupDialog, wxDialog)
442 EVT_LIST_ITEM_ACTIVATED(wxPRINTID_PRINTER, wxGenericPrintSetupDialog::OnPrinter)
443END_EVENT_TABLE()
444
445wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintData* data):
446wxDialog(parent, wxID_ANY, _("Print Setup"), wxPoint(0,0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL)
447{
448 Init(data);
449}
450
451/* XPM */
452static const char * check_xpm[] = {
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
479void wxGenericPrintSetupDialog::Init(wxPrintData* data)
480{
481 if ( data )
482 m_printData = *data;
483
484 m_targetData = data;
485
486 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
487
488 // printer selection
489
490 wxStaticBoxSizer *printer_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Printer") ), wxVERTICAL );
491 main_sizer->Add( printer_sizer, 0, wxALL|wxGROW, 10 );
492
493 m_printerListCtrl = new wxListCtrl( this, wxPRINTID_PRINTER,
494 wxDefaultPosition, wxSize(wxDefaultCoord,100), wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER );
495 wxImageList *image_list = new wxImageList;
496 image_list->Add( wxBitmap(check_xpm) );
497 m_printerListCtrl->AssignImageList( image_list, wxIMAGE_LIST_SMALL );
498
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
510 if (data->GetPrinterName().empty())
511 {
512 wxListItem item2;
513 item2.SetId( item.GetId() );
514 item2.SetMask( wxLIST_MASK_IMAGE );
515 item2.SetImage( 0 );
516 m_printerListCtrl->SetItem( item2 );
517 // also select item
518 m_printerListCtrl->SetItemState( item.GetId(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
519 }
520
521 item.SetId( 1+ item.GetId() );
522
523 wxArrayString errors;
524 wxArrayString output;
525 long res = wxExecute( wxT("lpstat -v"), output, errors, wxEXEC_NODISABLE );
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 );
555 // also select item
556 m_printerListCtrl->SetItemState( item.GetId(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
557 }
558
559 wxString command = wxT("lpstat -p ");
560 command += name;
561 wxArrayString errors2;
562 wxArrayString output2;
563 res = wxExecute( command, output2, errors2, wxEXEC_NODISABLE );
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('.') );
568 if (pos != wxNOT_FOUND)
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"
573 tmp = wxEmptyString;
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 }
583
584 item.SetColumn( 1 );
585 item.SetId( 1+ item.GetId() );
586 }
587 }
588
589
590 printer_sizer->Add( m_printerListCtrl, 0, wxALL|wxGROW, 5 );
591
592 wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
593 main_sizer->Add( item1, 0, wxALL, 5 );
594
595 // printer options (on the left)
596
597 wxBoxSizer *item2 = new wxBoxSizer( wxVERTICAL );
598
599 wxStaticBox *item4 = new wxStaticBox( this, wxPRINTID_STATIC, _("Paper size") );
600 wxStaticBoxSizer *item3 = new wxStaticBoxSizer( item4, wxVERTICAL );
601
602 m_paperTypeChoice = CreatePaperTypeChoice();
603 item3->Add( m_paperTypeChoice, 0, wxALIGN_CENTER|wxALL, 5 );
604
605 item2->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
606
607 wxString strs6[] =
608 {
609 _("Portrait"),
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 );
614
615 wxStaticBox *item8 = new wxStaticBox( this, wxID_ANY, _("Options") );
616 wxStaticBoxSizer *item7 = new wxStaticBoxSizer( item8, wxHORIZONTAL );
617
618 m_colourCheckBox = new wxCheckBox( this, wxPRINTID_PRINTCOLOUR, _("Print in colour") );
619 item7->Add( m_colourCheckBox, 0, wxALIGN_CENTER|wxALL, 5 );
620
621 item2->Add( item7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
622
623 item1->Add( item2, 0, wxALIGN_CENTER_HORIZONTAL, 5 );
624
625 // spooling options (on the right)
626
627 wxStaticBox *item11 = new wxStaticBox( this, wxID_ANY, _("Print spooling") );
628 wxStaticBoxSizer *item10 = new wxStaticBoxSizer( item11, wxVERTICAL );
629
630 wxStaticText *item12 = new wxStaticText( this, wxID_ANY, _("Printer command:") );
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
637 m_printerCommandText = new wxTextCtrl( this, wxPRINTID_COMMAND, wxEmptyString, wxDefaultPosition, wxSize(160,wxDefaultCoord) );
638 item13->Add( m_printerCommandText, 0, wxALIGN_CENTER|wxALL, 5 );
639
640 item10->Add( item13, 0, wxALIGN_CENTER|wxALL, 0 );
641
642 wxStaticText *item15 = new wxStaticText( this, wxID_ANY, _("Printer options:") );
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
649 m_printerOptionsText = new wxTextCtrl( this, wxPRINTID_OPTIONS, wxEmptyString, wxDefaultPosition, wxSize(160,wxDefaultCoord) );
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
659 main_sizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
660#endif
661
662 // buttons
663
664 main_sizer->Add( CreateButtonSizer( wxOK|wxCANCEL), 0, wxEXPAND|wxALL, 10 );
665
666 SetAutoLayout( true );
667 SetSizer( main_sizer );
668
669 main_sizer->Fit( this );
670 Centre(wxBOTH);
671
672
673 Fit();
674 Centre(wxBOTH);
675
676 InitDialog();
677}
678
679wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
680{
681}
682
683void wxGenericPrintSetupDialog::OnPrinter(wxListEvent& event)
684{
685 // Delete check mark
686 for (long item = 0; item < m_printerListCtrl->GetItemCount(); item++)
687 m_printerListCtrl->SetItemImage( item, -1 );
688
689 m_printerListCtrl->SetItemImage( event.GetIndex(), 0 );
690
691 if (event.GetIndex() == 0)
692 {
693 m_printerCommandText->SetValue( wxT("lpr") );
694 }
695 else
696 {
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() );
703 }
704}
705
706bool wxGenericPrintSetupDialog::TransferDataToWindow()
707{
708 wxPostScriptPrintNativeData *data =
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());
715 if (m_colourCheckBox)
716 m_colourCheckBox->SetValue(m_printData.GetColour());
717
718 if (m_orientationRadioBox)
719 {
720 if (m_printData.GetOrientation() == wxPORTRAIT)
721 m_orientationRadioBox->SetSelection(0);
722 else
723 m_orientationRadioBox->SetSelection(1);
724 }
725 return true;
726}
727
728bool wxGenericPrintSetupDialog::TransferDataFromWindow()
729{
730 wxPostScriptPrintNativeData *data =
731 (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
732
733 // find selected printer
734 long id = m_printerListCtrl->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
735 if (id == 0)
736 {
737 m_printData.SetPrinterName( wxEmptyString );
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
749 if (m_printerCommandText)
750 data->SetPrinterCommand(m_printerCommandText->GetValue());
751 if (m_printerOptionsText)
752 data->SetPrinterOptions(m_printerOptionsText->GetValue());
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 {
765 int selectedItem = m_paperTypeChoice->GetSelection();
766 if (selectedItem != -1)
767 {
768 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(selectedItem);
769 if (paper != NULL)
770 m_printData.SetPaperId( paper->GetId());
771 }
772 }
773
774 if (m_targetData)
775 *m_targetData = m_printData;
776
777 return true;
778}
779
780wxComboBox *wxGenericPrintSetupDialog::CreatePaperTypeChoice()
781{
782 size_t n = wxThePrintPaperDatabase->GetCount();
783 wxString *choices = new wxString [n];
784 size_t sel = 0;
785
786 for (size_t i = 0; i < n; i++)
787 {
788 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
789 choices[i] = paper->GetName();
790 if (m_printData.GetPaperId() == paper->GetId())
791 sel = i;
792 }
793
794 int width = 250;
795
796 wxComboBox *choice = new wxComboBox( this,
797 wxPRINTID_PAPERSIZE,
798 _("Paper Size"),
799 wxDefaultPosition,
800 wxSize(width, wxDefaultCoord),
801 n, choices );
802
803 delete[] choices;
804
805 choice->SetSelection(sel);
806 return choice;
807}
808
809#endif // wxUSE_POSTSCRIPT
810
811// ----------------------------------------------------------------------------
812// Generic page setup dialog
813// ----------------------------------------------------------------------------
814
815IMPLEMENT_CLASS(wxGenericPageSetupDialog, wxPageSetupDialogBase)
816
817BEGIN_EVENT_TABLE(wxGenericPageSetupDialog, wxPageSetupDialogBase)
818 EVT_BUTTON(wxPRINTID_SETUP, wxGenericPageSetupDialog::OnPrinter)
819END_EVENT_TABLE()
820
821wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow *parent,
822 wxPageSetupDialogData* data)
823 : wxPageSetupDialogBase( parent,
824 wxID_ANY,
825 _("Page Setup"),
826 wxPoint(0,0),
827 wxSize(600, 600),
828 wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL )
829{
830 if (data)
831 m_pageData = *data;
832
833 int textWidth = 80;
834
835 wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
836
837 // 1) top
838 wxStaticBoxSizer *topsizer = new wxStaticBoxSizer(
839 new wxStaticBox(this,wxPRINTID_STATIC, _("Paper size")), wxHORIZONTAL );
840
841 size_t n = wxThePrintPaperDatabase->GetCount();
842 wxString *choices = new wxString [n];
843
844 for (size_t i = 0; i < n; i++)
845 {
846 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
847 choices[i] = paper->GetName();
848 }
849
850 m_paperTypeChoice = new wxComboBox( this,
851 wxPRINTID_PAPERSIZE,
852 _("Paper Size"),
853 wxDefaultPosition,
854 wxSize(300, wxDefaultCoord),
855 n, choices );
856 topsizer->Add( m_paperTypeChoice, 1, wxEXPAND|wxALL, 5 );
857// m_paperTypeChoice->SetSelection(sel);
858
859 mainsizer->Add( topsizer, 0, wxTOP|wxLEFT|wxRIGHT | wxEXPAND, 10 );
860
861 // 2) middle sizer with radio box
862
863 wxString *choices2 = new wxString[2];
864 choices2[0] = _("Portrait");
865 choices2[1] = _("Landscape");
866 m_orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"),
867 wxDefaultPosition, wxDefaultSize, 2, choices2, 2);
868 m_orientationRadioBox->SetSelection(0);
869
870 mainsizer->Add( m_orientationRadioBox, 0, wxTOP|wxLEFT|wxRIGHT, 10 );
871
872 // 3) margins
873
874 wxBoxSizer *table = new wxBoxSizer( wxHORIZONTAL );
875
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 );
880
881 wxBoxSizer *column2 = new wxBoxSizer( wxVERTICAL );
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));
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 );
887
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 );
892
893 wxBoxSizer *column4 = new wxBoxSizer( wxVERTICAL );
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));
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
904 mainsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
905#endif
906
907 // 6) buttons
908
909 wxSizer* buttonsizer = CreateButtonSizer( wxOK|wxCANCEL);
910
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 }
922
923 // if (m_printData.GetEnableHelp())
924 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight);
925 mainsizer->Add( buttonsizer, 0, wxEXPAND|wxALL, 10 );
926
927
928 SetAutoLayout( true );
929 SetSizer( mainsizer );
930
931 mainsizer->Fit( this );
932 Centre(wxBOTH);
933
934 InitDialog();
935
936 delete[] choices;
937 delete [] choices2;
938}
939
940wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
941{
942}
943
944wxPageSetupDialogData& wxGenericPageSetupDialog::GetPageSetupDialogData()
945{
946 return m_pageData;
947}
948
949bool wxGenericPageSetupDialog::TransferDataToWindow()
950{
951 if (m_marginLeftText)
952 m_marginLeftText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginTopLeft().x));
953 if (m_marginTopText)
954 m_marginTopText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginTopLeft().y));
955 if (m_marginRightText)
956 m_marginRightText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginBottomRight().x));
957 if (m_marginBottomText)
958 m_marginBottomText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginBottomRight().y));
959
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 }
967
968 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
969 // failing that, the id in the wxPrintData object.
970
971 wxPrintPaperType* type = wxThePrintPaperDatabase->FindPaperType(
972 wxSize(m_pageData.GetPaperSize().x * 10, m_pageData.GetPaperSize().y * 10));
973
974 if (!type && m_pageData.GetPrintData().GetPaperId() != wxPAPER_NONE)
975 type = wxThePrintPaperDatabase->FindPaperType(m_pageData.GetPrintData().GetPaperId());
976
977 if (type)
978 {
979 m_paperTypeChoice->SetStringSelection(type->GetName());
980 }
981
982 return true;
983}
984
985bool wxGenericPageSetupDialog::TransferDataFromWindow()
986{
987 if (m_marginLeftText && m_marginTopText)
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 }
993 if (m_marginRightText && m_marginBottomText)
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 }
999
1000 if (m_orientationRadioBox)
1001 {
1002 int sel = m_orientationRadioBox->GetSelection();
1003 if (sel == 0)
1004 {
1005 m_pageData.GetPrintData().SetOrientation(wxPORTRAIT);
1006 }
1007 else
1008 {
1009 m_pageData.GetPrintData().SetOrientation(wxLANDSCAPE);
1010 }
1011 }
1012
1013 if (m_paperTypeChoice)
1014 {
1015 int selectedItem = m_paperTypeChoice->GetSelection();
1016 if (selectedItem != -1)
1017 {
1018 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(selectedItem);
1019 if ( paper )
1020 {
1021 m_pageData.SetPaperSize(wxSize(paper->GetWidth()/10, paper->GetHeight()/10));
1022 m_pageData.GetPrintData().SetPaperId(paper->GetId());
1023 }
1024 }
1025 }
1026
1027 return true;
1028}
1029
1030wxComboBox *wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x, int *y)
1031{
1032/*
1033 if (!wxThePrintPaperDatabase)
1034 {
1035 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
1036 wxThePrintPaperDatabase->CreateDatabase();
1037 }
1038*/
1039
1040 size_t n = wxThePrintPaperDatabase->GetCount();
1041 wxString *choices = new wxString [n];
1042
1043 for (size_t i = 0; i < n; i++)
1044 {
1045 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
1046 choices[i] = paper->GetName();
1047 }
1048
1049 (void) new wxStaticText(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(*x, *y));
1050 *y += 25;
1051
1052 wxComboBox *choice = new wxComboBox( this,
1053 wxPRINTID_PAPERSIZE,
1054 _("Paper Size"),
1055 wxPoint(*x, *y),
1056 wxSize(300, wxDefaultCoord),
1057 n, choices );
1058 *y += 35;
1059 delete[] choices;
1060
1061// choice->SetSelection(sel);
1062 return choice;
1063}
1064
1065void 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.
1079
1080#if 0
1081 // Use print factory later
1082
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
1099#endif
1100