]> git.saurik.com Git - wxWidgets.git/blame - src/generic/prntdlgg.cpp
forward port from 2.8
[wxWidgets.git] / src / generic / prntdlgg.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
54a7425b 2// Name: src/generic/prntdlgg.cpp
c801d85f
KB
3// Purpose: Generic print dialogs
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6aa89a22 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
8826f46f
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
c801d85f
KB
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
8826f46f 24 #pragma hdrstop
c801d85f
KB
25#endif
26
aba17e09 27#if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
ce4169a4 28
09a09455
PC
29#include "wx/generic/prntdlgg.h"
30
c801d85f 31#ifndef WX_PRECOMP
8826f46f
VZ
32 #include "wx/utils.h"
33 #include "wx/dc.h"
8826f46f
VZ
34 #include "wx/stattext.h"
35 #include "wx/statbox.h"
36 #include "wx/button.h"
37 #include "wx/checkbox.h"
38 #include "wx/textctrl.h"
39 #include "wx/radiobox.h"
40 #include "wx/filedlg.h"
fa12f7e6 41 #include "wx/combobox.h"
3096bd2f 42 #include "wx/intl.h"
27ea1d8a 43 #include "wx/sizer.h"
ebb7606e 44 #include "wx/cmndata.h"
27ea1d8a
RR
45#endif
46
47#if wxUSE_STATLINE
54a7425b 48 #include "wx/statline.h"
c801d85f
KB
49#endif
50
2a47d3c1 51#if wxUSE_POSTSCRIPT
8826f46f 52 #include "wx/generic/dcpsg.h"
2a47d3c1
JS
53#endif
54
8850cbd3 55#include "wx/prntbase.h"
c801d85f 56#include "wx/printdlg.h"
7bcb11d3 57#include "wx/paper.h"
eba33006 58#include "wx/filename.h"
2c84e0c2 59#include "wx/tokenzr.h"
f68535b0 60#include "wx/imaglist.h"
c801d85f
KB
61
62#include <stdlib.h>
63#include <string.h>
64
70dec69b 65#if wxUSE_LIBGNOMEPRINT
09a09455
PC
66 #include "wx/link.h"
67 wxFORCE_LINK_MODULE(gnome_print)
70dec69b
JS
68#endif
69
9dac27ad 70#if wxUSE_GTKPRINT
fa034c45
RR
71 #include "wx/link.h"
72 wxFORCE_LINK_MODULE(gtk_print)
9dac27ad
RR
73#endif
74
8826f46f 75// ----------------------------------------------------------------------------
8850cbd3 76// global vars
8826f46f
VZ
77// ----------------------------------------------------------------------------
78
8850cbd3 79extern wxPrintPaperDatabase *wxThePrintPaperDatabase;
25889d3c 80
2a47d3c1
JS
81#if wxUSE_POSTSCRIPT
82
8850cbd3
RR
83//----------------------------------------------------------------------------
84// wxPostScriptNativeData
85//----------------------------------------------------------------------------
30862d99 86
8850cbd3 87IMPLEMENT_CLASS(wxPostScriptPrintNativeData, wxPrintNativeDataBase)
8826f46f 88
8850cbd3
RR
89wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
90{
9548f380 91 m_previewCommand = wxEmptyString;
8850cbd3
RR
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
30862d99 97
8850cbd3
RR
98#ifdef __WXMSW__
99 m_printerCommand = wxT("print");
9548f380 100 m_printerOptions = wxEmptyString;
8850cbd3
RR
101 m_afmPath = wxT("c:\\windows\\system\\");
102#endif
8826f46f 103
8850cbd3
RR
104#if !defined(__VMS__) && !defined(__WXMSW__)
105 m_printerCommand = wxT("lpr");
9548f380 106 m_printerOptions = wxEmptyString;
f69fc95c 107 m_afmPath = wxEmptyString;
8850cbd3 108#endif
c801d85f 109
8850cbd3
RR
110 m_printerScaleX = 1.0;
111 m_printerScaleY = 1.0;
112 m_printerTranslateX = 0;
113 m_printerTranslateY = 0;
8850cbd3 114}
c801d85f 115
8850cbd3
RR
116wxPostScriptPrintNativeData::~wxPostScriptPrintNativeData()
117{
118}
119
4e4528f6 120bool wxPostScriptPrintNativeData::TransferTo( wxPrintData &WXUNUSED(data) )
8850cbd3
RR
121{
122 return true;
123}
124
4e4528f6 125bool wxPostScriptPrintNativeData::TransferFrom( const wxPrintData &WXUNUSED(data) )
8850cbd3
RR
126{
127 return true;
128}
25889d3c 129
8826f46f
VZ
130// ----------------------------------------------------------------------------
131// Generic print dialog for non-Windows printing use.
132// ----------------------------------------------------------------------------
133
c061373d
RR
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
8826f46f
VZ
142wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
143 wxPrintDialogData* data)
2229243b
VZ
144 : wxPrintDialogBase(GetParentForModalDialog(parent),
145 wxID_ANY, _("Print"),
c47addef 146 wxPoint(0,0), wxSize(600, 600),
8826f46f 147 wxDEFAULT_DIALOG_STYLE |
8826f46f
VZ
148 wxTAB_TRAVERSAL)
149{
150 if ( data )
151 m_printDialogData = *data;
c801d85f 152
8826f46f
VZ
153 Init(parent);
154}
c801d85f 155
8826f46f
VZ
156wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
157 wxPrintData* data)
2229243b
VZ
158 : wxPrintDialogBase(GetParentForModalDialog(parent),
159 wxID_ANY, _("Print"),
c47addef 160 wxPoint(0,0), wxSize(600, 600),
cb230244 161 wxDEFAULT_DIALOG_STYLE |
cb230244 162 wxTAB_TRAVERSAL)
c801d85f 163{
7bcb11d3
JS
164 if ( data )
165 m_printDialogData = *data;
2312c9e1 166
8826f46f
VZ
167 Init(parent);
168}
169
74e3313b 170void wxGenericPrintDialog::Init(wxWindow * WXUNUSED(parent))
8826f46f 171{
c47addef 172 // wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0,0), wxSize(600, 600),
2a21ac15 173 // wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL);
8826f46f 174
27ea1d8a 175 wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
2312c9e1 176
ca65c044
WS
177 // 1) top row
178
6038ec8e
RR
179 wxPrintFactory* factory = wxPrintFactory::GetFactory();
180
ca65c044
WS
181 wxStaticBoxSizer *topsizer = new wxStaticBoxSizer(
182 new wxStaticBox( this, wxID_ANY, _( "Printer options" ) ), wxHORIZONTAL );
6038ec8e
RR
183 wxFlexGridSizer *flex = new wxFlexGridSizer( 2 );
184 flex->AddGrowableCol( 1 );
185 topsizer->Add( flex, 1, wxGROW );
2312c9e1 186
27ea1d8a 187 m_printToFileCheckBox = new wxCheckBox( this, wxPRINTID_PRINTTOFILE, _("Print to File") );
6038ec8e 188 flex->Add( m_printToFileCheckBox, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
2312c9e1 189
27ea1d8a 190 m_setupButton = new wxButton(this, wxPRINTID_SETUP, _("Setup...") );
6038ec8e 191 flex->Add( m_setupButton, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
2312c9e1 192
6038ec8e
RR
193 if (!factory->HasPrintSetupDialog())
194 m_setupButton->Enable( false );
2312c9e1 195
6038ec8e
RR
196 if (factory->HasPrinterLine())
197 {
2312c9e1 198 flex->Add( new wxStaticText( this, wxID_ANY, _("Printer:") ),
6038ec8e 199 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
2312c9e1 200 flex->Add( new wxStaticText( this, wxID_ANY, factory->CreatePrinterLine() ),
6038ec8e
RR
201 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
202 }
ca65c044 203
6038ec8e
RR
204 if (factory->HasStatusLine())
205 {
2312c9e1 206 flex->Add( new wxStaticText( this, wxID_ANY, _("Status:") ),
6038ec8e 207 0, wxALIGN_CENTER_VERTICAL|wxALL-wxTOP, 5 );
2312c9e1 208 flex->Add( new wxStaticText( this, wxID_ANY, factory->CreateStatusLine() ),
6038ec8e
RR
209 0, wxALIGN_CENTER_VERTICAL|wxALL-wxTOP, 5 );
210 }
211
212 mainsizer->Add( topsizer, 0, wxLEFT|wxTOP|wxRIGHT|wxGROW, 10 );
ca65c044 213
27ea1d8a 214 // 2) middle row with radio box
ca65c044 215
7bcb11d3
JS
216 wxString *choices = new wxString[2];
217 choices[0] = _("All");
218 choices[1] = _("Pages");
8826f46f 219
7bcb11d3 220 m_fromText = (wxTextCtrl*)NULL;
d14612c6 221 m_toText = (wxTextCtrl*)NULL;
59e2b19f 222 m_rangeRadioBox = (wxRadioBox *)NULL;
ca65c044 223
7bcb11d3
JS
224 if (m_printDialogData.GetFromPage() != 0)
225 {
226 m_rangeRadioBox = new wxRadioBox(this, wxPRINTID_RANGE, _("Print Range"),
27ea1d8a 227 wxDefaultPosition, wxDefaultSize,
8826f46f
VZ
228 2, choices,
229 1, wxRA_VERTICAL);
7bcb11d3 230 m_rangeRadioBox->SetSelection(1);
b1d4dd7a 231
eba33006 232 mainsizer->Add( m_rangeRadioBox, 0, wxLEFT|wxTOP|wxRIGHT, 10 );
7bcb11d3 233 }
8826f46f 234
27ea1d8a 235 // 3) bottom row
ca65c044 236
27ea1d8a
RR
237 wxBoxSizer *bottomsizer = new wxBoxSizer( wxHORIZONTAL );
238
239 if (m_printDialogData.GetFromPage() != 0)
7bcb11d3 240 {
27ea1d8a 241 bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("From:") ), 0, wxCENTER|wxALL, 5 );
422d0ff0 242 m_fromText = new wxTextCtrl(this, wxPRINTID_FROM, wxEmptyString, wxDefaultPosition, wxSize(40, wxDefaultCoord));
eba33006 243 bottomsizer->Add( m_fromText, 1, wxCENTER|wxRIGHT, 10 );
8826f46f 244
27ea1d8a 245 bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("To:") ), 0, wxCENTER|wxALL, 5);
422d0ff0 246 m_toText = new wxTextCtrl(this, wxPRINTID_TO, wxEmptyString, wxDefaultPosition, wxSize(40, wxDefaultCoord));
eba33006 247 bottomsizer->Add( m_toText, 1, wxCENTER|wxRIGHT, 10 );
27ea1d8a 248 }
8826f46f 249
27ea1d8a 250 bottomsizer->Add( new wxStaticText(this, wxPRINTID_STATIC, _("Copies:") ), 0, wxCENTER|wxALL, 5 );
422d0ff0 251 m_noCopiesText = new wxTextCtrl(this, wxPRINTID_COPIES, wxEmptyString, wxPoint(252, 130), wxSize(40, wxDefaultCoord));
27ea1d8a 252 bottomsizer->Add( m_noCopiesText, 1, wxCENTER|wxRIGHT, 10 );
8826f46f 253
27ea1d8a 254 mainsizer->Add( bottomsizer, 0, wxTOP|wxLEFT|wxRIGHT, 12 );
8826f46f 255
bd9f3519 256 // 4) buttons
8826f46f 257
bd9f3519
VZ
258 wxSizer *sizerBtn = CreateSeparatedButtonSizer( wxOK|wxCANCEL);
259 if ( sizerBtn )
260 mainsizer->Add(sizerBtn, 0, wxEXPAND|wxALL, 10 );
8826f46f 261
ca65c044 262 SetAutoLayout( true );
27ea1d8a
RR
263 SetSizer( mainsizer );
264
265 mainsizer->Fit( this );
7bcb11d3 266 Centre(wxBOTH);
8826f46f 267
7bcb11d3
JS
268 // Calls wxWindow::OnInitDialog and then wxGenericPrintDialog::TransferDataToWindow
269 InitDialog();
270 delete[] choices;
c801d85f
KB
271}
272
7bcb11d3 273int wxGenericPrintDialog::ShowModal()
c801d85f 274{
6038ec8e 275 return wxDialog::ShowModal();
c801d85f
KB
276}
277
7bcb11d3 278wxGenericPrintDialog::~wxGenericPrintDialog()
c801d85f
KB
279{
280}
281
282void wxGenericPrintDialog::OnOK(wxCommandEvent& WXUNUSED(event))
283{
7bcb11d3 284 TransferDataFromWindow();
8826f46f 285
b386cd7a
JS
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
7bcb11d3
JS
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 {
6038ec8e 297 m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE);
ca65c044 298
eba33006 299 wxFileName fname( m_printDialogData.GetPrintData().GetFilename() );
ca65c044 300
eba33006 301 wxFileDialog dialog( this, _("PostScript file"),
ff3e84ff 302 fname.GetPath(), fname.GetFullName(), wxT("*.ps"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
eba33006 303 if (dialog.ShowModal() != wxID_OK) return;
2312c9e1 304
eba33006 305 m_printDialogData.GetPrintData().SetFilename( dialog.GetPath() );
7bcb11d3
JS
306 }
307 else
75737d05 308 {
6038ec8e 309 m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER);
75737d05 310 }
2312c9e1 311
7bcb11d3 312 EndModal(wxID_OK);
c801d85f
KB
313}
314
315void wxGenericPrintDialog::OnRange(wxCommandEvent& event)
316{
7bcb11d3 317 if (!m_fromText) return;
8826f46f 318
7bcb11d3
JS
319 if (event.GetInt() == 0)
320 {
ca65c044
WS
321 m_fromText->Enable(false);
322 m_toText->Enable(false);
7bcb11d3
JS
323 }
324 else if (event.GetInt() == 1)
325 {
ca65c044
WS
326 m_fromText->Enable(true);
327 m_toText->Enable(true);
7bcb11d3 328 }
c801d85f
KB
329}
330
331void wxGenericPrintDialog::OnSetup(wxCommandEvent& WXUNUSED(event))
332{
6038ec8e
RR
333 wxPrintFactory* factory = wxPrintFactory::GetFactory();
334
335 if (factory->HasPrintSetupDialog())
7bcb11d3 336 {
6038ec8e
RR
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();
7bcb11d3 342 }
c801d85f
KB
343}
344
7bcb11d3 345bool wxGenericPrintDialog::TransferDataToWindow()
c801d85f 346{
7bcb11d3
JS
347 if(m_printDialogData.GetFromPage() != 0)
348 {
d14612c6
KB
349 if(m_fromText)
350 {
351 if (m_printDialogData.GetEnablePageNumbers())
352 {
ca65c044
WS
353 m_fromText->Enable(true);
354 m_toText->Enable(true);
b386cd7a
JS
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()));
59e2b19f 359 if(m_rangeRadioBox)
b386cd7a 360 if (m_printDialogData.GetAllPages() || m_printDialogData.GetFromPage() == 0)
59e2b19f
KB
361 m_rangeRadioBox->SetSelection(0);
362 else
363 m_rangeRadioBox->SetSelection(1);
d14612c6
KB
364 }
365 else
366 {
ca65c044
WS
367 m_fromText->Enable(false);
368 m_toText->Enable(false);
59e2b19f
KB
369 if(m_rangeRadioBox)
370 {
371 m_rangeRadioBox->SetSelection(0);
ca65c044 372 m_rangeRadioBox->wxRadioBox::Enable(1, false);
59e2b19f 373 }
d14612c6
KB
374 }
375 }
7bcb11d3 376 }
30862d99
VZ
377 m_noCopiesText->SetValue(
378 wxString::Format(_T("%d"), m_printDialogData.GetNoCopies()));
8826f46f 379
7bcb11d3
JS
380 m_printToFileCheckBox->SetValue(m_printDialogData.GetPrintToFile());
381 m_printToFileCheckBox->Enable(m_printDialogData.GetEnablePrintToFile());
ca65c044 382 return true;
c801d85f
KB
383}
384
7bcb11d3 385bool wxGenericPrintDialog::TransferDataFromWindow()
c801d85f 386{
92980e90 387 long res = 0;
7bcb11d3
JS
388 if(m_printDialogData.GetFromPage() != -1)
389 {
390 if (m_printDialogData.GetEnablePageNumbers())
391 {
92980e90
RR
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)
ca65c044 399 {
92980e90
RR
400 wxString value = m_toText->GetValue();
401 if (value.ToLong( &res ))
402 m_printDialogData.SetToPage( res );
403 }
7bcb11d3 404 }
59e2b19f
KB
405 if(m_rangeRadioBox)
406 {
01b5396f
RR
407 if (m_rangeRadioBox->GetSelection() == 0)
408 {
409 m_printDialogData.SetAllPages(true);
2312c9e1 410
01b5396f
RR
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);
59e2b19f 417 }
7bcb11d3
JS
418 }
419 else
420 { // continuous printing
421 m_printDialogData.SetFromPage(1);
422 m_printDialogData.SetToPage(32000);
423 }
ca65c044 424
92980e90
RR
425 wxString value = m_noCopiesText->GetValue();
426 if (value.ToLong( &res ))
427 m_printDialogData.SetNoCopies( res );
ca65c044 428
7bcb11d3 429 m_printDialogData.SetPrintToFile(m_printToFileCheckBox->GetValue());
2312c9e1 430
ca65c044 431 return true;
c801d85f
KB
432}
433
7bcb11d3 434wxDC *wxGenericPrintDialog::GetPrintDC()
c801d85f 435{
6038ec8e 436 return new wxPostScriptDC(GetPrintDialogData().GetPrintData());
7bcb11d3 437}
c801d85f 438
8826f46f
VZ
439// ----------------------------------------------------------------------------
440// Generic print setup dialog
441// ----------------------------------------------------------------------------
c801d85f 442
8850cbd3
RR
443IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog)
444
2c84e0c2
RR
445BEGIN_EVENT_TABLE(wxGenericPrintSetupDialog, wxDialog)
446 EVT_LIST_ITEM_ACTIVATED(wxPRINTID_PRINTER, wxGenericPrintSetupDialog::OnPrinter)
447END_EVENT_TABLE()
448
7bcb11d3 449wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintData* data):
c47addef 450wxDialog(parent, wxID_ANY, _("Print Setup"), wxPoint(0,0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL)
7bcb11d3
JS
451{
452 Init(data);
453}
c801d85f 454
2c84e0c2 455/* XPM */
5080e86f 456static const char * check_xpm[] = {
2c84e0c2
RR
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
7bcb11d3
JS
483void wxGenericPrintSetupDialog::Init(wxPrintData* data)
484{
485 if ( data )
486 m_printData = *data;
9838df2c 487
2c84e0c2 488 m_targetData = data;
8826f46f 489
6038ec8e 490 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
8826f46f 491
2c84e0c2 492 // printer selection
2312c9e1
WS
493
494 wxStaticBoxSizer *printer_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Printer") ), wxVERTICAL );
2c84e0c2 495 main_sizer->Add( printer_sizer, 0, wxALL|wxGROW, 10 );
2312c9e1
WS
496
497 m_printerListCtrl = new wxListCtrl( this, wxPRINTID_PRINTER,
498 wxDefaultPosition, wxSize(wxDefaultCoord,100), wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER );
2c84e0c2
RR
499 wxImageList *image_list = new wxImageList;
500 image_list->Add( wxBitmap(check_xpm) );
501 m_printerListCtrl->AssignImageList( image_list, wxIMAGE_LIST_SMALL );
2312c9e1 502
2c84e0c2
RR
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
2312c9e1 514 if (data->GetPrinterName().empty())
2c84e0c2
RR
515 {
516 wxListItem item2;
517 item2.SetId( item.GetId() );
518 item2.SetMask( wxLIST_MASK_IMAGE );
519 item2.SetImage( 0 );
520 m_printerListCtrl->SetItem( item2 );
f36a04a7
RR
521 // also select item
522 m_printerListCtrl->SetItemState( item.GetId(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
2c84e0c2
RR
523 }
524
525 item.SetId( 1+ item.GetId() );
526
527 wxArrayString errors;
528 wxArrayString output;
b357f3fc 529 long res = wxExecute( wxT("lpstat -v"), output, errors, wxEXEC_NODISABLE );
2c84e0c2
RR
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:"
54a7425b
WS
543 if (tmp[tmp.length()-1] == wxT(':'))
544 tmp.Remove(tmp.length()-1,1);
2c84e0c2
RR
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 );
f36a04a7
RR
559 // also select item
560 m_printerListCtrl->SetItemState( item.GetId(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
2c84e0c2 561 }
2312c9e1 562
2c84e0c2
RR
563 wxString command = wxT("lpstat -p ");
564 command += name;
565 wxArrayString errors2;
566 wxArrayString output2;
b357f3fc 567 res = wxExecute( command, output2, errors2, wxEXEC_NODISABLE );
2c84e0c2
RR
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('.') );
2312c9e1 572 if (pos != wxNOT_FOUND)
54a7425b 573 tmp.Remove( (size_t)pos, tmp.length()-(size_t)pos );
2c84e0c2
RR
574 wxStringTokenizer tok2( tmp, wxT(" ") );
575 tmp = tok2.GetNextToken(); // "printer"
576 tmp = tok2.GetNextToken(); // "hp_deskjet930c"
9548f380 577 tmp = wxEmptyString;
2c84e0c2
RR
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 }
2312c9e1 587
2c84e0c2
RR
588 item.SetColumn( 1 );
589 item.SetId( 1+ item.GetId() );
590 }
591 }
592
2312c9e1 593
2c84e0c2
RR
594 printer_sizer->Add( m_printerListCtrl, 0, wxALL|wxGROW, 5 );
595
6038ec8e
RR
596 wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
597 main_sizer->Add( item1, 0, wxALL, 5 );
8826f46f 598
6038ec8e 599 // printer options (on the left)
8826f46f 600
6038ec8e 601 wxBoxSizer *item2 = new wxBoxSizer( wxVERTICAL );
8826f46f 602
6038ec8e
RR
603 wxStaticBox *item4 = new wxStaticBox( this, wxPRINTID_STATIC, _("Paper size") );
604 wxStaticBoxSizer *item3 = new wxStaticBoxSizer( item4, wxVERTICAL );
8826f46f 605
6038ec8e
RR
606 m_paperTypeChoice = CreatePaperTypeChoice();
607 item3->Add( m_paperTypeChoice, 0, wxALIGN_CENTER|wxALL, 5 );
8826f46f 608
6038ec8e
RR
609 item2->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
610
2312c9e1 611 wxString strs6[] =
6038ec8e 612 {
2312c9e1 613 _("Portrait"),
6038ec8e
RR
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 );
8826f46f 618
2312c9e1 619 wxStaticBox *item8 = new wxStaticBox( this, wxID_ANY, _("Options") );
6038ec8e 620 wxStaticBoxSizer *item7 = new wxStaticBoxSizer( item8, wxHORIZONTAL );
c801d85f 621
6038ec8e
RR
622 m_colourCheckBox = new wxCheckBox( this, wxPRINTID_PRINTCOLOUR, _("Print in colour") );
623 item7->Add( m_colourCheckBox, 0, wxALIGN_CENTER|wxALL, 5 );
8826f46f 624
6038ec8e 625 item2->Add( item7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
8826f46f 626
6038ec8e 627 item1->Add( item2, 0, wxALIGN_CENTER_HORIZONTAL, 5 );
8826f46f 628
6038ec8e 629 // spooling options (on the right)
8826f46f 630
2312c9e1 631 wxStaticBox *item11 = new wxStaticBox( this, wxID_ANY, _("Print spooling") );
6038ec8e 632 wxStaticBoxSizer *item10 = new wxStaticBoxSizer( item11, wxVERTICAL );
8826f46f 633
2312c9e1 634 wxStaticText *item12 = new wxStaticText( this, wxID_ANY, _("Printer command:") );
6038ec8e
RR
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
9548f380 641 m_printerCommandText = new wxTextCtrl( this, wxPRINTID_COMMAND, wxEmptyString, wxDefaultPosition, wxSize(160,wxDefaultCoord) );
6038ec8e
RR
642 item13->Add( m_printerCommandText, 0, wxALIGN_CENTER|wxALL, 5 );
643
644 item10->Add( item13, 0, wxALIGN_CENTER|wxALL, 0 );
645
2312c9e1 646 wxStaticText *item15 = new wxStaticText( this, wxID_ANY, _("Printer options:") );
6038ec8e
RR
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
9548f380 653 m_printerOptionsText = new wxTextCtrl( this, wxPRINTID_OPTIONS, wxEmptyString, wxDefaultPosition, wxSize(160,wxDefaultCoord) );
6038ec8e
RR
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
2312c9e1 663 main_sizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
6038ec8e
RR
664#endif
665
666 // buttons
667
acf2ac37 668 main_sizer->Add( CreateButtonSizer( wxOK|wxCANCEL), 0, wxEXPAND|wxALL, 10 );
6038ec8e
RR
669
670 SetAutoLayout( true );
671 SetSizer( main_sizer );
672
673 main_sizer->Fit( this );
674 Centre(wxBOTH);
8826f46f 675
ca65c044 676
7bcb11d3
JS
677 Fit();
678 Centre(wxBOTH);
8826f46f 679
7bcb11d3 680 InitDialog();
c801d85f
KB
681}
682
7bcb11d3 683wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
c801d85f
KB
684{
685}
686
2c84e0c2
RR
687void wxGenericPrintSetupDialog::OnPrinter(wxListEvent& event)
688{
689 // Delete check mark
17a1ebd1 690 for (long item = 0; item < m_printerListCtrl->GetItemCount(); item++)
2c84e0c2 691 m_printerListCtrl->SetItemImage( item, -1 );
2312c9e1 692
2c84e0c2 693 m_printerListCtrl->SetItemImage( event.GetIndex(), 0 );
2312c9e1 694
2c84e0c2
RR
695 if (event.GetIndex() == 0)
696 {
697 m_printerCommandText->SetValue( wxT("lpr") );
698 }
699 else
700 {
17a1ebd1
VZ
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() );
2c84e0c2
RR
707 }
708}
709
7bcb11d3 710bool wxGenericPrintSetupDialog::TransferDataToWindow()
c801d85f 711{
2312c9e1 712 wxPostScriptPrintNativeData *data =
8850cbd3
RR
713 (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
714
11aac4ba 715 if (m_printerCommandText && !data->GetPrinterCommand().empty())
8850cbd3 716 m_printerCommandText->SetValue(data->GetPrinterCommand());
11aac4ba 717 if (m_printerOptionsText && !data->GetPrinterOptions().empty())
8850cbd3 718 m_printerOptionsText->SetValue(data->GetPrinterOptions());
7bcb11d3
JS
719 if (m_colourCheckBox)
720 m_colourCheckBox->SetValue(m_printData.GetColour());
8826f46f 721
7bcb11d3
JS
722 if (m_orientationRadioBox)
723 {
724 if (m_printData.GetOrientation() == wxPORTRAIT)
725 m_orientationRadioBox->SetSelection(0);
726 else
727 m_orientationRadioBox->SetSelection(1);
728 }
ca65c044 729 return true;
c801d85f
KB
730}
731
7bcb11d3 732bool wxGenericPrintSetupDialog::TransferDataFromWindow()
c801d85f 733{
2312c9e1 734 wxPostScriptPrintNativeData *data =
8850cbd3
RR
735 (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
736
2c84e0c2
RR
737 // find selected printer
738 long id = m_printerListCtrl->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
739 if (id == 0)
740 {
9548f380 741 m_printData.SetPrinterName( wxEmptyString );
2c84e0c2
RR
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
7bcb11d3 753 if (m_printerCommandText)
8850cbd3 754 data->SetPrinterCommand(m_printerCommandText->GetValue());
7bcb11d3 755 if (m_printerOptionsText)
8850cbd3 756 data->SetPrinterOptions(m_printerOptionsText->GetValue());
7bcb11d3
JS
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 {
17dd9caa
VZ
769 int selectedItem = m_paperTypeChoice->GetSelection();
770 if (selectedItem != -1)
771 {
222ed1d6 772 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(selectedItem);
17dd9caa
VZ
773 if (paper != NULL)
774 m_printData.SetPaperId( paper->GetId());
775 }
7bcb11d3
JS
776 }
777
2c84e0c2
RR
778 if (m_targetData)
779 *m_targetData = m_printData;
780
ca65c044 781 return true;
c801d85f
KB
782}
783
6038ec8e 784wxComboBox *wxGenericPrintSetupDialog::CreatePaperTypeChoice()
c801d85f 785{
6038ec8e
RR
786 size_t n = wxThePrintPaperDatabase->GetCount();
787 wxString *choices = new wxString [n];
788 size_t sel = 0;
b1d4dd7a
RL
789
790 for (size_t i = 0; i < n; i++)
7bcb11d3 791 {
222ed1d6 792 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
7bcb11d3
JS
793 choices[i] = paper->GetName();
794 if (m_printData.GetPaperId() == paper->GetId())
795 sel = i;
796 }
8826f46f 797
7bcb11d3
JS
798 int width = 250;
799
b1d4dd7a
RL
800 wxComboBox *choice = new wxComboBox( this,
801 wxPRINTID_PAPERSIZE,
802 _("Paper Size"),
6038ec8e 803 wxDefaultPosition,
422d0ff0 804 wxSize(width, wxDefaultCoord),
b1d4dd7a 805 n, choices );
7bcb11d3 806
7bcb11d3 807 delete[] choices;
8826f46f 808
7bcb11d3
JS
809 choice->SetSelection(sel);
810 return choice;
c801d85f 811}
6038ec8e 812
8826f46f 813#endif // wxUSE_POSTSCRIPT
c801d85f 814
8826f46f
VZ
815// ----------------------------------------------------------------------------
816// Generic page setup dialog
817// ----------------------------------------------------------------------------
c801d85f 818
08680429 819IMPLEMENT_CLASS(wxGenericPageSetupDialog, wxPageSetupDialogBase)
8850cbd3 820
08680429 821BEGIN_EVENT_TABLE(wxGenericPageSetupDialog, wxPageSetupDialogBase)
8850cbd3
RR
822 EVT_BUTTON(wxPRINTID_SETUP, wxGenericPageSetupDialog::OnPrinter)
823END_EVENT_TABLE()
824
b1d4dd7a 825wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow *parent,
08680429
RR
826 wxPageSetupDialogData* data)
827 : wxPageSetupDialogBase( parent,
ca65c044 828 wxID_ANY,
b1d4dd7a 829 _("Page Setup"),
c47addef 830 wxPoint(0,0),
b1d4dd7a 831 wxSize(600, 600),
2a21ac15 832 wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL )
c801d85f 833{
27ea1d8a 834 if (data)
7bcb11d3 835 m_pageData = *data;
b1d4dd7a 836
27ea1d8a 837 int textWidth = 80;
b1d4dd7a 838
27ea1d8a 839 wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
b1d4dd7a 840
27ea1d8a 841 // 1) top
ca65c044 842 wxStaticBoxSizer *topsizer = new wxStaticBoxSizer(
27ea1d8a 843 new wxStaticBox(this,wxPRINTID_STATIC, _("Paper size")), wxHORIZONTAL );
b1d4dd7a
RL
844
845 size_t n = wxThePrintPaperDatabase->GetCount();
846 wxString *choices = new wxString [n];
847
848 for (size_t i = 0; i < n; i++)
27ea1d8a 849 {
222ed1d6 850 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
27ea1d8a
RR
851 choices[i] = paper->GetName();
852 }
8826f46f 853
b1d4dd7a
RL
854 m_paperTypeChoice = new wxComboBox( this,
855 wxPRINTID_PAPERSIZE,
856 _("Paper Size"),
857 wxDefaultPosition,
422d0ff0 858 wxSize(300, wxDefaultCoord),
b1d4dd7a 859 n, choices );
27ea1d8a
RR
860 topsizer->Add( m_paperTypeChoice, 1, wxEXPAND|wxALL, 5 );
861// m_paperTypeChoice->SetSelection(sel);
8826f46f 862
27ea1d8a 863 mainsizer->Add( topsizer, 0, wxTOP|wxLEFT|wxRIGHT | wxEXPAND, 10 );
8826f46f 864
27ea1d8a 865 // 2) middle sizer with radio box
8826f46f 866
27ea1d8a
RR
867 wxString *choices2 = new wxString[2];
868 choices2[0] = _("Portrait");
869 choices2[1] = _("Landscape");
7bcb11d3 870 m_orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"),
27ea1d8a 871 wxDefaultPosition, wxDefaultSize, 2, choices2, 2);
7bcb11d3 872 m_orientationRadioBox->SetSelection(0);
8826f46f 873
27ea1d8a 874 mainsizer->Add( m_orientationRadioBox, 0, wxTOP|wxLEFT|wxRIGHT, 10 );
8826f46f 875
27ea1d8a 876 // 3) margins
8826f46f 877
27ea1d8a 878 wxBoxSizer *table = new wxBoxSizer( wxHORIZONTAL );
8826f46f 879
27ea1d8a
RR
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 );
ca65c044 884
27ea1d8a 885 wxBoxSizer *column2 = new wxBoxSizer( wxVERTICAL );
422d0ff0
WS
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));
27ea1d8a
RR
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 );
ca65c044 891
27ea1d8a
RR
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 );
ca65c044 896
27ea1d8a 897 wxBoxSizer *column4 = new wxBoxSizer( wxVERTICAL );
422d0ff0
WS
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));
27ea1d8a
RR
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
ca65c044 908 mainsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
27ea1d8a 909#endif
8826f46f 910
27ea1d8a 911 // 6) buttons
ca65c044 912
27ea1d8a 913 wxSizer* buttonsizer = CreateButtonSizer( wxOK|wxCANCEL);
2312c9e1 914
08680429
RR
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 }
2312c9e1 926
27ea1d8a 927 // if (m_printData.GetEnableHelp())
422d0ff0 928 // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, _("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight);
acf2ac37 929 mainsizer->Add( buttonsizer, 0, wxEXPAND|wxALL, 10 );
8826f46f 930
8826f46f 931
ca65c044 932 SetAutoLayout( true );
27ea1d8a 933 SetSizer( mainsizer );
8826f46f 934
27ea1d8a 935 mainsizer->Fit( this );
7bcb11d3 936 Centre(wxBOTH);
8826f46f 937
7bcb11d3 938 InitDialog();
ca65c044 939
27ea1d8a
RR
940 delete[] choices;
941 delete [] choices2;
7bcb11d3 942}
9838df2c 943
7bcb11d3
JS
944wxGenericPageSetupDialog::~wxGenericPageSetupDialog()
945{
946}
c801d85f 947
08680429 948wxPageSetupDialogData& wxGenericPageSetupDialog::GetPageSetupDialogData()
2312c9e1 949{
08680429
RR
950 return m_pageData;
951}
952
7bcb11d3
JS
953bool wxGenericPageSetupDialog::TransferDataToWindow()
954{
955 if (m_marginLeftText)
963907fa 956 m_marginLeftText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginTopLeft().x));
7bcb11d3 957 if (m_marginTopText)
963907fa 958 m_marginTopText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginTopLeft().y));
7bcb11d3 959 if (m_marginRightText)
963907fa 960 m_marginRightText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginBottomRight().x));
7bcb11d3 961 if (m_marginBottomText)
963907fa 962 m_marginBottomText->SetValue(wxString::Format(wxT("%d"), m_pageData.GetMarginBottomRight().y));
8826f46f 963
7bcb11d3
JS
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 }
c801d85f 971
7bcb11d3
JS
972 // Find the paper type from either the current paper size in the wxPageSetupDialogData, or
973 // failing that, the id in the wxPrintData object.
c801d85f 974
7bcb11d3
JS
975 wxPrintPaperType* type = wxThePrintPaperDatabase->FindPaperType(
976 wxSize(m_pageData.GetPaperSize().x * 10, m_pageData.GetPaperSize().y * 10));
c801d85f 977
7bcb11d3
JS
978 if (!type && m_pageData.GetPrintData().GetPaperId() != wxPAPER_NONE)
979 type = wxThePrintPaperDatabase->FindPaperType(m_pageData.GetPrintData().GetPaperId());
c801d85f 980
7bcb11d3
JS
981 if (type)
982 {
983 m_paperTypeChoice->SetStringSelection(type->GetName());
984 }
c801d85f 985
ca65c044 986 return true;
c801d85f
KB
987}
988
7bcb11d3 989bool wxGenericPageSetupDialog::TransferDataFromWindow()
c801d85f 990{
7bcb11d3 991 if (m_marginLeftText && m_marginTopText)
eba33006
RR
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 }
7bcb11d3 997 if (m_marginRightText && m_marginBottomText)
eba33006
RR
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 }
8826f46f 1003
7bcb11d3 1004 if (m_orientationRadioBox)
c801d85f 1005 {
7bcb11d3
JS
1006 int sel = m_orientationRadioBox->GetSelection();
1007 if (sel == 0)
1008 {
7bcb11d3
JS
1009 m_pageData.GetPrintData().SetOrientation(wxPORTRAIT);
1010 }
1011 else
1012 {
7bcb11d3
JS
1013 m_pageData.GetPrintData().SetOrientation(wxLANDSCAPE);
1014 }
c801d85f 1015 }
ca65c044 1016
7bcb11d3 1017 if (m_paperTypeChoice)
c801d85f 1018 {
17dd9caa
VZ
1019 int selectedItem = m_paperTypeChoice->GetSelection();
1020 if (selectedItem != -1)
c801d85f 1021 {
222ed1d6 1022 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(selectedItem);
7bcb11d3
JS
1023 if ( paper )
1024 {
1025 m_pageData.SetPaperSize(wxSize(paper->GetWidth()/10, paper->GetHeight()/10));
1026 m_pageData.GetPrintData().SetPaperId(paper->GetId());
1027 }
c801d85f
KB
1028 }
1029 }
8826f46f 1030
ca65c044 1031 return true;
c801d85f
KB
1032}
1033
fa12f7e6 1034wxComboBox *wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x, int *y)
c801d85f 1035{
7bcb11d3
JS
1036/*
1037 if (!wxThePrintPaperDatabase)
1038 {
1039 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
1040 wxThePrintPaperDatabase->CreateDatabase();
1041 }
1042*/
1043
b1d4dd7a
RL
1044 size_t n = wxThePrintPaperDatabase->GetCount();
1045 wxString *choices = new wxString [n];
1046
1047 for (size_t i = 0; i < n; i++)
7bcb11d3 1048 {
222ed1d6 1049 wxPrintPaperType *paper = wxThePrintPaperDatabase->Item(i);
7bcb11d3
JS
1050 choices[i] = paper->GetName();
1051 }
8826f46f 1052
7bcb11d3
JS
1053 (void) new wxStaticText(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(*x, *y));
1054 *y += 25;
8826f46f 1055
b1d4dd7a
RL
1056 wxComboBox *choice = new wxComboBox( this,
1057 wxPRINTID_PAPERSIZE,
1058 _("Paper Size"),
1059 wxPoint(*x, *y),
422d0ff0 1060 wxSize(300, wxDefaultCoord),
b1d4dd7a 1061 n, choices );
7bcb11d3
JS
1062 *y += 35;
1063 delete[] choices;
8826f46f 1064
7bcb11d3
JS
1065// choice->SetSelection(sel);
1066 return choice;
c801d85f
KB
1067}
1068
08680429
RR
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.
2312c9e1 1083
08680429 1084#if 0
2312c9e1
WS
1085 // Use print factory later
1086
08680429
RR
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
ce4169a4 1103#endif