diff --git a/libs/libinterface/BitmapView.cpp b/libs/libinterface/BitmapView.cpp index 6210e64..89a50c2 100644 --- a/libs/libinterface/BitmapView.cpp +++ b/libs/libinterface/BitmapView.cpp @@ -6,6 +6,8 @@ * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com */ +#include + #include #include #include @@ -57,28 +59,38 @@ BitmapView::Bitmap() const } -void +status_t BitmapView::SetBitmap(const char* filename) { delete fBitmap; + fBitmap = BTranslationUtils::GetBitmap(filename); + if (fBitmap == NULL) + return B_ERROR; + + return B_OK; } -void -BitmapView::SetBitmap(BBitmap* bitmap) +status_t +BitmapView::SetBitmap(const BBitmap* bitmap) { delete fBitmap; - fBitmap = bitmap; + fBitmap = NULL; - if (fBitmap) { - BRect frame(fBitmap->Bounds()); - - fWidth = frame.Width(); - fHeight = frame.Height(); + if (bitmap != NULL) { + fBitmap = new(std::nothrow) BBitmap(bitmap); + if (fBitmap == NULL) + return B_NO_MEMORY; + if (fBitmap->InitCheck() != B_OK) + return fBitmap->InitCheck(); + fWidth = fBitmap->Bounds().Width(); + fHeight = fBitmap->Bounds().Height(); Invalidate(); } + + return B_OK; } @@ -109,7 +121,7 @@ BitmapView::PreferredSize() void BitmapView::Draw(BRect frame) { - if (!fBitmap) + if (fBitmap == NULL) return; SetDrawingMode(B_OP_ALPHA); diff --git a/libs/libinterface/BitmapView.h b/libs/libinterface/BitmapView.h index 5b1abba..93c2349 100644 --- a/libs/libinterface/BitmapView.h +++ b/libs/libinterface/BitmapView.h @@ -11,7 +11,7 @@ class BBitmap; class BitmapView : public BView { public: - BitmapView(const char* name, uint32 flags + BitmapView(const char* name = NULL, uint32 flags = B_WILL_DRAW); ~BitmapView(); @@ -20,8 +20,9 @@ public: status_t InitCheck(); 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 MaxSize();