Integrated the custom GTK+ container. Woo! Now to do minor fixups...

This commit is contained in:
Pietro Gagliardi 2014-08-13 23:37:54 -04:00
parent 9cad7bf60b
commit de22660ae4
2 changed files with 11 additions and 25 deletions

View File

@ -33,7 +33,7 @@ static void goContainer_init(goContainer *c)
static void goContainer_dispose(GObject *obj) static void goContainer_dispose(GObject *obj)
{ {
g_ptr_array_unref(c->children); g_ptr_array_unref(GOCONTAINER(obj)->children);
G_OBJECT_CLASS(goContainer_parent_class)->dispose(obj); G_OBJECT_CLASS(goContainer_parent_class)->dispose(obj);
} }
@ -58,7 +58,7 @@ static void goContainer_remove(GtkContainer *container, GtkWidget *widget)
static void goContainer_size_allocate(GtkWidget *widget, GtkAllocation *allocation) static void goContainer_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
{ {
gtk_widget_set_allocation(widget, allocation); gtk_widget_set_allocation(widget, allocation);
containerResized(GOCONTAINER(widget)->gocontainer, allocation); containerResizing(GOCONTAINER(widget)->gocontainer, allocation);
} }
/* /*
@ -105,9 +105,9 @@ static void goContainer_class_init(goContainerClass *class)
GTK_CONTAINER_CLASS(class)->forall = goContainer_forall; GTK_CONTAINER_CLASS(class)->forall = goContainer_forall;
} }
GtkWidget *newContainer(void *gocontianer) GtkWidget *newContainer(void *gocontainer)
{ {
GoContainer *c; goContainer *c;
c = (goContainer *) g_object_new(GOCONTAINER_TYPE, NULL); c = (goContainer *) g_object_new(GOCONTAINER_TYPE, NULL);
c->gocontainer = gocontainer; c->gocontainer = gocontainer;

View File

@ -10,14 +10,12 @@ import (
) )
// #include "gtk_unix.h" // #include "gtk_unix.h"
// extern void containerResizing(GtkWidget *, GdkRectangle *, gpointer);
import "C" import "C"
type container struct { type container struct {
containerbase containerbase
layoutwidget *C.GtkWidget layoutwidget *C.GtkWidget
layoutcontainer *C.GtkContainer layoutcontainer *C.GtkContainer
layout *C.GtkLayout
} }
type sizing struct { type sizing struct {
@ -31,23 +29,12 @@ type sizing struct {
} }
func newContainer(child Control) *container { func newContainer(child Control) *container {
widget := C.gtk_layout_new(nil, nil) c := new(container)
c := &container{ widget := C.newContainer(unsafe.Pointer(c))
layoutwidget: widget, c.layoutwidget = widget
layoutcontainer: (*C.GtkContainer)(unsafe.Pointer(widget)), c.layoutcontainer = (*C.GtkContainer)(unsafe.Pointer(widget))
layout: (*C.GtkLayout)(unsafe.Pointer(widget)),
}
c.child = child c.child = child
c.child.setParent(&controlParent{c.layoutcontainer}) c.child.setParent(&controlParent{c.layoutcontainer})
// we connect to the layout's size-allocate, not to the window's configure-event
// this allows us to handle client-side decoration-based configurations (such as GTK+ on Wayland) properly
// also see basecommitResize() in control_unix.go for additional notes
// thanks to many people in irc.gimp.net/#gtk+ for help (including tristan for suggesting g_signal_connect_after())
g_signal_connect_after(
C.gpointer(unsafe.Pointer(c.layout)),
"size-allocate",
C.GCallback(C.containerResizing),
C.gpointer(unsafe.Pointer(c)))
return c return c
} }
@ -56,10 +43,9 @@ func (c *container) setParent(p *controlParent) {
} }
//export containerResizing //export containerResizing
func containerResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) { func containerResizing(data unsafe.Pointer, r *C.GtkAllocation) {
c := (*container)(unsafe.Pointer(data)) c := (*container)(data)
// the GtkLayout's coordinate system is localized, so the origin is (0, 0) c.resize(int(r.x), int(r.y), int(r.width), int(r.height))
c.resize(0, 0, int(r.width), int(r.height))
fmt.Printf("new size %d x %d\n", r.width, r.height) fmt.Printf("new size %d x %d\n", r.width, r.height)
} }