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

View File

@ -37,14 +37,23 @@ 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;
delete fIcon;
}
//MediaListItem - DrawItem
void
void
LanguageListItem::DrawItem(BView *owner, BRect frame, bool complete)
{
rgb_color kHighlight = { 140,140,140,0 };
@ -66,7 +75,7 @@ LanguageListItem::DrawItem(BView *owner, BRect frame, bool complete)
} else {
owner->SetLowColor(owner->ViewColor());
}
frame.left += 4;
BRect iconFrame(frame);
iconFrame.Set(iconFrame.left, iconFrame.top+1, iconFrame.left+15, iconFrame.top+16);
@ -79,7 +88,7 @@ LanguageListItem::DrawItem(BView *owner, BRect frame, bool complete)
frame.left += 16 * (OutlineLevel() + 1);
owner->SetHighColor(kBlack);
BFont font = be_plain_font;
font_height finfo;
font.GetHeight(&finfo);
@ -193,7 +202,7 @@ void LanguageListView::MessageReceived (BMessage* message)
// Item has a parent
fDropIndex = FullListIndexOf(Superitem(FullListItemAt(fDropIndex)));
}
// Item is now a top level one - we must insert just below its last child
fDropIndex += CountItemsUnder(FullListItemAt(fDropIndex),false) + 1;
@ -355,7 +364,7 @@ LanguageListView::MouseMoved(BPoint where, uint32 transit, const BMessage* msg)
// offset where by half of item height
BRect r = ItemFrame(0);
where.y += r.Height() / 2.0;
int32 index = FullListIndexOf(where);
if (index < 0)
index = FullListCountItems();

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);

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
@ -54,7 +63,7 @@ LocaleWindow::LocaleWindow()
BView* languageTab = new BView(TR("Language"), B_WILL_DRAW);
languageTab->SetLayout(new BGroupLayout(B_VERTICAL, 0));
{
// first list: available languages
fLanguageListView = new LanguageListView("available",
@ -161,7 +170,7 @@ LocaleWindow::LocaleWindow()
BScrollView* scrollView = new BScrollView("scroller",
listView, B_WILL_DRAW | B_FRAME_EVENTS, false, true);
listView->SetSelectionMessage(new BMessage(kMsgCountrySelection));
// get all available countries from ICU
// Use DateFormat::getAvailableLocale so we get only the one we can
// use. Maybe check the NumberFormat one and see if there is more.