diff options
| author | Pietro Gagliardi <[email protected]> | 2014-10-18 17:03:07 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-10-18 17:03:07 -0400 |
| commit | 62048303a34f6cac733798651adb53b640e2114a (patch) | |
| tree | b03994dfe1d5cfbc94be65075f3345a45166bbef /tab_windows.go | |
| parent | 8c8b642adbed274133b6e9d975c7ca8786300d2c (diff) | |
Merged new container/sizing stuff.
Diffstat (limited to 'tab_windows.go')
| -rw-r--r-- | tab_windows.go | 75 |
1 files changed, 36 insertions, 39 deletions
diff --git a/tab_windows.go b/tab_windows.go index 05d75d0..7203166 100644 --- a/tab_windows.go +++ b/tab_windows.go @@ -12,12 +12,14 @@ import "C" /* On Windows, container controls are just regular controls that notify their parent when the user wants to do things; changing the contents of a switching container (such as a tab control) must be done manually. -We'll create a dummy window using the pre-existing Window window class for each tab page. This makes showing and hiding tabs a matter of showing and hiding one control. +We'll create a dummy window using the container window class for each tab page. This makes showing and hiding tabs a matter of showing and hiding one control. */ type tab struct { - _hwnd C.HWND - tabs []*container + *controlSingleHWND + tabs []*container + children []Control + chainresize func(x int, y int, width int, height int, d *sizing) } func newTab() Tab { @@ -25,22 +27,29 @@ func newTab() Tab { C.TCS_TOOLTIPS|C.WS_TABSTOP, 0) // don't set WS_EX_CONTROLPARENT here; see uitask_windows.c t := &tab{ - _hwnd: hwnd, + controlSingleHWND: newControlSingleHWND(hwnd), } - C.controlSetControlFont(t._hwnd) - C.setTabSubclass(t._hwnd, unsafe.Pointer(t)) + t.fpreferredSize = t.xpreferredSize + t.chainresize = t.fresize + t.fresize = t.xresize + // count tabs as 1 tab stop; the actual number of tab stops varies + C.controlSetControlFont(t.hwnd) + C.setTabSubclass(t.hwnd, unsafe.Pointer(t)) return t } +// TODO margined func (t *tab) Append(name string, control Control) { - c := newContainer(control) - c.setParent(t._hwnd) + c := newContainer() + control.setParent(&controlParent{c.hwnd}) + c.setParent(&controlParent{t.hwnd}) t.tabs = append(t.tabs, c) + t.children = append(t.children, control) // initially hide tab 1..n controls; if we don't, they'll appear over other tabs, resulting in weird behavior if len(t.tabs) != 1 { t.tabs[len(t.tabs)-1].hide() } - C.tabAppend(t._hwnd, toUTF16(name)) + C.tabAppend(t.hwnd, toUTF16(name)) } //export tabChanging @@ -61,27 +70,15 @@ func tabTabHasChildren(data unsafe.Pointer, which C.LRESULT) C.BOOL { if len(t.tabs) == 0 { // currently no tabs return C.FALSE } - if t.tabs[int(which)].nchildren > 0 { + if t.children[int(which)].nTabStops() > 0 { return C.TRUE } return C.FALSE } -func (t *tab) hwnd() C.HWND { - return t._hwnd -} - -func (t *tab) setParent(p *controlParent) { - basesetParent(t, p) -} - -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) { - for _, s := range t.tabs { - w, h := s.child.preferredSize(d) +func (t *tab) xpreferredSize(d *sizing) (width, height int) { + for _, c := range t.children { + w, h := c.preferredSize(d) if width < w { width = w } @@ -89,30 +86,30 @@ func (t *tab) preferredSize(d *sizing) (width, height int) { height = h } } - return width, height + int(C.tabGetTabHeight(t._hwnd)) + return width, height + int(C.tabGetTabHeight(t.hwnd)) } // a tab control contains other controls; size appropriately -func (t *tab) commitResize(c *allocation, d *sizing) { +func (t *tab) xresize(x int, y int, width int, height int, d *sizing) { + // first, chain up to the container base to keep the Z-order correct + t.chainresize(x, y, width, height, d) + + // now resize the children var r C.RECT // figure out what the rect for each child is... - // the tab contents are children of the tab itself, so ignore c.x and c.y, which are relative to the window! + // the tab contents are children of the tab itself, so ignore x and y, which are relative to the window! r.left = C.LONG(0) r.top = C.LONG(0) - r.right = C.LONG(c.width) - r.bottom = C.LONG(c.height) - C.tabGetContentRect(t._hwnd, &r) + r.right = C.LONG(width) + r.bottom = C.LONG(height) + C.tabGetContentRect(t.hwnd, &r) // and resize tabs // don't resize just the current tab; resize all tabs! - for _, c := range t.tabs { + for i, _ := range t.tabs { // because each widget is actually a child of the Window, the origin is the one we calculated above - c.move(&r) + t.tabs[i].resize(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top), d) + // TODO get the actual client rect + t.children[i].resize(int(0), int(0), int(r.right - r.left), int(r.bottom - r.top), d) } - // and now resize the tab control itself - basecommitResize(t, c, d) -} - -func (t *tab) getAuxResizeInfo(d *sizing) { - basegetAuxResizeInfo(t, d) } |
