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_ScopedMessageBoxImpl.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
29//==============================================================================
31{
32public:
33 virtual ~ScopedMessageBoxImpl() = default;
34 virtual void close() = 0;
35};
36
37//==============================================================================
39 private AsyncUpdater
40{
41public:
43 std::function<void (int)> callback)
44 {
45 return ScopedMessageBox (runAsync (std::move (native),
46 rawToUniquePtr (ModalCallbackFunction::create (std::move (callback)))));
47 }
48
49 static int showUnmanaged (std::unique_ptr<ScopedMessageBoxInterface>&& native,
51 {
52 #if JUCE_MODAL_LOOPS_PERMITTED
53 if (cb == nullptr)
54 return runSync (std::move (native));
55 #endif
56
57 runAsync (std::move (native), rawToUniquePtr (cb));
58
59 return 0;
60 }
61
63 {
65 }
66
67 void close() override
68 {
70 nativeImplementation->close();
71 self.reset();
72 }
73
74private:
77 {
78 std::shared_ptr<ConcreteScopedMessageBoxImpl> result (new ConcreteScopedMessageBoxImpl (std::move (p), std::move (c)));
79 result->self = result;
80 result->triggerAsyncUpdate();
81 return result;
82 }
83
84 static int runSync (std::unique_ptr<ScopedMessageBoxInterface>&& p)
85 {
86 auto local = std::move (p);
87 return local != nullptr ? local->runSync() : 0;
88 }
89
91 : ConcreteScopedMessageBoxImpl (std::move (p), nullptr) {}
92
95 : callback (std::move (c)), nativeImplementation (std::move (p)) {}
96
97 void handleAsyncUpdate() override
98 {
99 nativeImplementation->runAsync ([weakRecipient = std::weak_ptr<ConcreteScopedMessageBoxImpl> (self)] (int result)
100 {
101 const auto notifyRecipient = [result, weakRecipient]
102 {
103 if (const auto locked = weakRecipient.lock())
104 {
105 if (auto* cb = locked->callback.get())
106 cb->modalStateFinished (result);
107
108 locked->self.reset();
109 }
110 };
111
112 if (MessageManager::getInstance()->isThisTheMessageThread())
114 else
116 });
117 }
118
121
122 /* The 'old' native message box API doesn't have a concept of message box owners.
123 Instead, message boxes have to clean up after themselves, once they're done displaying.
124 To allow this mode of usage, the implementation keeps an owning reference to itself,
125 which is cleared once the message box is closed or asked to quit. To display a native
126 message box without a scoped lifetime, just create a Pimpl instance without using
127 the ScopedMessageBox wrapper, and the Pimpl will destroy itself after it is dismissed.
128 */
130};
131
132} // namespace juce::detail
Has a callback method that is triggered asynchronously.
void cancelPendingUpdate() noexcept
This will stop any pending updates from happening.
static bool callAsync(std::function< void()> functionToCall)
Asynchronously invokes a function or C++11 lambda on the message thread.
static MessageManager * getInstance()
Returns the global instance of the MessageManager.
static ModalComponentManager::Callback * create(CallbackFn &&fn)
This is a utility function to create a ModalComponentManager::Callback that will call a callable obje...
Receives callbacks when a modal component is dismissed.
Objects of this type can be used to programmatically close message boxes.
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.