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