29static juce_wchar getDefaultPasswordChar() noexcept
31 #if JUCE_LINUX || JUCE_BSD
38static int showAlertWindowUnmanaged (
const MessageBoxOptions&
opts, ModalComponentManager::Callback*
cb)
40 return detail::ConcreteScopedMessageBoxImpl::showUnmanaged (detail::AlertWindowHelpers::create (
opts),
cb);
49 alertIconType (iconType),
50 associatedComponent (comp),
51 desktopScale (comp !=
nullptr ?
Component::getApproximateScaleFactorForComponent (comp) : 1.0f)
74 for (
auto* t : textBoxes)
75 t->setWantsKeyboardFocus (
false);
86 if (escapeKeyCancels || buttons.size() > 0)
109void AlertWindow::exitAlert (
Button* button)
111 if (
auto* parent = button->getParentComponent())
112 parent->exitModalState (button->getCommandID());
117 const int returnValue,
124 b->setWantsKeyboardFocus (
true);
125 b->setExplicitFocusOrder (1);
126 b->setMouseClickGrabsKeyboardFocus (
false);
127 b->setCommandToTrigger (
nullptr, returnValue,
false);
130 b->onClick = [
this, b] { exitAlert (b); };
135 auto buttonHeight =
lf.getAlertWindowButtonHeight();
141 for (
auto* button : buttons)
145 updateLayout (
false);
150 return buttons.size();
155 return buttons[index];
160 for (
auto* button : buttons)
170 button->triggerClick();
186 ed->setEscapeAndReturnKeysConsumed (
false);
197 updateLayout (
false);
202 for (
auto*
tb : textBoxes)
227 cb->addItemList (items, 1);
230 cb->setSelectedItemIndex (0);
233 updateLayout (
false);
238 for (
auto*
cb : comboBoxes)
270 void updateLayout (
const int width)
293 updateLayout (
false);
300 progressBars.add (
pb);
304 updateLayout (
false);
310 customComps.add (component);
311 allComps.add (component);
314 updateLayout (
false);
326 customComps.removeFirstMatchingValue (c);
327 allComps.removeFirstMatchingValue (c);
330 updateLayout (
false);
340 lf.drawAlertBox (g, *
this, textArea, textLayout);
345 for (
int i = textBoxes.size(); --i >= 0;)
347 auto*
te = textBoxes.getUnchecked (i);
350 te->getX(),
te->getY() - 14,
355 for (
int i = comboBoxNames.
size(); --i >= 0;)
357 auto*
cb = comboBoxes.getUnchecked (i);
360 cb->getX(),
cb->getY() - 14,
365 for (
auto* c : customComps)
367 c->getX(), c->getY() - 14,
385 const int edgeGap = 10;
397 if (alertIconType == NoIcon)
418 for (
auto* b : buttons)
423 h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
425 if (
auto* b = buttons[0])
426 h += 20 + b->getHeight();
428 for (
auto* c : customComps)
430 w =
jmax (w, (c->getWidth() * 100) / 80);
431 h += 10 + c->getHeight();
433 if (c->getName().isNotEmpty())
437 for (
auto*
tb : textBlocks)
442 for (
auto*
tb : textBlocks)
444 auto*
ac =
static_cast<AlertTextComp*
> (
tb);
445 ac->updateLayout ((
int) ((
float) w * 0.8f));
446 h +=
ac->getHeight() + 10;
462 textArea.
setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
463 accessibleMessageLabel.
setBounds (textArea);
468 for (
auto* b : buttons)
471 auto x = (w - totalWidth) / 2;
474 for (
auto* c : buttons)
477 c->setTopLeftPosition (x,
ny);
481 x += c->getWidth() +
spacer;
488 for (
auto* c : allComps)
492 const int comboIndex = comboBoxes.indexOf (
dynamic_cast<ComboBox*
> (c));
496 const int tbIndex = textBoxes.indexOf (
dynamic_cast<TextEditor*
> (c));
500 if (customComps.contains (c))
502 if (c->getName().isNotEmpty())
508 else if (textBlocks.contains (c))
510 c->setTopLeftPosition ((
getWidth() - c->getWidth()) / 2, y);
526 return allComps.size() > 0;
542 for (
auto* b : buttons)
544 if (b->isRegisteredForShortcut (key))
559 buttons.getUnchecked (0)->triggerClick();
572 updateLayout (
false);
575int AlertWindow::getDesktopWindowStyleFlags()
const
581#if JUCE_MODAL_LOOPS_PERMITTED
584 const String& message,
586 Component* associatedComponent)
588 show (MessageBoxOptions()
589 .withIconType (iconType)
591 .withMessage (message)
593 .withAssociatedComponent (associatedComponent));
596int AlertWindow::show (
const MessageBoxOptions& options)
599 return NativeMessageBox::show (options);
601 return showAlertWindowUnmanaged (options,
nullptr);
604bool AlertWindow::showNativeDialogBox (
const String& title,
611 NativeMessageBox::showMessageBox (AlertWindow::NoIcon, title,
bodyText);
621 showAlertWindowUnmanaged (options, callback);
640 associatedComponent);
648 return showNativeBoxUnmanaged (options,
callbackIn, ResultCodeMappingMode::alertWindow);
650 return showAlertWindowUnmanaged (options,
callbackIn);
666 associatedComponent);
667 return showMaybeAsync (options, callback) == 1;
685 associatedComponent);
686 return showMaybeAsync (options, callback);
694 return detail::ConcreteScopedMessageBoxImpl::show (detail::AlertWindowHelpers::create (options), std::move (callback));
700 return std::make_unique<AccessibilityHandler> (*
this, AccessibilityRole::dialogWindow);
A window that displays a message and has buttons for the user to react to it.
void mouseDown(const MouseEvent &) override
Called when a mouse button is pressed.
@ textColourId
The colour for the text.
void setEscapeKeyCancels(bool shouldEscapeKeyCancel)
If set to true and the window contains no buttons, then pressing the escape key will make the alert c...
void addButton(const String &name, int returnValue, const KeyPress &shortcutKey1=KeyPress(), const KeyPress &shortcutKey2=KeyPress())
Adds a button to the window.
void addComboBox(const String &name, const StringArray &items, const String &onScreenLabel=String())
Adds a drop-down list of choices to the box.
static int JUCE_CALLTYPE showYesNoCancelBox(MessageBoxIconType 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.
void addTextEditor(const String &name, const String &initialContents, const String &onScreenLabel=String(), bool isPasswordBox=false)
Adds a textbox to the window for entering strings.
int getNumButtons() const
Returns the number of buttons that the window currently has.
static bool JUCE_CALLTYPE showOkCancelBox(MessageBoxIconType 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.
void setMessage(const String &message)
Changes the dialog box's message.
static ScopedMessageBox showScopedAsync(const MessageBoxOptions &options, std::function< void(int)> callback)
Shows an alert window using the specified options.
static void JUCE_CALLTYPE showAsync(const MessageBoxOptions &options, ModalComponentManager::Callback *callback)
Shows a dialog box using the specified options.
void addTextBlock(const String &text)
Adds a block of text.
int getNumCustomComponents() const
Returns the number of custom components in the dialog box.
void lookAndFeelChanged() override
Called to let the component react to a change in the look-and-feel setting.
bool containsAnyExtraComponents() const
Returns true if the window contains any components other than just buttons.
void mouseDrag(const MouseEvent &) override
Called when the mouse is moved while a button is held down.
static void JUCE_CALLTYPE showMessageBoxAsync(MessageBoxIconType iconType, const String &title, const String &message, const String &buttonText=String(), Component *associatedComponent=nullptr, ModalComponentManager::Callback *callback=nullptr)
Shows a dialog box that just has a message and a single button to get rid of it.
void addProgressBarComponent(double &progressValue, std::optional< ProgressBar::Style > style=std::nullopt)
Adds a progress-bar to the window.
Component * getCustomComponent(int index) const
Returns one of the custom components in the dialog box.
Button * getButton(int index) const
Returns a Button that was added to the AlertWindow.
void paint(Graphics &) override
Components can override this method to draw their content.
TextEditor * getTextEditor(const String &nameOfTextEditor) const
Returns a pointer to a textbox that was added with addTextEditor().
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Override this method to return a custom AccessibilityHandler for this component.
void triggerButtonClick(const String &buttonName)
Invokes a click of one of the buttons.
Component * removeCustomComponent(int index)
Removes one of the custom components in the dialog box.
void addCustomComponent(Component *component)
Adds a user-defined component to the dialog box.
AlertWindow(const String &title, const String &message, MessageBoxIconType iconType, Component *associatedComponent=nullptr)
Creates an AlertWindow.
String getTextEditorContents(const String &nameOfTextEditor) const
Returns the contents of a named textbox.
~AlertWindow() override
Destroys the AlertWindow.
bool keyPressed(const KeyPress &) override
Called when a key is pressed.
ComboBox * getComboBoxComponent(const String &nameOfList) const
Returns a drop-down list that was added to the AlertWindow.
void userTriedToCloseWindow() override
For components on the desktop, this is called if the system wants to close the window.
Holds a resizable array of primitive or copy-by-value objects.
A text string with a set of colour/font settings that are associated with sub-ranges of the text.
void append(const String &textToAppend)
Appends some text (with a default font and colour).
void setJustification(Justification newJustification) noexcept
Sets the justification that should be used for laying-out the text.
A component that lets the user choose from a drop-down list of choices.
@ outlineColourId
The colour for an outline around the box.
void setMinimumOnscreenAmounts(int minimumWhenOffTheTop, int minimumWhenOffTheLeft, int minimumWhenOffTheBottom, int minimumWhenOffTheRight) noexcept
Sets the amount by which the component is allowed to go off-screen.
void dragComponent(Component *componentToDrag, const MouseEvent &e, ComponentBoundsConstrainer *constrainer)
Call this from your mouseDrag() callback to move the component.
void startDraggingComponent(Component *componentToDrag, const MouseEvent &e)
Call this from your component's mouseDown() method, to prepare for dragging.
@ windowHasDropShadow
Indicates that the window should have a drop-shadow (this may not be possible on all platforms).
@ windowHasTitleBar
Indicates that the window should have a normal OS-specific title bar and frame.
The base class for all JUCE user-interface objects.
bool isColourSpecified(int colourID) const
Returns true if the specified colour ID has been explicitly set for this component using the setColou...
int proportionOfWidth(float proportion) const noexcept
Returns a proportion of the component's width.
void giveAwayKeyboardFocus()
If this component or any of its children currently have the keyboard focus, this will defocus it,...
void setInterceptsMouseClicks(bool allowClicksOnThisComponent, bool allowClicksOnChildComponents) noexcept
Changes the default return value for the hitTest() method.
bool isVisible() const noexcept
Tests whether the component is visible or not.
int getNumChildComponents() const noexcept
Returns the number of child components that this component contains.
int proportionOfHeight(float proportion) const noexcept
Returns a proportion of the component's height.
void exitModalState(int returnValue=0)
Ends a component's modal state.
bool isOpaque() const noexcept
Returns true if no parts of this component are transparent.
int getHeight() const noexcept
Returns the component's height in pixels.
void addAndMakeVisible(Component *child, int zOrder=-1)
Adds a child component to this one, and also makes the child visible if it isn't already.
void setAlwaysOnTop(bool shouldStayOnTop)
Sets whether the component should always be kept at the front of its siblings.
void setDescription(const String &newDescription)
Sets the description for this component.
Rectangle< int > getBounds() const noexcept
Returns this component's bounding box.
void repaint()
Marks the whole component as needing to be redrawn.
void removeChildComponent(Component *childToRemove)
Removes one of this component's child-components.
void removeAllChildren()
Removes all this component's children.
void setBounds(int x, int y, int width, int height)
Changes the component's position and size.
void setSize(int newWidth, int newHeight)
Changes the size of the component.
void setColour(int colourID, Colour newColour)
Registers a colour to be used for a particular purpose.
void setWantsKeyboardFocus(bool wantsFocus) noexcept
Sets a flag to indicate whether this component wants keyboard focus or not.
Colour findColour(int colourID, bool inheritFromParent=false) const
Looks for a colour that has been registered with the given colour ID number.
int getWidth() const noexcept
Returns the component's width in pixels.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
int getParentWidth() const noexcept
Returns the width of the component's parent.
int getParentHeight() const noexcept
Returns the height of the component's parent.
String getName() const noexcept
Returns the name of this component.
Represents a particular font, including its size, style, etc.
float getHeight() const noexcept
Returns the total height of this font, in pixels.
int getStringWidth(const String &text) const
Returns the total width of a string as it would be drawn using this font.
A graphics context, used for drawing a component or image.
void drawFittedText(const String &text, int x, int y, int width, int height, Justification justificationFlags, int maximumNumberOfLines, float minimumHorizontalScale=0.0f) const
Tries to draw a text string inside a given space.
void setFont(const Font &newFont)
Changes the font to use for subsequent text-drawing functions.
void setColour(Colour newColour)
Changes the current drawing colour.
@ centredLeft
Indicates that the item should be centred vertically but placed on the left hand side.
@ centredTop
Indicates that the item should be centred horizontally and placed at the top.
@ topLeft
Indicates that the item should be placed in the top-left corner.
Represents a key press, including any modifier keys that are needed.
bool isKeyCode(int keyCodeToCompare) const noexcept
Checks whether the KeyPress's key is the same as the one provided, without checking the modifiers.
static const int escapeKey
key-code for the escape key
static const int returnKey
key-code for the return key
@ outlineColourId
An optional colour to use to draw a border around the label.
@ backgroundColourId
The background colour to fill the label with.
@ textColourId
The colour for the text.
void setText(const String &newText, NotificationType notification)
Changes the label text.
static LookAndFeel & getDefaultLookAndFeel() noexcept
Returns the current default look-and-feel for a component to use when it hasn't got one explicitly se...
Class used to create a set of options to pass to the AlertWindow and NativeMessageBox methods for sho...
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.
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 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 ModalComponentManager::Callback * create(CallbackFn &&fn)
This is a utility function to create a ModalComponentManager::Callback that will call a callable obje...
Receives callbacks when a modal component is dismissed.
Contains position and status information about a mouse event.
static bool JUCE_CALLTYPE showOkCancelBox(MessageBoxIconType iconType, const String &title, const String &message, Component *associatedComponent, ModalComponentManager::Callback *callback)
Shows a dialog box with two buttons.
static ScopedMessageBox showScopedAsync(const MessageBoxOptions &options, std::function< void(int)> callback)
Shows a dialog box using the specified options.
static void JUCE_CALLTYPE showAsync(const MessageBoxOptions &options, ModalComponentManager::Callback *callback)
Shows a dialog box using the specified options.
A progress bar component.
void setBounds(ValueType newX, ValueType newY, ValueType newWidth, ValueType newHeight) noexcept
Changes all the rectangle's coordinates.
Objects of this type can be used to programmatically close message boxes.
A special array for holding a list of strings.
int size() const noexcept
Returns the number of strings in the array.
void add(String stringToAdd)
Appends a string at the end of the array.
bool isEmpty() const noexcept
Returns true if the string contains no characters.
String substring(int startIndex, int endIndex) const
Returns a subsection of the string.
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
A button that uses the standard lozenge-shaped background with a line of text on it.
void setScrollbarsShown(bool shouldBeEnabled)
Enables or disables scrollbars (this only applies when in multi-line mode).
void setMultiLine(bool shouldBeMultiLine, bool shouldWordWrap=true)
Puts the editor into either multi- or single-line mode.
@ backgroundColourId
The colour to use for the text component's background - this can be transparent if necessary.
@ textColourId
The colour that will be used when text is added to the editor.
@ outlineColourId
If this is non-transparent, it will be used to draw a box around the edge of the component.
@ shadowColourId
If this is non-transparent, it'll be used to draw an inner shadow around the edge of the editor.
const Font & getFont() const noexcept
Returns the font that's currently being used for new text.
void setFont(const Font &newFont)
Sets the font to use for newly added text.
void setText(const String &newText, bool sendTextChangeMessage=true)
Sets the entire content of the editor.
void setReadOnly(bool shouldBeReadOnly)
Changes the editor to read-only mode.
void lookAndFeelChanged() override
Called to let the component react to a change in the look-and-feel setting.
void setCaretVisible(bool shouldBeVisible)
Makes the caret visible or invisible.
String getText() const
Returns the entire contents of the editor.
void setSelectAllWhenFocused(bool shouldSelectAll)
If set to true, focusing on the editor will highlight all its text.
A Pre-formatted piece of text, which may contain multiple fonts and colours.
void createLayoutWithBalancedLineLengths(const AttributedString &, float maxWidth)
Creates a layout, attempting to choose a width which results in lines of a similar length.
float getWidth() const noexcept
Returns the maximum width of the content.
float getHeight() const noexcept
Returns the maximum height of the content.
A base class for top-level windows.
void centreAroundComponent(Component *componentToCentreAround, int width, int height)
This will set the bounds of the window so that it's centred in front of another window.
void setDropShadowEnabled(bool useShadow)
Turns the drop-shadow on and off.
void setUsingNativeTitleBar(bool useNativeTitleBar)
Sets whether an OS-native title bar will be used, or a JUCE one.
#define TRANS(stringLiteral)
Uses the LocalisedStrings class to translate the given string literal.
wchar_t juce_wchar
A platform-independent 32-bit unicode character type.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
MessageBoxIconType
The type of icon to show in the dialog box.
@ dontSendNotification
No notification message should be sent.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
static bool areThereAnyAlwaysOnTopWindows()
Returns true if any windows have a z order that is higher than normal.