Add functor-taking overload of CallAfter().

This is a generalization of the existing method-calling overloads.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74574 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2013-07-21 10:05:03 +00:00
parent a0bb0df5d7
commit cbc8576a9b
2 changed files with 75 additions and 1 deletions

View File

@@ -1470,6 +1470,39 @@ private:
const ParamType2 m_param2;
};
// This is a version for calling any functors
template <typename T>
class wxAsyncMethodCallEventFunctor : public wxAsyncMethodCallEvent
{
public:
typedef T FunctorType;
wxAsyncMethodCallEventFunctor(wxObject *object, const FunctorType& fn)
: wxAsyncMethodCallEvent(object),
m_fn(fn)
{
}
wxAsyncMethodCallEventFunctor(const wxAsyncMethodCallEventFunctor& other)
: wxAsyncMethodCallEvent(other),
m_fn(other.m_fn)
{
}
virtual wxEvent *Clone() const
{
return new wxAsyncMethodCallEventFunctor(*this);
}
virtual void Execute()
{
m_fn();
}
private:
FunctorType m_fn;
};
#endif // wxHAS_CALL_AFTER
@@ -3394,6 +3427,12 @@ public:
static_cast<T*>(this), method, x1, x2)
);
}
template <typename T>
void CallAfter(const T& fn)
{
QueueEvent(new wxAsyncMethodCallEventFunctor<T>(this, fn));
}
#endif // wxHAS_CALL_AFTER