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

NativeAlertWindow callback implementations.

This commit is contained in:
jules 2013-03-06 20:56:33 +00:00
parent 22b98217d8
commit 7969ec3611
8 changed files with 66 additions and 59 deletions

View file

@ -51,15 +51,13 @@ JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, launchApp, void, (JNIEnv* en
JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, suspendApp, void, (JNIEnv* env, jobject activity))
{
JUCEApplicationBase* const app = JUCEApplicationBase::getInstance();
if (app != nullptr)
if (JUCEApplicationBase* const app = JUCEApplicationBase::getInstance())
app->suspended();
}
JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, resumeApp, void, (JNIEnv* env, jobject activity))
{
JUCEApplicationBase* const app = JUCEApplicationBase::getInstance();
if (app != nullptr)
if (JUCEApplicationBase* const app = JUCEApplicationBase::getInstance())
app->resumed();
}
@ -415,9 +413,7 @@ public:
buffer = GlobalRef (env->NewIntArray (sizeNeeded));
}
jint* dest = env->GetIntArrayElements ((jintArray) buffer.get(), 0);
if (dest != nullptr)
if (jint* dest = env->GetIntArrayElements ((jintArray) buffer.get(), 0))
{
{
Image temp (new PreallocatedImage (clip.getWidth(), clip.getHeight(),
@ -646,9 +642,11 @@ void Process::makeForegroundProcess()
//==============================================================================
void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (AlertWindow::AlertIconType iconType,
const String& title, const String& message,
Component* associatedComponent)
Component* associatedComponent,
ModalComponentManager::Callback* callback)
{
android.activity.callVoidMethod (JuceAppActivity.showMessageBox, javaString (title).get(), javaString (message).get(), (jlong) 0);
android.activity.callVoidMethod (JuceAppActivity.showMessageBox, javaString (title).get(),
javaString (message).get(), (jlong) (pointer_sized_int) callback);
}
bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (AlertWindow::AlertIconType iconType,
@ -656,10 +654,10 @@ bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (AlertWindow::AlertIconType
Component* associatedComponent,
ModalComponentManager::Callback* callback)
{
jassert (callback != 0); // on android, all alerts must be non-modal!!
jassert (callback != nullptr); // on android, all alerts must be non-modal!!
android.activity.callVoidMethod (JuceAppActivity.showOkCancelBox, javaString (title).get(), javaString (message).get(),
(jlong) (pointer_sized_int) callback);
android.activity.callVoidMethod (JuceAppActivity.showOkCancelBox, javaString (title).get(),
javaString (message).get(), (jlong) (pointer_sized_int) callback);
return false;
}
@ -668,19 +666,17 @@ int JUCE_CALLTYPE NativeMessageBox::showYesNoCancelBox (AlertWindow::AlertIconTy
Component* associatedComponent,
ModalComponentManager::Callback* callback)
{
jassert (callback != 0); // on android, all alerts must be non-modal!!
jassert (callback != nullptr); // on android, all alerts must be non-modal!!
android.activity.callVoidMethod (JuceAppActivity.showYesNoCancelBox, javaString (title).get(), javaString (message).get(),
(jlong) (pointer_sized_int) callback);
android.activity.callVoidMethod (JuceAppActivity.showYesNoCancelBox, javaString (title).get(),
javaString (message).get(), (jlong) (pointer_sized_int) callback);
return 0;
}
JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, alertDismissed, void, (JNIEnv* env, jobject activity,
jlong callbackAsLong, jint result))
{
ModalComponentManager::Callback* callback = (ModalComponentManager::Callback*) callbackAsLong;
if (callback != 0)
if (ModalComponentManager::Callback* callback = (ModalComponentManager::Callback*) callbackAsLong)
callback->modalStateFinished (result);
}

View file

@ -106,9 +106,9 @@ class iOSMessageBox
public:
iOSMessageBox (const String& title, const String& message,
NSString* button1, NSString* button2, NSString* button3,
ModalComponentManager::Callback* callback_, const bool isAsync_)
ModalComponentManager::Callback* cb, const bool async)
: result (0), delegate (nil), alert (nil),
callback (callback_), isYesNo (button3 != nil), isAsync (isAsync_)
callback (cb), isYesNo (button3 != nil), isAsync (async)
{
delegate = [[JuceAlertBoxDelegate alloc] init];
delegate->owner = this;
@ -181,16 +181,16 @@ void JUCE_CALLTYPE NativeMessageBox::showMessageBox (AlertWindow::AlertIconType
Component* associatedComponent)
{
JUCE_AUTORELEASEPOOL
iOSMessageBox mb (title, message, @"OK", nil, nil, 0, false);
iOSMessageBox mb (title, message, @"OK", nil, nil, nullptr, false);
(void) mb.getResult();
}
void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (AlertWindow::AlertIconType iconType,
const String& title, const String& message,
Component* associatedComponent)
Component* associatedComponent,
ModalComponentManager::Callback* callback)
{
JUCE_AUTORELEASEPOOL
new iOSMessageBox (title, message, @"OK", nil, nil, 0, true);
new iOSMessageBox (title, message, @"OK", nil, nil, callback, true);
}
bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (AlertWindow::AlertIconType iconType,
@ -198,7 +198,8 @@ bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (AlertWindow::AlertIconType
Component* associatedComponent,
ModalComponentManager::Callback* callback)
{
ScopedPointer<iOSMessageBox> mb (new iOSMessageBox (title, message, @"Cancel", @"OK", nil, callback, callback != nullptr));
ScopedPointer<iOSMessageBox> mb (new iOSMessageBox (title, message, @"Cancel", @"OK",
nil, callback, callback != nullptr));
if (callback == nullptr)
return mb->getResult() == 1;

View file

@ -3386,9 +3386,10 @@ void JUCE_CALLTYPE NativeMessageBox::showMessageBox (AlertWindow::AlertIconType
void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (AlertWindow::AlertIconType iconType,
const String& title, const String& message,
Component* /* associatedComponent */)
Component* associatedComponent,
ModalComponentManager::Callback* callback)
{
AlertWindow::showMessageBoxAsync (iconType, title, message);
AlertWindow::showMessageBoxAsync (iconType, title, message, String::empty, associatedComponent, callback);
}
bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (AlertWindow::AlertIconType iconType,

View file

@ -32,13 +32,10 @@ void LookAndFeel::playAlertSound()
class OSXMessageBox : private AsyncUpdater
{
public:
OSXMessageBox (AlertWindow::AlertIconType type,
const String& title_, const String& message_,
OSXMessageBox (AlertWindow::AlertIconType type, const String& t, const String& m,
const char* b1, const char* b2, const char* b3,
ModalComponentManager::Callback* callback_,
const bool runAsync)
: iconType (type), title (title_),
message (message_), callback (callback_),
ModalComponentManager::Callback* c, const bool runAsync)
: iconType (type), title (t), message (m), callback (c),
button1 (b1), button2 (b2), button3 (b3)
{
if (runAsync)
@ -47,17 +44,21 @@ public:
int getResult() const
{
JUCE_AUTORELEASEPOOL
NSInteger r = getRawResult();
return r == NSAlertDefaultReturn ? 1 : (r == NSAlertOtherReturn ? 2 : 0);
switch (getRawResult())
{
case NSAlertDefaultReturn: return 1;
case NSAlertOtherReturn: return 2;
default: return 0;
}
}
static int show (AlertWindow::AlertIconType iconType, const String& title, const String& message,
ModalComponentManager::Callback* callback, const char* b1, const char* b2, const char* b3)
ModalComponentManager::Callback* callback, const char* b1, const char* b2, const char* b3,
bool runAsync)
{
ScopedPointer<OSXMessageBox> mb (new OSXMessageBox (iconType, title, message, b1, b2, b3,
callback, callback != nullptr));
if (callback == nullptr)
callback, runAsync));
if (! runAsync)
return mb->getResult();
mb.release();
@ -109,15 +110,15 @@ void JUCE_CALLTYPE NativeMessageBox::showMessageBox (AlertWindow::AlertIconType
const String& title, const String& message,
Component* /*associatedComponent*/)
{
OSXMessageBox box (iconType, title, message, "OK", nullptr, nullptr, nullptr, false);
(void) box.getResult();
OSXMessageBox::show (iconType, title, message, nullptr, "OK", nullptr, nullptr, false);
}
void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (AlertWindow::AlertIconType iconType,
const String& title, const String& message,
Component* /*associatedComponent*/)
Component* /*associatedComponent*/,
ModalComponentManager::Callback* callback)
{
new OSXMessageBox (iconType, title, message, "OK", nullptr, nullptr, nullptr, true);
OSXMessageBox::show (iconType, title, message, callback, "OK", nullptr, nullptr, true);
}
bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (AlertWindow::AlertIconType iconType,
@ -125,7 +126,8 @@ bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (AlertWindow::AlertIconType
Component* /*associatedComponent*/,
ModalComponentManager::Callback* callback)
{
return OSXMessageBox::show (iconType, title, message, callback, "OK", "Cancel", nullptr) == 1;
return OSXMessageBox::show (iconType, title, message, callback,
"OK", "Cancel", nullptr, callback != nullptr) == 1;
}
int JUCE_CALLTYPE NativeMessageBox::showYesNoCancelBox (AlertWindow::AlertIconType iconType,
@ -133,7 +135,8 @@ int JUCE_CALLTYPE NativeMessageBox::showYesNoCancelBox (AlertWindow::AlertIconTy
Component* /*associatedComponent*/,
ModalComponentManager::Callback* callback)
{
return OSXMessageBox::show (iconType, title, message, callback, "Yes", "Cancel", "No");
return OSXMessageBox::show (iconType, title, message, callback,
"Yes", "Cancel", "No", callback != nullptr);
}

View file

@ -2891,9 +2891,10 @@ void JUCE_CALLTYPE NativeMessageBox::showMessageBox (AlertWindow::AlertIconType
void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (AlertWindow::AlertIconType iconType,
const String& title, const String& message,
Component* associatedComponent)
Component* associatedComponent,
ModalComponentManager::Callback* callback)
{
new WindowsMessageBox (iconType, title, message, associatedComponent, MB_OK, 0, true);
new WindowsMessageBox (iconType, title, message, associatedComponent, MB_OK, callback, true);
}
bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (AlertWindow::AlertIconType iconType,

View file

@ -631,7 +631,7 @@ void AlertWindow::showMessageBox (AlertIconType iconType,
}
else
{
AlertWindowInfo info (title, message, associatedComponent, iconType, 1, 0, true);
AlertWindowInfo info (title, message, associatedComponent, iconType, 1, nullptr, true);
info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
info.invoke();
@ -648,7 +648,7 @@ void AlertWindow::showMessageBoxAsync (AlertIconType iconType,
{
if (LookAndFeel::getDefaultLookAndFeel().isUsingNativeAlertWindows())
{
NativeMessageBox::showMessageBoxAsync (iconType, title, message, associatedComponent);
NativeMessageBox::showMessageBoxAsync (iconType, title, message, associatedComponent, callback);
}
else
{

View file

@ -248,7 +248,7 @@ public:
@param message a longer, more descriptive message to show underneath the
headline
@param buttonText the text to show in the button - if this string is empty, the
default string "ok" (or a localised version) will be used.
default string "OK" (or a localised version) will be used.
@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.
@ -271,13 +271,12 @@ public:
@param message a longer, more descriptive message to show underneath the
headline
@param buttonText the text to show in the button - if this string is empty, the
default string "ok" (or a localised version) will be used.
default string "OK" (or a localised version) will be used.
@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
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.
@ -305,7 +304,7 @@ public:
@param message a longer, more descriptive message to show underneath the
headline
@param button1Text the text to show in the first button - if this string is
empty, the default string "ok" (or a localised version of it)
empty, the default string "OK" (or a localised version of it)
will be used.
@param button2Text the text to show in the second button - if this string is
empty, the default string "cancel" (or a localised version of it)
@ -316,7 +315,7 @@ public:
@param 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
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.
@ -368,7 +367,7 @@ public:
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
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.

View file

@ -62,11 +62,17 @@ 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. 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 (AlertWindow::AlertIconType iconType,
const String& title,
const String& message,
Component* associatedComponent = nullptr);
const String& title,
const String& message,
Component* associatedComponent = nullptr,
ModalComponentManager::Callback* callback = nullptr);
/** Shows a dialog box with two buttons.