xref: /haiku/headers/os/interface/GridLayout.h (revision bc3955fea5b07e2e94a27fc05e4bb58fe6f0319b)
1 /*
2  * Copyright 2006, Haiku Inc.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef	_GRID_LAYOUT_H
6 #define	_GRID_LAYOUT_H
7 
8 #include <TwoDimensionalLayout.h>
9 
10 
11 
12 class BGridLayout : public BTwoDimensionalLayout {
13 public:
14 								BGridLayout(float horizontal = 0.0f,
15 									float vertical = 0.0f);
16 	virtual						~BGridLayout();
17 
18 			float				HorizontalSpacing() const;
19 			float				VerticalSpacing() const;
20 
21 			void				SetHorizontalSpacing(float spacing);
22 			void				SetVerticalSpacing(float spacing);
23 			void				SetSpacing(float horizontal, float vertical);
24 
25 			float				ColumnWeight(int32 column) const;
26 			void				SetColumnWeight(int32 column, float weight);
27 
28 			float				MinColumnWidth(int32 column) const;
29 			void				SetMinColumnWidth(int32 column, float width);
30 
31 			float				MaxColumnWidth(int32 column) const;
32 			void				SetMaxColumnWidth(int32 column, float width);
33 
34 			float				RowWeight(int32 row) const;
35 			void				SetRowWeight(int32 row, float weight);
36 
37 			float				MinRowHeight(int row) const;
38 			void				SetMinRowHeight(int32 row, float height);
39 
40 			float				MaxRowHeight(int32 row) const;
41 			void				SetMaxRowHeight(int32 row, float height);
42 
43 	virtual	BLayoutItem*		AddView(BView* child);
44 	virtual	BLayoutItem*		AddView(int32 index, BView* child);
45 	virtual	BLayoutItem*		AddView(BView* child, int32 column, int32 row,
46 									int32 columnCount = 1, int32 rowCount = 1);
47 
48 	virtual	bool				AddItem(BLayoutItem* item);
49 	virtual	bool				AddItem(int32 index, BLayoutItem* item);
50 	virtual	bool				AddItem(BLayoutItem* item, int32 column,
51 									int32 row, int32 columnCount = 1,
52 									int32 rowCount = 1);
53 
54 protected:
55 	virtual	void				ItemAdded(BLayoutItem* item);
56 	virtual	void				ItemRemoved(BLayoutItem* item);
57 
58 	virtual	bool				HasMultiColumnItems();
59 	virtual	bool				HasMultiRowItems();
60 
61 	virtual	int32				InternalCountColumns();
62 	virtual	int32				InternalCountRows();
63 	virtual	void				GetColumnRowConstraints(
64 									enum orientation orientation,
65 									int32 index,
66 									ColumnRowConstraints* constraints);
67 	virtual	void	 			GetItemDimensions(BLayoutItem* item,
68 									Dimensions* dimensions);
69 
70 private:
71 			class DummyLayoutItem;
72 			class RowInfoArray;
73 			struct ItemLayoutData;
74 
75 			bool				_IsGridCellEmpty(int32 column, int32 row);
76 			bool				_AreGridCellsEmpty(int32 column, int32 row,
77 									int32 columnCount, int32 rowCount);
78 
79 			bool				_ResizeGrid(int32 columnCount, int32 rowCount);
80 
81 			ItemLayoutData*		_LayoutDataForItem(BLayoutItem* item) const;
82 
83 private:
84 			BLayoutItem***		fGrid;
85 			int32				fColumnCount;
86 			int32				fRowCount;
87 
88 			RowInfoArray*		fRowInfos;
89 			RowInfoArray*		fColumnInfos;
90 
91 			int32				fMultiColumnItems;
92 			int32				fMultiRowItems;
93 };
94 
95 #endif	// _GRID_LAYOUT_H
96