From 8fc80f17d97550b5da5ee6ec72d525bd2661af1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 28 Nov 2005 23:27:20 +0000 Subject: [PATCH] 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 --- src/servers/app/Layer.cpp | 115 ++++++++++++++++++++++++++------------ src/servers/app/Layer.h | 3 + 2 files changed, 82 insertions(+), 36 deletions(-) diff --git a/src/servers/app/Layer.cpp b/src/servers/app/Layer.cpp index a116e31ee6..6eb86b3fa9 100644 --- a/src/servers/app/Layer.cpp +++ b/src/servers/app/Layer.cpp @@ -136,18 +136,8 @@ Layer::AddChild(Layer* child, ServerWindow* window) return; } - // 1) attach layer to the tree structure - child->fParent = this; - - // 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; + // attach layer to the tree structure + _AddChildToList(child); // 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 @@ -224,30 +214,13 @@ Layer::RemoveChild(Layer *child) return; } - // 1) 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; + // remove this layer from the main tree. - if (child->fNextSibling != NULL) - child->fNextSibling->fPreviousSibling = child->fPreviousSibling; - - child->fPreviousSibling = NULL; - child->fNextSibling = NULL; + _RemoveChildFromList(child); child->_ClearVisibleRegions(); - // 2) Iterate over all of the removed-layer's descendants and unset the - // root layer, server window, and all redraw-related regions + // iterate over all of the removed-layer's descendants and unset the + // root layer, server window, and all redraw-related regions Layer* stop = child; 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 void Layer::RemoveSelf() @@ -488,9 +531,9 @@ Layer::IsHidden(void) const if (fHidden) return true; - if (fParent) - return fParent->IsHidden(); - + if (fParent != NULL) + return fParent->IsHidden(); + return fHidden; } diff --git a/src/servers/app/Layer.h b/src/servers/app/Layer.h index 706baa74cb..9c038b5e7c 100644 --- a/src/servers/app/Layer.h +++ b/src/servers/app/Layer.h @@ -210,6 +210,9 @@ class Layer { friend class RootLayer; friend class ServerWindow; + bool _AddChildToList(Layer* child, Layer* before = NULL); + void _RemoveChildFromList(Layer* child); + // private clipping stuff virtual void _ReserveRegions(BRegion ®); void _RebuildVisibleRegions( const BRegion &invalid,