summaryrefslogtreecommitdiff
path: root/newctrl/group_windows.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-10-15 10:12:36 -0400
committerPietro Gagliardi <[email protected]>2014-10-15 10:12:36 -0400
commitaed71fa5d4c6f2c33787adbdd5288b48416734d2 (patch)
tree1cae03d6729a0055e35c4d09d5fe8c701fbb17d9 /newctrl/group_windows.go
parentb6991d9b126cba4b55793008f12b164907cf3e9f (diff)
Migrated Group on Windows over.
Diffstat (limited to 'newctrl/group_windows.go')
-rw-r--r--newctrl/group_windows.go88
1 files changed, 88 insertions, 0 deletions
diff --git a/newctrl/group_windows.go b/newctrl/group_windows.go
new file mode 100644
index 0000000..98569d6
--- /dev/null
+++ b/newctrl/group_windows.go
@@ -0,0 +1,88 @@
+// 15 august 2014
+
+package ui
+
+// #include "winapi_windows.h"
+import "C"
+
+type group struct {
+ *controlSingleHWNDWithText
+ child Control
+ margined bool
+}
+
+func newGroup(text string, control Control) Group {
+ hwnd := C.newControl(buttonclass,
+ C.BS_GROUPBOX,
+ C.WS_EX_CONTROLPARENT)
+ g := &group{
+ controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
+ child: control
+ }
+ g.fpreferredSize = g.preferredSize
+ g.fresize = g.resize
+ g.SetText(text)
+ C.controlSetControlFont(g.hwnd)
+ g.setParent(&controlParent{g.hwnd})
+ return g
+}
+
+func (g *group) Text() string {
+ return g.text()
+}
+
+func (g *group) SetText(text string) {
+ g.setText(text)
+}
+
+const (
+ groupXMargin = 6
+ groupYMarginTop = 11 // note this value /includes the groupbox label/
+ groupYMarginBottom = 7
+)
+
+func (g *group) preferredSize(d *sizing) (width, height int) {
+ var r C.RECT
+
+ width, height = g.child.preferredSize(d)
+ if width < int(g.textlen) { // if the text is longer, try not to truncate
+ width = int(g._textlen)
+ }
+ 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 {
+ // unforutnately, as mentioned above, the size of a groupbox includes the label and border
+ // 1DLU on each side should be enough to make up for that; if not, we can change it
+ // TODO make these named constants
+ marginRectDLU(&r, -1, -1, -1, -1, d)
+ } else {
+ marginRectDLU(&r, -groupYMarginTop, -groupYMarginBottom, -groupXMargin, -groupXMargin, d)
+ }
+ return int(r.right - r.left), int(r.bottom - r.top)
+}
+
+func (g *group) resize(x int, y int, width int, height int, d *sizing) {
+ // first, chain up to the container base to keep the Z-order correct
+ // TODO use a variable for this
+ g.controlSingleHWNDWithText.resize(x, y, width, height, d)
+
+ // now resize the child container
+ 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(width)
+ r.bottom = C.LONG(height)
+ if g.margined {
+ // see above
+ marginRectDLU(&r, 1, 1, 1, 1, d)
+ } else {
+ marginRectDLU(&r, groupYMarginTop, groupYMarginBottom, groupXMargin, groupXMargin, d)
+ }
+ g.child.resize(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top), d)
+}