Rename BALM::GroupItem to BALM::ALMGroup, and move it to its own files.
Also make ALMGroup totally self-contained, i.e. BALMLayout no longer does the parsing, and is completely unaware of ALMGroup. A small touch of refactoring as well.
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2012, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef ALMGROUP_H
|
||||
#define ALMGROUP_H
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <InterfaceDefs.h> // for enum orientation
|
||||
#include <Referenceable.h>
|
||||
|
||||
#include "Tab.h"
|
||||
|
||||
|
||||
class BLayoutItem;
|
||||
class BView;
|
||||
|
||||
|
||||
namespace BALM {
|
||||
|
||||
class BALMLayout;
|
||||
|
||||
|
||||
class ALMGroup {
|
||||
public:
|
||||
ALMGroup(BLayoutItem* item);
|
||||
ALMGroup(BView* view);
|
||||
|
||||
BLayoutItem* LayoutItem() const;
|
||||
BView* View() const;
|
||||
|
||||
const std::vector<ALMGroup>& Groups() const;
|
||||
enum orientation Orientation() const;
|
||||
|
||||
ALMGroup& operator|(const ALMGroup& right);
|
||||
ALMGroup& operator/(const ALMGroup& bottom);
|
||||
|
||||
void BuildLayout(BALMLayout* layout,
|
||||
XTab* left = NULL, YTab* top = NULL,
|
||||
XTab* right = NULL, YTab* bottom = NULL);
|
||||
|
||||
private:
|
||||
ALMGroup();
|
||||
|
||||
void _Init(BLayoutItem* item, BView* view,
|
||||
enum orientation orien = B_HORIZONTAL);
|
||||
ALMGroup& _AddItem(const ALMGroup& item,
|
||||
enum orientation orien);
|
||||
|
||||
void _Build(BALMLayout* layout,
|
||||
BReference<XTab> left, BReference<YTab> top,
|
||||
BReference<XTab> right,
|
||||
BReference<YTab> bottom) const;
|
||||
|
||||
|
||||
BLayoutItem* fLayoutItem;
|
||||
BView* fView;
|
||||
|
||||
std::vector<ALMGroup> fGroups;
|
||||
enum orientation fOrientation;
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
using BALM::ALMGroup;
|
||||
|
||||
#endif
|
||||
@@ -22,7 +22,7 @@ namespace BALM {
|
||||
|
||||
|
||||
class Column;
|
||||
class GroupItem;
|
||||
class ALMGroup;
|
||||
class Row;
|
||||
class RowColumnManager;
|
||||
|
||||
@@ -86,10 +86,6 @@ public:
|
||||
YTab* BottomOf(const BView* view) const;
|
||||
YTab* BottomOf(const BLayoutItem* item) const;
|
||||
|
||||
void BuildLayout(GroupItem& item, XTab* left = NULL,
|
||||
YTab* top = NULL, XTab* right = NULL,
|
||||
YTab* bottom = NULL);
|
||||
|
||||
virtual BLayoutItem* AddView(BView* child);
|
||||
virtual BLayoutItem* AddView(int32 index, BView* child);
|
||||
virtual Area* AddView(BView* view, XTab* left, YTab* top,
|
||||
@@ -135,11 +131,6 @@ private:
|
||||
BSize _CalculateMaxSize();
|
||||
BSize _CalculatePreferredSize();
|
||||
|
||||
void _ParseGroupItem(GroupItem& item,
|
||||
BReference<XTab> left, BReference<YTab> top,
|
||||
BReference<XTab> right,
|
||||
BReference<YTab> bottom);
|
||||
|
||||
LinearProgramming::LinearSpec* fSolver;
|
||||
LinearProgramming::LinearSpec fOwnSolver;
|
||||
|
||||
|
||||
+1
-31
@@ -6,11 +6,9 @@
|
||||
#define AREA_H
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <InterfaceDefs.h> // for enum orientation
|
||||
#include <ObjectList.h>
|
||||
#include <Referenceable.h>
|
||||
#include <Rect.h>
|
||||
#include <Size.h>
|
||||
#include <String.h>
|
||||
|
||||
@@ -34,33 +32,6 @@ class XTab;
|
||||
class YTab;
|
||||
|
||||
|
||||
class GroupItem {
|
||||
public:
|
||||
GroupItem(BLayoutItem* item);
|
||||
GroupItem(BView* view);
|
||||
|
||||
BLayoutItem* LayoutItem();
|
||||
BView* View();
|
||||
|
||||
const std::vector<GroupItem>& GroupItems();
|
||||
enum orientation Orientation();
|
||||
|
||||
GroupItem& operator|(const GroupItem& right);
|
||||
GroupItem& operator/(const GroupItem& bottom);
|
||||
private:
|
||||
GroupItem();
|
||||
|
||||
void _Init(BLayoutItem* item, BView* view,
|
||||
enum orientation orien = B_HORIZONTAL);
|
||||
GroupItem& _AddItem(const GroupItem& item,
|
||||
enum orientation orien);
|
||||
|
||||
BLayoutItem* fLayoutItem;
|
||||
BView* fView;
|
||||
|
||||
std::vector<GroupItem> fGroupItems;
|
||||
enum orientation fOrientation;
|
||||
};
|
||||
|
||||
|
||||
class RowColumnManager;
|
||||
@@ -179,7 +150,6 @@ public:
|
||||
} // namespace BALM
|
||||
|
||||
using BALM::Area;
|
||||
using BALM::GroupItem;
|
||||
|
||||
#endif // AREA_H
|
||||
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
#include "ALMGroup.h"
|
||||
|
||||
|
||||
#include <ALMLayout.h>
|
||||
#include <Tab.h>
|
||||
|
||||
|
||||
ALMGroup::ALMGroup(BLayoutItem* item)
|
||||
{
|
||||
_Init(item, NULL);
|
||||
}
|
||||
|
||||
|
||||
ALMGroup::ALMGroup(BView* view)
|
||||
{
|
||||
_Init(NULL, view);
|
||||
}
|
||||
|
||||
|
||||
BLayoutItem*
|
||||
ALMGroup::LayoutItem() const
|
||||
{
|
||||
return fLayoutItem;
|
||||
}
|
||||
|
||||
|
||||
BView*
|
||||
ALMGroup::View() const
|
||||
{
|
||||
return fView;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<ALMGroup>&
|
||||
ALMGroup::Groups() const
|
||||
{
|
||||
return fGroups;
|
||||
}
|
||||
|
||||
|
||||
enum orientation
|
||||
ALMGroup::Orientation() const
|
||||
{
|
||||
return fOrientation;
|
||||
}
|
||||
|
||||
|
||||
ALMGroup&
|
||||
ALMGroup::operator|(const ALMGroup& right)
|
||||
{
|
||||
return _AddItem(right, B_HORIZONTAL);
|
||||
}
|
||||
|
||||
|
||||
ALMGroup&
|
||||
ALMGroup::operator/(const ALMGroup& bottom)
|
||||
{
|
||||
return _AddItem(bottom, B_VERTICAL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ALMGroup::BuildLayout(BALMLayout* layout, XTab* left, YTab* top, XTab* right,
|
||||
YTab* bottom)
|
||||
{
|
||||
if (left == NULL)
|
||||
left = layout->Left();
|
||||
if (top == NULL)
|
||||
top = layout->Top();
|
||||
if (right == NULL)
|
||||
right = layout->Right();
|
||||
if (bottom == NULL)
|
||||
bottom = layout->Bottom();
|
||||
|
||||
_Build(layout, left, top, right, bottom);
|
||||
}
|
||||
|
||||
|
||||
ALMGroup::ALMGroup()
|
||||
{
|
||||
_Init(NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ALMGroup::_Init(BLayoutItem* item, BView* view, enum orientation orien)
|
||||
{
|
||||
fLayoutItem = item;
|
||||
fView = view;
|
||||
fOrientation = orien;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ALMGroup::_Build(BALMLayout* layout, BReference<XTab> left,
|
||||
BReference<YTab> top, BReference<XTab> right, BReference<YTab> bottom) const
|
||||
{
|
||||
if (LayoutItem())
|
||||
layout->AddItem(LayoutItem(), left, top, right, bottom);
|
||||
else if (View()) {
|
||||
layout->AddView(View(), left, top, right, bottom);
|
||||
} else {
|
||||
for (unsigned int i = 0; i < Groups().size(); i++) {
|
||||
const ALMGroup& current = Groups()[i];
|
||||
if (Orientation() == B_HORIZONTAL) {
|
||||
BReference<XTab> currentRight;
|
||||
if (i == Groups().size() - 1)
|
||||
currentRight = right;
|
||||
else
|
||||
currentRight = layout->AddXTab();
|
||||
current._Build(layout, left, top, currentRight, bottom);
|
||||
left = currentRight;
|
||||
} else {
|
||||
BReference<YTab> currentBottom;
|
||||
if (i == Groups().size() - 1)
|
||||
currentBottom = bottom;
|
||||
else
|
||||
currentBottom = layout->AddYTab();
|
||||
current._Build(layout, left, top, right, currentBottom);
|
||||
top = currentBottom;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ALMGroup&
|
||||
ALMGroup::_AddItem(const ALMGroup& item, enum orientation orien)
|
||||
{
|
||||
if (fGroups.size() == 0)
|
||||
fGroups.push_back(*this);
|
||||
else if (fOrientation != orien) {
|
||||
ALMGroup clone = *this;
|
||||
fGroups.clear();
|
||||
_Init(NULL, NULL, orien);
|
||||
fGroups.push_back(clone);
|
||||
}
|
||||
|
||||
_Init(NULL, NULL, orien);
|
||||
fGroups.push_back(item);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <ControlLook.h>
|
||||
|
||||
#include "ALMGroup.h"
|
||||
#include "RowColumnManager.h"
|
||||
#include "ViewLayoutItem.h"
|
||||
|
||||
@@ -352,53 +353,6 @@ BALMLayout::BottomOf(const BLayoutItem* item) const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BALMLayout::BuildLayout(GroupItem& item, XTab* left, YTab* top, XTab* right,
|
||||
YTab* bottom)
|
||||
{
|
||||
if (left == NULL)
|
||||
left = Left();
|
||||
if (top == NULL)
|
||||
top = Top();
|
||||
if (right == NULL)
|
||||
right = Right();
|
||||
if (bottom == NULL)
|
||||
bottom = Bottom();
|
||||
|
||||
_ParseGroupItem(item, left, top, right, bottom);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BALMLayout::_ParseGroupItem(GroupItem& item, BReference<XTab> left,
|
||||
BReference<YTab> top, BReference<XTab> right, BReference<YTab> bottom)
|
||||
{
|
||||
if (item.LayoutItem())
|
||||
AddItem(item.LayoutItem(), left, top, right, bottom);
|
||||
else if (item.View()) {
|
||||
AddView(item.View(), left, top, right, bottom);
|
||||
}
|
||||
else {
|
||||
for (unsigned int i = 0; i < item.GroupItems().size(); i++) {
|
||||
GroupItem& current = const_cast<GroupItem&>(
|
||||
item.GroupItems()[i]);
|
||||
if (item.Orientation() == B_HORIZONTAL) {
|
||||
BReference<XTab> r = (i == item.GroupItems().size() - 1) ? right
|
||||
: AddXTab();
|
||||
_ParseGroupItem(current, left, top, r, bottom);
|
||||
left = r;
|
||||
}
|
||||
else {
|
||||
BReference<YTab> b = (i == item.GroupItems().size() - 1)
|
||||
? bottom : AddYTab();
|
||||
_ParseGroupItem(current, left, top, right, b);
|
||||
top = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BLayoutItem*
|
||||
BALMLayout::AddView(BView* child)
|
||||
{
|
||||
|
||||
@@ -17,94 +17,6 @@
|
||||
|
||||
|
||||
using namespace LinearProgramming;
|
||||
using namespace std;
|
||||
|
||||
|
||||
GroupItem::GroupItem(BLayoutItem* item)
|
||||
{
|
||||
_Init(item, NULL);
|
||||
}
|
||||
|
||||
|
||||
GroupItem::GroupItem(BView* view)
|
||||
{
|
||||
_Init(NULL, view);
|
||||
}
|
||||
|
||||
|
||||
BLayoutItem*
|
||||
GroupItem::LayoutItem()
|
||||
{
|
||||
return fLayoutItem;
|
||||
}
|
||||
|
||||
|
||||
BView*
|
||||
GroupItem::View()
|
||||
{
|
||||
return fView;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<GroupItem>&
|
||||
GroupItem::GroupItems()
|
||||
{
|
||||
return fGroupItems;
|
||||
}
|
||||
|
||||
|
||||
enum orientation
|
||||
GroupItem::Orientation()
|
||||
{
|
||||
return fOrientation;
|
||||
}
|
||||
|
||||
|
||||
GroupItem&
|
||||
GroupItem::operator|(const GroupItem& right)
|
||||
{
|
||||
return _AddItem(right, B_HORIZONTAL);
|
||||
}
|
||||
|
||||
|
||||
GroupItem&
|
||||
GroupItem::operator/(const GroupItem& bottom)
|
||||
{
|
||||
return _AddItem(bottom, B_VERTICAL);
|
||||
}
|
||||
|
||||
|
||||
GroupItem::GroupItem()
|
||||
{
|
||||
_Init(NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GroupItem::_Init(BLayoutItem* item, BView* view, enum orientation orien)
|
||||
{
|
||||
fLayoutItem = item;
|
||||
fView = view;
|
||||
fOrientation = orien;
|
||||
}
|
||||
|
||||
|
||||
GroupItem&
|
||||
GroupItem::_AddItem(const GroupItem& item, enum orientation orien)
|
||||
{
|
||||
if (fGroupItems.size() == 0)
|
||||
fGroupItems.push_back(*this);
|
||||
else if (fOrientation != orien) {
|
||||
GroupItem clone = *this;
|
||||
fGroupItems.clear();
|
||||
_Init(NULL, NULL, orien);
|
||||
fGroupItems.push_back(clone);
|
||||
}
|
||||
|
||||
_Init(NULL, NULL, orien);
|
||||
fGroupItems.push_back(item);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BLayoutItem*
|
||||
|
||||
@@ -7,6 +7,7 @@ UseHeaders [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) kits interface ] ;
|
||||
|
||||
|
||||
SharedLibrary libalm.so :
|
||||
ALMGroup.cpp
|
||||
ALMLayout.cpp
|
||||
ALMLayoutBuilder.cpp
|
||||
Area.cpp
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <Window.h>
|
||||
|
||||
#include "ALMLayout.h"
|
||||
#include "ALMGroup.h"
|
||||
|
||||
|
||||
class OperatorWindow : public BWindow {
|
||||
@@ -37,11 +38,10 @@ public:
|
||||
SetLayout(layout);
|
||||
layout->SetInsets(spacing);
|
||||
|
||||
GroupItem item = GroupItem(button1) | (GroupItem(button2)
|
||||
/ (GroupItem(button3) | GroupItem(BSpaceLayoutItem::CreateGlue())
|
||||
| GroupItem(button4))
|
||||
/ GroupItem(button5));
|
||||
layout->BuildLayout(item);
|
||||
(ALMGroup(button1) | (ALMGroup(button2)
|
||||
/ (ALMGroup(button3) | ALMGroup(BSpaceLayoutItem::CreateGlue())
|
||||
| ALMGroup(button4))
|
||||
/ ALMGroup(button5))).BuildLayout(layout);
|
||||
|
||||
// test size limits
|
||||
BSize min = layout->MinSize();
|
||||
|
||||
Reference in New Issue
Block a user