Windows sysData has been adjusted to deal with child controls. Rather than storing the parent window, it is passed as an argument to sysData.make(), which does the child ID allocation. Child IDs are now window-local, getting rid of that restriction.

This commit is contained in:
Pietro Gagliardi 2014-02-12 21:08:10 -05:00
parent e296398eff
commit 3dcbb3920d
2 changed files with 24 additions and 22 deletions

View File

@ -2,4 +2,3 @@ This is a file to keep track of API restrictions that simplify the implementatio
- Once you open a window, the controls are finalized: you cannot change the window's control or add/remove controls to layouts. - Once you open a window, the controls are finalized: you cannot change the window's control or add/remove controls to layouts.
- Once you open a window, you cannot change its event channels or its controls's event channels. - Once you open a window, you cannot change its event channels or its controls's event channels.
- [Windows] At most 65535 controls can be made, period. This is because child window IDs are alloted by the UI library application-global, not window-local, and BN_CLICKED only stores the control ID in a word (and I start counting at 1 to be safe). If I keep the first restriction and amend it such that you can only set the control of a window at the time of first open (somehow; split create and open?), I can easily make them window-local.

View File

@ -12,7 +12,9 @@ type sysData struct {
cSysData cSysData
hwnd _HWND hwnd _HWND
cid _HMENU children map[_HMENU]*sysData
nextChildID _HMENU
childrenLock sync.Mutex
shownAlready bool shownAlready bool
} }
@ -36,30 +38,32 @@ var classTypes = [nctypes]*classData{
name: "BUTTON", name: "BUTTON",
style: _BS_PUSHBUTTON | controlstyle, style: _BS_PUSHBUTTON | controlstyle,
xstyle: 0 | controlxstyle, xstyle: 0 | controlxstyle,
mkid: true,
}, },
} }
var ( func (s *sysData) addChild(chlid *sysData) _HMENU {
cid _HMENU = 0 s.childrenLock.Lock()
cidLock sync.Mutex defer s.childrenLock.Unlock()
) s.nextChildID++ // start at 1
s.children[s.nextChildID] = child
func nextID() _HMENU { return s.nextChildID
cidLock.Lock()
defer cidLock.Unlock()
cid++
return cid
} }
func (s *sysData) make(initText string, initWidth int, initHeight int) (err error) { func (s *sysData) delChild(id _HMENU) {
s.childrenLock.Lock()
defer s.childrenLock.Unlock()
delete(s.children, id)
}
func (s *sysData) make(initText string, initWidth int, initHeight int, window *sysData) (err error) {
ret := make(chan uiret) ret := make(chan uiret)
defer close(ret) defer close(ret)
ct := classTypes[s.ctype] ct := classTypes[s.ctype]
cid := _HMENU(0)
pwin := uintptr(_NULL) pwin := uintptr(_NULL)
if ct.mkid { if window != nil { // this is a child control
s.cid = nextID() cid = window.addChild(s)
pwin = uintptr(s.parentWindow.hwnd) pwin = uintptr(window.hwnd)
} }
uitask <- &uimsg{ uitask <- &uimsg{
call: _createWindowEx, call: _createWindowEx,
@ -73,7 +77,7 @@ func (s *sysData) make(initText string, initWidth int, initHeight int) (err erro
uintptr(initWidth), uintptr(initWidth),
uintptr(initHeight), uintptr(initHeight),
pwin, pwin,
uintptr(s.cid), uintptr(cid),
uintptr(hInstance), uintptr(hInstance),
uintptr(_NULL), uintptr(_NULL),
}, },
@ -81,13 +85,12 @@ func (s *sysData) make(initText string, initWidth int, initHeight int) (err erro
} }
r := <-ret r := <-ret
if r.ret == 0 { // failure if r.ret == 0 { // failure
if window != nil {
window.delChild(cid)
}
return r.err return r.err
} }
s.hwnd = _HWND(r.ret) s.hwnd = _HWND(r.ret)
addSysData(s.hwnd, s)
if ct.mkid {
addSysDataID(s.cid, s)
}
return nil return nil
} }