ASPiK SDK
valuelistener.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #pragma once
6 
7 #include "../ivaluelistener.h"
8 
9 //------------------------------------------------------------------------
10 namespace VSTGUI {
11 namespace Standalone {
12 
13 //------------------------------------------------------------------------
19 {
20 public:
21  void onBeginEdit (IValue& value) override {}
22  void onPerformEdit (IValue& value, IValue::Type newValue) override {}
23  void onEndEdit (IValue& value) override {}
24  void onStateChange (IValue& value) override {}
25 };
26 
27 //------------------------------------------------------------------------
28 namespace Value {
29 namespace Detail {
30 
31 //------------------------------------------------------------------------
33 {
34 public:
35  ListenerBase (IValue& value) : value (value)
36  {
37  value.registerListener (this);
38  }
39  ~ListenerBase () noexcept override
40  {
41  value.unregisterListener (this);
42  }
43  IValue& getValueObject () const { return value; }
44 private:
45  IValue& value;
46 };
47 
48 //------------------------------------------------------------------------
49 } // Detail
50 
51 //------------------------------------------------------------------------
56 template <typename Context>
58 {
59 public:
60  ListenerT (IValue& value, Context context) : Detail::ListenerBase (value), context (context) {}
61 
62  using OnBeginEditFunc = void(*) (IValue&, Context&);
63  using OnEndEditFunc = void(*) (IValue&, Context&);
64  using OnStateChangeFunc = void(*) (IValue&, Context&);
65  using OnPerformEditFunc = void(*) (IValue&, IValue::Type, Context&);
66 
67  OnBeginEditFunc onBeginEditFunc {nullptr};
68  OnEndEditFunc onEndEditFunc {nullptr};
69  OnStateChangeFunc onStateChangeFunc {nullptr};
70  OnPerformEditFunc onPerformEditFunc {nullptr};
71 
72 private:
73  void onBeginEdit (IValue& value) final
74  {
75  if (onBeginEditFunc)
76  onBeginEditFunc (value, context);
77  }
78  void onPerformEdit (IValue& value, IValue::Type newValue) final
79  {
80  if (onPerformEditFunc)
81  onPerformEditFunc (value, newValue, context);
82  }
83  void onEndEdit (IValue& value) final
84  {
85  if (onEndEditFunc)
86  onEndEditFunc (value, context);
87  }
88  void onStateChange (IValue& value) final
89  {
90  if (onStateChangeFunc)
91  onStateChangeFunc (value, context);
92  }
93 
94  Context context;
95 };
96 
97 //------------------------------------------------------------------------
103 {
104 public:
105  Listener (IValue& value) : Detail::ListenerBase (value) {}
106 
107  using OnBeginEditFunc = void(*) (IValue&);
108  using OnEndEditFunc = void(*) (IValue&);
109  using OnStateChangeFunc = void(*) (IValue&);
110  using OnPerformEditFunc = void(*) (IValue&, IValue::Type);
111 
112  OnBeginEditFunc onBeginEditFunc {nullptr};
113  OnEndEditFunc onEndEditFunc {nullptr};
114  OnStateChangeFunc onStateChangeFunc {nullptr};
115  OnPerformEditFunc onPerformEditFunc {nullptr};
116 private:
117  void onBeginEdit (IValue& value) final
118  {
119  if (onBeginEditFunc)
120  onBeginEditFunc (value);
121  }
122  void onPerformEdit (IValue& value, IValue::Type newValue) final
123  {
124  if (onPerformEditFunc)
125  onPerformEditFunc (value, newValue);
126  }
127  void onEndEdit (IValue& value) final
128  {
129  if (onEndEditFunc)
130  onEndEditFunc (value);
131  }
132  void onStateChange (IValue& value) final
133  {
134  if (onStateChangeFunc)
135  onStateChangeFunc (value);
136  }
137 };
138 
139 //------------------------------------------------------------------------
140 } // Value
141 } // Standalone
142 } // VSTGUI
Definition: valuelistener.h:57
Definition: ivaluelistener.h:18
void onPerformEdit(IValue &value, IValue::Type newValue) override
Definition: valuelistener.h:22
double Type
Definition: ivalue.h:24
void onStateChange(IValue &value) override
Definition: valuelistener.h:24
Definition: valuelistener.h:102
void onEndEdit(IValue &value) override
Definition: valuelistener.h:23
void onBeginEdit(IValue &value) override
Definition: valuelistener.h:21
Definition: valuelistener.h:18
Definition: customcontrols.cpp:8
Definition: ivalue.h:20