Added optional event sink for use with dynamic event tables

Removed comments and commented-out code re. focus window processing
from wxToolBarBase


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21511 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart 2003-06-30 13:11:51 +00:00
parent d48568a5ec
commit 65b17727e6
5 changed files with 37 additions and 31 deletions

View File

@ -1969,19 +1969,27 @@ struct WXDLLEXPORT wxEventTableEntry : public wxEventTableEntryBase
const int& m_eventType;
};
class WXDLLEXPORT wxEvtHandler;
// an entry used in dynamic event table managed by wxEvtHandler::Connect()
struct WXDLLEXPORT wxDynamicEventTableEntry : public wxEventTableEntryBase
{
wxDynamicEventTableEntry(int evType, int winid, int idLast,
wxObjectEventFunction fn, wxObject *data)
wxObjectEventFunction fn, wxObject *data, wxEvtHandler* eventSink)
: wxEventTableEntryBase(winid, idLast, fn, data),
m_eventType(evType)
m_eventType(evType),
m_eventSink(eventSink)
{ }
// not a reference here as we can't keep a reference to a temporary int
// created to wrap the constant value typically passed to Connect() - nor
// do we need it
int m_eventType;
// Pointer to object whose function is fn - so we don't assume the
// EventFunction is always a member of the EventHandler receiving the
// message
wxEvtHandler* m_eventSink;
};
#endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
@ -2031,23 +2039,27 @@ public:
// winid and event type
void Connect( int winid, int lastId, int eventType,
wxObjectEventFunction func,
wxObject *userData = (wxObject *) NULL );
wxObject *userData = (wxObject *) NULL,
wxEvtHandler *eventSink = (wxEvtHandler *) NULL );
// Convenience function: take just one id
void Connect( int winid, int eventType,
wxObjectEventFunction func,
wxObject *userData = (wxObject *) NULL )
{ Connect(winid, wxID_ANY, eventType, func, userData); }
wxObject *userData = (wxObject *) NULL,
wxEvtHandler *eventSink = (wxEvtHandler *) NULL )
{ Connect(winid, wxID_ANY, eventType, func, userData, eventSink); }
bool Disconnect( int winid, int lastId, wxEventType eventType,
wxObjectEventFunction func = NULL,
wxObject *userData = (wxObject *) NULL );
wxObject *userData = (wxObject *) NULL,
wxEvtHandler *eventSink = (wxEvtHandler *) NULL );
// Convenience function: take just one id
bool Disconnect( int winid, wxEventType eventType = wxEVT_NULL,
wxObjectEventFunction func = NULL,
wxObject *userData = (wxObject *) NULL )
{ return Disconnect(winid, wxID_ANY, eventType, func, userData); }
wxObject *userData = (wxObject *) NULL,
wxEvtHandler *eventSink = (wxEvtHandler *) NULL )
{ return Disconnect(winid, wxID_ANY, eventType, func, userData, eventSink); }
// User data can be associated with each wxEvtHandler

View File

@ -27,10 +27,10 @@
// Note: this is intended to be used in wxDC at some point to replace
// the current system of scaling/translation. It is not yet used.
//:defenition
//:definition
// A 3x3 matrix to do 2D transformations.
// It can be used to map data to window coordinates.
// But also for manipulating your own data.
// It can be used to map data to window coordinates,
// and also for manipulating your own data.
// For example drawing a picture (composed of several primitives)
// at a certain coordinate and angle within another parent picture.
// At all times m_isIdentity is set if the matrix itself is an Identity matrix.

View File

@ -16,7 +16,7 @@
/*
There is no wxRadioButtonBase class as wxRadioButton interface is the same
as of wxCheckBox(Base), but under some platforms wxRadioButton really
as wxCheckBox(Base), but under some platforms wxRadioButton really
derives from wxCheckBox and on the others it doesn't.
The pseudo-declaration of wxRadioButtonBase would look like this:

View File

@ -903,7 +903,8 @@ bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
void wxEvtHandler::Connect( int id, int lastId,
int eventType,
wxObjectEventFunction func,
wxObject *userData )
wxObject *userData,
wxEvtHandler* eventSink )
{
#if WXWIN_COMPATIBILITY_EVENT_TYPES
wxEventTableEntry *entry = new wxEventTableEntry;
@ -914,7 +915,7 @@ void wxEvtHandler::Connect( int id, int lastId,
entry->m_callbackUserData = userData;
#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
wxDynamicEventTableEntry *entry =
new wxDynamicEventTableEntry(eventType, id, lastId, func, userData);
new wxDynamicEventTableEntry(eventType, id, lastId, func, userData, eventSink);
#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
if (!m_dynamicEvents)
@ -926,7 +927,8 @@ void wxEvtHandler::Connect( int id, int lastId,
bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType,
wxObjectEventFunction func,
wxObject *userData )
wxObject *userData,
wxEvtHandler* eventSink )
{
if (!m_dynamicEvents)
return FALSE;
@ -944,6 +946,7 @@ bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType,
((entry->m_lastId == lastId) || (lastId == -1)) &&
((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) &&
((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) &&
((entry->m_eventSink == eventSink) || (eventSink == (wxEvtHandler*)NULL)) &&
((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL)))
{
if (entry->m_callbackUserData)
@ -985,6 +988,11 @@ bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
event.Skip(FALSE);
event.m_callbackUserData = entry->m_callbackUserData;
#if !WXWIN_COMPATIBILITY_EVENT_TYPES
if (entry->m_eventSink)
((entry->m_eventSink)->*((wxEventFunction) (entry->m_fn)))(event);
else
#endif
(this->*((wxEventFunction) (entry->m_fn)))(event);
if ( ! event.GetSkipped() )

View File

@ -591,21 +591,7 @@ void wxToolBarBase::OnIdle(wxIdleEvent& event)
// Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
void wxToolBarBase::DoToolbarUpdates()
{
wxWindow* parent = this;
while (parent->GetParent())
parent = parent->GetParent();
// This kind of #ifdef is a good way to annoy people. It breaks
// apps, but only on one platform and due to a hack in officially
// platform independent code. It took me hours to fix this. RR.
//
// #ifdef __WXMSW__
// wxWindow* focusWin = wxFindFocusDescendant(parent);
// #else
wxWindow* focusWin = (wxWindow*) NULL;
// #endif
wxEvtHandler* evtHandler = focusWin ? focusWin->GetEventHandler() : GetEventHandler() ;
wxEvtHandler* evtHandler = GetEventHandler() ;
for ( wxToolBarToolsList::Node* node = m_tools.GetFirst();
node;