From 882c2aa01dcd363f361c70063ebdcbce7ff164e0 Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 16 Feb 2023 20:35:05 +0000 Subject: [PATCH] AlertWindow: Allow parent component to be specified --- .../juce_gui_basics/windows/juce_AlertWindow.cpp | 9 +++++++++ .../windows/juce_MessageBoxOptions.h | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/modules/juce_gui_basics/windows/juce_AlertWindow.cpp b/modules/juce_gui_basics/windows/juce_AlertWindow.cpp index 3816af7751..6f80650ab0 100644 --- a/modules/juce_gui_basics/windows/juce_AlertWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_AlertWindow.cpp @@ -94,7 +94,16 @@ static std::unique_ptr 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; } diff --git a/modules/juce_gui_basics/windows/juce_MessageBoxOptions.h b/modules/juce_gui_basics/windows/juce_MessageBoxOptions.h index 35b9f461fe..eac1f76afe 100644 --- a/modules/juce_gui_basics/windows/juce_MessageBoxOptions.h +++ b/modules/juce_gui_basics/windows/juce_MessageBoxOptions.h @@ -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 associatedComponent; + WeakReference parentComponent; }; } // namespace juce