summaryrefslogtreecommitdiff
path: root/redo
diff options
context:
space:
mode:
Diffstat (limited to 'redo')
-rw-r--r--redo/containers_unix.go62
-rw-r--r--redo/controls_unix.go4
-rw-r--r--redo/sizing.go19
-rw-r--r--redo/sizing_unix.go15
-rw-r--r--redo/window_unix.go2
5 files changed, 73 insertions, 29 deletions
diff --git a/redo/containers_unix.go b/redo/containers_unix.go
new file mode 100644
index 0000000..20d1bef
--- /dev/null
+++ b/redo/containers_unix.go
@@ -0,0 +1,62 @@
+// 25 july 2014
+
+package ui
+
+import (
+ "unsafe"
+)
+
+// #include "gtk_unix.h"
+// extern void layoutResizing(GtkWidget *, GdkRectangle *, gpointer);
+import "C"
+
+type tab struct {
+ *widgetbase
+ notebook *C.GtkNotebook
+
+ containers []*container
+ layoutws []*C.GtkWidget
+ layoutcs []*C.GtkContainer
+ layouts []*C.GtkLayout
+}
+
+func newTab() Tab {
+ widget := C.gtk_notebook_new()
+ t := &tab{
+ widgetbase: newWidget(widget),
+ notebook: (*C.GtkNotebook)(unsafe.Pointer(widget)),
+ }
+ 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)
+ c.beginResize = beginResize
+ t.containers = append(t.containers, c)
+ c.child = control
+ c.child.setParent((*C.GtkContainer)(unsafe.Pointer(layout)))
+ 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")
+ }
+}
+
+//export layoutResizing
+func layoutResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
+ c := (*container)(unsafe.Pointer(data))
+ c.resize(int(r.width), int(r.height))
+}
diff --git a/redo/controls_unix.go b/redo/controls_unix.go
index 21c01e4..4867e7d 100644
--- a/redo/controls_unix.go
+++ b/redo/controls_unix.go
@@ -120,7 +120,3 @@ func (c *checkbox) Checked() bool {
func (c *checkbox) SetChecked(checked bool) {
C.gtk_toggle_button_set_active(c.toggle, togbool(checked))
}
-
-//TODO
-func newTab() Tab{return newButton("tab")}
-func(*button)Append(string,Control){}
diff --git a/redo/sizing.go b/redo/sizing.go
index 5bf1e84..0db6216 100644
--- a/redo/sizing.go
+++ b/redo/sizing.go
@@ -18,14 +18,6 @@ type sizingbase struct {
ypadding int
}
-// this ensures that all *windows across all platforms contain the necessary functions
-// if this fails to compile, we have a problem
-var windowSizeEnsure interface {
- beginResize() *sizing
- endResize(*sizing)
- translateAllocationCoords([]*allocation, int, int)
-} = &window{}
-
type controlSizing interface {
allocate(x int, y int, width int, height int, d *sizing) []*allocation
preferredSize(*sizing) (int, int)
@@ -33,8 +25,8 @@ type controlSizing interface {
getAuxResizeInfo(*sizing)
}
-// on Windows, this is only embedded by window, as all other containers cannot have their own children
-// on GTK+ and Mac OS X, one is embedded by window and all containers; the containers call container.continueResize()
+// on Windows, this is only embedded by window, as all other containers cannot have their own children; beginResize() points to an instance method literal (TODO get correct term) from window
+// on GTK+ and Mac OS X, one is embedded by window and all containers; beginResize() points to a global function (TODO NOT GOOD; ideally the sizing data should be passed across size-allocate requests)
type container struct {
child Control
spaced bool
@@ -46,13 +38,6 @@ func (c *container) resize(width, height int) {
return
}
d := c.beginResize()
- c.continueResize(width, height, d)
-}
-
-func (c *container) continueResize(width, height int, d *sizing) {
- if c.child == nil { // no children; nothing to do
- return
- }
allocations := c.child.allocate(0, 0, width, height, d)
c.translateAllocationCoords(allocations, width, height)
// move in reverse so as to approximate right->left order so neighbors make sense
diff --git a/redo/sizing_unix.go b/redo/sizing_unix.go
index 5b19f9e..2180b8d 100644
--- a/redo/sizing_unix.go
+++ b/redo/sizing_unix.go
@@ -24,14 +24,15 @@ const (
gtkYPadding = 6
)
-func (w *window) beginResize() (d *sizing) {
+func beginResize() (d *sizing) {
d = new(sizing)
- if w.spaced {
- d.xmargin = gtkXMargin
- d.ymargin = gtkYMargin
- d.xpadding = gtkXPadding
- d.ypadding = gtkYPadding
- }
+//TODO
+// if w.spaced {
+// d.xmargin = gtkXMargin
+// d.ymargin = gtkYMargin
+// d.xpadding = gtkXPadding
+// d.ypadding = gtkYPadding
+// }
return d
}
diff --git a/redo/window_unix.go b/redo/window_unix.go
index 6ab68b1..736ad7e 100644
--- a/redo/window_unix.go
+++ b/redo/window_unix.go
@@ -49,7 +49,7 @@ func newWindow(title string, width int, height int, control Control) *window {
closing: newEvent(),
container: new(container),
}
- w.container.beginResize = w.beginResize
+ w.container.beginResize = beginResize
C.gtk_window_set_title(w.window, ctitle)
g_signal_connect(
C.gpointer(unsafe.Pointer(w.window)),