Return error code when bitmap changes.

This commit is contained in:
plfiorini 2010-06-15 17:09:31 +00:00
parent 1cd3ad8d26
commit bf2f726629
2 changed files with 26 additions and 13 deletions

View File

@ -6,6 +6,8 @@
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
*/ */
#include <new>
#include <Bitmap.h> #include <Bitmap.h>
#include <LayoutUtils.h> #include <LayoutUtils.h>
#include <TranslationUtils.h> #include <TranslationUtils.h>
@ -57,28 +59,38 @@ BitmapView::Bitmap() const
} }
void status_t
BitmapView::SetBitmap(const char* filename) BitmapView::SetBitmap(const char* filename)
{ {
delete fBitmap; delete fBitmap;
fBitmap = BTranslationUtils::GetBitmap(filename); fBitmap = BTranslationUtils::GetBitmap(filename);
if (fBitmap == NULL)
return B_ERROR;
return B_OK;
} }
void status_t
BitmapView::SetBitmap(BBitmap* bitmap) BitmapView::SetBitmap(const BBitmap* bitmap)
{ {
delete fBitmap; delete fBitmap;
fBitmap = bitmap; fBitmap = NULL;
if (fBitmap) { if (bitmap != NULL) {
BRect frame(fBitmap->Bounds()); fBitmap = new(std::nothrow) BBitmap(bitmap);
if (fBitmap == NULL)
fWidth = frame.Width(); return B_NO_MEMORY;
fHeight = frame.Height(); if (fBitmap->InitCheck() != B_OK)
return fBitmap->InitCheck();
fWidth = fBitmap->Bounds().Width();
fHeight = fBitmap->Bounds().Height();
Invalidate(); Invalidate();
} }
return B_OK;
} }
@ -109,7 +121,7 @@ BitmapView::PreferredSize()
void void
BitmapView::Draw(BRect frame) BitmapView::Draw(BRect frame)
{ {
if (!fBitmap) if (fBitmap == NULL)
return; return;
SetDrawingMode(B_OP_ALPHA); SetDrawingMode(B_OP_ALPHA);

View File

@ -11,7 +11,7 @@ class BBitmap;
class BitmapView : public BView { class BitmapView : public BView {
public: public:
BitmapView(const char* name, uint32 flags BitmapView(const char* name = NULL, uint32 flags
= B_WILL_DRAW); = B_WILL_DRAW);
~BitmapView(); ~BitmapView();
@ -20,8 +20,9 @@ public:
status_t InitCheck(); status_t InitCheck();
BBitmap* Bitmap() const; BBitmap* Bitmap() const;
void SetBitmap(const char* filename);
void SetBitmap(BBitmap* bitmap); status_t SetBitmap(const char* filename);
status_t SetBitmap(const BBitmap* bitmap);
virtual BSize MinSize(); virtual BSize MinSize();
virtual BSize MaxSize(); virtual BSize MaxSize();