openshot-audio  0.1.2
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) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_MODALCOMPONENTMANAGER_H_INCLUDED
26 #define JUCE_MODALCOMPONENTMANAGER_H_INCLUDED
27 
28 
29 //==============================================================================
41  private DeletedAtShutdown
42 {
43 public:
44  //==============================================================================
53  class Callback
54  {
55  public:
57  Callback() {}
58 
60  virtual ~Callback() {}
61 
72  virtual void modalStateFinished (int returnValue) = 0;
73  };
74 
75  //==============================================================================
77 
78  //==============================================================================
82  int getNumModalComponents() const;
83 
87  Component* getModalComponent (int index) const;
88 
90  bool isModal (Component* component) const;
91 
93  bool isFrontModalComponent (Component* component) const;
94 
108  void attachCallback (Component* component, Callback* callback);
109 
111  void bringModalComponentsToFront (bool topOneShouldGrabFocus = true);
112 
116  bool cancelAllModalComponents();
117 
118  #if JUCE_MODAL_LOOPS_PERMITTED
119 
122  int runEventLoopForCurrentComponent();
123  #endif
124 
125 protected:
130 
133 
135  void handleAsyncUpdate() override;
136 
137 private:
138  //==============================================================================
139  class ModalItem;
140  class ReturnValueRetriever;
141 
142  friend class Component;
144  OwnedArray<ModalItem> stack;
145 
146  void startModal (Component*, bool autoDelete);
147  void endModal (Component*, int returnValue);
148  void endModal (Component*);
149 
151 };
152 
153 //==============================================================================
159 {
160 public:
161  //==============================================================================
183  template <typename ParamType>
184  static ModalComponentManager::Callback* create (void (*functionToCall) (int, ParamType),
185  ParamType parameterValue)
186  {
187  return new FunctionCaller1 <ParamType> (functionToCall, parameterValue);
188  }
189 
190  //==============================================================================
212  template <typename ParamType1, typename ParamType2>
213  static ModalComponentManager::Callback* withParam (void (*functionToCall) (int, ParamType1, ParamType2),
214  ParamType1 parameterValue1,
215  ParamType2 parameterValue2)
216  {
217  return new FunctionCaller2 <ParamType1, ParamType2> (functionToCall, parameterValue1, parameterValue2);
218  }
219 
220  //==============================================================================
243  template <class ComponentType>
244  static ModalComponentManager::Callback* forComponent (void (*functionToCall) (int, ComponentType*),
245  ComponentType* component)
246  {
247  return new ComponentCaller1 <ComponentType> (functionToCall, component);
248  }
249 
250  //==============================================================================
273  template <class ComponentType, typename ParamType>
274  static ModalComponentManager::Callback* forComponent (void (*functionToCall) (int, ComponentType*, ParamType),
275  ComponentType* component,
276  ParamType param)
277  {
278  return new ComponentCaller2 <ComponentType, ParamType> (functionToCall, component, param);
279  }
280 
281 private:
282  //==============================================================================
283  template <typename ParamType>
284  class FunctionCaller1 : public ModalComponentManager::Callback
285  {
286  public:
287  typedef void (*FunctionType) (int, ParamType);
288 
289  FunctionCaller1 (FunctionType& f, ParamType& p1)
290  : function (f), param (p1) {}
291 
292  void modalStateFinished (int returnValue) { function (returnValue, param); }
293 
294  private:
295  const FunctionType function;
296  ParamType param;
297 
299  };
300 
301  template <typename ParamType1, typename ParamType2>
302  class FunctionCaller2 : public ModalComponentManager::Callback
303  {
304  public:
305  typedef void (*FunctionType) (int, ParamType1, ParamType2);
306 
307  FunctionCaller2 (FunctionType& f, ParamType1& p1, ParamType2& p2)
308  : function (f), param1 (p1), param2 (p2) {}
309 
310  void modalStateFinished (int returnValue) { function (returnValue, param1, param2); }
311 
312  private:
313  const FunctionType function;
314  ParamType1 param1;
315  ParamType2 param2;
316 
318  };
319 
320  template <typename ComponentType>
321  class ComponentCaller1 : public ModalComponentManager::Callback
322  {
323  public:
324  typedef void (*FunctionType) (int, ComponentType*);
325 
326  ComponentCaller1 (FunctionType& f, ComponentType* c)
327  : function (f), comp (c) {}
328 
329  void modalStateFinished (int returnValue)
330  {
331  function (returnValue, static_cast <ComponentType*> (comp.get()));
332  }
333 
334  private:
335  const FunctionType function;
337 
339  };
340 
341  template <typename ComponentType, typename ParamType1>
342  class ComponentCaller2 : public ModalComponentManager::Callback
343  {
344  public:
345  typedef void (*FunctionType) (int, ComponentType*, ParamType1);
346 
347  ComponentCaller2 (FunctionType& f, ComponentType* c, ParamType1 p1)
348  : function (f), comp (c), param1 (p1) {}
349 
350  void modalStateFinished (int returnValue)
351  {
352  function (returnValue, static_cast <ComponentType*> (comp.get()), param1);
353  }
354 
355  private:
356  const FunctionType function;
358  ParamType1 param1;
359 
361  };
362 
366 };
367 
368 
369 #endif // JUCE_MODALCOMPONENTMANAGER_H_INCLUDED
static ModalComponentManager::Callback * forComponent(void(*functionToCall)(int, ComponentType *, ParamType), ComponentType *component, ParamType param)
Definition: juce_ModalComponentManager.h:274
static ModalComponentManager::Callback * create(void(*functionToCall)(int, ParamType), ParamType parameterValue)
Definition: juce_ModalComponentManager.h:184
virtual ~Callback()
Definition: juce_ModalComponentManager.h:60
Callback()
Definition: juce_ModalComponentManager.h:57
Definition: juce_DeletedAtShutdown.h:40
Definition: juce_ModalComponentManager.h:53
#define JUCE_API
Definition: juce_StandardHeader.h:139
Definition: juce_AsyncUpdater.h:39
Definition: juce_Component.h:33
Definition: juce_ModalComponentManager.h:158
Definition: juce_ContainerDeletePolicy.h:44
static ModalComponentManager::Callback * forComponent(void(*functionToCall)(int, ComponentType *), ComponentType *component)
Definition: juce_ModalComponentManager.h:244
Definition: juce_OwnedArray.h:55
Definition: juce_ModalComponentManager.cpp:25
#define JUCE_DECLARE_NON_COPYABLE(className)
Definition: juce_PlatformDefs.h:191
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198
#define juce_DeclareSingleton_SingleThreaded_Minimal(classname)
static ModalComponentManager::Callback * withParam(void(*functionToCall)(int, ParamType1, ParamType2), ParamType1 parameterValue1, ParamType2 parameterValue2)
Definition: juce_ModalComponentManager.h:213
Definition: juce_ModalComponentManager.h:40