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(enum 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(enum 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 InvalidateLayout(bool children = false); 83 84 virtual void DerivedLayoutItems(); 85 86 // interface for BSplitView 87 BRect SplitterItemFrame(int32 index) const; 88 bool IsAboveSplitter(const BPoint& point) const; 89 90 bool StartDraggingSplitter(BPoint point); 91 bool DragSplitter(BPoint point); 92 bool StopDraggingSplitter(); 93 int32 DraggedSplitter() const; 94 95 // archiving methods 96 virtual status_t Archive(BMessage* into, bool deep = true) const; 97 static BArchivable* Instantiate(BMessage* from); 98 99 virtual status_t ItemArchived(BMessage* into, BLayoutItem* item, 100 int32 index) const; 101 virtual status_t ItemUnarchived(const BMessage* from, 102 BLayoutItem* item, int32 index); 103 104 protected: 105 virtual bool ItemAdded(BLayoutItem* item, int32 atIndex); 106 virtual void ItemRemoved(BLayoutItem* item, int32 fromIndex); 107 108 private: 109 class ItemLayoutInfo; 110 class ValueRange; 111 class SplitterItem; 112 113 void _InvalidateLayout(bool invalidateView, 114 bool children = false); 115 void _InvalidateCachedHeightForWidth(); 116 117 SplitterItem* _SplitterItemAt(const BPoint& point, 118 int32* index = NULL) const; 119 SplitterItem* _SplitterItemAt(int32 index) const; 120 121 void _GetSplitterValueRange(int32 index, 122 ValueRange& range); 123 int32 _SplitterValue(int32 index) const; 124 125 void _LayoutItem(BLayoutItem* item, BRect frame, 126 bool visible); 127 void _LayoutItem(BLayoutItem* item, 128 ItemLayoutInfo* info); 129 130 bool _SetSplitterValue(int32 index, int32 value); 131 132 ItemLayoutInfo* _ItemLayoutInfo(BLayoutItem* item) const; 133 134 135 void _UpdateSplitterWeights(); 136 137 void _ValidateMinMax(); 138 139 void _InternalGetHeightForWidth(float width, 140 bool realLayout, float* minHeight, 141 float* maxHeight, float* preferredHeight); 142 143 float _SplitterSpace() const; 144 145 BSize _AddInsets(BSize size); 146 void _AddInsets(float* minHeight, float* maxHeight, 147 float* preferredHeight); 148 BSize _SubtractInsets(BSize size); 149 150 private: 151 orientation fOrientation; 152 float fLeftInset; 153 float fRightInset; 154 float fTopInset; 155 float fBottomInset; 156 float fSplitterSize; 157 float fSpacing; 158 159 BList fSplitterItems; 160 BList fVisibleItems; 161 162 BSize fMin; 163 BSize fMax; 164 BSize fPreferred; 165 166 Layouter* fHorizontalLayouter; 167 Layouter* fVerticalLayouter; 168 169 LayoutInfo* fHorizontalLayoutInfo; 170 LayoutInfo* fVerticalLayoutInfo; 171 172 BList fHeightForWidthItems; 173 // Incorporates the children's height for width constraints for a 174 // concrete width. Cloned lazily from fVerticalLayout when needed. 175 Layouter* fHeightForWidthVerticalLayouter; 176 LayoutInfo* fHeightForWidthHorizontalLayoutInfo; 177 // for computing height for width info 178 179 bool fLayoutValid; 180 181 float fCachedHeightForWidthWidth; 182 float fHeightForWidthVerticalLayouterWidth; 183 float fCachedMinHeightForWidth; 184 float fCachedMaxHeightForWidth; 185 float fCachedPreferredHeightForWidth; 186 187 BPoint fDraggingStartPoint; 188 int32 fDraggingStartValue; 189 int32 fDraggingCurrentValue; 190 int32 fDraggingSplitterIndex; 191 }; 192 193 #endif // _SPLIT_LAYOUT_H 194