diff --git a/modules/juce_gui_basics/native/juce_linux_NativeMessageBox.cpp b/modules/juce_gui_basics/native/juce_linux_NativeMessageBox.cpp index 17ff64db2e..c3a27fb16f 100644 --- a/modules/juce_gui_basics/native/juce_linux_NativeMessageBox.cpp +++ b/modules/juce_gui_basics/native/juce_linux_NativeMessageBox.cpp @@ -28,7 +28,42 @@ namespace juce std::unique_ptr ScopedMessageBoxInterface::create (const MessageBoxOptions& options) { - return createAlertWindowImpl (options); + // On Linux, we re-use the AlertWindow rather than using a platform-specific dialog. + // For consistency with the NativeMessageBox on other platforms, the result code must + // match the button index, hence this adapter. + class MessageBox : public ScopedMessageBoxInterface + { + public: + explicit MessageBox (const MessageBoxOptions& options) + : inner (createAlertWindowImpl (options)), + numButtons (options.getNumButtons()) {} + + void runAsync (std::function fn) override + { + inner->runAsync ([fn, n = numButtons] (int result) + { + fn (map (result, n)); + }); + } + + int runSync() override + { + return map (inner->runSync(), numButtons); + } + + void close() override + { + inner->close(); + } + + private: + static int map (int button, int numButtons) { return (button + numButtons - 1) % numButtons; } + + std::unique_ptr inner; + int numButtons = 0; + }; + + return std::make_unique (options); } } // namespace juce