(libinterface) Optional bitmap-ownership with BitmapMenuItem
This commit is contained in:
parent
6d8be225ca
commit
71917d4a4d
|
@ -6,12 +6,13 @@
|
||||||
#include "BitmapMenuItem.h"
|
#include "BitmapMenuItem.h"
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
|
|
||||||
|
|
||||||
BitmapMenuItem::BitmapMenuItem(const char* label, BMessage* msg,
|
BitmapMenuItem::BitmapMenuItem(const char* label, BMessage* msg,
|
||||||
BBitmap *bitmap, char shortcut,
|
BBitmap* bitmap, char shortcut, uint32 modifiers, bool ownership)
|
||||||
uint32 modifiers)
|
|
||||||
:
|
:
|
||||||
BMenuItem(label, msg, shortcut, modifiers),
|
BMenuItem(label, msg, shortcut, modifiers),
|
||||||
fBitmap(bitmap)
|
fBitmap(bitmap),
|
||||||
|
fOwnership(ownership)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ BitmapMenuItem::BitmapMenuItem(BMessage *data)
|
||||||
|
|
||||||
BitmapMenuItem::~BitmapMenuItem(void)
|
BitmapMenuItem::~BitmapMenuItem(void)
|
||||||
{
|
{
|
||||||
|
if (fOwnership == true)
|
||||||
delete fBitmap;
|
delete fBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +109,7 @@ BitmapMenuItem::DrawContent(void)
|
||||||
void
|
void
|
||||||
BitmapMenuItem::SetBitmap(BBitmap *bitmap)
|
BitmapMenuItem::SetBitmap(BBitmap *bitmap)
|
||||||
{
|
{
|
||||||
|
if (fOwnership == true)
|
||||||
delete fBitmap;
|
delete fBitmap;
|
||||||
fBitmap = bitmap;
|
fBitmap = bitmap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
/*
|
/*
|
||||||
BitmapMenuItems are simple little items, really. They provide the
|
BitmapMenuItems are simple little items, really. They provide the
|
||||||
ability to show a menu item with some text, a picture, or both. The item
|
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
|
Note that it is still possible to see the checkmark on marked
|
||||||
BitmapMenuItems -- the bitmap does not obscure the checkmark.
|
BitmapMenuItems -- the bitmap does not obscure the checkmark.
|
||||||
*/
|
*/
|
||||||
|
@ -20,9 +20,10 @@ class BitmapMenuItem : public BMenuItem {
|
||||||
public:
|
public:
|
||||||
BitmapMenuItem(const char* label, BMessage* msg,
|
BitmapMenuItem(const char* label, BMessage* msg,
|
||||||
BBitmap* bitmap, char shortcut = 0,
|
BBitmap* bitmap, char shortcut = 0,
|
||||||
uint32 modifiers = 0);
|
uint32 modifiers = 0, bool ownership = true);
|
||||||
BitmapMenuItem(BMessage* data);
|
BitmapMenuItem(BMessage* data);
|
||||||
virtual ~BitmapMenuItem(void);
|
virtual ~BitmapMenuItem(void);
|
||||||
|
|
||||||
virtual status_t Archive(BMessage* data, bool deep = true) const;
|
virtual status_t Archive(BMessage* data, bool deep = true) const;
|
||||||
|
|
||||||
virtual void GetContentSize(float* width, float* height);
|
virtual void GetContentSize(float* width, float* height);
|
||||||
|
@ -34,6 +35,7 @@ public:
|
||||||
private:
|
private:
|
||||||
BBitmap* fBitmap;
|
BBitmap* fBitmap;
|
||||||
float fBaselineOffset;
|
float fBaselineOffset;
|
||||||
|
bool fOwnership;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Ŝarĝante…
Reference in New Issue