Wrong callback value for AlertWindow::showOkCancelBox

Hi,

the showOkCancelBox calls its callback with the wrong result value when executed as a native messagebox on iOS (‘OK’ triggers a callback(0) and ‘Cancel’ triggers a callback(1)).

Paste the following code in the JUCE DialogsDemo.h in place of yesNoCancelAlertWindow demo to reproduce. Toggle the ‘Use native windows’ checkbox to observe that the result changes.

AlertWindow::showOkCancelBox(AlertWindow::WarningIcon,
                                                    "Hello", "Is it ok",
                                                    "OK", "Cancel", this,  ModalCallbackFunction::create([](int result){ std::cerr << " result=" << result << "\n"; }));

I think I’ve seen this recently…

Yes, as mentioned in that other thread, this seems to be due to a difference in the UI standards of Windows vs Mac, and the fact that JUCE follows the the Windows standard. (Windows puts the affirmative/default option on the left, whereas Mac puts it on the right.)

One solution would be for the NativeMessageBox methods to return a more explicit value than an integer, like an enum class with enumerated values for “OK”, “Cancel”, “Yes”, and “No”. Currently they return “the index of the button that was clicked”, but as we have seen, that makes the meaning of the result dependent on the order of the buttons!

Thanks for reporting, that should be fixed here:

3 Likes