public:
typedef typename EventTag::EventClass EventArg;
- wxEventFunctorFunctor(Functor& handler)
+ wxEventFunctorFunctor(const Functor& handler)
: m_handler(handler), m_handlerAddr(&handler)
{ }
// 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);
}
// 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)
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)
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()