From fff7b3cd5d86bb012f6137c5ddf52305f82ab837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 10 Nov 2005 15:40:22 +0000 Subject: [PATCH] Now also sorts the font list - unlike the app_server, it could also take the user's locale into account. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14827 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Font.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/kits/interface/Font.cpp b/src/kits/interface/Font.cpp index abcdf4ab70..fb596a1c7b 100644 --- a/src/kits/interface/Font.cpp +++ b/src/kits/interface/Font.cpp @@ -89,6 +89,17 @@ class FontList : public BLocker { static BPrivate::FontList sFontList; +// #pragma mark - + + +static int +compare_families(const family* a, const family* b) +{ + // TODO: compare font names according to the user's locale settings + return strcmp(a->name.String(), b->name.String()); +} + + namespace BPrivate { FontList::FontList() @@ -179,7 +190,7 @@ FontList::_Update() family->styles.AddItem(style); } - fFamilies.AddItem(family); + fFamilies.BinaryInsert(family, compare_families); } fRevision = revision; @@ -209,16 +220,10 @@ FontList::_FindFamily(font_family name) if (fLastFamily != NULL && fLastFamily->name == name) return fLastFamily; - for (int32 i = 0; i < fFamilies.CountItems(); i++) { - family* family = fFamilies.ItemAt(i); - - if (family->name == name) { - fLastFamily = family; - return family; - } - } - - return NULL; + ::family family; + family.name = name; + fLastFamily = const_cast< ::family*>(fFamilies.BinarySearch(family, compare_families)); + return fLastFamily; }