diff --git a/redo/basicctrls_windows.go b/redo/basicctrls_windows.go index ef16825..1099a19 100644 --- a/redo/basicctrls_windows.go +++ b/redo/basicctrls_windows.go @@ -173,7 +173,7 @@ const ( func (l *label) labelcommitResize(c *allocation, d *sizing) { if !l.standalone { - yoff := int(C.MulDiv(C.int(labelYOffset), C.int(d.baseY), 8)) + yoff := fromdlgunitsY(labelYOffset, d) c.y += yoff c.height -= yoff } diff --git a/redo/control_windows.go b/redo/control_windows.go index a2c55e2..3fdec5d 100644 --- a/redo/control_windows.go +++ b/redo/control_windows.go @@ -9,6 +9,7 @@ type controlbase struct { *controldefs hwnd C.HWND parent C.HWND // for Tab and Group + textlen C.LONG } type controlParent struct { @@ -50,5 +51,7 @@ func (c *controlbase) text() string { } func (c *controlbase) setText(text string) { - C.setWindowText(c.hwnd, toUTF16(text)) + t := toUTF16(text) + C.setWindowText(c.hwnd, t) + c.textlen = C.controlTextLength(c.hwnd, t) } diff --git a/redo/sizing_windows.go b/redo/sizing_windows.go index 2404aea..127bb85 100644 --- a/redo/sizing_windows.go +++ b/redo/sizing_windows.go @@ -9,13 +9,25 @@ type sizing struct { sizingbase // for size calculations - baseX int - baseY int + baseX C.int + baseY C.int // for the actual resizing // possibly the HDWP } +// note on MulDiv(): +// div will not be 0 in the usages below +// we also ignore overflow; that isn't likely to happen for our use case anytime soon + +func fromdlgunitsX(du int, d *sizing) int { + return int(C.MulDiv(C.int(du), d.baseX, 4)) +} + +func fromdlgunitsY(du int, d *sizing) int { + return int(C.MulDiv(C.int(du), d.baseY, 8)) +} + const ( marginDialogUnits = 7 paddingDialogUnits = 4 @@ -24,14 +36,14 @@ const ( func (c *container) beginResize() (d *sizing) { d = new(sizing) - d.baseX = int(C.baseX) - d.baseY = int(C.baseY) + d.baseX = C.baseX + d.baseY = C.baseY if spaced { - d.xmargin = int(C.MulDiv(marginDialogUnits, C.int(d.baseX), 4)) - d.ymargin = int(C.MulDiv(marginDialogUnits, C.int(d.baseY), 8)) - d.xpadding = int(C.MulDiv(paddingDialogUnits, C.int(d.baseX), 4)) - d.ypadding = int(C.MulDiv(paddingDialogUnits, C.int(d.baseY), 8)) + d.xmargin = fromdlgunitsX(marginDialogUnits, d) + d.ymargin = fromdlgunitsY(marginDialogUnits, d) + d.xpadding = fromdlgunitsX(paddingDialogUnits, d) + d.ypadding = fromdlgunitsY(paddingDialogUnits, d) } return d @@ -140,12 +152,8 @@ var stdDlgSizes = [nctypes]dlgunits{ width = defaultWidth } height = stdDlgSizes[s.ctype].height - width = int(C.MulDiv(C.int(width), C.int(d.baseX), 4)) // equivalent to right of rect - height = int(C.MulDiv(C.int(height), C.int(d.baseY), 8)) // equivalent to bottom of rect + width = fromdlgunitsX(width, d) // equivalent to right of rect + height = fromdlguntisY(height, d) // equivalent to bottom of rect */ // return width, height //} - -// note on MulDiv(): -// div will not be 0 in the usages above -// we also ignore overflow; that isn't likely to happen for our use case anytime soon