btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / kits / interface / GroupLayoutBuilder.cpp
blob91231f3498d9b112444118b88bb1afcc146bf3cd
1 /*
2 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
6 #include <GroupLayoutBuilder.h>
8 #include <new>
10 #include <SpaceLayoutItem.h>
13 using std::nothrow;
16 // constructor
17 BGroupLayoutBuilder::BGroupLayoutBuilder(orientation orientation,
18 float spacing)
19 : fRootLayout((new BGroupView(orientation, spacing))->GroupLayout())
21 _PushLayout(fRootLayout);
24 // constructor
25 BGroupLayoutBuilder::BGroupLayoutBuilder(BGroupLayout* layout)
26 : fRootLayout(layout)
28 _PushLayout(fRootLayout);
31 // constructor
32 BGroupLayoutBuilder::BGroupLayoutBuilder(BGroupView* view)
33 : fRootLayout(view->GroupLayout())
35 _PushLayout(fRootLayout);
38 // RootLayout
39 BGroupLayout*
40 BGroupLayoutBuilder::RootLayout() const
42 return fRootLayout;
45 // TopLayout
46 BGroupLayout*
47 BGroupLayoutBuilder::TopLayout() const
49 int32 count = fLayoutStack.CountItems();
50 return (count > 0
51 ? (BGroupLayout*)fLayoutStack.ItemAt(count - 1) : NULL);
54 // GetTopLayout
55 BGroupLayoutBuilder&
56 BGroupLayoutBuilder::GetTopLayout(BGroupLayout** _layout)
58 *_layout = TopLayout();
59 return *this;
62 // TopView
63 BView*
64 BGroupLayoutBuilder::TopView() const
66 if (BGroupLayout* layout = TopLayout())
67 return layout->Owner();
68 return NULL;
71 // GetTopView
72 BGroupLayoutBuilder&
73 BGroupLayoutBuilder::GetTopView(BView** _view)
75 if (BGroupLayout* layout = TopLayout())
76 *_view = layout->Owner();
77 else
78 *_view = NULL;
80 return *this;
83 // Add
84 BGroupLayoutBuilder&
85 BGroupLayoutBuilder::Add(BView* view)
87 if (BGroupLayout* layout = TopLayout())
88 layout->AddView(view);
89 return *this;
92 // Add
93 BGroupLayoutBuilder&
94 BGroupLayoutBuilder::Add(BView* view, float weight)
96 if (BGroupLayout* layout = TopLayout())
97 layout->AddView(view, weight);
98 return *this;
101 // Add
102 BGroupLayoutBuilder&
103 BGroupLayoutBuilder::Add(BLayoutItem* item)
105 if (BGroupLayout* layout = TopLayout())
106 layout->AddItem(item);
107 return *this;
110 // Add
111 BGroupLayoutBuilder&
112 BGroupLayoutBuilder::Add(BLayoutItem* item, float weight)
114 if (BGroupLayout* layout = TopLayout())
115 layout->AddItem(item, weight);
116 return *this;
119 // AddGroup
120 BGroupLayoutBuilder&
121 BGroupLayoutBuilder::AddGroup(orientation orientation, float spacing,
122 float weight)
124 if (BGroupLayout* layout = TopLayout()) {
125 BGroupView* group = new(nothrow) BGroupView(orientation, spacing);
126 if (group) {
127 if (layout->AddView(group, weight))
128 _PushLayout(group->GroupLayout());
129 else
130 delete group;
134 return *this;
137 // End
138 BGroupLayoutBuilder&
139 BGroupLayoutBuilder::End()
141 _PopLayout();
142 return *this;
145 // AddGlue
146 BGroupLayoutBuilder&
147 BGroupLayoutBuilder::AddGlue(float weight)
149 if (BGroupLayout* layout = TopLayout())
150 layout->AddItem(BSpaceLayoutItem::CreateGlue(), weight);
152 return *this;
155 // AddStrut
156 BGroupLayoutBuilder&
157 BGroupLayoutBuilder::AddStrut(float size)
159 if (BGroupLayout* layout = TopLayout()) {
160 if (layout->Orientation() == B_HORIZONTAL)
161 layout->AddItem(BSpaceLayoutItem::CreateHorizontalStrut(size));
162 else
163 layout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(size));
166 return *this;
169 // SetInsets
170 BGroupLayoutBuilder&
171 BGroupLayoutBuilder::SetInsets(float left, float top, float right, float bottom)
173 if (BGroupLayout* layout = TopLayout())
174 layout->SetInsets(left, top, right, bottom);
176 return *this;
179 // cast operator BGroupLayout*
180 BGroupLayoutBuilder::operator BGroupLayout*()
182 return fRootLayout;
185 // _PushLayout
186 bool
187 BGroupLayoutBuilder::_PushLayout(BGroupLayout* layout)
189 return fLayoutStack.AddItem(layout);
192 // _PopLayout
193 void
194 BGroupLayoutBuilder::_PopLayout()
196 int32 count = fLayoutStack.CountItems();
197 if (count > 0)
198 fLayoutStack.RemoveItem(count - 1);