Author: bonefish Date: 2010-07-16 19:23:15 +0200 (Fri, 16 Jul 2010) New Revision: 37540 Changeset: http://dev.haiku-os.org/changeset/37540 Modified: haiku/trunk/headers/os/interface/AbstractLayoutItem.h haiku/trunk/src/kits/interface/AbstractLayoutItem.cpp Log: Patch by Alex Wilson: * Added archiving/unarchiving support. * Style cleanup (also some by myself). Modified: haiku/trunk/headers/os/interface/AbstractLayoutItem.h =================================================================== --- haiku/trunk/headers/os/interface/AbstractLayoutItem.h 2010-07-16 17:06:55 UTC (rev 37539) +++ haiku/trunk/headers/os/interface/AbstractLayoutItem.h 2010-07-16 17:23:15 UTC (rev 37540) @@ -13,6 +13,7 @@ class BAbstractLayoutItem : public BLayoutItem { public: BAbstractLayoutItem(); + BAbstractLayoutItem(BMessage* from); virtual ~BAbstractLayoutItem(); virtual BSize MinSize(); @@ -30,6 +31,8 @@ virtual BSize BasePreferredSize(); virtual BAlignment BaseAlignment(); + virtual status_t Archive(BMessage* into, bool deep = true) const; + private: BSize fMinSize; BSize fMaxSize; Modified: haiku/trunk/src/kits/interface/AbstractLayoutItem.cpp =================================================================== --- haiku/trunk/src/kits/interface/AbstractLayoutItem.cpp 2010-07-16 17:06:55 UTC (rev 37539) +++ haiku/trunk/src/kits/interface/AbstractLayoutItem.cpp 2010-07-16 17:23:15 UTC (rev 37540) @@ -1,107 +1,155 @@ /* + * Copyright 2010, Haiku, Inc. * Copyright 2006, Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx>. * All rights reserved. Distributed under the terms of the MIT License. */ + #include <AbstractLayoutItem.h> #include <LayoutUtils.h> +#include <Message.h> -// constructor +namespace { + const char* kMinSizeField = "BAbstractLayoutItem:minSize"; + const char* kMaxSizeField = "BAbstractLayoutItem:maxSize"; + const char* kPreferredSizeField = "BAbstractLayoutItem:preferredSize"; + const char* kAlignmentField = "BAbstractLayoutItem:alignment"; +} + + BAbstractLayoutItem::BAbstractLayoutItem() - : fMinSize(), - fMaxSize(), - fPreferredSize(), - fAlignment() + : + fMinSize(), + fMaxSize(), + 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() { } -// MinSize + BSize BAbstractLayoutItem::MinSize() { return BLayoutUtils::ComposeSize(fMinSize, BaseMinSize()); } -// MaxSize + BSize BAbstractLayoutItem::MaxSize() { return BLayoutUtils::ComposeSize(fMaxSize, BaseMaxSize()); } -// PreferredSize + BSize BAbstractLayoutItem::PreferredSize() { return BLayoutUtils::ComposeSize(fMaxSize, BasePreferredSize()); } -// Alignment + BAlignment BAbstractLayoutItem::Alignment() { return BLayoutUtils::ComposeAlignment(fAlignment, BaseAlignment()); } -// SetExplicitMinSize + void BAbstractLayoutItem::SetExplicitMinSize(BSize size) { fMinSize = size; } -// SetExplicitMaxSize + void BAbstractLayoutItem::SetExplicitMaxSize(BSize size) { fMaxSize = size; } -// SetExplicitPreferredSize + void BAbstractLayoutItem::SetExplicitPreferredSize(BSize size) { fPreferredSize = size; } -// SetExplicitAlignment + void BAbstractLayoutItem::SetExplicitAlignment(BAlignment alignment) { fAlignment = alignment; } -// BaseMinSize + BSize BAbstractLayoutItem::BaseMinSize() { return BSize(0, 0); } -// BaseMaxSize + BSize BAbstractLayoutItem::BaseMaxSize() { return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED); } -// BasePreferredSize + BSize BAbstractLayoutItem::BasePreferredSize() { return BSize(0, 0); } -// BaseAlignment + BAlignment BAbstractLayoutItem::BaseAlignment() { 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); +}