Patch by Alex Wilson:
* Added support for archiving/unarchiving. * Coding style cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37613 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku, Inc. All rights reserved.
|
* Copyright 2006-2010, Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _CARD_LAYOUT_H
|
#ifndef _CARD_LAYOUT_H
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
class BCardLayout : public BLayout {
|
class BCardLayout : public BLayout {
|
||||||
public:
|
public:
|
||||||
BCardLayout();
|
BCardLayout();
|
||||||
|
BCardLayout(BMessage* from);
|
||||||
virtual ~BCardLayout();
|
virtual ~BCardLayout();
|
||||||
|
|
||||||
BLayoutItem* VisibleItem() const;
|
BLayoutItem* VisibleItem() const;
|
||||||
@@ -30,6 +31,10 @@ public:
|
|||||||
virtual void InvalidateLayout();
|
virtual void InvalidateLayout();
|
||||||
virtual void LayoutView();
|
virtual void LayoutView();
|
||||||
|
|
||||||
|
virtual status_t Archive(BMessage* into, bool deep = true) const;
|
||||||
|
virtual status_t AllUnarchived(const BMessage* from);
|
||||||
|
static BArchivable* Instantiate(BMessage* from);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void ItemAdded(BLayoutItem* item);
|
virtual void ItemAdded(BLayoutItem* item);
|
||||||
virtual void ItemRemoved(BLayoutItem* item);
|
virtual void ItemRemoved(BLayoutItem* item);
|
||||||
|
|||||||
@@ -6,46 +6,66 @@
|
|||||||
#include <CardLayout.h>
|
#include <CardLayout.h>
|
||||||
|
|
||||||
#include <LayoutItem.h>
|
#include <LayoutItem.h>
|
||||||
|
#include <Message.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
// constructor
|
|
||||||
|
namespace {
|
||||||
|
const char* kVisibleItemField = "BCardLayout:visibleItem";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BCardLayout::BCardLayout()
|
BCardLayout::BCardLayout()
|
||||||
: BLayout(),
|
:
|
||||||
fMin(0, 0),
|
BLayout(),
|
||||||
fMax(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED),
|
fMin(0, 0),
|
||||||
fPreferred(0, 0),
|
fMax(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED),
|
||||||
fVisibleItem(NULL),
|
fPreferred(0, 0),
|
||||||
fMinMaxValid(false)
|
fVisibleItem(NULL),
|
||||||
|
fMinMaxValid(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
|
||||||
|
BCardLayout::BCardLayout(BMessage* from)
|
||||||
|
:
|
||||||
|
BLayout(BUnarchiver::PrepareArchive(from)),
|
||||||
|
fMin(0, 0),
|
||||||
|
fMax(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED),
|
||||||
|
fPreferred(0, 0),
|
||||||
|
fVisibleItem(NULL),
|
||||||
|
fMinMaxValid(false)
|
||||||
|
{
|
||||||
|
BUnarchiver(from).Finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BCardLayout::~BCardLayout()
|
BCardLayout::~BCardLayout()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisibleItem
|
|
||||||
BLayoutItem*
|
BLayoutItem*
|
||||||
BCardLayout::VisibleItem() const
|
BCardLayout::VisibleItem() const
|
||||||
{
|
{
|
||||||
return fVisibleItem;
|
return fVisibleItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisibleIndex
|
|
||||||
int32
|
int32
|
||||||
BCardLayout::VisibleIndex() const
|
BCardLayout::VisibleIndex() const
|
||||||
{
|
{
|
||||||
return IndexOfItem(fVisibleItem);
|
return IndexOfItem(fVisibleItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetVisibleItem
|
|
||||||
void
|
void
|
||||||
BCardLayout::SetVisibleItem(int32 index)
|
BCardLayout::SetVisibleItem(int32 index)
|
||||||
{
|
{
|
||||||
SetVisibleItem(ItemAt(index));
|
SetVisibleItem(ItemAt(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetVisibleItem
|
|
||||||
void
|
void
|
||||||
BCardLayout::SetVisibleItem(BLayoutItem* item)
|
BCardLayout::SetVisibleItem(BLayoutItem* item)
|
||||||
{
|
{
|
||||||
@@ -67,7 +87,7 @@ BCardLayout::SetVisibleItem(BLayoutItem* item)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MinSize
|
|
||||||
BSize
|
BSize
|
||||||
BCardLayout::MinSize()
|
BCardLayout::MinSize()
|
||||||
{
|
{
|
||||||
@@ -75,7 +95,7 @@ BCardLayout::MinSize()
|
|||||||
return fMin;
|
return fMin;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxSize
|
|
||||||
BSize
|
BSize
|
||||||
BCardLayout::MaxSize()
|
BCardLayout::MaxSize()
|
||||||
{
|
{
|
||||||
@@ -83,7 +103,7 @@ BCardLayout::MaxSize()
|
|||||||
return fMax;
|
return fMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreferredSize
|
|
||||||
BSize
|
BSize
|
||||||
BCardLayout::PreferredSize()
|
BCardLayout::PreferredSize()
|
||||||
{
|
{
|
||||||
@@ -91,14 +111,14 @@ BCardLayout::PreferredSize()
|
|||||||
return fPreferred;
|
return fPreferred;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alignment
|
|
||||||
BAlignment
|
BAlignment
|
||||||
BCardLayout::Alignment()
|
BCardLayout::Alignment()
|
||||||
{
|
{
|
||||||
return BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT);
|
return BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasHeightForWidth
|
|
||||||
bool
|
bool
|
||||||
BCardLayout::HasHeightForWidth()
|
BCardLayout::HasHeightForWidth()
|
||||||
{
|
{
|
||||||
@@ -111,7 +131,7 @@ BCardLayout::HasHeightForWidth()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHeightForWidth
|
|
||||||
void
|
void
|
||||||
BCardLayout::GetHeightForWidth(float width, float* min, float* max,
|
BCardLayout::GetHeightForWidth(float width, float* min, float* max,
|
||||||
float* preferred)
|
float* preferred)
|
||||||
@@ -152,7 +172,7 @@ BCardLayout::GetHeightForWidth(float width, float* min, float* max,
|
|||||||
*preferred = preferredHeight;
|
*preferred = preferredHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// InvalidateLayout
|
|
||||||
void
|
void
|
||||||
BCardLayout::InvalidateLayout()
|
BCardLayout::InvalidateLayout()
|
||||||
{
|
{
|
||||||
@@ -161,7 +181,7 @@ BCardLayout::InvalidateLayout()
|
|||||||
fMinMaxValid = false;
|
fMinMaxValid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// LayoutView
|
|
||||||
void
|
void
|
||||||
BCardLayout::LayoutView()
|
BCardLayout::LayoutView()
|
||||||
{
|
{
|
||||||
@@ -175,14 +195,52 @@ BCardLayout::LayoutView()
|
|||||||
fVisibleItem->AlignInFrame(BRect(0, 0, size.width, size.height));
|
fVisibleItem->AlignInFrame(BRect(0, 0, size.width, size.height));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ItemAdded
|
|
||||||
|
status_t
|
||||||
|
BCardLayout::Archive(BMessage* into, bool deep) const
|
||||||
|
{
|
||||||
|
BArchiver archiver(into);
|
||||||
|
status_t err = BLayout::Archive(into, deep);
|
||||||
|
|
||||||
|
if (err == B_OK && deep)
|
||||||
|
err = into->AddInt32(kVisibleItemField, IndexOfItem(fVisibleItem));
|
||||||
|
|
||||||
|
return archiver.Finish(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BCardLayout::AllUnarchived(const BMessage* from)
|
||||||
|
{
|
||||||
|
status_t err = BLayout::AllUnarchived(from);
|
||||||
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
int32 visibleIndex;
|
||||||
|
err = from->FindInt32(kVisibleItemField, &visibleIndex);
|
||||||
|
if (err == B_OK)
|
||||||
|
SetVisibleItem(visibleIndex);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BArchivable*
|
||||||
|
BCardLayout::Instantiate(BMessage* from)
|
||||||
|
{
|
||||||
|
if (validate_instantiation(from, "BCardLayout"))
|
||||||
|
return new BCardLayout(from);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BCardLayout::ItemAdded(BLayoutItem* item)
|
BCardLayout::ItemAdded(BLayoutItem* item)
|
||||||
{
|
{
|
||||||
item->SetVisible(false);
|
item->SetVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ItemRemoved
|
|
||||||
void
|
void
|
||||||
BCardLayout::ItemRemoved(BLayoutItem* item)
|
BCardLayout::ItemRemoved(BLayoutItem* item)
|
||||||
{
|
{
|
||||||
@@ -192,7 +250,7 @@ BCardLayout::ItemRemoved(BLayoutItem* item)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _ValidateMinMax
|
|
||||||
void
|
void
|
||||||
BCardLayout::_ValidateMinMax()
|
BCardLayout::_ValidateMinMax()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user