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.
8 #include <SpaceLayoutItem.h>
12 #include <ControlLook.h>
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
);
32 BSpaceLayoutItem::BSpaceLayoutItem(BSize minSize
, BSize maxSize
,
33 BSize preferredSize
, BAlignment alignment
)
36 fMinSize(ComposeSpacingInPlace(minSize
)),
37 fMaxSize(ComposeSpacingInPlace(maxSize
)),
38 fPreferredSize(ComposeSpacingInPlace(preferredSize
)),
39 fAlignment(alignment
),
45 BSpaceLayoutItem::BSpaceLayoutItem(BMessage
* 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()
66 BSpaceLayoutItem::CreateGlue()
68 return new BSpaceLayoutItem(
70 BSize(B_SIZE_UNLIMITED
, B_SIZE_UNLIMITED
),
72 BAlignment(B_ALIGN_HORIZONTAL_CENTER
, B_ALIGN_VERTICAL_CENTER
));
77 BSpaceLayoutItem::CreateHorizontalStrut(float width
)
79 return new BSpaceLayoutItem(
81 BSize(width
, B_SIZE_UNLIMITED
),
83 BAlignment(B_ALIGN_HORIZONTAL_CENTER
, B_ALIGN_VERTICAL_CENTER
));
88 BSpaceLayoutItem::CreateVerticalStrut(float height
)
90 return new BSpaceLayoutItem(
92 BSize(B_SIZE_UNLIMITED
, height
),
94 BAlignment(B_ALIGN_HORIZONTAL_CENTER
, B_ALIGN_VERTICAL_CENTER
));
99 BSpaceLayoutItem::MinSize()
106 BSpaceLayoutItem::MaxSize()
113 BSpaceLayoutItem::PreferredSize()
115 return fPreferredSize
;
120 BSpaceLayoutItem::Alignment()
127 BSpaceLayoutItem::SetExplicitMinSize(BSize size
)
129 if (size
.IsWidthSet())
130 fMinSize
.width
= size
.width
;
131 if (size
.IsHeightSet())
132 fMinSize
.height
= size
.height
;
139 BSpaceLayoutItem::SetExplicitMaxSize(BSize size
)
141 if (size
.IsWidthSet())
142 fMaxSize
.width
= size
.width
;
143 if (size
.IsHeightSet())
144 fMaxSize
.height
= size
.height
;
151 BSpaceLayoutItem::SetExplicitPreferredSize(BSize size
)
153 if (size
.IsWidthSet())
154 fPreferredSize
.width
= size
.width
;
155 if (size
.IsHeightSet())
156 fPreferredSize
.height
= size
.height
;
163 BSpaceLayoutItem::SetExplicitAlignment(BAlignment alignment
)
165 if (alignment
.IsHorizontalSet())
166 fAlignment
.horizontal
= alignment
.horizontal
;
167 if (alignment
.IsVerticalSet())
168 fAlignment
.vertical
= alignment
.vertical
;
175 BSpaceLayoutItem::IsVisible()
182 BSpaceLayoutItem::SetVisible(bool visible
)
189 BSpaceLayoutItem::Frame()
196 BSpaceLayoutItem::SetFrame(BRect frame
)
203 BSpaceLayoutItem::Archive(BMessage
* into
, bool deep
) const
205 status_t err
= BLayoutItem::Archive(into
, deep
);
208 err
= into
->AddRect(kFrameField
, fFrame
);
211 err
= into
->AddSize(kSizesField
, fMinSize
);
214 err
= into
->AddSize(kSizesField
, fMaxSize
);
217 err
= into
->AddSize(kSizesField
, fPreferredSize
);
220 err
= into
->AddAlignment(kAlignmentField
, fAlignment
);
223 err
= into
->AddBool(kVisibleField
, fVisible
);
230 BSpaceLayoutItem::Instantiate(BMessage
* from
)
232 if (validate_instantiation(from
, "BSpaceLayoutItem"))
233 return new(std::nothrow
) BSpaceLayoutItem(from
);
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() {}