Fixed all the remaining compiler errors. C conversion works!

This commit is contained in:
Pietro Gagliardi 2014-07-18 00:22:21 -04:00
parent 7c6fa3b2fd
commit d2f09a0222
10 changed files with 32 additions and 37 deletions

View File

@ -5,6 +5,11 @@
static ULONG_PTR comctlManifestCookie; static ULONG_PTR comctlManifestCookie;
static HMODULE comctl32; 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) DWORD initCommonControls(LPCWSTR manifest, char **errmsg)
{ {
ACTCTX actctx; ACTCTX actctx;

View File

@ -9,6 +9,9 @@ import (
"unsafe" "unsafe"
) )
// #include "winapi_windows.h"
import "C"
// pretty much every constant here except _WM_USER is from commctrl.h, except where noted // pretty much every constant here except _WM_USER is from commctrl.h, except where noted
/* /*

View File

@ -22,13 +22,13 @@ func xmissedmsg(purpose *C.char, f *C.char, uMsg C.UINT) {
} }
func toUTF16(s string) C.LPCWSTR { 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 // 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 // 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)) buf := make([]uint16, int(n + 1))
C.getWindowText(hwnd, C.WPARAM(n), C.getWindowText(hwnd, C.WPARAM(n),
C.LPCWSTR(unsafe.Pointer(&buf[0]))) C.LPCWSTR(unsafe.Pointer(&buf[0])))

View File

@ -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.) also don't use low control IDs as they will conflict with dialog boxes (IDCANCEL, etc.)
*/ */
msgwin, (HMENU) 100, hInstance, NULL); msgwin, (HMENU) 100, hInstance, NULL);
if (hwnd == NULL) { if (hwnd == NULL)
xpanic("error creating control", GetLastError()); xpanic("error creating control", GetLastError());
return hwnd; return hwnd;
} }

View File

@ -3,8 +3,6 @@
package ui package ui
import ( import (
"fmt"
"syscall"
"unsafe" "unsafe"
) )
@ -15,7 +13,7 @@ type widgetbase struct {
hwnd C.HWND 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{ return &widgetbase{
hwnd: C.newWidget(class, style, extstyle), 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{}) c := make(chan interface{})
return &Request{ return &Request{
op: func() { op: func() {
@ -99,13 +97,6 @@ func (b *button) SetText(text string) *Request {
return b.settext(text) return b.settext(text)
} }
var buttonsubprocptr uintptr
// to avoid recursive initialization loop
func init() {
buttonsubprocptr = syscall.NewCallback(buttonSubProc)
}
//export buttonClicked //export buttonClicked
func buttonClicked(data unsafe.Pointer) { func buttonClicked(data unsafe.Pointer) {
b := (*button)(data) b := (*button)(data)

View File

@ -2,7 +2,7 @@
#include "winapi_windows.h" #include "winapi_windows.h"
HINSTANCE hInstnace; HINSTANCE hInstance;
int nCmdShow; int nCmdShow;
HICON hDefaultIcon; HICON hDefaultIcon;
@ -29,7 +29,7 @@ DWORD initWindows(char **errmsg)
*errmsg = "error loading default icon"; *errmsg = "error loading default icon";
return GetLastError(); return GetLastError();
} }
hDefaultCursor = LoadCursorW(NULL, IDC_ARROW); hArrowCursor = LoadCursorW(NULL, IDC_ARROW);
if (hArrowCursor == NULL) { if (hArrowCursor == NULL) {
*errmsg = "error loading arrow (default) cursor"; *errmsg = "error loading arrow (default) cursor";
return GetLastError(); return GetLastError();

View File

@ -2,10 +2,6 @@
package ui package ui
import (
"fmt"
)
// #include "winapi_windows.h" // #include "winapi_windows.h"
import "C" import "C"
@ -38,10 +34,10 @@ func (w *window) beginResize() (d *sizing) {
d.baseY = int(tm.tmHeight) d.baseY = int(tm.tmHeight)
if w.spaced { if w.spaced {
d.xmargin = int(C.MulDiv(marginDialogUnits, d.baseX, 4)) d.xmargin = int(C.MulDiv(marginDialogUnits, C.int(d.baseX), 4))
d.ymargin = int(C.MulDiv(marginDialogUnits, d.baseY, 8)) d.ymargin = int(C.MulDiv(marginDialogUnits, C.int(d.baseY), 8))
d.xpadding = int(C.MulDiv(paddingDialogUnits, d.baseX, 4)) d.xpadding = int(C.MulDiv(paddingDialogUnits, C.int(d.baseX), 4))
d.ypadding = int(C.MulDiv(paddingDialogUnits, d.baseY, 8)) d.ypadding = int(C.MulDiv(paddingDialogUnits, C.int(d.baseY), 8))
} }
return d return d
@ -75,11 +71,11 @@ func (w *widgetbase) commitResize(c *allocation, d *sizing) {
yoff = stdDlgSizes[s.ctype].yoffalt yoff = stdDlgSizes[s.ctype].yoffalt
} }
if yoff != 0 { 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.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) { func (w *widgetbase) getAuxResizeInfo(d *sizing) {
@ -185,8 +181,8 @@ func (w *widgetbase) preferredSize(d *sizing) (width int, height int) {
width = defaultWidth width = defaultWidth
} }
height = stdDlgSizes[s.ctype].height height = stdDlgSizes[s.ctype].height
width = f_MulDiv(width, d.baseX, 4) // equivalent to right of rect width = int(C.MulDiv(C.int(width), C.int(d.baseX), 4)) // equivalent to right of rect
height = f_MulDiv(height, d.baseY, 8) // equivalent to bottom of rect height = int(C.MulDiv(C.int(height), C.int(d.baseY), 8)) // equivalent to bottom of rect
*/ */
return width, height return width, height
} }

View File

@ -24,7 +24,7 @@ void uimsgloop(void)
void issue(void *request) void issue(void *request)
{ {
SetLastError(0); SetLastError(0);
if (PostMessageW(msgwin, msgRequested, 0, (LPARAM) request) == 0) if (PostMessageW(msgwin, msgRequest, 0, (LPARAM) request) == 0)
xpanic("error issuing request", GetLastError()); xpanic("error issuing request", GetLastError());
} }
@ -37,7 +37,7 @@ static LRESULT CALLBACK msgwinproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
switch (uMsg) { switch (uMsg) {
case WM_COMMAND: case WM_COMMAND:
return forwardCommand(hwnd, uMsg, wParam, lParam); return forwardCommand(hwnd, uMsg, wParam, lParam);
case msgRequested: case msgRequest:
xperform((void *) lParam); xperform((void *) lParam);
return 0; return 0;
default: default:

View File

@ -38,7 +38,7 @@ func uimsgloop() {
} }
func uistop() { func uistop() {
f_PostQuitMessage(0) C.PostQuitMessage(0)
} }
func issue(req *Request) { func issue(req *Request) {

View File

@ -4,7 +4,7 @@
#define windowclass L"gouiwindow" #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; void *data;
RECT r; RECT r;
@ -23,10 +23,10 @@ static LRESULT CALLBACK windowWinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARA
switch (uMsg) { switch (uMsg) {
case WM_COMMAND: case WM_COMMAND:
return forwardCommand(hwnd, msg, wParam, lParam) return forwardCommand(hwnd, uMsg, wParam, lParam);
case WM_SIZE: case WM_SIZE:
if (GetClientRect(hwnd, &r) == 0) 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); windowResize(data, &r);
return 0; return 0;
case WM_CLOSE: case WM_CLOSE:
@ -67,9 +67,9 @@ HWND newWindow(LPCWSTR title, int width, int height, void *data)
WS_OVERLAPPEDWINDOW, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
width, height, width, height,
NULL, NULL, hInstance, w); NULL, NULL, hInstance, data);
if (hwnd == NULL) if (hwnd == NULL)
xpanic("Window creation failed", GetLastError(); xpanic("Window creation failed", GetLastError());
return hwnd; return hwnd;
} }