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(); 48 49 // Layouting related methods 50 51 virtual void InvalidateLayout(bool children = false); 52 virtual 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(); 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 DerivedLayoutItems() = 0; 77 virtual void OwnerChanged(BView* was); 78 79 // BLayoutItem hook methods 80 virtual void AttachedToLayout(); 81 virtual void DetachedFromLayout(BLayout* layout); 82 virtual void AncestorVisibilityChanged(bool shown); 83 84 // To be called by sub-classes in SetVisible(). 85 void VisibilityChanged(bool show); 86 // To be called when layout data is known to be good 87 void ResetLayoutInvalidation(); 88 89 private: 90 friend class BView; 91 92 bool RemoveViewRecursive(BView* view); 93 bool InvalidateLayoutsForView(BView* view); 94 bool InvalidationLegal(); 95 void SetOwner(BView* owner); 96 void SetTarget(BView* target); 97 98 void _LayoutWithinContext(bool force, 99 BLayoutContext* context); 100 101 uint32 fState; 102 bool fAncestorsVisible; 103 int32 fInvalidationDisabled; 104 BLayoutContext* fContext; 105 BView* fOwner; 106 BView* fTarget; 107 BList fItems; 108 BList fNestedLayouts; 109 }; 110 111 112 #endif // _LAYOUT_H 113