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 <List.h> 12 #include <Size.h> 13 14 15 class BLayoutItem; 16 class BView; 17 18 19 class BLayout : public BArchivable { 20 public: 21 BLayout(); 22 BLayout(BMessage* archive); 23 virtual ~BLayout(); 24 25 BView* View() const; 26 27 virtual BLayoutItem* AddView(BView* child); 28 virtual BLayoutItem* AddView(int32 index, BView* child); 29 30 virtual bool AddItem(BLayoutItem* item); 31 virtual bool AddItem(int32 index, BLayoutItem* item); 32 33 virtual bool RemoveView(BView* child); 34 virtual bool RemoveItem(BLayoutItem* item); 35 virtual BLayoutItem* RemoveItem(int32 index); 36 37 BLayoutItem* ItemAt(int32 index) const; 38 int32 CountItems() const; 39 int32 IndexOfItem(const BLayoutItem* item) const; 40 int32 IndexOfView(BView* child) const; 41 42 virtual BSize MinSize() = 0; 43 virtual BSize MaxSize() = 0; 44 virtual BSize PreferredSize() = 0; 45 virtual BAlignment Alignment() = 0; 46 47 virtual bool HasHeightForWidth() = 0; 48 virtual void GetHeightForWidth(float width, float* min, 49 float* max, float* preferred) = 0; 50 51 virtual void InvalidateLayout(); 52 53 virtual void LayoutView() = 0; 54 55 virtual status_t Archive(BMessage* into, bool deep = true) const; 56 virtual status_t AllUnarchived(const BMessage* from); 57 58 virtual status_t ItemArchived(BMessage* into, BLayoutItem* item, 59 int32 index) const; 60 virtual status_t ItemUnarchived(const BMessage* from, 61 BLayoutItem* item, int32 index); 62 protected: 63 virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); 64 virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); 65 66 private: 67 friend class BView; 68 69 void SetView(BView* view); 70 71 BView* fView; 72 BList fItems; 73 }; 74 75 76 #endif // _LAYOUT_H 77