Browse Source

AlertWindow: Allow parent component to be specified

v7.0.9
reuk 3 years ago
parent
commit
882c2aa01d
No known key found for this signature in database GPG Key ID: FCB43929F012EE5C
2 changed files with 23 additions and 0 deletions
  1. +9
    -0
      modules/juce_gui_basics/windows/juce_AlertWindow.cpp
  2. +14
    -0
      modules/juce_gui_basics/windows/juce_MessageBoxOptions.h

+ 9
- 0
modules/juce_gui_basics/windows/juce_AlertWindow.cpp 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;
}


+ 14
- 0
modules/juce_gui_basics/windows/juce_MessageBoxOptions.h 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

Loading…
Cancel
Save