1 /* 2 * Copyright 2006-2010, 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 <AbstractLayout.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 BAbstractLayout { 25 public: 26 BSplitLayout(orientation orientation, 27 float spacing = 0.0f); 28 BSplitLayout(BMessage* from); 29 virtual ~BSplitLayout(); 30 31 void SetInsets(float left, float top, float right, 32 float bottom); 33 void GetInsets(float* left, float* top, float* right, 34 float* bottom) const; 35 36 float Spacing() const; 37 void SetSpacing(float spacing); 38 39 orientation Orientation() const; 40 void SetOrientation(orientation orientation); 41 42 float SplitterSize() const; 43 void SetSplitterSize(float size); 44 45 virtual BLayoutItem* AddView(BView* child); 46 virtual BLayoutItem* AddView(int32 index, BView* child); 47 virtual BLayoutItem* AddView(BView* child, float weight); 48 virtual BLayoutItem* AddView(int32 index, BView* child, 49 float weight); 50 51 virtual bool AddItem(BLayoutItem* item); 52 virtual bool AddItem(int32 index, BLayoutItem* item); 53 virtual bool AddItem(BLayoutItem* item, float weight); 54 virtual bool AddItem(int32 index, BLayoutItem* item, 55 float weight); 56 57 58 float ItemWeight(int32 index) const; 59 float ItemWeight(BLayoutItem* item) const; 60 void SetItemWeight(int32 index, float weight, 61 bool invalidateLayout); 62 void SetItemWeight(BLayoutItem* item, float weight); 63 64 bool IsCollapsible(int32 index) const; 65 void SetCollapsible(bool collapsible); 66 void SetCollapsible(int32 index, bool collapsible); 67 void SetCollapsible(int32 first, int32 last, 68 bool collapsible); 69 70 bool IsItemCollapsed(int32 index) const; 71 void SetItemCollapsed(int32 index, bool visible); 72 73 virtual BSize BaseMinSize(); 74 virtual BSize BaseMaxSize(); 75 virtual BSize BasePreferredSize(); 76 virtual BAlignment BaseAlignment(); 77 78 virtual bool HasHeightForWidth(); 79 virtual void GetHeightForWidth(float width, float* min, 80 float* max, float* preferred); 81 82 virtual void LayoutInvalidated(bool children); 83 virtual void DoLayout(); 84 85 // interface for BSplitView 86 BRect SplitterItemFrame(int32 index) const; 87 bool IsAboveSplitter(const BPoint& point) const; 88 89 bool StartDraggingSplitter(BPoint point); 90 bool DragSplitter(BPoint point); 91 bool StopDraggingSplitter(); 92 int32 DraggedSplitter() const; 93 94 // archiving methods 95 virtual status_t Archive(BMessage* into, bool deep = true) const; 96 static BArchivable* Instantiate(BMessage* from); 97 98 virtual status_t ItemArchived(BMessage* into, BLayoutItem* item, 99 int32 index) const; 100 virtual status_t ItemUnarchived(const BMessage* from, 101 BLayoutItem* item, int32 index); 102 103 protected: 104 virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); 105 virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); 106 107 private: 108 class ItemLayoutInfo; 109 class ValueRange; 110 class SplitterItem; 111 112 void _InvalidateLayout(bool invalidateView, 113 bool children = false); 114 void _InvalidateCachedHeightForWidth(); 115 116 SplitterItem* _SplitterItemAt(const BPoint& point, 117 int32* index = NULL) const; 118 SplitterItem* _SplitterItemAt(int32 index) const; 119 120 void _GetSplitterValueRange(int32 index, 121 ValueRange& range); 122 int32 _SplitterValue(int32 index) const; 123 124 void _LayoutItem(BLayoutItem* item, BRect frame, 125 bool visible); 126 void _LayoutItem(BLayoutItem* item, 127 ItemLayoutInfo* info); 128 129 bool _SetSplitterValue(int32 index, int32 value); 130 131 ItemLayoutInfo* _ItemLayoutInfo(BLayoutItem* item) const; 132 133 134 void _UpdateSplitterWeights(); 135 136 void _ValidateMinMax(); 137 138 void _InternalGetHeightForWidth(float width, 139 bool realLayout, float* minHeight, 140 float* maxHeight, float* preferredHeight); 141 142 float _SplitterSpace() const; 143 144 BSize _AddInsets(BSize size); 145 void _AddInsets(float* minHeight, float* maxHeight, 146 float* preferredHeight); 147 BSize _SubtractInsets(BSize size); 148 149 private: 150 orientation fOrientation; 151 float fLeftInset; 152 float fRightInset; 153 float fTopInset; 154 float fBottomInset; 155 float fSplitterSize; 156 float fSpacing; 157 158 BList fSplitterItems; 159 BList fVisibleItems; 160 161 BSize fMin; 162 BSize fMax; 163 BSize fPreferred; 164 165 Layouter* fHorizontalLayouter; 166 Layouter* fVerticalLayouter; 167 168 LayoutInfo* fHorizontalLayoutInfo; 169 LayoutInfo* fVerticalLayoutInfo; 170 171 BList fHeightForWidthItems; 172 // Incorporates the children's height for width constraints for a 173 // concrete width. Cloned lazily from fVerticalLayout when needed. 174 Layouter* fHeightForWidthVerticalLayouter; 175 LayoutInfo* fHeightForWidthHorizontalLayoutInfo; 176 // for computing height for width info 177 178 bool fLayoutValid; 179 180 float fCachedHeightForWidthWidth; 181 float fHeightForWidthVerticalLayouterWidth; 182 float fCachedMinHeightForWidth; 183 float fCachedMaxHeightForWidth; 184 float fCachedPreferredHeightForWidth; 185 186 BPoint fDraggingStartPoint; 187 int32 fDraggingStartValue; 188 int32 fDraggingCurrentValue; 189 int32 fDraggingSplitterIndex; 190 }; 191 192 #endif // _SPLIT_LAYOUT_H 193