diff options
| -rw-r--r-- | redo/sizing.go | 27 | ||||
| -rw-r--r-- | redo/sizing_windows.go | 5 | ||||
| -rw-r--r-- | redo/window_windows.go | 12 |
3 files changed, 30 insertions, 14 deletions
diff --git a/redo/sizing.go b/redo/sizing.go index a3f8c0e..5bf1e84 100644 --- a/redo/sizing.go +++ b/redo/sizing.go @@ -33,16 +33,31 @@ type controlSizing interface { getAuxResizeInfo(*sizing) } -func (w *window) doresize(width, height int) { - if w.child == nil { // no children; nothing to do +// on Windows, this is only embedded by window, as all other containers cannot have their own children +// on GTK+ and Mac OS X, one is embedded by window and all containers; the containers call container.continueResize() +type container struct { + child Control + spaced bool + beginResize func() (d *sizing) +} + +func (c *container) resize(width, height int) { + if c.child == nil { // no children; nothing to do + return + } + d := c.beginResize() + c.continueResize(width, height, d) +} + +func (c *container) continueResize(width, height int, d *sizing) { + if c.child == nil { // no children; nothing to do return } - d := w.beginResize() - allocations := w.child.allocate(0, 0, width, height, d) - w.translateAllocationCoords(allocations, width, height) + allocations := c.child.allocate(0, 0, width, height, d) + c.translateAllocationCoords(allocations, width, height) // move in reverse so as to approximate right->left order so neighbors make sense for i := len(allocations) - 1; i >= 0; i-- { allocations[i].this.commitResize(allocations[i], d) } - w.endResize(d) + c.endResize(d) } diff --git a/redo/sizing_windows.go b/redo/sizing_windows.go index d0c3937..442aad0 100644 --- a/redo/sizing_windows.go +++ b/redo/sizing_windows.go @@ -21,6 +21,7 @@ const ( paddingDialogUnits = 4 ) +// only windows are containers, so only windows get beginResize() func (w *window) beginResize() (d *sizing) { d = new(sizing) @@ -43,11 +44,11 @@ func (w *window) beginResize() (d *sizing) { return d } -func (w *window) endResize(d *sizing) { +func (c *container) endResize(d *sizing) { // redraw } -func (w *window) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) { +func (c *container) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) { // no translation needed on windows } diff --git a/redo/window_windows.go b/redo/window_windows.go index 1ac294a..34e8f93 100644 --- a/redo/window_windows.go +++ b/redo/window_windows.go @@ -12,14 +12,12 @@ import ( import "C" type window struct { + *container + hwnd C.HWND shownbefore bool - child Control - closing *event - - spaced bool } const windowclassname = "" @@ -42,8 +40,10 @@ type controlParent interface { func newWindow(title string, width int, height int, control Control) *window { w := &window{ // hwnd set in WM_CREATE handler - closing: newEvent(), + closing: newEvent(), + container: new(container), } + w.container.beginResize = w.beginResize hwnd := C.newWindow(toUTF16(title), C.int(width), C.int(height), unsafe.Pointer(w)) if hwnd != w.hwnd { panic(fmt.Errorf("inconsistency: hwnd returned by CreateWindowEx() (%p) and hwnd stored in window (%p) differ", hwnd, w.hwnd)) @@ -97,7 +97,7 @@ func storeWindowHWND(data unsafe.Pointer, hwnd C.HWND) { //export windowResize func windowResize(data unsafe.Pointer, r *C.RECT) { w := (*window)(data) - w.doresize(int(r.right - r.left), int(r.bottom - r.top)) + w.resize(int(r.right - r.left), int(r.bottom - r.top)) } //export windowClosing |
