Patch by Alex Wilson: Added archiving/unarchiving of layout and layout
related data. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37539 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -143,6 +143,8 @@ public:
|
|||||||
static BArchivable* Instantiate(BMessage* archive);
|
static BArchivable* Instantiate(BMessage* archive);
|
||||||
virtual status_t Archive(BMessage* archive,
|
virtual status_t Archive(BMessage* archive,
|
||||||
bool deep = true) const;
|
bool deep = true) const;
|
||||||
|
virtual status_t AllUnarchived(const BMessage* archive);
|
||||||
|
virtual status_t AllArchived(BMessage* archive) const;
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void AllAttached();
|
virtual void AllAttached();
|
||||||
|
|||||||
+125
-16
@@ -48,6 +48,7 @@
|
|||||||
#include <AppMisc.h>
|
#include <AppMisc.h>
|
||||||
#include <AppServerLink.h>
|
#include <AppServerLink.h>
|
||||||
#include <binary_compatibility/Interface.h>
|
#include <binary_compatibility/Interface.h>
|
||||||
|
#include <binary_compatibility/Support.h>
|
||||||
#include <MessagePrivate.h>
|
#include <MessagePrivate.h>
|
||||||
#include <MessageUtils.h>
|
#include <MessageUtils.h>
|
||||||
#include <PortLink.h>
|
#include <PortLink.h>
|
||||||
@@ -315,6 +316,15 @@ ViewState::UpdateFrom(BPrivate::PortLink &link)
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
// archiving constants
|
||||||
|
namespace {
|
||||||
|
const char* kMinSizeField = "ViewLayoutData:minsize";
|
||||||
|
const char* kMaxSizeField = "ViewLayoutData:maxsize";
|
||||||
|
const char* kPreferredSizeField = "ViewLayoutData:prefsize";
|
||||||
|
const char* kAlignmentField = "ViewLayoutData:alignment";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct BView::LayoutData {
|
struct BView::LayoutData {
|
||||||
LayoutData()
|
LayoutData()
|
||||||
:
|
:
|
||||||
@@ -332,6 +342,32 @@ struct BView::LayoutData {
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status_t
|
||||||
|
AddDataToArchive(BMessage* archive)
|
||||||
|
{
|
||||||
|
status_t err = archive->AddSize(kMinSizeField, fMinSize);
|
||||||
|
|
||||||
|
if (err == B_OK)
|
||||||
|
err = archive->AddSize(kMaxSizeField, fMaxSize);
|
||||||
|
|
||||||
|
if (err == B_OK)
|
||||||
|
err = archive->AddSize(kPreferredSizeField, fPreferredSize);
|
||||||
|
|
||||||
|
if (err == B_OK)
|
||||||
|
err = archive->AddAlignment(kAlignmentField, fAlignment);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PopulateFromArchive(BMessage* archive)
|
||||||
|
{
|
||||||
|
archive->FindSize(kMinSizeField, &fMinSize);
|
||||||
|
archive->FindSize(kMaxSizeField, &fMaxSize);
|
||||||
|
archive->FindSize(kPreferredSizeField, &fPreferredSize);
|
||||||
|
archive->FindAlignment(kAlignmentField, &fAlignment);
|
||||||
|
}
|
||||||
|
|
||||||
BSize fMinSize;
|
BSize fMinSize;
|
||||||
BSize fMaxSize;
|
BSize fMaxSize;
|
||||||
BSize fPreferredSize;
|
BSize fPreferredSize;
|
||||||
@@ -366,8 +402,10 @@ BView::BView(BRect frame, const char* name, uint32 resizingMode, uint32 flags)
|
|||||||
|
|
||||||
BView::BView(BMessage* archive)
|
BView::BView(BMessage* archive)
|
||||||
:
|
:
|
||||||
BHandler(archive)
|
BHandler(BUnarchiver::PrepareArchive(archive))
|
||||||
{
|
{
|
||||||
|
BUnarchiver unarchiver(archive);
|
||||||
|
|
||||||
BRect frame;
|
BRect frame;
|
||||||
archive->FindRect("_frame", &frame);
|
archive->FindRect("_frame", &frame);
|
||||||
|
|
||||||
@@ -450,11 +488,25 @@ BView::BView(BMessage* archive)
|
|||||||
if (archive->FindInt32("_dmod", (int32*)&drawingMode) == B_OK)
|
if (archive->FindInt32("_dmod", (int32*)&drawingMode) == B_OK)
|
||||||
SetDrawingMode((drawing_mode)drawingMode);
|
SetDrawingMode((drawing_mode)drawingMode);
|
||||||
|
|
||||||
BMessage msg;
|
fLayoutData->PopulateFromArchive(archive);
|
||||||
for (int32 i = 0; archive->FindMessage("_views", i, &msg) == B_OK; i++) {
|
|
||||||
BArchivable* object = instantiate_object(&msg);
|
if (archive->FindInt16("_show", &fShowLevel) != B_OK)
|
||||||
if (BView* child = dynamic_cast<BView*>(object))
|
fShowLevel = 0;
|
||||||
AddChild(child);
|
|
||||||
|
if (BUnarchiver::IsArchiveManaged(archive)) {
|
||||||
|
int32 i = 0;
|
||||||
|
while (unarchiver.EnsureUnarchived("_views", i++) == B_OK)
|
||||||
|
;
|
||||||
|
unarchiver.EnsureUnarchived("_layout");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
BMessage msg;
|
||||||
|
for (int32 i = 0; archive->FindMessage("_views", i, &msg) == B_OK;
|
||||||
|
i++) {
|
||||||
|
BArchivable* object = instantiate_object(&msg);
|
||||||
|
if (BView* child = dynamic_cast<BView*>(object))
|
||||||
|
AddChild(child);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,7 +524,9 @@ BView::Instantiate(BMessage* data)
|
|||||||
status_t
|
status_t
|
||||||
BView::Archive(BMessage* data, bool deep) const
|
BView::Archive(BMessage* data, bool deep) const
|
||||||
{
|
{
|
||||||
|
BArchiver archiver(data);
|
||||||
status_t ret = BHandler::Archive(data, deep);
|
status_t ret = BHandler::Archive(data, deep);
|
||||||
|
|
||||||
if (ret != B_OK)
|
if (ret != B_OK)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@@ -552,20 +606,59 @@ BView::Archive(BMessage* data, bool deep) const
|
|||||||
if (ret == B_OK && (fState->archiving_flags & B_VIEW_DRAWING_MODE_BIT) != 0)
|
if (ret == B_OK && (fState->archiving_flags & B_VIEW_DRAWING_MODE_BIT) != 0)
|
||||||
ret = data->AddInt32("_dmod", DrawingMode());
|
ret = data->AddInt32("_dmod", DrawingMode());
|
||||||
|
|
||||||
if (deep) {
|
if (ret == B_OK)
|
||||||
int32 i = 0;
|
ret = fLayoutData->AddDataToArchive(data);
|
||||||
BView* child;
|
|
||||||
|
|
||||||
while (ret == B_OK && (child = ChildAt(i++)) != NULL) {
|
if (ret == B_OK)
|
||||||
BMessage childArchive;
|
ret = data->AddInt16("_show", fShowLevel);
|
||||||
|
|
||||||
ret = child->Archive(&childArchive, deep);
|
if (deep && ret == B_OK) {
|
||||||
if (ret == B_OK)
|
for (BView* child = fFirstChild; child != NULL && ret == B_OK;
|
||||||
ret = data->AddMessage("_views", &childArchive);
|
child = child->fNextSibling)
|
||||||
}
|
ret = archiver.AddArchivable("_views", child, deep);
|
||||||
|
|
||||||
|
if (ret == B_OK)
|
||||||
|
ret = archiver.AddArchivable("_layout", GetLayout(), deep);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return archiver.Finish(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BView::AllUnarchived(const BMessage* from)
|
||||||
|
{
|
||||||
|
BUnarchiver unarchiver(from);
|
||||||
|
status_t err = B_OK;
|
||||||
|
|
||||||
|
int32 count;
|
||||||
|
from->GetInfo("_views", NULL, &count);
|
||||||
|
|
||||||
|
for (int32 i = 0; err == B_OK && i < count; i++) {
|
||||||
|
BView* child;
|
||||||
|
err = unarchiver.FindObject<BView>("_views", i, child);
|
||||||
|
if (err == B_OK)
|
||||||
|
err = _AddChild(child, NULL) ? B_OK : B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err == B_OK) {
|
||||||
|
BLayout*& layout = fLayoutData->fLayout;
|
||||||
|
err = unarchiver.FindObject("_layout", layout);
|
||||||
|
if (err == B_OK && layout) {
|
||||||
|
fFlags |= B_SUPPORTS_LAYOUT;
|
||||||
|
fLayoutData->fLayout->BLayout::SetView(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BView::AllArchived(BMessage* into) const
|
||||||
|
{
|
||||||
|
return BHandler::AllArchived(into);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -4398,6 +4491,22 @@ BView::Perform(perform_code code, void* _data)
|
|||||||
= BView::GetToolTipAt(data->point, data->tool_tip);
|
= BView::GetToolTipAt(data->point, data->tool_tip);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
case PERFORM_CODE_ALL_UNARCHIVED:
|
||||||
|
{
|
||||||
|
perform_data_all_unarchived* data =
|
||||||
|
(perform_data_all_unarchived*)_data;
|
||||||
|
|
||||||
|
data->return_value = BView::AllUnarchived(data->archive);
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
case PERFORM_CODE_ALL_ARCHIVED:
|
||||||
|
{
|
||||||
|
perform_data_all_archived* data =
|
||||||
|
(perform_data_all_archived*)_data;
|
||||||
|
|
||||||
|
data->return_value = BView::AllArchived(data->archive);
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return BHandler::Perform(code, _data);
|
return BHandler::Perform(code, _data);
|
||||||
|
|||||||
Reference in New Issue
Block a user