More go fmt.
This commit is contained in:
parent
1e66637cd2
commit
380afbf755
352
area_windows.go
352
area_windows.go
|
@ -4,13 +4,13 @@ package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"image"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
"image"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
areastyle = _WS_HSCROLL | _WS_VSCROLL | controlstyle
|
areastyle = _WS_HSCROLL | _WS_VSCROLL | controlstyle
|
||||||
areaxstyle = 0 | controlxstyle
|
areaxstyle = 0 | controlxstyle
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -27,17 +27,17 @@ func getScrollPos(hwnd _HWND) (xpos int32, ypos int32) {
|
||||||
uintptr(hwnd),
|
uintptr(hwnd),
|
||||||
uintptr(_SB_HORZ),
|
uintptr(_SB_HORZ),
|
||||||
uintptr(unsafe.Pointer(&si)))
|
uintptr(unsafe.Pointer(&si)))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error getting horizontal scroll position for Area: %v", err))
|
panic(fmt.Errorf("error getting horizontal scroll position for Area: %v", err))
|
||||||
}
|
}
|
||||||
xpos = si.nPos
|
xpos = si.nPos
|
||||||
si.cbSize = uint32(unsafe.Sizeof(si)) // MSDN example code reinitializes this each time, so we'll do it too just to be safe
|
si.cbSize = uint32(unsafe.Sizeof(si)) // MSDN example code reinitializes this each time, so we'll do it too just to be safe
|
||||||
si.fMask = _SIF_POS | _SIF_TRACKPOS
|
si.fMask = _SIF_POS | _SIF_TRACKPOS
|
||||||
r1, _, err = _getScrollInfo.Call(
|
r1, _, err = _getScrollInfo.Call(
|
||||||
uintptr(hwnd),
|
uintptr(hwnd),
|
||||||
uintptr(_SB_VERT),
|
uintptr(_SB_VERT),
|
||||||
uintptr(unsafe.Pointer(&si)))
|
uintptr(unsafe.Pointer(&si)))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error getting vertical scroll position for Area: %v", err))
|
panic(fmt.Errorf("error getting vertical scroll position for Area: %v", err))
|
||||||
}
|
}
|
||||||
ypos = si.nPos
|
ypos = si.nPos
|
||||||
|
@ -45,17 +45,17 @@ func getScrollPos(hwnd _HWND) (xpos int32, ypos int32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_alphaBlend = msimg32.NewProc("AlphaBlend")
|
_alphaBlend = msimg32.NewProc("AlphaBlend")
|
||||||
_beginPaint = user32.NewProc("BeginPaint")
|
_beginPaint = user32.NewProc("BeginPaint")
|
||||||
_bitBlt = gdi32.NewProc("BitBlt")
|
_bitBlt = gdi32.NewProc("BitBlt")
|
||||||
_createCompatibleBitmap = gdi32.NewProc("CreateCompatibleBitmap")
|
_createCompatibleBitmap = gdi32.NewProc("CreateCompatibleBitmap")
|
||||||
_createCompatibleDC = gdi32.NewProc("CreateCompatibleDC")
|
_createCompatibleDC = gdi32.NewProc("CreateCompatibleDC")
|
||||||
_createDIBSection = gdi32.NewProc("CreateDIBSection")
|
_createDIBSection = gdi32.NewProc("CreateDIBSection")
|
||||||
_deleteDC = gdi32.NewProc("DeleteDC")
|
_deleteDC = gdi32.NewProc("DeleteDC")
|
||||||
_deleteObject = gdi32.NewProc("DeleteObject")
|
_deleteObject = gdi32.NewProc("DeleteObject")
|
||||||
_endPaint = user32.NewProc("EndPaint")
|
_endPaint = user32.NewProc("EndPaint")
|
||||||
_fillRect = user32.NewProc("FillRect")
|
_fillRect = user32.NewProc("FillRect")
|
||||||
_getUpdateRect = user32.NewProc("GetUpdateRect")
|
_getUpdateRect = user32.NewProc("GetUpdateRect")
|
||||||
// _selectObject in prefsize_windows.go
|
// _selectObject in prefsize_windows.go
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -70,8 +70,8 @@ func paintArea(s *sysData) {
|
||||||
r1, _, _ := _getUpdateRect.Call(
|
r1, _, _ := _getUpdateRect.Call(
|
||||||
uintptr(s.hwnd),
|
uintptr(s.hwnd),
|
||||||
uintptr(unsafe.Pointer(&xrect)),
|
uintptr(unsafe.Pointer(&xrect)),
|
||||||
uintptr(_TRUE)) // erase the update rect with the background color
|
uintptr(_TRUE)) // erase the update rect with the background color
|
||||||
if r1 == 0 { // no update rect; do nothing
|
if r1 == 0 { // no update rect; do nothing
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,10 +79,10 @@ func paintArea(s *sysData) {
|
||||||
|
|
||||||
// both Windows RECT and Go image.Rect are point..point, so the following is correct
|
// both Windows RECT and Go image.Rect are point..point, so the following is correct
|
||||||
cliprect := image.Rect(int(xrect.left), int(xrect.top), int(xrect.right), int(xrect.bottom))
|
cliprect := image.Rect(int(xrect.left), int(xrect.top), int(xrect.right), int(xrect.bottom))
|
||||||
cliprect = cliprect.Add(image.Pt(int(hscroll), int(vscroll))) // adjust by scroll position
|
cliprect = cliprect.Add(image.Pt(int(hscroll), int(vscroll))) // adjust by scroll position
|
||||||
// make sure the cliprect doesn't fall outside the size of the Area
|
// make sure the cliprect doesn't fall outside the size of the Area
|
||||||
cliprect = cliprect.Intersect(image.Rect(0, 0, s.areawidth, s.areaheight))
|
cliprect = cliprect.Intersect(image.Rect(0, 0, s.areawidth, s.areaheight))
|
||||||
if cliprect.Empty() { // still no update rect
|
if cliprect.Empty() { // still no update rect
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ func paintArea(s *sysData) {
|
||||||
r1, _, err := _beginPaint.Call(
|
r1, _, err := _beginPaint.Call(
|
||||||
uintptr(s.hwnd),
|
uintptr(s.hwnd),
|
||||||
uintptr(unsafe.Pointer(&ps)))
|
uintptr(unsafe.Pointer(&ps)))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error beginning Area repaint: %v", err))
|
panic(fmt.Errorf("error beginning Area repaint: %v", err))
|
||||||
}
|
}
|
||||||
hdc := _HANDLE(r1)
|
hdc := _HANDLE(r1)
|
||||||
|
@ -101,7 +101,7 @@ func paintArea(s *sysData) {
|
||||||
// first let's create the destination image, which we fill with the windows background color
|
// first let's create the destination image, which we fill with the windows background color
|
||||||
// this is how we fake drawing the background; see also http://msdn.microsoft.com/en-us/library/ms969905.aspx
|
// this is how we fake drawing the background; see also http://msdn.microsoft.com/en-us/library/ms969905.aspx
|
||||||
r1, _, err = _createCompatibleDC.Call(uintptr(hdc))
|
r1, _, err = _createCompatibleDC.Call(uintptr(hdc))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error creating off-screen rendering DC: %v", err))
|
panic(fmt.Errorf("error creating off-screen rendering DC: %v", err))
|
||||||
}
|
}
|
||||||
rdc := _HANDLE(r1)
|
rdc := _HANDLE(r1)
|
||||||
|
@ -110,30 +110,30 @@ func paintArea(s *sysData) {
|
||||||
// thanks to David Heffernan in http://stackoverflow.com/questions/23033636/winapi-gdi-fillrectcolor-btnface-fills-with-strange-grid-like-brush-on-window
|
// thanks to David Heffernan in http://stackoverflow.com/questions/23033636/winapi-gdi-fillrectcolor-btnface-fills-with-strange-grid-like-brush-on-window
|
||||||
r1, _, err = _createCompatibleBitmap.Call(
|
r1, _, err = _createCompatibleBitmap.Call(
|
||||||
uintptr(hdc),
|
uintptr(hdc),
|
||||||
uintptr(xrect.right - xrect.left),
|
uintptr(xrect.right-xrect.left),
|
||||||
uintptr(xrect.bottom - xrect.top))
|
uintptr(xrect.bottom-xrect.top))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error creating off-screen rendering bitmap: %v", err))
|
panic(fmt.Errorf("error creating off-screen rendering bitmap: %v", err))
|
||||||
}
|
}
|
||||||
rbitmap := _HANDLE(r1)
|
rbitmap := _HANDLE(r1)
|
||||||
r1, _, err = _selectObject.Call(
|
r1, _, err = _selectObject.Call(
|
||||||
uintptr(rdc),
|
uintptr(rdc),
|
||||||
uintptr(rbitmap))
|
uintptr(rbitmap))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error connecting off-screen rendering bitmap to off-screen rendering DC: %v", err))
|
panic(fmt.Errorf("error connecting off-screen rendering bitmap to off-screen rendering DC: %v", err))
|
||||||
}
|
}
|
||||||
prevrbitmap := _HANDLE(r1)
|
prevrbitmap := _HANDLE(r1)
|
||||||
rrect := _RECT{
|
rrect := _RECT{
|
||||||
left: 0,
|
left: 0,
|
||||||
right: xrect.right - xrect.left,
|
right: xrect.right - xrect.left,
|
||||||
top: 0,
|
top: 0,
|
||||||
bottom: xrect.bottom - xrect.top,
|
bottom: xrect.bottom - xrect.top,
|
||||||
}
|
}
|
||||||
r1, _, err = _fillRect.Call(
|
r1, _, err = _fillRect.Call(
|
||||||
uintptr(rdc),
|
uintptr(rdc),
|
||||||
uintptr(unsafe.Pointer(&rrect)),
|
uintptr(unsafe.Pointer(&rrect)),
|
||||||
uintptr(areaBackgroundBrush))
|
uintptr(areaBackgroundBrush))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error filling off-screen rendering bitmap with the system background color: %v", err))
|
panic(fmt.Errorf("error filling off-screen rendering bitmap with the system background color: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,21 +146,21 @@ func paintArea(s *sysData) {
|
||||||
bi := _BITMAPINFO{}
|
bi := _BITMAPINFO{}
|
||||||
bi.bmiHeader.biSize = uint32(unsafe.Sizeof(bi.bmiHeader))
|
bi.bmiHeader.biSize = uint32(unsafe.Sizeof(bi.bmiHeader))
|
||||||
bi.bmiHeader.biWidth = int32(i.Rect.Dx())
|
bi.bmiHeader.biWidth = int32(i.Rect.Dx())
|
||||||
bi.bmiHeader.biHeight = -int32(i.Rect.Dy()) // negative height to force top-down drawing
|
bi.bmiHeader.biHeight = -int32(i.Rect.Dy()) // negative height to force top-down drawing
|
||||||
bi.bmiHeader.biPlanes = 1
|
bi.bmiHeader.biPlanes = 1
|
||||||
bi.bmiHeader.biBitCount = 32
|
bi.bmiHeader.biBitCount = 32
|
||||||
bi.bmiHeader.biCompression = _BI_RGB
|
bi.bmiHeader.biCompression = _BI_RGB
|
||||||
bi.bmiHeader.biSizeImage = uint32(i.Rect.Dx() * i.Rect.Dy() * 4)
|
bi.bmiHeader.biSizeImage = uint32(i.Rect.Dx() * i.Rect.Dy() * 4)
|
||||||
// this is all we need, but because this confused me at first, I will say the two pixels-per-meter fields are unused (see http://blogs.msdn.com/b/oldnewthing/archive/2013/05/15/10418646.aspx and page 581 of Charles Petzold's Programming Windows, Fifth Edition)
|
// this is all we need, but because this confused me at first, I will say the two pixels-per-meter fields are unused (see http://blogs.msdn.com/b/oldnewthing/archive/2013/05/15/10418646.aspx and page 581 of Charles Petzold's Programming Windows, Fifth Edition)
|
||||||
ppvBits := uintptr(0) // now for the trouble: CreateDIBSection() allocates the memory for us...
|
ppvBits := uintptr(0) // now for the trouble: CreateDIBSection() allocates the memory for us...
|
||||||
r1, _, err = _createDIBSection.Call(
|
r1, _, err = _createDIBSection.Call(
|
||||||
uintptr(_NULL), // Ninjifox does this, so do some wine tests (http://source.winehq.org/source/dlls/gdi32/tests/bitmap.c#L725, thanks vpovirk in irc.freenode.net/#winehackers) and even Raymond Chen (http://blogs.msdn.com/b/oldnewthing/archive/2006/11/16/1086835.aspx), so.
|
uintptr(_NULL), // Ninjifox does this, so do some wine tests (http://source.winehq.org/source/dlls/gdi32/tests/bitmap.c#L725, thanks vpovirk in irc.freenode.net/#winehackers) and even Raymond Chen (http://blogs.msdn.com/b/oldnewthing/archive/2006/11/16/1086835.aspx), so.
|
||||||
uintptr(unsafe.Pointer(&bi)),
|
uintptr(unsafe.Pointer(&bi)),
|
||||||
uintptr(_DIB_RGB_COLORS),
|
uintptr(_DIB_RGB_COLORS),
|
||||||
uintptr(unsafe.Pointer(&ppvBits)),
|
uintptr(unsafe.Pointer(&ppvBits)),
|
||||||
uintptr(0), // we're not dealing with hSection or dwOffset
|
uintptr(0), // we're not dealing with hSection or dwOffset
|
||||||
uintptr(0))
|
uintptr(0))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error creating HBITMAP for image returned by AreaHandler.Paint(): %v", err))
|
panic(fmt.Errorf("error creating HBITMAP for image returned by AreaHandler.Paint(): %v", err))
|
||||||
}
|
}
|
||||||
ibitmap := _HANDLE(r1)
|
ibitmap := _HANDLE(r1)
|
||||||
|
@ -170,43 +170,43 @@ func paintArea(s *sysData) {
|
||||||
// the pixels are arranged in RGBA order, but GDI requires BGRA
|
// the pixels are arranged in RGBA order, but GDI requires BGRA
|
||||||
// this turns out to be just ARGB in little endian; let's convert into this memory
|
// this turns out to be just ARGB in little endian; let's convert into this memory
|
||||||
// the bitmap Windows gives us has a stride == width
|
// the bitmap Windows gives us has a stride == width
|
||||||
toARGB(i, ppvBits, i.Rect.Dx() * 4)
|
toARGB(i, ppvBits, i.Rect.Dx()*4)
|
||||||
|
|
||||||
// the second thing is... make a device context for the bitmap :|
|
// the second thing is... make a device context for the bitmap :|
|
||||||
// Ninjifox just makes another compatible DC; we'll do the same
|
// Ninjifox just makes another compatible DC; we'll do the same
|
||||||
r1, _, err = _createCompatibleDC.Call(uintptr(hdc))
|
r1, _, err = _createCompatibleDC.Call(uintptr(hdc))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error creating HDC for image returned by AreaHandler.Paint(): %v", err))
|
panic(fmt.Errorf("error creating HDC for image returned by AreaHandler.Paint(): %v", err))
|
||||||
}
|
}
|
||||||
idc := _HANDLE(r1)
|
idc := _HANDLE(r1)
|
||||||
r1, _, err = _selectObject.Call(
|
r1, _, err = _selectObject.Call(
|
||||||
uintptr(idc),
|
uintptr(idc),
|
||||||
uintptr(ibitmap))
|
uintptr(ibitmap))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error connecting HBITMAP for image returned by AreaHandler.Paint() to its HDC: %v", err))
|
panic(fmt.Errorf("error connecting HBITMAP for image returned by AreaHandler.Paint() to its HDC: %v", err))
|
||||||
}
|
}
|
||||||
previbitmap := _HANDLE(r1)
|
previbitmap := _HANDLE(r1)
|
||||||
|
|
||||||
// AND FINALLY WE CAN DO THE ALPHA BLENDING!!!!!!111
|
// AND FINALLY WE CAN DO THE ALPHA BLENDING!!!!!!111
|
||||||
blendfunc := _BLENDFUNCTION{
|
blendfunc := _BLENDFUNCTION{
|
||||||
BlendOp: _AC_SRC_OVER,
|
BlendOp: _AC_SRC_OVER,
|
||||||
BlendFlags: 0,
|
BlendFlags: 0,
|
||||||
SourceConstantAlpha: 255, // only use per-pixel alphas
|
SourceConstantAlpha: 255, // only use per-pixel alphas
|
||||||
AlphaFormat: _AC_SRC_ALPHA, // premultiplied
|
AlphaFormat: _AC_SRC_ALPHA, // premultiplied
|
||||||
}
|
}
|
||||||
r1, _, err = _alphaBlend.Call(
|
r1, _, err = _alphaBlend.Call(
|
||||||
uintptr(rdc), // destination
|
uintptr(rdc), // destination
|
||||||
uintptr(0), // origin and size
|
uintptr(0), // origin and size
|
||||||
uintptr(0),
|
uintptr(0),
|
||||||
uintptr(i.Rect.Dx()),
|
uintptr(i.Rect.Dx()),
|
||||||
uintptr(i.Rect.Dy()),
|
uintptr(i.Rect.Dy()),
|
||||||
uintptr(idc), // source image
|
uintptr(idc), // source image
|
||||||
uintptr(0),
|
uintptr(0),
|
||||||
uintptr(0),
|
uintptr(0),
|
||||||
uintptr(i.Rect.Dx()),
|
uintptr(i.Rect.Dx()),
|
||||||
uintptr(i.Rect.Dy()),
|
uintptr(i.Rect.Dy()),
|
||||||
blendfunc.arg())
|
blendfunc.arg())
|
||||||
if r1 == _FALSE { // failure
|
if r1 == _FALSE { // failure
|
||||||
panic(fmt.Errorf("error alpha-blending image returned by AreaHandler.Paint() onto background: %v", err))
|
panic(fmt.Errorf("error alpha-blending image returned by AreaHandler.Paint() onto background: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,13 +215,13 @@ func paintArea(s *sysData) {
|
||||||
uintptr(hdc),
|
uintptr(hdc),
|
||||||
uintptr(xrect.left),
|
uintptr(xrect.left),
|
||||||
uintptr(xrect.top),
|
uintptr(xrect.top),
|
||||||
uintptr(xrect.right - xrect.left),
|
uintptr(xrect.right-xrect.left),
|
||||||
uintptr(xrect.bottom - xrect.top),
|
uintptr(xrect.bottom-xrect.top),
|
||||||
uintptr(rdc),
|
uintptr(rdc),
|
||||||
uintptr(0), // from the rdc's origin
|
uintptr(0), // from the rdc's origin
|
||||||
uintptr(0),
|
uintptr(0),
|
||||||
uintptr(_SRCCOPY))
|
uintptr(_SRCCOPY))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error blitting Area image to Area: %v", err))
|
panic(fmt.Errorf("error blitting Area image to Area: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,29 +229,29 @@ func paintArea(s *sysData) {
|
||||||
r1, _, err = _selectObject.Call(
|
r1, _, err = _selectObject.Call(
|
||||||
uintptr(idc),
|
uintptr(idc),
|
||||||
uintptr(previbitmap))
|
uintptr(previbitmap))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error reverting HDC for image returned by AreaHandler.Paint() to original HBITMAP: %v", err))
|
panic(fmt.Errorf("error reverting HDC for image returned by AreaHandler.Paint() to original HBITMAP: %v", err))
|
||||||
}
|
}
|
||||||
r1, _, err = _selectObject.Call(
|
r1, _, err = _selectObject.Call(
|
||||||
uintptr(rdc),
|
uintptr(rdc),
|
||||||
uintptr(prevrbitmap))
|
uintptr(prevrbitmap))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error reverting HDC for off-screen rendering to original HBITMAP: %v", err))
|
panic(fmt.Errorf("error reverting HDC for off-screen rendering to original HBITMAP: %v", err))
|
||||||
}
|
}
|
||||||
r1, _, err = _deleteObject.Call(uintptr(ibitmap))
|
r1, _, err = _deleteObject.Call(uintptr(ibitmap))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error deleting HBITMAP for image returned by AreaHandler.Paint(): %v", err))
|
panic(fmt.Errorf("error deleting HBITMAP for image returned by AreaHandler.Paint(): %v", err))
|
||||||
}
|
}
|
||||||
r1, _, err = _deleteObject.Call(uintptr(rbitmap))
|
r1, _, err = _deleteObject.Call(uintptr(rbitmap))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error deleting HBITMAP for off-screen rendering: %v", err))
|
panic(fmt.Errorf("error deleting HBITMAP for off-screen rendering: %v", err))
|
||||||
}
|
}
|
||||||
r1, _, err = _deleteDC.Call(uintptr(idc))
|
r1, _, err = _deleteDC.Call(uintptr(idc))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error deleting HDC for image returned by AreaHandler.Paint(): %v", err))
|
panic(fmt.Errorf("error deleting HDC for image returned by AreaHandler.Paint(): %v", err))
|
||||||
}
|
}
|
||||||
r1, _, err = _deleteDC.Call(uintptr(rdc))
|
r1, _, err = _deleteDC.Call(uintptr(rdc))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error deleting HDC for off-screen rendering: %v", err))
|
panic(fmt.Errorf("error deleting HDC for off-screen rendering: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ func getAreaControlSize(hwnd _HWND) (width int, height int) {
|
||||||
r1, _, err := _getClientRect.Call(
|
r1, _, err := _getClientRect.Call(
|
||||||
uintptr(hwnd),
|
uintptr(hwnd),
|
||||||
uintptr(unsafe.Pointer(&rect)))
|
uintptr(unsafe.Pointer(&rect)))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error getting size of actual Area control: %v", err))
|
panic(fmt.Errorf("error getting size of actual Area control: %v", err))
|
||||||
}
|
}
|
||||||
return int(rect.right - rect.left),
|
return int(rect.right - rect.left),
|
||||||
|
@ -291,31 +291,31 @@ func scrollArea(s *sysData, wparam _WPARAM, which uintptr) {
|
||||||
uintptr(s.hwnd),
|
uintptr(s.hwnd),
|
||||||
which,
|
which,
|
||||||
uintptr(unsafe.Pointer(&si)))
|
uintptr(unsafe.Pointer(&si)))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error getting current scroll position for scrolling: %v", err))
|
panic(fmt.Errorf("error getting current scroll position for scrolling: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
newpos := si.nPos
|
newpos := si.nPos
|
||||||
switch wparam & 0xFFFF {
|
switch wparam & 0xFFFF {
|
||||||
case _SB_LEFT: // also _SB_TOP but Go won't let me
|
case _SB_LEFT: // also _SB_TOP but Go won't let me
|
||||||
newpos = 0
|
newpos = 0
|
||||||
case _SB_RIGHT: // also _SB_BOTTOM
|
case _SB_RIGHT: // also _SB_BOTTOM
|
||||||
// see comment in adjustAreaScrollbars() below
|
// see comment in adjustAreaScrollbars() below
|
||||||
newpos = maxsize - pagesize
|
newpos = maxsize - pagesize
|
||||||
case _SB_LINELEFT: // also _SB_LINEUP
|
case _SB_LINELEFT: // also _SB_LINEUP
|
||||||
newpos--
|
newpos--
|
||||||
case _SB_LINERIGHT: // also _SB_LINEDOWN
|
case _SB_LINERIGHT: // also _SB_LINEDOWN
|
||||||
newpos++
|
newpos++
|
||||||
case _SB_PAGELEFT: // also _SB_PAGEUP
|
case _SB_PAGELEFT: // also _SB_PAGEUP
|
||||||
newpos -= pagesize
|
newpos -= pagesize
|
||||||
case _SB_PAGERIGHT: // also _SB_PAGEDOWN
|
case _SB_PAGERIGHT: // also _SB_PAGEDOWN
|
||||||
newpos += pagesize
|
newpos += pagesize
|
||||||
case _SB_THUMBPOSITION:
|
case _SB_THUMBPOSITION:
|
||||||
// raymond chen says to just set the newpos to the SCROLLINFO nPos for this message; see http://blogs.msdn.com/b/oldnewthing/archive/2003/07/31/54601.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/08/05/54602.aspx
|
// raymond chen says to just set the newpos to the SCROLLINFO nPos for this message; see http://blogs.msdn.com/b/oldnewthing/archive/2003/07/31/54601.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/08/05/54602.aspx
|
||||||
// do nothing here; newpos already has nPos
|
// do nothing here; newpos already has nPos
|
||||||
case _SB_THUMBTRACK:
|
case _SB_THUMBTRACK:
|
||||||
newpos = si.nTrackPos
|
newpos = si.nTrackPos
|
||||||
} // otherwise just keep the current position (that's what MSDN example code says, anyway)
|
} // otherwise just keep the current position (that's what MSDN example code says, anyway)
|
||||||
|
|
||||||
// make sure we're not out of range
|
// make sure we're not out of range
|
||||||
if newpos < 0 {
|
if newpos < 0 {
|
||||||
|
@ -327,7 +327,7 @@ func scrollArea(s *sysData, wparam _WPARAM, which uintptr) {
|
||||||
|
|
||||||
// this would be where we would put a check to not scroll if the scroll position changed, but see the note about SB_THUMBPOSITION above: Raymond Chen's code always does the scrolling anyway in this case
|
// this would be where we would put a check to not scroll if the scroll position changed, but see the note about SB_THUMBPOSITION above: Raymond Chen's code always does the scrolling anyway in this case
|
||||||
|
|
||||||
delta := -(newpos - si.nPos) // negative because ScrollWindowEx() scrolls in the opposite direction
|
delta := -(newpos - si.nPos) // negative because ScrollWindowEx() scrolls in the opposite direction
|
||||||
dx := delta
|
dx := delta
|
||||||
dy := int32(0)
|
dy := int32(0)
|
||||||
if which == uintptr(_SB_VERT) {
|
if which == uintptr(_SB_VERT) {
|
||||||
|
@ -338,12 +338,12 @@ func scrollArea(s *sysData, wparam _WPARAM, which uintptr) {
|
||||||
uintptr(s.hwnd),
|
uintptr(s.hwnd),
|
||||||
uintptr(dx),
|
uintptr(dx),
|
||||||
uintptr(dy),
|
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), // 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),
|
uintptr(0),
|
||||||
uintptr(0),
|
uintptr(0),
|
||||||
uintptr(_SW_INVALIDATE | _SW_ERASE)) // mark the remaining rect as needing redraw and erase...
|
uintptr(_SW_INVALIDATE|_SW_ERASE)) // mark the remaining rect as needing redraw and erase...
|
||||||
if r1 == _ERROR { // failure
|
if r1 == _ERROR { // failure
|
||||||
panic(fmt.Errorf("error scrolling Area: %v", err))
|
panic(fmt.Errorf("error scrolling Area: %v", err))
|
||||||
}
|
}
|
||||||
// ...but don't redraw the window yet; we need to apply our scroll changes
|
// ...but don't redraw the window yet; we need to apply our scroll changes
|
||||||
|
@ -359,7 +359,7 @@ func scrollArea(s *sysData, wparam _WPARAM, which uintptr) {
|
||||||
|
|
||||||
// NOW redraw it
|
// NOW redraw it
|
||||||
r1, _, err = _updateWindow.Call(uintptr(s.hwnd))
|
r1, _, err = _updateWindow.Call(uintptr(s.hwnd))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error updating Area after scrolling: %v", err))
|
panic(fmt.Errorf("error updating Area after scrolling: %v", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -378,15 +378,15 @@ func adjustAreaScrollbars(s *sysData) {
|
||||||
si.cbSize = uint32(unsafe.Sizeof(si))
|
si.cbSize = uint32(unsafe.Sizeof(si))
|
||||||
si.fMask = _SIF_RANGE | _SIF_PAGE
|
si.fMask = _SIF_RANGE | _SIF_PAGE
|
||||||
si.nMin = 0
|
si.nMin = 0
|
||||||
si.nMax = int32(s.areawidth - 1) // the max point is inclusive, so we have to pass in the last valid value, not the first invalid one (see http://blogs.msdn.com/b/oldnewthing/archive/2003/07/31/54601.aspx); if we don't, we get weird things like the scrollbar sometimes showing one extra scroll position at the end that you can never scroll to
|
si.nMax = int32(s.areawidth - 1) // the max point is inclusive, so we have to pass in the last valid value, not the first invalid one (see http://blogs.msdn.com/b/oldnewthing/archive/2003/07/31/54601.aspx); if we don't, we get weird things like the scrollbar sometimes showing one extra scroll position at the end that you can never scroll to
|
||||||
si.nPage = uint32(cwid)
|
si.nPage = uint32(cwid)
|
||||||
_setScrollInfo.Call(
|
_setScrollInfo.Call(
|
||||||
uintptr(s.hwnd),
|
uintptr(s.hwnd),
|
||||||
uintptr(_SB_HORZ),
|
uintptr(_SB_HORZ),
|
||||||
uintptr(unsafe.Pointer(&si)),
|
uintptr(unsafe.Pointer(&si)),
|
||||||
uintptr(_TRUE)) // redraw the scroll bar
|
uintptr(_TRUE)) // redraw the scroll bar
|
||||||
|
|
||||||
si.cbSize = uint32(unsafe.Sizeof(si)) // MSDN sample code does this a second time; let's do it too to be safe
|
si.cbSize = uint32(unsafe.Sizeof(si)) // MSDN sample code does this a second time; let's do it too to be safe
|
||||||
si.fMask = _SIF_RANGE | _SIF_PAGE
|
si.fMask = _SIF_RANGE | _SIF_PAGE
|
||||||
si.nMin = 0
|
si.nMin = 0
|
||||||
si.nMax = int32(s.areaheight - 1)
|
si.nMax = int32(s.areaheight - 1)
|
||||||
|
@ -395,7 +395,7 @@ func adjustAreaScrollbars(s *sysData) {
|
||||||
uintptr(s.hwnd),
|
uintptr(s.hwnd),
|
||||||
uintptr(_SB_VERT),
|
uintptr(_SB_VERT),
|
||||||
uintptr(unsafe.Pointer(&si)),
|
uintptr(unsafe.Pointer(&si)),
|
||||||
uintptr(_TRUE)) // redraw the scroll bar
|
uintptr(_TRUE)) // redraw the scroll bar
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -405,13 +405,13 @@ var (
|
||||||
func repaintArea(s *sysData) {
|
func repaintArea(s *sysData) {
|
||||||
r1, _, err := _invalidateRect.Call(
|
r1, _, err := _invalidateRect.Call(
|
||||||
uintptr(s.hwnd),
|
uintptr(s.hwnd),
|
||||||
uintptr(0), // the whole area
|
uintptr(0), // the whole area
|
||||||
uintptr(_TRUE)) // have Windows erase if possible
|
uintptr(_TRUE)) // have Windows erase if possible
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error flagging Area as needing repainting after event (last error: %v)", err))
|
panic(fmt.Errorf("error flagging Area as needing repainting after event (last error: %v)", err))
|
||||||
}
|
}
|
||||||
r1, _, err = _updateWindow.Call(uintptr(s.hwnd))
|
r1, _, err = _updateWindow.Call(uintptr(s.hwnd))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error repainting Area after event: %v", err))
|
panic(fmt.Errorf("error repainting Area after event: %v", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -443,24 +443,24 @@ func getModifiers() (m Modifiers) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_getMessageTime = user32.NewProc("GetMessageTime")
|
_getMessageTime = user32.NewProc("GetMessageTime")
|
||||||
_getDoubleClickTime = user32.NewProc("GetDoubleClickTime")
|
_getDoubleClickTime = user32.NewProc("GetDoubleClickTime")
|
||||||
_getSystemMetrics = user32.NewProc("GetSystemMetrics")
|
_getSystemMetrics = user32.NewProc("GetSystemMetrics")
|
||||||
)
|
)
|
||||||
|
|
||||||
func areaMouseEvent(s *sysData, button uint, up bool, wparam _WPARAM, lparam _LPARAM) {
|
func areaMouseEvent(s *sysData, button uint, up bool, wparam _WPARAM, lparam _LPARAM) {
|
||||||
var me MouseEvent
|
var me MouseEvent
|
||||||
|
|
||||||
xpos, ypos := getScrollPos(s.hwnd) // mouse coordinates are relative to control; make them relative to Area
|
xpos, ypos := getScrollPos(s.hwnd) // mouse coordinates are relative to control; make them relative to Area
|
||||||
xpos += lparam.X()
|
xpos += lparam.X()
|
||||||
ypos += lparam.Y()
|
ypos += lparam.Y()
|
||||||
me.Pos = image.Pt(int(xpos), int(ypos))
|
me.Pos = image.Pt(int(xpos), int(ypos))
|
||||||
if !me.Pos.In(image.Rect(0, 0, s.areawidth, s.areaheight)) { // outside the actual Area; no event
|
if !me.Pos.In(image.Rect(0, 0, s.areawidth, s.areaheight)) { // outside the actual Area; no event
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if up {
|
if up {
|
||||||
me.Up = button
|
me.Up = button
|
||||||
} else if button != 0 { // don't run the click counter if the mouse was only moved
|
} else if button != 0 { // don't run the click counter if the mouse was only moved
|
||||||
me.Down = button
|
me.Down = button
|
||||||
// this returns a LONG, which is int32, but we don't need to worry about the signedness because for the same bit widths and two's complement arithmetic, s1-s2 == u1-u2 if bits(s1)==bits(s2) and bits(u1)==bits(u2) (and Windows requires two's complement: http://blogs.msdn.com/b/oldnewthing/archive/2005/05/27/422551.aspx)
|
// this returns a LONG, which is int32, but we don't need to worry about the signedness because for the same bit widths and two's complement arithmetic, s1-s2 == u1-u2 if bits(s1)==bits(s2) and bits(u1)==bits(u2) (and Windows requires two's complement: http://blogs.msdn.com/b/oldnewthing/archive/2005/05/27/422551.aspx)
|
||||||
// signedness isn't much of an issue for these calls anyway because http://stackoverflow.com/questions/24022225/what-are-the-sign-extension-rules-for-calling-windows-api-functions-stdcall-t and that we're only using unsigned values (think back to how you (didn't) handle signedness in assembly language) AND because of the above AND because the statistics below (time interval and width/height) really don't make sense if negative
|
// signedness isn't much of an issue for these calls anyway because http://stackoverflow.com/questions/24022225/what-are-the-sign-extension-rules-for-calling-windows-api-functions-stdcall-t and that we're only using unsigned values (think back to how you (didn't) handle signedness in assembly language) AND because of the above AND because the statistics below (time interval and width/height) really don't make sense if negative
|
||||||
|
@ -470,23 +470,23 @@ func areaMouseEvent(s *sysData, button uint, up bool, wparam _WPARAM, lparam _LP
|
||||||
xdist, _, _ := _getSystemMetrics.Call(_SM_CXDOUBLECLK)
|
xdist, _, _ := _getSystemMetrics.Call(_SM_CXDOUBLECLK)
|
||||||
ydist, _, _ := _getSystemMetrics.Call(_SM_CYDOUBLECLK)
|
ydist, _, _ := _getSystemMetrics.Call(_SM_CYDOUBLECLK)
|
||||||
me.Count = s.clickCounter.click(button, me.Pos.X, me.Pos.Y,
|
me.Count = s.clickCounter.click(button, me.Pos.X, me.Pos.Y,
|
||||||
time, maxTime, int(xdist / 2), int(ydist / 2))
|
time, maxTime, int(xdist/2), int(ydist/2))
|
||||||
}
|
}
|
||||||
// though wparam will contain control and shift state, let's use just one function to get modifiers for both keyboard and mouse events; it'll work the same anyway since we have to do this for alt and windows key (super)
|
// though wparam will contain control and shift state, let's use just one function to get modifiers for both keyboard and mouse events; it'll work the same anyway since we have to do this for alt and windows key (super)
|
||||||
me.Modifiers = getModifiers()
|
me.Modifiers = getModifiers()
|
||||||
if button != 1 && (wparam & _MK_LBUTTON) != 0 {
|
if button != 1 && (wparam&_MK_LBUTTON) != 0 {
|
||||||
me.Held = append(me.Held, 1)
|
me.Held = append(me.Held, 1)
|
||||||
}
|
}
|
||||||
if button != 2 && (wparam & _MK_MBUTTON) != 0 {
|
if button != 2 && (wparam&_MK_MBUTTON) != 0 {
|
||||||
me.Held = append(me.Held, 2)
|
me.Held = append(me.Held, 2)
|
||||||
}
|
}
|
||||||
if button != 3 && (wparam & _MK_RBUTTON) != 0 {
|
if button != 3 && (wparam&_MK_RBUTTON) != 0 {
|
||||||
me.Held = append(me.Held, 3)
|
me.Held = append(me.Held, 3)
|
||||||
}
|
}
|
||||||
if button != 4 && (wparam & _MK_XBUTTON1) != 0 {
|
if button != 4 && (wparam&_MK_XBUTTON1) != 0 {
|
||||||
me.Held = append(me.Held, 4)
|
me.Held = append(me.Held, 4)
|
||||||
}
|
}
|
||||||
if button != 5 && (wparam & _MK_XBUTTON2) != 0 {
|
if button != 5 && (wparam&_MK_XBUTTON2) != 0 {
|
||||||
me.Held = append(me.Held, 5)
|
me.Held = append(me.Held, 5)
|
||||||
}
|
}
|
||||||
repaint := s.handler.Mouse(me)
|
repaint := s.handler.Mouse(me)
|
||||||
|
@ -532,49 +532,49 @@ func areaKeyEvent(s *sysData, up bool, wparam _WPARAM, lparam _LPARAM) {
|
||||||
|
|
||||||
// all mappings come from GLFW - https://github.com/glfw/glfw/blob/master/src/win32_window.c#L152
|
// all mappings come from GLFW - https://github.com/glfw/glfw/blob/master/src/win32_window.c#L152
|
||||||
var numpadextkeys = map[_WPARAM]ExtKey{
|
var numpadextkeys = map[_WPARAM]ExtKey{
|
||||||
_VK_HOME: N7,
|
_VK_HOME: N7,
|
||||||
_VK_UP: N8,
|
_VK_UP: N8,
|
||||||
_VK_PRIOR: N9,
|
_VK_PRIOR: N9,
|
||||||
_VK_LEFT: N4,
|
_VK_LEFT: N4,
|
||||||
_VK_CLEAR: N5,
|
_VK_CLEAR: N5,
|
||||||
_VK_RIGHT: N6,
|
_VK_RIGHT: N6,
|
||||||
_VK_END: N1,
|
_VK_END: N1,
|
||||||
_VK_DOWN: N2,
|
_VK_DOWN: N2,
|
||||||
_VK_NEXT: N3,
|
_VK_NEXT: N3,
|
||||||
_VK_INSERT: N0,
|
_VK_INSERT: N0,
|
||||||
_VK_DELETE: NDot,
|
_VK_DELETE: NDot,
|
||||||
}
|
}
|
||||||
|
|
||||||
var extkeys = map[_WPARAM]ExtKey{
|
var extkeys = map[_WPARAM]ExtKey{
|
||||||
_VK_ESCAPE: Escape,
|
_VK_ESCAPE: Escape,
|
||||||
_VK_INSERT: Insert,
|
_VK_INSERT: Insert,
|
||||||
_VK_DELETE: Delete,
|
_VK_DELETE: Delete,
|
||||||
_VK_HOME: Home,
|
_VK_HOME: Home,
|
||||||
_VK_END: End,
|
_VK_END: End,
|
||||||
_VK_PRIOR: PageUp,
|
_VK_PRIOR: PageUp,
|
||||||
_VK_NEXT: PageDown,
|
_VK_NEXT: PageDown,
|
||||||
_VK_UP: Up,
|
_VK_UP: Up,
|
||||||
_VK_DOWN: Down,
|
_VK_DOWN: Down,
|
||||||
_VK_LEFT: Left,
|
_VK_LEFT: Left,
|
||||||
_VK_RIGHT: Right,
|
_VK_RIGHT: Right,
|
||||||
_VK_F1: F1,
|
_VK_F1: F1,
|
||||||
_VK_F2: F2,
|
_VK_F2: F2,
|
||||||
_VK_F3: F3,
|
_VK_F3: F3,
|
||||||
_VK_F4: F4,
|
_VK_F4: F4,
|
||||||
_VK_F5: F5,
|
_VK_F5: F5,
|
||||||
_VK_F6: F6,
|
_VK_F6: F6,
|
||||||
_VK_F7: F7,
|
_VK_F7: F7,
|
||||||
_VK_F8: F8,
|
_VK_F8: F8,
|
||||||
_VK_F9: F9,
|
_VK_F9: F9,
|
||||||
_VK_F10: F10,
|
_VK_F10: F10,
|
||||||
_VK_F11: F11,
|
_VK_F11: F11,
|
||||||
_VK_F12: F12,
|
_VK_F12: F12,
|
||||||
// numpad numeric keys and . are handled in events_notdarwin.go
|
// numpad numeric keys and . are handled in events_notdarwin.go
|
||||||
// numpad enter is handled in code above
|
// numpad enter is handled in code above
|
||||||
_VK_ADD: NAdd,
|
_VK_ADD: NAdd,
|
||||||
_VK_SUBTRACT: NSubtract,
|
_VK_SUBTRACT: NSubtract,
|
||||||
_VK_MULTIPLY: NMultiply,
|
_VK_MULTIPLY: NMultiply,
|
||||||
_VK_DIVIDE: NDivide,
|
_VK_DIVIDE: NDivide,
|
||||||
}
|
}
|
||||||
|
|
||||||
// sanity check
|
// sanity check
|
||||||
|
@ -584,7 +584,7 @@ func init() {
|
||||||
included[v] = true
|
included[v] = true
|
||||||
}
|
}
|
||||||
for i := 1; i < int(_nextkeys); i++ {
|
for i := 1; i < int(_nextkeys); i++ {
|
||||||
if i >= int(N0) && i <= int(N9) { // skip numpad numbers, ., and enter
|
if i >= int(N0) && i <= int(N9) { // skip numpad numbers, ., and enter
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if i == int(NDot) || i == int(NEnter) {
|
if i == int(NDot) || i == int(NEnter) {
|
||||||
|
@ -598,18 +598,18 @@ func init() {
|
||||||
|
|
||||||
var modonlykeys = map[_WPARAM]Modifiers{
|
var modonlykeys = map[_WPARAM]Modifiers{
|
||||||
// even if the separate left/right aren't necessary, have them here anyway, just to be safe
|
// even if the separate left/right aren't necessary, have them here anyway, just to be safe
|
||||||
_VK_CONTROL: Ctrl,
|
_VK_CONTROL: Ctrl,
|
||||||
_VK_LCONTROL: Ctrl,
|
_VK_LCONTROL: Ctrl,
|
||||||
_VK_RCONTROL: Ctrl,
|
_VK_RCONTROL: Ctrl,
|
||||||
_VK_MENU: Alt,
|
_VK_MENU: Alt,
|
||||||
_VK_LMENU: Alt,
|
_VK_LMENU: Alt,
|
||||||
_VK_RMENU: Alt,
|
_VK_RMENU: Alt,
|
||||||
_VK_SHIFT: Shift,
|
_VK_SHIFT: Shift,
|
||||||
_VK_LSHIFT: Shift,
|
_VK_LSHIFT: Shift,
|
||||||
_VK_RSHIFT: Shift,
|
_VK_RSHIFT: Shift,
|
||||||
// there's no combined Windows key virtual-key code as there is with the others
|
// there's no combined Windows key virtual-key code as there is with the others
|
||||||
_VK_LWIN: Super,
|
_VK_LWIN: Super,
|
||||||
_VK_RWIN: Super,
|
_VK_RWIN: Super,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -618,7 +618,7 @@ var (
|
||||||
|
|
||||||
func areaWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT {
|
func areaWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT {
|
||||||
s := getSysData(hwnd)
|
s := getSysData(hwnd)
|
||||||
if s == nil { // not yet saved
|
if s == nil { // not yet saved
|
||||||
return storeSysData(hwnd, uMsg, wParam, lParam)
|
return storeSysData(hwnd, uMsg, wParam, lParam)
|
||||||
}
|
}
|
||||||
switch uMsg {
|
switch uMsg {
|
||||||
|
@ -672,11 +672,11 @@ func areaWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESU
|
||||||
areaMouseEvent(s, 3, true, wParam, lParam)
|
areaMouseEvent(s, 3, true, wParam, lParam)
|
||||||
return 0
|
return 0
|
||||||
case _WM_XBUTTONDOWN:
|
case _WM_XBUTTONDOWN:
|
||||||
which := uint((wParam >> 16) & 0xFFFF) + 3 // values start at 1; we want them to start at 4
|
which := uint((wParam>>16)&0xFFFF) + 3 // values start at 1; we want them to start at 4
|
||||||
areaMouseEvent(s, which, false, wParam, lParam)
|
areaMouseEvent(s, which, false, wParam, lParam)
|
||||||
return _LRESULT(_TRUE) // XBUTTON messages are different!
|
return _LRESULT(_TRUE) // XBUTTON messages are different!
|
||||||
case _WM_XBUTTONUP:
|
case _WM_XBUTTONUP:
|
||||||
which := uint((wParam >> 16) & 0xFFFF) + 3
|
which := uint((wParam>>16)&0xFFFF) + 3
|
||||||
areaMouseEvent(s, which, true, wParam, lParam)
|
areaMouseEvent(s, which, true, wParam, lParam)
|
||||||
return _LRESULT(_TRUE)
|
return _LRESULT(_TRUE)
|
||||||
case _WM_KEYDOWN:
|
case _WM_KEYDOWN:
|
||||||
|
@ -693,10 +693,10 @@ func areaWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESU
|
||||||
areaKeyEvent(s, true, wParam, lParam)
|
areaKeyEvent(s, true, wParam, lParam)
|
||||||
return defWindowProc(hwnd, uMsg, wParam, lParam)
|
return defWindowProc(hwnd, uMsg, wParam, lParam)
|
||||||
case msgSetAreaSize:
|
case msgSetAreaSize:
|
||||||
s.areawidth = int(wParam) // see setAreaSize() in sysdata_windows.go
|
s.areawidth = int(wParam) // see setAreaSize() in sysdata_windows.go
|
||||||
s.areaheight = int(lParam)
|
s.areaheight = int(lParam)
|
||||||
adjustAreaScrollbars(s)
|
adjustAreaScrollbars(s)
|
||||||
repaintArea(s) // this calls for an update
|
repaintArea(s) // this calls for an update
|
||||||
return 0
|
return 0
|
||||||
case msgRepaintAll:
|
case msgRepaintAll:
|
||||||
repaintArea(s)
|
repaintArea(s)
|
||||||
|
@ -709,45 +709,45 @@ func areaWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESU
|
||||||
|
|
||||||
func registerAreaWndClass() (err error) {
|
func registerAreaWndClass() (err error) {
|
||||||
wc := &_WNDCLASS{
|
wc := &_WNDCLASS{
|
||||||
style: _CS_HREDRAW | _CS_VREDRAW, // no CS_DBLCLKS because do that manually
|
style: _CS_HREDRAW | _CS_VREDRAW, // no CS_DBLCLKS because do that manually
|
||||||
lpszClassName: utf16ToArg(areaWndClass),
|
lpszClassName: utf16ToArg(areaWndClass),
|
||||||
lpfnWndProc: syscall.NewCallback(areaWndProc),
|
lpfnWndProc: syscall.NewCallback(areaWndProc),
|
||||||
hInstance: hInstance,
|
hInstance: hInstance,
|
||||||
hIcon: icon,
|
hIcon: icon,
|
||||||
hCursor: cursor,
|
hCursor: cursor,
|
||||||
hbrBackground: _HBRUSH(_NULL), // no brush; we handle WM_ERASEBKGND
|
hbrBackground: _HBRUSH(_NULL), // no brush; we handle WM_ERASEBKGND
|
||||||
}
|
}
|
||||||
r1, _, err := _registerClass.Call(uintptr(unsafe.Pointer(wc)))
|
r1, _, err := _registerClass.Call(uintptr(unsafe.Pointer(wc)))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type _BITMAPINFO struct {
|
type _BITMAPINFO struct {
|
||||||
bmiHeader _BITMAPINFOHEADER
|
bmiHeader _BITMAPINFOHEADER
|
||||||
bmiColors [32]uintptr // we don't use it; make it an arbitrary number that wouldn't cause issues
|
bmiColors [32]uintptr // we don't use it; make it an arbitrary number that wouldn't cause issues
|
||||||
}
|
}
|
||||||
|
|
||||||
type _BITMAPINFOHEADER struct {
|
type _BITMAPINFOHEADER struct {
|
||||||
biSize uint32
|
biSize uint32
|
||||||
biWidth int32
|
biWidth int32
|
||||||
biHeight int32
|
biHeight int32
|
||||||
biPlanes uint16
|
biPlanes uint16
|
||||||
biBitCount uint16
|
biBitCount uint16
|
||||||
biCompression uint32
|
biCompression uint32
|
||||||
biSizeImage uint32
|
biSizeImage uint32
|
||||||
biXPelsPerMeter int32
|
biXPelsPerMeter int32
|
||||||
biYPelsPerMeter int32
|
biYPelsPerMeter int32
|
||||||
biClrUsed uint32
|
biClrUsed uint32
|
||||||
biClrImportant uint32
|
biClrImportant uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
type _BLENDFUNCTION struct {
|
type _BLENDFUNCTION struct {
|
||||||
BlendOp byte
|
BlendOp byte
|
||||||
BlendFlags byte
|
BlendFlags byte
|
||||||
SourceConstantAlpha byte
|
SourceConstantAlpha byte
|
||||||
AlphaFormat byte
|
AlphaFormat byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// AlphaBlend() takes a BLENDFUNCTION value
|
// AlphaBlend() takes a BLENDFUNCTION value
|
||||||
|
@ -761,10 +761,10 @@ func (b _BLENDFUNCTION) arg() (x uintptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type _PAINTSTRUCT struct {
|
type _PAINTSTRUCT struct {
|
||||||
hdc _HANDLE
|
hdc _HANDLE
|
||||||
fErase int32 // originally BOOL
|
fErase int32 // originally BOOL
|
||||||
rcPaint _RECT
|
rcPaint _RECT
|
||||||
fRestore int32 // originally BOOL
|
fRestore int32 // originally BOOL
|
||||||
fIncUpdate int32 // originally BOOL
|
fIncUpdate int32 // originally BOOL
|
||||||
rgbReserved [32]byte
|
rgbReserved [32]byte
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue