1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-13 00:04:19 +00:00

NativeMessageBox: Fix result codes on Linux

This commit is contained in:
reuk 2023-02-25 20:51:47 +00:00
parent d073a7e8ca
commit edca5e9629
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -28,7 +28,42 @@ namespace juce
std::unique_ptr<ScopedMessageBoxInterface> 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<void (int)> 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<ScopedMessageBoxInterface> inner;
int numButtons = 0;
};
return std::make_unique<MessageBox> (options);
}
} // namespace juce