diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index 9750234ba7..faaaa828f3 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -1384,7 +1384,7 @@ void Component::enterModalState (bool shouldTakeKeyboardFocus, } auto& mcm = *ModalComponentManager::getInstance(); - mcm.startModal (this, deleteWhenDismissed); + mcm.startModal ({}, this, deleteWhenDismissed); mcm.attachCallback (this, callback); setVisible (true); @@ -1408,7 +1408,7 @@ void Component::exitModalState (int returnValue) if (MessageManager::getInstance()->isThisTheMessageThread()) { auto& mcm = *ModalComponentManager::getInstance(); - mcm.endModal (this, returnValue); + mcm.endModal ({}, this, returnValue); mcm.bringModalComponentsToFront(); // While this component is in modal state it may block other components from receiving diff --git a/modules/juce_gui_basics/components/juce_ModalComponentManager.cpp b/modules/juce_gui_basics/components/juce_ModalComponentManager.cpp index dfad648689..18a5731eb9 100644 --- a/modules/juce_gui_basics/components/juce_ModalComponentManager.cpp +++ b/modules/juce_gui_basics/components/juce_ModalComponentManager.cpp @@ -112,7 +112,7 @@ JUCE_IMPLEMENT_SINGLETON (ModalComponentManager) //============================================================================== -void ModalComponentManager::startModal (Component* component, bool autoDelete) +void ModalComponentManager::startModal (Key, Component* component, bool autoDelete) { if (component != nullptr) { @@ -141,18 +141,7 @@ void ModalComponentManager::attachCallback (Component* component, Callback* call } } -void ModalComponentManager::endModal (Component* component) -{ - for (int i = stack.size(); --i >= 0;) - { - auto* item = stack.getUnchecked (i); - - if (item->component == component) - item->cancel(); - } -} - -void ModalComponentManager::endModal (Component* component, int returnValue) +void ModalComponentManager::endModal (Key, Component* component, int returnValue) { for (int i = stack.size(); --i >= 0;) { diff --git a/modules/juce_gui_basics/components/juce_ModalComponentManager.h b/modules/juce_gui_basics/components/juce_ModalComponentManager.h index 5f065cdf54..52364876e3 100644 --- a/modules/juce_gui_basics/components/juce_ModalComponentManager.h +++ b/modules/juce_gui_basics/components/juce_ModalComponentManager.h @@ -135,6 +135,19 @@ public: int runEventLoopForCurrentComponent(); #endif + /** @internal Only friends of Key can call startModal and endModal. */ + class Key + { + friend Component; + Key() {} + }; + + /** @internal */ + void startModal (Key, Component*, bool autoDelete); + + /** @internal */ + void endModal (Key, Component*, int returnValue); + protected: /** Creates a ModalComponentManager. You shouldn't ever call the constructor - it's a singleton, so use ModalComponentManager::getInstance() @@ -149,15 +162,9 @@ protected: private: //============================================================================== - friend class Component; - struct ModalItem; OwnedArray stack; - void startModal (Component*, bool autoDelete); - void endModal (Component*, int returnValue); - void endModal (Component*); - JUCE_DECLARE_NON_COPYABLE (ModalComponentManager) };