1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Reverted commit 8483aa4 as the same functionality already existed in JUCE with ModalCallbackFunction. Improved the documentation in NativeMessageBox to mention that class.

This commit is contained in:
hogliux 2017-09-13 11:14:10 +01:00
parent 8b3ab7c152
commit 1291f1a06b
2 changed files with 20 additions and 69 deletions

View file

@ -725,35 +725,4 @@ bool AlertWindow::showNativeDialogBox (const String& title,
}
#endif
//==============================================================================
struct NativeMessageBoxCallback : ModalComponentManager::Callback
{
NativeMessageBoxCallback (std::function<void (int)> && lambda)
: callback (static_cast<std::function<void (int)>&&> (lambda))
{}
void modalStateFinished (int returnValue) override { if (callback) callback (returnValue); }
std::function<void (int)> callback;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeMessageBoxCallback)
};
void NativeMessageBox::showMessageBox (MessageBoxType dialogType, AlertWindow::AlertIconType iconType,
const String& title, const String& message,
std::function<void (int)> && lambda, Component* associatedComponent)
{
auto* callback = new NativeMessageBoxCallback (static_cast<std::function<void (int)>&&> (lambda));
switch (dialogType)
{
case okType: showMessageBoxAsync (iconType, title, message, associatedComponent, callback); break;
case okCancelType: showOkCancelBox (iconType, title, message, associatedComponent, callback); break;
case yesNoType: showYesNoBox (iconType, title, message, associatedComponent, callback); break;
case yesNoCancelType: showYesNoCancelBox (iconType, title, message, associatedComponent, callback); break;
default:
jassertfalse;
}
}
} // namespace juce

View file

@ -34,15 +34,6 @@ namespace juce
class NativeMessageBox
{
public:
/** A set of enums describing the type of dialog box */
enum MessageBoxType
{
okType, /** A message box with a simple ok button. */
okCancelType, /** A message box with an ok and cancel button. */
yesNoType, /** A message box with a yes and no button. */
yesNoCancelType, /** A message box with a yes, no and cancel button. */
};
/** Shows a dialog box that just has a message and a single 'ok' button to close it.
The box is shown modally, and the method will block until the user has clicked its
@ -62,27 +53,6 @@ public:
Component* associatedComponent = nullptr);
#endif
/** Shows a dialog box asynchronously triggering a lambda when the user dismisses the box.
The box will be displayed and placed into a modal state, but this method will return
immediately, and the lambda will be invoked later when the user dismisses the box.
@param dialogType the type of the dialog
@param iconType the type of icon to show
@param title the headline to show at the top of the box
@param message a longer, more descriptive message to show underneath the title
@param lambda a lambda which will be triggered when the box is dismissed
@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.
*/
static void JUCE_CALLTYPE showMessageBox (MessageBoxType dialogType,
AlertWindow::AlertIconType iconType,
const String& title,
const String& message,
std::function<void (int)> && lambda = {},
Component* associatedComponent = nullptr);
/** Shows a dialog box that just has a message and a single 'ok' button to close it.
The box will be displayed and placed into a modal state, but this method will return
@ -98,13 +68,16 @@ public:
modalStateFinished() when the box is dismissed. 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.
before it gets called. You can use the ModalCallbackFunction to easily
pass in a lambda for this parameter.
@see ModalCallbackFunction
*/
static void JUCE_CALLTYPE showMessageBoxAsync (AlertWindow::AlertIconType iconType,
const String& title,
const String& message,
Component* associatedComponent = nullptr,
ModalComponentManager::Callback* callback = nullptr);
const String& title,
const String& message,
Component* associatedComponent = nullptr,
ModalComponentManager::Callback* callback = nullptr);
/** Shows a dialog box with two buttons.
@ -129,10 +102,13 @@ public:
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.
before it gets called. You can use the ModalCallbackFunction to easily
pass in a lambda for this parameter.
@returns true if button 1 was clicked, false if it was button 2. If the callback parameter
is not null, the method always returns false, and the user's choice is delivered
later by the callback.
@see ModalCallbackFunction
*/
static bool JUCE_CALLTYPE showOkCancelBox (AlertWindow::AlertIconType iconType,
const String& title,
@ -169,13 +145,16 @@ public:
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.
to objects that might be deleted before it gets called. You can use the
ModalCallbackFunction to easily pass in a lambda for this parameter.
@returns If the callback parameter has been set, this returns 0. Otherwise, it returns one
of the following values:
- 0 if 'cancel' was pressed
- 1 if 'yes' was pressed
- 2 if 'no' was pressed
@see ModalCallbackFunction
*/
static int JUCE_CALLTYPE showYesNoCancelBox (AlertWindow::AlertIconType iconType,
const String& title,
@ -212,12 +191,15 @@ public:
being 1 if the "yes" button was pressed or 0 for the "no" button was
pressed. 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.
to objects that might be deleted before it gets called. You can use the
ModalCallbackFunction to easily pass in a lambda for this parameter.
@returns If the callback parameter has been set, this returns 0. Otherwise, it returns one
of the following values:
- 0 if 'no' was pressed
- 1 if 'yes' was pressed
@see ModalCallbackFunction
*/
static int JUCE_CALLTYPE showYesNoBox (AlertWindow::AlertIconType iconType,
const String& title,