xref: /haiku/src/libs/alm/ALMGroup.cpp (revision 0da6f2e916c5912ab5b2bd2d8aa271cf31a3300a)
1 #include "ALMGroup.h"
2 
3 
4 #include <ALMLayout.h>
5 #include <Tab.h>
6 
7 
8 ALMGroup::ALMGroup(BLayoutItem* item)
9 {
10 	_Init(item, NULL);
11 }
12 
13 
14 ALMGroup::ALMGroup(BView* view)
15 {
16 	_Init(NULL, view);
17 }
18 
19 
20 BLayoutItem*
21 ALMGroup::LayoutItem() const
22 {
23 	return fLayoutItem;
24 }
25 
26 
27 BView*
28 ALMGroup::View() const
29 {
30 	return fView;
31 }
32 
33 
34 const std::vector<ALMGroup>&
35 ALMGroup::Groups() const
36 {
37 	return fGroups;
38 }
39 
40 
41 enum orientation
42 ALMGroup::Orientation() const
43 {
44 	return fOrientation;
45 }
46 
47 
48 ALMGroup&
49 ALMGroup::operator|(const ALMGroup& right)
50 {
51 	return _AddItem(right, B_HORIZONTAL);
52 }
53 
54 
55 ALMGroup&
56 ALMGroup::operator/(const ALMGroup& bottom)
57 {
58 	return _AddItem(bottom, B_VERTICAL);
59 }
60 
61 
62 void
63 ALMGroup::BuildLayout(BALMLayout* layout, XTab* left, YTab* top, XTab* right,
64 	YTab* bottom)
65 {
66 	if (left == NULL)
67 		left = layout->Left();
68 	if (top == NULL)
69 		top = layout->Top();
70 	if (right == NULL)
71 		right = layout->Right();
72 	if (bottom == NULL)
73 		bottom = layout->Bottom();
74 
75 	_Build(layout, left, top, right, bottom);
76 }
77 
78 
79 ALMGroup::ALMGroup()
80 {
81 	_Init(NULL, NULL);
82 }
83 
84 
85 void
86 ALMGroup::_Init(BLayoutItem* item, BView* view, enum orientation orien)
87 {
88 	fLayoutItem = item;
89 	fView = view;
90 	fOrientation = orien;
91 }
92 
93 
94 void
95 ALMGroup::_Build(BALMLayout* layout, BReference<XTab> left,
96 	BReference<YTab> top, BReference<XTab> right, BReference<YTab> bottom) const
97 {
98 	if (LayoutItem())
99 		layout->AddItem(LayoutItem(), left, top, right, bottom);
100 	else if (View()) {
101 		layout->AddView(View(), left, top, right, bottom);
102 	} else {
103 		for (unsigned int i = 0; i < Groups().size(); i++) {
104 			const ALMGroup& current = Groups()[i];
105 			if (Orientation() == B_HORIZONTAL) {
106 				BReference<XTab> currentRight;
107 				if (i == Groups().size() - 1)
108 					currentRight = right;
109 				else
110 					currentRight = layout->AddXTab();
111 				current._Build(layout, left, top, currentRight, bottom);
112 				left = currentRight;
113 			} else {
114 				BReference<YTab> currentBottom;
115 				if (i == Groups().size() - 1)
116 					currentBottom = bottom;
117 				else
118 					currentBottom = layout->AddYTab();
119 				current._Build(layout, left, top, right, currentBottom);
120 				top = currentBottom;
121 			}
122 		}
123 	}
124 }
125 
126 
127 ALMGroup&
128 ALMGroup::_AddItem(const ALMGroup& item, enum orientation orien)
129 {
130 	if (fGroups.size() == 0)
131 		fGroups.push_back(*this);
132 	else if (fOrientation != orien) {
133 		ALMGroup clone = *this;
134 		fGroups.clear();
135 		_Init(NULL, NULL, orien);
136 		fGroups.push_back(clone);
137 	}
138 
139 	_Init(NULL, NULL, orien);
140 	fGroups.push_back(item);
141 	return *this;
142 }
143 
144