1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-22 01:34:21 +00:00

Fix for a crash when deleting FileBrowserComponent under certain circumstances.

This commit is contained in:
jules 2015-03-24 16:00:58 +00:00
parent 7086f673ac
commit a4f5faec2d
4 changed files with 40 additions and 8 deletions

View file

@ -60,6 +60,7 @@ ScrollBar::ScrollBar (const bool vertical_)
thumbAreaSize (0),
thumbStart (0),
thumbSize (0),
minimumScrollBarThumbSize (0),
initialDelayInMillisecs (100),
repeatDelayInMillisecs (50),
minimumDelayInMillisecs (10),
@ -67,6 +68,8 @@ ScrollBar::ScrollBar (const bool vertical_)
isDraggingThumb (false),
autohides (true)
{
minimumScrollBarThumbSize = getLookAndFeel().getMinimumScrollbarThumbSize (*this);
setRepaintsOnMouseActivity (true);
setFocusContainer (true);
}
@ -190,10 +193,8 @@ void ScrollBar::updateThumbPosition()
int newThumbSize = roundToInt (totalRange.getLength() > 0 ? (visibleRange.getLength() * thumbAreaSize) / totalRange.getLength()
: thumbAreaSize);
LookAndFeel& lf = getLookAndFeel();
if (newThumbSize < lf.getMinimumScrollbarThumbSize (*this))
newThumbSize = jmin (lf.getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
if (newThumbSize < minimumScrollBarThumbSize)
newThumbSize = jmin (minimumScrollBarThumbSize, thumbAreaSize - 1);
if (newThumbSize > thumbAreaSize)
newThumbSize = thumbAreaSize;
@ -280,6 +281,7 @@ void ScrollBar::resized()
const int length = vertical ? getHeight() : getWidth();
LookAndFeel& lf = getLookAndFeel();
minimumScrollBarThumbSize = lf.getMinimumScrollbarThumbSize (*this);
const bool buttonsVisible = lf.areScrollbarButtonsVisible();
int buttonSize = 0;

View file

@ -382,6 +382,7 @@ private:
Range <double> totalRange, visibleRange;
double singleStepSize, dragStartRange;
int thumbAreaStart, thumbAreaSize, thumbStart, thumbSize;
int minimumScrollBarThumbSize;
int dragStartMousePos, lastMousePos;
int initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs;
bool vertical, isDraggingThumb, autohides;

View file

@ -24,6 +24,7 @@
Viewport::Viewport (const String& name)
: Component (name),
customScrollBarThickness(false),
scrollBarThickness (0),
singleStepX (16),
singleStepY (16),
@ -39,6 +40,8 @@ Viewport::Viewport (const String& name)
addAndMakeVisible (contentHolder);
contentHolder.setInterceptsMouseClicks (false, true);
scrollBarThickness = getLookAndFeel().getDefaultScrollbarWidth();
addChildComponent (verticalScrollBar);
addChildComponent (horizontalScrollBar);
@ -174,6 +177,14 @@ void Viewport::componentMovedOrResized (Component&, bool, bool)
updateVisibleArea();
}
void Viewport::lookAndFeelChanged()
{
if (customScrollBarThickness == false)
{
scrollBarThickness = getLookAndFeel().getDefaultScrollbarWidth();
}
}
void Viewport::resized()
{
updateVisibleArea();
@ -314,17 +325,32 @@ void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
void Viewport::setScrollBarThickness (const int thickness)
{
if (scrollBarThickness != thickness)
int newThickness;
// To stay compatible with the previous code: use the
// default thickness if thickness parameter is zero
// or negative
if (thickness <= 0)
{
scrollBarThickness = thickness;
customScrollBarThickness = false;
newThickness = getLookAndFeel().getDefaultScrollbarWidth();
}
else
{
customScrollBarThickness = true;
newThickness = thickness;
}
if (scrollBarThickness != newThickness)
{
scrollBarThickness = newThickness;
updateVisibleArea();
}
}
int Viewport::getScrollBarThickness() const
{
return scrollBarThickness > 0 ? scrollBarThickness
: getLookAndFeel().getDefaultScrollbarWidth();
return scrollBarThickness;
}
void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)

View file

@ -253,6 +253,8 @@ public:
/** @internal */
void componentMovedOrResized (Component&, bool wasMoved, bool wasResized) override;
/** @internal */
void lookAndFeelChanged() override;
/** @internal */
bool useMouseWheelMoveIfNeeded (const MouseEvent&, const MouseWheelDetails&);
/** @internal */
static bool respondsToKey (const KeyPress&);
@ -261,6 +263,7 @@ private:
//==============================================================================
WeakReference<Component> contentComp;
Rectangle<int> lastVisibleArea;
bool customScrollBarThickness;
int scrollBarThickness;
int singleStepX, singleStepY;
bool showHScrollbar, showVScrollbar, deleteContent;