From 28a632c5b6d2020121bf70fd0a193b7f6b30a0dc Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 27 Apr 2015 11:50:22 -0400 Subject: [PATCH] Wrote up a Bin for the Windows backend. Minor changes in uiBox too. --- new/box.c | 2 +- new/uipriv.h | 4 ++ new/windows/OLDcontainer.c | 19 ------- new/windows/bin.c | 101 +++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 20 deletions(-) create mode 100644 new/windows/bin.c diff --git a/new/box.c b/new/box.c index ef77e8a4..b2b81d82 100644 --- a/new/box.c +++ b/new/box.c @@ -38,7 +38,7 @@ static void boxDestroy(uiControl *c) } uiFree(b->controls); // NOW we can chain up to base - (*(b->baseDestroy))(c); + (*(b->baseDestroy))(uiControl(b)); uiFree(b); } diff --git a/new/uipriv.h b/new/uipriv.h index cc3d672a..6f603fa7 100644 --- a/new/uipriv.h +++ b/new/uipriv.h @@ -10,5 +10,9 @@ extern void uiFree(void *); extern void complain(const char *, ...); +extern uiContainer *newBin(void); +extern void binSetMainControl(uiContainer *, uiControl *); +extern void binSetMargins(uiContainer *, intmax_t, intmax_t, intmax_t, intmax_t); + // lifetimes.c extern void properlyDestroyControl(uiControl *); diff --git a/new/windows/OLDcontainer.c b/new/windows/OLDcontainer.c index ca2afd8d..281b1704 100644 --- a/new/windows/OLDcontainer.c +++ b/new/windows/OLDcontainer.c @@ -50,25 +50,6 @@ static void paintControlBackground(HWND hwnd, HDC dc) logLastError("error resetting window origin in paintControlBackground()"); } -static void resize(uiControl *control, HWND parent, RECT r, RECT margin) -{ - r.left += uiDlgUnitsToX(margin.left, sys.baseX); - r.top += uiDlgUnitsToY(margin.top, sys.baseY); - r.right -= uiDlgUnitsToX(margin.right, sys.baseX); - r.bottom -= uiDlgUnitsToY(margin.bottom, sys.baseY); -} - -// TODO make this a uiOSContainer directly -struct parent { - HWND hwnd; - uiControl *mainControl; - intmax_t marginLeft; - intmax_t marginTop; - intmax_t marginRight; - intmax_t marginBottom; - BOOL canDestroy; -}; - static LRESULT CALLBACK parentWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { uiOSContainer *p; diff --git a/new/windows/bin.c b/new/windows/bin.c new file mode 100644 index 00000000..5102aaaf --- /dev/null +++ b/new/windows/bin.c @@ -0,0 +1,101 @@ +// 27 april 2015 +#include "uipriv_windows.h" + +struct bin { + uiContainer c; + void (*baseDestroy)(uiControl *); + uiControl *mainControl; + intmax_t marginLeft; + intmax_t marginTop; + intmax_t marginRight; + intmax_t marginBottom; +}; + +void binDestroy(uiControl *c) +{ + struct bin *b = (struct bin *) c; + + // TODO find a way to move the parented check here + // don't chain up to base here; we need to destroy children ourselves first + if (b->mainControl != NULL) { + uiControlSetParent(b->mainControl, NULL); + uiControlDestroy(b->mainControl); + } + // NOW we can chain up to base + (*(b->baseDestroy))(uiControl(b)); + uiFree(b); +} + +void binPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height) +{ + struct bin *b = (struct bin *) c; + intmax_t marginX, marginY; + + // TODO have the margins count even if no control? + if (b->mainControl == NULL) { + *width = 0; + *height = 0; + return; + } + uiControlPreferredSize(b->mainControl, d, width, height); + marginX = uiDlgUnitsToX(b->marginLeft, d->sys->baseX) + uiDlgUnitsToX(b->marginRight, d->sys->baseX); + marginY = uiDlgUnitsToY(b->marginTop, d->sys->baseY) + uiDlgUnitsToY(b->marginBottom, d->sys->baseY); + *width += marginX; + *height += marginY; +} + +void binResizeChildren(uiContainer *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d) +{ + struct bin *b = (struct bin *) c; + intmax_t marginLeft, marginTop; + + if (b->mainControl == NULL) + return; + marginLeft = uiDlgUnitsToX(b->marginLeft, d->sys->baseX); + marginTop = uiDlgUnitsToY(b->marginTop, d->sys->baseY); + x += marginLeft; + y += marginTop; + width -= marginLeft + uiDlgUnitsToX(b->marginRight, d->sys->baseX); + height -= marginTop + uiDlgUnitsToY(b->marginBottom, d->sys->baseY); + uiControlResize(b->mainControl, x, y, width, height, d); +} + +uiContainer *newBin(void) +{ + struct bin *b; + + b = uiNew(struct bin); + + uiMakeContainer(uiContainer(b)); + + b->baseDestroy = uiControl(b)->Destroy; + uiControl(b)->Destroy = binDestroy; + uiControl(b)->PreferredSize = binPreferredSize; + + uiContainer(b)->ControlResize = binControlResize; + + return uiContainer(b); +} + +void binSetMainControl(uiContainer *c, uiControl *mainControl) +{ + struct bin *b = (struct bin *) c; + + if (b->mainControl != NULL) + uiControlSetParent(b->mainControl, NULL); + b->mainControl = mainControl; + if (b->mainControl != NULL) + uiControlSetParent(b->mainControl, uiContainer(b)); + uiContainerUpdate(uiContainer(b)); +} + +void binSetMargins(uiContainer *c, intmax_t left, intmax_t top, intmax_t right, intmax_t bottom) +{ + struct bin *b = (struct bin *) c; + + b->marginLeft = left; + b->marginRight = right; + b->marginTop = top; + b->marginBottom = bottom; + uiContainerUpdate(uiContainer(b)); +}