improvements to wxEventFunctor classes; use wxHAS_EVENT_BIND instead of wxEVENTS_COMPATIBILITY_2_8 (see #10653)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60470 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -682,13 +682,6 @@ WX_ARG_ENABLE_PARAM(universal_binary, [[ --enable-universal_binary create Mac
|
|||||||
WX_ARG_ENABLE(compat26, [ --enable-compat26 enable wxWidgets 2.6 compatibility], WXWIN_COMPATIBILITY_2_6)
|
WX_ARG_ENABLE(compat26, [ --enable-compat26 enable wxWidgets 2.6 compatibility], WXWIN_COMPATIBILITY_2_6)
|
||||||
WX_ARG_DISABLE(compat28, [ --disable-compat28 disable wxWidgets 2.8 compatibility], WXWIN_COMPATIBILITY_2_8)
|
WX_ARG_DISABLE(compat28, [ --disable-compat28 disable wxWidgets 2.8 compatibility], WXWIN_COMPATIBILITY_2_8)
|
||||||
|
|
||||||
dnl currently we don't provide a switch for disabling it as it shouldn't be
|
|
||||||
dnl necessary to do it unless the compiler doesn't support the new events and
|
|
||||||
dnl this should be tested for by configure itself (but also isn't done yet
|
|
||||||
dnl because there are no known examples of such compilers among the currently
|
|
||||||
dnl supported ones)
|
|
||||||
AC_DEFINE(wxEVENTS_COMPATIBILITY_2_8, 0)
|
|
||||||
|
|
||||||
WX_ARG_DISABLE(rpath, [ --disable-rpath disable use of rpath for uninstalled builds], wxUSE_RPATH)
|
WX_ARG_DISABLE(rpath, [ --disable-rpath disable use of rpath for uninstalled builds], wxUSE_RPATH)
|
||||||
|
|
||||||
WX_ARG_ENABLE(objc_uniquifying,[ --enable-objc_uniquifying enable Objective-C class name uniquifying], wxUSE_OBJC_UNIQUIFYING)
|
WX_ARG_ENABLE(objc_uniquifying,[ --enable-objc_uniquifying enable Objective-C class name uniquifying], wxUSE_OBJC_UNIQUIFYING)
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
#include "wx/thread.h"
|
#include "wx/thread.h"
|
||||||
#include "wx/tracker.h"
|
#include "wx/tracker.h"
|
||||||
|
|
||||||
#if !wxEVENTS_COMPATIBILITY_2_8
|
#ifdef wxHAS_EVENT_BIND
|
||||||
#include "wx/meta/convertible.h"
|
#include "wx/meta/convertible.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ extern WXDLLIMPEXP_BASE wxEventType wxNewEventType();
|
|||||||
|
|
||||||
// New macros to create templatized event types:
|
// New macros to create templatized event types:
|
||||||
|
|
||||||
#if wxEVENTS_COMPATIBILITY_2_8
|
#ifndef wxHAS_EVENT_BIND
|
||||||
|
|
||||||
// Define/Declare a wxEventType-based event type:
|
// Define/Declare a wxEventType-based event type:
|
||||||
|
|
||||||
@@ -126,7 +126,8 @@ extern WXDLLIMPEXP_BASE wxEventType wxNewEventType();
|
|||||||
#define wxDECLARE_EVENT( name, type ) \
|
#define wxDECLARE_EVENT( name, type ) \
|
||||||
wxDECLARE_EXPORTED_EVENT( wxEMPTY_PARAMETER_VALUE, name, type )
|
wxDECLARE_EXPORTED_EVENT( wxEMPTY_PARAMETER_VALUE, name, type )
|
||||||
|
|
||||||
#else
|
#else // wxHAS_EVENT_BIND
|
||||||
|
|
||||||
// Define/Declare a templatized event type with the corresponding event as
|
// Define/Declare a templatized event type with the corresponding event as
|
||||||
// a nested typedef:
|
// a nested typedef:
|
||||||
|
|
||||||
@@ -151,16 +152,15 @@ extern WXDLLIMPEXP_BASE wxEventType wxNewEventType();
|
|||||||
#define wxDECLARE_EVENT( name, type ) \
|
#define wxDECLARE_EVENT( name, type ) \
|
||||||
wxDECLARE_EXPORTED_EVENT( wxEMPTY_PARAMETER_VALUE, name, type )
|
wxDECLARE_EXPORTED_EVENT( wxEMPTY_PARAMETER_VALUE, name, type )
|
||||||
|
|
||||||
#endif
|
#endif // wxHAS_EVENT_BIND
|
||||||
|
|
||||||
// Try to cast the given event handler to the correct handler type:
|
// Try to cast the given event handler to the correct handler type:
|
||||||
|
|
||||||
#define wxEVENT_HANDLER_CAST( functype, func ) \
|
#define wxEVENT_HANDLER_CAST( functype, func ) \
|
||||||
( wxObjectEventFunction )( wxEventFunction )wxStaticCastEvent( functype, &func )
|
( wxObjectEventFunction )( wxEventFunction )wxStaticCastEvent( functype, &func )
|
||||||
|
|
||||||
// Template which associates the correct event object with the event type
|
|
||||||
|
|
||||||
#if !wxEVENTS_COMPATIBILITY_2_8
|
#ifdef wxHAS_EVENT_BIND
|
||||||
|
|
||||||
// The tag is a type associated to the event type (which is an integer itself,
|
// The tag is a type associated to the event type (which is an integer itself,
|
||||||
// in spite of its name) value. It exists in order to be used as a template
|
// in spite of its name) value. It exists in order to be used as a template
|
||||||
@@ -184,7 +184,7 @@ private:
|
|||||||
wxEventType m_type;
|
wxEventType m_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !wxEVENTS_COMPATIBILITY_2_8
|
#endif // wxHAS_EVENT_BIND
|
||||||
|
|
||||||
// These are needed for the functor definitions
|
// These are needed for the functor definitions
|
||||||
typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
|
typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
|
||||||
@@ -199,6 +199,15 @@ typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
|
|||||||
typedef wxEventFunction wxObjectEventFunction;
|
typedef wxEventFunction wxObjectEventFunction;
|
||||||
|
|
||||||
|
|
||||||
|
// wxEventFunctorClassInfo is used as a unique identifier for wxEventFunctor-
|
||||||
|
// derived classes; it is more light weight than wxClassInfo and can be used in
|
||||||
|
// template classes
|
||||||
|
typedef void (*wxEventFunctorClassInfo)();
|
||||||
|
|
||||||
|
// this macro must be used in wxEventFunctor-derived classes
|
||||||
|
#define wxDEFINE_EVENT_FUNCTOR_CLASS_INFO( classInfoName ) \
|
||||||
|
static void classInfoName() {}
|
||||||
|
|
||||||
// The event functor which is stored in the static and dynamic event tables:
|
// The event functor which is stored in the static and dynamic event tables:
|
||||||
class WXDLLIMPEXP_BASE wxEventFunctor
|
class WXDLLIMPEXP_BASE wxEventFunctor
|
||||||
{
|
{
|
||||||
@@ -209,54 +218,74 @@ public:
|
|||||||
virtual void operator()(wxEvtHandler *, wxEvent&) = 0;
|
virtual void operator()(wxEvtHandler *, wxEvent&) = 0;
|
||||||
|
|
||||||
// this function tests whether this functor is matched, for the purpose of
|
// this function tests whether this functor is matched, for the purpose of
|
||||||
// finding it in an event table in Disconnect(), by the given func
|
// finding it in an event table in Unbind(), by the given functor:
|
||||||
virtual bool Matches(const wxEventFunctor& func) const = 0;
|
virtual bool IsMatching(const wxEventFunctor& functor) const = 0;
|
||||||
|
|
||||||
// these functions are used for functors comparison in Matches()
|
// Test whether the given class info is the same as from this functor. This
|
||||||
virtual void *GetHandler() const { return GetEvtHandler(); }
|
// allows us in IsMatching to safely downcast the given wxEventFunctor without
|
||||||
virtual wxEventFunction GetMethod() const { return NULL; }
|
// the usage of dynamic_cast<>().
|
||||||
|
virtual bool IsSameClass(wxEventFunctorClassInfo classInfo) const = 0;
|
||||||
|
|
||||||
// this one is also used elsewhere in the code and should be overridden to
|
// If the functor holds an wxEvtHandler, then get access to it and track
|
||||||
// return non-NULL if we are indeed associated with an wxEvtHandler
|
// its lifetime with wxEventConnectionRef:
|
||||||
virtual wxEvtHandler *GetEvtHandler() const { return NULL; }
|
virtual wxEvtHandler *GetEvtHandler() const
|
||||||
|
{ return NULL; }
|
||||||
|
|
||||||
|
// This is only used to maintain backward compatibility in
|
||||||
|
// wxAppConsoleBase::CallEventHandler and ensures that an overwritten
|
||||||
|
// wxAppConsoleBase::HandleEvent is still called for functors which hold an
|
||||||
|
// wxEventFunction:
|
||||||
|
virtual wxEventFunction GetEvtMethod() const
|
||||||
|
{ return NULL; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// A plain method functor: notice that it is used even with the new events as
|
// A plain method functor for the untyped legacy event types:
|
||||||
// it is reused as a specialization of wxEventFunctorMethod for legacy untyped
|
|
||||||
// event types
|
|
||||||
class WXDLLIMPEXP_BASE wxObjectEventFunctor : public wxEventFunctor
|
class WXDLLIMPEXP_BASE wxObjectEventFunctor : public wxEventFunctor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxObjectEventFunctor(wxObjectEventFunction method, wxEvtHandler *handler)
|
wxObjectEventFunctor(wxObjectEventFunction method, wxEvtHandler *handler)
|
||||||
|
: m_handler( handler ), m_method( method )
|
||||||
|
{ }
|
||||||
|
|
||||||
|
virtual void operator()(wxEvtHandler *handler, wxEvent& event)
|
||||||
{
|
{
|
||||||
m_handler = handler;
|
wxEvtHandler * const realHandler = m_handler ? m_handler : handler;
|
||||||
m_method = method;
|
|
||||||
|
(realHandler->*m_method)(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void operator()(wxEvtHandler *handler, wxEvent& event);
|
virtual bool IsMatching(const wxEventFunctor& functor) const
|
||||||
|
|
||||||
virtual bool Matches(const wxEventFunctor& func) const
|
|
||||||
{
|
{
|
||||||
void * const handler = func.GetHandler();
|
if ( functor.IsSameClass( sm_classInfo ))
|
||||||
if ( handler && GetHandler() != handler )
|
{
|
||||||
|
const wxObjectEventFunctor &other =
|
||||||
|
static_cast< const wxObjectEventFunctor & >( functor );
|
||||||
|
|
||||||
|
// FIXME-VC6: amazing but true: replacing "method == NULL" here
|
||||||
|
// with "!method" makes VC6 crash with an ICE in DLL build (only!)
|
||||||
|
|
||||||
|
return ( m_method == other.m_method || other.m_method == NULL ) &&
|
||||||
|
( m_handler == other.m_handler || other.m_handler == NULL );
|
||||||
|
}
|
||||||
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const wxEventFunction method = GetMethod();
|
|
||||||
|
|
||||||
// FIXME-VC6: amazing but true: replacing "method == NULL" here with
|
|
||||||
// "!method" makes VC6 crash with an ICE in DLL build (only!)
|
|
||||||
return method == NULL || GetMethod() == method;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual wxEvtHandler *GetEvtHandler() const { return m_handler; }
|
virtual bool IsSameClass( wxEventFunctorClassInfo otherClassInfo ) const
|
||||||
virtual wxEventFunction GetMethod() const { return m_method; }
|
{ return sm_classInfo == otherClassInfo; }
|
||||||
|
|
||||||
|
virtual wxEvtHandler *GetEvtHandler() const
|
||||||
|
{ return m_handler; }
|
||||||
|
|
||||||
|
virtual wxEventFunction GetEvtMethod() const
|
||||||
|
{ return m_method; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxEvtHandler *m_handler;
|
wxEvtHandler *m_handler;
|
||||||
wxEventFunction m_method;
|
wxEventFunction m_method;
|
||||||
};
|
|
||||||
|
|
||||||
#if wxEVENTS_COMPATIBILITY_2_8
|
wxDEFINE_EVENT_FUNCTOR_CLASS_INFO( sm_classInfo );
|
||||||
|
};
|
||||||
|
|
||||||
// Create a functor for the legacy events: used by Connect()
|
// Create a functor for the legacy events: used by Connect()
|
||||||
inline wxObjectEventFunctor *
|
inline wxObjectEventFunctor *
|
||||||
@@ -283,40 +312,7 @@ wxMakeEventFunctor(const wxEventType& WXUNUSED(evtType),
|
|||||||
return wxObjectEventFunctor(method, handler);
|
return wxObjectEventFunctor(method, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // !wxEVENTS_COMPATIBILITY_2_8
|
#ifdef wxHAS_EVENT_BIND
|
||||||
|
|
||||||
// functor forwarding the event to anything callable (function, static method,
|
|
||||||
// generalized functor...)
|
|
||||||
template <typename EventTag, typename Functor>
|
|
||||||
class wxEventFunctorFunction : public wxEventFunctor
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef typename EventTag::EventClass EventArg;
|
|
||||||
|
|
||||||
wxEventFunctorFunction(Functor handler)
|
|
||||||
{
|
|
||||||
m_handler = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void operator()(wxEvtHandler *WXUNUSED(handler), wxEvent& event)
|
|
||||||
{
|
|
||||||
m_handler(static_cast<EventArg&>(event));
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool Matches(const wxEventFunctor& WXUNUSED(func)) const
|
|
||||||
{
|
|
||||||
// we have no way to compare arbitrary functors so just consider them
|
|
||||||
// to be equal: this means that disconnecting a functor will always
|
|
||||||
// find the last functor connected which in turn implies that it's
|
|
||||||
// probably a bad idea to connect more than one functor if you plan to
|
|
||||||
// disconnect them but this limitation doesn't seem very important in
|
|
||||||
// practice
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Functor m_handler;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace wxPrivate
|
namespace wxPrivate
|
||||||
{
|
{
|
||||||
@@ -356,7 +352,7 @@ struct HandlerImpl<T, A, true>
|
|||||||
{ return static_cast<T *>(p); }
|
{ return static_cast<T *>(p); }
|
||||||
static wxEvtHandler *ConvertToEvtHandler(T *p)
|
static wxEvtHandler *ConvertToEvtHandler(T *p)
|
||||||
{ return p; }
|
{ return p; }
|
||||||
static wxEventFunction ConvertToEvtFunction(void (T::*f)(A&))
|
static wxEventFunction ConvertToEvtMethod(void (T::*f)(A&))
|
||||||
{ return static_cast<wxEventFunction>(
|
{ return static_cast<wxEventFunction>(
|
||||||
reinterpret_cast<void (T::*)(wxEvent&)>(f)); }
|
reinterpret_cast<void (T::*)(wxEvent&)>(f)); }
|
||||||
};
|
};
|
||||||
@@ -371,7 +367,7 @@ struct HandlerImpl<T, A, false>
|
|||||||
{ return NULL; }
|
{ return NULL; }
|
||||||
static wxEvtHandler *ConvertToEvtHandler(T *)
|
static wxEvtHandler *ConvertToEvtHandler(T *)
|
||||||
{ return NULL; }
|
{ return NULL; }
|
||||||
static wxEventFunction ConvertToEvtFunction(void (T::*)(A&))
|
static wxEventFunction ConvertToEvtMethod(void (T::*)(A&))
|
||||||
{ return NULL; }
|
{ return NULL; }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -406,6 +402,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
wxEventFunctorMethod(void (Class::*method)(EventArg&), EventHandler *handler)
|
wxEventFunctorMethod(void (Class::*method)(EventArg&), EventHandler *handler)
|
||||||
|
: m_handler( handler ), m_method( method )
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( handler || this->IsEvtHandler(),
|
wxASSERT_MSG( handler || this->IsEvtHandler(),
|
||||||
"handlers defined in non-wxEvtHandler-derived classes "
|
"handlers defined in non-wxEvtHandler-derived classes "
|
||||||
@@ -415,9 +412,6 @@ public:
|
|||||||
// you're trying to use is not compatible with (i.e. is not the same as
|
// you're trying to use is not compatible with (i.e. is not the same as
|
||||||
// or a base class of) the real event class used for this event type
|
// or a base class of) the real event class used for this event type
|
||||||
CheckHandlerArgument(static_cast<EventClass *>(NULL));
|
CheckHandlerArgument(static_cast<EventClass *>(NULL));
|
||||||
|
|
||||||
m_handler = handler;
|
|
||||||
m_method = method;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void operator()(wxEvtHandler *handler, wxEvent& event)
|
virtual void operator()(wxEvtHandler *handler, wxEvent& event)
|
||||||
@@ -437,60 +431,179 @@ public:
|
|||||||
(realHandler->*m_method)(static_cast<EventArg&>(event));
|
(realHandler->*m_method)(static_cast<EventArg&>(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool Matches(const wxEventFunctor& func) const
|
virtual bool IsMatching(const wxEventFunctor& functor) const
|
||||||
{
|
{
|
||||||
void * const handler = func.GetHandler();
|
if ( !functor.IsSameClass(sm_classInfo) )
|
||||||
if ( handler && GetHandler() != handler )
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const wxEventFunction method = GetMethod();
|
typedef wxEventFunctorMethod<EventTag, Class, EventArg, EventHandler>
|
||||||
return !method || GetMethod() == method;
|
ThisFunctor;
|
||||||
|
|
||||||
|
// the cast is valid because IsSameClass() returned true above
|
||||||
|
const ThisFunctor& other = static_cast<const ThisFunctor &>(functor);
|
||||||
|
|
||||||
|
return (m_method == other.m_method || other.m_method == NULL) &&
|
||||||
|
(m_handler == other.m_handler || other.m_handler == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void *GetHandler() const
|
virtual bool IsSameClass( wxEventFunctorClassInfo otherClassInfo ) const
|
||||||
{
|
{ return sm_classInfo == otherClassInfo; }
|
||||||
return m_handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual wxEventFunction GetMethod() const
|
|
||||||
{
|
|
||||||
return this->ConvertToEvtFunction(m_method);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual wxEvtHandler *GetEvtHandler() const
|
virtual wxEvtHandler *GetEvtHandler() const
|
||||||
{
|
{ return this->ConvertToEvtHandler(m_handler); }
|
||||||
return this->ConvertToEvtHandler(m_handler);
|
|
||||||
}
|
virtual wxEventFunction GetEvtMethod() const
|
||||||
|
{ return this->ConvertToEvtMethod(m_method); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EventHandler *m_handler;
|
EventHandler *m_handler;
|
||||||
void (Class::*m_method)(EventArg&);
|
void (Class::*m_method)(EventArg&);
|
||||||
|
|
||||||
|
wxDEFINE_EVENT_FUNCTOR_CLASS_INFO( sm_classInfo );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// functor forwarding the event to function (function, static method)
|
||||||
|
template <typename EventTag, typename EventArg>
|
||||||
|
class wxEventFunctorFunction : public wxEventFunctor
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static void CheckHandlerArgument(EventArg *) { }
|
||||||
|
|
||||||
|
public:
|
||||||
|
// the event class associated with the given event tag
|
||||||
|
typedef typename wxPrivate::EventClassOf<EventTag>::type EventClass;
|
||||||
|
|
||||||
|
wxEventFunctorFunction( void ( *handler )( EventArg & ))
|
||||||
|
: m_handler( handler )
|
||||||
|
{
|
||||||
|
// if you get an error here it means that the signature of the handler
|
||||||
|
// you're trying to use is not compatible with (i.e. is not the same as
|
||||||
|
// or a base class of) the real event class used for this event type
|
||||||
|
CheckHandlerArgument(static_cast<EventClass *>(NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
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 wxEventFunctorFunction<EventTag, EventArg> ThisFunctor;
|
||||||
|
|
||||||
|
const ThisFunctor& other = static_cast<const ThisFunctor&>( functor );
|
||||||
|
|
||||||
|
return m_handler == other.m_handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool IsSameClass( wxEventFunctorClassInfo otherClassInfo ) const
|
||||||
|
{ return sm_classInfo == otherClassInfo; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void (*m_handler)(EventArg&);
|
||||||
|
|
||||||
|
wxDEFINE_EVENT_FUNCTOR_CLASS_INFO( sm_classInfo );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <typename EventTag, typename Functor>
|
||||||
|
class wxEventFunctorFunctor : public wxEventFunctor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename EventTag::EventClass EventArg;
|
||||||
|
|
||||||
|
wxEventFunctorFunctor(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 );
|
||||||
|
};
|
||||||
|
|
||||||
// Create functors for the templatized events, either allocated on the heap for
|
// Create functors for the templatized events, either allocated on the heap for
|
||||||
// wxNewXXX() variants (this is needed in wxEvtHandler::Bind<>() to store them
|
// wxNewXXX() variants (this is needed in wxEvtHandler::Bind<>() to store them
|
||||||
// in dynamic event table) or just by returning them as temporary objects (this
|
// in dynamic event table) or just by returning them as a temporary objects (this
|
||||||
// is enough for Unbind<>() and we avoid unnecessary heap allocation like this).
|
// is enough for Unbind<>() and we avoid unnecessary heap allocation like this).
|
||||||
|
|
||||||
|
|
||||||
// Create functors wrapping other functors (including functions):
|
// Create functors wrapping functions:
|
||||||
template <typename EventTag, typename Functor>
|
template <typename EventTag, typename EventArg>
|
||||||
inline wxEventFunctorFunction<EventTag, Functor> *
|
inline wxEventFunctorFunction<EventTag, EventArg> *
|
||||||
wxNewEventFunctor(const EventTag&, Functor func)
|
wxNewEventFunctor(const EventTag&, void (*func)(EventArg &))
|
||||||
{
|
{
|
||||||
return new wxEventFunctorFunction<EventTag, Functor>(func);
|
return new wxEventFunctorFunction<EventTag, EventArg>(func);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename EventTag, typename EventArg>
|
||||||
|
inline wxEventFunctorFunction<EventTag, EventArg>
|
||||||
|
wxMakeEventFunctor(const EventTag&, void (*func)(EventArg &))
|
||||||
|
{
|
||||||
|
return wxEventFunctorFunction<EventTag, EventArg>(func);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create functors wrapping other functors:
|
||||||
|
template <typename EventTag, typename Functor>
|
||||||
|
inline wxEventFunctorFunctor<EventTag, Functor> *
|
||||||
|
wxNewEventFunctor(const EventTag&, Functor &func)
|
||||||
|
{
|
||||||
|
return new wxEventFunctorFunctor<EventTag, Functor>(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename EventTag, typename Functor>
|
template <typename EventTag, typename Functor>
|
||||||
inline wxEventFunctorFunction<EventTag, Functor>
|
inline wxEventFunctorFunctor<EventTag, Functor>
|
||||||
wxMakeEventFunctor(const EventTag&, Functor func)
|
wxMakeEventFunctor(const EventTag&, Functor &func)
|
||||||
{
|
{
|
||||||
return wxEventFunctorFunction<EventTag, Functor>(func);
|
return wxEventFunctorFunctor<EventTag, Functor>(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create functors wrapping methods:
|
||||||
// Create functors for methods:
|
|
||||||
template
|
template
|
||||||
<typename EventTag, typename Class, typename EventArg, typename EventHandler>
|
<typename EventTag, typename Class, typename EventArg, typename EventHandler>
|
||||||
inline wxEventFunctorMethod<EventTag, Class, EventArg, EventHandler> *
|
inline wxEventFunctorMethod<EventTag, Class, EventArg, EventHandler> *
|
||||||
@@ -524,7 +637,7 @@ wxNewEventTableFunctor(const EventTag&, void (Class::*method)(EventArg&))
|
|||||||
method, NULL);
|
method, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !wxEVENTS_COMPATIBILITY_2_8
|
#endif // wxHAS_EVENT_BIND
|
||||||
|
|
||||||
|
|
||||||
// many, but not all, standard event types
|
// many, but not all, standard event types
|
||||||
@@ -2871,7 +2984,7 @@ public:
|
|||||||
wxObject *userData = NULL,
|
wxObject *userData = NULL,
|
||||||
wxEvtHandler *eventSink = NULL)
|
wxEvtHandler *eventSink = NULL)
|
||||||
{
|
{
|
||||||
DoConnect(winid, lastId, eventType,
|
DoBind(winid, lastId, eventType,
|
||||||
wxNewEventFunctor(eventType, func, eventSink),
|
wxNewEventFunctor(eventType, func, eventSink),
|
||||||
userData);
|
userData);
|
||||||
}
|
}
|
||||||
@@ -2898,7 +3011,7 @@ public:
|
|||||||
wxObject *userData = NULL,
|
wxObject *userData = NULL,
|
||||||
wxEvtHandler *eventSink = NULL)
|
wxEvtHandler *eventSink = NULL)
|
||||||
{
|
{
|
||||||
return DoDisconnect(winid, lastId, eventType,
|
return DoUnbind(winid, lastId, eventType,
|
||||||
wxMakeEventFunctor(eventType, func, eventSink),
|
wxMakeEventFunctor(eventType, func, eventSink),
|
||||||
userData );
|
userData );
|
||||||
}
|
}
|
||||||
@@ -2916,16 +3029,42 @@ public:
|
|||||||
wxEvtHandler *eventSink = NULL)
|
wxEvtHandler *eventSink = NULL)
|
||||||
{ return Disconnect(wxID_ANY, eventType, func, userData, eventSink); }
|
{ return Disconnect(wxID_ANY, eventType, func, userData, eventSink); }
|
||||||
|
|
||||||
#if !wxEVENTS_COMPATIBILITY_2_8
|
#ifdef wxHAS_EVENT_BIND
|
||||||
// Bind arbitrary functor (including just a function) to an event:
|
// Bind functions to an event:
|
||||||
template <typename EventTag, typename Functor>
|
template <typename EventTag, typename EventArg>
|
||||||
void Bind(const EventTag& eventType,
|
void Bind(const EventTag& eventType,
|
||||||
Functor functor,
|
void (*function)(EventArg &),
|
||||||
int winid = wxID_ANY,
|
int winid = wxID_ANY,
|
||||||
int lastId = wxID_ANY,
|
int lastId = wxID_ANY,
|
||||||
wxObject *userData = NULL)
|
wxObject *userData = NULL)
|
||||||
{
|
{
|
||||||
DoConnect(winid, lastId, eventType,
|
DoBind(winid, lastId, eventType,
|
||||||
|
wxNewEventFunctor(eventType, function),
|
||||||
|
userData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename EventTag, typename EventArg>
|
||||||
|
bool Unbind(const EventTag& eventType,
|
||||||
|
void (*function)(EventArg &),
|
||||||
|
int winid = wxID_ANY,
|
||||||
|
int lastId = wxID_ANY,
|
||||||
|
wxObject *userData = NULL)
|
||||||
|
{
|
||||||
|
return DoUnbind(winid, lastId, eventType,
|
||||||
|
wxMakeEventFunctor(eventType, function),
|
||||||
|
userData);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bind functors to an event:
|
||||||
|
template <typename EventTag, typename Functor>
|
||||||
|
void Bind(const EventTag& eventType,
|
||||||
|
Functor &functor,
|
||||||
|
int winid = wxID_ANY,
|
||||||
|
int lastId = wxID_ANY,
|
||||||
|
wxObject *userData = NULL)
|
||||||
|
{
|
||||||
|
DoBind(winid, lastId, eventType,
|
||||||
wxNewEventFunctor(eventType, functor),
|
wxNewEventFunctor(eventType, functor),
|
||||||
userData);
|
userData);
|
||||||
}
|
}
|
||||||
@@ -2933,12 +3072,12 @@ public:
|
|||||||
|
|
||||||
template <typename EventTag, typename Functor>
|
template <typename EventTag, typename Functor>
|
||||||
bool Unbind(const EventTag& eventType,
|
bool Unbind(const EventTag& eventType,
|
||||||
Functor functor,
|
Functor &functor,
|
||||||
int winid = wxID_ANY,
|
int winid = wxID_ANY,
|
||||||
int lastId = wxID_ANY,
|
int lastId = wxID_ANY,
|
||||||
wxObject *userData = NULL)
|
wxObject *userData = NULL)
|
||||||
{
|
{
|
||||||
return DoDisconnect(winid, lastId, eventType,
|
return DoUnbind(winid, lastId, eventType,
|
||||||
wxMakeEventFunctor(eventType, functor),
|
wxMakeEventFunctor(eventType, functor),
|
||||||
userData);
|
userData);
|
||||||
}
|
}
|
||||||
@@ -2955,7 +3094,7 @@ public:
|
|||||||
int lastId = wxID_ANY,
|
int lastId = wxID_ANY,
|
||||||
wxObject *userData = NULL)
|
wxObject *userData = NULL)
|
||||||
{
|
{
|
||||||
DoConnect(winid, lastId, eventType,
|
DoBind(winid, lastId, eventType,
|
||||||
wxNewEventFunctor(eventType, method, handler),
|
wxNewEventFunctor(eventType, method, handler),
|
||||||
userData);
|
userData);
|
||||||
}
|
}
|
||||||
@@ -2968,11 +3107,11 @@ public:
|
|||||||
int lastId = wxID_ANY,
|
int lastId = wxID_ANY,
|
||||||
wxObject *userData = NULL )
|
wxObject *userData = NULL )
|
||||||
{
|
{
|
||||||
return DoDisconnect(winid, lastId, eventType,
|
return DoUnbind(winid, lastId, eventType,
|
||||||
wxMakeEventFunctor(eventType, method, handler),
|
wxMakeEventFunctor(eventType, method, handler),
|
||||||
userData);
|
userData);
|
||||||
}
|
}
|
||||||
#endif // !wxEVENTS_COMPATIBILITY_2_8
|
#endif // wxHAS_EVENT_BIND
|
||||||
|
|
||||||
wxList* GetDynamicEventTable() const { return m_dynamicEvents ; }
|
wxList* GetDynamicEventTable() const { return m_dynamicEvents ; }
|
||||||
|
|
||||||
@@ -3014,13 +3153,13 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DoConnect(int winid,
|
void DoBind(int winid,
|
||||||
int lastId,
|
int lastId,
|
||||||
wxEventType eventType,
|
wxEventType eventType,
|
||||||
wxEventFunctor *func,
|
wxEventFunctor *func,
|
||||||
wxObject* userData = NULL);
|
wxObject* userData = NULL);
|
||||||
|
|
||||||
bool DoDisconnect(int winid,
|
bool DoUnbind(int winid,
|
||||||
int lastId,
|
int lastId,
|
||||||
wxEventType eventType,
|
wxEventType eventType,
|
||||||
const wxEventFunctor& func,
|
const wxEventFunctor& func,
|
||||||
@@ -3155,13 +3294,6 @@ private:
|
|||||||
wxDECLARE_NO_ASSIGN_CLASS(wxEventConnectionRef);
|
wxDECLARE_NO_ASSIGN_CLASS(wxEventConnectionRef);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void wxObjectEventFunctor::operator()(wxEvtHandler *handler, wxEvent& event)
|
|
||||||
{
|
|
||||||
wxEvtHandler * const realHandler = m_handler ? m_handler : handler;
|
|
||||||
|
|
||||||
(realHandler->*m_method)(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Post a message to the given event handler which will be processed during the
|
// Post a message to the given event handler which will be processed during the
|
||||||
// next event loop iteration.
|
// next event loop iteration.
|
||||||
//
|
//
|
||||||
@@ -3771,17 +3903,17 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent&
|
|||||||
// (and not in a private header) because the base class must be visible from
|
// (and not in a private header) because the base class must be visible from
|
||||||
// other public headers, please do NOT use this in your code, it will be
|
// other public headers, please do NOT use this in your code, it will be
|
||||||
// removed from future wx versions without warning.
|
// removed from future wx versions without warning.
|
||||||
#if wxEVENTS_COMPATIBILITY_2_8
|
#ifndef wxHAS_EVENT_BIND
|
||||||
#define wxBIND_OR_CONNECT_HACK_BASE_CLASS public wxEvtHandler,
|
#define wxBIND_OR_CONNECT_HACK_BASE_CLASS public wxEvtHandler,
|
||||||
#define wxBIND_OR_CONNECT_HACK_ONLY_BASE_CLASS : public wxEvtHandler
|
#define wxBIND_OR_CONNECT_HACK_ONLY_BASE_CLASS : public wxEvtHandler
|
||||||
#define wxBIND_OR_CONNECT_HACK(w, evt, handler, func, obj) \
|
#define wxBIND_OR_CONNECT_HACK(w, evt, handler, func, obj) \
|
||||||
win->Connect(evt, handler(func), NULL, obj)
|
win->Connect(evt, handler(func), NULL, obj)
|
||||||
#else // wxEVENTS_COMPATIBILITY_2_8
|
#else // wxHAS_EVENT_BIND
|
||||||
#define wxBIND_OR_CONNECT_HACK_BASE_CLASS
|
#define wxBIND_OR_CONNECT_HACK_BASE_CLASS
|
||||||
#define wxBIND_OR_CONNECT_HACK_ONLY_BASE_CLASS
|
#define wxBIND_OR_CONNECT_HACK_ONLY_BASE_CLASS
|
||||||
#define wxBIND_OR_CONNECT_HACK(w, evt, handler, func, obj) \
|
#define wxBIND_OR_CONNECT_HACK(w, evt, handler, func, obj) \
|
||||||
win->Bind(evt, &func, obj)
|
win->Bind(evt, &func, obj)
|
||||||
#endif // wxEVENTS_COMPATIBILITY_2_8/!wxEVENTS_COMPATIBILITY_2_8
|
#endif // wxHAS_EVENT_BIND
|
||||||
|
|
||||||
#if wxUSE_GUI
|
#if wxUSE_GUI
|
||||||
|
|
||||||
|
@@ -99,5 +99,13 @@
|
|||||||
#define wxHAVE_RAW_BITMAP
|
#define wxHAVE_RAW_BITMAP
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
If this is defined, wxEvtHandler::Bind<>() is available (not all compilers
|
||||||
|
have the required template support for this and in particular under Windows
|
||||||
|
where only g++ and MSVC >= 7 currently support it, for the others it will be
|
||||||
|
undefined in wx/chkconf.h).
|
||||||
|
*/
|
||||||
|
#define wxHAS_EVENT_BIND
|
||||||
|
|
||||||
#endif /* _WX_FEATURES_H_ */
|
#endif /* _WX_FEATURES_H_ */
|
||||||
|
|
||||||
|
@@ -47,19 +47,6 @@
|
|||||||
// Recommended setting: 0 (please update your code)
|
// Recommended setting: 0 (please update your code)
|
||||||
#define WXWIN_COMPATIBILITY_2_8 1
|
#define WXWIN_COMPATIBILITY_2_8 1
|
||||||
|
|
||||||
// Use the 2.8-compatible events and Connect(): this is set to 0 by default as
|
|
||||||
// the new events bring significant benefits in compile-time safety and
|
|
||||||
// flexibility but can be disabled to somewhat reduce the compilation time and,
|
|
||||||
// especially, to still allow building if the compiler template support is too
|
|
||||||
// bad to compile the new code.
|
|
||||||
//
|
|
||||||
// Default is 0 but this is set to 1 automatically in wx/chkconf.h for the
|
|
||||||
// compilers which can't build the new code (currently only g++ and MSVC >= 8
|
|
||||||
// can)
|
|
||||||
//
|
|
||||||
// Recommended setting: 0
|
|
||||||
#define wxEVENTS_COMPATIBILITY_2_8 0
|
|
||||||
|
|
||||||
// MSW-only: Set to 0 for accurate dialog units, else 1 for old behaviour when
|
// MSW-only: Set to 0 for accurate dialog units, else 1 for old behaviour when
|
||||||
// default system font is used for wxWindow::GetCharWidth/Height() instead of
|
// default system font is used for wxWindow::GetCharWidth/Height() instead of
|
||||||
// the current font.
|
// the current font.
|
||||||
|
@@ -415,10 +415,9 @@
|
|||||||
Currently only recent MSVC compilers can build the new events code under
|
Currently only recent MSVC compilers can build the new events code under
|
||||||
Windows.
|
Windows.
|
||||||
*/
|
*/
|
||||||
#if !wxEVENTS_COMPATIBILITY_2_8
|
#ifdef wxHAS_EVENT_BIND
|
||||||
# if !wxCHECK_VISUALC_VERSION(7)
|
# if !wxCHECK_VISUALC_VERSION(7)
|
||||||
# undef wxEVENTS_COMPATIBILITY_2_8
|
# undef wxHAS_EVENT_BIND
|
||||||
# define wxEVENTS_COMPATIBILITY_2_8 1
|
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -47,19 +47,6 @@
|
|||||||
// Recommended setting: 0 (please update your code)
|
// Recommended setting: 0 (please update your code)
|
||||||
#define WXWIN_COMPATIBILITY_2_8 1
|
#define WXWIN_COMPATIBILITY_2_8 1
|
||||||
|
|
||||||
// Use the 2.8-compatible events and Connect(): this is set to 0 by default as
|
|
||||||
// the new events bring significant benefits in compile-time safety and
|
|
||||||
// flexibility but can be disabled to somewhat reduce the compilation time and,
|
|
||||||
// especially, to still allow building if the compiler template support is too
|
|
||||||
// bad to compile the new code.
|
|
||||||
//
|
|
||||||
// Default is 0 but this is set to 1 automatically in wx/chkconf.h for the
|
|
||||||
// compilers which can't build the new code (currently only g++ and MSVC >= 8
|
|
||||||
// can)
|
|
||||||
//
|
|
||||||
// Recommended setting: 0
|
|
||||||
#define wxEVENTS_COMPATIBILITY_2_8 0
|
|
||||||
|
|
||||||
// MSW-only: Set to 0 for accurate dialog units, else 1 for old behaviour when
|
// MSW-only: Set to 0 for accurate dialog units, else 1 for old behaviour when
|
||||||
// default system font is used for wxWindow::GetCharWidth/Height() instead of
|
// default system font is used for wxWindow::GetCharWidth/Height() instead of
|
||||||
// the current font.
|
// the current font.
|
||||||
|
@@ -47,19 +47,6 @@
|
|||||||
// Recommended setting: 0 (please update your code)
|
// Recommended setting: 0 (please update your code)
|
||||||
#define WXWIN_COMPATIBILITY_2_8 1
|
#define WXWIN_COMPATIBILITY_2_8 1
|
||||||
|
|
||||||
// Use the 2.8-compatible events and Connect(): this is set to 0 by default as
|
|
||||||
// the new events bring significant benefits in compile-time safety and
|
|
||||||
// flexibility but can be disabled to somewhat reduce the compilation time and,
|
|
||||||
// especially, to still allow building if the compiler template support is too
|
|
||||||
// bad to compile the new code.
|
|
||||||
//
|
|
||||||
// Default is 0 but this is set to 1 automatically in wx/chkconf.h for the
|
|
||||||
// compilers which can't build the new code (currently only g++ and MSVC >= 8
|
|
||||||
// can)
|
|
||||||
//
|
|
||||||
// Recommended setting: 0
|
|
||||||
#define wxEVENTS_COMPATIBILITY_2_8 0
|
|
||||||
|
|
||||||
// MSW-only: Set to 0 for accurate dialog units, else 1 for old behaviour when
|
// MSW-only: Set to 0 for accurate dialog units, else 1 for old behaviour when
|
||||||
// default system font is used for wxWindow::GetCharWidth/Height() instead of
|
// default system font is used for wxWindow::GetCharWidth/Height() instead of
|
||||||
// the current font.
|
// the current font.
|
||||||
|
@@ -47,19 +47,6 @@
|
|||||||
// Recommended setting: 0 (please update your code)
|
// Recommended setting: 0 (please update your code)
|
||||||
#define WXWIN_COMPATIBILITY_2_8 1
|
#define WXWIN_COMPATIBILITY_2_8 1
|
||||||
|
|
||||||
// Use the 2.8-compatible events and Connect(): this is set to 0 by default as
|
|
||||||
// the new events bring significant benefits in compile-time safety and
|
|
||||||
// flexibility but can be disabled to somewhat reduce the compilation time and,
|
|
||||||
// especially, to still allow building if the compiler template support is too
|
|
||||||
// bad to compile the new code.
|
|
||||||
//
|
|
||||||
// Default is 0 but this is set to 1 automatically in wx/chkconf.h for the
|
|
||||||
// compilers which can't build the new code (currently only g++ and MSVC >= 8
|
|
||||||
// can)
|
|
||||||
//
|
|
||||||
// Recommended setting: 0
|
|
||||||
#define wxEVENTS_COMPATIBILITY_2_8 0
|
|
||||||
|
|
||||||
// MSW-only: Set to 0 for accurate dialog units, else 1 for old behaviour when
|
// MSW-only: Set to 0 for accurate dialog units, else 1 for old behaviour when
|
||||||
// default system font is used for wxWindow::GetCharWidth/Height() instead of
|
// default system font is used for wxWindow::GetCharWidth/Height() instead of
|
||||||
// the current font.
|
// the current font.
|
||||||
|
@@ -48,19 +48,6 @@
|
|||||||
// Recommended setting: 0 (please update your code)
|
// Recommended setting: 0 (please update your code)
|
||||||
#define WXWIN_COMPATIBILITY_2_8 1
|
#define WXWIN_COMPATIBILITY_2_8 1
|
||||||
|
|
||||||
// Use the 2.8-compatible events and Connect(): this is set to 0 by default as
|
|
||||||
// the new events bring significant benefits in compile-time safety and
|
|
||||||
// flexibility but can be disabled to somewhat reduce the compilation time and,
|
|
||||||
// especially, to still allow building if the compiler template support is too
|
|
||||||
// bad to compile the new code.
|
|
||||||
//
|
|
||||||
// Default is 0 but this is set to 1 automatically in wx/chkconf.h for the
|
|
||||||
// compilers which can't build the new code (currently only g++ and MSVC >= 8
|
|
||||||
// can)
|
|
||||||
//
|
|
||||||
// Recommended setting: 0
|
|
||||||
#define wxEVENTS_COMPATIBILITY_2_8 0
|
|
||||||
|
|
||||||
// MSW-only: Set to 0 for accurate dialog units, else 1 for old behaviour when
|
// MSW-only: Set to 0 for accurate dialog units, else 1 for old behaviour when
|
||||||
// default system font is used for wxWindow::GetCharWidth/Height() instead of
|
// default system font is used for wxWindow::GetCharWidth/Height() instead of
|
||||||
// the current font.
|
// the current font.
|
||||||
|
@@ -47,19 +47,6 @@
|
|||||||
// Recommended setting: 0 (please update your code)
|
// Recommended setting: 0 (please update your code)
|
||||||
#define WXWIN_COMPATIBILITY_2_8 1
|
#define WXWIN_COMPATIBILITY_2_8 1
|
||||||
|
|
||||||
// Use the 2.8-compatible events and Connect(): this is set to 0 by default as
|
|
||||||
// the new events bring significant benefits in compile-time safety and
|
|
||||||
// flexibility but can be disabled to somewhat reduce the compilation time and,
|
|
||||||
// especially, to still allow building if the compiler template support is too
|
|
||||||
// bad to compile the new code.
|
|
||||||
//
|
|
||||||
// Default is 0 but this is set to 1 automatically in wx/chkconf.h for the
|
|
||||||
// compilers which can't build the new code (currently only g++ and MSVC >= 8
|
|
||||||
// can)
|
|
||||||
//
|
|
||||||
// Recommended setting: 0
|
|
||||||
#define wxEVENTS_COMPATIBILITY_2_8 0
|
|
||||||
|
|
||||||
// MSW-only: Set to 0 for accurate dialog units, else 1 for old behaviour when
|
// MSW-only: Set to 0 for accurate dialog units, else 1 for old behaviour when
|
||||||
// default system font is used for wxWindow::GetCharWidth/Height() instead of
|
// default system font is used for wxWindow::GetCharWidth/Height() instead of
|
||||||
// the current font.
|
// the current font.
|
||||||
|
@@ -43,19 +43,6 @@
|
|||||||
// Recommended setting: 0 (please update your code)
|
// Recommended setting: 0 (please update your code)
|
||||||
#define WXWIN_COMPATIBILITY_2_8 1
|
#define WXWIN_COMPATIBILITY_2_8 1
|
||||||
|
|
||||||
// Use the 2.8-compatible events and Connect(): this is set to 0 by default as
|
|
||||||
// the new events bring significant benefits in compile-time safety and
|
|
||||||
// flexibility but can be disabled to somewhat reduce the compilation time and,
|
|
||||||
// especially, to still allow building if the compiler template support is too
|
|
||||||
// bad to compile the new code.
|
|
||||||
//
|
|
||||||
// Default is 0 but this is set to 1 automatically in wx/chkconf.h for the
|
|
||||||
// compilers which can't build the new code (currently only g++ and MSVC >= 8
|
|
||||||
// can)
|
|
||||||
//
|
|
||||||
// Recommended setting: 0
|
|
||||||
#define wxEVENTS_COMPATIBILITY_2_8 0
|
|
||||||
|
|
||||||
// MSW-only: Set to 0 for accurate dialog units, else 1 for old behaviour when
|
// MSW-only: Set to 0 for accurate dialog units, else 1 for old behaviour when
|
||||||
// default system font is used for wxWindow::GetCharWidth/Height() instead of
|
// default system font is used for wxWindow::GetCharWidth/Height() instead of
|
||||||
// the current font.
|
// the current font.
|
||||||
|
@@ -46,19 +46,6 @@
|
|||||||
// Recommended setting: 0 (please update your code)
|
// Recommended setting: 0 (please update your code)
|
||||||
#define WXWIN_COMPATIBILITY_2_8 1
|
#define WXWIN_COMPATIBILITY_2_8 1
|
||||||
|
|
||||||
// Use the 2.8-compatible events and Connect(): this is set to 0 by default as
|
|
||||||
// the new events bring significant benefits in compile-time safety and
|
|
||||||
// flexibility but can be disabled to somewhat reduce the compilation time and,
|
|
||||||
// especially, to still allow building if the compiler template support is too
|
|
||||||
// bad to compile the new code.
|
|
||||||
//
|
|
||||||
// Default is 0 but this is set to 1 automatically in wx/chkconf.h for the
|
|
||||||
// compilers which can't build the new code (currently only g++ and MSVC >= 8
|
|
||||||
// can)
|
|
||||||
//
|
|
||||||
// Recommended setting: 0
|
|
||||||
#define wxEVENTS_COMPATIBILITY_2_8 0
|
|
||||||
|
|
||||||
// MSW-only: Set to 0 for accurate dialog units, else 1 for old behaviour when
|
// MSW-only: Set to 0 for accurate dialog units, else 1 for old behaviour when
|
||||||
// default system font is used for wxWindow::GetCharWidth/Height() instead of
|
// default system font is used for wxWindow::GetCharWidth/Height() instead of
|
||||||
// the current font.
|
// the current font.
|
||||||
|
@@ -77,9 +77,9 @@ public:
|
|||||||
|
|
||||||
void OnQuit(wxCommandEvent& event);
|
void OnQuit(wxCommandEvent& event);
|
||||||
void OnAbout(wxCommandEvent& event);
|
void OnAbout(wxCommandEvent& event);
|
||||||
#if !wxEVENTS_COMPATIBILITY_2_8
|
#ifdef wxHAS_EVENT_BIND
|
||||||
void OnBind(wxCommandEvent& event);
|
void OnBind(wxCommandEvent& event);
|
||||||
#endif // !wxEVENTS_COMPATIBILITY_2_8
|
#endif // wxHAS_EVENT_BIND
|
||||||
void OnConnect(wxCommandEvent& event);
|
void OnConnect(wxCommandEvent& event);
|
||||||
void OnDynamic(wxCommandEvent& event);
|
void OnDynamic(wxCommandEvent& event);
|
||||||
void OnPushEventHandler(wxCommandEvent& event);
|
void OnPushEventHandler(wxCommandEvent& event);
|
||||||
@@ -177,9 +177,9 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
EVT_MENU(Event_Quit, MyFrame::OnQuit)
|
EVT_MENU(Event_Quit, MyFrame::OnQuit)
|
||||||
EVT_MENU(Event_About, MyFrame::OnAbout)
|
EVT_MENU(Event_About, MyFrame::OnAbout)
|
||||||
|
|
||||||
#if !wxEVENTS_COMPATIBILITY_2_8
|
#ifdef wxHAS_EVENT_BIND
|
||||||
EVT_MENU(Event_Bind, MyFrame::OnBind)
|
EVT_MENU(Event_Bind, MyFrame::OnBind)
|
||||||
#endif // !wxEVENTS_COMPATIBILITY_2_8
|
#endif // wxHAS_EVENT_BIND
|
||||||
EVT_MENU(Event_Connect, MyFrame::OnConnect)
|
EVT_MENU(Event_Connect, MyFrame::OnConnect)
|
||||||
|
|
||||||
EVT_MENU(Event_Custom, MyFrame::OnFireCustom)
|
EVT_MENU(Event_Custom, MyFrame::OnFireCustom)
|
||||||
@@ -257,10 +257,10 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
|||||||
menuFile->Append(Event_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
|
menuFile->Append(Event_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
|
||||||
|
|
||||||
wxMenu *menuEvent = new wxMenu;
|
wxMenu *menuEvent = new wxMenu;
|
||||||
#if !wxEVENTS_COMPATIBILITY_2_8
|
#ifdef wxHAS_EVENT_BIND
|
||||||
menuEvent->AppendCheckItem(Event_Bind, "&Bind\tCtrl-B",
|
menuEvent->AppendCheckItem(Event_Bind, "&Bind\tCtrl-B",
|
||||||
"Bind or unbind a dynamic event handler");
|
"Bind or unbind a dynamic event handler");
|
||||||
#endif // !wxEVENTS_COMPATIBILITY_2_8
|
#endif // wxHAS_EVENT_BIND
|
||||||
menuEvent->AppendCheckItem(Event_Connect, _T("&Connect\tCtrl-C"),
|
menuEvent->AppendCheckItem(Event_Connect, _T("&Connect\tCtrl-C"),
|
||||||
_T("Connect or disconnect the dynamic event handler"));
|
_T("Connect or disconnect the dynamic event handler"));
|
||||||
menuEvent->Append(Event_Dynamic, _T("&Dynamic event\tCtrl-D"),
|
menuEvent->Append(Event_Dynamic, _T("&Dynamic event\tCtrl-D"),
|
||||||
@@ -352,7 +352,7 @@ void MyFrame::OnDynamic(wxCommandEvent& event)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !wxEVENTS_COMPATIBILITY_2_8
|
#ifdef wxHAS_EVENT_BIND
|
||||||
|
|
||||||
void MyFrame::OnBind(wxCommandEvent& event)
|
void MyFrame::OnBind(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
@@ -379,7 +379,7 @@ void MyFrame::OnBind(wxCommandEvent& event)
|
|||||||
UpdateDynamicStatus(event.IsChecked());
|
UpdateDynamicStatus(event.IsChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !wxEVENTS_COMPATIBILITY_2_8
|
#endif // wxHAS_EVENT_BIND
|
||||||
|
|
||||||
void MyFrame::OnConnect(wxCommandEvent& event)
|
void MyFrame::OnConnect(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
|
@@ -152,8 +152,6 @@
|
|||||||
|
|
||||||
#define WXWIN_COMPATIBILITY_2_8 0
|
#define WXWIN_COMPATIBILITY_2_8 0
|
||||||
|
|
||||||
#define wxEVENTS_COMPATIBILITY_2_8 0
|
|
||||||
|
|
||||||
#define wxDIALOG_UNIT_COMPATIBILITY 0
|
#define wxDIALOG_UNIT_COMPATIBILITY 0
|
||||||
|
|
||||||
|
|
||||||
|
@@ -503,7 +503,7 @@ void wxAppConsoleBase::CallEventHandler(wxEvtHandler *handler,
|
|||||||
{
|
{
|
||||||
// If the functor holds a method then, for backward compatibility, call
|
// If the functor holds a method then, for backward compatibility, call
|
||||||
// HandleEvent():
|
// HandleEvent():
|
||||||
wxEventFunction eventFunction = functor.GetMethod();
|
wxEventFunction eventFunction = functor.GetEvtMethod();
|
||||||
|
|
||||||
if ( eventFunction )
|
if ( eventFunction )
|
||||||
HandleEvent(handler, eventFunction, event);
|
HandleEvent(handler, eventFunction, event);
|
||||||
|
@@ -1415,11 +1415,11 @@ bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxEvtHandler::DoConnect(int id,
|
void wxEvtHandler::DoBind(int id,
|
||||||
int lastId,
|
int lastId,
|
||||||
wxEventType eventType,
|
wxEventType eventType,
|
||||||
wxEventFunctor *func,
|
wxEventFunctor *func,
|
||||||
wxObject *userData)
|
wxObject *userData)
|
||||||
{
|
{
|
||||||
wxDynamicEventTableEntry *entry =
|
wxDynamicEventTableEntry *entry =
|
||||||
new wxDynamicEventTableEntry(eventType, id, lastId, func, userData);
|
new wxDynamicEventTableEntry(eventType, id, lastId, func, userData);
|
||||||
@@ -1443,11 +1443,11 @@ void wxEvtHandler::DoConnect(int id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
wxEvtHandler::DoDisconnect(int id,
|
wxEvtHandler::DoUnbind(int id,
|
||||||
int lastId,
|
int lastId,
|
||||||
wxEventType eventType,
|
wxEventType eventType,
|
||||||
const wxEventFunctor& func,
|
const wxEventFunctor& func,
|
||||||
wxObject *userData)
|
wxObject *userData)
|
||||||
{
|
{
|
||||||
if (!m_dynamicEvents)
|
if (!m_dynamicEvents)
|
||||||
return false;
|
return false;
|
||||||
@@ -1469,7 +1469,7 @@ wxEvtHandler::DoDisconnect(int id,
|
|||||||
if ((entry->m_id == id) &&
|
if ((entry->m_id == id) &&
|
||||||
((entry->m_lastId == lastId) || (lastId == wxID_ANY)) &&
|
((entry->m_lastId == lastId) || (lastId == wxID_ANY)) &&
|
||||||
((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) &&
|
((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) &&
|
||||||
entry->m_fn->Matches(func) &&
|
entry->m_fn->IsMatching(func) &&
|
||||||
((entry->m_callbackUserData == userData) || !userData))
|
((entry->m_callbackUserData == userData) || !userData))
|
||||||
{
|
{
|
||||||
delete entry->m_callbackUserData;
|
delete entry->m_callbackUserData;
|
||||||
|
@@ -37,7 +37,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef void (wxEvtHandler::*MyEventFunction)(MyEvent&);
|
typedef void (wxEvtHandler::*MyEventFunction)(MyEvent&);
|
||||||
#if wxEVENTS_COMPATIBILITY_2_8
|
#ifndef wxHAS_EVENT_BIND
|
||||||
#define MyEventHandler(func) wxEVENT_HANDLER_CAST(MyEventFunction, func)
|
#define MyEventHandler(func) wxEVENT_HANDLER_CAST(MyEventFunction, func)
|
||||||
#else
|
#else
|
||||||
#define MyEventHandler(func) &func
|
#define MyEventHandler(func) &func
|
||||||
@@ -75,6 +75,11 @@ void GlobalOnMyEvent(MyEvent&)
|
|||||||
g_called.function = true;
|
g_called.function = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GlobalOnEvent(wxEvent&)
|
||||||
|
{
|
||||||
|
g_called.function = true;
|
||||||
|
}
|
||||||
|
|
||||||
void GlobalOnAnotherEvent(AnotherEvent&);
|
void GlobalOnAnotherEvent(AnotherEvent&);
|
||||||
|
|
||||||
void GlobalOnIdle(wxIdleEvent&)
|
void GlobalOnIdle(wxIdleEvent&)
|
||||||
@@ -130,7 +135,7 @@ BEGIN_EVENT_TABLE(MyClassWithEventTable, wxEvtHandler)
|
|||||||
EVT_IDLE(MyClassWithEventTable::OnIdle)
|
EVT_IDLE(MyClassWithEventTable::OnIdle)
|
||||||
|
|
||||||
EVT_MYEVENT(MyClassWithEventTable::OnMyEvent)
|
EVT_MYEVENT(MyClassWithEventTable::OnMyEvent)
|
||||||
#if !wxEVENTS_COMPATIBILITY_2_8
|
#ifdef wxHAS_EVENT_BIND
|
||||||
EVT_MYEVENT(MyClassWithEventTable::OnEvent)
|
EVT_MYEVENT(MyClassWithEventTable::OnEvent)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -155,28 +160,30 @@ private:
|
|||||||
CPPUNIT_TEST_SUITE( EvtHandlerTestCase );
|
CPPUNIT_TEST_SUITE( EvtHandlerTestCase );
|
||||||
CPPUNIT_TEST( BuiltinConnect );
|
CPPUNIT_TEST( BuiltinConnect );
|
||||||
CPPUNIT_TEST( LegacyConnect );
|
CPPUNIT_TEST( LegacyConnect );
|
||||||
#if !wxEVENTS_COMPATIBILITY_2_8
|
#ifdef wxHAS_EVENT_BIND
|
||||||
CPPUNIT_TEST( BindFunction );
|
CPPUNIT_TEST( BindFunction );
|
||||||
CPPUNIT_TEST( BindStaticMethod );
|
CPPUNIT_TEST( BindStaticMethod );
|
||||||
CPPUNIT_TEST( BindFunctor );
|
CPPUNIT_TEST( BindFunctor );
|
||||||
CPPUNIT_TEST( BindMethod );
|
CPPUNIT_TEST( BindMethod );
|
||||||
CPPUNIT_TEST( BindMethodUsingBaseEvent );
|
CPPUNIT_TEST( BindMethodUsingBaseEvent );
|
||||||
|
CPPUNIT_TEST( BindFunctionUsingBaseEvent );
|
||||||
CPPUNIT_TEST( BindNonHandler );
|
CPPUNIT_TEST( BindNonHandler );
|
||||||
CPPUNIT_TEST( InvalidBind );
|
CPPUNIT_TEST( InvalidBind );
|
||||||
#endif // !wxEVENTS_COMPATIBILITY_2_8
|
#endif // wxHAS_EVENT_BIND
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
void BuiltinConnect();
|
void BuiltinConnect();
|
||||||
void LegacyConnect();
|
void LegacyConnect();
|
||||||
#if !wxEVENTS_COMPATIBILITY_2_8
|
#ifdef wxHAS_EVENT_BIND
|
||||||
void BindFunction();
|
void BindFunction();
|
||||||
void BindStaticMethod();
|
void BindStaticMethod();
|
||||||
void BindFunctor();
|
void BindFunctor();
|
||||||
void BindMethod();
|
void BindMethod();
|
||||||
void BindMethodUsingBaseEvent();
|
void BindMethodUsingBaseEvent();
|
||||||
|
void BindFunctionUsingBaseEvent();
|
||||||
void BindNonHandler();
|
void BindNonHandler();
|
||||||
void InvalidBind();
|
void InvalidBind();
|
||||||
#endif // !wxEVENTS_COMPATIBILITY_2_8
|
#endif // wxHAS_EVENT_BIND
|
||||||
|
|
||||||
|
|
||||||
// these member variables exceptionally don't use "m_" prefix because
|
// these member variables exceptionally don't use "m_" prefix because
|
||||||
@@ -206,7 +213,7 @@ void EvtHandlerTestCase::BuiltinConnect()
|
|||||||
handler.Connect(wxEVT_IDLE, (wxObjectEventFunction)(wxEventFunction)&MyHandler::OnIdle);
|
handler.Connect(wxEVT_IDLE, (wxObjectEventFunction)(wxEventFunction)&MyHandler::OnIdle);
|
||||||
handler.Disconnect(wxEVT_IDLE, (wxObjectEventFunction)(wxEventFunction)&MyHandler::OnIdle);
|
handler.Disconnect(wxEVT_IDLE, (wxObjectEventFunction)(wxEventFunction)&MyHandler::OnIdle);
|
||||||
|
|
||||||
#if !wxEVENTS_COMPATIBILITY_2_8
|
#ifdef wxHAS_EVENT_BIND
|
||||||
handler.Bind(wxEVT_IDLE, GlobalOnIdle);
|
handler.Bind(wxEVT_IDLE, GlobalOnIdle);
|
||||||
handler.Unbind(wxEVT_IDLE, GlobalOnIdle);
|
handler.Unbind(wxEVT_IDLE, GlobalOnIdle);
|
||||||
|
|
||||||
@@ -219,7 +226,7 @@ void EvtHandlerTestCase::BuiltinConnect()
|
|||||||
|
|
||||||
handler.Bind(wxEVT_IDLE, &MyHandler::StaticOnIdle);
|
handler.Bind(wxEVT_IDLE, &MyHandler::StaticOnIdle);
|
||||||
handler.Unbind(wxEVT_IDLE, &MyHandler::StaticOnIdle);
|
handler.Unbind(wxEVT_IDLE, &MyHandler::StaticOnIdle);
|
||||||
#endif // !wxEVENTS_COMPATIBILITY_2_8
|
#endif // wxHAS_EVENT_BIND
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvtHandlerTestCase::LegacyConnect()
|
void EvtHandlerTestCase::LegacyConnect()
|
||||||
@@ -242,7 +249,7 @@ void EvtHandlerTestCase::LegacyConnect()
|
|||||||
handler.Disconnect( 0, 0, LegacyEventType, (wxObjectEventFunction)&MyHandler::OnEvent, NULL, &handler );
|
handler.Disconnect( 0, 0, LegacyEventType, (wxObjectEventFunction)&MyHandler::OnEvent, NULL, &handler );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !wxEVENTS_COMPATIBILITY_2_8
|
#ifdef wxHAS_EVENT_BIND
|
||||||
|
|
||||||
void EvtHandlerTestCase::BindFunction()
|
void EvtHandlerTestCase::BindFunction()
|
||||||
{
|
{
|
||||||
@@ -345,6 +352,29 @@ void EvtHandlerTestCase::BindMethodUsingBaseEvent()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void EvtHandlerTestCase::BindFunctionUsingBaseEvent()
|
||||||
|
{
|
||||||
|
// test connecting a function taking just wxEvent and not MyEvent: this
|
||||||
|
// should work too if we don't need any MyEvent-specific information in the
|
||||||
|
// handler
|
||||||
|
handler.Bind( MyEventType, GlobalOnEvent );
|
||||||
|
g_called.Reset();
|
||||||
|
handler.ProcessEvent(e);
|
||||||
|
CPPUNIT_ASSERT( g_called.function );
|
||||||
|
handler.Unbind( MyEventType, GlobalOnEvent );
|
||||||
|
g_called.Reset();
|
||||||
|
handler.ProcessEvent(e);
|
||||||
|
CPPUNIT_ASSERT( !g_called.function );
|
||||||
|
|
||||||
|
handler.Bind( MyEventType, GlobalOnEvent, 0 );
|
||||||
|
handler.Unbind( MyEventType, GlobalOnEvent, 0 );
|
||||||
|
|
||||||
|
handler.Bind( MyEventType, GlobalOnEvent, 0, 0 );
|
||||||
|
handler.Unbind( MyEventType, GlobalOnEvent, 0, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void EvtHandlerTestCase::BindNonHandler()
|
void EvtHandlerTestCase::BindNonHandler()
|
||||||
{
|
{
|
||||||
// class method tests for class not derived from wxEvtHandler
|
// class method tests for class not derived from wxEvtHandler
|
||||||
@@ -402,4 +432,4 @@ void EvtHandlerTestCase::InvalidBind()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !wxEVENTS_COMPATIBILITY_2_8
|
#endif // wxHAS_EVENT_BIND
|
||||||
|
Reference in New Issue
Block a user