aboutsummaryrefslogtreecommitdiffstats
path: root/src/gwin
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@unormal.org>2014-01-05 20:42:19 +0100
committerJoel Bodenmann <joel@unormal.org>2014-01-05 20:42:19 +0100
commit1778a7f3b1917fceb8bc6b5d48a5548d4e1ee7b9 (patch)
treefaa4489158f4230f57af27e54ae27f9a9b7e8840 /src/gwin
parentf3f3650ca9be377f20fb43159ce18d583f0705c4 (diff)
downloaduGFX-1778a7f3b1917fceb8bc6b5d48a5548d4e1ee7b9.tar.gz
uGFX-1778a7f3b1917fceb8bc6b5d48a5548d4e1ee7b9.tar.bz2
uGFX-1778a7f3b1917fceb8bc6b5d48a5548d4e1ee7b9.zip
gwinDestroy() and gwinRemoveChild()
Diffstat (limited to 'src/gwin')
-rw-r--r--src/gwin/gwin.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c
index 88be0c88..923567ef 100644
--- a/src/gwin/gwin.c
+++ b/src/gwin/gwin.c
@@ -180,18 +180,20 @@ GHandle gwinGWindowCreate(GDisplay *g, GWindowObject *pgw, const GWindowInit *pI
}
void gwinDestroy(GHandle gh) {
+ if (!gh) {
+ // should log a runtime error here
+ return;
+ }
+
#if GWIN_NEED_HIERARCHY
- // fix hierarchy structure
- if (gh->parent->child == gh) {
- // we are the first child
- gh->parent->child = gh->sibling;
- } else {
- // find our predecessor
- GHandle tmp = gh->parent->child;
- while (tmp->sibling != gh)
- tmp = tmp->sibling;
- tmp->sibling = gh->sibling;
- }
+ GHandle tmp;
+
+ // recursively destroy our children first
+ for(tmp = gh->child; tmp; tmp = tmp->sibling)
+ gwinDestroy(tmp);
+
+ // remove myself from the hierarchy
+ gwinRemoveChild(gh);
#endif
// Make the window invisible
@@ -332,6 +334,32 @@ void gwinRedraw(GHandle gh) {
gwinRedraw(parent);
}
+ void gwinRemoveChild(GHandle gh) {
+ if(!gh || !gh->parent) {
+ // without a parent, removing is impossible
+ // should log a runtime error here
+ return;
+ }
+
+ if (gh->parent->child == gh) {
+ // we are the first child, update parent
+ gh->parent->child = gh->sibling;
+ } else {
+ // otherwise find our predecessor
+ GHandle tmp = gh->parent->child;
+ while (tmp && tmp->sibling != gh)
+ tmp = tmp->sibling;
+
+ if(!tmp) {
+ // our parent's children list is corrupted
+ // should log a runtime error here
+ return;
+ }
+
+ tmp->sibling = gh->sibling;
+ }
+ }
+
GHandle gwinGetFirstChild(GHandle gh) {
return gh->child;
}