ui internal destroy

This commit is contained in:
Eduardo Bart 2011-08-22 16:39:46 -03:00
parent 6a3ee47cc5
commit bfa3903940
2 changed files with 39 additions and 38 deletions

View File

@ -32,22 +32,34 @@ UIWidget::UIWidget()
UIWidget::~UIWidget()
{
if(!m_destroyed)
if(!m_destroyed) {
logWarning("widget '", m_id, "' was destructed without being explicit destroyed");
internalDestroy();
}
}
void UIWidget::destroy()
{
// destroy only once
if(!m_destroyed) {
internalDestroy();
// add destroy check event
g_dispatcher.addEvent(std::bind(&UIWidget::internalDestroyCheck, asUIWidget()));
} else
logWarning("attempt to destroy widget '", m_id, "' again");
}
void UIWidget::internalDestroy()
{
// first release lua table, because it may contains references to children
releaseLuaFieldsTable();
// clear additional child references
// clear other references
m_lockedChildren.clear();
m_focusedChild.reset();
m_anchors.clear();
m_anchoredWidgets.clear();
m_focusedChild.reset();
// destroy children
while(m_children.size() > 0) {
@ -59,16 +71,10 @@ void UIWidget::destroy()
if(UIWidgetPtr parent = getParent())
parent->removeChild(asUIWidget());
// by now this widget is destroyed
m_destroyed = true;
// add destroy check event
g_dispatcher.addEvent(std::bind(&UIWidget::destroyCheck, asUIWidget()));
} else
logWarning("attempt to destroy widget '", m_id, "' again");
}
void UIWidget::destroyCheck()
void UIWidget::internalDestroyCheck()
{
// collect lua garbage before checking
g_lua.collectGarbage();
@ -128,7 +134,7 @@ void UIWidget::setParent(const UIWidgetPtr& parent)
// set new parent
if(parent) {
m_parent = UIWidgetWeakPtr(parent);
m_parent = parent;
// add to parent if needed
if(!parent->hasChild(self))
@ -141,9 +147,6 @@ void UIWidget::applyStyle(const std::string& styleName)
try {
OTMLNodePtr styleNode = g_ui.getStyle(styleName);
onStyleApply(styleNode);
// forces layout recalculation
updateLayout();
} catch(std::exception& e) {
logError("couldn't change widget '", m_id, "' style: ", e.what());
}
@ -336,9 +339,7 @@ void UIWidget::focusChild(const UIWidgetPtr& child, UI::FocusReason reason)
{
assert(!m_destroyed);
if(!child)
return;
if(child)
assert(hasChild(child));
if(child != m_focusedChild) {
@ -704,7 +705,7 @@ void UIWidget::internalUpdateChildrenLayout()
// update children layouts
for(const UIWidgetWeakPtr& anchoredWidgetWeak : m_anchoredWidgets) {
if(UIWidgetPtr anchoredWidget = anchoredWidgetWeak.lock())
anchoredWidget->updateLayout();
anchoredWidget->internalUpdateLayout();
}
}
@ -850,10 +851,10 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
addAnchor(edge, hookedWidgetId, hookedEdge);
}
}
else if(node->tag() == "onLoad") {
/*else if(node->tag() == "onLoad") {
g_lua.loadFunction(node->value<std::string>(), "@" + node->source() + "[" + node->tag() + "]");
luaSetField("onLoad");
}
}*/
}
}

View File

@ -116,6 +116,9 @@ public:
UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); }
private:
void internalDestroy();
void internalDestroyCheck();
void internalUpdateLayout();
void internalUpdateChildrenLayout();
@ -154,9 +157,6 @@ protected:
friend class UIManager;
private:
void destroyCheck();
protected:
bool m_enabled;
bool m_visible;