Ticket #6314: viewLayoutArchiving.patch
File viewLayoutArchiving.patch, 5.5 KB (added by , 14 years ago) |
---|
-
src/kits/interface/View.cpp
48 48 #include <AppMisc.h> 49 49 #include <AppServerLink.h> 50 50 #include <binary_compatibility/Interface.h> 51 #include <binary_compatibility/Support.h> 51 52 #include <MessagePrivate.h> 52 53 #include <MessageUtils.h> 53 54 #include <PortLink.h> … … 315 316 // #pragma mark - 316 317 317 318 319 // archiving constants 320 namespace { 321 const char* kMinSizeField = "ViewLayoutData:minsize"; 322 const char* kMaxSizeField = "ViewLayoutData:maxsize"; 323 const char* kPreferredSizeField = "ViewLayoutData:prefsize"; 324 const char* kAlignmentField = "ViewLayoutData:alignment"; 325 } 326 327 318 328 struct BView::LayoutData { 319 329 LayoutData() 320 330 : … … 332 342 { 333 343 } 334 344 345 status_t 346 AddDataToArchive(BMessage* archive) 347 { 348 status_t err = archive->AddSize(kMinSizeField, fMinSize); 349 350 if (err == B_OK) 351 err = archive->AddSize(kMaxSizeField, fMaxSize); 352 353 if (err == B_OK) 354 err = archive->AddSize(kPreferredSizeField, fPreferredSize); 355 356 if (err == B_OK) 357 err = archive->AddAlignment(kAlignmentField, fAlignment); 358 359 return err; 360 } 361 362 void 363 PopulateFromArchive(BMessage* archive) 364 { 365 archive->FindSize(kMinSizeField, &fMinSize); 366 archive->FindSize(kMaxSizeField, &fMaxSize); 367 archive->FindSize(kPreferredSizeField, &fPreferredSize); 368 archive->FindAlignment(kAlignmentField, &fAlignment); 369 } 370 335 371 BSize fMinSize; 336 372 BSize fMaxSize; 337 373 BSize fPreferredSize; … … 366 402 367 403 BView::BView(BMessage* archive) 368 404 : 369 BHandler( archive)405 BHandler(BUnarchiver::PrepareArchive(archive)) 370 406 { 407 BUnarchiver unarchiver(archive); 408 371 409 BRect frame; 372 410 archive->FindRect("_frame", &frame); 373 411 … … 450 488 if (archive->FindInt32("_dmod", (int32*)&drawingMode) == B_OK) 451 489 SetDrawingMode((drawing_mode)drawingMode); 452 490 453 BMessage msg; 454 for (int32 i = 0; archive->FindMessage("_views", i, &msg) == B_OK; i++) { 455 BArchivable* object = instantiate_object(&msg); 456 if (BView* child = dynamic_cast<BView*>(object)) 457 AddChild(child); 491 fLayoutData->PopulateFromArchive(archive); 492 493 if (archive->FindInt16("_show", &fShowLevel) != B_OK) 494 fShowLevel = 0; 495 496 if (BUnarchiver::IsArchiveManaged(archive)) { 497 int32 i = 0; 498 while (unarchiver.EnsureUnarchived("_views", i++) == B_OK) 499 ; 500 unarchiver.EnsureUnarchived("_layout"); 501 502 } else { 503 BMessage msg; 504 for (int32 i = 0; archive->FindMessage("_views", i, &msg) == B_OK; 505 i++) { 506 BArchivable* object = instantiate_object(&msg); 507 if (BView* child = dynamic_cast<BView*>(object)) 508 AddChild(child); 509 } 458 510 } 459 511 } 460 512 … … 472 524 status_t 473 525 BView::Archive(BMessage* data, bool deep) const 474 526 { 527 BArchiver archiver(data); 475 528 status_t ret = BHandler::Archive(data, deep); 529 476 530 if (ret != B_OK) 477 531 return ret; 478 532 … … 552 606 if (ret == B_OK && (fState->archiving_flags & B_VIEW_DRAWING_MODE_BIT) != 0) 553 607 ret = data->AddInt32("_dmod", DrawingMode()); 554 608 555 if (deep) { 556 int32 i = 0; 609 if (ret == B_OK) 610 ret = fLayoutData->AddDataToArchive(data); 611 612 if (ret == B_OK) 613 ret = data->AddInt16("_show", fShowLevel); 614 615 if (deep && ret == B_OK) { 616 for (BView* child = fFirstChild; child != NULL && ret == B_OK; 617 child = child->fNextSibling) 618 ret = archiver.AddArchivable("_views", child, deep); 619 620 if (ret == B_OK) 621 ret = archiver.AddArchivable("_layout", GetLayout(), deep); 622 } 623 624 return archiver.Finish(ret); 625 } 626 627 628 status_t 629 BView::AllUnarchived(const BMessage* from) 630 { 631 BUnarchiver unarchiver(from); 632 status_t err = B_OK; 633 634 int32 count; 635 from->GetInfo("_views", NULL, &count); 636 637 for (int32 i = 0; err == B_OK && i < count; i++) { 557 638 BView* child; 639 err = unarchiver.FindObject<BView>("_views", i, child); 640 if (err == B_OK) 641 err = _AddChild(child, NULL) ? B_OK : B_ERROR; 642 } 558 643 559 while (ret == B_OK && (child = ChildAt(i++)) != NULL) { 560 BMessage childArchive; 644 if (err == B_OK) { 645 BLayout*& layout = fLayoutData->fLayout; 646 err = unarchiver.FindObject("_layout", layout); 647 if (err == B_OK && layout) { 648 fFlags |= B_SUPPORTS_LAYOUT; 649 fLayoutData->fLayout->BLayout::SetView(this); 650 } 561 651 562 ret = child->Archive(&childArchive, deep);563 if (ret == B_OK)564 ret = data->AddMessage("_views", &childArchive);565 }566 652 } 567 653 568 return ret;654 return err; 569 655 } 570 656 571 657 658 status_t 659 BView::AllArchived(BMessage* into) const 660 { 661 return BHandler::AllArchived(into); 662 } 663 664 572 665 BView::~BView() 573 666 { 574 667 STRACE(("BView(%s)::~BView()\n", this->Name())); … … 4398 4491 = BView::GetToolTipAt(data->point, data->tool_tip); 4399 4492 return B_OK; 4400 4493 } 4494 case PERFORM_CODE_ALL_UNARCHIVED: 4495 { 4496 perform_data_all_unarchived* data = 4497 (perform_data_all_unarchived*)_data; 4498 4499 data->return_value = BView::AllUnarchived(data->archive); 4500 return B_OK; 4501 } 4502 case PERFORM_CODE_ALL_ARCHIVED: 4503 { 4504 perform_data_all_archived* data = 4505 (perform_data_all_archived*)_data; 4506 4507 data->return_value = BView::AllArchived(data->archive); 4508 return B_OK; 4509 } 4401 4510 } 4402 4511 4403 4512 return BHandler::Perform(code, _data); -
headers/os/interface/View.h
143 143 static BArchivable* Instantiate(BMessage* archive); 144 144 virtual status_t Archive(BMessage* archive, 145 145 bool deep = true) const; 146 virtual status_t AllUnarchived(const BMessage* archive); 147 virtual status_t AllArchived(BMessage* archive) const; 146 148 147 149 virtual void AttachedToWindow(); 148 150 virtual void AllAttached();