Kaydet (Commit) 64caddc3 authored tarafından Caolán McNamara's avatar Caolán McNamara Kaydeden (comit) Andras Timar

Resolves: tdf#92148 SmElementsControl invalidates itself from paint endlessly

Change-Id: Id9cd7fbe9e433005cc27b2e8e3417a5e289b94e3
(cherry picked from commit b1760dc3)
Reviewed-on: https://gerrit.libreoffice.org/17302Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst b8b804c2
...@@ -106,6 +106,10 @@ class SmElementsControl : public Control ...@@ -106,6 +106,10 @@ class SmElementsControl : public Control
void build(); void build();
//if pContext is not NULL, then draw, otherwise
//just layout
void LayoutOrPaintContents(vcl::RenderContext *pContext = NULL);
public: public:
SmElementsControl(vcl::Window *pParent); SmElementsControl(vcl::Window *pParent);
virtual ~SmElementsControl(); virtual ~SmElementsControl();
......
...@@ -254,10 +254,8 @@ void SmElementsControl::setVerticalMode(bool bVerticalMode) ...@@ -254,10 +254,8 @@ void SmElementsControl::setVerticalMode(bool bVerticalMode)
mbVerticalMode = bVerticalMode; mbVerticalMode = bVerticalMode;
} }
void SmElementsControl::Paint(vcl::RenderContext& rRenderContext, const Rectangle&) void SmElementsControl::LayoutOrPaintContents(vcl::RenderContext *pContext)
{ {
rRenderContext.Push();
bool bOldVisibleState = mxScroll->IsVisible(); bool bOldVisibleState = mxScroll->IsVisible();
sal_Int32 nScrollbarWidth = bOldVisibleState ? GetSettings().GetStyleSettings().GetScrollBarSize() : 0; sal_Int32 nScrollbarWidth = bOldVisibleState ? GetSettings().GetStyleSettings().GetScrollBarSize() : 0;
...@@ -301,7 +299,8 @@ void SmElementsControl::Paint(vcl::RenderContext& rRenderContext, const Rectangl ...@@ -301,7 +299,8 @@ void SmElementsControl::Paint(vcl::RenderContext& rRenderContext, const Rectangl
Rectangle aSelectionRectangle(x + 5 - 1, y + 5, Rectangle aSelectionRectangle(x + 5 - 1, y + 5,
x + 5 + 1, nControlHeight - 5); x + 5 + 1, nControlHeight - 5);
rRenderContext.DrawRect(PixelToLogic(aSelectionRectangle)); if (pContext)
pContext->DrawRect(PixelToLogic(aSelectionRectangle));
x += 10; x += 10;
} }
else else
...@@ -312,14 +311,15 @@ void SmElementsControl::Paint(vcl::RenderContext& rRenderContext, const Rectangl ...@@ -312,14 +311,15 @@ void SmElementsControl::Paint(vcl::RenderContext& rRenderContext, const Rectangl
Rectangle aSelectionRectangle(x + 5, y + 5 - 1, Rectangle aSelectionRectangle(x + 5, y + 5 - 1,
nControlWidth - 5, y + 5 + 1); nControlWidth - 5, y + 5 + 1);
rRenderContext.DrawRect(PixelToLogic(aSelectionRectangle)); if (pContext)
pContext->DrawRect(PixelToLogic(aSelectionRectangle));
y += 10; y += 10;
} }
} }
else else
{ {
Size aSizePixel = rRenderContext.LogicToPixel(Size(element->getNode()->GetWidth(), Size aSizePixel = LogicToPixel(Size(element->getNode()->GetWidth(),
element->getNode()->GetHeight())); element->getNode()->GetHeight()));
if (mbVerticalMode) if (mbVerticalMode)
{ {
if (y + boxY > nControlHeight) if (y + boxY > nControlHeight)
...@@ -337,20 +337,21 @@ void SmElementsControl::Paint(vcl::RenderContext& rRenderContext, const Rectangl ...@@ -337,20 +337,21 @@ void SmElementsControl::Paint(vcl::RenderContext& rRenderContext, const Rectangl
} }
} }
if (mpCurrentElement == element) if (mpCurrentElement == element && pContext)
{ {
rRenderContext.Push(PushFlags::FILLCOLOR | PushFlags::LINECOLOR); pContext->Push(PushFlags::FILLCOLOR | PushFlags::LINECOLOR);
rRenderContext.SetFillColor(Color(230, 230, 230)); pContext->SetFillColor(Color(230, 230, 230));
rRenderContext.SetLineColor(Color(230, 230, 230)); pContext->SetLineColor(Color(230, 230, 230));
rRenderContext.DrawRect(PixelToLogic(Rectangle(x + 2, y + 2, x + boxX - 2, y + boxY - 2))); pContext->DrawRect(PixelToLogic(Rectangle(x + 2, y + 2, x + boxX - 2, y + boxY - 2)));
rRenderContext.Pop(); pContext->Pop();
} }
Point location(x + ((boxX - aSizePixel.Width()) / 2), Point location(x + ((boxX - aSizePixel.Width()) / 2),
y + ((boxY - aSizePixel.Height()) / 2)); y + ((boxY - aSizePixel.Height()) / 2));
SmDrawingVisitor(rRenderContext, PixelToLogic(location), element->getNode().get()); if (pContext)
SmDrawingVisitor(*pContext, PixelToLogic(location), element->getNode().get());
element->mBoxLocation = Point(x,y); element->mBoxLocation = Point(x,y);
element->mBoxSize = Size(boxX, boxY); element->mBoxSize = Size(boxX, boxY);
...@@ -362,26 +363,29 @@ void SmElementsControl::Paint(vcl::RenderContext& rRenderContext, const Rectangl ...@@ -362,26 +363,29 @@ void SmElementsControl::Paint(vcl::RenderContext& rRenderContext, const Rectangl
} }
} }
sal_Int32 nTotalControlHeight = y + boxY + mxScroll->GetThumbPos(); if (!pContext)
if (nTotalControlHeight > GetOutputSizePixel().Height())
{ {
mxScroll->SetRangeMax(nTotalControlHeight); sal_Int32 nTotalControlHeight = y + boxY + mxScroll->GetThumbPos();
mxScroll->SetPosSizePixel(Point(nControlWidth, 0), Size(nScrollbarWidth, nControlHeight));
mxScroll->SetVisibleSize(nControlHeight);
mxScroll->Show();
}
else
{
mxScroll->SetThumbPos(0);
mxScroll->Hide();
}
// If scrollbar visibility changed, we have to go through the if (nTotalControlHeight > GetOutputSizePixel().Height())
// calculation once more, see nScrollbarWidth {
if (bOldVisibleState != mxScroll->IsVisible()) mxScroll->SetRangeMax(nTotalControlHeight);
Invalidate(); mxScroll->SetPosSizePixel(Point(nControlWidth, 0), Size(nScrollbarWidth, nControlHeight));
mxScroll->SetVisibleSize(nControlHeight);
mxScroll->Show();
}
else
{
mxScroll->SetThumbPos(0);
mxScroll->Hide();
}
}
}
void SmElementsControl::Paint(vcl::RenderContext& rRenderContext, const Rectangle&)
{
rRenderContext.Push();
LayoutOrPaintContents(&rRenderContext);
rRenderContext.Pop(); rRenderContext.Pop();
} }
...@@ -400,6 +404,7 @@ void SmElementsControl::MouseMove( const MouseEvent& rMouseEvent ) ...@@ -400,6 +404,7 @@ void SmElementsControl::MouseMove( const MouseEvent& rMouseEvent )
if (mpCurrentElement != element) if (mpCurrentElement != element)
{ {
mpCurrentElement = element; mpCurrentElement = element;
LayoutOrPaintContents();
Invalidate(); Invalidate();
tooltip = element->getHelpText(); tooltip = element->getHelpText();
} }
...@@ -450,6 +455,7 @@ void SmElementsControl::DoScroll(long nDelta) ...@@ -450,6 +455,7 @@ void SmElementsControl::DoScroll(long nDelta)
aRect.Right() -= mxScroll->GetSizePixel().Width(); aRect.Right() -= mxScroll->GetSizePixel().Width();
Scroll( 0, -nDelta, aRect ); Scroll( 0, -nDelta, aRect );
mxScroll->SetPosPixel(aNewPoint); mxScroll->SetPosPixel(aNewPoint);
LayoutOrPaintContents();
Invalidate(); Invalidate();
} }
...@@ -630,6 +636,7 @@ void SmElementsControl::build() ...@@ -630,6 +636,7 @@ void SmElementsControl::build()
} }
break; break;
} }
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