[haiku-commits] r35983 - haiku/trunk/src/kits/interface

  • From: ingo_weinhold@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 28 Mar 2010 15:28:10 +0200 (CEST)

Author: bonefish
Date: 2010-03-28 15:28:10 +0200 (Sun, 28 Mar 2010)
New Revision: 35983
Changeset: http://dev.haiku-os.org/changeset/35983/haiku

Modified:
   haiku/trunk/src/kits/interface/TwoDimensionalLayout.cpp
Log:
* The CompoundLayouters were leaked before. Made the class BReferenceable and
  update references correctly.
* LocalLayouter::SetCompoundLayouter(): Remove the local layouter from the
  previous compound layouter.


Modified: haiku/trunk/src/kits/interface/TwoDimensionalLayout.cpp
===================================================================
--- haiku/trunk/src/kits/interface/TwoDimensionalLayout.cpp     2010-03-27 
22:41:43 UTC (rev 35982)
+++ haiku/trunk/src/kits/interface/TwoDimensionalLayout.cpp     2010-03-28 
13:28:10 UTC (rev 35983)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006-2009, Ingo Weinhold <ingo_weinhold@xxxxxx>.
+ * Copyright 2006-2010, Ingo Weinhold <ingo_weinhold@xxxxxx>.
  * All rights reserved. Distributed under the terms of the MIT License.
  */
 
@@ -14,6 +14,8 @@
 #include <List.h>
 #include <View.h>
 
+#include <Referenceable.h>
+
 #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 @@
 class BTwoDimensionalLayout::LocalLayouter : private BLayoutContextListener {
 public:
                                                                
LocalLayouter(BTwoDimensionalLayout* layout);
+                                                               
~LocalLayouter();
 
        // interface for the BTwoDimensionalLayout class
 
@@ -891,6 +894,20 @@
 }
 
 
+BTwoDimensionalLayout::LocalLayouter::~LocalLayouter()
+{
+       if (fHLayouter != NULL) {
+               fHLayouter->RemoveLocalLayouter(this);
+               fHLayouter->ReleaseReference();
+       }
+
+       if (fVLayouter != NULL) {
+               fVLayouter->RemoveLocalLayouter(this);
+               fVLayouter->ReleaseReference();
+       }
+}
+
+
 BSize
 BTwoDimensionalLayout::LocalLayouter::MinSize()
 {
@@ -1146,11 +1163,26 @@
 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);
 }
 


Other related posts:

  • » [haiku-commits] r35983 - haiku/trunk/src/kits/interface - ingo_weinhold