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

AlertWindow: Allow parent component to be specified

This commit is contained in:
reuk 2023-02-16 20:35:05 +00:00
parent 39a731de46
commit 882c2aa01d
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
2 changed files with 23 additions and 0 deletions

View file

@ -94,7 +94,16 @@ static std::unique_ptr<ScopedMessageBoxInterface> createAlertWindowImpl (const M
return nullptr;
}
if (auto* parent = options.getParentComponent())
{
parent->addAndMakeVisible (alert);
if (options.getAssociatedComponent() == nullptr)
alert->setCentrePosition (parent->getLocalBounds().getCentre());
}
alert->setAlwaysOnTop (juce_areThereAnyAlwaysOnTopWindows());
return alert;
}

View file

@ -87,6 +87,13 @@ public:
/** The component that the dialog box should be associated with. */
[[nodiscard]] MessageBoxOptions withAssociatedComponent (Component* component) const { return with (*this, &MessageBoxOptions::associatedComponent, component); }
/** The component that will contain the message box (e.g. the AudioProcessorEditor in a plugin).
This will only affect JUCE AlertWindows. It won't affect the drawing of native message boxes.
This is mainly intended for use in AU plugins, where opening additional windows can be problematic.
*/
[[nodiscard]] MessageBoxOptions withParentComponent (Component* component) const { return with (*this, &MessageBoxOptions::parentComponent, component); }
//==============================================================================
/** Returns the icon type of the dialog box.
@ -124,6 +131,12 @@ public:
*/
Component* getAssociatedComponent() const noexcept { return associatedComponent; }
/** Returns the component that will be used as the parent of the dialog box.
@see withParentComponent
*/
Component* getParentComponent() const noexcept { return parentComponent; }
/** Creates options suitable for a message box with a single button.
If no button text is supplied, "OK" will be used.
@ -182,6 +195,7 @@ private:
String title, message;
StringArray buttons;
WeakReference<Component> associatedComponent;
WeakReference<Component> parentComponent;
};
} // namespace juce