Patch by Alex Wilson:

* Added archiving/unarchiving support.
* Style cleanup (also some by myself).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37540 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2010-07-16 17:23:15 +00:00
parent cbac1a2355
commit 7ed1644c55
2 changed files with 69 additions and 18 deletions
@@ -13,6 +13,7 @@
class BAbstractLayoutItem : public BLayoutItem { class BAbstractLayoutItem : public BLayoutItem {
public: public:
BAbstractLayoutItem(); BAbstractLayoutItem();
BAbstractLayoutItem(BMessage* from);
virtual ~BAbstractLayoutItem(); virtual ~BAbstractLayoutItem();
virtual BSize MinSize(); virtual BSize MinSize();
@@ -30,6 +31,8 @@ public:
virtual BSize BasePreferredSize(); virtual BSize BasePreferredSize();
virtual BAlignment BaseAlignment(); virtual BAlignment BaseAlignment();
virtual status_t Archive(BMessage* into, bool deep = true) const;
private: private:
BSize fMinSize; BSize fMinSize;
BSize fMaxSize; BSize fMaxSize;
+66 -18
View File
@@ -1,107 +1,155 @@
/* /*
* Copyright 2010, Haiku, Inc.
* Copyright 2006, Ingo Weinhold <[email protected]>. * Copyright 2006, Ingo Weinhold <[email protected]>.
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
#include <AbstractLayoutItem.h> #include <AbstractLayoutItem.h>
#include <LayoutUtils.h> #include <LayoutUtils.h>
#include <Message.h>
namespace {
const char* kMinSizeField = "BAbstractLayoutItem:minSize";
const char* kMaxSizeField = "BAbstractLayoutItem:maxSize";
const char* kPreferredSizeField = "BAbstractLayoutItem:preferredSize";
const char* kAlignmentField = "BAbstractLayoutItem:alignment";
}
// constructor
BAbstractLayoutItem::BAbstractLayoutItem() BAbstractLayoutItem::BAbstractLayoutItem()
: fMinSize(), :
fMaxSize(), fMinSize(),
fPreferredSize(), fMaxSize(),
fAlignment() fPreferredSize(),
fAlignment()
{ {
} }
// destructor
BAbstractLayoutItem::BAbstractLayoutItem(BMessage* from)
:
BLayoutItem(from),
fMinSize(),
fMaxSize(),
fPreferredSize(),
fAlignment()
{
from->FindSize(kMinSizeField, &fMinSize);
from->FindSize(kMaxSizeField, &fMaxSize);
from->FindSize(kPreferredSizeField, &fPreferredSize);
from->FindAlignment(kAlignmentField, &fAlignment);
}
BAbstractLayoutItem::~BAbstractLayoutItem() BAbstractLayoutItem::~BAbstractLayoutItem()
{ {
} }
// MinSize
BSize BSize
BAbstractLayoutItem::MinSize() BAbstractLayoutItem::MinSize()
{ {
return BLayoutUtils::ComposeSize(fMinSize, BaseMinSize()); return BLayoutUtils::ComposeSize(fMinSize, BaseMinSize());
} }
// MaxSize
BSize BSize
BAbstractLayoutItem::MaxSize() BAbstractLayoutItem::MaxSize()
{ {
return BLayoutUtils::ComposeSize(fMaxSize, BaseMaxSize()); return BLayoutUtils::ComposeSize(fMaxSize, BaseMaxSize());
} }
// PreferredSize
BSize BSize
BAbstractLayoutItem::PreferredSize() BAbstractLayoutItem::PreferredSize()
{ {
return BLayoutUtils::ComposeSize(fMaxSize, BasePreferredSize()); return BLayoutUtils::ComposeSize(fMaxSize, BasePreferredSize());
} }
// Alignment
BAlignment BAlignment
BAbstractLayoutItem::Alignment() BAbstractLayoutItem::Alignment()
{ {
return BLayoutUtils::ComposeAlignment(fAlignment, BaseAlignment()); return BLayoutUtils::ComposeAlignment(fAlignment, BaseAlignment());
} }
// SetExplicitMinSize
void void
BAbstractLayoutItem::SetExplicitMinSize(BSize size) BAbstractLayoutItem::SetExplicitMinSize(BSize size)
{ {
fMinSize = size; fMinSize = size;
} }
// SetExplicitMaxSize
void void
BAbstractLayoutItem::SetExplicitMaxSize(BSize size) BAbstractLayoutItem::SetExplicitMaxSize(BSize size)
{ {
fMaxSize = size; fMaxSize = size;
} }
// SetExplicitPreferredSize
void void
BAbstractLayoutItem::SetExplicitPreferredSize(BSize size) BAbstractLayoutItem::SetExplicitPreferredSize(BSize size)
{ {
fPreferredSize = size; fPreferredSize = size;
} }
// SetExplicitAlignment
void void
BAbstractLayoutItem::SetExplicitAlignment(BAlignment alignment) BAbstractLayoutItem::SetExplicitAlignment(BAlignment alignment)
{ {
fAlignment = alignment; fAlignment = alignment;
} }
// BaseMinSize
BSize BSize
BAbstractLayoutItem::BaseMinSize() BAbstractLayoutItem::BaseMinSize()
{ {
return BSize(0, 0); return BSize(0, 0);
} }
// BaseMaxSize
BSize BSize
BAbstractLayoutItem::BaseMaxSize() BAbstractLayoutItem::BaseMaxSize()
{ {
return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED); return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED);
} }
// BasePreferredSize
BSize BSize
BAbstractLayoutItem::BasePreferredSize() BAbstractLayoutItem::BasePreferredSize()
{ {
return BSize(0, 0); return BSize(0, 0);
} }
// BaseAlignment
BAlignment BAlignment
BAbstractLayoutItem::BaseAlignment() BAbstractLayoutItem::BaseAlignment()
{ {
return BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER); return BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER);
} }
status_t
BAbstractLayoutItem::Archive(BMessage* into, bool deep) const
{
BArchiver archiver(into);
status_t err = BLayoutItem::Archive(into, deep);
if (err == B_OK)
err = into->AddSize(kMinSizeField, fMinSize);
if (err == B_OK)
err = into->AddSize(kMaxSizeField, fMaxSize);
if (err == B_OK)
err = into->AddSize(kPreferredSizeField, fPreferredSize);
if (err == B_OK)
err = into->AddAlignment(kAlignmentField, fAlignment);
return archiver.Finish(err);
}