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