tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / kits / interface / SpaceLayoutItem.cpp
bloba863780fe9b69b73acc4e9bb890b855769a62806
1 /*
2 * Copyright 2010, Haiku, Inc.
3 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
4 * All rights reserved. Distributed under the terms of the MIT License.
5 */
8 #include <SpaceLayoutItem.h>
10 #include <new>
12 #include <ControlLook.h>
13 #include <Message.h>
16 namespace {
17 const char* const kSizesField = "BSpaceLayoutItem:sizes";
18 // kSizesField = {min, max, preferred}
19 const char* const kAlignmentField = "BSpaceLayoutItem:alignment";
20 const char* const kFrameField = "BSpaceLayoutItem:frame";
21 const char* const kVisibleField = "BSpaceLayoutItem:visible";
23 BSize& ComposeSpacingInPlace(BSize& size)
25 size.width = BControlLook::ComposeSpacing(size.width);
26 size.height = BControlLook::ComposeSpacing(size.height);
27 return size;
32 BSpaceLayoutItem::BSpaceLayoutItem(BSize minSize, BSize maxSize,
33 BSize preferredSize, BAlignment alignment)
35 fFrame(),
36 fMinSize(ComposeSpacingInPlace(minSize)),
37 fMaxSize(ComposeSpacingInPlace(maxSize)),
38 fPreferredSize(ComposeSpacingInPlace(preferredSize)),
39 fAlignment(alignment),
40 fVisible(true)
45 BSpaceLayoutItem::BSpaceLayoutItem(BMessage* archive)
47 BLayoutItem(archive)
49 archive->FindSize(kSizesField, 0, &fMinSize);
50 archive->FindSize(kSizesField, 1, &fMaxSize);
51 archive->FindSize(kSizesField, 2, &fPreferredSize);
53 archive->FindAlignment(kAlignmentField, &fAlignment);
55 archive->FindRect(kFrameField, &fFrame);
56 archive->FindBool(kVisibleField, &fVisible);
60 BSpaceLayoutItem::~BSpaceLayoutItem()
65 BSpaceLayoutItem*
66 BSpaceLayoutItem::CreateGlue()
68 return new BSpaceLayoutItem(
69 BSize(-1, -1),
70 BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED),
71 BSize(-1, -1),
72 BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
76 BSpaceLayoutItem*
77 BSpaceLayoutItem::CreateHorizontalStrut(float width)
79 return new BSpaceLayoutItem(
80 BSize(width, -1),
81 BSize(width, B_SIZE_UNLIMITED),
82 BSize(width, -1),
83 BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
87 BSpaceLayoutItem*
88 BSpaceLayoutItem::CreateVerticalStrut(float height)
90 return new BSpaceLayoutItem(
91 BSize(-1, height),
92 BSize(B_SIZE_UNLIMITED, height),
93 BSize(-1, height),
94 BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
98 BSize
99 BSpaceLayoutItem::MinSize()
101 return fMinSize;
105 BSize
106 BSpaceLayoutItem::MaxSize()
108 return fMaxSize;
112 BSize
113 BSpaceLayoutItem::PreferredSize()
115 return fPreferredSize;
119 BAlignment
120 BSpaceLayoutItem::Alignment()
122 return fAlignment;
126 void
127 BSpaceLayoutItem::SetExplicitMinSize(BSize size)
129 if (size.IsWidthSet())
130 fMinSize.width = size.width;
131 if (size.IsHeightSet())
132 fMinSize.height = size.height;
134 InvalidateLayout();
138 void
139 BSpaceLayoutItem::SetExplicitMaxSize(BSize size)
141 if (size.IsWidthSet())
142 fMaxSize.width = size.width;
143 if (size.IsHeightSet())
144 fMaxSize.height = size.height;
146 InvalidateLayout();
150 void
151 BSpaceLayoutItem::SetExplicitPreferredSize(BSize size)
153 if (size.IsWidthSet())
154 fPreferredSize.width = size.width;
155 if (size.IsHeightSet())
156 fPreferredSize.height = size.height;
158 InvalidateLayout();
162 void
163 BSpaceLayoutItem::SetExplicitAlignment(BAlignment alignment)
165 if (alignment.IsHorizontalSet())
166 fAlignment.horizontal = alignment.horizontal;
167 if (alignment.IsVerticalSet())
168 fAlignment.vertical = alignment.vertical;
170 InvalidateLayout();
174 bool
175 BSpaceLayoutItem::IsVisible()
177 return fVisible;
181 void
182 BSpaceLayoutItem::SetVisible(bool visible)
184 fVisible = visible;
188 BRect
189 BSpaceLayoutItem::Frame()
191 return fFrame;
195 void
196 BSpaceLayoutItem::SetFrame(BRect frame)
198 fFrame = frame;
202 status_t
203 BSpaceLayoutItem::Archive(BMessage* into, bool deep) const
205 status_t err = BLayoutItem::Archive(into, deep);
207 if (err == B_OK)
208 err = into->AddRect(kFrameField, fFrame);
210 if (err == B_OK)
211 err = into->AddSize(kSizesField, fMinSize);
213 if (err == B_OK)
214 err = into->AddSize(kSizesField, fMaxSize);
216 if (err == B_OK)
217 err = into->AddSize(kSizesField, fPreferredSize);
219 if (err == B_OK)
220 err = into->AddAlignment(kAlignmentField, fAlignment);
222 if (err == B_OK)
223 err = into->AddBool(kVisibleField, fVisible);
225 return err;
229 BArchivable*
230 BSpaceLayoutItem::Instantiate(BMessage* from)
232 if (validate_instantiation(from, "BSpaceLayoutItem"))
233 return new(std::nothrow) BSpaceLayoutItem(from);
234 return NULL;
238 void BSpaceLayoutItem::_ReservedSpaceLayoutItem1() {}
239 void BSpaceLayoutItem::_ReservedSpaceLayoutItem2() {}
240 void BSpaceLayoutItem::_ReservedSpaceLayoutItem3() {}
241 void BSpaceLayoutItem::_ReservedSpaceLayoutItem4() {}
242 void BSpaceLayoutItem::_ReservedSpaceLayoutItem5() {}
243 void BSpaceLayoutItem::_ReservedSpaceLayoutItem6() {}
244 void BSpaceLayoutItem::_ReservedSpaceLayoutItem7() {}
245 void BSpaceLayoutItem::_ReservedSpaceLayoutItem8() {}
246 void BSpaceLayoutItem::_ReservedSpaceLayoutItem9() {}
247 void BSpaceLayoutItem::_ReservedSpaceLayoutItem10() {}