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