Migrated sysdata_windows.go to the new API. Also more TODOs.
This commit is contained in:
parent
a894c3fc6d
commit
2e7f3d299e
|
@ -148,9 +148,6 @@ var (
|
|||
)
|
||||
|
||||
func (s *sysData) make(window *sysData) (err error) {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
ct := classTypes[s.ctype]
|
||||
cid := _HMENU(0)
|
||||
pwin := uintptr(_NULL)
|
||||
|
@ -197,9 +194,6 @@ func (s *sysData) make(window *sysData) (err error) {
|
|||
uintptr(_WPARAM(controlFont)),
|
||||
uintptr(_LPARAM(_TRUE)))
|
||||
}
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -211,9 +205,6 @@ var (
|
|||
// ShowWindow(hwnd, nCmdShow);
|
||||
// UpdateWindow(hwnd);
|
||||
func (s *sysData) firstShow() error {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
_showWindow.Call(
|
||||
uintptr(s.hwnd),
|
||||
uintptr(nCmdShow))
|
||||
|
@ -221,40 +212,22 @@ func (s *sysData) firstShow() error {
|
|||
if r1 == 0 { // failure
|
||||
panic(fmt.Errorf("error updating window for the first time: %v", err))
|
||||
}
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *sysData) show() {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
_showWindow.Call(
|
||||
uintptr(s.hwnd),
|
||||
uintptr(_SW_SHOW))
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
}
|
||||
|
||||
func (s *sysData) hide() {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
_showWindow.Call(
|
||||
uintptr(s.hwnd),
|
||||
uintptr(_SW_HIDE))
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
}
|
||||
|
||||
func (s *sysData) setText(text string) {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
ptext := toUTF16(text)
|
||||
r1, _, err := _setWindowText.Call(
|
||||
uintptr(s.hwnd),
|
||||
|
@ -262,12 +235,8 @@ func (s *sysData) setText(text string) {
|
|||
if r1 == 0 { // failure
|
||||
panic(fmt.Errorf("error setting window/control text: %v", err))
|
||||
}
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
}
|
||||
|
||||
// runs on uitask
|
||||
func (s *sysData) setRect(x int, y int, width int, height int, winheight int) error {
|
||||
r1, _, err := _moveWindow.Call(
|
||||
uintptr(s.hwnd),
|
||||
|
@ -283,23 +252,15 @@ func (s *sysData) setRect(x int, y int, width int, height int, winheight int) er
|
|||
}
|
||||
|
||||
func (s *sysData) isChecked() bool {
|
||||
ret := make(chan bool)
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
r1, _, _ := _sendMessage.Call(
|
||||
uintptr(s.hwnd),
|
||||
uintptr(_BM_GETCHECK),
|
||||
uintptr(0),
|
||||
uintptr(0))
|
||||
ret <- r1 == _BST_CHECKED
|
||||
}
|
||||
return <-ret
|
||||
return r1 == _BST_CHECKED
|
||||
}
|
||||
|
||||
func (s *sysData) text() (str string) {
|
||||
ret := make(chan string)
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
var tc []uint16
|
||||
|
||||
r1, _, _ := _sendMessage.Call(
|
||||
|
@ -314,15 +275,10 @@ func (s *sysData) text() (str string) {
|
|||
uintptr(_WM_GETTEXT),
|
||||
uintptr(_WPARAM(length)),
|
||||
uintptr(_LPARAM(unsafe.Pointer(&tc[0]))))
|
||||
ret <- syscall.UTF16ToString(tc)
|
||||
}
|
||||
return <-ret
|
||||
return syscall.UTF16ToString(tc)
|
||||
}
|
||||
|
||||
func (s *sysData) append(what string) {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
pwhat := toUTF16(what)
|
||||
r1, _, err := _sendMessage.Call(
|
||||
uintptr(s.hwnd),
|
||||
|
@ -334,15 +290,9 @@ func (s *sysData) append(what string) {
|
|||
} else if r1 == uintptr(classTypes[s.ctype].selectedIndexErr) {
|
||||
panic(fmt.Errorf("failed to add item to combobox/listbox (last error: %v)", err))
|
||||
}
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
}
|
||||
|
||||
func (s *sysData) insertBefore(what string, index int) {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
pwhat := toUTF16(what)
|
||||
r1, _, err := _sendMessage.Call(
|
||||
uintptr(s.hwnd),
|
||||
|
@ -354,13 +304,9 @@ func (s *sysData) insertBefore(what string, index int) {
|
|||
} else if r1 == uintptr(classTypes[s.ctype].selectedIndexErr) {
|
||||
panic(fmt.Errorf("failed to add item to combobox/listbox (last error: %v)", err))
|
||||
}
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
}
|
||||
|
||||
// runs on uitask
|
||||
func (s *sysData) doSelectedIndex() int {
|
||||
func (s *sysData) selectedIndex() int {
|
||||
r1, _, _ := _sendMessage.Call(
|
||||
uintptr(s.hwnd),
|
||||
uintptr(classTypes[s.ctype].selectedIndexMsg),
|
||||
|
@ -372,19 +318,9 @@ func (s *sysData) doSelectedIndex() int {
|
|||
return int(r1)
|
||||
}
|
||||
|
||||
func (s *sysData) selectedIndex() int {
|
||||
ret := make(chan int)
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
ret <- s.doSelectedIndex()
|
||||
}
|
||||
return <-ret
|
||||
}
|
||||
|
||||
// runs on uitask
|
||||
func (s *sysData) doSelectedIndices() []int {
|
||||
func (s *sysData) selectedIndices() []int {
|
||||
if !s.alternate { // single-selection list box; use single-selection method
|
||||
index := s.doSelectedIndex()
|
||||
index := s.selectedIndex()
|
||||
if index == -1 {
|
||||
return nil
|
||||
}
|
||||
|
@ -414,20 +350,8 @@ func (s *sysData) doSelectedIndices() []int {
|
|||
return indices
|
||||
}
|
||||
|
||||
func (s *sysData) selectedIndices() []int {
|
||||
ret := make(chan []int)
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
ret <- s.doSelectedIndices()
|
||||
}
|
||||
return <-ret
|
||||
}
|
||||
|
||||
func (s *sysData) selectedTexts() []string {
|
||||
ret := make(chan []string)
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
indices := s.doSelectedIndices()
|
||||
indices := s.selectedIndices()
|
||||
strings := make([]string, len(indices))
|
||||
for i, v := range indices {
|
||||
r1, _, err := _sendMessage.Call(
|
||||
|
@ -449,15 +373,10 @@ func (s *sysData) selectedTexts() []string {
|
|||
}
|
||||
strings[i] = syscall.UTF16ToString(str)
|
||||
}
|
||||
ret <- strings
|
||||
}
|
||||
return <-ret
|
||||
return strings
|
||||
}
|
||||
|
||||
func (s *sysData) setWindowSize(width int, height int) error {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
var rect _RECT
|
||||
|
||||
r1, _, err := _getClientRect.Call(
|
||||
|
@ -472,16 +391,9 @@ func (s *sysData) setWindowSize(width int, height int) error {
|
|||
if err != nil {
|
||||
panic(fmt.Errorf("error actually resizing window: %v", err))
|
||||
}
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *sysData) delete(index int) {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
r1, _, err := _sendMessage.Call(
|
||||
uintptr(s.hwnd),
|
||||
uintptr(classTypes[s.ctype].deleteMsg),
|
||||
|
@ -490,15 +402,9 @@ func (s *sysData) delete(index int) {
|
|||
if r1 == uintptr(classTypes[s.ctype].selectedIndexErr) {
|
||||
panic(fmt.Errorf("failed to delete item from combobox/listbox (last error: %v)", err))
|
||||
}
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
}
|
||||
|
||||
func (s *sysData) setIndeterminate() {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
r1, _, err := _setWindowLongPtr.Call(
|
||||
uintptr(s.hwnd),
|
||||
negConst(_GWL_STYLE),
|
||||
|
@ -512,9 +418,6 @@ func (s *sysData) setIndeterminate() {
|
|||
uintptr(_WPARAM(_TRUE)),
|
||||
uintptr(0))
|
||||
s.isMarquee = true
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
}
|
||||
|
||||
func (s *sysData) setProgress(percent int) {
|
||||
|
@ -522,9 +425,6 @@ func (s *sysData) setProgress(percent int) {
|
|||
s.setIndeterminate()
|
||||
return
|
||||
}
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
if s.isMarquee {
|
||||
// turn off marquee before switching back
|
||||
_sendMessage.Call(
|
||||
|
@ -560,15 +460,9 @@ func (s *sysData) setProgress(percent int) {
|
|||
if percent == 100 {
|
||||
send(_PBM_SETRANGE32, 0, 100)
|
||||
}
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
}
|
||||
|
||||
func (s *sysData) len() int {
|
||||
ret := make(chan int)
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
r1, _, err := _sendMessage.Call(
|
||||
uintptr(s.hwnd),
|
||||
uintptr(classTypes[s.ctype].lenMsg),
|
||||
|
@ -577,43 +471,26 @@ func (s *sysData) len() int {
|
|||
if r1 == uintptr(classTypes[s.ctype].selectedIndexErr) {
|
||||
panic(fmt.Errorf("unexpected error return from sysData.len(); GetLastError() says %v", err))
|
||||
}
|
||||
ret <- int(r1)
|
||||
}
|
||||
return <-ret
|
||||
return int(r1)
|
||||
}
|
||||
|
||||
func (s *sysData) setAreaSize(width int, height int) {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
_sendMessage.Call(
|
||||
uintptr(s.hwnd),
|
||||
uintptr(msgSetAreaSize),
|
||||
uintptr(width), // WPARAM is UINT_PTR on Windows XP and newer at least, so we're good with this
|
||||
uintptr(height))
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
}
|
||||
|
||||
func (s *sysData) repaintAll() {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
_sendMessage.Call(
|
||||
uintptr(s.hwnd),
|
||||
uintptr(msgRepaintAll),
|
||||
uintptr(0),
|
||||
uintptr(0))
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
}
|
||||
|
||||
func (s *sysData) center() {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
var ws _RECT
|
||||
|
||||
r1, _, err := _getWindowRect.Call(
|
||||
|
@ -624,6 +501,7 @@ func (s *sysData) center() {
|
|||
}
|
||||
// TODO should this be using the monitor functions instead? http://blogs.msdn.com/b/oldnewthing/archive/2005/05/05/414910.aspx
|
||||
// error returns from GetSystemMetrics() is meaningless because the return value, 0, is still valid
|
||||
// TODO should this be using the client rect and not the window rect?
|
||||
dw, _, _ := _getSystemMetrics.Call(uintptr(_SM_CXFULLSCREEN))
|
||||
dh, _, _ := _getSystemMetrics.Call(uintptr(_SM_CYFULLSCREEN))
|
||||
ww := ws.right - ws.left
|
||||
|
@ -631,15 +509,9 @@ func (s *sysData) center() {
|
|||
wx := (int32(dw) / 2) - (ww / 2)
|
||||
wy := (int32(dh) / 2) - (wh / 2)
|
||||
s.setRect(int(wx), int(wy), int(ww), int(wh), 0)
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
}
|
||||
|
||||
func (s *sysData) setChecked(checked bool) {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
c := uintptr(_BST_CHECKED)
|
||||
if !checked {
|
||||
c = uintptr(_BST_UNCHECKED)
|
||||
|
@ -649,7 +521,4 @@ func (s *sysData) setChecked(checked bool) {
|
|||
uintptr(_BM_SETCHECK),
|
||||
c,
|
||||
uintptr(0))
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue