xref: /haiku/headers/os/interface/Layout.h (revision 25a7b01d15612846f332751841da3579db313082)
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 
6327d84b48SAdrien Destugues 	virtual status_t			Archive(BMessage* into, bool deep = true) const;
64*d56e7bd6SAlex Wilson 
65*d56e7bd6SAlex Wilson 	virtual status_t			Perform(perform_code d, void* arg);
66*d56e7bd6SAlex Wilson 
67*d56e7bd6SAlex Wilson protected:
68*d56e7bd6SAlex Wilson 	// Archiving hook methods
6953617d36SAlex Wilson 	virtual	status_t			AllArchived(BMessage* archive) const;
7027d84b48SAdrien Destugues 	virtual	status_t			AllUnarchived(const BMessage* from);
7127d84b48SAdrien Destugues 
72b137ab3eSIngo Weinhold 	virtual status_t			ItemArchived(BMessage* into, BLayoutItem* item,
73b137ab3eSIngo Weinhold 									int32 index) const;
74b137ab3eSIngo Weinhold 	virtual	status_t			ItemUnarchived(const BMessage* from,
75b137ab3eSIngo Weinhold 									BLayoutItem* item, int32 index);
761d6c7b6cSAlex Wilson 	// BLayout hook methods
776829d417SAlex Wilson 	virtual	bool				ItemAdded(BLayoutItem* item, int32 atIndex);
786829d417SAlex Wilson 	virtual	void				ItemRemoved(BLayoutItem* item, int32 fromIndex);
79b38ea98fSAlex Wilson 	virtual	void				LayoutInvalidated(bool children);
804e0131f5SAlex Wilson 	virtual	void				DoLayout() = 0;
811d6c7b6cSAlex Wilson 	virtual	void				OwnerChanged(BView* was);
821d6c7b6cSAlex Wilson 
831d6c7b6cSAlex Wilson 	// BLayoutItem hook methods
841d6c7b6cSAlex Wilson 	virtual	void				AttachedToLayout();
851d6c7b6cSAlex Wilson 	virtual void				DetachedFromLayout(BLayout* layout);
861d6c7b6cSAlex Wilson 	virtual	void				AncestorVisibilityChanged(bool shown);
871d6c7b6cSAlex Wilson 
881d6c7b6cSAlex Wilson 	// To be called by sub-classes in SetVisible().
891d6c7b6cSAlex Wilson 			void				VisibilityChanged(bool show);
901d6c7b6cSAlex Wilson 	// To be called when layout data is known to be good
911d6c7b6cSAlex Wilson 			void				ResetLayoutInvalidation();
929ecf9d1cSIngo Weinhold 
939ecf9d1cSIngo Weinhold private:
948151838eSAlex Wilson 
958151838eSAlex Wilson 	// FBC padding
968151838eSAlex Wilson 	virtual	void				_ReservedLayout1();
978151838eSAlex Wilson 	virtual	void				_ReservedLayout2();
988151838eSAlex Wilson 	virtual	void				_ReservedLayout3();
998151838eSAlex Wilson 	virtual	void				_ReservedLayout4();
1008151838eSAlex Wilson 	virtual	void				_ReservedLayout5();
1018151838eSAlex Wilson 	virtual	void				_ReservedLayout6();
1028151838eSAlex Wilson 	virtual	void				_ReservedLayout7();
1038151838eSAlex Wilson 	virtual	void				_ReservedLayout8();
1048151838eSAlex Wilson 	virtual	void				_ReservedLayout9();
1058151838eSAlex Wilson 	virtual	void				_ReservedLayout10();
1068151838eSAlex Wilson 
107e044d51aSAlex Wilson 	// forbidden methods
108e044d51aSAlex Wilson 								BLayout(const BLayout&);
109e044d51aSAlex Wilson 			void				operator =(const BLayout&);
110e044d51aSAlex Wilson 
1119ecf9d1cSIngo Weinhold 			friend class BView;
1129ecf9d1cSIngo Weinhold 
1131d6c7b6cSAlex Wilson 			void				SetOwner(BView* owner);
1141d6c7b6cSAlex Wilson 			void				SetTarget(BView* target);
1159ecf9d1cSIngo Weinhold 
1161d6c7b6cSAlex Wilson 			void				_LayoutWithinContext(bool force,
1171d6c7b6cSAlex Wilson 									BLayoutContext* context);
1181d6c7b6cSAlex Wilson 
1191d6c7b6cSAlex Wilson 			uint32				fState;
1201d6c7b6cSAlex Wilson 			bool				fAncestorsVisible;
1211d6c7b6cSAlex Wilson 			int32				fInvalidationDisabled;
1221d6c7b6cSAlex Wilson 			BLayoutContext*		fContext;
1231d6c7b6cSAlex Wilson 			BView*				fOwner;
1241d6c7b6cSAlex Wilson 			BView*				fTarget;
1259ecf9d1cSIngo Weinhold 			BList				fItems;
1261d6c7b6cSAlex Wilson 			BList				fNestedLayouts;
1278151838eSAlex Wilson 
1288151838eSAlex Wilson 			uint32				_reserved[10];
1299ecf9d1cSIngo Weinhold };
1309ecf9d1cSIngo Weinhold 
131268317bdSAxel Dörfler 
1329ecf9d1cSIngo Weinhold #endif	//	_LAYOUT_H
133