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