gwinDestroy() and gwinRemoveChild()
This commit is contained in:
parent
f3f3650ca9
commit
1778a7f3b1
@ -389,14 +389,26 @@ extern "C" {
|
|||||||
/**
|
/**
|
||||||
* @brief Add a child widget to a parent one
|
* @brief Add a child widget to a parent one
|
||||||
*
|
*
|
||||||
* @param[in] parent The parent widget (does not need to be parent yet)
|
* @param[in] parent The parent window (does not need to be parent yet)
|
||||||
* @param[in] child The child widget
|
* @param[in] child The child window
|
||||||
* @param[in] last Should the child widget be added to the front or the back of the list?
|
* @param[in] last Should the child window be added to the front or the back of the list?
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void gwinAddChild(GHandle parent, GHandle child, bool_t last);
|
void gwinAddChild(GHandle parent, GHandle child, bool_t last);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Remove a child from a parent
|
||||||
|
*
|
||||||
|
* @note Other children of the same parent stay
|
||||||
|
* @note Children of the child are lost, they have to be reassigned manually if necessary.
|
||||||
|
*
|
||||||
|
* @param[in] child The child window
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
void gwinRemoveChild(GHandle child);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get first child of a widget
|
* @brief Get first child of a widget
|
||||||
*
|
*
|
||||||
@ -882,6 +894,10 @@ extern "C" {
|
|||||||
#include "gwin/image.h"
|
#include "gwin/image.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if GWIN_NEED_LAYOUT || defined(__DOXYGEN__)
|
||||||
|
#include "gwin/layout.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* GFX_USE_GWIN */
|
#endif /* GFX_USE_GWIN */
|
||||||
|
|
||||||
#endif /* _GWIN_H */
|
#endif /* _GWIN_H */
|
||||||
|
@ -180,18 +180,20 @@ GHandle gwinGWindowCreate(GDisplay *g, GWindowObject *pgw, const GWindowInit *pI
|
|||||||
}
|
}
|
||||||
|
|
||||||
void gwinDestroy(GHandle gh) {
|
void gwinDestroy(GHandle gh) {
|
||||||
|
if (!gh) {
|
||||||
|
// should log a runtime error here
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#if GWIN_NEED_HIERARCHY
|
#if GWIN_NEED_HIERARCHY
|
||||||
// fix hierarchy structure
|
GHandle tmp;
|
||||||
if (gh->parent->child == gh) {
|
|
||||||
// we are the first child
|
// recursively destroy our children first
|
||||||
gh->parent->child = gh->sibling;
|
for(tmp = gh->child; tmp; tmp = tmp->sibling)
|
||||||
} else {
|
gwinDestroy(tmp);
|
||||||
// find our predecessor
|
|
||||||
GHandle tmp = gh->parent->child;
|
// remove myself from the hierarchy
|
||||||
while (tmp->sibling != gh)
|
gwinRemoveChild(gh);
|
||||||
tmp = tmp->sibling;
|
|
||||||
tmp->sibling = gh->sibling;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Make the window invisible
|
// Make the window invisible
|
||||||
@ -332,6 +334,32 @@ void gwinRedraw(GHandle gh) {
|
|||||||
gwinRedraw(parent);
|
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) {
|
GHandle gwinGetFirstChild(GHandle gh) {
|
||||||
return gh->child;
|
return gh->child;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user