Browse Source

Added callback to AlertWindow::showMessageBoxAsync

tags/2021-05-28
jules 12 years ago
parent
commit
a1ed537463
2 changed files with 44 additions and 51 deletions
  1. +30
    -39
      modules/juce_gui_basics/windows/juce_AlertWindow.cpp
  2. +14
    -12
      modules/juce_gui_basics/windows/juce_AlertWindow.h

+ 30
- 39
modules/juce_gui_basics/windows/juce_AlertWindow.cpp View File

@@ -80,8 +80,8 @@ void AlertWindow::setMessage (const String& message)
//==============================================================================
void AlertWindow::buttonClicked (Button* button)
{
if (button->getParentComponent() != nullptr)
button->getParentComponent()->exitModalState (button->getCommandID());
if (Component* parent = button->getParentComponent())
parent->exitModalState (button->getCommandID());
}
//==============================================================================
@@ -163,8 +163,10 @@ TextEditor* AlertWindow::getTextEditor (const String& nameOfTextEditor) const
String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
{
TextEditor* const t = getTextEditor (nameOfTextEditor);
return t != nullptr ? t->getText() : String::empty;
if (TextEditor* const t = getTextEditor (nameOfTextEditor))
return t->getText();
return String::empty;
}
@@ -562,12 +564,12 @@ int AlertWindow::getDesktopWindowStyleFlags() const
class AlertWindowInfo
{
public:
AlertWindowInfo (const String& title_, const String& message_, Component* component,
AlertWindow::AlertIconType iconType_, int numButtons_,
ModalComponentManager::Callback* callback_, bool modal_)
: title (title_), message (message_), iconType (iconType_),
numButtons (numButtons_), returnValue (0), associatedComponent (component),
callback (callback_), modal (modal_)
AlertWindowInfo (const String& t, const String& m, Component* component,
AlertWindow::AlertIconType icon, int numButts,
ModalComponentManager::Callback* cb, bool runModally)
: title (t), message (m), iconType (icon), numButtons (numButts),
returnValue (0), associatedComponent (component),
callback (cb), modal (runModally)
{
}
@@ -641,15 +643,16 @@ void AlertWindow::showMessageBoxAsync (AlertIconType iconType,
const String& title,
const String& message,
const String& buttonText,
Component* associatedComponent)
Component* associatedComponent,
ModalComponentManager::Callback* callback)
{
if (LookAndFeel::getDefaultLookAndFeel().isUsingNativeAlertWindows())
{
return NativeMessageBox::showMessageBoxAsync (iconType, title, message, associatedComponent);
NativeMessageBox::showMessageBoxAsync (iconType, title, message, associatedComponent);
}
else
{
AlertWindowInfo info (title, message, associatedComponent, iconType, 1, 0, false);
AlertWindowInfo info (title, message, associatedComponent, iconType, 1, callback, false);
info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
info.invoke();
@@ -665,17 +668,13 @@ bool AlertWindow::showOkCancelBox (AlertIconType iconType,
ModalComponentManager::Callback* callback)
{
if (LookAndFeel::getDefaultLookAndFeel().isUsingNativeAlertWindows())
{
return NativeMessageBox::showOkCancelBox (iconType, title, message, associatedComponent, callback);
}
else
{
AlertWindowInfo info (title, message, associatedComponent, iconType, 2, callback, callback == nullptr);
info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
return info.invoke() != 0;
}
AlertWindowInfo info (title, message, associatedComponent, iconType, 2, callback, callback == nullptr);
info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
return info.invoke() != 0;
}
int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
@@ -688,18 +687,14 @@ int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
ModalComponentManager::Callback* callback)
{
if (LookAndFeel::getDefaultLookAndFeel().isUsingNativeAlertWindows())
{
return NativeMessageBox::showYesNoCancelBox (iconType, title, message, associatedComponent, callback);
}
else
{
AlertWindowInfo info (title, message, associatedComponent, iconType, 3, callback, callback == nullptr);
info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
return info.invoke();
}
AlertWindowInfo info (title, message, associatedComponent, iconType, 3, callback, callback == nullptr);
info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
return info.invoke();
}
#if JUCE_MODAL_LOOPS_PERMITTED
@@ -708,13 +703,9 @@ bool AlertWindow::showNativeDialogBox (const String& title,
bool isOkCancel)
{
if (isOkCancel)
{
return NativeMessageBox::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
}
else
{
NativeMessageBox::showMessageBox (AlertWindow::NoIcon, title, bodyText);
return true;
}
NativeMessageBox::showMessageBox (AlertWindow::NoIcon, title, bodyText);
return true;
}
#endif

+ 14
- 12
modules/juce_gui_basics/windows/juce_AlertWindow.h View File

@@ -237,13 +237,11 @@ public:
//==============================================================================
// easy-to-use message box functions:
#if JUCE_MODAL_LOOPS_PERMITTED
/** 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.
The box is shown modally, and the method will block until the user has clicked the
button (or pressed the escape or return keys).
@param iconType the type of icon to show
@param title the headline to show at the top of the box
@@ -255,7 +253,6 @@ public:
alert window should be associated with. Depending on the look
and feel, this might be used for positioning of the alert window.
*/
#if JUCE_MODAL_LOOPS_PERMITTED
static void JUCE_CALLTYPE showMessageBox (AlertIconType iconType,
const String& title,
const String& message,
@@ -265,11 +262,9 @@ public:
/** 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.
The box will be displayed and placed into a modal state, but this method will
return immediately, and if a callback was supplied, it will be invoked later
when the user dismisses the box.
@param iconType the type of icon to show
@param title the headline to show at the top of the box
@@ -280,12 +275,19 @@ public:
@param 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.
@param callback if this is non-null, 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 void JUCE_CALLTYPE showMessageBoxAsync (AlertIconType iconType,
const String& title,
const String& message,
const String& buttonText = String::empty,
Component* associatedComponent = nullptr);
Component* associatedComponent = nullptr,
ModalComponentManager::Callback* callback = nullptr);
/** Shows a dialog box with two buttons.


Loading…
Cancel
Save