From 515a605dda3b4054693cb31d9f4dae36a7e29720 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 4 Aug 2014 22:21:58 -0400 Subject: [PATCH] Same as three commits ago, but for the GTK+ backend. --- redo/container_unix.go | 24 ++++++++++++++---------- redo/tab_unix.go | 15 ++++++++------- redo/window_unix.go | 3 +-- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/redo/container_unix.go b/redo/container_unix.go index 964df5a..1b48fba 100644 --- a/redo/container_unix.go +++ b/redo/container_unix.go @@ -20,6 +20,16 @@ type container struct { layout *C.GtkLayout } +type sizing struct { + sizingbase + + // for size calculations + // gtk+ needs nothing + + // for the actual resizing + shouldVAlignTop bool +} + func newContainer(child Control) *container { widget := C.gtk_layout_new(nil, nil) c := &container{ @@ -41,6 +51,10 @@ func newContainer(child Control) *container { return c } +func (c *container) setParent(p *controlParent) { + C.gtk_container_add(p.c, c.layoutwidget) +} + //export containerResizing func containerResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) { c := (*container)(unsafe.Pointer(data)) @@ -49,16 +63,6 @@ func containerResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) { fmt.Printf("new size %d x %d\n", r.width, r.height) } -type sizing struct { - sizingbase - - // for size calculations - // gtk+ needs nothing - - // for the actual resizing - shouldVAlignTop bool -} - const ( gtkXMargin = 12 gtkYMargin = 12 diff --git a/redo/tab_unix.go b/redo/tab_unix.go index e815935..c73796f 100644 --- a/redo/tab_unix.go +++ b/redo/tab_unix.go @@ -13,6 +13,7 @@ import "C" type tab struct { _widget *C.GtkWidget + container *C.GtkContainer notebook *C.GtkNotebook tabs []*container @@ -22,6 +23,7 @@ func newTab() Tab { widget := C.gtk_notebook_new() t := &tab{ _widget: widget, + container: (*C.GtkContainer)(unsafe.Pointer(widget)), notebook: (*C.GtkNotebook)(unsafe.Pointer(widget)), } // there are no scrolling arrows by default; add them in case there are too many tabs @@ -32,15 +34,14 @@ func newTab() Tab { func (t *tab) Append(name string, control Control) { c := newContainer(control) t.tabs = append(t.tabs, c) + // this calls gtk_container_add(), which, according to gregier in irc.gimp.net/#gtk+, acts just like gtk_notebook_append_page() + c.setParent(&controlParent{t.container}) cname := togstr(name) defer freegstr(cname) - tab := C.gtk_notebook_append_page(t.notebook, - // TODO figure out how to keep this private - c.layoutwidget, - C.gtk_label_new(cname)) - if tab == -1 { - panic("gtk_notebook_append_page() failed") - } + C.gtk_notebook_set_tab_label_text(t.notebook, + // unfortunately there does not seem to be a gtk_notebook_set_nth_tab_label_text() + C.gtk_notebook_get_nth_page(t.notebook, C.gint(len(t.tabs) - 1)), + cname) } func (t *tab) widget() *C.GtkWidget { diff --git a/redo/window_unix.go b/redo/window_unix.go index e798443..7a5cc16 100644 --- a/redo/window_unix.go +++ b/redo/window_unix.go @@ -42,8 +42,7 @@ func newWindow(title string, width int, height int, control Control) *window { C.gpointer(unsafe.Pointer(w))) C.gtk_window_resize(w.window, C.gint(width), C.gint(height)) w.container = newContainer(control) - // TODO make a method of container? because this would conflict with tabs... - C.gtk_container_add(w.wc, w.container.layoutwidget) + w.container.setParent(&controlParent{w.wc}) return w }