diff --git a/src/preferences/locale/LanguageListView.cpp b/src/preferences/locale/LanguageListView.cpp index 332031ecee..e59ff065d2 100644 --- a/src/preferences/locale/LanguageListView.cpp +++ b/src/preferences/locale/LanguageListView.cpp @@ -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(); diff --git a/src/preferences/locale/LanguageListView.h b/src/preferences/locale/LanguageListView.h index 5134bd0c6a..907cbbd8c3 100644 --- a/src/preferences/locale/LanguageListView.h +++ b/src/preferences/locale/LanguageListView.h @@ -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); diff --git a/src/preferences/locale/LocaleWindow.cpp b/src/preferences/locale/LocaleWindow.cpp index 91510ff28b..25c2fffc88 100644 --- a/src/preferences/locale/LocaleWindow.cpp +++ b/src/preferences/locale/LocaleWindow.cpp @@ -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.