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:
parent
d073a7e8ca
commit
edca5e9629
1 changed files with 36 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue