refactored a _AddChildToList() and a _RemoveChildFromList() out of AddChild() and

RemoveChild() (very similar to what BView does).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15206 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-11-28 23:27:20 +00:00
parent ae0a90cedb
commit 8fc80f17d9
2 changed files with 82 additions and 36 deletions
+79 -36
View File
@@ -136,18 +136,8 @@ Layer::AddChild(Layer* child, ServerWindow* window)
return; return;
} }
// 1) attach layer to the tree structure // attach layer to the tree structure
child->fParent = this; _AddChildToList(child);
// if we have children already, bump the current last child back one and
// make the new child the last layer
if (fLastChild) {
child->fPreviousSibling = fLastChild;
fLastChild->fNextSibling = child;
} else {
fFirstChild = child;
}
fLastChild = child;
// if we have no RootLayer yet, then there is no need to set any parameters -- // if we have no RootLayer yet, then there is no need to set any parameters --
// they will be set when the RootLayer for this tree will be added // they will be set when the RootLayer for this tree will be added
@@ -224,30 +214,13 @@ Layer::RemoveChild(Layer *child)
return; return;
} }
// 1) remove this layer from the main tree. // remove this layer from the main tree.
// Take care of fParent
child->fParent = NULL;
if (fFirstChild == child)
fFirstChild = child->fNextSibling;
if (fLastChild == child)
fLastChild = child->fPreviousSibling;
// Take care of siblings
if (child->fPreviousSibling != NULL)
child->fPreviousSibling->fNextSibling = child->fNextSibling;
if (child->fNextSibling != NULL) _RemoveChildFromList(child);
child->fNextSibling->fPreviousSibling = child->fPreviousSibling;
child->fPreviousSibling = NULL;
child->fNextSibling = NULL;
child->_ClearVisibleRegions(); child->_ClearVisibleRegions();
// 2) Iterate over all of the removed-layer's descendants and unset the // iterate over all of the removed-layer's descendants and unset the
// root layer, server window, and all redraw-related regions // root layer, server window, and all redraw-related regions
Layer* stop = child; Layer* stop = child;
while (true) { while (true) {
@@ -287,6 +260,76 @@ Layer::RemoveChild(Layer *child)
} }
bool
Layer::_AddChildToList(Layer* child, Layer* before)
{
if (!child)
return false;
if (child->fParent != NULL) {
debugger("Layer already belongs to someone else");
return false;
}
if (before != NULL && before->fParent != this) {
debugger("Invalid before layer");
return false;
}
if (before != NULL) {
// add view before this one
child->fNextSibling = before;
child->fPreviousSibling = before->fPreviousSibling;
if (child->fPreviousSibling != NULL)
child->fPreviousSibling->fNextSibling = child;
before->fPreviousSibling = child;
if (fFirstChild == before)
fFirstChild = child;
} else {
// add view to the end of the list
if (fLastChild != NULL) {
fLastChild->fNextSibling = child;
child->fPreviousSibling = fLastChild;
} else {
fFirstChild = child;
child->fPreviousSibling = NULL;
}
child->fNextSibling = NULL;
fLastChild = child;
}
child->fParent = this;
return true;
}
void
Layer::_RemoveChildFromList(Layer* child)
{
// update first/last layers
if (fFirstChild == child) {
// it's the first child
fFirstChild = child->fNextSibling;
} else {
// it must have a previous sibling
child->fPreviousSibling->fNextSibling = child->fNextSibling;
}
if (fLastChild == child) {
// it's the last child
fLastChild = child->fPreviousSibling;
} else {
// it must have a next sibling
child->fNextSibling->fPreviousSibling = child->fPreviousSibling;
}
child->fPreviousSibling = NULL;
child->fNextSibling = NULL;
child->fParent = NULL;
}
//! Removes the calling layer from the tree //! Removes the calling layer from the tree
void void
Layer::RemoveSelf() Layer::RemoveSelf()
@@ -488,9 +531,9 @@ Layer::IsHidden(void) const
if (fHidden) if (fHidden)
return true; return true;
if (fParent) if (fParent != NULL)
return fParent->IsHidden(); return fParent->IsHidden();
return fHidden; return fHidden;
} }
+3
View File
@@ -210,6 +210,9 @@ class Layer {
friend class RootLayer; friend class RootLayer;
friend class ServerWindow; friend class ServerWindow;
bool _AddChildToList(Layer* child, Layer* before = NULL);
void _RemoveChildFromList(Layer* child);
// private clipping stuff // private clipping stuff
virtual void _ReserveRegions(BRegion &reg); virtual void _ReserveRegions(BRegion &reg);
void _RebuildVisibleRegions( const BRegion &invalid, void _RebuildVisibleRegions( const BRegion &invalid,