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