57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
// 11 february 2014
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
)
|
|
|
|
// 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
|
|
)
|
|
|
|
// MUST HAVE LOCKED BEFORE CALLING
|
|
func addSysData(hwnd _HWND, s *sysData) {
|
|
sysDatas[hwnd] = &sdcEntry{
|
|
s: s,
|
|
members: map[_HMENU]*sysData{},
|
|
}
|
|
}
|
|
|
|
// MUST HAVE LOCKED BEFORE CALLING
|
|
func addIDSysData(hwnd _HWND, id _HMENU, s *sysData) {
|
|
if ss, ok := sysDatas[hwnd]; ok {
|
|
ss.members[id] = s
|
|
}
|
|
panic(fmt.Sprintf("adding ID %d to nonexistent HWND %d\n", id, hwnd))
|
|
}
|
|
|
|
func getSysData(hwnd _HWND) *sysData {
|
|
sysDatasLock.Lock()
|
|
defer sysDatasLock.Unlock()
|
|
if ss, ok := sysDatas[hwnd]; ok {
|
|
return ss.s
|
|
}
|
|
panic(fmt.Sprintf("getting nonexistent HWND %d\n", hwnd))
|
|
}
|
|
|
|
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
|
|
}
|
|
panic(fmt.Sprintf("getting nonexistent ID %d for HWND %d\n", id, hwnd))
|
|
}
|
|
panic(fmt.Sprintf("getting nonexistent HWND %d\n", hwnd))
|
|
}
|