Ticket #5525: 2dlayout.patch
File 2dlayout.patch, 8.0 KB (added by , 14 years ago) |
---|
-
headers/os/interface/TwoDimensionalLayout.h
1 1 /* 2 * Copyright 2006 , Haiku, Inc. All rights reserved.2 * Copyright 2006-2010, Haiku, Inc. All rights reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 */ 5 5 #ifndef _TWO_DIMENSIONAL_LAYOUT_H … … 14 14 class BTwoDimensionalLayout : public BLayout { 15 15 public: 16 16 BTwoDimensionalLayout(); 17 BTwoDimensionalLayout(BMessage* from); 17 18 virtual ~BTwoDimensionalLayout(); 18 19 19 20 void SetInsets(float left, float top, float right, … … 37 38 38 39 virtual void LayoutView(); 39 40 41 virtual status_t Archive(BMessage* into, bool deep = true) const; 42 virtual status_t AllArchived(BMessage* into) const; 43 virtual status_t AllUnarchived(const BMessage* from); 44 40 45 protected: 41 46 struct ColumnRowConstraints { 42 47 float weight; … … 66 71 enum orientation orientation, 67 72 int32 index, 68 73 ColumnRowConstraints* constraints) = 0; 69 virtual void 74 virtual void GetItemDimensions(BLayoutItem* item, 70 75 Dimensions* dimensions) = 0; 71 76 72 77 private: -
src/kits/interface/TwoDimensionalLayout.cpp
12 12 #include <LayoutItem.h> 13 13 #include <LayoutUtils.h> 14 14 #include <List.h> 15 #include <Message.h> 15 16 #include <View.h> 16 17 17 18 #include <Referenceable.h> … … 21 22 #include "SimpleLayouter.h" 22 23 23 24 25 // Archiving constants 26 namespace { 27 const char* kHAlignedLayoutField = "B2DLayout:halignedlayout"; 28 const char* kVAlignedLayoutField = "B2DLayout:valignedlayout"; 29 } 30 31 24 32 // Some words of explanation: 25 33 // 26 34 // This class is the base class for BLayouts that organize their items … … 67 75 void RemoveLocalLayouter( 68 76 LocalLayouter* localLayouter); 69 77 78 status_t AddAlignedLayoutsToArchive(BArchiver* archiver, 79 LocalLayouter* requestedBy); 80 70 81 void AbsorbCompoundLayouter(CompoundLayouter* other); 71 82 72 83 virtual void InvalidateLayout(); … … 164 175 void AlignWith(LocalLayouter* other, 165 176 enum orientation orientation); 166 177 178 // Archiving stuff 179 status_t AddAlignedLayoutsToArchive(BArchiver* archiver); 180 status_t AddOwnerToArchive(BArchiver* archiver, 181 CompoundLayouter* requestedBy, 182 bool& _wasAvailable); 183 status_t AlignLayoutsFromArchive(BUnarchiver* unarchiver, 184 orientation posture); 167 185 186 168 187 // interface for the compound layout context 169 188 170 189 void PrepareItems( … … 197 216 198 217 // implementation private 199 218 private: 200 BTwoDimensionalLayout* fLayout;201 CompoundLayouter* fHLayouter;202 VerticalCompoundLayouter* fVLayouter;203 BList fHeightForWidthItems;219 BTwoDimensionalLayout* fLayout; 220 CompoundLayouter* fHLayouter; 221 VerticalCompoundLayouter* fVLayouter; 222 BList fHeightForWidthItems; 204 223 205 224 // active layout context when doing last horizontal layout 206 225 BLayoutContext* fHorizontalLayoutContext; … … 217 236 218 237 // #pragma mark - 219 238 239 // archiving constants 240 namespace { 241 const char* kLeftInsetField = "B2Dlayout:leftInset"; 242 const char* kRightInsetField = "B2Dlayout:rightInset"; 243 const char* kTopInsetField = "B2Dlayout:topInset"; 244 const char* kBottomInsetField = "B2Dlayout:bottomInset"; 245 const char* kHSpacingField = "B2Dlayout:hspacing"; 246 const char* kVSpacingField = "B2Dlayout:vspacing"; 247 } 220 248 249 221 250 BTwoDimensionalLayout::BTwoDimensionalLayout() 222 251 : 223 252 fLeftInset(0), … … 231 260 } 232 261 233 262 263 BTwoDimensionalLayout::BTwoDimensionalLayout(BMessage* from) 264 : 265 BLayout(from), 266 fLeftInset(0), 267 fRightInset(0), 268 fTopInset(0), 269 fBottomInset(0), 270 fHSpacing(0), 271 fVSpacing(0), 272 fLocalLayouter(new LocalLayouter(this)) 273 { 274 float LeftInset; 275 float RightInset; 276 float TopInset; 277 float BottomInset; 278 if (from->FindFloat(kLeftInsetField, &LeftInset) == B_OK 279 && from->FindFloat(kRightInsetField, &RightInset) == B_OK 280 && from->FindFloat(kTopInsetField, &TopInset) == B_OK 281 && from->FindFloat(kBottomInsetField, &BottomInset) == B_OK) 282 SetInsets(LeftInset, TopInset, RightInset, BottomInset); 283 284 285 from->FindFloat(kHSpacingField, &fHSpacing); 286 from->FindFloat(kVSpacingField, &fVSpacing); 287 } 288 289 234 290 BTwoDimensionalLayout::~BTwoDimensionalLayout() 235 291 { 236 292 delete fLocalLayouter; … … 393 449 } 394 450 395 451 452 status_t 453 BTwoDimensionalLayout::Archive(BMessage* into, bool deep) const 454 { 455 BArchiver archiver(into); 456 status_t err = BLayout::Archive(into, deep); 457 458 if (err == B_OK) 459 err = into->AddFloat(kLeftInsetField, fLeftInset); 460 461 if (err == B_OK) 462 err = into->AddFloat(kRightInsetField, fRightInset); 463 464 if (err == B_OK) 465 err = into->AddFloat(kTopInsetField, fTopInset); 466 467 if (err == B_OK) 468 err = into->AddFloat(kBottomInsetField, fBottomInset); 469 470 if (err == B_OK) 471 err = into->AddFloat(kHSpacingField, fHSpacing); 472 473 if (err == B_OK) 474 err = into->AddFloat(kVSpacingField, fVSpacing); 475 476 return archiver.Finish(err); 477 } 478 479 480 status_t 481 BTwoDimensionalLayout::AllArchived(BMessage* into) const 482 { 483 BArchiver archiver(into); 484 485 status_t err = BLayout::AllArchived(into); 486 if (err == B_OK) 487 err = fLocalLayouter->AddAlignedLayoutsToArchive(&archiver); 488 return err; 489 } 490 491 492 status_t 493 BTwoDimensionalLayout::AllUnarchived(const BMessage* from) 494 { 495 status_t err = BLayout::AllUnarchived(from); 496 if (err != B_OK) 497 return err; 498 499 BUnarchiver unarchiver(from); 500 err = fLocalLayouter->AlignLayoutsFromArchive(&unarchiver, B_HORIZONTAL); 501 if (err == B_OK) 502 err = fLocalLayouter->AlignLayoutsFromArchive(&unarchiver, B_VERTICAL); 503 504 return err; 505 } 506 507 396 508 BSize 397 509 BTwoDimensionalLayout::AddInsets(BSize size) 398 510 { … … 531 643 } 532 644 533 645 646 status_t 647 BTwoDimensionalLayout::CompoundLayouter::AddAlignedLayoutsToArchive( 648 BArchiver* archiver, LocalLayouter* requestedBy) 649 { 650 // The LocalLayouter* that really owns us is at index 0, layouts 651 // at other indices are aligned to this one. 652 if (requestedBy != fLocalLayouters.ItemAt(0)) 653 return B_OK; 654 655 status_t err; 656 for (int32 i = fLocalLayouters.CountItems() - 1; i > 0; i--) { 657 LocalLayouter* layouter = (LocalLayouter*)fLocalLayouters.ItemAt(i); 658 659 bool wasAvailable; 660 err = layouter->AddOwnerToArchive(archiver, this, wasAvailable); 661 if (err != B_OK && wasAvailable) 662 return err; 663 } 664 return B_OK; 665 } 666 667 534 668 void 535 669 BTwoDimensionalLayout::CompoundLayouter::AbsorbCompoundLayouter( 536 670 CompoundLayouter* other) … … 1013 1147 } 1014 1148 1015 1149 1150 status_t 1151 BTwoDimensionalLayout::LocalLayouter::AddAlignedLayoutsToArchive( 1152 BArchiver* archiver) 1153 { 1154 status_t err = fHLayouter->AddAlignedLayoutsToArchive(archiver, this); 1155 1156 if (err == B_OK) 1157 err = fVLayouter->AddAlignedLayoutsToArchive(archiver, this); 1158 1159 return err; 1160 } 1161 1162 1163 status_t 1164 BTwoDimensionalLayout::LocalLayouter::AddOwnerToArchive(BArchiver* archiver, 1165 CompoundLayouter* requestedBy, bool& _wasAvailable) 1166 { 1167 const char* field = kHAlignedLayoutField; 1168 if (requestedBy == fVLayouter) 1169 field = kVAlignedLayoutField; 1170 1171 if ((_wasAvailable = archiver->IsArchived(fLayout))) 1172 return archiver->AddArchivable(field, fLayout); 1173 1174 return B_NAME_NOT_FOUND; 1175 } 1176 1177 1178 status_t 1179 BTwoDimensionalLayout::LocalLayouter::AlignLayoutsFromArchive( 1180 BUnarchiver* unarchiver, orientation posture) 1181 { 1182 const char* field = kHAlignedLayoutField; 1183 if (posture == B_VERTICAL) 1184 field = kVAlignedLayoutField; 1185 1186 int32 count; 1187 status_t err = unarchiver->ArchiveMessage()->GetInfo(field, NULL, &count); 1188 if (err == B_NAME_NOT_FOUND) 1189 return B_OK; 1190 1191 BTwoDimensionalLayout* retriever; 1192 for (int32 i = 0; i < count && err == B_OK; i++) { 1193 err = unarchiver->FindObject(field, i, 1194 BUnarchiver::B_DONT_ASSUME_OWNERSHIP, retriever); 1195 1196 if (err == B_OK) 1197 retriever->AlignLayoutWith(fLayout, posture); 1198 } 1199 1200 return err; 1201 } 1202 1203 1016 1204 void 1017 1205 BTwoDimensionalLayout::LocalLayouter::PrepareItems( 1018 1206 CompoundLayouter* compoundLayouter)