+template <typename EventTag, typename Functor>
+class wxEventFunctorFunctor : public wxEventFunctor
+{
+public:
+ typedef typename EventTag::EventClass EventArg;
+
+ wxEventFunctorFunctor(const Functor& handler)
+ : m_handler(handler), m_handlerAddr(&handler)
+ { }
+
+ virtual void operator()(wxEvtHandler *WXUNUSED(handler), wxEvent& event)
+ {
+ // If you get an error here like "must use '.*' or '->*' to call
+ // pointer-to-member function" then you probably tried to call
+ // Bind/Unbind with a method pointer but without a handler pointer or
+ // NULL as a handler e.g.:
+ // Unbind( wxEVT_XXX, &EventHandler::method );
+ // or
+ // Unbind( wxEVT_XXX, &EventHandler::method, NULL )
+ m_handler(static_cast<EventArg&>(event));
+ }
+
+ virtual bool IsMatching(const wxEventFunctor &functor) const
+ {
+ if ( !functor.IsSameClass(sm_classInfo) )
+ return false;
+
+ typedef wxEventFunctorFunctor<EventTag, Functor> FunctorThis;
+
+ const FunctorThis& other = static_cast<const FunctorThis&>(functor);
+
+ // The only reliable/portable way to compare two functors is by
+ // identity:
+ return m_handlerAddr == other.m_handlerAddr;
+ }
+
+ virtual bool IsSameClass( wxEventFunctorClassInfo otherClassInfo ) const
+ { return sm_classInfo == otherClassInfo; }
+
+private:
+ // Store a copy of the functor to prevent using/calling an already
+ // destroyed instance:
+ Functor m_handler;
+
+ // Use the address of the original functor for comparison in IsMatching:
+ const void *m_handlerAddr;
+
+ wxDEFINE_EVENT_FUNCTOR_CLASS_INFO( sm_classInfo );
+};
+