[haiku-commits] r38793 - in haiku/trunk: headers/libs/alm src/libs/alm

  • From: clemens.zeidler@xxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 23 Sep 2010 09:16:49 +0200 (CEST)

Author: czeidler
Date: 2010-09-23 09:16:49 +0200 (Thu, 23 Sep 2010)
New Revision: 38793
Changeset: http://dev.haiku-os.org/changeset/38793

Modified:
   haiku/trunk/headers/libs/alm/ALMLayout.h
   haiku/trunk/headers/libs/alm/Area.h
   haiku/trunk/src/libs/alm/ALMLayout.cpp
   haiku/trunk/src/libs/alm/Area.cpp
   haiku/trunk/src/libs/alm/Jamfile
Log:
- Implement all Add* function of the BLayout class properly. If the Add* 
functions of the BLayout class are called add the item to the right upper 
corner of the previous area. That is at least better than ignore this functions.
- Add more convenience AddViewTo{Right, Left, Top, Bottom} functions to add a 
item to the sides of an existing area.
- Need to add the Jamfile hack again to include the ViewLayoutItem.h header. I 
thing about to add the ALMLayout.* files to the interface dir when its a little 
bit more matured. Then the problem will be solved. Till I made a decision or 
somebody tell me its a bad idea to add the ALMLayout to the official interface 
stuff or the ViewLayoutItem.h should be in a shared header dir I will keep this 
hack.



Modified: haiku/trunk/headers/libs/alm/ALMLayout.h
===================================================================
--- haiku/trunk/headers/libs/alm/ALMLayout.h    2010-09-23 00:53:33 UTC (rev 
38792)
+++ haiku/trunk/headers/libs/alm/ALMLayout.h    2010-09-23 07:16:49 UTC (rev 
38793)
@@ -38,17 +38,61 @@
                        Column*                         AddColumn();
                        Column*                         AddColumn(XTab* left, 
XTab* right);
 
-                       Area*                           AddArea(XTab* left, 
YTab* top, XTab* right,
-                                                                       YTab* 
bottom, BView* content);
-                       Area*                           AddArea(Row* row, 
Column* column,
-                                                                       BView* 
content);
-                       Area*                           AreaOf(BView* control);
-
                        XTab*                           Left() const;
                        XTab*                           Right() const;
                        YTab*                           Top() const;
                        YTab*                           Bottom() const;
 
+                       char*                           PerformancePath() const;
+                       void                            
SetPerformancePath(char* path);
+
+                       LinearSpec*                     Solver();
+
+                       void                            SetInset(float inset);
+                       float                           Inset();
+
+                       void                            SetSpacing(float 
spacing);
+                       float                           Spacing();
+
+       virtual BLayoutItem*            AddView(BView* child);
+       virtual BLayoutItem*            AddView(int32 index, BView* child);
+       virtual Area*                           AddView(BView* view, XTab* 
left, YTab* top,
+                                                                       XTab* 
right, YTab* bottom);
+       virtual Area*                           AddView(BView* view, Row* row, 
Column* column);
+       virtual Area*                           AddViewToRight(BView* view, 
Area* leftArea,
+                                                                       XTab* 
right = NULL, YTab* top = NULL,
+                                                                       YTab* 
bottom = NULL);
+       virtual Area*                           AddViewToLeft(BView* view, 
Area* rightArea,
+                                                                       XTab* 
left = NULL, YTab* top = NULL,
+                                                                       YTab* 
bottom = NULL);
+       virtual Area*                           AddViewToTop(BView* view, Area* 
bottomArea,
+                                                                       YTab* 
top = NULL, XTab* left = NULL,
+                                                                       XTab* 
right = NULL);
+       virtual Area*                           AddViewToBottom(BView* view, 
Area* topArea,
+                                                                       YTab* 
bottom = NULL, XTab* left = NULL,
+                                                                       XTab* 
right = NULL);
+
+       virtual bool                            AddItem(BLayoutItem* item);
+       virtual bool                            AddItem(int32 index, 
BLayoutItem* item);
+       virtual Area*                           AddItem(BLayoutItem* item, 
XTab* left,
+                                                                       YTab* 
top, XTab* right, YTab* bottom);
+       virtual Area*                           AddItem(BLayoutItem* item, Row* 
row,
+                                                                       Column* 
column);
+       virtual Area*                           AddItemToRight(BLayoutItem* 
item,
+                                                                       Area* 
leftArea, XTab* right = NULL,
+                                                                       YTab* 
top = NULL, YTab* bottom = NULL);
+       virtual Area*                           AddItemToLeft(BLayoutItem* item,
+                                                                       Area* 
rightArea, XTab* left = NULL,
+                                                                       YTab* 
top = NULL, YTab* bottom = NULL);
+       virtual Area*                           AddItemToTop(BLayoutItem* item,
+                                                                       Area* 
bottomArea, YTab* top = NULL,
+                                                                       XTab* 
left = NULL, XTab* right = NULL);
+       virtual Area*                           AddItemToBottom(BLayoutItem* 
item,
+                                                                       Area* 
topArea, YTab* bottom = NULL,
+                                                                       XTab* 
left = NULL, XTab* right = NULL);
+
+       virtual Area*                           AreaOf(BView* control);
+
        virtual BSize                           BaseMinSize();
        virtual BSize                           BaseMaxSize();
        virtual BSize                           BasePreferredSize();
@@ -60,18 +104,10 @@
        virtual void                            ItemRemoved(BLayoutItem* item, 
int32 fromIndex);
        virtual void                            DerivedLayoutItems();
 
-                       char*                           PerformancePath() const;
-                       void                            
SetPerformancePath(char* path);
+private:
+                       /*! Add a view without initialize the Area. */
+                       BLayoutItem*            _CreateLayoutItem(BView* view);
 
-                       LinearSpec*                     Solver();
-
-                       void                            SetInset(float inset);
-                       float                           Inset();
-
-                       void                            SetSpacing(float 
spacing);
-                       float                           Spacing();
-
-private:
                        void                            _SolveLayout();
 
                        Area*                           
_AreaForItem(BLayoutItem* item) const;

Modified: haiku/trunk/headers/libs/alm/Area.h
===================================================================
--- haiku/trunk/headers/libs/alm/Area.h 2010-09-23 00:53:33 UTC (rev 38792)
+++ haiku/trunk/headers/libs/alm/Area.h 2010-09-23 07:16:49 UTC (rev 38793)
@@ -81,9 +81,8 @@
                                                                
Area(BLayoutItem* item);
 
                        void                            _Init(LinearSpec* ls, 
XTab* left, YTab* top,
-                                                                       XTab* 
right, YTab* bottom, BView* content);
-                       void                            _Init(LinearSpec* ls, 
Row* row, Column* column,
-                                                                       BView* 
content);
+                                                                       XTab* 
right, YTab* bottom);
+                       void                            _Init(LinearSpec* ls, 
Row* row, Column* column);
 
                        void                            _DoLayout();
 

Modified: haiku/trunk/src/libs/alm/ALMLayout.cpp
===================================================================
--- haiku/trunk/src/libs/alm/ALMLayout.cpp      2010-09-23 00:53:33 UTC (rev 
38792)
+++ haiku/trunk/src/libs/alm/ALMLayout.cpp      2010-09-23 07:16:49 UTC (rev 
38793)
@@ -11,6 +11,8 @@
 #include <math.h>              // for floor
 #include <new>
 
+#include "ViewLayoutItem.h"
+
 #include "Area.h"
 #include "Column.h"
 #include "ResultType.h"
@@ -144,6 +146,20 @@
 }
 
 
+BLayoutItem*
+BALMLayout::AddView(BView* child)
+{
+       return AddView(-1, child);
+}
+
+
+BLayoutItem*
+BALMLayout::AddView(int32 index, BView* child)
+{
+       return BAbstractLayout::AddView(index, child);
+}
+
+
 /**
  * Adds a new area to the specification, automatically setting preferred size 
constraints.
  *
@@ -155,17 +171,15 @@
  * @return the new area
  */
 Area*
-BALMLayout::AddArea(XTab* left, YTab* top, XTab* right, YTab* bottom,
-       BView* content)
+BALMLayout::AddView(BView* view, XTab* left, YTab* top, XTab* right,
+       YTab* bottom)
 {
-       BLayoutItem* item = AddView(content);
-       Area* area = _AreaForItem(item);
-       if (!area)
+       BLayoutItem* item = _CreateLayoutItem(view);
+       Area* area = AddItem(item, left, top, right, bottom);
+       if (!area) {
+               delete item;
                return NULL;
-
-       area->_Init(&fSolver, left, top, right, bottom, content);
-       area->SetDefaultBehavior();
-       area->SetAutoPreferredContentSize(false);
+       }
        return area;
 }
 
@@ -179,20 +193,209 @@
  * @return the new area
  */
 Area*
-BALMLayout::AddArea(Row* row, Column* column, BView* content)
+BALMLayout::AddView(BView* view, Row* row, Column* column)
 {
-       BLayoutItem* item = AddView(content);
+       BLayoutItem* item = _CreateLayoutItem(view);
+       Area* area = AddItem(item, row, column);
+       if (!area) {
+               delete item;
+               return NULL;
+       }
+       return area;
+}
+
+
+Area*
+BALMLayout::AddViewToRight(BView* view, Area* leftArea, XTab* right, YTab* top,
+       YTab* bottom)
+{
+       BLayoutItem* item = _CreateLayoutItem(view);
+       Area* area = AddItemToRight(item, leftArea, right, top, bottom);
+       if (!area) {
+               delete item;
+               return NULL;
+       }
+       return area;
+}
+
+
+Area*
+BALMLayout::AddViewToLeft(BView* view, Area* rightArea, XTab* left, YTab* top,
+       YTab* bottom)
+{
+       BLayoutItem* item = _CreateLayoutItem(view);
+       Area* area = AddItemToLeft(item, rightArea, left, top, bottom);
+       if (!area) {
+               delete item;
+               return NULL;
+       }
+       return area;
+}
+
+
+Area*
+BALMLayout::AddViewToTop(BView* view, Area* bottomArea, YTab* top, XTab* left,
+       XTab* right)
+{
+       BLayoutItem* item = _CreateLayoutItem(view);
+       Area* area = AddItemToTop(item, bottomArea, top, left, right);
+       if (!area) {
+               delete item;
+               return NULL;
+       }
+       return area;
+}
+
+
+Area*
+BALMLayout::AddViewToBottom(BView* view, Area* topArea, YTab* bottom,
+       XTab* left, XTab* right)
+{
+       BLayoutItem* item = _CreateLayoutItem(view);
+       Area* area = AddItemToBottom(item, topArea, bottom, left, right);
+       if (!area) {
+               delete item;
+               return NULL;
+       }
+       return area;
+}
+
+
+bool
+BALMLayout::AddItem(BLayoutItem* item)
+{
+       return AddItem(-1, item);
+}
+
+
+bool
+BALMLayout::AddItem(int32 index, BLayoutItem* item)
+{
+       if (!item)
+               return NULL;
+
+       // simply add the item at the upper right corner of the previous item
+       // TODO maybe find a more elegant solution
+       XTab* left = Left();
+       YTab* top = Top();
+       XTab* right = AddXTab();
+       YTab* bottom = AddYTab();
+
+       // check range
+       if (index < 0 || index > CountItems())
+               index = CountItems();
+
+       // for index = 0 we already have set the right tabs
+       if (index != 0) {
+               BLayoutItem* prevItem = ItemAt(index - 1);
+               Area* area = _AreaForItem(prevItem);
+               if (area) {
+                       left = area->Right();
+                       top = area->Top();
+               }
+       }
+       Area* area = AddItem(item, left, top, right, bottom);
+       return area ? true : false;
+}
+
+
+Area*
+BALMLayout::AddItem(BLayoutItem* item, XTab* left, YTab* top, XTab* right,
+       YTab* bottom)
+{
+       if (!BAbstractLayout::AddItem(-1, item))
+               return NULL;
        Area* area = _AreaForItem(item);
        if (!area)
                return NULL;
 
-       area->_Init(&fSolver, row, column, content);
+       area->_Init(&fSolver, left, top, right, bottom);
        area->SetDefaultBehavior();
        area->SetAutoPreferredContentSize(false);
        return area;
 }
 
 
+Area*
+BALMLayout::AddItem(BLayoutItem* item, Row* row, Column* column)
+{
+       if (!BAbstractLayout::AddItem(-1, item))
+               return NULL;
+       Area* area = _AreaForItem(item);
+       if (!area)
+               return NULL;
+
+       area->_Init(&fSolver, row, column);
+       area->SetDefaultBehavior();
+       area->SetAutoPreferredContentSize(false);
+       return area;
+}
+
+
+Area*
+BALMLayout::AddItemToRight(BLayoutItem* item, Area* leftArea, XTab* right,
+       YTab* top, YTab* bottom)
+{
+       XTab* left = leftArea->Right();
+       if (!right)
+               right = AddXTab();
+       if (!top)
+               top = leftArea->Top();
+       if (!bottom)
+               bottom = leftArea->Bottom();
+
+       return AddItem(item, left, top, right, bottom);
+}
+
+
+Area*
+BALMLayout::AddItemToLeft(BLayoutItem* item, Area* rightArea, XTab* left,
+       YTab* top, YTab* bottom)
+{
+       if (!left)
+               left = AddXTab();
+       XTab* right = rightArea->Left();
+       if (!top)
+               top = rightArea->Top();
+       if (!bottom)
+               bottom = rightArea->Bottom();
+
+       return AddItem(item, left, top, right, bottom);
+}
+
+
+Area*
+BALMLayout::AddItemToTop(BLayoutItem* item, Area* bottomArea, YTab* top,
+       XTab* left, XTab* right)
+{
+       if (!left)
+               left = bottomArea->Left();
+       if (!right)
+               right = bottomArea->Right();
+       if (!top)
+               top = AddYTab();
+       YTab* bottom = bottomArea->Top();
+
+       return AddItem(item, left, top, right, bottom);
+}
+
+
+Area*
+BALMLayout::AddItemToBottom(BLayoutItem* item, Area* topArea, YTab* bottom,
+       XTab* left, XTab* right)
+{
+       if (!left)
+               left = topArea->Left();
+       if (!right)
+               right = topArea->Right();
+       YTab* top = topArea->Bottom();
+       if (!bottom)
+               bottom = AddYTab();
+
+       return AddItem(item, left, top, right, bottom);
+}
+
+
 /**
  * Finds the area that contains the given control.
  *
@@ -418,6 +621,13 @@
 }
 
 
+BLayoutItem*
+BALMLayout::_CreateLayoutItem(BView* view)
+{
+       return new(std::nothrow) BViewLayoutItem(view);
+}
+
+
 void
 BALMLayout::_SolveLayout()
 {

Modified: haiku/trunk/src/libs/alm/Area.cpp
===================================================================
--- haiku/trunk/src/libs/alm/Area.cpp   2010-09-23 00:53:33 UTC (rev 38792)
+++ haiku/trunk/src/libs/alm/Area.cpp   2010-09-23 07:16:49 UTC (rev 38793)
@@ -549,8 +549,7 @@
  * Initialize variables.
  */
 void
-Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom,
-       BView* content)
+Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom)
 {
        fShrinkPenalties = BSize(2, 2);
        fGrowPenalties = BSize(1, 1);
@@ -578,10 +577,9 @@
 
 
 void
-Area::_Init(LinearSpec* ls, Row* row, Column* column, BView* content)
+Area::_Init(LinearSpec* ls, Row* row, Column* column)
 {
-       _Init(ls, column->Left(), row->Top(), column->Right(), row->Bottom(),
-                 content);
+       _Init(ls, column->Left(), row->Top(), column->Right(), row->Bottom());
        fRow = row;
        fColumn = column;
 }

Modified: haiku/trunk/src/libs/alm/Jamfile
===================================================================
--- haiku/trunk/src/libs/alm/Jamfile    2010-09-23 00:53:33 UTC (rev 38792)
+++ haiku/trunk/src/libs/alm/Jamfile    2010-09-23 07:16:49 UTC (rev 38793)
@@ -4,6 +4,7 @@
 
 UseLibraryHeaders lp_solve linprog alm ;
 UsePrivateHeaders shared ;
+UsePrivateHeaders [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) kits interface ] ;
 
 
 SharedLibrary libalm.so : 
@@ -16,4 +17,3 @@
        :
        be liblpsolve55.so liblinprog.so $(TARGET_LIBSUPC++)
 ;
-


Other related posts:

  • » [haiku-commits] r38793 - in haiku/trunk: headers/libs/alm src/libs/alm - clemens . zeidler