xref: /haiku/headers/os/interface/GridLayout.h (revision 0d452c8f34013b611a54c746a71c05e28796eae2)
1 /*
2  * Copyright 2006-2011, 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 
9 #include <TwoDimensionalLayout.h>
10 
11 
12 class BGridLayout : public BTwoDimensionalLayout {
13 public:
14 								BGridLayout(float horizontal
15 										= B_USE_DEFAULT_SPACING,
16 									float vertical = B_USE_DEFAULT_SPACING);
17 								BGridLayout(BMessage* from);
18 	virtual						~BGridLayout();
19 
20 			int32				CountColumns() const;
21 			int32				CountRows() const;
22 
23 			float				HorizontalSpacing() const;
24 			float				VerticalSpacing() const;
25 
26 			void				SetHorizontalSpacing(float spacing);
27 			void				SetVerticalSpacing(float spacing);
28 			void				SetSpacing(float horizontal, float vertical);
29 
30 			float				ColumnWeight(int32 column) const;
31 			void				SetColumnWeight(int32 column, float weight);
32 
33 			float				MinColumnWidth(int32 column) const;
34 			void				SetMinColumnWidth(int32 column, float width);
35 
36 			float				MaxColumnWidth(int32 column) const;
37 			void				SetMaxColumnWidth(int32 column, float width);
38 
39 			float				RowWeight(int32 row) const;
40 			void				SetRowWeight(int32 row, float weight);
41 
42 			float				MinRowHeight(int row) const;
43 			void				SetMinRowHeight(int32 row, float height);
44 
45 			float				MaxRowHeight(int32 row) const;
46 			void				SetMaxRowHeight(int32 row, float height);
47 
48 			BLayoutItem*		ItemAt(int32 column, int32 row) const;
49 
50 	virtual	BLayoutItem*		AddView(BView* child);
51 	virtual	BLayoutItem*		AddView(int32 index, BView* child);
52 	virtual	BLayoutItem*		AddView(BView* child, int32 column, int32 row,
53 									int32 columnCount = 1, int32 rowCount = 1);
54 
55 	virtual	bool				AddItem(BLayoutItem* item);
56 	virtual	bool				AddItem(int32 index, BLayoutItem* item);
57 	virtual	bool				AddItem(BLayoutItem* item, int32 column,
58 									int32 row, int32 columnCount = 1,
59 									int32 rowCount = 1);
60 
61 	virtual	status_t			Archive(BMessage* into, bool deep = true) const;
62 	static	BArchivable*		Instantiate(BMessage* from);
63 
64 	virtual status_t			ItemArchived(BMessage* into,
65 									BLayoutItem* item, int32 index) const;
66 	virtual status_t			ItemUnarchived(const BMessage* from,
67 									BLayoutItem* item, int32 index);
68 
69 protected:
70 	virtual	bool				ItemAdded(BLayoutItem* item, int32 atIndex);
71 	virtual	void				ItemRemoved(BLayoutItem* item, int32 fromIndex);
72 
73 	virtual	bool				HasMultiColumnItems();
74 	virtual	bool				HasMultiRowItems();
75 
76 	virtual	int32				InternalCountColumns();
77 	virtual	int32				InternalCountRows();
78 	virtual	void				GetColumnRowConstraints(
79 									enum orientation orientation,
80 									int32 index,
81 									ColumnRowConstraints* constraints);
82 	virtual	void				GetItemDimensions(BLayoutItem* item,
83 									Dimensions* dimensions);
84 
85 private:
86 			class DummyLayoutItem;
87 			class RowInfoArray;
88 			struct ItemLayoutData;
89 
90 			bool				_IsGridCellEmpty(int32 column, int32 row);
91 			bool				_AreGridCellsEmpty(int32 column, int32 row,
92 									int32 columnCount, int32 rowCount);
93 
94 			bool				_InsertItemIntoGrid(BLayoutItem* item);
95 			bool				_ResizeGrid(int32 columnCount, int32 rowCount);
96 
97 			ItemLayoutData*		_LayoutDataForItem(BLayoutItem* item) const;
98 
99 private:
100 			BLayoutItem***		fGrid;
101 			int32				fColumnCount;
102 			int32				fRowCount;
103 
104 			RowInfoArray*		fRowInfos;
105 			RowInfoArray*		fColumnInfos;
106 
107 			int32				fMultiColumnItems;
108 			int32				fMultiRowItems;
109 };
110 
111 
112 #endif	// _GRID_LAYOUT_H
113