LMMS
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//==============================================================================
43 private DeletedAtShutdown
44{
45public:
46 //==============================================================================
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
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>
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
181 std::remove_reference_t<CallbackFn> fn;
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:
322};
323
324} // namespace juce
AsyncUpdater()
Definition juce_AsyncUpdater.cpp:44
DeletedAtShutdown()
Definition juce_DeletedAtShutdown.cpp:34
static ModalComponentManager::Callback * forComponent(void(*functionToCall)(int, ComponentType *, ParamType), ComponentType *component, ParamType param)
Definition juce_ModalComponentManager.h:309
static ModalComponentManager::Callback * create(CallbackFn &&fn)
Definition juce_ModalComponentManager.h:174
static ModalComponentManager::Callback * forComponent(void(*functionToCall)(int, ComponentType *), ComponentType *component)
Definition juce_ModalComponentManager.h:276
static ModalComponentManager::Callback * withParam(void(*functionToCall)(int, ParamType1, ParamType2), ParamType1 parameterValue1, ParamType2 parameterValue2)
Definition juce_ModalComponentManager.h:242
static ModalComponentManager::Callback * create(void(*functionToCall)(int, ParamType), ParamType parameterValue)
Definition juce_ModalComponentManager.h:210
Definition juce_ModalComponentManager.h:56
virtual void modalStateFinished(int returnValue)=0
OwnedArray< ModalItem > stack
Definition juce_ModalComponentManager.h:146
void handleAsyncUpdate() override
Definition juce_ModalComponentManager.cpp:198
bool isModal(const Component *component) const
Definition juce_ModalComponentManager.cpp:184
void bringModalComponentsToFront(bool topOneShouldGrabFocus=true)
Definition juce_ModalComponentManager.cpp:217
void startModal(Component *, bool autoDelete)
Definition juce_ModalComponentManager.cpp:106
Component * getModalComponent(int index) const
Definition juce_ModalComponentManager.cpp:168
bool isFrontModalComponent(const Component *component) const
Definition juce_ModalComponentManager.cpp:193
void attachCallback(Component *component, Callback *callback)
Definition juce_ModalComponentManager.cpp:112
bool cancelAllModalComponents()
Definition juce_ModalComponentManager.cpp:250
friend class Component
Definition juce_ModalComponentManager.h:143
void endModal(Component *, int returnValue)
Definition juce_ModalComponentManager.cpp:143
ModalComponentManager()
Definition juce_ModalComponentManager.cpp:92
int getNumModalComponents() const
Definition juce_ModalComponentManager.cpp:157
Definition juce_OwnedArray.h:51
Definition juce_WeakReference.h:78
unsigned f
Definition inflate.c:1572
#define JUCE_DECLARE_NON_COPYABLE(className)
#define JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL(Classname)
Definition juce_Singleton.h:252
#define JUCE_API
Definition juce_StandardHeader.h:152
static int JUCE_CDECL comp(const void *a, const void *b)
Definition lsp.c:298
Definition carla_juce.cpp:31
Definition juce_ModalComponentManager.cpp:30
static void invoke(Callable &&fn, Args &&... args)
Definition juce_Functional.h:58
const char const char const char const char char * fn
Definition swell-functions.h:168
RECT const char void(* callback)(const char *droppath))) SWELL_API_DEFINE(BOOL
Definition swell-functions.h:1004
int r
Definition crypt.c:458
int result
Definition process.c:1455