Fix leak of all icon bitmaps
Originally committed to SVN as r5471.
This commit is contained in:
parent
7842ccbeb1
commit
1e2abbd45a
7 changed files with 18 additions and 19 deletions
|
@ -76,14 +76,14 @@ enum AudioBoxControlIDs {
|
|||
|
||||
static void add_button(wxWindow *parent, wxSizer *sizer, int border, const char *command) {
|
||||
cmd::Command *c = cmd::get(command);
|
||||
wxBitmapButton *btn = new wxBitmapButton(parent, cmd::id(command), *c->Icon(16));
|
||||
wxBitmapButton *btn = new wxBitmapButton(parent, cmd::id(command), c->Icon(16));
|
||||
ToolTipManager::Bind(btn, c->StrHelp(), "Audio", command);
|
||||
sizer->Add(btn, 0, wxRIGHT, border);
|
||||
}
|
||||
|
||||
static void add_option(wxWindow *parent, wxSizer *sizer, int border, const char *command, const char *option) {
|
||||
cmd::Command *c = cmd::get(command);
|
||||
ToggleBitmap *btn = new ToggleBitmap(parent, cmd::id(command), *c->Icon(16), wxSize(20, -1));
|
||||
ToggleBitmap *btn = new ToggleBitmap(parent, cmd::id(command), c->Icon(16), wxSize(20, -1));
|
||||
ToolTipManager::Bind(btn, c->StrHelp(), "Audio", command);
|
||||
btn->SetValue(OPT_GET(option)->GetBool());
|
||||
sizer->Add(btn, 0, wxRIGHT | wxALIGN_CENTER | wxEXPAND, border);
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace cmd {
|
|||
}
|
||||
}
|
||||
|
||||
wxBitmap* Command::Icon(int size) {
|
||||
wxBitmap const& Command::Icon(int size) {
|
||||
if (size == 16) {
|
||||
return icon::get(name(), 16);
|
||||
} else if (size == 24) {
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace cmd {
|
|||
|
||||
/// Request icon.
|
||||
/// @param size Icon size.
|
||||
wxBitmap* Icon(int size);
|
||||
wxBitmap const& Icon(int size);
|
||||
|
||||
/// Command function
|
||||
virtual void operator()(agi::Context *c)=0;
|
||||
|
|
|
@ -33,13 +33,12 @@
|
|||
#include "../libresrc/bitmap.h"
|
||||
|
||||
namespace icon {
|
||||
typedef std::map<std::string, wxBitmap*> iconMap;
|
||||
typedef std::pair<std::string, wxBitmap*> iconPair;
|
||||
typedef std::map<std::string, wxBitmap> iconMap;
|
||||
|
||||
iconMap icon16;
|
||||
iconMap icon24;
|
||||
|
||||
wxBitmap* get(std::string const& name, const int size) {
|
||||
wxBitmap const& get(std::string const& name, const int size) {
|
||||
// XXX: This code will go away with dynamic icon generation so I'm not
|
||||
// concerned about it.
|
||||
if (size != 24) {
|
||||
|
@ -58,21 +57,21 @@ wxBitmap* get(std::string const& name, const int size) {
|
|||
}
|
||||
printf("icon::get NOT FOUND (%s)\n", name.c_str());
|
||||
}
|
||||
return new wxBitmap();
|
||||
static wxBitmap empty;
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
wxBitmap* getimage(const unsigned char *buff, size_t size) {
|
||||
wxBitmap getimage(const unsigned char *buff, size_t size) {
|
||||
wxMemoryInputStream mem(buff, size);
|
||||
wxImage img(mem);
|
||||
wxBitmap *bitmap = new wxBitmap(img);
|
||||
return bitmap;
|
||||
return wxBitmap(img);
|
||||
}
|
||||
|
||||
|
||||
#define INSERT_ICON(a, b) \
|
||||
icon16.insert(iconPair(a, getimage(b##_16, sizeof(b##_16)))); \
|
||||
icon24.insert(iconPair(a, getimage(b##_24, sizeof(b##_24))));
|
||||
icon16.insert(std::make_pair(a, getimage(b##_16, sizeof(b##_16)))); \
|
||||
icon24.insert(std::make_pair(a, getimage(b##_24, sizeof(b##_24))));
|
||||
|
||||
|
||||
void icon_init() {
|
||||
|
|
|
@ -29,5 +29,5 @@ DEFINE_SIMPLE_EXCEPTION_NOINNER(IconInvalid, IconError, "icon/invalid")
|
|||
|
||||
namespace icon {
|
||||
void icon_init();
|
||||
wxBitmap* get(std::string const& name, int size);
|
||||
wxBitmap const& get(std::string const& name, int size);
|
||||
}
|
||||
|
|
|
@ -107,9 +107,9 @@ namespace {
|
|||
else {
|
||||
cmd::Command *command = cmd::get(command_name.Value());
|
||||
|
||||
wxBitmap *bitmap = command->Icon(icon_size);
|
||||
wxBitmap const& bitmap = command->Icon(icon_size);
|
||||
// this hack is needed because ???
|
||||
wxBitmap icon = bitmap->GetSubBitmap(wxRect(0, 0, bitmap->GetWidth(), bitmap->GetHeight()));
|
||||
wxBitmap icon = bitmap.GetSubBitmap(wxRect(0, 0, bitmap.GetWidth(), bitmap.GetHeight()));
|
||||
|
||||
int flags = command->Type();
|
||||
wxItemKind kind =
|
||||
|
|
|
@ -65,14 +65,14 @@
|
|||
|
||||
static void add_button(wxWindow *parent, wxSizer *sizer, const char *command) {
|
||||
cmd::Command *c = cmd::get(command);
|
||||
wxBitmapButton *btn = new wxBitmapButton(parent, cmd::id(command), *c->Icon(24));
|
||||
wxBitmapButton *btn = new wxBitmapButton(parent, cmd::id(command), c->Icon(24));
|
||||
ToolTipManager::Bind(btn, c->StrHelp(), "Video", command);
|
||||
sizer->Add(btn, 0, wxTOP | wxLEFT | wxBOTTOM | wxALIGN_CENTER, 2);;
|
||||
}
|
||||
|
||||
static void add_option(wxWindow *parent, wxSizer *sizer, const char *command, const char *option) {
|
||||
cmd::Command *c = cmd::get(command);
|
||||
ToggleBitmap *btn = new ToggleBitmap(parent, cmd::id(command), *c->Icon(24));
|
||||
ToggleBitmap *btn = new ToggleBitmap(parent, cmd::id(command), c->Icon(24));
|
||||
ToolTipManager::Bind(btn, c->StrHelp(), "Video", command);
|
||||
btn->SetValue(OPT_GET(option)->GetBool());
|
||||
sizer->Add(btn, 0, wxTOP | wxLEFT | wxBOTTOM | wxALIGN_CENTER, 2);
|
||||
|
@ -121,7 +121,7 @@ VideoBox::VideoBox(wxWindow *parent, bool isDetached, agi::Context *context)
|
|||
visualToolBar->AddTool(Video_Mode_Clip,_("Clip"),GETIMAGE(visual_clip_24),_("Clip subtitles to a rectangle."),wxITEM_RADIO);
|
||||
visualToolBar->AddTool(Video_Mode_Vector_Clip,_("Vector Clip"),GETIMAGE(visual_vector_clip_24),_("Clip subtitles to a vectorial area."),wxITEM_RADIO);
|
||||
visualToolBar->AddSeparator();
|
||||
visualToolBar->AddTool(cmd::id("help/video"),_("Help"),*cmd::get("help/video")->Icon(24),_("Open the manual page for Visual Typesetting."));
|
||||
visualToolBar->AddTool(cmd::id("help/video"),_("Help"),cmd::get("help/video")->Icon(24),_("Open the manual page for Visual Typesetting."));
|
||||
visualToolBar->Realize();
|
||||
// Avoid ugly themed background on Vista and possibly also Win7
|
||||
visualToolBar->SetBackgroundStyle(wxBG_STYLE_COLOUR);
|
||||
|
|
Loading…
Reference in a new issue