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