Made the new sizing system work on Windows.
This commit is contained in:
parent
9a3e73b460
commit
1eeadc000a
4
area.go
4
area.go
|
@ -350,8 +350,8 @@ func (a *Area) preferredSize(d *sysSizeData) (width int, height int) {
|
||||||
return a.sysData.preferredSize(d)
|
return a.sysData.preferredSize(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Area) commitResize(a *allocation, d *sysSizeData) {
|
func (a *Area) commitResize(c *allocation, d *sysSizeData) {
|
||||||
a.sysData.preferredSize(a, d)
|
a.sysData.commitResize(c, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Area) getAuxResizeInfo(d *sysSizeData) {
|
func (a *Area) getAuxResizeInfo(d *sysSizeData) {
|
||||||
|
|
|
@ -80,7 +80,7 @@ func (b *Button) preferredSize(d *sysSizeData) (width int, height int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Button) commitResize(a *allocation, d *sysSizeData) {
|
func (b *Button) commitResize(a *allocation, d *sysSizeData) {
|
||||||
b.sysData.preferredSize(a, d)
|
b.sysData.commitResize(a, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Button) getAuxResizeInfo(d *sysSizeData) {
|
func (b *Button) getAuxResizeInfo(d *sysSizeData) {
|
||||||
|
|
|
@ -85,7 +85,7 @@ func (c *Checkbox) preferredSize(d *sysSizeData) (width int, height int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Checkbox) commitResize(a *allocation, d *sysSizeData) {
|
func (c *Checkbox) commitResize(a *allocation, d *sysSizeData) {
|
||||||
c.sysData.preferredSize(a, d)
|
c.sysData.commitResize(a, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Checkbox) getAuxResizeInfo(d *sysSizeData) {
|
func (c *Checkbox) getAuxResizeInfo(d *sysSizeData) {
|
||||||
|
|
|
@ -162,7 +162,7 @@ func (c *Combobox) preferredSize(d *sysSizeData) (width int, height int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Combobox) commitResize(a *allocation, d *sysSizeData) {
|
func (c *Combobox) commitResize(a *allocation, d *sysSizeData) {
|
||||||
c.sysData.preferredSize(a, d)
|
c.sysData.commitResize(a, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Combobox) getAuxResizeInfo(d *sysSizeData) {
|
func (c *Combobox) getAuxResizeInfo(d *sysSizeData) {
|
||||||
|
|
|
@ -19,7 +19,7 @@ type cSysSizeData struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// for verification; see sysdata.go
|
// for verification; see sysdata.go
|
||||||
type sysDataSizeFuncs interface {
|
type sysDataSizingFunctions interface {
|
||||||
beginResize() *sysSizeData
|
beginResize() *sysSizeData
|
||||||
endResize(*sysSizeData)
|
endResize(*sysSizeData)
|
||||||
translateAllocationCoords([]*allocation, int, int)
|
translateAllocationCoords([]*allocation, int, int)
|
||||||
|
@ -32,7 +32,7 @@ func (s *sysData) resizeWindow(width, height int) {
|
||||||
d := s.beginResize()
|
d := s.beginResize()
|
||||||
allocations := s.allocate(0, 0, width, height, d)
|
allocations := s.allocate(0, 0, width, height, d)
|
||||||
s.translateAllocationCoords(allocations, width, height)
|
s.translateAllocationCoords(allocations, width, height)
|
||||||
for _, c := range s.allocations {
|
for _, c := range allocations {
|
||||||
c.this.commitResize(c, d)
|
c.this.commitResize(c, d)
|
||||||
}
|
}
|
||||||
s.endResize(d)
|
s.endResize(d)
|
||||||
|
|
|
@ -21,15 +21,17 @@ type sysSizeData struct {
|
||||||
const (
|
const (
|
||||||
marginDialogUnits = 7
|
marginDialogUnits = 7
|
||||||
paddingDialogUnits = 4
|
paddingDialogUnits = 4
|
||||||
}
|
)
|
||||||
|
|
||||||
func (s *sysData) beginResize() (d *sysSizeData) {
|
func (s *sysData) beginResize() (d *sysSizeData) {
|
||||||
d = new(sysSizeData)
|
d = new(sysSizeData)
|
||||||
|
|
||||||
dc := getTextDC(s.hwnd)
|
dc := getTextDC(s.hwnd)
|
||||||
defer releaseTextDC(dc)
|
defer releaseTextDC(s.hwnd, dc)
|
||||||
|
|
||||||
r1, _, err = _getTextMetrics.Call(
|
var tm _TEXTMETRICS
|
||||||
|
|
||||||
|
r1, _, err := _getTextMetrics.Call(
|
||||||
uintptr(dc),
|
uintptr(dc),
|
||||||
uintptr(unsafe.Pointer(&tm)))
|
uintptr(unsafe.Pointer(&tm)))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
|
@ -66,7 +68,7 @@ func (s *sysData) commitResize(c *allocation, d *sysSizeData) {
|
||||||
}
|
}
|
||||||
c.y += yoff
|
c.y += yoff
|
||||||
// TODO move this here
|
// TODO move this here
|
||||||
s.setRect(c.x, c.y, c.width, c.height)
|
s.setRect(c.x, c.y, c.width, c.height, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *sysData) getAuxResizeInfo(d *sysSizeData) {
|
func (s *sysData) getAuxResizeInfo(d *sysSizeData) {
|
||||||
|
@ -150,8 +152,6 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func getTextDC(hwnd _HWND) (dc _HANDLE) {
|
func getTextDC(hwnd _HWND) (dc _HANDLE) {
|
||||||
var tm _TEXTMETRICS
|
|
||||||
|
|
||||||
r1, _, err := _getDC.Call(uintptr(hwnd))
|
r1, _, err := _getDC.Call(uintptr(hwnd))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
panic(fmt.Errorf("error getting DC for preferred size calculations: %v", err))
|
panic(fmt.Errorf("error getting DC for preferred size calculations: %v", err))
|
||||||
|
@ -167,7 +167,7 @@ func getTextDC(hwnd _HWND) (dc _HANDLE) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func releaseTextDC(hwnd _HWND, dc _HANDLE) {
|
func releaseTextDC(hwnd _HWND, dc _HANDLE) {
|
||||||
r1, _, err = _releaseDC.Call(
|
r1, _, err := _releaseDC.Call(
|
||||||
uintptr(hwnd),
|
uintptr(hwnd),
|
||||||
uintptr(dc))
|
uintptr(dc))
|
||||||
if r1 == 0 { // failure
|
if r1 == 0 { // failure
|
||||||
|
@ -179,7 +179,7 @@ func releaseTextDC(hwnd _HWND, dc _HANDLE) {
|
||||||
func (s *sysData) preferredSize(d *sysSizeData) (width int, height int) {
|
func (s *sysData) preferredSize(d *sysSizeData) (width int, height int) {
|
||||||
// the preferred size of an Area is its size
|
// the preferred size of an Area is its size
|
||||||
if stdDlgSizes[s.ctype].area {
|
if stdDlgSizes[s.ctype].area {
|
||||||
return s.areawidth, s.areaheight, 0 // no yoff for areas
|
return s.areawidth, s.areaheight
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg := stdDlgSizes[s.ctype].getsize; msg != 0 {
|
if msg := stdDlgSizes[s.ctype].getsize; msg != 0 {
|
||||||
|
@ -191,7 +191,7 @@ func (s *sysData) preferredSize(d *sysSizeData) (width int, height int) {
|
||||||
uintptr(0),
|
uintptr(0),
|
||||||
uintptr(unsafe.Pointer(&size)))
|
uintptr(unsafe.Pointer(&size)))
|
||||||
if r1 != uintptr(_FALSE) { // success
|
if r1 != uintptr(_FALSE) { // success
|
||||||
return int(size.cx), int(size.cy), 0 // TODO
|
return int(size.cx), int(size.cy)
|
||||||
}
|
}
|
||||||
// otherwise the message approach failed, so fall back to the regular approach
|
// otherwise the message approach failed, so fall back to the regular approach
|
||||||
println("message failed; falling back")
|
println("message failed; falling back")
|
||||||
|
|
2
grid.go
2
grid.go
|
@ -184,7 +184,7 @@ _=ymargin
|
||||||
w = g.colwidths[col]
|
w = g.colwidths[col]
|
||||||
h = g.rowheights[row]
|
h = g.rowheights[row]
|
||||||
}
|
}
|
||||||
as := c.allocation(x, y, w, h, d)
|
as := c.allocate(x, y, w, h, d)
|
||||||
if current != nil { // connect first left to first right
|
if current != nil { // connect first left to first right
|
||||||
current.neighbor = c
|
current.neighbor = c
|
||||||
}
|
}
|
||||||
|
|
2
label.go
2
label.go
|
@ -89,7 +89,7 @@ func (l *Label) preferredSize(d *sysSizeData) (width int, height int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Label) commitResize(a *allocation, d *sysSizeData) {
|
func (l *Label) commitResize(a *allocation, d *sysSizeData) {
|
||||||
l.sysData.preferredSize(a, d)
|
l.sysData.commitResize(a, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Label) getAuxResizeInfo(d *sysSizeData) {
|
func (l *Label) getAuxResizeInfo(d *sysSizeData) {
|
||||||
|
|
|
@ -83,7 +83,7 @@ func (l *LineEdit) preferredSize(d *sysSizeData) (width int, height int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LineEdit) commitResize(a *allocation, d *sysSizeData) {
|
func (l *LineEdit) commitResize(a *allocation, d *sysSizeData) {
|
||||||
l.sysData.preferredSize(a, d)
|
l.sysData.commitResize(a, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LineEdit) getAuxResizeInfo(d *sysSizeData) {
|
func (l *LineEdit) getAuxResizeInfo(d *sysSizeData) {
|
||||||
|
|
|
@ -165,7 +165,7 @@ func (l *Listbox) preferredSize(d *sysSizeData) (width int, height int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Listbox) commitResize(a *allocation, d *sysSizeData) {
|
func (l *Listbox) commitResize(a *allocation, d *sysSizeData) {
|
||||||
l.sysData.preferredSize(a, d)
|
l.sysData.commitResize(a, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Listbox) getAuxResizeInfo(d *sysSizeData) {
|
func (l *Listbox) getAuxResizeInfo(d *sysSizeData) {
|
||||||
|
|
|
@ -71,7 +71,7 @@ func (p *ProgressBar) preferredSize(d *sysSizeData) (width int, height int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProgressBar) commitResize(a *allocation, d *sysSizeData) {
|
func (p *ProgressBar) commitResize(a *allocation, d *sysSizeData) {
|
||||||
p.sysData.preferredSize(a, d)
|
p.sysData.commitResize(a, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProgressBar) getAuxResizeInfo(d *sysSizeData) {
|
func (p *ProgressBar) getAuxResizeInfo(d *sysSizeData) {
|
||||||
|
|
|
@ -148,7 +148,7 @@ func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESUL
|
||||||
_ = mm
|
_ = mm
|
||||||
return 0
|
return 0
|
||||||
case _WM_SIZE:
|
case _WM_SIZE:
|
||||||
if s.resize != nil {
|
if s.allocate != nil {
|
||||||
var r _RECT
|
var r _RECT
|
||||||
|
|
||||||
r1, _, err := _getClientRect.Call(
|
r1, _, err := _getClientRect.Call(
|
||||||
|
@ -157,8 +157,8 @@ func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESUL
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
panic("GetClientRect failed: " + err.Error())
|
panic("GetClientRect failed: " + err.Error())
|
||||||
}
|
}
|
||||||
// top-left corner is (0,0) so no need for winheight
|
// top-left corner of a client rect is (0,0) so no need for left/top
|
||||||
s.doResize(int(r.left), int(r.top), int(r.right-r.left), int(r.bottom-r.top), 0)
|
s.resizeWindow(int(r.right), int(r.bottom))
|
||||||
// TODO use the Defer movement functions here?
|
// TODO use the Defer movement functions here?
|
||||||
// TODO redraw window and all children here?
|
// TODO redraw window and all children here?
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ func newEvent() chan struct{} {
|
||||||
type cSysData struct {
|
type cSysData struct {
|
||||||
ctype int
|
ctype int
|
||||||
event chan struct{}
|
event chan struct{}
|
||||||
resize func(x int, y int, width int, height int, rr *[]resizerequest)
|
allocate func(x int, y int, width int, height int, d *sysSizeData) []*allocation
|
||||||
spaced bool
|
spaced bool
|
||||||
alternate bool // editable for Combobox, multi-select for listbox, password for lineedit
|
alternate bool // editable for Combobox, multi-select for listbox, password for lineedit
|
||||||
handler AreaHandler // for Areas
|
handler AreaHandler // for Areas
|
||||||
|
@ -75,8 +75,5 @@ func mksysdata(ctype int) *sysData {
|
||||||
ctype: ctype,
|
ctype: ctype,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if ctype == c_window { // make resizes non-nil so it can be passed in
|
|
||||||
s.resizes = make([]resizerequest, 0, 0)
|
|
||||||
}
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ func (w *Window) Create(control Control) {
|
||||||
panic(fmt.Errorf("error opening window: %v", err))
|
panic(fmt.Errorf("error opening window: %v", err))
|
||||||
}
|
}
|
||||||
if control != nil {
|
if control != nil {
|
||||||
w.sysData.resize = control.setRect
|
w.sysData.allocate = control.allocate
|
||||||
err = control.make(w.sysData)
|
err = control.make(w.sysData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("error adding window's control: %v", err))
|
panic(fmt.Errorf("error adding window's control: %v", err))
|
||||||
|
|
Loading…
Reference in New Issue