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 = 21; 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 bool statField, bool editable); 52 ~BColumn(); 53 54 BColumn(BMallocIO *stream, bool endianSwap = false); 55 BColumn(const BMessage &, int32 index = 0); 56 static BColumn *InstantiateFromStream(BMallocIO *stream, 57 bool endianSwap = false); 58 static BColumn *InstantiateFromMessage(const BMessage &archive, 59 int32 index = 0); 60 void ArchiveToStream(BMallocIO *stream) const; 61 void ArchiveToMessage(BMessage &) const; 62 63 const char *Title() const; 64 float Offset() const; 65 float Width() const; 66 alignment Alignment() const; 67 const char *AttrName() const; 68 uint32 AttrType() const; 69 uint32 AttrHash() const; 70 bool StatField() const; 71 bool Editable() const; 72 73 void SetOffset(float); 74 void SetWidth(float); 75 76 private: 77 static BColumn *_Sanitize(BColumn *column); 78 79 BString fTitle; 80 float fOffset; 81 float fWidth; 82 alignment fAlignment; 83 BString fAttrName; 84 uint32 fAttrHash; 85 uint32 fAttrType; 86 bool fStatField; 87 bool fEditable; 88 }; 89 90 91 const int32 kViewStateArchiveVersion = 10; 92 // bump version when layout or size changes 93 94 class BViewState { 95 public: 96 BViewState(); 97 98 BViewState(BMallocIO *stream, bool endianSwap = false); 99 BViewState(const BMessage &message); 100 static BViewState *InstantiateFromStream(BMallocIO *stream, bool endianSwap = false); 101 static BViewState *InstantiateFromMessage(const BMessage &message); 102 void ArchiveToStream(BMallocIO *stream) const; 103 void ArchiveToMessage(BMessage &message) const; 104 105 uint32 ViewMode() const; 106 uint32 LastIconMode() const; 107 uint32 IconSize() const; 108 BPoint ListOrigin() const; 109 BPoint IconOrigin() const; 110 uint32 PrimarySort() const; 111 uint32 SecondarySort() const; 112 uint32 PrimarySortType() const; 113 uint32 SecondarySortType() const; 114 bool ReverseSort() const; 115 116 void SetViewMode(uint32); 117 void SetLastIconMode(uint32); 118 void SetIconSize(uint32); 119 void SetListOrigin(BPoint); 120 void SetIconOrigin(BPoint); 121 void SetPrimarySort(uint32); 122 void SetSecondarySort(uint32); 123 void SetPrimarySortType(uint32); 124 void SetSecondarySortType(uint32); 125 void SetReverseSort(bool); 126 127 bool StateNeedsSaving(); 128 void MarkSaved(); 129 130 private: 131 static BViewState *_Sanitize(BViewState *state, bool fixOnly = false); 132 133 uint32 fViewMode; 134 uint32 fLastIconMode; 135 uint32 fIconSize; 136 BPoint fListOrigin; 137 BPoint fIconOrigin; 138 uint32 fPrimarySortAttr; 139 uint32 fSecondarySortAttr; 140 uint32 fPrimarySortType; 141 uint32 fSecondarySortType; 142 bool fReverseSort; 143 bool fStateNeedsSaving; 144 }; 145 146 147 inline const char * 148 BColumn::Title() const 149 { 150 return fTitle.String(); 151 } 152 153 inline float 154 BColumn::Offset() const 155 { 156 return fOffset; 157 } 158 159 inline float 160 BColumn::Width() const 161 { 162 return fWidth; 163 } 164 165 inline alignment 166 BColumn::Alignment() const 167 { 168 return fAlignment; 169 } 170 171 inline const char * 172 BColumn::AttrName() const 173 { 174 return fAttrName.String(); 175 } 176 177 inline uint32 178 BColumn::AttrHash() const 179 { 180 return fAttrHash; 181 } 182 183 inline uint32 184 BColumn::AttrType() const 185 { 186 return fAttrType; 187 } 188 189 inline bool 190 BColumn::StatField() const 191 { 192 return fStatField; 193 } 194 195 inline bool 196 BColumn::Editable() const 197 { 198 return fEditable; 199 } 200 201 inline void 202 BColumn::SetWidth(float w) 203 { 204 fWidth = w; 205 } 206 207 inline void 208 BColumn::SetOffset(float o) 209 { 210 fOffset = o; 211 } 212 213 inline uint32 214 BViewState::ViewMode() const 215 { 216 return fViewMode; 217 } 218 219 inline uint32 220 BViewState::LastIconMode() const 221 { 222 return fLastIconMode; 223 } 224 225 inline uint32 226 BViewState::IconSize() const 227 { 228 return fIconSize; 229 } 230 231 inline BPoint 232 BViewState::ListOrigin() const 233 { 234 return fListOrigin; 235 } 236 237 inline BPoint 238 BViewState::IconOrigin() const 239 { 240 return fIconOrigin; 241 } 242 243 inline uint32 244 BViewState::PrimarySort() const 245 { 246 return fPrimarySortAttr; 247 } 248 249 inline uint32 250 BViewState::SecondarySort() const 251 { 252 return fSecondarySortAttr; 253 } 254 255 inline uint32 256 BViewState::PrimarySortType() const 257 { 258 return fPrimarySortType; 259 } 260 261 inline uint32 262 BViewState::SecondarySortType() const 263 { 264 return fSecondarySortType; 265 } 266 267 inline bool 268 BViewState::ReverseSort() const 269 { 270 return fReverseSort; 271 } 272 273 inline void 274 BViewState::SetViewMode(uint32 mode) 275 { 276 if (mode != fViewMode) 277 fStateNeedsSaving = true; 278 279 fViewMode = mode; 280 } 281 282 inline void 283 BViewState::SetLastIconMode(uint32 mode) 284 { 285 if (mode != fLastIconMode) 286 fStateNeedsSaving = true; 287 288 fLastIconMode = mode; 289 } 290 291 inline void 292 BViewState::SetIconSize(uint32 size) 293 { 294 fIconSize = size; 295 } 296 297 inline void 298 BViewState::SetListOrigin(BPoint newOrigin) 299 { 300 if (newOrigin != fListOrigin) 301 fStateNeedsSaving = true; 302 303 fListOrigin = newOrigin; 304 } 305 306 inline void 307 BViewState::SetIconOrigin(BPoint newOrigin) 308 { 309 if (newOrigin != fIconOrigin) 310 fStateNeedsSaving = true; 311 312 fIconOrigin = newOrigin; 313 } 314 315 inline void 316 BViewState::SetPrimarySort(uint32 attr) 317 { 318 if (attr != fPrimarySortAttr) 319 fStateNeedsSaving = true; 320 321 fPrimarySortAttr = attr; 322 } 323 324 inline void 325 BViewState::SetSecondarySort(uint32 attr) 326 { 327 if (attr != fSecondarySortAttr) 328 fStateNeedsSaving = true; 329 330 fSecondarySortAttr = attr; 331 } 332 333 inline void 334 BViewState::SetPrimarySortType(uint32 type) 335 { 336 if (type != fPrimarySortType) 337 fStateNeedsSaving = true; 338 339 fPrimarySortType = type; 340 } 341 342 inline void 343 BViewState::SetSecondarySortType(uint32 type) 344 { 345 if (type != fSecondarySortType) 346 fStateNeedsSaving = true; 347 348 fSecondarySortType = type; 349 } 350 351 inline void 352 BViewState::SetReverseSort(bool on) 353 { 354 if (fReverseSort != on) 355 fStateNeedsSaving = true; 356 357 fReverseSort = on; 358 } 359 360 inline bool 361 BViewState::StateNeedsSaving() 362 { 363 return fStateNeedsSaving; 364 } 365 366 inline void 367 BViewState::MarkSaved() 368 { 369 fStateNeedsSaving = false; 370 } 371 372 373 } // namespace BPrivate 374 375 using namespace BPrivate; 376 377 #endif 378