2014-08-02 00:14:09 -05:00
|
|
|
// +build !windows,!darwin
|
|
|
|
|
|
|
|
// 23 february 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #include "gtk_unix.h"
|
2014-08-04 20:08:18 -05:00
|
|
|
// extern void containerResizing(GtkWidget *, GdkRectangle *, gpointer);
|
2014-08-02 00:14:09 -05:00
|
|
|
import "C"
|
|
|
|
|
2014-08-04 20:08:18 -05:00
|
|
|
type container struct {
|
|
|
|
containerbase
|
|
|
|
layoutwidget *C.GtkWidget
|
|
|
|
layoutcontainer *C.GtkContainer
|
|
|
|
layout *C.GtkLayout
|
|
|
|
}
|
|
|
|
|
2014-08-04 21:21:58 -05:00
|
|
|
type sizing struct {
|
|
|
|
sizingbase
|
|
|
|
|
|
|
|
// for size calculations
|
|
|
|
// gtk+ needs nothing
|
|
|
|
|
|
|
|
// for the actual resizing
|
|
|
|
shouldVAlignTop bool
|
|
|
|
}
|
|
|
|
|
2014-08-04 20:08:18 -05:00
|
|
|
func newContainer(child Control) *container {
|
|
|
|
widget := C.gtk_layout_new(nil, nil)
|
|
|
|
c := &container{
|
|
|
|
layoutwidget: widget,
|
|
|
|
layoutcontainer: (*C.GtkContainer)(unsafe.Pointer(widget)),
|
|
|
|
layout: (*C.GtkLayout)(unsafe.Pointer(widget)),
|
|
|
|
}
|
|
|
|
c.child = child
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2014-08-04 21:21:58 -05:00
|
|
|
func (c *container) setParent(p *controlParent) {
|
|
|
|
C.gtk_container_add(p.c, c.layoutwidget)
|
|
|
|
}
|
|
|
|
|
2014-08-04 20:08:18 -05:00
|
|
|
//export containerResizing
|
|
|
|
func containerResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
|
|
|
|
c := (*container)(unsafe.Pointer(data))
|
|
|
|
// the GtkLayout's coordinate system is localized, so the origin is (0, 0)
|
|
|
|
c.resize(0, 0, int(r.width), int(r.height))
|
|
|
|
fmt.Printf("new size %d x %d\n", r.width, r.height)
|
|
|
|
}
|
|
|
|
|
2014-08-02 00:14:09 -05:00
|
|
|
const (
|
|
|
|
gtkXMargin = 12
|
|
|
|
gtkYMargin = 12
|
|
|
|
gtkXPadding = 12
|
|
|
|
gtkYPadding = 6
|
|
|
|
)
|
|
|
|
|
2014-08-04 20:08:18 -05:00
|
|
|
func (c *container) beginResize() (d *sizing) {
|
2014-08-02 00:14:09 -05:00
|
|
|
d = new(sizing)
|
|
|
|
if spaced {
|
|
|
|
d.xmargin = gtkXMargin
|
|
|
|
d.ymargin = gtkYMargin
|
|
|
|
d.xpadding = gtkXPadding
|
|
|
|
d.ypadding = gtkYPadding
|
|
|
|
}
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
2014-08-04 20:08:18 -05:00
|
|
|
func (c *container) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
|
2014-08-02 00:14:09 -05:00
|
|
|
// no need for coordinate conversion with gtk+
|
|
|
|
}
|