xref: /haiku/src/kits/tracker/ViewState.h (revision c49e0c68b013ebe90a3a48d5e98b5788ba2e6542)
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 	uint32 IconSize() const;
103 	BPoint ListOrigin() const;
104 	BPoint IconOrigin() const;
105 	uint32 PrimarySort() const;
106 	uint32 SecondarySort() const;
107 	uint32 PrimarySortType() const;
108 	uint32 SecondarySortType() const;
109 	bool ReverseSort() const;
110 
111 	void SetViewMode(uint32);
112 	void SetLastIconMode(uint32);
113 	void SetIconSize(uint32);
114 	void SetListOrigin(BPoint);
115 	void SetIconOrigin(BPoint);
116 	void SetPrimarySort(uint32);
117 	void SetSecondarySort(uint32);
118 	void SetPrimarySortType(uint32);
119 	void SetSecondarySortType(uint32);
120 	void SetReverseSort(bool);
121 
122 	bool StateNeedsSaving();
123 	void MarkSaved();
124 
125 private:
126 	uint32 fViewMode;
127 	uint32 fLastIconMode;
128 	uint32 fIconSize;
129 	BPoint fListOrigin;
130 	BPoint fIconOrigin;
131 	uint32 fPrimarySortAttr;
132 	uint32 fSecondarySortAttr;
133 	uint32 fPrimarySortType;
134 	uint32 fSecondarySortType;
135 	bool fReverseSort;
136 	bool fStateNeedsSaving;
137 };
138 
139 inline const char *
140 BColumn::Title() const
141 {
142 	return fTitle.String();
143 }
144 
145 inline float
146 BColumn::Offset() const
147 {
148 	return fOffset;
149 }
150 
151 inline float
152 BColumn::Width() const
153 {
154 	return fWidth;
155 }
156 
157 inline alignment
158 BColumn::Alignment() const
159 {
160 	return fAlignment;
161 }
162 
163 inline const char *
164 BColumn::AttrName() const
165 {
166 	return fAttrName.String();
167 }
168 
169 inline uint32
170 BColumn::AttrHash() const
171 {
172 	return fAttrHash;
173 }
174 
175 inline uint32
176 BColumn::AttrType() const
177 {
178 	return fAttrType;
179 }
180 
181 inline bool
182 BColumn::StatField() const
183 {
184 	return fStatField;
185 }
186 
187 inline bool
188 BColumn::Editable() const
189 {
190 	return fEditable;
191 }
192 
193 inline void
194 BColumn::SetWidth(float w)
195 {
196 	fWidth = w;
197 }
198 
199 inline void
200 BColumn::SetOffset(float o)
201 {
202 	fOffset = o;
203 }
204 
205 inline uint32
206 BViewState::ViewMode() const
207 {
208 	return fViewMode;
209 }
210 
211 inline uint32
212 BViewState::LastIconMode() const
213 {
214 	return fLastIconMode;
215 }
216 
217 inline uint32
218 BViewState::IconSize() const
219 {
220 	return fIconSize;
221 }
222 
223 inline BPoint
224 BViewState::ListOrigin() const
225 {
226 	return fListOrigin;
227 }
228 
229 inline BPoint
230 BViewState::IconOrigin() const
231 {
232 	return fIconOrigin;
233 }
234 
235 inline uint32
236 BViewState::PrimarySort() const
237 {
238 	return fPrimarySortAttr;
239 }
240 
241 inline uint32
242 BViewState::SecondarySort() const
243 {
244 	return fSecondarySortAttr;
245 }
246 
247 inline uint32
248 BViewState::PrimarySortType() const
249 {
250 	return fPrimarySortType;
251 }
252 
253 inline uint32
254 BViewState::SecondarySortType() const
255 {
256 	return fSecondarySortType;
257 }
258 
259 inline bool
260 BViewState::ReverseSort() const
261 {
262 	return fReverseSort;
263 }
264 
265 inline void
266 BViewState::SetViewMode(uint32 mode)
267 {
268 	if (mode != fViewMode)
269 		fStateNeedsSaving = true;
270 
271 	fViewMode = mode;
272 }
273 
274 inline void
275 BViewState::SetLastIconMode(uint32 mode)
276 {
277 	if (mode != fLastIconMode)
278 		fStateNeedsSaving = true;
279 
280 	fLastIconMode = mode;
281 }
282 
283 inline void
284 BViewState::SetIconSize(uint32 size)
285 {
286 	fIconSize = size;
287 }
288 
289 inline void
290 BViewState::SetListOrigin(BPoint newOrigin)
291 {
292 	if (newOrigin != fListOrigin)
293 		fStateNeedsSaving = true;
294 
295 	fListOrigin = newOrigin;
296 }
297 
298 inline void
299 BViewState::SetIconOrigin(BPoint newOrigin)
300 {
301 	if (newOrigin != fIconOrigin)
302 		fStateNeedsSaving = true;
303 
304 	fIconOrigin = newOrigin;
305 }
306 
307 inline void
308 BViewState::SetPrimarySort(uint32 attr)
309 {
310 	if (attr != fPrimarySortAttr)
311 		fStateNeedsSaving = true;
312 
313 	fPrimarySortAttr = attr;
314 }
315 
316 inline void
317 BViewState::SetSecondarySort(uint32 attr)
318 {
319 	if (attr != fSecondarySortAttr)
320 		fStateNeedsSaving = true;
321 
322 	fSecondarySortAttr = attr;
323 }
324 
325 inline void
326 BViewState::SetPrimarySortType(uint32 type)
327 {
328 	if (type != fPrimarySortType)
329 		fStateNeedsSaving = true;
330 
331 	fPrimarySortType = type;
332 }
333 
334 inline void
335 BViewState::SetSecondarySortType(uint32 type)
336 {
337 	if (type != fSecondarySortType)
338 		fStateNeedsSaving = true;
339 
340 	fSecondarySortType = type;
341 }
342 
343 inline void
344 BViewState::SetReverseSort(bool on)
345 {
346 	if (fReverseSort != on)
347 		fStateNeedsSaving = true;
348 
349 	fReverseSort = on;
350 }
351 
352 inline bool
353 BViewState::StateNeedsSaving()
354 {
355 	return fStateNeedsSaving;
356 }
357 
358 inline void
359 BViewState::MarkSaved()
360 {
361 	fStateNeedsSaving = false;
362 }
363 
364 
365 } // namespace BPrivate
366 
367 using namespace BPrivate;
368 
369 #endif
370