Adjusted uiWindow to use the new system for propagating minimum size changes.

This commit is contained in:
Pietro Gagliardi 2016-04-28 17:11:32 -04:00
parent c457d9bf00
commit 3baa94476d
3 changed files with 46 additions and 22 deletions

View File

@ -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 *);

View File

@ -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));
}

View File

@ -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)
return;
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;
}
// 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)
{