allow passing temporary functors to Bind() too (closes #10653)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60477 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -523,7 +523,7 @@ class wxEventFunctorFunctor : public wxEventFunctor
|
|||||||
public:
|
public:
|
||||||
typedef typename EventTag::EventClass EventArg;
|
typedef typename EventTag::EventClass EventArg;
|
||||||
|
|
||||||
wxEventFunctorFunctor(Functor& handler)
|
wxEventFunctorFunctor(const Functor& handler)
|
||||||
: m_handler(handler), m_handlerAddr(&handler)
|
: m_handler(handler), m_handlerAddr(&handler)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@@ -591,14 +591,14 @@ wxMakeEventFunctor(const EventTag&, void (*func)(EventArg &))
|
|||||||
// Create functors wrapping other functors:
|
// Create functors wrapping other functors:
|
||||||
template <typename EventTag, typename Functor>
|
template <typename EventTag, typename Functor>
|
||||||
inline wxEventFunctorFunctor<EventTag, Functor> *
|
inline wxEventFunctorFunctor<EventTag, Functor> *
|
||||||
wxNewEventFunctor(const EventTag&, Functor &func)
|
wxNewEventFunctor(const EventTag&, const Functor &func)
|
||||||
{
|
{
|
||||||
return new wxEventFunctorFunctor<EventTag, Functor>(func);
|
return new wxEventFunctorFunctor<EventTag, Functor>(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename EventTag, typename Functor>
|
template <typename EventTag, typename Functor>
|
||||||
inline wxEventFunctorFunctor<EventTag, Functor>
|
inline wxEventFunctorFunctor<EventTag, Functor>
|
||||||
wxMakeEventFunctor(const EventTag&, Functor &func)
|
wxMakeEventFunctor(const EventTag&, const Functor &func)
|
||||||
{
|
{
|
||||||
return wxEventFunctorFunctor<EventTag, Functor>(func);
|
return wxEventFunctorFunctor<EventTag, Functor>(func);
|
||||||
}
|
}
|
||||||
@@ -3059,7 +3059,7 @@ public:
|
|||||||
// Bind functors to an event:
|
// Bind functors to an event:
|
||||||
template <typename EventTag, typename Functor>
|
template <typename EventTag, typename Functor>
|
||||||
void Bind(const EventTag& eventType,
|
void Bind(const EventTag& eventType,
|
||||||
Functor &functor,
|
const Functor &functor,
|
||||||
int winid = wxID_ANY,
|
int winid = wxID_ANY,
|
||||||
int lastId = wxID_ANY,
|
int lastId = wxID_ANY,
|
||||||
wxObject *userData = NULL)
|
wxObject *userData = NULL)
|
||||||
@@ -3072,7 +3072,7 @@ public:
|
|||||||
|
|
||||||
template <typename EventTag, typename Functor>
|
template <typename EventTag, typename Functor>
|
||||||
bool Unbind(const EventTag& eventType,
|
bool Unbind(const EventTag& eventType,
|
||||||
Functor &functor,
|
const Functor &functor,
|
||||||
int winid = wxID_ANY,
|
int winid = wxID_ANY,
|
||||||
int lastId = wxID_ANY,
|
int lastId = wxID_ANY,
|
||||||
wxObject *userData = NULL)
|
wxObject *userData = NULL)
|
||||||
|
@@ -309,6 +309,19 @@ void EvtHandlerTestCase::BindFunctor()
|
|||||||
|
|
||||||
handler.Bind( MyEventType, functor, 0, 0 );
|
handler.Bind( MyEventType, functor, 0, 0 );
|
||||||
handler.Unbind( MyEventType, functor, 0, 0 );
|
handler.Unbind( MyEventType, functor, 0, 0 );
|
||||||
|
|
||||||
|
// Test that a temporary functor is working as well. Note that Unbind will
|
||||||
|
// fail because a functor can only be unbound if it is the same instance as
|
||||||
|
// in Bind!
|
||||||
|
|
||||||
|
handler.Bind( MyEventType, MyFunctor() );
|
||||||
|
CPPUNIT_ASSERT( !handler.Unbind( MyEventType, MyFunctor() ));
|
||||||
|
|
||||||
|
handler.Bind( MyEventType, MyFunctor(), 0 );
|
||||||
|
CPPUNIT_ASSERT( !handler.Unbind( MyEventType, MyFunctor(), 0 ));
|
||||||
|
|
||||||
|
handler.Bind( MyEventType, MyFunctor(), 0, 0 );
|
||||||
|
CPPUNIT_ASSERT( !handler.Unbind( MyEventType, MyFunctor(), 0, 0 ));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvtHandlerTestCase::BindMethod()
|
void EvtHandlerTestCase::BindMethod()
|
||||||
|
Reference in New Issue
Block a user