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