Browse Source

NativeMessageBox: Fix result codes on Linux

v7.0.9
reuk 2 years ago
parent
commit
edca5e9629
No known key found for this signature in database GPG Key ID: FCB43929F012EE5C
1 changed files with 36 additions and 1 deletions
  1. +36
    -1
      modules/juce_gui_basics/native/juce_linux_NativeMessageBox.cpp

+ 36
- 1
modules/juce_gui_basics/native/juce_linux_NativeMessageBox.cpp 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

Loading…
Cancel
Save