From 7ed1644c55c3bedebf4c85fb41e292ae94e2260e Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 16 Jul 2010 17:23:15 +0000 Subject: [PATCH] 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 --- headers/os/interface/AbstractLayoutItem.h | 3 + src/kits/interface/AbstractLayoutItem.cpp | 84 ++++++++++++++++++----- 2 files changed, 69 insertions(+), 18 deletions(-) diff --git a/headers/os/interface/AbstractLayoutItem.h b/headers/os/interface/AbstractLayoutItem.h index 8ba3c219e7..aef495832c 100644 --- a/headers/os/interface/AbstractLayoutItem.h +++ b/headers/os/interface/AbstractLayoutItem.h @@ -13,6 +13,7 @@ class BAbstractLayoutItem : public BLayoutItem { public: BAbstractLayoutItem(); + BAbstractLayoutItem(BMessage* from); virtual ~BAbstractLayoutItem(); virtual BSize MinSize(); @@ -30,6 +31,8 @@ public: virtual BSize BasePreferredSize(); virtual BAlignment BaseAlignment(); + virtual status_t Archive(BMessage* into, bool deep = true) const; + private: BSize fMinSize; BSize fMaxSize; diff --git a/src/kits/interface/AbstractLayoutItem.cpp b/src/kits/interface/AbstractLayoutItem.cpp index e07b852f53..397994ecb5 100644 --- a/src/kits/interface/AbstractLayoutItem.cpp +++ b/src/kits/interface/AbstractLayoutItem.cpp @@ -1,107 +1,155 @@ /* + * Copyright 2010, Haiku, Inc. * Copyright 2006, Ingo Weinhold . * All rights reserved. Distributed under the terms of the MIT License. */ + #include #include +#include + + +namespace { + const char* kMinSizeField = "BAbstractLayoutItem:minSize"; + const char* kMaxSizeField = "BAbstractLayoutItem:maxSize"; + const char* kPreferredSizeField = "BAbstractLayoutItem:preferredSize"; + const char* kAlignmentField = "BAbstractLayoutItem:alignment"; +} -// constructor 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); +}