- 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.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38793 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Clemens Zeidler 2010-09-23 07:16:49 +00:00
parent 96e2013e70
commit 21f083af82
5 changed files with 281 additions and 38 deletions

View File

@ -38,28 +38,11 @@ public:
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;
virtual BSize BaseMinSize();
virtual BSize BaseMaxSize();
virtual BSize BasePreferredSize();
virtual BAlignment BaseAlignment();
virtual void InvalidateLayout(bool children = false);
virtual bool ItemAdded(BLayoutItem* item, int32 atIndex);
virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex);
virtual void DerivedLayoutItems();
char* PerformancePath() const;
void SetPerformancePath(char* path);
@ -71,7 +54,60 @@ public:
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();
virtual BAlignment BaseAlignment();
virtual void InvalidateLayout(bool children = false);
virtual bool ItemAdded(BLayoutItem* item, int32 atIndex);
virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex);
virtual void DerivedLayoutItems();
private:
/*! Add a view without initialize the Area. */
BLayoutItem* _CreateLayoutItem(BView* view);
void _SolveLayout();
Area* _AreaForItem(BLayoutItem* item) const;

View File

@ -81,9 +81,8 @@ private:
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();

View File

@ -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 @@ BALMLayout::AddColumn(XTab* left, XTab* right)
}
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 @@ BALMLayout::AddColumn(XTab* left, XTab* right)
* @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 @@ BALMLayout::AddArea(XTab* left, YTab* top, XTab* right, YTab* bottom,
* @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 @@ BALMLayout::Spacing()
}
BLayoutItem*
BALMLayout::_CreateLayoutItem(BView* view)
{
return new(std::nothrow) BViewLayoutItem(view);
}
void
BALMLayout::_SolveLayout()
{

View File

@ -549,8 +549,7 @@ Area::Area(BLayoutItem* item)
* 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 @@ Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom,
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;
}

View File

@ -4,6 +4,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ;
UseLibraryHeaders lp_solve linprog alm ;
UsePrivateHeaders shared ;
UsePrivateHeaders [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) kits interface ] ;
SharedLibrary libalm.so :
@ -16,4 +17,3 @@ SharedLibrary libalm.so :
:
be liblpsolve55.so liblinprog.so $(TARGET_LIBSUPC++)
;