diff --git a/redo/comctl32_windows.c b/redo/comctl32_windows.c index a6ffaf1..ede4c0c 100644 --- a/redo/comctl32_windows.c +++ b/redo/comctl32_windows.c @@ -5,6 +5,11 @@ static ULONG_PTR comctlManifestCookie; static HMODULE comctl32; +/* TODO do any of these take WINAPI? */ +BOOL (*WINAPI fv_SetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR); +BOOL (*WINAPI fv_RemoveWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR); +LRESULT (*WINAPI fv_DefSubclassProc)(HWND, UINT, WPARAM, LPARAM); + DWORD initCommonControls(LPCWSTR manifest, char **errmsg) { ACTCTX actctx; diff --git a/redo/comctl32_windows.go b/redo/comctl32_windows.go index a28da69..55ba49f 100644 --- a/redo/comctl32_windows.go +++ b/redo/comctl32_windows.go @@ -9,6 +9,9 @@ import ( "unsafe" ) +// #include "winapi_windows.h" +import "C" + // pretty much every constant here except _WM_USER is from commctrl.h, except where noted /* diff --git a/redo/common_windows.go b/redo/common_windows.go index 77a2b99..a80ee2e 100644 --- a/redo/common_windows.go +++ b/redo/common_windows.go @@ -22,13 +22,13 @@ func xmissedmsg(purpose *C.char, f *C.char, uMsg C.UINT) { } func toUTF16(s string) C.LPCWSTR { - return C.LPCWSTR(unsafe.Pointer(syscall.StringToUTF16(s))) + return C.LPCWSTR(unsafe.Pointer(syscall.StringToUTF16Ptr(s))) } -func getWindowText(hwnd uintptr) string { +func getWindowText(hwnd C.HWND) string { // WM_GETTEXTLENGTH and WM_GETTEXT return the count /without/ the terminating null character // but WM_GETTEXT expects the buffer size handed to it to /include/ the terminating null character - n := C.getWindowTextLen(hwnd, c_WM_GETTEXTLENGTH, 0, 0) + n := C.getWindowTextLen(hwnd) buf := make([]uint16, int(n + 1)) C.getWindowText(hwnd, C.WPARAM(n), C.LPCWSTR(unsafe.Pointer(&buf[0]))) diff --git a/redo/controls_windows.c b/redo/controls_windows.c index dadce75..77cf758 100644 --- a/redo/controls_windows.c +++ b/redo/controls_windows.c @@ -19,7 +19,7 @@ HWND newWidget(LPCWSTR class, DWORD style, DWORD extstyle) also don't use low control IDs as they will conflict with dialog boxes (IDCANCEL, etc.) */ msgwin, (HMENU) 100, hInstance, NULL); - if (hwnd == NULL) { + if (hwnd == NULL) xpanic("error creating control", GetLastError()); return hwnd; } diff --git a/redo/controls_windows.go b/redo/controls_windows.go index a553144..ec2f827 100644 --- a/redo/controls_windows.go +++ b/redo/controls_windows.go @@ -3,8 +3,6 @@ package ui import ( - "fmt" - "syscall" "unsafe" ) @@ -15,7 +13,7 @@ type widgetbase struct { hwnd C.HWND } -func newWidget(class C.LPCWSTR, style uintptr, extstyle uintptr) *widgetbase { +func newWidget(class C.LPCWSTR, style C.DWORD, extstyle C.DWORD) *widgetbase { return &widgetbase{ hwnd: C.newWidget(class, style, extstyle), } @@ -43,7 +41,7 @@ func (w *widgetbase) text() *Request { } } -func (w *widgetbase) settext(text string, results ...t_LRESULT) *Request { +func (w *widgetbase) settext(text string) *Request { c := make(chan interface{}) return &Request{ op: func() { @@ -99,13 +97,6 @@ func (b *button) SetText(text string) *Request { return b.settext(text) } -var buttonsubprocptr uintptr - -// to avoid recursive initialization loop -func init() { - buttonsubprocptr = syscall.NewCallback(buttonSubProc) -} - //export buttonClicked func buttonClicked(data unsafe.Pointer) { b := (*button)(data) diff --git a/redo/init_windows.c b/redo/init_windows.c index ad3124c..d3771e0 100644 --- a/redo/init_windows.c +++ b/redo/init_windows.c @@ -2,7 +2,7 @@ #include "winapi_windows.h" -HINSTANCE hInstnace; +HINSTANCE hInstance; int nCmdShow; HICON hDefaultIcon; @@ -29,7 +29,7 @@ DWORD initWindows(char **errmsg) *errmsg = "error loading default icon"; return GetLastError(); } - hDefaultCursor = LoadCursorW(NULL, IDC_ARROW); + hArrowCursor = LoadCursorW(NULL, IDC_ARROW); if (hArrowCursor == NULL) { *errmsg = "error loading arrow (default) cursor"; return GetLastError(); diff --git a/redo/sizing_windows.go b/redo/sizing_windows.go index ede3101..d0c3937 100644 --- a/redo/sizing_windows.go +++ b/redo/sizing_windows.go @@ -2,10 +2,6 @@ package ui -import ( - "fmt" -) - // #include "winapi_windows.h" import "C" @@ -38,10 +34,10 @@ func (w *window) beginResize() (d *sizing) { d.baseY = int(tm.tmHeight) if w.spaced { - d.xmargin = int(C.MulDiv(marginDialogUnits, d.baseX, 4)) - d.ymargin = int(C.MulDiv(marginDialogUnits, d.baseY, 8)) - d.xpadding = int(C.MulDiv(paddingDialogUnits, d.baseX, 4)) - d.ypadding = int(C.MulDiv(paddingDialogUnits, d.baseY, 8)) + d.xmargin = int(C.MulDiv(marginDialogUnits, C.int(d.baseX), 4)) + d.ymargin = int(C.MulDiv(marginDialogUnits, C.int(d.baseY), 8)) + d.xpadding = int(C.MulDiv(paddingDialogUnits, C.int(d.baseX), 4)) + d.ypadding = int(C.MulDiv(paddingDialogUnits, C.int(d.baseY), 8)) } return d @@ -75,11 +71,11 @@ func (w *widgetbase) commitResize(c *allocation, d *sizing) { yoff = stdDlgSizes[s.ctype].yoffalt } if yoff != 0 { - yoff = int(C.MulDiv(yoff, d.baseY, 8)) + yoff = int(C.MulDiv(C.int(yoff), C.int(d.baseY), 8)) } c.y += yoff */ - C.moveWindow(w.hwnd, int(c.x), int(c.y), int(c.width), int(c.height)) + C.moveWindow(w.hwnd, C.int(c.x), C.int(c.y), C.int(c.width), C.int(c.height)) } func (w *widgetbase) getAuxResizeInfo(d *sizing) { @@ -185,8 +181,8 @@ func (w *widgetbase) preferredSize(d *sizing) (width int, height int) { width = defaultWidth } height = stdDlgSizes[s.ctype].height - width = f_MulDiv(width, d.baseX, 4) // equivalent to right of rect - height = f_MulDiv(height, d.baseY, 8) // equivalent to bottom of rect + width = int(C.MulDiv(C.int(width), C.int(d.baseX), 4)) // equivalent to right of rect + height = int(C.MulDiv(C.int(height), C.int(d.baseY), 8)) // equivalent to bottom of rect */ return width, height } diff --git a/redo/uitask_windows.c b/redo/uitask_windows.c index 11ce412..291ef3b 100644 --- a/redo/uitask_windows.c +++ b/redo/uitask_windows.c @@ -24,7 +24,7 @@ void uimsgloop(void) void issue(void *request) { SetLastError(0); - if (PostMessageW(msgwin, msgRequested, 0, (LPARAM) request) == 0) + if (PostMessageW(msgwin, msgRequest, 0, (LPARAM) request) == 0) xpanic("error issuing request", GetLastError()); } @@ -37,7 +37,7 @@ static LRESULT CALLBACK msgwinproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l switch (uMsg) { case WM_COMMAND: return forwardCommand(hwnd, uMsg, wParam, lParam); - case msgRequested: + case msgRequest: xperform((void *) lParam); return 0; default: diff --git a/redo/uitask_windows.go b/redo/uitask_windows.go index ccb3fdb..3cb5012 100644 --- a/redo/uitask_windows.go +++ b/redo/uitask_windows.go @@ -38,7 +38,7 @@ func uimsgloop() { } func uistop() { - f_PostQuitMessage(0) + C.PostQuitMessage(0) } func issue(req *Request) { diff --git a/redo/window_windows.c b/redo/window_windows.c index 5b45840..02eaddd 100644 --- a/redo/window_windows.c +++ b/redo/window_windows.c @@ -4,7 +4,7 @@ #define windowclass L"gouiwindow" -static LRESULT CALLBACK windowWinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { void *data; RECT r; @@ -23,10 +23,10 @@ static LRESULT CALLBACK windowWinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARA switch (uMsg) { case WM_COMMAND: - return forwardCommand(hwnd, msg, wParam, lParam) + return forwardCommand(hwnd, uMsg, wParam, lParam); case WM_SIZE: if (GetClientRect(hwnd, &r) == 0) - xparent("error getting client rect for Window in WM_SIZE", GetLastError()); + xpanic("error getting client rect for Window in WM_SIZE", GetLastError()); windowResize(data, &r); return 0; case WM_CLOSE: @@ -67,9 +67,9 @@ HWND newWindow(LPCWSTR title, int width, int height, void *data) WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, width, height, - NULL, NULL, hInstance, w); + NULL, NULL, hInstance, data); if (hwnd == NULL) - xpanic("Window creation failed", GetLastError(); + xpanic("Window creation failed", GetLastError()); return hwnd; }