Refactor wxWindow::MSWHandleMessage() out from MSWWindowProc().

This commit just refactors the code without changing anything in its
behaviour and will be followed by the real changes in the next one.

The new function just handles the message, without calling MSWDefWindowProc()
if it wasn't handled. This allows to call it and determine whether the message
was really handled and only continue processing it if it wasn't.

Notice that while in theory this shouldn't be necessary because the return
value of MSWWindowProc() should indicate whether the message was handled or
not (0 meaning that it was, for most messages), in practice it doesn't work
because many standard controls window procs return 0 even for message they do
nothing with, e.g. "up down" control always returns 0 for WM_CHAR messages
even it it only really handles the arrow keys.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68327 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-07-22 12:49:22 +00:00
parent 41936464fd
commit 2e1cee233e
2 changed files with 33 additions and 4 deletions

View File

@@ -366,7 +366,21 @@ public:
bool HandlePower(WXWPARAM wParam, WXLPARAM lParam, bool *vetoed); bool HandlePower(WXWPARAM wParam, WXLPARAM lParam, bool *vetoed);
// Window procedure // The main body of common window proc for all wxWindow objects. It tries
// to handle the given message and returns true if it was handled (the
// appropriate return value is then put in result, which must be non-NULL)
// or false if it wasn't.
//
// This function should be overridden in any new code instead of
// MSWWindowProc() even if currently most of the code overrides
// MSWWindowProc() as it had been written before this function was added.
virtual bool MSWHandleMessage(WXLRESULT *result,
WXUINT message,
WXWPARAM wParam,
WXLPARAM lParam);
// Common Window procedure for all wxWindow objects: forwards to
// MSWHandleMessage() and MSWDefWindowProc() if the message wasn't handled.
virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
// Calls an appropriate default window procedure // Calls an appropriate default window procedure

View File

@@ -2728,7 +2728,11 @@ LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM w
return rc; return rc;
} }
WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) bool
wxWindowMSW::MSWHandleMessage(WXLRESULT *result,
WXUINT message,
WXWPARAM wParam,
WXLPARAM lParam)
{ {
// did we process the message? // did we process the message?
bool processed = false; bool processed = false;
@@ -3608,15 +3612,26 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
} }
if ( !processed ) if ( !processed )
return false;
*result = rc.result;
return true;
}
WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
{
WXLRESULT result;
if ( !MSWHandleMessage(&result, message, wParam, lParam) )
{ {
#if wxDEBUG_LEVEL >= 2 #if wxDEBUG_LEVEL >= 2
wxLogTrace("winmsg", wxT("Forwarding %s to DefWindowProc."), wxLogTrace("winmsg", wxT("Forwarding %s to DefWindowProc."),
wxGetMessageName(message)); wxGetMessageName(message));
#endif // wxDEBUG_LEVEL >= 2 #endif // wxDEBUG_LEVEL >= 2
rc.result = MSWDefWindowProc(message, wParam, lParam); result = MSWDefWindowProc(message, wParam, lParam);
} }
return rc.result; return result;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------