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