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 void Relayout(bool immediate = false); 53 void RequireLayout(); 54 bool IsValid(); 55 void EnableLayoutInvalidation(); 56 void DisableLayoutInvalidation(); 57 58 void LayoutItems(bool force = false); 59 BRect LayoutArea(); 60 BLayoutContext* LayoutContext() const; 61 62 // Archiving methods 63 64 virtual status_t Archive(BMessage* into, bool deep = true) const; 65 virtual status_t AllUnarchived(const BMessage* from); 66 67 virtual status_t ItemArchived(BMessage* into, BLayoutItem* item, 68 int32 index) const; 69 virtual status_t ItemUnarchived(const BMessage* from, 70 BLayoutItem* item, int32 index); 71 72 protected: 73 // BLayout hook methods 74 virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); 75 virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); 76 virtual void LayoutInvalidated(bool children); 77 virtual void DoLayout() = 0; 78 virtual void OwnerChanged(BView* was); 79 80 // BLayoutItem hook methods 81 virtual void AttachedToLayout(); 82 virtual void DetachedFromLayout(BLayout* layout); 83 virtual void AncestorVisibilityChanged(bool shown); 84 85 // To be called by sub-classes in SetVisible(). 86 void VisibilityChanged(bool show); 87 // To be called when layout data is known to be good 88 void ResetLayoutInvalidation(); 89 90 private: 91 friend class BView; 92 93 void SetOwner(BView* owner); 94 void SetTarget(BView* target); 95 96 void _LayoutWithinContext(bool force, 97 BLayoutContext* context); 98 99 uint32 fState; 100 bool fAncestorsVisible; 101 int32 fInvalidationDisabled; 102 BLayoutContext* fContext; 103 BView* fOwner; 104 BView* fTarget; 105 BList fItems; 106 BList fNestedLayouts; 107 }; 108 109 110 #endif // _LAYOUT_H 111