xref: /haiku/headers/os/interface/Layout.h (revision 9d6d3fcf5fe8308cd020cecf89dede440346f8c4)
1 /*
2  * Copyright 2006, Haiku Inc.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef	_LAYOUT_H
6 #define	_LAYOUT_H
7 
8 #include <Alignment.h>
9 #include <List.h>
10 #include <Size.h>
11 
12 class BLayoutItem;
13 class BView;
14 
15 
16 class BLayout {
17 public:
18 								BLayout();
19 	virtual						~BLayout();
20 
21 			BView*				View() const;
22 
23 	virtual	BLayoutItem*		AddView(BView* child);
24 	virtual	BLayoutItem*		AddView(int32 index, BView* child);
25 
26 	virtual	bool				AddItem(BLayoutItem* item);
27 	virtual	bool				AddItem(int32 index, BLayoutItem* item);
28 
29 	virtual	bool				RemoveView(BView* child);
30 	virtual	bool				RemoveItem(BLayoutItem* item);
31 	virtual	BLayoutItem*		RemoveItem(int32 index);
32 
33 			BLayoutItem*		ItemAt(int32 index) const;
34 			int32				CountItems() const;
35 			int32				IndexOfItem(BLayoutItem* item) const;
36 			int32				IndexOfView(BView* child) const;
37 
38 	virtual	BSize				MinSize() = 0;
39 	virtual	BSize				MaxSize() = 0;
40 	virtual	BSize				PreferredSize() = 0;
41 	virtual	BAlignment			Alignment() = 0;
42 
43 	virtual	bool				HasHeightForWidth() = 0;
44 	virtual	void				GetHeightForWidth(float width, float* min,
45 									float* max, float* preferred) = 0;
46 
47 	virtual	void				InvalidateLayout();
48 
49 	virtual	void				LayoutView() = 0;
50 
51 protected:
52 // TODO: Since memory allocations can fail, we should return a bool and
53 // undo the addition, if false.
54 	virtual	void				ItemAdded(BLayoutItem* item);
55 	virtual	void				ItemRemoved(BLayoutItem* item);
56 
57 
58 private:
59 			friend class BView;
60 
61 			void				SetView(BView* view);
62 
63 			BView*				fView;
64 			BList				fItems;
65 };
66 
67 #endif	//	_LAYOUT_H
68