Changed Areas on WIndows so that they all use the same window class, rather than having one per Area.

This commit is contained in:
Pietro Gagliardi 2014-05-30 23:02:15 -04:00
parent 855a09656a
commit 2e0914e575
3 changed files with 117 additions and 134 deletions

View File

@ -6,7 +6,6 @@ import (
"fmt"
"syscall"
"unsafe"
"sync"
"image"
)
@ -16,12 +15,7 @@ const (
)
const (
areaWndClassFormat = "gouiarea%X"
)
var (
areaWndClassNum uintptr
areaWndClassNumLock sync.Mutex
areaWndClass = "gouiarea"
)
func getScrollPos(hwnd _HWND) (xpos int32, ypos int32) {
@ -604,8 +598,7 @@ var (
_setFocus = user32.NewProc("SetFocus")
)
func areaWndProc(unused *sysData) func(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT {
return func(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT {
func areaWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT {
s := getSysData(hwnd)
if s == nil { // not yet saved
return storeSysData(hwnd, uMsg, wParam, lParam)
@ -711,36 +704,22 @@ func areaWndProc(unused *sysData) func(hwnd _HWND, uMsg uint32, wParam _WPARAM,
}
panic(fmt.Sprintf("areaWndProc message %d did not return: internal bug in ui library", uMsg))
}
}
func registerAreaWndClass(s *sysData) (newClassName string, err error) {
areaWndClassNumLock.Lock()
newClassName = fmt.Sprintf(areaWndClassFormat, areaWndClassNum)
areaWndClassNum++
areaWndClassNumLock.Unlock()
func registerAreaWndClass() (err error) {
wc := &_WNDCLASS{
style: _CS_HREDRAW | _CS_VREDRAW, // no CS_DBLCLKS because do that manually
lpszClassName: uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(newClassName))),
lpfnWndProc: syscall.NewCallback(areaWndProc(s)),
lpszClassName: uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(areaWndClass))),
lpfnWndProc: syscall.NewCallback(areaWndProc),
hInstance: hInstance,
hIcon: icon,
hCursor: cursor,
hbrBackground: _HBRUSH(_NULL), // no brush; we handle WM_ERASEBKGND
}
ret := make(chan uiret)
defer close(ret)
uitask <- &uimsg{
call: _registerClass,
p: []uintptr{uintptr(unsafe.Pointer(wc))},
ret: ret,
r1, _, err := _registerClass.Call(uintptr(unsafe.Pointer(wc)))
if r1 == 0 { // failure
return err
}
r := <-ret
if r.ret == 0 { // failure
return "", r.err
}
return newClassName, nil
return nil
}
type _BITMAPINFO struct {

View File

@ -69,6 +69,10 @@ func doWindowsInit() (err error) {
if err != nil {
return fmt.Errorf("error registering standard window class (for Window): %v", err)
}
err = registerAreaWndClass()
if err != nil {
return fmt.Errorf("error registering Area window class: %v", err)
}
err = getStandardWindowFonts()
if err != nil {
return fmt.Errorf("error getting standard window fonts: %v", err)

View File

@ -113,7 +113,7 @@ var classTypes = [nctypes]*classData{
doNotLoadFont: true,
},
c_area: &classData{
register: registerAreaWndClass,
name: areaWndClass,
style: areastyle,
xstyle: areaxstyle,
storeSysData: true,