gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

commit 42f7fe5f79b6b28da28b55750fa5ac476b149f3a
parent 9150f906218ac176dba626ddeeb65d18e475fe08
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Sat,  8 Feb 2025 15:44:27 +0100

wrap juce native message box calls - use async versions to be able to get rid of modal loops permitted compiler flag

Diffstat:
Msource/juceUiLib/CMakeLists.txt | 1+
Asource/juceUiLib/messageBox.cpp | 48++++++++++++++++++++++++++++++++++++++++++++++++
Asource/juceUiLib/messageBox.h | 34++++++++++++++++++++++++++++++++++
3 files changed, 83 insertions(+), 0 deletions(-)

diff --git a/source/juceUiLib/CMakeLists.txt b/source/juceUiLib/CMakeLists.txt @@ -13,6 +13,7 @@ set(SOURCES comboboxStyle.cpp comboboxStyle.h buttonStyle.cpp buttonStyle.h labelStyle.cpp labelStyle.h + messageBox.cpp messageBox.h scrollbarStyle.cpp scrollbarStyle.h slider.cpp slider.h textbuttonStyle.cpp textbuttonStyle.h diff --git a/source/juceUiLib/messageBox.cpp b/source/juceUiLib/messageBox.cpp @@ -0,0 +1,48 @@ +#include "messageBox.h" + +#include <memory> + +#include "juce_gui_basics/juce_gui_basics.h" + +namespace genericUI +{ + namespace + { + juce::ModalComponentManager::Callback* addCallback(MessageBox::Callback _callback) + { + return juce::ModalCallbackFunction::create([callback = std::move(_callback)](const int _result) + { + callback(_result == 1 ? MessageBox::Result::Yes : MessageBox::Result::No); + }); + } + } + + void MessageBox::showYesNo(const juce::MessageBoxIconType _icon, const std::string& _header, const std::string& _message, Callback _callback) + { + juce::NativeMessageBox::showYesNoBox(_icon, _header.c_str(), _message.c_str(), nullptr, addCallback(std::move(_callback))); + } + + void MessageBox::showOkCancel(const juce::MessageBoxIconType _icon, const std::string& _header, const std::string& _message, Callback _callback) + { + juce::NativeMessageBox::showOkCancelBox(_icon, _header.c_str(), _message.c_str(), nullptr, addCallback(std::move(_callback))); + } + + void MessageBox::showOk(const juce::MessageBoxIconType _icon, const std::string& _header, const std::string& _message) + { + juce::NativeMessageBox::showMessageBoxAsync(_icon, _header.c_str(), _message.c_str()); + } + + void MessageBox::showOk(juce::MessageBoxIconType _icon, const std::string& _header, const std::string& _message, juce::Component* _owner, std::function<void()> _callback) + { + juce::NativeMessageBox::showMessageBoxAsync(_icon, _header.c_str(), _message.c_str(), _owner, + juce::ModalCallbackFunction::create([_callback = std::move(_callback)](int) + { + _callback(); + })); + } + + void MessageBox::showOk(juce::MessageBoxIconType _icon, const std::string& _header, const std::string& _message, std::function<void()> _callback) + { + return showOk(_icon, _header, _message, nullptr, std::move(_callback)); + } +} diff --git a/source/juceUiLib/messageBox.h b/source/juceUiLib/messageBox.h @@ -0,0 +1,34 @@ +#pragma once + +#include <functional> +#include <string> +#include <cstdint> + +namespace juce +{ + class Component; + enum class MessageBoxIconType; +} + +namespace genericUI +{ + class MessageBox + { + public: + enum class Result : uint8_t + { + Yes = 0, + No = 1, + Ok = Yes, + Cancel = No + }; + + using Callback = std::function<void(Result)>; + + static void showYesNo(juce::MessageBoxIconType _icon, const std::string& _header, const std::string& _message, Callback _callback); + static void showOkCancel(juce::MessageBoxIconType _icon, const std::string& _header, const std::string& _message, Callback _callback); + static void showOk(juce::MessageBoxIconType _icon, const std::string& _header, const std::string& _message); + static void showOk(juce::MessageBoxIconType _icon, const std::string& _header, const std::string& _message, juce::Component* _owner, std::function<void()> _callback); + static void showOk(juce::MessageBoxIconType _icon, const std::string& _header, const std::string& _message, std::function<void()> _callback); + }; +}