From 76737287c752c42071ba6ab8981b4ac538484d38 Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 1 Feb 2016 16:21:11 +0000 Subject: [PATCH] Simplified some component modal state handling code, hopefully also fixing an edge-case problem when showing modal windows on linux --- .../components/juce_Component.cpp | 39 ++++++++----------- .../components/juce_Component.h | 1 - 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index f2d827b649..7cbe44e985 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -1721,50 +1721,46 @@ void Component::enterModalState (const bool shouldTakeKeyboardFocus, // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe. ASSERT_MESSAGE_MANAGER_IS_LOCKED - // Check for an attempt to make a component modal when it already is! - // This can cause nasty problems.. - jassert (! flags.currentlyModalFlag); - if (! isCurrentlyModal()) { - ModalComponentManager* const mcm = ModalComponentManager::getInstance(); - mcm->startModal (this, deleteWhenDismissed); - mcm->attachCallback (this, callback); + ModalComponentManager& mcm = *ModalComponentManager::getInstance(); + mcm.startModal (this, deleteWhenDismissed); + mcm.attachCallback (this, callback); - flags.currentlyModalFlag = true; setVisible (true); if (shouldTakeKeyboardFocus) grabKeyboardFocus(); } + else + { + // Probably a bad idea to try to make a component modal twice! + jassertfalse; + } } void Component::exitModalState (const int returnValue) { - if (flags.currentlyModalFlag) + if (isCurrentlyModal()) { if (MessageManager::getInstance()->isThisTheMessageThread()) { - ModalComponentManager::getInstance()->endModal (this, returnValue); - flags.currentlyModalFlag = false; - - ModalComponentManager::getInstance()->bringModalComponentsToFront(); + ModalComponentManager& mcm = *ModalComponentManager::getInstance(); + mcm.endModal (this, returnValue); + mcm.bringModalComponentsToFront(); } else { - class ExitModalStateMessage : public CallbackMessage + struct ExitModalStateMessage : public CallbackMessage { - public: - ExitModalStateMessage (Component* const c, const int res) - : target (c), result (res) {} + ExitModalStateMessage (Component* c, int res) : target (c), result (res) {} void messageCallback() override { - if (target.get() != nullptr) // (get() required for VS2003 bug) - target->exitModalState (result); + if (Component* c = target) + c->exitModalState (result); } - private: WeakReference target; int result; }; @@ -1776,8 +1772,7 @@ void Component::exitModalState (const int returnValue) bool Component::isCurrentlyModal() const noexcept { - return flags.currentlyModalFlag - && getCurrentlyModalComponent() == this; + return getCurrentlyModalComponent() == this; } bool Component::isCurrentlyBlockedByAnotherModalComponent() const diff --git a/modules/juce_gui_basics/components/juce_Component.h b/modules/juce_gui_basics/components/juce_Component.h index de25a5debb..11541456ab 100644 --- a/modules/juce_gui_basics/components/juce_Component.h +++ b/modules/juce_gui_basics/components/juce_Component.h @@ -2277,7 +2277,6 @@ private: bool bufferToImageFlag : 1; bool bringToFrontOnClickFlag : 1; bool repaintOnMouseActivityFlag : 1; - bool currentlyModalFlag : 1; bool isDisabledFlag : 1; bool childCompFocusedFlag : 1; bool dontClipGraphicsFlag : 1;