Loading...
Searching...
No Matches
juce::MessageBoxOptions Class Reference

Detailed Description

Class used to create a set of options to pass to the AlertWindow and NativeMessageBox methods for showing dialog boxes.

You can chain together a series of calls to this class's methods to create a set of whatever options you want to specify.

E.g.

.withTitle ("A Title")
.withMessage ("A message.")
.withButton ("OK", 1)
.withButton ("Cancel", 0)
myCallback);
static void JUCE_CALLTYPE showAsync(const MessageBoxOptions &options, ModalComponentManager::Callback *callback)
Shows a dialog box using the specified options.
MessageBoxOptions withMessage(const String &boxMessage) const
Sets the message that should be displayed in the dialog box.
Definition juce_MessageBoxOptions.h:200
MessageBoxOptions withTitle(const String &boxTitle) const
Sets the title of the dialog box.
Definition juce_MessageBoxOptions.h:197
MessageBoxOptions withIconType(MessageBoxIconType type) const
Sets the type of icon that should be used for the dialog box.
Definition juce_MessageBoxOptions.h:194
MessageBoxOptions withButton(const String &text, int resultCode) const
This will add a button to the dialog box with the specified text and result code.
Definition juce_MessageBoxOptions.h:221
MessageBoxOptions withAssociatedComponent(Component *component) const
The component that the dialog box should be associated with.
Definition juce_MessageBoxOptions.h:254
@ InfoIcon
An icon that indicates that the dialog box is just giving the user some information,...
Definition juce_MessageBoxOptions.h:46

The documentation for this class was generated from the following file:

Public Member Functions

 MessageBoxOptions ()=default
 MessageBoxOptions (const MessageBoxOptions &)=default
MessageBoxOptions & operator= (const MessageBoxOptions &)=default
MessageBoxOptions withIconType (MessageBoxIconType type) const
 Sets the type of icon that should be used for the dialog box.
MessageBoxOptions withTitle (const String &boxTitle) const
 Sets the title of the dialog box.
MessageBoxOptions withMessage (const String &boxMessage) const
 Sets the message that should be displayed in the dialog box.
MessageBoxOptions withButton (const String &text, int resultCode) const
 This will add a button to the dialog box with the specified text and result code.
MessageBoxOptions withButton (MessageBoxButtonOptions opt) const
 This will add a button to the dialog box with the specified properties.
MessageBoxOptions withAssociatedComponent (Component *component) const
 The component that the dialog box should be associated with.
MessageBoxOptions withParentComponent (Component *component) const
 The component that will contain the message box (e.g.
MessageBoxIconType getIconType () const noexcept
 Returns the icon type of the dialog box.
String getTitle () const
 Returns the title of the dialog box.
String getMessage () const
 Returns the message of the dialog box.
int getNumButtons () const noexcept
 Returns the number of buttons that have been added to the dialog box.
String getButtonText (int buttonIndex) const
 Returns the text that has been set for one of the buttons of the dialog box.
int getButtonResultCode (int buttonIndex) const
 Returns the result code associated with the button at the given index.
Span< const MessageBoxButtonOptions > getButtons () const &
 Returns the properties of all buttons in the message box.
Span< const MessageBoxButtonOptions > getButtons () const &&=delete
 Deleted to avoid dangling references.
bool areAllResultCodesUnique () const
 Returns true if all buttons have a unique result code, or false otherwise.
Component * getAssociatedComponent () const noexcept
 Returns the component that the dialog box is associated with.
Component * getParentComponent () const noexcept
 Returns the component that will be used as the parent of the dialog box.

Static Public Member Functions

static MessageBoxOptions makeOptionsOk (MessageBoxIconType iconType, const String &title, const String &message, const String &buttonText=String(), Component *associatedComponent=nullptr)
 Creates options suitable for a message box with a single button.
static MessageBoxOptions makeOptionsOkCancel (MessageBoxIconType iconType, const String &title, const String &message, const String &button1Text=String(), const String &button2Text=String(), Component *associatedComponent=nullptr)
 Creates options suitable for a message box with two buttons.
static MessageBoxOptions makeOptionsYesNo (MessageBoxIconType iconType, const String &title, const String &message, const String &button1Text=String(), const String &button2Text=String(), Component *associatedComponent=nullptr)
 Creates options suitable for a message box with two buttons.
static MessageBoxOptions makeOptionsYesNoCancel (MessageBoxIconType iconType, const String &title, const String &message, const String &button1Text=String(), const String &button2Text=String(), const String &button3Text=String(), Component *associatedComponent=nullptr)
 Creates options suitable for a message box with three buttons.

Constructors and Destructors

◆ MessageBoxOptions() [1/2]

◆ MessageBoxOptions() [2/2]

juce::MessageBoxOptions::MessageBoxOptions ( const MessageBoxOptions & )
default

References MessageBoxOptions().

Member Functions

◆ operator=()

MessageBoxOptions & juce::MessageBoxOptions::operator= ( const MessageBoxOptions & )
default

References MessageBoxOptions().

◆ withIconType()

MessageBoxOptions juce::MessageBoxOptions::withIconType ( MessageBoxIconType type) const
inlinenodiscard

Sets the type of icon that should be used for the dialog box.

References MessageBoxOptions(), and juce::withMember().

◆ withTitle()

MessageBoxOptions juce::MessageBoxOptions::withTitle ( const String & boxTitle) const
inlinenodiscard

Sets the title of the dialog box.

References MessageBoxOptions(), and juce::withMember().

◆ withMessage()

MessageBoxOptions juce::MessageBoxOptions::withMessage ( const String & boxMessage) const
inlinenodiscard

Sets the message that should be displayed in the dialog box.

References MessageBoxOptions(), and juce::withMember().

◆ withButton() [1/2]

MessageBoxOptions juce::MessageBoxOptions::withButton ( const String & text,
int resultCode ) const
inlinenodiscard

This will add a button to the dialog box with the specified text and result code.

Generally up to 3 buttons are supported for dialog boxes, so adding any more than this may have no effect.

Message-boxes with zero or one buttons, or that hold a button with the 'cancel' role, may be cancelled. For example, on Windows, a native message box can be dismissed by pressing alt+f4 or escape, and on Android, a native message box can be dismissed by tapping outside the box or pressing the back button.

On macOS, a preferred "OK" button will be added automatically to native dialogs with no buttons. Such dialogs can be dismissed with the return key, but not with the escape key.

Cancelling a zero-button message box will return "0". Cancelling a single-button message box will return the result code of that button. Cancelling a message box with a different number of buttons will return the code of whichever button has the 'cancel' role.

References MessageBoxOptions().

◆ withButton() [2/2]

MessageBoxOptions juce::MessageBoxOptions::withButton ( MessageBoxButtonOptions opt) const
nodiscard

This will add a button to the dialog box with the specified properties.

Generally up to 3 buttons are supported for dialog boxes, so adding any more than this may have no effect.

Message-boxes with zero or one buttons, or that hold a button with the 'cancel' role, may be cancelled. For example, on Windows, a native message box can be dismissed by pressing alt+f4 or escape, and on Android, a native message box can be dismissed by tapping outside the box or pressing the back button.

On macOS, a preferred "OK" button will be added automatically to native dialogs with no buttons. Such dialogs can be dismissed with the return key, but not with the escape key.

Cancelling a zero-button message box will return "0". Cancelling a single-button message box will return the result code of that button. Cancelling a message box with a different number of buttons will return the code of whichever button has the 'cancel' role.

References MessageBoxOptions().

◆ withAssociatedComponent()

MessageBoxOptions juce::MessageBoxOptions::withAssociatedComponent ( Component * component) const
inlinenodiscard

The component that the dialog box should be associated with.

An AlertWindow is kept above the window containing this component. See TopLevelWindow::setAssociatedComponent().

References MessageBoxOptions(), and juce::withMember().

◆ withParentComponent()

MessageBoxOptions juce::MessageBoxOptions::withParentComponent ( Component * component) const
inlinenodiscard

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.

References MessageBoxOptions(), and juce::withMember().

◆ getIconType()

MessageBoxIconType juce::MessageBoxOptions::getIconType ( ) const
inlinenoexcept

Returns the icon type of the dialog box.

See also
withIconType

◆ getTitle()

String juce::MessageBoxOptions::getTitle ( ) const
inline

Returns the title of the dialog box.

See also
withTitle

◆ getMessage()

String juce::MessageBoxOptions::getMessage ( ) const
inline

Returns the message of the dialog box.

See also
withMessage

◆ getNumButtons()

int juce::MessageBoxOptions::getNumButtons ( ) const
inlinenoexcept

Returns the number of buttons that have been added to the dialog box.

See also
withButton

Referenced by areAllResultCodesUnique().

◆ getButtonText()

String juce::MessageBoxOptions::getButtonText ( int buttonIndex) const
inline

Returns the text that has been set for one of the buttons of the dialog box.

See also
withButton, getNumButtons
Deprecated
Prefer to index into the result of getButtons()

References juce::isPositiveAndBelow(), and jassertfalse.

◆ getButtonResultCode()

int juce::MessageBoxOptions::getButtonResultCode ( int buttonIndex) const
inline

Returns the result code associated with the button at the given index.

See also
withButton, getNumButtons
Deprecated
Prefer to index into the result of getButtons()

References juce::isPositiveAndBelow(), and jassertfalse.

◆ getButtons() [1/2]

Span< const MessageBoxButtonOptions > juce::MessageBoxOptions::getButtons ( ) const &
inline

Returns the properties of all buttons in the message box.

◆ getButtons() [2/2]

Span< const MessageBoxButtonOptions > juce::MessageBoxOptions::getButtons ( ) const &&
delete

Deleted to avoid dangling references.

◆ areAllResultCodesUnique()

bool juce::MessageBoxOptions::areAllResultCodesUnique ( ) const
inline

Returns true if all buttons have a unique result code, or false otherwise.

References areAllResultCodesUnique(), and getNumButtons().

Referenced by areAllResultCodesUnique().

◆ getAssociatedComponent()

Component * juce::MessageBoxOptions::getAssociatedComponent ( ) const
inlinenoexcept

Returns the component that the dialog box is associated with.

See also
withAssociatedComponent

◆ getParentComponent()

Component * juce::MessageBoxOptions::getParentComponent ( ) const
inlinenoexcept

Returns the component that will be used as the parent of the dialog box.

See also
withParentComponent

◆ makeOptionsOk()

MessageBoxOptions juce::MessageBoxOptions::makeOptionsOk ( MessageBoxIconType iconType,
const String & title,
const String & message,
const String & buttonText = String(),
Component * associatedComponent = nullptr )
static

Creates options suitable for a message box with a single button.

If no button text is supplied, "OK" will be used.

References MessageBoxOptions().

Referenced by juce::StandalonePluginHolder::askUserToLoadState(), and juce::StandalonePluginHolder::askUserToSaveState().

◆ makeOptionsOkCancel()

MessageBoxOptions juce::MessageBoxOptions::makeOptionsOkCancel ( MessageBoxIconType iconType,
const String & title,
const String & message,
const String & button1Text = String(),
const String & button2Text = String(),
Component * associatedComponent = nullptr )
static

Creates options suitable for a message box with two buttons.

If no button text is supplied, "OK" and "Cancel" will be used.

Deprecated
Prefer to use MessageBoxOptions{}.withButton()..., so that result codes for each button are explicit

References MessageBoxOptions().

◆ makeOptionsYesNo()

MessageBoxOptions juce::MessageBoxOptions::makeOptionsYesNo ( MessageBoxIconType iconType,
const String & title,
const String & message,
const String & button1Text = String(),
const String & button2Text = String(),
Component * associatedComponent = nullptr )
static

Creates options suitable for a message box with two buttons.

If no button text is supplied, "Yes" and "No" will be used.

Deprecated
Prefer to use MessageBoxOptions{}.withButton()..., so that result codes for each button are explicit

References MessageBoxOptions().

◆ makeOptionsYesNoCancel()

MessageBoxOptions juce::MessageBoxOptions::makeOptionsYesNoCancel ( MessageBoxIconType iconType,
const String & title,
const String & message,
const String & button1Text = String(),
const String & button2Text = String(),
const String & button3Text = String(),
Component * associatedComponent = nullptr )
static

Creates options suitable for a message box with three buttons.

If no button text is supplied, "Yes", "No", and "Cancel" will be used.

Deprecated
Prefer to use MessageBoxOptions{}.withButton()..., so that result codes for each button are explicit

References juce::InfoIcon, and MessageBoxOptions().