1 /* 2 * Copyright 2006-2010, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _TWO_DIMENSIONAL_LAYOUT_H 6 #define _TWO_DIMENSIONAL_LAYOUT_H 7 8 9 #include <AbstractLayout.h> 10 11 class BLayoutContext; 12 13 14 class BTwoDimensionalLayout : public BAbstractLayout { 15 public: 16 BTwoDimensionalLayout(); 17 BTwoDimensionalLayout(BMessage* from); 18 virtual ~BTwoDimensionalLayout(); 19 20 void SetInsets(float left, float top, float right, 21 float bottom); 22 void SetInsets(float horizontal, float vertical); 23 void SetInsets(float insets); 24 void GetInsets(float* left, float* top, float* right, 25 float* bottom) const; 26 27 void AlignLayoutWith(BTwoDimensionalLayout* other, 28 enum orientation orientation); 29 30 virtual BSize BaseMinSize(); 31 virtual BSize BaseMaxSize(); 32 virtual BSize BasePreferredSize(); 33 virtual BAlignment BaseAlignment(); 34 35 virtual bool HasHeightForWidth(); 36 virtual void GetHeightForWidth(float width, float* min, 37 float* max, float* preferred); 38 39 virtual void SetFrame(BRect frame); 40 41 virtual void InvalidateLayout(bool children = false); 42 43 virtual status_t Archive(BMessage* into, bool deep = true) const; 44 virtual status_t AllArchived(BMessage* into) const; 45 virtual status_t AllUnarchived(const BMessage* from); 46 47 protected: 48 struct ColumnRowConstraints { 49 float weight; 50 float min; 51 float max; 52 }; 53 54 struct Dimensions { 55 int32 x; 56 int32 y; 57 int32 width; 58 int32 height; 59 }; 60 61 virtual void DerivedLayoutItems(); 62 63 BSize AddInsets(BSize size); 64 void AddInsets(float* minHeight, float* maxHeight, 65 float* preferredHeight); 66 BSize SubtractInsets(BSize size); 67 68 virtual void PrepareItems(enum orientation orientation); 69 virtual bool HasMultiColumnItems(); 70 virtual bool HasMultiRowItems(); 71 72 virtual int32 InternalCountColumns() = 0; 73 virtual int32 InternalCountRows() = 0; 74 virtual void GetColumnRowConstraints( 75 enum orientation orientation, 76 int32 index, 77 ColumnRowConstraints* constraints) = 0; 78 virtual void GetItemDimensions(BLayoutItem* item, 79 Dimensions* dimensions) = 0; 80 81 private: 82 class CompoundLayouter; 83 class LocalLayouter; 84 class VerticalCompoundLayouter; 85 86 friend class LocalLayouter; 87 88 void _ValidateMinMax(); 89 90 protected: 91 float fLeftInset; 92 float fRightInset; 93 float fTopInset; 94 float fBottomInset; 95 float fHSpacing; 96 float fVSpacing; 97 98 private: 99 LocalLayouter* fLocalLayouter; 100 }; 101 102 #endif // _TWO_DIMENSIONAL_LAYOUT_H 103