2 * Copyright 2010-2012, 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 <LayoutItem.h>
11 #include <LayoutUtils.h>
13 #include <ViewPrivate.h>
18 BLayoutItem::BLayoutItem()
26 BLayoutItem::BLayoutItem(BMessage
* from
)
28 BArchivable(BUnarchiver::PrepareArchive(from
)),
32 BUnarchiver(from
).Finish();
36 BLayoutItem::~BLayoutItem()
38 if (fLayout
!= NULL
) {
39 debugger("Deleting a BLayoutItem that is still attached to a layout. "
40 "Call RemoveSelf first.");
46 BLayoutItem::Layout() const
53 BLayoutItem::RemoveSelf()
55 return Layout() != NULL
&& Layout()->RemoveItem(this);
60 BLayoutItem::SetExplicitSize(BSize size
)
62 SetExplicitMinSize(size
);
63 SetExplicitMaxSize(size
);
64 SetExplicitPreferredSize(size
);
69 BLayoutItem::HasHeightForWidth()
71 // no "height for width" by default
77 BLayoutItem::GetHeightForWidth(float width
, float* min
, float* max
,
80 // no "height for width" by default
92 BLayoutItem::InvalidateLayout(bool children
)
94 LayoutInvalidated(children
);
96 fLayout
->InvalidateLayout(children
);
101 BLayoutItem::Relayout(bool immediate
)
103 BView
* view
= View();
104 if (view
&& !immediate
)
106 else if (view
&& immediate
)
112 BLayoutItem::LayoutData() const
119 BLayoutItem::SetLayoutData(void* data
)
126 BLayoutItem::AlignInFrame(BRect frame
)
128 BSize maxSize
= MaxSize();
129 BAlignment alignment
= Alignment();
131 if (HasHeightForWidth()) {
132 // The item has height for width, so we do the horizontal alignment
133 // ourselves and restrict the height max constraint respectively.
134 if (maxSize
.width
< frame
.Width()
135 && alignment
.horizontal
!= B_ALIGN_USE_FULL_WIDTH
) {
136 frame
.left
+= (int)((frame
.Width() - maxSize
.width
)
137 * alignment
.horizontal
);
138 frame
.right
= frame
.left
+ maxSize
.width
;
140 alignment
.horizontal
= B_ALIGN_USE_FULL_WIDTH
;
143 GetHeightForWidth(frame
.Width(), &minHeight
, NULL
, NULL
);
145 frame
.bottom
= frame
.top
+ max_c(frame
.Height(), minHeight
);
146 maxSize
.height
= minHeight
;
149 SetFrame(BLayoutUtils::AlignInFrame(frame
, maxSize
, alignment
));
154 BLayoutItem::Archive(BMessage
* into
, bool deep
) const
156 BArchiver
archiver(into
);
157 status_t err
= BArchivable::Archive(into
, deep
);
160 err
= archiver
.Finish();
167 BLayoutItem::AllArchived(BMessage
* into
) const
169 BArchiver
archiver(into
);
170 return BArchivable::AllArchived(into
);
175 BLayoutItem::AllUnarchived(const BMessage
* from
)
177 return BArchivable::AllUnarchived(from
);
182 BLayoutItem::SetLayout(BLayout
* layout
)
184 if (layout
== fLayout
)
187 BLayout
* oldLayout
= fLayout
;
191 DetachedFromLayout(oldLayout
);
193 if (BView
* view
= View()) {
194 if (oldLayout
&& !fLayout
) {
195 BView::Private(view
).DeregisterLayoutItem(this);
196 } else if (fLayout
&& !oldLayout
) {
197 BView::Private(view
).RegisterLayoutItem(this);
207 BLayoutItem::Perform(perform_code code
, void* _data
)
209 return BArchivable::Perform(code
, _data
);
214 BLayoutItem::LayoutInvalidated(bool children
)
221 BLayoutItem::AttachedToLayout()
228 BLayoutItem::DetachedFromLayout(BLayout
* oldLayout
)
235 BLayoutItem::AncestorVisibilityChanged(bool shown
)
241 // Binary compatibility stuff
244 void BLayoutItem::_ReservedLayoutItem1() {}
245 void BLayoutItem::_ReservedLayoutItem2() {}
246 void BLayoutItem::_ReservedLayoutItem3() {}
247 void BLayoutItem::_ReservedLayoutItem4() {}
248 void BLayoutItem::_ReservedLayoutItem5() {}
249 void BLayoutItem::_ReservedLayoutItem6() {}
250 void BLayoutItem::_ReservedLayoutItem7() {}
251 void BLayoutItem::_ReservedLayoutItem8() {}
252 void BLayoutItem::_ReservedLayoutItem9() {}
253 void BLayoutItem::_ReservedLayoutItem10() {}