xref: /haiku/headers/os/interface/GridLayout.h (revision 9760dcae2038d47442f4658c2575844c6cf92c40)
1 /*
2  * Copyright 2006, Haiku, Inc. All rights reserved.
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 			int32				CountColumns() const;
19 			int32				CountRows() const;
20 
21 			float				HorizontalSpacing() const;
22 			float				VerticalSpacing() const;
23 
24 			void				SetHorizontalSpacing(float spacing);
25 			void				SetVerticalSpacing(float spacing);
26 			void				SetSpacing(float horizontal, float vertical);
27 
28 			float				ColumnWeight(int32 column) const;
29 			void				SetColumnWeight(int32 column, float weight);
30 
31 			float				MinColumnWidth(int32 column) const;
32 			void				SetMinColumnWidth(int32 column, float width);
33 
34 			float				MaxColumnWidth(int32 column) const;
35 			void				SetMaxColumnWidth(int32 column, float width);
36 
37 			float				RowWeight(int32 row) const;
38 			void				SetRowWeight(int32 row, float weight);
39 
40 			float				MinRowHeight(int row) const;
41 			void				SetMinRowHeight(int32 row, float height);
42 
43 			float				MaxRowHeight(int32 row) const;
44 			void				SetMaxRowHeight(int32 row, float height);
45 
46 	virtual	BLayoutItem*		AddView(BView* child);
47 	virtual	BLayoutItem*		AddView(int32 index, BView* child);
48 	virtual	BLayoutItem*		AddView(BView* child, int32 column, int32 row,
49 									int32 columnCount = 1, int32 rowCount = 1);
50 
51 	virtual	bool				AddItem(BLayoutItem* item);
52 	virtual	bool				AddItem(int32 index, BLayoutItem* item);
53 	virtual	bool				AddItem(BLayoutItem* item, int32 column,
54 									int32 row, int32 columnCount = 1,
55 									int32 rowCount = 1);
56 
57 protected:
58 	virtual	void				ItemAdded(BLayoutItem* item);
59 	virtual	void				ItemRemoved(BLayoutItem* item);
60 
61 	virtual	bool				HasMultiColumnItems();
62 	virtual	bool				HasMultiRowItems();
63 
64 	virtual	int32				InternalCountColumns();
65 	virtual	int32				InternalCountRows();
66 	virtual	void				GetColumnRowConstraints(
67 									enum orientation orientation,
68 									int32 index,
69 									ColumnRowConstraints* constraints);
70 	virtual	void	 			GetItemDimensions(BLayoutItem* item,
71 									Dimensions* dimensions);
72 
73 private:
74 			class DummyLayoutItem;
75 			class RowInfoArray;
76 			struct ItemLayoutData;
77 
78 			bool				_IsGridCellEmpty(int32 column, int32 row);
79 			bool				_AreGridCellsEmpty(int32 column, int32 row,
80 									int32 columnCount, int32 rowCount);
81 
82 			bool				_ResizeGrid(int32 columnCount, int32 rowCount);
83 
84 			ItemLayoutData*		_LayoutDataForItem(BLayoutItem* item) const;
85 
86 private:
87 			BLayoutItem***		fGrid;
88 			int32				fColumnCount;
89 			int32				fRowCount;
90 
91 			RowInfoArray*		fRowInfos;
92 			RowInfoArray*		fColumnInfos;
93 
94 			int32				fMultiColumnItems;
95 			int32				fMultiRowItems;
96 };
97 
98 #endif	// _GRID_LAYOUT_H
99