summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-08-05 12:49:08 -0400
committerPietro Gagliardi <[email protected]>2014-08-05 12:49:08 -0400
commit96c81996bacd8709cbb4293e2153eb0b9efac294 (patch)
treea10472b54b7b70522c5249965113652b9d8c58a7
parent57df87f11d0d77da35ee624241d6177918a7215a (diff)
Fixed errors with Area on Windows. Woo!
-rw-r--r--redo/area_windows.c24
-rw-r--r--redo/area_windows.go45
-rw-r--r--redo/uitask_windows.go2
-rw-r--r--redo/winapi_windows.h1
4 files changed, 38 insertions, 34 deletions
diff --git a/redo/area_windows.c b/redo/area_windows.c
index 35c02fd..49a56c6 100644
--- a/redo/area_windows.c
+++ b/redo/area_windows.c
@@ -258,7 +258,7 @@ static void scrollArea(HWND hwnd, void *data, WPARAM wParam, int which)
// NOW redraw it
if (UpdateWindow(hwnd) == 0)
- panic("error updating Area after scrolling", GetLastError());
+ xpanic("error updating Area after scrolling", GetLastError());
}
static void adjustAreaScrollbars(HWND hwnd, void *data)
@@ -305,7 +305,7 @@ void repaintArea(HWND hwnd)
xpanic("error repainting Area after event", GetLastError());
}
-void areaMouseEvent(HWND hwnd, void *data, DWORD button, BOOL up, LPARAM lParam)
+void areaMouseEvent(HWND hwnd, void *data, DWORD button, BOOL up, WPARAM wParam, LPARAM lParam)
{
int xpos, ypos;
@@ -313,7 +313,7 @@ void areaMouseEvent(HWND hwnd, void *data, DWORD button, BOOL up, LPARAM lParam)
getScrollPos(hwnd, &xpos, &ypos);
xpos += GET_X_LPARAM(lParam);
ypos += GET_Y_LPARAM(lParam);
- finishAreaMouseEvent(data, button, up, xpos, ypos);
+ finishAreaMouseEvent(data, button, up, wParam, xpos, ypos);
}
static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
@@ -363,34 +363,34 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
// and don't eat the click, as we want to handle clicks that switch into Windows with Areas from other windows
return MA_ACTIVATE;
case WM_MOUSEMOVE:
- areaMouseEvent(hwnd, data, 0, FALSE, lParam);
+ areaMouseEvent(hwnd, data, 0, FALSE, wParam, lParam);
return 0;
case WM_LBUTTONDOWN:
- areaMouseEvent(hwnd, data, 1, FALSE, lParam);
+ areaMouseEvent(hwnd, data, 1, FALSE, wParam, lParam);
return 0;
case WM_LBUTTONUP:
- areaMouseEvent(hwnd, data, 1, TRUE, lParam);
+ areaMouseEvent(hwnd, data, 1, TRUE, wParam, lParam);
return 0;
case WM_MBUTTONDOWN:
- areaMouseEvent(hwnd, data, 2, FALSE, lParam);
+ areaMouseEvent(hwnd, data, 2, FALSE, wParam, lParam);
return 0;
case WM_MBUTTONUP:
- areaMouseEvent(hwnd, data, 2, TRUE, lParam);
+ areaMouseEvent(hwnd, data, 2, TRUE, wParam, lParam);
return 0;
case WM_RBUTTONDOWN:
- areaMouseEvent(hwnd, data, 3, FALSE, lParam);
+ areaMouseEvent(hwnd, data, 3, FALSE, wParam, lParam);
return 0;
case WM_RBUTTONUP:
- areaMouseEvent(hwnd, data, 3, TRUE, lParam);
+ areaMouseEvent(hwnd, data, 3, TRUE, wParam, lParam);
return 0;
case WM_XBUTTONDOWN:
// values start at 1; we want them to start at 4
which = (DWORD) GET_XBUTTON_WPARAM(wParam) + 3;
- areaMouseEvent(hwnd, data, which, FALSE, lParam);
+ areaMouseEvent(hwnd, data, which, FALSE, wParam, lParam);
return TRUE; // XBUTTON messages are different!
case WM_XBUTTONUP:
which = (DWORD) GET_XBUTTON_WPARAM(wParam) + 3;
- areaMouseEvent(hwnd, data, which, TRUE, lParam);
+ areaMouseEvent(hwnd, data, which, TRUE, wParam, lParam);
return TRUE;
case WM_KEYDOWN:
areaKeyEvent(data, FALSE, wParam, lParam);
diff --git a/redo/area_windows.go b/redo/area_windows.go
index ce90167..d96a21c 100644
--- a/redo/area_windows.go
+++ b/redo/area_windows.go
@@ -20,10 +20,10 @@ type area struct {
clickCounter *clickCounter
}
-func registerAreaWndClass() (err error) {
+func makeAreaWindowClass() error {
var errmsg *C.char
- err := C.makeWindowWindowClass(&errmsg)
+ err := C.makeAreaWindowClass(&errmsg)
if err != 0 || errmsg != nil {
return fmt.Errorf("%s: %v", C.GoString(errmsg), syscall.Errno(err))
}
@@ -36,7 +36,7 @@ func newArea(ab *areabase) Area {
clickCounter: new(clickCounter),
}
a._hwnd = C.newArea(unsafe.Pointer(a))
- a.SetSize(width, height)
+ a.SetSize(a.width, a.height)
return a
}
@@ -57,7 +57,7 @@ func doPaint(xrect *C.RECT, hscroll C.int, vscroll C.int, data unsafe.Pointer, d
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
// make sure the cliprect doesn't fall outside the size of the Area
- cliprect = cliprect.Intersect(image.Rect(0, 0, a.areawidth, a.areaheight))
+ cliprect = cliprect.Intersect(image.Rect(0, 0, a.width, a.height))
if !cliprect.Empty() { // we have an update rect
i := a.handler.Paint(cliprect)
*dx = C.intptr_t(i.Rect.Dx())
@@ -68,10 +68,10 @@ func doPaint(xrect *C.RECT, hscroll C.int, vscroll C.int, data unsafe.Pointer, d
}
//export dotoARGB
-func dotoARGB(img unsafe.Pointer, ppvBIts unsafe.Pointer) {
+func dotoARGB(img unsafe.Pointer, ppvBits unsafe.Pointer) {
i := (*image.RGBA)(unsafe.Pointer(img))
// the bitmap Windows gives us has a stride == width
- toARGB(i, unsafe.Pointer(ppvBits), i.Rect.Dx() * 4)
+ toARGB(i, uintptr(ppvBits), i.Rect.Dx() * 4)
}
//export areaWidthLONG
@@ -108,13 +108,13 @@ func getModifiers() (m Modifiers) {
}
//export finishAreaMouseEvent
-func finishAreaMouseEvent(data unsafe.Pointer, cbutton C.DWORD, up C.BOOL, xpos C.int, ypos C.int) {
+func finishAreaMouseEvent(data unsafe.Pointer, cbutton C.DWORD, up C.BOOL, wParam C.WPARAM, xpos C.int, ypos C.int) {
var me MouseEvent
a := (*area)(data)
button := uint(cbutton)
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, a.width, a.height)) { // outside the actual Area; no event
return
}
if up != C.FALSE {
@@ -127,30 +127,32 @@ func finishAreaMouseEvent(data unsafe.Pointer, cbutton C.DWORD, up C.BOOL, xpos
maxTime := C.GetDoubleClickTime()
// ignore zero returns and errors; MSDN says zero will be returned on error but that GetLastError() is meaningless
xdist := C.GetSystemMetrics(C.SM_CXDOUBLECLK)
- ydist, _, _ := C.GetSystemMetrics(C.SM_CYDOUBLECLK)
- me.Count = s.clickCounter.click(button, me.Pos.X, me.Pos.Y,
- time, maxTime, int(xdist/2), int(ydist/2))
+ ydist := C.GetSystemMetrics(C.SM_CYDOUBLECLK)
+ me.Count = a.clickCounter.click(button, me.Pos.X, me.Pos.Y,
+ uintptr(time), uintptr(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)
me.Modifiers = getModifiers()
- if button != 1 && (wparam&_MK_LBUTTON) != 0 {
+ // TODO make wParam unsigned
+ // TODO XBUTTONs use something different
+ if button != 1 && (wParam & C.MK_LBUTTON) != 0 {
me.Held = append(me.Held, 1)
}
- if button != 2 && (wparam&_MK_MBUTTON) != 0 {
+ if button != 2 && (wParam & C.MK_MBUTTON) != 0 {
me.Held = append(me.Held, 2)
}
- if button != 3 && (wparam&_MK_RBUTTON) != 0 {
+ if button != 3 && (wParam & C.MK_RBUTTON) != 0 {
me.Held = append(me.Held, 3)
}
- if button != 4 && (wparam&_MK_XBUTTON1) != 0 {
+ if button != 4 && (wParam & C.MK_XBUTTON1) != 0 {
me.Held = append(me.Held, 4)
}
- if button != 5 && (wparam&_MK_XBUTTON2) != 0 {
+ if button != 5 && (wParam & C.MK_XBUTTON2) != 0 {
me.Held = append(me.Held, 5)
}
repaint := a.handler.Mouse(me)
if repaint {
- C.repaintArea(a.hwnd)
+ a.RepaintAll()
}
}
@@ -185,10 +187,11 @@ func areaKeyEvent(data unsafe.Pointer, up C.BOOL, wParam C.WPARAM, lParam C.LPAR
// no key, extkey, or modifiers; do nothing
return
}
- ke.Up = up
+ ke.Up = up != C.FALSE
+ // TODO repaint may no longer be needed
repaint := a.handler.Key(ke)
if repaint {
- C.repaintArea(a)
+ a.RepaintAll()
}
}
@@ -303,8 +306,8 @@ func (a *area) preferredSize(d *sizing) (width, height int) {
return a.width, a.height
}
-func (a *area) commitResize(a *allocation, d *sizing) {
- basecommitResize(a, a, d)
+func (a *area) commitResize(c *allocation, d *sizing) {
+ basecommitResize(a, c, d)
}
func (a *area) getAuxResizeInfo(d *sizing) {
diff --git a/redo/uitask_windows.go b/redo/uitask_windows.go
index 0f8fa4b..d99d6a9 100644
--- a/redo/uitask_windows.go
+++ b/redo/uitask_windows.go
@@ -8,7 +8,7 @@ import (
"unsafe"
)
-// #cgo LDFLAGS: -luser32 -lkernel32 -lgdi32 -luxtheme
+// #cgo LDFLAGS: -luser32 -lkernel32 -lgdi32 -luxtheme -lmsimg32
// #include "winapi_windows.h"
import "C"
diff --git a/redo/winapi_windows.h b/redo/winapi_windows.h
index 0cc8cb1..ebbb58a 100644
--- a/redo/winapi_windows.h
+++ b/redo/winapi_windows.h
@@ -20,6 +20,7 @@
#include <uxtheme.h>
#include <string.h>
#include <wchar.h>
+#include <windowsx.h>
/* global messages unique to everything */
enum {