xref: /haiku/src/kits/tracker/ViewState.h (revision 5e96d7d537fbec23bad4ae9b4c8e7b02e769f0c6)
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 #ifndef _VIEW_STATE_H
35 #define _VIEW_STATE_H
36 
37 
38 #include <DataIO.h>
39 #include <String.h>
40 
41 
42 namespace BPrivate {
43 
44 const int32 kColumnStateArchiveVersion = 22;
45 	// bump version when layout or size changes
46 
47 class BColumn {
48 	public:
49 		BColumn(const char* title, float offset, float width,
50 			alignment align, const char* attributeName, uint32 attrType,
51 			const char* displayAs, bool statField, bool editable);
52 		BColumn(const char* title, float offset, float width,
53 			alignment align, const char* attributeName, uint32 attrType,
54 			bool statField, bool editable);
55 		~BColumn();
56 
57 		BColumn(BMallocIO* stream, int32 version, bool endianSwap = false);
58 		BColumn(const BMessage &, int32 index = 0);
59 		static BColumn* InstantiateFromStream(BMallocIO* stream,
60 			bool endianSwap = false);
61 		static BColumn* InstantiateFromMessage(const BMessage &archive,
62 			int32 index = 0);
63 		void ArchiveToStream(BMallocIO* stream) const;
64 		void ArchiveToMessage(BMessage &) const;
65 
66 		const char* Title() const;
67 		float 		Offset() const;
68 		float 		Width() const;
69 		alignment 	Alignment() const;
70 		const char* AttrName() const;
71 		uint32 		AttrType() const;
72 		const char* DisplayAs() const;
73 		uint32 		AttrHash() const;
74 		bool 		StatField() const;
75 		bool 		Editable() const;
76 
77 		void 		SetOffset(float);
78 		void 		SetWidth(float);
79 
80 	private:
81 		void _Init(const char* title, float offset, float width,
82 			alignment align, const char* attributeName, uint32 attrType,
83 			const char* displayAs, bool statField, bool editable);
84 		static BColumn* _Sanitize(BColumn* column);
85 
86 		BString 	fTitle;
87 		float 		fOffset;
88 		float 		fWidth;
89 		alignment 	fAlignment;
90 		BString 	fAttrName;
91 		BString 	fDisplayAs;
92 		uint32 		fAttrHash;
93 		uint32 		fAttrType;
94 		bool 		fStatField;
95 		bool 		fEditable;
96 };
97 
98 
99 const int32 kViewStateArchiveVersion = 11;
100 	// bump version when layout or size changes
101 
102 class BViewState {
103 	public:
104 		BViewState();
105 
106 		BViewState(BMallocIO* stream, bool endianSwap = false);
107 		BViewState(const BMessage &message);
108 		static BViewState* InstantiateFromStream(BMallocIO* stream,
109 			bool endianSwap = false);
110 		static BViewState* InstantiateFromMessage(const BMessage &message);
111 		void ArchiveToStream(BMallocIO* stream) const;
112 		void ArchiveToMessage(BMessage &message) const;
113 
114 		uint32 ViewMode() const;
115 		uint32 LastIconMode() const;
116 		uint32 IconSize() const;
117 		uint32 LastIconSize() const;
118 		BPoint ListOrigin() const;
119 		BPoint IconOrigin() const;
120 		uint32 PrimarySort() const;
121 		uint32 SecondarySort() const;
122 		uint32 PrimarySortType() const;
123 		uint32 SecondarySortType() const;
124 		bool ReverseSort() const;
125 
126 		void SetViewMode(uint32);
127 		void SetLastIconMode(uint32);
128 		void SetIconSize(uint32);
129 		void SetLastIconSize(uint32);
130 		void SetListOrigin(BPoint);
131 		void SetIconOrigin(BPoint);
132 		void SetPrimarySort(uint32);
133 		void SetSecondarySort(uint32);
134 		void SetPrimarySortType(uint32);
135 		void SetSecondarySortType(uint32);
136 		void SetReverseSort(bool);
137 
138 		bool StateNeedsSaving();
139 
140 	private:
141 		static BViewState* _Sanitize(BViewState* state, bool fixOnly = false);
142 
143 		uint32	fViewMode;
144 		uint32	fLastIconMode;
145 		uint32	fIconSize;
146 		uint32	fLastIconSize;
147 		BPoint	fListOrigin;
148 		BPoint	fIconOrigin;
149 		uint32	fPrimarySortAttr;
150 		uint32	fSecondarySortAttr;
151 		uint32	fPrimarySortType;
152 		uint32	fSecondarySortType;
153 		bool	fReverseSort;
154 
155 		void _Init();
156 		void _StorePreviousState();
157 
158 		uint32	fPreviousViewMode;
159 		uint32	fPreviousLastIconMode;
160 		uint32	fPreviousIconSize;
161 		uint32	fPreviousLastIconSize;
162 		BPoint	fPreviousListOrigin;
163 		BPoint	fPreviousIconOrigin;
164 		uint32	fPreviousPrimarySortAttr;
165 		uint32	fPreviousSecondarySortAttr;
166 		uint32	fPreviousPrimarySortType;
167 		uint32	fPreviousSecondarySortType;
168 		bool	fPreviousReverseSort;
169 };
170 
171 
172 inline const char*
173 BColumn::Title() const
174 {
175 	return fTitle.String();
176 }
177 
178 
179 inline float
180 BColumn::Offset() const
181 {
182 	return fOffset;
183 }
184 
185 
186 inline float
187 BColumn::Width() const
188 {
189 	return fWidth;
190 }
191 
192 
193 inline alignment
194 BColumn::Alignment() const
195 {
196 	return fAlignment;
197 }
198 
199 
200 inline const char*
201 BColumn::AttrName() const
202 {
203 	return fAttrName.String();
204 }
205 
206 
207 inline uint32
208 BColumn::AttrHash() const
209 {
210 	return fAttrHash;
211 }
212 
213 
214 inline uint32
215 BColumn::AttrType() const
216 {
217 	return fAttrType;
218 }
219 
220 
221 inline const char*
222 BColumn::DisplayAs() const
223 {
224 	return fDisplayAs.String();
225 }
226 
227 
228 inline bool
229 BColumn::StatField() const
230 {
231 	return fStatField;
232 }
233 
234 
235 inline bool
236 BColumn::Editable() const
237 {
238 	return fEditable;
239 }
240 
241 
242 inline void
243 BColumn::SetWidth(float w)
244 {
245 	fWidth = w;
246 }
247 
248 
249 inline void
250 BColumn::SetOffset(float o)
251 {
252 	fOffset = o;
253 }
254 
255 
256 inline uint32
257 BViewState::ViewMode() const
258 {
259 	return fViewMode;
260 }
261 
262 
263 inline uint32
264 BViewState::LastIconMode() const
265 {
266 	return fLastIconMode;
267 }
268 
269 
270 inline uint32
271 BViewState::IconSize() const
272 {
273 	return fIconSize;
274 }
275 
276 
277 inline uint32
278 BViewState::LastIconSize() const
279 {
280 	return fLastIconSize;
281 }
282 
283 
284 inline BPoint
285 BViewState::ListOrigin() const
286 {
287 	return fListOrigin;
288 }
289 
290 
291 inline BPoint
292 BViewState::IconOrigin() const
293 {
294 	return fIconOrigin;
295 }
296 
297 
298 inline uint32
299 BViewState::PrimarySort() const
300 {
301 	return fPrimarySortAttr;
302 }
303 
304 
305 inline uint32
306 BViewState::SecondarySort() const
307 {
308 	return fSecondarySortAttr;
309 }
310 
311 
312 inline uint32
313 BViewState::PrimarySortType() const
314 {
315 	return fPrimarySortType;
316 }
317 
318 inline uint32
319 BViewState::SecondarySortType() const
320 {
321 	return fSecondarySortType;
322 }
323 
324 inline bool
325 BViewState::ReverseSort() const
326 {
327 	return fReverseSort;
328 }
329 
330 
331 inline void
332 BViewState::SetViewMode(uint32 mode)
333 {
334 	fViewMode = mode;
335 }
336 
337 
338 inline void
339 BViewState::SetLastIconMode(uint32 mode)
340 {
341 	fLastIconMode = mode;
342 }
343 
344 
345 inline void
346 BViewState::SetIconSize(uint32 size)
347 {
348 	fIconSize = size;
349 }
350 
351 
352 inline void
353 BViewState::SetLastIconSize(uint32 size)
354 {
355 	fLastIconSize = size;
356 }
357 
358 
359 inline void
360 BViewState::SetListOrigin(BPoint newOrigin)
361 {
362 	fListOrigin = newOrigin;
363 }
364 
365 inline void
366 BViewState::SetIconOrigin(BPoint newOrigin)
367 {
368 	fIconOrigin = newOrigin;
369 }
370 
371 inline void
372 BViewState::SetPrimarySort(uint32 attr)
373 {
374 	fPrimarySortAttr = attr;
375 }
376 
377 
378 inline void
379 BViewState::SetSecondarySort(uint32 attr)
380 {
381 	fSecondarySortAttr = attr;
382 }
383 
384 
385 inline void
386 BViewState::SetPrimarySortType(uint32 type)
387 {
388 	fPrimarySortType = type;
389 }
390 
391 
392 inline void
393 BViewState::SetSecondarySortType(uint32 type)
394 {
395 	fSecondarySortType = type;
396 }
397 
398 
399 inline void
400 BViewState::SetReverseSort(bool on)
401 {
402 	fReverseSort = on;
403 }
404 
405 
406 inline bool
407 BViewState::StateNeedsSaving()
408 {
409 	return (fPreviousViewMode != fViewMode)
410 		|| (fPreviousLastIconMode != fLastIconMode)
411 		|| (fPreviousIconSize != fIconSize)
412 		|| (fPreviousLastIconSize != fLastIconSize)
413 		|| (fPreviousListOrigin != fListOrigin)
414 		|| (fPreviousIconOrigin != fIconOrigin)
415 		|| (fPreviousPrimarySortAttr != fPrimarySortAttr)
416 		|| (fPreviousSecondarySortAttr != fSecondarySortAttr)
417 		|| (fPreviousPrimarySortType != fPrimarySortType)
418 		|| (fPreviousSecondarySortType != fSecondarySortType)
419 		|| (fPreviousReverseSort != fReverseSort);
420 }
421 
422 } // namespace BPrivate
423 
424 using namespace BPrivate;
425 
426 #endif	// _VIEW_STATE_H
427