1 /* 2 * Copyright 2006, Haiku Inc. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _SPLIT_LAYOUT_H 6 #define _SPLIT_LAYOUT_H 7 8 9 #include <Layout.h> 10 #include <Point.h> 11 12 13 namespace BPrivate { 14 namespace Layout { 15 class Layouter; 16 class LayoutInfo; 17 } 18 } 19 20 using BPrivate::Layout::Layouter; 21 using BPrivate::Layout::LayoutInfo; 22 23 24 class BSplitLayout : public BLayout { 25 public: 26 BSplitLayout(enum orientation orientation, 27 float spacing = 0.0f); 28 virtual ~BSplitLayout(); 29 30 void SetInsets(float left, float top, float right, 31 float bottom); 32 void GetInsets(float* left, float* top, float* right, 33 float* bottom); 34 35 float Spacing() const; 36 void SetSpacing(float spacing); 37 38 orientation Orientation() const; 39 void SetOrientation(enum orientation orientation); 40 41 float SplitterSize() const; 42 void SetSplitterSize(float size); 43 44 virtual BLayoutItem* AddView(BView* child); 45 virtual BLayoutItem* AddView(int32 index, BView* child); 46 virtual BLayoutItem* AddView(BView* child, float weight); 47 virtual BLayoutItem* AddView(int32 index, BView* child, 48 float weight); 49 50 virtual bool AddItem(BLayoutItem* item); 51 virtual bool AddItem(int32 index, BLayoutItem* item); 52 virtual bool AddItem(BLayoutItem* item, float weight); 53 virtual bool AddItem(int32 index, BLayoutItem* item, 54 float weight); 55 56 57 float ItemWeight(int32 index) const; 58 float ItemWeight(BLayoutItem* item) const; 59 void SetItemWeight(int32 index, float weight, 60 bool invalidateLayout); 61 void SetItemWeight(BLayoutItem* item, float weight); 62 63 void SetCollapsible(bool collapsible); 64 void SetCollapsible(int32 index, bool collapsible); 65 void SetCollapsible(int32 first, int32 last, 66 bool collapsible); 67 68 virtual BSize MinSize(); 69 virtual BSize MaxSize(); 70 virtual BSize PreferredSize(); 71 virtual BAlignment Alignment(); 72 73 virtual bool HasHeightForWidth(); 74 virtual void GetHeightForWidth(float width, float* min, 75 float* max, float* preferred); 76 77 virtual void InvalidateLayout(); 78 79 virtual void LayoutView(); 80 81 // interface for BSplitView 82 BRect SplitterItemFrame(int32 index) const; 83 84 bool StartDraggingSplitter(BPoint point); 85 bool DragSplitter(BPoint point); 86 bool StopDraggingSplitter(); 87 int32 DraggedSplitter() const; 88 89 protected: 90 virtual void ItemAdded(BLayoutItem* item); 91 virtual void ItemRemoved(BLayoutItem* item); 92 93 private: 94 class ItemLayoutInfo; 95 class ValueRange; 96 class SplitterItem; 97 98 void _InvalidateLayout(bool invalidateView); 99 void _InvalidateCachedHeightForWidth(); 100 101 SplitterItem* _SplitterItemAt(int32 index) const; 102 103 void _GetSplitterValueRange(int32 index, 104 ValueRange& range); 105 int32 _SplitterValue(int32 index) const; 106 107 void _LayoutItem(BLayoutItem* item, BRect frame, 108 bool visible); 109 void _LayoutItem(BLayoutItem* item, 110 ItemLayoutInfo* info); 111 112 bool _SetSplitterValue(int32 index, int32 value); 113 114 ItemLayoutInfo* _ItemLayoutInfo(BLayoutItem* item) const; 115 116 117 void _UpdateSplitterWeights(); 118 119 void _ValidateMinMax(); 120 121 void _InternalGetHeightForWidth(float width, 122 bool realLayout, float* minHeight, 123 float* maxHeight, float* preferredHeight); 124 125 float _SplitterSpace() const; 126 127 BSize _AddInsets(BSize size); 128 void _AddInsets(float* minHeight, float* maxHeight, 129 float* preferredHeight); 130 BSize _SubtractInsets(BSize size); 131 132 private: 133 orientation fOrientation; 134 float fLeftInset; 135 float fRightInset; 136 float fTopInset; 137 float fBottomInset; 138 float fSplitterSize; 139 float fSpacing; 140 141 BList fSplitterItems; 142 BList fVisibleItems; 143 144 BSize fMin; 145 BSize fMax; 146 BSize fPreferred; 147 148 Layouter* fHorizontalLayouter; 149 Layouter* fVerticalLayouter; 150 151 LayoutInfo* fHorizontalLayoutInfo; 152 LayoutInfo* fVerticalLayoutInfo; 153 154 BList fHeightForWidthItems; 155 // Incorporates the children's height for width constraints for a 156 // concrete width. Cloned lazily from fVerticalLayout when needed. 157 Layouter* fHeightForWidthVerticalLayouter; 158 LayoutInfo* fHeightForWidthHorizontalLayoutInfo; 159 // for computing height for width info 160 161 bool fLayoutValid; 162 163 float fCachedHeightForWidthWidth; 164 float fHeightForWidthVerticalLayouterWidth; 165 float fCachedMinHeightForWidth; 166 float fCachedMaxHeightForWidth; 167 float fCachedPreferredHeightForWidth; 168 169 BPoint fDraggingStartPoint; 170 int32 fDraggingStartValue; 171 int32 fDraggingCurrentValue; 172 int32 fDraggingSplitterIndex; 173 }; 174 175 #endif // _SPLIT_LAYOUT_H 176