From 618c515c4c100842178d66ab54c04450376429a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 14 Nov 2005 17:39:33 +0000 Subject: [PATCH] * 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 --- src/servers/app/Layer.cpp | 41 ++++++++++---------------------- src/servers/app/Layer.h | 5 ++-- src/servers/app/ServerWindow.cpp | 21 +++++++--------- src/servers/app/WinBorder.cpp | 21 +++++++--------- 4 files changed, 32 insertions(+), 56 deletions(-) diff --git a/src/servers/app/Layer.cpp b/src/servers/app/Layer.cpp index dc2d62ee13..50aaaaff33 100644 --- a/src/servers/app/Layer.cpp +++ b/src/servers/app/Layer.cpp @@ -113,10 +113,17 @@ Layer::~Layer() { delete fDrawState; - // TODO: uncomment! - //PruneTree(); + Layer* child = fFirstChild; + + while (child != NULL) { + Layer* nextChild = child->fNextSibling; + + delete child; + child = nextChild; + } } + /*! \brief Adds a child layer to the current one \param layer a new child layer @@ -889,31 +896,7 @@ Layer::Scale() const 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 Layer::AddToViewsWithInvalidCoords() const { @@ -925,7 +908,7 @@ Layer::AddToViewsWithInvalidCoords() const } } -// SendViewCoordUpdateMsg + void Layer::SendViewCoordUpdateMsg() const { @@ -935,14 +918,14 @@ Layer::SendViewCoordUpdateMsg() const } } -// SetViewColor + void Layer::SetViewColor(const RGBColor& color) { fViewColor = color; } -// SetBackgroundBitmap + void Layer::SetBackgroundBitmap(const ServerBitmap* bitmap) { diff --git a/src/servers/app/Layer.h b/src/servers/app/Layer.h index 3ef813b6c6..77b678df00 100644 --- a/src/servers/app/Layer.h +++ b/src/servers/app/Layer.h @@ -81,6 +81,8 @@ class Layer { void RemoveChild(Layer* child); void RemoveSelf(); bool HasChild(Layer* layer); + Layer* Parent() const + { return fParent; } uint32 CountChildren() const; Layer* FindLayer(const int32 token); @@ -210,9 +212,6 @@ class Layer { virtual void Draw(const BRect& r); void _AllRedraw(const BRegion &invalid); - // others - void PruneTree(); - private: friend class RootLayer; friend class WinBorder; diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index 5c2195d4b2..b5296b565c 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -642,21 +642,19 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) // layer, detach the layer itself, delete it, and invalidate the // area assuming that the view was visible when removed - STRACE(("ServerWindow %s: AS_LAYER_DELETE(self)...\n", fTitle)); - Layer *parent = fCurrentLayer->fParent; -// BRegion *invalidRegion = NULL; - if (!fCurrentLayer->IsHidden() && parent && myRootLayer) { - if (fCurrentLayer->FullVisible().Frame().IsValid()) { - parent->MarkForRebuild(fCurrentLayer->FullVisible()); - myRootLayer->MarkForRedraw(fCurrentLayer->FullVisible()); - } + STRACE(("ServerWindow %s: AS_LAYER_DELETE view: %p, parent: %p\n", fTitle, + fCurrentLayer, parent)); + + if (!fCurrentLayer->IsHidden() && parent && myRootLayer + && fCurrentLayer->FullVisible().Frame().IsValid()) { + parent->MarkForRebuild(fCurrentLayer->FullVisible()); + myRootLayer->MarkForRedraw(fCurrentLayer->FullVisible()); } // here we remove current layer from list. fCurrentLayer->RemoveSelf(); - fCurrentLayer->PruneTree(); if (parent) parent->TriggerRebuild(); @@ -665,14 +663,13 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) myRootLayer->LayerRemoved(fCurrentLayer); myRootLayer->TriggerRedraw(); } - + #ifdef DEBUG_SERVERWINDOW parent->PrintTree(); #endif - STRACE(("DONE: ServerWindow %s: Message AS_DELETE_LAYER: Parent: %s Layer: %s\n", fTitle, parent->Name(), fCurrentLayer->Name())); 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; break; } diff --git a/src/servers/app/WinBorder.cpp b/src/servers/app/WinBorder.cpp index c52a9d1522..019efef75d 100644 --- a/src/servers/app/WinBorder.cpp +++ b/src/servers/app/WinBorder.cpp @@ -146,10 +146,10 @@ WinBorder::~WinBorder() { STRACE(("WinBorder(%s)::~WinBorder()\n", Name())); - delete fTopLayer; delete fDecorator; } + //! redraws a certain section of the window border void 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 (fDecorator) { - WinBorder* wb = GetRootLayer()->Focus(); - if (wb == this) + if (GetRootLayer()->Focus() == this) fDecorator->SetFocus(true); else fDecorator->SetFocus(false); + fDecorator->Draw(r); } } + //! Moves the winborder with redraw void WinBorder::MoveBy(float x, float y) @@ -278,7 +279,7 @@ WinBorder::ResizeBy(float x, float y) Window()->SendMessageToClient(&msg, B_NULL_TOKEN, false); } -// SetName + void WinBorder::SetName(const char* name) { @@ -306,7 +307,7 @@ WinBorder::SetName(const char* name) } } -// UpdateStart + void WinBorder::UpdateStart() { @@ -488,8 +489,6 @@ WinBorder::MouseDown(const BMessage *msg) GetRootLayer()->SetActive(this, false); } else { GetRootLayer()->SetNotifyLayer(this, B_POINTER_EVENTS, 0UL); - - activateWindow: GetRootLayer()->SetActive(this); } } else if (target != NULL) { @@ -632,7 +631,6 @@ WinBorder::Activated(bool active) } -// SetTabLocation void WinBorder::SetTabLocation(float location) { @@ -641,7 +639,6 @@ WinBorder::SetTabLocation(float location) } -// TabLocation float WinBorder::TabLocation() const { @@ -759,7 +756,7 @@ WinBorder::QuietlySetFeel(int32 feel) } } -// _ActionFor + click_type WinBorder::_ActionFor(const BMessage *msg) const { @@ -773,8 +770,8 @@ WinBorder::_ActionFor(const BMessage *msg) const if (fDecorator) return fDecorator->Clicked(where, buttons, modifiers); - else - return DEC_NONE; + + return DEC_NONE; }