diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2022-01-31 20:27:54 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2022-02-01 11:16:43 +0100 |
commit | ddaebfb270c4b52ddebaf678a9352312c75247fa (patch) | |
tree | e64bb9ecbcece35a7cd4adb4b8c66bfead2ddc0b /vcl/source | |
parent | de5aa409353c839483df21d47254fd2a508ab7d9 (diff) |
fix the orientation combobox in the print dialog
Changing the orientation value to anything else than 'Automatic'
didn't do anything by default. This was because by default
neither isPaperSizeFromUser() nor getPapersizeFromSetup()
were set, so PrintDialog::setPaperOrientation() did nothing.
It looks to me like 8cbdc6a068ad88fc43a98bd0f88 that introduced it
was rather broken (not just this bug, but also e.g. the ugly
modifying of the paper sizes by non-const reference from a const
function). In fact this whole stuff still looks broken to me, why
does it change paper size instead of just setting the orientation?
It seems like the orientation gets reset, or maybe the setting
was just a band-aid. I don't know how to fix that all though.
Change-Id: If5fdf4c47e06f2b0797d27126d21b3451b8334cf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129239
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/gdi/print3.cxx | 51 | ||||
-rw-r--r-- | vcl/source/window/printdlg.cxx | 37 |
2 files changed, 37 insertions, 51 deletions
diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx index f33d59820caa..aecc43e15e33 100644 --- a/vcl/source/gdi/print3.cxx +++ b/vcl/source/gdi/print3.cxx @@ -158,6 +158,7 @@ public: bool mbReversePageOrder; bool mbPapersizeFromSetup; bool mbPapersizeFromUser; + bool mbOrientationFromUser; bool mbPrinterModified; css::view::PrintableState meJobState; @@ -171,6 +172,8 @@ public: Size maDefaultPageSize; // set by user through print dialog Size maUserPageSize; + // set by user through print dialog + Orientation meUserOrientation; // set by user through printer properties subdialog of printer settings dialog sal_Int32 mnDefaultPaperBin; // Set by user through printer properties subdialog of print dialog. @@ -197,6 +200,7 @@ public: mbReversePageOrder( false ), mbPapersizeFromSetup( false ), mbPapersizeFromUser( false ), + mbOrientationFromUser( false ), mbPrinterModified( false ), meJobState( css::view::PrintableState_JOB_STARTED ), mnDefaultPaperBin( -1 ), @@ -212,15 +216,27 @@ public: } } - const Size& getRealPaperSize( const Size& i_rPageSize, bool bNoNUP ) const + Size getRealPaperSize( const Size& i_rPageSize, bool bNoNUP ) const { + Size size; if ( mbPapersizeFromUser ) - return maUserPageSize; - if( mbPapersizeFromSetup ) - return maDefaultPageSize; - if( maMultiPage.nRows * maMultiPage.nColumns > 1 && ! bNoNUP ) - return maMultiPage.aPaperSize; - return i_rPageSize; + size = maUserPageSize; + else if( mbPapersizeFromSetup ) + size = maDefaultPageSize; + else if( maMultiPage.nRows * maMultiPage.nColumns > 1 && ! bNoNUP ) + size = maMultiPage.aPaperSize; + else + size = i_rPageSize; + if(mbOrientationFromUser) + { + if ( (meUserOrientation == Orientation::Portrait && size.Width() > size.Height()) || + (meUserOrientation == Orientation::Landscape && size.Width() < size.Height()) ) + { + // coverity[swapped-arguments : FALSE] - this is in the correct order + size = Size( size.Height(), size.Width() ); + } + } + return size; } PrinterController::PageSize modifyJobSetup( const css::uno::Sequence< css::beans::PropertyValue >& i_rProps ); void resetPaperToLastConfigured(); @@ -824,6 +840,7 @@ void PrinterController::setPrinter( const VclPtr<Printer>& i_rPrinter ) } mpImplData->mbPapersizeFromUser = false; + mpImplData->mbOrientationFromUser = false; mpImplData->mxPrinter->Pop(); mpImplData->mnFixedPaperBin = -1; } @@ -1407,7 +1424,10 @@ void PrinterController::setPapersizeFromSetup( bool i_bPapersizeFromSetup ) mpImplData->mbPapersizeFromSetup = i_bPapersizeFromSetup; mpImplData->mxPrinter->SetPrinterSettingsPreferred( i_bPapersizeFromSetup ); if ( i_bPapersizeFromSetup ) - mpImplData->mbPapersizeFromUser = !i_bPapersizeFromSetup; + { + mpImplData->mbPapersizeFromUser = false; + mpImplData->mbOrientationFromUser = false; + } } bool PrinterController::getPapersizeFromSetup() const @@ -1415,11 +1435,6 @@ bool PrinterController::getPapersizeFromSetup() const return mpImplData->mbPapersizeFromSetup; } -Size& PrinterController::getPaperSizeSetup() const -{ - return mpImplData->maDefaultPageSize; -} - void PrinterController::setPaperSizeFromUser( Size i_aUserSize ) { mpImplData->mbPapersizeFromUser = true; @@ -1429,14 +1444,10 @@ void PrinterController::setPaperSizeFromUser( Size i_aUserSize ) mpImplData->maUserPageSize = i_aUserSize; } -Size& PrinterController::getPaperSizeFromUser() const -{ - return mpImplData->maUserPageSize; -} - -bool PrinterController::isPaperSizeFromUser() const +void PrinterController::setOrientationFromUser( Orientation eOrientation, bool set ) { - return mpImplData->mbPapersizeFromUser; + mpImplData->mbOrientationFromUser = set; + mpImplData->meUserOrientation = eOrientation; } void PrinterController::setPrinterModified( bool i_bPrinterModified ) diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx index e98afe8db92b..bb89ebbd5e9b 100644 --- a/vcl/source/window/printdlg.cxx +++ b/vcl/source/window/printdlg.cxx @@ -1025,35 +1025,12 @@ bool PrintDialog::hasOrientationChanged() const || (nOrientation == ORIENTATION_PORTRAIT && eOrientation == Orientation::Landscape); } -// make sure paper size matches paper orientation -void PrintDialog::checkPaperSize( Size& rPaperSize ) -{ - Orientation eOrientation = maPController->getPrinter()->GetOrientation(); - if ( (eOrientation == Orientation::Portrait && rPaperSize.Width() > rPaperSize.Height()) || - (eOrientation == Orientation::Landscape && rPaperSize.Width() < rPaperSize.Height()) ) - { - // coverity[swapped-arguments : FALSE] - this is in the correct order - rPaperSize = Size( rPaperSize.Height(), rPaperSize.Width() ); - } -} - // Always use this function to set paper orientation to make sure everything behaves well -void PrintDialog::setPaperOrientation( Orientation eOrientation ) +void PrintDialog::setPaperOrientation( Orientation eOrientation, bool fromUser ) { VclPtr<Printer> aPrt( maPController->getPrinter() ); aPrt->SetOrientation( eOrientation ); - - // check if it's necessary to swap width and height of paper - if ( maPController->isPaperSizeFromUser() ) - { - Size& aPaperSize = maPController->getPaperSizeFromUser(); - checkPaperSize( aPaperSize ); - } - else if ( maPController->getPapersizeFromSetup() ) - { - Size& aPaperSize = maPController->getPaperSizeSetup(); - checkPaperSize( aPaperSize ); - } + maPController->setOrientationFromUser( eOrientation, fromUser ); } void PrintDialog::checkControlDependencies() @@ -1174,12 +1151,12 @@ void PrintDialog::updateNup( bool i_bMayUseCache ) if( aMultiSize.Width() > aMultiSize.Height() ) // fits better on landscape { aMPS.aPaperSize = maNupLandscapeSize; - setPaperOrientation( Orientation::Landscape ); + setPaperOrientation( Orientation::Landscape, false ); } else { aMPS.aPaperSize = maNupPortraitSize; - setPaperOrientation( Orientation::Portrait ); + setPaperOrientation( Orientation::Portrait, false ); } } @@ -2000,7 +1977,7 @@ IMPL_LINK( PrintDialog, SelectHdl, weld::ComboBox&, rBox, void ) { int nOrientation = mxOrientationBox->get_active(); if ( nOrientation != ORIENTATION_AUTOMATIC ) - setPaperOrientation( static_cast<Orientation>( nOrientation - 1 ) ); + setPaperOrientation( static_cast<Orientation>( nOrientation - 1 ), true ); updateNup( false ); } @@ -2026,9 +2003,7 @@ IMPL_LINK( PrintDialog, SelectHdl, weld::ComboBox&, rBox, void ) else aPrt->SetPaper( mePaper ); - Size aPaperSize( aInfo.getWidth(), aInfo.getHeight() ); - checkPaperSize( aPaperSize ); - maPController->setPaperSizeFromUser( aPaperSize ); + maPController->setPaperSizeFromUser( Size( aInfo.getWidth(), aInfo.getHeight() ) ); maUpdatePreviewIdle.Start(); } |