2014-07-30 09:21:23 -05:00
|
|
|
// +build !windows,!darwin
|
|
|
|
|
|
|
|
// 30 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #include "gtk_unix.h"
|
|
|
|
import "C"
|
|
|
|
|
2014-08-03 15:28:21 -05:00
|
|
|
// all Controls that call base methods must be this
|
|
|
|
type controlPrivate interface {
|
|
|
|
widget() *C.GtkWidget
|
|
|
|
Control
|
2014-07-30 09:21:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type controlParent struct {
|
|
|
|
c *C.GtkContainer
|
|
|
|
}
|
|
|
|
|
2014-08-03 15:28:21 -05:00
|
|
|
func basesetParent(c controlPrivate, p *controlParent) {
|
2014-08-04 12:39:33 -05:00
|
|
|
widget := c.widget() // avoid multiple interface lookups
|
|
|
|
C.gtk_container_add(p.c, widget)
|
2014-08-03 15:28:21 -05:00
|
|
|
// make sure the new widget is shown if not explicitly hidden
|
2014-08-04 12:39:33 -05:00
|
|
|
C.gtk_widget_show_all(widget)
|
2014-08-03 15:28:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func basepreferredSize(c controlPrivate, d *sizing) (int, int) {
|
|
|
|
// GTK+ 3 makes this easy: controls can tell us what their preferred size is!
|
|
|
|
// ...actually, it tells us two things: the "minimum size" and the "natural size".
|
|
|
|
// The "minimum size" is the smallest size we /can/ display /anything/. The "natural size" is the smallest size we would /prefer/ to display.
|
|
|
|
// The difference? Minimum size takes into account things like truncation with ellipses: the minimum size of a label can allot just the ellipses!
|
|
|
|
// So we use the natural size instead.
|
|
|
|
// There is a warning about height-for-width controls, but in my tests this isn't an issue.
|
|
|
|
var r C.GtkRequisition
|
2014-07-30 09:21:23 -05:00
|
|
|
|
2014-08-03 15:28:21 -05:00
|
|
|
C.gtk_widget_get_preferred_size(c.widget(), nil, &r)
|
|
|
|
return int(r.width), int(r.height)
|
2014-07-30 09:21:23 -05:00
|
|
|
}
|
|
|
|
|
2014-08-03 15:28:21 -05:00
|
|
|
func basecommitResize(c controlPrivate, a *allocation, d *sizing) {
|
|
|
|
dobasecommitResize(c.widget(), a, d)
|
|
|
|
}
|
|
|
|
|
|
|
|
func dobasecommitResize(w *C.GtkWidget, c *allocation, d *sizing) {
|
|
|
|
// as we resize on size-allocate, we have to also use size-allocate on our children
|
|
|
|
// this is fine anyway; in fact, this allows us to move without knowing what the container is!
|
|
|
|
// this is what GtkBox does anyway
|
|
|
|
// thanks to tristan in irc.gimp.net/#gtk+
|
|
|
|
|
|
|
|
var r C.GtkAllocation
|
|
|
|
|
|
|
|
r.x = C.int(c.x)
|
|
|
|
r.y = C.int(c.y)
|
|
|
|
r.width = C.int(c.width)
|
|
|
|
r.height = C.int(c.height)
|
|
|
|
C.gtk_widget_size_allocate(w, &r)
|
|
|
|
}
|
|
|
|
|
2014-08-03 19:33:19 -05:00
|
|
|
func basegetAuxResizeInfo(c Control, d *sizing) {
|
2014-08-03 15:28:21 -05:00
|
|
|
// controls set this to true if a Label to its left should be vertically aligned to the control's top
|
|
|
|
d.shouldVAlignTop = false
|
|
|
|
}
|
|
|
|
|
|
|
|
type scroller struct {
|
|
|
|
scrollwidget *C.GtkWidget
|
2014-07-30 09:21:23 -05:00
|
|
|
scrollcontainer *C.GtkContainer
|
|
|
|
scrollwindow *C.GtkScrolledWindow
|
2014-08-22 09:52:51 -05:00
|
|
|
|
|
|
|
overlaywidget *C.GtkWidget
|
|
|
|
overlaycontainer *C.GtkContainer
|
|
|
|
overlay *C.GtkOverlay
|
|
|
|
|
|
|
|
addShowWhich *C.GtkWidget
|
2014-07-30 09:21:23 -05:00
|
|
|
}
|
|
|
|
|
2014-08-22 09:52:51 -05:00
|
|
|
func newScroller(widget *C.GtkWidget, native bool, bordered bool, overlay bool) *scroller {
|
|
|
|
var o *C.GtkWidget
|
|
|
|
|
2014-08-03 15:28:21 -05:00
|
|
|
scrollwidget := C.gtk_scrolled_window_new(nil, nil)
|
2014-08-22 09:52:51 -05:00
|
|
|
if overlay {
|
|
|
|
o = C.gtk_overlay_new()
|
|
|
|
}
|
2014-08-03 15:28:21 -05:00
|
|
|
s := &scroller{
|
|
|
|
scrollwidget: scrollwidget,
|
|
|
|
scrollcontainer: (*C.GtkContainer)(unsafe.Pointer(scrollwidget)),
|
|
|
|
scrollwindow: (*C.GtkScrolledWindow)(unsafe.Pointer(scrollwidget)),
|
2014-08-22 09:52:51 -05:00
|
|
|
overlaywidget: o,
|
|
|
|
overlaycontainer: (*C.GtkContainer)(unsafe.Pointer(o)),
|
|
|
|
overlay: (*C.GtkOverlay)(unsafe.Pointer(o)),
|
2014-07-30 09:21:23 -05:00
|
|
|
}
|
|
|
|
// give the scrolled window a border (thanks to jlindgren in irc.gimp.net/#gtk+)
|
2014-08-08 19:31:15 -05:00
|
|
|
if bordered {
|
|
|
|
C.gtk_scrolled_window_set_shadow_type(s.scrollwindow, C.GTK_SHADOW_IN)
|
|
|
|
}
|
2014-08-04 22:31:11 -05:00
|
|
|
if native {
|
|
|
|
C.gtk_container_add(s.scrollcontainer, widget)
|
|
|
|
} else {
|
|
|
|
C.gtk_scrolled_window_add_with_viewport(s.scrollwindow, widget)
|
|
|
|
}
|
2014-08-22 09:52:51 -05:00
|
|
|
s.addShowWhich = s.scrollwidget
|
|
|
|
if overlay {
|
|
|
|
C.gtk_container_add(s.overlaycontainer, s.scrollwidget)
|
|
|
|
s.addShowWhich = s.overlaywidget
|
|
|
|
}
|
2014-07-30 09:21:23 -05:00
|
|
|
return s
|
|
|
|
}
|
2014-08-03 15:28:21 -05:00
|
|
|
|
|
|
|
func (s *scroller) setParent(p *controlParent) {
|
2014-08-22 09:52:51 -05:00
|
|
|
C.gtk_container_add(p.c, s.addShowWhich)
|
2014-08-04 12:39:33 -05:00
|
|
|
// see basesetParent() above for why we call gtk_widget_show_all()
|
2014-08-22 09:52:51 -05:00
|
|
|
C.gtk_widget_show_all(s.addShowWhich)
|
2014-08-03 15:28:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *scroller) commitResize(c *allocation, d *sizing) {
|
2014-08-22 09:52:51 -05:00
|
|
|
dobasecommitResize(s.addShowWhich, c, d)
|
2014-08-03 15:28:21 -05:00
|
|
|
}
|