diff --git a/ui_windows.h b/ui_windows.h index 0ea27aa9..e297e019 100644 --- a/ui_windows.h +++ b/ui_windows.h @@ -114,8 +114,10 @@ _UI_EXTERN void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *, LONG_P #define uiWindowsControlDefaultMinimumSizeChanged(type) \ static void type ## MinimumSizeChanged)(uiWIndowsControl *c) \ { \ - if (uiWindowsControlTooSmall(c)) \ - uiWindowsControlMinimumSizeChanged(uiWindowsControl(c->parent)); \ + if (uiWindowsControlTooSmall(c)) { \ + uiWindowsControlContinueMinimumSizeChanged(c); \ + return; \ + } \ /* otherwise do nothing; we have no children */ \ } #define uiWindowsControlDefaultLayoutRect(type) \ @@ -235,6 +237,7 @@ _UI_EXTERN HWND uiWindowsMakeContainer(void (*onResize)(void *data), void *data) // TODO document _UI_EXTERN BOOL uiWindowsControlTooSmall(uiWindowsControl *c); +_UI_EXTERN void uiWindowsControlContinueMinimumSizeChanged(uiWindowsControl *c); // TODO document _UI_EXTERN void uiWindowsControlAssignSoleControlIDZOrder(uiWindowsControl *); diff --git a/windows/control.cpp b/windows/control.cpp index 398c0b16..9a175e69 100644 --- a/windows/control.cpp +++ b/windows/control.cpp @@ -80,3 +80,26 @@ void uiWindowsControlAssignSoleControlIDZOrder(uiWindowsControl *c) insertAfter = NULL; uiWindowsControlAssignControlIDZorder(c, &controlID, &insertAfter); } + +BOOL uiWindowsControlTooSmall(uiWindowsControl *c) +{ + RECT r; + intmax_t width, height; + + uiWindowsControlLayoutRect(c, &r); + uiWindowsControlMinimumSize(c, &width, &height); + if ((r.right - r.left) < width) + return TRUE; + if ((r.bottom - r.top) < height) + return TRUE; + return FALSE; +} + +void uiWindowsControlContinueMinimumSizeChanged(uiWindowsControl *c) +{ + uiControl *parent; + + parent = uiControlParent(uiControl(c)); + if (parent != NULL) + uiWindowsControlMinimumSizeChanged(uiWindowsControl(parent)); +} diff --git a/windows/window.cpp b/windows/window.cpp index b8e2d396..6e466572 100644 --- a/windows/window.cpp +++ b/windows/window.cpp @@ -183,7 +183,7 @@ static void uiWindowShow(uiControl *c) uiWindow *w = uiWindow(c); w->visible = 1; - // just in case this wasn't called already + // just in case the window's minimum size wasn't recalculated already // TODO is it needed? ensureMinimumWindowSize(w); if (w->shownOnce) { @@ -230,31 +230,29 @@ static void uiWindowMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t * *height += 2 * my; } -static void uiWindowChildMinimumSizeChanged(uiWindowsControl *c) +static void uiWindowMinimumSizeChanged(uiWindowsControl *c) { uiWindow *w = uiWindow(c); - intmax_t width, height; - RECT r; - BOOL needsGrowing; - int mx, my; - uiWindowsControlMinimumSize(uiWindowsControl(w->child), &width, &height); - uiWindowsEnsureGetClientRect(w->hwnd, &r); - windowMargins(w, &mx, &my); - needsGrowing = FALSE; - // subtract margins so we only care about the area that's used - if ((r.right - r.left - (2 * mx)) < width) - needsGrowing = TRUE; - if ((r.bottom - r.top - (2 * my)) < height) - needsGrowing = TRUE; - if (!needsGrowing) + if (uiWindowsControlTooSmall(uiWindowsControl(w)) { + // TODO figure out what to do with this function + // maybe split it into two so WM_GETMINMAXINFO can use it? + ensureMinimumWindowSize(w); return; - // TODO figure out what to do with this function - // maybe split it into two so WM_GETMINMAXINFO can use it? - ensureMinimumWindowSize(w); + } + // otherwise we only need to re-layout everything + windowRelayout(w); } -uiWindowsDefaultAssignControlIDZorder(uiWindow) +static void uiWindowLayoutRect(uiWindowsControl *w, RECT *r) +{ + uiWindow *w = uiWindow(c); + + // the layout rect is the client rect in this case + uiWindowsEnsureGetClientRect(w->hwnd, r); +} + +uiWindowsControlDefaultAssignControlIDZorder(uiWindow) char *uiWindowTitle(uiWindow *w) {