2014-02-11 15:14:15 -06:00
// 11 february 2014
2014-02-19 10:41:10 -06:00
package ui
2014-02-11 15:14:15 -06:00
import (
"runtime"
)
2014-02-18 09:53:15 -06:00
const eventbufsiz = 100 // suggested by skelterjohn
// Event returns a new channel suitable for listening for events.
func Event ( ) chan struct { } {
return make ( chan struct { } , eventbufsiz )
}
2014-02-11 15:14:15 -06:00
// The sysData type contains all system data. It provides the system-specific underlying implementation. It is guaranteed to have the following by embedding:
type cSysData struct {
2014-02-12 19:57:30 -06:00
ctype int
event chan struct { }
2014-02-13 04:28:26 -06:00
resize func ( x int , y int , width int , height int ) error
2014-02-14 14:54:56 -06:00
alternate bool // editable for Combobox, multi-select for listbox
2014-02-11 15:14:15 -06:00
}
2014-02-15 12:07:46 -06:00
func ( c * cSysData ) make ( initText string , window * sysData ) error {
2014-02-11 15:14:15 -06:00
panic ( runtime . GOOS + " sysData does not define make()" )
}
func ( c * cSysData ) show ( ) error {
panic ( runtime . GOOS + " sysData does not define show()" )
}
2014-02-11 17:57:03 -06:00
func ( c * cSysData ) hide ( ) error {
2014-02-11 15:14:15 -06:00
panic ( runtime . GOOS + " sysData does not define hide()" )
}
2014-02-12 17:14:37 -06:00
func ( c * cSysData ) setText ( text string ) error {
panic ( runtime . GOOS + " sysData does not define setText()" )
}
2014-02-13 04:28:26 -06:00
func ( c * cSysData ) setRect ( x int , y int , width int , height int ) error {
panic ( runtime . GOOS + " sysData does not define setRect()" )
}
2014-02-15 12:36:24 -06:00
func ( c * cSysData ) isChecked ( ) bool {
2014-02-13 14:14:10 -06:00
panic ( runtime . GOOS + " sysData does not define isChecked()" )
}
2014-02-15 13:03:46 -06:00
func ( c * cSysData ) text ( ) string {
2014-02-14 11:16:27 -06:00
panic ( runtime . GOOS + " sysData does not define text()" )
}
func ( c * cSysData ) append ( string ) error {
panic ( runtime . GOOS + " sysData does not define append()" )
}
2014-02-15 11:06:29 -06:00
func ( c * cSysData ) insertBefore ( string , int ) error {
panic ( runtime . GOOS + " sysData does not define insertBefore()" )
}
2014-02-15 13:03:46 -06:00
func ( c * cSysData ) selectedIndex ( ) int {
2014-02-15 11:32:12 -06:00
panic ( runtime . GOOS + " sysData does not define selectedIndex()" )
}
2014-02-15 13:03:46 -06:00
func ( c * cSysData ) selectedIndices ( ) [ ] int {
2014-02-15 11:32:12 -06:00
panic ( runtime . GOOS + " sysData does not define selectedIndices()" )
}
2014-02-15 13:03:46 -06:00
func ( c * cSysData ) selectedTexts ( ) [ ] string {
2014-02-15 11:32:12 -06:00
panic ( runtime . GOOS + " sysData does not define selectedIndex()" )
}
2014-02-15 12:02:10 -06:00
func ( c * cSysData ) setWindowSize ( int , int ) error {
panic ( runtime . GOOS + " sysData does not define setWindowSize()" )
}
2014-02-15 17:14:43 -06:00
func ( c * cSysData ) delete ( int ) error {
panic ( runtime . GOOS + " sysData does not define delete()" )
}
2014-02-11 15:14:15 -06:00
2014-02-18 08:57:19 -06:00
// signal sends the event signal. This raise is done asynchronously to avoid deadlocking the UI task.
2014-02-18 09:53:15 -06:00
// Thanks skelterjohn for this techinque: if we can't queue any more events, drop them
2014-02-18 08:57:19 -06:00
func ( s * cSysData ) signal ( ) {
if s . event != nil {
go func ( ) {
select {
case s . event <- struct { } { } :
default :
}
} ( )
}
}
2014-02-11 15:14:15 -06:00
const (
c_window = iota
c_button
2014-02-13 11:26:43 -06:00
c_checkbox
2014-02-14 11:16:27 -06:00
c_combobox
2014-02-14 14:00:59 -06:00
c_lineedit
2014-02-14 14:12:03 -06:00
c_label
2014-02-14 15:25:39 -06:00
c_listbox
2014-02-11 18:09:10 -06:00
nctypes
2014-02-11 15:14:15 -06:00
)
2014-02-14 10:02:59 -06:00
func mksysdata ( ctype int ) * sysData {
return & sysData {
cSysData : cSysData {
ctype : ctype ,
} ,
}
}