include/vcl/print.hxx | 4 ++ sc/source/ui/unoobj/docuno.cxx | 63 +++++++++++++++++++++++++++++------------ vcl/source/gdi/print.cxx | 1 vcl/source/gdi/print3.cxx | 10 +++++- vcl/source/window/printdlg.cxx | 7 ++-- 5 files changed, 64 insertions(+), 21 deletions(-)
New commits: commit 2fc3251ef884ba75077126a631a55c9a51a47d1d Author: Tibor Nagy <[email protected]> AuthorDate: Wed Feb 28 11:13:10 2024 +0100 Commit: Thorsten Behrens <[email protected]> CommitDate: Mon Mar 4 02:09:14 2024 +0100 tdf#155218 sc: fix regression page orientation in print dialog The print page orientation set in the Print Dialog displays incorrect print area borders on the sheet after closing the Print Dialog or interrupting the printing process. The print dialog increase in size if the "Pages" and "All pages" radio buttons are toggled many times.(problem is not reproduced on Windows) regression was made by: I5e494a0714e398221bee00744d7e25c419a41df7 Includes "Read of uninitialized Printer::mbResetPrintArea" fixup by Stephan. Change-Id: I5a0ab3d781b21eff575afaebb233237eff1827d5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164085 Tested-by: Jenkins Reviewed-by: Nagy Tibor <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164312 Tested-by: Thorsten Behrens <[email protected]> Reviewed-by: Thorsten Behrens <[email protected]> diff --git a/include/vcl/print.hxx b/include/vcl/print.hxx index 870ed5d915a1..53ff09694556 100644 --- a/include/vcl/print.hxx +++ b/include/vcl/print.hxx @@ -93,6 +93,7 @@ private: bool mbNewJobSetup; bool mbSinglePrintJobs; bool mbUsePrintSetting; + bool mbResetPrintArea; VCL_DLLPRIVATE void ImplInitData(); VCL_DLLPRIVATE void ImplInit( SalPrinterQueueInfo* pInfo ); @@ -222,6 +223,8 @@ public: VCL_DLLPRIVATE void SetPrinterOptions( const vcl::printer::Options& rOptions ); const vcl::printer::Options& GetPrinterOptions() const { return( *mpPrinterOptions ); } + void ResetPrintArea(bool bReset) { mbResetPrintArea = bReset; } + bool IsPrintAreaReset() { return mbResetPrintArea; } void SetUsePrintDialogSetting(bool bUsed) { mbUsePrintSetting = bUsed; } bool IsUsePrintDialogSetting() { return mbUsePrintSetting; } void SetPrintPageSize(Size aPrintPageSize) { maPrintPageSize = aPrintPageSize; } @@ -482,6 +485,7 @@ public: bool getPrinterModified() const; VCL_DLLPRIVATE void pushPropertiesToPrinter(); VCL_DLLPRIVATE void resetPaperToLastConfigured(); + VCL_DLLPRIVATE void resetPrintArea(); void setJobState( css::view::PrintableState ); VCL_DLLPRIVATE void setupPrinter( weld::Window* i_pDlgParent ); diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index d70716b0a4c1..b572ae28c975 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -1570,22 +1570,20 @@ static bool lcl_ParseTarget( const OUString& rTarget, ScRange& rTargetRange, too return bRangeValid; } - static void lcl_SetPrintPage(const uno::Sequence<beans::PropertyValue>& rOptions, Size& aSize, - bool& bLandscape, bool& bUsed) +static Printer* lcl_GetPrinter(const uno::Sequence<beans::PropertyValue>& rOptions) { + Printer* pPrinter = nullptr; OutputDevice* pDev = lcl_GetRenderDevice(rOptions); if (pDev && pDev->GetOutDevType() == OUTDEV_PRINTER) - { - Printer* pPrinter = dynamic_cast<Printer*>(pDev); - if (pPrinter && pPrinter->IsUsePrintDialogSetting()) - { - bUsed = true; - bLandscape = (pPrinter->GetOrientation() == Orientation::Landscape); - aSize = pPrinter->GetPrintPageSize(); - aSize.setWidth(o3tl::convert(aSize.Width(), o3tl::Length::mm100, o3tl::Length::twip)); - aSize.setHeight(o3tl::convert(aSize.Height(), o3tl::Length::mm100, o3tl::Length::twip)); - } - } + pPrinter = dynamic_cast<Printer*>(pDev); + return pPrinter; +} + +static Size lcl_GetPrintPageSize(Size aSize) +{ + aSize.setWidth(o3tl::convert(aSize.Width(), o3tl::Length::mm100, o3tl::Length::twip)); + aSize.setHeight(o3tl::convert(aSize.Height(), o3tl::Length::mm100, o3tl::Length::twip)); + return aSize; } bool ScModelObj::FillRenderMarkData( const uno::Any& aSelection, @@ -1775,15 +1773,28 @@ sal_Int32 SAL_CALL ScModelObj::getRendererCount(const uno::Any& aSelection, return 0; Size aPrintPageSize; + bool bPrintAreaReset = false; bool bPrintPageLandscape = false; bool bUsePrintDialogSetting = false; - lcl_SetPrintPage(rOptions, aPrintPageSize, bPrintPageLandscape, bUsePrintDialogSetting); + Printer* pPrinter = lcl_GetPrinter(rOptions); + if (pPrinter) + { + if (pPrinter->IsUsePrintDialogSetting()) + { + bUsePrintDialogSetting = true; + bPrintPageLandscape = (pPrinter->GetOrientation() == Orientation::Landscape); + aPrintPageSize = lcl_GetPrintPageSize(pPrinter->GetPrintPageSize()); + } + else // reset the print area created by the Print Dialog to the page style's print area. + bPrintAreaReset = pPrinter->IsPrintAreaReset(); + } // The same ScPrintFuncCache object in pPrintFuncCache is used as long as // the same selection is used (aStatus) and the document isn't changed // (pPrintFuncCache is cleared in Notify handler) - if (!pPrintFuncCache || !pPrintFuncCache->IsSameSelection(aStatus) || bUsePrintDialogSetting) + if (!pPrintFuncCache || !pPrintFuncCache->IsSameSelection(aStatus) || bUsePrintDialogSetting + || bPrintAreaReset) { pPrintFuncCache.reset(new ScPrintFuncCache(pDocShell, aMark, aStatus, aPrintPageSize, bPrintPageLandscape, bUsePrintDialogSetting)); @@ -2015,7 +2026,16 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32 Size aPrintPageSize; bool bPrintPageLandscape = false; bool bUsePrintDialogSetting = false; - lcl_SetPrintPage(rOptions, aPrintPageSize, bPrintPageLandscape, bUsePrintDialogSetting); + Printer* pPrinter = lcl_GetPrinter(rOptions); + if (pPrinter) + { + if (pPrinter->IsUsePrintDialogSetting()) + { + bUsePrintDialogSetting = true; + bPrintPageLandscape = (pPrinter->GetOrientation() == Orientation::Landscape); + aPrintPageSize = lcl_GetPrintPageSize(pPrinter->GetPrintPageSize()); + } + } std::unique_ptr<ScPrintFunc, o3tl::default_delete<ScPrintFunc>> pPrintFunc; if (m_pPrintState && m_pPrintState->nPrintTab == nTab) @@ -2251,7 +2271,16 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec Size aPrintPageSize; bool bPrintPageLandscape = false; bool bUsePrintDialogSetting = false; - lcl_SetPrintPage(rOptions, aPrintPageSize, bPrintPageLandscape, bUsePrintDialogSetting); + Printer* pPrinter = lcl_GetPrinter(rOptions); + if (pPrinter) + { + if (pPrinter->IsUsePrintDialogSetting()) + { + bUsePrintDialogSetting = true; + bPrintPageLandscape = (pPrinter->GetOrientation() == Orientation::Landscape); + aPrintPageSize = lcl_GetPrintPageSize(pPrinter->GetPrintPageSize()); + } + } // to increase performance, ScPrintState might be used here for subsequent // pages of the same sheet diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx index 98aca69aed5d..c77d175e44aa 100644 --- a/vcl/source/gdi/print.cxx +++ b/vcl/source/gdi/print.cxx @@ -450,6 +450,7 @@ void Printer::ImplInitData() mbNewJobSetup = false; mbSinglePrintJobs = false; mbUsePrintSetting = false; + mbResetPrintArea = false; mpInfoPrinter = nullptr; mpPrinter = nullptr; mpDisplayDev = nullptr; diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx index 5fb7b2b286d1..2df79a645a5b 100644 --- a/vcl/source/gdi/print3.cxx +++ b/vcl/source/gdi/print3.cxx @@ -514,7 +514,6 @@ bool Printer::PreparePrintJob(std::shared_ptr<PrinterController> xController, PrintDialog aDlg(xController->getWindow(), xController); if (!aDlg.run()) { - xController->getPrinter()->SetUsePrintDialogSetting(false); xController->abortJob(); return false; } @@ -565,6 +564,7 @@ bool Printer::ExecutePrintJob(const std::shared_ptr<PrinterController>& xControl void Printer::FinishPrintJob(const std::shared_ptr<PrinterController>& xController) { + xController->resetPrintArea(); xController->resetPaperToLastConfigured(); xController->jobFinished( xController->getJobState() ); } @@ -1015,6 +1015,14 @@ void vcl::ImplPrinterControllerData::resetPaperToLastConfigured() mxPrinter->Pop(); } +// reset the print area created by the Print Dialog to the page style's print area. +void PrinterController::resetPrintArea() +{ + mpImplData->mxPrinter->ResetPrintArea(true); + mpImplData->mxPrinter->SetUsePrintDialogSetting(false); + getPageCount(); +} + int PrinterController::getPageCountProtected() const { const MapMode aMapMode( MapUnit::Map100thMM ); diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx index ff3dd99dcaca..baa3483d550d 100644 --- a/vcl/source/window/printdlg.cxx +++ b/vcl/source/window/printdlg.cxx @@ -1014,8 +1014,9 @@ void PrintDialog::updatePageRange(sal_Int32 nPages) { aBuf.append("-" + OUString::number(nPages)); } - maPController->setValue("PageRange", css::uno::Any(aBuf.makeStringAndClear())); - setupOptionalUI(); + OUString sRange = aBuf.makeStringAndClear(); + mxPageRangeEdit->set_text(sRange); + maPController->setValue("PageRange", Any(sRange)); } } @@ -2185,7 +2186,7 @@ IMPL_LINK( PrintDialog, UIOption_SpinModifyHdl, weld::SpinButton&, i_rBox, void IMPL_LINK( PrintDialog, UIOption_EntryModifyHdl, weld::Entry&, i_rBox, void ) { PropertyValue* pVal = getValueForWindow( &i_rBox ); - if( pVal ) + if( pVal && mxPageRangesRadioButton->get_active() ) { makeEnabled( &i_rBox );
