>
class ListenerList
{
- #ifndef DOXYGEN
- #define LL_TEMPLATE(a) typename P##a
- #define LL_PARAM(a) typename TypeHelpers::ParameterType::type param##a
- #endif
-
public:
//==============================================================================
/** Creates an empty list. */
- ListenerList()
- {
- }
+ ListenerList() {}
/** Destructor. */
- ~ListenerList()
- {
- }
+ ~ListenerList() {}
//==============================================================================
/** Adds a listener to the list.
@@ -88,387 +79,88 @@ public:
this method has no effect.
@see remove
*/
- void add (ListenerClass* const listenerToAdd)
+ void add (ListenerClass* listenerToAdd)
{
- // Listeners can't be null pointers!
- jassert (listenerToAdd != nullptr);
-
if (listenerToAdd != nullptr)
listeners.addIfNotAlreadyThere (listenerToAdd);
+ else
+ jassertfalse; // Listeners can't be null pointers!
}
/** Removes a listener from the list.
If the listener wasn't in the list, this has no effect.
*/
- void remove (ListenerClass* const listenerToRemove)
+ void remove (ListenerClass* listenerToRemove)
{
- // Listeners can't be null pointers!
- jassert (listenerToRemove != nullptr);
-
+ jassert (listenerToRemove != nullptr); // Listeners can't be null pointers!
listeners.removeFirstMatchingValue (listenerToRemove);
}
/** Returns the number of registered listeners. */
- int size() const noexcept
- {
- return listeners.size();
- }
+ int size() const noexcept { return listeners.size(); }
/** Returns true if any listeners are registered. */
- bool isEmpty() const noexcept
- {
- return listeners.size() == 0;
- }
+ bool isEmpty() const noexcept { return listeners.isEmpty(); }
/** Clears the list. */
- void clear()
- {
- listeners.clear();
- }
+ void clear() { listeners.clear(); }
/** Returns true if the specified listener has been added to the list. */
- bool contains (ListenerClass* const listener) const noexcept
- {
- return listeners.contains (listener);
- }
+ bool contains (ListenerClass* listener) const noexcept { return listeners.contains (listener); }
+
+ /** Returns the raw array of listeners. */
+ const ArrayType& getListeners() const noexcept { return listeners; }
//==============================================================================
- /** Calls a member function on each listener in the list, with no parameters. */
- void call (void (ListenerClass::*callbackFunction) ())
- {
- callChecked (static_cast (DummyBailOutChecker()), callbackFunction);
- }
-
- /** Calls a member function, with no parameters, on all but the specified listener in the list.
- This can be useful if the caller is also a listener and needs to exclude itself.
- */
- void callExcluding (ListenerClass* listenerToExclude, void (ListenerClass::*callbackFunction) ())
- {
- callCheckedExcluding (listenerToExclude,
- static_cast (DummyBailOutChecker()), callbackFunction);
- }
-
- /** Calls a member function on each listener in the list, with no parameters and a bail-out-checker.
- See the class description for info about writing a bail-out checker.
- */
- template
- void callChecked (const BailOutCheckerType& bailOutChecker,
- void (ListenerClass::*callbackFunction) ())
- {
- for (Iterator iter (*this); iter.next (bailOutChecker);)
- (iter.getListener()->*callbackFunction) ();
- }
-
- /** Calls a member function on all but the specified listener in the list with a bail-out-checker.
- This can be useful if the caller is also a listener and needs to exclude itself. See the class
- description for info about writing a bail-out checker.
- */
- template
- void callCheckedExcluding (ListenerClass* listenerToExclude,
- const BailOutCheckerType& bailOutChecker,
- void (ListenerClass::*callbackFunction) ())
- {
- for (Iterator iter (*this); iter.next (bailOutChecker);)
- if (iter.getListener() != listenerToExclude)
- (iter.getListener()->*callbackFunction) ();
- }
-
- //==============================================================================
- /** Calls a member function on each listener in the list, with 1 parameter. */
- template
- void call (void (ListenerClass::*callbackFunction) (P1), LL_PARAM(1))
+ /** Calls a member function on each listener in the list, with multiple parameters. */
+ template
+ void call (Callback&& callback)
{
for (Iterator iter (*this); iter.next();)
- (iter.getListener()->*callbackFunction) (param1);
+ callback (*iter.getListener());
}
- /** Calls a member function, with 1 parameter, on all but the specified listener in the list.
+ /** Calls a member function with 1 parameter, on all but the specified listener in the list.
This can be useful if the caller is also a listener and needs to exclude itself.
*/
- template
- void callExcluding (ListenerClass* listenerToExclude,
- void (ListenerClass::*callbackFunction) (P1), LL_PARAM(1))
+ template
+ void callExcluding (ListenerClass* listenerToExclude, Callback&& callback)
{
for (Iterator iter (*this); iter.next();)
- if (iter.getListener() != listenerToExclude)
- (iter.getListener()->*callbackFunction) (param1);
+ {
+ auto* l = iter.getListener();
+
+ if (l != listenerToExclude)
+ callback (*l);
+ }
}
/** Calls a member function on each listener in the list, with 1 parameter and a bail-out-checker.
See the class description for info about writing a bail-out checker.
*/
- template
- void callChecked (const BailOutCheckerType& bailOutChecker,
- void (ListenerClass::*callbackFunction) (P1),
- LL_PARAM(1))
+ template
+ void callChecked (const BailOutCheckerType& bailOutChecker, Callback&& callback)
{
for (Iterator iter (*this); iter.next (bailOutChecker);)
- (iter.getListener()->*callbackFunction) (param1);
+ callback (*iter.getListener());
}
/** Calls a member function, with 1 parameter, on all but the specified listener in the list
with a bail-out-checker. This can be useful if the caller is also a listener and needs to
exclude itself. See the class description for info about writing a bail-out checker.
*/
- template
+ template
void callCheckedExcluding (ListenerClass* listenerToExclude,
const BailOutCheckerType& bailOutChecker,
- void (ListenerClass::*callbackFunction) (P1),
- LL_PARAM(1))
+ Callback&& callback)
{
for (Iterator iter (*this); iter.next (bailOutChecker);)
- if (iter.getListener() != listenerToExclude)
- (iter.getListener()->*callbackFunction) (param1);
- }
+ {
+ auto* l = iter.getListener();
- //==============================================================================
- /** Calls a member function on each listener in the list, with 2 parameters. */
- template
- void call (void (ListenerClass::*callbackFunction) (P1, P2),
- LL_PARAM(1), LL_PARAM(2))
- {
- for (Iterator iter (*this); iter.next();)
- (iter.getListener()->*callbackFunction) (param1, param2);
- }
-
- /** Calls a member function, with 2 parameters, on all but the specified listener in the list.
- This can be useful if the caller is also a listener and needs to exclude itself.
- */
- template
- void callExcluding (ListenerClass* listenerToExclude,
- void (ListenerClass::*callbackFunction) (P1, P2),
- LL_PARAM(1), LL_PARAM(2))
- {
- for (Iterator iter (*this); iter.next();)
- if (iter.getListener() != listenerToExclude)
- (iter.getListener()->*callbackFunction) (param1, param2);
- }
-
- /** Calls a member function on each listener in the list, with 2 parameters and a bail-out-checker.
- See the class description for info about writing a bail-out checker.
- */
- template
- void callChecked (const BailOutCheckerType& bailOutChecker,
- void (ListenerClass::*callbackFunction) (P1, P2),
- LL_PARAM(1), LL_PARAM(2))
- {
- for (Iterator iter (*this); iter.next (bailOutChecker);)
- (iter.getListener()->*callbackFunction) (param1, param2);
- }
-
- /** Calls a member function, with 2 parameters, on all but the specified listener in the list
- with a bail-out-checker. This can be useful if the caller is also a listener and needs to
- exclude itself. See the class description for info about writing a bail-out checker.
- */
- template
- void callCheckedExcluding (ListenerClass* listenerToExclude,
- const BailOutCheckerType& bailOutChecker,
- void (ListenerClass::*callbackFunction) (P1, P2),
- LL_PARAM(1), LL_PARAM(2))
- {
- for (Iterator iter (*this); iter.next (bailOutChecker);)
- if (iter.getListener() != listenerToExclude)
- (iter.getListener()->*callbackFunction) (param1, param2);
- }
-
- //==============================================================================
- /** Calls a member function on each listener in the list, with 3 parameters. */
- template
- void call (void (ListenerClass::*callbackFunction) (P1, P2, P3),
- LL_PARAM(1), LL_PARAM(2), LL_PARAM(3))
- {
- for (Iterator iter (*this); iter.next();)
- (iter.getListener()->*callbackFunction) (param1, param2, param3);
- }
-
- /** Calls a member function, with 3 parameters, on all but the specified listener in the list.
- This can be useful if the caller is also a listener and needs to exclude itself.
- */
- template
- void callExcluding (ListenerClass* listenerToExclude,
- void (ListenerClass::*callbackFunction) (P1, P2, P3),
- LL_PARAM(1), LL_PARAM(2), LL_PARAM(3))
- {
- for (Iterator iter (*this); iter.next();)
- if (iter.getListener() != listenerToExclude)
- (iter.getListener()->*callbackFunction) (param1, param2, param3);
- }
-
- /** Calls a member function on each listener in the list, with 3 parameters and a bail-out-checker.
- See the class description for info about writing a bail-out checker.
- */
- template
- void callChecked (const BailOutCheckerType& bailOutChecker,
- void (ListenerClass::*callbackFunction) (P1, P2, P3),
- LL_PARAM(1), LL_PARAM(2), LL_PARAM(3))
- {
- for (Iterator iter (*this); iter.next (bailOutChecker);)
- (iter.getListener()->*callbackFunction) (param1, param2, param3);
- }
-
- /** Calls a member function, with 3 parameters, on all but the specified listener in the list
- with a bail-out-checker. This can be useful if the caller is also a listener and needs to
- exclude itself. See the class description for info about writing a bail-out checker.
- */
- template
- void callCheckedExcluding (ListenerClass* listenerToExclude,
- const BailOutCheckerType& bailOutChecker,
- void (ListenerClass::*callbackFunction) (P1, P2, P3),
- LL_PARAM(1), LL_PARAM(2), LL_PARAM(3))
- {
- for (Iterator iter (*this); iter.next (bailOutChecker);)
- if (iter.getListener() != listenerToExclude)
- (iter.getListener()->*callbackFunction) (param1, param2, param3);
- }
-
- //==============================================================================
- /** Calls a member function on each listener in the list, with 4 parameters. */
- template
- void call (void (ListenerClass::*callbackFunction) (P1, P2, P3, P4),
- LL_PARAM(1), LL_PARAM(2), LL_PARAM(3), LL_PARAM(4))
- {
- for (Iterator iter (*this); iter.next();)
- (iter.getListener()->*callbackFunction) (param1, param2, param3, param4);
- }
-
- /** Calls a member function, with 4 parameters, on all but the specified listener in the list.
- This can be useful if the caller is also a listener and needs to exclude itself.
- */
- template
- void callExcluding (ListenerClass* listenerToExclude,
- void (ListenerClass::*callbackFunction) (P1, P2, P3, P4),
- LL_PARAM(1), LL_PARAM(2), LL_PARAM(3), LL_PARAM(4))
- {
- for (Iterator iter (*this); iter.next();)
- if (iter.getListener() != listenerToExclude)
- (iter.getListener()->*callbackFunction) (param1, param2, param3, param4);
- }
-
- /** Calls a member function on each listener in the list, with 4 parameters and a bail-out-checker.
- See the class description for info about writing a bail-out checker.
- */
- template
- void callChecked (const BailOutCheckerType& bailOutChecker,
- void (ListenerClass::*callbackFunction) (P1, P2, P3, P4),
- LL_PARAM(1), LL_PARAM(2), LL_PARAM(3), LL_PARAM(4))
- {
- for (Iterator iter (*this); iter.next (bailOutChecker);)
- (iter.getListener()->*callbackFunction) (param1, param2, param3, param4);
- }
-
- /** Calls a member function, with 4 parameters, on all but the specified listener in the list
- with a bail-out-checker. This can be useful if the caller is also a listener and needs to
- exclude itself. See the class description for info about writing a bail-out checker.
- */
- template
- void callCheckedExcluding (ListenerClass* listenerToExclude,
- const BailOutCheckerType& bailOutChecker,
- void (ListenerClass::*callbackFunction) (P1, P2, P3, P4),
- LL_PARAM(1), LL_PARAM(2), LL_PARAM(3), LL_PARAM(4))
- {
- for (Iterator iter (*this); iter.next (bailOutChecker);)
- if (iter.getListener() != listenerToExclude)
- (iter.getListener()->*callbackFunction) (param1, param2, param3, param4);
- }
-
- //==============================================================================
- /** Calls a member function on each listener in the list, with 5 parameters. */
- template
- void call (void (ListenerClass::*callbackFunction) (P1, P2, P3, P4, P5),
- LL_PARAM(1), LL_PARAM(2), LL_PARAM(3), LL_PARAM(4), LL_PARAM(5))
- {
- for (Iterator iter (*this); iter.next();)
- (iter.getListener()->*callbackFunction) (param1, param2, param3, param4, param5);
- }
-
- /** Calls a member function, with 5 parameters, on all but the specified listener in the list.
- This can be useful if the caller is also a listener and needs to exclude itself.
- */
- template
- void callExcluding (ListenerClass* listenerToExclude,
- void (ListenerClass::*callbackFunction) (P1, P2, P3, P4, P5),
- LL_PARAM(1), LL_PARAM(2), LL_PARAM(3), LL_PARAM(4), LL_PARAM(5))
- {
- for (Iterator iter (*this); iter.next();)
- if (iter.getListener() != listenerToExclude)
- (iter.getListener()->*callbackFunction) (param1, param2, param3, param4, param5);
- }
-
- /** Calls a member function on each listener in the list, with 5 parameters and a bail-out-checker.
- See the class description for info about writing a bail-out checker.
- */
- template
- void callChecked (const BailOutCheckerType& bailOutChecker,
- void (ListenerClass::*callbackFunction) (P1, P2, P3, P4, P5),
- LL_PARAM(1), LL_PARAM(2), LL_PARAM(3), LL_PARAM(4), LL_PARAM(5))
- {
- for (Iterator iter (*this); iter.next (bailOutChecker);)
- (iter.getListener()->*callbackFunction) (param1, param2, param3, param4, param5);
- }
-
- /** Calls a member function, with 5 parameters, on all but the specified listener in the list
- with a bail-out-checker. This can be useful if the caller is also a listener and needs to
- exclude itself. See the class description for info about writing a bail-out checker.
- */
- template
- void callCheckedExcluding (ListenerClass* listenerToExclude,
- const BailOutCheckerType& bailOutChecker,
- void (ListenerClass::*callbackFunction) (P1, P2, P3, P4, P5),
- LL_PARAM(1), LL_PARAM(2), LL_PARAM(3), LL_PARAM(4), LL_PARAM(5))
- {
- for (Iterator iter (*this); iter.next (bailOutChecker);)
- if (iter.getListener() != listenerToExclude)
- (iter.getListener()->*callbackFunction) (param1, param2, param3, param4, param5);
- }
-
- //==============================================================================
- /** Calls a member function on each listener in the list, with 6 parameters. */
- template
- void call (void (ListenerClass::*callbackFunction) (P1, P2, P3, P4, P5, P6),
- LL_PARAM(1), LL_PARAM(2), LL_PARAM(3), LL_PARAM(4), LL_PARAM(5), LL_PARAM(6))
- {
- for (Iterator iter (*this); iter.next();)
- (iter.getListener()->*callbackFunction) (param1, param2, param3, param4, param5, param6);
- }
-
- /** Calls a member function, with 6 parameters, on all but the specified listener in the list.
- This can be useful if the caller is also a listener and needs to exclude itself.
- */
- template
- void callExcluding (ListenerClass* listenerToExclude,
- void (ListenerClass::*callbackFunction) (P1, P2, P3, P4, P5, P6),
- LL_PARAM(1), LL_PARAM(2), LL_PARAM(3), LL_PARAM(4), LL_PARAM(5), LL_PARAM(6))
- {
- for (Iterator iter (*this); iter.next();)
- if (iter.getListener() != listenerToExclude)
- (iter.getListener()->*callbackFunction) (param1, param2, param3, param4, param5, param6);
- }
-
- /** Calls a member function on each listener in the list, with 6 parameters and a bail-out-checker.
- See the class description for info about writing a bail-out checker.
- */
- template
- void callChecked (const BailOutCheckerType& bailOutChecker,
- void (ListenerClass::*callbackFunction) (P1, P2, P3, P4, P5, P6),
- LL_PARAM(1), LL_PARAM(2), LL_PARAM(3), LL_PARAM(4), LL_PARAM(5), LL_PARAM(6))
- {
- for (Iterator iter (*this); iter.next (bailOutChecker);)
- (iter.getListener()->*callbackFunction) (param1, param2, param3, param4, param5, param6);
- }
-
- /** Calls a member function, with 5 parameters, on all but the specified listener in the list
- with a bail-out-checker. This can be useful if the caller is also a listener and needs to
- exclude itself. See the class description for info about writing a bail-out checker.
- */
- template
- void callCheckedExcluding (ListenerClass* listenerToExclude,
- const BailOutCheckerType& bailOutChecker,
- void (ListenerClass::*callbackFunction) (P1, P2, P3, P4, P5, P6),
- LL_PARAM(1), LL_PARAM(2), LL_PARAM(3), LL_PARAM(4), LL_PARAM(5), LL_PARAM(6))
- {
- for (Iterator iter (*this); iter.next (bailOutChecker);)
- if (iter.getListener() != listenerToExclude)
- (iter.getListener()->*callbackFunction) (param1, param2, param3, param4, param5, param6);
+ if (l != listenerToExclude)
+ callback (*l);
+ }
}
//==============================================================================
@@ -480,13 +172,14 @@ public:
bool shouldBailOut() const noexcept { return false; }
};
+ typedef ListenerList ThisType;
+ typedef ListenerClass ListenerType;
+
//==============================================================================
/** Iterates the listeners in a ListenerList. */
template
- class Iterator
+ struct Iterator
{
- public:
- //==============================================================================
Iterator (const ListType& listToIterate) noexcept
: list (listToIterate), index (listToIterate.size())
{}
@@ -499,7 +192,7 @@ public:
if (index <= 0)
return false;
- const int listSize = list.size();
+ auto listSize = list.size();
if (--index < listSize)
return true;
@@ -526,19 +219,77 @@ public:
JUCE_DECLARE_NON_COPYABLE (Iterator)
};
- typedef ListenerList ThisType;
- typedef ListenerClass ListenerType;
+ //==============================================================================
+ #ifndef DOXYGEN
+ // There are now lambda-based call functions that can be used to replace these old method-based versions.
+ // We'll eventually deprecate these old ones, so please begin moving your code to use lambdas!
+ void call (void (ListenerClass::*callbackFunction) ())
+ {
+ call ([=] (ListenerClass& l) { (l.*callbackFunction)(); });
+ }
- const ArrayType& getListeners() const noexcept { return listeners; }
+ void callExcluding (ListenerClass* listenerToExclude, void (ListenerClass::*callbackFunction) ())
+ {
+ callExcluding (listenerToExclude, [=] (ListenerClass& l) { (l.*callbackFunction)(); });
+ }
+
+ template
+ void callChecked (const BailOutCheckerType& bailOutChecker, void (ListenerClass::*callbackFunction) ())
+ {
+ callChecked (bailOutChecker, [=] (ListenerClass& l) { (l.*callbackFunction)(); });
+ }
+
+ template
+ void callCheckedExcluding (ListenerClass* listenerToExclude,
+ const BailOutCheckerType& bailOutChecker,
+ void (ListenerClass::*callbackFunction) ())
+ {
+ callCheckedExcluding (listenerToExclude, bailOutChecker, [=] (ListenerClass& l) { (l.*callbackFunction)(); });
+ }
+
+ template
+ void call (void (ListenerClass::*callbackFunction) (MethodArgs...), Args&&... args)
+ {
+ for (Iterator iter (*this); iter.next();)
+ (iter.getListener()->*callbackFunction) (static_cast::type> (args)...);
+ }
+
+ template
+ void callExcluding (ListenerClass* listenerToExclude,
+ void (ListenerClass::*callbackFunction) (MethodArgs...),
+ Args&&... args)
+ {
+ for (Iterator iter (*this); iter.next();)
+ if (iter.getListener() != listenerToExclude)
+ (iter.getListener()->*callbackFunction) (static_cast::type> (args)...);
+ }
+
+ template
+ void callChecked (const BailOutCheckerType& bailOutChecker,
+ void (ListenerClass::*callbackFunction) (MethodArgs...),
+ Args&&... args)
+ {
+ for (Iterator iter (*this); iter.next (bailOutChecker);)
+ (iter.getListener()->*callbackFunction) (static_cast::type> (args)...);
+ }
+
+ template
+ void callCheckedExcluding (ListenerClass* listenerToExclude,
+ const BailOutCheckerType& bailOutChecker,
+ void (ListenerClass::*callbackFunction) (MethodArgs...),
+ Args&&... args)
+ {
+ for (Iterator iter (*this); iter.next (bailOutChecker);)
+ if (iter.getListener() != listenerToExclude)
+ (iter.getListener()->*callbackFunction) (static_cast::type> (args)...);
+ }
+ #endif
private:
//==============================================================================
ArrayType listeners;
JUCE_DECLARE_NON_COPYABLE (ListenerList)
-
- #undef LL_TEMPLATE
- #undef LL_PARAM
};
} // namespace juce
diff --git a/modules/juce_core/juce_core.cpp b/modules/juce_core/juce_core.cpp
index 136dd284e7..71c0554db0 100644
--- a/modules/juce_core/juce_core.cpp
+++ b/modules/juce_core/juce_core.cpp
@@ -119,7 +119,6 @@
//==============================================================================
#include "containers/juce_AbstractFifo.cpp"
#include "containers/juce_NamedValueSet.cpp"
-#include "containers/juce_ListenerList.cpp"
#include "containers/juce_PropertySet.cpp"
#include "containers/juce_Variant.cpp"
#include "files/juce_DirectoryIterator.cpp"
diff --git a/modules/juce_core/threads/juce_Thread.cpp b/modules/juce_core/threads/juce_Thread.cpp
index 4a335937f0..0e433e7b6e 100644
--- a/modules/juce_core/threads/juce_Thread.cpp
+++ b/modules/juce_core/threads/juce_Thread.cpp
@@ -167,7 +167,7 @@ Thread* JUCE_CALLTYPE Thread::getCurrentThread()
void Thread::signalThreadShouldExit()
{
shouldExit = true;
- listeners.call (&Listener::exitSignalSent);
+ listeners.call ([] (Listener& l) { l.exitSignalSent(); });
}
bool Thread::currentThreadShouldExit()
@@ -183,7 +183,7 @@ bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
// Doh! So how exactly do you expect this thread to wait for itself to stop??
jassert (getThreadId() != getCurrentThreadId() || getCurrentThreadId() == 0);
- const uint32 timeoutEnd = Time::getMillisecondCounter() + (uint32) timeOutMilliseconds;
+ auto timeoutEnd = Time::getMillisecondCounter() + (uint32) timeOutMilliseconds;
while (isThreadRunning())
{
diff --git a/modules/juce_core/threads/juce_ThreadPool.cpp b/modules/juce_core/threads/juce_ThreadPool.cpp
index 4f12038327..2f6dba675d 100644
--- a/modules/juce_core/threads/juce_ThreadPool.cpp
+++ b/modules/juce_core/threads/juce_ThreadPool.cpp
@@ -69,7 +69,7 @@ void ThreadPoolJob::setJobName (const String& newName)
void ThreadPoolJob::signalJobShouldExit()
{
shouldStop = true;
- listeners.call (&Thread::Listener::exitSignalSent);
+ listeners.call ([] (Thread::Listener& l) { l.exitSignalSent(); });
}
void ThreadPoolJob::addListener (Thread::Listener* listener)
diff --git a/modules/juce_data_structures/values/juce_Value.cpp b/modules/juce_data_structures/values/juce_Value.cpp
index b09530fed6..b455e35491 100644
--- a/modules/juce_data_structures/values/juce_Value.cpp
+++ b/modules/juce_data_structures/values/juce_Value.cpp
@@ -230,7 +230,7 @@ void Value::callListeners()
if (listeners.size() > 0)
{
Value v (*this); // (create a copy in case this gets deleted by a callback)
- listeners.call (&ValueListener::valueChanged, v);
+ listeners.call ([&] (ValueListener& l) { l.valueChanged (v); });
}
}
diff --git a/modules/juce_data_structures/values/juce_ValueTree.cpp b/modules/juce_data_structures/values/juce_ValueTree.cpp
index cc97abca74..045f631219 100644
--- a/modules/juce_data_structures/values/juce_ValueTree.cpp
+++ b/modules/juce_data_structures/values/juce_ValueTree.cpp
@@ -66,13 +66,13 @@ public:
}
template
- 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
- 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& 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& 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& 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& 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& 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); });
}
}
diff --git a/modules/juce_events/broadcasters/juce_ChangeBroadcaster.cpp b/modules/juce_events/broadcasters/juce_ChangeBroadcaster.cpp
index a816c3d8ff..5b7298a2b5 100644
--- a/modules/juce_events/broadcasters/juce_ChangeBroadcaster.cpp
+++ b/modules/juce_events/broadcasters/juce_ChangeBroadcaster.cpp
@@ -81,7 +81,7 @@ void ChangeBroadcaster::dispatchPendingMessages()
void ChangeBroadcaster::callListeners()
{
- changeListeners.call (&ChangeListener::changeListenerCallback, this);
+ changeListeners.call ([this] (ChangeListener& l) { l.changeListenerCallback (this); });
}
//==============================================================================
diff --git a/modules/juce_graphics/images/juce_Image.cpp b/modules/juce_graphics/images/juce_Image.cpp
index 1181c0e0f4..0ecbcc91b6 100644
--- a/modules/juce_graphics/images/juce_Image.cpp
+++ b/modules/juce_graphics/images/juce_Image.cpp
@@ -36,12 +36,12 @@ ImagePixelData::ImagePixelData (const Image::PixelFormat format, const int w, co
ImagePixelData::~ImagePixelData()
{
- listeners.call (&Listener::imageDataBeingDeleted, this);
+ listeners.call ([this] (Listener& l) { l.imageDataBeingDeleted (this); });
}
void ImagePixelData::sendDataChangeMessage()
{
- listeners.call (&Listener::imageDataChanged, this);
+ listeners.call ([this] (Listener& l) { l.imageDataChanged (this); });
}
int ImagePixelData::getSharedCount() const noexcept
diff --git a/modules/juce_gui_basics/buttons/juce_Button.cpp b/modules/juce_gui_basics/buttons/juce_Button.cpp
index fd90a382d6..8600592211 100644
--- a/modules/juce_gui_basics/buttons/juce_Button.cpp
+++ b/modules/juce_gui_basics/buttons/juce_Button.cpp
@@ -396,7 +396,7 @@ void Button::sendClickMessage (const ModifierKeys& modifiers)
clicked (modifiers);
if (! checker.shouldBailOut())
- buttonListeners.callChecked (checker, &Button::Listener::buttonClicked, this);
+ buttonListeners.callChecked (checker, [this] (Listener& l) { l.buttonClicked (this); });
}
void Button::sendStateMessage()
@@ -406,7 +406,7 @@ void Button::sendStateMessage()
buttonStateChanged();
if (! checker.shouldBailOut())
- buttonListeners.callChecked (checker, &Button::Listener::buttonStateChanged, this);
+ buttonListeners.callChecked (checker, [this] (Listener& l) { l.buttonStateChanged (this); });
}
//==============================================================================
diff --git a/modules/juce_gui_basics/buttons/juce_Button.h b/modules/juce_gui_basics/buttons/juce_Button.h
index 91792d98ee..4c80befa9e 100644
--- a/modules/juce_gui_basics/buttons/juce_Button.h
+++ b/modules/juce_gui_basics/buttons/juce_Button.h
@@ -352,9 +352,6 @@ public:
/** Returns the button's current over/down/up state. */
ButtonState getState() const noexcept { return buttonState; }
- // This method's parameters have changed - see the new version.
- JUCE_DEPRECATED (void setToggleState (bool, bool));
-
//==============================================================================
/** This abstract base class is implemented by LookAndFeel classes to provide
button-drawing functionality.
@@ -390,6 +387,9 @@ public:
#endif
};
+ // This method's parameters have changed - see the new version.
+ JUCE_DEPRECATED (void setToggleState (bool, bool));
+
protected:
//==============================================================================
/** This method is called when the button has been clicked.
diff --git a/modules/juce_gui_basics/commands/juce_ApplicationCommandManager.cpp b/modules/juce_gui_basics/commands/juce_ApplicationCommandManager.cpp
index e68511cff8..d54322e086 100644
--- a/modules/juce_gui_basics/commands/juce_ApplicationCommandManager.cpp
+++ b/modules/juce_gui_basics/commands/juce_ApplicationCommandManager.cpp
@@ -70,7 +70,7 @@ void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& n
}
else
{
- ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
+ auto* newInfo = new ApplicationCommandInfo (newCommand);
newInfo->flags &= ~ApplicationCommandInfo::isTicked;
commands.add (newInfo);
@@ -129,12 +129,12 @@ ApplicationCommandInfo* ApplicationCommandManager::getMutableCommandForID (Comma
return nullptr;
}
-const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const noexcept
+const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (CommandID commandID) const noexcept
{
return getMutableCommandForID (commandID);
}
-String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const noexcept
+String ApplicationCommandManager::getNameOfCommand (CommandID commandID) const noexcept
{
if (auto* ci = getCommandForID (commandID))
return ci->shortName;
@@ -142,7 +142,7 @@ String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) c
return {};
}
-String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const noexcept
+String ApplicationCommandManager::getDescriptionOfCommand (CommandID commandID) const noexcept
{
if (auto* ci = getCommandForID (commandID))
return ci->description.isNotEmpty() ? ci->description
@@ -173,7 +173,7 @@ Array ApplicationCommandManager::getCommandsInCategory (const String&
}
//==============================================================================
-bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
+bool ApplicationCommandManager::invokeDirectly (CommandID commandID, bool asynchronously)
{
ApplicationCommandTarget::InvocationInfo info (commandID);
info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
@@ -181,7 +181,7 @@ bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const
return invoke (info, asynchronously);
}
-bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& inf, const bool asynchronously)
+bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& inf, bool asynchronously)
{
// This call isn't thread-safe for use from a non-UI thread without locking the message
// manager first..
@@ -204,21 +204,21 @@ bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::Invocati
}
//==============================================================================
-ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
+ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (CommandID)
{
return firstTarget != nullptr ? firstTarget
: findDefaultComponentTarget();
}
-void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) noexcept
+void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* newTarget) noexcept
{
firstTarget = newTarget;
}
-ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
+ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (CommandID commandID,
ApplicationCommandInfo& upToDateInfo)
{
- ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
+ auto* target = getFirstCommandTarget (commandID);
if (target == nullptr)
target = JUCEApplication::getInstance();
@@ -238,7 +238,7 @@ ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const
//==============================================================================
ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
{
- ApplicationCommandTarget* target = dynamic_cast (c);
+ auto* target = dynamic_cast (c);
if (target == nullptr && c != nullptr)
target = c->findParentComponentOfClass();
@@ -248,7 +248,7 @@ ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Com
ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
{
- Component* c = Component::getCurrentlyFocusedComponent();
+ auto* c = Component::getCurrentlyFocusedComponent();
if (c == nullptr)
{
@@ -290,24 +290,24 @@ ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget(
}
//==============================================================================
-void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener)
+void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* listener)
{
listeners.add (listener);
}
-void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener)
+void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* listener)
{
listeners.remove (listener);
}
void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info)
{
- listeners.call (&ApplicationCommandManagerListener::applicationCommandInvoked, info);
+ listeners.call ([&] (ApplicationCommandManagerListener& l) { l.applicationCommandInvoked (info); });
}
void ApplicationCommandManager::handleAsyncUpdate()
{
- listeners.call (&ApplicationCommandManagerListener::applicationCommandListChanged);
+ listeners.call ([] (ApplicationCommandManagerListener& l) { l.applicationCommandListChanged(); });
}
void ApplicationCommandManager::globalFocusChanged (Component*)
diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp
index f8a2cb6487..f68eeab363 100644
--- a/modules/juce_gui_basics/components/juce_Component.cpp
+++ b/modules/juce_gui_basics/components/juce_Component.cpp
@@ -36,7 +36,7 @@ class Component::MouseListenerList
public:
MouseListenerList() noexcept {}
- void addListener (MouseListener* const newListener, const bool wantsEventsForAllNestedChildComponents)
+ void addListener (MouseListener* newListener, bool wantsEventsForAllNestedChildComponents)
{
if (! listeners.contains (newListener))
{
@@ -52,7 +52,7 @@ public:
}
}
- void removeListener (MouseListener* const listenerToRemove)
+ void removeListener (MouseListener* listenerToRemove)
{
auto index = listeners.indexOf (listenerToRemove);
@@ -150,7 +150,7 @@ private:
struct BailOutChecker2
{
- BailOutChecker2 (Component::BailOutChecker& boc, Component* const comp)
+ BailOutChecker2 (Component::BailOutChecker& boc, Component* comp)
: checker (boc), safePointer (comp)
{
}
@@ -470,7 +470,7 @@ Component::~Component()
{
static_assert (sizeof (flags) <= sizeof (componentFlags), "componentFlags has too many bits!");
- componentListeners.call (&ComponentListener::componentBeingDeleted, *this);
+ componentListeners.call ([this] (ComponentListener& l) { l.componentBeingDeleted (*this); });
masterReference.clear();
@@ -505,7 +505,7 @@ void Component::setName (const String& name)
peer->setTitle (name);
BailOutChecker checker (this);
- componentListeners.callChecked (checker, &ComponentListener::componentNameChanged, *this);
+ componentListeners.callChecked (checker, [this] (ComponentListener& l) { l.componentNameChanged (*this); });
}
}
@@ -569,7 +569,7 @@ void Component::sendVisibilityChangeMessage()
visibilityChanged();
if (! checker.shouldBailOut())
- componentListeners.callChecked (checker, &ComponentListener::componentVisibilityChanged, *this);
+ componentListeners.callChecked (checker, [this] (ComponentListener& l) { l.componentVisibilityChanged (*this); });
}
bool Component::isShowing() const
@@ -1207,8 +1207,7 @@ void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasRes
parentComponent->childBoundsChanged (this);
if (! checker.shouldBailOut())
- componentListeners.callChecked (checker, &ComponentListener::componentMovedOrResized,
- *this, wasMoved, wasResized);
+ componentListeners.callChecked (checker, [=] (ComponentListener& l) { l.componentMovedOrResized (*this, wasMoved, wasResized); });
}
void Component::setSize (int w, int h)
@@ -1661,7 +1660,7 @@ void Component::internalChildrenChanged()
childrenChanged();
if (! checker.shouldBailOut())
- componentListeners.callChecked (checker, &ComponentListener::componentChildrenChanged, *this);
+ componentListeners.callChecked (checker, [this] (ComponentListener& l) { l.componentChildrenChanged (*this); });
}
}
@@ -1674,7 +1673,7 @@ void Component::internalHierarchyChanged()
if (checker.shouldBailOut())
return;
- componentListeners.callChecked (checker, &ComponentListener::componentParentHierarchyChanged, *this);
+ componentListeners.callChecked (checker, [this] (ComponentListener& l) { l.componentParentHierarchyChanged (*this); });
if (checker.shouldBailOut())
return;
@@ -2387,7 +2386,7 @@ void Component::internalMouseEnter (MouseInputSource source, Point relati
if (checker.shouldBailOut())
return;
- Desktop::getInstance().getMouseListeners().callChecked (checker, &MouseListener::mouseEnter, me);
+ Desktop::getInstance().getMouseListeners().callChecked (checker, [&] (MouseListener& l) { l.mouseEnter (me); });
MouseListenerList::sendMouseEvent (*this, checker, &MouseListener::mouseEnter, me);
}
@@ -2416,7 +2415,7 @@ void Component::internalMouseExit (MouseInputSource source, Point relativ
if (checker.shouldBailOut())
return;
- Desktop::getInstance().getMouseListeners().callChecked (checker, &MouseListener::mouseExit, me);
+ Desktop::getInstance().getMouseListeners().callChecked (checker, [&] (MouseListener& l) { l.mouseExit (me); });
MouseListenerList::sendMouseEvent (*this, checker, &MouseListener::mouseExit, me);
}
@@ -2444,7 +2443,7 @@ void Component::internalMouseDown (MouseInputSource source, Point relativ
orientation, rotation, tiltX, tiltY, this, this, time, relativePos,
time, source.getNumberOfMultipleClicks(), false);
- desktop.getMouseListeners().callChecked (checker, &MouseListener::mouseDown, me);
+ desktop.getMouseListeners().callChecked (checker, [&] (MouseListener& l) { l.mouseDown (me); });
return;
}
}
@@ -2481,7 +2480,7 @@ void Component::internalMouseDown (MouseInputSource source, Point relativ
if (checker.shouldBailOut())
return;
- desktop.getMouseListeners().callChecked (checker, &MouseListener::mouseDown, me);
+ desktop.getMouseListeners().callChecked (checker, [&] (MouseListener& l) { l.mouseDown (me); });
MouseListenerList::sendMouseEvent (*this, checker, &MouseListener::mouseDown, me);
}
@@ -2509,7 +2508,7 @@ void Component::internalMouseUp (MouseInputSource source, Point relativeP
return;
auto& desktop = Desktop::getInstance();
- desktop.getMouseListeners().callChecked (checker, &MouseListener::mouseUp, me);
+ desktop.getMouseListeners().callChecked (checker, [&] (MouseListener& l) { l.mouseUp (me); });
MouseListenerList::sendMouseEvent (*this, checker, &MouseListener::mouseUp, me);
@@ -2524,7 +2523,7 @@ void Component::internalMouseUp (MouseInputSource source, Point relativeP
if (checker.shouldBailOut())
return;
- desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDoubleClick, me);
+ desktop.mouseListeners.callChecked (checker, [&] (MouseListener& l) { l.mouseDoubleClick (me); });
MouseListenerList::sendMouseEvent (*this, checker, &MouseListener::mouseDoubleClick, me);
}
}
@@ -2547,7 +2546,7 @@ void Component::internalMouseDrag (MouseInputSource source, Point relativ
if (checker.shouldBailOut())
return;
- Desktop::getInstance().getMouseListeners().callChecked (checker, &MouseListener::mouseDrag, me);
+ Desktop::getInstance().getMouseListeners().callChecked (checker, [&] (MouseListener& l) { l.mouseDrag (me); });
MouseListenerList::sendMouseEvent (*this, checker, &MouseListener::mouseDrag, me);
}
@@ -2575,7 +2574,7 @@ void Component::internalMouseMove (MouseInputSource source, Point relativ
if (checker.shouldBailOut())
return;
- desktop.getMouseListeners().callChecked (checker, &MouseListener::mouseMove, me);
+ desktop.getMouseListeners().callChecked (checker, [&] (MouseListener& l) { l.mouseMove (me); });
MouseListenerList::sendMouseEvent (*this, checker, &MouseListener::mouseMove, me);
}
@@ -2595,7 +2594,7 @@ void Component::internalMouseWheel (MouseInputSource source, Point relati
if (isCurrentlyBlockedByAnotherModalComponent())
{
// allow blocked mouse-events to go to global listeners..
- desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheel);
+ desktop.mouseListeners.callChecked (checker, [&] (MouseListener& l) { l.mouseWheelMove (me, wheel); });
}
else
{
@@ -2604,7 +2603,7 @@ void Component::internalMouseWheel (MouseInputSource source, Point relati
if (checker.shouldBailOut())
return;
- desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheel);
+ desktop.mouseListeners.callChecked (checker, [&] (MouseListener& l) { l.mouseWheelMove (me, wheel); });
if (! checker.shouldBailOut())
MouseListenerList::sendWheelEvent (*this, checker, me, wheel);
@@ -2654,7 +2653,7 @@ void Component::internalBroughtToFront()
if (checker.shouldBailOut())
return;
- componentListeners.callChecked (checker, &ComponentListener::componentBroughtToFront, *this);
+ componentListeners.callChecked (checker, [this] (ComponentListener& l) { l.componentBroughtToFront (*this); });
if (checker.shouldBailOut())
return;
@@ -2903,7 +2902,7 @@ void JUCE_CALLTYPE Component::unfocusAllComponents()
c->giveAwayFocus (true);
}
-void Component::giveAwayFocus (const bool sendFocusLossEvent)
+void Component::giveAwayFocus (bool sendFocusLossEvent)
{
auto* componentLosingFocus = currentlyFocusedComponent;
currentlyFocusedComponent = nullptr;
@@ -2933,7 +2932,7 @@ void Component::setEnabled (const bool shouldBeEnabled)
sendEnablementChangeMessage();
BailOutChecker checker (this);
- componentListeners.callChecked (checker, &ComponentListener::componentEnablementChanged, *this);
+ componentListeners.callChecked (checker, [this] (ComponentListener& l) { l.componentEnablementChanged (*this); });
}
}
diff --git a/modules/juce_gui_basics/components/juce_Desktop.cpp b/modules/juce_gui_basics/components/juce_Desktop.cpp
index edaf72f98b..27fdd37763 100644
--- a/modules/juce_gui_basics/components/juce_Desktop.cpp
+++ b/modules/juce_gui_basics/components/juce_Desktop.cpp
@@ -197,7 +197,7 @@ void Desktop::handleAsyncUpdate()
// The component may be deleted during this operation, but we'll use a SafePointer rather than a
// BailOutChecker so that any remaining listeners will still get a callback (with a null pointer).
WeakReference currentFocus (Component::getCurrentlyFocusedComponent());
- focusListeners.call (&FocusChangeListener::globalFocusChanged, currentFocus);
+ focusListeners.call ([&] (FocusChangeListener& l) { l.globalFocusChanged (currentFocus); });
}
//==============================================================================
@@ -248,8 +248,8 @@ void Desktop::sendMouseMove()
if (auto* target = findComponentAt (lastFakeMouseMove.roundToInt()))
{
Component::BailOutChecker checker (target);
- const Point pos (target->getLocalPoint (nullptr, lastFakeMouseMove));
- const Time now (Time::getCurrentTime());
+ auto pos = target->getLocalPoint (nullptr, lastFakeMouseMove);
+ auto now = Time::getCurrentTime();
const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(), MouseInputSource::invalidPressure,
MouseInputSource::invalidOrientation, MouseInputSource::invalidRotation,
@@ -257,9 +257,9 @@ void Desktop::sendMouseMove()
target, target, now, pos, now, 0, false);
if (me.mods.isAnyMouseButtonDown())
- mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
+ mouseListeners.callChecked (checker, [&] (MouseListener& l) { l.mouseDrag (me); });
else
- mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
+ mouseListeners.callChecked (checker, [&] (MouseListener& l) { l.mouseMove (me); });
}
}
}
diff --git a/modules/juce_gui_basics/filebrowser/juce_DirectoryContentsDisplayComponent.cpp b/modules/juce_gui_basics/filebrowser/juce_DirectoryContentsDisplayComponent.cpp
index b83d356253..ff42121ccb 100644
--- a/modules/juce_gui_basics/filebrowser/juce_DirectoryContentsDisplayComponent.cpp
+++ b/modules/juce_gui_basics/filebrowser/juce_DirectoryContentsDisplayComponent.cpp
@@ -47,7 +47,7 @@ void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* l)
void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
{
Component::BailOutChecker checker (dynamic_cast (this));
- listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
+ listeners.callChecked (checker, [] (FileBrowserListener& l) { l.selectionChanged(); });
}
void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
@@ -55,7 +55,7 @@ void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file,
if (directoryContentsList.getDirectory().exists())
{
Component::BailOutChecker checker (dynamic_cast (this));
- listeners.callChecked (checker, &FileBrowserListener::fileClicked, file, e);
+ listeners.callChecked (checker, [&] (FileBrowserListener& l) { l.fileClicked (file, e); });
}
}
@@ -64,7 +64,7 @@ void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file
if (directoryContentsList.getDirectory().exists())
{
Component::BailOutChecker checker (dynamic_cast (this));
- listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, file);
+ listeners.callChecked (checker, [&] (FileBrowserListener& l) { l.fileDoubleClicked (file); });
}
}
diff --git a/modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.cpp b/modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.cpp
index 456002e350..de343edba7 100644
--- a/modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.cpp
+++ b/modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.cpp
@@ -68,7 +68,7 @@ FileBrowserComponent::FileBrowserComponent (int flags_,
if ((flags & useTreeView) != 0)
{
- FileTreeComponent* const tree = new FileTreeComponent (*fileList);
+ auto tree = new FileTreeComponent (*fileList);
fileListComponent = tree;
if ((flags & canSelectMultipleItems) != 0)
@@ -78,7 +78,7 @@ FileBrowserComponent::FileBrowserComponent (int flags_,
}
else
{
- FileListComponent* const list = new FileListComponent (*fileList);
+ auto list = new FileListComponent (*fileList);
fileListComponent = list;
list->setOutlineThickness (1);
@@ -147,7 +147,7 @@ bool FileBrowserComponent::isSaveMode() const noexcept
int FileBrowserComponent::getNumSelectedFiles() const noexcept
{
- if (chosenFiles.size() == 0 && currentFileIsValid())
+ if (chosenFiles.isEmpty() && currentFileIsValid())
return 1;
return chosenFiles.size();
@@ -166,7 +166,7 @@ File FileBrowserComponent::getSelectedFile (int index) const noexcept
bool FileBrowserComponent::currentFileIsValid() const
{
- const File f (getSelectedFile (0));
+ auto f = getSelectedFile (0);
if (isSaveMode())
return (flags & canSelectDirectories) != 0 || ! f.isDirectory();
@@ -266,7 +266,7 @@ void FileBrowserComponent::setRoot (const File& newRootDirectory)
if (callListeners)
{
Component::BailOutChecker checker (this);
- listeners.callChecked (checker, &FileBrowserListener::browserRootChanged, currentRoot);
+ listeners.callChecked (checker, [&] (FileBrowserListener& l) { l.browserRootChanged (currentRoot); });
}
}
@@ -366,7 +366,7 @@ void FileBrowserComponent::sendListenerChangeMessage()
// You shouldn't delete the browser when the file gets changed!
jassert (! checker.shouldBailOut());
- listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
+ listeners.callChecked (checker, [] (FileBrowserListener& l) { l.selectionChanged(); });
}
void FileBrowserComponent::selectionChanged()
@@ -400,7 +400,7 @@ void FileBrowserComponent::selectionChanged()
void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
{
Component::BailOutChecker checker (this);
- listeners.callChecked (checker, &FileBrowserListener::fileClicked, f, e);
+ listeners.callChecked (checker, [&] (FileBrowserListener& l) { l.fileClicked (f, e); });
}
void FileBrowserComponent::fileDoubleClicked (const File& f)
@@ -415,7 +415,7 @@ void FileBrowserComponent::fileDoubleClicked (const File& f)
else
{
Component::BailOutChecker checker (this);
- listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, f);
+ listeners.callChecked (checker, [&] (FileBrowserListener& l) { l.fileDoubleClicked (f); });
}
}
@@ -489,11 +489,11 @@ void FileBrowserComponent::buttonClicked (Button*)
void FileBrowserComponent::comboBoxChanged (ComboBox*)
{
- const String newText (currentPathBox.getText().trim().unquoted());
+ auto newText = currentPathBox.getText().trim().unquoted();
if (newText.isNotEmpty())
{
- const int index = currentPathBox.getSelectedId() - 1;
+ auto index = currentPathBox.getSelectedId() - 1;
StringArray rootNames, rootPaths;
getRoots (rootNames, rootPaths);
diff --git a/modules/juce_gui_basics/filebrowser/juce_FilenameComponent.cpp b/modules/juce_gui_basics/filebrowser/juce_FilenameComponent.cpp
index 4fda4c4070..d3efecc638 100644
--- a/modules/juce_gui_basics/filebrowser/juce_FilenameComponent.cpp
+++ b/modules/juce_gui_basics/filebrowser/juce_FilenameComponent.cpp
@@ -175,7 +175,7 @@ String FilenameComponent::getCurrentFileText() const
File FilenameComponent::getCurrentFile() const
{
- File f (File::getCurrentWorkingDirectory().getChildFile (getCurrentFileText()));
+ auto f = File::getCurrentWorkingDirectory().getChildFile (getCurrentFileText());
if (enforcedSuffix.isNotEmpty())
f = f.withFileExtension (enforcedSuffix);
@@ -244,7 +244,7 @@ void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
void FilenameComponent::addRecentlyUsedFile (const File& file)
{
- StringArray files (getRecentlyUsedFilenames());
+ auto files = getRecentlyUsedFilenames();
if (file.getFullPathName().isNotEmpty())
{
@@ -269,7 +269,7 @@ void FilenameComponent::removeListener (FilenameComponentListener* const listene
void FilenameComponent::handleAsyncUpdate()
{
Component::BailOutChecker checker (this);
- listeners.callChecked (checker, &FilenameComponentListener::filenameComponentChanged, this);
+ listeners.callChecked (checker, [this] (FilenameComponentListener& l) { l.filenameComponentChanged (this); });
}
} // namespace juce
diff --git a/modules/juce_gui_basics/layout/juce_AnimatedPosition.h b/modules/juce_gui_basics/layout/juce_AnimatedPosition.h
index 7b4b320f4e..dccf55df2a 100644
--- a/modules/juce_gui_basics/layout/juce_AnimatedPosition.h
+++ b/modules/juce_gui_basics/layout/juce_AnimatedPosition.h
@@ -160,14 +160,14 @@ private:
static double getSpeed (const Time last, double lastPos,
const Time now, double newPos)
{
- const double elapsedSecs = jmax (0.005, (now - last).inSeconds());
- const double v = (newPos - lastPos) / elapsedSecs;
+ auto elapsedSecs = jmax (0.005, (now - last).inSeconds());
+ auto v = (newPos - lastPos) / elapsedSecs;
return std::abs (v) > 0.2 ? v : 0.0;
}
void moveTo (double newPos)
{
- const Time now (Time::getCurrentTime());
+ auto now = Time::getCurrentTime();
releaseVelocity = getSpeed (lastDrag, position, now, newPos);
behaviour.releasedWithVelocity (newPos, releaseVelocity);
lastDrag = now;
@@ -182,18 +182,16 @@ private:
if (position != newPosition)
{
position = newPosition;
- listeners.call (&Listener::positionChanged, *this, newPosition);
+ listeners.call ([this, newPosition] (Listener& l) { l.positionChanged (*this, newPosition); });
}
}
void timerCallback() override
{
- const Time now = Time::getCurrentTime();
-
- const double elapsed = jlimit (0.001, 0.020, (now - lastUpdate).inSeconds());
+ auto now = Time::getCurrentTime();
+ auto elapsed = jlimit (0.001, 0.020, (now - lastUpdate).inSeconds());
lastUpdate = now;
-
- const double newPos = behaviour.getNextPosition (position, elapsed);
+ auto newPos = behaviour.getNextPosition (position, elapsed);
if (behaviour.isStopped (newPos))
stopTimer();
diff --git a/modules/juce_gui_basics/layout/juce_ScrollBar.cpp b/modules/juce_gui_basics/layout/juce_ScrollBar.cpp
index 056d4ecc4a..c0107d2658 100644
--- a/modules/juce_gui_basics/layout/juce_ScrollBar.cpp
+++ b/modules/juce_gui_basics/layout/juce_ScrollBar.cpp
@@ -171,14 +171,14 @@ void ScrollBar::removeListener (Listener* const listener)
void ScrollBar::handleAsyncUpdate()
{
- double start = visibleRange.getStart(); // (need to use a temp variable for VC7 compatibility)
- listeners.call (&ScrollBar::Listener::scrollBarMoved, this, start);
+ auto start = visibleRange.getStart(); // (need to use a temp variable for VC7 compatibility)
+ listeners.call ([=] (Listener& l) { l.scrollBarMoved (this, start); });
}
//==============================================================================
void ScrollBar::updateThumbPosition()
{
- const int minimumScrollBarThumbSize = getLookAndFeel().getMinimumScrollbarThumbSize (*this);
+ auto minimumScrollBarThumbSize = getLookAndFeel().getMinimumScrollbarThumbSize (*this);
int newThumbSize = roundToInt (totalRange.getLength() > 0 ? (visibleRange.getLength() * thumbAreaSize) / totalRange.getLength()
: thumbAreaSize);
diff --git a/modules/juce_gui_basics/menus/juce_MenuBarModel.cpp b/modules/juce_gui_basics/menus/juce_MenuBarModel.cpp
index fcc06afe98..0c599e43f8 100644
--- a/modules/juce_gui_basics/menus/juce_MenuBarModel.cpp
+++ b/modules/juce_gui_basics/menus/juce_MenuBarModel.cpp
@@ -75,12 +75,12 @@ void MenuBarModel::removeListener (Listener* const listenerToRemove) noexcept
//==============================================================================
void MenuBarModel::handleAsyncUpdate()
{
- listeners.call (&MenuBarModel::Listener::menuBarItemsChanged, this);
+ listeners.call ([this] (Listener& l) { l.menuBarItemsChanged (this); });
}
void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
{
- listeners.call (&MenuBarModel::Listener::menuCommandInvoked, this, info);
+ listeners.call ([this, &info] (Listener& l) { l.menuCommandInvoked (this, info); });
}
void MenuBarModel::applicationCommandListChanged()
@@ -91,7 +91,7 @@ void MenuBarModel::applicationCommandListChanged()
void MenuBarModel::handleMenuBarActivate (bool isActive)
{
menuBarActivated (isActive);
- listeners.call (&MenuBarModel::Listener::menuBarActivated, this, isActive);
+ listeners.call ([this, isActive] (Listener& l) { l.menuBarActivated (this, isActive); });
}
void MenuBarModel::menuBarActivated (bool) {}
diff --git a/modules/juce_gui_basics/mouse/juce_MouseInactivityDetector.cpp b/modules/juce_gui_basics/mouse/juce_MouseInactivityDetector.cpp
index 45b35219a0..b5053e4535 100644
--- a/modules/juce_gui_basics/mouse/juce_MouseInactivityDetector.cpp
+++ b/modules/juce_gui_basics/mouse/juce_MouseInactivityDetector.cpp
@@ -27,8 +27,7 @@
namespace juce
{
-MouseInactivityDetector::MouseInactivityDetector (Component& c)
- : targetComp (c), delayMs (1500), toleranceDistance (15), isActive (true)
+MouseInactivityDetector::MouseInactivityDetector (Component& c) : targetComp (c)
{
targetComp.addMouseListener (this, true);
}
@@ -51,7 +50,7 @@ void MouseInactivityDetector::timerCallback()
void MouseInactivityDetector::wakeUp (const MouseEvent& e, bool alwaysWake)
{
- const Point newPos (e.getEventRelativeTo (&targetComp).getPosition());
+ auto newPos = e.getEventRelativeTo (&targetComp).getPosition();
if ((! isActive) && (alwaysWake || e.source.isTouch() || newPos.getDistanceFrom (lastMousePos) > toleranceDistance))
setActive (true);
@@ -69,8 +68,10 @@ void MouseInactivityDetector::setActive (bool b)
{
isActive = b;
- listenerList.call (b ? &Listener::mouseBecameActive
- : &Listener::mouseBecameInactive);
+ if (isActive)
+ listenerList.call ([] (Listener& l) { l.mouseBecameActive(); });
+ else
+ listenerList.call ([] (Listener& l) { l.mouseBecameInactive(); });
}
}
diff --git a/modules/juce_gui_basics/mouse/juce_MouseInactivityDetector.h b/modules/juce_gui_basics/mouse/juce_MouseInactivityDetector.h
index f8c6a5e555..a965743573 100644
--- a/modules/juce_gui_basics/mouse/juce_MouseInactivityDetector.h
+++ b/modules/juce_gui_basics/mouse/juce_MouseInactivityDetector.h
@@ -90,8 +90,8 @@ private:
Component& targetComp;
ListenerList listenerList;
Point lastMousePos;
- int delayMs, toleranceDistance;
- bool isActive;
+ int delayMs = 1500, toleranceDistance = 15;
+ bool isActive = true;
void timerCallback() override;
void wakeUp (const MouseEvent&, bool alwaysWake);
diff --git a/modules/juce_gui_basics/positioning/juce_MarkerList.cpp b/modules/juce_gui_basics/positioning/juce_MarkerList.cpp
index 7646943d31..b5b83253c8 100644
--- a/modules/juce_gui_basics/positioning/juce_MarkerList.cpp
+++ b/modules/juce_gui_basics/positioning/juce_MarkerList.cpp
@@ -50,7 +50,7 @@ MarkerList& MarkerList::operator= (const MarkerList& other)
MarkerList::~MarkerList()
{
- listeners.call (&MarkerList::Listener::markerListBeingDeleted, this);
+ listeners.call ([this] (Listener& l) { l.markerListBeingDeleted (this); });
}
bool MarkerList::operator== (const MarkerList& other) const noexcept
@@ -148,7 +148,7 @@ void MarkerList::removeMarker (const String& name)
void MarkerList::markersHaveChanged()
{
- listeners.call (&MarkerList::Listener::markersChanged, this);
+ listeners.call ([this] (Listener& l) { l.markersChanged (this); });
}
void MarkerList::Listener::markerListBeingDeleted (MarkerList*)
diff --git a/modules/juce_gui_basics/properties/juce_TextPropertyComponent.cpp b/modules/juce_gui_basics/properties/juce_TextPropertyComponent.cpp
index 290b8fd478..9bff521da4 100644
--- a/modules/juce_gui_basics/properties/juce_TextPropertyComponent.cpp
+++ b/modules/juce_gui_basics/properties/juce_TextPropertyComponent.cpp
@@ -170,7 +170,7 @@ void TextPropertyComponent::removeListener (TextPropertyComponentListener* const
void TextPropertyComponent::callListeners()
{
Component::BailOutChecker checker (this);
- listenerList.callChecked (checker, &TextPropertyComponentListener::textPropertyComponentChanged, this);
+ listenerList.callChecked (checker, [this] (Listener& l) { l.textPropertyComponentChanged (this); });
}
void TextPropertyComponent::colourChanged()
diff --git a/modules/juce_gui_basics/widgets/juce_ComboBox.cpp b/modules/juce_gui_basics/widgets/juce_ComboBox.cpp
index f3ff747841..d367956236 100644
--- a/modules/juce_gui_basics/widgets/juce_ComboBox.cpp
+++ b/modules/juce_gui_basics/widgets/juce_ComboBox.cpp
@@ -629,7 +629,7 @@ void ComboBox::removeListener (ComboBoxListener* listener) { listeners.remove
void ComboBox::handleAsyncUpdate()
{
Component::BailOutChecker checker (this);
- listeners.callChecked (checker, &ComboBox::Listener::comboBoxChanged, this);
+ listeners.callChecked (checker, [this] (Listener& l) { l.comboBoxChanged (this); });
}
void ComboBox::sendChange (const NotificationType notification)
diff --git a/modules/juce_gui_basics/widgets/juce_Label.cpp b/modules/juce_gui_basics/widgets/juce_Label.cpp
index 3640e730c8..ac51d54491 100644
--- a/modules/juce_gui_basics/widgets/juce_Label.cpp
+++ b/modules/juce_gui_basics/widgets/juce_Label.cpp
@@ -154,7 +154,7 @@ void Label::attachToComponent (Component* owner, const bool onLeft)
void Label::componentMovedOrResized (Component& component, bool /*wasMoved*/, bool /*wasResized*/)
{
- const Font f (getLookAndFeel().getLabelFont (*this));
+ auto f = getLookAndFeel().getLabelFont (*this);
if (leftOfOwnerComp)
{
@@ -191,16 +191,16 @@ void Label::textWasChanged() {}
void Label::editorShown (TextEditor* textEditor)
{
Component::BailOutChecker checker (this);
- listeners.callChecked (checker, &LabelListener::editorShown, this, *textEditor);
+ listeners.callChecked (checker, [this, textEditor] (LabelListener& l) { l.editorShown (this, *textEditor); });
}
void Label::editorAboutToBeHidden (TextEditor* textEditor)
{
- if (ComponentPeer* const peer = getPeer())
+ if (auto* peer = getPeer())
peer->dismissPendingTextInput();
Component::BailOutChecker checker (this);
- listeners.callChecked (checker, &LabelListener::editorHidden, this, *textEditor);
+ listeners.callChecked (checker, [this, textEditor] (LabelListener& l) { l.editorHidden (this, *textEditor); });
}
void Label::showEditor()
@@ -230,7 +230,7 @@ void Label::showEditor()
bool Label::updateFromTextEditorContents (TextEditor& ed)
{
- const String newText (ed.getText());
+ auto newText = ed.getText();
if (textValue.toString() != newText)
{
@@ -409,7 +409,7 @@ void Label::removeListener (LabelListener* const listener)
void Label::callChangeListeners()
{
Component::BailOutChecker checker (this);
- listeners.callChecked (checker, &Label::Listener::labelTextChanged, this);
+ listeners.callChecked (checker, [this] (Listener& l) { l.labelTextChanged (this); });
}
//==============================================================================
diff --git a/modules/juce_gui_basics/widgets/juce_Slider.cpp b/modules/juce_gui_basics/widgets/juce_Slider.cpp
index 664ffd42c7..c6c8f77ed3 100644
--- a/modules/juce_gui_basics/widgets/juce_Slider.cpp
+++ b/modules/juce_gui_basics/widgets/juce_Slider.cpp
@@ -320,8 +320,7 @@ public:
cancelPendingUpdate();
Component::BailOutChecker checker (&owner);
- Slider* slider = &owner; // (must use an intermediate variable here to avoid a VS2005 compiler bug)
- listeners.callChecked (checker, &Slider::Listener::sliderValueChanged, slider);
+ listeners.callChecked (checker, [&] (Slider::Listener& l) { l.sliderValueChanged (&owner); });
}
void sendDragStart()
@@ -329,19 +328,16 @@ public:
owner.startedDragging();
Component::BailOutChecker checker (&owner);
- Slider* slider = &owner; // (must use an intermediate variable here to avoid a VS2005 compiler bug)
- listeners.callChecked (checker, &Slider::Listener::sliderDragStarted, slider);
+ listeners.callChecked (checker, [&] (Slider::Listener& l) { l.sliderDragStarted (&owner); });
}
void sendDragEnd()
{
owner.stoppedDragging();
-
sliderBeingDragged = -1;
Component::BailOutChecker checker (&owner);
- Slider* slider = &owner; // (must use an intermediate variable here to avoid a VS2005 compiler bug)
- listeners.callChecked (checker, &Slider::Listener::sliderDragEnded, slider);
+ listeners.callChecked (checker, [&] (Slider::Listener& l) { l.sliderDragEnded (&owner); });
}
struct DragInProgress
diff --git a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp
index da5190a3b2..ca3af1f372 100644
--- a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp
+++ b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp
@@ -2098,20 +2098,20 @@ void TextEditor::handleCommandMessage (const int commandId)
switch (commandId)
{
case TextEditorDefs::textChangeMessageId:
- listeners.callChecked (checker, &Listener::textEditorTextChanged, (TextEditor&) *this);
+ listeners.callChecked (checker, [this] (Listener& l) { l.textEditorTextChanged (*this); });
break;
case TextEditorDefs::returnKeyMessageId:
- listeners.callChecked (checker, &Listener::textEditorReturnKeyPressed, (TextEditor&) *this);
+ listeners.callChecked (checker, [this] (Listener& l) { l.textEditorReturnKeyPressed (*this); });
break;
case TextEditorDefs::escapeKeyMessageId:
- listeners.callChecked (checker, &Listener::textEditorEscapeKeyPressed, (TextEditor&) *this);
+ listeners.callChecked (checker, [this] (Listener& l) { l.textEditorEscapeKeyPressed (*this); });
break;
case TextEditorDefs::focusLossMessageId:
updateValueFromText();
- listeners.callChecked (checker, &Listener::textEditorFocusLost, (TextEditor&) *this);
+ listeners.callChecked (checker, [this] (Listener& l) { l.textEditorFocusLost (*this); });
break;
default:
diff --git a/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp b/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp
index 2c3cd4355c..bfe6d0e6f3 100644
--- a/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp
+++ b/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp
@@ -841,7 +841,7 @@ void CodeDocument::insert (const String& text, const int insertPos, const bool u
if (p->getPosition() >= insertPos)
p->setPosition (p->getPosition() + newTextLength);
- listeners.call (&CodeDocument::Listener::codeDocumentTextInserted, text, insertPos);
+ listeners.call ([&] (Listener& l) { l.codeDocumentTextInserted (text, insertPos); });
}
}
}
@@ -935,7 +935,7 @@ void CodeDocument::remove (const int startPos, const int endPos, const bool undo
p->setPosition (totalChars);
}
- listeners.call (&CodeDocument::Listener::codeDocumentTextDeleted, startPos, endPos);
+ listeners.call ([=] (Listener& l) { l.codeDocumentTextDeleted (startPos, endPos); });
}
}
diff --git a/modules/juce_gui_extra/misc/juce_PushNotifications.cpp b/modules/juce_gui_extra/misc/juce_PushNotifications.cpp
index 62c4de567c..c1efbc0dc0 100644
--- a/modules/juce_gui_extra/misc/juce_PushNotifications.cpp
+++ b/modules/juce_gui_extra/misc/juce_PushNotifications.cpp
@@ -53,7 +53,7 @@ void PushNotifications::requestPermissionsWithSettings (const PushNotifications:
pimpl->requestPermissionsWithSettings (settings);
#else
ignoreUnused (settings);
- listeners.call (&PushNotifications::Listener::notificationSettingsReceived, {});
+ listeners.call ([] (Listener& l) { l.notificationSettingsReceived ({}); });
#endif
}
@@ -62,7 +62,7 @@ void PushNotifications::requestSettingsUsed()
#if JUCE_PUSH_NOTIFICATIONS && (JUCE_IOS || JUCE_MAC)
pimpl->requestSettingsUsed();
#else
- listeners.call (&PushNotifications::Listener::notificationSettingsReceived, {});
+ listeners.call ([] (Listener& l) { l.notificationSettingsReceived ({}); });
#endif
}
diff --git a/modules/juce_gui_extra/native/juce_android_PushNotifications.cpp b/modules/juce_gui_extra/native/juce_android_PushNotifications.cpp
index 787450cb49..e0d16a01a7 100644
--- a/modules/juce_gui_extra/native/juce_android_PushNotifications.cpp
+++ b/modules/juce_gui_extra/native/juce_android_PushNotifications.cpp
@@ -377,11 +377,11 @@ struct PushNotifications::Pimpl
}
}
- owner.listeners.call (&Listener::deliveredNotificationsListReceived, notifications);
+ owner.listeners.call ([&] (Listener& l) { l.deliveredNotificationsListReceived (notifications); });
#else
// Not supported on this platform
jassertfalse;
- owner.listeners.call (&Listener::deliveredNotificationsListReceived, {});
+ owner.listeners.call ([] (Listener& l) { l.deliveredNotificationsListReceived ({}); });
#endif
}
@@ -403,25 +403,21 @@ struct PushNotifications::Pimpl
if (actionString.contains (notificationString))
{
- owner.listeners.call (&PushNotifications::Listener::handleNotification, true, notification);
+ owner.listeners.call ([&] (Listener& l) { l.handleNotification (true, notification); });
}
else if (actionString.contains (notificationButtonActionString))
{
- String prefix = notificationButtonActionString + notification.identifier + ".";
+ auto prefix = notificationButtonActionString + notification.identifier + ".";
auto actionTitle = actionString.fromLastOccurrenceOf (prefix, false, false) // skip prefix
.fromFirstOccurrenceOf (".", false, false); // skip action index
- owner.listeners.call (&PushNotifications::Listener::handleNotificationAction,
- true,
- notification,
- actionTitle,
- {});
+ owner.listeners.call ([&] (Listener& l) { l.handleNotificationAction (true, notification, actionTitle, {}); });
}
#if __ANDROID_API__ >= 20
else if (actionString.contains (notificationTextInputActionString))
{
- String prefix = notificationTextInputActionString + notification.identifier + ".";
+ auto prefix = notificationTextInputActionString + notification.identifier + ".";
auto actionTitle = actionString.fromLastOccurrenceOf (prefix, false, false) // skip prefix
.fromFirstOccurrenceOf (".", false, false); // skip action index
@@ -430,26 +426,16 @@ struct PushNotifications::Pimpl
auto resultKeyString = javaString (actionTitle + actionIndex);
auto remoteInputResult = LocalRef (env->CallStaticObjectMethod (RemoteInput, RemoteInput.getResultsFromIntent, intent.get()));
+ String responseString;
if (remoteInputResult.get() != 0)
{
auto charSequence = LocalRef (env->CallObjectMethod (remoteInputResult, JavaBundle.getCharSequence, resultKeyString.get()));
- auto responseString = LocalRef ((jstring) env->CallObjectMethod (charSequence, JavaCharSequence.toString));
+ auto responseStringRef = LocalRef ((jstring) env->CallObjectMethod (charSequence, JavaCharSequence.toString));
+ responseString = juceString (responseStringRef.get());
+ }
- owner.listeners.call (&PushNotifications::Listener::handleNotificationAction,
- true,
- notification,
- actionTitle,
- juceString (responseString.get()));
- }
- else
- {
- owner.listeners.call (&PushNotifications::Listener::handleNotificationAction,
- true,
- notification,
- actionTitle,
- {});
- }
+ owner.listeners.call ([&] (Listener& l) { l.handleNotificationAction (true, notification, actionTitle, responseString); });
}
#endif
}
@@ -459,9 +445,9 @@ struct PushNotifications::Pimpl
auto* env = getEnv();
auto bundle = LocalRef (env->CallObjectMethod (intent, AndroidIntent.getExtras));
+ auto notification = localNotificationBundleToJuceNotification (bundle);
- owner.listeners.call (&PushNotifications::Listener::localNotificationDismissedByUser,
- localNotificationBundleToJuceNotification (bundle));
+ owner.listeners.call ([&] (Listener& l) { l.localNotificationDismissedByUser (notification); });
}
void removeAllDeliveredNotifications()
@@ -507,9 +493,9 @@ struct PushNotifications::Pimpl
{
#if defined(JUCE_FIREBASE_INSTANCE_ID_SERVICE_CLASSNAME)
MessageManager::callAsync ([this, token]()
- {
- owner.listeners.call (&PushNotifications::Listener::deviceTokenRefreshed, token);
- });
+ {
+ owner.listeners.call ([&] (Listener& l) { l.deviceTokenRefreshed (token); });
+ });
#else
ignoreUnused (token);
#endif
@@ -588,9 +574,9 @@ struct PushNotifications::Pimpl
auto* env = getEnv();
auto bundle = LocalRef (env->CallObjectMethod (intent, AndroidIntent.getExtras));
+ auto notification = remoteNotificationBundleToJuceNotification (bundle);
- owner.listeners.call (&PushNotifications::Listener::handleNotification, false,
- remoteNotificationBundleToJuceNotification (bundle));
+ owner.listeners.call ([&] (Listener& l) { l.handleNotification (false, notification); });
#else
ignoreUnused (intent);
#endif
@@ -603,8 +589,8 @@ struct PushNotifications::Pimpl
MessageManager::callAsync ([this, rn]()
{
- owner.listeners.call (&PushNotifications::Listener::handleNotification, false,
- firebaseRemoteNotificationToJuceNotification (rn.get()));
+ auto notification = firebaseRemoteNotificationToJuceNotification (rn.get());
+ owner.listeners.call ([&] (Listener& l) { l.handleNotification (false, notification); });
});
#else
ignoreUnused (remoteNotification);
@@ -615,9 +601,9 @@ struct PushNotifications::Pimpl
{
#if defined(JUCE_FIREBASE_MESSAGING_SERVICE_CLASSNAME)
MessageManager::callAsync ([this]()
- {
- owner.listeners.call (&PushNotifications::Listener::remoteNotificationsDeleted);
- });
+ {
+ owner.listeners.call ([] (Listener& l) { l.remoteNotificationsDeleted(); });
+ });
#endif
}
@@ -627,10 +613,10 @@ struct PushNotifications::Pimpl
GlobalRef mid (messageId);
MessageManager::callAsync ([this, mid]()
- {
- owner.listeners.call (&PushNotifications::Listener::upstreamMessageSent,
- juceString ((jstring) mid.get()));
- });
+ {
+ auto midString = juceString ((jstring) mid.get());
+ owner.listeners.call ([&] (Listener& l) { l.upstreamMessageSent (midString); });
+ });
#else
ignoreUnused (messageId);
#endif
@@ -643,11 +629,12 @@ struct PushNotifications::Pimpl
GlobalRef mid (messageId), e (error);
MessageManager::callAsync ([this, mid, e]()
- {
- owner.listeners.call (&PushNotifications::Listener::upstreamMessageSendingError,
- juceString ((jstring) mid.get()),
- juceString ((jstring) e.get()));
- });
+ {
+ auto midString = juceString ((jstring) mid.get());
+ auto eString = juceString ((jstring) e.get());
+
+ owner.listeners.call ([&] (Listener& l) { l.upstreamMessageSendingError (midString, eString); });
+ });
#else
ignoreUnused (messageId, error);
#endif
diff --git a/modules/juce_gui_extra/native/juce_ios_PushNotifications.cpp b/modules/juce_gui_extra/native/juce_ios_PushNotifications.cpp
index 74fdd65ff3..df00c2744b 100644
--- a/modules/juce_gui_extra/native/juce_ios_PushNotifications.cpp
+++ b/modules/juce_gui_extra/native/juce_ios_PushNotifications.cpp
@@ -644,7 +644,7 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
for (UIUserNotificationCategory *c in s.categories)
settings.categories.add (PushNotificationsDelegateDetails::uiUserNotificationCategoryToCategory (c));
- owner.listeners.call (&PushNotifications::Listener::notificationSettingsReceived, settings);
+ owner.listeners.call ([&] (Listener& l) { l.notificationSettingsReceived (settings); });
}
#if defined (__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
else
@@ -663,7 +663,7 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
for (UNNotificationCategory* c in categories)
settings.categories.add (PushNotificationsDelegateDetails::unNotificationCategoryToCategory (c));
- owner.listeners.call (&PushNotifications::Listener::notificationSettingsReceived, settings);
+ owner.listeners.call ([&] (Listener& l) { l.notificationSettingsReceived (settings); });
}
];
@@ -707,7 +707,7 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
{
// Not supported on this platform
jassertfalse;
- owner.listeners.call (&Listener::deliveredNotificationsListReceived, {});
+ owner.listeners.call ([] (Listener& l) { l.deliveredNotificationsListReceived ({}); });
}
#if defined (__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
else
@@ -720,7 +720,7 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
for (UNNotification* n in notifications)
notifs.add (PushNotificationsDelegateDetails::unNotificationToJuceNotification (n));
- owner.listeners.call (&Listener::deliveredNotificationsListReceived, notifs);
+ owner.listeners.call ([&] (Listener& l) { l.deliveredNotificationsListReceived (notifs); });
}];
}
#endif
@@ -775,7 +775,7 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
for (UILocalNotification* n in [UIApplication sharedApplication].scheduledLocalNotifications)
notifs.add (PushNotificationsDelegateDetails::uiLocalNotificationToJuceNotification (n));
- owner.listeners.call (&PushNotifications::Listener::pendingLocalNotificationsListReceived, notifs);
+ owner.listeners.call ([&] (Listener& l) { l.pendingLocalNotificationsListReceived (notifs); });
}
#if defined (__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
else
@@ -789,7 +789,7 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
for (UNNotificationRequest* r : requests)
notifs.add (PushNotificationsDelegateDetails::unNotificationRequestToJuceNotification (r));
- owner.listeners.call (&PushNotifications::Listener::pendingLocalNotificationsListReceived, notifs);
+ owner.listeners.call ([&] (Listener& l) { l.pendingLocalNotificationsListReceived (notifs); });
}
];
}
@@ -854,7 +854,7 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
initialised = true;
- owner.listeners.call (&PushNotifications::Listener::deviceTokenRefreshed, deviceToken);
+ owner.listeners.call ([&] (Listener& l) { l.deviceTokenRefreshed (deviceToken); });
}
void failedToRegisterForRemoteNotifications (NSError* error) override
@@ -868,16 +868,13 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
{
auto n = PushNotificationsDelegateDetails::nsDictionaryToJuceNotification (userInfo);
- owner.listeners.call (&PushNotifications::Listener::handleNotification, false, n);
+ owner.listeners.call ([&] (Listener& l) { l.handleNotification (false, n); });
}
void didReceiveRemoteNotificationFetchCompletionHandler (NSDictionary* userInfo,
void (^completionHandler)(UIBackgroundFetchResult result)) override
{
- auto n = PushNotificationsDelegateDetails::nsDictionaryToJuceNotification (userInfo);
-
- owner.listeners.call (&PushNotifications::Listener::handleNotification, false, n);
-
+ didReceiveRemoteNotification (userInfo);
completionHandler (UIBackgroundFetchResultNewData);
}
@@ -890,7 +887,7 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
auto actionString = nsStringToJuce (actionIdentifier);
auto response = PushNotificationsDelegateDetails::getUserResponseFromNSDictionary (responseInfo);
- owner.listeners.call (&PushNotifications::Listener::handleNotificationAction, false, n, actionString, response);
+ owner.listeners.call ([&] (Listener& l) { l.handleNotificationAction (false, n, actionString, response); });
completionHandler();
}
@@ -899,7 +896,7 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
{
auto n = PushNotificationsDelegateDetails::uiLocalNotificationToJuceNotification (notification);
- owner.listeners.call (&PushNotifications::Listener::handleNotification, true, n);
+ owner.listeners.call ([&] (Listener& l) { l.handleNotification (true, n); });
}
void handleActionForLocalNotificationCompletionHandler (NSString* actionIdentifier,
@@ -921,7 +918,7 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
auto actionString = nsStringToJuce (actionIdentifier);
auto response = PushNotificationsDelegateDetails::getUserResponseFromNSDictionary (responseInfo);
- owner.listeners.call (&PushNotifications::Listener::handleNotificationAction, true, n, actionString, response);
+ owner.listeners.call ([&] (Listener& l) { l.handleNotificationAction (true, n, actionString, response); });
completionHandler();
}
@@ -961,8 +958,7 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
responseString = nsStringToJuce (textResponse.userText);
}
- owner.listeners.call (&PushNotifications::Listener::handleNotificationAction, ! remote, n, actionString, responseString);
-
+ owner.listeners.call ([&] (Listener& l) { l.handleNotificationAction (! remote, n, actionString, responseString); });
completionHandler();
}
#endif
diff --git a/modules/juce_gui_extra/native/juce_mac_PushNotifications.cpp b/modules/juce_gui_extra/native/juce_mac_PushNotifications.cpp
index 47a9a1df9f..2b3673c84e 100644
--- a/modules/juce_gui_extra/native/juce_mac_PushNotifications.cpp
+++ b/modules/juce_gui_extra/native/juce_mac_PushNotifications.cpp
@@ -379,7 +379,7 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
if (isEarlierThanLion)
{
// no settings available
- owner.listeners.call (&PushNotifications::Listener::notificationSettingsReceived, {});
+ owner.listeners.call ([] (Listener& l) { l.notificationSettingsReceived ({}); });
return;
}
@@ -391,7 +391,7 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
settings.allowAlert = [NSApplication sharedApplication].enabledRemoteNotificationTypes & NSRemoteNotificationTypeAlert;
}
- owner.listeners.call (&PushNotifications::Listener::notificationSettingsReceived, settings);
+ owner.listeners.call ([&] (Listener& l) { l.notificationSettingsReceived (settings); });
}
bool areNotificationsEnabled() const { return true; }
@@ -410,7 +410,7 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
for (NSUserNotification* n in [NSUserNotificationCenter defaultUserNotificationCenter].deliveredNotifications)
notifs.add (PushNotificationsDelegateDetailsOsx::nsUserNotificationToJuceNotification (n, isEarlierThanMavericks, isEarlierThanYosemite));
- owner.listeners.call (&Listener::deliveredNotificationsListReceived, notifs);
+ owner.listeners.call ([&] (Listener& l) { l.deliveredNotificationsListReceived (notifs); });
}
void removeAllDeliveredNotifications()
@@ -440,7 +440,7 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
for (NSUserNotification* n in [NSUserNotificationCenter defaultUserNotificationCenter].scheduledNotifications)
notifs.add (PushNotificationsDelegateDetailsOsx::nsUserNotificationToJuceNotification (n, isEarlierThanMavericks, isEarlierThanYosemite));
- owner.listeners.call (&PushNotifications::Listener::pendingLocalNotificationsListReceived, notifs);
+ owner.listeners.call ([&] (Listener& l) { l.pendingLocalNotificationsListReceived (notifs); });
}
void removePendingLocalNotification (const String& identifier)
@@ -480,47 +480,45 @@ struct PushNotifications::Pimpl : private PushNotificationsDelegate
initialised = true;
- owner.listeners.call (&PushNotifications::Listener::deviceTokenRefreshed, deviceToken);
+ owner.listeners.call ([&] (Listener& l) { l.deviceTokenRefreshed (deviceToken); });
}
void failedToRegisterForRemoteNotifications (NSError* error) override
{
ignoreUnused (error);
-
deviceToken.clear();
}
void didReceiveRemoteNotification (NSDictionary* userInfo) override
{
auto n = PushNotificationsDelegateDetailsOsx::nsDictionaryToJuceNotification (userInfo);
-
- owner.listeners.call (&PushNotifications::Listener::handleNotification, true, n);
+ owner.listeners.call ([&] (Listener& l) { l.handleNotification (true, n); });
}
- void didDeliverNotification (NSUserNotification* notification) override
+ void didDeliverNotification (NSUserNotification* notification) override
{
ignoreUnused (notification);
}
- void didActivateNotification (NSUserNotification* notification) override
+ void didActivateNotification (NSUserNotification* notification) override
{
auto n = PushNotificationsDelegateDetailsOsx::nsUserNotificationToJuceNotification (notification, isEarlierThanMavericks, isEarlierThanYosemite);
if (notification.activationType == NSUserNotificationActivationTypeContentsClicked)
{
- owner.listeners.call (&PushNotifications::Listener::handleNotification, notification.remote, n);
+ owner.listeners.call ([&] (Listener& l) { l.handleNotification (notification.remote, n); });
}
else
{
auto actionIdentifier = (! isEarlierThanYosemite && notification.additionalActivationAction != nil)
- ? nsStringToJuce (notification.additionalActivationAction.identifier)
- : nsStringToJuce (notification.actionButtonTitle);
+ ? nsStringToJuce (notification.additionalActivationAction.identifier)
+ : nsStringToJuce (notification.actionButtonTitle);
auto reply = notification.activationType == NSUserNotificationActivationTypeReplied
- ? nsStringToJuce ([notification.response string])
- : String();
+ ? nsStringToJuce ([notification.response string])
+ : String();
- owner.listeners.call (&PushNotifications::Listener::handleNotificationAction, notification.remote, n, actionIdentifier, reply);
+ owner.listeners.call ([&] (Listener& l) { l.handleNotificationAction (notification.remote, n, actionIdentifier, reply); });
}
}
diff --git a/modules/juce_osc/osc/juce_OSCReceiver.cpp b/modules/juce_osc/osc/juce_OSCReceiver.cpp
index 56f31e9be9..7dfcbba082 100644
--- a/modules/juce_osc/osc/juce_OSCReceiver.cpp
+++ b/modules/juce_osc/osc/juce_OSCReceiver.cpp
@@ -518,9 +518,15 @@ private:
typedef OSCReceiver::Listener Listener;
if (content.isMessage())
- listeners.call (&Listener::oscMessageReceived, content.getMessage());
+ {
+ auto&& message = content.getMessage();
+ listeners.call ([&] (Listener& l) { l.oscMessageReceived (message); });
+ }
else if (content.isBundle())
- listeners.call (&Listener::oscBundleReceived, content.getBundle());
+ {
+ auto&& bundle = content.getBundle();
+ listeners.call ([&] (Listener& l) { l.oscBundleReceived (bundle); });
+ }
}
void callRealtimeListeners (const OSCBundle::Element& content)
@@ -528,9 +534,15 @@ private:
typedef OSCReceiver::Listener Listener;
if (content.isMessage())
- realtimeListeners.call (&Listener::oscMessageReceived, content.getMessage());
+ {
+ auto&& message = content.getMessage();
+ realtimeListeners.call ([&] (Listener& l) { l.oscMessageReceived (message); });
+ }
else if (content.isBundle())
- realtimeListeners.call (&Listener::oscBundleReceived, content.getBundle());
+ {
+ auto&& bundle = content.getBundle();
+ realtimeListeners.call ([&] (Listener& l) { l.oscBundleReceived (bundle); });
+ }
}
//==============================================================================
diff --git a/modules/juce_product_unlocking/in_app_purchases/juce_InAppPurchases.cpp b/modules/juce_product_unlocking/in_app_purchases/juce_InAppPurchases.cpp
index c28df9133b..7a13e5c2a8 100644
--- a/modules/juce_product_unlocking/in_app_purchases/juce_InAppPurchases.cpp
+++ b/modules/juce_product_unlocking/in_app_purchases/juce_InAppPurchases.cpp
@@ -53,7 +53,7 @@ void InAppPurchases::getProductsInformation (const StringArray& productIdentifie
for (auto productId : productIdentifiers)
products.add (Product { productId, {}, {}, {}, {} });
- listeners.call (&Listener::productsInfoReturned, products);
+ listeners.call ([&] (Listener& l) { l.productsInfoReturned (products); });
#endif
}
@@ -68,7 +68,7 @@ void InAppPurchases::purchaseProduct (const String& productIdentifier,
#else
Listener::PurchaseInfo purchaseInfo { Purchase { "", productIdentifier, {}, {}, {} }, {} };
- listeners.call (&Listener::productPurchaseFinished, purchaseInfo, false, "In-app purchases unavailable");
+ listeners.call ([&] (Listener& l) { l.productPurchaseFinished (purchaseInfo, false, "In-app purchases unavailable"); });
ignoreUnused (isSubscription, upgradeProductIdentifiers, creditForUnusedSubscription);
#endif
}
@@ -78,7 +78,7 @@ void InAppPurchases::restoreProductsBoughtList (bool includeDownloadInfo, const
#if JUCE_ANDROID || JUCE_IOS || JUCE_MAC
pimpl->restoreProductsBoughtList (includeDownloadInfo, subscriptionsSharedSecret);
#else
- listeners.call (&Listener::purchasesListRestored, Array(), false, "In-app purchases unavailable");
+ listeners.call ([] (Listener& l) { l.purchasesListRestored ({}, false, "In-app purchases unavailable"); });
ignoreUnused (includeDownloadInfo, subscriptionsSharedSecret);
#endif
}
@@ -88,7 +88,7 @@ void InAppPurchases::consumePurchase (const String& productIdentifier, const Str
#if JUCE_ANDROID || JUCE_IOS || JUCE_MAC
pimpl->consumePurchase (productIdentifier, purchaseToken);
#else
- listeners.call (&Listener::productConsumed, productIdentifier, false, "In-app purchases unavailable");
+ listeners.call ([&] (Listener& l) { l.productConsumed (productIdentifier, false, "In-app purchases unavailable"); });
ignoreUnused (purchaseToken);
#endif
}
diff --git a/modules/juce_product_unlocking/native/juce_android_InAppPurchases.cpp b/modules/juce_product_unlocking/native/juce_android_InAppPurchases.cpp
index d4a4bb9827..b227f650c6 100644
--- a/modules/juce_product_unlocking/native/juce_android_InAppPurchases.cpp
+++ b/modules/juce_product_unlocking/native/juce_android_InAppPurchases.cpp
@@ -263,7 +263,7 @@ struct InAppPurchases::Pimpl : private AsyncUpdater,
//==============================================================================
void notifyAboutPurchaseResult (const InAppPurchases::Purchase& purchase, bool success, const String& statusDescription)
{
- owner.listeners.call (&Listener::productPurchaseFinished, { purchase, {} }, success, statusDescription);
+ owner.listeners.call ([&] (Listener& l) { l.productPurchaseFinished ({ purchase, {} }, success, statusDescription); });
}
//==============================================================================
@@ -738,7 +738,7 @@ struct InAppPurchases::Pimpl : private AsyncUpdater,
{
const auto& result = getProductsInformationJobResults.getReference (i);
- owner.listeners.call (&Listener::productsInfoReturned, result);
+ owner.listeners.call ([&] (Listener& l) { l.productsInfoReturned (result); });
getProductsInformationJobResults.remove (i);
}
}
@@ -750,7 +750,7 @@ struct InAppPurchases::Pimpl : private AsyncUpdater,
{
const auto& result = getProductsBoughtJobResults.getReference (i);
- owner.listeners.call (&Listener::purchasesListRestored, result.purchases, result.success, result.statusDescription);
+ owner.listeners.call ([&] (Listener& l) { l.purchasesListRestored (result.purchases, result.success, result.statusDescription); });
getProductsBoughtJobResults.remove (i);
}
}
@@ -762,8 +762,7 @@ struct InAppPurchases::Pimpl : private AsyncUpdater,
{
const auto& result = consumePurchaseJobResults.getReference (i);
- owner.listeners.call (&Listener::productConsumed, result.productIdentifier,
- result.success, result.statusDescription);
+ owner.listeners.call ([&] (Listener& l) { l.productConsumed (result.productIdentifier, result.success, result.statusDescription); });
consumePurchaseJobResults.remove (i);
}
}
diff --git a/modules/juce_product_unlocking/native/juce_ios_InAppPurchases.cpp b/modules/juce_product_unlocking/native/juce_ios_InAppPurchases.cpp
index 01ccd8f7c7..426af72496 100644
--- a/modules/juce_product_unlocking/native/juce_ios_InAppPurchases.cpp
+++ b/modules/juce_product_unlocking/native/juce_ios_InAppPurchases.cpp
@@ -196,7 +196,7 @@ struct InAppPurchases::Pimpl : public SKDelegateAndPaymentObserver
{
if (! [SKPaymentQueue canMakePayments])
{
- owner.listeners.call (&Listener::productPurchaseFinished, {}, false, NEEDS_TRANS ("Payments not allowed"));
+ owner.listeners.call ([&] (Listener& l) { l.productPurchaseFinished ({}, false, NEEDS_TRANS ("Payments not allowed")); });
return;
}
@@ -299,8 +299,8 @@ struct InAppPurchases::Pimpl : public SKDelegateAndPaymentObserver
if (pendingRequest.request == receiptRefreshRequest)
{
- auto errorDetails = error != nil ? (", " + nsStringToJuce ([error localizedDescription])) : String ("");
- owner.listeners.call (&Listener::purchasesListRestored, {}, false, NEEDS_TRANS ("Receipt fetch failed") + errorDetails);
+ auto errorDetails = error != nil ? (", " + nsStringToJuce ([error localizedDescription])) : String();
+ owner.listeners.call ([&] (Listener& l) { l.purchasesListRestored ({}, false, NEEDS_TRANS ("Receipt fetch failed") + errorDetails); });
pendingReceiptRefreshRequests.remove (i);
return;
}
@@ -326,12 +326,12 @@ struct InAppPurchases::Pimpl : public SKDelegateAndPaymentObserver
void restoreCompletedTransactionsFailedWithError (SKPaymentQueue*, NSError* error) override
{
- owner.listeners.call (&Listener::purchasesListRestored, {}, false, nsStringToJuce (error.localizedDescription));
+ owner.listeners.call ([&] (Listener& l) { l.purchasesListRestored ({}, false, nsStringToJuce (error.localizedDescription)); });
}
void restoreCompletedTransactionsFinished (SKPaymentQueue*) override
{
- owner.listeners.call (&Listener::purchasesListRestored, restoredPurchases, true, NEEDS_TRANS ("Success"));
+ owner.listeners.call ([this] (Listener& l) { l.purchasesListRestored (restoredPurchases, true, NEEDS_TRANS ("Success")); });
restoredPurchases.clear();
}
@@ -348,9 +348,10 @@ struct InAppPurchases::Pimpl : public SKDelegateAndPaymentObserver
#endif
{
case SKDownloadStateWaiting: break;
- case SKDownloadStatePaused: owner.listeners.call (&Listener::productDownloadPaused, *pendingDownload); break;
- case SKDownloadStateActive: owner.listeners.call (&Listener::productDownloadProgressUpdate, *pendingDownload,
- download.progress, RelativeTime (download.timeRemaining)); break;
+ case SKDownloadStatePaused: owner.listeners.call ([&] (Listener& l) { l.productDownloadPaused (*pendingDownload); }); break;
+ case SKDownloadStateActive: owner.listeners.call ([&] (Listener& l) { l.productDownloadProgressUpdate (*pendingDownload,
+ download.progress,
+ RelativeTime (download.timeRemaining)); }); break;
case SKDownloadStateFinished:
case SKDownloadStateFailed:
case SKDownloadStateCancelled: processDownloadFinish (pendingDownload, download); break;
@@ -369,7 +370,7 @@ struct InAppPurchases::Pimpl : public SKDelegateAndPaymentObserver
for (SKProduct* skProduct in products)
productsToReturn.add (SKProductToIAPProduct (skProduct));
- owner.listeners.call (&Listener::productsInfoReturned, productsToReturn);
+ owner.listeners.call ([&] (Listener& l) { l.productsInfoReturned (productsToReturn); });
}
void startPurchase (NSArray* products)
@@ -385,8 +386,7 @@ struct InAppPurchases::Pimpl : public SKDelegateAndPaymentObserver
}
else
{
- owner.listeners.call (&Listener::productPurchaseFinished, {}, false,
- NEEDS_TRANS ("Your app is not setup for payments"));
+ owner.listeners.call ([] (Listener& l) { l.productPurchaseFinished ({}, false, NEEDS_TRANS ("Your app is not setup for payments")); });
}
}
@@ -464,8 +464,8 @@ struct InAppPurchases::Pimpl : public SKDelegateAndPaymentObserver
if (transaction.transactionState == SKPaymentTransactionStateRestored)
restoredPurchases.add ({ purchase, downloads });
else
- owner.listeners.call (&Listener::productPurchaseFinished, { purchase, downloads }, success,
- SKPaymentTransactionStateToString (transaction.transactionState));
+ owner.listeners.call ([&] (Listener& l) { l.productPurchaseFinished ({ purchase, downloads }, success,
+ SKPaymentTransactionStateToString (transaction.transactionState)); });
}
PendingDownloadsTransaction* getPendingDownloadsTransactionForSKTransaction (SKPaymentTransaction* transaction)
@@ -514,7 +514,7 @@ struct InAppPurchases::Pimpl : public SKDelegateAndPaymentObserver
? URL (nsStringToJuce (download.contentURL.absoluteString))
: URL();
- owner.listeners.call (&Listener::productDownloadFinished, *pendingDownload, contentURL);
+ owner.listeners.call ([&] (Listener& l) { l.productDownloadFinished (*pendingDownload, contentURL); });
if (pdt->canBeMarkedAsFinished())
{
@@ -534,7 +534,7 @@ struct InAppPurchases::Pimpl : public SKDelegateAndPaymentObserver
if (auto* receiptData = [NSData dataWithContentsOfURL: receiptURL])
fetchReceiptDetailsFromAppStore (receiptData, secret);
else
- owner.listeners.call (&Listener::purchasesListRestored, {}, false, NEEDS_TRANS ("Receipt fetch failed"));
+ owner.listeners.call ([&] (Listener& l) { l.purchasesListRestored ({}, false, NEEDS_TRANS ("Receipt fetch failed")); });
}
void fetchReceiptDetailsFromAppStore (NSData* receiptData, const String& secret)
@@ -551,7 +551,7 @@ struct InAppPurchases::Pimpl : public SKDelegateAndPaymentObserver
error: &error];
if (requestData == nil)
{
- owner.listeners.call (&Listener::purchasesListRestored, {}, false, NEEDS_TRANS ("Receipt fetch failed"));
+ sendReceiptFetchFail();
return;
}
@@ -572,7 +572,7 @@ struct InAppPurchases::Pimpl : public SKDelegateAndPaymentObserver
{
if (connectionError != nil)
{
- owner.listeners.call (&Listener::purchasesListRestored, {}, false, NEEDS_TRANS ("Receipt fetch failed"));
+ sendReceiptFetchFail();
}
else
{
@@ -581,7 +581,7 @@ struct InAppPurchases::Pimpl : public SKDelegateAndPaymentObserver
if (NSDictionary* receiptDetails = [NSJSONSerialization JSONObjectWithData: data options: 0 error: &err])
processReceiptDetails (receiptDetails);
else
- owner.listeners.call (&Listener::purchasesListRestored, {}, false, NEEDS_TRANS ("Receipt fetch failed"));
+ sendReceiptFetchFail();
}
}];
@@ -622,31 +622,34 @@ struct InAppPurchases::Pimpl : public SKDelegateAndPaymentObserver
}
else
{
- return sendReceiptFetchFail();
+ return sendReceiptFetchFailAsync();
}
}
}
}
else
{
- return sendReceiptFetchFail();
+ return sendReceiptFetchFailAsync();
}
}
- MessageManager::callAsync ([this, purchases]() { owner.listeners.call (&Listener::purchasesListRestored,
- purchases, true, NEEDS_TRANS ("Success")); });
+ MessageManager::callAsync ([this, purchases]() { owner.listeners.call ([&] (Listener& l) { l.purchasesListRestored (purchases, true, NEEDS_TRANS ("Success")); }); });
return;
}
}
}
- sendReceiptFetchFail();
+ sendReceiptFetchFailAsync();
}
void sendReceiptFetchFail()
{
- MessageManager::callAsync ([this]() { owner.listeners.call (&Listener::purchasesListRestored,
- {}, false, NEEDS_TRANS ("Receipt fetch failed")); });
+ owner.listeners.call ([] (Listener& l) { l.purchasesListRestored ({}, false, NEEDS_TRANS ("Receipt fetch failed")); });
+ }
+
+ void sendReceiptFetchFailAsync()
+ {
+ MessageManager::callAsync ([this]() { sendReceiptFetchFail(); });
}
static int64 getPurchaseDateMs (id date)