diff options
| author | Pietro Gagliardi <[email protected]> | 2014-06-25 23:21:57 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-06-25 23:21:57 -0400 |
| commit | 1eeadc000ae796bd022879196c4f2bae3bb189de (patch) | |
| tree | e63f905f533f183935850b04f5ab8356e06e7084 | |
| parent | 9a3e73b46001219177bb13a381420007217dfecf (diff) | |
Made the new sizing system work on Windows.
| -rw-r--r-- | area.go | 4 | ||||
| -rw-r--r-- | button.go | 2 | ||||
| -rw-r--r-- | checkbox.go | 2 | ||||
| -rw-r--r-- | combobox.go | 2 | ||||
| -rw-r--r-- | controlsize.go | 4 | ||||
| -rw-r--r-- | controlsize_windows.go | 18 | ||||
| -rw-r--r-- | grid.go | 2 | ||||
| -rw-r--r-- | label.go | 2 | ||||
| -rw-r--r-- | lineedit.go | 2 | ||||
| -rw-r--r-- | listbox.go | 2 | ||||
| -rw-r--r-- | progressbar.go | 2 | ||||
| -rw-r--r-- | stdwndclass_windows.go | 6 | ||||
| -rw-r--r-- | sysdata.go | 5 | ||||
| -rw-r--r-- | window.go | 2 |
14 files changed, 26 insertions, 29 deletions
@@ -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) { @@ -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) { diff --git a/checkbox.go b/checkbox.go index 1f2ea58..d079e17 100644 --- a/checkbox.go +++ b/checkbox.go @@ -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) { diff --git a/combobox.go b/combobox.go index 9298f87..83024ed 100644 --- a/combobox.go +++ b/combobox.go @@ -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) { diff --git a/controlsize.go b/controlsize.go index ff0973b..d0a5eaf 100644 --- a/controlsize.go +++ b/controlsize.go @@ -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) @@ -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) diff --git a/controlsize_windows.go b/controlsize_windows.go index 3bb3ecb..6e1c860 100644 --- a/controlsize_windows.go +++ b/controlsize_windows.go @@ -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 @@ -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) { @@ -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)) @@ -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 @@ -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 { @@ -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") @@ -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 } @@ -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) { diff --git a/lineedit.go b/lineedit.go index 3e71db1..a45a443 100644 --- a/lineedit.go +++ b/lineedit.go @@ -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) { @@ -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) { diff --git a/progressbar.go b/progressbar.go index c2cd289..e7c7149 100644 --- a/progressbar.go +++ b/progressbar.go @@ -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) { diff --git a/stdwndclass_windows.go b/stdwndclass_windows.go index f907b43..9d6fc35 100644 --- a/stdwndclass_windows.go +++ b/stdwndclass_windows.go @@ -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( @@ -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? } @@ -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 @@ -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 } @@ -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)) |
