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 "ViewLayoutItem.h"
14 #include <ViewPrivate.h>
18 const char* const kViewField
= "BViewLayoutItem:view";
22 BViewLayoutItem::BViewLayoutItem(BView
* view
)
25 fAncestorsVisible(true)
30 BViewLayoutItem::BViewLayoutItem(BMessage
* from
)
32 BLayoutItem(BUnarchiver::PrepareArchive(from
)),
34 fAncestorsVisible(true)
36 BUnarchiver
unarchiver(from
);
37 unarchiver
.Finish(unarchiver
.FindObject
<BView
>(kViewField
, 0,
38 BUnarchiver::B_DONT_ASSUME_OWNERSHIP
, fView
));
42 BViewLayoutItem::~BViewLayoutItem()
48 BViewLayoutItem::MinSize()
50 return fView
->MinSize();
55 BViewLayoutItem::MaxSize()
57 return fView
->MaxSize();
62 BViewLayoutItem::PreferredSize()
64 return fView
->PreferredSize();
69 BViewLayoutItem::Alignment()
71 return fView
->LayoutAlignment();
76 BViewLayoutItem::SetExplicitMinSize(BSize size
)
78 fView
->SetExplicitMinSize(size
);
83 BViewLayoutItem::SetExplicitMaxSize(BSize size
)
85 fView
->SetExplicitMaxSize(size
);
90 BViewLayoutItem::SetExplicitPreferredSize(BSize size
)
92 fView
->SetExplicitPreferredSize(size
);
97 BViewLayoutItem::SetExplicitAlignment(BAlignment alignment
)
99 fView
->SetExplicitAlignment(alignment
);
104 BViewLayoutItem::IsVisible()
106 int16 showLevel
= BView::Private(fView
).ShowLevel();
107 return showLevel
- (fAncestorsVisible
? 0 : 1) <= 0;
112 BViewLayoutItem::SetVisible(bool visible
)
114 if (visible
!= IsVisible()) {
124 BViewLayoutItem::Frame()
126 return fView
->Frame();
131 BViewLayoutItem::SetFrame(BRect frame
)
133 fView
->MoveTo(frame
.LeftTop());
134 fView
->ResizeTo(frame
.Width(), frame
.Height());
139 BViewLayoutItem::HasHeightForWidth()
141 return fView
->HasHeightForWidth();
146 BViewLayoutItem::GetHeightForWidth(float width
, float* min
, float* max
,
149 fView
->GetHeightForWidth(width
, min
, max
, preferred
);
154 BViewLayoutItem::View()
161 BViewLayoutItem::Relayout(bool immediate
)
164 fView
->Layout(false);
171 BViewLayoutItem::Archive(BMessage
* into
, bool deep
) const
173 BArchiver
archiver(into
);
174 status_t err
= BLayoutItem::Archive(into
, deep
);
176 return archiver
.Finish(err
);
181 BViewLayoutItem::AllArchived(BMessage
* into
) const
183 BArchiver
archiver(into
);
184 status_t err
= BLayoutItem::AllArchived(into
);
187 if (archiver
.IsArchived(fView
))
188 err
= archiver
.AddArchivable(kViewField
, fView
);
190 err
= B_NAME_NOT_FOUND
;
198 BViewLayoutItem::AllUnarchived(const BMessage
* from
)
203 return BLayoutItem::AllUnarchived(from
);
208 BViewLayoutItem::Instantiate(BMessage
* from
)
210 if (validate_instantiation(from
, "BViewLayoutItem"))
211 return new(std::nothrow
) BViewLayoutItem(from
);
217 BViewLayoutItem::LayoutInvalidated(bool children
)
219 fView
->InvalidateLayout(children
);
224 BViewLayoutItem::AncestorVisibilityChanged(bool shown
)
226 if (fAncestorsVisible
== shown
)
229 fAncestorsVisible
= shown
;