_AddChildToList() was very inefficient in case there was a "before" view
specified. Also, it now drops into the debugger in case "before" doesn't belong to us already. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15198 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+33
-32
@@ -3872,47 +3872,48 @@ BView::_RemoveChildFromList(BView* child)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BView::_AddChildToList(BView* view, BView* before)
|
BView::_AddChildToList(BView* child, BView* before)
|
||||||
{
|
{
|
||||||
if (!view)
|
if (!child)
|
||||||
|
return false;
|
||||||
|
if (child->fParent != NULL) {
|
||||||
|
debugger("View already belongs to someone else");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (before != NULL && before->fParent != this) {
|
||||||
|
debugger("Invalid before view");
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
BView *current = fFirstChild;
|
|
||||||
BView *last = current;
|
|
||||||
|
|
||||||
while (current && current != before) {
|
|
||||||
last = current;
|
|
||||||
current = current->fNextSibling;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!current && before)
|
if (before != NULL) {
|
||||||
return false;
|
// add view before this one
|
||||||
|
child->fNextSibling = before;
|
||||||
|
child->fPreviousSibling = before->fPreviousSibling;
|
||||||
|
if (child->fPreviousSibling != NULL)
|
||||||
|
child->fPreviousSibling->fNextSibling = child;
|
||||||
|
|
||||||
// we're at begining of the list, OR between two elements
|
before->fPreviousSibling = child;
|
||||||
if (current) {
|
if (fFirstChild == before)
|
||||||
if (current == fFirstChild) {
|
fFirstChild = child;
|
||||||
view->fNextSibling = current;
|
|
||||||
current->fPreviousSibling = view;
|
|
||||||
fFirstChild = view;
|
|
||||||
} else {
|
|
||||||
view->fNextSibling = current;
|
|
||||||
view->fPreviousSibling = current->fPreviousSibling;
|
|
||||||
current->fPreviousSibling->fNextSibling = view;
|
|
||||||
current->fPreviousSibling = view;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// we have reached the end of the list
|
// add view to the end of the list
|
||||||
|
BView *last = fFirstChild;
|
||||||
|
while (last != NULL && last->fNextSibling != NULL) {
|
||||||
|
last = last->fNextSibling;
|
||||||
|
}
|
||||||
|
|
||||||
// if last!=NULL then we add to the end. Otherwise, view is the
|
if (last != NULL) {
|
||||||
// first chiild in the list
|
last->fNextSibling = child;
|
||||||
if (last) {
|
child->fPreviousSibling = last;
|
||||||
last->fNextSibling = view;
|
} else {
|
||||||
view->fPreviousSibling = last;
|
fFirstChild = child;
|
||||||
} else
|
child->fPreviousSibling = NULL;
|
||||||
fFirstChild = view;
|
}
|
||||||
|
|
||||||
|
child->fNextSibling = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
view->fParent = this;
|
child->fParent = this;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user