JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_AlertWindowHelpers.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce::detail
27{
28
30{
31 AlertWindowHelpers() = delete;
32
34 {
36 {
37 public:
38 explicit AlertWindowImpl (const MessageBoxOptions& opts) : options (opts) {}
39
40 void runAsync (std::function<void (int)> recipient) override
41 {
42 if (auto* comp = setUpAlert())
43 comp->enterModalState (true, ModalCallbackFunction::create (std::move (recipient)), true);
44 else
45 NullCheckedInvocation::invoke (recipient, 0);
46 }
47
48 int runSync() override
49 {
50 #if JUCE_MODAL_LOOPS_PERMITTED
51 if (auto comp = rawToUniquePtr (setUpAlert()))
52 return comp->runModalLoop();
53 #endif
54
56 return 0;
57 }
58
59 void close() override
60 {
61 if (alert != nullptr)
62 if (alert->isCurrentlyModal())
63 alert->exitModalState();
64
65 alert = nullptr;
66 }
67
68 private:
69 Component* setUpAlert()
70 {
71 auto* component = options.getAssociatedComponent();
72
73 auto& lf = component != nullptr ? component->getLookAndFeel()
74 : LookAndFeel::getDefaultLookAndFeel();
75
76 alert = lf.createAlertWindow (options.getTitle(),
77 options.getMessage(),
78 options.getButtonText (0),
79 options.getButtonText (1),
80 options.getButtonText (2),
81 options.getIconType(),
82 options.getNumButtons(),
83 component);
84
85 if (alert == nullptr)
86 {
87 // You have to return an alert box!
89 return nullptr;
90 }
91
92 if (auto* parent = options.getParentComponent())
93 {
94 parent->addAndMakeVisible (alert);
95
96 if (options.getAssociatedComponent() == nullptr)
97 alert->setCentrePosition (parent->getLocalBounds().getCentre());
98 }
99
100 alert->setAlwaysOnTop (WindowUtils::areThereAnyAlwaysOnTopWindows());
101
102 return alert;
103 }
104
105 const MessageBoxOptions options;
107
109 };
110
111 return std::make_unique<AlertWindowImpl> (opts);
112 }
113};
114
115} // namespace juce::detail
Holds a pointer to some type of Component, which automatically becomes null if the component is delet...
The base class for all JUCE user-interface objects.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
Class used to create a set of options to pass to the AlertWindow and NativeMessageBox methods for sho...
close
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
#define jassertfalse
This will always cause an assertion failure.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
std::unique_ptr< T > rawToUniquePtr(T *ptr)
Converts an owning raw pointer into a unique_ptr, deriving the type of the unique_ptr automatically.