From 320a5686e4a077d464f71a382571d882784321c3 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 28 Mar 2010 13:28:10 +0000 Subject: [PATCH] * The CompoundLayouters were leaked before. Made the class BReferenceable and update references correctly. * LocalLayouter::SetCompoundLayouter(): Remove the local layouter from the previous compound layouter. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35983 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/TwoDimensionalLayout.cpp | 40 ++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/kits/interface/TwoDimensionalLayout.cpp b/src/kits/interface/TwoDimensionalLayout.cpp index b9e32b245f..513efb9c0e 100644 --- a/src/kits/interface/TwoDimensionalLayout.cpp +++ b/src/kits/interface/TwoDimensionalLayout.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006-2009, Ingo Weinhold . + * Copyright 2006-2010, Ingo Weinhold . * All rights reserved. Distributed under the terms of the MIT License. */ @@ -14,6 +14,8 @@ #include #include +#include + #include "ComplexLayouter.h" #include "OneElementLayouter.h" #include "SimpleLayouter.h" @@ -50,7 +52,7 @@ //#define DEBUG_LAYOUT // CompoundLayouter -class BTwoDimensionalLayout::CompoundLayouter { +class BTwoDimensionalLayout::CompoundLayouter : public BReferenceable { public: CompoundLayouter(enum orientation orientation); virtual ~CompoundLayouter(); @@ -138,6 +140,7 @@ private: class BTwoDimensionalLayout::LocalLayouter : private BLayoutContextListener { public: LocalLayouter(BTwoDimensionalLayout* layout); + ~LocalLayouter(); // interface for the BTwoDimensionalLayout class @@ -891,6 +894,20 @@ BTwoDimensionalLayout::LocalLayouter::LocalLayouter( } +BTwoDimensionalLayout::LocalLayouter::~LocalLayouter() +{ + if (fHLayouter != NULL) { + fHLayouter->RemoveLocalLayouter(this); + fHLayouter->ReleaseReference(); + } + + if (fVLayouter != NULL) { + fVLayouter->RemoveLocalLayouter(this); + fVLayouter->ReleaseReference(); + } +} + + BSize BTwoDimensionalLayout::LocalLayouter::MinSize() { @@ -1146,10 +1163,25 @@ void BTwoDimensionalLayout::LocalLayouter::SetCompoundLayouter( CompoundLayouter* compoundLayouter, enum orientation orientation) { - if (orientation == B_HORIZONTAL) + CompoundLayouter* oldCompoundLayouter; + if (orientation == B_HORIZONTAL) { + oldCompoundLayouter = fHLayouter; fHLayouter = compoundLayouter; - else + } else { + oldCompoundLayouter = fVLayouter; fVLayouter = (VerticalCompoundLayouter*)compoundLayouter; + } + + if (compoundLayouter == oldCompoundLayouter) + return; + + if (oldCompoundLayouter != NULL) { + oldCompoundLayouter->RemoveLocalLayouter(this); + oldCompoundLayouter->ReleaseReference(); + } + + if (compoundLayouter != NULL) + compoundLayouter->AcquireReference(); InternalInvalidateLayout(compoundLayouter); }