Update ooo320-m1
[ooovba.git] / svtools / source / dialogs / printdlg.cxx
blob43c3f40321ff867658da40667f9498b54b4c9d5d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: printdlg.cxx,v $
10 * $Revision: 1.32 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <tools/debug.hxx>
34 #ifndef _SV_APP_HXX
35 #include <vcl/svapp.hxx>
36 #endif
37 #ifndef _VCL_PRINT_HXX
38 #include <vcl/print.hxx>
39 #endif
40 #include <vcl/msgbox.hxx>
41 #include <vcl/jobset.hxx>
42 #include <tools/urlobj.hxx>
44 #include "printdlg.hrc"
45 #include "controldims.hrc"
46 #include <svtools/prnsetup.hxx>
47 #include <svtools/printdlg.hxx>
48 #include <svtools/svtdata.hxx>
49 #include <filedlg.hxx>
50 #include "pickerhelper.hxx"
51 #ifndef _SVT_HELPID_HRC
52 #include <svtools/helpid.hrc>
53 #endif
54 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
55 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
56 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
57 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
58 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
59 #include <comphelper/processfactory.hxx>
61 using rtl::OUString;
62 using namespace com::sun::star;
64 struct SvtPrinterImpl
66 Printer* m_pTempPrinter;
67 sal_Bool m_bHelpDisabled;
68 PrintSheetRange m_eSheetRange;
70 SvtPrinterImpl() :
71 m_pTempPrinter( NULL ), m_bHelpDisabled( sal_False ), m_eSheetRange( PRINTSHEETS_ALL ) {}
72 ~SvtPrinterImpl() { delete m_pTempPrinter; }
75 #define TEMPPRINTER() mpPrinterImpl->m_pTempPrinter
77 // =======================================================================
79 PrintDialog::PrintDialog( Window* pWindow, bool bWithSheetsAndCells ) :
80 ModalDialog ( pWindow, SvtResId( DLG_SVT_PRNDLG_PRINTDLG ) ),
81 maFlPrinter ( this, SvtResId( FL_PRINTER ) ),
82 maFtName ( this, SvtResId( FT_NAME ) ),
83 maLbName ( this, SvtResId( LB_NAMES ) ),
84 maBtnProperties ( this, SvtResId( BTN_PROPERTIES ) ),
85 maFtStatus ( this, SvtResId( FT_STATUS ) ),
86 maFiStatus ( this, SvtResId( FI_STATUS ) ),
87 maFtType ( this, SvtResId( FT_TYPE ) ),
88 maFiType ( this, SvtResId( FI_TYPE ) ),
89 maFtLocation ( this, SvtResId( FT_LOCATION ) ),
90 maFiLocation ( this, SvtResId( FI_LOCATION ) ),
91 maFtComment ( this, SvtResId( FT_COMMENT ) ),
92 maFiComment ( this, SvtResId( FI_COMMENT ) ),
93 maCbxFilePrint ( this, SvtResId( CBX_FILEPRINT ) ),
94 maFiPrintFile ( this, SvtResId( FI_PRINTFILE ) ),
95 maFiFaxNo ( this, SvtResId( FI_FAXNO ) ),
96 maEdtFaxNo ( this, SvtResId( EDT_FAXNO ) ),
97 maFlPrint ( this, SvtResId( FL_PRINT ) ),
98 maRbtAllSheets ( this, SvtResId( RBT_ALL_SHEETS ) ),
99 maRbtSelectedSheets ( this, SvtResId( RBT_SELECTED_SHEETS ) ),
100 maRbtSelectedCells ( this, SvtResId( RBT_SELECTED_CELLS ) ),
101 maFlPrintRange ( this, SvtResId( FL_PRINTRANGE ) ),
102 maRbtAll ( this, SvtResId( RBT_ALL ) ),
103 maRbtPages ( this, SvtResId( RBT_PAGES ) ),
104 maRbtSelection ( this, SvtResId( RBT_SELECTION ) ),
105 maEdtPages ( this, SvtResId( EDT_PAGES ) ),
106 maFlSepCopiesRange ( this, SvtResId( FL_SEPCOPIESRANGE ) ),
107 maFlCopies ( this, SvtResId( FL_COPIES ) ),
108 maFtCopies ( this, SvtResId( FT_COPIES ) ),
109 maNumCopies ( this, SvtResId( NUM_COPIES ) ),
110 maImgCollate ( this, SvtResId( IMG_COLLATE ) ),
111 maImgNotCollate ( this, SvtResId( IMG_NOT_COLLATE ) ),
112 maCbxCollate ( this, SvtResId( CBX_COLLATE ) ),
113 maFlSepButtonLine ( this, SvtResId( FL_SEPBUTTONLINE ) ),
114 maBtnOptions ( this, SvtResId( BTN_OPTIONS ) ),
115 maBtnOK ( this, SvtResId( BTN_OK ) ),
116 maBtnCancel ( this, SvtResId( BTN_CANCEL ) ),
117 maBtnHelp ( this, SvtResId( BTN_HELP ) ),
118 mbWithSheetsAndCells( bWithSheetsAndCells ),
119 maAllFilterStr ( SvtResId( STR_ALLFILTER ) )
122 FreeResource();
124 mpPrinter = NULL;
125 mpPrinterImpl = new SvtPrinterImpl;
126 mnCopyCount = 1;
127 mnFirstPage = 0;
128 mnLastPage = 0;
129 mnMinPage = 1;
130 mnMaxPage = 65535;
131 meCheckRange = PRINTDIALOG_ALL;
132 mbAll = TRUE;
133 mbSelection = FALSE;
134 mbFromTo = FALSE;
135 mbRange = FALSE;
136 mbCollate = TRUE;
137 mbCollateCheck = TRUE;
138 mbOptions = FALSE;
140 maStatusTimer.SetTimeout( IMPL_PRINTDLG_STATUS_UPDATE );
141 maStatusTimer.SetTimeoutHdl( LINK( this, PrintDialog, ImplStatusHdl ) );
142 maBtnProperties.SetClickHdl( LINK( this, PrintDialog, ImplPropertiesHdl ) );
143 maLbName.SetSelectHdl( LINK( this, PrintDialog, ImplChangePrinterHdl ) );
145 maFiPrintFile.SetStyle( maFiPrintFile.GetStyle() | WB_PATHELLIPSIS );
147 Link aLink( LINK( this, PrintDialog, ImplModifyControlHdl ) );
148 maCbxFilePrint.SetClickHdl( aLink );
149 maRbtAll.SetClickHdl( aLink );
150 maRbtPages.SetClickHdl( aLink );
151 maRbtSelection.SetClickHdl( aLink );
152 maEdtPages.SetModifyHdl( aLink );
153 maNumCopies.SetModifyHdl( aLink );
154 maCbxCollate.SetClickHdl( aLink );
155 maBtnOptions.SetClickHdl( aLink );
156 maEdtFaxNo.SetModifyHdl( aLink );
157 maBtnOK.SetClickHdl( aLink );
159 maRbtAll.Check();
160 ImplSetImages();
163 // -----------------------------------------------------------------------
165 PrintDialog::~PrintDialog()
167 ImplFreePrnDlgListBox( &maLbName, FALSE );
168 delete mpPrinterImpl;
171 // -----------------------------------------------------------------------
173 void PrintDialog::ImplSetImages()
175 if( ! GetSettings().GetStyleSettings().GetDialogColor().IsDark() )
177 maImgCollate.SetModeImage( Image( SvtResId( RID_IMG_PRNDLG_COLLATE ) ), BMP_COLOR_NORMAL );
178 maImgNotCollate.SetModeImage( Image( SvtResId( RID_IMG_PRNDLG_NOCOLLATE ) ), BMP_COLOR_NORMAL );
180 else
182 maImgCollate.SetModeImage( Image( SvtResId( RID_IMG_PRNDLG_COLLATE_HC ) ), BMP_COLOR_HIGHCONTRAST );
183 maImgNotCollate.SetModeImage( Image( SvtResId( RID_IMG_PRNDLG_NOCOLLATE_HC ) ), BMP_COLOR_HIGHCONTRAST );
187 // -----------------------------------------------------------------------
189 void PrintDialog::ImplSetInfo()
191 const QueueInfo* pInfo = Printer::GetQueueInfo( maLbName.GetSelectEntry(), true );
192 if ( pInfo )
194 maFiType.SetText( pInfo->GetDriver() );
195 maFiLocation.SetText( pInfo->GetLocation() );
196 maFiComment.SetText( pInfo->GetComment() );
197 maFiStatus.SetText( ImplPrnDlgGetStatusText( *pInfo ) );
199 else
201 XubString aTempStr;
202 maFiType.SetText( aTempStr );
203 maFiLocation.SetText( aTempStr );
204 maFiComment.SetText( aTempStr );
205 maFiStatus.SetText( aTempStr );
208 #ifdef UNX
209 if( pInfo && pInfo->GetLocation().EqualsAscii( "fax_queue" ) )
211 maFiPrintFile.Show( FALSE );
212 maCbxFilePrint.Show( FALSE );
213 maFiFaxNo.Show( TRUE );
214 maEdtFaxNo.Show( TRUE );
215 Printer* pPrinter = TEMPPRINTER() ? TEMPPRINTER() : mpPrinter;
216 maEdtFaxNo.SetText( pPrinter->GetJobValue( String::CreateFromAscii( "FAX#" ) ) );
218 Size aFTSize = maFiFaxNo.GetSizePixel();
219 long nTextWidth = maFiFaxNo.GetCtrlTextWidth( maFiFaxNo.GetText() ) + 10;
220 if ( aFTSize.Width() < nTextWidth )
222 long nDelta = nTextWidth - aFTSize.Width();
223 aFTSize.Width() = aFTSize.Width() + nDelta;
224 maFiFaxNo.SetSizePixel( aFTSize );
225 Size aEdtSize = maEdtFaxNo.GetSizePixel();
226 aEdtSize.Width() = aEdtSize.Width() - nDelta;
227 Point aEdtPos = maEdtFaxNo.GetPosPixel();
228 aEdtPos.X() = aEdtPos.X() + nDelta;
229 maEdtFaxNo.SetPosSizePixel( aEdtPos, aEdtSize );
232 else
233 #endif
235 maFiPrintFile.Show( TRUE );
236 maCbxFilePrint.Show( TRUE );
237 maFiFaxNo.Show( FALSE );
238 maEdtFaxNo.Show( FALSE );
243 // -----------------------------------------------------------------------
245 void PrintDialog::ImplCheckOK()
247 // Ueberprueft, ob der OK-Button enabled ist
248 BOOL bEnable = TRUE;
250 if ( bEnable && maRbtPages.IsChecked() )
251 bEnable = maEdtPages.GetText().Len() > 0;
253 if ( bEnable )
255 if ( TEMPPRINTER() )
256 bEnable = TEMPPRINTER()->IsValid();
257 else
258 bEnable = mpPrinter->IsValid();
261 maBtnOK.Enable( bEnable );
264 // -----------------------------------------------------------------------
266 void PrintDialog::ImplInitControls()
268 // Alles
269 if ( mbAll )
271 maRbtAll.Enable();
272 if( meCheckRange == PRINTDIALOG_ALL )
273 maRbtAll.Check( TRUE );
275 else
276 maRbtAll.Enable( FALSE );
278 // Selektion
279 if ( mbSelection )
281 maRbtSelection.Enable();
282 if ( meCheckRange == PRINTDIALOG_SELECTION )
283 maRbtSelection.Check( TRUE );
285 else
286 maRbtSelection.Enable( FALSE );
288 // Seiten
289 if ( mbRange )
291 maRbtPages.Enable();
292 maEdtPages.Show();
293 maEdtPages.SetText( maRangeText );
295 if( ( meCheckRange == PRINTDIALOG_FROMTO ) ||
296 ( meCheckRange == PRINTDIALOG_RANGE ) )
298 maRbtPages.Check( TRUE );
299 maEdtPages.Enable();
301 else
302 maEdtPages.Enable( FALSE );
304 else
306 maRbtPages.Enable( FALSE );
307 maEdtPages.Hide();
310 // Anzahl Kopien
311 maNumCopies.SetValue( mnCopyCount );
313 // Sortierung
314 maCbxCollate.Enable( mbCollate );
315 maCbxCollate.Check( mbCollateCheck );
317 // Zusaetze-Button
318 if ( mbOptions )
319 maBtnOptions.Show();
321 if ( !mbWithSheetsAndCells )
323 Size aMarginSize =
324 LogicToPixel( Size( RSC_SP_CTRL_GROUP_X, RSC_SP_CTRL_GROUP_Y ), MAP_APPFONT );
325 long nTempPos = maImgCollate.GetPosPixel().Y() +
326 maImgCollate.GetSizePixel().Height() + aMarginSize.Height();
327 long nDelta1 = maFlPrintRange.GetPosPixel().Y() - maFlPrint.GetPosPixel().Y();
328 long nDelta2 = maFlSepButtonLine.GetPosPixel().Y() - nTempPos;
330 maFlPrint.Hide();
331 maRbtAllSheets.Hide();
332 maRbtSelectedSheets.Hide();
333 maRbtSelectedCells.Hide();
334 maRbtSelection.Show();
336 Size aNewSize = GetSizePixel();
337 aNewSize.Height() -= nDelta2;
338 SetSizePixel( aNewSize );
339 aNewSize = maFlSepCopiesRange.GetSizePixel();
340 aNewSize.Height() -= nDelta2;
341 maFlSepCopiesRange.SetSizePixel( aNewSize );
343 long nDelta = nDelta1;
344 Window* pControls[] = { &maFlPrintRange, &maRbtAll,
345 &maRbtPages, &maEdtPages, &maRbtSelection, NULL,
346 &maFlSepButtonLine, &maBtnOptions, &maBtnOK,
347 &maBtnCancel, &maBtnHelp };
348 Window** pCtrl = pControls;
349 const sal_Int32 nCount = sizeof( pControls ) / sizeof( pControls[0] );
350 for ( sal_Int32 i = 0; i < nCount; ++i, ++pCtrl )
352 if ( NULL == *pCtrl )
354 nDelta = nDelta2;
355 continue;
357 Point aNewPos = (*pCtrl)->GetPosPixel();
358 aNewPos.Y() -= nDelta;
359 (*pCtrl)->SetPosPixel( aNewPos );
364 // -----------------------------------------------------------------------
366 void PrintDialog::ImplFillDialogData()
368 if ( maRbtAll.IsChecked() )
369 meCheckRange = PRINTDIALOG_ALL;
370 else if( maRbtSelection.IsChecked() )
371 meCheckRange = PRINTDIALOG_SELECTION;
372 else
374 meCheckRange = PRINTDIALOG_RANGE;
375 maRangeText = maEdtPages.GetText();
378 mnCopyCount = (USHORT) maNumCopies.GetValue();
379 mbCollateCheck = maCbxCollate.IsChecked();
381 // In Datei drucken
382 if ( maCbxFilePrint.IsChecked() )
383 mpPrinter->SetPrintFile( maFiPrintFile.GetText() );
384 mpPrinter->EnablePrintFile( maCbxFilePrint.IsChecked() );
387 // -----------------------------------------------------------------------
389 IMPL_LINK( PrintDialog, ImplStatusHdl, Timer*, EMPTYARG )
391 QueueInfo aInfo;
392 ImplPrnDlgUpdateQueueInfo( &maLbName, aInfo );
393 maFiStatus.SetText( ImplPrnDlgGetStatusText( aInfo ) );
395 return 0;
398 // -----------------------------------------------------------------------
400 IMPL_LINK( PrintDialog, ImplPropertiesHdl, void*, EMPTYARG )
402 if ( !TEMPPRINTER() )
403 TEMPPRINTER() = new Printer( mpPrinter->GetJobSetup() );
404 TEMPPRINTER()->Setup( this );
406 return 0;
409 // -----------------------------------------------------------------------
411 IMPL_LINK( PrintDialog, ImplChangePrinterHdl, void*, EMPTYARG )
413 TEMPPRINTER() = ImplPrnDlgListBoxSelect( &maLbName, &maBtnProperties,
414 mpPrinter, TEMPPRINTER() );
415 ImplSetInfo();
416 ImplCheckOK(); // Check if "OK" button can be enabled now!
418 return 0;
421 // -----------------------------------------------------------------------
423 bool PrintDialog::ImplGetFilename()
425 uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
426 static ::rtl::OUString aOldFile;
427 if( xFactory.is() )
429 uno::Sequence< uno::Any > aTempl( 1 );
430 aTempl.getArray()[0] <<= ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION;
431 uno::Reference< ui::dialogs::XFilePicker > xFilePicker(
432 xFactory->createInstanceWithArguments(
433 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ),
434 aTempl ), uno::UNO_QUERY );
435 DBG_ASSERT( xFilePicker.is(), "could not get FilePicker service" );
437 uno::Reference< ui::dialogs::XFilterManager > xFilterMgr( xFilePicker, uno::UNO_QUERY );
438 if( xFilePicker.is() && xFilterMgr.is() )
442 #ifdef UNX
443 // add PostScript and PDF
444 Printer* pPrinter = TEMPPRINTER() ? TEMPPRINTER() : mpPrinter;
445 bool bPS = true, bPDF = true;
446 if( pPrinter )
448 if( pPrinter->GetCapabilities( PRINTER_CAPABILITIES_PDF ) )
449 bPS = false;
450 else
451 bPDF = false;
453 if( bPS )
454 xFilterMgr->appendFilter( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PostScript" ) ), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*.ps" ) ) );
455 if( bPDF )
456 xFilterMgr->appendFilter( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Portable Document Format" ) ), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*.pdf" ) ) );
457 #elif defined WNT
458 xFilterMgr->appendFilter( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*.PRN" ) ), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*.prn" ) ) );
459 #endif
460 // add arbitrary files
461 xFilterMgr->appendFilter( maAllFilterStr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*.*" ) ) );
463 catch( lang::IllegalArgumentException rExc )
465 DBG_ERRORFILE( "caught IllegalArgumentException when registering filter\n" );
468 if( aOldFile.getLength() )
470 INetURLObject aUrl( aOldFile, INET_PROT_FILE );
471 xFilePicker->setDefaultName( aUrl.GetLastName() );
472 aUrl.CutLastName();
473 xFilePicker->setDisplayDirectory( aUrl.GetMainURL( INetURLObject::DECODE_TO_IURI ) );
476 if( xFilePicker->execute() == ui::dialogs::ExecutableDialogResults::OK )
478 uno::Sequence< ::rtl::OUString > aPathSeq( xFilePicker->getFiles() );
479 INetURLObject aObj( aPathSeq[0] );
480 maFiPrintFile.SetText( aOldFile = aObj.PathToFileName() );
481 return true;
483 return false;
487 // something went awry, lets try the old fashioned dialogue
488 Window* pDlgParent = IsReallyVisible() ? this : GetParent();
489 FileDialog aDlg( pDlgParent, WB_STDDIALOG | WB_SAVEAS );
490 #ifdef WNT
491 aDlg.AddFilter( String( RTL_CONSTASCII_USTRINGPARAM( "*.prn" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "*.prn" ) ) );
492 aDlg.SetDefaultExt( String( RTL_CONSTASCII_USTRINGPARAM( "prn" ) ) );
493 #elif defined UNX
494 aDlg.AddFilter( String( RTL_CONSTASCII_USTRINGPARAM( "PostScript" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "*.ps" ) ) );
495 aDlg.SetDefaultExt( String( RTL_CONSTASCII_USTRINGPARAM( "ps" ) ) );
496 #endif
498 if( aOldFile.getLength() )
499 aDlg.SetPath( aOldFile );
501 if( aDlg.Execute() )
503 String aTargetFile = aDlg.GetPath();
504 maFiPrintFile.SetText( aOldFile = aTargetFile );
505 return true;
508 return false;
511 // -----------------------------------------------------------------------
513 IMPL_LINK( PrintDialog, ImplModifyControlHdl, void*, p )
515 // Radiobuttons (Umfang)
516 if ( !p || (p == &maRbtAll) || (p == &maRbtPages) || (p == &maRbtSelection) )
518 BOOL bCheck = maRbtPages.IsChecked();
519 maEdtPages.Enable( bCheck );
520 if ( p == &maRbtPages )
521 maEdtPages.GrabFocus();
522 ImplCheckOK();
525 // Edit-Felder (Seiten)
526 if ( p == &maEdtPages )
527 ImplCheckOK();
529 if( p == &maEdtFaxNo )
531 Printer* pPrinter = TEMPPRINTER() ? TEMPPRINTER() : mpPrinter;
532 pPrinter->SetJobValue( String::CreateFromAscii( "FAX#" ), maEdtFaxNo.GetText() );
535 // Anzahl Kopien
536 BOOL bNumCopies = FALSE;
538 if ( !p || p == &maNumCopies )
540 if ( p )
541 bNumCopies = TRUE;
542 //BOOL bCopies = maNumCopies.GetValue() > 1;
543 maCbxCollate.Enable( mbCollate );
545 /*if ( !bCopies )
546 maCbxCollate.Check( FALSE );
547 else*/
548 if ( mbCollateCheck )
549 maCbxCollate.Check( TRUE );
552 // Sortieren
553 if ( !p || p == &maCbxCollate || bNumCopies )
555 BOOL bCheck = maCbxCollate.IsChecked();
557 if ( !bNumCopies )
558 mbCollateCheck = maCbxCollate.IsChecked();
560 if( bCheck )
562 maImgCollate.Show();
563 maImgNotCollate.Hide();
565 else
567 maImgCollate.Hide();
568 maImgNotCollate.Show();
572 // Zus"atze
573 if ( p == &maBtnOptions )
574 ClickOptionsHdl();
576 if( p == &maBtnOK )
578 EndDialog( maCbxFilePrint.IsChecked() ? ImplGetFilename() : TRUE );
581 return 0;
584 // -----------------------------------------------------------------------
586 long PrintDialog::ClickOptionsHdl()
588 if ( maOptionsHdlLink.IsSet() )
589 return maOptionsHdlLink.Call( this );
590 else
591 return TRUE;
594 // -----------------------------------------------------------------------
596 long PrintDialog::OK()
598 if ( maOKHdlLink.IsSet() )
599 return maOKHdlLink.Call( this );
600 else
601 return TRUE;
604 // -----------------------------------------------------------------------
606 void PrintDialog::EnableSheetRange( bool bEnable, PrintSheetRange eRange )
608 if ( mbWithSheetsAndCells )
610 switch ( eRange )
612 case PRINTSHEETS_ALL :
613 maRbtAllSheets.Enable( bEnable != false );
614 break;
615 case PRINTSHEETS_SELECTED_SHEETS :
616 maRbtSelectedSheets.Enable( bEnable != false );
617 break;
618 case PRINTSHEETS_SELECTED_CELLS :
619 maRbtSelectedCells.Enable( bEnable != false );
620 break;
621 default:
622 DBG_ERRORFILE( "PrintDialog::EnableSheetRange(): invalid range" );
627 // -----------------------------------------------------------------------
629 bool PrintDialog::IsSheetRangeEnabled( PrintSheetRange eRange ) const
631 if ( !mbWithSheetsAndCells )
632 return false;
634 bool bRet = false;
635 switch ( eRange )
637 case PRINTSHEETS_ALL :
638 bRet = maRbtAllSheets.IsEnabled() != FALSE;
639 break;
640 case PRINTSHEETS_SELECTED_SHEETS :
641 bRet = maRbtSelectedSheets.IsEnabled() != FALSE;
642 break;
643 case PRINTSHEETS_SELECTED_CELLS :
644 bRet = maRbtSelectedCells.IsEnabled() != FALSE;
645 break;
646 default:
647 DBG_ERRORFILE( "PrintDialog::IsSheetRangeEnabled(): invalid range" );
649 return bRet;
652 // -----------------------------------------------------------------------
654 void PrintDialog::CheckSheetRange( PrintSheetRange eRange )
656 if ( mbWithSheetsAndCells )
658 switch ( eRange )
660 case PRINTSHEETS_ALL :
661 maRbtAllSheets.Check();
662 break;
663 case PRINTSHEETS_SELECTED_SHEETS :
664 maRbtSelectedSheets.Check();
665 break;
666 case PRINTSHEETS_SELECTED_CELLS :
667 maRbtSelectedCells.Check();
668 break;
669 default:
670 DBG_ERRORFILE( "PrintDialog::CheckSheetRange(): invalid range" );
675 // -----------------------------------------------------------------------
677 PrintSheetRange PrintDialog::GetCheckedSheetRange() const
679 PrintSheetRange eRange = PRINTSHEETS_ALL;
680 if ( mbWithSheetsAndCells )
682 if ( maRbtSelectedSheets.IsChecked() )
683 eRange = PRINTSHEETS_SELECTED_SHEETS;
684 else if ( maRbtSelectedCells.IsChecked() )
685 eRange = PRINTSHEETS_SELECTED_CELLS;
687 return eRange;
690 // -----------------------------------------------------------------------
692 bool PrintDialog::IsSheetRangeChecked( PrintSheetRange eRange ) const
694 if ( !mbWithSheetsAndCells )
695 return false;
697 bool bRet = false;
698 switch ( eRange )
700 case PRINTSHEETS_ALL :
701 bRet = maRbtAllSheets.IsChecked() != FALSE;
702 break;
703 case PRINTSHEETS_SELECTED_SHEETS :
704 bRet = maRbtSelectedSheets.IsChecked() != FALSE;
705 break;
706 case PRINTSHEETS_SELECTED_CELLS :
707 bRet = maRbtSelectedCells.IsChecked() != FALSE;
708 break;
709 default:
710 DBG_ERRORFILE( "PrintDialog::IsSheetRangeChecked(): invalid range" );
712 return bRet;
715 // -----------------------------------------------------------------------
717 long PrintDialog::Notify( NotifyEvent& rNEvt )
719 if ( (rNEvt.GetType() == EVENT_GETFOCUS) && IsReallyVisible() )
720 ImplStatusHdl( &maStatusTimer );
721 else if ( rNEvt.GetType() == EVENT_KEYINPUT )
723 if ( rNEvt.GetKeyEvent()->GetKeyCode().GetCode() == KEY_F1 && mpPrinterImpl->m_bHelpDisabled )
724 return 1; // do nothing
727 return ModalDialog::Notify( rNEvt );
730 // -----------------------------------------------------------------------
732 void PrintDialog::DataChanged( const DataChangedEvent& rDCEvt )
734 if ( rDCEvt.GetType() == DATACHANGED_PRINTER )
736 TEMPPRINTER() = ImplPrnDlgUpdatePrinter( mpPrinter, TEMPPRINTER() );
737 Printer* pPrn;
738 if ( TEMPPRINTER() )
739 pPrn = TEMPPRINTER();
740 else
741 pPrn = mpPrinter;
742 ImplFillPrnDlgListBox( pPrn, &maLbName, &maBtnProperties );
743 ImplSetInfo();
744 ImplCheckOK();
746 else if ( rDCEvt.GetType() == DATACHANGED_SETTINGS )
747 ImplSetImages();
749 ModalDialog::DataChanged( rDCEvt );
752 // -----------------------------------------------------------------------
754 short PrintDialog::Execute()
756 if ( !mpPrinter || mpPrinter->IsPrinting() || mpPrinter->IsJobActive() )
758 DBG_ERRORFILE( "PrinterSetupDialog::Execute() - No Printer or printer is printing" );
759 return FALSE;
762 // check if the printer brings up its own dialog
763 // in that case leave the work to that dialog
764 if( mpPrinter->GetCapabilities( PRINTER_CAPABILITIES_EXTERNALDIALOG ) )
765 return TRUE;
767 Printer::updatePrinters();
769 // Controls initialisieren
770 ImplFillPrnDlgListBox( mpPrinter, &maLbName, &maBtnProperties );
771 ImplSetInfo();
772 maStatusTimer.Start();
773 ImplInitControls();
774 maNumCopies.GrabFocus();
775 maNumCopies.SetSelection( Selection( 0, maNumCopies.GetText().Len() ) );
776 ImplModifyControlHdl( NULL );
778 // Dialog starten
779 short nRet = ModalDialog::Execute();
781 // Wenn Dialog mit OK beendet wurde, dann die Daten updaten
782 if( nRet == TRUE )
784 if ( TEMPPRINTER() )
785 mpPrinter->SetPrinterProps( TEMPPRINTER() );
786 ImplFillDialogData();
789 maStatusTimer.Stop();
791 return nRet;
794 // -----------------------------------------------------------------------
796 void PrintDialog::DisableHelp()
798 mpPrinterImpl->m_bHelpDisabled = sal_True;
799 maBtnHelp.Disable();