From 13370c22d314f6e8b7d87e692e392f3606388703 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 25 Mar 2014 08:23:31 -0400 Subject: [PATCH] Added the actual scrolling to Windows Areas. Now to just adjust the cliprect properly... --- area_windows.go | 25 ++++++++++++++++++++++++- controls_windows.go | 9 +++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/area_windows.go b/area_windows.go index 33692fb..4b4eedc 100644 --- a/area_windows.go +++ b/area_windows.go @@ -208,7 +208,30 @@ func scrollArea(hwnd _HWND, wparam _WPARAM, which uintptr) { return } - // TODO scroll + delta := -(newpos - si.nPos) // negative because ScrollWindowEx() scrolls in the opposite direction + dx := delta + dy := int32(0) + if which == uintptr(_SB_VERT) { + dx = int32(0) + dy = delta + } + r1, _, err = _scrollWindowEx.Call( + uintptr(hwnd), + uintptr(dx), + uintptr(dy), + uintptr(0), // these four change what is scrolled and record info about the scroll; we're scrolling the whole client area and don't care about the returned information here + uintptr(0), + uintptr(0), + uintptr(0), + // TODO also SW_ERASE? or will the GetUpdateRect() call handle it? + uintptr(_SW_INVALIDATE)) // mark the remaining rect as needing redraw... + if r1 == _ERROR { // failure + panic(fmt.Errorf("error scrolling Area: %v", err)) + } + r1, _, err = _updateWindow.Call(uintptr(hwnd)) // ...and redraw it + if r1 == 0 { // failure + panic(fmt.Errorf("error updating Area after scrolling: %v", err)) + } // we actually have to commit the change back to the scrollbar; otherwise the scroll position will merely reset itself si.cbSize = uint32(unsafe.Sizeof(si)) diff --git a/controls_windows.go b/controls_windows.go index 24adcfa..ab227ee 100644 --- a/controls_windows.go +++ b/controls_windows.go @@ -490,6 +490,15 @@ const ( _SIF_ALL = (_SIF_RANGE | _SIF_PAGE | _SIF_POS | _SIF_TRACKPOS) ) +// ScrollWindowEx return values. +const ( + // from wingdi.h + _ERROR = 0 + _NULLREGION = 1 + _SIMPLEREGION = 2 + _COMPLEXREGION = 3 +) + var ( _getScrollInfo = user32.NewProc("GetScrollInfo") _getScrollPos = user32.NewProc("GetScrollPos")