Reimplemented uiGroup sizing. This gets rid of the need for windows/OLDgroup.c.

This commit is contained in:
Pietro Gagliardi 2015-06-01 18:45:37 -04:00
parent a29c15a897
commit 162c6f8e4d
2 changed files with 54 additions and 95 deletions

View File

@ -1,94 +0,0 @@
// 11 may 2015
#include "uipriv_windows.h"
struct group {
uiGroup g;
HWND hwnd;
uiControl *child;
void (*baseResize)(uiControl *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *);
};
// TODO get source
#define groupXMargin 6
#define groupYMarginTop 11 /* note this value /includes the groupbox label */
#define groupYMarginBottom 7
// unfortunately because the client area of a groupbox includes the frame and caption text, we have to apply some margins ourselves, even if we don't want "any"
// these were deduced by hand based on the standard DLU conversions; the X and Y top margins are the width and height, respectively, of one character cell
// they can be fine-tuned later
#define groupUnmarginedXMargin 4
#define groupUnmarginedYMarginTop 8
#define groupUnmarginedYMarginBottom 3
static void groupPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
{
struct group *g = (struct group *) c;
uiControlPreferredSize(g->child, d, width, height);
*width += uiWindowsDlgUnitsToX(groupUnmarginedXMargin, d->Sys->BaseX) * 2;
*height += uiWindowsDlgUnitsToY(groupUnmarginedYMarginTop, d->Sys->BaseY) + uiWindowsDlgUnitsToY(groupUnmarginedYMarginBottom, d->Sys->BaseY);
}
static void groupResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
{
struct group *g = (struct group *) c;
(*(g->baseResize))(uiControl(g), x, y, width, height, d);
if (g->child != NULL)
uiControlQueueResize(g->child);
}
static void groupComputeChildSize(uiControl *c, intmax_t *x, intmax_t *y, intmax_t *width, intmax_t *height, uiSizing *d)
{
struct group *g = (struct group *) c;
RECT r;
if (GetClientRect(g->hwnd, &r) == 0)
logLastError("error getting uiGroup client rect for computing child size in groupResize()");
r.left += uiWindowsDlgUnitsToX(groupUnmarginedXMargin, d->Sys->BaseX);
r.top += uiWindowsDlgUnitsToY(groupUnmarginedYMarginTop, d->Sys->BaseY);
r.right -= uiWindowsDlgUnitsToX(groupUnmarginedXMargin, d->Sys->BaseX);
r.bottom -= uiWindowsDlgUnitsToY(groupUnmarginedYMarginBottom, d->Sys->BaseY);
*x = r.left;
*y = r.top;
*width = r.right - r.left;
*height = r.bottom - r.top;
}
uiGroup *uiNewGroup(const char *text)
{
struct group *g;
uiWindowsMakeControlParams p;
WCHAR *wtext;
g = uiNew(struct group);
uiTyped(g)->Type = uiTypeGroup();
p.dwExStyle = WS_EX_CONTROLPARENT;
p.lpClassName = L"button";
wtext = toUTF16(text);
p.lpWindowName = wtext;
p.dwStyle = BS_GROUPBOX;
p.hInstance = hInstance;
p.lpParam = NULL;
p.useStandardControlFont = TRUE;
p.onWM_COMMAND = onWM_COMMAND;
p.onWM_NOTIFY = onWM_NOTIFY;
p.onDestroy = onDestroy;
p.onDestroyData = g;
uiWindowsMakeControl(uiControl(g), &p);
uiFree(wtext);
g->hwnd = (HWND) uiControlHandle(uiControl(g));
uiControl(g)->PreferredSize = groupPreferredSize;
g->baseResize = uiControl(g)->Resize;
uiControl(g)->Resize = groupResize;
uiControl(g)->ComputeChildSize = groupComputeChildSize;
// TODO enable, disable, sysfunc
uiGroup(g)->SetChild = groupSetChild;
return uiGroup(g);
}

View File

@ -6,6 +6,8 @@ struct group {
HWND hwnd; HWND hwnd;
uiControl *child; uiControl *child;
void (*baseCommitDestroy)(uiControl *); void (*baseCommitDestroy)(uiControl *);
int margined;
void (*baseResize)(uiControl *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *);
}; };
uiDefineControlType(uiGroup, uiTypeGroup, struct group) uiDefineControlType(uiGroup, uiTypeGroup, struct group)
@ -28,11 +30,60 @@ static uintptr_t groupHandle(uiControl *c)
return (uintptr_t) (g->hwnd); return (uintptr_t) (g->hwnd);
} }
// TODO get source
#define groupXMargin 6
#define groupYMarginTop 11 /* note this value /includes the groupbox label */
#define groupYMarginBottom 7
// unfortunately because the client area of a groupbox includes the frame and caption text, we have to apply some margins ourselves, even if we don't want "any"
// these were deduced by hand based on the standard DLU conversions; the X and Y top margins are the width and height, respectively, of one character cell
// they can be fine-tuned later
#define groupUnmarginedXMargin 4
#define groupUnmarginedYMarginTop 8
#define groupUnmarginedYMarginBottom 3
static void groupPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height) static void groupPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
{ {
// TODO struct group *g = (struct group *) c;
*width = 0; *width = 0;
*height = 0; *height = 0;
if (g->child != NULL)
uiControlPreferredSize(g->child, d, width, height);
if (g->margined) {
*width += 2 * uiWindowsDlgUnitsToX(groupXMargin, d->Sys->BaseX);
*height += uiWindowsDlgUnitsToY(groupYMarginTop, d->Sys->BaseY) + uiWindowsDlgUnitsToY(groupYMarginBottom, d->Sys->BaseY);
} else {
*width += 2 * uiWindowsDlgUnitsToX(groupUnmarginedXMargin, d->Sys->BaseX);
*height += uiWindowsDlgUnitsToY(groupUnmarginedYMarginTop, d->Sys->BaseY) + uiWindowsDlgUnitsToY(groupUnmarginedYMarginBottom, d->Sys->BaseY);
}
}
static void groupResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
{
struct group *g = (struct group *) c;
uiSizing *dchild;
(*(g->baseResize))(uiControl(g), x, y, width, height, d);
if (g->child == NULL)
return;
if (g->margined) {
x += uiWindowsDlgUnitsToX(groupXMargin, d->Sys->BaseX);
y += uiWindowsDlgUnitsToY(groupYMarginTop, d->Sys->BaseY);
width -= 2 * uiWindowsDlgUnitsToX(groupXMargin, d->Sys->BaseX);
height -= uiWindowsDlgUnitsToY(groupYMarginTop, d->Sys->BaseY) + uiWindowsDlgUnitsToY(groupYMarginBottom, d->Sys->BaseY);
} else {
x += uiWindowsDlgUnitsToX(groupUnmarginedXMargin, d->Sys->BaseX);
y += uiWindowsDlgUnitsToY(groupUnmarginedYMarginTop, d->Sys->BaseY);
width -= 2 * uiWindowsDlgUnitsToX(groupUnmarginedXMargin, d->Sys->BaseX);
height -= uiWindowsDlgUnitsToY(groupUnmarginedYMarginTop, d->Sys->BaseY) + uiWindowsDlgUnitsToY(groupUnmarginedYMarginBottom, d->Sys->BaseY);
}
dchild = uiControlSizing(uiControl(g));
uiControlResize(g->child, x, y, width, height, dchild);
uiFreeSizing(dchild);
} }
static void groupContainerUpdateState(uiControl *c) static void groupContainerUpdateState(uiControl *c)
@ -73,6 +124,8 @@ uiGroup *uiNewGroup(const char *text)
uiControl(g)->Handle = groupHandle; uiControl(g)->Handle = groupHandle;
uiControl(g)->PreferredSize = groupPreferredSize; uiControl(g)->PreferredSize = groupPreferredSize;
g->baseResize = uiControl(g)->Resize;
uiControl(g)->Resize = groupResize;
g->baseCommitDestroy = uiControl(g)->CommitDestroy; g->baseCommitDestroy = uiControl(g)->CommitDestroy;
uiControl(g)->CommitDestroy = groupCommitDestroy; uiControl(g)->CommitDestroy = groupCommitDestroy;
uiControl(g)->ContainerUpdateState = groupContainerUpdateState; uiControl(g)->ContainerUpdateState = groupContainerUpdateState;