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