Migrated sysdata_darwin.go and uitask_darwin.go to the new API. Now to just wait for the answer to my Stack Overflow question so I can migrate dialog_darwin.go...
This commit is contained in:
parent
dff7ed3321
commit
ed989a9d9f
|
@ -225,17 +225,9 @@ func (s *sysData) make(window *sysData) error {
|
|||
if window != nil {
|
||||
parentWindow = window.id
|
||||
}
|
||||
ret := make(chan C.id)
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
ret <- ct.make(parentWindow, s.alternate, s)
|
||||
}
|
||||
s.id = <-ret
|
||||
s.id = ct.make(parentWindow, s.alternate, s)
|
||||
if ct.getinside != nil {
|
||||
uitask <- func() {
|
||||
ret <- ct.getinside(s.id)
|
||||
}
|
||||
addSysData(<-ret, s)
|
||||
addSysData(ct.getinside(s.id), s)
|
||||
} else {
|
||||
addSysData(s.id, s)
|
||||
}
|
||||
|
@ -249,33 +241,15 @@ func (s *sysData) firstShow() error {
|
|||
}
|
||||
|
||||
func (s *sysData) show() {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
classTypes[s.ctype].show(s.id)
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
classTypes[s.ctype].show(s.id)
|
||||
}
|
||||
|
||||
func (s *sysData) hide() {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
classTypes[s.ctype].hide(s.id)
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
classTypes[s.ctype].hide(s.id)
|
||||
}
|
||||
|
||||
func (s *sysData) setText(text string) {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
classTypes[s.ctype].settext(s.id, toNSString(text))
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
classTypes[s.ctype].settext(s.id, toNSString(text))
|
||||
}
|
||||
|
||||
func (s *sysData) setRect(x int, y int, width int, height int, winheight int) error {
|
||||
|
@ -288,147 +262,63 @@ 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() {
|
||||
ret <- C.isCheckboxChecked(s.id) != C.NO
|
||||
}
|
||||
return <-ret
|
||||
return C.isCheckboxChecked(s.id) != C.NO
|
||||
}
|
||||
|
||||
func (s *sysData) text() string {
|
||||
ret := make(chan string)
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
str := classTypes[s.ctype].text(s.id, s.alternate)
|
||||
ret <- fromNSString(str)
|
||||
}
|
||||
return <-ret
|
||||
str := classTypes[s.ctype].text(s.id, s.alternate)
|
||||
return fromNSString(str)
|
||||
}
|
||||
|
||||
func (s *sysData) append(what string) {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
classTypes[s.ctype].append(s.id, what, s.alternate)
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
classTypes[s.ctype].append(s.id, what, s.alternate)
|
||||
}
|
||||
|
||||
func (s *sysData) insertBefore(what string, before int) {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
classTypes[s.ctype].insertBefore(s.id, what, before, s.alternate)
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
classTypes[s.ctype].insertBefore(s.id, what, before, s.alternate)
|
||||
}
|
||||
|
||||
func (s *sysData) selectedIndex() int {
|
||||
ret := make(chan int)
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
ret <- classTypes[s.ctype].selIndex(s.id)
|
||||
}
|
||||
return <-ret
|
||||
return classTypes[s.ctype].selIndex(s.id)
|
||||
}
|
||||
|
||||
func (s *sysData) selectedIndices() []int {
|
||||
ret := make(chan []int)
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
ret <- classTypes[s.ctype].selIndices(s.id)
|
||||
}
|
||||
return <-ret
|
||||
return classTypes[s.ctype].selIndices(s.id)
|
||||
}
|
||||
|
||||
func (s *sysData) selectedTexts() []string {
|
||||
ret := make(chan []string)
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
ret <- classTypes[s.ctype].selTexts(s.id)
|
||||
}
|
||||
return <-ret
|
||||
return classTypes[s.ctype].selTexts(s.id)
|
||||
}
|
||||
|
||||
func (s *sysData) setWindowSize(width int, height int) error {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
C.windowSetContentSize(s.id, C.intptr_t(width), C.intptr_t(height))
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
C.windowSetContentSize(s.id, C.intptr_t(width), C.intptr_t(height))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *sysData) delete(index int) {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
classTypes[s.ctype].delete(s.id, index)
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
classTypes[s.ctype].delete(s.id, index)
|
||||
}
|
||||
|
||||
func (s *sysData) setProgress(percent int) {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
C.setProgress(s.id, C.intptr_t(percent))
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
C.setProgress(s.id, C.intptr_t(percent))
|
||||
}
|
||||
|
||||
func (s *sysData) len() int {
|
||||
ret := make(chan int)
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
ret <- classTypes[s.ctype].len(s.id)
|
||||
}
|
||||
return <-ret
|
||||
return classTypes[s.ctype].len(s.id)
|
||||
}
|
||||
|
||||
func (s *sysData) setAreaSize(width int, height int) {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
C.setAreaSize(s.id, C.intptr_t(width), C.intptr_t(height))
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
return C.setAreaSize(s.id, C.intptr_t(width), C.intptr_t(height))
|
||||
}
|
||||
|
||||
func (s *sysData) repaintAll() {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
C.display(s.id)
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
return C.display(s.id)
|
||||
}
|
||||
|
||||
func (s *sysData) center() {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
C.center(s.id)
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
return C.center(s.id)
|
||||
}
|
||||
|
||||
func (s *sysData) setChecked(checked bool) {
|
||||
ret := make(chan struct{})
|
||||
defer close(ret)
|
||||
uitask <- func() {
|
||||
C.setCheckboxChecked(s.id, toBOOL(checked))
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
C.setCheckboxChecked(s.id, toBOOL(checked))
|
||||
}
|
||||
|
|
|
@ -16,32 +16,31 @@ import "C"
|
|||
|
||||
var uitask chan func()
|
||||
|
||||
func ui(main func()) error {
|
||||
runtime.LockOSThread()
|
||||
|
||||
uitask = make(chan func())
|
||||
|
||||
func uiinit() error {
|
||||
err := initCocoa()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// do this at the end in case something goes wrong
|
||||
uitask = make(chan func())
|
||||
return nil
|
||||
}
|
||||
|
||||
func ui() {
|
||||
// Cocoa must run on the first thread created by the program, so we run our dispatcher on another thread instead
|
||||
go func() {
|
||||
for f := range uitask {
|
||||
C.douitask(appDelegate, unsafe.Pointer(&f))
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
main()
|
||||
uitask <- func() {
|
||||
C.breakMainLoop()
|
||||
for {
|
||||
select {
|
||||
case f := range uitask:
|
||||
C.douitask(appDelegate, unsafe.Pointer(&f))
|
||||
case <-Stop:
|
||||
C.breakMainLoop()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
C.cocoaMainLoop()
|
||||
return nil
|
||||
}
|
||||
|
||||
func initCocoa() (err error) {
|
||||
|
|
Loading…
Reference in New Issue