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