* Archive() should have been broken, because it didn't add the
class name. Also returns the actual error from the BMessage::AddData() if there was any. Please people, correct code like that if you spot this elsewhere and don't write such code anymore. * the BMessage constructor should be more robust. * the copy constructor takes the possibility into account that BitsLength() does not match. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17187 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -207,7 +207,7 @@ BBitmap::BBitmap(const BBitmap *source, bool acceptsViews,
|
|||||||
_InitObject(source->Bounds(), source->ColorSpace(), flags,
|
_InitObject(source->Bounds(), source->ColorSpace(), flags,
|
||||||
source->BytesPerRow(), B_MAIN_SCREEN_ID);
|
source->BytesPerRow(), B_MAIN_SCREEN_ID);
|
||||||
if (InitCheck() == B_OK)
|
if (InitCheck() == B_OK)
|
||||||
memcpy(Bits(), source->Bits(), BitsLength());
|
memcpy(Bits(), source->Bits(), min_c(BitsLength(), source->BitsLength()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,32 +240,33 @@ BBitmap::BBitmap(BMessage *data)
|
|||||||
fInitError(B_NO_INIT)
|
fInitError(B_NO_INIT)
|
||||||
{
|
{
|
||||||
BRect bounds;
|
BRect bounds;
|
||||||
data->FindRect("_frame", &bounds);
|
|
||||||
|
|
||||||
color_space cspace;
|
color_space cspace;
|
||||||
data->FindInt32("_cspace", (int32 *)&cspace);
|
int32 flags;
|
||||||
|
int32 rowBytes;
|
||||||
|
if (data->FindRect("_frame", &bounds) == B_OK
|
||||||
|
&& data->FindInt32("_cspace", (int32*)&cspace) == B_OK
|
||||||
|
&& data->FindInt32("_bmflags", &flags) == B_OK
|
||||||
|
&& data->FindInt32("_rowbytes", &rowBytes) == B_OK) {
|
||||||
|
|
||||||
int32 flags = 0;
|
_InitObject(bounds, cspace, flags, rowBytes, B_MAIN_SCREEN_ID);
|
||||||
data->FindInt32("_bmflags", &flags);
|
}
|
||||||
|
|
||||||
int32 rowBytes = 0;
|
if (InitCheck() == B_OK) {
|
||||||
data->FindInt32("_rowbytes", &rowBytes);
|
ssize_t size;
|
||||||
|
|
||||||
_InitObject(bounds, cspace, flags, rowBytes, B_MAIN_SCREEN_ID);
|
|
||||||
|
|
||||||
if (data->HasData("_data", B_RAW_TYPE) && InitCheck() == B_OK) {
|
|
||||||
_AssertPointer();
|
|
||||||
ssize_t size = 0;
|
|
||||||
const void *buffer;
|
const void *buffer;
|
||||||
if (data->FindData("_data", B_RAW_TYPE, &buffer, &size) == B_OK)
|
if (data->FindData("_data", B_RAW_TYPE, &buffer, &size) == B_OK) {
|
||||||
memcpy(fBasePointer, buffer, size);
|
if (size == BitsLength()) {
|
||||||
|
_AssertPointer();
|
||||||
|
memcpy(fBasePointer, buffer, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fFlags & B_BITMAP_ACCEPTS_VIEWS) {
|
if (fFlags & B_BITMAP_ACCEPTS_VIEWS) {
|
||||||
BMessage message;
|
BMessage message;
|
||||||
int32 i = 0;
|
int32 i = 0;
|
||||||
|
|
||||||
while (data->FindMessage("_view", i++, &message) == B_OK) {
|
while (data->FindMessage("_views", i++, &message) == B_OK) {
|
||||||
if (BView *view = dynamic_cast<BView *>(instantiate_object(&message)))
|
if (BView *view = dynamic_cast<BView *>(instantiate_object(&message)))
|
||||||
AddChild(view);
|
AddChild(view);
|
||||||
}
|
}
|
||||||
@@ -297,30 +298,45 @@ BBitmap::Instantiate(BMessage *data)
|
|||||||
status_t
|
status_t
|
||||||
BBitmap::Archive(BMessage *data, bool deep) const
|
BBitmap::Archive(BMessage *data, bool deep) const
|
||||||
{
|
{
|
||||||
BArchivable::Archive(data, deep);
|
status_t ret = BArchivable::Archive(data, deep);
|
||||||
|
|
||||||
data->AddRect("_frame", fBounds);
|
if (ret == B_OK)
|
||||||
data->AddInt32("_cspace", (int32)fColorSpace);
|
ret = data->AddRect("_frame", fBounds);
|
||||||
data->AddInt32("_bmflags", fFlags);
|
|
||||||
data->AddInt32("_rowbytes", fBytesPerRow);
|
|
||||||
|
|
||||||
if (deep) {
|
if (ret == B_OK)
|
||||||
|
ret = data->AddInt32("_cspace", (int32)fColorSpace);
|
||||||
|
|
||||||
|
if (ret == B_OK)
|
||||||
|
ret = data->AddInt32("_bmflags", fFlags);
|
||||||
|
|
||||||
|
if (ret == B_OK)
|
||||||
|
ret = data->AddInt32("_rowbytes", fBytesPerRow);
|
||||||
|
|
||||||
|
if (ret == B_OK && deep) {
|
||||||
if (fFlags & B_BITMAP_ACCEPTS_VIEWS) {
|
if (fFlags & B_BITMAP_ACCEPTS_VIEWS) {
|
||||||
BMessage views;
|
BMessage views;
|
||||||
for (int32 i = 0; i < CountChildren(); i++) {
|
for (int32 i = 0; i < CountChildren(); i++) {
|
||||||
if (ChildAt(i)->Archive(&views, deep))
|
if (ChildAt(i)->Archive(&views, deep))
|
||||||
data->AddMessage("_views", &views);
|
ret = data->AddMessage("_views", &views);
|
||||||
|
views.MakeEmpty();
|
||||||
|
if (ret < B_OK)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Note: R5 does not archive the data if B_BITMAP_IS_CONTIGNUOUS is
|
// Note: R5 does not archive the data if B_BITMAP_IS_CONTIGNUOUS is
|
||||||
// true and it does save all formats as B_RAW_TYPE and it does save
|
// true and it does save all formats as B_RAW_TYPE and it does save
|
||||||
// the data even if B_BITMAP_ACCEPTS_VIEWS is set (as opposed to
|
// the data even if B_BITMAP_ACCEPTS_VIEWS is set (as opposed to
|
||||||
// the BeBook)
|
// the BeBook)
|
||||||
const_cast<BBitmap *>(this)->_AssertPointer();
|
if (ret == B_OK) {
|
||||||
data->AddData("_data", B_RAW_TYPE, fBasePointer, fSize);
|
const_cast<BBitmap *>(this)->_AssertPointer();
|
||||||
|
ret = data->AddData("_data", B_RAW_TYPE, fBasePointer, fSize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
if (ret == B_OK)
|
||||||
|
ret = data->AddString("class", "BBitmap");
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitCheck
|
// InitCheck
|
||||||
|
|||||||
Reference in New Issue
Block a user