From 2e1cee233eb64ddf4855970b93f276c5709e2eec Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 22 Jul 2011 12:49:22 +0000 Subject: [PATCH] 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 --- include/wx/msw/window.h | 16 +++++++++++++++- src/msw/window.cpp | 21 ++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index 5b41235d9f..95a9d72206 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -366,7 +366,21 @@ public: 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); // Calls an appropriate default window procedure diff --git a/src/msw/window.cpp b/src/msw/window.cpp index eee4ca18ad..7535e4efeb 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -2728,7 +2728,11 @@ LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM w 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? bool processed = false; @@ -3608,15 +3612,26 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l } 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 wxLogTrace("winmsg", wxT("Forwarding %s to DefWindowProc."), wxGetMessageName(message)); #endif // wxDEBUG_LEVEL >= 2 - rc.result = MSWDefWindowProc(message, wParam, lParam); + result = MSWDefWindowProc(message, wParam, lParam); } - return rc.result; + return result; } // ---------------------------------------------------------------------------- -- 2.45.2