(libinterface) Optional bitmap-ownership with BitmapMenuItem
This commit is contained in:
parent
6d8be225ca
commit
71917d4a4d
|
@ -6,17 +6,18 @@
|
|||
#include "BitmapMenuItem.h"
|
||||
#include <Bitmap.h>
|
||||
|
||||
BitmapMenuItem::BitmapMenuItem(const char *label, BMessage *msg,
|
||||
BBitmap *bitmap, char shortcut,
|
||||
uint32 modifiers)
|
||||
|
||||
BitmapMenuItem::BitmapMenuItem(const char* label, BMessage* msg,
|
||||
BBitmap* bitmap, char shortcut, uint32 modifiers, bool ownership)
|
||||
:
|
||||
BMenuItem(label,msg,shortcut,modifiers),
|
||||
fBitmap(bitmap)
|
||||
BMenuItem(label, msg, shortcut, modifiers),
|
||||
fBitmap(bitmap),
|
||||
fOwnership(ownership)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BitmapMenuItem::BitmapMenuItem(BMessage *data)
|
||||
BitmapMenuItem::BitmapMenuItem(BMessage* data)
|
||||
:
|
||||
BMenuItem(data)
|
||||
{
|
||||
|
@ -26,27 +27,28 @@ BitmapMenuItem::BitmapMenuItem(BMessage *data)
|
|||
|
||||
BitmapMenuItem::~BitmapMenuItem(void)
|
||||
{
|
||||
delete fBitmap;
|
||||
if (fOwnership == true)
|
||||
delete fBitmap;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BitmapMenuItem::Archive(BMessage *data, bool deep) const
|
||||
BitmapMenuItem::Archive(BMessage* data, bool deep) const
|
||||
{
|
||||
status_t status = BMenuItem::Archive(data,deep);
|
||||
status_t status = BMenuItem::Archive(data, deep);
|
||||
|
||||
if (status == B_OK && fBitmap)
|
||||
status = fBitmap->Archive(data,deep);
|
||||
status = fBitmap->Archive(data, deep);
|
||||
|
||||
if (status == B_OK)
|
||||
status = data->AddString("class","BitmapMenuItem");
|
||||
status = data->AddString("class", "BitmapMenuItem");
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BitmapMenuItem::GetContentSize(float *width, float *height)
|
||||
BitmapMenuItem::GetContentSize(float* width, float* height)
|
||||
{
|
||||
float w,h;
|
||||
BMenuItem::GetContentSize(&w,&h);
|
||||
|
@ -107,7 +109,8 @@ BitmapMenuItem::DrawContent(void)
|
|||
void
|
||||
BitmapMenuItem::SetBitmap(BBitmap *bitmap)
|
||||
{
|
||||
delete fBitmap;
|
||||
if (fOwnership == true)
|
||||
delete fBitmap;
|
||||
fBitmap = bitmap;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,29 +11,31 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
class BitmapMenuItem : public BMenuItem {
|
||||
public:
|
||||
BitmapMenuItem(const char *label, BMessage *msg,
|
||||
BBitmap *bitmap, char shortcut = 0,
|
||||
uint32 modifiers = 0);
|
||||
BitmapMenuItem(BMessage *data);
|
||||
virtual ~BitmapMenuItem(void);
|
||||
virtual status_t Archive(BMessage *data, bool deep = true) const;
|
||||
BitmapMenuItem(const char* label, BMessage* msg,
|
||||
BBitmap* bitmap, char shortcut = 0,
|
||||
uint32 modifiers = 0, bool ownership = true);
|
||||
BitmapMenuItem(BMessage* data);
|
||||
virtual ~BitmapMenuItem(void);
|
||||
|
||||
virtual void GetContentSize(float *width, float *height);
|
||||
virtual status_t Archive(BMessage* data, bool deep = true) const;
|
||||
|
||||
virtual void GetContentSize(float* width, float* height);
|
||||
virtual void DrawContent(void);
|
||||
|
||||
virtual void SetBitmap(BBitmap *bitmap);
|
||||
BBitmap* Bitmap(void) const { return fBitmap; }
|
||||
virtual void SetBitmap(BBitmap* bitmap);
|
||||
BBitmap* Bitmap(void) const { return fBitmap; }
|
||||
|
||||
private:
|
||||
BBitmap *fBitmap;
|
||||
BBitmap* fBitmap;
|
||||
float fBaselineOffset;
|
||||
bool fOwnership;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Ŝarĝante…
Reference in New Issue