diff --git a/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp b/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp index 1b1d27085d..abd21fade9 100644 --- a/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp @@ -27,6 +27,7 @@ ResizableWindow::ResizableWindow (const String& name, bool shouldAddToDesktop) ownsContentComponent (false), resizeToFitContent (false), fullscreen (false), + canDrag (true), dragStarted (false), constrainer (nullptr) #if JUCE_DEBUG @@ -41,6 +42,8 @@ ResizableWindow::ResizableWindow (const String& name, Colour bkgnd, bool shouldA ownsContentComponent (false), resizeToFitContent (false), fullscreen (false), + canDrag (true), + dragStarted (false), constrainer (nullptr) #if JUCE_DEBUG , hasBeenResized (false) @@ -314,6 +317,11 @@ void ResizableWindow::setResizeLimits (const int newMinimumWidth, setBoundsConstrained (getBounds()); } +void ResizableWindow::setDraggable (bool shouldBeDraggable) noexcept +{ + canDrag = shouldBeDraggable; +} + void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer) { if (constrainer != newConstrainer) @@ -571,7 +579,7 @@ bool ResizableWindow::restoreWindowStateFromString (const String& s) //============================================================================== void ResizableWindow::mouseDown (const MouseEvent& e) { - if (! isFullScreen()) + if (canDrag && ! isFullScreen()) { dragStarted = true; dragger.startDraggingComponent (this, e); diff --git a/modules/juce_gui_basics/windows/juce_ResizableWindow.h b/modules/juce_gui_basics/windows/juce_ResizableWindow.h index 15c56fa73c..936d838289 100644 --- a/modules/juce_gui_basics/windows/juce_ResizableWindow.h +++ b/modules/juce_gui_basics/windows/juce_ResizableWindow.h @@ -140,6 +140,12 @@ public: int newMaximumWidth, int newMaximumHeight) noexcept; + /** Can be used to enable or disable user-dragging of the window. */ + void setDraggable (bool shouldBeDraggable) noexcept; + + /** Returns true if the window can be dragged around by the user. */ + bool isDraggable() const noexcept { return canDrag; } + /** Returns the bounds constrainer object that this window is using. You can access this to change its properties. */ @@ -370,20 +376,20 @@ protected: void addAndMakeVisible (Component*, int zOrder = -1); #endif - ScopedPointer resizableCorner; - ScopedPointer resizableBorder; + ScopedPointer resizableCorner; + ScopedPointer resizableBorder; private: //============================================================================== Component::SafePointer contentComponent; - bool ownsContentComponent, resizeToFitContent, fullscreen, dragStarted; + bool ownsContentComponent, resizeToFitContent, fullscreen, canDrag, dragStarted; ComponentDragger dragger; Rectangle lastNonFullScreenPos; ComponentBoundsConstrainer defaultConstrainer; ComponentBoundsConstrainer* constrainer; - #if JUCE_DEBUG + #if JUCE_DEBUG bool hasBeenResized; - #endif + #endif void initialise (bool addToDesktop); void updateLastPosIfNotFullScreen();