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_ModalComponentManager.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
27{
28
29//==============================================================================
42class JUCE_API ModalComponentManager : private AsyncUpdater,
43 private DeletedAtShutdown
44{
45public:
46 //==============================================================================
55 class JUCE_API Callback
56 {
57 public:
59 Callback() = default;
60
62 virtual ~Callback() = default;
63
74 virtual void modalStateFinished (int returnValue) = 0;
75 };
76
77 //==============================================================================
78 #ifndef DOXYGEN
80 #endif
81
82 //==============================================================================
86 int getNumModalComponents() const;
87
91 Component* getModalComponent (int index) const;
92
94 bool isModal (const Component* component) const;
95
97 bool isFrontModalComponent (const Component* component) const;
98
112 void attachCallback (Component* component, Callback* callback);
113
115 void bringModalComponentsToFront (bool topOneShouldGrabFocus = true);
116
120 bool cancelAllModalComponents();
121
122 #if JUCE_MODAL_LOOPS_PERMITTED
126 int runEventLoopForCurrentComponent();
127 #endif
128
129protected:
134
136 ~ModalComponentManager() override;
137
139 void handleAsyncUpdate() override;
140
141private:
142 //==============================================================================
143 friend class Component;
144
145 struct ModalItem;
147
148 void startModal (Component*, bool autoDelete);
149 void endModal (Component*, int returnValue);
150 void endModal (Component*);
151
153};
154
155//==============================================================================
163{
164public:
173 template <typename CallbackFn>
174 static ModalComponentManager::Callback* create (CallbackFn&& fn)
175 {
176 struct Callable : public ModalComponentManager::Callback
177 {
178 explicit Callable (CallbackFn&& f) : fn (std::forward<CallbackFn> (f)) {}
179 void modalStateFinished (int result) override { NullCheckedInvocation::invoke (std::move (fn), result); }
180
182 };
183
184 return new Callable (std::forward<CallbackFn> (fn));
185 }
186
187 //==============================================================================
209 template <typename ParamType>
210 static ModalComponentManager::Callback* create (void (*functionToCall) (int, ParamType),
211 ParamType parameterValue)
212 {
213 return create ([functionToCall, parameterValue] (int r)
214 {
215 functionToCall (r, parameterValue);
216 });
217 }
218
219 //==============================================================================
241 template <typename ParamType1, typename ParamType2>
242 static ModalComponentManager::Callback* withParam (void (*functionToCall) (int, ParamType1, ParamType2),
243 ParamType1 parameterValue1,
244 ParamType2 parameterValue2)
245 {
246 return create ([functionToCall, parameterValue1, parameterValue2] (int r)
247 {
248 functionToCall (r, parameterValue1, parameterValue2);
249 });
250 }
251
252 //==============================================================================
275 template <class ComponentType>
276 static ModalComponentManager::Callback* forComponent (void (*functionToCall) (int, ComponentType*),
277 ComponentType* component)
278 {
279 return create ([functionToCall, comp = WeakReference<Component> { component }] (int r)
280 {
281 functionToCall (r, static_cast<ComponentType*> (comp.get()));
282 });
283 }
284
285 //==============================================================================
308 template <class ComponentType, typename ParamType>
309 static ModalComponentManager::Callback* forComponent (void (*functionToCall) (int, ComponentType*, ParamType),
310 ComponentType* component,
311 ParamType param)
312 {
313 return create ([functionToCall, param, comp = WeakReference<Component> { component }] (int r)
314 {
315 functionToCall (r, static_cast<ComponentType*> (comp.get()), param);
316 });
317 }
318
319private:
320 ModalCallbackFunction() = delete;
321 ~ModalCallbackFunction() = delete;
322};
323
324} // namespace juce
Has a callback method that is triggered asynchronously.
The base class for all JUCE user-interface objects.
Classes derived from this will be automatically deleted when the application exits.
This class provides some handy utility methods for creating ModalComponentManager::Callback objects t...
static ModalComponentManager::Callback * forComponent(void(*functionToCall)(int, ComponentType *, ParamType), ComponentType *component, ParamType param)
Creates a ModalComponentManager::Callback that will call a static function with a component.
static ModalComponentManager::Callback * create(CallbackFn &&fn)
This is a utility function to create a ModalComponentManager::Callback that will call a callable obje...
static ModalComponentManager::Callback * forComponent(void(*functionToCall)(int, ComponentType *), ComponentType *component)
This is a utility function to create a ModalComponentManager::Callback that will call a static functi...
static ModalComponentManager::Callback * withParam(void(*functionToCall)(int, ParamType1, ParamType2), ParamType1 parameterValue1, ParamType2 parameterValue2)
This is a utility function to create a ModalComponentManager::Callback that will call a static functi...
static ModalComponentManager::Callback * create(void(*functionToCall)(int, ParamType), ParamType parameterValue)
This is a utility function to create a ModalComponentManager::Callback that will call a static functi...
Receives callbacks when a modal component is dismissed.
virtual void modalStateFinished(int returnValue)=0
Called to indicate that a modal component has been dismissed.
virtual ~Callback()=default
Destructor.
Manages the system's stack of modal components.
An array designed for holding objects.
This class acts as a pointer which will automatically become null if the object to which it points is...
#define JUCE_DECLARE_NON_COPYABLE(className)
This is a shorthand macro for deleting a class's copy constructor and copy assignment operator.
#define JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL(Classname)
Macro to declare member variables and methods for a singleton class.
JUCE Namespace.