summaryrefslogtreecommitdiff
path: root/redo/containers_windows.go
diff options
context:
space:
mode:
Diffstat (limited to 'redo/containers_windows.go')
-rw-r--r--redo/containers_windows.go30
1 files changed, 16 insertions, 14 deletions
diff --git a/redo/containers_windows.go b/redo/containers_windows.go
index 6398257..66f6edf 100644
--- a/redo/containers_windows.go
+++ b/redo/containers_windows.go
@@ -10,7 +10,7 @@ import (
import "C"
/*
-On Windows, container controls are just regular controls; their children have to be children of the parent window, and changing the contents of a switching container (such as a tab control) must be done manually. Mind the odd code here.
+On Windows, container controls are just regular controls; their children have to be children of the parent window, and changing the contents of a switching container (such as a tab control) must be done manually.
TODO
- make sure all tabs cannot be deselected (that is, make sure the current tab can never have index -1)
@@ -20,7 +20,7 @@ TODO
type tab struct {
*widgetbase
- tabs []Control
+ tabs []*container
}
func newTab() Tab {
@@ -38,14 +38,16 @@ func newTab() Tab {
func (t *tab) setParent(win C.HWND) {
t.widgetbase.setParent(win)
for _, c := range t.tabs {
- c.setParent(win)
+ c.child.setParent(win)
}
}
func (t *tab) Append(name string, control Control) {
- t.tabs = append(t.tabs, control)
+ c := new(container)
+ t.tabs = append(t.tabs, c)
+ c.child = control
if t.parent != nil {
- control.setParent(t.parent)
+ c.child.setParent(t.parent)
}
C.tabAppend(t.hwnd, toUTF16(name))
}
@@ -53,31 +55,31 @@ func (t *tab) Append(name string, control Control) {
//export tabChanging
func tabChanging(data unsafe.Pointer, current C.LRESULT) {
t := (*tab)(data)
- t.tabs[int(current)].containerHide()
+ t.tabs[int(current)].child.containerHide()
}
//export tabChanged
func tabChanged(data unsafe.Pointer, new C.LRESULT) {
t := (*tab)(data)
- t.tabs[int(new)].containerShow()
+ t.tabs[int(new)].child.containerShow()
}
// a tab control contains other controls; size appropriately
func (t *tab) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
var r C.RECT
- // first, append the tab control itself
- a := t.widgetbase.allocate(x, y, width, height, d)
- // now figure out what the rect for each child is
- r.left = C.LONG(x) // load rect with existing values
+ // figure out what the rect for each child is...
+ r.left = C.LONG(x) // load structure with the window's rect
r.top = C.LONG(y)
r.right = C.LONG(x + width)
r.bottom = C.LONG(y + height)
C.tabGetContentRect(t.hwnd, &r)
// and allocate
- // don't allocate to just hte current tab; allocate to all tabs!
+ // don't allocate to just the current tab; allocate to all tabs!
for _, c := range t.tabs {
- a = append(a, c.allocate(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top), d)...)
+ // because each widget is actually a child of the Window, the origin is the one we calculated above
+ c.resize(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top))
}
- return a
+ // and now allocate the tab control itself
+ return t.widgetbase.allocate(x, y, width, height, d)
}