Separated initial text from sysData and fixed errors in the previous commits.

This commit is contained in:
Pietro Gagliardi 2014-02-12 10:43:57 -05:00
parent f93bebfeec
commit 3f8fe0e710
4 changed files with 13 additions and 13 deletions

View File

@ -8,12 +8,11 @@ import (
// The sysData type contains all system data. It provides the system-specific underlying implementation. It is guaranteed to have the following by embedding: // 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 { type cSysData struct {
ctype int ctype int
text string
// for Window // for Window
closing chan struct{} closing chan struct{}
} }
func (c *cSysData) make() error { func (c *cSysData) make(initText string) error {
panic(runtime.GOOS + " sysData does not define make()") panic(runtime.GOOS + " sysData does not define make()")
} }
func (c *cSysData) show() error { func (c *cSysData) show() error {

View File

@ -42,7 +42,7 @@ var classTypes = [nctypes]*classData{
var ( var (
cid _HMENU = 0 cid _HMENU = 0
cidLock sys.Mutex cidLock sync.Mutex
) )
func nextID() _HMENU { func nextID() _HMENU {
@ -52,7 +52,7 @@ func nextID() _HMENU {
return cid return cid
} }
func (s *sysData) make() (err error) { func (s *sysData) make(initText string) (err error) {
ret := make(chan uiret) ret := make(chan uiret)
defer close(ret) defer close(ret)
ct := classTypes[s.ctype] ct := classTypes[s.ctype]
@ -64,7 +64,7 @@ func (s *sysData) make() (err error) {
p: []uintptr{ p: []uintptr{
uintptr(ct.xstyle), uintptr(ct.xstyle),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(ct.name))), uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(ct.name))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(s.text))), uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(initText))),
uintptr(ct.style), uintptr(ct.style),
uintptr(_CW_USEDEFAULT), // TODO uintptr(_CW_USEDEFAULT), // TODO
uintptr(_CW_USEDEFAULT), uintptr(_CW_USEDEFAULT),

View File

@ -9,9 +9,9 @@ import (
// I need a way to get a sysData for a given HWND or a given HWND/control ID. So, this. // I need a way to get a sysData for a given HWND or a given HWND/control ID. So, this.
var ( var (
sysDatas = map[_HWND]*sdcEntry{} sysDatas = map[_HWND]*sysData{}
sysDatasLock sync.Mutex sysDatasLock sync.Mutex
sysDataIDs = map[_HMENU]*sdcEntry{} sysDataIDs = map[_HMENU]*sysData{}
sysDataIDsLock sync.Mutex sysDataIDsLock sync.Mutex
) )
@ -21,7 +21,7 @@ func addSysData(hwnd _HWND, s *sysData) {
sysDatas[hwnd] = s sysDatas[hwnd] = s
} }
func addIDSysData(id _HMENU, s *sysData) { func addSysDataID(id _HMENU, s *sysData) {
sysDataIDsLock.Lock() sysDataIDsLock.Lock()
defer sysDataIDsLock.Unlock() defer sysDataIDsLock.Unlock()
sysDataIDs[id] = s sysDataIDs[id] = s
@ -36,11 +36,11 @@ func getSysData(hwnd _HWND) *sysData {
return nil return nil
} }
func getIDSysData(id _HMENU) *sysData { func getSysDataID(id _HMENU) *sysData {
sysDataIDsLock.Lock() sysDataIDsLock.Lock()
defer sysDataIDsLock.Unlock() defer sysDataIDsLock.Unlock()
if ss, ok := sysDataIDs[id]; ok { if ss, ok := sysDataIDs[id]; ok {
return ss return ss
} }
panic(fmt.Sprintf("getting nonexistent ID %d for HWND %d\n", id, hwnd)) panic(fmt.Sprintf("getting nonexistent ID %d\n", id))
} }

View File

@ -18,6 +18,7 @@ type Window struct {
created bool created bool
control Control control Control
sysData *sysData sysData *sysData
initText string
} }
// NewWindow creates a new window with the given title. The window is not constructed at the OS level until a call to Open(). // NewWindow creates a new window with the given title. The window is not constructed at the OS level until a call to Open().
@ -26,9 +27,9 @@ func NewWindow(title string) *Window {
sysData: &sysData{ sysData: &sysData{
cSysData: cSysData{ cSysData: cSysData{
ctype: c_window, ctype: c_window,
text: title,
}, },
}, },
initText: title,
} }
} }
@ -54,7 +55,7 @@ func (w *Window) Open() (err error) {
// If the window has already been created, show it. // If the window has already been created, show it.
if !w.created { if !w.created {
w.sysData.closing = w.Closing w.sysData.closing = w.Closing
err = w.sysData.make() err = w.sysData.make(w.initText)
if err != nil { if err != nil {
return err return err
} }
@ -82,6 +83,6 @@ func (w *Window) apply() error {
func (w *Window) setParent(c Control) { func (w *Window) setParent(c Control) {
panic("Window.setParent() should never be called") panic("Window.setParent() should never be called")
} }
func (w *Window) setParentWindow(w *Window) { func (w *Window) setParentWindow(w2 *Window) {
panic("Window.setParent() should never be called") panic("Window.setParent() should never be called")
} }