summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-05-25 11:31:57 -0400
committerPietro Gagliardi <[email protected]>2014-05-25 11:31:57 -0400
commiteb0188a0999b7a7c1746b06a6c22e147cf3f1ac6 (patch)
treee16c9021de42396061f3c01bf7205aa62f039b09
parent0d23bda925359ae6d240b25f20dc544207ce8106 (diff)
Changed most instances of var to const in the Windows code. Only one left...
-rw-r--r--comctl_windows.go6
-rw-r--r--common_windows.go6
-rw-r--r--controls_windows.go4
-rw-r--r--sysdata_windows.go24
-rw-r--r--uitask_windows.go6
-rw-r--r--windows_windows.go10
6 files changed, 27 insertions, 29 deletions
diff --git a/comctl_windows.go b/comctl_windows.go
index ea26704..ffef7c7 100644
--- a/comctl_windows.go
+++ b/comctl_windows.go
@@ -50,8 +50,8 @@ References:
- http://support.microsoft.com/kb/830033
*/
func forceCommonControls6() (err error) {
- var (
- // from winbase.h; var because Go won't let me convert this constant
+ const (
+ // from winbase.h
_INVALID_HANDLE_VALUE = -1
)
@@ -85,7 +85,7 @@ func forceCommonControls6() (err error) {
actctx.lpSource = syscall.StringToUTF16Ptr(filename)
r1, _, err := _createActCtx.Call(uintptr(unsafe.Pointer(&actctx)))
- if r1 == uintptr(_INVALID_HANDLE_VALUE) { // failure
+ if r1 == negConst(_INVALID_HANDLE_VALUE) { // failure
return fmt.Errorf("error creating activation context for synthesized manifest file: %v", err)
}
r1, _, err = _activateActCtx.Call(
diff --git a/common_windows.go b/common_windows.go
index 85dce45..f9289cb 100644
--- a/common_windows.go
+++ b/common_windows.go
@@ -76,6 +76,12 @@ type _RECT struct {
bottom int32
}
+// Go doesn't allow negative constants to be forced into unsigned types at compile-time; this will do it at runtime.
+// TODO make sure sign extension works fine here (check Go's rules and ABI sign extension rules)
+func negConst(c int) uintptr {
+ return uintptr(c)
+}
+
// Predefined cursor resource IDs.
const (
_IDC_APPSTARTING = 32650
diff --git a/controls_windows.go b/controls_windows.go
index 991e879..86c4eba 100644
--- a/controls_windows.go
+++ b/controls_windows.go
@@ -179,7 +179,7 @@ const (
)
// Combobox errors.
-var ( // var so they can be cast to uintptr
+const (
// from winuser.h
_CB_ERR = (-1)
_CB_ERRSPACE = (-2)
@@ -356,7 +356,7 @@ const (
)
// Listbox errors.
-var ( // var so they can be cast to uintptr
+const (
// from winuser.h
_LB_OKAY = 0
_LB_ERR = (-1)
diff --git a/sysdata_windows.go b/sysdata_windows.go
index 1e02936..aaa3332 100644
--- a/sysdata_windows.go
+++ b/sysdata_windows.go
@@ -35,8 +35,8 @@ type classData struct {
insertBeforeMsg uintptr
deleteMsg uintptr
selectedIndexMsg uintptr
- selectedIndexErr int
- addSpaceErr int
+ selectedIndexErr uintptr
+ addSpaceErr uintptr
lenMsg uintptr
}
@@ -69,8 +69,8 @@ var classTypes = [nctypes]*classData{
insertBeforeMsg: _CB_INSERTSTRING,
deleteMsg: _CB_DELETESTRING,
selectedIndexMsg: _CB_GETCURSEL,
- selectedIndexErr: _CB_ERR,
- addSpaceErr: _CB_ERRSPACE,
+ selectedIndexErr: negConst(_CB_ERR),
+ addSpaceErr: negConst(_CB_ERRSPACE),
lenMsg: _CB_GETCOUNT,
},
c_lineedit: &classData{
@@ -100,8 +100,8 @@ var classTypes = [nctypes]*classData{
insertBeforeMsg: _LB_INSERTSTRING,
deleteMsg: _LB_DELETESTRING,
selectedIndexMsg: _LB_GETCURSEL,
- selectedIndexErr: _LB_ERR,
- addSpaceErr: _LB_ERRSPACE,
+ selectedIndexErr: negConst(_LB_ERR),
+ addSpaceErr: negConst(_LB_ERRSPACE),
lenMsg: _LB_GETCOUNT,
},
c_progressbar: &classData{
@@ -422,7 +422,7 @@ func (s *sysData) selectedIndices() []int {
ret: ret,
}
r := <-ret
- if r.ret == uintptr(_LB_ERR) {
+ if r.ret == negConst(_LB_ERR) {
panic("UI library internal error: LB_ERR from LB_GETSELCOUNT in what we know is a multi-selection listbox")
}
if r.ret == 0 { // nothing selected
@@ -440,7 +440,7 @@ func (s *sysData) selectedIndices() []int {
ret: ret,
}
r = <-ret
- if r.ret == uintptr(_LB_ERR) {
+ if r.ret == negConst(_LB_ERR) {
panic("UI library internal error: LB_ERR from LB_GETSELITEMS in what we know is a multi-selection listbox")
}
return indices
@@ -463,7 +463,7 @@ func (s *sysData) selectedTexts() []string {
ret: ret,
}
r := <-ret
- if r.ret == uintptr(_LB_ERR) {
+ if r.ret == negConst(_LB_ERR) {
panic("UI library internal error: LB_ERR from LB_GETTEXTLEN in what we know is a valid listbox index (came from LB_GETSELITEMS)")
}
str := make([]uint16, r.ret)
@@ -478,7 +478,7 @@ func (s *sysData) selectedTexts() []string {
ret: ret,
}
r = <-ret
- if r.ret == uintptr(_LB_ERR) {
+ if r.ret == negConst(_LB_ERR) {
panic("UI library internal error: LB_ERR from LB_GETTEXT in what we know is a valid listbox index (came from LB_GETSELITEMS)")
}
strings[i] = syscall.UTF16ToString(str)
@@ -537,7 +537,7 @@ func (s *sysData) setIndeterminate() {
call: _setWindowLong,
p: []uintptr{
uintptr(s.hwnd),
- uintptr(_GWL_STYLE),
+ negConst(_GWL_STYLE),
uintptr(classTypes[s.ctype].style | _PBS_MARQUEE),
},
ret: ret,
@@ -584,7 +584,7 @@ func (s *sysData) setProgress(percent int) {
call: _setWindowLong,
p: []uintptr{
uintptr(s.hwnd),
- uintptr(_GWL_STYLE),
+ negConst(_GWL_STYLE),
uintptr(classTypes[s.ctype].style),
},
ret: ret,
diff --git a/uitask_windows.go b/uitask_windows.go
index db9aa24..621c1fc 100644
--- a/uitask_windows.go
+++ b/uitask_windows.go
@@ -133,8 +133,8 @@ const (
msghandlerclass = "gomsghandler"
)
-var (
- // fron winuser.h; var because Go won't let me
+const (
+ // fron winuser.h
_HWND_MESSAGE = -3
)
@@ -162,7 +162,7 @@ func makeMessageHandler() (hwnd _HWND, err error) {
uintptr(_CW_USEDEFAULT),
uintptr(_CW_USEDEFAULT),
uintptr(_CW_USEDEFAULT),
- uintptr(_HWND_MESSAGE),
+ negConst(_HWND_MESSAGE),
uintptr(_NULL),
uintptr(hInstance),
uintptr(_NULL))
diff --git a/windows_windows.go b/windows_windows.go
index ea848f9..5012170 100644
--- a/windows_windows.go
+++ b/windows_windows.go
@@ -121,14 +121,6 @@ const (
_HWND_TOP = _HWND(0)
)
-// SetWindowPos hWndInsertAfter values that Go won't allow as constants.
-var (
- __HWND_NOTOPMOST = -2
- _HWND_NOTOPMOST = _HWND(__HWND_NOTOPMOST)
- __HWND_TOPMOST = -1
- _HWND_TOPMOST = _HWND(__HWND_TOPMOST)
-)
-
// SetWindowPos uFlags values.
const (
_SWP_DRAWFRAME = 0x0020
@@ -244,7 +236,7 @@ const (
)
// WM_STYLECHANGED and WM_STYLECHANGING values (wParam).
-var ( // var because Go won't let me cast a negative const to a uintptr
+const (
_GWL_EXSTYLE = -20
_GWL_STYLE = -16
)