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