xref: /haiku/headers/os/interface/Layout.h (revision 21258e2674226d6aa732321b6f8494841895af5f)
1 /*
2  * Copyright 2006-2010, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef	_LAYOUT_H
6 #define	_LAYOUT_H
7 
8 
9 #include <Alignment.h>
10 #include <Archivable.h>
11 #include <LayoutItem.h>
12 #include <List.h>
13 #include <Size.h>
14 
15 
16 class BLayoutContext;
17 class BLayoutItem;
18 class BView;
19 
20 
21 class BLayout : public BLayoutItem {
22 public:
23 								BLayout();
24 								BLayout(BMessage* archive);
25 	virtual						~BLayout();
26 
27 			BView*				Owner() const;
28 			BView*				TargetView() const;
29 	virtual	BView*				View(); // from BLayoutItem
30 
31 	// methods dealing with items
32 	virtual	BLayoutItem*		AddView(BView* child);
33 	virtual	BLayoutItem*		AddView(int32 index, BView* child);
34 
35 	virtual	bool				AddItem(BLayoutItem* item);
36 	virtual	bool				AddItem(int32 index, BLayoutItem* item);
37 
38 	virtual	bool				RemoveView(BView* child);
39 	virtual	bool				RemoveItem(BLayoutItem* item);
40 	virtual	BLayoutItem*		RemoveItem(int32 index);
41 
42 			BLayoutItem*		ItemAt(int32 index) const;
43 			int32				CountItems() const;
44 			int32				IndexOfItem(const BLayoutItem* item) const;
45 			int32				IndexOfView(BView* child) const;
46 
47 			bool				AncestorsVisible() const;
48 
49 	// Layouting related methods
50 
51 	virtual	void				InvalidateLayout(bool children = false);
52 	virtual	void				Relayout(bool immediate = false);
53 									// from BLayoutItem
54 			void				RequireLayout();
55 			bool				IsValid();
56 			void				EnableLayoutInvalidation();
57 			void				DisableLayoutInvalidation();
58 
59 			void				LayoutItems(bool force = false);
60 			BRect				LayoutArea();
61 			BLayoutContext*		LayoutContext() const;
62 
63 	virtual status_t			Archive(BMessage* into, bool deep = true) const;
64 
65 	virtual status_t			Perform(perform_code d, void* arg);
66 
67 protected:
68 	// Archiving hook methods
69 	virtual	status_t			AllArchived(BMessage* archive) const;
70 	virtual	status_t			AllUnarchived(const BMessage* from);
71 
72 	virtual status_t			ItemArchived(BMessage* into, BLayoutItem* item,
73 									int32 index) const;
74 	virtual	status_t			ItemUnarchived(const BMessage* from,
75 									BLayoutItem* item, int32 index);
76 	// BLayout hook methods
77 	virtual	bool				ItemAdded(BLayoutItem* item, int32 atIndex);
78 	virtual	void				ItemRemoved(BLayoutItem* item, int32 fromIndex);
79 	virtual	void				LayoutInvalidated(bool children);
80 	virtual	void				DoLayout() = 0;
81 	virtual	void				OwnerChanged(BView* was);
82 
83 	// BLayoutItem hook methods
84 	virtual	void				AttachedToLayout();
85 	virtual void				DetachedFromLayout(BLayout* layout);
86 	virtual	void				AncestorVisibilityChanged(bool shown);
87 
88 	// To be called by sub-classes in SetVisible().
89 			void				VisibilityChanged(bool show);
90 	// To be called when layout data is known to be good
91 			void				ResetLayoutInvalidation();
92 
93 private:
94 
95 	// FBC padding
96 	virtual	void				_ReservedLayout1();
97 	virtual	void				_ReservedLayout2();
98 	virtual	void				_ReservedLayout3();
99 	virtual	void				_ReservedLayout4();
100 	virtual	void				_ReservedLayout5();
101 	virtual	void				_ReservedLayout6();
102 	virtual	void				_ReservedLayout7();
103 	virtual	void				_ReservedLayout8();
104 	virtual	void				_ReservedLayout9();
105 	virtual	void				_ReservedLayout10();
106 
107 	// forbidden methods
108 								BLayout(const BLayout&);
109 			void				operator =(const BLayout&);
110 
111 			friend class BView;
112 
113 			void				SetOwner(BView* owner);
114 			void				SetTarget(BView* target);
115 
116 			void				_LayoutWithinContext(bool force,
117 									BLayoutContext* context);
118 
119 			uint32				fState;
120 			bool				fAncestorsVisible;
121 			int32				fInvalidationDisabled;
122 			BLayoutContext*		fContext;
123 			BView*				fOwner;
124 			BView*				fTarget;
125 			BList				fItems;
126 			BList				fNestedLayouts;
127 
128 			uint32				_reserved[10];
129 };
130 
131 
132 #endif	//	_LAYOUT_H
133