Filled in the standard window procedure.
This commit is contained in:
parent
c6a8a4d2f7
commit
b918496ae4
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -16,8 +17,26 @@ var (
|
|||
)
|
||||
|
||||
func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT {
|
||||
// TODO get CreateWindowEx data
|
||||
sysData := getSysData(hwnd)
|
||||
switch uMsg {
|
||||
case _WM_COMMAND:
|
||||
id := wParam.LOWORD()
|
||||
// ... member events
|
||||
_ = id
|
||||
return 0
|
||||
case _WM_GETMINMAXINFO:
|
||||
mm := lParam.MINMAXINFO()
|
||||
// ... minimum size
|
||||
_ = mm
|
||||
return 0
|
||||
case _WM_SIZE:
|
||||
// TODO
|
||||
return 0
|
||||
case _WM_CLOSE:
|
||||
if sysData.closing != nil {
|
||||
sysData.closing <- struct{}
|
||||
}
|
||||
return 0
|
||||
default:
|
||||
r1, _, _ := defWindowProc.Call(
|
||||
uintptr(hwnd),
|
||||
|
|
|
@ -9,6 +9,9 @@ import (
|
|||
type cSysData struct {
|
||||
ctype int
|
||||
text string
|
||||
|
||||
// for Window
|
||||
closing chan struct{}
|
||||
}
|
||||
func (c *cSysData) make() error {
|
||||
panic(runtime.GOOS + " sysData does not define make()")
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
// 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 sys.Mutex
|
||||
)
|
||||
|
||||
func addSysData(hwnd _HWND, s *sysData) {
|
||||
sysDatasLock.Lock()
|
||||
defer sysDatasLock.Unlock()
|
||||
sysDatas[hwnd] = &sdcEntry{
|
||||
s: s,
|
||||
members: map[_HMENU]*sysData{},
|
||||
}
|
||||
}
|
||||
|
||||
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 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))
|
||||
}
|
|
@ -57,6 +57,7 @@ func (w *Window) Open() (err error) {
|
|||
|
||||
// If the window has already been created, show it.
|
||||
if !w.created {
|
||||
w.sysData.closing = w.Closing
|
||||
err = w.sysData.make()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -72,6 +73,7 @@ func (w *Window) Open() (err error) {
|
|||
}
|
||||
|
||||
// Close closes the window. The window is not destroyed; it is merely hidden.
|
||||
// TODO don't send on w.Closing
|
||||
func (w *Window) Close() (err error) {
|
||||
return w.sysData.hide()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue