Set up the Control restructure and migrated the Windows implementation over. Lots of repetition, but hopefully more correct and maintainable!
This commit is contained in:
parent
585f5f5b62
commit
1aea308645
|
@ -16,9 +16,9 @@ type button struct {
|
||||||
|
|
||||||
var buttonclass = toUTF16("BUTTON")
|
var buttonclass = toUTF16("BUTTON")
|
||||||
|
|
||||||
func startNewButton(text string, style C.DWORD) *button {
|
func newButton(text string) *button {
|
||||||
c := newControl(buttonclass,
|
c := newControl(buttonclass,
|
||||||
style | C.WS_TABSTOP,
|
C.BS_PUSHBUTTON | C.WS_TABSTOP,
|
||||||
0)
|
0)
|
||||||
c.setText(text)
|
c.setText(text)
|
||||||
C.controlSetControlFont(c.hwnd)
|
C.controlSetControlFont(c.hwnd)
|
||||||
|
@ -26,13 +26,7 @@ func startNewButton(text string, style C.DWORD) *button {
|
||||||
controlbase: c,
|
controlbase: c,
|
||||||
clicked: newEvent(),
|
clicked: newEvent(),
|
||||||
}
|
}
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
func newButton(text string) *button {
|
|
||||||
b := startNewButton(text, C.BS_PUSHBUTTON)
|
|
||||||
C.setButtonSubclass(b.hwnd, unsafe.Pointer(b))
|
C.setButtonSubclass(b.hwnd, unsafe.Pointer(b))
|
||||||
b.fpreferredSize = b.buttonpreferredSize
|
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,13 +49,29 @@ func buttonClicked(data unsafe.Pointer) {
|
||||||
println("button clicked")
|
println("button clicked")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *button) setParent(p *controlParent) {
|
||||||
|
basesetParent(b.controlbase, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *button) containerShow() {
|
||||||
|
basecontainerShow(b.controlbase)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *button) containerHide() {
|
||||||
|
basecontainerHide(b.controlbase)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *button) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
||||||
|
return baseallocate(b, x, y, width, height, d)
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
||||||
buttonHeight = 14
|
buttonHeight = 14
|
||||||
)
|
)
|
||||||
|
|
||||||
func (b *button) buttonpreferredSize(d *sizing) (width, height int) {
|
func (b *button) preferredSize(d *sizing) (width, height int) {
|
||||||
// common controls 6 thankfully provides a method to grab this...
|
// comctl32.dll version 6 thankfully provides a method to grab this...
|
||||||
var size C.SIZE
|
var size C.SIZE
|
||||||
|
|
||||||
size.cx = 0 // explicitly ask for ideal size
|
size.cx = 0 // explicitly ask for ideal size
|
||||||
|
@ -75,3 +85,11 @@ println("message failed; falling back")
|
||||||
xmargins := 2 * int(C.GetSystemMetrics(C.SM_CXEDGE))
|
xmargins := 2 * int(C.GetSystemMetrics(C.SM_CXEDGE))
|
||||||
return xmargins + int(b.textlen), fromdlgunitsY(buttonHeight, d)
|
return xmargins + int(b.textlen), fromdlgunitsY(buttonHeight, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *button) commitResize(a *allocation, d *sizing) {
|
||||||
|
basecommitResize(b.controlbase, a, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *button) getAuxResizeInfo(d *sizing) {
|
||||||
|
basegetAuxResizeInfo(d)
|
||||||
|
}
|
||||||
|
|
|
@ -10,20 +10,38 @@ import (
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
type checkbox struct {
|
type checkbox struct {
|
||||||
*button
|
*controlbase
|
||||||
|
toggled *event
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCheckbox(text string) *checkbox {
|
func newCheckbox(text string) *checkbox {
|
||||||
c := &checkbox{
|
|
||||||
// don't use BS_AUTOCHECKBOX here because it creates problems when refocusing (see http://blogs.msdn.com/b/oldnewthing/archive/2014/05/22/10527522.aspx)
|
// don't use BS_AUTOCHECKBOX here because it creates problems when refocusing (see http://blogs.msdn.com/b/oldnewthing/archive/2014/05/22/10527522.aspx)
|
||||||
// we'll handle actually toggling the check state ourselves (see controls_windows.c)
|
// we'll handle actually toggling the check state ourselves (see controls_windows.c)
|
||||||
button: startNewButton(text, C.BS_CHECKBOX),
|
cc := newControl(buttonclass,
|
||||||
|
C.BS_CHECKBOX | C.WS_TABSTOP,
|
||||||
|
0)
|
||||||
|
cc.setText(text)
|
||||||
|
C.controlSetControlFont(cc.hwnd)
|
||||||
|
c := &checkbox{
|
||||||
|
controlbase: cc,
|
||||||
|
toggled: newEvent(),
|
||||||
}
|
}
|
||||||
c.fpreferredSize = c.checkboxpreferredSize
|
|
||||||
C.setCheckboxSubclass(c.hwnd, unsafe.Pointer(c))
|
C.setCheckboxSubclass(c.hwnd, unsafe.Pointer(c))
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *checkbox) OnToggled(e func()) {
|
||||||
|
c.toggled.set(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *checkbox) Text() string {
|
||||||
|
return c.text()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *checkbox) SetText(text string) {
|
||||||
|
c.setText(text)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *checkbox) Checked() bool {
|
func (c *checkbox) Checked() bool {
|
||||||
if C.checkboxChecked(c.hwnd) == C.FALSE {
|
if C.checkboxChecked(c.hwnd) == C.FALSE {
|
||||||
return false
|
return false
|
||||||
|
@ -42,10 +60,26 @@ func (c *checkbox) SetChecked(checked bool) {
|
||||||
//export checkboxToggled
|
//export checkboxToggled
|
||||||
func checkboxToggled(data unsafe.Pointer) {
|
func checkboxToggled(data unsafe.Pointer) {
|
||||||
c := (*checkbox)(data)
|
c := (*checkbox)(data)
|
||||||
c.clicked.fire()
|
c.toggled.fire()
|
||||||
println("checkbox toggled")
|
println("checkbox toggled")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *checkbox) setParent(p *controlParent) {
|
||||||
|
basesetParent(c.controlbase, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *checkbox) containerShow() {
|
||||||
|
basecontainerShow(c.controlbase)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *checkbox) containerHide() {
|
||||||
|
basecontainerHide(c.controlbase)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *checkbox) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
||||||
|
return baseallocate(c, x, y, width, height, d)
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
||||||
checkboxHeight = 10
|
checkboxHeight = 10
|
||||||
|
@ -53,7 +87,15 @@ const (
|
||||||
checkboxXFromLeftOfBoxToLeftOfLabel = 12
|
checkboxXFromLeftOfBoxToLeftOfLabel = 12
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *checkbox) checkboxpreferredSize(d *sizing) (width, height int) {
|
func (c *checkbox) preferredSize(d *sizing) (width, height int) {
|
||||||
return fromdlgunitsX(checkboxXFromLeftOfBoxToLeftOfLabel, d) + int(c.textlen),
|
return fromdlgunitsX(checkboxXFromLeftOfBoxToLeftOfLabel, d) + int(c.textlen),
|
||||||
fromdlgunitsY(checkboxHeight, d)
|
fromdlgunitsY(checkboxHeight, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *checkbox) commitResize(a *allocation, d *sizing) {
|
||||||
|
basecommitResize(c.controlbase, a, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *checkbox) getAuxResizeInfo(d *sizing) {
|
||||||
|
basegetAuxResizeInfo(d)
|
||||||
|
}
|
||||||
|
|
|
@ -13,51 +13,8 @@ type Control interface {
|
||||||
controlSizing
|
controlSizing
|
||||||
}
|
}
|
||||||
|
|
||||||
// All Controls on the backend (that is, everything except Stack and Grid) embed this structure, which provides the Control interface methods.
|
// this is the same across all platforms
|
||||||
// If a Control needs to override one of these functions, it assigns to the function variables.
|
func baseallocate(c Control, x int, y int, width int, height int, d *sizing) []*allocation {
|
||||||
type controldefs struct {
|
|
||||||
fsetParent func(p *controlParent)
|
|
||||||
fcontainerShow func()
|
|
||||||
fcontainerHide func()
|
|
||||||
fallocate func(x int, y int, width int, height int, d *sizing) []*allocation
|
|
||||||
fpreferredSize func(*sizing) (int, int)
|
|
||||||
fcommitResize func(*allocation, *sizing)
|
|
||||||
fgetAuxResizeInfo func(*sizing)
|
|
||||||
}
|
|
||||||
|
|
||||||
// There's no newcontroldefs() function; all defaults are set by controlbase.
|
|
||||||
|
|
||||||
func (w *controldefs) setParent(p *controlParent) {
|
|
||||||
w.fsetParent(p)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *controldefs) containerShow() {
|
|
||||||
w.fcontainerShow()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *controldefs) containerHide() {
|
|
||||||
w.fcontainerHide()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *controldefs) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
|
||||||
return w.fallocate(x, y, width, height, d)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *controldefs) preferredSize(d *sizing) (int, int) {
|
|
||||||
return w.fpreferredSize(d)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *controldefs) commitResize(c *allocation, d *sizing) {
|
|
||||||
w.fcommitResize(c, d)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *controldefs) getAuxResizeInfo(d *sizing) {
|
|
||||||
w.fgetAuxResizeInfo(d)
|
|
||||||
}
|
|
||||||
|
|
||||||
// and this is the same across all platforms
|
|
||||||
func baseallocate(c *controlbase) func(x int, y int, width int, height int, d *sizing) []*allocation {
|
|
||||||
return func(x int, y int, width int, height int, d *sizing) []*allocation {
|
|
||||||
return []*allocation{&allocation{
|
return []*allocation{&allocation{
|
||||||
x: x,
|
x: x,
|
||||||
y: y,
|
y: y,
|
||||||
|
@ -66,4 +23,3 @@ func baseallocate(c *controlbase) func(x int, y int, width int, height int, d *s
|
||||||
this: c,
|
this: c,
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ package ui
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
type controlbase struct {
|
type controlbase struct {
|
||||||
*controldefs
|
|
||||||
hwnd C.HWND
|
hwnd C.HWND
|
||||||
parent C.HWND // for Tab and Group
|
parent C.HWND // for Tab and Group
|
||||||
textlen C.LONG
|
textlen C.LONG
|
||||||
|
@ -18,28 +17,33 @@ type controlParent struct {
|
||||||
|
|
||||||
func newControl(class C.LPWSTR, style C.DWORD, extstyle C.DWORD) *controlbase {
|
func newControl(class C.LPWSTR, style C.DWORD, extstyle C.DWORD) *controlbase {
|
||||||
c := new(controlbase)
|
c := new(controlbase)
|
||||||
|
// TODO rename to newWidget
|
||||||
c.hwnd = C.newWidget(class, style, extstyle)
|
c.hwnd = C.newWidget(class, style, extstyle)
|
||||||
c.controldefs = new(controldefs)
|
return c
|
||||||
c.fsetParent = func(p *controlParent) {
|
}
|
||||||
|
|
||||||
|
func basesetParent(c *controlbase, p *controlParent) {
|
||||||
C.controlSetParent(c.hwnd, p.hwnd)
|
C.controlSetParent(c.hwnd, p.hwnd)
|
||||||
c.parent = p.hwnd
|
c.parent = p.hwnd
|
||||||
}
|
}
|
||||||
c.fcontainerShow = func() {
|
|
||||||
|
func basecontainerShow(c *controlbase) {
|
||||||
C.ShowWindow(c.hwnd, C.SW_SHOW)
|
C.ShowWindow(c.hwnd, C.SW_SHOW)
|
||||||
}
|
}
|
||||||
c.fcontainerHide = func() {
|
|
||||||
|
func basecontainerHide(c *controlbase) {
|
||||||
C.ShowWindow(c.hwnd, C.SW_HIDE)
|
C.ShowWindow(c.hwnd, C.SW_HIDE)
|
||||||
}
|
}
|
||||||
c.fallocate = baseallocate(c)
|
|
||||||
// don't specify c.fpreferredSize; it is custom on ALL controls
|
// don't specify basepreferredSize; it is custom on ALL controls
|
||||||
c.fcommitResize = func(a *allocation, d *sizing) {
|
|
||||||
|
func basecommitResize(c *controlbase, a *allocation, d *sizing) {
|
||||||
C.moveWindow(c.hwnd, C.int(a.x), C.int(a.y), C.int(a.width), C.int(a.height))
|
C.moveWindow(c.hwnd, C.int(a.x), C.int(a.y), C.int(a.width), C.int(a.height))
|
||||||
}
|
}
|
||||||
c.fgetAuxResizeInfo = func(d *sizing) {
|
|
||||||
|
func basegetAuxResizeInfo(d *sizing) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
// these are provided for convenience
|
// these are provided for convenience
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import "C"
|
||||||
type label struct {
|
type label struct {
|
||||||
*controlbase
|
*controlbase
|
||||||
standalone bool
|
standalone bool
|
||||||
supercommitResize func(c *allocation, d *sizing)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var labelclass = toUTF16("STATIC")
|
var labelclass = toUTF16("STATIC")
|
||||||
|
@ -25,9 +24,6 @@ func finishNewLabel(text string, standalone bool) *label {
|
||||||
controlbase: c,
|
controlbase: c,
|
||||||
standalone: standalone,
|
standalone: standalone,
|
||||||
}
|
}
|
||||||
l.fpreferredSize = l.labelpreferredSize
|
|
||||||
l.supercommitResize = l.fcommitResize
|
|
||||||
l.fcommitResize = l.labelcommitResize
|
|
||||||
return l
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +43,22 @@ func (l *label) SetText(text string) {
|
||||||
l.setText(text)
|
l.setText(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *label) setParent(p *controlParent) {
|
||||||
|
basesetParent(l.controlbase, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *label) containerShow() {
|
||||||
|
basecontainerShow(l.controlbase)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *label) containerHide() {
|
||||||
|
basecontainerHide(l.controlbase)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *label) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
||||||
|
return baseallocate(l, x, y, width, height, d)
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
// via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
||||||
labelHeight = 8
|
labelHeight = 8
|
||||||
|
@ -54,15 +66,19 @@ const (
|
||||||
// TODO the label is offset slightly by default...
|
// TODO the label is offset slightly by default...
|
||||||
)
|
)
|
||||||
|
|
||||||
func (l *label) labelpreferredSize(d *sizing) (width, height int) {
|
func (l *label) preferredSize(d *sizing) (width, height int) {
|
||||||
return int(l.textlen), fromdlgunitsY(labelHeight, d)
|
return int(l.textlen), fromdlgunitsY(labelHeight, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *label) labelcommitResize(c *allocation, d *sizing) {
|
func (l *label) commitResize(c *allocation, d *sizing) {
|
||||||
if !l.standalone {
|
if !l.standalone {
|
||||||
yoff := fromdlgunitsY(labelYOffset, d)
|
yoff := fromdlgunitsY(labelYOffset, d)
|
||||||
c.y += yoff
|
c.y += yoff
|
||||||
c.height -= yoff
|
c.height -= yoff
|
||||||
}
|
}
|
||||||
l.supercommitResize(c, d)
|
basecommitResize(l.controlbase, c, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *label) getAuxResizeInfo(d *sizing) {
|
||||||
|
basegetAuxResizeInfo(d)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,6 @@ TODO
|
||||||
type tab struct {
|
type tab struct {
|
||||||
*controlbase
|
*controlbase
|
||||||
tabs []*sizer
|
tabs []*sizer
|
||||||
supersetParent func(p *controlParent)
|
|
||||||
superallocate func(x int, y int, width int, height int, d *sizing) []*allocation
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTab() Tab {
|
func newTab() Tab {
|
||||||
|
@ -31,23 +29,11 @@ func newTab() Tab {
|
||||||
t := &tab{
|
t := &tab{
|
||||||
controlbase: c,
|
controlbase: c,
|
||||||
}
|
}
|
||||||
t.supersetParent = t.fsetParent
|
|
||||||
t.fsetParent = t.tabsetParent
|
|
||||||
t.fpreferredSize = t.tabpreferredSize
|
|
||||||
t.superallocate = t.fallocate
|
|
||||||
t.fallocate = t.taballocate
|
|
||||||
C.controlSetControlFont(t.hwnd)
|
C.controlSetControlFont(t.hwnd)
|
||||||
C.setTabSubclass(t.hwnd, unsafe.Pointer(t))
|
C.setTabSubclass(t.hwnd, unsafe.Pointer(t))
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tab) tabsetParent(p *controlParent) {
|
|
||||||
t.supersetParent(p)
|
|
||||||
for _, c := range t.tabs {
|
|
||||||
c.child.setParent(p)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *tab) Append(name string, control Control) {
|
func (t *tab) Append(name string, control Control) {
|
||||||
s := new(sizer)
|
s := new(sizer)
|
||||||
t.tabs = append(t.tabs, s)
|
t.tabs = append(t.tabs, s)
|
||||||
|
@ -74,7 +60,28 @@ func tabChanged(data unsafe.Pointer, new C.LRESULT) {
|
||||||
t.tabs[int(new)].child.containerShow()
|
t.tabs[int(new)].child.containerShow()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tab) tabpreferredSize(d *sizing) (width, height int) {
|
func (t *tab) setParent(p *controlParent) {
|
||||||
|
basesetParent(t.controlbase, p)
|
||||||
|
for _, c := range t.tabs {
|
||||||
|
c.child.setParent(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO actually write this
|
||||||
|
func (t *tab) containerShow() {
|
||||||
|
basecontainerShow(t.controlbase)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO actually write this
|
||||||
|
func (t *tab) containerHide() {
|
||||||
|
basecontainerHide(t.controlbase)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *tab) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
||||||
|
return baseallocate(t, x, y, width, height, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *tab) preferredSize(d *sizing) (width, height int) {
|
||||||
// TODO only consider the size of the current tab?
|
// TODO only consider the size of the current tab?
|
||||||
for _, s := range t.tabs {
|
for _, s := range t.tabs {
|
||||||
w, h := s.child.preferredSize(d)
|
w, h := s.child.preferredSize(d)
|
||||||
|
@ -89,22 +96,25 @@ func (t *tab) tabpreferredSize(d *sizing) (width, height int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// a tab control contains other controls; size appropriately
|
// a tab control contains other controls; size appropriately
|
||||||
// TODO change this to commitResize()
|
func (t *tab) commitResize(c *allocation, d *sizing) {
|
||||||
func (t *tab) taballocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
|
||||||
var r C.RECT
|
var r C.RECT
|
||||||
|
|
||||||
// figure out what the rect for each child is...
|
// figure out what the rect for each child is...
|
||||||
r.left = C.LONG(x) // load structure with the window's rect
|
r.left = C.LONG(c.x) // load structure with the window's rect
|
||||||
r.top = C.LONG(y)
|
r.top = C.LONG(c.y)
|
||||||
r.right = C.LONG(x + width)
|
r.right = C.LONG(c.x + c.width)
|
||||||
r.bottom = C.LONG(y + height)
|
r.bottom = C.LONG(c.y + c.height)
|
||||||
C.tabGetContentRect(t.hwnd, &r)
|
C.tabGetContentRect(t.hwnd, &r)
|
||||||
// and allocate
|
// and resize tabs
|
||||||
// don't allocate to just the current tab; allocate to all tabs!
|
// don't resize just the current tab; resize all tabs!
|
||||||
for _, s := range t.tabs {
|
for _, s := range t.tabs {
|
||||||
// because each widget is actually a child of the Window, the origin is the one we calculated above
|
// because each widget is actually a child of the Window, the origin is the one we calculated above
|
||||||
s.resize(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top))
|
s.resize(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top))
|
||||||
}
|
}
|
||||||
// and now allocate the tab control itself
|
// and now resize the tab control itself
|
||||||
return t.superallocate(x, y, width, height, d)
|
basecommitResize(t.controlbase, c, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *tab) getAuxResizeInfo(d *sizing) {
|
||||||
|
basegetAuxResizeInfo(d)
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table {
|
||||||
for i := 0; i < ty.NumField(); i++ {
|
for i := 0; i < ty.NumField(); i++ {
|
||||||
C.tableAppendColumn(t.hwnd, C.int(i), toUTF16(ty.Field(i).Name))
|
C.tableAppendColumn(t.hwnd, C.int(i), toUTF16(ty.Field(i).Name))
|
||||||
}
|
}
|
||||||
t.fpreferredSize = t.tablepreferredSize
|
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,16 +42,6 @@ func (t *table) Unlock() {
|
||||||
C.tableUpdate(t.hwnd, C.int(reflect.Indirect(reflect.ValueOf(t.data)).Len()))
|
C.tableUpdate(t.hwnd, C.int(reflect.Indirect(reflect.ValueOf(t.data)).Len()))
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
// from C++ Template 05 in http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx as this is the best I can do for now... (TODO see if I can reliably get item width/height from text size)
|
|
||||||
tableWidth = 183
|
|
||||||
tableHeight = 50
|
|
||||||
)
|
|
||||||
|
|
||||||
func (t *table) tablepreferredSize(d *sizing) (width, height int) {
|
|
||||||
return fromdlgunitsX(tableWidth, d), fromdlgunitsY(tableHeight, d)
|
|
||||||
}
|
|
||||||
|
|
||||||
//export tableGetCellText
|
//export tableGetCellText
|
||||||
func tableGetCellText(data unsafe.Pointer, row C.int, col C.int, str *C.LPWSTR) {
|
func tableGetCellText(data unsafe.Pointer, row C.int, col C.int, str *C.LPWSTR) {
|
||||||
t := (*table)(data)
|
t := (*table)(data)
|
||||||
|
@ -63,3 +52,37 @@ func tableGetCellText(data unsafe.Pointer, row C.int, col C.int, str *C.LPWSTR)
|
||||||
s := fmt.Sprintf("%v", datum)
|
s := fmt.Sprintf("%v", datum)
|
||||||
*str = toUTF16(s)
|
*str = toUTF16(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *table) setParent(p *controlParent) {
|
||||||
|
basesetParent(t.controlbase, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *table) containerShow() {
|
||||||
|
basecontainerShow(t.controlbase)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *table) containerHide() {
|
||||||
|
basecontainerHide(t.controlbase)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *table) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
||||||
|
return baseallocate(t, x, y, width, height, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
// from C++ Template 05 in http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx as this is the best I can do for now... (TODO see if I can reliably get item width/height from text size)
|
||||||
|
tableWidth = 183
|
||||||
|
tableHeight = 50
|
||||||
|
)
|
||||||
|
|
||||||
|
func (t *table) preferredSize(d *sizing) (width, height int) {
|
||||||
|
return fromdlgunitsX(tableWidth, d), fromdlgunitsY(tableHeight, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *table) commitResize(a *allocation, d *sizing) {
|
||||||
|
basecommitResize(t.controlbase, a, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *table) getAuxResizeInfo(d *sizing) {
|
||||||
|
basegetAuxResizeInfo(d)
|
||||||
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ func startNewTextField(style C.DWORD) *textField {
|
||||||
t := &textField{
|
t := &textField{
|
||||||
controlbase: c,
|
controlbase: c,
|
||||||
}
|
}
|
||||||
t.fpreferredSize = t.textfieldpreferredSize
|
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,12 +38,36 @@ func (t *textField) SetText(text string) {
|
||||||
t.setText(text)
|
t.setText(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *textField) setParent(p *controlParent) {
|
||||||
|
basesetParent(t.controlbase, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *textField) containerShow() {
|
||||||
|
basecontainerShow(t.controlbase)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *textField) containerHide() {
|
||||||
|
basecontainerHide(t.controlbase)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *textField) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
||||||
|
return baseallocate(t, x, y, width, height, d)
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
||||||
textfieldWidth = 107 // this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary
|
textfieldWidth = 107 // this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary
|
||||||
textfieldHeight = 14
|
textfieldHeight = 14
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *textField) textfieldpreferredSize(d *sizing) (width, height int) {
|
func (t *textField) preferredSize(d *sizing) (width, height int) {
|
||||||
return fromdlgunitsX(textfieldWidth, d), fromdlgunitsY(textfieldHeight, d)
|
return fromdlgunitsX(textfieldWidth, d), fromdlgunitsY(textfieldHeight, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *textField) commitResize(a *allocation, d *sizing) {
|
||||||
|
basecommitResize(t.controlbase, a, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *textField) getAuxResizeInfo(d *sizing) {
|
||||||
|
basegetAuxResizeInfo(d)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue