From 73b590484023d59300e795e52f80da3f4de448f2 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Thu, 4 Feb 2021 20:48:41 +0000 Subject: improve SalInstanceWidget::draw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I9acb8dfceee586b343feb184e0788491d66d24a5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110427 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- vcl/source/app/salvtables.cxx | 54 +++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 12 deletions(-) (limited to 'vcl/source/app') diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index c1ac2432ff7c..f983237dafed 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -1172,39 +1172,69 @@ std::unique_ptr SalInstanceWidget::weld_parent() const return std::make_unique(pParent, m_pBuilder, false); } -namespace -{ -void DoRecursivePaint(vcl::Window* pWindow, const Point& rPos, OutputDevice& rOutput) +void SalInstanceWidget::DoRecursivePaint(vcl::Window* pWindow, const Point& rRenderLogicPos, + OutputDevice& rOutput) { - Size aSize = pWindow->GetSizePixel(); + pWindow->Push(); + bool bOldMapModeEnabled = pWindow->IsMapModeEnabled(); + + if (pWindow->GetMapMode().GetMapUnit() != rOutput.GetMapMode().GetMapUnit()) + { + // This is needed for e.g. the scrollbar in writer comments in margins that has its map unit in pixels + // as seen with bin/run gtktiledviewer --enable-tiled-annotations on a document containing a comment + // long enough to need a scrollbar + pWindow->EnableMapMode(); + MapMode aMapMode = pWindow->GetMapMode(); + aMapMode.SetMapUnit(rOutput.GetMapMode().GetMapUnit()); + aMapMode.SetScaleX(rOutput.GetMapMode().GetScaleX()); + aMapMode.SetScaleY(rOutput.GetMapMode().GetScaleY()); + pWindow->SetMapMode(aMapMode); + } VclPtr xOutput(VclPtr::Create(DeviceFormat::DEFAULT)); - xOutput->SetOutputSizePixel(aSize); - xOutput->DrawOutDev(Point(), aSize, rPos, aSize, rOutput); + Size aChildSizePixel(pWindow->GetSizePixel()); + xOutput->SetOutputSizePixel(aChildSizePixel); - //set ReallyVisible to match Visible, we restore the original - //state after Paint + MapMode aMapMode(xOutput->GetMapMode()); + aMapMode.SetMapUnit(rOutput.GetMapMode().GetMapUnit()); + aMapMode.SetScaleX(rOutput.GetMapMode().GetScaleX()); + aMapMode.SetScaleY(rOutput.GetMapMode().GetScaleY()); + xOutput->SetMapMode(aMapMode); + + Size aTempLogicSize(xOutput->PixelToLogic(aChildSizePixel)); + Size aRenderLogicSize(rOutput.PixelToLogic(aChildSizePixel)); + + xOutput->DrawOutDev(Point(), aTempLogicSize, rRenderLogicPos, aRenderLogicSize, rOutput); + + //set ReallyVisible to match Visible, we restore the original state after Paint WindowImpl* pImpl = pWindow->ImplGetWindowImpl(); bool bRVisible = pImpl->mbReallyVisible; pImpl->mbReallyVisible = pWindow->IsVisible(); - pWindow->Paint(*xOutput, tools::Rectangle(Point(), pWindow->PixelToLogic(aSize))); + pWindow->ApplySettings(*xOutput); + pWindow->Paint(*xOutput, tools::Rectangle(Point(), pWindow->PixelToLogic(aChildSizePixel))); pImpl->mbReallyVisible = bRVisible; - rOutput.DrawOutDev(rPos, aSize, Point(), aSize, *xOutput); + rOutput.DrawOutDev(rRenderLogicPos, aRenderLogicSize, Point(), aTempLogicSize, *xOutput); xOutput.disposeAndClear(); + pWindow->EnableMapMode(bOldMapModeEnabled); + pWindow->Pop(); + for (vcl::Window* pChild = pWindow->GetWindow(GetWindowType::FirstChild); pChild; pChild = pChild->GetWindow(GetWindowType::Next)) { if (!pChild->IsVisible()) continue; - DoRecursivePaint(pChild, rPos + rOutput.PixelToLogic(pChild->GetPosPixel()), rOutput); + Point aRelPos(pChild->GetPosPixel()); + Size aRelLogicOffset(rOutput.PixelToLogic(Size(aRelPos.X(), aRelPos.Y()))); + DoRecursivePaint(pChild, + rRenderLogicPos + Point(aRelLogicOffset.Width(), aRelLogicOffset.Height()), + rOutput); } } -} void SalInstanceWidget::draw(OutputDevice& rOutput, const Point& rPos, const Size& rSizePixel) { -- cgit