summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--new/newcontrol_darwin.m17
-rw-r--r--new/newcontrol_unix.c19
-rw-r--r--new/newcontrol_windows.c18
-rw-r--r--new/stack.c17
-rw-r--r--new/uipriv.h1
5 files changed, 55 insertions, 17 deletions
diff --git a/new/newcontrol_darwin.m b/new/newcontrol_darwin.m
index 8b0bd48..77c23ca 100644
--- a/new/newcontrol_darwin.m
+++ b/new/newcontrol_darwin.m
@@ -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;
diff --git a/new/newcontrol_unix.c b/new/newcontrol_unix.c
index 0f050be..870406c 100644
--- a/new/newcontrol_unix.c
+++ b/new/newcontrol_unix.c
@@ -27,17 +27,23 @@ static uintptr_t singleHandle(uiControl *c)
static void singleSetParent(uiControl *c, uintptr_t parent)
{
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);
- updateParent(oldparent);
updateParent(s->parent);
}
+static void singleRemoveParent(uiControl *c)
+{
+ uiSingleWidgetControl *s = S(c);
+ uintptr_t oldparent;
+
+ oldparent = s->parent;
+ s->parent = 0;
+ gtk_container_remove(GTK_CONTAINER(oldparent), s->immediate);
+ updateParent(oldparent);
+}
+
static uiSize singlePreferredSize(uiControl *c, uiSizing *d)
{
uiSize size;
@@ -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;
diff --git a/new/newcontrol_windows.c b/new/newcontrol_windows.c
index 56719b3..1ff404b 100644
--- a/new/newcontrol_windows.c
+++ b/new/newcontrol_windows.c
@@ -32,16 +32,25 @@ static uintptr_t singleHandle(uiControl *c)
static void singleSetParent(uiControl *c, uintptr_t parent)
{
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()");
- updateParent(oldparent);
+ 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 = 0;
+ if (SetParent(s->hwnd, initialParent) == NULL)
+ logLastError("error removing control parent in singleSetParent()");
+ updateParent(oldparent);
+}
+
static uiSize singlePreferredSize(uiControl *c, uiSizing *d)
{
uiSize size;
@@ -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;
diff --git a/new/stack.c b/new/stack.c
index eaa7a7e..80c2d75 100644
--- a/new/stack.c
+++ b/new/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;
diff --git a/new/uipriv.h b/new/uipriv.h
index 26d06ba..7745c2a 100644
--- a/new/uipriv.h
+++ b/new/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 *);
};