merge the formfield patch from ooo-build
[ooovba.git] / i18npool / source / indexentry / indexentrysupplier_common.cxx
blob13e97e01d814a85423b55796d47ef7815a5e3c20
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: indexentrysupplier_common.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_i18npool.hxx"
34 #include <indexentrysupplier_common.hxx>
35 #include <com/sun/star/i18n/CollatorOptions.hpp>
36 #include <localedata.hxx>
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star;
40 using namespace ::rtl;
42 namespace com { namespace sun { namespace star { namespace i18n {
44 IndexEntrySupplier_Common::IndexEntrySupplier_Common(const Reference < lang::XMultiServiceFactory >& rxMSF)
46 implementationName = "com.sun.star.i18n.IndexEntrySupplier_Common";
47 collator = new CollatorImpl(rxMSF);
48 usePhonetic = sal_False;
51 IndexEntrySupplier_Common::~IndexEntrySupplier_Common()
53 delete collator;
56 Sequence < lang::Locale > SAL_CALL IndexEntrySupplier_Common::getLocaleList() throw (RuntimeException)
58 throw RuntimeException();
61 Sequence < OUString > SAL_CALL IndexEntrySupplier_Common::getAlgorithmList( const lang::Locale& ) throw (RuntimeException)
63 throw RuntimeException();
66 OUString SAL_CALL IndexEntrySupplier_Common::getPhoneticCandidate( const OUString&,
67 const lang::Locale& ) throw (RuntimeException)
69 return OUString();
72 sal_Bool SAL_CALL IndexEntrySupplier_Common::usePhoneticEntry( const lang::Locale& ) throw (RuntimeException)
74 throw RuntimeException();
77 sal_Bool SAL_CALL IndexEntrySupplier_Common::loadAlgorithm( const lang::Locale& rLocale,
78 const OUString& rAlgorithm, sal_Int32 collatorOptions ) throw (RuntimeException)
80 usePhonetic = LocaleData().isPhonetic(rLocale, rAlgorithm);
81 collator->loadCollatorAlgorithm(rAlgorithm, rLocale, collatorOptions);
82 aLocale = rLocale;
83 aAlgorithm = rAlgorithm;
84 return sal_True;
87 OUString SAL_CALL IndexEntrySupplier_Common::getIndexKey( const OUString& rIndexEntry,
88 const OUString&, const lang::Locale& ) throw (RuntimeException)
90 sal_Int32 nPos=0;
91 sal_uInt32 indexChar=rIndexEntry.iterateCodePoints(&nPos, 0);
92 return OUString(&indexChar, 1);
95 sal_Int16 SAL_CALL IndexEntrySupplier_Common::compareIndexEntry(
96 const OUString& rIndexEntry1, const OUString&, const lang::Locale&,
97 const OUString& rIndexEntry2, const OUString&, const lang::Locale& )
98 throw (RuntimeException)
100 return sal::static_int_cast< sal_Int16 >(
101 collator->compareString(rIndexEntry1, rIndexEntry2));
102 // return value of compareString in { -1, 0, 1 }
105 OUString SAL_CALL IndexEntrySupplier_Common::getIndexCharacter( const OUString& rIndexEntry,
106 const lang::Locale& rLocale, const OUString& ) throw (RuntimeException)
108 return getIndexKey(rIndexEntry, rIndexEntry, rLocale);
111 OUString SAL_CALL IndexEntrySupplier_Common::getIndexFollowPageWord( sal_Bool,
112 const lang::Locale& ) throw (RuntimeException)
114 throw RuntimeException();
117 const OUString& SAL_CALL
118 IndexEntrySupplier_Common::getEntry( const OUString& IndexEntry,
119 const OUString& PhoneticEntry, const lang::Locale& rLocale ) throw (RuntimeException)
121 // The condition for using phonetic entry is:
122 // usePhonetic is set for the algorithm;
123 // rLocale for phonetic entry is same as aLocale for algorithm,
124 // which means Chinese phonetic will not be used for Japanese algorithm;
125 // phonetic entry is not blank.
126 if (usePhonetic && PhoneticEntry.getLength() > 0 && rLocale.Language == aLocale.Language &&
127 rLocale.Country == aLocale.Country && rLocale.Variant == aLocale.Variant)
128 return PhoneticEntry;
129 else
130 return IndexEntry;
133 OUString SAL_CALL
134 IndexEntrySupplier_Common::getImplementationName() throw( RuntimeException )
136 return OUString::createFromAscii( implementationName );
139 sal_Bool SAL_CALL
140 IndexEntrySupplier_Common::supportsService(const OUString& rServiceName) throw( RuntimeException )
142 return rServiceName.compareToAscii(implementationName) == 0;
145 Sequence< OUString > SAL_CALL
146 IndexEntrySupplier_Common::getSupportedServiceNames() throw( RuntimeException )
148 Sequence< OUString > aRet(1);
149 aRet[0] = OUString::createFromAscii( implementationName );
150 return aRet;
153 } } } }