2008-02-25 04:54:05 +03:00
|
|
|
/*
|
2010-09-22 03:31:50 +04:00
|
|
|
* Copyright 2006 - 2010, Haiku, Inc. All rights reserved.
|
2008-02-25 04:54:05 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2010-09-22 03:31:50 +04:00
|
|
|
#ifndef ALM_LAYOUT_H
|
|
|
|
#define ALM_LAYOUT_H
|
2008-02-06 13:51:44 +03:00
|
|
|
|
2010-09-23 01:53:32 +04:00
|
|
|
|
2010-08-17 22:43:41 +04:00
|
|
|
#include <AbstractLayout.h>
|
2008-02-06 13:51:44 +03:00
|
|
|
#include <Size.h>
|
|
|
|
|
2009-10-28 12:00:14 +03:00
|
|
|
#include "Area.h"
|
2008-02-06 13:51:44 +03:00
|
|
|
#include "LinearSpec.h"
|
2010-09-30 05:32:48 +04:00
|
|
|
#include "Tab.h"
|
2008-02-06 13:51:44 +03:00
|
|
|
|
|
|
|
|
2012-01-17 05:28:01 +04:00
|
|
|
class BView;
|
|
|
|
class BLayoutItem;
|
2012-09-01 07:36:59 +04:00
|
|
|
class Constraint;
|
|
|
|
|
2012-01-17 05:28:01 +04:00
|
|
|
|
2012-01-23 04:12:26 +04:00
|
|
|
namespace BPrivate {
|
|
|
|
class SharedSolver;
|
|
|
|
};
|
|
|
|
|
2012-01-17 05:28:01 +04:00
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
namespace BALM {
|
2010-09-23 04:04:08 +04:00
|
|
|
|
2011-03-14 03:24:12 +03:00
|
|
|
|
2012-01-17 05:28:01 +04:00
|
|
|
class Column;
|
2012-01-17 06:50:57 +04:00
|
|
|
class ALMGroup;
|
2012-01-17 05:28:01 +04:00
|
|
|
class Row;
|
2011-03-14 03:24:12 +03:00
|
|
|
class RowColumnManager;
|
|
|
|
|
|
|
|
|
2010-09-23 01:53:32 +04:00
|
|
|
/*!
|
|
|
|
* A GUI layout engine using the Auckland Layout Model (ALM).
|
2008-02-06 13:51:44 +03:00
|
|
|
*/
|
2010-09-21 02:47:13 +04:00
|
|
|
class BALMLayout : public BAbstractLayout {
|
2008-02-06 13:51:44 +03:00
|
|
|
public:
|
2012-01-16 02:54:25 +04:00
|
|
|
BALMLayout(float hSpacing = 0.0f,
|
|
|
|
float vSpacing = 0.0f,
|
2010-10-21 15:19:18 +04:00
|
|
|
BALMLayout* friendLayout = NULL);
|
2012-02-01 02:19:07 +04:00
|
|
|
BALMLayout(BMessage* archive);
|
2010-09-21 11:04:40 +04:00
|
|
|
virtual ~BALMLayout();
|
|
|
|
|
2011-11-30 08:55:36 +04:00
|
|
|
BReference<XTab> AddXTab();
|
2012-01-17 01:37:12 +04:00
|
|
|
void AddXTabs(BReference<XTab>* tabs, uint32 count);
|
2011-11-30 08:55:36 +04:00
|
|
|
BReference<YTab> AddYTab();
|
2012-01-17 01:37:12 +04:00
|
|
|
void AddYTabs(BReference<YTab>* tabs, uint32 count);
|
2011-11-30 08:55:36 +04:00
|
|
|
|
2011-03-14 03:24:12 +03:00
|
|
|
int32 CountXTabs() const;
|
|
|
|
int32 CountYTabs() const;
|
2012-01-24 02:19:51 +04:00
|
|
|
XTab* XTabAt(int32 index, bool ordered = false);
|
2012-01-26 05:20:44 +04:00
|
|
|
XTab* XTabAt(int32 index) const;
|
2012-01-24 02:19:51 +04:00
|
|
|
YTab* YTabAt(int32 index, bool ordered = false);
|
2012-01-26 05:20:44 +04:00
|
|
|
YTab* YTabAt(int32 index) const;
|
2012-09-01 07:36:59 +04:00
|
|
|
const XTabList GetXTabs() const;
|
|
|
|
const YTabList GetYTabs() const;
|
2012-01-26 05:20:44 +04:00
|
|
|
|
2012-03-17 21:16:50 +04:00
|
|
|
int32 IndexOf(XTab* tab, bool ordered = false);
|
|
|
|
int32 IndexOf(YTab* tab, bool ordered = false);
|
2011-03-14 03:24:12 +03:00
|
|
|
|
2012-09-01 07:36:59 +04:00
|
|
|
int32 CountConstraints() const;
|
|
|
|
Constraint* ConstraintAt(int32 index) const;
|
|
|
|
bool AddConstraint(Constraint* constraint);
|
|
|
|
bool RemoveConstraint(Constraint* constraint,
|
|
|
|
bool deleteConstraint = true);
|
|
|
|
|
|
|
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
|
|
|
OperatorType op, double rightSide,
|
|
|
|
double penaltyNeg = -1,
|
|
|
|
double penaltyPos = -1);
|
|
|
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
|
|
|
double coeff2, Variable* var2,
|
|
|
|
OperatorType op, double rightSide,
|
|
|
|
double penaltyNeg = -1,
|
|
|
|
double penaltyPos = -1);
|
|
|
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
|
|
|
double coeff2, Variable* var2,
|
|
|
|
double coeff3, Variable* var3,
|
|
|
|
OperatorType op, double rightSide,
|
|
|
|
double penaltyNeg = -1,
|
|
|
|
double penaltyPos = -1);
|
|
|
|
Constraint* AddConstraint(double coeff1, Variable* var1,
|
|
|
|
double coeff2, Variable* var2,
|
|
|
|
double coeff3, Variable* var3,
|
|
|
|
double coeff4, Variable* var4,
|
|
|
|
OperatorType op, double rightSide,
|
|
|
|
double penaltyNeg = -1,
|
|
|
|
double penaltyPos = -1);
|
|
|
|
|
2010-09-20 10:26:32 +04:00
|
|
|
Row* AddRow(YTab* top, YTab* bottom);
|
|
|
|
Column* AddColumn(XTab* left, XTab* right);
|
2010-09-23 01:53:32 +04:00
|
|
|
|
2010-09-20 10:26:32 +04:00
|
|
|
XTab* Left() const;
|
|
|
|
XTab* Right() const;
|
|
|
|
YTab* Top() const;
|
|
|
|
YTab* Bottom() const;
|
2008-02-06 13:51:44 +03:00
|
|
|
|
2012-01-17 05:28:01 +04:00
|
|
|
LinearProgramming::LinearSpec* Solver() const;
|
2012-09-01 07:36:59 +04:00
|
|
|
LinearProgramming::ResultType ValidateLayout();
|
2010-09-21 02:47:13 +04:00
|
|
|
|
2012-01-16 02:54:25 +04:00
|
|
|
void SetInsets(float insets);
|
|
|
|
void SetInsets(float x, float y);
|
|
|
|
void SetInsets(float left, float top, float right,
|
|
|
|
float bottom);
|
|
|
|
void GetInsets(float* left, float* top, float* right,
|
|
|
|
float* bottom) const;
|
2010-09-23 04:53:33 +04:00
|
|
|
|
2012-01-16 02:54:25 +04:00
|
|
|
void SetSpacing(float hSpacing, float vSpacing);
|
|
|
|
void GetSpacing(float* _hSpacing,
|
|
|
|
float* _vSpacing) const;
|
2010-09-29 07:30:47 +04:00
|
|
|
|
2012-01-11 08:19:29 +04:00
|
|
|
Area* AreaFor(int32 id) const;
|
2010-09-30 05:32:48 +04:00
|
|
|
Area* AreaFor(const BView* view) const;
|
2010-09-29 07:30:47 +04:00
|
|
|
Area* AreaFor(const BLayoutItem* item) const;
|
2012-01-10 08:43:58 +04:00
|
|
|
int32 CountAreas() const;
|
2011-03-14 03:24:12 +03:00
|
|
|
Area* AreaAt(int32 index) const;
|
2010-09-29 07:30:47 +04:00
|
|
|
|
2010-09-30 05:32:48 +04:00
|
|
|
XTab* LeftOf(const BView* view) const;
|
|
|
|
XTab* LeftOf(const BLayoutItem* item) const;
|
|
|
|
XTab* RightOf(const BView* view) const;
|
|
|
|
XTab* RightOf(const BLayoutItem* item) const;
|
|
|
|
YTab* TopOf(const BView* view) const;
|
|
|
|
YTab* TopOf(const BLayoutItem* item) const;
|
|
|
|
YTab* BottomOf(const BView* view) const;
|
|
|
|
YTab* BottomOf(const BLayoutItem* item) const;
|
|
|
|
|
2010-09-23 11:16:49 +04:00
|
|
|
virtual BLayoutItem* AddView(BView* child);
|
|
|
|
virtual BLayoutItem* AddView(int32 index, BView* child);
|
|
|
|
virtual Area* AddView(BView* view, XTab* left, YTab* top,
|
2010-09-30 05:32:48 +04:00
|
|
|
XTab* right = NULL, YTab* bottom = NULL);
|
2010-09-23 11:16:49 +04:00
|
|
|
virtual Area* AddView(BView* view, Row* row, Column* column);
|
|
|
|
|
|
|
|
virtual bool AddItem(BLayoutItem* item);
|
|
|
|
virtual bool AddItem(int32 index, BLayoutItem* item);
|
|
|
|
virtual Area* AddItem(BLayoutItem* item, XTab* left,
|
2010-09-30 05:32:48 +04:00
|
|
|
YTab* top, XTab* right = NULL,
|
|
|
|
YTab* bottom = NULL);
|
2010-09-23 11:16:49 +04:00
|
|
|
virtual Area* AddItem(BLayoutItem* item, Row* row,
|
|
|
|
Column* column);
|
2012-09-01 07:36:59 +04:00
|
|
|
|
2012-01-18 07:19:10 +04:00
|
|
|
struct BadLayoutPolicy;
|
|
|
|
|
|
|
|
void SetBadLayoutPolicy(BadLayoutPolicy* policy);
|
|
|
|
BadLayoutPolicy* GetBadLayoutPolicy() const;
|
2012-01-10 08:43:58 +04:00
|
|
|
|
2010-09-23 11:16:49 +04:00
|
|
|
virtual BSize BaseMinSize();
|
|
|
|
virtual BSize BaseMaxSize();
|
|
|
|
virtual BSize BasePreferredSize();
|
|
|
|
virtual BAlignment BaseAlignment();
|
|
|
|
|
2012-02-01 02:19:07 +04:00
|
|
|
virtual status_t Archive(BMessage* into, bool deep = true) const;
|
|
|
|
static BArchivable* Instantiate(BMessage* archive);
|
|
|
|
|
2012-01-17 07:21:32 +04:00
|
|
|
virtual status_t Perform(perform_code d, void* arg);
|
|
|
|
|
2011-10-23 00:54:43 +04:00
|
|
|
protected:
|
2010-09-23 11:16:49 +04:00
|
|
|
virtual bool ItemAdded(BLayoutItem* item, int32 atIndex);
|
|
|
|
virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex);
|
2011-10-23 00:54:43 +04:00
|
|
|
|
2012-02-01 02:19:07 +04:00
|
|
|
virtual status_t ItemArchived(BMessage* into, BLayoutItem* item,
|
|
|
|
int32 index) const;
|
|
|
|
virtual status_t ItemUnarchived(const BMessage* from,
|
|
|
|
BLayoutItem* item, int32 index);
|
|
|
|
|
|
|
|
virtual status_t AllUnarchived(const BMessage* archive);
|
|
|
|
virtual status_t AllArchived(BMessage* archive) const;
|
|
|
|
|
2011-10-23 00:54:43 +04:00
|
|
|
virtual void LayoutInvalidated(bool children);
|
|
|
|
virtual void DoLayout();
|
2010-09-23 11:16:49 +04:00
|
|
|
|
2012-01-18 07:19:10 +04:00
|
|
|
public:
|
2012-02-01 06:07:51 +04:00
|
|
|
struct BadLayoutPolicy : public BArchivable {
|
|
|
|
BadLayoutPolicy();
|
|
|
|
BadLayoutPolicy(BMessage* archive);
|
|
|
|
virtual ~BadLayoutPolicy();
|
2012-01-18 07:19:10 +04:00
|
|
|
/* return false to abandon layout, true to use layout */
|
2012-02-01 06:07:51 +04:00
|
|
|
virtual bool OnBadLayout(BALMLayout* layout,
|
|
|
|
LinearProgramming::ResultType result,
|
|
|
|
BLayoutContext* context) = 0;
|
2012-01-18 07:19:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DefaultPolicy : public BadLayoutPolicy {
|
2012-02-01 06:07:51 +04:00
|
|
|
DefaultPolicy();
|
|
|
|
DefaultPolicy(BMessage* archive);
|
|
|
|
virtual ~DefaultPolicy();
|
|
|
|
virtual bool OnBadLayout(BALMLayout* layout,
|
|
|
|
LinearProgramming::ResultType result,
|
|
|
|
BLayoutContext* context);
|
|
|
|
virtual status_t Archive(BMessage* message,
|
|
|
|
bool deep = false) const;
|
|
|
|
static BArchivable* Instantiate(BMessage* message);
|
2012-01-18 07:19:10 +04:00
|
|
|
};
|
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
private:
|
2012-01-17 07:21:32 +04:00
|
|
|
|
|
|
|
// FBC padding
|
|
|
|
virtual void _ReservedALMLayout1();
|
|
|
|
virtual void _ReservedALMLayout2();
|
|
|
|
virtual void _ReservedALMLayout3();
|
|
|
|
virtual void _ReservedALMLayout4();
|
|
|
|
virtual void _ReservedALMLayout5();
|
|
|
|
virtual void _ReservedALMLayout6();
|
|
|
|
virtual void _ReservedALMLayout7();
|
|
|
|
virtual void _ReservedALMLayout8();
|
|
|
|
virtual void _ReservedALMLayout9();
|
|
|
|
virtual void _ReservedALMLayout10();
|
|
|
|
|
|
|
|
// forbidden methods
|
|
|
|
BALMLayout(const BALMLayout&);
|
|
|
|
void operator =(const BALMLayout&);
|
|
|
|
|
2012-01-19 05:56:29 +04:00
|
|
|
private:
|
|
|
|
template <class T>
|
|
|
|
struct TabAddTransaction;
|
2012-01-19 01:48:29 +04:00
|
|
|
|
2012-01-19 05:56:29 +04:00
|
|
|
template <class T>
|
|
|
|
friend class TabAddTransaction;
|
2012-01-23 04:12:26 +04:00
|
|
|
friend class BPrivate::SharedSolver;
|
2012-01-17 07:21:32 +04:00
|
|
|
|
2011-11-30 08:55:36 +04:00
|
|
|
friend class XTab;
|
|
|
|
friend class YTab;
|
2012-01-16 02:54:25 +04:00
|
|
|
friend class Area;
|
|
|
|
|
2012-09-01 07:36:59 +04:00
|
|
|
class BALMLayoutSpecListener;
|
|
|
|
friend class BALMLayoutSpecListener;
|
|
|
|
|
2012-01-17 07:07:48 +04:00
|
|
|
float InsetForTab(XTab* tab) const;
|
|
|
|
float InsetForTab(YTab* tab) const;
|
2011-11-30 08:55:36 +04:00
|
|
|
|
2012-01-23 04:12:26 +04:00
|
|
|
void UpdateConstraints(BLayoutContext* context);
|
|
|
|
|
2012-01-19 01:48:29 +04:00
|
|
|
void _RemoveSelfFromTab(XTab* tab);
|
|
|
|
void _RemoveSelfFromTab(YTab* tab);
|
2012-01-19 05:56:29 +04:00
|
|
|
bool _HasTabInLayout(XTab* tab);
|
|
|
|
bool _HasTabInLayout(YTab* tab);
|
|
|
|
bool _AddedTab(XTab* tab);
|
|
|
|
bool _AddedTab(YTab* tab);
|
2012-01-19 01:48:29 +04:00
|
|
|
|
2012-01-16 03:36:51 +04:00
|
|
|
BLayoutItem* _LayoutItemToAdd(BView* view);
|
2012-02-01 02:19:07 +04:00
|
|
|
void _SetSolver(BPrivate::SharedSolver* solver);
|
2010-09-23 11:16:49 +04:00
|
|
|
|
2012-01-23 04:12:26 +04:00
|
|
|
BPrivate::SharedSolver* fSolver;
|
2012-09-01 07:36:59 +04:00
|
|
|
BALMLayoutSpecListener* fSpecListener;
|
2010-09-21 02:47:13 +04:00
|
|
|
|
2011-11-30 08:55:36 +04:00
|
|
|
BReference<XTab> fLeft;
|
|
|
|
BReference<XTab> fRight;
|
|
|
|
BReference<YTab> fTop;
|
|
|
|
BReference<YTab> fBottom;
|
2010-09-20 10:26:32 +04:00
|
|
|
BSize fMinSize;
|
|
|
|
BSize fMaxSize;
|
|
|
|
BSize fPreferredSize;
|
2010-09-23 04:53:33 +04:00
|
|
|
|
2012-01-16 02:54:25 +04:00
|
|
|
float fLeftInset;
|
|
|
|
float fRightInset;
|
|
|
|
float fTopInset;
|
|
|
|
float fBottomInset;
|
|
|
|
|
|
|
|
float fHSpacing;
|
|
|
|
float fVSpacing;
|
2010-09-29 07:30:47 +04:00
|
|
|
|
2011-03-14 03:24:12 +03:00
|
|
|
XTabList fXTabList;
|
2012-01-24 02:19:51 +04:00
|
|
|
bool fXTabsSorted;
|
|
|
|
|
2011-03-14 03:24:12 +03:00
|
|
|
YTabList fYTabList;
|
2012-01-24 02:19:51 +04:00
|
|
|
bool fYTabsSorted;
|
2011-03-14 03:24:12 +03:00
|
|
|
|
2012-09-01 07:36:59 +04:00
|
|
|
BObjectList<Constraint> fConstraints;
|
|
|
|
|
2011-03-14 03:24:12 +03:00
|
|
|
RowColumnManager* fRowColumnManager;
|
2012-01-17 07:21:32 +04:00
|
|
|
|
2012-01-18 07:19:10 +04:00
|
|
|
BadLayoutPolicy* fBadLayoutPolicy;
|
2012-09-01 07:36:59 +04:00
|
|
|
|
2012-01-17 07:21:32 +04:00
|
|
|
uint32 _reserved[5];
|
2008-02-06 13:51:44 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace BALM
|
|
|
|
|
2012-01-17 01:37:12 +04:00
|
|
|
|
2008-02-06 13:51:44 +03:00
|
|
|
using BALM::BALMLayout;
|
|
|
|
|
2012-01-17 01:37:12 +04:00
|
|
|
|
2010-09-22 03:31:50 +04:00
|
|
|
#endif // ALM_LAYOUT_H
|