Author: yourpalal Date: 2010-07-28 22:03:41 +0200 (Wed, 28 Jul 2010) New Revision: 37796 Changeset: http://dev.haiku-os.org/changeset/37796 Modified: haiku/trunk/headers/os/interface/TabView.h haiku/trunk/src/kits/interface/TabView.cpp Log: Update BTabView for layout-friendly archiving. Added _InitContainerView() method that is called from _InitObject() but also called on its own during unarchival. Implemented BTabView::AllUnarchived() and implemented a case for this in BTabView::Perform(). Modified: haiku/trunk/headers/os/interface/TabView.h =================================================================== --- haiku/trunk/headers/os/interface/TabView.h 2010-07-28 18:00:09 UTC (rev 37795) +++ haiku/trunk/headers/os/interface/TabView.h 2010-07-28 20:03:41 UTC (rev 37796) @@ -96,6 +96,7 @@ static BArchivable* Instantiate(BMessage* archive); virtual status_t Archive(BMessage* into, bool deep = true) const; + virtual status_t AllUnarchived(const BMessage* from); virtual status_t Perform(perform_code d, void* arg); virtual void AttachedToWindow(); @@ -182,6 +183,7 @@ private: void _InitObject(bool layouted, button_width width); + void _InitContainerView(bool layouted); BSize _TabsMinSize() const; float _BorderWidth() const; void _LayoutContainerView(bool layouted); Modified: haiku/trunk/src/kits/interface/TabView.cpp =================================================================== --- haiku/trunk/src/kits/interface/TabView.cpp 2010-07-28 18:00:09 UTC (rev 37795) +++ haiku/trunk/src/kits/interface/TabView.cpp 2010-07-28 20:03:41 UTC (rev 37796) @@ -26,7 +26,12 @@ #include <Region.h> #include <String.h> +#include <binary_compatibility/Support.h> + +using std::nothrow; + + static property_info sPropertyList[] = { { "Selection", @@ -52,6 +57,7 @@ BTab::BTab(BMessage *archive) : + BArchivable(archive), fSelected(false), fFocus(false), fView(NULL) @@ -400,14 +406,15 @@ BTabView::BTabView(BMessage *archive) - : BView(archive), + : + BView(BUnarchiver::PrepareArchive(archive)), + fTabList(new BList), + fContainerView(NULL), fFocus(-1) { - fContainerView = NULL; - fTabList = new BList; + BUnarchiver unarchiver(archive); int16 width; - if (archive->FindInt16("_but_width", &width) == B_OK) fTabWidthSetting = (button_width)width; else @@ -419,17 +426,25 @@ fTabHeight = fh.ascent + fh.descent + fh.leading + 8.0f; } - fFocus = -1; - if (archive->FindInt32("_sel", &fSelection) != B_OK) fSelection = 0; - if (fContainerView == NULL) - fContainerView = ChildAt(0); - int32 i = 0; BMessage tabMsg; + if (BUnarchiver::IsArchiveManaged(archive)) { + int32 tabCount; + archive->GetInfo("_l_items", NULL, &tabCount); + for (int32 i = 0; i < tabCount; i++) { + unarchiver.EnsureUnarchived("_l_items", i); + unarchiver.EnsureUnarchived("_view_list", i); + } + return; + } + + fContainerView = ChildAt(0); + _InitContainerView(Flags() & B_SUPPORTS_LAYOUT); + while (archive->FindMessage("_l_items", i, &tabMsg) == B_OK) { BArchivable *archivedTab = instantiate_object(&tabMsg); @@ -461,10 +476,9 @@ status_t -BTabView::Archive(BMessage *archive, bool deep) const +BTabView::Archive(BMessage* archive, bool deep) const { - if (CountTabs() > 0) - TabAt(Selection())->View()->RemoveSelf(); + BArchiver archiver(archive); status_t ret = BView::Archive(archive, deep); @@ -477,38 +491,68 @@ if (ret == B_OK && deep) { for (int32 i = 0; i < CountTabs(); i++) { - BMessage tabArchive; - BTab *tab = TabAt(i); + BTab* tab = TabAt(i); - if (!tab) - continue; - ret = tab->Archive(&tabArchive, true); - if (ret == B_OK) - ret = archive->AddMessage("_l_items", &tabArchive); + if ((ret = archiver.AddArchivable("_l_items", tab, deep)) != B_OK) + break; + ret = archiver.AddArchivable("_view_list", tab->View(), deep); + } + } - if (!tab->View()) - continue; + return archiver.Finish(ret); +} - BMessage viewArchive; - ret = tab->View()->Archive(&viewArchive, true); - if (ret == B_OK) - ret = archive->AddMessage("_view_list", &viewArchive); + +status_t +BTabView::AllUnarchived(const BMessage* archive) +{ + status_t err = BView::AllUnarchived(archive); + if (err != B_OK) + return err; + + fContainerView = ChildAt(0); + _InitContainerView(Flags() & B_SUPPORTS_LAYOUT); + + BUnarchiver unarchiver(archive); + + int32 tabCount; + archive->GetInfo("_l_items", NULL, &tabCount); + for (int32 i = 0; i < tabCount && err == B_OK; i++) { + BTab* tab; + err = unarchiver.FindObject("_l_items", i, tab); + if (err == B_OK && tab) { + BView* view; + if ((err = unarchiver.FindObject("_view_list", i, + BUnarchiver::B_DONT_ASSUME_OWNERSHIP, view)) != B_OK) + break; + + tab->SetView(view); + fTabList->AddItem(tab); } } - if (CountTabs() > 0) { - if (TabAt(Selection())->View() && ContainerView()) - TabAt(Selection())->Select(ContainerView()); - } + if (err == B_OK) + Select(fSelection); - return ret; + return err; } status_t -BTabView::Perform(perform_code d, void *arg) +BTabView::Perform(perform_code code, void* _data) { - return BView::Perform(d, arg); + switch (code) { + case PERFORM_CODE_ALL_UNARCHIVED: + { + perform_data_all_unarchived* data + = (perform_data_all_unarchived*)_data; + + data->return_value = BTabView::AllUnarchived(data->archive); + return B_OK; + } + } + + return BView::Perform(code, _data); } @@ -1317,21 +1361,37 @@ GetFontHeight(&fh); fTabHeight = fh.ascent + fh.descent + fh.leading + 8.0f; + _InitContainerView(layouted); +} + + +void +BTabView::_InitContainerView(bool layouted) +{ + bool needsLayout = false; if (layouted) { - SetLayout(new(std::nothrow) BGroupLayout(B_HORIZONTAL)); + if (!GetLayout()) { + SetLayout(new(nothrow) BGroupLayout(B_HORIZONTAL)); + needsLayout = true; + } - fContainerView = new BView("view container", B_WILL_DRAW); - fContainerView->SetLayout(new(std::nothrow) BCardLayout()); - } else { + if (!fContainerView) { + fContainerView = new BView("view container", B_WILL_DRAW); + fContainerView->SetLayout(new(std::nothrow) BCardLayout()); + needsLayout = true; + } + } else if (!fContainerView) { fContainerView = new BView(Bounds(), "view container", B_FOLLOW_ALL, B_WILL_DRAW); + needsLayout= true; } - _LayoutContainerView(layouted); - fContainerView->SetViewColor(color); - fContainerView->SetLowColor(color); - - AddChild(fContainerView); + if (needsLayout) { + _LayoutContainerView(layouted); + fContainerView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + fContainerView->SetLowColor(fContainerView->ViewColor()); + AddChild(fContainerView); + } }