summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-08-15 22:56:55 -0400
committerPietro Gagliardi <[email protected]>2014-08-15 22:56:55 -0400
commit5531866fed831b29d807e4c56a4c5526a340eb24 (patch)
tree1993dae3aaa0dae409f646490418cbd1a1f1536b
parentc5ee8c62da7200ceb66535cdee11bf338dcec58a (diff)
Added Group on Windows.
-rw-r--r--redo/container_windows.go13
-rw-r--r--redo/group_windows.go82
2 files changed, 95 insertions, 0 deletions
diff --git a/redo/container_windows.go b/redo/container_windows.go
index c782c38..e1470cc 100644
--- a/redo/container_windows.go
+++ b/redo/container_windows.go
@@ -15,6 +15,7 @@ type container struct {
containerbase
hwnd C.HWND
nchildren int
+ isGroup bool
}
type sizing struct {
@@ -104,6 +105,11 @@ func fromdlgunitsY(du int, d *sizing) int {
const (
marginDialogUnits = 7
paddingDialogUnits = 4
+
+ groupXMargin = 6
+ // TODO
+ groupYMarginTop = 11 // note this value /includes the groupbox label/
+ groupYMarginBottom = 7
)
func (c *container) beginResize() (d *sizing) {
@@ -123,6 +129,13 @@ func (c *container) beginResize() (d *sizing) {
d.xpadding = fromdlgunitsX(paddingDialogUnits, d)
d.ypadding = fromdlgunitsY(paddingDialogUnits, d)
}
+ if c.isGroup {
+ // note that these values apply regardless of whether or not spaced is set
+ // this is because Windows groupboxes have the client rect spanning the entire size of the control, not just the active work area
+ // the measurements Microsoft give us are for spaced margining; let's just use them
+ d.xmargin = fromdlgunitsX(groupXMargin, d)
+ d.ymargin = fromdlgunitsY(groupYMarginTop, d)
+ }
return d
}
diff --git a/redo/group_windows.go b/redo/group_windows.go
new file mode 100644
index 0000000..43f6fec
--- /dev/null
+++ b/redo/group_windows.go
@@ -0,0 +1,82 @@
+// 15 august 2014
+
+package ui
+
+// #include "winapi_windows.h"
+import "C"
+
+type group struct {
+ _hwnd C.HWND
+ _textlen C.LONG
+
+ *container
+}
+
+func newGroup(text string, control Control) Group {
+ hwnd := C.newControl(buttonclass,
+ C.BS_GROUPBOX,
+ 0)
+ g := &group{
+ _hwnd: hwnd,
+ container: newContainer(control),
+ }
+ g.SetText(text)
+ C.controlSetControlFont(g._hwnd)
+ g.container.setParent(g._hwnd)
+ g.container.isGroup = true
+ return g
+}
+
+func (g *group) Text() string {
+ return baseText(g)
+}
+
+func (g *group) SetText(text string) {
+ baseSetText(g, text)
+}
+
+func (g *group) hwnd() C.HWND {
+ return g._hwnd
+}
+
+func (g *group) textlen() C.LONG {
+ return g._textlen
+}
+
+func (g *group) settextlen(len C.LONG) {
+ g._textlen = len
+}
+
+func (g *group) setParent(p *controlParent) {
+ basesetParent(g, p)
+}
+
+func (g *group) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
+ return baseallocate(g, x, y, width, height, d)
+}
+
+func (g *group) preferredSize(d *sizing) (width, height int) {
+ width, height = g.child.preferredSize(d)
+ if width < int(g._textlen) { // if the text is longer, try not to truncate
+ width = int(g._textlen)
+ }
+ // the two margin constants come from container_windows.go
+ return width, height + fromdlgunitsY(groupYMarginTop, d) + fromdlgunitsY(groupYMarginBottom, d)
+}
+
+func (g *group) commitResize(c *allocation, d *sizing) {
+ var r C.RECT
+
+ // pretend that the client area of the group box only includes the actual empty space
+ // container will handle the necessary adjustments properly
+ r.left = 0
+ r.top = 0
+ r.right = C.LONG(c.width)
+ r.bottom = C.LONG(c.height)
+ g.container.move(&r)
+ basecommitResize(g, c, d)
+}
+
+func (g *group) getAuxResizeInfo(d *sizing) {
+ basegetAuxResizeInfo(g, d)
+}