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