summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-07-17 23:45:12 -0400
committerPietro Gagliardi <[email protected]>2014-07-17 23:45:12 -0400
commit6a5a28d917015c9bca730f9ffd3748011fe3528d (patch)
tree5a4fba8c11bb6fdcaf5b69e792a3f6b1420e8d14
parentd8f302f15728ab6222310657e508cf4480080c79 (diff)
Migrated common_windows.go to C. Now to nuke unneeded files and fix compiler errors...
-rw-r--r--redo/common_windows.c36
-rw-r--r--redo/common_windows.go44
-rw-r--r--redo/controls_windows.go2
-rw-r--r--redo/winapi_windows.h7
-rw-r--r--redo/window_windows.go2
5 files changed, 49 insertions, 42 deletions
diff --git a/redo/common_windows.c b/redo/common_windows.c
new file mode 100644
index 0000000..6b9bf8c
--- /dev/null
+++ b/redo/common_windows.c
@@ -0,0 +1,36 @@
+// 17 july 2014
+
+#include "winapi_windows.h"
+
+LRESULT getWindowTextLen(HWND hwnd)
+{
+ return SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0);
+}
+
+void getWindowText(HWND hwnd, WPARAM n, LPCWSTR out)
+{
+ SetLastError(0);
+ if (SendMessageW(hwnd, WM_GETTEXT, n + 1, (LPARAM) buf) != n)
+ xpanic("WM_GETTEXT did not copy the correct number of characters out", GetLastError());
+}
+
+void setWindowText(HWND hwnd, LPCWSTR text)
+{
+ switch (SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM) text)) {
+ case FALSE:
+ xpanic("WM_SETTEXT failed", GetLastError());
+ }
+}
+
+void updateWindow(HWND hwnd)
+{
+ if (UpdateWindow(hwnd) == 0)
+ xpanic("error calling UpdateWindow()", GetLastError());
+}
+
+void storelpParam(HWND hwnd, LPARAM lParam)
+{
+ CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
+
+ SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (cs->lpCreateParams));
+}
diff --git a/redo/common_windows.go b/redo/common_windows.go
index b34a623..f8e39eb 100644
--- a/redo/common_windows.go
+++ b/redo/common_windows.go
@@ -21,52 +21,16 @@ func xmissedmsg(purpose *C.char, f *C.char, uMsg C.UINT) {
panic(fmt.Errorf("%s window procedure message %d does not return a value (bug in %s)", C.GoString(purpose), uMsg, C.GoString(f)))
}
-func toUINT16(s string) C.LPCWSTR {
+func toUTF16(s string) C.LPCWSTR {
return C.LPCWSTR(unsafe.Pointer(syscall.StringToUTF16(s)))
}
func getWindowText(hwnd uintptr) 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 := f_SendMessageW(hwnd, c_WM_GETTEXTLENGTH, 0, 0)
+ n := C.getWindowTextLen(hwnd, c_WM_GETTEXTLENGTH, 0, 0)
buf := make([]uint16, int(n + 1))
- if f_SendMessageW(hwnd, c_WM_GETTEXT,
- t_WPARAM(n + 1), t_LPARAM(uintptr(unsafe.Pointer(&buf[0])))) != n {
- panic(fmt.Errorf("WM_GETTEXT did not copy exactly %d characters out", n))
- }
+ C.getWindowText(hwnd, C.WPARAM(n),
+ C.LPCWSTR(unsafe.Pointer(&buf[0])))
return syscall.UTF16ToString(buf)
}
-
-func setWindowText(hwnd uintptr, text string, errors []t_LRESULT) {
- res := f_SendMessageW(hwnd, c_WM_SETTEXT,
- 0, t_LPARAM(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(text)))))
- for _, err := range errors {
- if res == err {
- panic(fmt.Errorf("WM_SETTEXT failed; error code %d", res))
- }
- }
-}
-
-func updateWindow(hwnd uintptr, caller string) {
- res, err := f_UpdateWindow(hwnd)
- if res == 0 {
- panic(fmt.Errorf("error calling UpdateWindow() from %s: %v", caller, err))
- }
-}
-
-func storelpParam(hwnd uintptr, lParam t_LPARAM) {
- var cs *s_CREATESTRUCTW
-
- cs = (*s_CREATESTRUCTW)(unsafe.Pointer(uintptr(lParam)))
- f_SetWindowLongPtrW(hwnd, c_GWLP_USERDATA, cs.lpCreateParams)
-}
-
-func (w t_WPARAM) HIWORD() uint16 {
- u := uintptr(w) & 0xFFFF0000
- return uint16(u >> 16)
-}
-
-func (w t_WPARAM) LOWORD() uint16 {
- u := uintptr(w) & 0x0000FFFF
- return uint16(u)
-}
diff --git a/redo/controls_windows.go b/redo/controls_windows.go
index 8f82eac..a553144 100644
--- a/redo/controls_windows.go
+++ b/redo/controls_windows.go
@@ -37,7 +37,7 @@ func (w *widgetbase) text() *Request {
c := make(chan interface{})
return &Request{
op: func() {
- c <- C.GoString(C.getWindowText(w.hwnd))
+ c <- getWindowText(w.hwnd)
},
resp: c,
}
diff --git a/redo/winapi_windows.h b/redo/winapi_windows.h
index 068cb13..3896c3b 100644
--- a/redo/winapi_windows.h
+++ b/redo/winapi_windows.h
@@ -56,3 +56,10 @@ extern void moveWindow(HWND, int, int, int, int);
extern DWORD makeWindowWindowClass(char **);
extern HWND newWindow(LPCWSTR, int, int, void *);
extern void windowClose(HWND);
+
+/* common_windows.c */
+extern LRESULT getWindowTextLen(HWND);
+extern void getWindowText(HWND, WPARAM, LPCWSTR);
+extern void setWindowText(HWND, LPCWSTR);
+extern void updateWindow(HWND);
+extern void storelpParam(HWND, LPARAM);
diff --git a/redo/window_windows.go b/redo/window_windows.go
index c670daa..7b1ff92 100644
--- a/redo/window_windows.go
+++ b/redo/window_windows.go
@@ -73,7 +73,7 @@ func (w *window) Title() *Request {
c := make(chan interface{})
return &Request{
op: func() {
- c <- C.GoString(C.getWindowText(w.hwnd))
+ c <- getWindowText(w.hwnd)
},
resp: c,
}