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 */
6
7
8 #include <AbstractLayoutItem.h>
9
10 #include <LayoutUtils.h>
11 #include <Message.h>
12
13
14 namespace {
15 const char* const kSizesField = "BAbstractLayoutItem:sizes";
16 // kSizesField == {min, max, preferred}
17 const char* const kAlignmentField = "BAbstractLayoutItem:alignment";
18 }
19
20
BAbstractLayoutItem()21 BAbstractLayoutItem::BAbstractLayoutItem()
22 :
23 fMinSize(),
24 fMaxSize(),
25 fPreferredSize(),
26 fAlignment()
27 {
28 }
29
30
BAbstractLayoutItem(BMessage * from)31 BAbstractLayoutItem::BAbstractLayoutItem(BMessage* from)
32 :
33 BLayoutItem(from),
34 fMinSize(),
35 fMaxSize(),
36 fPreferredSize(),
37 fAlignment()
38 {
39 from->FindSize(kSizesField, 0, &fMinSize);
40 from->FindSize(kSizesField, 1, &fMaxSize);
41 from->FindSize(kSizesField, 2, &fPreferredSize);
42 from->FindAlignment(kAlignmentField, &fAlignment);
43 }
44
45
~BAbstractLayoutItem()46 BAbstractLayoutItem::~BAbstractLayoutItem()
47 {
48 }
49
50
51 BSize
MinSize()52 BAbstractLayoutItem::MinSize()
53 {
54 return BLayoutUtils::ComposeSize(fMinSize, BaseMinSize());
55 }
56
57
58 BSize
MaxSize()59 BAbstractLayoutItem::MaxSize()
60 {
61 return BLayoutUtils::ComposeSize(fMaxSize, BaseMaxSize());
62 }
63
64
65 BSize
PreferredSize()66 BAbstractLayoutItem::PreferredSize()
67 {
68 return BLayoutUtils::ComposeSize(fMaxSize, BasePreferredSize());
69 }
70
71
72 BAlignment
Alignment()73 BAbstractLayoutItem::Alignment()
74 {
75 return BLayoutUtils::ComposeAlignment(fAlignment, BaseAlignment());
76 }
77
78
79 void
SetExplicitMinSize(BSize size)80 BAbstractLayoutItem::SetExplicitMinSize(BSize size)
81 {
82 fMinSize = size;
83 }
84
85
86 void
SetExplicitMaxSize(BSize size)87 BAbstractLayoutItem::SetExplicitMaxSize(BSize size)
88 {
89 fMaxSize = size;
90 }
91
92
93 void
SetExplicitPreferredSize(BSize size)94 BAbstractLayoutItem::SetExplicitPreferredSize(BSize size)
95 {
96 fPreferredSize = size;
97 }
98
99
100 void
SetExplicitAlignment(BAlignment alignment)101 BAbstractLayoutItem::SetExplicitAlignment(BAlignment alignment)
102 {
103 fAlignment = alignment;
104 }
105
106
107 BSize
BaseMinSize()108 BAbstractLayoutItem::BaseMinSize()
109 {
110 return BSize(0, 0);
111 }
112
113
114 BSize
BaseMaxSize()115 BAbstractLayoutItem::BaseMaxSize()
116 {
117 return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED);
118 }
119
120
121 BSize
BasePreferredSize()122 BAbstractLayoutItem::BasePreferredSize()
123 {
124 return BSize(0, 0);
125 }
126
127
128 BAlignment
BaseAlignment()129 BAbstractLayoutItem::BaseAlignment()
130 {
131 return BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER);
132 }
133
134
135 status_t
Archive(BMessage * into,bool deep) const136 BAbstractLayoutItem::Archive(BMessage* into, bool deep) const
137 {
138 BArchiver archiver(into);
139 status_t err = BLayoutItem::Archive(into, deep);
140
141 if (err == B_OK)
142 err = into->AddSize(kSizesField, fMinSize);
143
144 if (err == B_OK)
145 err = into->AddSize(kSizesField, fMaxSize);
146
147 if (err == B_OK)
148 err = into->AddSize(kSizesField, fPreferredSize);
149
150 if (err == B_OK)
151 err = into->AddAlignment(kAlignmentField, fAlignment);
152
153 return archiver.Finish(err);
154 }
155
156
157 status_t
AllUnarchived(const BMessage * archive)158 BAbstractLayoutItem::AllUnarchived(const BMessage* archive)
159 {
160 return BLayoutItem::AllUnarchived(archive);
161 }
162
163
164 status_t
AllArchived(BMessage * archive) const165 BAbstractLayoutItem::AllArchived(BMessage* archive) const
166 {
167 return BLayoutItem::AllArchived(archive);
168 }
169
170
171 void
LayoutInvalidated(bool children)172 BAbstractLayoutItem::LayoutInvalidated(bool children)
173 {
174 BLayoutItem::LayoutInvalidated(children);
175 }
176
177
178 void
AttachedToLayout()179 BAbstractLayoutItem::AttachedToLayout()
180 {
181 BLayoutItem::AttachedToLayout();
182 }
183
184
185 void
DetachedFromLayout(BLayout * layout)186 BAbstractLayoutItem::DetachedFromLayout(BLayout* layout)
187 {
188 BLayoutItem::DetachedFromLayout(layout);
189 }
190
191
192 void
AncestorVisibilityChanged(bool shown)193 BAbstractLayoutItem::AncestorVisibilityChanged(bool shown)
194 {
195 BLayoutItem::AncestorVisibilityChanged(shown);
196 }
197
198
199 status_t
Perform(perform_code d,void * arg)200 BAbstractLayoutItem::Perform(perform_code d, void* arg)
201 {
202 return BLayoutItem::Perform(d, arg);
203 }
204
205
_ReservedAbstractLayoutItem1()206 void BAbstractLayoutItem::_ReservedAbstractLayoutItem1() {}
_ReservedAbstractLayoutItem2()207 void BAbstractLayoutItem::_ReservedAbstractLayoutItem2() {}
_ReservedAbstractLayoutItem3()208 void BAbstractLayoutItem::_ReservedAbstractLayoutItem3() {}
_ReservedAbstractLayoutItem4()209 void BAbstractLayoutItem::_ReservedAbstractLayoutItem4() {}
_ReservedAbstractLayoutItem5()210 void BAbstractLayoutItem::_ReservedAbstractLayoutItem5() {}
_ReservedAbstractLayoutItem6()211 void BAbstractLayoutItem::_ReservedAbstractLayoutItem6() {}
_ReservedAbstractLayoutItem7()212 void BAbstractLayoutItem::_ReservedAbstractLayoutItem7() {}
_ReservedAbstractLayoutItem8()213 void BAbstractLayoutItem::_ReservedAbstractLayoutItem8() {}
_ReservedAbstractLayoutItem9()214 void BAbstractLayoutItem::_ReservedAbstractLayoutItem9() {}
_ReservedAbstractLayoutItem10()215 void BAbstractLayoutItem::_ReservedAbstractLayoutItem10() {}
216
217