19ecf9d1cSIngo Weinhold/*
27ed1644cSIngo Weinhold * Copyright 2010, Haiku, Inc.
39ecf9d1cSIngo Weinhold * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
49ecf9d1cSIngo Weinhold * All rights reserved. Distributed under the terms of the MIT License.
59ecf9d1cSIngo Weinhold */
69ecf9d1cSIngo Weinhold
77ed1644cSIngo Weinhold
89ecf9d1cSIngo Weinhold#include <AbstractLayoutItem.h>
99ecf9d1cSIngo Weinhold
109ecf9d1cSIngo Weinhold#include <LayoutUtils.h>
117ed1644cSIngo Weinhold#include <Message.h>
127ed1644cSIngo Weinhold
137ed1644cSIngo Weinhold
147ed1644cSIngo Weinholdnamespace {
154a254e4dSAlex Wilson	const char* const kSizesField = "BAbstractLayoutItem:sizes";
164a254e4dSAlex Wilson		// kSizesField == {min, max, preferred}
174a254e4dSAlex Wilson	const char* const kAlignmentField = "BAbstractLayoutItem:alignment";
187ed1644cSIngo Weinhold}
199ecf9d1cSIngo Weinhold
209ecf9d1cSIngo Weinhold
219ecf9d1cSIngo WeinholdBAbstractLayoutItem::BAbstractLayoutItem()
227ed1644cSIngo Weinhold	:
237ed1644cSIngo Weinhold	fMinSize(),
247ed1644cSIngo Weinhold	fMaxSize(),
257ed1644cSIngo Weinhold	fPreferredSize(),
267ed1644cSIngo Weinhold	fAlignment()
277ed1644cSIngo Weinhold{
287ed1644cSIngo Weinhold}
297ed1644cSIngo Weinhold
307ed1644cSIngo Weinhold
317ed1644cSIngo WeinholdBAbstractLayoutItem::BAbstractLayoutItem(BMessage* from)
327ed1644cSIngo Weinhold	:
337ed1644cSIngo Weinhold	BLayoutItem(from),
347ed1644cSIngo Weinhold	fMinSize(),
357ed1644cSIngo Weinhold	fMaxSize(),
367ed1644cSIngo Weinhold	fPreferredSize(),
377ed1644cSIngo Weinhold	fAlignment()
389ecf9d1cSIngo Weinhold{
394a254e4dSAlex Wilson	from->FindSize(kSizesField, 0, &fMinSize);
404a254e4dSAlex Wilson	from->FindSize(kSizesField, 1, &fMaxSize);
414a254e4dSAlex Wilson	from->FindSize(kSizesField, 2, &fPreferredSize);
427ed1644cSIngo Weinhold	from->FindAlignment(kAlignmentField, &fAlignment);
439ecf9d1cSIngo Weinhold}
449ecf9d1cSIngo Weinhold
457ed1644cSIngo Weinhold
469ecf9d1cSIngo WeinholdBAbstractLayoutItem::~BAbstractLayoutItem()
479ecf9d1cSIngo Weinhold{
489ecf9d1cSIngo Weinhold}
499ecf9d1cSIngo Weinhold
507ed1644cSIngo Weinhold
519ecf9d1cSIngo WeinholdBSize
529ecf9d1cSIngo WeinholdBAbstractLayoutItem::MinSize()
539ecf9d1cSIngo Weinhold{
549ecf9d1cSIngo Weinhold	return BLayoutUtils::ComposeSize(fMinSize, BaseMinSize());
559ecf9d1cSIngo Weinhold}
569ecf9d1cSIngo Weinhold
577ed1644cSIngo Weinhold
589ecf9d1cSIngo WeinholdBSize
599ecf9d1cSIngo WeinholdBAbstractLayoutItem::MaxSize()
609ecf9d1cSIngo Weinhold{
619ecf9d1cSIngo Weinhold	return BLayoutUtils::ComposeSize(fMaxSize, BaseMaxSize());
629ecf9d1cSIngo Weinhold}
639ecf9d1cSIngo Weinhold
647ed1644cSIngo Weinhold
659ecf9d1cSIngo WeinholdBSize
669ecf9d1cSIngo WeinholdBAbstractLayoutItem::PreferredSize()
679ecf9d1cSIngo Weinhold{
680cf8c36aSAdrien Destugues	return BLayoutUtils::ComposeSize(fMaxSize, BasePreferredSize());
699ecf9d1cSIngo Weinhold}
709ecf9d1cSIngo Weinhold
717ed1644cSIngo Weinhold
729ecf9d1cSIngo WeinholdBAlignment
739ecf9d1cSIngo WeinholdBAbstractLayoutItem::Alignment()
749ecf9d1cSIngo Weinhold{
759ecf9d1cSIngo Weinhold	return BLayoutUtils::ComposeAlignment(fAlignment, BaseAlignment());
769ecf9d1cSIngo Weinhold}
779ecf9d1cSIngo Weinhold
787ed1644cSIngo Weinhold
799ecf9d1cSIngo Weinholdvoid
809ecf9d1cSIngo WeinholdBAbstractLayoutItem::SetExplicitMinSize(BSize size)
819ecf9d1cSIngo Weinhold{
829ecf9d1cSIngo Weinhold	fMinSize = size;
839ecf9d1cSIngo Weinhold}
849ecf9d1cSIngo Weinhold
857ed1644cSIngo Weinhold
869ecf9d1cSIngo Weinholdvoid
879ecf9d1cSIngo WeinholdBAbstractLayoutItem::SetExplicitMaxSize(BSize size)
889ecf9d1cSIngo Weinhold{
899ecf9d1cSIngo Weinhold	fMaxSize = size;
909ecf9d1cSIngo Weinhold}
919ecf9d1cSIngo Weinhold
927ed1644cSIngo Weinhold
939ecf9d1cSIngo Weinholdvoid
949ecf9d1cSIngo WeinholdBAbstractLayoutItem::SetExplicitPreferredSize(BSize size)
959ecf9d1cSIngo Weinhold{
969ecf9d1cSIngo Weinhold	fPreferredSize = size;
979ecf9d1cSIngo Weinhold}
989ecf9d1cSIngo Weinhold
997ed1644cSIngo Weinhold
1009ecf9d1cSIngo Weinholdvoid
1019ecf9d1cSIngo WeinholdBAbstractLayoutItem::SetExplicitAlignment(BAlignment alignment)
1029ecf9d1cSIngo Weinhold{
1039ecf9d1cSIngo Weinhold	fAlignment = alignment;
1049ecf9d1cSIngo Weinhold}
1059ecf9d1cSIngo Weinhold
1067ed1644cSIngo Weinhold
1079ecf9d1cSIngo WeinholdBSize
1089ecf9d1cSIngo WeinholdBAbstractLayoutItem::BaseMinSize()
1099ecf9d1cSIngo Weinhold{
1109ecf9d1cSIngo Weinhold	return BSize(0, 0);
1119ecf9d1cSIngo Weinhold}
1129ecf9d1cSIngo Weinhold
1137ed1644cSIngo Weinhold
1149ecf9d1cSIngo WeinholdBSize
1159ecf9d1cSIngo WeinholdBAbstractLayoutItem::BaseMaxSize()
1169ecf9d1cSIngo Weinhold{
1179ecf9d1cSIngo Weinhold	return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED);
1189ecf9d1cSIngo Weinhold}
1199ecf9d1cSIngo Weinhold
1207ed1644cSIngo Weinhold
1219ecf9d1cSIngo WeinholdBSize
1229ecf9d1cSIngo WeinholdBAbstractLayoutItem::BasePreferredSize()
1239ecf9d1cSIngo Weinhold{
1249ecf9d1cSIngo Weinhold	return BSize(0, 0);
1259ecf9d1cSIngo Weinhold}
1269ecf9d1cSIngo Weinhold
1277ed1644cSIngo Weinhold
1289ecf9d1cSIngo WeinholdBAlignment
1299ecf9d1cSIngo WeinholdBAbstractLayoutItem::BaseAlignment()
1309ecf9d1cSIngo Weinhold{
1319ecf9d1cSIngo Weinhold	return BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER);
1329ecf9d1cSIngo Weinhold}
1337ed1644cSIngo Weinhold
1347ed1644cSIngo Weinhold
1357ed1644cSIngo Weinholdstatus_t
1367ed1644cSIngo WeinholdBAbstractLayoutItem::Archive(BMessage* into, bool deep) const
1377ed1644cSIngo Weinhold{
1387ed1644cSIngo Weinhold	BArchiver archiver(into);
1397ed1644cSIngo Weinhold	status_t err = BLayoutItem::Archive(into, deep);
1407ed1644cSIngo Weinhold
1417ed1644cSIngo Weinhold	if (err == B_OK)
1424a254e4dSAlex Wilson		err = into->AddSize(kSizesField, fMinSize);
1437ed1644cSIngo Weinhold
1447ed1644cSIngo Weinhold	if (err == B_OK)
1454a254e4dSAlex Wilson		err = into->AddSize(kSizesField, fMaxSize);
1467ed1644cSIngo Weinhold
1477ed1644cSIngo Weinhold	if (err == B_OK)
1484a254e4dSAlex Wilson		err = into->AddSize(kSizesField, fPreferredSize);
1497ed1644cSIngo Weinhold
1507ed1644cSIngo Weinhold	if (err == B_OK)
1517ed1644cSIngo Weinhold		err = into->AddAlignment(kAlignmentField, fAlignment);
1527ed1644cSIngo Weinhold
1537ed1644cSIngo Weinhold	return archiver.Finish(err);
1547ed1644cSIngo Weinhold}
155a851b3adSAlex Wilson
156a851b3adSAlex Wilson
15753617d36SAlex Wilsonstatus_t
15853617d36SAlex WilsonBAbstractLayoutItem::AllUnarchived(const BMessage* archive)
15953617d36SAlex Wilson{
16053617d36SAlex Wilson	return BLayoutItem::AllUnarchived(archive);
16153617d36SAlex Wilson}
16253617d36SAlex Wilson
16353617d36SAlex Wilson
16453617d36SAlex Wilsonstatus_t
16553617d36SAlex WilsonBAbstractLayoutItem::AllArchived(BMessage* archive) const
16653617d36SAlex Wilson{
16753617d36SAlex Wilson	return BLayoutItem::AllArchived(archive);
16853617d36SAlex Wilson}
16953617d36SAlex Wilson
17053617d36SAlex Wilson
17153617d36SAlex Wilsonvoid
17253617d36SAlex WilsonBAbstractLayoutItem::LayoutInvalidated(bool children)
17353617d36SAlex Wilson{
17453617d36SAlex Wilson	BLayoutItem::LayoutInvalidated(children);
17553617d36SAlex Wilson}
17653617d36SAlex Wilson
17753617d36SAlex Wilson
17853617d36SAlex Wilsonvoid
17953617d36SAlex WilsonBAbstractLayoutItem::AttachedToLayout()
18053617d36SAlex Wilson{
18153617d36SAlex Wilson	BLayoutItem::AttachedToLayout();
18253617d36SAlex Wilson}
18353617d36SAlex Wilson
18453617d36SAlex Wilson
18553617d36SAlex Wilsonvoid
18653617d36SAlex WilsonBAbstractLayoutItem::DetachedFromLayout(BLayout* layout)
18753617d36SAlex Wilson{
18853617d36SAlex Wilson	BLayoutItem::DetachedFromLayout(layout);
18953617d36SAlex Wilson}
19053617d36SAlex Wilson
19153617d36SAlex Wilson
19253617d36SAlex Wilsonvoid
19353617d36SAlex WilsonBAbstractLayoutItem::AncestorVisibilityChanged(bool shown)
19453617d36SAlex Wilson{
19553617d36SAlex Wilson	BLayoutItem::AncestorVisibilityChanged(shown);
19653617d36SAlex Wilson}
19753617d36SAlex Wilson
19853617d36SAlex Wilson
199a851b3adSAlex Wilsonstatus_t
200a851b3adSAlex WilsonBAbstractLayoutItem::Perform(perform_code d, void* arg)
201a851b3adSAlex Wilson{
202a851b3adSAlex Wilson	return BLayoutItem::Perform(d, arg);
203a851b3adSAlex Wilson}
204a851b3adSAlex Wilson
2058151838eSAlex Wilson
2068151838eSAlex Wilsonvoid BAbstractLayoutItem::_ReservedAbstractLayoutItem1() {}
2078151838eSAlex Wilsonvoid BAbstractLayoutItem::_ReservedAbstractLayoutItem2() {}
2088151838eSAlex Wilsonvoid BAbstractLayoutItem::_ReservedAbstractLayoutItem3() {}
2098151838eSAlex Wilsonvoid BAbstractLayoutItem::_ReservedAbstractLayoutItem4() {}
2108151838eSAlex Wilsonvoid BAbstractLayoutItem::_ReservedAbstractLayoutItem5() {}
2118151838eSAlex Wilsonvoid BAbstractLayoutItem::_ReservedAbstractLayoutItem6() {}
2128151838eSAlex Wilsonvoid BAbstractLayoutItem::_ReservedAbstractLayoutItem7() {}
2138151838eSAlex Wilsonvoid BAbstractLayoutItem::_ReservedAbstractLayoutItem8() {}
2148151838eSAlex Wilsonvoid BAbstractLayoutItem::_ReservedAbstractLayoutItem9() {}
2158151838eSAlex Wilsonvoid BAbstractLayoutItem::_ReservedAbstractLayoutItem10() {}
2168151838eSAlex Wilson
217