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; 6627d84b48SAdrien Destugues virtual status_t AllUnarchived(const BMessage* from); 6727d84b48SAdrien Destugues 68b137ab3eSIngo Weinhold virtual status_t ItemArchived(BMessage* into, BLayoutItem* item, 69b137ab3eSIngo Weinhold int32 index) const; 70b137ab3eSIngo Weinhold virtual status_t ItemUnarchived(const BMessage* from, 71b137ab3eSIngo Weinhold BLayoutItem* item, int32 index); 721d6c7b6cSAlex Wilson 739ecf9d1cSIngo Weinhold protected: 741d6c7b6cSAlex Wilson // BLayout hook methods 756829d417SAlex Wilson virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); 766829d417SAlex Wilson virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); 77b38ea98fSAlex Wilson virtual void LayoutInvalidated(bool children); 784e0131f5SAlex Wilson virtual void DoLayout() = 0; 791d6c7b6cSAlex Wilson virtual void OwnerChanged(BView* was); 801d6c7b6cSAlex Wilson 811d6c7b6cSAlex Wilson // BLayoutItem hook methods 821d6c7b6cSAlex Wilson virtual void AttachedToLayout(); 831d6c7b6cSAlex Wilson virtual void DetachedFromLayout(BLayout* layout); 841d6c7b6cSAlex Wilson virtual void AncestorVisibilityChanged(bool shown); 851d6c7b6cSAlex Wilson 861d6c7b6cSAlex Wilson // To be called by sub-classes in SetVisible(). 871d6c7b6cSAlex Wilson void VisibilityChanged(bool show); 881d6c7b6cSAlex Wilson // To be called when layout data is known to be good 891d6c7b6cSAlex Wilson void ResetLayoutInvalidation(); 909ecf9d1cSIngo Weinhold 91a851b3adSAlex Wilson virtual status_t Perform(perform_code d, void* arg); 92a851b3adSAlex Wilson 939ecf9d1cSIngo Weinhold private: 94*8151838eSAlex Wilson 95*8151838eSAlex Wilson // FBC padding 96*8151838eSAlex Wilson virtual void _ReservedLayout1(); 97*8151838eSAlex Wilson virtual void _ReservedLayout2(); 98*8151838eSAlex Wilson virtual void _ReservedLayout3(); 99*8151838eSAlex Wilson virtual void _ReservedLayout4(); 100*8151838eSAlex Wilson virtual void _ReservedLayout5(); 101*8151838eSAlex Wilson virtual void _ReservedLayout6(); 102*8151838eSAlex Wilson virtual void _ReservedLayout7(); 103*8151838eSAlex Wilson virtual void _ReservedLayout8(); 104*8151838eSAlex Wilson virtual void _ReservedLayout9(); 105*8151838eSAlex Wilson virtual void _ReservedLayout10(); 106*8151838eSAlex Wilson 1079ecf9d1cSIngo Weinhold friend class BView; 1089ecf9d1cSIngo Weinhold 1091d6c7b6cSAlex Wilson void SetOwner(BView* owner); 1101d6c7b6cSAlex Wilson void SetTarget(BView* target); 1119ecf9d1cSIngo Weinhold 1121d6c7b6cSAlex Wilson void _LayoutWithinContext(bool force, 1131d6c7b6cSAlex Wilson BLayoutContext* context); 1141d6c7b6cSAlex Wilson 1151d6c7b6cSAlex Wilson uint32 fState; 1161d6c7b6cSAlex Wilson bool fAncestorsVisible; 1171d6c7b6cSAlex Wilson int32 fInvalidationDisabled; 1181d6c7b6cSAlex Wilson BLayoutContext* fContext; 1191d6c7b6cSAlex Wilson BView* fOwner; 1201d6c7b6cSAlex Wilson BView* fTarget; 1219ecf9d1cSIngo Weinhold BList fItems; 1221d6c7b6cSAlex Wilson BList fNestedLayouts; 123*8151838eSAlex Wilson 124*8151838eSAlex Wilson uint32 _reserved[10]; 1259ecf9d1cSIngo Weinhold }; 1269ecf9d1cSIngo Weinhold 127268317bdSAxel Dörfler 1289ecf9d1cSIngo Weinhold #endif // _LAYOUT_H 129