Patch by Alex Wilson:
* Added archiving/unarchiving support. * Coding style cleanup (some by myself). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37549 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,88 +1,109 @@
|
|||||||
/*
|
/*
|
||||||
|
* 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 "ViewLayoutItem.h"
|
#include "ViewLayoutItem.h"
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
|
||||||
|
#include <Layout.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
|
||||||
// constructor
|
namespace {
|
||||||
|
const char* kViewField = "ViewLayoutItem:view";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BViewLayoutItem::BViewLayoutItem(BView* view)
|
BViewLayoutItem::BViewLayoutItem(BView* view)
|
||||||
: fView(view)
|
:
|
||||||
|
fView(view)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
|
||||||
|
BViewLayoutItem::BViewLayoutItem(BMessage* from)
|
||||||
|
:
|
||||||
|
BLayoutItem(BUnarchiver::PrepareArchive(from)),
|
||||||
|
fView(NULL)
|
||||||
|
{
|
||||||
|
BUnarchiver unarchiver(from);
|
||||||
|
unarchiver.Finish(unarchiver.FindObject<BView>(kViewField, 0,
|
||||||
|
BUnarchiver::B_DONT_ASSUME_OWNERSHIP, fView));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BViewLayoutItem::~BViewLayoutItem()
|
BViewLayoutItem::~BViewLayoutItem()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// MinSize
|
|
||||||
BSize
|
BSize
|
||||||
BViewLayoutItem::MinSize()
|
BViewLayoutItem::MinSize()
|
||||||
{
|
{
|
||||||
return fView->MinSize();
|
return fView->MinSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxSize
|
|
||||||
BSize
|
BSize
|
||||||
BViewLayoutItem::MaxSize()
|
BViewLayoutItem::MaxSize()
|
||||||
{
|
{
|
||||||
return fView->MaxSize();
|
return fView->MaxSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreferredSize
|
|
||||||
BSize
|
BSize
|
||||||
BViewLayoutItem::PreferredSize()
|
BViewLayoutItem::PreferredSize()
|
||||||
{
|
{
|
||||||
return fView->PreferredSize();
|
return fView->PreferredSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alignment
|
|
||||||
BAlignment
|
BAlignment
|
||||||
BViewLayoutItem::Alignment()
|
BViewLayoutItem::Alignment()
|
||||||
{
|
{
|
||||||
return fView->LayoutAlignment();
|
return fView->LayoutAlignment();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExplicitMinSize
|
|
||||||
void
|
void
|
||||||
BViewLayoutItem::SetExplicitMinSize(BSize size)
|
BViewLayoutItem::SetExplicitMinSize(BSize size)
|
||||||
{
|
{
|
||||||
fView->SetExplicitMinSize(size);
|
fView->SetExplicitMinSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExplicitMaxSize
|
|
||||||
void
|
void
|
||||||
BViewLayoutItem::SetExplicitMaxSize(BSize size)
|
BViewLayoutItem::SetExplicitMaxSize(BSize size)
|
||||||
{
|
{
|
||||||
fView->SetExplicitMaxSize(size);
|
fView->SetExplicitMaxSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExplicitPreferredSize
|
|
||||||
void
|
void
|
||||||
BViewLayoutItem::SetExplicitPreferredSize(BSize size)
|
BViewLayoutItem::SetExplicitPreferredSize(BSize size)
|
||||||
{
|
{
|
||||||
fView->SetExplicitPreferredSize(size);
|
fView->SetExplicitPreferredSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExplicitAlignment
|
|
||||||
void
|
void
|
||||||
BViewLayoutItem::SetExplicitAlignment(BAlignment alignment)
|
BViewLayoutItem::SetExplicitAlignment(BAlignment alignment)
|
||||||
{
|
{
|
||||||
fView->SetExplicitAlignment(alignment);
|
fView->SetExplicitAlignment(alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsVisible
|
|
||||||
bool
|
bool
|
||||||
BViewLayoutItem::IsVisible()
|
BViewLayoutItem::IsVisible()
|
||||||
{
|
{
|
||||||
return !fView->IsHidden(fView);
|
return !fView->IsHidden(fView);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetVisible
|
|
||||||
void
|
void
|
||||||
BViewLayoutItem::SetVisible(bool visible)
|
BViewLayoutItem::SetVisible(bool visible)
|
||||||
{
|
{
|
||||||
@@ -94,14 +115,14 @@ BViewLayoutItem::SetVisible(bool visible)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Frame
|
|
||||||
BRect
|
BRect
|
||||||
BViewLayoutItem::Frame()
|
BViewLayoutItem::Frame()
|
||||||
{
|
{
|
||||||
return fView->Frame();
|
return fView->Frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFrame
|
|
||||||
void
|
void
|
||||||
BViewLayoutItem::SetFrame(BRect frame)
|
BViewLayoutItem::SetFrame(BRect frame)
|
||||||
{
|
{
|
||||||
@@ -109,14 +130,14 @@ BViewLayoutItem::SetFrame(BRect frame)
|
|||||||
fView->ResizeTo(frame.Width(), frame.Height());
|
fView->ResizeTo(frame.Width(), frame.Height());
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasHeightForWidth
|
|
||||||
bool
|
bool
|
||||||
BViewLayoutItem::HasHeightForWidth()
|
BViewLayoutItem::HasHeightForWidth()
|
||||||
{
|
{
|
||||||
return fView->HasHeightForWidth();
|
return fView->HasHeightForWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHeightForWidth
|
|
||||||
void
|
void
|
||||||
BViewLayoutItem::GetHeightForWidth(float width, float* min, float* max,
|
BViewLayoutItem::GetHeightForWidth(float width, float* min, float* max,
|
||||||
float* preferred)
|
float* preferred)
|
||||||
@@ -124,16 +145,62 @@ BViewLayoutItem::GetHeightForWidth(float width, float* min, float* max,
|
|||||||
fView->GetHeightForWidth(width, min, max, preferred);
|
fView->GetHeightForWidth(width, min, max, preferred);
|
||||||
}
|
}
|
||||||
|
|
||||||
// View
|
|
||||||
BView*
|
BView*
|
||||||
BViewLayoutItem::View()
|
BViewLayoutItem::View()
|
||||||
{
|
{
|
||||||
return fView;
|
return fView;
|
||||||
}
|
}
|
||||||
|
|
||||||
// InvalidateLayout
|
|
||||||
void
|
void
|
||||||
BViewLayoutItem::InvalidateLayout()
|
BViewLayoutItem::InvalidateLayout()
|
||||||
{
|
{
|
||||||
fView->InvalidateLayout();
|
fView->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BViewLayoutItem::Archive(BMessage* into, bool deep) const
|
||||||
|
{
|
||||||
|
BArchiver archiver(into);
|
||||||
|
status_t err = BLayoutItem::Archive(into, deep);
|
||||||
|
|
||||||
|
return archiver.Finish(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BViewLayoutItem::AllArchived(BMessage* into) const
|
||||||
|
{
|
||||||
|
BArchiver archiver(into);
|
||||||
|
status_t err = BLayoutItem::AllArchived(into);
|
||||||
|
|
||||||
|
if (err == B_OK) {
|
||||||
|
if (archiver.IsArchived(fView))
|
||||||
|
err = archiver.AddArchivable(kViewField, fView);
|
||||||
|
else
|
||||||
|
err = B_NAME_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BViewLayoutItem::AllUnarchived(const BMessage* from)
|
||||||
|
{
|
||||||
|
if (!fView)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
return BLayoutItem::AllUnarchived(from);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BArchivable*
|
||||||
|
BViewLayoutItem::Instantiate(BMessage* from)
|
||||||
|
{
|
||||||
|
if (validate_instantiation(from, "BViewLayoutItem"))
|
||||||
|
return new(std::nothrow) BViewLayoutItem(from);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku Inc.
|
* Copyright 2006-2010, Haiku Inc.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _VIEW_LAYOUT_ITEM_H
|
#ifndef _VIEW_LAYOUT_ITEM_H
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
class BViewLayoutItem : public BLayoutItem {
|
class BViewLayoutItem : public BLayoutItem {
|
||||||
public:
|
public:
|
||||||
BViewLayoutItem(BView* view);
|
BViewLayoutItem(BView* view);
|
||||||
|
BViewLayoutItem(BMessage* from);
|
||||||
virtual ~BViewLayoutItem();
|
virtual ~BViewLayoutItem();
|
||||||
|
|
||||||
virtual BSize MinSize();
|
virtual BSize MinSize();
|
||||||
@@ -37,6 +38,11 @@ public:
|
|||||||
|
|
||||||
virtual void InvalidateLayout();
|
virtual void InvalidateLayout();
|
||||||
|
|
||||||
|
virtual status_t Archive(BMessage* into, bool deep = true) const;
|
||||||
|
virtual status_t AllArchived(BMessage* into) const;
|
||||||
|
virtual status_t AllUnarchived(const BMessage* from);
|
||||||
|
static BArchivable* Instantiate(BMessage* from);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BView* fView;
|
BView* fView;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user