Added control ID generation.
This commit is contained in:
parent
e9e2c0f269
commit
f93bebfeec
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type sysData struct {
|
||||
|
@ -19,6 +20,7 @@ type classData struct {
|
|||
name string
|
||||
style uint32
|
||||
xstyle uint32
|
||||
mkid bool
|
||||
}
|
||||
|
||||
//const controlstyle = _WS_CHILD | _WS_VISIBLE | _WS_TABSTOP
|
||||
|
@ -34,13 +36,29 @@ var classTypes = [nctypes]*classData{
|
|||
// name: "BUTTON"
|
||||
// style: _BS_PUSHBUTTON | controlstyle,
|
||||
// xstyle: 0 | controlxstyle,
|
||||
// mkid: true,
|
||||
// },
|
||||
}
|
||||
|
||||
var (
|
||||
cid _HMENU = 0
|
||||
cidLock sys.Mutex
|
||||
)
|
||||
|
||||
func nextID() _HMENU {
|
||||
cidLock.Lock()
|
||||
defer cidLock.Unlock()
|
||||
cid++
|
||||
return cid
|
||||
}
|
||||
|
||||
func (s *sysData) make() (err error) {
|
||||
ret := make(chan uiret)
|
||||
defer close(ret)
|
||||
ct := classTypes[s.ctype]
|
||||
if ct.mkid {
|
||||
s.cid = nextID()
|
||||
}
|
||||
uitask <- &uimsg{
|
||||
call: _createWindowEx,
|
||||
p: []uintptr{
|
||||
|
@ -65,7 +83,9 @@ func (s *sysData) make() (err error) {
|
|||
}
|
||||
s.hwnd = _HWND(r.ret)
|
||||
addSysData(s.hwnd, s)
|
||||
// TODO parent
|
||||
if ct.mkid {
|
||||
addSysDataID(s.cid, s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -8,51 +8,39 @@ import (
|
|||
|
||||
// I need a way to get a sysData for a given HWND or a given HWND/control ID. So, this.
|
||||
|
||||
type sdcEntry struct {
|
||||
s *sysData
|
||||
members map[_HMENU]*sysData
|
||||
}
|
||||
|
||||
var (
|
||||
sysDatas = map[_HWND]*sdcEntry{}
|
||||
sysDatasLock sync.Mutex
|
||||
sysDataIDs = map[_HMENU]*sdcEntry{}
|
||||
sysDataIDsLock sync.Mutex
|
||||
)
|
||||
|
||||
func addSysData(hwnd _HWND, s *sysData) {
|
||||
sysDatasLock.Lock()
|
||||
defer sysDatasLock.Unlock()
|
||||
sysDatas[hwnd] = &sdcEntry{
|
||||
s: s,
|
||||
members: map[_HMENU]*sysData{},
|
||||
}
|
||||
sysDatas[hwnd] = s
|
||||
}
|
||||
|
||||
func addIDSysData(hwnd _HWND, id _HMENU, s *sysData) {
|
||||
sysDatasLock.Lock()
|
||||
defer sysDatasLock.Unlock()
|
||||
if ss, ok := sysDatas[hwnd]; ok {
|
||||
ss.members[id] = s
|
||||
}
|
||||
panic(fmt.Sprintf("adding ID %d to nonexistent HWND %d\n", id, hwnd))
|
||||
func addIDSysData(id _HMENU, s *sysData) {
|
||||
sysDataIDsLock.Lock()
|
||||
defer sysDataIDsLock.Unlock()
|
||||
sysDataIDs[id] = s
|
||||
}
|
||||
|
||||
func getSysData(hwnd _HWND) *sysData {
|
||||
sysDatasLock.Lock()
|
||||
defer sysDatasLock.Unlock()
|
||||
if ss, ok := sysDatas[hwnd]; ok {
|
||||
return ss.s
|
||||
return ss
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getIDSysData(hwnd _HWND, id _HMENU) *sysData {
|
||||
sysDatasLock.Lock()
|
||||
defer sysDatasLock.Unlock()
|
||||
if ss, ok := sysDatas[hwnd]; ok {
|
||||
if xx, ok := ss.members[id]; ok {
|
||||
return xx
|
||||
func getIDSysData(id _HMENU) *sysData {
|
||||
sysDataIDsLock.Lock()
|
||||
defer sysDataIDsLock.Unlock()
|
||||
if ss, ok := sysDataIDs[id]; ok {
|
||||
return ss
|
||||
}
|
||||
panic(fmt.Sprintf("getting nonexistent ID %d for HWND %d\n", id, hwnd))
|
||||
}
|
||||
panic(fmt.Sprintf("getting nonexistent HWND %d\n", hwnd))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue