2014-08-15 20:43:24 -05:00
|
|
|
// +build !windows,!darwin
|
|
|
|
|
|
|
|
// 15 august 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #include "gtk_unix.h"
|
|
|
|
import "C"
|
|
|
|
|
2014-10-27 14:23:52 -05:00
|
|
|
// TODO on which sides do margins get applied?
|
|
|
|
|
2014-08-15 20:43:24 -05:00
|
|
|
type group struct {
|
2014-10-18 16:03:07 -05:00
|
|
|
*controlSingleWidget
|
2014-10-02 09:05:53 -05:00
|
|
|
gcontainer *C.GtkContainer
|
|
|
|
frame *C.GtkFrame
|
2014-08-15 20:43:24 -05:00
|
|
|
|
2014-10-18 16:03:07 -05:00
|
|
|
child Control
|
|
|
|
container *container
|
2014-08-15 20:43:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func newGroup(text string, control Control) Group {
|
|
|
|
ctext := togstr(text)
|
|
|
|
defer freegstr(ctext)
|
|
|
|
widget := C.gtk_frame_new(ctext)
|
|
|
|
g := &group{
|
2014-10-18 16:03:07 -05:00
|
|
|
controlSingleWidget: newControlSingleWidget(widget),
|
2014-10-02 09:05:53 -05:00
|
|
|
gcontainer: (*C.GtkContainer)(unsafe.Pointer(widget)),
|
|
|
|
frame: (*C.GtkFrame)(unsafe.Pointer(widget)),
|
2014-10-18 16:03:07 -05:00
|
|
|
child: control,
|
2014-08-15 20:43:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// with GTK+, groupboxes by default have frames and slightly x-offset regular text
|
|
|
|
// they should have no frame and fully left-justified, bold text
|
|
|
|
var yalign C.gfloat
|
|
|
|
|
|
|
|
// preserve default y-alignment
|
|
|
|
C.gtk_frame_get_label_align(g.frame, nil, &yalign)
|
|
|
|
C.gtk_frame_set_label_align(g.frame, 0, yalign)
|
|
|
|
C.gtk_frame_set_shadow_type(g.frame, C.GTK_SHADOW_NONE)
|
|
|
|
label := (*C.GtkLabel)(unsafe.Pointer(C.gtk_frame_get_label_widget(g.frame)))
|
2014-08-28 19:00:11 -05:00
|
|
|
// this is the boldness level used by GtkPrintUnixDialog
|
|
|
|
// (it technically uses "bold" but see pango's pango-enum-types.c for the name conversion; GType is weird)
|
2014-08-15 20:43:24 -05:00
|
|
|
bold := C.pango_attr_weight_new(C.PANGO_WEIGHT_BOLD)
|
|
|
|
boldlist := C.pango_attr_list_new()
|
|
|
|
C.pango_attr_list_insert(boldlist, bold)
|
|
|
|
C.gtk_label_set_attributes(label, boldlist)
|
2014-10-02 09:05:53 -05:00
|
|
|
C.pango_attr_list_unref(boldlist) // thanks baedert in irc.gimp.net/#gtk+
|
2014-08-15 20:43:24 -05:00
|
|
|
|
2014-10-18 16:03:07 -05:00
|
|
|
g.container = newContainer()
|
|
|
|
g.child.setParent(g.container.parent())
|
2014-10-27 14:21:47 -05:00
|
|
|
g.container.resize = g.child.resize
|
|
|
|
C.gtk_container_add(g.gcontainer, g.container.widget)
|
2014-10-18 16:03:07 -05:00
|
|
|
|
2014-08-15 20:43:24 -05:00
|
|
|
return g
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *group) Text() string {
|
|
|
|
return fromgstr(C.gtk_frame_get_label(g.frame))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *group) SetText(text string) {
|
|
|
|
ctext := togstr(text)
|
|
|
|
defer freegstr(ctext)
|
|
|
|
C.gtk_frame_set_label(g.frame, ctext)
|
|
|
|
}
|
|
|
|
|
2014-10-18 16:03:07 -05:00
|
|
|
func (g *group) Margined() bool {
|
2014-10-27 14:21:47 -05:00
|
|
|
return g.container.margined
|
2014-08-15 20:43:24 -05:00
|
|
|
}
|
|
|
|
|
2014-10-18 16:03:07 -05:00
|
|
|
func (g *group) SetMargined(margined bool) {
|
2014-10-27 14:21:47 -05:00
|
|
|
g.container.margined = margined
|
2014-08-15 20:43:24 -05:00
|
|
|
}
|
|
|
|
|
2014-10-27 14:21:47 -05:00
|
|
|
// no need to override resize; the child container handles that for us
|