2014-07-25 14:58:24 -05:00
|
|
|
// 25 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #include "winapi_windows.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
/*
|
2014-07-28 14:02:27 -05:00
|
|
|
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.
|
2014-07-25 14:58:24 -05:00
|
|
|
|
2014-08-04 12:13:59 -05:00
|
|
|
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, at the cost of having to do C.moveWindow() in tab.commitResize()... (TODO)
|
|
|
|
|
2014-07-25 14:58:24 -05:00
|
|
|
TODO
|
|
|
|
- make sure all tabs cannot be deselected (that is, make sure the current tab can never have index -1)
|
|
|
|
*/
|
|
|
|
|
|
|
|
type tab struct {
|
2014-08-03 20:52:21 -05:00
|
|
|
_hwnd C.HWND
|
2014-08-04 12:13:59 -05:00
|
|
|
tabs []*layout
|
|
|
|
parent *controlParent
|
2014-07-25 14:58:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func newTab() Tab {
|
2014-08-03 20:52:21 -05:00
|
|
|
hwnd := C.newControl(C.xWC_TABCONTROL,
|
2014-07-25 14:58:24 -05:00
|
|
|
C.TCS_TOOLTIPS | C.WS_TABSTOP,
|
|
|
|
0)
|
|
|
|
t := &tab{
|
2014-08-03 20:52:21 -05:00
|
|
|
_hwnd: hwnd,
|
2014-07-25 14:58:24 -05:00
|
|
|
}
|
2014-08-03 20:52:21 -05:00
|
|
|
C.controlSetControlFont(t._hwnd)
|
|
|
|
C.setTabSubclass(t._hwnd, unsafe.Pointer(t))
|
2014-07-25 14:58:24 -05:00
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *tab) Append(name string, control Control) {
|
2014-08-04 12:13:59 -05:00
|
|
|
l := newLayout("", 0, 0, C.TRUE, control)
|
|
|
|
t.tabs = append(t.tabs, l)
|
2014-07-25 16:34:45 -05:00
|
|
|
if t.parent != nil {
|
2014-08-04 12:13:59 -05:00
|
|
|
l.setParent(t.parent)
|
2014-07-25 14:58:24 -05:00
|
|
|
}
|
2014-07-28 20:10:13 -05:00
|
|
|
// 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 {
|
2014-08-04 12:13:59 -05:00
|
|
|
// TODO move these calls to layout itself
|
|
|
|
C.ShowWindow(t.tabs[len(t.tabs) - 1].hwnd, C.SW_HIDE)
|
2014-07-28 20:10:13 -05:00
|
|
|
}
|
2014-08-03 20:52:21 -05:00
|
|
|
C.tabAppend(t._hwnd, toUTF16(name))
|
2014-07-25 14:58:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//export tabChanging
|
|
|
|
func tabChanging(data unsafe.Pointer, current C.LRESULT) {
|
|
|
|
t := (*tab)(data)
|
2014-08-04 12:13:59 -05:00
|
|
|
C.ShowWindow(t.tabs[int(current)].hwnd, C.SW_HIDE)
|
2014-07-25 14:58:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//export tabChanged
|
|
|
|
func tabChanged(data unsafe.Pointer, new C.LRESULT) {
|
|
|
|
t := (*tab)(data)
|
2014-08-04 12:13:59 -05:00
|
|
|
C.ShowWindow(t.tabs[int(new)].hwnd, C.SW_SHOW)
|
2014-07-25 14:58:24 -05:00
|
|
|
}
|
|
|
|
|
2014-08-03 20:52:21 -05:00
|
|
|
func (t *tab) hwnd() C.HWND {
|
|
|
|
return t._hwnd
|
|
|
|
}
|
|
|
|
|
2014-08-03 08:18:35 -05:00
|
|
|
func (t *tab) setParent(p *controlParent) {
|
2014-08-03 20:52:21 -05:00
|
|
|
basesetParent(t, p)
|
2014-08-04 12:13:59 -05:00
|
|
|
for _, l := range t.tabs {
|
|
|
|
l.setParent(p)
|
2014-08-03 08:18:35 -05:00
|
|
|
}
|
2014-08-04 12:13:59 -05:00
|
|
|
t.parent = p
|
2014-08-03 08:18:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2014-08-02 11:35:36 -05:00
|
|
|
// TODO only consider the size of the current tab?
|
|
|
|
for _, s := range t.tabs {
|
|
|
|
w, h := s.child.preferredSize(d)
|
|
|
|
if width < w {
|
|
|
|
width = w
|
|
|
|
}
|
|
|
|
if height < h {
|
|
|
|
height = h
|
|
|
|
}
|
|
|
|
}
|
2014-08-03 20:52:21 -05:00
|
|
|
return width, height + int(C.tabGetTabHeight(t._hwnd))
|
2014-08-02 11:35:36 -05:00
|
|
|
}
|
|
|
|
|
2014-07-25 14:58:24 -05:00
|
|
|
// a tab control contains other controls; size appropriately
|
2014-08-03 08:18:35 -05:00
|
|
|
func (t *tab) commitResize(c *allocation, d *sizing) {
|
2014-07-25 14:58:24 -05:00
|
|
|
var r C.RECT
|
|
|
|
|
2014-07-28 14:02:27 -05:00
|
|
|
// figure out what the rect for each child is...
|
2014-08-03 08:18:35 -05:00
|
|
|
r.left = C.LONG(c.x) // load structure with the window's rect
|
|
|
|
r.top = C.LONG(c.y)
|
|
|
|
r.right = C.LONG(c.x + c.width)
|
|
|
|
r.bottom = C.LONG(c.y + c.height)
|
2014-08-03 20:52:21 -05:00
|
|
|
C.tabGetContentRect(t._hwnd, &r)
|
2014-08-03 08:18:35 -05:00
|
|
|
// and resize tabs
|
|
|
|
// don't resize just the current tab; resize all tabs!
|
2014-08-04 12:13:59 -05:00
|
|
|
for _, l := range t.tabs {
|
2014-07-28 14:02:27 -05:00
|
|
|
// because each widget is actually a child of the Window, the origin is the one we calculated above
|
2014-08-04 12:13:59 -05:00
|
|
|
// we use moveWindow() rather than calling resize() directly
|
|
|
|
// TODO
|
|
|
|
C.moveWindow(l.hwnd, C.int(r.left), C.int(r.top), C.int(r.right - r.left), C.int(r.bottom - r.top))
|
2014-07-25 14:58:24 -05:00
|
|
|
}
|
2014-08-03 08:18:35 -05:00
|
|
|
// and now resize the tab control itself
|
2014-08-03 20:52:21 -05:00
|
|
|
basecommitResize(t, c, d)
|
2014-08-03 08:18:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *tab) getAuxResizeInfo(d *sizing) {
|
2014-08-03 19:42:45 -05:00
|
|
|
basegetAuxResizeInfo(t, d)
|
2014-07-25 14:58:24 -05:00
|
|
|
}
|