65 if (component == &comp || comp.
isParentOf (component))
78 if (
auto*
mcm = ModalComponentManager::getInstanceWithoutCreating())
79 mcm->triggerAsyncUpdate();
86 bool isActive =
true, autoDelete;
106void ModalComponentManager::startModal (
Component* component,
bool autoDelete)
108 if (component !=
nullptr)
110 stack.add (
new ModalItem (component, autoDelete));
111 detail::ComponentHelpers::ModalComponentManagerChangeNotifier::getInstance().modalComponentManagerChanged();
117 if (callback !=
nullptr)
121 for (
int i = stack.size(); --i >= 0;)
123 auto* item = stack.getUnchecked (i);
125 if (item->component == component)
127 item->callbacks.add (callback);
135void ModalComponentManager::endModal (
Component* component)
137 for (
int i = stack.size(); --i >= 0;)
139 auto* item = stack.getUnchecked (i);
141 if (item->component == component)
146void ModalComponentManager::endModal (Component* component,
int returnValue)
148 for (
int i = stack.size(); --i >= 0;)
150 auto* item = stack.getUnchecked (i);
152 if (item->component == component)
154 item->returnValue = returnValue;
164 for (
auto* item : stack)
175 for (
int i = stack.size(); --i >= 0;)
177 auto* item = stack.getUnchecked (i);
181 return item->component;
189 for (
auto* item : stack)
190 if (item->isActive && item->component == comp)
203 for (
int i = stack.size(); --i >= 0;)
205 auto* item = stack.getUnchecked (i);
207 if (! item->isActive)
212 for (
int j = item->callbacks.size(); --
j >= 0;)
213 item->callbacks.getUnchecked (
j)->modalStateFinished (item->returnValue);
217 detail::ComponentHelpers::ModalComponentManagerChangeNotifier::getInstance().modalComponentManagerChanged();
233 if (
auto* peer = c->getPeer())
261 c->exitModalState (0);
267#if JUCE_MODAL_LOOPS_PERMITTED
268int ModalComponentManager::runEventLoopForCurrentComponent()
278 bool finished =
false;
An object that watches for any movement of a component or any of its parent components.
void componentBeingDeleted(Component &) override
Called when the component is in the process of being deleted.
virtual void componentMovedOrResized(bool wasMoved, bool wasResized)=0
This callback happens when the component that is being watched is moved relative to its top-level pee...
virtual void componentVisibilityChanged()=0
This callback happens when the component's visibility state changes, possibly due to one of its paren...
The Component class uses a ComponentPeer internally to create and manage a real operating-system wind...
Holds a pointer to some type of Component, which automatically becomes null if the component is delet...
void deleteAndZero()
If the component is valid, this deletes it and sets this pointer to null.
The base class for all JUCE user-interface objects.
bool isShowing() const
Tests whether this component and all its parents are visible.
bool isParentOf(const Component *possibleChild) const noexcept
Checks whether a component is anywhere inside this component or its children.
static MessageManager * getInstance()
Returns the global instance of the MessageManager.
static ModalComponentManager::Callback * create(CallbackFn &&fn)
This is a utility function to create a ModalComponentManager::Callback that will call a callable obje...
Receives callbacks when a modal component is dismissed.
Manages the system's stack of modal components.
void handleAsyncUpdate() override
Called back to do whatever your class needs to do.
bool isModal(const Component *component) const
Returns true if the specified component is in a modal state.
void bringModalComponentsToFront(bool topOneShouldGrabFocus=true)
Brings any modal components to the front.
~ModalComponentManager() override
Destructor.
Component * getModalComponent(int index) const
Returns one of the components being shown modally.
bool isFrontModalComponent(const Component *component) const
Returns true if the specified component is currently the topmost modal component.
void attachCallback(Component *component, Callback *callback)
Adds a new callback that will be called when the specified modal component is dismissed.
bool cancelAllModalComponents()
Calls exitModalState (0) on any components that are currently modal.
ModalComponentManager()
Creates a ModalComponentManager.
int getNumModalComponents() const
Returns the number of components currently being shown modally.
#define JUCE_TRY
The JUCE_TRY/JUCE_CATCH_EXCEPTION wrappers can be used to pass any uncaught exceptions to the JUCEApp...
#define JUCE_CATCH_EXCEPTION
The JUCE_TRY/JUCE_CATCH_EXCEPTION wrappers can be used to pass any uncaught exceptions to the JUCEApp...
#define JUCE_ASSERT_MESSAGE_THREAD
This macro is used to catch unsafe use of functions which expect to only be called on the message thr...
#define JUCE_IMPLEMENT_SINGLETON(Classname)
This is a counterpart to the JUCE_DECLARE_SINGLETON macros.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
void componentBeingDeleted(Component &comp) override
Called when the component is in the process of being deleted.
void componentVisibilityChanged() override
This callback happens when the component's visibility state changes, possibly due to one of its paren...
void componentMovedOrResized(bool, bool) override
This callback happens when the component that is being watched is moved relative to its top-level pee...
void componentPeerChanged() override
This callback happens when the component's top-level peer is changed.