diff --git a/starmath/inc/ElementsDockingWindow.hxx b/starmath/inc/ElementsDockingWindow.hxx index fe712401f77343a70e981145f1f4003107241d5c..c98072143bdcb87d4f12a79f741ab7363d8ecf4e 100644 --- a/starmath/inc/ElementsDockingWindow.hxx +++ b/starmath/inc/ElementsDockingWindow.hxx @@ -77,6 +77,7 @@ class SmElementsControl : public Control virtual void MouseButtonDown(const MouseEvent& rMEvt) override; virtual void MouseMove(const MouseEvent& rMEvt) override; virtual void RequestHelp(const HelpEvent& rHEvt) override; + virtual void Resize() override; SmDocShell* mpDocShell; SmFormat maFormat; @@ -88,6 +89,7 @@ class SmElementsControl : public Control Size maMaxElementDimensions; bool mbVerticalMode; VclPtr< ScrollBar > mxScroll; + bool mbFirstPaintAfterLayout; void addElement(const OUString& aElementVisual, const OUString& aElementSource, const OUString& aHelpText); diff --git a/starmath/source/ElementsDockingWindow.cxx b/starmath/source/ElementsDockingWindow.cxx index ab0ad7dd689e8da3ba0decc202a1ebdacfc7518a..36af328f1cedbe521299db2063d822c2d1b05e4d 100644 --- a/starmath/source/ElementsDockingWindow.cxx +++ b/starmath/source/ElementsDockingWindow.cxx @@ -238,6 +238,7 @@ SmElementsControl::SmElementsControl(vcl::Window *pParent) , mpCurrentElement(nullptr) , mbVerticalMode(true) , mxScroll(VclPtr::Create(this, WB_VERT)) + , mbFirstPaintAfterLayout(false) { set_id("element_selector"); SetMapMode( MapMode(MapUnit::Map100thMM) ); @@ -248,7 +249,6 @@ SmElementsControl::SmElementsControl(vcl::Window *pParent) maFormat.SetBaseSize(PixelToLogic(Size(0, SmPtsTo100th_mm(12)))); mxScroll->SetScrollHdl( LINK(this, SmElementsControl, ScrollHdl) ); - mxScroll->Show(); } SmElementsControl::~SmElementsControl() @@ -268,14 +268,19 @@ void SmElementsControl::setVerticalMode(bool bVerticalMode) mbVerticalMode = bVerticalMode; } +/** + * !pContext => layout only + * + * Layouting is always done without a scrollbar and will show or hide it. + * The first paint (mbFirstPaintAfterLayout) therefore needs to update a + * visible scrollbar, because the layouting was wrong. + **/ void SmElementsControl::LayoutOrPaintContents(vcl::RenderContext *pContext) { - bool bOldVisibleState = mxScroll->IsVisible(); - - sal_Int32 nScrollbarWidth = bOldVisibleState ? GetSettings().GetStyleSettings().GetScrollBarSize() : 0; - - sal_Int32 nControlWidth = GetOutputSizePixel().Width() - nScrollbarWidth; - sal_Int32 nControlHeight = GetOutputSizePixel().Height(); + const sal_Int32 nScrollbarWidth = GetSettings().GetStyleSettings().GetScrollBarSize(); + const sal_Int32 nControlWidth = GetOutputSizePixel().Width() + - (pContext && mxScroll->IsVisible() ? nScrollbarWidth : 0); + const sal_Int32 nControlHeight = GetOutputSizePixel().Height(); sal_Int32 boxX = maMaxElementDimensions.Width() + 10; sal_Int32 boxY = maMaxElementDimensions.Height() + 10; @@ -379,15 +384,21 @@ void SmElementsControl::LayoutOrPaintContents(vcl::RenderContext *pContext) } if (pContext) - return; + { + if (!mbFirstPaintAfterLayout || !mxScroll->IsVisible()) + return; + mbFirstPaintAfterLayout = false; + } + else + mbFirstPaintAfterLayout = true; sal_Int32 nTotalControlHeight = y + boxY + mxScroll->GetThumbPos(); - if (nTotalControlHeight > GetOutputSizePixel().Height()) { mxScroll->SetRangeMax(nTotalControlHeight); mxScroll->SetPosSizePixel(Point(nControlWidth, 0), Size(nScrollbarWidth, nControlHeight)); mxScroll->SetVisibleSize(nControlHeight); + mxScroll->SetPageSize(nControlHeight); mxScroll->Show(); } else @@ -397,6 +408,12 @@ void SmElementsControl::LayoutOrPaintContents(vcl::RenderContext *pContext) } } +void SmElementsControl::Resize() +{ + Window::Resize(); + LayoutOrPaintContents(nullptr); +} + void SmElementsControl::ApplySettings(vcl::RenderContext& rRenderContext) { rRenderContext.SetBackground(COL_WHITE); @@ -461,7 +478,6 @@ void SmElementsControl::MouseMove( const MouseEvent& rMouseEvent ) mpCurrentElement = nullptr; if (rMouseEvent.IsLeaveWindow()) { - LayoutOrPaintContents(); Invalidate(); return; } @@ -476,7 +492,6 @@ void SmElementsControl::MouseMove( const MouseEvent& rMouseEvent ) if (pPrevElement != element) { mpCurrentElement = element; - LayoutOrPaintContents(); Invalidate(); return; } @@ -541,7 +556,6 @@ void SmElementsControl::DoScroll(long nDelta) aRect.AdjustRight( -(mxScroll->GetSizePixel().Width()) ); Scroll( 0, -nDelta, aRect ); mxScroll->SetPosPixel(aNewPoint); - LayoutOrPaintContents(); Invalidate(); }