* pruned Layer::PruneTree()

* the Layer destructor now deletes all of the layer's children
* WinBorder no longer has to delete its top layer, as it's also its child.
* minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14919 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2005-11-14 17:39:33 +00:00
parent 4a71b881a9
commit 618c515c4c
4 changed files with 32 additions and 56 deletions

View File

@ -113,10 +113,17 @@ Layer::~Layer()
{ {
delete fDrawState; delete fDrawState;
// TODO: uncomment! Layer* child = fFirstChild;
//PruneTree();
while (child != NULL) {
Layer* nextChild = child->fNextSibling;
delete child;
child = nextChild;
}
} }
/*! /*!
\brief Adds a child layer to the current one \brief Adds a child layer to the current one
\param layer a new child layer \param layer a new child layer
@ -889,31 +896,7 @@ Layer::Scale() const
return CurrentState()->Scale(); return CurrentState()->Scale();
} }
//! Recursively deletes all children of the calling layer
void
Layer::PruneTree(void)
{
Layer* child;
Layer* nextChild;
child = fFirstChild;
fFirstChild = NULL;
while (child != NULL) {
if (child->fFirstChild != NULL)
child->PruneTree();
nextChild = child->fNextSibling;
child->fNextSibling = NULL;
delete child;
child = nextChild;
}
// Man, this thing is short. Elegant, ain't it? :P
}
// AddToViewsWithInvalidCoords
void void
Layer::AddToViewsWithInvalidCoords() const Layer::AddToViewsWithInvalidCoords() const
{ {
@ -925,7 +908,7 @@ Layer::AddToViewsWithInvalidCoords() const
} }
} }
// SendViewCoordUpdateMsg
void void
Layer::SendViewCoordUpdateMsg() const Layer::SendViewCoordUpdateMsg() const
{ {
@ -935,14 +918,14 @@ Layer::SendViewCoordUpdateMsg() const
} }
} }
// SetViewColor
void void
Layer::SetViewColor(const RGBColor& color) Layer::SetViewColor(const RGBColor& color)
{ {
fViewColor = color; fViewColor = color;
} }
// SetBackgroundBitmap
void void
Layer::SetBackgroundBitmap(const ServerBitmap* bitmap) Layer::SetBackgroundBitmap(const ServerBitmap* bitmap)
{ {

View File

@ -81,6 +81,8 @@ class Layer {
void RemoveChild(Layer* child); void RemoveChild(Layer* child);
void RemoveSelf(); void RemoveSelf();
bool HasChild(Layer* layer); bool HasChild(Layer* layer);
Layer* Parent() const
{ return fParent; }
uint32 CountChildren() const; uint32 CountChildren() const;
Layer* FindLayer(const int32 token); Layer* FindLayer(const int32 token);
@ -210,9 +212,6 @@ class Layer {
virtual void Draw(const BRect& r); virtual void Draw(const BRect& r);
void _AllRedraw(const BRegion &invalid); void _AllRedraw(const BRegion &invalid);
// others
void PruneTree();
private: private:
friend class RootLayer; friend class RootLayer;
friend class WinBorder; friend class WinBorder;

View File

@ -642,21 +642,19 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// layer, detach the layer itself, delete it, and invalidate the // layer, detach the layer itself, delete it, and invalidate the
// area assuming that the view was visible when removed // area assuming that the view was visible when removed
STRACE(("ServerWindow %s: AS_LAYER_DELETE(self)...\n", fTitle));
Layer *parent = fCurrentLayer->fParent; Layer *parent = fCurrentLayer->fParent;
// BRegion *invalidRegion = NULL;
if (!fCurrentLayer->IsHidden() && parent && myRootLayer) { STRACE(("ServerWindow %s: AS_LAYER_DELETE view: %p, parent: %p\n", fTitle,
if (fCurrentLayer->FullVisible().Frame().IsValid()) { fCurrentLayer, parent));
parent->MarkForRebuild(fCurrentLayer->FullVisible());
myRootLayer->MarkForRedraw(fCurrentLayer->FullVisible()); if (!fCurrentLayer->IsHidden() && parent && myRootLayer
} && fCurrentLayer->FullVisible().Frame().IsValid()) {
parent->MarkForRebuild(fCurrentLayer->FullVisible());
myRootLayer->MarkForRedraw(fCurrentLayer->FullVisible());
} }
// here we remove current layer from list. // here we remove current layer from list.
fCurrentLayer->RemoveSelf(); fCurrentLayer->RemoveSelf();
fCurrentLayer->PruneTree();
if (parent) if (parent)
parent->TriggerRebuild(); parent->TriggerRebuild();
@ -665,14 +663,13 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
myRootLayer->LayerRemoved(fCurrentLayer); myRootLayer->LayerRemoved(fCurrentLayer);
myRootLayer->TriggerRedraw(); myRootLayer->TriggerRedraw();
} }
#ifdef DEBUG_SERVERWINDOW #ifdef DEBUG_SERVERWINDOW
parent->PrintTree(); parent->PrintTree();
#endif #endif
STRACE(("DONE: ServerWindow %s: Message AS_DELETE_LAYER: Parent: %s Layer: %s\n", fTitle, parent->Name(), fCurrentLayer->Name()));
delete fCurrentLayer; delete fCurrentLayer;
// TODO: It is necessary to do this, but I find it very obscure. // TODO: It is necessary to do this, but I find it very obscure.
fCurrentLayer = parent; fCurrentLayer = parent;
break; break;
} }

View File

@ -146,10 +146,10 @@ WinBorder::~WinBorder()
{ {
STRACE(("WinBorder(%s)::~WinBorder()\n", Name())); STRACE(("WinBorder(%s)::~WinBorder()\n", Name()));
delete fTopLayer;
delete fDecorator; delete fDecorator;
} }
//! redraws a certain section of the window border //! redraws a certain section of the window border
void void
WinBorder::Draw(const BRect &r) WinBorder::Draw(const BRect &r)
@ -161,15 +161,16 @@ WinBorder::Draw(const BRect &r)
// if we have a visible region, it is decorator's one. // if we have a visible region, it is decorator's one.
if (fDecorator) { if (fDecorator) {
WinBorder* wb = GetRootLayer()->Focus(); if (GetRootLayer()->Focus() == this)
if (wb == this)
fDecorator->SetFocus(true); fDecorator->SetFocus(true);
else else
fDecorator->SetFocus(false); fDecorator->SetFocus(false);
fDecorator->Draw(r); fDecorator->Draw(r);
} }
} }
//! Moves the winborder with redraw //! Moves the winborder with redraw
void void
WinBorder::MoveBy(float x, float y) WinBorder::MoveBy(float x, float y)
@ -278,7 +279,7 @@ WinBorder::ResizeBy(float x, float y)
Window()->SendMessageToClient(&msg, B_NULL_TOKEN, false); Window()->SendMessageToClient(&msg, B_NULL_TOKEN, false);
} }
// SetName
void void
WinBorder::SetName(const char* name) WinBorder::SetName(const char* name)
{ {
@ -306,7 +307,7 @@ WinBorder::SetName(const char* name)
} }
} }
// UpdateStart
void void
WinBorder::UpdateStart() WinBorder::UpdateStart()
{ {
@ -488,8 +489,6 @@ WinBorder::MouseDown(const BMessage *msg)
GetRootLayer()->SetActive(this, false); GetRootLayer()->SetActive(this, false);
} else { } else {
GetRootLayer()->SetNotifyLayer(this, B_POINTER_EVENTS, 0UL); GetRootLayer()->SetNotifyLayer(this, B_POINTER_EVENTS, 0UL);
activateWindow:
GetRootLayer()->SetActive(this); GetRootLayer()->SetActive(this);
} }
} else if (target != NULL) { } else if (target != NULL) {
@ -632,7 +631,6 @@ WinBorder::Activated(bool active)
} }
// SetTabLocation
void void
WinBorder::SetTabLocation(float location) WinBorder::SetTabLocation(float location)
{ {
@ -641,7 +639,6 @@ WinBorder::SetTabLocation(float location)
} }
// TabLocation
float float
WinBorder::TabLocation() const WinBorder::TabLocation() const
{ {
@ -759,7 +756,7 @@ WinBorder::QuietlySetFeel(int32 feel)
} }
} }
// _ActionFor
click_type click_type
WinBorder::_ActionFor(const BMessage *msg) const WinBorder::_ActionFor(const BMessage *msg) const
{ {
@ -773,8 +770,8 @@ WinBorder::_ActionFor(const BMessage *msg) const
if (fDecorator) if (fDecorator)
return fDecorator->Clicked(where, buttons, modifiers); return fDecorator->Clicked(where, buttons, modifiers);
else
return DEC_NONE; return DEC_NONE;
} }