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