2014-07-25 22:11:41 -05:00
|
|
|
// +build !windows,!darwin
|
|
|
|
|
2014-07-25 19:47:08 -05:00
|
|
|
// 25 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #include "gtk_unix.h"
|
|
|
|
// extern void layoutResizing(GtkWidget *, GdkRectangle *, gpointer);
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type tab struct {
|
2014-07-30 09:21:23 -05:00
|
|
|
*controlbase
|
2014-07-25 19:47:08 -05:00
|
|
|
notebook *C.GtkNotebook
|
|
|
|
|
|
|
|
containers []*container
|
|
|
|
layoutws []*C.GtkWidget
|
|
|
|
layoutcs []*C.GtkContainer
|
|
|
|
layouts []*C.GtkLayout
|
|
|
|
}
|
|
|
|
|
|
|
|
func newTab() Tab {
|
|
|
|
widget := C.gtk_notebook_new()
|
|
|
|
t := &tab{
|
2014-07-30 09:21:23 -05:00
|
|
|
controlbase: newControl(widget),
|
2014-07-25 19:47:08 -05:00
|
|
|
notebook: (*C.GtkNotebook)(unsafe.Pointer(widget)),
|
|
|
|
}
|
2014-07-28 12:18:03 -05:00
|
|
|
// there are no scrolling arrows by default; add them in case there are too many tabs
|
|
|
|
C.gtk_notebook_set_scrollable(t.notebook, C.TRUE)
|
2014-07-25 19:47:08 -05:00
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *tab) Append(name string, control Control) {
|
|
|
|
// TODO isolate and standardize
|
|
|
|
layout := C.gtk_layout_new(nil, nil)
|
|
|
|
t.layoutws = append(t.layoutws, layout)
|
|
|
|
t.layoutcs = append(t.layoutcs, (*C.GtkContainer)(unsafe.Pointer(layout)))
|
|
|
|
t.layouts = append(t.layouts, (*C.GtkLayout)(unsafe.Pointer(layout)))
|
|
|
|
c := new(container)
|
|
|
|
t.containers = append(t.containers, c)
|
|
|
|
c.child = control
|
2014-07-29 22:01:28 -05:00
|
|
|
c.child.setParent(&controlParent{(*C.GtkContainer)(unsafe.Pointer(layout))})
|
2014-07-25 19:47:08 -05:00
|
|
|
g_signal_connect_after(
|
|
|
|
C.gpointer(unsafe.Pointer(layout)),
|
|
|
|
"size-allocate",
|
|
|
|
C.GCallback(C.layoutResizing),
|
|
|
|
C.gpointer(unsafe.Pointer(c)))
|
|
|
|
cname := togstr(name)
|
|
|
|
defer freegstr(cname)
|
|
|
|
tab := C.gtk_notebook_append_page(t.notebook,
|
|
|
|
layout,
|
|
|
|
C.gtk_label_new(cname))
|
|
|
|
if tab == -1 {
|
|
|
|
panic("gtk_notebook_append_page() failed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-30 09:21:23 -05:00
|
|
|
// no need to override Control.allocate() as only prepared the tabbed control; its children will be reallocated when that one is resized
|
2014-07-25 21:13:09 -05:00
|
|
|
|
2014-07-25 19:47:08 -05:00
|
|
|
//export layoutResizing
|
|
|
|
func layoutResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
|
|
|
|
c := (*container)(unsafe.Pointer(data))
|
2014-07-28 14:02:27 -05:00
|
|
|
// the layout's coordinate system is localized, so the origin is (0, 0)
|
|
|
|
c.resize(0, 0, int(r.width), int(r.height))
|
2014-07-25 19:47:08 -05:00
|
|
|
}
|