xref: /haiku/src/kits/tracker/ViewState.h (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
28 
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
33 */
34 
35 #ifndef _VIEW_STATE_H
36 #define _VIEW_STATE_H
37 
38 #include <DataIO.h>
39 #include <String.h>
40 
41 namespace BPrivate {
42 
43 const int32 kColumnStateArchiveVersion = 21;
44 	// bump version when layout or size changes
45 
46 class BColumn {
47 public:
48 	BColumn(const char *title, float offset, float width,
49 		alignment, const char *attributeName, uint32 attr_type,
50 		bool stat_field, bool editable);
51 	~BColumn();
52 
53 	BColumn(BMallocIO *stream, bool endianSwap = false);
54 	BColumn(const BMessage &, int32 index = 0);
55 	static BColumn *InstantiateFromStream(BMallocIO *stream, bool endianSwap = false);
56 	static BColumn *InstantiateFromMessage(const BMessage &, int32 index = 0);
57 	void ArchiveToStream(BMallocIO *stream) const;
58 	void ArchiveToMessage(BMessage &) const;
59 
60 	const char *Title() const;
61 	float Offset() const;
62 	float Width() const;
63 	alignment Alignment() const;
64 	const char *AttrName() const;
65 	uint32 AttrType() const;
66 	uint32 AttrHash() const;
67 	bool StatField() const;
68 	bool Editable() const;
69 
70 	void SetOffset(float);
71 	void SetWidth(float);
72 
73 private:
74 	BString fTitle;
75 	float fOffset;
76 	float fWidth;
77 	alignment fAlignment;
78 	BString fAttrName;
79 	uint32 fAttrHash;
80 	uint32 fAttrType;
81 	bool fStatField;
82 	bool fEditable;
83 };
84 
85 
86 const int32 kViewStateArchiveVersion = 10;
87 	// bump version when layout or size changes
88 
89 class BViewState {
90 	public:
91 	BViewState();
92 
93 	BViewState(BMallocIO *stream, bool endianSwap = false);
94 	BViewState(const BMessage &message);
95 	static BViewState *InstantiateFromStream(BMallocIO *stream, bool endianSwap = false);
96 	static BViewState *InstantiateFromMessage(const BMessage &message);
97 	void ArchiveToStream(BMallocIO *stream) const;
98 	void ArchiveToMessage(BMessage &message) const;
99 
100 	uint32 ViewMode() const;
101 	uint32 LastIconMode() const;
102 	BPoint ListOrigin() const;
103 	BPoint IconOrigin() const;
104 	uint32 PrimarySort() const;
105 	uint32 SecondarySort() const;
106 	uint32 PrimarySortType() const;
107 	uint32 SecondarySortType() const;
108 	bool ReverseSort() const;
109 
110 	void SetViewMode(uint32);
111 	void SetLastIconMode(uint32);
112 	void SetListOrigin(BPoint);
113 	void SetIconOrigin(BPoint);
114 	void SetPrimarySort(uint32);
115 	void SetSecondarySort(uint32);
116 	void SetPrimarySortType(uint32);
117 	void SetSecondarySortType(uint32);
118 	void SetReverseSort(bool);
119 
120 	bool StateNeedsSaving();
121 	void MarkSaved();
122 
123 private:
124 	uint32 fViewMode;
125 	uint32 fLastIconMode;
126 	BPoint fListOrigin;
127 	BPoint fIconOrigin;
128 	uint32 fPrimarySortAttr;
129 	uint32 fSecondarySortAttr;
130 	uint32 fPrimarySortType;
131 	uint32 fSecondarySortType;
132 	bool fReverseSort;
133 	bool fStateNeedsSaving;
134 };
135 
136 inline const char *
137 BColumn::Title() const
138 {
139 	return fTitle.String();
140 }
141 
142 inline float
143 BColumn::Offset() const
144 {
145 	return fOffset;
146 }
147 
148 inline float
149 BColumn::Width() const
150 {
151 	return fWidth;
152 }
153 
154 inline alignment
155 BColumn::Alignment() const
156 {
157 	return fAlignment;
158 }
159 
160 inline const char *
161 BColumn::AttrName() const
162 {
163 	return fAttrName.String();
164 }
165 
166 inline uint32
167 BColumn::AttrHash() const
168 {
169 	return fAttrHash;
170 }
171 
172 inline uint32
173 BColumn::AttrType() const
174 {
175 	return fAttrType;
176 }
177 
178 inline bool
179 BColumn::StatField() const
180 {
181 	return fStatField;
182 }
183 
184 inline bool
185 BColumn::Editable() const
186 {
187 	return fEditable;
188 }
189 
190 inline void
191 BColumn::SetWidth(float w)
192 {
193 	fWidth = w;
194 }
195 
196 inline void
197 BColumn::SetOffset(float o)
198 {
199 	fOffset = o;
200 }
201 
202 inline uint32
203 BViewState::ViewMode() const
204 {
205 	return fViewMode;
206 }
207 
208 inline uint32
209 BViewState::LastIconMode() const
210 {
211 	return fLastIconMode;
212 }
213 
214 inline BPoint
215 BViewState::ListOrigin() const
216 {
217 	return fListOrigin;
218 }
219 
220 inline BPoint
221 BViewState::IconOrigin() const
222 {
223 	return fIconOrigin;
224 }
225 
226 inline uint32
227 BViewState::PrimarySort() const
228 {
229 	return fPrimarySortAttr;
230 }
231 
232 inline uint32
233 BViewState::SecondarySort() const
234 {
235 	return fSecondarySortAttr;
236 }
237 
238 inline uint32
239 BViewState::PrimarySortType() const
240 {
241 	return fPrimarySortType;
242 }
243 
244 inline uint32
245 BViewState::SecondarySortType() const
246 {
247 	return fSecondarySortType;
248 }
249 
250 inline bool
251 BViewState::ReverseSort() const
252 {
253 	return fReverseSort;
254 }
255 
256 inline void
257 BViewState::SetViewMode(uint32 mode)
258 {
259 	if (mode != fViewMode)
260 		fStateNeedsSaving = true;
261 
262 	fViewMode = mode;
263 }
264 
265 inline void
266 BViewState::SetLastIconMode(uint32 mode)
267 {
268 	if (mode != fLastIconMode)
269 		fStateNeedsSaving = true;
270 
271 	fLastIconMode = mode;
272 }
273 
274 inline void
275 BViewState::SetListOrigin(BPoint newOrigin)
276 {
277 	if (newOrigin != fListOrigin)
278 		fStateNeedsSaving = true;
279 
280 	fListOrigin = newOrigin;
281 }
282 
283 inline void
284 BViewState::SetIconOrigin(BPoint newOrigin)
285 {
286 	if (newOrigin != fIconOrigin)
287 		fStateNeedsSaving = true;
288 
289 	fIconOrigin = newOrigin;
290 }
291 
292 inline void
293 BViewState::SetPrimarySort(uint32 attr)
294 {
295 	if (attr != fPrimarySortAttr)
296 		fStateNeedsSaving = true;
297 
298 	fPrimarySortAttr = attr;
299 }
300 
301 inline void
302 BViewState::SetSecondarySort(uint32 attr)
303 {
304 	if (attr != fSecondarySortAttr)
305 		fStateNeedsSaving = true;
306 
307 	fSecondarySortAttr = attr;
308 }
309 
310 inline void
311 BViewState::SetPrimarySortType(uint32 type)
312 {
313 	if (type != fPrimarySortType)
314 		fStateNeedsSaving = true;
315 
316 	fPrimarySortType = type;
317 }
318 
319 inline void
320 BViewState::SetSecondarySortType(uint32 type)
321 {
322 	if (type != fSecondarySortType)
323 		fStateNeedsSaving = true;
324 
325 	fSecondarySortType = type;
326 }
327 
328 inline void
329 BViewState::SetReverseSort(bool on)
330 {
331 	if (fReverseSort != on)
332 		fStateNeedsSaving = true;
333 
334 	fReverseSort = on;
335 }
336 
337 inline bool
338 BViewState::StateNeedsSaving()
339 {
340 	return fStateNeedsSaving;
341 }
342 
343 inline void
344 BViewState::MarkSaved()
345 {
346 	fStateNeedsSaving = false;
347 }
348 
349 
350 } // namespace BPrivate
351 
352 using namespace BPrivate;
353 
354 #endif
355