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