Bitmaps are now owned (and deleted) by BitmapMenuItem, small changes. Added a check for NULL which cures the symptoms of a bug in resource loading. Even if we fix the bug, this is defensive programming
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15355 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
// System Headers
|
||||
#ifndef _NODE_INFO_H
|
||||
#include <Bitmap.h>
|
||||
#include <NodeInfo.h>
|
||||
#endif
|
||||
|
||||
// Project Headers
|
||||
#include "BitmapMenuItem.h"
|
||||
@@ -9,32 +7,39 @@
|
||||
|
||||
// BitmapMenuItem class definition
|
||||
BitmapMenuItem::BitmapMenuItem(const char* name, BMessage* message,
|
||||
BBitmap* bmp, char shortcut, uint32 modifiers)
|
||||
: BMenuItem(name, message, shortcut, modifiers)
|
||||
BBitmap* bmp, char shortcut, uint32 modifiers)
|
||||
:
|
||||
BMenuItem(name, message, shortcut, modifiers),
|
||||
fBitmap(bmp),
|
||||
fName(name)
|
||||
{
|
||||
fBmp = bmp;
|
||||
fName.SetTo(name);
|
||||
|
||||
fCheckBmp = BTranslationUtils::GetBitmap(B_RAW_TYPE, "CHECK");
|
||||
}
|
||||
|
||||
void BitmapMenuItem::DrawContent(void)
|
||||
|
||||
BitmapMenuItem::~BitmapMenuItem()
|
||||
{
|
||||
delete fBitmap;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BitmapMenuItem::DrawContent()
|
||||
{
|
||||
BRect dr;
|
||||
|
||||
BMenu* menu = Menu();
|
||||
|
||||
// if we don't have a menu, get out...
|
||||
if (!menu) return;
|
||||
if (!menu)
|
||||
return;
|
||||
|
||||
BRect itemFrame = Frame();
|
||||
|
||||
menu->MovePenTo(itemFrame.left + 38, itemFrame.top + 2);
|
||||
BMenuItem::DrawContent();
|
||||
|
||||
BRect bitmapFrame = fBmp->Bounds();
|
||||
dr.Set(itemFrame.left + 14, itemFrame.top + 2, itemFrame.left + 14 + bitmapFrame.right, itemFrame.top + 17);
|
||||
menu->SetDrawingMode(B_OP_OVER);
|
||||
menu->DrawBitmap(fBmp, bitmapFrame, dr);
|
||||
menu->SetDrawingMode(B_OP_COPY);
|
||||
if (fBitmap != NULL) {
|
||||
BRect bitmapFrame = fBitmap->Bounds();
|
||||
BRect dr(itemFrame.left + 14, itemFrame.top + 2, itemFrame.left + 14 + bitmapFrame.right, itemFrame.top + 17);
|
||||
menu->SetDrawingMode(B_OP_OVER);
|
||||
menu->DrawBitmap(fBitmap, bitmapFrame, dr);
|
||||
menu->SetDrawingMode(B_OP_COPY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,22 @@
|
||||
#ifndef _MBitmapMenuItem_h
|
||||
#define _MBitmapMenuItem_h
|
||||
|
||||
// System Headers
|
||||
#include <Bitmap.h>
|
||||
#include <MenuItem.h>
|
||||
#ifndef _TRANSLATION_UTILS_H
|
||||
#include <TranslationUtils.h>
|
||||
#endif
|
||||
#include <String.h>
|
||||
|
||||
class BBitmap;
|
||||
|
||||
// MBitmapMenuItem class declaration
|
||||
class BitmapMenuItem : public BMenuItem
|
||||
{
|
||||
class BitmapMenuItem : public BMenuItem {
|
||||
public:
|
||||
BitmapMenuItem(const char* name, BMessage* message, BBitmap* bmp,
|
||||
char shortcut = 0, uint32 modifiers = 0);
|
||||
virtual void DrawContent(void);
|
||||
BitmapMenuItem(const char* name, BMessage* message, BBitmap* bmp,
|
||||
char shortcut = 0, uint32 modifiers = 0);
|
||||
~BitmapMenuItem();
|
||||
virtual void DrawContent();
|
||||
|
||||
private:
|
||||
BBitmap *fBmp;
|
||||
BString fName;
|
||||
BBitmap *fCheckBmp;
|
||||
BBitmap *fBitmap;
|
||||
BString fName;
|
||||
};
|
||||
|
||||
#endif // _MBitmapMenuItem_h
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
class MenuBar : public BMenuBar {
|
||||
public:
|
||||
MenuBar();
|
||||
virtual ~MenuBar();
|
||||
void set_menu();
|
||||
void build_menu();
|
||||
virtual void Update();
|
||||
@@ -59,12 +58,12 @@
|
||||
menu_info info;
|
||||
|
||||
//bitmaps
|
||||
BBitmap *fCtlBmp;
|
||||
/*BBitmap *fCtlBmp;
|
||||
BBitmap *fAltBmp;
|
||||
BBitmap *fSep0Bmp;
|
||||
BBitmap *fSep1Bmp;
|
||||
BBitmap *fSep2Bmp;
|
||||
|
||||
*/
|
||||
//seperator submenu
|
||||
BMenu *separatorStyleMenu;
|
||||
BMenuItem *separatorStyleZero;
|
||||
|
||||
@@ -1,26 +1,20 @@
|
||||
#include "MenuApp.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <Application.h>
|
||||
#include <Resources.h>
|
||||
#include <Application.h>
|
||||
#include <TranslationUtils.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
MenuBar::MenuBar()
|
||||
:BMenuBar(BRect(40,10,10,10), "menu", B_FOLLOW_TOP|B_FRAME_EVENTS, B_ITEMS_IN_COLUMN, true)
|
||||
{
|
||||
fCtlBmp = BTranslationUtils::GetBitmap(B_RAW_TYPE, "CTL");
|
||||
fAltBmp = BTranslationUtils::GetBitmap(B_RAW_TYPE, "ALT");
|
||||
fSep0Bmp = BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP0");
|
||||
fSep1Bmp = BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP1");
|
||||
fSep2Bmp = BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP2");
|
||||
|
||||
|
||||
get_menu_info(&info);
|
||||
build_menu();
|
||||
set_menu();
|
||||
}
|
||||
|
||||
MenuBar::~MenuBar()
|
||||
{ /*nothing to clean up*/}
|
||||
|
||||
void
|
||||
MenuBar::build_menu()
|
||||
@@ -33,8 +27,10 @@
|
||||
clickToOpenItem = new BMenuItem("Click To Open", new BMessage(CLICK_OPEN_MSG), 0, 0);
|
||||
alwaysShowTriggersItem = new BMenuItem("Always Show Triggers", new BMessage(ALLWAYS_TRIGGERS_MSG), 0, 0);
|
||||
separatorStyleItem = new BMenuItem("Separator Style", new BMessage(DEFAULT_MSG), 0, 0);
|
||||
ctlAsShortcutItem = new BitmapMenuItem("as Shortcut Key", new BMessage(CTL_MARKED_MSG), fCtlBmp);
|
||||
altAsShortcutItem = new BitmapMenuItem("as Shortcut Key", new BMessage(ALT_MARKED_MSG), fAltBmp);
|
||||
ctlAsShortcutItem = new BitmapMenuItem("as Shortcut Key",
|
||||
new BMessage(CTL_MARKED_MSG), BTranslationUtils::GetBitmap(B_RAW_TYPE, "CTL"));
|
||||
altAsShortcutItem = new BitmapMenuItem("as Shortcut Key",
|
||||
new BMessage(ALT_MARKED_MSG), BTranslationUtils::GetBitmap(B_RAW_TYPE, "ALT"));
|
||||
|
||||
// color menu
|
||||
colorSchemeItem = new BMenuItem("Color Scheme...", new BMessage(COLOR_SCHEME_MSG), 0, 0);
|
||||
@@ -44,13 +40,14 @@
|
||||
separatorStyleMenu->SetRadioMode(true);
|
||||
BMessage *msg = new BMessage(MENU_SEP_TYPE);
|
||||
msg->AddInt32("sep", 0);
|
||||
separatorStyleZero = new BitmapMenuItem(" ", msg, fSep0Bmp);
|
||||
separatorStyleZero = new BitmapMenuItem(" ", msg,
|
||||
BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP0"));
|
||||
msg = new BMessage(MENU_SEP_TYPE);
|
||||
msg->AddInt32("sep", 1);
|
||||
separatorStyleOne = new BitmapMenuItem("", msg, fSep1Bmp);
|
||||
separatorStyleOne = new BitmapMenuItem("", msg, BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP1"));
|
||||
msg = new BMessage(MENU_SEP_TYPE);
|
||||
msg->AddInt32("sep", 2);
|
||||
separatorStyleTwo = new BitmapMenuItem("", msg, fSep2Bmp);
|
||||
separatorStyleTwo = new BitmapMenuItem("", msg, BTranslationUtils::GetBitmap(B_RAW_TYPE, "SEP2"));
|
||||
if (info.separator == 0)
|
||||
separatorStyleZero->SetMarked(true);
|
||||
if (info.separator == 1)
|
||||
@@ -81,8 +78,8 @@
|
||||
MenuBar::set_menu()
|
||||
{
|
||||
key_map *keys;
|
||||
char *chars;
|
||||
bool altAsShortcut;
|
||||
char *chars;
|
||||
bool altAsShortcut;
|
||||
|
||||
// get up-to-date menu info
|
||||
get_menu_info(&info);
|
||||
@@ -94,12 +91,12 @@
|
||||
|
||||
get_key_map(&keys, &chars);
|
||||
|
||||
altAsShortcut = (keys->left_command_key == 0x5d) && (keys->right_command_key == 0x5f);
|
||||
altAsShortcutItem->SetMarked(altAsShortcut);
|
||||
ctlAsShortcutItem->SetMarked(!altAsShortcut);
|
||||
altAsShortcut = (keys->left_command_key == 0x5d) && (keys->right_command_key == 0x5f);
|
||||
altAsShortcutItem->SetMarked(altAsShortcut);
|
||||
ctlAsShortcutItem->SetMarked(!altAsShortcut);
|
||||
|
||||
free(chars);
|
||||
free(keys);
|
||||
free(chars);
|
||||
free(keys);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user