Decided to split control removal from parent into its own method removeParent() rather than automatically doing it in setParent().
This commit is contained in:
parent
1575a0dc7c
commit
b60ff74a9e
|
@ -13,6 +13,7 @@ struct uiSingleViewControl {
|
|||
|
||||
#define S(c) ((uiSingleViewControl *) (c))
|
||||
|
||||
// TODO this will need to change if we want to provide removal
|
||||
static void singleDestroy(uiControl *c)
|
||||
{
|
||||
[S(c)->view removeFromSuperview];
|
||||
|
@ -26,18 +27,25 @@ static uintptr_t singleHandle(uiControl *c)
|
|||
static void singleSetParent(uiControl *c, uintptr_t parent)
|
||||
{
|
||||
uiSingleViewControl *s = S(c);
|
||||
uintptr_t oldparent;
|
||||
NSView *parentView;
|
||||
|
||||
oldparent = s->parent;
|
||||
s->parent = parent;
|
||||
parentView = (NSView *) (s->parent);
|
||||
// TODO will this change parents?
|
||||
[parentView addSubview:s->immediate];
|
||||
updateParent(oldparent);
|
||||
updateParent(s->parent);
|
||||
}
|
||||
|
||||
static void singleRemoveParent(uiControl *c)
|
||||
{
|
||||
uiSingleViewControl *s = S(c);
|
||||
uintptr_t oldparent;
|
||||
|
||||
oldparent = s->parent;
|
||||
s->parent = 0;
|
||||
[s->immediate removeFromSuperview];
|
||||
updateParent(oldparent);
|
||||
}
|
||||
|
||||
// also good for NSBox and NSProgressIndicator
|
||||
static uiSize singlePreferredSize(uiControl *c, uiSizing *d)
|
||||
{
|
||||
|
@ -92,6 +100,7 @@ uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHas
|
|||
c->control.destroy = singleDestroy;
|
||||
c->control.handle = singleHandle;
|
||||
c->control.setParent = singleSetParent;
|
||||
c->control.removeParent = singleRemoveParent;
|
||||
c->control.preferredSize = singlePreferredSize;
|
||||
c->control.resize = singleResize;
|
||||
|
||||
|
|
|
@ -25,17 +25,23 @@ static uintptr_t singleHandle(uiControl *c)
|
|||
}
|
||||
|
||||
static void singleSetParent(uiControl *c, uintptr_t parent)
|
||||
{
|
||||
uiSingleWidgetControl *s = S(c);
|
||||
|
||||
s->parent = parent;
|
||||
gtk_container_add(GTK_CONTAINER(s->parent), s->immediate);
|
||||
updateParent(s->parent);
|
||||
}
|
||||
|
||||
static void singleRemoveParent(uiControl *c)
|
||||
{
|
||||
uiSingleWidgetControl *s = S(c);
|
||||
uintptr_t oldparent;
|
||||
|
||||
oldparent = s->parent;
|
||||
s->parent = parent;
|
||||
if (oldparent != 0)
|
||||
gtk_container_remove(GTK_CONTAINER(oldparent), s->immediate);
|
||||
gtk_container_add(GTK_CONTAINER(s->parent), s->immediate);
|
||||
s->parent = 0;
|
||||
gtk_container_remove(GTK_CONTAINER(oldparent), s->immediate);
|
||||
updateParent(oldparent);
|
||||
updateParent(s->parent);
|
||||
}
|
||||
|
||||
static uiSize singlePreferredSize(uiControl *c, uiSizing *d)
|
||||
|
@ -101,7 +107,7 @@ uiControl *uiUnixNewControl(GType type, gboolean inScrolledWindow, gboolean scro
|
|||
// with this:
|
||||
// - end user call works (shoudn't be in any container)
|
||||
// - call in uiContainer works (both refs freed)
|
||||
// this also ensures singleSetParent() works properly when changing parents
|
||||
// this also ensures singleRemoveParent() works properly
|
||||
g_object_ref_sink(c->immediate);
|
||||
// and let's free the uiSingleWidgetControl with it
|
||||
g_signal_connect(c->immediate, "destroy", G_CALLBACK(onDestroy), c);
|
||||
|
@ -109,6 +115,7 @@ uiControl *uiUnixNewControl(GType type, gboolean inScrolledWindow, gboolean scro
|
|||
c->control.destroy = singleDestroy;
|
||||
c->control.handle = singleHandle;
|
||||
c->control.setParent = singleSetParent;
|
||||
c->control.removeParent = singleRemoveParent;
|
||||
c->control.preferredSize = singlePreferredSize;
|
||||
c->control.resize = singleResize;
|
||||
|
||||
|
|
|
@ -30,16 +30,25 @@ static uintptr_t singleHandle(uiControl *c)
|
|||
}
|
||||
|
||||
static void singleSetParent(uiControl *c, uintptr_t parent)
|
||||
{
|
||||
uiSingleHWNDControl *s = S(c);
|
||||
|
||||
s->parent = parent;
|
||||
if (SetParent(s->hwnd, (HWND) (s->parent)) == NULL)
|
||||
logLastError("error setting control parent in singleSetParent()");
|
||||
updateParent(s->parent);
|
||||
}
|
||||
|
||||
static void singleRemoveParent(uiControl *c)
|
||||
{
|
||||
uiSingleHWNDControl *s = S(c);
|
||||
uintptr_t oldparent;
|
||||
|
||||
oldparent = s->parent;
|
||||
s->parent = parent;
|
||||
if (SetParent(s->hwnd, (HWND) (s->parent)) == NULL)
|
||||
logLastError("error changing control parent in singleSetParent()");
|
||||
s->parent = 0;
|
||||
if (SetParent(s->hwnd, initialParent) == NULL)
|
||||
logLastError("error removing control parent in singleSetParent()");
|
||||
updateParent(oldparent);
|
||||
updateParent(s->parent);
|
||||
}
|
||||
|
||||
static uiSize singlePreferredSize(uiControl *c, uiSizing *d)
|
||||
|
@ -102,6 +111,7 @@ uiControl *uiWindowsNewControl(uiWindowsNewControlParams *p)
|
|||
c->control.destroy = singleDestroy;
|
||||
c->control.handle = singleHandle;
|
||||
c->control.setParent = singleSetParent;
|
||||
c->control.removeParent = singleRemoveParent;
|
||||
c->control.preferredSize = singlePreferredSize;
|
||||
c->control.resize = singleResize;
|
||||
|
||||
|
|
17
stack.c
17
stack.c
|
@ -41,16 +41,26 @@ static void stackSetParent(uiControl *c, uintptr_t parent)
|
|||
{
|
||||
stack *s = S(c);
|
||||
uintmax_t i;
|
||||
uintptr_t oldparent;
|
||||
|
||||
oldparent = s->parent;
|
||||
s->parent = parent;
|
||||
for (i = 0; i < S(c)->len; i++)
|
||||
(*(s->controls[i]->setParent))(s->controls[i], s->parent);
|
||||
updateParent(oldparent);
|
||||
updateParent(s->parent);
|
||||
}
|
||||
|
||||
static void stackRemoveParent(uiControl *c)
|
||||
{
|
||||
stack *s = S(c);
|
||||
uintmax_t i;
|
||||
uintptr_t oldparent;
|
||||
|
||||
oldparent = s->parent;
|
||||
s->parent = 0;
|
||||
for (i = 0; i < S(c)->len; i++)
|
||||
(*(s->controls[i]->removeParent))(s->controls[i]);
|
||||
updateParent(oldparent);
|
||||
}
|
||||
|
||||
static uiSize stackPreferredSize(uiControl *c, uiSizing *d)
|
||||
{
|
||||
stack *s = S(c);
|
||||
|
@ -197,6 +207,7 @@ uiControl *uiNewHorizontalStack(void)
|
|||
s->control.destroy = stackDestroy;
|
||||
s->control.handle = stackHandle;
|
||||
s->control.setParent = stackSetParent;
|
||||
s->control.removeParent = stackRemoveParent;
|
||||
s->control.preferredSize = stackPreferredSize;
|
||||
s->control.resize = stackResize;
|
||||
|
||||
|
|
1
uipriv.h
1
uipriv.h
|
@ -24,6 +24,7 @@ struct uiControl {
|
|||
void (*destroy)(uiControl *);
|
||||
uintptr_t (*handle)(uiControl *);
|
||||
void (*setParent)(uiControl *, uintptr_t);
|
||||
void (*removeParent)(uiControl *);
|
||||
uiSize (*preferredSize)(uiControl *, uiSizing *);
|
||||
void (*resize)(uiControl *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue