tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / kits / interface / ViewLayoutItem.cpp
blob7c14bd0d5aebaea0b64bc883ba8e09c2827bc810
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 "ViewLayoutItem.h"
10 #include <new>
12 #include <Layout.h>
13 #include <View.h>
14 #include <ViewPrivate.h>
17 namespace {
18 const char* const kViewField = "BViewLayoutItem:view";
22 BViewLayoutItem::BViewLayoutItem(BView* view)
24 fView(view),
25 fAncestorsVisible(true)
30 BViewLayoutItem::BViewLayoutItem(BMessage* from)
32 BLayoutItem(BUnarchiver::PrepareArchive(from)),
33 fView(NULL),
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()
47 BSize
48 BViewLayoutItem::MinSize()
50 return fView->MinSize();
54 BSize
55 BViewLayoutItem::MaxSize()
57 return fView->MaxSize();
61 BSize
62 BViewLayoutItem::PreferredSize()
64 return fView->PreferredSize();
68 BAlignment
69 BViewLayoutItem::Alignment()
71 return fView->LayoutAlignment();
75 void
76 BViewLayoutItem::SetExplicitMinSize(BSize size)
78 fView->SetExplicitMinSize(size);
82 void
83 BViewLayoutItem::SetExplicitMaxSize(BSize size)
85 fView->SetExplicitMaxSize(size);
89 void
90 BViewLayoutItem::SetExplicitPreferredSize(BSize size)
92 fView->SetExplicitPreferredSize(size);
96 void
97 BViewLayoutItem::SetExplicitAlignment(BAlignment alignment)
99 fView->SetExplicitAlignment(alignment);
103 bool
104 BViewLayoutItem::IsVisible()
106 int16 showLevel = BView::Private(fView).ShowLevel();
107 return showLevel - (fAncestorsVisible ? 0 : 1) <= 0;
111 void
112 BViewLayoutItem::SetVisible(bool visible)
114 if (visible != IsVisible()) {
115 if (visible)
116 fView->Show();
117 else
118 fView->Hide();
123 BRect
124 BViewLayoutItem::Frame()
126 return fView->Frame();
130 void
131 BViewLayoutItem::SetFrame(BRect frame)
133 fView->MoveTo(frame.LeftTop());
134 fView->ResizeTo(frame.Width(), frame.Height());
138 bool
139 BViewLayoutItem::HasHeightForWidth()
141 return fView->HasHeightForWidth();
145 void
146 BViewLayoutItem::GetHeightForWidth(float width, float* min, float* max,
147 float* preferred)
149 fView->GetHeightForWidth(width, min, max, preferred);
153 BView*
154 BViewLayoutItem::View()
156 return fView;
160 void
161 BViewLayoutItem::Relayout(bool immediate)
163 if (immediate)
164 fView->Layout(false);
165 else
166 fView->Relayout();
170 status_t
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);
180 status_t
181 BViewLayoutItem::AllArchived(BMessage* into) const
183 BArchiver archiver(into);
184 status_t err = BLayoutItem::AllArchived(into);
186 if (err == B_OK) {
187 if (archiver.IsArchived(fView))
188 err = archiver.AddArchivable(kViewField, fView);
189 else
190 err = B_NAME_NOT_FOUND;
193 return err;
197 status_t
198 BViewLayoutItem::AllUnarchived(const BMessage* from)
200 if (!fView)
201 return B_ERROR;
203 return BLayoutItem::AllUnarchived(from);
207 BArchivable*
208 BViewLayoutItem::Instantiate(BMessage* from)
210 if (validate_instantiation(from, "BViewLayoutItem"))
211 return new(std::nothrow) BViewLayoutItem(from);
212 return NULL;
216 void
217 BViewLayoutItem::LayoutInvalidated(bool children)
219 fView->InvalidateLayout(children);
223 void
224 BViewLayoutItem::AncestorVisibilityChanged(bool shown)
226 if (fAncestorsVisible == shown)
227 return;
229 fAncestorsVisible = shown;
230 if (shown)
231 fView->Show();
232 if (!shown)
233 fView->Hide();