Fixed lots of syntax errors, including one where I forgot a parameter to a Windows API call, oops... the problem is present in the main package being replaced too. :x It will be fixed when I move this redo up. Also added Area initializer to uiinit(). NOW does it work???

This commit is contained in:
Pietro Gagliardi 2014-08-05 12:29:37 -04:00
parent fada6849c4
commit 57df87f11d
3 changed files with 27 additions and 28 deletions

View File

@ -3,7 +3,7 @@
/* TODO either strip the // comments or find out if --std=c99 is safe for cgo */ /* TODO either strip the // comments or find out if --std=c99 is safe for cgo */
#include "winapi_windows.h" #include "winapi_windows.h"
#include "_cgo_epxort.h" #include "_cgo_export.h"
#define areaWindowClass L"gouiarea" #define areaWindowClass L"gouiarea"
@ -21,7 +21,7 @@ static void getScrollPos(HWND hwnd, int *xpos, int *ypos)
ZeroMemory(&si, sizeof (SCROLLINFO)); ZeroMemory(&si, sizeof (SCROLLINFO));
si.cbSize = sizeof (SCROLLINFO); si.cbSize = sizeof (SCROLLINFO);
si.fMask = SIF_POS | SIF_TRACKPOS; si.fMask = SIF_POS | SIF_TRACKPOS;
if (GetScrollInfo(hwnd, _SB_VERT, &si) == 0) if (GetScrollInfo(hwnd, SB_VERT, &si) == 0)
xpanic("error getting vertical scroll position for Area", GetLastError()); xpanic("error getting vertical scroll position for Area", GetLastError());
*ypos = si.nPos; *ypos = si.nPos;
} }
@ -50,7 +50,7 @@ static void paintArea(HWND hwnd, void *data)
if (GetUpdateRect(hwnd, &xrect, TRUE) == 0) if (GetUpdateRect(hwnd, &xrect, TRUE) == 0)
return; // no update rect; do nothing return; // no update rect; do nothing
getScrollPos(s.hwnd, &hscroll, &vscroll); getScrollPos(hwnd, &hscroll, &vscroll);
i = doPaint(&xrect, hscroll, vscroll, data, &dx, &dy); i = doPaint(&xrect, hscroll, vscroll, data, &dx, &dy);
if (i == NULL) // cliprect empty if (i == NULL) // cliprect empty
@ -91,8 +91,9 @@ static void paintArea(HWND hwnd, void *data)
// AlphaBlend(), however, sees it - see http://msdn.microsoft.com/en-us/library/windows/desktop/dd183352%28v=vs.85%29.aspx // AlphaBlend(), however, sees it - see http://msdn.microsoft.com/en-us/library/windows/desktop/dd183352%28v=vs.85%29.aspx
ZeroMemory(&bi, sizeof (BITMAPINFO)); ZeroMemory(&bi, sizeof (BITMAPINFO));
bi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); bi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
bi.bmiHeader.biWidth = int32(i.Rect.Dx()) // TODO check types
bi.bmiHeader.biHeight = -int32(i.Rect.Dy()) // negative height to force top-down drawing bi.bmiHeader.biWidth = dx;
bi.bmiHeader.biHeight = -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;
@ -108,7 +109,7 @@ static void paintArea(HWND hwnd, void *data)
// first, we need to load the bitmap memory, because Windows makes it for us // first, we need to load the bitmap memory, because Windows makes it for us
// 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
dotoARGB(i, ppvBits); dotoARGB(i, (void *) ppvBits);
// 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
@ -118,7 +119,6 @@ static void paintArea(HWND hwnd, void *data)
previbitmap = (HBITMAP) SelectObject(idc, ibitmap); previbitmap = (HBITMAP) SelectObject(idc, ibitmap);
if (previbitmap == NULL) if (previbitmap == NULL)
xpanic("error connecting HBITMAP for image returned by AreaHandler.Paint() to its HDC", GetLastError()); xpanic("error connecting HBITMAP for image returned by AreaHandler.Paint() to its HDC", GetLastError());
}
// AND FINALLY WE CAN DO THE ALPHA BLENDING!!!!!!111 // AND FINALLY WE CAN DO THE ALPHA BLENDING!!!!!!111
blendfunc.BlendOp = AC_SRC_OVER; blendfunc.BlendOp = AC_SRC_OVER;
@ -167,7 +167,7 @@ static SIZE getAreaControlSize(HWND hwnd)
static void scrollArea(HWND hwnd, void *data, WPARAM wParam, int which) static void scrollArea(HWND hwnd, void *data, WPARAM wParam, int which)
{ {
SCROLILNFO si; SCROLLINFO si;
SIZE size; SIZE size;
LONG cwid, cht; LONG cwid, cht;
LONG pagesize, maxsize; LONG pagesize, maxsize;
@ -180,10 +180,10 @@ static void scrollArea(HWND hwnd, void *data, WPARAM wParam, int which)
cht = size.cy; cht = size.cy;
if (which == SB_HORZ) { if (which == SB_HORZ) {
pagesize = cwid; pagesize = cwid;
maxsize = areaWidthLONG(data) maxsize = areaWidthLONG(data);
} else if (which == SB_VERT) { } else if (which == SB_VERT) {
pagesize = cht pagesize = cht;
maxsize = areaHeightLONG(data) maxsize = areaHeightLONG(data);
} else } else
xpanic("invalid which sent to scrollArea()", 0); xpanic("invalid which sent to scrollArea()", 0);
@ -231,12 +231,12 @@ static void scrollArea(HWND hwnd, void *data, WPARAM wParam, int which)
// 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 = 0 dy = 0;
if (which == SB_VERT) { if (which == SB_VERT) {
dx = 0 dx = 0;
dy = delta dy = delta;
} }
if (ScrollWindowEx(hwnd, if (ScrollWindowEx(hwnd,
dx, dy, // TODO correct types dx, dy, // TODO correct types
@ -254,7 +254,7 @@ static void scrollArea(HWND hwnd, void *data, WPARAM wParam, int which)
si.fMask = SIF_POS; si.fMask = SIF_POS;
si.nPos = (int) newpos; si.nPos = (int) newpos;
// TODO double-check that this doesn't return an error // TODO double-check that this doesn't return an error
SetScrollInfo(hwnd, which, &si); SetScrollInfo(hwnd, which, &si, TRUE); // redraw scrollbar
// NOW redraw it // NOW redraw it
if (UpdateWindow(hwnd) == 0) if (UpdateWindow(hwnd) == 0)
@ -316,10 +316,6 @@ void areaMouseEvent(HWND hwnd, void *data, DWORD button, BOOL up, LPARAM lParam)
finishAreaMouseEvent(data, button, up, xpos, ypos); finishAreaMouseEvent(data, button, up, xpos, ypos);
} }
var (
_setFocus = user32.NewProc("SetFocus")
)
static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
void *data; void *data;
@ -373,11 +369,11 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
areaMouseEvent(hwnd, data, 1, FALSE, lParam); areaMouseEvent(hwnd, data, 1, FALSE, lParam);
return 0; return 0;
case WM_LBUTTONUP: case WM_LBUTTONUP:
areaMouseEvent(hwnd, data, 1, TRUE, lParam) areaMouseEvent(hwnd, data, 1, TRUE, lParam);
return 0; return 0;
case WM_MBUTTONDOWN: case WM_MBUTTONDOWN:
areaMouseEvent(hwnd, data, 2, FALSE, lParam); areaMouseEvent(hwnd, data, 2, FALSE, lParam);
return 0 return 0;
case WM_MBUTTONUP: case WM_MBUTTONUP:
areaMouseEvent(hwnd, data, 2, TRUE, lParam); areaMouseEvent(hwnd, data, 2, TRUE, lParam);
return 0; return 0;
@ -396,17 +392,17 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
which = (DWORD) GET_XBUTTON_WPARAM(wParam) + 3; which = (DWORD) GET_XBUTTON_WPARAM(wParam) + 3;
areaMouseEvent(hwnd, data, which, TRUE, lParam); areaMouseEvent(hwnd, data, which, TRUE, lParam);
return TRUE; return TRUE;
case _WM_KEYDOWN: case WM_KEYDOWN:
areaKeyEvent(data, FALSE, wParam, lParam); areaKeyEvent(data, FALSE, wParam, lParam);
return 0; return 0;
case _WM_KEYUP: case WM_KEYUP:
areaKeyEvent(data, TRUE, wParam, lParam); areaKeyEvent(data, TRUE, wParam, lParam);
return 0; return 0;
// Alt+[anything] and F10 send these instead and require us to return to DefWindowProc() so global keystrokes such as Alt+Tab can be processed // Alt+[anything] and F10 send these instead and require us to return to DefWindowProc() so global keystrokes such as Alt+Tab can be processed
case _WM_SYSKEYDOWN: case WM_SYSKEYDOWN:
areaKeyEvent(data, FALSE, wParam, lParam); areaKeyEvent(data, FALSE, wParam, lParam);
return DefWindowProcW(hwnd, uMsg, wParam, lParam); return DefWindowProcW(hwnd, uMsg, wParam, lParam);
case _WM_SYSKEYUP: case WM_SYSKEYUP:
areaKeyEvent(data, TRUE, wParam, lParam); areaKeyEvent(data, TRUE, wParam, lParam);
return DefWindowProcW(hwnd, uMsg, wParam, lParam); return DefWindowProcW(hwnd, uMsg, wParam, lParam);
case msgAreaSizeChanged: case msgAreaSizeChanged:

View File

@ -68,7 +68,7 @@ func doPaint(xrect *C.RECT, hscroll C.int, vscroll C.int, data unsafe.Pointer, d
} }
//export dotoARGB //export dotoARGB
func dotoARGB(img unsafe.Pointer, ppvBIts *C.VOID) { func dotoARGB(img unsafe.Pointer, ppvBIts unsafe.Pointer) {
i := (*image.RGBA)(unsafe.Pointer(img)) i := (*image.RGBA)(unsafe.Pointer(img))
// the bitmap Windows gives us has a stride == width // the bitmap Windows gives us has a stride == width
toARGB(i, unsafe.Pointer(ppvBits), i.Rect.Dx() * 4) toARGB(i, unsafe.Pointer(ppvBits), i.Rect.Dx() * 4)

View File

@ -33,6 +33,9 @@ func uiinit() error {
if err := makeContainerWindowClass(); err != nil { if err := makeContainerWindowClass(); err != nil {
return fmt.Errorf("error creating container window class: %v", err) return fmt.Errorf("error creating container window class: %v", err)
} }
if err := makeAreaWindowClass(); err != nil {
return fmt.Errorf("error creating Area window class: %v", err)
}
return nil return nil
} }