mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-26 02:14:22 +00:00
Added lambda callback methods to ListenerList. Its old method-invocation callbacks were refactored to use variadic templates instead of the old awful macros they used in the past, but please move your code to use the new lambda functions, as the one stuff will eventually be deprecated!
This commit is contained in:
parent
3dcd918ddd
commit
a586966c65
185 changed files with 469 additions and 1268 deletions
|
|
@ -66,13 +66,13 @@ public:
|
|||
}
|
||||
|
||||
template <typename Function>
|
||||
void callListeners (Function fn) const
|
||||
void callListeners (ValueTree::Listener* listenerToExclude, Function fn) const
|
||||
{
|
||||
auto numListeners = valueTreesWithListeners.size();
|
||||
|
||||
if (numListeners == 1)
|
||||
{
|
||||
fn (valueTreesWithListeners.getUnchecked(0)->listeners);
|
||||
valueTreesWithListeners.getUnchecked(0)->listeners.callExcluding (listenerToExclude, fn);
|
||||
}
|
||||
else if (numListeners > 0)
|
||||
{
|
||||
|
|
@ -83,40 +83,40 @@ public:
|
|||
auto* v = listenersCopy.getUnchecked(i);
|
||||
|
||||
if (i == 0 || valueTreesWithListeners.contains (v))
|
||||
fn (v->listeners);
|
||||
v->listeners.callExcluding (listenerToExclude, fn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Function>
|
||||
void callListenersForAllParents (Function fn) const
|
||||
void callListenersForAllParents (ValueTree::Listener* listenerToExclude, Function fn) const
|
||||
{
|
||||
for (auto* t = this; t != nullptr; t = t->parent)
|
||||
t->callListeners (fn);
|
||||
t->callListeners (listenerToExclude, fn);
|
||||
}
|
||||
|
||||
void sendPropertyChangeMessage (const Identifier& property, ValueTree::Listener* listenerToExclude = nullptr)
|
||||
{
|
||||
ValueTree tree (this);
|
||||
callListenersForAllParents ([&] (ListenerList<Listener>& list) { list.callExcluding (listenerToExclude, &ValueTree::Listener::valueTreePropertyChanged, tree, property); });
|
||||
callListenersForAllParents (listenerToExclude, [&] (Listener& l) { l.valueTreePropertyChanged (tree, property); });
|
||||
}
|
||||
|
||||
void sendChildAddedMessage (ValueTree child)
|
||||
{
|
||||
ValueTree tree (this);
|
||||
callListenersForAllParents ([&] (ListenerList<Listener>& list) { list.call (&ValueTree::Listener::valueTreeChildAdded, tree, child); });
|
||||
callListenersForAllParents (nullptr, [&] (Listener& l) { l.valueTreeChildAdded (tree, child); });
|
||||
}
|
||||
|
||||
void sendChildRemovedMessage (ValueTree child, int index)
|
||||
{
|
||||
ValueTree tree (this);
|
||||
callListenersForAllParents ([=, &tree, &child] (ListenerList<Listener>& list) { list.call (&ValueTree::Listener::valueTreeChildRemoved, tree, child, index); });
|
||||
callListenersForAllParents (nullptr, [=, &tree, &child] (Listener& l) { l.valueTreeChildRemoved (tree, child, index); });
|
||||
}
|
||||
|
||||
void sendChildOrderChangedMessage (int oldIndex, int newIndex)
|
||||
{
|
||||
ValueTree tree (this);
|
||||
callListenersForAllParents ([=, &tree] (ListenerList<Listener>& list) { list.call (&ValueTree::Listener::valueTreeChildOrderChanged, tree, oldIndex, newIndex); });
|
||||
callListenersForAllParents (nullptr, [=, &tree] (Listener& l) { l.valueTreeChildOrderChanged (tree, oldIndex, newIndex); });
|
||||
}
|
||||
|
||||
void sendParentChangeMessage()
|
||||
|
|
@ -127,7 +127,7 @@ public:
|
|||
if (auto* child = children.getObjectPointer (j))
|
||||
child->sendParentChangeMessage();
|
||||
|
||||
callListeners ([&] (ListenerList<Listener>& list) { list.call (&ValueTree::Listener::valueTreeParentChanged, tree); });
|
||||
callListeners (nullptr, [&] (Listener& l) { l.valueTreeParentChanged (tree); });
|
||||
}
|
||||
|
||||
void setProperty (const Identifier& name, const var& newValue, UndoManager* undoManager,
|
||||
|
|
@ -615,7 +615,7 @@ ValueTree& ValueTree::operator= (const ValueTree& other)
|
|||
|
||||
object = other.object;
|
||||
|
||||
listeners.call (&ValueTree::Listener::valueTreeRedirected, *this);
|
||||
listeners.call ([this] (Listener& l) { l.valueTreeRedirected (*this); });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue