diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-02-14 20:56:14 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-02-15 15:52:04 +0000 |
commit | 7aae1678ec974220f0f245d731f201054ccbc1df (patch) | |
tree | 01921760e68bd66d6f693697ea2233d74c5140be /vcl/source | |
parent | 6b0733a00b1b038fe20072984c87233c891660c8 (diff) |
use Natural sort as default sort for listboxes, etc.
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/app/unohelp.cxx | 16 | ||||
-rw-r--r-- | vcl/source/control/ilstbox.cxx | 45 |
2 files changed, 29 insertions, 32 deletions
diff --git a/vcl/source/app/unohelp.cxx b/vcl/source/app/unohelp.cxx index b33d252f6bb1..ce3b2f2a1018 100644 --- a/vcl/source/app/unohelp.cxx +++ b/vcl/source/app/unohelp.cxx @@ -171,22 +171,6 @@ uno::Reference < i18n::XCharacterClassification > vcl::unohelper::CreateCharacte return xB; } -uno::Reference < i18n::XCollator > vcl::unohelper::CreateCollator() -{ - uno::Reference < i18n::XCollator > xB; - uno::Reference< lang::XMultiServiceFactory > xMSF = GetMultiServiceFactory(); - if ( xMSF.is() ) - { - uno::Reference < uno::XInterface > xI = xMSF->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.i18n.Collator")) ); - if ( xI.is() ) - { - uno::Any x = xI->queryInterface( ::getCppuType((const uno::Reference< i18n::XCollator >*)0) ); - x >>= xB; - } - } - return xB; -} - ::rtl::OUString vcl::unohelper::CreateLibraryName( const sal_Char* pModName, sal_Bool bSUPD ) { // create variable library name suffixes diff --git a/vcl/source/control/ilstbox.cxx b/vcl/source/control/ilstbox.cxx index b0ad4efe50ca..2ece83f6d392 100644 --- a/vcl/source/control/ilstbox.cxx +++ b/vcl/source/control/ilstbox.cxx @@ -46,6 +46,10 @@ #include <com/sun/star/accessibility/AccessibleRole.hpp> +#include <rtl/instance.hxx> +#include <comphelper/string.hxx> +#include <comphelper/processfactory.hxx> + #define MULTILINE_ENTRY_DRAW_FLAGS ( TEXT_DRAW_WORDBREAK | TEXT_DRAW_MULTILINE | TEXT_DRAW_VCENTER ) using namespace ::com::sun::star; @@ -144,17 +148,29 @@ void ImplEntryList::SelectEntry( USHORT nPos, BOOL bSelect ) } } -// ----------------------------------------------------------------------- - -uno::Reference< i18n::XCollator > ImplGetCollator (lang::Locale &rLocale) +namespace { - static uno::Reference< i18n::XCollator > xCollator; - if ( !xCollator.is() ) - xCollator = vcl::unohelper::CreateCollator(); - if( xCollator.is() ) - xCollator->loadDefaultCollator (rLocale, 0); + struct theSorter + : public rtl::StaticWithInit< comphelper::string::NaturalStringSorter, theSorter > + { + comphelper::string::NaturalStringSorter operator () () + { + return comphelper::string::NaturalStringSorter( + ::comphelper::getProcessComponentContext(), + Application::GetSettings().GetLocale()); + } + }; +} - return xCollator; +namespace vcl +{ + namespace unohelper + { + const comphelper::string::NaturalStringSorter& getNaturalStringSorterForAppLocale() + { + return theSorter::get(); + } + } } USHORT ImplEntryList::InsertEntry( USHORT nPos, ImplEntryType* pNewEntry, BOOL bSort ) @@ -168,8 +184,7 @@ USHORT ImplEntryList::InsertEntry( USHORT nPos, ImplEntryType* pNewEntry, BOOL b } else { - lang::Locale aLocale = Application::GetSettings().GetLocale(); - uno::Reference< i18n::XCollator > xCollator = ImplGetCollator(aLocale); + const comphelper::string::NaturalStringSorter &rSorter = theSorter::get(); const XubString& rStr = pNewEntry->maStr; ULONG nLow, nHigh, nMid; @@ -182,9 +197,7 @@ USHORT ImplEntryList::InsertEntry( USHORT nPos, ImplEntryType* pNewEntry, BOOL b { // XXX even though XCollator::compareString returns a sal_Int32 the only // defined values are {-1, 0, 1} which is compatible with StringCompare - StringCompare eComp = xCollator.is() ? - (StringCompare)xCollator->compareString (rStr, pTemp->maStr) - : COMPARE_EQUAL; + StringCompare eComp = (StringCompare)rSorter.compare(rStr, pTemp->maStr); // Schnelles Einfuegen bei sortierten Daten if ( eComp != COMPARE_LESS ) @@ -196,7 +209,7 @@ USHORT ImplEntryList::InsertEntry( USHORT nPos, ImplEntryType* pNewEntry, BOOL b nLow = mnMRUCount; pTemp = (ImplEntryType*)GetEntry( (USHORT)nLow ); - eComp = (StringCompare)xCollator->compareString (rStr, pTemp->maStr); + eComp = (StringCompare)rSorter.compare(rStr, pTemp->maStr); if ( eComp != COMPARE_GREATER ) { Insert( pNewEntry, (ULONG)0 ); @@ -210,7 +223,7 @@ USHORT ImplEntryList::InsertEntry( USHORT nPos, ImplEntryType* pNewEntry, BOOL b nMid = (nLow + nHigh) / 2; pTemp = (ImplEntryType*)GetObject( nMid ); - eComp = (StringCompare)xCollator->compareString (rStr, pTemp->maStr); + eComp = (StringCompare)rSorter.compare(rStr, pTemp->maStr); if ( eComp == COMPARE_LESS ) nHigh = nMid-1; |