From c93a502153a51b4182154c1e277564ace44a9d48 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 14 May 2015 10:08:49 -0400 Subject: [PATCH] Wrote windows/resize.c, which is the code that runs every so often to do a resize (instead of doing them immediately). --- redo/ui.idl | 3 ++- redo/windows/resize.c | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/redo/ui.idl b/redo/ui.idl index cf80de10..8031e3cd 100644 --- a/redo/ui.idl +++ b/redo/ui.idl @@ -43,7 +43,8 @@ interface Control { field Internal *void; // for use by ui only func Destroy(void); func Handle(void) uintptr_t; - func SetParent(c *Container); + func Parent(void) *Control; + func SetParent(c *Control); func PreferredSize(d *Sizing, width *intmax_t, height *intmax_t); func Resize(x intmax_t, y intmax_t, width intmax_t, height intmax_t, d *Sizing); func QueueResize(void); diff --git a/redo/windows/resize.c b/redo/windows/resize.c index ec88fd7f..6e88e089 100644 --- a/redo/windows/resize.c +++ b/redo/windows/resize.c @@ -1,2 +1,60 @@ // 14 may 2015 #include "uipriv_windows.h" + +static struct ptrArray *resizes; + +void initResizes(void) +{ + resizes = newPtrArray(); +} + +void uninitResizes(void) +{ + while (resizes->len != 0) + ptrArrayDelete(resizes, 0); + ptrArrayDestroy(resizes); +} + +void queueResize(uiControl *c) +{ + // TODO make this more robust + ptrArrayAppend(resizes, c); +} + +void doResizes(void) +{ + uiControl *c, *parent; + intmax_t x, y, width, height; + uiSizing d; + uiSizngSys sys; + + while (resizes->len != 0) { + c = ptrArrayIndex(resizes, uiControl *, 0); + ptrArrayDelete(resizes, 0); + parent = uiControlParent(c); + if (parent == NULL) // not in a parent; can't resize + continue; // this is for uiBox, etc. + d.sys = &sys; + uiControlComputeChildSizeArea(parent, &x, &y, &width, &height, &d); + uiControlResize(c, x, y, width, height, &d); + hwnd = (HWND) uiControlHandle(c); + // we used SWP_NOREDRAW; we need to queue a redraw ourselves + // TODO use RedrawWindow() to bypass WS_CLIPCHILDREN complications + if (InvalidateRect(hwnd, NULL, TRUE) == 0) + logLastError("error redrawing controls after a resize in doResizes()"); + } +} + +#define swpflags (SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOREDRAW) + +void moveWindow(HWND hwnd, intmax_t x, intmax_t y, intmax_t width, intmax_t height) +{ + if (SetWindowPos(hwnd, NULL, x, y, width, height, swpflags | SWP_NOZORDER) == 0) + logLastError("error moving window in moveWindow()"); +} + +void moveAndReorderWindow(HWND hwnd, HWND insertAfter, intmax_t x, intmax_t y, intmax_t width, intmax_t height) +{ + if (SetWindowPos(hwnd, insertAfter, x, y, width, height, swpflags) == 0) + logLastError("error moving and reordering window in moveAndReorderWindow()"); +}