xref: /haiku/headers/os/interface/Layout.h (revision 53617d366d1729716cc1e2764feb4a734b65b9f0)
19ecf9d1cSIngo Weinhold /*
227d84b48SAdrien Destugues  * Copyright 2006-2010, Haiku, Inc. All rights reserved.
39ecf9d1cSIngo Weinhold  * Distributed under the terms of the MIT License.
49ecf9d1cSIngo Weinhold  */
59ecf9d1cSIngo Weinhold #ifndef	_LAYOUT_H
69ecf9d1cSIngo Weinhold #define	_LAYOUT_H
79ecf9d1cSIngo Weinhold 
8268317bdSAxel Dörfler 
99ecf9d1cSIngo Weinhold #include <Alignment.h>
1027d84b48SAdrien Destugues #include <Archivable.h>
111d6c7b6cSAlex Wilson #include <LayoutItem.h>
129ecf9d1cSIngo Weinhold #include <List.h>
139ecf9d1cSIngo Weinhold #include <Size.h>
149ecf9d1cSIngo Weinhold 
15268317bdSAxel Dörfler 
161d6c7b6cSAlex Wilson class BLayoutContext;
179ecf9d1cSIngo Weinhold class BLayoutItem;
189ecf9d1cSIngo Weinhold class BView;
199ecf9d1cSIngo Weinhold 
209ecf9d1cSIngo Weinhold 
211d6c7b6cSAlex Wilson class BLayout : public BLayoutItem {
229ecf9d1cSIngo Weinhold public:
239ecf9d1cSIngo Weinhold 								BLayout();
2427d84b48SAdrien Destugues 								BLayout(BMessage* archive);
259ecf9d1cSIngo Weinhold 	virtual						~BLayout();
269ecf9d1cSIngo Weinhold 
271d6c7b6cSAlex Wilson 			BView*				Owner() const;
281d6c7b6cSAlex Wilson 			BView*				TargetView() const;
291d6c7b6cSAlex Wilson 	virtual	BView*				View(); // from BLayoutItem
309ecf9d1cSIngo Weinhold 
311d6c7b6cSAlex Wilson 	// methods dealing with items
329ecf9d1cSIngo Weinhold 	virtual	BLayoutItem*		AddView(BView* child);
339ecf9d1cSIngo Weinhold 	virtual	BLayoutItem*		AddView(int32 index, BView* child);
349ecf9d1cSIngo Weinhold 
359ecf9d1cSIngo Weinhold 	virtual	bool				AddItem(BLayoutItem* item);
369ecf9d1cSIngo Weinhold 	virtual	bool				AddItem(int32 index, BLayoutItem* item);
379ecf9d1cSIngo Weinhold 
389ecf9d1cSIngo Weinhold 	virtual	bool				RemoveView(BView* child);
399ecf9d1cSIngo Weinhold 	virtual	bool				RemoveItem(BLayoutItem* item);
409ecf9d1cSIngo Weinhold 	virtual	BLayoutItem*		RemoveItem(int32 index);
419ecf9d1cSIngo Weinhold 
429ecf9d1cSIngo Weinhold 			BLayoutItem*		ItemAt(int32 index) const;
439ecf9d1cSIngo Weinhold 			int32				CountItems() const;
4427d84b48SAdrien Destugues 			int32				IndexOfItem(const BLayoutItem* item) const;
459ecf9d1cSIngo Weinhold 			int32				IndexOfView(BView* child) const;
469ecf9d1cSIngo Weinhold 
47df730987SIngo Weinhold 			bool				AncestorsVisible() const;
489ecf9d1cSIngo Weinhold 
491d6c7b6cSAlex Wilson 	// Layouting related methods
509ecf9d1cSIngo Weinhold 
51c74faed4SAlex Wilson 	virtual	void				InvalidateLayout(bool children = false);
520843fb45SAlex Wilson 	virtual	void				Relayout(bool immediate = false);
530843fb45SAlex Wilson 									// from BLayoutItem
541d6c7b6cSAlex Wilson 			void				RequireLayout();
551d6c7b6cSAlex Wilson 			bool				IsValid();
561d6c7b6cSAlex Wilson 			void				EnableLayoutInvalidation();
571d6c7b6cSAlex Wilson 			void				DisableLayoutInvalidation();
589ecf9d1cSIngo Weinhold 
591d6c7b6cSAlex Wilson 			void				LayoutItems(bool force = false);
601d6c7b6cSAlex Wilson 			BRect				LayoutArea();
61a9e89a73SIngo Weinhold 			BLayoutContext*		LayoutContext() const;
621d6c7b6cSAlex Wilson 
631d6c7b6cSAlex Wilson 	// Archiving methods
649ecf9d1cSIngo Weinhold 
6527d84b48SAdrien Destugues 	virtual status_t			Archive(BMessage* into, bool deep = true) const;
66*53617d36SAlex Wilson 	virtual	status_t			AllArchived(BMessage* archive) const;
6727d84b48SAdrien Destugues 	virtual	status_t			AllUnarchived(const BMessage* from);
6827d84b48SAdrien Destugues 
69b137ab3eSIngo Weinhold 	virtual status_t			ItemArchived(BMessage* into, BLayoutItem* item,
70b137ab3eSIngo Weinhold 									int32 index) const;
71b137ab3eSIngo Weinhold 	virtual	status_t			ItemUnarchived(const BMessage* from,
72b137ab3eSIngo Weinhold 									BLayoutItem* item, int32 index);
731d6c7b6cSAlex Wilson 
74121a15eaSAlex Wilson 	virtual status_t			Perform(perform_code d, void* arg);
75121a15eaSAlex Wilson 
769ecf9d1cSIngo Weinhold protected:
771d6c7b6cSAlex Wilson 	// BLayout hook methods
786829d417SAlex Wilson 	virtual	bool				ItemAdded(BLayoutItem* item, int32 atIndex);
796829d417SAlex Wilson 	virtual	void				ItemRemoved(BLayoutItem* item, int32 fromIndex);
80b38ea98fSAlex Wilson 	virtual	void				LayoutInvalidated(bool children);
814e0131f5SAlex Wilson 	virtual	void				DoLayout() = 0;
821d6c7b6cSAlex Wilson 	virtual	void				OwnerChanged(BView* was);
831d6c7b6cSAlex Wilson 
841d6c7b6cSAlex Wilson 	// BLayoutItem hook methods
851d6c7b6cSAlex Wilson 	virtual	void				AttachedToLayout();
861d6c7b6cSAlex Wilson 	virtual void				DetachedFromLayout(BLayout* layout);
871d6c7b6cSAlex Wilson 	virtual	void				AncestorVisibilityChanged(bool shown);
881d6c7b6cSAlex Wilson 
891d6c7b6cSAlex Wilson 	// To be called by sub-classes in SetVisible().
901d6c7b6cSAlex Wilson 			void				VisibilityChanged(bool show);
911d6c7b6cSAlex Wilson 	// To be called when layout data is known to be good
921d6c7b6cSAlex Wilson 			void				ResetLayoutInvalidation();
939ecf9d1cSIngo Weinhold 
949ecf9d1cSIngo Weinhold private:
958151838eSAlex Wilson 
968151838eSAlex Wilson 	// FBC padding
978151838eSAlex Wilson 	virtual	void				_ReservedLayout1();
988151838eSAlex Wilson 	virtual	void				_ReservedLayout2();
998151838eSAlex Wilson 	virtual	void				_ReservedLayout3();
1008151838eSAlex Wilson 	virtual	void				_ReservedLayout4();
1018151838eSAlex Wilson 	virtual	void				_ReservedLayout5();
1028151838eSAlex Wilson 	virtual	void				_ReservedLayout6();
1038151838eSAlex Wilson 	virtual	void				_ReservedLayout7();
1048151838eSAlex Wilson 	virtual	void				_ReservedLayout8();
1058151838eSAlex Wilson 	virtual	void				_ReservedLayout9();
1068151838eSAlex Wilson 	virtual	void				_ReservedLayout10();
1078151838eSAlex Wilson 
108e044d51aSAlex Wilson 	// forbidden methods
109e044d51aSAlex Wilson 								BLayout(const BLayout&);
110e044d51aSAlex Wilson 			void				operator =(const BLayout&);
111e044d51aSAlex Wilson 
1129ecf9d1cSIngo Weinhold 			friend class BView;
1139ecf9d1cSIngo Weinhold 
1141d6c7b6cSAlex Wilson 			void				SetOwner(BView* owner);
1151d6c7b6cSAlex Wilson 			void				SetTarget(BView* target);
1169ecf9d1cSIngo Weinhold 
1171d6c7b6cSAlex Wilson 			void				_LayoutWithinContext(bool force,
1181d6c7b6cSAlex Wilson 									BLayoutContext* context);
1191d6c7b6cSAlex Wilson 
1201d6c7b6cSAlex Wilson 			uint32				fState;
1211d6c7b6cSAlex Wilson 			bool				fAncestorsVisible;
1221d6c7b6cSAlex Wilson 			int32				fInvalidationDisabled;
1231d6c7b6cSAlex Wilson 			BLayoutContext*		fContext;
1241d6c7b6cSAlex Wilson 			BView*				fOwner;
1251d6c7b6cSAlex Wilson 			BView*				fTarget;
1269ecf9d1cSIngo Weinhold 			BList				fItems;
1271d6c7b6cSAlex Wilson 			BList				fNestedLayouts;
1288151838eSAlex Wilson 
1298151838eSAlex Wilson 			uint32				_reserved[10];
1309ecf9d1cSIngo Weinhold };
1319ecf9d1cSIngo Weinhold 
132268317bdSAxel Dörfler 
1339ecf9d1cSIngo Weinhold #endif	//	_LAYOUT_H
134