From 72b49689bf0c32ebb593bd4be4def7356d2a7050 Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 25 Mar 2015 15:14:46 +0000 Subject: [PATCH] Fix to make sure that ResizableWindow can't accidentally be dragged without first getting a mouseDown event. --- .../windows/juce_ResizableWindow.cpp | 28 +++++++++++-------- .../windows/juce_ResizableWindow.h | 4 ++- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp b/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp index 0338cc48ac..1b1d27085d 100644 --- a/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp @@ -22,24 +22,22 @@ ============================================================================== */ -ResizableWindow::ResizableWindow (const String& name, - const bool addToDesktop_) - : TopLevelWindow (name, addToDesktop_), +ResizableWindow::ResizableWindow (const String& name, bool shouldAddToDesktop) + : TopLevelWindow (name, shouldAddToDesktop), ownsContentComponent (false), resizeToFitContent (false), fullscreen (false), + dragStarted (false), constrainer (nullptr) #if JUCE_DEBUG , hasBeenResized (false) #endif { - initialise (addToDesktop_); + initialise (shouldAddToDesktop); } -ResizableWindow::ResizableWindow (const String& name, - Colour backgroundColour_, - const bool addToDesktop_) - : TopLevelWindow (name, addToDesktop_), +ResizableWindow::ResizableWindow (const String& name, Colour bkgnd, bool shouldAddToDesktop) + : TopLevelWindow (name, shouldAddToDesktop), ownsContentComponent (false), resizeToFitContent (false), fullscreen (false), @@ -48,9 +46,9 @@ ResizableWindow::ResizableWindow (const String& name, , hasBeenResized (false) #endif { - setBackgroundColour (backgroundColour_); + setBackgroundColour (bkgnd); - initialise (addToDesktop_); + initialise (shouldAddToDesktop); } ResizableWindow::~ResizableWindow() @@ -574,15 +572,23 @@ bool ResizableWindow::restoreWindowStateFromString (const String& s) void ResizableWindow::mouseDown (const MouseEvent& e) { if (! isFullScreen()) + { + dragStarted = true; dragger.startDraggingComponent (this, e); + } } void ResizableWindow::mouseDrag (const MouseEvent& e) { - if (! isFullScreen()) + if (dragStarted) dragger.dragComponent (this, e, constrainer); } +void ResizableWindow::mouseUp (const MouseEvent&) +{ + dragStarted = false; +} + //============================================================================== #if JUCE_DEBUG void ResizableWindow::addChildComponent (Component* const child, int zOrder) diff --git a/modules/juce_gui_basics/windows/juce_ResizableWindow.h b/modules/juce_gui_basics/windows/juce_ResizableWindow.h index dd9f806ed2..15c56fa73c 100644 --- a/modules/juce_gui_basics/windows/juce_ResizableWindow.h +++ b/modules/juce_gui_basics/windows/juce_ResizableWindow.h @@ -339,6 +339,8 @@ protected: /** @internal */ void mouseDrag (const MouseEvent&) override; /** @internal */ + void mouseUp (const MouseEvent&) override; + /** @internal */ void lookAndFeelChanged() override; /** @internal */ void childBoundsChanged (Component*) override; @@ -374,7 +376,7 @@ protected: private: //============================================================================== Component::SafePointer contentComponent; - bool ownsContentComponent, resizeToFitContent, fullscreen; + bool ownsContentComponent, resizeToFitContent, fullscreen, dragStarted; ComponentDragger dragger; Rectangle lastNonFullScreenPos; ComponentBoundsConstrainer defaultConstrainer;