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