1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

ModalComponentManager: Remove friendship with Component

This change makes it slightly easier to audit invariants of
ModalComponentManager, as we can now be certain that only member
functions of ModalComponentManager can access its data members.
This commit is contained in:
reuk 2024-05-13 17:06:26 +01:00
parent 24f3a91a35
commit d7788100d5
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
3 changed files with 17 additions and 21 deletions

View file

@ -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

View file

@ -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;)
{

View file

@ -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<ModalItem> stack;
void startModal (Component*, bool autoDelete);
void endModal (Component*, int returnValue);
void endModal (Component*);
JUCE_DECLARE_NON_COPYABLE (ModalComponentManager)
};