2 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
6 #include <GroupLayoutBuilder.h>
10 #include <SpaceLayoutItem.h>
17 BGroupLayoutBuilder::BGroupLayoutBuilder(orientation orientation
,
19 : fRootLayout((new BGroupView(orientation
, spacing
))->GroupLayout())
21 _PushLayout(fRootLayout
);
25 BGroupLayoutBuilder::BGroupLayoutBuilder(BGroupLayout
* layout
)
28 _PushLayout(fRootLayout
);
32 BGroupLayoutBuilder::BGroupLayoutBuilder(BGroupView
* view
)
33 : fRootLayout(view
->GroupLayout())
35 _PushLayout(fRootLayout
);
40 BGroupLayoutBuilder::RootLayout() const
47 BGroupLayoutBuilder::TopLayout() const
49 int32 count
= fLayoutStack
.CountItems();
51 ? (BGroupLayout
*)fLayoutStack
.ItemAt(count
- 1) : NULL
);
56 BGroupLayoutBuilder::GetTopLayout(BGroupLayout
** _layout
)
58 *_layout
= TopLayout();
64 BGroupLayoutBuilder::TopView() const
66 if (BGroupLayout
* layout
= TopLayout())
67 return layout
->Owner();
73 BGroupLayoutBuilder::GetTopView(BView
** _view
)
75 if (BGroupLayout
* layout
= TopLayout())
76 *_view
= layout
->Owner();
85 BGroupLayoutBuilder::Add(BView
* view
)
87 if (BGroupLayout
* layout
= TopLayout())
88 layout
->AddView(view
);
94 BGroupLayoutBuilder::Add(BView
* view
, float weight
)
96 if (BGroupLayout
* layout
= TopLayout())
97 layout
->AddView(view
, weight
);
103 BGroupLayoutBuilder::Add(BLayoutItem
* item
)
105 if (BGroupLayout
* layout
= TopLayout())
106 layout
->AddItem(item
);
112 BGroupLayoutBuilder::Add(BLayoutItem
* item
, float weight
)
114 if (BGroupLayout
* layout
= TopLayout())
115 layout
->AddItem(item
, weight
);
121 BGroupLayoutBuilder::AddGroup(orientation orientation
, float spacing
,
124 if (BGroupLayout
* layout
= TopLayout()) {
125 BGroupView
* group
= new(nothrow
) BGroupView(orientation
, spacing
);
127 if (layout
->AddView(group
, weight
))
128 _PushLayout(group
->GroupLayout());
139 BGroupLayoutBuilder::End()
147 BGroupLayoutBuilder::AddGlue(float weight
)
149 if (BGroupLayout
* layout
= TopLayout())
150 layout
->AddItem(BSpaceLayoutItem::CreateGlue(), weight
);
157 BGroupLayoutBuilder::AddStrut(float size
)
159 if (BGroupLayout
* layout
= TopLayout()) {
160 if (layout
->Orientation() == B_HORIZONTAL
)
161 layout
->AddItem(BSpaceLayoutItem::CreateHorizontalStrut(size
));
163 layout
->AddItem(BSpaceLayoutItem::CreateVerticalStrut(size
));
171 BGroupLayoutBuilder::SetInsets(float left
, float top
, float right
, float bottom
)
173 if (BGroupLayout
* layout
= TopLayout())
174 layout
->SetInsets(left
, top
, right
, bottom
);
179 // cast operator BGroupLayout*
180 BGroupLayoutBuilder::operator BGroupLayout
*()
187 BGroupLayoutBuilder::_PushLayout(BGroupLayout
* layout
)
189 return fLayoutStack
.AddItem(layout
);
194 BGroupLayoutBuilder::_PopLayout()
196 int32 count
= fLayoutStack
.CountItems();
198 fLayoutStack
.RemoveItem(count
- 1);