A window that displays a message and has buttons for the user to react to it. More...
Inherits TopLevelWindow.
Public Types | |
| enum | AlertIconType { NoIcon, QuestionIcon, WarningIcon, InfoIcon } |
The type of icon to show in the dialog box. More... | |
| enum | ColourIds { backgroundColourId = 0x1001800, textColourId = 0x1001810, outlineColourId = 0x1001820 } |
Shows an operating-system native dialog box. More... | |
Public Member Functions | |
| AlertWindow (const String &title, const String &message, AlertIconType iconType, Component *associatedComponent=nullptr) | |
| Creates an AlertWindow. | |
| ~AlertWindow () | |
| Destroys the AlertWindow. | |
| AlertIconType | getAlertType () const noexcept |
| Returns the type of alert icon that was specified when the window was created. | |
| void | setMessage (const String &message) |
| Changes the dialog box's message. | |
| void | addButton (const String &name, int returnValue, const KeyPress &shortcutKey1=KeyPress(), const KeyPress &shortcutKey2=KeyPress()) |
| Adds a button to the window. | |
| int | getNumButtons () const |
| Returns the number of buttons that the window currently has. | |
| void | triggerButtonClick (const String &buttonName) |
| Invokes a click of one of the buttons. | |
| void | addTextEditor (const String &name, const String &initialContents, const String &onScreenLabel=String::empty, bool isPasswordBox=false) |
| Adds a textbox to the window for entering strings. | |
| String | getTextEditorContents (const String &nameOfTextEditor) const |
| Returns the contents of a named textbox. | |
| TextEditor * | getTextEditor (const String &nameOfTextEditor) const |
| Returns a pointer to a textbox that was added with addTextEditor(). | |
| void | addComboBox (const String &name, const StringArray &items, const String &onScreenLabel=String::empty) |
| Adds a drop-down list of choices to the box. | |
| ComboBox * | getComboBoxComponent (const String &nameOfList) const |
| Returns a drop-down list that was added to the AlertWindow. | |
| void | addTextBlock (const String &text) |
| Adds a block of text. | |
| void | addProgressBarComponent (double &progressValue) |
| Adds a progress-bar to the window. | |
| void | addCustomComponent (Component *component) |
| Adds a user-defined component to the dialog box. | |
| int | getNumCustomComponents () const |
| Returns the number of custom components in the dialog box. | |
| Component * | getCustomComponent (int index) const |
| Returns one of the custom components in the dialog box. | |
| Component * | removeCustomComponent (int index) |
| Removes one of the custom components in the dialog box. | |
| bool | containsAnyExtraComponents () const |
| Returns true if the window contains any components other than just buttons. | |
Static Public Member Functions | |
| static void JUCE_CALLTYPE | showMessageBoxAsync (AlertIconType iconType, const String &title, const String &message, const String &buttonText=String::empty, Component *associatedComponent=nullptr) |
| Shows a dialog box that just has a message and a single button to get rid of it. | |
| static bool JUCE_CALLTYPE | showOkCancelBox (AlertIconType iconType, const String &title, const String &message, const String &button1Text, const String &button2Text, Component *associatedComponent, ModalComponentManager::Callback *callback) |
| Shows a dialog box with two buttons. | |
| static int JUCE_CALLTYPE | showYesNoCancelBox (AlertIconType iconType, const String &title, const String &message, const String &button1Text, const String &button2Text, const String &button3Text, Component *associatedComponent, ModalComponentManager::Callback *callback) |
| Shows a dialog box with three buttons. | |
Protected Member Functions | |
| void | paint (Graphics &g) |
| Components can override this method to draw their content. | |
| void | mouseDown (const MouseEvent &e) |
| Called when a mouse button is pressed while it's over this component. | |
| void | mouseDrag (const MouseEvent &e) |
| Called when the mouse is moved while a button is held down. | |
| bool | keyPressed (const KeyPress &key) |
| Called when a key is pressed. | |
| void | buttonClicked (Button *button) |
| void | lookAndFeelChanged () |
| Called to let the component react to a change in the look-and-feel setting. | |
| void | userTriedToCloseWindow () |
| For components on the desktop, this is called if the system wants to close the window. | |
| int | getDesktopWindowStyleFlags () const |
A window that displays a message and has buttons for the user to react to it.
For simple dialog boxes with just a couple of buttons on them, there are some static methods for running these.
For more complex dialogs, an AlertWindow can be created, then it can have some buttons and components added to it, and its runModalLoop() method is then used to show it. The value returned by runModalLoop() shows which button the user pressed to dismiss the box.
The type of icon to show in the dialog box.
Shows an operating-system native dialog box.
| title | the title to use at the top |
| bodyText | the longer message to show |
| isOkCancel | if true, this will show an ok/cancel box, if false, it'll show a box with just an ok button |
These constants can be used either via the Component::setColour(), or LookAndFeel::setColour() methods.
| AlertWindow::AlertWindow | ( | const String & | title, |
| const String & | message, | ||
| AlertIconType | iconType, | ||
| Component * | associatedComponent = nullptr |
||
| ) |
Creates an AlertWindow.
| title | the headline to show at the top of the dialog box |
| message | a longer, more descriptive message to show underneath the headline |
| iconType | the type of icon to display |
| associatedComponent | if this is non-null, it specifies the component that the alert window should be associated with. Depending on the look and feel, this might be used for positioning of the alert window. |
| AlertWindow::~AlertWindow | ( | ) |
Destroys the AlertWindow.
| AlertIconType AlertWindow::getAlertType | ( | ) | const |
Returns the type of alert icon that was specified when the window was created.
| void AlertWindow::setMessage | ( | const String & | message ) |
Changes the dialog box's message.
This will also resize the window to fit the new message if required.
| void AlertWindow::addButton | ( | const String & | name, |
| int | returnValue, | ||
| const KeyPress & | shortcutKey1 = KeyPress(), |
||
| const KeyPress & | shortcutKey2 = KeyPress() |
||
| ) |
Adds a button to the window.
| name | the text to show on the button |
| returnValue | the value that should be returned from runModalLoop() if this is the button that the user presses. |
| shortcutKey1 | an optional key that can be pressed to trigger this button |
| shortcutKey2 | a second optional key that can be pressed to trigger this button |
| int AlertWindow::getNumButtons | ( | ) | const |
Returns the number of buttons that the window currently has.
| void AlertWindow::triggerButtonClick | ( | const String & | buttonName ) |
Invokes a click of one of the buttons.
| void AlertWindow::addTextEditor | ( | const String & | name, |
| const String & | initialContents, | ||
| const String & | onScreenLabel = String::empty, |
||
| bool | isPasswordBox = false |
||
| ) |
Adds a textbox to the window for entering strings.
| name | an internal name for the text-box. This is the name to pass to the getTextEditorContents() method to find out what the user typed-in. |
| initialContents | a string to show in the text box when it's first shown |
| onScreenLabel | if this is non-empty, it will be displayed next to the text-box to label it. |
| isPasswordBox | if true, the text editor will display asterisks instead of the actual text |
Returns the contents of a named textbox.
After showing an AlertWindow that contains a text editor, this can be used to find out what the user has typed into it.
| nameOfTextEditor | the name of the text box that you're interested in |
| TextEditor* AlertWindow::getTextEditor | ( | const String & | nameOfTextEditor ) | const |
Returns a pointer to a textbox that was added with addTextEditor().
| void AlertWindow::addComboBox | ( | const String & | name, |
| const StringArray & | items, | ||
| const String & | onScreenLabel = String::empty |
||
| ) |
Adds a drop-down list of choices to the box.
After the box has been shown, the getComboBoxComponent() method can be used to find out which item the user picked.
| name | the label to use for the drop-down list |
| items | the list of items to show in it |
| onScreenLabel | if this is non-empty, it will be displayed next to the combo-box to label it. |
Returns a drop-down list that was added to the AlertWindow.
| nameOfList | the name that was passed into the addComboBox() method when creating the drop-down |
| void AlertWindow::addTextBlock | ( | const String & | text ) |
Adds a block of text.
This is handy for adding a multi-line note next to a textbox or combo-box, to provide more details about what's going on.
| void AlertWindow::addProgressBarComponent | ( | double & | progressValue ) |
Adds a progress-bar to the window.
| progressValue | a variable that will be repeatedly checked while the dialog box is visible, to see how far the process has got. The value should be in the range 0 to 1.0 |
| void AlertWindow::addCustomComponent | ( | Component * | component ) |
Adds a user-defined component to the dialog box.
| component | the component to add - its size should be set up correctly before it is passed in. The caller is responsible for deleting the component later on - the AlertWindow won't delete it. |
| int AlertWindow::getNumCustomComponents | ( | ) | const |
Returns the number of custom components in the dialog box.
| Component* AlertWindow::getCustomComponent | ( | int | index ) | const |
Returns one of the custom components in the dialog box.
| index | a value 0 to (getNumCustomComponents() - 1). Out-of-range indexes will return 0 |
| Component* AlertWindow::removeCustomComponent | ( | int | index ) |
Removes one of the custom components in the dialog box.
Note that this won't delete it, it just removes the component from the window
| index | a value 0 to (getNumCustomComponents() - 1). Out-of-range indexes will return 0 |
| bool AlertWindow::containsAnyExtraComponents | ( | ) | const |
Returns true if the window contains any components other than just buttons.
| static void JUCE_CALLTYPE AlertWindow::showMessageBoxAsync | ( | AlertIconType | iconType, |
| const String & | title, | ||
| const String & | message, | ||
| const String & | buttonText = String::empty, |
||
| Component * | associatedComponent = nullptr |
||
| ) | [static] |
Shows a dialog box that just has a message and a single button to get rid of it.
If the callback parameter is null, the box is shown modally, and the method will block until the user has clicked the button (or pressed the escape or return keys). If the callback parameter is non-null, the box will be displayed and placed into a modal state, but this method will return immediately, and the callback will be invoked later when the user dismisses the box.
| iconType | the type of icon to show |
| title | the headline to show at the top of the box |
| message | a longer, more descriptive message to show underneath the headline |
| buttonText | the text to show in the button - if this string is empty, the default string "ok" (or a localised version) will be used. |
| associatedComponent | if this is non-null, it specifies the component that the alert window should be associated with. Depending on the look and feel, this might be used for positioning of the alert window. Shows a dialog box that just has a message and a single button to get rid of it. |
If the callback parameter is null, the box is shown modally, and the method will block until the user has clicked the button (or pressed the escape or return keys). If the callback parameter is non-null, the box will be displayed and placed into a modal state, but this method will return immediately, and the callback will be invoked later when the user dismisses the box.
| iconType | the type of icon to show |
| title | the headline to show at the top of the box |
| message | a longer, more descriptive message to show underneath the headline |
| buttonText | the text to show in the button - if this string is empty, the default string "ok" (or a localised version) will be used. |
| associatedComponent | if this is non-null, it specifies the component that the alert window should be associated with. Depending on the look and feel, this might be used for positioning of the alert window. |
| static bool JUCE_CALLTYPE AlertWindow::showOkCancelBox | ( | AlertIconType | iconType, |
| const String & | title, | ||
| const String & | message, | ||
| const String & | button1Text, | ||
| const String & | button2Text, | ||
| Component * | associatedComponent, | ||
| ModalComponentManager::Callback * | callback | ||
| ) | [static] |
Shows a dialog box with two buttons.
Ideal for ok/cancel or yes/no choices. The return key can also be used to trigger the first button, and the escape key for the second button.
If the callback parameter is null, the box is shown modally, and the method will block until the user has clicked the button (or pressed the escape or return keys). If the callback parameter is non-null, the box will be displayed and placed into a modal state, but this method will return immediately, and the callback will be invoked later when the user dismisses the box.
| iconType | the type of icon to show |
| title | the headline to show at the top of the box |
| message | a longer, more descriptive message to show underneath the headline |
| button1Text | the text to show in the first button - if this string is empty, the default string "ok" (or a localised version of it) will be used. |
| button2Text | the text to show in the second button - if this string is empty, the default string "cancel" (or a localised version of it) will be used. |
| associatedComponent | if this is non-null, it specifies the component that the alert window should be associated with. Depending on the look and feel, this might be used for positioning of the alert window. |
| callback | if this is non-null, the menu will be launched asynchronously, returning immediately, and the callback will receive a call to its modalStateFinished() when the box is dismissed, with its parameter being 1 if the ok button was pressed, or 0 for cancel, The callback object will be owned and deleted by the system, so make sure that it works safely and doesn't keep any references to objects that might be deleted before it gets called. |
| static int JUCE_CALLTYPE AlertWindow::showYesNoCancelBox | ( | AlertIconType | iconType, |
| const String & | title, | ||
| const String & | message, | ||
| const String & | button1Text, | ||
| const String & | button2Text, | ||
| const String & | button3Text, | ||
| Component * | associatedComponent, | ||
| ModalComponentManager::Callback * | callback | ||
| ) | [static] |
Shows a dialog box with three buttons.
Ideal for yes/no/cancel boxes.
The escape key can be used to trigger the third button.
If the callback parameter is null, the box is shown modally, and the method will block until the user has clicked the button (or pressed the escape or return keys). If the callback parameter is non-null, the box will be displayed and placed into a modal state, but this method will return immediately, and the callback will be invoked later when the user dismisses the box.
| iconType | the type of icon to show |
| title | the headline to show at the top of the box |
| message | a longer, more descriptive message to show underneath the headline |
| button1Text | the text to show in the first button - if an empty string, then "yes" will be used (or a localised version of it) |
| button2Text | the text to show in the first button - if an empty string, then "no" will be used (or a localised version of it) |
| button3Text | the text to show in the first button - if an empty string, then "cancel" will be used (or a localised version of it) |
| associatedComponent | if this is non-null, it specifies the component that the alert window should be associated with. Depending on the look and feel, this might be used for positioning of the alert window. |
| callback | if this is non-null, the menu will be launched asynchronously, returning immediately, and the callback will receive a call to its modalStateFinished() when the box is dismissed, with its parameter being 1 if the "yes" button was pressed, 2 for the "no" button, or 0 if it was cancelled, The callback object will be owned and deleted by the system, so make sure that it works safely and doesn't keep any references to objects that might be deleted before it gets called. |
| void AlertWindow::paint | ( | Graphics & | g ) | [protected, virtual] |
Components can override this method to draw their content.
The paint() method gets called when a region of a component needs redrawing, either because the component's repaint() method has been called, or because something has happened on the screen that means a section of a window needs to be redrawn.
Any child components will draw themselves over whatever this method draws. If you need to paint over the top of your child components, you can also implement the paintOverChildren() method to do this.
If you want to cause a component to redraw itself, this is done asynchronously - calling the repaint() method marks a region of the component as "dirty", and the paint() method will automatically be called sometime later, by the message thread, to paint any bits that need refreshing. In Juce (and almost all modern UI frameworks), you never redraw something synchronously.
You should never need to call this method directly - to take a snapshot of the component you could use createComponentSnapshot() or paintEntireComponent().
| g | the graphics context that must be used to do the drawing operations. |
Reimplemented from Component.
| void AlertWindow::mouseDown | ( | const MouseEvent & | e ) | [protected, virtual] |
Called when a mouse button is pressed while it's over this component.
The MouseEvent object passed in contains lots of methods for finding out which button was pressed, as well as which modifier keys (e.g. shift, ctrl) were held down at the time.
Once a button is held down, the mouseDrag method will be called when the mouse moves, until the button is released.
| e | details about the position and status of the mouse event |
Reimplemented from Component.
| void AlertWindow::mouseDrag | ( | const MouseEvent & | e ) | [protected, virtual] |
Called when the mouse is moved while a button is held down.
When a mouse button is pressed inside a component, that component receives mouseDrag callbacks each time the mouse moves, even if the mouse strays outside the component's bounds.
If you want to be able to drag things off the edge of a component and have the component scroll when you get to the edges, the beginDragAutoRepeat() method might be useful.
| e | details about the position and status of the mouse event |
Reimplemented from Component.
| bool AlertWindow::keyPressed | ( | const KeyPress & | key ) | [protected, virtual] |
Called when a key is pressed.
When a key is pressed, the component that has the keyboard focus will have this method called. Remember that a component will only be given the focus if its setWantsKeyboardFocus() method has been used to enable this.
If your implementation returns true, the event will be consumed and not passed on to any other listeners. If it returns false, the key will be passed to any KeyListeners that have been registered with this component. As soon as one of these returns true, the process will stop, but if they all return false, the event will be passed upwards to this component's parent, and so on.
The default implementation of this method does nothing and returns false.
Reimplemented from Component.
| void AlertWindow::buttonClicked | ( | Button * | button ) | [protected] |
| void AlertWindow::lookAndFeelChanged | ( | ) | [protected, virtual] |
Called to let the component react to a change in the look-and-feel setting.
When the look-and-feel is changed for a component, this will be called in all its child components, recursively.
It can also be triggered manually by the sendLookAndFeelChange() method, in case an application uses a LookAndFeel class that might have changed internally.
Reimplemented from Component.
| void AlertWindow::userTriedToCloseWindow | ( | ) | [protected, virtual] |
For components on the desktop, this is called if the system wants to close the window.
This is a signal that either the user or the system wants the window to close. The default implementation of this method will trigger an assertion to warn you that your component should do something about it, but you can override this to ignore the event if you want.
Reimplemented from Component.
| int AlertWindow::getDesktopWindowStyleFlags | ( | ) | const [protected, virtual] |
Reimplemented from TopLevelWindow.