Kaydet (Commit) 87b8c32f authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

SM fix element control scrollbar

The element layouting must always be done without a scrollbar, so
it can be decided, if a scrollbar is needed. If it's needed the
first paint will update the scrollbar accordingly.

This also sets the scrollbar's page size to the control height,
so clicking in an empty area will correctly scroll the widget not
just a single pixel.

Change-Id: Ib9a0eb1952bc0355f683cd8d116c61f9c9d462c4
Reviewed-on: https://gerrit.libreoffice.org/72315
Tested-by: Jenkins
Reviewed-by: 's avatarJan-Marek Glogowski <glogow@fbihome.de>
üst f9c94cfd
...@@ -77,6 +77,7 @@ class SmElementsControl : public Control ...@@ -77,6 +77,7 @@ class SmElementsControl : public Control
virtual void MouseButtonDown(const MouseEvent& rMEvt) override; virtual void MouseButtonDown(const MouseEvent& rMEvt) override;
virtual void MouseMove(const MouseEvent& rMEvt) override; virtual void MouseMove(const MouseEvent& rMEvt) override;
virtual void RequestHelp(const HelpEvent& rHEvt) override; virtual void RequestHelp(const HelpEvent& rHEvt) override;
virtual void Resize() override;
SmDocShell* mpDocShell; SmDocShell* mpDocShell;
SmFormat maFormat; SmFormat maFormat;
...@@ -88,6 +89,7 @@ class SmElementsControl : public Control ...@@ -88,6 +89,7 @@ class SmElementsControl : public Control
Size maMaxElementDimensions; Size maMaxElementDimensions;
bool mbVerticalMode; bool mbVerticalMode;
VclPtr< ScrollBar > mxScroll; VclPtr< ScrollBar > mxScroll;
bool mbFirstPaintAfterLayout;
void addElement(const OUString& aElementVisual, const OUString& aElementSource, const OUString& aHelpText); void addElement(const OUString& aElementVisual, const OUString& aElementSource, const OUString& aHelpText);
......
...@@ -238,6 +238,7 @@ SmElementsControl::SmElementsControl(vcl::Window *pParent) ...@@ -238,6 +238,7 @@ SmElementsControl::SmElementsControl(vcl::Window *pParent)
, mpCurrentElement(nullptr) , mpCurrentElement(nullptr)
, mbVerticalMode(true) , mbVerticalMode(true)
, mxScroll(VclPtr<ScrollBar>::Create(this, WB_VERT)) , mxScroll(VclPtr<ScrollBar>::Create(this, WB_VERT))
, mbFirstPaintAfterLayout(false)
{ {
set_id("element_selector"); set_id("element_selector");
SetMapMode( MapMode(MapUnit::Map100thMM) ); SetMapMode( MapMode(MapUnit::Map100thMM) );
...@@ -248,7 +249,6 @@ SmElementsControl::SmElementsControl(vcl::Window *pParent) ...@@ -248,7 +249,6 @@ SmElementsControl::SmElementsControl(vcl::Window *pParent)
maFormat.SetBaseSize(PixelToLogic(Size(0, SmPtsTo100th_mm(12)))); maFormat.SetBaseSize(PixelToLogic(Size(0, SmPtsTo100th_mm(12))));
mxScroll->SetScrollHdl( LINK(this, SmElementsControl, ScrollHdl) ); mxScroll->SetScrollHdl( LINK(this, SmElementsControl, ScrollHdl) );
mxScroll->Show();
} }
SmElementsControl::~SmElementsControl() SmElementsControl::~SmElementsControl()
...@@ -268,14 +268,19 @@ void SmElementsControl::setVerticalMode(bool bVerticalMode) ...@@ -268,14 +268,19 @@ void SmElementsControl::setVerticalMode(bool bVerticalMode)
mbVerticalMode = 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) void SmElementsControl::LayoutOrPaintContents(vcl::RenderContext *pContext)
{ {
bool bOldVisibleState = mxScroll->IsVisible(); const sal_Int32 nScrollbarWidth = GetSettings().GetStyleSettings().GetScrollBarSize();
const sal_Int32 nControlWidth = GetOutputSizePixel().Width()
sal_Int32 nScrollbarWidth = bOldVisibleState ? GetSettings().GetStyleSettings().GetScrollBarSize() : 0; - (pContext && mxScroll->IsVisible() ? nScrollbarWidth : 0);
const sal_Int32 nControlHeight = GetOutputSizePixel().Height();
sal_Int32 nControlWidth = GetOutputSizePixel().Width() - nScrollbarWidth;
sal_Int32 nControlHeight = GetOutputSizePixel().Height();
sal_Int32 boxX = maMaxElementDimensions.Width() + 10; sal_Int32 boxX = maMaxElementDimensions.Width() + 10;
sal_Int32 boxY = maMaxElementDimensions.Height() + 10; sal_Int32 boxY = maMaxElementDimensions.Height() + 10;
...@@ -379,15 +384,21 @@ void SmElementsControl::LayoutOrPaintContents(vcl::RenderContext *pContext) ...@@ -379,15 +384,21 @@ void SmElementsControl::LayoutOrPaintContents(vcl::RenderContext *pContext)
} }
if (pContext) if (pContext)
return; {
if (!mbFirstPaintAfterLayout || !mxScroll->IsVisible())
return;
mbFirstPaintAfterLayout = false;
}
else
mbFirstPaintAfterLayout = true;
sal_Int32 nTotalControlHeight = y + boxY + mxScroll->GetThumbPos(); sal_Int32 nTotalControlHeight = y + boxY + mxScroll->GetThumbPos();
if (nTotalControlHeight > GetOutputSizePixel().Height()) if (nTotalControlHeight > GetOutputSizePixel().Height())
{ {
mxScroll->SetRangeMax(nTotalControlHeight); mxScroll->SetRangeMax(nTotalControlHeight);
mxScroll->SetPosSizePixel(Point(nControlWidth, 0), Size(nScrollbarWidth, nControlHeight)); mxScroll->SetPosSizePixel(Point(nControlWidth, 0), Size(nScrollbarWidth, nControlHeight));
mxScroll->SetVisibleSize(nControlHeight); mxScroll->SetVisibleSize(nControlHeight);
mxScroll->SetPageSize(nControlHeight);
mxScroll->Show(); mxScroll->Show();
} }
else else
...@@ -397,6 +408,12 @@ void SmElementsControl::LayoutOrPaintContents(vcl::RenderContext *pContext) ...@@ -397,6 +408,12 @@ void SmElementsControl::LayoutOrPaintContents(vcl::RenderContext *pContext)
} }
} }
void SmElementsControl::Resize()
{
Window::Resize();
LayoutOrPaintContents(nullptr);
}
void SmElementsControl::ApplySettings(vcl::RenderContext& rRenderContext) void SmElementsControl::ApplySettings(vcl::RenderContext& rRenderContext)
{ {
rRenderContext.SetBackground(COL_WHITE); rRenderContext.SetBackground(COL_WHITE);
...@@ -461,7 +478,6 @@ void SmElementsControl::MouseMove( const MouseEvent& rMouseEvent ) ...@@ -461,7 +478,6 @@ void SmElementsControl::MouseMove( const MouseEvent& rMouseEvent )
mpCurrentElement = nullptr; mpCurrentElement = nullptr;
if (rMouseEvent.IsLeaveWindow()) if (rMouseEvent.IsLeaveWindow())
{ {
LayoutOrPaintContents();
Invalidate(); Invalidate();
return; return;
} }
...@@ -476,7 +492,6 @@ void SmElementsControl::MouseMove( const MouseEvent& rMouseEvent ) ...@@ -476,7 +492,6 @@ void SmElementsControl::MouseMove( const MouseEvent& rMouseEvent )
if (pPrevElement != element) if (pPrevElement != element)
{ {
mpCurrentElement = element; mpCurrentElement = element;
LayoutOrPaintContents();
Invalidate(); Invalidate();
return; return;
} }
...@@ -541,7 +556,6 @@ void SmElementsControl::DoScroll(long nDelta) ...@@ -541,7 +556,6 @@ void SmElementsControl::DoScroll(long nDelta)
aRect.AdjustRight( -(mxScroll->GetSizePixel().Width()) ); aRect.AdjustRight( -(mxScroll->GetSizePixel().Width()) );
Scroll( 0, -nDelta, aRect ); Scroll( 0, -nDelta, aRect );
mxScroll->SetPosPixel(aNewPoint); mxScroll->SetPosPixel(aNewPoint);
LayoutOrPaintContents();
Invalidate(); Invalidate();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment