diff options
author | Christof Pintaske <cp@openoffice.org> | 2000-10-19 16:06:15 +0000 |
---|---|---|
committer | Christof Pintaske <cp@openoffice.org> | 2000-10-19 16:06:15 +0000 |
commit | 11aa19bff3fece2f08e1eb73c9397ad8b40b4274 (patch) | |
tree | d1aaf3abb076dd90687a78c4781068eacaef9ffc /vcl | |
parent | c1340314cef9ddf05789fadec7c7d88656b1388c (diff) |
use Collator::compareString service to insert entries
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/control/ilstbox.cxx | 111 |
1 files changed, 78 insertions, 33 deletions
diff --git a/vcl/source/control/ilstbox.cxx b/vcl/source/control/ilstbox.cxx index 3f1b977e7eab..19681d90d911 100644 --- a/vcl/source/control/ilstbox.cxx +++ b/vcl/source/control/ilstbox.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ilstbox.cxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: hr $ $Date: 2000-09-18 17:05:35 $ + * last change: $Author: cp $ $Date: 2000-10-19 17:06:15 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -91,8 +91,17 @@ #include <ilstbox.hxx> #endif +#ifndef _VCL_UNOHELP_HXX +#include <unohelp.hxx> +#endif +#ifndef _COM_SUN_STAR_UTIL_XCOLLATOR_HPP_ +#include <com/sun/star/util/XCollator.hpp> +#endif + #pragma hdrstop +using namespace ::com::sun::star; + // ======================================================================= void ImplInitFieldSettings( Window* pWin, BOOL bFont, BOOL bForeground, BOOL bBackground ) @@ -182,6 +191,15 @@ void ImplEntryList::SelectEntry( USHORT nPos, BOOL bSelect ) // ----------------------------------------------------------------------- +uno::Reference< util::XCollator > ImplGetCollator() +{ + static uno::Reference< util::XCollator > xCollator; + if ( !xCollator.is() ) + xCollator = vcl::unohelper::CreateCollator(); + + return xCollator; +} + USHORT ImplEntryList::InsertEntry( USHORT nPos, ImplEntryType* pNewEntry, BOOL bSort ) { if ( !!pNewEntry->maImage ) @@ -193,57 +211,84 @@ USHORT ImplEntryList::InsertEntry( USHORT nPos, ImplEntryType* pNewEntry, BOOL b } else { + // XXX the transliteration !IsValid(). This exploits that neither + // the i18n nor the i18n_simple implementation uses it yet + uno::Reference< util::XCollator > xCollator = ImplGetCollator(); + uno::Reference< util::XTransliteration > xTransliteration; + lang::Locale aLocale = Application::GetSettings().GetLocale(); + const XubString& rStr = pNewEntry->maStr; ULONG nLow, nHigh, nMid; nHigh = Count(); - const International& rIntl = Application::GetSettings().GetInternational(); ImplEntryType* pTemp = GetEntry( (USHORT)(nHigh-1) ); - StringCompare eComp = rIntl.Compare( rStr, pTemp->maStr ); - // Schnelles Einfuegen bei sortierten Daten - if ( eComp != COMPARE_LESS ) - { - Insert( pNewEntry, LIST_APPEND ); - } - else + try { - nLow = mnMRUCount; - pTemp = (ImplEntryType*)GetEntry( (USHORT)nLow ); - eComp = rIntl.Compare( rStr, pTemp->maStr ); - if ( eComp != COMPARE_GREATER ) + // XXX even though XCollator::compareString returns a sal_Int32 the only + // defined values are {-1, 0, 1} which is compatible with StringCompare + StringCompare eComp = (StringCompare)xCollator->compareString ( + rStr, pTemp->maStr, + aLocale, xTransliteration); + + // Schnelles Einfuegen bei sortierten Daten + if ( eComp != COMPARE_LESS ) { - Insert( pNewEntry, (ULONG)0 ); + Insert( pNewEntry, LIST_APPEND ); } else { - // Binaeres Suchen - nHigh--; - do - { - nMid = (nLow + nHigh) / 2; - pTemp = (ImplEntryType*)GetObject( nMid ); - eComp = rIntl.Compare( rStr, pTemp->maStr ); + nLow = mnMRUCount; + pTemp = (ImplEntryType*)GetEntry( (USHORT)nLow ); - if ( eComp == COMPARE_LESS ) - nHigh = nMid-1; - else + eComp = (StringCompare)xCollator->compareString (rStr, pTemp->maStr, + aLocale, xTransliteration); + if ( eComp != COMPARE_GREATER ) + { + Insert( pNewEntry, (ULONG)0 ); + } + else + { + // Binaeres Suchen + nHigh--; + do { - if ( eComp == COMPARE_GREATER ) - nLow = nMid + 1; + nMid = (nLow + nHigh) / 2; + pTemp = (ImplEntryType*)GetObject( nMid ); + + eComp = (StringCompare)xCollator->compareString ( + rStr, pTemp->maStr, + aLocale, xTransliteration); + + if ( eComp == COMPARE_LESS ) + nHigh = nMid-1; else - break; + { + if ( eComp == COMPARE_GREATER ) + nLow = nMid + 1; + else + break; + } } - } - while ( nLow <= nHigh ); + while ( nLow <= nHigh ); - if ( eComp != COMPARE_LESS ) - nMid++; + if ( eComp != COMPARE_LESS ) + nMid++; - Insert( pNewEntry, nMid ); + Insert( pNewEntry, nMid ); + } } } + catch (uno::RuntimeException &rError) + { + // XXX this is arguable, if the exception occured because pNewEntry is + // garbage you wouldn't insert it. If the exception occured because the + // Collator implementation is garbage then give the user a chance to see + // his stuff + Insert( pNewEntry, (ULONG)0 ); + } + } return (USHORT)GetPos( pNewEntry ); |