1/*
2Open Tracker License
3
4Terms and Conditions
5
6Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7
8Permission is hereby granted, free of charge, to any person obtaining a copy of
9this software and associated documentation files (the "Software"), to deal in
10the Software without restriction, including without limitation the rights to
11use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12of the Software, and to permit persons to whom the Software is furnished to do
13so, subject to the following conditions:
14
15The above copyright notice and this permission notice applies to all licensees
16and shall be included in all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25Except as contained in this notice, the name of Be Incorporated shall not be
26used in advertising or otherwise to promote the sale, use or other dealings in
27this Software without prior written authorization from Be Incorporated.
28
29Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30of Be Incorporated in the United States and other countries. Other brand product
31names are registered trademarks or trademarks of their respective holders.
32All 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
42namespace BPrivate {
43
44const int32 kColumnStateArchiveVersion = 22;
45	// bump version when layout or size changes
46
47class BColumn {
48public:
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
81private:
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
101const int32 kViewStateArchiveVersion = 11;
102	// bump version when layout or size changes
103
104class BViewState {
105public:
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
142private:
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
177inline const char*
178BColumn::Title() const
179{
180	return fTitle.String();
181}
182
183
184inline float
185BColumn::Offset() const
186{
187	return fOffset;
188}
189
190
191inline float
192BColumn::Width() const
193{
194	return fWidth;
195}
196
197
198inline alignment
199BColumn::Alignment() const
200{
201	return fAlignment;
202}
203
204
205inline const char*
206BColumn::AttrName() const
207{
208	return fAttrName.String();
209}
210
211
212inline uint32
213BColumn::AttrHash() const
214{
215	return fAttrHash;
216}
217
218
219inline uint32
220BColumn::AttrType() const
221{
222	return fAttrType;
223}
224
225
226inline const char*
227BColumn::DisplayAs() const
228{
229	return fDisplayAs.String();
230}
231
232
233inline bool
234BColumn::StatField() const
235{
236	return fStatField;
237}
238
239
240inline bool
241BColumn::Editable() const
242{
243	return fEditable;
244}
245
246
247inline void
248BColumn::SetWidth(float w)
249{
250	fWidth = w;
251}
252
253
254inline void
255BColumn::SetOffset(float o)
256{
257	fOffset = o;
258}
259
260
261inline uint32
262BViewState::ViewMode() const
263{
264	return fViewMode;
265}
266
267
268inline uint32
269BViewState::LastIconMode() const
270{
271	return fLastIconMode;
272}
273
274
275inline uint32
276BViewState::IconSize() const
277{
278	return fIconSize;
279}
280
281
282inline uint32
283BViewState::LastIconSize() const
284{
285	return fLastIconSize;
286}
287
288
289inline BPoint
290BViewState::ListOrigin() const
291{
292	return fListOrigin;
293}
294
295
296inline BPoint
297BViewState::IconOrigin() const
298{
299	return fIconOrigin;
300}
301
302
303inline uint32
304BViewState::PrimarySort() const
305{
306	return fPrimarySortAttr;
307}
308
309
310inline uint32
311BViewState::SecondarySort() const
312{
313	return fSecondarySortAttr;
314}
315
316
317inline uint32
318BViewState::PrimarySortType() const
319{
320	return fPrimarySortType;
321}
322
323inline uint32
324BViewState::SecondarySortType() const
325{
326	return fSecondarySortType;
327}
328
329inline bool
330BViewState::ReverseSort() const
331{
332	return fReverseSort;
333}
334
335
336inline void
337BViewState::SetViewMode(uint32 mode)
338{
339	fViewMode = mode;
340}
341
342
343inline void
344BViewState::SetLastIconMode(uint32 mode)
345{
346	fLastIconMode = mode;
347}
348
349
350inline void
351BViewState::SetIconSize(uint32 size)
352{
353	fIconSize = size;
354}
355
356
357inline void
358BViewState::SetLastIconSize(uint32 size)
359{
360	fLastIconSize = size;
361}
362
363
364inline void
365BViewState::SetListOrigin(BPoint newOrigin)
366{
367	fListOrigin = newOrigin;
368}
369
370inline void
371BViewState::SetIconOrigin(BPoint newOrigin)
372{
373	fIconOrigin = newOrigin;
374}
375
376inline void
377BViewState::SetPrimarySort(uint32 attr)
378{
379	fPrimarySortAttr = attr;
380}
381
382
383inline void
384BViewState::SetSecondarySort(uint32 attr)
385{
386	fSecondarySortAttr = attr;
387}
388
389
390inline void
391BViewState::SetPrimarySortType(uint32 type)
392{
393	fPrimarySortType = type;
394}
395
396
397inline void
398BViewState::SetSecondarySortType(uint32 type)
399{
400	fSecondarySortType = type;
401}
402
403
404inline void
405BViewState::SetReverseSort(bool on)
406{
407	fReverseSort = on;
408}
409
410
411inline bool
412BViewState::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
429using namespace BPrivate;
430
431
432#endif	// _VIEW_STATE_H
433