2008-02-25 01:54:05 +00:00
|
|
|
/*
|
2010-09-21 23:31:50 +00:00
|
|
|
* Copyright 2006 - 2010, Haiku, Inc. All rights reserved.
|
2008-02-25 01:54:05 +00:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2010-09-21 23:31:50 +00:00
|
|
|
#ifndef ALM_LAYOUT_H
|
|
|
|
#define ALM_LAYOUT_H
|
2008-02-06 10:51:44 +00:00
|
|
|
|
2010-09-22 21:53:32 +00:00
|
|
|
|
2010-08-17 18:43:41 +00:00
|
|
|
#include <AbstractLayout.h>
|
2008-02-06 10:51:44 +00:00
|
|
|
#include <Size.h>
|
|
|
|
|
2009-10-28 09:00:14 +00:00
|
|
|
#include "Area.h"
|
2008-02-06 10:51:44 +00:00
|
|
|
#include "LinearSpec.h"
|
2010-09-30 01:32:48 +00:00
|
|
|
#include "Tab.h"
|
2008-02-06 10:51:44 +00:00
|
|
|
|
|
|
|
|
2012-01-17 14:28:01 +13:00
|
|
|
class BView;
|
|
|
|
class BLayoutItem;
|
|
|
|
|
2012-01-23 13:12:26 +13:00
|
|
|
namespace BPrivate {
|
|
|
|
class SharedSolver;
|
|
|
|
};
|
|
|
|
|
2012-01-17 14:28:01 +13:00
|
|
|
|
2008-02-06 10:51:44 +00:00
|
|
|
namespace BALM {
|
2010-09-23 00:04:08 +00:00
|
|
|
|
2011-03-14 00:24:12 +00:00
|
|
|
|
2012-01-17 14:28:01 +13:00
|
|
|
class Column;
|
2012-01-17 15:50:57 +13:00
|
|
|
class ALMGroup;
|
2012-01-17 14:28:01 +13:00
|
|
|
class Row;
|
2011-03-14 00:24:12 +00:00
|
|
|
class RowColumnManager;
|
|
|
|
|
|
|
|
|
2010-09-22 21:53:32 +00:00
|
|
|
/*!
|
|
|
|
* A GUI layout engine using the Auckland Layout Model (ALM).
|
2008-02-06 10:51:44 +00:00
|
|
|
*/
|
2010-09-20 22:47:13 +00:00
|
|
|
class BALMLayout : public BAbstractLayout {
|
2008-02-06 10:51:44 +00:00
|
|
|
public:
|
2012-01-16 11:54:25 +13:00
|
|
|
BALMLayout(float hSpacing = 0.0f,
|
|
|
|
float vSpacing = 0.0f,
|
2010-10-21 11:19:18 +00:00
|
|
|
BALMLayout* friendLayout = NULL);
|
2010-09-21 07:04:40 +00:00
|
|
|
virtual ~BALMLayout();
|
|
|
|
|
2011-11-30 17:55:36 +13:00
|
|
|
BReference<XTab> AddXTab();
|
2012-01-17 10:37:12 +13:00
|
|
|
void AddXTabs(BReference<XTab>* tabs, uint32 count);
|
2011-11-30 17:55:36 +13:00
|
|
|
BReference<YTab> AddYTab();
|
2012-01-17 10:37:12 +13:00
|
|
|
void AddYTabs(BReference<YTab>* tabs, uint32 count);
|
2011-11-30 17:55:36 +13:00
|
|
|
|
2011-03-14 00:24:12 +00:00
|
|
|
int32 CountXTabs() const;
|
|
|
|
int32 CountYTabs() const;
|
2012-01-24 11:19:51 +13:00
|
|
|
XTab* XTabAt(int32 index, bool ordered = false);
|
|
|
|
YTab* YTabAt(int32 index, bool ordered = false);
|
2012-03-17 17:16:50 +00:00
|
|
|
int32 IndexOf(XTab* tab, bool ordered = false);
|
|
|
|
int32 IndexOf(YTab* tab, bool ordered = false);
|
2011-03-14 00:24:12 +00:00
|
|
|
|
2010-09-20 06:26:32 +00:00
|
|
|
Row* AddRow(YTab* top, YTab* bottom);
|
|
|
|
Column* AddColumn(XTab* left, XTab* right);
|
2010-09-22 21:53:32 +00:00
|
|
|
|
2010-09-20 06:26:32 +00:00
|
|
|
XTab* Left() const;
|
|
|
|
XTab* Right() const;
|
|
|
|
YTab* Top() const;
|
|
|
|
YTab* Bottom() const;
|
2008-02-06 10:51:44 +00:00
|
|
|
|
2012-01-17 14:28:01 +13:00
|
|
|
LinearProgramming::LinearSpec* Solver() const;
|
2010-09-20 22:47:13 +00:00
|
|
|
|
2012-01-16 11:54:25 +13: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 00:53:33 +00:00
|
|
|
|
2012-01-16 11:54:25 +13:00
|
|
|
void SetSpacing(float hSpacing, float vSpacing);
|
|
|
|
void GetSpacing(float* _hSpacing,
|
|
|
|
float* _vSpacing) const;
|
2010-09-29 03:30:47 +00:00
|
|
|
|
2012-01-11 17:19:29 +13:00
|
|
|
Area* AreaFor(int32 id) const;
|
2010-09-30 01:32:48 +00:00
|
|
|
Area* AreaFor(const BView* view) const;
|
2010-09-29 03:30:47 +00:00
|
|
|
Area* AreaFor(const BLayoutItem* item) const;
|
2012-01-10 17:43:58 +13:00
|
|
|
int32 CountAreas() const;
|
2011-03-14 00:24:12 +00:00
|
|
|
Area* AreaAt(int32 index) const;
|
2010-09-29 03:30:47 +00:00
|
|
|
|
2010-09-30 01:32:48 +00: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 07:16:49 +00: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 01:32:48 +00:00
|
|
|
XTab* right = NULL, YTab* bottom = NULL);
|
2010-09-23 07:16:49 +00: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 01:32:48 +00:00
|
|
|
YTab* top, XTab* right = NULL,
|
|
|
|
YTab* bottom = NULL);
|
2010-09-23 07:16:49 +00:00
|
|
|
virtual Area* AddItem(BLayoutItem* item, Row* row,
|
|
|
|
Column* column);
|
2011-11-30 17:55:36 +13:00
|
|
|
|
2012-01-10 17:43:58 +13:00
|
|
|
bool SaveLayout(BMessage* archive) const;
|
|
|
|
bool RestoreLayout(const BMessage* archive);
|
2012-01-18 16:19:10 +13:00
|
|
|
struct BadLayoutPolicy;
|
|
|
|
|
|
|
|
void SetBadLayoutPolicy(BadLayoutPolicy* policy);
|
|
|
|
BadLayoutPolicy* GetBadLayoutPolicy() const;
|
2012-01-10 17:43:58 +13:00
|
|
|
|
2010-09-23 07:16:49 +00:00
|
|
|
virtual BSize BaseMinSize();
|
|
|
|
virtual BSize BaseMaxSize();
|
|
|
|
virtual BSize BasePreferredSize();
|
|
|
|
virtual BAlignment BaseAlignment();
|
|
|
|
|
2012-01-17 16:21:32 +13:00
|
|
|
virtual status_t Perform(perform_code d, void* arg);
|
|
|
|
|
2011-10-22 14:54:43 -06:00
|
|
|
protected:
|
2010-09-23 07:16:49 +00:00
|
|
|
virtual bool ItemAdded(BLayoutItem* item, int32 atIndex);
|
|
|
|
virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex);
|
2011-10-22 14:54:43 -06:00
|
|
|
|
|
|
|
virtual void LayoutInvalidated(bool children);
|
|
|
|
virtual void DoLayout();
|
2010-09-23 07:16:49 +00:00
|
|
|
|
2012-01-18 16:19:10 +13:00
|
|
|
public:
|
|
|
|
struct BadLayoutPolicy {
|
|
|
|
virtual ~BadLayoutPolicy();
|
|
|
|
/* return false to abandon layout, true to use layout */
|
2012-01-23 13:57:55 +13:00
|
|
|
virtual bool OnBadLayout(BALMLayout* layout,
|
|
|
|
LinearProgramming::ResultType result, BLayoutContext* context) = 0;
|
2012-01-18 16:19:10 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DefaultPolicy : public BadLayoutPolicy {
|
|
|
|
virtual ~DefaultPolicy();
|
2012-01-23 13:57:55 +13:00
|
|
|
virtual bool OnBadLayout(BALMLayout* layout,
|
|
|
|
LinearProgramming::ResultType result, BLayoutContext* context);
|
2012-01-18 16:19:10 +13:00
|
|
|
};
|
|
|
|
|
2008-02-06 10:51:44 +00:00
|
|
|
private:
|
2012-01-17 16:21:32 +13: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 14:56:29 +13:00
|
|
|
private:
|
|
|
|
template <class T>
|
|
|
|
struct TabAddTransaction;
|
2012-01-19 10:48:29 +13:00
|
|
|
|
2012-01-19 14:56:29 +13:00
|
|
|
template <class T>
|
|
|
|
friend class TabAddTransaction;
|
2012-01-23 13:12:26 +13:00
|
|
|
friend class BPrivate::SharedSolver;
|
2012-01-17 16:21:32 +13:00
|
|
|
|
2011-11-30 17:55:36 +13:00
|
|
|
friend class XTab;
|
|
|
|
friend class YTab;
|
2012-01-16 11:54:25 +13:00
|
|
|
friend class Area;
|
|
|
|
|
2012-01-17 16:07:48 +13:00
|
|
|
float InsetForTab(XTab* tab) const;
|
|
|
|
float InsetForTab(YTab* tab) const;
|
2011-11-30 17:55:36 +13:00
|
|
|
|
2012-01-23 13:12:26 +13:00
|
|
|
void UpdateConstraints(BLayoutContext* context);
|
|
|
|
|
2012-01-19 10:48:29 +13:00
|
|
|
void _RemoveSelfFromTab(XTab* tab);
|
|
|
|
void _RemoveSelfFromTab(YTab* tab);
|
2012-01-19 14:56:29 +13:00
|
|
|
bool _HasTabInLayout(XTab* tab);
|
|
|
|
bool _HasTabInLayout(YTab* tab);
|
|
|
|
bool _AddedTab(XTab* tab);
|
|
|
|
bool _AddedTab(YTab* tab);
|
2012-01-19 10:48:29 +13:00
|
|
|
|
2012-01-16 12:36:51 +13:00
|
|
|
BLayoutItem* _LayoutItemToAdd(BView* view);
|
2010-09-23 07:16:49 +00:00
|
|
|
|
2012-01-23 13:12:26 +13:00
|
|
|
BPrivate::SharedSolver* fSolver;
|
2010-09-20 22:47:13 +00:00
|
|
|
|
2011-11-30 17:55:36 +13:00
|
|
|
BReference<XTab> fLeft;
|
|
|
|
BReference<XTab> fRight;
|
|
|
|
BReference<YTab> fTop;
|
|
|
|
BReference<YTab> fBottom;
|
2010-09-20 06:26:32 +00:00
|
|
|
BSize fMinSize;
|
|
|
|
BSize fMaxSize;
|
|
|
|
BSize fPreferredSize;
|
2010-09-23 00:53:33 +00:00
|
|
|
|
2012-01-16 11:54:25 +13:00
|
|
|
float fLeftInset;
|
|
|
|
float fRightInset;
|
|
|
|
float fTopInset;
|
|
|
|
float fBottomInset;
|
|
|
|
|
|
|
|
float fHSpacing;
|
|
|
|
float fVSpacing;
|
2010-09-29 03:30:47 +00:00
|
|
|
|
2011-03-14 00:24:12 +00:00
|
|
|
XTabList fXTabList;
|
2012-01-24 11:19:51 +13:00
|
|
|
bool fXTabsSorted;
|
|
|
|
|
2011-03-14 00:24:12 +00:00
|
|
|
YTabList fYTabList;
|
2012-01-24 11:19:51 +13:00
|
|
|
bool fYTabsSorted;
|
2011-03-14 00:24:12 +00:00
|
|
|
|
|
|
|
RowColumnManager* fRowColumnManager;
|
2012-01-17 16:21:32 +13:00
|
|
|
|
2012-01-18 16:19:10 +13:00
|
|
|
BadLayoutPolicy* fBadLayoutPolicy;
|
2012-01-17 16:21:32 +13:00
|
|
|
uint32 _reserved[5];
|
2008-02-06 10:51:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace BALM
|
|
|
|
|
2012-01-17 10:37:12 +13:00
|
|
|
|
2008-02-06 10:51:44 +00:00
|
|
|
using BALM::BALMLayout;
|
|
|
|
|
2012-01-17 10:37:12 +13:00
|
|
|
|
2010-09-21 23:31:50 +00:00
|
|
|
#endif // ALM_LAYOUT_H
|