diff --git a/container_windows.c b/container_windows.c index 2056653f..20d7d8d9 100644 --- a/container_windows.c +++ b/container_windows.c @@ -82,3 +82,19 @@ void resize(uiControl *control, HWND parent, RECT r) logLastError("error releasing DC in resize()"); (*(control->resize))(control, r.left, r.top, r.right - r.left, r.bottom - r.top, &d); } + +void updateParent(uintptr_t h) +{ + HWND hwnd; + RECT r; + + if (h == 0) // no parent + return; + hwnd = (HWND) h; + // TODO is there a better way? + if (GetWindowRect(hwnd, &r) == 0) + logLastError("error getting window rect for dummy move in updateParent()"); + if (MoveWindow(hwnd, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE) == 0) + logLastError("error moving window in updateParent()"); + // TODO invalidate rect? +} diff --git a/newcontrol_windows.c b/newcontrol_windows.c index 98956faf..1293f5aa 100644 --- a/newcontrol_windows.c +++ b/newcontrol_windows.c @@ -12,6 +12,7 @@ struct uiSingleHWNDControl { void *onCommandNotifyDestroyData; void (*preferredSize)(uiControl *, int, int, LONG, intmax_t *, intmax_t *); void *data; + uintptr_t parent; }; #define S(c) ((uiSingleHWNDControl *) (c)) @@ -28,10 +29,17 @@ static uintptr_t singleHandle(uiControl *c) return (uintptr_t) (S(c)->hwnd); } -static void singleSetParent(uiControl *c, uintptr_t parentHWND) +static void singleSetParent(uiControl *c, uintptr_t parent) { - if (SetParent(S(c)->hwnd, (HWND) parentHWND) == NULL) + uiSingleHWNDControl *s = S(c); + uintptr_t oldparent; + + oldparent = s->parent; + s->parent = parent; + if (SetParent(s->hwnd, (HWND) (s->parent)) == NULL) logLastError("error changing control parent in singleSetParent()"); + updateParent(oldparent); + updateParent(s->parent); } static uiSize singlePreferredSize(uiControl *c, uiSizing *d) diff --git a/stack.c b/stack.c index 45fcf545..fa28e593 100644 --- a/stack.c +++ b/stack.c @@ -38,11 +38,16 @@ static uintptr_t stackHandle(uiControl *c) static void stackSetParent(uiControl *c, uintptr_t parent) { + stack *s = S(c); uintmax_t i; + uintptr_t oldparent; - S(c)->parent = parent; + oldparent = s->parent; + s->parent = parent; for (i = 0; i < S(c)->len; i++) - (*(S(c)->controls[i]->setParent))(S(c)->controls[i], S(c)->parent); + (*(s->controls[i]->setParent))(s->controls[i], s->parent); + updateParent(oldparent); + updateParent(s->parent); } static uiSize stackPreferredSize(uiControl *c, uiSizing *d) @@ -213,5 +218,5 @@ void uiStackAdd(uiControl *st, uiControl *c, int stretchy) if (s->parent != 0) (*(s->controls[s->len]->setParent))(s->controls[s->len], s->parent); s->len++; - // TODO queue reposition + updateParent(s->parent); } diff --git a/uipriv.h b/uipriv.h index b8f5835b..a12fbdc9 100644 --- a/uipriv.h +++ b/uipriv.h @@ -25,3 +25,5 @@ extern void *uiAlloc(size_t, const char *); #define uiNew(T) ((T *) uiAlloc(sizeof (T), #T )) extern void *uiRealloc(void *, size_t, const char *); extern void uiFree(void *); + +extern void updateParent(uintptr_t); diff --git a/window_windows.c b/window_windows.c index d68843ba..7bbb8950 100644 --- a/window_windows.c +++ b/window_windows.c @@ -1,9 +1,6 @@ // 6 april 2015 #include "uipriv_windows.h" -// TODOs: -// - child not set to fit initial size - struct uiWindow { HWND hwnd; uiControl *child;