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