Patch by Alex Wilson:
* Added archiving/unarchiving support. * Coding style cleanup (some more by myself). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37548 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -3,18 +3,35 @@
|
|||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "SplitLayout.h"
|
#include "SplitLayout.h"
|
||||||
|
|
||||||
|
#include <new>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <LayoutItem.h>
|
#include <LayoutItem.h>
|
||||||
#include <LayoutUtils.h>
|
#include <LayoutUtils.h>
|
||||||
|
#include <Message.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
#include "OneElementLayouter.h"
|
#include "OneElementLayouter.h"
|
||||||
#include "SimpleLayouter.h"
|
#include "SimpleLayouter.h"
|
||||||
|
|
||||||
// ItemLayoutInfo
|
|
||||||
|
// archivng constants
|
||||||
|
namespace {
|
||||||
|
const char* kInfoCollapsibleField = "BSplitLayout::info::collapsible";
|
||||||
|
const char* kInfoWeightField = "BSplitLayout::info::weight";
|
||||||
|
const char* kSpacingField = "BSplitLayout::spacing";
|
||||||
|
const char* kSplitterSizeField = "BSplitLayout::splitterSize";
|
||||||
|
const char* kIsVerticalField = "BSplitLayout::vertical";
|
||||||
|
const char* kTopInsetField = "BSplitLayout::TopInset";
|
||||||
|
const char* kBottomInsetField = "BSplitLayout::BottomInset";
|
||||||
|
const char* kLeftInsetField = "BSplitLayout::LeftInset";
|
||||||
|
const char* kRightInsetField = "BSplitLayout::RightInset";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class BSplitLayout::ItemLayoutInfo {
|
class BSplitLayout::ItemLayoutInfo {
|
||||||
public:
|
public:
|
||||||
float weight;
|
float weight;
|
||||||
@@ -25,17 +42,18 @@ public:
|
|||||||
bool isCollapsible;
|
bool isCollapsible;
|
||||||
|
|
||||||
ItemLayoutInfo()
|
ItemLayoutInfo()
|
||||||
: weight(1.0f),
|
:
|
||||||
layoutFrame(0, 0, -1, -1),
|
weight(1.0f),
|
||||||
min(),
|
layoutFrame(0, 0, -1, -1),
|
||||||
max(),
|
min(),
|
||||||
isVisible(true),
|
max(),
|
||||||
isCollapsible(true)
|
isVisible(true),
|
||||||
|
isCollapsible(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ValueRange
|
|
||||||
class BSplitLayout::ValueRange {
|
class BSplitLayout::ValueRange {
|
||||||
public:
|
public:
|
||||||
int32 sumValue; // including spacing
|
int32 sumValue; // including spacing
|
||||||
@@ -47,15 +65,17 @@ public:
|
|||||||
int32 nextSize;
|
int32 nextSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
// SplitterItem
|
|
||||||
class BSplitLayout::SplitterItem : public BLayoutItem {
|
class BSplitLayout::SplitterItem : public BLayoutItem {
|
||||||
public:
|
public:
|
||||||
SplitterItem(BSplitLayout* layout)
|
SplitterItem(BSplitLayout* layout)
|
||||||
: fLayout(layout),
|
:
|
||||||
fFrame()
|
fLayout(layout),
|
||||||
|
fFrame()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual BSize MinSize()
|
virtual BSize MinSize()
|
||||||
{
|
{
|
||||||
if (fLayout->Orientation() == B_HORIZONTAL)
|
if (fLayout->Orientation() == B_HORIZONTAL)
|
||||||
@@ -132,53 +152,97 @@ private:
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
// constructor
|
|
||||||
BSplitLayout::BSplitLayout(enum orientation orientation,
|
BSplitLayout::BSplitLayout(enum orientation orientation,
|
||||||
float spacing)
|
float spacing)
|
||||||
: fOrientation(orientation),
|
:
|
||||||
fLeftInset(0),
|
fOrientation(orientation),
|
||||||
fRightInset(0),
|
fLeftInset(0),
|
||||||
fTopInset(0),
|
fRightInset(0),
|
||||||
fBottomInset(0),
|
fTopInset(0),
|
||||||
fSplitterSize(6),
|
fBottomInset(0),
|
||||||
fSpacing(spacing),
|
fSplitterSize(6),
|
||||||
|
fSpacing(spacing),
|
||||||
|
|
||||||
fSplitterItems(),
|
fSplitterItems(),
|
||||||
fVisibleItems(),
|
fVisibleItems(),
|
||||||
fMin(),
|
fMin(),
|
||||||
fMax(),
|
fMax(),
|
||||||
fPreferred(),
|
fPreferred(),
|
||||||
|
|
||||||
fHorizontalLayouter(NULL),
|
fHorizontalLayouter(NULL),
|
||||||
fVerticalLayouter(NULL),
|
fVerticalLayouter(NULL),
|
||||||
fHorizontalLayoutInfo(NULL),
|
fHorizontalLayoutInfo(NULL),
|
||||||
fVerticalLayoutInfo(NULL),
|
fVerticalLayoutInfo(NULL),
|
||||||
|
|
||||||
fHeightForWidthItems(),
|
fHeightForWidthItems(),
|
||||||
fHeightForWidthVerticalLayouter(NULL),
|
fHeightForWidthVerticalLayouter(NULL),
|
||||||
fHeightForWidthHorizontalLayoutInfo(NULL),
|
fHeightForWidthHorizontalLayoutInfo(NULL),
|
||||||
|
|
||||||
fLayoutValid(false),
|
fLayoutValid(false),
|
||||||
|
|
||||||
fCachedHeightForWidthWidth(-2),
|
fCachedHeightForWidthWidth(-2),
|
||||||
fHeightForWidthVerticalLayouterWidth(-2),
|
fHeightForWidthVerticalLayouterWidth(-2),
|
||||||
fCachedMinHeightForWidth(-1),
|
fCachedMinHeightForWidth(-1),
|
||||||
fCachedMaxHeightForWidth(-1),
|
fCachedMaxHeightForWidth(-1),
|
||||||
fCachedPreferredHeightForWidth(-1),
|
fCachedPreferredHeightForWidth(-1),
|
||||||
|
|
||||||
fDraggingStartPoint(),
|
fDraggingStartPoint(),
|
||||||
fDraggingStartValue(0),
|
fDraggingStartValue(0),
|
||||||
fDraggingCurrentValue(0),
|
fDraggingCurrentValue(0),
|
||||||
fDraggingSplitterIndex(-1)
|
fDraggingSplitterIndex(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
|
||||||
|
BSplitLayout::BSplitLayout(BMessage* from)
|
||||||
|
:
|
||||||
|
BLayout(from),
|
||||||
|
fSplitterItems(),
|
||||||
|
fVisibleItems(),
|
||||||
|
fMin(),
|
||||||
|
fMax(),
|
||||||
|
fPreferred(),
|
||||||
|
|
||||||
|
fHorizontalLayouter(NULL),
|
||||||
|
fVerticalLayouter(NULL),
|
||||||
|
fHorizontalLayoutInfo(NULL),
|
||||||
|
fVerticalLayoutInfo(NULL),
|
||||||
|
|
||||||
|
fHeightForWidthItems(),
|
||||||
|
fHeightForWidthVerticalLayouter(NULL),
|
||||||
|
fHeightForWidthHorizontalLayoutInfo(NULL),
|
||||||
|
|
||||||
|
fLayoutValid(false),
|
||||||
|
|
||||||
|
fCachedHeightForWidthWidth(-2),
|
||||||
|
fHeightForWidthVerticalLayouterWidth(-2),
|
||||||
|
fCachedMinHeightForWidth(-1),
|
||||||
|
fCachedMaxHeightForWidth(-1),
|
||||||
|
fCachedPreferredHeightForWidth(-1),
|
||||||
|
|
||||||
|
fDraggingStartPoint(),
|
||||||
|
fDraggingStartValue(0),
|
||||||
|
fDraggingCurrentValue(0),
|
||||||
|
fDraggingSplitterIndex(-1)
|
||||||
|
{
|
||||||
|
bool isVertical;
|
||||||
|
from->FindBool(kIsVerticalField, &isVertical);
|
||||||
|
fOrientation = (isVertical) ? B_VERTICAL : B_HORIZONTAL ;
|
||||||
|
|
||||||
|
from->FindFloat(kLeftInsetField, &fLeftInset);
|
||||||
|
from->FindFloat(kRightInsetField, &fRightInset);
|
||||||
|
from->FindFloat(kTopInsetField, &fTopInset);
|
||||||
|
from->FindFloat(kBottomInsetField, &fBottomInset);
|
||||||
|
from->FindFloat(kSplitterSizeField, &fSplitterSize);
|
||||||
|
from->FindFloat(kSpacingField, &fSpacing);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BSplitLayout::~BSplitLayout()
|
BSplitLayout::~BSplitLayout()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetInsets
|
|
||||||
void
|
void
|
||||||
BSplitLayout::SetInsets(float left, float top, float right, float bottom)
|
BSplitLayout::SetInsets(float left, float top, float right, float bottom)
|
||||||
{
|
{
|
||||||
@@ -190,7 +254,7 @@ BSplitLayout::SetInsets(float left, float top, float right, float bottom)
|
|||||||
InvalidateLayout();
|
InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetInsets
|
|
||||||
void
|
void
|
||||||
BSplitLayout::GetInsets(float* left, float* top, float* right,
|
BSplitLayout::GetInsets(float* left, float* top, float* right,
|
||||||
float* bottom) const
|
float* bottom) const
|
||||||
@@ -205,14 +269,14 @@ BSplitLayout::GetInsets(float* left, float* top, float* right,
|
|||||||
*bottom = fBottomInset;
|
*bottom = fBottomInset;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spacing
|
|
||||||
float
|
float
|
||||||
BSplitLayout::Spacing() const
|
BSplitLayout::Spacing() const
|
||||||
{
|
{
|
||||||
return fSpacing;
|
return fSpacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSpacing
|
|
||||||
void
|
void
|
||||||
BSplitLayout::SetSpacing(float spacing)
|
BSplitLayout::SetSpacing(float spacing)
|
||||||
{
|
{
|
||||||
@@ -223,14 +287,14 @@ BSplitLayout::SetSpacing(float spacing)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Orientation
|
|
||||||
orientation
|
orientation
|
||||||
BSplitLayout::Orientation() const
|
BSplitLayout::Orientation() const
|
||||||
{
|
{
|
||||||
return fOrientation;
|
return fOrientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOrientation
|
|
||||||
void
|
void
|
||||||
BSplitLayout::SetOrientation(enum orientation orientation)
|
BSplitLayout::SetOrientation(enum orientation orientation)
|
||||||
{
|
{
|
||||||
@@ -241,14 +305,14 @@ BSplitLayout::SetOrientation(enum orientation orientation)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SplitterSize
|
|
||||||
float
|
float
|
||||||
BSplitLayout::SplitterSize() const
|
BSplitLayout::SplitterSize() const
|
||||||
{
|
{
|
||||||
return fSplitterSize;
|
return fSplitterSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSplitterSize
|
|
||||||
void
|
void
|
||||||
BSplitLayout::SetSplitterSize(float size)
|
BSplitLayout::SetSplitterSize(float size)
|
||||||
{
|
{
|
||||||
@@ -259,28 +323,28 @@ BSplitLayout::SetSplitterSize(float size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddView
|
|
||||||
BLayoutItem*
|
BLayoutItem*
|
||||||
BSplitLayout::AddView(BView* child)
|
BSplitLayout::AddView(BView* child)
|
||||||
{
|
{
|
||||||
return BLayout::AddView(child);
|
return BLayout::AddView(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddView
|
|
||||||
BLayoutItem*
|
BLayoutItem*
|
||||||
BSplitLayout::AddView(int32 index, BView* child)
|
BSplitLayout::AddView(int32 index, BView* child)
|
||||||
{
|
{
|
||||||
return BLayout::AddView(index, child);
|
return BLayout::AddView(index, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddView
|
|
||||||
BLayoutItem*
|
BLayoutItem*
|
||||||
BSplitLayout::AddView(BView* child, float weight)
|
BSplitLayout::AddView(BView* child, float weight)
|
||||||
{
|
{
|
||||||
return AddView(-1, child, weight);
|
return AddView(-1, child, weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddView
|
|
||||||
BLayoutItem*
|
BLayoutItem*
|
||||||
BSplitLayout::AddView(int32 index, BView* child, float weight)
|
BSplitLayout::AddView(int32 index, BView* child, float weight)
|
||||||
{
|
{
|
||||||
@@ -291,28 +355,28 @@ BSplitLayout::AddView(int32 index, BView* child, float weight)
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddItem
|
|
||||||
bool
|
bool
|
||||||
BSplitLayout::AddItem(BLayoutItem* item)
|
BSplitLayout::AddItem(BLayoutItem* item)
|
||||||
{
|
{
|
||||||
return BLayout::AddItem(item);
|
return BLayout::AddItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddItem
|
|
||||||
bool
|
bool
|
||||||
BSplitLayout::AddItem(int32 index, BLayoutItem* item)
|
BSplitLayout::AddItem(int32 index, BLayoutItem* item)
|
||||||
{
|
{
|
||||||
return BLayout::AddItem(index, item);
|
return BLayout::AddItem(index, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddItem
|
|
||||||
bool
|
bool
|
||||||
BSplitLayout::AddItem(BLayoutItem* item, float weight)
|
BSplitLayout::AddItem(BLayoutItem* item, float weight)
|
||||||
{
|
{
|
||||||
return AddItem(-1, item, weight);
|
return AddItem(-1, item, weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddItem
|
|
||||||
bool
|
bool
|
||||||
BSplitLayout::AddItem(int32 index, BLayoutItem* item, float weight)
|
BSplitLayout::AddItem(int32 index, BLayoutItem* item, float weight)
|
||||||
{
|
{
|
||||||
@@ -323,7 +387,7 @@ BSplitLayout::AddItem(int32 index, BLayoutItem* item, float weight)
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ItemWeight
|
|
||||||
float
|
float
|
||||||
BSplitLayout::ItemWeight(int32 index) const
|
BSplitLayout::ItemWeight(int32 index) const
|
||||||
{
|
{
|
||||||
@@ -333,7 +397,7 @@ BSplitLayout::ItemWeight(int32 index) const
|
|||||||
return ItemWeight(ItemAt(index));
|
return ItemWeight(ItemAt(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ItemWeight
|
|
||||||
float
|
float
|
||||||
BSplitLayout::ItemWeight(BLayoutItem* item) const
|
BSplitLayout::ItemWeight(BLayoutItem* item) const
|
||||||
{
|
{
|
||||||
@@ -342,7 +406,7 @@ BSplitLayout::ItemWeight(BLayoutItem* item) const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetItemWeight
|
|
||||||
void
|
void
|
||||||
BSplitLayout::SetItemWeight(int32 index, float weight, bool invalidateLayout)
|
BSplitLayout::SetItemWeight(int32 index, float weight, bool invalidateLayout)
|
||||||
{
|
{
|
||||||
@@ -366,7 +430,7 @@ BSplitLayout::SetItemWeight(int32 index, float weight, bool invalidateLayout)
|
|||||||
InvalidateLayout();
|
InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetItemWeight
|
|
||||||
void
|
void
|
||||||
BSplitLayout::SetItemWeight(BLayoutItem* item, float weight)
|
BSplitLayout::SetItemWeight(BLayoutItem* item, float weight)
|
||||||
{
|
{
|
||||||
@@ -374,21 +438,21 @@ BSplitLayout::SetItemWeight(BLayoutItem* item, float weight)
|
|||||||
info->weight = weight;
|
info->weight = weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCollapsible
|
|
||||||
void
|
void
|
||||||
BSplitLayout::SetCollapsible(bool collapsible)
|
BSplitLayout::SetCollapsible(bool collapsible)
|
||||||
{
|
{
|
||||||
SetCollapsible(0, CountItems() - 1, collapsible);
|
SetCollapsible(0, CountItems() - 1, collapsible);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCollapsible
|
|
||||||
void
|
void
|
||||||
BSplitLayout::SetCollapsible(int32 index, bool collapsible)
|
BSplitLayout::SetCollapsible(int32 index, bool collapsible)
|
||||||
{
|
{
|
||||||
SetCollapsible(index, index, collapsible);
|
SetCollapsible(index, index, collapsible);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCollapsible
|
|
||||||
void
|
void
|
||||||
BSplitLayout::SetCollapsible(int32 first, int32 last, bool collapsible)
|
BSplitLayout::SetCollapsible(int32 first, int32 last, bool collapsible)
|
||||||
{
|
{
|
||||||
@@ -401,7 +465,7 @@ BSplitLayout::SetCollapsible(int32 first, int32 last, bool collapsible)
|
|||||||
_ItemLayoutInfo(ItemAt(i))->isCollapsible = collapsible;
|
_ItemLayoutInfo(ItemAt(i))->isCollapsible = collapsible;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MinSize
|
|
||||||
BSize
|
BSize
|
||||||
BSplitLayout::MinSize()
|
BSplitLayout::MinSize()
|
||||||
{
|
{
|
||||||
@@ -410,7 +474,7 @@ BSplitLayout::MinSize()
|
|||||||
return _AddInsets(fMin);
|
return _AddInsets(fMin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxSize
|
|
||||||
BSize
|
BSize
|
||||||
BSplitLayout::MaxSize()
|
BSplitLayout::MaxSize()
|
||||||
{
|
{
|
||||||
@@ -419,7 +483,7 @@ BSplitLayout::MaxSize()
|
|||||||
return _AddInsets(fMax);
|
return _AddInsets(fMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreferredSize
|
|
||||||
BSize
|
BSize
|
||||||
BSplitLayout::PreferredSize()
|
BSplitLayout::PreferredSize()
|
||||||
{
|
{
|
||||||
@@ -428,14 +492,14 @@ BSplitLayout::PreferredSize()
|
|||||||
return _AddInsets(fPreferred);
|
return _AddInsets(fPreferred);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alignment
|
|
||||||
BAlignment
|
BAlignment
|
||||||
BSplitLayout::Alignment()
|
BSplitLayout::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
|
||||||
BSplitLayout::HasHeightForWidth()
|
BSplitLayout::HasHeightForWidth()
|
||||||
{
|
{
|
||||||
@@ -444,7 +508,7 @@ BSplitLayout::HasHeightForWidth()
|
|||||||
return !fHeightForWidthItems.IsEmpty();
|
return !fHeightForWidthItems.IsEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHeightForWidth
|
|
||||||
void
|
void
|
||||||
BSplitLayout::GetHeightForWidth(float width, float* min, float* max,
|
BSplitLayout::GetHeightForWidth(float width, float* min, float* max,
|
||||||
float* preferred)
|
float* preferred)
|
||||||
@@ -457,14 +521,14 @@ BSplitLayout::GetHeightForWidth(float width, float* min, float* max,
|
|||||||
_AddInsets(min, max, preferred);
|
_AddInsets(min, max, preferred);
|
||||||
}
|
}
|
||||||
|
|
||||||
// InvalidateLayout
|
|
||||||
void
|
void
|
||||||
BSplitLayout::InvalidateLayout()
|
BSplitLayout::InvalidateLayout()
|
||||||
{
|
{
|
||||||
_InvalidateLayout(true);
|
_InvalidateLayout(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// LayoutView
|
|
||||||
void
|
void
|
||||||
BSplitLayout::LayoutView()
|
BSplitLayout::LayoutView()
|
||||||
{
|
{
|
||||||
@@ -543,7 +607,7 @@ BSplitLayout::LayoutView()
|
|||||||
fLayoutValid = true;
|
fLayoutValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SplitterItemFrame
|
|
||||||
BRect
|
BRect
|
||||||
BSplitLayout::SplitterItemFrame(int32 index) const
|
BSplitLayout::SplitterItemFrame(int32 index) const
|
||||||
{
|
{
|
||||||
@@ -552,14 +616,14 @@ BSplitLayout::SplitterItemFrame(int32 index) const
|
|||||||
return BRect();
|
return BRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsAboveSplitter
|
|
||||||
bool
|
bool
|
||||||
BSplitLayout::IsAboveSplitter(const BPoint& point) const
|
BSplitLayout::IsAboveSplitter(const BPoint& point) const
|
||||||
{
|
{
|
||||||
return _SplitterItemAt(point) != NULL;
|
return _SplitterItemAt(point) != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartDraggingSplitter
|
|
||||||
bool
|
bool
|
||||||
BSplitLayout::StartDraggingSplitter(BPoint point)
|
BSplitLayout::StartDraggingSplitter(BPoint point)
|
||||||
{
|
{
|
||||||
@@ -589,7 +653,7 @@ BSplitLayout::StartDraggingSplitter(BPoint point)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DragSplitter
|
|
||||||
bool
|
bool
|
||||||
BSplitLayout::DragSplitter(BPoint point)
|
BSplitLayout::DragSplitter(BPoint point)
|
||||||
{
|
{
|
||||||
@@ -608,7 +672,7 @@ BSplitLayout::DragSplitter(BPoint point)
|
|||||||
fDraggingStartValue + valueDiff);
|
fDraggingStartValue + valueDiff);
|
||||||
}
|
}
|
||||||
|
|
||||||
// StopDraggingSplitter
|
|
||||||
bool
|
bool
|
||||||
BSplitLayout::StopDraggingSplitter()
|
BSplitLayout::StopDraggingSplitter()
|
||||||
{
|
{
|
||||||
@@ -623,14 +687,85 @@ BSplitLayout::StopDraggingSplitter()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DraggedSplitter
|
|
||||||
int32
|
int32
|
||||||
BSplitLayout::DraggedSplitter() const
|
BSplitLayout::DraggedSplitter() const
|
||||||
{
|
{
|
||||||
return fDraggingSplitterIndex;
|
return fDraggingSplitterIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ItemAdded
|
|
||||||
|
status_t
|
||||||
|
BSplitLayout::Archive(BMessage* into, bool deep) const
|
||||||
|
{
|
||||||
|
BArchiver archiver(into);
|
||||||
|
status_t err = BLayout::Archive(into, deep);
|
||||||
|
|
||||||
|
if (err == B_OK)
|
||||||
|
into->AddBool(kIsVerticalField, fOrientation == B_VERTICAL);
|
||||||
|
|
||||||
|
if (err == B_OK)
|
||||||
|
err = into->AddFloat(kLeftInsetField, fLeftInset);
|
||||||
|
|
||||||
|
if (err == B_OK)
|
||||||
|
err = into->AddFloat(kRightInsetField, fRightInset);
|
||||||
|
|
||||||
|
if (err == B_OK)
|
||||||
|
err = into->AddFloat(kTopInsetField, fTopInset);
|
||||||
|
|
||||||
|
if (err == B_OK)
|
||||||
|
err = into->AddFloat(kBottomInsetField, fBottomInset);
|
||||||
|
|
||||||
|
if (err == B_OK)
|
||||||
|
err = into->AddFloat(kSplitterSizeField, fSplitterSize);
|
||||||
|
|
||||||
|
if (err == B_OK)
|
||||||
|
err = into->AddFloat(kSpacingField, fSpacing);
|
||||||
|
|
||||||
|
return archiver.Finish(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BArchivable*
|
||||||
|
BSplitLayout::Instantiate(BMessage* from)
|
||||||
|
{
|
||||||
|
if (validate_instantiation(from, "BSplitLayout"))
|
||||||
|
return new(std::nothrow) BSplitLayout(from);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BSplitLayout::ItemArchived(BMessage* into, BLayoutItem* item, int32 index) const
|
||||||
|
{
|
||||||
|
ItemLayoutInfo* info = (ItemLayoutInfo*)item->LayoutData();
|
||||||
|
|
||||||
|
if (!info) // TODO: remove this check when AddItem() returns a bool
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
status_t err = into->AddFloat(kInfoWeightField, info->weight);
|
||||||
|
if (err == B_OK)
|
||||||
|
err = into->AddBool(kInfoCollapsibleField, info->isCollapsible);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BSplitLayout::ItemUnarchived(const BMessage* from,
|
||||||
|
BLayoutItem* item, int32 index)
|
||||||
|
{
|
||||||
|
ItemLayoutInfo* info = _ItemLayoutInfo(item);
|
||||||
|
status_t err = from->FindFloat(kInfoWeightField, index, &info->weight);
|
||||||
|
|
||||||
|
if (err == B_OK) {
|
||||||
|
bool* collapsible = &info->isCollapsible;
|
||||||
|
err = from->FindBool(kInfoCollapsibleField, index, collapsible);
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BSplitLayout::ItemAdded(BLayoutItem* item)
|
BSplitLayout::ItemAdded(BLayoutItem* item)
|
||||||
{
|
{
|
||||||
@@ -643,7 +778,7 @@ BSplitLayout::ItemAdded(BLayoutItem* item)
|
|||||||
SetItemWeight(item, 1);
|
SetItemWeight(item, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ItemRemoved
|
|
||||||
void
|
void
|
||||||
BSplitLayout::ItemRemoved(BLayoutItem* item)
|
BSplitLayout::ItemRemoved(BLayoutItem* item)
|
||||||
{
|
{
|
||||||
@@ -658,7 +793,7 @@ BSplitLayout::ItemRemoved(BLayoutItem* item)
|
|||||||
item->SetLayoutData(NULL);
|
item->SetLayoutData(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// _InvalidateLayout
|
|
||||||
void
|
void
|
||||||
BSplitLayout::_InvalidateLayout(bool invalidateView)
|
BSplitLayout::_InvalidateLayout(bool invalidateView)
|
||||||
{
|
{
|
||||||
@@ -680,7 +815,7 @@ BSplitLayout::_InvalidateLayout(bool invalidateView)
|
|||||||
fLayoutValid = false;
|
fLayoutValid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _InvalidateCachedHeightForWidth
|
|
||||||
void
|
void
|
||||||
BSplitLayout::_InvalidateCachedHeightForWidth()
|
BSplitLayout::_InvalidateCachedHeightForWidth()
|
||||||
{
|
{
|
||||||
@@ -694,7 +829,7 @@ BSplitLayout::_InvalidateCachedHeightForWidth()
|
|||||||
fHeightForWidthVerticalLayouterWidth = -2;
|
fHeightForWidthVerticalLayouterWidth = -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _SplitterItemAt
|
|
||||||
BSplitLayout::SplitterItem*
|
BSplitLayout::SplitterItem*
|
||||||
BSplitLayout::_SplitterItemAt(const BPoint& point, int32* index) const
|
BSplitLayout::_SplitterItemAt(const BPoint& point, int32* index) const
|
||||||
{
|
{
|
||||||
@@ -711,14 +846,14 @@ BSplitLayout::_SplitterItemAt(const BPoint& point, int32* index) const
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _SplitterItemAt
|
|
||||||
BSplitLayout::SplitterItem*
|
BSplitLayout::SplitterItem*
|
||||||
BSplitLayout::_SplitterItemAt(int32 index) const
|
BSplitLayout::_SplitterItemAt(int32 index) const
|
||||||
{
|
{
|
||||||
return (SplitterItem*)fSplitterItems.ItemAt(index);
|
return (SplitterItem*)fSplitterItems.ItemAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
// _GetSplitterValueRange
|
|
||||||
void
|
void
|
||||||
BSplitLayout::_GetSplitterValueRange(int32 index, ValueRange& range)
|
BSplitLayout::_GetSplitterValueRange(int32 index, ValueRange& range)
|
||||||
{
|
{
|
||||||
@@ -747,7 +882,7 @@ BSplitLayout::_GetSplitterValueRange(int32 index, ValueRange& range)
|
|||||||
range.sumValue += (int32)fSpacing;
|
range.sumValue += (int32)fSpacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _SplitterValue
|
|
||||||
int32
|
int32
|
||||||
BSplitLayout::_SplitterValue(int32 index) const
|
BSplitLayout::_SplitterValue(int32 index) const
|
||||||
{
|
{
|
||||||
@@ -761,7 +896,7 @@ BSplitLayout::_SplitterValue(int32 index) const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _LayoutItem
|
|
||||||
void
|
void
|
||||||
BSplitLayout::_LayoutItem(BLayoutItem* item, BRect frame, bool visible)
|
BSplitLayout::_LayoutItem(BLayoutItem* item, BRect frame, bool visible)
|
||||||
{
|
{
|
||||||
@@ -790,7 +925,7 @@ BSplitLayout::_LayoutItem(BLayoutItem* item, BRect frame, bool visible)
|
|||||||
item->AlignInFrame(frame);
|
item->AlignInFrame(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
// _LayoutItem
|
|
||||||
void
|
void
|
||||||
BSplitLayout::_LayoutItem(BLayoutItem* item, ItemLayoutInfo* info)
|
BSplitLayout::_LayoutItem(BLayoutItem* item, ItemLayoutInfo* info)
|
||||||
{
|
{
|
||||||
@@ -813,7 +948,7 @@ BSplitLayout::_LayoutItem(BLayoutItem* item, ItemLayoutInfo* info)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _SetSplitterValue
|
|
||||||
bool
|
bool
|
||||||
BSplitLayout::_SetSplitterValue(int32 index, int32 value)
|
BSplitLayout::_SetSplitterValue(int32 index, int32 value)
|
||||||
{
|
{
|
||||||
@@ -1042,7 +1177,7 @@ BSplitLayout::_SetSplitterValue(int32 index, int32 value)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _ItemLayoutInfo
|
|
||||||
BSplitLayout::ItemLayoutInfo*
|
BSplitLayout::ItemLayoutInfo*
|
||||||
BSplitLayout::_ItemLayoutInfo(BLayoutItem* item) const
|
BSplitLayout::_ItemLayoutInfo(BLayoutItem* item) const
|
||||||
{
|
{
|
||||||
@@ -1055,7 +1190,7 @@ BSplitLayout::_ItemLayoutInfo(BLayoutItem* item) const
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _UpdateSplitterWeights
|
|
||||||
void
|
void
|
||||||
BSplitLayout::_UpdateSplitterWeights()
|
BSplitLayout::_UpdateSplitterWeights()
|
||||||
{
|
{
|
||||||
@@ -1078,7 +1213,7 @@ BSplitLayout::_UpdateSplitterWeights()
|
|||||||
_InvalidateCachedHeightForWidth();
|
_InvalidateCachedHeightForWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
// _ValidateMinMax
|
|
||||||
void
|
void
|
||||||
BSplitLayout::_ValidateMinMax()
|
BSplitLayout::_ValidateMinMax()
|
||||||
{
|
{
|
||||||
@@ -1152,7 +1287,7 @@ BSplitLayout::_ValidateMinMax()
|
|||||||
view->ResetLayoutInvalidation();
|
view->ResetLayoutInvalidation();
|
||||||
}
|
}
|
||||||
|
|
||||||
// _InternalGetHeightForWidth
|
|
||||||
void
|
void
|
||||||
BSplitLayout::_InternalGetHeightForWidth(float width, bool realLayout,
|
BSplitLayout::_InternalGetHeightForWidth(float width, bool realLayout,
|
||||||
float* minHeight, float* maxHeight, float* preferredHeight)
|
float* minHeight, float* maxHeight, float* preferredHeight)
|
||||||
@@ -1221,7 +1356,7 @@ BSplitLayout::_InternalGetHeightForWidth(float width, bool realLayout,
|
|||||||
*preferredHeight = fCachedPreferredHeightForWidth;
|
*preferredHeight = fCachedPreferredHeightForWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _SplitterSpace
|
|
||||||
float
|
float
|
||||||
BSplitLayout::_SplitterSpace() const
|
BSplitLayout::_SplitterSpace() const
|
||||||
{
|
{
|
||||||
@@ -1235,7 +1370,7 @@ BSplitLayout::_SplitterSpace() const
|
|||||||
return space;
|
return space;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _AddInsets
|
|
||||||
BSize
|
BSize
|
||||||
BSplitLayout::_AddInsets(BSize size)
|
BSplitLayout::_AddInsets(BSize size)
|
||||||
{
|
{
|
||||||
@@ -1253,7 +1388,7 @@ BSplitLayout::_AddInsets(BSize size)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _AddInsets
|
|
||||||
void
|
void
|
||||||
BSplitLayout::_AddInsets(float* minHeight, float* maxHeight,
|
BSplitLayout::_AddInsets(float* minHeight, float* maxHeight,
|
||||||
float* preferredHeight)
|
float* preferredHeight)
|
||||||
@@ -1269,7 +1404,7 @@ BSplitLayout::_AddInsets(float* minHeight, float* maxHeight,
|
|||||||
*preferredHeight = BLayoutUtils::AddDistances(*preferredHeight, insets);
|
*preferredHeight = BLayoutUtils::AddDistances(*preferredHeight, insets);
|
||||||
}
|
}
|
||||||
|
|
||||||
// _SubtractInsets
|
|
||||||
BSize
|
BSize
|
||||||
BSplitLayout::_SubtractInsets(BSize size)
|
BSplitLayout::_SubtractInsets(BSize size)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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 _SPLIT_LAYOUT_H
|
#ifndef _SPLIT_LAYOUT_H
|
||||||
@@ -25,6 +25,7 @@ class BSplitLayout : public BLayout {
|
|||||||
public:
|
public:
|
||||||
BSplitLayout(enum orientation orientation,
|
BSplitLayout(enum orientation orientation,
|
||||||
float spacing = 0.0f);
|
float spacing = 0.0f);
|
||||||
|
BSplitLayout(BMessage* from);
|
||||||
virtual ~BSplitLayout();
|
virtual ~BSplitLayout();
|
||||||
|
|
||||||
void SetInsets(float left, float top, float right,
|
void SetInsets(float left, float top, float right,
|
||||||
@@ -87,6 +88,15 @@ public:
|
|||||||
bool StopDraggingSplitter();
|
bool StopDraggingSplitter();
|
||||||
int32 DraggedSplitter() const;
|
int32 DraggedSplitter() const;
|
||||||
|
|
||||||
|
// archiving methods
|
||||||
|
virtual status_t Archive(BMessage* into, bool deep = true) const;
|
||||||
|
static BArchivable* Instantiate(BMessage* from);
|
||||||
|
|
||||||
|
virtual status_t ItemArchived(BMessage* into, BLayoutItem* item,
|
||||||
|
int32 index) const;
|
||||||
|
virtual status_t ItemUnarchived(const BMessage* from,
|
||||||
|
BLayoutItem* item, int32 index);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void ItemAdded(BLayoutItem* item);
|
virtual void ItemAdded(BLayoutItem* item);
|
||||||
virtual void ItemRemoved(BLayoutItem* item);
|
virtual void ItemRemoved(BLayoutItem* item);
|
||||||
@@ -121,7 +131,7 @@ private:
|
|||||||
|
|
||||||
void _ValidateMinMax();
|
void _ValidateMinMax();
|
||||||
|
|
||||||
void _InternalGetHeightForWidth(float width,
|
void _InternalGetHeightForWidth(float width,
|
||||||
bool realLayout, float* minHeight,
|
bool realLayout, float* minHeight,
|
||||||
float* maxHeight, float* preferredHeight);
|
float* maxHeight, float* preferredHeight);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user