Migrated sysdata_windows.go to the new API. Also more TODOs.

This commit is contained in:
Pietro Gagliardi 2014-06-28 02:55:15 -04:00
parent a894c3fc6d
commit 2e7f3d299e
1 changed files with 233 additions and 364 deletions

View File

@ -148,58 +148,52 @@ var (
) )
func (s *sysData) make(window *sysData) (err error) { func (s *sysData) make(window *sysData) (err error) {
ret := make(chan struct{}) ct := classTypes[s.ctype]
defer close(ret) cid := _HMENU(0)
uitask <- func() { pwin := uintptr(_NULL)
ct := classTypes[s.ctype] if window != nil { // this is a child control
cid := _HMENU(0) cid = window.addChild(s)
pwin := uintptr(_NULL) pwin = uintptr(window.hwnd)
if window != nil { // this is a child control }
cid = window.addChild(s) style := uintptr(ct.style)
pwin = uintptr(window.hwnd) if s.alternate {
} style = uintptr(ct.altStyle)
style := uintptr(ct.style) }
if s.alternate { lpParam := uintptr(_NULL)
style = uintptr(ct.altStyle) if ct.storeSysData {
} lpParam = uintptr(unsafe.Pointer(s))
lpParam := uintptr(_NULL) }
if ct.storeSysData { r1, _, err := _createWindowEx.Call(
lpParam = uintptr(unsafe.Pointer(s)) uintptr(ct.xstyle),
} utf16ToArg(ct.name),
r1, _, err := _createWindowEx.Call( blankString, // we set the window text later
uintptr(ct.xstyle), style,
utf16ToArg(ct.name), negConst(_CW_USEDEFAULT),
blankString, // we set the window text later negConst(_CW_USEDEFAULT),
style, negConst(_CW_USEDEFAULT),
negConst(_CW_USEDEFAULT), negConst(_CW_USEDEFAULT),
negConst(_CW_USEDEFAULT), pwin,
negConst(_CW_USEDEFAULT), uintptr(cid),
negConst(_CW_USEDEFAULT), uintptr(hInstance),
pwin, lpParam)
uintptr(cid), if r1 == 0 { // failure
uintptr(hInstance), if window != nil {
lpParam) window.delChild(cid)
if r1 == 0 { // failure }
if window != nil { panic(fmt.Errorf("error actually creating window/control: %v", err))
window.delChild(cid) }
} if !ct.storeSysData { // regular control; store s.hwnd ourselves
panic(fmt.Errorf("error actually creating window/control: %v", err)) s.hwnd = _HWND(r1)
} } else if s.hwnd != _HWND(r1) { // we store sysData in storeSysData(); sanity check
if !ct.storeSysData { // regular control; store s.hwnd ourselves panic(fmt.Errorf("hwnd mismatch creating window/control: storeSysData() stored 0x%X but CreateWindowEx() returned 0x%X", s.hwnd, r1))
s.hwnd = _HWND(r1) }
} else if s.hwnd != _HWND(r1) { // we store sysData in storeSysData(); sanity check if !ct.doNotLoadFont {
panic(fmt.Errorf("hwnd mismatch creating window/control: storeSysData() stored 0x%X but CreateWindowEx() returned 0x%X", s.hwnd, r1)) _sendMessage.Call(
} uintptr(s.hwnd),
if !ct.doNotLoadFont { uintptr(_WM_SETFONT),
_sendMessage.Call( uintptr(_WPARAM(controlFont)),
uintptr(s.hwnd), uintptr(_LPARAM(_TRUE)))
uintptr(_WM_SETFONT),
uintptr(_WPARAM(controlFont)),
uintptr(_LPARAM(_TRUE)))
}
ret <- struct{}{}
} }
<-ret
return nil return nil
} }
@ -211,63 +205,38 @@ var (
// ShowWindow(hwnd, nCmdShow); // ShowWindow(hwnd, nCmdShow);
// UpdateWindow(hwnd); // UpdateWindow(hwnd);
func (s *sysData) firstShow() error { func (s *sysData) firstShow() error {
ret := make(chan struct{}) _showWindow.Call(
defer close(ret) uintptr(s.hwnd),
uitask <- func() { uintptr(nCmdShow))
_showWindow.Call( r1, _, err := _updateWindow.Call(uintptr(s.hwnd))
uintptr(s.hwnd), if r1 == 0 { // failure
uintptr(nCmdShow)) panic(fmt.Errorf("error updating window for the first time: %v", err))
r1, _, err := _updateWindow.Call(uintptr(s.hwnd))
if r1 == 0 { // failure
panic(fmt.Errorf("error updating window for the first time: %v", err))
}
ret <- struct{}{}
} }
<-ret
return nil return nil
} }
func (s *sysData) show() { func (s *sysData) show() {
ret := make(chan struct{}) _showWindow.Call(
defer close(ret) uintptr(s.hwnd),
uitask <- func() { uintptr(_SW_SHOW))
_showWindow.Call(
uintptr(s.hwnd),
uintptr(_SW_SHOW))
ret <- struct{}{}
}
<-ret
} }
func (s *sysData) hide() { func (s *sysData) hide() {
ret := make(chan struct{}) _showWindow.Call(
defer close(ret) uintptr(s.hwnd),
uitask <- func() { uintptr(_SW_HIDE))
_showWindow.Call(
uintptr(s.hwnd),
uintptr(_SW_HIDE))
ret <- struct{}{}
}
<-ret
} }
func (s *sysData) setText(text string) { func (s *sysData) setText(text string) {
ret := make(chan struct{}) ptext := toUTF16(text)
defer close(ret) r1, _, err := _setWindowText.Call(
uitask <- func() { uintptr(s.hwnd),
ptext := toUTF16(text) utf16ToArg(ptext))
r1, _, err := _setWindowText.Call( if r1 == 0 { // failure
uintptr(s.hwnd), panic(fmt.Errorf("error setting window/control text: %v", err))
utf16ToArg(ptext))
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 { func (s *sysData) setRect(x int, y int, width int, height int, winheight int) error {
r1, _, err := _moveWindow.Call( r1, _, err := _moveWindow.Call(
uintptr(s.hwnd), uintptr(s.hwnd),
@ -283,84 +252,61 @@ func (s *sysData) setRect(x int, y int, width int, height int, winheight int) er
} }
func (s *sysData) isChecked() bool { func (s *sysData) isChecked() bool {
ret := make(chan bool) r1, _, _ := _sendMessage.Call(
defer close(ret) uintptr(s.hwnd),
uitask <- func() { uintptr(_BM_GETCHECK),
r1, _, _ := _sendMessage.Call( uintptr(0),
uintptr(s.hwnd), uintptr(0))
uintptr(_BM_GETCHECK), return r1 == _BST_CHECKED
uintptr(0),
uintptr(0))
ret <- r1 == _BST_CHECKED
}
return <-ret
} }
func (s *sysData) text() (str string) { func (s *sysData) text() (str string) {
ret := make(chan string) var tc []uint16
defer close(ret)
uitask <- func() {
var tc []uint16
r1, _, _ := _sendMessage.Call( r1, _, _ := _sendMessage.Call(
uintptr(s.hwnd), uintptr(s.hwnd),
uintptr(_WM_GETTEXTLENGTH), uintptr(_WM_GETTEXTLENGTH),
uintptr(0), uintptr(0),
uintptr(0)) uintptr(0))
length := r1 + 1 // terminating null length := r1 + 1 // terminating null
tc = make([]uint16, length) tc = make([]uint16, length)
_sendMessage.Call( _sendMessage.Call(
uintptr(s.hwnd), uintptr(s.hwnd),
uintptr(_WM_GETTEXT), uintptr(_WM_GETTEXT),
uintptr(_WPARAM(length)), uintptr(_WPARAM(length)),
uintptr(_LPARAM(unsafe.Pointer(&tc[0])))) uintptr(_LPARAM(unsafe.Pointer(&tc[0]))))
ret <- syscall.UTF16ToString(tc) return syscall.UTF16ToString(tc)
}
return <-ret
} }
func (s *sysData) append(what string) { func (s *sysData) append(what string) {
ret := make(chan struct{}) pwhat := toUTF16(what)
defer close(ret) r1, _, err := _sendMessage.Call(
uitask <- func() { uintptr(s.hwnd),
pwhat := toUTF16(what) uintptr(classTypes[s.ctype].appendMsg),
r1, _, err := _sendMessage.Call( uintptr(_WPARAM(0)),
uintptr(s.hwnd), utf16ToLPARAM(pwhat))
uintptr(classTypes[s.ctype].appendMsg), if r1 == uintptr(classTypes[s.ctype].addSpaceErr) {
uintptr(_WPARAM(0)), panic(fmt.Errorf("out of space adding item to combobox/listbox (last error: %v)", err))
utf16ToLPARAM(pwhat)) } else if r1 == uintptr(classTypes[s.ctype].selectedIndexErr) {
if r1 == uintptr(classTypes[s.ctype].addSpaceErr) { panic(fmt.Errorf("failed to add item to combobox/listbox (last error: %v)", err))
panic(fmt.Errorf("out of space adding item to combobox/listbox (last error: %v)", err))
} 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) { func (s *sysData) insertBefore(what string, index int) {
ret := make(chan struct{}) pwhat := toUTF16(what)
defer close(ret) r1, _, err := _sendMessage.Call(
uitask <- func() { uintptr(s.hwnd),
pwhat := toUTF16(what) uintptr(classTypes[s.ctype].insertBeforeMsg),
r1, _, err := _sendMessage.Call( uintptr(_WPARAM(index)),
uintptr(s.hwnd), utf16ToLPARAM(pwhat))
uintptr(classTypes[s.ctype].insertBeforeMsg), if r1 == uintptr(classTypes[s.ctype].addSpaceErr) {
uintptr(_WPARAM(index)), panic(fmt.Errorf("out of space adding item to combobox/listbox (last error: %v)", err))
utf16ToLPARAM(pwhat)) } else if r1 == uintptr(classTypes[s.ctype].selectedIndexErr) {
if r1 == uintptr(classTypes[s.ctype].addSpaceErr) { panic(fmt.Errorf("failed to add item to combobox/listbox (last error: %v)", err))
panic(fmt.Errorf("out of space adding item to combobox/listbox (last error: %v)", err))
} 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) selectedIndex() int {
func (s *sysData) doSelectedIndex() int {
r1, _, _ := _sendMessage.Call( r1, _, _ := _sendMessage.Call(
uintptr(s.hwnd), uintptr(s.hwnd),
uintptr(classTypes[s.ctype].selectedIndexMsg), uintptr(classTypes[s.ctype].selectedIndexMsg),
@ -372,19 +318,9 @@ func (s *sysData) doSelectedIndex() int {
return int(r1) return int(r1)
} }
func (s *sysData) selectedIndex() int { func (s *sysData) selectedIndices() []int {
ret := make(chan int)
defer close(ret)
uitask <- func() {
ret <- s.doSelectedIndex()
}
return <-ret
}
// runs on uitask
func (s *sysData) doSelectedIndices() []int {
if !s.alternate { // single-selection list box; use single-selection method if !s.alternate { // single-selection list box; use single-selection method
index := s.doSelectedIndex() index := s.selectedIndex()
if index == -1 { if index == -1 {
return nil return nil
} }
@ -414,107 +350,74 @@ func (s *sysData) doSelectedIndices() []int {
return indices 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 { func (s *sysData) selectedTexts() []string {
ret := make(chan []string) indices := s.selectedIndices()
defer close(ret) strings := make([]string, len(indices))
uitask <- func() { for i, v := range indices {
indices := s.doSelectedIndices() r1, _, err := _sendMessage.Call(
strings := make([]string, len(indices)) uintptr(s.hwnd),
for i, v := range indices { uintptr(_LB_GETTEXTLEN),
r1, _, err := _sendMessage.Call( uintptr(_WPARAM(v)),
uintptr(s.hwnd), uintptr(0))
uintptr(_LB_GETTEXTLEN), if r1 == negConst(_LB_ERR) {
uintptr(_WPARAM(v)), panic(fmt.Errorf("error: LB_ERR from LB_GETTEXTLEN in what we know is a valid listbox index (came from LB_GETSELITEMS): %v", err))
uintptr(0))
if r1 == negConst(_LB_ERR) {
panic(fmt.Errorf("error: LB_ERR from LB_GETTEXTLEN in what we know is a valid listbox index (came from LB_GETSELITEMS): %v", err))
}
str := make([]uint16, r1)
r1, _, err = _sendMessage.Call(
uintptr(s.hwnd),
uintptr(_LB_GETTEXT),
uintptr(_WPARAM(v)),
uintptr(_LPARAM(unsafe.Pointer(&str[0]))))
if r1 == negConst(_LB_ERR) {
panic(fmt.Errorf("error: LB_ERR from LB_GETTEXT in what we know is a valid listbox index (came from LB_GETSELITEMS): %v", err))
}
strings[i] = syscall.UTF16ToString(str)
} }
ret <- strings str := make([]uint16, r1)
r1, _, err = _sendMessage.Call(
uintptr(s.hwnd),
uintptr(_LB_GETTEXT),
uintptr(_WPARAM(v)),
uintptr(_LPARAM(unsafe.Pointer(&str[0]))))
if r1 == negConst(_LB_ERR) {
panic(fmt.Errorf("error: LB_ERR from LB_GETTEXT in what we know is a valid listbox index (came from LB_GETSELITEMS): %v", err))
}
strings[i] = syscall.UTF16ToString(str)
} }
return <-ret return strings
} }
func (s *sysData) setWindowSize(width int, height int) error { func (s *sysData) setWindowSize(width int, height int) error {
ret := make(chan struct{}) var rect _RECT
defer close(ret)
uitask <- func() {
var rect _RECT
r1, _, err := _getClientRect.Call( r1, _, err := _getClientRect.Call(
uintptr(s.hwnd), uintptr(s.hwnd),
uintptr(unsafe.Pointer(&rect))) uintptr(unsafe.Pointer(&rect)))
if r1 == 0 { if r1 == 0 {
panic(fmt.Errorf("error getting upper-left of window for resize: %v", err)) panic(fmt.Errorf("error getting upper-left of window for resize: %v", err))
} }
// TODO AdjustWindowRect() on the result // TODO AdjustWindowRect() on the result
// 0 because (0,0) is top-left so no winheight // 0 because (0,0) is top-left so no winheight
err = s.setRect(int(rect.left), int(rect.top), width, height, 0) err = s.setRect(int(rect.left), int(rect.top), width, height, 0)
if err != nil { if err != nil {
panic(fmt.Errorf("error actually resizing window: %v", err)) panic(fmt.Errorf("error actually resizing window: %v", err))
}
ret <- struct{}{}
} }
<-ret
return nil
} }
func (s *sysData) delete(index int) { func (s *sysData) delete(index int) {
ret := make(chan struct{}) r1, _, err := _sendMessage.Call(
defer close(ret) uintptr(s.hwnd),
uitask <- func() { uintptr(classTypes[s.ctype].deleteMsg),
r1, _, err := _sendMessage.Call( uintptr(_WPARAM(index)),
uintptr(s.hwnd), uintptr(0))
uintptr(classTypes[s.ctype].deleteMsg), if r1 == uintptr(classTypes[s.ctype].selectedIndexErr) {
uintptr(_WPARAM(index)), panic(fmt.Errorf("failed to delete item from combobox/listbox (last error: %v)", err))
uintptr(0))
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() { func (s *sysData) setIndeterminate() {
ret := make(chan struct{}) r1, _, err := _setWindowLongPtr.Call(
defer close(ret) uintptr(s.hwnd),
uitask <- func() { negConst(_GWL_STYLE),
r1, _, err := _setWindowLongPtr.Call( uintptr(classTypes[s.ctype].style | _PBS_MARQUEE))
uintptr(s.hwnd), if r1 == 0 {
negConst(_GWL_STYLE), panic(fmt.Errorf("error setting progress bar style to enter indeterminate mode: %v", err))
uintptr(classTypes[s.ctype].style | _PBS_MARQUEE))
if r1 == 0 {
panic(fmt.Errorf("error setting progress bar style to enter indeterminate mode: %v", err))
}
_sendMessage.Call(
uintptr(s.hwnd),
uintptr(_PBM_SETMARQUEE),
uintptr(_WPARAM(_TRUE)),
uintptr(0))
s.isMarquee = true
ret <- struct{}{}
} }
<-ret _sendMessage.Call(
uintptr(s.hwnd),
uintptr(_PBM_SETMARQUEE),
uintptr(_WPARAM(_TRUE)),
uintptr(0))
s.isMarquee = true
} }
func (s *sysData) setProgress(percent int) { func (s *sysData) setProgress(percent int) {
@ -522,134 +425,100 @@ func (s *sysData) setProgress(percent int) {
s.setIndeterminate() s.setIndeterminate()
return return
} }
ret := make(chan struct{}) if s.isMarquee {
defer close(ret) // turn off marquee before switching back
uitask <- func() { _sendMessage.Call(
if s.isMarquee { uintptr(s.hwnd),
// turn off marquee before switching back uintptr(_PBM_SETMARQUEE),
_sendMessage.Call( uintptr(_WPARAM(_FALSE)),
uintptr(s.hwnd), uintptr(0))
uintptr(_PBM_SETMARQUEE), r1, _, err := _setWindowLongPtr.Call(
uintptr(_WPARAM(_FALSE)), uintptr(s.hwnd),
uintptr(0)) negConst(_GWL_STYLE),
r1, _, err := _setWindowLongPtr.Call( uintptr(classTypes[s.ctype].style))
uintptr(s.hwnd), if r1 == 0 {
negConst(_GWL_STYLE), panic(fmt.Errorf("error setting progress bar style to leave indeterminate mode (percent %d): %v", percent, err))
uintptr(classTypes[s.ctype].style))
if r1 == 0 {
panic(fmt.Errorf("error setting progress bar style to leave indeterminate mode (percent %d): %v", percent, err))
}
s.isMarquee = false
} }
send := func(msg uintptr, n int, l _LPARAM) { s.isMarquee = false
_sendMessage.Call( }
uintptr(s.hwnd), send := func(msg uintptr, n int, l _LPARAM) {
msg, _sendMessage.Call(
uintptr(_WPARAM(n)), uintptr(s.hwnd),
uintptr(l)) msg,
} uintptr(_WPARAM(n)),
// Windows 7 has a non-disableable slowly-animating progress bar increment uintptr(l))
// there isn't one for decrement, so we'll work around by going one higher and then lower again }
// for the case where percent == 100, we need to increase the range temporarily // Windows 7 has a non-disableable slowly-animating progress bar increment
// sources: http://social.msdn.microsoft.com/Forums/en-US/61350dc7-6584-4c4e-91b0-69d642c03dae/progressbar-disable-smooth-animation http://stackoverflow.com/questions/2217688/windows-7-aero-theme-progress-bar-bug http://discuss.joelonsoftware.com/default.asp?dotnet.12.600456.2 http://stackoverflow.com/questions/22469876/progressbar-lag-when-setting-position-with-pbm-setpos http://stackoverflow.com/questions/6128287/tprogressbar-never-fills-up-all-the-way-seems-to-be-updating-too-fast // there isn't one for decrement, so we'll work around by going one higher and then lower again
if percent == 100 { // for the case where percent == 100, we need to increase the range temporarily
send(_PBM_SETRANGE32, 0, 101) // sources: http://social.msdn.microsoft.com/Forums/en-US/61350dc7-6584-4c4e-91b0-69d642c03dae/progressbar-disable-smooth-animation http://stackoverflow.com/questions/2217688/windows-7-aero-theme-progress-bar-bug http://discuss.joelonsoftware.com/default.asp?dotnet.12.600456.2 http://stackoverflow.com/questions/22469876/progressbar-lag-when-setting-position-with-pbm-setpos http://stackoverflow.com/questions/6128287/tprogressbar-never-fills-up-all-the-way-seems-to-be-updating-too-fast
} if percent == 100 {
send(_PBM_SETPOS, percent+1, 0) send(_PBM_SETRANGE32, 0, 101)
send(_PBM_SETPOS, percent, 0) }
if percent == 100 { send(_PBM_SETPOS, percent+1, 0)
send(_PBM_SETRANGE32, 0, 100) send(_PBM_SETPOS, percent, 0)
} if percent == 100 {
ret <- struct{}{} send(_PBM_SETRANGE32, 0, 100)
} }
<-ret
} }
func (s *sysData) len() int { func (s *sysData) len() int {
ret := make(chan int) r1, _, err := _sendMessage.Call(
defer close(ret) uintptr(s.hwnd),
uitask <- func() { uintptr(classTypes[s.ctype].lenMsg),
r1, _, err := _sendMessage.Call( uintptr(_WPARAM(0)),
uintptr(s.hwnd), uintptr(_LPARAM(0)))
uintptr(classTypes[s.ctype].lenMsg), if r1 == uintptr(classTypes[s.ctype].selectedIndexErr) {
uintptr(_WPARAM(0)), panic(fmt.Errorf("unexpected error return from sysData.len(); GetLastError() says %v", err))
uintptr(_LPARAM(0)))
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) { func (s *sysData) setAreaSize(width int, height int) {
ret := make(chan struct{}) _sendMessage.Call(
defer close(ret) uintptr(s.hwnd),
uitask <- func() { uintptr(msgSetAreaSize),
_sendMessage.Call( uintptr(width), // WPARAM is UINT_PTR on Windows XP and newer at least, so we're good with this
uintptr(s.hwnd), uintptr(height))
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() { func (s *sysData) repaintAll() {
ret := make(chan struct{}) _sendMessage.Call(
defer close(ret) uintptr(s.hwnd),
uitask <- func() { uintptr(msgRepaintAll),
_sendMessage.Call( uintptr(0),
uintptr(s.hwnd), uintptr(0))
uintptr(msgRepaintAll),
uintptr(0),
uintptr(0))
ret <- struct{}{}
}
<-ret
} }
func (s *sysData) center() { func (s *sysData) center() {
ret := make(chan struct{}) var ws _RECT
defer close(ret)
uitask <- func() {
var ws _RECT
r1, _, err := _getWindowRect.Call( r1, _, err := _getWindowRect.Call(
uintptr(s.hwnd), uintptr(s.hwnd),
uintptr(unsafe.Pointer(&ws))) uintptr(unsafe.Pointer(&ws)))
if r1 == 0 { if r1 == 0 {
panic(fmt.Errorf("error getting window rect for sysData.center(): %v", err)) panic(fmt.Errorf("error getting window rect for sysData.center(): %v", err))
}
// 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
dw, _, _ := _getSystemMetrics.Call(uintptr(_SM_CXFULLSCREEN))
dh, _, _ := _getSystemMetrics.Call(uintptr(_SM_CYFULLSCREEN))
ww := ws.right - ws.left
wh := ws.bottom - ws.top
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 // 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
wh := ws.bottom - ws.top
wx := (int32(dw) / 2) - (ww / 2)
wy := (int32(dh) / 2) - (wh / 2)
s.setRect(int(wx), int(wy), int(ww), int(wh), 0)
} }
func (s *sysData) setChecked(checked bool) { func (s *sysData) setChecked(checked bool) {
ret := make(chan struct{}) c := uintptr(_BST_CHECKED)
defer close(ret) if !checked {
uitask <- func() { c = uintptr(_BST_UNCHECKED)
c := uintptr(_BST_CHECKED)
if !checked {
c = uintptr(_BST_UNCHECKED)
}
_sendMessage.Call(
uintptr(s.hwnd),
uintptr(_BM_SETCHECK),
c,
uintptr(0))
ret <- struct{}{}
} }
<-ret _sendMessage.Call(
uintptr(s.hwnd),
uintptr(_BM_SETCHECK),
c,
uintptr(0))
} }