Skip to content

Commit

Permalink
Made the new sizing system work on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
andlabs committed Jun 26, 2014
1 parent 9a3e73b commit 1eeadc0
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 29 deletions.
4 changes: 2 additions & 2 deletions area.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ func (a *Area) preferredSize(d *sysSizeData) (width int, height int) {
return a.sysData.preferredSize(d)
}

func (a *Area) commitResize(a *allocation, d *sysSizeData) {
a.sysData.preferredSize(a, d)
func (a *Area) commitResize(c *allocation, d *sysSizeData) {
a.sysData.commitResize(c, d)
}

func (a *Area) getAuxResizeInfo(d *sysSizeData) {
Expand Down
2 changes: 1 addition & 1 deletion button.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (b *Button) preferredSize(d *sysSizeData) (width int, height int) {
}

func (b *Button) commitResize(a *allocation, d *sysSizeData) {
b.sysData.preferredSize(a, d)
b.sysData.commitResize(a, d)
}

func (b *Button) getAuxResizeInfo(d *sysSizeData) {
Expand Down
2 changes: 1 addition & 1 deletion checkbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (c *Checkbox) preferredSize(d *sysSizeData) (width int, height int) {
}

func (c *Checkbox) commitResize(a *allocation, d *sysSizeData) {
c.sysData.preferredSize(a, d)
c.sysData.commitResize(a, d)
}

func (c *Checkbox) getAuxResizeInfo(d *sysSizeData) {
Expand Down
2 changes: 1 addition & 1 deletion combobox.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (c *Combobox) preferredSize(d *sysSizeData) (width int, height int) {
}

func (c *Combobox) commitResize(a *allocation, d *sysSizeData) {
c.sysData.preferredSize(a, d)
c.sysData.commitResize(a, d)
}

func (c *Combobox) getAuxResizeInfo(d *sysSizeData) {
Expand Down
4 changes: 2 additions & 2 deletions controlsize.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type cSysSizeData struct {
}

// for verification; see sysdata.go
type sysDataSizeFuncs interface {
type sysDataSizingFunctions interface {
beginResize() *sysSizeData
endResize(*sysSizeData)
translateAllocationCoords([]*allocation, int, int)
Expand All @@ -32,7 +32,7 @@ func (s *sysData) resizeWindow(width, height int) {
d := s.beginResize()
allocations := s.allocate(0, 0, width, height, d)
s.translateAllocationCoords(allocations, width, height)
for _, c := range s.allocations {
for _, c := range allocations {
c.this.commitResize(c, d)
}
s.endResize(d)
Expand Down
18 changes: 9 additions & 9 deletions controlsize_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ type sysSizeData struct {
const (
marginDialogUnits = 7
paddingDialogUnits = 4
}
)

func (s *sysData) beginResize() (d *sysSizeData) {
d = new(sysSizeData)

dc := getTextDC(s.hwnd)
defer releaseTextDC(dc)
defer releaseTextDC(s.hwnd, dc)

var tm _TEXTMETRICS

r1, _, err = _getTextMetrics.Call(
r1, _, err := _getTextMetrics.Call(
uintptr(dc),
uintptr(unsafe.Pointer(&tm)))
if r1 == 0 { // failure
Expand Down Expand Up @@ -66,7 +68,7 @@ func (s *sysData) commitResize(c *allocation, d *sysSizeData) {
}
c.y += yoff
// 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) {
Expand Down Expand Up @@ -150,8 +152,6 @@ var (
)

func getTextDC(hwnd _HWND) (dc _HANDLE) {
var tm _TEXTMETRICS

r1, _, err := _getDC.Call(uintptr(hwnd))
if r1 == 0 { // failure
panic(fmt.Errorf("error getting DC for preferred size calculations: %v", err))
Expand All @@ -167,7 +167,7 @@ func getTextDC(hwnd _HWND) (dc _HANDLE) {
}

func releaseTextDC(hwnd _HWND, dc _HANDLE) {
r1, _, err = _releaseDC.Call(
r1, _, err := _releaseDC.Call(
uintptr(hwnd),
uintptr(dc))
if r1 == 0 { // failure
Expand All @@ -179,7 +179,7 @@ func releaseTextDC(hwnd _HWND, dc _HANDLE) {
func (s *sysData) preferredSize(d *sysSizeData) (width int, height int) {
// the preferred size of an Area is its size
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 {
Expand All @@ -191,7 +191,7 @@ func (s *sysData) preferredSize(d *sysSizeData) (width int, height int) {
uintptr(0),
uintptr(unsafe.Pointer(&size)))
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
println("message failed; falling back")
Expand Down
2 changes: 1 addition & 1 deletion grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ _=ymargin
w = g.colwidths[col]
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
current.neighbor = c
}
Expand Down
2 changes: 1 addition & 1 deletion label.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (l *Label) preferredSize(d *sysSizeData) (width int, height int) {
}

func (l *Label) commitResize(a *allocation, d *sysSizeData) {
l.sysData.preferredSize(a, d)
l.sysData.commitResize(a, d)
}

func (l *Label) getAuxResizeInfo(d *sysSizeData) {
Expand Down
2 changes: 1 addition & 1 deletion lineedit.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (l *LineEdit) preferredSize(d *sysSizeData) (width int, height int) {
}

func (l *LineEdit) commitResize(a *allocation, d *sysSizeData) {
l.sysData.preferredSize(a, d)
l.sysData.commitResize(a, d)
}

func (l *LineEdit) getAuxResizeInfo(d *sysSizeData) {
Expand Down
2 changes: 1 addition & 1 deletion listbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (l *Listbox) preferredSize(d *sysSizeData) (width int, height int) {
}

func (l *Listbox) commitResize(a *allocation, d *sysSizeData) {
l.sysData.preferredSize(a, d)
l.sysData.commitResize(a, d)
}

func (l *Listbox) getAuxResizeInfo(d *sysSizeData) {
Expand Down
2 changes: 1 addition & 1 deletion progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (p *ProgressBar) preferredSize(d *sysSizeData) (width int, height int) {
}

func (p *ProgressBar) commitResize(a *allocation, d *sysSizeData) {
p.sysData.preferredSize(a, d)
p.sysData.commitResize(a, d)
}

func (p *ProgressBar) getAuxResizeInfo(d *sysSizeData) {
Expand Down
6 changes: 3 additions & 3 deletions stdwndclass_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESUL
_ = mm
return 0
case _WM_SIZE:
if s.resize != nil {
if s.allocate != nil {
var r _RECT

r1, _, err := _getClientRect.Call(
Expand All @@ -157,8 +157,8 @@ func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESUL
if r1 == 0 {
panic("GetClientRect failed: " + err.Error())
}
// top-left corner is (0,0) so no need for winheight
s.doResize(int(r.left), int(r.top), int(r.right-r.left), int(r.bottom-r.top), 0)
// top-left corner of a client rect is (0,0) so no need for left/top
s.resizeWindow(int(r.right), int(r.bottom))
// TODO use the Defer movement functions here?
// TODO redraw window and all children here?
}
Expand Down
5 changes: 1 addition & 4 deletions sysdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func newEvent() chan struct{} {
type cSysData struct {
ctype int
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
alternate bool // editable for Combobox, multi-select for listbox, password for lineedit
handler AreaHandler // for Areas
Expand Down Expand Up @@ -75,8 +75,5 @@ func mksysdata(ctype int) *sysData {
ctype: ctype,
},
}
if ctype == c_window { // make resizes non-nil so it can be passed in
s.resizes = make([]resizerequest, 0, 0)
}
return s
}
2 changes: 1 addition & 1 deletion window.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (w *Window) Create(control Control) {
panic(fmt.Errorf("error opening window: %v", err))
}
if control != nil {
w.sysData.resize = control.setRect
w.sysData.allocate = control.allocate
err = control.make(w.sysData)
if err != nil {
panic(fmt.Errorf("error adding window's control: %v", err))
Expand Down

0 comments on commit 1eeadc0

Please sign in to comment.