diff --git a/include/wx/msw/spinctrl.h b/include/wx/msw/spinctrl.h index f43103affe..243e7b6833 100644 --- a/include/wx/msw/spinctrl.h +++ b/include/wx/msw/spinctrl.h @@ -73,6 +73,7 @@ public: WXFARPROC GetBuddyWndProc() const { return m_oldBuddyWndProc; } protected: + virtual void DoGetPosition(int *x, int *y) const; virtual void DoMoveWindow(int x, int y, int width, int height); virtual wxSize DoGetBestSize() const; virtual void DoGetSize(int *width, int *height) const; diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index 09b50942ea..9f2928f82a 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -343,13 +343,24 @@ void wxSpinCtrl::DoGetSize(int *x, int *y) const GetWindowRect(GetHwnd(), &spinrect); GetWindowRect((HWND)m_hwndBuddy, &textrect); UnionRect(&ctrlrect,&textrect, &spinrect); - + if ( x ) *x = ctrlrect.right - ctrlrect.left; if ( y ) *y = ctrlrect.bottom - ctrlrect.top; } +void wxSpinCtrl::DoGetPosition(int *x, int *y) const +{ + // hack: pretend that our HWND is the text control just for a moment + WXHWND hWnd = GetHWND(); + wxConstCast(this, wxSpinCtrl)->m_hWnd = m_hwndBuddy; + + wxSpinButton::DoGetPosition(x, y); + + wxConstCast(this, wxSpinCtrl)->m_hWnd = hWnd; +} + #endif // __WIN95__ #endif diff --git a/src/msw/window.cpp b/src/msw/window.cpp index f89cf5d4da..3daa43cce4 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -3461,11 +3461,34 @@ bool wxWindow::MSWOnScroll(int orientation, WXWORD wParam, break; case SB_THUMBPOSITION: - event.m_eventType = wxEVT_SCROLLWIN_THUMBRELEASE; - break; - case SB_THUMBTRACK: - event.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK; +#ifdef __WIN32__ + // under Win32, the scrollbar range and position are 32 bit integers, + // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must + // explicitly query the scrollbar for the correct position (this must + // be done only for these two SB_ events as they are the only one + // carrying the scrollbar position) + { + SCROLLINFO scrollInfo; + wxZeroMemory(scrollInfo); + scrollInfo.cbSize = sizeof(SCROLLINFO); + scrollInfo.fMask = SIF_TRACKPOS; + + if ( !::GetScrollInfo(GetHwnd(), + orientation == wxHORIZONTAL ? SB_HORZ + : SB_VERT, + &scrollInfo) ) + { + wxLogLastError(_T("GetScrollInfo")); + } + + event.SetPosition(scrollInfo.nTrackPos); + } +#endif // Win32 + + event.m_eventType = wParam == SB_THUMBPOSITION + ? wxEVT_SCROLLWIN_THUMBRELEASE + : wxEVT_SCROLLWIN_THUMBTRACK; break; default: