2014-08-15 21:56:55 -05:00
|
|
|
// 15 august 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
2014-10-27 09:41:10 -05:00
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2014-08-15 21:56:55 -05:00
|
|
|
// #include "winapi_windows.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
type group struct {
|
2014-10-18 16:03:07 -05:00
|
|
|
*controlSingleHWNDWithText
|
|
|
|
child Control
|
|
|
|
margined bool
|
2014-08-15 21:56:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func newGroup(text string, control Control) Group {
|
|
|
|
hwnd := C.newControl(buttonclass,
|
|
|
|
C.BS_GROUPBOX,
|
2014-08-28 10:17:44 -05:00
|
|
|
C.WS_EX_CONTROLPARENT)
|
2014-08-15 21:56:55 -05:00
|
|
|
g := &group{
|
2014-10-18 16:03:07 -05:00
|
|
|
controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
|
|
|
|
child: control,
|
2014-08-15 21:56:55 -05:00
|
|
|
}
|
2014-10-18 16:03:07 -05:00
|
|
|
g.fpreferredSize = g.xpreferredSize
|
|
|
|
g.fnTabStops = control.nTabStops // groupbox itself is not tabbable but the contents might be
|
2014-08-15 21:56:55 -05:00
|
|
|
g.SetText(text)
|
2014-10-18 16:03:07 -05:00
|
|
|
C.controlSetControlFont(g.hwnd)
|
2014-10-27 09:41:10 -05:00
|
|
|
C.setGroupSubclass(g.hwnd, unsafe.Pointer(g))
|
2014-10-18 16:03:07 -05:00
|
|
|
control.setParent(&controlParent{g.hwnd})
|
2014-08-15 21:56:55 -05:00
|
|
|
return g
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *group) Text() string {
|
2014-10-18 16:03:07 -05:00
|
|
|
return g.text()
|
2014-08-15 21:56:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (g *group) SetText(text string) {
|
2014-10-18 16:03:07 -05:00
|
|
|
g.setText(text)
|
2014-08-15 21:56:55 -05:00
|
|
|
}
|
|
|
|
|
2014-10-18 16:03:07 -05:00
|
|
|
func (g *group) Margined() bool {
|
|
|
|
return g.margined
|
2014-08-15 21:56:55 -05:00
|
|
|
}
|
|
|
|
|
2014-10-18 16:03:07 -05:00
|
|
|
func (g *group) SetMargined(margined bool) {
|
|
|
|
g.margined = margined
|
2014-08-15 21:56:55 -05:00
|
|
|
}
|
|
|
|
|
2014-10-18 16:03:07 -05:00
|
|
|
const (
|
|
|
|
groupXMargin = 6
|
|
|
|
groupYMarginTop = 11 // note this value /includes the groupbox label/
|
|
|
|
groupYMarginBottom = 7
|
|
|
|
)
|
2014-08-15 21:56:55 -05:00
|
|
|
|
2014-10-18 16:03:07 -05:00
|
|
|
func (g *group) xpreferredSize(d *sizing) (width, height int) {
|
|
|
|
var r C.RECT
|
2014-08-15 21:56:55 -05:00
|
|
|
|
|
|
|
width, height = g.child.preferredSize(d)
|
2014-10-18 16:03:07 -05:00
|
|
|
if width < int(g.textlen) { // if the text is longer, try not to truncate
|
|
|
|
width = int(g.textlen)
|
2014-08-15 21:56:55 -05:00
|
|
|
}
|
2014-10-18 16:03:07 -05:00
|
|
|
r.left = 0
|
|
|
|
r.top = 0
|
|
|
|
r.right = C.LONG(width)
|
|
|
|
r.bottom = C.LONG(height)
|
|
|
|
// use negative numbers to increase the size of the rectangle
|
|
|
|
if g.margined {
|
|
|
|
marginRectDLU(&r, -groupYMarginTop, -groupYMarginBottom, -groupXMargin, -groupXMargin, d)
|
|
|
|
} else {
|
|
|
|
// unforutnately, as mentioned above, the size of a groupbox includes the label and border
|
2014-10-25 22:28:24 -05:00
|
|
|
// 1 character cell (4DLU x, 8DLU y) on each side (but only 3DLU on the bottom) should be enough to make up for that; TODO is not, we can change it
|
2014-10-18 16:03:07 -05:00
|
|
|
// TODO make these named constants
|
2014-10-25 22:28:24 -05:00
|
|
|
marginRectDLU(&r, -8, -3, -4, -4, d)
|
2014-10-18 16:03:07 -05:00
|
|
|
}
|
|
|
|
return int(r.right - r.left), int(r.bottom - r.top)
|
2014-08-15 21:56:55 -05:00
|
|
|
}
|
|
|
|
|
2014-10-27 09:41:10 -05:00
|
|
|
//export groupResized
|
|
|
|
func groupResized(data unsafe.Pointer, r C.RECT) {
|
|
|
|
g := (*group)(unsafe.Pointer(data))
|
|
|
|
d := beginResize(g.hwnd)
|
2014-10-18 16:03:07 -05:00
|
|
|
if g.margined {
|
|
|
|
// see above
|
|
|
|
marginRectDLU(&r, groupYMarginTop, groupYMarginBottom, groupXMargin, groupXMargin, d)
|
|
|
|
} else {
|
2014-10-25 22:28:24 -05:00
|
|
|
marginRectDLU(&r, 8, 3, 4, 4, d)
|
2014-10-18 16:03:07 -05:00
|
|
|
}
|
|
|
|
g.child.resize(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top), d)
|
2014-08-15 21:56:55 -05:00
|
|
|
}
|