2008-02-25 04:54:05 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
|
|
|
|
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
|
2010-09-23 01:53:32 +04:00
|
|
|
|
2010-09-22 08:51:09 +04:00
|
|
|
#include "Area.h"
|
|
|
|
|
2010-09-20 10:09:19 +04:00
|
|
|
#include <algorithm> // for max
|
|
|
|
|
|
|
|
#include <Button.h>
|
|
|
|
#include <CheckBox.h>
|
|
|
|
#include <PictureButton.h>
|
|
|
|
#include <RadioButton.h>
|
|
|
|
#include <StatusBar.h>
|
|
|
|
#include <StringView.h>
|
|
|
|
|
2010-09-22 03:35:36 +04:00
|
|
|
#include "ALMLayout.h"
|
2008-02-06 13:51:44 +03:00
|
|
|
|
|
|
|
|
2008-02-07 22:31:49 +03:00
|
|
|
using namespace std;
|
2008-02-06 13:51:44 +03:00
|
|
|
|
|
|
|
|
2010-09-21 11:04:40 +04:00
|
|
|
BView*
|
|
|
|
Area::View()
|
|
|
|
{
|
|
|
|
return fLayoutItem->View();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
/**
|
|
|
|
* Gets the auto preferred content size.
|
|
|
|
*
|
|
|
|
* @return the auto preferred content size
|
|
|
|
*/
|
|
|
|
bool
|
2009-10-28 12:00:14 +03:00
|
|
|
Area::AutoPreferredContentSize() const
|
2008-02-06 13:51:44 +03:00
|
|
|
{
|
2009-10-28 12:00:14 +03:00
|
|
|
return fAutoPreferredContentSize;
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the auto preferred content size true or false.
|
|
|
|
*
|
|
|
|
* @param value the auto preferred content size
|
|
|
|
*/
|
|
|
|
void
|
2009-10-28 12:00:14 +03:00
|
|
|
Area::SetAutoPreferredContentSize(bool value)
|
2008-02-06 13:51:44 +03:00
|
|
|
{
|
2009-10-28 12:00:14 +03:00
|
|
|
fAutoPreferredContentSize = value;
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the left tab of the area.
|
|
|
|
*
|
|
|
|
* @return the left tab of the area
|
|
|
|
*/
|
|
|
|
XTab*
|
|
|
|
Area::Left() const
|
|
|
|
{
|
|
|
|
return fLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-22 09:50:51 +04:00
|
|
|
/**
|
|
|
|
* Gets the right tab of the area.
|
|
|
|
*
|
|
|
|
* @return the right tab of the area
|
|
|
|
*/
|
|
|
|
XTab*
|
|
|
|
Area::Right() const
|
|
|
|
{
|
|
|
|
return fRight;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the top tab of the area.
|
|
|
|
*/
|
|
|
|
YTab*
|
|
|
|
Area::Top() const
|
|
|
|
{
|
|
|
|
return fTop;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the bottom tab of the area.
|
|
|
|
*/
|
|
|
|
YTab*
|
|
|
|
Area::Bottom() const
|
|
|
|
{
|
|
|
|
return fBottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
/**
|
|
|
|
* Sets the left tab of the area.
|
|
|
|
*
|
|
|
|
* @param left the left tab of the area
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Area::SetLeft(XTab* left)
|
|
|
|
{
|
|
|
|
fLeft = left;
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
fColumn = NULL;
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2010-09-22 08:51:09 +04:00
|
|
|
fMinContentWidth->SetLeftSide(-1.0, fLeft, 1.0, fRight);
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2010-09-22 08:51:09 +04:00
|
|
|
if (fMaxContentWidth != NULL)
|
|
|
|
fMaxContentWidth->SetLeftSide(-1.0, fLeft, 1.0, fRight);
|
|
|
|
|
|
|
|
fLayoutItem->Layout()->InvalidateLayout();
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the right tab of the area.
|
|
|
|
*
|
|
|
|
* @param right the right tab of the area
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Area::SetRight(XTab* right)
|
|
|
|
{
|
|
|
|
fRight = right;
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
fColumn = NULL;
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2010-09-22 08:51:09 +04:00
|
|
|
fMinContentWidth->SetLeftSide(-1.0, fLeft, 1.0, fRight);
|
|
|
|
|
|
|
|
if (fMaxContentWidth != NULL)
|
|
|
|
fMaxContentWidth->SetLeftSide(-1.0, fLeft, 1.0, fRight);
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2010-09-22 08:51:09 +04:00
|
|
|
fLayoutItem->Layout()->InvalidateLayout();
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the top tab of the area.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Area::SetTop(YTab* top)
|
|
|
|
{
|
|
|
|
fTop = top;
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
fRow = NULL;
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2010-09-22 08:51:09 +04:00
|
|
|
fMinContentHeight->SetLeftSide(-1.0, fTop, 1.0, fBottom);
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2010-09-22 08:51:09 +04:00
|
|
|
if (fMaxContentHeight != NULL)
|
|
|
|
fMaxContentHeight->SetLeftSide(-1.0, fTop, 1.0, fBottom);
|
|
|
|
|
|
|
|
fLayoutItem->Layout()->InvalidateLayout();
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the bottom tab of the area.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Area::SetBottom(YTab* bottom)
|
|
|
|
{
|
|
|
|
fBottom = bottom;
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
fRow = NULL;
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2010-09-22 08:51:09 +04:00
|
|
|
fMinContentHeight->SetLeftSide(-1.0, fTop, 1.0, fBottom);
|
|
|
|
|
|
|
|
if (fMaxContentHeight != NULL)
|
|
|
|
fMaxContentHeight->SetLeftSide(-1.0, fTop, 1.0, fBottom);
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2010-09-22 08:51:09 +04:00
|
|
|
fLayoutItem->Layout()->InvalidateLayout();
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the row that defines the top and bottom tabs.
|
|
|
|
*/
|
|
|
|
Row*
|
|
|
|
Area::GetRow() const
|
|
|
|
{
|
|
|
|
return fRow;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-22 09:50:51 +04:00
|
|
|
/**
|
|
|
|
* Gets the column that defines the left and right tabs.
|
|
|
|
*/
|
|
|
|
Column*
|
|
|
|
Area::GetColumn() const
|
|
|
|
{
|
|
|
|
return fColumn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
/**
|
|
|
|
* Sets the row that defines the top and bottom tabs.
|
|
|
|
* May be null.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Area::SetRow(Row* row)
|
|
|
|
{
|
|
|
|
SetTop(row->Top());
|
|
|
|
SetBottom(row->Bottom());
|
|
|
|
fRow = row;
|
2010-09-22 08:51:09 +04:00
|
|
|
fLayoutItem->Layout()->InvalidateLayout();
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the column that defines the left and right tabs.
|
|
|
|
* May be null.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Area::SetColumn(Column* column)
|
|
|
|
{
|
|
|
|
SetLeft(column->Left());
|
|
|
|
SetRight(column->Right());
|
|
|
|
fColumn = column;
|
2010-09-22 08:51:09 +04:00
|
|
|
fLayoutItem->Layout()->InvalidateLayout();
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-09-22 09:50:51 +04:00
|
|
|
* The reluctance with which the area's content shrinks below its preferred size.
|
|
|
|
* The bigger the less likely is such shrinking.
|
2008-02-06 13:51:44 +03:00
|
|
|
*/
|
2010-09-22 09:50:51 +04:00
|
|
|
BSize
|
|
|
|
Area::ShrinkPenalties() const
|
2008-02-06 13:51:44 +03:00
|
|
|
{
|
2010-09-22 09:50:51 +04:00
|
|
|
return fShrinkPenalties;
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-09-22 09:50:51 +04:00
|
|
|
* The reluctance with which the area's content grows over its preferred size.
|
|
|
|
* The bigger the less likely is such growth.
|
2008-02-06 13:51:44 +03:00
|
|
|
*/
|
|
|
|
BSize
|
2010-09-22 09:50:51 +04:00
|
|
|
Area::GrowPenalties() const
|
2008-02-06 13:51:44 +03:00
|
|
|
{
|
2010-09-22 09:50:51 +04:00
|
|
|
return fGrowPenalties;
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-28 12:00:14 +03:00
|
|
|
void Area::SetShrinkPenalties(BSize shrink) {
|
2010-09-22 08:51:09 +04:00
|
|
|
fShrinkPenalties = shrink;
|
|
|
|
if (fPreferredContentWidth != NULL) {
|
|
|
|
fPreferredContentWidth->SetPenaltyNeg(shrink.Width());
|
|
|
|
fPreferredContentHeight->SetPenaltyNeg(shrink.Height());
|
|
|
|
}
|
|
|
|
fLayoutItem->Layout()->InvalidateLayout();
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2009-10-28 12:00:14 +03:00
|
|
|
Area::SetGrowPenalties(BSize grow)
|
2008-02-06 13:51:44 +03:00
|
|
|
{
|
2010-09-22 08:51:09 +04:00
|
|
|
fGrowPenalties = grow;
|
|
|
|
if (fPreferredContentWidth != NULL) {
|
|
|
|
fPreferredContentWidth->SetPenaltyPos(grow.Width());
|
|
|
|
fPreferredContentHeight->SetPenaltyPos(grow.Height());
|
|
|
|
}
|
|
|
|
fLayoutItem->Layout()->InvalidateLayout();
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets aspect ratio of the area's content.
|
|
|
|
*/
|
|
|
|
double
|
|
|
|
Area::ContentAspectRatio() const
|
|
|
|
{
|
2010-09-22 08:51:09 +04:00
|
|
|
return fContentAspectRatio;
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets aspect ratio of the area's content.
|
|
|
|
* May be different from the aspect ratio of the area.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Area::SetContentAspectRatio(double ratio)
|
|
|
|
{
|
2010-09-22 08:51:09 +04:00
|
|
|
fContentAspectRatio = ratio;
|
|
|
|
if (fContentAspectRatioC == NULL) {
|
|
|
|
fContentAspectRatioC = fLS->AddConstraint(-1.0, fLeft, 1.0, fRight,
|
|
|
|
ratio, fTop, -ratio, fBottom, OperatorType(EQ), 0.0);
|
|
|
|
fConstraints.AddItem(fContentAspectRatioC);
|
|
|
|
} else {
|
|
|
|
fContentAspectRatioC->SetLeftSide(-1.0, fLeft, 1.0, fRight, ratio,
|
|
|
|
fTop, -ratio, fBottom);
|
|
|
|
}
|
|
|
|
fLayoutItem->Layout()->InvalidateLayout();
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets left inset between area and its content.
|
|
|
|
*/
|
|
|
|
int32
|
|
|
|
Area::LeftInset() const
|
|
|
|
{
|
|
|
|
return fLeftInset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-09-22 09:50:51 +04:00
|
|
|
* Gets top inset between area and its content.
|
2008-02-06 13:51:44 +03:00
|
|
|
*/
|
2010-09-22 09:50:51 +04:00
|
|
|
int32
|
|
|
|
Area::TopInset() const
|
2008-02-06 13:51:44 +03:00
|
|
|
{
|
2010-09-22 09:50:51 +04:00
|
|
|
return fTopInset;
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-09-22 09:50:51 +04:00
|
|
|
* Gets right inset between area and its content.
|
2008-02-06 13:51:44 +03:00
|
|
|
*/
|
|
|
|
int32
|
2010-09-22 09:50:51 +04:00
|
|
|
Area::RightInset() const
|
2008-02-06 13:51:44 +03:00
|
|
|
{
|
2010-09-22 09:50:51 +04:00
|
|
|
return fRightInset;
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-09-22 09:50:51 +04:00
|
|
|
* Gets bottom inset between area and its content.
|
2008-02-06 13:51:44 +03:00
|
|
|
*/
|
2010-09-22 09:50:51 +04:00
|
|
|
int32
|
|
|
|
Area::BottomInset() const
|
2008-02-06 13:51:44 +03:00
|
|
|
{
|
2010-09-22 09:50:51 +04:00
|
|
|
return fBottomInset;
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-09-22 09:50:51 +04:00
|
|
|
* Sets left inset between area and its content.
|
2008-02-06 13:51:44 +03:00
|
|
|
*/
|
2010-09-22 09:50:51 +04:00
|
|
|
void
|
|
|
|
Area::SetLeftInset(int32 left)
|
2008-02-06 13:51:44 +03:00
|
|
|
{
|
2010-09-22 09:50:51 +04:00
|
|
|
fLeftInset = left;
|
|
|
|
fLayoutItem->Layout()->InvalidateLayout();
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-09-22 09:50:51 +04:00
|
|
|
* Sets top inset between area and its content.
|
2008-02-06 13:51:44 +03:00
|
|
|
*/
|
|
|
|
void
|
2010-09-22 09:50:51 +04:00
|
|
|
Area::SetTopInset(int32 top)
|
2008-02-06 13:51:44 +03:00
|
|
|
{
|
2010-09-22 09:50:51 +04:00
|
|
|
fTopInset = top;
|
|
|
|
fLayoutItem->Layout()->InvalidateLayout();
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-09-22 09:50:51 +04:00
|
|
|
* Sets right inset between area and its content.
|
2008-02-06 13:51:44 +03:00
|
|
|
*/
|
2010-09-22 09:50:51 +04:00
|
|
|
void
|
|
|
|
Area::SetRightInset(int32 right)
|
2008-02-06 13:51:44 +03:00
|
|
|
{
|
2010-09-22 09:50:51 +04:00
|
|
|
fRightInset = right;
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets bottom inset between area and its content.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Area::SetBottomInset(int32 bottom)
|
|
|
|
{
|
|
|
|
fBottomInset = bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-12-06 16:14:45 +03:00
|
|
|
* Sets the preferred size according to the content's PreferredSize method,
|
2009-10-28 12:00:14 +03:00
|
|
|
* and the penalties according to heuristics.
|
2008-02-06 13:51:44 +03:00
|
|
|
*/
|
|
|
|
void
|
2009-10-28 12:00:14 +03:00
|
|
|
Area::SetDefaultBehavior()
|
2008-02-06 13:51:44 +03:00
|
|
|
{
|
2010-09-21 11:04:40 +04:00
|
|
|
if (View() == NULL) {
|
2009-10-28 12:00:14 +03:00
|
|
|
SetShrinkPenalties(BSize(0, 0));
|
|
|
|
SetGrowPenalties(BSize(0, 0));
|
2008-02-06 13:51:44 +03:00
|
|
|
return;
|
|
|
|
}
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2010-09-21 11:04:40 +04:00
|
|
|
if (dynamic_cast<BButton*>(View()) != NULL
|
|
|
|
|| dynamic_cast<BRadioButton*>(View()) != NULL
|
|
|
|
|| dynamic_cast<BCheckBox*>(View()) != NULL
|
|
|
|
|| dynamic_cast<BStringView*>(View()) != NULL
|
|
|
|
|| dynamic_cast<BPictureButton*>(View()) != NULL
|
|
|
|
|| dynamic_cast<BStatusBar*>(View()) != NULL) {
|
2009-10-28 12:00:14 +03:00
|
|
|
fShrinkPenalties = BSize(4, 4);
|
|
|
|
fGrowPenalties = BSize(3, 3);
|
2008-02-06 13:51:44 +03:00
|
|
|
} else {
|
2009-10-28 12:00:14 +03:00
|
|
|
fShrinkPenalties = BSize(2, 2);
|
|
|
|
fGrowPenalties = BSize(1, 1);
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-06 16:14:45 +03:00
|
|
|
Area::operator BString() const
|
|
|
|
{
|
|
|
|
BString string;
|
|
|
|
GetString(string);
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Area::GetString(BString& string) const
|
|
|
|
{
|
|
|
|
string << "Area(";
|
|
|
|
fLeft->GetString(string);
|
|
|
|
string << ", ";
|
|
|
|
fTop->GetString(string);
|
|
|
|
string << ", ";
|
|
|
|
fRight->GetString(string);
|
|
|
|
string << ", ";
|
|
|
|
fBottom->GetString(string);
|
|
|
|
string << ")";
|
2009-10-28 12:00:14 +03:00
|
|
|
}
|
2008-02-06 13:51:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the width of the area to be the same as the width of the given area.
|
2009-12-06 16:14:45 +03:00
|
|
|
*
|
2008-02-06 13:51:44 +03:00
|
|
|
* @param area the area that should have the same width
|
|
|
|
* @return the same-width constraint
|
|
|
|
*/
|
|
|
|
Constraint*
|
|
|
|
Area::HasSameWidthAs(Area* area)
|
|
|
|
{
|
2008-02-25 04:54:05 +03:00
|
|
|
return fLS->AddConstraint(
|
2009-12-06 16:14:45 +03:00
|
|
|
-1.0, fLeft, 1.0, fRight, 1.0, area->fLeft, -1.0, area->fRight,
|
2008-02-25 04:54:05 +03:00
|
|
|
OperatorType(EQ), 0.0);
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the height of the area to be the same as the height of the given area.
|
2009-12-06 16:14:45 +03:00
|
|
|
*
|
2008-02-06 13:51:44 +03:00
|
|
|
* @param area the area that should have the same height
|
|
|
|
* @return the same-height constraint
|
|
|
|
*/
|
|
|
|
Constraint*
|
|
|
|
Area::HasSameHeightAs(Area* area)
|
|
|
|
{
|
2008-02-25 04:54:05 +03:00
|
|
|
return fLS->AddConstraint(
|
2009-12-06 16:14:45 +03:00
|
|
|
-1.0, fTop, 1.0, fBottom, 1.0, area->fTop, -1.0, area->fBottom,
|
2008-02-25 04:54:05 +03:00
|
|
|
OperatorType(EQ), 0.0);
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the size of the area to be the same as the size of the given area.
|
2009-12-06 16:14:45 +03:00
|
|
|
*
|
2008-02-06 13:51:44 +03:00
|
|
|
* @param area the area that should have the same size
|
|
|
|
* @return a list containing a same-width and same-height constraint
|
|
|
|
*/
|
|
|
|
BList*
|
2009-10-28 12:00:14 +03:00
|
|
|
Area::HasSameSizeAs(Area* area)
|
2008-02-06 13:51:44 +03:00
|
|
|
{
|
|
|
|
BList* constraints = new BList(2);
|
|
|
|
constraints->AddItem(this->HasSameWidthAs(area));
|
|
|
|
constraints->AddItem(this->HasSameHeightAs(area));
|
|
|
|
return constraints;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-22 03:18:43 +04:00
|
|
|
void
|
|
|
|
Area::InvalidateSizeConstraints()
|
|
|
|
{
|
|
|
|
BSize minSize = fLayoutItem->MinSize();
|
|
|
|
BSize maxSize = fLayoutItem->MaxSize();
|
|
|
|
BSize prefSize = fLayoutItem->PreferredSize();
|
|
|
|
|
|
|
|
_UpdateMinSizeConstraint(minSize);
|
|
|
|
_UpdateMaxSizeConstraint(maxSize);
|
|
|
|
_UpdatePreferredConstraint(prefSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
* Removes the area from its specification.
|
|
|
|
*/
|
|
|
|
Area::~Area()
|
|
|
|
{
|
2010-09-22 08:51:09 +04:00
|
|
|
for (int32 i = 0; i < fConstraints.CountItems(); i++)
|
|
|
|
delete (Constraint*)fConstraints.ItemAt(i);
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
* Uses XTabs and YTabs.
|
|
|
|
*/
|
2010-09-22 08:51:09 +04:00
|
|
|
Area::Area(BLayoutItem* item)
|
2010-09-21 11:04:40 +04:00
|
|
|
:
|
|
|
|
fLayoutItem(item)
|
2009-12-06 16:14:45 +03:00
|
|
|
{
|
2008-02-06 13:51:44 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize variables.
|
|
|
|
*/
|
|
|
|
void
|
2010-09-23 01:53:32 +04:00
|
|
|
Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom,
|
|
|
|
BView* content)
|
2008-02-06 13:51:44 +03:00
|
|
|
{
|
|
|
|
fMaxContentWidth = NULL;
|
|
|
|
fMaxContentHeight = NULL;
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2009-10-28 12:00:14 +03:00
|
|
|
fShrinkPenalties = BSize(2, 2);
|
|
|
|
fGrowPenalties = BSize(1, 1);
|
2008-05-28 19:30:27 +04:00
|
|
|
fContentAspectRatio = 0;
|
2008-02-06 13:51:44 +03:00
|
|
|
fContentAspectRatioC = NULL;
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2009-10-28 12:00:14 +03:00
|
|
|
fAutoPreferredContentSize = false;
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2009-10-28 12:00:14 +03:00
|
|
|
fPreferredContentWidth = NULL;
|
|
|
|
fPreferredContentHeight = NULL;
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
fLeftInset = 0;
|
|
|
|
fTopInset = 0;
|
|
|
|
fRightInset = 0;
|
|
|
|
fBottomInset = 0;
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
fLS = ls;
|
|
|
|
fLeft = left;
|
|
|
|
fRight = right;
|
|
|
|
fTop = top;
|
|
|
|
fBottom = bottom;
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2010-09-23 01:53:32 +04:00
|
|
|
// adds the two essential constraints of the area that make sure that the
|
|
|
|
// left x-tab is really to the left of the right x-tab, and the top y-tab
|
|
|
|
// really above the bottom y-tab
|
|
|
|
fMinContentWidth = ls->AddConstraint(-1.0, left, 1.0, right,
|
|
|
|
OperatorType(GE), 0);
|
|
|
|
fMinContentHeight = ls->AddConstraint(-1.0, top, 1.0, bottom,
|
|
|
|
OperatorType(GE), 0);
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2010-09-23 01:53:32 +04:00
|
|
|
fConstraints.AddItem(fMinContentWidth);
|
2010-09-22 08:51:09 +04:00
|
|
|
fConstraints.AddItem(fMinContentHeight);
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-21 11:04:40 +04:00
|
|
|
void
|
2010-09-23 01:53:32 +04:00
|
|
|
Area::_Init(LinearSpec* ls, Row* row, Column* column, BView* content)
|
2010-09-21 11:04:40 +04:00
|
|
|
{
|
2010-09-22 09:50:51 +04:00
|
|
|
_Init(ls, column->Left(), row->Top(), column->Right(), row->Bottom(),
|
2010-09-23 01:53:32 +04:00
|
|
|
content);
|
2010-09-21 11:04:40 +04:00
|
|
|
fRow = row;
|
|
|
|
fColumn = column;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
/**
|
|
|
|
* Perform layout on the area.
|
|
|
|
*/
|
2010-09-22 09:50:51 +04:00
|
|
|
void Area::_DoLayout()
|
2008-02-06 13:51:44 +03:00
|
|
|
{
|
2010-09-22 08:51:09 +04:00
|
|
|
BRect areaFrame(round(Left()->Value()), round(Top()->Value()),
|
|
|
|
round(Right()->Value()), round(Bottom()->Value()));
|
|
|
|
areaFrame.left += fLeftInset;
|
|
|
|
areaFrame.right -= fRightInset;
|
|
|
|
areaFrame.top += fTopInset;
|
|
|
|
areaFrame.bottom -= fBottomInset;
|
2009-12-06 16:14:45 +03:00
|
|
|
|
2010-09-22 08:51:09 +04:00
|
|
|
fLayoutItem->AlignInFrame(areaFrame);
|
2008-02-06 13:51:44 +03:00
|
|
|
}
|
|
|
|
|
2010-09-22 03:18:43 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
Area::_UpdateMinSizeConstraint(BSize min)
|
|
|
|
{
|
2010-09-22 08:51:09 +04:00
|
|
|
fMinContentWidth->SetRightSide(min.Width() + fLeftInset + fRightInset);
|
|
|
|
fMinContentHeight->SetRightSide(min.Height() + fTopInset + fBottomInset);
|
2010-09-22 03:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Area::_UpdateMaxSizeConstraint(BSize max)
|
|
|
|
{
|
2010-09-22 08:51:09 +04:00
|
|
|
max.width += fLeftInset + fRightInset;
|
|
|
|
max.height += fTopInset + fBottomInset;
|
2010-09-22 03:18:43 +04:00
|
|
|
|
2010-09-22 09:24:15 +04:00
|
|
|
// we only need max constraints if the alignment is full height/width
|
|
|
|
// otherwise we can just align the item in the free space
|
2010-09-22 08:51:09 +04:00
|
|
|
BAlignment alignment = fLayoutItem->Alignment();
|
|
|
|
if (alignment.Vertical() == B_ALIGN_USE_FULL_HEIGHT) {
|
|
|
|
if (fMaxContentHeight == NULL) {
|
2010-09-22 03:18:43 +04:00
|
|
|
fMaxContentHeight = fLS->AddConstraint(-1.0, fTop, 1.0, fBottom,
|
2010-09-22 03:51:41 +04:00
|
|
|
OperatorType(LE), max.Height());
|
2010-09-22 08:51:09 +04:00
|
|
|
fConstraints.AddItem(fMaxContentHeight);
|
|
|
|
} else
|
2010-09-22 03:51:41 +04:00
|
|
|
fMaxContentHeight->SetRightSide(max.Height());
|
2010-09-22 08:51:09 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
fConstraints.RemoveItem(fMaxContentHeight);
|
|
|
|
delete fMaxContentHeight;
|
|
|
|
fMaxContentHeight = NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-22 09:24:15 +04:00
|
|
|
if (alignment.Horizontal() == B_ALIGN_USE_FULL_WIDTH) {
|
2010-09-22 08:51:09 +04:00
|
|
|
if (fMaxContentWidth == NULL) {
|
|
|
|
fMaxContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0, fRight,
|
|
|
|
OperatorType(LE), max.Width());
|
|
|
|
fConstraints.AddItem(fMaxContentWidth);
|
|
|
|
} else
|
|
|
|
fMaxContentWidth->SetRightSide(max.Width());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fConstraints.RemoveItem(fMaxContentWidth);
|
|
|
|
delete fMaxContentWidth;
|
|
|
|
fMaxContentWidth = NULL;
|
|
|
|
}
|
2010-09-22 03:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets Preferred size of the area's content.
|
|
|
|
* May be different from the preferred size of the area.
|
|
|
|
* Manual changes of PreferredContentSize are ignored unless
|
|
|
|
* autoPreferredContentSize is set to false.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Area::_UpdatePreferredConstraint(BSize preferred)
|
|
|
|
{
|
2010-09-22 08:51:09 +04:00
|
|
|
preferred.width += fLeftInset + fRightInset;
|
|
|
|
preferred.height += fTopInset + fBottomInset;
|
|
|
|
if (fPreferredContentWidth == NULL) {
|
|
|
|
fPreferredContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0,
|
|
|
|
fRight, OperatorType(EQ), preferred.Width(),
|
|
|
|
fShrinkPenalties.Width(), fGrowPenalties.Width());
|
|
|
|
fConstraints.AddItem(fPreferredContentWidth);
|
|
|
|
|
|
|
|
fPreferredContentHeight = fLS->AddConstraint(-1.0, fTop, 1.0,
|
|
|
|
fBottom, OperatorType(EQ), preferred.Height(),
|
|
|
|
fShrinkPenalties.Height(), fGrowPenalties.Height());
|
|
|
|
fConstraints.AddItem(fPreferredContentHeight);
|
|
|
|
} else {
|
|
|
|
fPreferredContentWidth->SetRightSide(preferred.Width());
|
|
|
|
fPreferredContentHeight->SetRightSide(preferred.Height());
|
|
|
|
}
|
2010-09-22 03:18:43 +04:00
|
|
|
}
|