From 2c23a96f7b6888c0e05fdc2aba57f03cd797b647 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 15 May 2018 22:58:38 -0300 Subject: [PATCH] tdf#67905 adds an option to disable print preview in print dialog Change-Id: Id6dd1724a1b8f61d94f0685f63d28b3cff19988f --- vcl/inc/printdlg.hxx | 5 ++- vcl/inc/strings.hrc | 1 + vcl/source/window/printdlg.cxx | 64 +++++++++++++++++++++++++++------- vcl/uiconfig/ui/printdialog.ui | 16 +++++++++ 4 files changed, 73 insertions(+), 13 deletions(-) diff --git a/vcl/inc/printdlg.hxx b/vcl/inc/printdlg.hxx index 077711896bcd..8799c8dba277 100644 --- a/vcl/inc/printdlg.hxx +++ b/vcl/inc/printdlg.hxx @@ -181,13 +181,15 @@ namespace vcl VclPtr mpNumPagesText; VclPtr mpBackwardBtn; VclPtr mpForwardBtn; + VclPtr mpPreviewBox; VclPtr mpOKButton; VclPtr mpCancelButton; VclPtr mpHelpButton; OUString maPageStr; - OUString const maNoPageStr; + OUString maNoPageStr; + OUString maNoPreviewStr; sal_Int32 mnCurPage; sal_Int32 mnCachedPages; @@ -247,6 +249,7 @@ namespace vcl bool isPrintToFile(); bool isCollate(); bool isSingleJobs(); + bool hasPreview(); void previewForward(); void previewBackward(); diff --git a/vcl/inc/strings.hrc b/vcl/inc/strings.hrc index 4b33177c74c1..ab696bd43b3f 100644 --- a/vcl/inc/strings.hrc +++ b/vcl/inc/strings.hrc @@ -113,6 +113,7 @@ #define SV_ACCESSERROR_NO_FONTS NC_("SV_ACCESSERROR_NO_FONTS", "No fonts could be found on the system.") #define SV_PRINT_NOPAGES NC_("SV_PRINT_NOPAGES", "No pages") +#define SV_PRINT_NOPREVIEW NC_("SV_PRINT_NOPREVIEW", "Preview is disabled") #define SV_PRINT_TOFILE_TXT NC_("SV_PRINT_TOFILE_TXT", "Print to File...") #define SV_PRINT_DEFPRT_TXT NC_("SV_PRINT_DEFPRT_TXT", "Default printer") #define SV_PRINT_PRINTPREVIEW_TXT NC_("SV_PRINT_PRINTPREVIEW_TXT", "Print preview") diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx index ce0e4b03fa3f..32bc19824d64 100644 --- a/vcl/source/window/printdlg.cxx +++ b/vcl/source/window/printdlg.cxx @@ -653,6 +653,7 @@ PrintDialog::PrintDialog( vcl::Window* i_pParent, const std::shared_ptrGetText(); @@ -717,9 +719,6 @@ PrintDialog::PrintDialog( vcl::Window* i_pParent, const std::shared_ptrresetPrinterOptions( false ); - // get the first page - preparePreview( true, true ); - // update the text fields for the printer updatePrinterText(); @@ -750,6 +749,7 @@ PrintDialog::PrintDialog( vcl::Window* i_pParent, const std::shared_ptrSetClickHdl( LINK( this, PrintDialog, ClickHdl ) ); mpForwardBtn->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) ); mpBackwardBtn->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) ); + mpPreviewBox->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) ); maJobPage.mpCollateBox->SetToggleHdl( LINK( this, PrintDialog, ToggleHdl ) ); maJobPage.mpSetupButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) ); @@ -808,6 +808,7 @@ void PrintDialog::dispose() mpNumPagesText.clear(); mpBackwardBtn.clear(); mpForwardBtn.clear(); + mpPreviewBox.clear(); mpOKButton.clear(); mpCancelButton.clear(); mpHelpButton.clear(); @@ -837,6 +838,16 @@ void PrintDialog::readFromSettings() } } + aValue = pItem->getValue( "PrintDialog", "HasPreview" ); + if ( aValue.equalsIgnoreAsciiCase("true") ) + { + mpPreviewBox->Check(); + } + else + { + mpPreviewBox->Check( false ); + } + // persistent window state OUString aWinState( pItem->getValue( "PrintDialog", "WindowState" ) ); @@ -867,6 +878,9 @@ void PrintDialog::storeToSettings() "WindowState", OStringToOUString( GetWindowState(), RTL_TEXTENCODING_UTF8 ) ); + pItem->setValue( "PrintDialog", + "HasPreview", + hasPreview() ? OUString("true") : OUString("false") ); pItem->Commit(); } @@ -885,7 +899,12 @@ bool PrintDialog::isSingleJobs() return maOptionsPage.mpCollateSingleJobsBox->IsChecked(); } -static void setHelpId( vcl::Window* i_pWindow, const Sequence< OUString >& i_rHelpIds, sal_Int32 i_nIndex ) +bool PrintDialog::hasPreview() +{ + return mpPreviewBox->IsChecked(); +} + +void setHelpId( vcl::Window* i_pWindow, const Sequence< OUString >& i_rHelpIds, sal_Int32 i_nIndex ) { if( i_nIndex >= 0 && i_nIndex < i_rHelpIds.getLength() ) i_pWindow->SetHelpId( OUStringToOString( i_rHelpIds.getConstArray()[i_nIndex], RTL_TEXTENCODING_UTF8 ) ); @@ -1370,25 +1389,43 @@ void PrintDialog::setPreviewText() void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache ) { + VclPtr aPrt( maPController->getPrinter() ); + Size aCurPageSize = aPrt->PixelToLogic( aPrt->GetPaperSizePixel(), MapMode( MapUnit::Map100thMM ) ); + GDIMetaFile aMtf; + // page range may have changed depending on options sal_Int32 nPages = maPController->getFilteredPageCount(); mnCachedPages = nPages; + mpPageEdit->SetMin( 1 ); + mpPageEdit->SetMax( nPages ); + + setPreviewText(); + + if ( !hasPreview() ) + { + mpPreviewWindow->setPreview( aMtf, aCurPageSize, + aPrt->GetPaperName(), + maNoPreviewStr, + aPrt->GetDPIX(), aPrt->GetDPIY(), + aPrt->GetPrinterOptions().IsConvertToGreyscales() + ); + + mpForwardBtn->Enable( false ); + mpBackwardBtn->Enable( false ); + mpPageEdit->Enable( false ); + + return; + } + if( mnCurPage >= nPages ) mnCurPage = nPages-1; if( mnCurPage < 0 ) mnCurPage = 0; - setPreviewText(); - - mpPageEdit->SetMin( 1 ); - mpPageEdit->SetMax( nPages ); - if( i_bNewPage ) { const MapMode aMapMode( MapUnit::Map100thMM ); - GDIMetaFile aMtf; - VclPtr aPrt( maPController->getPrinter() ); if( nPages > 0 ) { PrinterController::PageSize aPageSize = @@ -1400,7 +1437,6 @@ void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache ) } } - Size aCurPageSize = aPrt->PixelToLogic( aPrt->GetPaperSizePixel(), MapMode( MapUnit::Map100thMM ) ); mpPreviewWindow->setPreview( aMtf, aCurPageSize, aPrt->GetPaperName(), nPages > 0 ? OUString() : maNoPageStr, @@ -1650,6 +1686,10 @@ IMPL_LINK( PrintDialog, ClickHdl, Button*, pButton, void ) pHelp->Start( "vcl/ui/printdialog", mpOKButton ); } } + else if ( pButton == mpPreviewBox ) + { + preparePreview( true, true ); + } else if( pButton == mpForwardBtn ) { previewForward(); diff --git a/vcl/uiconfig/ui/printdialog.ui b/vcl/uiconfig/ui/printdialog.ui index d832944052cc..0c1a7c7ab450 100644 --- a/vcl/uiconfig/ui/printdialog.ui +++ b/vcl/uiconfig/ui/printdialog.ui @@ -273,6 +273,22 @@ True 1 + + + Preview + True + True + 0 + center + 30 + 30 + + + False + True + end + +