Changes to template Connect() to make it compile with MSVC7 and possible other

not quite up-to-date compilers, to reduce repetitions and to allow using
methods of non-wxEvtHandler-derived classes as event callbacks:

1. Don't rely on compiler ability to deduce template parameter from the type
   of a parameter of a function used as another template parameter, at least
   MSVC7 can't do this and it's probably not the only one.
2. Do rely on compiler support for partial specialization to make
   wxEventFunctorMethod compile for non-wxEvtHandler-derived handlers while
   still keeping the old functionality for the wxEvtHandler-derived ones.
3. Don't make any difference between functions and functors, both are callable
   objects so use them as such, this allows to fold code for both cases.
4. Avoid the use of dynamic_cast<>.
5. Several naming changes:
 a) wxTypedEventType -> wxEventTypeTag (because this is what it is)
 b) Subscribe/Unsubscribe -> DoConnect/Disconnect (to follow the usual
    convention of public Foo calling private DoFoo and to avoid using up
    another name)
 c) Derived -> ObjClass (because it's not clear what does Derived mean)
6. Extend the unit test to cover more cases.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58625 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-02-02 20:38:56 +00:00
parent 4c509aecb6
commit f3ff831f3b
4 changed files with 686 additions and 568 deletions

View File

@@ -1065,7 +1065,7 @@ wxEvtHandler::~wxEvtHandler()
// Remove ourselves from sink destructor notifications
// (this has usually been done, in wxTrackable destructor)
wxEvtHandler *eventSink = entry->m_fn->GetHandler();
wxEvtHandler *eventSink = entry->m_fn->GetEvtHandler();
if ( eventSink )
{
wxEventConnectionRef * const
@@ -1408,10 +1408,11 @@ bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
return false;
}
void wxEvtHandler::Subscribe( int id, int lastId,
wxEventType eventType,
wxEventFunctor *func,
wxObject *userData )
void wxEvtHandler::DoConnect(int id,
int lastId,
wxEventType eventType,
wxEventFunctor *func,
wxObject *userData)
{
wxDynamicEventTableEntry *entry =
new wxDynamicEventTableEntry(eventType, id, lastId, func, userData);
@@ -1423,7 +1424,7 @@ void wxEvtHandler::Subscribe( int id, int lastId,
m_dynamicEvents->Insert( (wxObject*) entry );
// Make sure we get to know when a sink is destroyed
wxEvtHandler *eventSink = func->GetHandler();
wxEvtHandler *eventSink = func->GetEvtHandler();
if ( eventSink && eventSink != this )
{
wxEventConnectionRef *evtConnRef = FindRefInTrackerList(eventSink);
@@ -1435,17 +1436,17 @@ void wxEvtHandler::Subscribe( int id, int lastId,
}
bool
wxEvtHandler::Unsubscribe(int id,
int lastId,
wxEventType eventType,
const wxEventFunctor& func,
wxObject *userData)
wxEvtHandler::DoDisconnect(int id,
int lastId,
wxEventType eventType,
const wxEventFunctor& func,
wxObject *userData)
{
if (!m_dynamicEvents)
return false;
// Remove connection from tracker node (wxEventConnectionRef)
wxEvtHandler *eventSink = func.GetHandler();
wxEvtHandler *eventSink = func.GetEvtHandler();
if ( eventSink && eventSink != this )
{
wxEventConnectionRef *evtConnRef = FindRefInTrackerList(eventSink);
@@ -1490,7 +1491,7 @@ bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
if ( event.GetEventType() == entry->m_eventType )
{
wxEvtHandler *handler = entry->m_fn->GetHandler();
wxEvtHandler *handler = entry->m_fn->GetEvtHandler();
if ( !handler )
handler = this;
if ( ProcessEventIfMatchesId(*entry, handler, event) )
@@ -1571,7 +1572,7 @@ void wxEvtHandler::OnSinkDestroyed( wxEvtHandler *sink )
wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
node_nxt = node->GetNext();
if ( entry->m_fn->GetHandler() == sink )
if ( entry->m_fn->GetEvtHandler() == sink )
{
delete entry->m_callbackUserData;
m_dynamicEvents->Erase( node );