More uiParent work. Something I did broke stack removal...

This commit is contained in:
Pietro Gagliardi 2015-04-14 10:20:07 -04:00
parent d935c8896f
commit d71721964c
3 changed files with 20 additions and 38 deletions

View File

@ -16,11 +16,6 @@ void uiControlSetParent(uiControl *c, uiParent *parent)
(*(c->setParent))(c, parent);
}
void uiControlRemoveParent(uiControl *c)
{
(*(c->removeParent))(c);
}
void uiControlPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
{
(*(c->preferredSize))(c, d, width, height);

View File

@ -32,25 +32,22 @@ static uintptr_t singleHandle(uiControl *c)
}
static void singleSetParent(uiControl *c, uiParent *parent)
{
singleHWND *s = (singleHWND *) (c->internal);
s->parent = parent;
if (SetParent(s->hwnd, uiParentHWND(s->parent)) == NULL)
logLastError("error setting control parent in singleSetParent()");
uiParentUpdate(s->parent);
}
static void singleRemoveParent(uiControl *c)
{
singleHWND *s = (singleHWND *) (c->internal);
uiParent *oldparent;
HWND newParentHWND;
oldparent = s->parent;
s->parent = NULL;
if (SetParent(s->hwnd, initialParent) == NULL)
logLastError("error removing control parent in singleSetParent()");
s->parent = parent;
newParentHWND = initialParent;
if (s->parent != NULL)
newParentHWND = uiParentHWND(s->parent);
if (SetParent(s->hwnd, newParentHWND) == NULL)
logLastError("error setting control parent in singleSetParent()");
if (oldparent != NULL)
uiParentUpdate(oldparent);
if (s->parent != NULL)
uiParentUpdate(s->parent);
}
static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
@ -199,7 +196,6 @@ uiControl *uiWindowsNewControl(uiWindowsNewControlParams *p)
c->destroy = singleDestroy;
c->handle = singleHandle;
c->setParent = singleSetParent;
c->removeParent = singleRemoveParent;
c->resize = singleResize;
c->visible = singleVisible;
c->show = singleShow;

25
stack.c
View File

@ -45,27 +45,19 @@ static uintptr_t stackHandle(uiControl *c)
}
static void stackSetParent(uiControl *c, uiParent *parent)
{
stack *s = (stack *) (c->data);
uintmax_t i;
s->parent = parent;
for (i = 0; i < s->len; i++)
uiControlSetParent(s->controls[i].c, s->parent);
uiParentUpdate(s->parent);
}
static void stackRemoveParent(uiControl *c)
{
stack *s = (stack *) (c->data);
uintmax_t i;
uiParent *oldparent;
oldparent = s->parent;
s->parent = NULL;
s->parent = parent;
for (i = 0; i < s->len; i++)
uiControlRemoveParent(s->controls[i].c);
uiControlSetParent(s->controls[i].c, s->parent);
if (oldparent != NULL)
uiParentUpdate(oldparent);
if (s->parent != NULL)
uiParentUpdate(s->parent);
}
static void stackPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
@ -324,7 +316,6 @@ uiControl *uiNewHorizontalStack(void)
c->destroy = stackDestroy;
c->handle = stackHandle;
c->setParent = stackSetParent;
c->removeParent = stackRemoveParent;
c->preferredSize = stackPreferredSize;
c->resize = stackResize;
c->visible = stackVisible;
@ -363,14 +354,14 @@ void uiStackAdd(uiControl *st, uiControl *c, int stretchy)
}
s->controls[s->len].c = c;
s->controls[s->len].stretchy = stretchy;
s->len++;
if (s->parent != NULL) {
uiControlSetParent(s->controls[s->len].c, s->parent);
uiParentUpdate(s->parent);
}
s->len++;
}
void uiStackRemove(uiControl *st, uintptr_t index)
void uiStackRemove(uiControl *st, uintmax_t index)
{
stack *s = (stack *) (st->data);
uiControl *removed;
@ -382,7 +373,7 @@ void uiStackRemove(uiControl *st, uintptr_t index)
memmove(&(s->controls[index + 1]), &(s->controls[index]), nAfter * sizeof (stackControl));
s->len--;
if (s->parent != NULL) {
uiControlRemoveParent(removed);
uiControlSetParent(removed, NULL);
uiParentUpdate(s->parent);
}
}