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:
Vadim Zeitlin 2009-05-02 15:28:16 +00:00
parent 951f792f7d
commit ca6911c361
2 changed files with 18 additions and 5 deletions

View File

@ -523,7 +523,7 @@ class wxEventFunctorFunctor : public wxEventFunctor
public:
typedef typename EventTag::EventClass EventArg;
wxEventFunctorFunctor(Functor& handler)
wxEventFunctorFunctor(const Functor& handler)
: m_handler(handler), m_handlerAddr(&handler)
{ }
@ -591,14 +591,14 @@ wxMakeEventFunctor(const EventTag&, void (*func)(EventArg &))
// Create functors wrapping other functors:
template <typename EventTag, typename Functor>
inline wxEventFunctorFunctor<EventTag, Functor> *
wxNewEventFunctor(const EventTag&, Functor &func)
wxNewEventFunctor(const EventTag&, const Functor &func)
{
return new wxEventFunctorFunctor<EventTag, Functor>(func);
}
template <typename EventTag, typename Functor>
inline wxEventFunctorFunctor<EventTag, Functor>
wxMakeEventFunctor(const EventTag&, Functor &func)
wxMakeEventFunctor(const EventTag&, const Functor &func)
{
return wxEventFunctorFunctor<EventTag, Functor>(func);
}
@ -3059,7 +3059,7 @@ public:
// Bind functors to an event:
template <typename EventTag, typename Functor>
void Bind(const EventTag& eventType,
Functor &functor,
const Functor &functor,
int winid = wxID_ANY,
int lastId = wxID_ANY,
wxObject *userData = NULL)
@ -3072,7 +3072,7 @@ public:
template <typename EventTag, typename Functor>
bool Unbind(const EventTag& eventType,
Functor &functor,
const Functor &functor,
int winid = wxID_ANY,
int lastId = wxID_ANY,
wxObject *userData = NULL)

View File

@ -309,6 +309,19 @@ void EvtHandlerTestCase::BindFunctor()
handler.Bind( 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()