(libinterface) Optional bitmap-ownership with BitmapMenuItem

This commit is contained in:
Jaidyn Ann 2021-08-03 10:15:04 -05:00
parent 6d8be225ca
commit 71917d4a4d
2 changed files with 29 additions and 24 deletions

View File

@ -6,12 +6,13 @@
#include "BitmapMenuItem.h"
#include <Bitmap.h>
BitmapMenuItem::BitmapMenuItem(const char* label, BMessage* msg,
BBitmap *bitmap, char shortcut,
uint32 modifiers)
BBitmap* bitmap, char shortcut, uint32 modifiers, bool ownership)
:
BMenuItem(label, msg, shortcut, modifiers),
fBitmap(bitmap)
fBitmap(bitmap),
fOwnership(ownership)
{
}
@ -26,6 +27,7 @@ BitmapMenuItem::BitmapMenuItem(BMessage *data)
BitmapMenuItem::~BitmapMenuItem(void)
{
if (fOwnership == true)
delete fBitmap;
}
@ -107,6 +109,7 @@ BitmapMenuItem::DrawContent(void)
void
BitmapMenuItem::SetBitmap(BBitmap *bitmap)
{
if (fOwnership == true)
delete fBitmap;
fBitmap = bitmap;
}

View File

@ -11,7 +11,7 @@
/*
BitmapMenuItems are simple little items, really. They provide the
ability to show a menu item with some text, a picture, or both. The item
takes ownership of the BBitmap given to it, so please do not delete it.
optionally takes ownership of the BBitmap given to it.
Note that it is still possible to see the checkmark on marked
BitmapMenuItems -- the bitmap does not obscure the checkmark.
*/
@ -20,9 +20,10 @@ class BitmapMenuItem : public BMenuItem {
public:
BitmapMenuItem(const char* label, BMessage* msg,
BBitmap* bitmap, char shortcut = 0,
uint32 modifiers = 0);
uint32 modifiers = 0, bool ownership = true);
BitmapMenuItem(BMessage* data);
virtual ~BitmapMenuItem(void);
virtual status_t Archive(BMessage* data, bool deep = true) const;
virtual void GetContentSize(float* width, float* height);
@ -34,6 +35,7 @@ public:
private:
BBitmap* fBitmap;
float fBaselineOffset;
bool fOwnership;
};
#endif