Patch by Alex Wilson:
* Added archiving/unarchving support. * Coding style cleanup (some more by myself). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37547 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -12,6 +12,7 @@ class BSpaceLayoutItem : public BLayoutItem {
|
|||||||
public:
|
public:
|
||||||
BSpaceLayoutItem(BSize minSize, BSize maxSize,
|
BSpaceLayoutItem(BSize minSize, BSize maxSize,
|
||||||
BSize preferredSize, BAlignment alignment);
|
BSize preferredSize, BAlignment alignment);
|
||||||
|
BSpaceLayoutItem(BMessage* archive);
|
||||||
virtual ~BSpaceLayoutItem();
|
virtual ~BSpaceLayoutItem();
|
||||||
|
|
||||||
static BSpaceLayoutItem* CreateGlue();
|
static BSpaceLayoutItem* CreateGlue();
|
||||||
@@ -34,6 +35,9 @@ public:
|
|||||||
virtual BRect Frame();
|
virtual BRect Frame();
|
||||||
virtual void SetFrame(BRect frame);
|
virtual void SetFrame(BRect frame);
|
||||||
|
|
||||||
|
virtual status_t Archive(BMessage* into, bool deep = true) const;
|
||||||
|
static BArchivable* Instantiate(BMessage* from);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BRect fFrame;
|
BRect fFrame;
|
||||||
BSize fMinSize;
|
BSize fMinSize;
|
||||||
|
|||||||
@@ -1,31 +1,63 @@
|
|||||||
/*
|
/*
|
||||||
|
* 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 <SpaceLayoutItem.h>
|
#include <SpaceLayoutItem.h>
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
|
||||||
|
#include <Message.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
const char* kMinSizeField = "BSpaceLayoutItem:minsize";
|
||||||
|
const char* kMaxSizeField = "BSpaceLayoutItem:maxsize";
|
||||||
|
const char* kPreferredSizeField = "BSpaceLayoutItem:prefsize";
|
||||||
|
const char* kAlignmentField = "BSpaceLayoutItem:alignment";
|
||||||
|
const char* kFrameField = "BSpaceLayoutItem:frame";
|
||||||
|
const char* kVisibleField = "BSpaceLayoutItem:visible";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// constructor
|
|
||||||
BSpaceLayoutItem::BSpaceLayoutItem(BSize minSize, BSize maxSize,
|
BSpaceLayoutItem::BSpaceLayoutItem(BSize minSize, BSize maxSize,
|
||||||
BSize preferredSize, BAlignment alignment)
|
BSize preferredSize, BAlignment alignment)
|
||||||
: fFrame(),
|
:
|
||||||
fMinSize(minSize),
|
fFrame(),
|
||||||
fMaxSize(maxSize),
|
fMinSize(minSize),
|
||||||
fPreferredSize(preferredSize),
|
fMaxSize(maxSize),
|
||||||
fAlignment(alignment),
|
fPreferredSize(preferredSize),
|
||||||
fVisible(true)
|
fAlignment(alignment),
|
||||||
|
fVisible(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
|
||||||
|
BSpaceLayoutItem::BSpaceLayoutItem(BMessage* archive)
|
||||||
|
:
|
||||||
|
BLayoutItem(archive)
|
||||||
|
{
|
||||||
|
archive->FindSize(kMinSizeField, &fMinSize);
|
||||||
|
archive->FindSize(kMaxSizeField, &fMaxSize);
|
||||||
|
archive->FindSize(kPreferredSizeField, &fPreferredSize);
|
||||||
|
|
||||||
|
archive->FindAlignment(kAlignmentField, &fAlignment);
|
||||||
|
|
||||||
|
archive->FindRect(kFrameField, &fFrame);
|
||||||
|
archive->FindBool(kVisibleField, &fVisible);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BSpaceLayoutItem::~BSpaceLayoutItem()
|
BSpaceLayoutItem::~BSpaceLayoutItem()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateGlue
|
|
||||||
BSpaceLayoutItem*
|
BSpaceLayoutItem*
|
||||||
BSpaceLayoutItem::CreateGlue() {
|
BSpaceLayoutItem::CreateGlue()
|
||||||
|
{
|
||||||
return new BSpaceLayoutItem(
|
return new BSpaceLayoutItem(
|
||||||
BSize(-1, -1),
|
BSize(-1, -1),
|
||||||
BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED),
|
BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED),
|
||||||
@@ -33,9 +65,10 @@ BSpaceLayoutItem::CreateGlue() {
|
|||||||
BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
|
BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateHorizontalStrut
|
|
||||||
BSpaceLayoutItem*
|
BSpaceLayoutItem*
|
||||||
BSpaceLayoutItem::CreateHorizontalStrut(float width) {
|
BSpaceLayoutItem::CreateHorizontalStrut(float width)
|
||||||
|
{
|
||||||
return new BSpaceLayoutItem(
|
return new BSpaceLayoutItem(
|
||||||
BSize(width, -1),
|
BSize(width, -1),
|
||||||
BSize(width, B_SIZE_UNLIMITED),
|
BSize(width, B_SIZE_UNLIMITED),
|
||||||
@@ -43,9 +76,10 @@ BSpaceLayoutItem::CreateHorizontalStrut(float width) {
|
|||||||
BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
|
BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateVerticalStrut
|
|
||||||
BSpaceLayoutItem*
|
BSpaceLayoutItem*
|
||||||
BSpaceLayoutItem::CreateVerticalStrut(float height) {
|
BSpaceLayoutItem::CreateVerticalStrut(float height)
|
||||||
|
{
|
||||||
return new BSpaceLayoutItem(
|
return new BSpaceLayoutItem(
|
||||||
BSize(-1, height),
|
BSize(-1, height),
|
||||||
BSize(B_SIZE_UNLIMITED, height),
|
BSize(B_SIZE_UNLIMITED, height),
|
||||||
@@ -53,35 +87,35 @@ BSpaceLayoutItem::CreateVerticalStrut(float height) {
|
|||||||
BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
|
BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
|
||||||
}
|
}
|
||||||
|
|
||||||
// MinSize
|
|
||||||
BSize
|
BSize
|
||||||
BSpaceLayoutItem::MinSize()
|
BSpaceLayoutItem::MinSize()
|
||||||
{
|
{
|
||||||
return fMinSize;
|
return fMinSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxSize
|
|
||||||
BSize
|
BSize
|
||||||
BSpaceLayoutItem::MaxSize()
|
BSpaceLayoutItem::MaxSize()
|
||||||
{
|
{
|
||||||
return fMaxSize;
|
return fMaxSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreferredSize
|
|
||||||
BSize
|
BSize
|
||||||
BSpaceLayoutItem::PreferredSize()
|
BSpaceLayoutItem::PreferredSize()
|
||||||
{
|
{
|
||||||
return fPreferredSize;
|
return fPreferredSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alignment
|
|
||||||
BAlignment
|
BAlignment
|
||||||
BSpaceLayoutItem::Alignment()
|
BSpaceLayoutItem::Alignment()
|
||||||
{
|
{
|
||||||
return fAlignment;
|
return fAlignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExplicitMinSize
|
|
||||||
void
|
void
|
||||||
BSpaceLayoutItem::SetExplicitMinSize(BSize size)
|
BSpaceLayoutItem::SetExplicitMinSize(BSize size)
|
||||||
{
|
{
|
||||||
@@ -93,7 +127,7 @@ BSpaceLayoutItem::SetExplicitMinSize(BSize size)
|
|||||||
InvalidateLayout();
|
InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExplicitMaxSize
|
|
||||||
void
|
void
|
||||||
BSpaceLayoutItem::SetExplicitMaxSize(BSize size)
|
BSpaceLayoutItem::SetExplicitMaxSize(BSize size)
|
||||||
{
|
{
|
||||||
@@ -105,7 +139,7 @@ BSpaceLayoutItem::SetExplicitMaxSize(BSize size)
|
|||||||
InvalidateLayout();
|
InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExplicitPreferredSize
|
|
||||||
void
|
void
|
||||||
BSpaceLayoutItem::SetExplicitPreferredSize(BSize size)
|
BSpaceLayoutItem::SetExplicitPreferredSize(BSize size)
|
||||||
{
|
{
|
||||||
@@ -117,7 +151,7 @@ BSpaceLayoutItem::SetExplicitPreferredSize(BSize size)
|
|||||||
InvalidateLayout();
|
InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExplicitAlignment
|
|
||||||
void
|
void
|
||||||
BSpaceLayoutItem::SetExplicitAlignment(BAlignment alignment)
|
BSpaceLayoutItem::SetExplicitAlignment(BAlignment alignment)
|
||||||
{
|
{
|
||||||
@@ -129,30 +163,67 @@ BSpaceLayoutItem::SetExplicitAlignment(BAlignment alignment)
|
|||||||
InvalidateLayout();
|
InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsVisible
|
|
||||||
bool
|
bool
|
||||||
BSpaceLayoutItem::IsVisible()
|
BSpaceLayoutItem::IsVisible()
|
||||||
{
|
{
|
||||||
return fVisible;
|
return fVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetVisible
|
|
||||||
void
|
void
|
||||||
BSpaceLayoutItem::SetVisible(bool visible)
|
BSpaceLayoutItem::SetVisible(bool visible)
|
||||||
{
|
{
|
||||||
fVisible = visible;
|
fVisible = visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Frame
|
|
||||||
BRect
|
BRect
|
||||||
BSpaceLayoutItem::Frame()
|
BSpaceLayoutItem::Frame()
|
||||||
{
|
{
|
||||||
return fFrame;
|
return fFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFrame
|
|
||||||
void
|
void
|
||||||
BSpaceLayoutItem::SetFrame(BRect frame)
|
BSpaceLayoutItem::SetFrame(BRect frame)
|
||||||
{
|
{
|
||||||
fFrame = frame;
|
fFrame = frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BSpaceLayoutItem::Archive(BMessage* into, bool deep) const
|
||||||
|
{
|
||||||
|
status_t err = BLayoutItem::Archive(into, deep);
|
||||||
|
|
||||||
|
if (err == B_OK)
|
||||||
|
err = into->AddRect(kFrameField, fFrame);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (err == B_OK)
|
||||||
|
err = into->AddBool(kVisibleField, fVisible);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BArchivable*
|
||||||
|
BSpaceLayoutItem::Instantiate(BMessage* from)
|
||||||
|
{
|
||||||
|
if (validate_instantiation(from, "BSpaceLayoutItem"))
|
||||||
|
return new(std::nothrow) BSpaceLayoutItem(from);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user