Fix #5755: Locale preflet crashing when dragging languages around

* The flag bitmaps being part of list items were not treated properly in
  the language item's copy constructor (the bitmap pointer was copied, not
  the bitmap object itself). As a result, bitmap objects were freed more than 
  once. 
* some cleanup

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36487 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe
2010-04-26 13:43:06 +00:00
parent c1b8ab4ef0
commit 1d26f9e11c
3 changed files with 29 additions and 27 deletions
@@ -37,6 +37,15 @@ LanguageListItem::LanguageListItem(const char* text, const char* code)
}
LanguageListItem::LanguageListItem(const LanguageListItem& other)
:
BStringItem(other.Text()),
fLanguageCode(other.fLanguageCode),
fIcon(other.fIcon ? new(std::nothrow) BBitmap(other.fIcon) : NULL)
{
}
LanguageListItem::~LanguageListItem()
{
delete fIcon;
+3 -19
View File
@@ -19,34 +19,18 @@
class LanguageListItem: public BStringItem {
public:
LanguageListItem(const char* text, const char* code);
LanguageListItem(const LanguageListItem& other)
:
BStringItem(other.Text()),
fLanguageCode(other.fLanguageCode),
fIcon(other.fIcon)
{}
LanguageListItem(const LanguageListItem& other);
~LanguageListItem();
const inline BString LanguageCode() { return fLanguageCode; }
const BString& LanguageCode() { return fLanguageCode; }
void DrawItem(BView *owner, BRect frame, bool complete = false);
private:
const BString fLanguageCode;
BString fLanguageCode;
BBitmap* fIcon;
};
static int
compare_list_items(const void* _a, const void* _b)
{
LanguageListItem* a = *(LanguageListItem**)_a;
LanguageListItem* b = *(LanguageListItem**)_b;
return strcasecmp(a->Text(), b->Text());
}
class LanguageListView: public BOutlineListView {
public:
LanguageListView(const char* name, list_view_type type);
+9
View File
@@ -34,6 +34,15 @@
#define TR_CONTEXT "Locale Preflet Window"
static int
compare_list_items(const void* _a, const void* _b)
{
LanguageListItem* a = *(LanguageListItem**)_a;
LanguageListItem* b = *(LanguageListItem**)_b;
return strcasecmp(a->Text(), b->Text());
}
LocaleWindow::LocaleWindow()
:
BWindow(BRect(0, 0, 0, 0), "Locale", B_TITLED_WINDOW, B_NOT_RESIZABLE