The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
7.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. template <ScopedMessageBox::Pimpl::MapFn mapFn = nullptr>
  21. static int showNativeBoxUnmanaged (const MessageBoxOptions& opts, ModalComponentManager::Callback* cb)
  22. {
  23. return ScopedMessageBox::Pimpl::showUnmanaged<mapFn> (ScopedMessageBoxInterface::create (opts), cb);
  24. }
  25. #if JUCE_MODAL_LOOPS_PERMITTED
  26. void JUCE_CALLTYPE NativeMessageBox::showMessageBox (MessageBoxIconType iconType,
  27. const String& title, const String& message,
  28. Component* associatedComponent)
  29. {
  30. showNativeBoxUnmanaged<ScopedMessageBox::Pimpl::messageBox> (MessageBoxOptions().withIconType (iconType)
  31. .withTitle (title)
  32. .withMessage (message)
  33. .withButton (TRANS("OK"))
  34. .withAssociatedComponent (associatedComponent),
  35. nullptr);
  36. }
  37. int JUCE_CALLTYPE NativeMessageBox::show (const MessageBoxOptions& options)
  38. {
  39. return showNativeBoxUnmanaged<> (options, nullptr);
  40. }
  41. #endif
  42. void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (MessageBoxIconType iconType,
  43. const String& title, const String& message,
  44. Component* associatedComponent,
  45. ModalComponentManager::Callback* callback)
  46. {
  47. showNativeBoxUnmanaged<ScopedMessageBox::Pimpl::messageBox> (MessageBoxOptions().withIconType (iconType)
  48. .withTitle (title)
  49. .withMessage (message)
  50. .withButton (TRANS("OK"))
  51. .withAssociatedComponent (associatedComponent),
  52. callback);
  53. }
  54. bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (MessageBoxIconType iconType,
  55. const String& title, const String& message,
  56. Component* associatedComponent,
  57. ModalComponentManager::Callback* callback)
  58. {
  59. return showNativeBoxUnmanaged<ScopedMessageBox::Pimpl::okCancel> (MessageBoxOptions().withIconType (iconType)
  60. .withTitle (title)
  61. .withMessage (message)
  62. .withButton (TRANS("OK"))
  63. .withButton (TRANS("Cancel"))
  64. .withAssociatedComponent (associatedComponent),
  65. callback) != 0;
  66. }
  67. int JUCE_CALLTYPE NativeMessageBox::showYesNoCancelBox (MessageBoxIconType iconType,
  68. const String& title, const String& message,
  69. Component* associatedComponent,
  70. ModalComponentManager::Callback* callback)
  71. {
  72. return showNativeBoxUnmanaged<ScopedMessageBox::Pimpl::yesNoCancel> (MessageBoxOptions().withIconType (iconType)
  73. .withTitle (title)
  74. .withMessage (message)
  75. .withButton (TRANS("Yes"))
  76. .withButton (TRANS("No"))
  77. .withButton (TRANS("Cancel"))
  78. .withAssociatedComponent (associatedComponent),
  79. callback);
  80. }
  81. int JUCE_CALLTYPE NativeMessageBox::showYesNoBox (MessageBoxIconType iconType,
  82. const String& title, const String& message,
  83. Component* associatedComponent,
  84. ModalComponentManager::Callback* callback)
  85. {
  86. return showNativeBoxUnmanaged<ScopedMessageBox::Pimpl::okCancel> (MessageBoxOptions().withIconType (iconType)
  87. .withTitle (title)
  88. .withMessage (message)
  89. .withButton (TRANS("Yes"))
  90. .withButton (TRANS("No"))
  91. .withAssociatedComponent (associatedComponent),
  92. callback);
  93. }
  94. void JUCE_CALLTYPE NativeMessageBox::showAsync (const MessageBoxOptions& options,
  95. ModalComponentManager::Callback* callback)
  96. {
  97. showNativeBoxUnmanaged<> (options, callback);
  98. }
  99. void JUCE_CALLTYPE NativeMessageBox::showAsync (const MessageBoxOptions& options,
  100. std::function<void (int)> callback)
  101. {
  102. showAsync (options, ModalCallbackFunction::create (callback));
  103. }
  104. ScopedMessageBox NativeMessageBox::showScopedAsync (const MessageBoxOptions& options, std::function<void (int)> callback)
  105. {
  106. return ScopedMessageBox::Pimpl::show (ScopedMessageBoxInterface::create (options), std::move (callback));
  107. }
  108. } // namespace juce