Replace public wxEvtHandler::ProcessEventHere() with private TryHere().

ProcessEventHere() doesn't have to be public any more now that we have
ProcessEventLocally() which is safe to call from the outside (i.e. doesn't
forget about the chained event handlers and validators).

Still keep this function because it makes the code more modular and also
because we might want to make it virtual for consistency with TryBefore() and
TryAfter() later. Also rename it to TryHere() to make the symmetry with these
functions more manifest.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64264 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-05-09 14:55:46 +00:00
parent 44070fd379
commit 512220b67b
5 changed files with 43 additions and 44 deletions

View File

@@ -1026,8 +1026,8 @@ protected:
bool m_wasProcessed; bool m_wasProcessed;
// this flag is used by ProcessEventLocally() to prevent ProcessEvent() // this flag is used by ProcessEventLocally() to prevent ProcessEvent()
// from doing its usual stuff and force it to just call ProcessEventHere() // from doing its usual stuff and force it to just call TryHere() instead,
// instead, see the comment there explaining why is this needed // see the comment there explaining why is this needed
bool m_processHereOnly; bool m_processHereOnly;
protected: protected:
@@ -3232,13 +3232,6 @@ public:
void OnSinkDestroyed( wxEvtHandler *sink ); void OnSinkDestroyed( wxEvtHandler *sink );
// The method tries to process the event in this event handler.
//
// It is called from ProcessEventLocally() and normally shouldn't be called
// directly as doing it would ignore any chained event handlers.
bool ProcessEventHere(wxEvent& event);
private: private:
void DoBind(int winid, void DoBind(int winid,
int lastId, int lastId,
@@ -3263,6 +3256,12 @@ protected:
// validators. // validators.
virtual bool TryBefore(wxEvent& event); virtual bool TryBefore(wxEvent& event);
// this one is not a hook but just a helper which looks up the handler in
// this object itself called from ProcessEventLocally() and normally
// shouldn't be called directly as doing it would ignore any chained event
// handlers
bool TryHere(wxEvent& event);
// this one is called after failing to find the event handle in our own // this one is called after failing to find the event handle in our own
// table to give a chance to the other windows to process it // table to give a chance to the other windows to process it
// //

View File

@@ -512,9 +512,9 @@ public:
the chain until the event is processed or the chain is exhausted. the chain until the event is processed or the chain is exhausted.
This function is called from ProcessEvent() and, in turn, calls This function is called from ProcessEvent() and, in turn, calls
ProcessEventHere() for each handler in turn. It is not virtual and so TryThis() for each handler in turn. It is not virtual and so cannot be
cannot be overridden but can, and should, be called to forward an event overridden but can, and should, be called to forward an event to
to another handler instead of ProcessEvent() which would result in a another handler instead of ProcessEvent() which would result in a
duplicate call to TryAfter(), e.g. resulting in all unprocessed events duplicate call to TryAfter(), e.g. resulting in all unprocessed events
being sent to the application object multiple times. being sent to the application object multiple times.
@@ -528,25 +528,6 @@ public:
*/ */
bool ProcessEventLocally(wxEvent& event); bool ProcessEventLocally(wxEvent& event);
/**
Try to process the event in this event handler.
This method is called from ProcessEventLocally() and thus,
indirectly, from ProcessEvent(), please see the detailed description of
the event processing logic there.
It is @em not virtual and so may not be overridden.
@since 2.9.1
@param event
Event to process.
@return
@true if this object itself defines a handler for this event and
the handler didn't skip the event.
*/
bool ProcessEventHere(wxEvent& event);
/** /**
Processes an event by calling ProcessEvent() and handles any exceptions Processes an event by calling ProcessEvent() and handles any exceptions
that occur in the process. that occur in the process.
@@ -1111,10 +1092,29 @@ protected:
}; };
@endcode @endcode
@see ProcessEvent(), ProcessEventHere() @see ProcessEvent()
*/ */
virtual bool TryBefore(wxEvent& event); virtual bool TryBefore(wxEvent& event);
/**
Try to process the event in this event handler.
This method is called from ProcessEventLocally() and thus, indirectly,
from ProcessEvent(), please see the detailed description of the event
processing logic there.
It is currently @em not virtual and so may not be overridden.
@since 2.9.1
@param event
Event to process.
@return
@true if this object itself defines a handler for this event and
the handler didn't skip the event.
*/
bool TryThis(wxEvent& event);
/** /**
Method called by ProcessEvent() as last resort. Method called by ProcessEvent() as last resort.
@@ -1140,7 +1140,7 @@ protected:
}; };
@endcode @endcode
@see ProcessEvent(), ProcessEventHere() @see ProcessEvent()
*/ */
virtual bool TryAfter(wxEvent& event); virtual bool TryAfter(wxEvent& event);
}; };

View File

@@ -1846,8 +1846,8 @@ public:
This method is similar to ProcessWindowEvent() but can be used to This method is similar to ProcessWindowEvent() but can be used to
search for the event handler only in this window and any event handlers search for the event handler only in this window and any event handlers
pushed on top of it. Unlike ProcessWindowEvent() it won't propagate the pushed on top of it. Unlike ProcessWindowEvent() it won't propagate the
event upwards. But unlike wxEvtHandler::ProcessEventHere() it will use event upwards. But it will use the validator and event handlers
the event handlers associated with this window. associated with this window, if any.
@since 2.9.1 @since 2.9.1
*/ */

View File

@@ -1379,7 +1379,7 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event)
// Short circuit the event processing logic if we're requested to process // Short circuit the event processing logic if we're requested to process
// this event in this handler only, see DoTryChain() for more details. // this event in this handler only, see DoTryChain() for more details.
if ( event.ShouldProcessHereOnly() ) if ( event.ShouldProcessHereOnly() )
return ProcessEventHere(event); return TryHere(event);
// Try to process the event in this handler itself. // Try to process the event in this handler itself.
@@ -1405,7 +1405,7 @@ bool wxEvtHandler::ProcessEventLocally(wxEvent& event)
// Then try this handler itself, notice that we should not call // Then try this handler itself, notice that we should not call
// ProcessEvent() on this one as we're already called from it, which // ProcessEvent() on this one as we're already called from it, which
// explains why we do it here and not in DoTryChain() // explains why we do it here and not in DoTryChain()
if ( ProcessEventHere(event) ) if ( TryHere(event) )
return true; return true;
// Finally try the event handlers chained to this one, // Finally try the event handlers chained to this one,
@@ -1426,16 +1426,16 @@ bool wxEvtHandler::DoTryChain(wxEvent& event)
// ProcessEvent() from which we were called or will be done by it when // ProcessEvent() from which we were called or will be done by it when
// we return. // we return.
// //
// However we must call ProcessEvent() and not ProcessEventHere() // However we must call ProcessEvent() and not TryHere() because the
// because the existing code (including some in wxWidgets itself) // existing code (including some in wxWidgets itself) expects the
// expects the overridden ProcessEvent() in its custom event handlers // overridden ProcessEvent() in its custom event handlers pushed on a
// pushed on a window to be called. // window to be called.
// //
// So we must call ProcessEvent() but it must not do what it usually // So we must call ProcessEvent() but it must not do what it usually
// does. To resolve this paradox we pass a special "process here only" // does. To resolve this paradox we pass a special "process here only"
// flag to ProcessEvent() via the event object itself. This ensures // flag to ProcessEvent() via the event object itself. This ensures
// that if our own, base class, version is called, it will just call // that if our own, base class, version is called, it will just call
// ProcessEventHere() and won't do anything else, just as we want it to. // TryHere() and won't do anything else, just as we want it to.
wxEventProcessHereOnly processHereOnly(event); wxEventProcessHereOnly processHereOnly(event);
if ( h->ProcessEvent(event) ) if ( h->ProcessEvent(event) )
return true; return true;
@@ -1444,7 +1444,7 @@ bool wxEvtHandler::DoTryChain(wxEvent& event)
return false; return false;
} }
bool wxEvtHandler::ProcessEventHere(wxEvent& event) bool wxEvtHandler::TryHere(wxEvent& event)
{ {
// If the event handler is disabled it doesn't process any events // If the event handler is disabled it doesn't process any events
if ( !GetEvtHandlerEnabled() ) if ( !GetEvtHandlerEnabled() )

View File

@@ -2983,7 +2983,7 @@ bool wxWindowBase::TryBefore(wxEvent& event)
if ( event.GetEventObject() == this ) if ( event.GetEventObject() == this )
{ {
wxValidator * const validator = GetValidator(); wxValidator * const validator = GetValidator();
if ( validator && validator->ProcessEventHere(event) ) if ( validator && validator->ProcessEventLocally(event) )
{ {
return true; return true;
} }