X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cff58b52994be223d4e6b183084435b761d6ee81..4a10ea8b13fd0851e71e6fa5ebbe5b93933be11e:/src/msw/window.cpp diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 800b06910d..66fcdf4355 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -17,10 +17,6 @@ // headers // --------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "window.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -127,6 +123,14 @@ // by setting this to 0 (in the future this should be removed completely) #define USE_DEFERRED_SIZING 1 +// set this to 1 to filter out duplicate mouse events, e.g. mouse move events +// when mouse position didnd't change +#ifdef __WXWINCE__ + #define wxUSE_MOUSEEVENT_HACK 0 +#else + #define wxUSE_MOUSEEVENT_HACK 1 +#endif + // --------------------------------------------------------------------------- // global variables // --------------------------------------------------------------------------- @@ -145,6 +149,18 @@ extern const wxChar *wxCanvasClassName; // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT) static bool gs_hasStdCmap = false; +// last mouse event information we need to filter out the duplicates +#if wxUSE_MOUSEEVENT_HACK +static struct MouseEventInfoDummy +{ + // mouse position (in screen coordinates) + wxPoint pos; + + // last mouse event type + wxEventType type; +} gs_lastMouseEvent; +#endif // wxUSE_MOUSEEVENT_HACK + // --------------------------------------------------------------------------- // private functions // --------------------------------------------------------------------------- @@ -466,12 +482,6 @@ void wxWindowMSW::Init() m_xThumbSize = 0; m_yThumbSize = 0; -#if wxUSE_MOUSEEVENT_HACK - m_lastMouseX = - m_lastMouseY = -1; - m_lastMouseEvent = -1; -#endif // wxUSE_MOUSEEVENT_HACK - m_pendingPosition = wxDefaultPosition; m_pendingSize = wxDefaultSize; } @@ -694,12 +704,23 @@ bool wxWindowMSW::Show(bool show) return false; HWND hWnd = GetHwnd(); - int cshow = show ? SW_SHOW : SW_HIDE; - ::ShowWindow(hWnd, cshow); - if ( show && IsTopLevel() ) + // we could be called before the underlying window is created (this is + // actually useful to prevent it from being initially shown), e.g. + // + // wxFoo *foo = new wxFoo; + // foo->Hide(); + // foo->Create(parent, ...); + // + // should work without errors + if ( hWnd ) { - wxBringWindowToTop(hWnd); + ::ShowWindow(hWnd, show ? SW_SHOW : SW_HIDE); + + if ( show && IsTopLevel() ) + { + wxBringWindowToTop(hWnd); + } } return true; @@ -810,7 +831,7 @@ void wxWindowMSW::WarpPointer(int x, int y) } } -void wxWindowMSW::MSWUpdateUIState() +void wxWindowMSW::MSWUpdateUIState(int action) { // WM_UPDATEUISTATE only appeared in Windows 2000 so it can do us no good // to use it on older systems -- and could possibly do some harm @@ -828,8 +849,7 @@ void wxWindowMSW::MSWUpdateUIState() // include just one UISF_XXX or both, both are affected, no idea // why ::SendMessage(GetHwnd(), WM_UPDATEUISTATE, - MAKEWPARAM(UIS_INITIALIZE, - UISF_HIDEFOCUS | UISF_HIDEACCEL), 0); + MAKEWPARAM(action, UISF_HIDEFOCUS | UISF_HIDEACCEL), 0); } } @@ -2088,7 +2108,7 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg) // this by default, we need to manually send this message // so that controls could change their appearance // appropriately - MSWUpdateUIState(); + MSWUpdateUIState(UIS_CLEAR); return true; } @@ -4498,9 +4518,8 @@ void wxWindowMSW::InitMouseEvent(wxMouseEvent& event, event.SetId(GetId()); #if wxUSE_MOUSEEVENT_HACK - m_lastMouseX = x; - m_lastMouseY = y; - m_lastMouseEvent = event.GetEventType(); + gs_lastMouseEvent.pos = ClientToScreen(wxPoint(x, y)); + gs_lastMouseEvent.type = event.GetEventType(); #endif // wxUSE_MOUSEEVENT_HACK } @@ -4640,17 +4659,22 @@ bool wxWindowMSW::HandleMouseMove(int x, int y, WXUINT flags) #endif // HAVE_TRACKMOUSEEVENT #if wxUSE_MOUSEEVENT_HACK - // Window gets a click down message followed by a mouse move message even - // if position isn't changed! We want to discard the trailing move event - // if x and y are the same. - if ( (m_lastMouseEvent == wxEVT_RIGHT_DOWN || - m_lastMouseEvent == wxEVT_LEFT_DOWN || - m_lastMouseEvent == wxEVT_MIDDLE_DOWN) && - (m_lastMouseX == x && m_lastMouseY == y) ) - { - m_lastMouseEvent = wxEVT_MOTION; + // Windows often generates mouse events even if mouse position hasn't + // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576) + // + // Filter this out as it can result in unexpected behaviour compared to + // other platforms + if ( gs_lastMouseEvent.type == wxEVT_RIGHT_DOWN || + gs_lastMouseEvent.type == wxEVT_LEFT_DOWN || + gs_lastMouseEvent.type == wxEVT_MIDDLE_DOWN || + gs_lastMouseEvent.type == wxEVT_MOTION ) + { + if ( ClientToScreen(wxPoint(x, y)) == gs_lastMouseEvent.pos ) + { + gs_lastMouseEvent.type = wxEVT_MOTION; - return false; + return false; + } } #endif // wxUSE_MOUSEEVENT_HACK