1*3b8558fdSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*3b8558fdSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*3b8558fdSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*3b8558fdSAndrew Rist * distributed with this work for additional information
6*3b8558fdSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*3b8558fdSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*3b8558fdSAndrew Rist * "License"); you may not use this file except in compliance
9*3b8558fdSAndrew Rist * with the License. You may obtain a copy of the License at
10*3b8558fdSAndrew Rist *
11*3b8558fdSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*3b8558fdSAndrew Rist *
13*3b8558fdSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*3b8558fdSAndrew Rist * software distributed under the License is distributed on an
15*3b8558fdSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3b8558fdSAndrew Rist * KIND, either express or implied. See the License for the
17*3b8558fdSAndrew Rist * specific language governing permissions and limitations
18*3b8558fdSAndrew Rist * under the License.
19*3b8558fdSAndrew Rist *
20*3b8558fdSAndrew Rist *************************************************************/
21*3b8558fdSAndrew Rist
22*3b8558fdSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_linguistic.hxx"
26cdf0e10cSrcweir #include <tools/string.hxx>
27cdf0e10cSrcweir #include <tools/fsys.hxx>
28cdf0e10cSrcweir #include <tools/debug.hxx>
29cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
30cdf0e10cSrcweir #include <svl/lngmisc.hxx>
31cdf0e10cSrcweir #include <ucbhelper/content.hxx>
32cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
33cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp>
34cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
35cdf0e10cSrcweir #include <com/sun/star/beans/XFastPropertySet.hpp>
36cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyChangeListener.hpp>
37cdf0e10cSrcweir #include <com/sun/star/frame/XTerminateListener.hpp>
38cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
39cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
40cdf0e10cSrcweir
41cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValues.hpp>
42cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
43cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
44cdf0e10cSrcweir #include <com/sun/star/linguistic2/DictionaryType.hpp>
45cdf0e10cSrcweir #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
46cdf0e10cSrcweir #include <unotools/processfactory.hxx>
47cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
48cdf0e10cSrcweir #include <unotools/syslocale.hxx>
49cdf0e10cSrcweir
50cdf0e10cSrcweir #include <rtl/instance.hxx>
51cdf0e10cSrcweir
52cdf0e10cSrcweir #include "linguistic/misc.hxx"
53cdf0e10cSrcweir #include "defs.hxx"
54cdf0e10cSrcweir #include "linguistic/lngprops.hxx"
55cdf0e10cSrcweir #include "linguistic/hyphdta.hxx"
56cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
57cdf0e10cSrcweir
58cdf0e10cSrcweir using namespace utl;
59cdf0e10cSrcweir using namespace osl;
60cdf0e10cSrcweir using namespace rtl;
61cdf0e10cSrcweir using namespace com::sun::star;
62cdf0e10cSrcweir using namespace com::sun::star::beans;
63cdf0e10cSrcweir using namespace com::sun::star::lang;
64cdf0e10cSrcweir using namespace com::sun::star::uno;
65cdf0e10cSrcweir using namespace com::sun::star::i18n;
66cdf0e10cSrcweir using namespace com::sun::star::linguistic2;
67cdf0e10cSrcweir
68cdf0e10cSrcweir namespace linguistic
69cdf0e10cSrcweir {
70cdf0e10cSrcweir
71cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
72cdf0e10cSrcweir
73cdf0e10cSrcweir //!! multi-thread safe mutex for all platforms !!
74cdf0e10cSrcweir struct LinguMutex : public rtl::Static< osl::Mutex, LinguMutex >
75cdf0e10cSrcweir {
76cdf0e10cSrcweir };
77cdf0e10cSrcweir
GetLinguMutex()78cdf0e10cSrcweir osl::Mutex & GetLinguMutex()
79cdf0e10cSrcweir {
80cdf0e10cSrcweir return LinguMutex::get();
81cdf0e10cSrcweir }
82cdf0e10cSrcweir
83cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
84cdf0e10cSrcweir
GetLocaleDataWrapper(sal_Int16 nLang)85cdf0e10cSrcweir LocaleDataWrapper & GetLocaleDataWrapper( sal_Int16 nLang )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir static LocaleDataWrapper aLclDtaWrp(
88cdf0e10cSrcweir getProcessServiceFactory(),
89cdf0e10cSrcweir CreateLocale( SvtSysLocale().GetUILanguage() ) );
90cdf0e10cSrcweir
91cdf0e10cSrcweir const Locale &rLcl = aLclDtaWrp.getLoadedLocale();
92cdf0e10cSrcweir Locale aLcl( CreateLocale( nLang ) );
93cdf0e10cSrcweir if (aLcl.Language != rLcl.Language ||
94cdf0e10cSrcweir aLcl.Country != rLcl.Country ||
95cdf0e10cSrcweir aLcl.Variant != rLcl.Variant)
96cdf0e10cSrcweir aLclDtaWrp.setLocale( aLcl );
97cdf0e10cSrcweir return aLclDtaWrp;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
100cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
101cdf0e10cSrcweir
102cdf0e10cSrcweir /**
103cdf0e10cSrcweir returns text-encoding used for ByteString unicode String conversion
104cdf0e10cSrcweir */
GetTextEncoding(sal_Int16 nLanguage)105cdf0e10cSrcweir rtl_TextEncoding GetTextEncoding( sal_Int16 nLanguage )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir DBG_ASSERT( nLanguage != LANGUAGE_NONE, "invalid language argument" );
108cdf0e10cSrcweir static sal_Int16 nLastLanguage = LANGUAGE_NONE;
109cdf0e10cSrcweir
110cdf0e10cSrcweir // set default value for unknown languages
111cdf0e10cSrcweir static rtl_TextEncoding nEncoding = RTL_TEXTENCODING_DONTKNOW;
112cdf0e10cSrcweir
113cdf0e10cSrcweir if (nLastLanguage != nLanguage)
114cdf0e10cSrcweir {
115cdf0e10cSrcweir //!! IPR uses textencodings Latin-1, Latin-2, Latin-5 and Latin-7 !!
116cdf0e10cSrcweir
117cdf0e10cSrcweir nLastLanguage = nLanguage;
118cdf0e10cSrcweir switch (nLanguage)
119cdf0e10cSrcweir {
120cdf0e10cSrcweir case LANGUAGE_GERMAN :
121cdf0e10cSrcweir case LANGUAGE_GERMAN_SWISS :
122cdf0e10cSrcweir case LANGUAGE_ENGLISH_US :
123cdf0e10cSrcweir case LANGUAGE_ENGLISH_UK :
124cdf0e10cSrcweir case LANGUAGE_FRENCH :
125cdf0e10cSrcweir case LANGUAGE_ITALIAN :
126cdf0e10cSrcweir case LANGUAGE_SPANISH :
127cdf0e10cSrcweir case LANGUAGE_CATALAN :
128cdf0e10cSrcweir case LANGUAGE_PORTUGUESE :
129cdf0e10cSrcweir case LANGUAGE_PORTUGUESE_BRAZILIAN :
130cdf0e10cSrcweir case LANGUAGE_DANISH :
131cdf0e10cSrcweir case LANGUAGE_DUTCH :
132cdf0e10cSrcweir case LANGUAGE_SWEDISH :
133cdf0e10cSrcweir case LANGUAGE_FINNISH :
134cdf0e10cSrcweir case LANGUAGE_NORWEGIAN_BOKMAL :
135cdf0e10cSrcweir case LANGUAGE_NORWEGIAN_NYNORSK :
136cdf0e10cSrcweir case LANGUAGE_AFRIKAANS :
137cdf0e10cSrcweir case LANGUAGE_ENGLISH_EIRE :
138cdf0e10cSrcweir case LANGUAGE_ENGLISH_AUS :
139cdf0e10cSrcweir #ifdef WNT
140cdf0e10cSrcweir nEncoding = RTL_TEXTENCODING_MS_1252; break;
141cdf0e10cSrcweir #else
142cdf0e10cSrcweir nEncoding = RTL_TEXTENCODING_ISO_8859_1; break;
143cdf0e10cSrcweir #endif
144cdf0e10cSrcweir case LANGUAGE_CZECH :
145cdf0e10cSrcweir case LANGUAGE_HUNGARIAN :
146cdf0e10cSrcweir case LANGUAGE_POLISH :
147cdf0e10cSrcweir #ifdef WNT
148cdf0e10cSrcweir nEncoding = RTL_TEXTENCODING_MS_1250; break;
149cdf0e10cSrcweir #else
150cdf0e10cSrcweir nEncoding = RTL_TEXTENCODING_ISO_8859_2; break;
151cdf0e10cSrcweir #endif
152cdf0e10cSrcweir case LANGUAGE_RUSSIAN :
153cdf0e10cSrcweir #ifdef WNT
154cdf0e10cSrcweir nEncoding = RTL_TEXTENCODING_MS_1251; break;
155cdf0e10cSrcweir #else
156cdf0e10cSrcweir nEncoding = RTL_TEXTENCODING_ISO_8859_5; break;
157cdf0e10cSrcweir #endif
158cdf0e10cSrcweir case LANGUAGE_GREEK :
159cdf0e10cSrcweir #ifdef WNT
160cdf0e10cSrcweir nEncoding = RTL_TEXTENCODING_MS_1253; break;
161cdf0e10cSrcweir #else
162cdf0e10cSrcweir nEncoding = RTL_TEXTENCODING_ISO_8859_7; break;
163cdf0e10cSrcweir #endif
164cdf0e10cSrcweir default:
165cdf0e10cSrcweir DBG_ASSERT( 0, "unexpected language" );
166cdf0e10cSrcweir }
167cdf0e10cSrcweir }
168cdf0e10cSrcweir
169cdf0e10cSrcweir return nEncoding;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir
172cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
173cdf0e10cSrcweir
Minimum(sal_Int32 n1,sal_Int32 n2,sal_Int32 n3)174cdf0e10cSrcweir static inline sal_Int32 Minimum( sal_Int32 n1, sal_Int32 n2, sal_Int32 n3 )
175cdf0e10cSrcweir {
176cdf0e10cSrcweir sal_Int32 nMin = n1 < n2 ? n1 : n2;
177cdf0e10cSrcweir return nMin < n3 ? nMin : n3;
178cdf0e10cSrcweir }
179cdf0e10cSrcweir
180cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
181cdf0e10cSrcweir
182cdf0e10cSrcweir class IntArray2D
183cdf0e10cSrcweir {
184cdf0e10cSrcweir private:
185cdf0e10cSrcweir sal_Int32 *pData;
186cdf0e10cSrcweir int n1, n2;
187cdf0e10cSrcweir
188cdf0e10cSrcweir public:
189cdf0e10cSrcweir IntArray2D( int nDim1, int nDim2 );
190cdf0e10cSrcweir ~IntArray2D();
191cdf0e10cSrcweir
192cdf0e10cSrcweir sal_Int32 & Value( int i, int k );
193cdf0e10cSrcweir };
194cdf0e10cSrcweir
IntArray2D(int nDim1,int nDim2)195cdf0e10cSrcweir IntArray2D::IntArray2D( int nDim1, int nDim2 )
196cdf0e10cSrcweir {
197cdf0e10cSrcweir n1 = nDim1;
198cdf0e10cSrcweir n2 = nDim2;
199cdf0e10cSrcweir pData = new sal_Int32[n1 * n2];
200cdf0e10cSrcweir }
201cdf0e10cSrcweir
~IntArray2D()202cdf0e10cSrcweir IntArray2D::~IntArray2D()
203cdf0e10cSrcweir {
204cdf0e10cSrcweir delete[] pData;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
Value(int i,int k)207cdf0e10cSrcweir sal_Int32 & IntArray2D::Value( int i, int k )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir DBG_ASSERT( 0 <= i && i < n1, "first index out of range" );
210cdf0e10cSrcweir DBG_ASSERT( 0 <= k && k < n2, "first index out of range" );
211cdf0e10cSrcweir DBG_ASSERT( i * n2 + k < n1 * n2, "index out of range" );
212cdf0e10cSrcweir return pData[ i * n2 + k ];
213cdf0e10cSrcweir }
214cdf0e10cSrcweir
215cdf0e10cSrcweir
LevDistance(const OUString & rTxt1,const OUString & rTxt2)216cdf0e10cSrcweir sal_Int32 LevDistance( const OUString &rTxt1, const OUString &rTxt2 )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir sal_Int32 nLen1 = rTxt1.getLength();
219cdf0e10cSrcweir sal_Int32 nLen2 = rTxt2.getLength();
220cdf0e10cSrcweir
221cdf0e10cSrcweir if (nLen1 == 0)
222cdf0e10cSrcweir return nLen2;
223cdf0e10cSrcweir if (nLen2 == 0)
224cdf0e10cSrcweir return nLen1;
225cdf0e10cSrcweir
226cdf0e10cSrcweir IntArray2D aData( nLen1 + 1, nLen2 + 1 );
227cdf0e10cSrcweir
228cdf0e10cSrcweir sal_Int32 i, k;
229cdf0e10cSrcweir for (i = 0; i <= nLen1; ++i)
230cdf0e10cSrcweir aData.Value(i, 0) = i;
231cdf0e10cSrcweir for (k = 0; k <= nLen2; ++k)
232cdf0e10cSrcweir aData.Value(0, k) = k;
233cdf0e10cSrcweir for (i = 1; i <= nLen1; ++i)
234cdf0e10cSrcweir {
235cdf0e10cSrcweir for (k = 1; k <= nLen2; ++k)
236cdf0e10cSrcweir {
237cdf0e10cSrcweir sal_Unicode c1i = rTxt1.getStr()[i - 1];
238cdf0e10cSrcweir sal_Unicode c2k = rTxt2.getStr()[k - 1];
239cdf0e10cSrcweir sal_Int32 nCost = c1i == c2k ? 0 : 1;
240cdf0e10cSrcweir sal_Int32 nNew = Minimum( aData.Value(i-1, k ) + 1,
241cdf0e10cSrcweir aData.Value(i , k-1) + 1,
242cdf0e10cSrcweir aData.Value(i-1, k-1) + nCost );
243cdf0e10cSrcweir // take transposition (exchange with left or right char) in account
244cdf0e10cSrcweir if (2 < i && 2 < k)
245cdf0e10cSrcweir {
246cdf0e10cSrcweir int nT = aData.Value(i-2, k-2) + 1;
247cdf0e10cSrcweir if (rTxt1.getStr()[i - 2] != c1i)
248cdf0e10cSrcweir ++nT;
249cdf0e10cSrcweir if (rTxt2.getStr()[k - 2] != c2k)
250cdf0e10cSrcweir ++nT;
251cdf0e10cSrcweir if (nT < nNew)
252cdf0e10cSrcweir nNew = nT;
253cdf0e10cSrcweir }
254cdf0e10cSrcweir
255cdf0e10cSrcweir aData.Value(i, k) = nNew;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir }
258cdf0e10cSrcweir sal_Int32 nDist = aData.Value(nLen1, nLen2);
259cdf0e10cSrcweir return nDist;
260cdf0e10cSrcweir }
261cdf0e10cSrcweir
262cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
263cdf0e10cSrcweir
IsUseDicList(const PropertyValues & rProperties,const uno::Reference<XPropertySet> & rxProp)264cdf0e10cSrcweir sal_Bool IsUseDicList( const PropertyValues &rProperties,
265cdf0e10cSrcweir const uno::Reference< XPropertySet > &rxProp )
266cdf0e10cSrcweir {
267cdf0e10cSrcweir sal_Bool bRes = sal_True;
268cdf0e10cSrcweir
269cdf0e10cSrcweir sal_Int32 nLen = rProperties.getLength();
270cdf0e10cSrcweir const PropertyValue *pVal = rProperties.getConstArray();
271cdf0e10cSrcweir sal_Int32 i;
272cdf0e10cSrcweir
273cdf0e10cSrcweir for ( i = 0; i < nLen; ++i)
274cdf0e10cSrcweir {
275cdf0e10cSrcweir if (UPH_IS_USE_DICTIONARY_LIST == pVal[i].Handle)
276cdf0e10cSrcweir {
277cdf0e10cSrcweir pVal[i].Value >>= bRes;
278cdf0e10cSrcweir break;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir }
281cdf0e10cSrcweir if (i >= nLen) // no temporary value found in 'rProperties'
282cdf0e10cSrcweir {
283cdf0e10cSrcweir uno::Reference< XFastPropertySet > xFast( rxProp, UNO_QUERY );
284cdf0e10cSrcweir if (xFast.is())
285cdf0e10cSrcweir xFast->getFastPropertyValue( UPH_IS_USE_DICTIONARY_LIST ) >>= bRes;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir
288cdf0e10cSrcweir return bRes;
289cdf0e10cSrcweir }
290cdf0e10cSrcweir
291cdf0e10cSrcweir
IsIgnoreControlChars(const PropertyValues & rProperties,const uno::Reference<XPropertySet> & rxProp)292cdf0e10cSrcweir sal_Bool IsIgnoreControlChars( const PropertyValues &rProperties,
293cdf0e10cSrcweir const uno::Reference< XPropertySet > &rxProp )
294cdf0e10cSrcweir {
295cdf0e10cSrcweir sal_Bool bRes = sal_True;
296cdf0e10cSrcweir
297cdf0e10cSrcweir sal_Int32 nLen = rProperties.getLength();
298cdf0e10cSrcweir const PropertyValue *pVal = rProperties.getConstArray();
299cdf0e10cSrcweir sal_Int32 i;
300cdf0e10cSrcweir
301cdf0e10cSrcweir for ( i = 0; i < nLen; ++i)
302cdf0e10cSrcweir {
303cdf0e10cSrcweir if (UPH_IS_IGNORE_CONTROL_CHARACTERS == pVal[i].Handle)
304cdf0e10cSrcweir {
305cdf0e10cSrcweir pVal[i].Value >>= bRes;
306cdf0e10cSrcweir break;
307cdf0e10cSrcweir }
308cdf0e10cSrcweir }
309cdf0e10cSrcweir if (i >= nLen) // no temporary value found in 'rProperties'
310cdf0e10cSrcweir {
311cdf0e10cSrcweir uno::Reference< XFastPropertySet > xFast( rxProp, UNO_QUERY );
312cdf0e10cSrcweir if (xFast.is())
313cdf0e10cSrcweir xFast->getFastPropertyValue( UPH_IS_IGNORE_CONTROL_CHARACTERS ) >>= bRes;
314cdf0e10cSrcweir }
315cdf0e10cSrcweir
316cdf0e10cSrcweir return bRes;
317cdf0e10cSrcweir }
318cdf0e10cSrcweir
319cdf0e10cSrcweir
lcl_HasHyphInfo(const uno::Reference<XDictionaryEntry> & xEntry)320cdf0e10cSrcweir static sal_Bool lcl_HasHyphInfo( const uno::Reference<XDictionaryEntry> &xEntry )
321cdf0e10cSrcweir {
322cdf0e10cSrcweir sal_Bool bRes = sal_False;
323cdf0e10cSrcweir if (xEntry.is())
324cdf0e10cSrcweir {
325cdf0e10cSrcweir // there has to be (at least one) '=' denoting a hyphenation position
326cdf0e10cSrcweir // and it must not be before any character of the word
327cdf0e10cSrcweir sal_Int32 nIdx = xEntry->getDictionaryWord().indexOf( '=' );
328cdf0e10cSrcweir bRes = nIdx != -1 && nIdx != 0;
329cdf0e10cSrcweir }
330cdf0e10cSrcweir return bRes;
331cdf0e10cSrcweir }
332cdf0e10cSrcweir
333cdf0e10cSrcweir
SearchDicList(const uno::Reference<XDictionaryList> & xDicList,const OUString & rWord,sal_Int16 nLanguage,sal_Bool bSearchPosDics,sal_Bool bSearchSpellEntry)334cdf0e10cSrcweir uno::Reference< XDictionaryEntry > SearchDicList(
335cdf0e10cSrcweir const uno::Reference< XDictionaryList > &xDicList,
336cdf0e10cSrcweir const OUString &rWord, sal_Int16 nLanguage,
337cdf0e10cSrcweir sal_Bool bSearchPosDics, sal_Bool bSearchSpellEntry )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir MutexGuard aGuard( GetLinguMutex() );
340cdf0e10cSrcweir
341cdf0e10cSrcweir uno::Reference< XDictionaryEntry > xEntry;
342cdf0e10cSrcweir
343cdf0e10cSrcweir if (!xDicList.is())
344cdf0e10cSrcweir return xEntry;
345cdf0e10cSrcweir
346cdf0e10cSrcweir const uno::Sequence< uno::Reference< XDictionary > >
347cdf0e10cSrcweir aDics( xDicList->getDictionaries() );
348cdf0e10cSrcweir const uno::Reference< XDictionary >
349cdf0e10cSrcweir *pDic = aDics.getConstArray();
350cdf0e10cSrcweir sal_Int32 nDics = xDicList->getCount();
351cdf0e10cSrcweir
352cdf0e10cSrcweir sal_Int32 i;
353cdf0e10cSrcweir for (i = 0; i < nDics; i++)
354cdf0e10cSrcweir {
355cdf0e10cSrcweir uno::Reference< XDictionary > axDic( pDic[i], UNO_QUERY );
356cdf0e10cSrcweir
357cdf0e10cSrcweir DictionaryType eType = axDic->getDictionaryType();
358cdf0e10cSrcweir sal_Int16 nLang = LocaleToLanguage( axDic->getLocale() );
359cdf0e10cSrcweir
360cdf0e10cSrcweir if ( axDic.is() && axDic->isActive()
361cdf0e10cSrcweir && (nLang == nLanguage || nLang == LANGUAGE_NONE) )
362cdf0e10cSrcweir {
363cdf0e10cSrcweir DBG_ASSERT( eType != DictionaryType_MIXED,
364cdf0e10cSrcweir "lng : unexpected dictionary type" );
365cdf0e10cSrcweir
366cdf0e10cSrcweir if ( (!bSearchPosDics && eType == DictionaryType_NEGATIVE)
367cdf0e10cSrcweir || ( bSearchPosDics && eType == DictionaryType_POSITIVE))
368cdf0e10cSrcweir {
369cdf0e10cSrcweir if ( (xEntry = axDic->getEntry( rWord )).is() )
370cdf0e10cSrcweir {
371cdf0e10cSrcweir if (bSearchSpellEntry || lcl_HasHyphInfo( xEntry ))
372cdf0e10cSrcweir break;
373cdf0e10cSrcweir }
374cdf0e10cSrcweir xEntry = 0;
375cdf0e10cSrcweir }
376cdf0e10cSrcweir }
377cdf0e10cSrcweir }
378cdf0e10cSrcweir
379cdf0e10cSrcweir return xEntry;
380cdf0e10cSrcweir }
381cdf0e10cSrcweir
382cdf0e10cSrcweir
SaveDictionaries(const uno::Reference<XDictionaryList> & xDicList)383cdf0e10cSrcweir sal_Bool SaveDictionaries( const uno::Reference< XDictionaryList > &xDicList )
384cdf0e10cSrcweir {
385cdf0e10cSrcweir if (!xDicList.is())
386cdf0e10cSrcweir return sal_True;
387cdf0e10cSrcweir
388cdf0e10cSrcweir sal_Bool bRet = sal_True;
389cdf0e10cSrcweir
390cdf0e10cSrcweir Sequence< uno::Reference< XDictionary > > aDics( xDicList->getDictionaries() );
391cdf0e10cSrcweir const uno::Reference< XDictionary > *pDic = aDics.getConstArray();
392cdf0e10cSrcweir sal_Int32 nCount = aDics.getLength();
393cdf0e10cSrcweir for (sal_Int32 i = 0; i < nCount; i++)
394cdf0e10cSrcweir {
395cdf0e10cSrcweir try
396cdf0e10cSrcweir {
397cdf0e10cSrcweir uno::Reference< frame::XStorable > xStor( pDic[i], UNO_QUERY );
398cdf0e10cSrcweir if (xStor.is())
399cdf0e10cSrcweir {
400cdf0e10cSrcweir if (!xStor->isReadonly() && xStor->hasLocation())
401cdf0e10cSrcweir xStor->store();
402cdf0e10cSrcweir }
403cdf0e10cSrcweir }
404cdf0e10cSrcweir catch(uno::Exception &)
405cdf0e10cSrcweir {
406cdf0e10cSrcweir bRet = sal_False;
407cdf0e10cSrcweir }
408cdf0e10cSrcweir }
409cdf0e10cSrcweir
410cdf0e10cSrcweir return bRet;
411cdf0e10cSrcweir }
412cdf0e10cSrcweir
413cdf0e10cSrcweir
AddEntryToDic(uno::Reference<XDictionary> & rxDic,const OUString & rWord,sal_Bool bIsNeg,const OUString & rRplcTxt,sal_Int16,sal_Bool bStripDot)414cdf0e10cSrcweir sal_uInt8 AddEntryToDic(
415cdf0e10cSrcweir uno::Reference< XDictionary > &rxDic,
416cdf0e10cSrcweir const OUString &rWord, sal_Bool bIsNeg,
417cdf0e10cSrcweir const OUString &rRplcTxt, sal_Int16 /* nRplcLang */,
418cdf0e10cSrcweir sal_Bool bStripDot )
419cdf0e10cSrcweir {
420cdf0e10cSrcweir if (!rxDic.is())
421cdf0e10cSrcweir return DIC_ERR_NOT_EXISTS;
422cdf0e10cSrcweir
423cdf0e10cSrcweir OUString aTmp( rWord );
424cdf0e10cSrcweir if (bStripDot)
425cdf0e10cSrcweir {
426cdf0e10cSrcweir sal_Int32 nLen = rWord.getLength();
427cdf0e10cSrcweir if (nLen > 0 && '.' == rWord[ nLen - 1])
428cdf0e10cSrcweir {
429cdf0e10cSrcweir // remove trailing '.'
430cdf0e10cSrcweir // (this is the official way to do this :-( )
431cdf0e10cSrcweir aTmp = aTmp.copy( 0, nLen - 1 );
432cdf0e10cSrcweir }
433cdf0e10cSrcweir }
434cdf0e10cSrcweir sal_Bool bAddOk = rxDic->add( aTmp, bIsNeg, rRplcTxt );
435cdf0e10cSrcweir
436cdf0e10cSrcweir sal_uInt8 nRes = DIC_ERR_NONE;
437cdf0e10cSrcweir if (!bAddOk)
438cdf0e10cSrcweir {
439cdf0e10cSrcweir if (rxDic->isFull())
440cdf0e10cSrcweir nRes = DIC_ERR_FULL;
441cdf0e10cSrcweir else
442cdf0e10cSrcweir {
443cdf0e10cSrcweir uno::Reference< frame::XStorable > xStor( rxDic, UNO_QUERY );
444cdf0e10cSrcweir if (xStor.is() && xStor->isReadonly())
445cdf0e10cSrcweir nRes = DIC_ERR_READONLY;
446cdf0e10cSrcweir else
447cdf0e10cSrcweir nRes = DIC_ERR_UNKNOWN;
448cdf0e10cSrcweir }
449cdf0e10cSrcweir }
450cdf0e10cSrcweir
451cdf0e10cSrcweir return nRes;
452cdf0e10cSrcweir }
453cdf0e10cSrcweir
454cdf0e10cSrcweir
455cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
456cdf0e10cSrcweir
LocaleToLanguage(const Locale & rLocale)457cdf0e10cSrcweir LanguageType LocaleToLanguage( const Locale& rLocale )
458cdf0e10cSrcweir {
459cdf0e10cSrcweir // empty Locale -> LANGUAGE_NONE
460cdf0e10cSrcweir if ( rLocale.Language.getLength() == 0 )
461cdf0e10cSrcweir return LANGUAGE_NONE;
462cdf0e10cSrcweir
463cdf0e10cSrcweir return MsLangId::convertLocaleToLanguage( rLocale );
464cdf0e10cSrcweir }
465cdf0e10cSrcweir
466cdf0e10cSrcweir
LanguageToLocale(Locale & rLocale,LanguageType eLang)467cdf0e10cSrcweir Locale& LanguageToLocale( Locale& rLocale, LanguageType eLang )
468cdf0e10cSrcweir {
469cdf0e10cSrcweir if ( eLang != LANGUAGE_NONE /* && eLang != LANGUAGE_SYSTEM */)
470cdf0e10cSrcweir MsLangId::convertLanguageToLocale( eLang, rLocale );
471cdf0e10cSrcweir
472cdf0e10cSrcweir return rLocale;
473cdf0e10cSrcweir }
474cdf0e10cSrcweir
CreateLocale(LanguageType eLang)475cdf0e10cSrcweir Locale CreateLocale( LanguageType eLang )
476cdf0e10cSrcweir {
477cdf0e10cSrcweir Locale aLocale;
478cdf0e10cSrcweir if ( eLang != LANGUAGE_NONE /* && eLang != LANGUAGE_SYSTEM */)
479cdf0e10cSrcweir return MsLangId::convertLanguageToLocale( eLang );
480cdf0e10cSrcweir
481cdf0e10cSrcweir return aLocale;
482cdf0e10cSrcweir }
483cdf0e10cSrcweir
LangSeqToLocaleSeq(const uno::Sequence<sal_Int16> & rLangSeq)484cdf0e10cSrcweir uno::Sequence< Locale > LangSeqToLocaleSeq( const uno::Sequence< sal_Int16 > &rLangSeq )
485cdf0e10cSrcweir {
486cdf0e10cSrcweir const sal_Int16 *pLang = rLangSeq.getConstArray();
487cdf0e10cSrcweir sal_Int32 nCount = rLangSeq.getLength();
488cdf0e10cSrcweir
489cdf0e10cSrcweir uno::Sequence< Locale > aLocales( nCount );
490cdf0e10cSrcweir Locale *pLocale = aLocales.getArray();
491cdf0e10cSrcweir for (sal_Int32 i = 0; i < nCount; ++i)
492cdf0e10cSrcweir {
493cdf0e10cSrcweir LanguageToLocale( pLocale[i], pLang[ i ] );
494cdf0e10cSrcweir }
495cdf0e10cSrcweir
496cdf0e10cSrcweir return aLocales;
497cdf0e10cSrcweir }
498cdf0e10cSrcweir
499cdf0e10cSrcweir uno::Sequence< sal_Int16 >
LocaleSeqToLangSeq(uno::Sequence<Locale> & rLocaleSeq)500cdf0e10cSrcweir LocaleSeqToLangSeq( uno::Sequence< Locale > &rLocaleSeq )
501cdf0e10cSrcweir {
502cdf0e10cSrcweir const Locale *pLocale = rLocaleSeq.getConstArray();
503cdf0e10cSrcweir sal_Int32 nCount = rLocaleSeq.getLength();
504cdf0e10cSrcweir
505cdf0e10cSrcweir uno::Sequence< sal_Int16 > aLangs( nCount );
506cdf0e10cSrcweir sal_Int16 *pLang = aLangs.getArray();
507cdf0e10cSrcweir for (sal_Int32 i = 0; i < nCount; ++i)
508cdf0e10cSrcweir {
509cdf0e10cSrcweir pLang[i] = LocaleToLanguage( pLocale[i] );
510cdf0e10cSrcweir }
511cdf0e10cSrcweir
512cdf0e10cSrcweir return aLangs;
513cdf0e10cSrcweir }
514cdf0e10cSrcweir
515cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
516cdf0e10cSrcweir
IsReadOnly(const String & rURL,sal_Bool * pbExist)517cdf0e10cSrcweir sal_Bool IsReadOnly( const String &rURL, sal_Bool *pbExist )
518cdf0e10cSrcweir {
519cdf0e10cSrcweir sal_Bool bRes = sal_False;
520cdf0e10cSrcweir sal_Bool bExists = sal_False;
521cdf0e10cSrcweir
522cdf0e10cSrcweir if (rURL.Len() > 0)
523cdf0e10cSrcweir {
524cdf0e10cSrcweir try
525cdf0e10cSrcweir {
526cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > xCmdEnv;
527cdf0e10cSrcweir ::ucbhelper::Content aContent( rURL, xCmdEnv );
528cdf0e10cSrcweir
529cdf0e10cSrcweir bExists = aContent.isDocument();
530cdf0e10cSrcweir if (bExists)
531cdf0e10cSrcweir {
532cdf0e10cSrcweir Any aAny( aContent.getPropertyValue( A2OU( "IsReadOnly" ) ) );
533cdf0e10cSrcweir aAny >>= bRes;
534cdf0e10cSrcweir }
535cdf0e10cSrcweir }
536cdf0e10cSrcweir catch (Exception &)
537cdf0e10cSrcweir {
538cdf0e10cSrcweir bRes = sal_True;
539cdf0e10cSrcweir }
540cdf0e10cSrcweir }
541cdf0e10cSrcweir
542cdf0e10cSrcweir if (pbExist)
543cdf0e10cSrcweir *pbExist = bExists;
544cdf0e10cSrcweir return bRes;
545cdf0e10cSrcweir }
546cdf0e10cSrcweir
547cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
548cdf0e10cSrcweir
549cdf0e10cSrcweir
GetAltSpelling(sal_Int16 & rnChgPos,sal_Int16 & rnChgLen,OUString & rRplc,uno::Reference<XHyphenatedWord> & rxHyphWord)550cdf0e10cSrcweir static sal_Bool GetAltSpelling( sal_Int16 &rnChgPos, sal_Int16 &rnChgLen, OUString &rRplc,
551cdf0e10cSrcweir uno::Reference< XHyphenatedWord > &rxHyphWord )
552cdf0e10cSrcweir {
553cdf0e10cSrcweir sal_Bool bRes = rxHyphWord->isAlternativeSpelling();
554cdf0e10cSrcweir if (bRes)
555cdf0e10cSrcweir {
556cdf0e10cSrcweir OUString aWord( rxHyphWord->getWord() ),
557cdf0e10cSrcweir aHyphenatedWord( rxHyphWord->getHyphenatedWord() );
558cdf0e10cSrcweir sal_Int16 nHyphenationPos = rxHyphWord->getHyphenationPos();
559cdf0e10cSrcweir /*sal_Int16 nHyphenPos = rxHyphWord->getHyphenPos()*/;
560cdf0e10cSrcweir const sal_Unicode *pWord = aWord.getStr(),
561cdf0e10cSrcweir *pAltWord = aHyphenatedWord.getStr();
562cdf0e10cSrcweir
563cdf0e10cSrcweir // at least char changes directly left or right to the hyphen
564cdf0e10cSrcweir // should(!) be handled properly...
565cdf0e10cSrcweir //! nHyphenationPos and nHyphenPos differ at most by 1 (see above)
566cdf0e10cSrcweir //! Beware: eg "Schiffahrt" in German (pre spelling reform)
567cdf0e10cSrcweir //! proves to be a bit nasty (nChgPosLeft and nChgPosRight overlap
568cdf0e10cSrcweir //! to an extend.)
569cdf0e10cSrcweir
570cdf0e10cSrcweir // find first different char from left
571cdf0e10cSrcweir sal_Int32 nPosL = 0,
572cdf0e10cSrcweir nAltPosL = 0;
573cdf0e10cSrcweir for (sal_Int16 i = 0 ; pWord[ nPosL ] == pAltWord[ nAltPosL ]; nPosL++, nAltPosL++, i++)
574cdf0e10cSrcweir {
575cdf0e10cSrcweir // restrict changes area beginning to the right to
576cdf0e10cSrcweir // the char immediately following the hyphen.
577cdf0e10cSrcweir //! serves to insert the additional "f" in "Schiffahrt" at
578cdf0e10cSrcweir //! position 5 rather than position 6.
579cdf0e10cSrcweir if (i >= nHyphenationPos + 1)
580cdf0e10cSrcweir break;
581cdf0e10cSrcweir }
582cdf0e10cSrcweir
583cdf0e10cSrcweir // find first different char from right
584cdf0e10cSrcweir sal_Int32 nPosR = aWord.getLength() - 1,
585cdf0e10cSrcweir nAltPosR = aHyphenatedWord.getLength() - 1;
586cdf0e10cSrcweir for ( ; nPosR >= nPosL && nAltPosR >= nAltPosL
587cdf0e10cSrcweir && pWord[ nPosR ] == pAltWord[ nAltPosR ];
588cdf0e10cSrcweir nPosR--, nAltPosR--)
589cdf0e10cSrcweir ;
590cdf0e10cSrcweir
591cdf0e10cSrcweir rnChgPos = sal::static_int_cast< sal_Int16 >(nPosL);
592cdf0e10cSrcweir rnChgLen = sal::static_int_cast< sal_Int16 >(nPosR - nPosL + 1);
593cdf0e10cSrcweir DBG_ASSERT( rnChgLen >= 0, "nChgLen < 0");
594cdf0e10cSrcweir
595cdf0e10cSrcweir sal_Int32 nTxtStart = nPosL;
596cdf0e10cSrcweir sal_Int32 nTxtLen = nAltPosL - nPosL + 1;
597cdf0e10cSrcweir rRplc = aHyphenatedWord.copy( nTxtStart, nTxtLen );
598cdf0e10cSrcweir }
599cdf0e10cSrcweir return bRes;
600cdf0e10cSrcweir }
601cdf0e10cSrcweir
602cdf0e10cSrcweir
GetOrigWordPos(const OUString & rOrigWord,sal_Int16 nPos)603cdf0e10cSrcweir static sal_Int16 GetOrigWordPos( const OUString &rOrigWord, sal_Int16 nPos )
604cdf0e10cSrcweir {
605cdf0e10cSrcweir sal_Int32 nLen = rOrigWord.getLength();
606cdf0e10cSrcweir sal_Int32 i = -1;
607cdf0e10cSrcweir while (nPos >= 0 && i++ < nLen)
608cdf0e10cSrcweir {
609cdf0e10cSrcweir sal_Unicode cChar = rOrigWord[i];
610cdf0e10cSrcweir sal_Bool bSkip = IsHyphen( cChar ) || IsControlChar( cChar );
611cdf0e10cSrcweir if (!bSkip)
612cdf0e10cSrcweir --nPos;
613cdf0e10cSrcweir }
614cdf0e10cSrcweir return sal::static_int_cast< sal_Int16 >((0 <= i && i < nLen) ? i : -1);
615cdf0e10cSrcweir }
616cdf0e10cSrcweir
617cdf0e10cSrcweir
GetPosInWordToCheck(const OUString & rTxt,sal_Int32 nPos)618cdf0e10cSrcweir sal_Int32 GetPosInWordToCheck( const OUString &rTxt, sal_Int32 nPos )
619cdf0e10cSrcweir {
620cdf0e10cSrcweir sal_Int32 nRes = -1;
621cdf0e10cSrcweir sal_Int32 nLen = rTxt.getLength();
622cdf0e10cSrcweir if (0 <= nPos && nPos < nLen)
623cdf0e10cSrcweir {
624cdf0e10cSrcweir nRes = 0;
625cdf0e10cSrcweir for (sal_Int32 i = 0; i < nPos; ++i)
626cdf0e10cSrcweir {
627cdf0e10cSrcweir sal_Unicode cChar = rTxt[i];
628cdf0e10cSrcweir sal_Bool bSkip = IsHyphen( cChar ) || IsControlChar( cChar );
629cdf0e10cSrcweir if (!bSkip)
630cdf0e10cSrcweir ++nRes;
631cdf0e10cSrcweir }
632cdf0e10cSrcweir }
633cdf0e10cSrcweir return nRes;
634cdf0e10cSrcweir }
635cdf0e10cSrcweir
636cdf0e10cSrcweir
RebuildHyphensAndControlChars(const OUString & rOrigWord,uno::Reference<XHyphenatedWord> & rxHyphWord)637cdf0e10cSrcweir uno::Reference< XHyphenatedWord > RebuildHyphensAndControlChars(
638cdf0e10cSrcweir const OUString &rOrigWord,
639cdf0e10cSrcweir uno::Reference< XHyphenatedWord > &rxHyphWord )
640cdf0e10cSrcweir {
641cdf0e10cSrcweir uno::Reference< XHyphenatedWord > xRes;
642cdf0e10cSrcweir if (rOrigWord.getLength() && rxHyphWord.is())
643cdf0e10cSrcweir {
644cdf0e10cSrcweir sal_Int16 nChgPos = 0,
645cdf0e10cSrcweir nChgLen = 0;
646cdf0e10cSrcweir OUString aRplc;
647cdf0e10cSrcweir sal_Bool bAltSpelling = GetAltSpelling( nChgPos, nChgLen, aRplc, rxHyphWord );
648cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
649cdf0e10cSrcweir OUString aWord( rxHyphWord->getWord() );
650cdf0e10cSrcweir #endif
651cdf0e10cSrcweir
652cdf0e10cSrcweir OUString aOrigHyphenatedWord;
653cdf0e10cSrcweir sal_Int16 nOrigHyphenPos = -1;
654cdf0e10cSrcweir sal_Int16 nOrigHyphenationPos = -1;
655cdf0e10cSrcweir if (!bAltSpelling)
656cdf0e10cSrcweir {
657cdf0e10cSrcweir aOrigHyphenatedWord = rOrigWord;
658cdf0e10cSrcweir nOrigHyphenPos = GetOrigWordPos( rOrigWord, rxHyphWord->getHyphenPos() );
659cdf0e10cSrcweir nOrigHyphenationPos = GetOrigWordPos( rOrigWord, rxHyphWord->getHyphenationPos() );
660cdf0e10cSrcweir }
661cdf0e10cSrcweir else
662cdf0e10cSrcweir {
663cdf0e10cSrcweir //! should at least work with the German words
664cdf0e10cSrcweir //! B�-c-k-er and Sc-hif-fah-rt
665cdf0e10cSrcweir
666cdf0e10cSrcweir OUString aLeft, aRight;
667cdf0e10cSrcweir sal_Int16 nPos = GetOrigWordPos( rOrigWord, nChgPos );
668cdf0e10cSrcweir
669cdf0e10cSrcweir // get words like Sc-hif-fah-rt to work correct
670cdf0e10cSrcweir sal_Int16 nHyphenationPos = rxHyphWord->getHyphenationPos();
671cdf0e10cSrcweir if (nChgPos > nHyphenationPos)
672cdf0e10cSrcweir --nPos;
673cdf0e10cSrcweir
674cdf0e10cSrcweir aLeft = rOrigWord.copy( 0, nPos );
675cdf0e10cSrcweir aRight = rOrigWord.copy( nPos + nChgLen );
676cdf0e10cSrcweir
677cdf0e10cSrcweir aOrigHyphenatedWord = aLeft;
678cdf0e10cSrcweir aOrigHyphenatedWord += aRplc;
679cdf0e10cSrcweir aOrigHyphenatedWord += aRight;
680cdf0e10cSrcweir
681cdf0e10cSrcweir nOrigHyphenPos = sal::static_int_cast< sal_Int16 >(aLeft.getLength() +
682cdf0e10cSrcweir rxHyphWord->getHyphenPos() - nChgPos);
683cdf0e10cSrcweir nOrigHyphenationPos = GetOrigWordPos( rOrigWord, nHyphenationPos );
684cdf0e10cSrcweir }
685cdf0e10cSrcweir
686cdf0e10cSrcweir if (nOrigHyphenPos == -1 || nOrigHyphenationPos == -1)
687cdf0e10cSrcweir {
688cdf0e10cSrcweir DBG_ASSERT( 0, "failed to get nOrigHyphenPos or nOrigHyphenationPos" );
689cdf0e10cSrcweir }
690cdf0e10cSrcweir else
691cdf0e10cSrcweir {
692cdf0e10cSrcweir sal_Int16 nLang = LocaleToLanguage( rxHyphWord->getLocale() );
693cdf0e10cSrcweir xRes = new HyphenatedWord(
694cdf0e10cSrcweir rOrigWord, nLang, nOrigHyphenationPos,
695cdf0e10cSrcweir aOrigHyphenatedWord, nOrigHyphenPos );
696cdf0e10cSrcweir }
697cdf0e10cSrcweir
698cdf0e10cSrcweir }
699cdf0e10cSrcweir return xRes;
700cdf0e10cSrcweir }
701cdf0e10cSrcweir
702cdf0e10cSrcweir
703cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
704cdf0e10cSrcweir
705cdf0e10cSrcweir
lcl_GetCharClass()706cdf0e10cSrcweir static CharClass & lcl_GetCharClass()
707cdf0e10cSrcweir {
708cdf0e10cSrcweir static CharClass aCC( CreateLocale( LANGUAGE_ENGLISH_US ) );
709cdf0e10cSrcweir return aCC;
710cdf0e10cSrcweir }
711cdf0e10cSrcweir
712cdf0e10cSrcweir
lcl_GetCharClassMutex()713cdf0e10cSrcweir osl::Mutex & lcl_GetCharClassMutex()
714cdf0e10cSrcweir {
715cdf0e10cSrcweir static osl::Mutex aMutex;
716cdf0e10cSrcweir return aMutex;
717cdf0e10cSrcweir }
718cdf0e10cSrcweir
719cdf0e10cSrcweir
IsUpper(const String & rText,xub_StrLen nPos,xub_StrLen nLen,sal_Int16 nLanguage)720cdf0e10cSrcweir sal_Bool IsUpper( const String &rText, xub_StrLen nPos, xub_StrLen nLen, sal_Int16 nLanguage )
721cdf0e10cSrcweir {
722cdf0e10cSrcweir MutexGuard aGuard( lcl_GetCharClassMutex() );
723cdf0e10cSrcweir
724cdf0e10cSrcweir CharClass &rCC = lcl_GetCharClass();
725cdf0e10cSrcweir rCC.setLocale( CreateLocale( nLanguage ) );
726cdf0e10cSrcweir sal_Int32 nFlags = rCC.getStringType( rText, nPos, nLen );
727cdf0e10cSrcweir return (nFlags & KCharacterType::UPPER)
728cdf0e10cSrcweir && !(nFlags & KCharacterType::LOWER);
729cdf0e10cSrcweir }
730cdf0e10cSrcweir
731cdf0e10cSrcweir
IsLower(const String & rText,xub_StrLen nPos,xub_StrLen nLen,sal_Int16 nLanguage)732cdf0e10cSrcweir sal_Bool IsLower( const String &rText, xub_StrLen nPos, xub_StrLen nLen, sal_Int16 nLanguage )
733cdf0e10cSrcweir {
734cdf0e10cSrcweir MutexGuard aGuard( lcl_GetCharClassMutex() );
735cdf0e10cSrcweir
736cdf0e10cSrcweir CharClass &rCC = lcl_GetCharClass();
737cdf0e10cSrcweir rCC.setLocale( CreateLocale( nLanguage ) );
738cdf0e10cSrcweir sal_Int32 nFlags = rCC.getStringType( rText, nPos, nLen );
739cdf0e10cSrcweir return (nFlags & KCharacterType::LOWER)
740cdf0e10cSrcweir && !(nFlags & KCharacterType::UPPER);
741cdf0e10cSrcweir }
742cdf0e10cSrcweir
743cdf0e10cSrcweir
ToLower(const String & rText,sal_Int16 nLanguage)744cdf0e10cSrcweir String ToLower( const String &rText, sal_Int16 nLanguage )
745cdf0e10cSrcweir {
746cdf0e10cSrcweir MutexGuard aGuard( lcl_GetCharClassMutex() );
747cdf0e10cSrcweir
748cdf0e10cSrcweir CharClass &rCC = lcl_GetCharClass();
749cdf0e10cSrcweir rCC.setLocale( CreateLocale( nLanguage ) );
750cdf0e10cSrcweir return rCC.lower( rText );
751cdf0e10cSrcweir }
752cdf0e10cSrcweir
753cdf0e10cSrcweir
ToUpper(const String & rText,sal_Int16 nLanguage)754cdf0e10cSrcweir String ToUpper( const String &rText, sal_Int16 nLanguage )
755cdf0e10cSrcweir {
756cdf0e10cSrcweir MutexGuard aGuard( lcl_GetCharClassMutex() );
757cdf0e10cSrcweir
758cdf0e10cSrcweir CharClass &rCC = lcl_GetCharClass();
759cdf0e10cSrcweir rCC.setLocale( CreateLocale( nLanguage ) );
760cdf0e10cSrcweir return rCC.upper( rText );
761cdf0e10cSrcweir }
762cdf0e10cSrcweir
763cdf0e10cSrcweir
ToTitle(const String & rText,sal_Int16 nLanguage)764cdf0e10cSrcweir String ToTitle( const String &rText, sal_Int16 nLanguage )
765cdf0e10cSrcweir {
766cdf0e10cSrcweir MutexGuard aGuard( lcl_GetCharClassMutex() );
767cdf0e10cSrcweir
768cdf0e10cSrcweir CharClass &rCC = lcl_GetCharClass();
769cdf0e10cSrcweir rCC.setLocale( CreateLocale( nLanguage ) );
770cdf0e10cSrcweir return rCC.toTitle( rText, 0, rText.Len() );
771cdf0e10cSrcweir }
772cdf0e10cSrcweir
773cdf0e10cSrcweir
ToLower(const sal_Unicode cChar,sal_Int16 nLanguage)774cdf0e10cSrcweir sal_Unicode ToLower( const sal_Unicode cChar, sal_Int16 nLanguage )
775cdf0e10cSrcweir {
776cdf0e10cSrcweir MutexGuard aGuard( lcl_GetCharClassMutex() );
777cdf0e10cSrcweir
778cdf0e10cSrcweir CharClass &rCC = lcl_GetCharClass();
779cdf0e10cSrcweir rCC.setLocale( CreateLocale( nLanguage ) );
780cdf0e10cSrcweir return rCC.lower( cChar ).GetChar(0);
781cdf0e10cSrcweir }
782cdf0e10cSrcweir
783cdf0e10cSrcweir
ToUpper(const sal_Unicode cChar,sal_Int16 nLanguage)784cdf0e10cSrcweir sal_Unicode ToUpper( const sal_Unicode cChar, sal_Int16 nLanguage )
785cdf0e10cSrcweir {
786cdf0e10cSrcweir MutexGuard aGuard( lcl_GetCharClassMutex() );
787cdf0e10cSrcweir
788cdf0e10cSrcweir CharClass &rCC = lcl_GetCharClass();
789cdf0e10cSrcweir rCC.setLocale( CreateLocale( nLanguage ) );
790cdf0e10cSrcweir return rCC.upper( cChar ).GetChar(0);
791cdf0e10cSrcweir }
792cdf0e10cSrcweir
793cdf0e10cSrcweir // sorted(!) array of unicode ranges for code points that are exclusively(!) used as numbers
794cdf0e10cSrcweir // and thus may NOT not be part of names or words like the Chinese/Japanese number characters
795cdf0e10cSrcweir static const sal_uInt32 the_aDigitZeroes [] =
796cdf0e10cSrcweir {
797cdf0e10cSrcweir 0x00000030, //0039 ; Decimal # Nd [10] DIGIT ZERO..DIGIT NINE
798cdf0e10cSrcweir 0x00000660, //0669 ; Decimal # Nd [10] ARABIC-INDIC DIGIT ZERO..ARABIC-INDIC DIGIT NINE
799cdf0e10cSrcweir 0x000006F0, //06F9 ; Decimal # Nd [10] EXTENDED ARABIC-INDIC DIGIT ZERO..EXTENDED ARABIC-INDIC DIGIT NINE
800cdf0e10cSrcweir 0x000007C0, //07C9 ; Decimal # Nd [10] NKO DIGIT ZERO..NKO DIGIT NINE
801cdf0e10cSrcweir 0x00000966, //096F ; Decimal # Nd [10] DEVANAGARI DIGIT ZERO..DEVANAGARI DIGIT NINE
802cdf0e10cSrcweir 0x000009E6, //09EF ; Decimal # Nd [10] BENGALI DIGIT ZERO..BENGALI DIGIT NINE
803cdf0e10cSrcweir 0x00000A66, //0A6F ; Decimal # Nd [10] GURMUKHI DIGIT ZERO..GURMUKHI DIGIT NINE
804cdf0e10cSrcweir 0x00000AE6, //0AEF ; Decimal # Nd [10] GUJARATI DIGIT ZERO..GUJARATI DIGIT NINE
805cdf0e10cSrcweir 0x00000B66, //0B6F ; Decimal # Nd [10] ORIYA DIGIT ZERO..ORIYA DIGIT NINE
806cdf0e10cSrcweir 0x00000BE6, //0BEF ; Decimal # Nd [10] TAMIL DIGIT ZERO..TAMIL DIGIT NINE
807cdf0e10cSrcweir 0x00000C66, //0C6F ; Decimal # Nd [10] TELUGU DIGIT ZERO..TELUGU DIGIT NINE
808cdf0e10cSrcweir 0x00000CE6, //0CEF ; Decimal # Nd [10] KANNADA DIGIT ZERO..KANNADA DIGIT NINE
809cdf0e10cSrcweir 0x00000D66, //0D6F ; Decimal # Nd [10] MALAYALAM DIGIT ZERO..MALAYALAM DIGIT NINE
810cdf0e10cSrcweir 0x00000E50, //0E59 ; Decimal # Nd [10] THAI DIGIT ZERO..THAI DIGIT NINE
811cdf0e10cSrcweir 0x00000ED0, //0ED9 ; Decimal # Nd [10] LAO DIGIT ZERO..LAO DIGIT NINE
812cdf0e10cSrcweir 0x00000F20, //0F29 ; Decimal # Nd [10] TIBETAN DIGIT ZERO..TIBETAN DIGIT NINE
813cdf0e10cSrcweir 0x00001040, //1049 ; Decimal # Nd [10] MYANMAR DIGIT ZERO..MYANMAR DIGIT NINE
814cdf0e10cSrcweir 0x00001090, //1099 ; Decimal # Nd [10] MYANMAR SHAN DIGIT ZERO..MYANMAR SHAN DIGIT NINE
815cdf0e10cSrcweir 0x000017E0, //17E9 ; Decimal # Nd [10] KHMER DIGIT ZERO..KHMER DIGIT NINE
816cdf0e10cSrcweir 0x00001810, //1819 ; Decimal # Nd [10] MONGOLIAN DIGIT ZERO..MONGOLIAN DIGIT NINE
817cdf0e10cSrcweir 0x00001946, //194F ; Decimal # Nd [10] LIMBU DIGIT ZERO..LIMBU DIGIT NINE
818cdf0e10cSrcweir 0x000019D0, //19D9 ; Decimal # Nd [10] NEW TAI LUE DIGIT ZERO..NEW TAI LUE DIGIT NINE
819cdf0e10cSrcweir 0x00001B50, //1B59 ; Decimal # Nd [10] BALINESE DIGIT ZERO..BALINESE DIGIT NINE
820cdf0e10cSrcweir 0x00001BB0, //1BB9 ; Decimal # Nd [10] SUNDANESE DIGIT ZERO..SUNDANESE DIGIT NINE
821cdf0e10cSrcweir 0x00001C40, //1C49 ; Decimal # Nd [10] LEPCHA DIGIT ZERO..LEPCHA DIGIT NINE
822cdf0e10cSrcweir 0x00001C50, //1C59 ; Decimal # Nd [10] OL CHIKI DIGIT ZERO..OL CHIKI DIGIT NINE
823cdf0e10cSrcweir 0x0000A620, //A629 ; Decimal # Nd [10] VAI DIGIT ZERO..VAI DIGIT NINE
824cdf0e10cSrcweir 0x0000A8D0, //A8D9 ; Decimal # Nd [10] SAURASHTRA DIGIT ZERO..SAURASHTRA DIGIT NINE
825cdf0e10cSrcweir 0x0000A900, //A909 ; Decimal # Nd [10] KAYAH LI DIGIT ZERO..KAYAH LI DIGIT NINE
826cdf0e10cSrcweir 0x0000AA50, //AA59 ; Decimal # Nd [10] CHAM DIGIT ZERO..CHAM DIGIT NINE
827cdf0e10cSrcweir 0x0000FF10, //FF19 ; Decimal # Nd [10] FULLWIDTH DIGIT ZERO..FULLWIDTH DIGIT NINE
828cdf0e10cSrcweir 0x000104A0, //104A9 ; Decimal # Nd [10] OSMANYA DIGIT ZERO..OSMANYA DIGIT NINE
829cdf0e10cSrcweir 0x0001D7CE //1D7FF ; Decimal # Nd [50] MATHEMATICAL BOLD DIGIT ZERO..MATHEMATICAL MONOSPACE DIGIT NINE
830cdf0e10cSrcweir };
831cdf0e10cSrcweir
HasDigits(const OUString & rText)832cdf0e10cSrcweir sal_Bool HasDigits( const OUString &rText )
833cdf0e10cSrcweir {
834cdf0e10cSrcweir static const int nNumDigitZeroes = sizeof(the_aDigitZeroes) / sizeof(the_aDigitZeroes[0]);
835cdf0e10cSrcweir const sal_Int32 nLen = rText.getLength();
836cdf0e10cSrcweir
837cdf0e10cSrcweir sal_Int32 i = 0;
838cdf0e10cSrcweir while (i < nLen) // for all characters ...
839cdf0e10cSrcweir {
840cdf0e10cSrcweir const sal_uInt32 nCodePoint = rText.iterateCodePoints( &i ); // handle unicode surrogates correctly...
841cdf0e10cSrcweir for (int j = 0; j < nNumDigitZeroes; ++j) // ... check in all 0..9 ranges
842cdf0e10cSrcweir {
843cdf0e10cSrcweir sal_uInt32 nDigitZero = the_aDigitZeroes[ j ];
844cdf0e10cSrcweir if (nDigitZero > nCodePoint)
845cdf0e10cSrcweir break;
846cdf0e10cSrcweir if (/*nDigitZero <= nCodePoint &&*/ nCodePoint <= nDigitZero + 9)
847cdf0e10cSrcweir return sal_True;
848cdf0e10cSrcweir }
849cdf0e10cSrcweir }
850cdf0e10cSrcweir return sal_False;
851cdf0e10cSrcweir }
852cdf0e10cSrcweir
853cdf0e10cSrcweir
IsNumeric(const String & rText)854cdf0e10cSrcweir sal_Bool IsNumeric( const String &rText )
855cdf0e10cSrcweir {
856cdf0e10cSrcweir sal_Bool bRes = sal_False;
857cdf0e10cSrcweir xub_StrLen nLen = rText.Len();
858cdf0e10cSrcweir if (nLen)
859cdf0e10cSrcweir {
860cdf0e10cSrcweir bRes = sal_True;
861cdf0e10cSrcweir xub_StrLen i = 0;
862cdf0e10cSrcweir while (i < nLen)
863cdf0e10cSrcweir {
864cdf0e10cSrcweir sal_Unicode cChar = rText.GetChar( i++ );
865cdf0e10cSrcweir if ( !((sal_Unicode)'0' <= cChar && cChar <= (sal_Unicode)'9') )
866cdf0e10cSrcweir {
867cdf0e10cSrcweir bRes = sal_False;
868cdf0e10cSrcweir break;
869cdf0e10cSrcweir }
870cdf0e10cSrcweir }
871cdf0e10cSrcweir }
872cdf0e10cSrcweir return bRes;
873cdf0e10cSrcweir }
874cdf0e10cSrcweir
875cdf0e10cSrcweir
876cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
877cdf0e10cSrcweir
GetOneInstanceService(const char * pServiceName)878cdf0e10cSrcweir uno::Reference< XInterface > GetOneInstanceService( const char *pServiceName )
879cdf0e10cSrcweir {
880cdf0e10cSrcweir uno::Reference< XInterface > xRef;
881cdf0e10cSrcweir
882cdf0e10cSrcweir if (pServiceName)
883cdf0e10cSrcweir {
884cdf0e10cSrcweir uno::Reference< XMultiServiceFactory > xMgr( getProcessServiceFactory() );
885cdf0e10cSrcweir if (xMgr.is())
886cdf0e10cSrcweir {
887cdf0e10cSrcweir try
888cdf0e10cSrcweir {
889cdf0e10cSrcweir xRef = xMgr->createInstance( A2OU( pServiceName ) );
890cdf0e10cSrcweir }
891cdf0e10cSrcweir catch (uno::Exception &)
892cdf0e10cSrcweir {
893cdf0e10cSrcweir DBG_ASSERT( 0, "createInstance failed" );
894cdf0e10cSrcweir }
895cdf0e10cSrcweir }
896cdf0e10cSrcweir }
897cdf0e10cSrcweir
898cdf0e10cSrcweir return xRef;
899cdf0e10cSrcweir }
900cdf0e10cSrcweir
GetLinguProperties()901cdf0e10cSrcweir uno::Reference< XPropertySet > GetLinguProperties()
902cdf0e10cSrcweir {
903cdf0e10cSrcweir return uno::Reference< XPropertySet > (
904cdf0e10cSrcweir GetOneInstanceService( SN_LINGU_PROPERTIES ), UNO_QUERY );
905cdf0e10cSrcweir }
906cdf0e10cSrcweir
GetSearchableDictionaryList()907cdf0e10cSrcweir uno::Reference< XSearchableDictionaryList > GetSearchableDictionaryList()
908cdf0e10cSrcweir {
909cdf0e10cSrcweir return uno::Reference< XSearchableDictionaryList > (
910cdf0e10cSrcweir GetOneInstanceService( SN_DICTIONARY_LIST ), UNO_QUERY );
911cdf0e10cSrcweir }
912cdf0e10cSrcweir
GetDictionaryList()913cdf0e10cSrcweir uno::Reference< XDictionaryList > GetDictionaryList()
914cdf0e10cSrcweir {
915cdf0e10cSrcweir return uno::Reference< XDictionaryList > (
916cdf0e10cSrcweir GetOneInstanceService( SN_DICTIONARY_LIST ), UNO_QUERY );
917cdf0e10cSrcweir }
918cdf0e10cSrcweir
GetIgnoreAllList()919cdf0e10cSrcweir uno::Reference< XDictionary > GetIgnoreAllList()
920cdf0e10cSrcweir {
921cdf0e10cSrcweir uno::Reference< XDictionary > xRes;
922cdf0e10cSrcweir uno::Reference< XDictionaryList > xDL( GetDictionaryList() );
923cdf0e10cSrcweir if (xDL.is())
924cdf0e10cSrcweir xRes = xDL->getDictionaryByName( A2OU("IgnoreAllList") );
925cdf0e10cSrcweir return xRes;
926cdf0e10cSrcweir }
927cdf0e10cSrcweir
928cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
929cdf0e10cSrcweir
AppExitListener()930cdf0e10cSrcweir AppExitListener::AppExitListener()
931cdf0e10cSrcweir {
932cdf0e10cSrcweir // add object to Desktop EventListeners in order to properly call
933cdf0e10cSrcweir // the AtExit function at appliction exit.
934cdf0e10cSrcweir uno::Reference< XMultiServiceFactory > xMgr = getProcessServiceFactory();
935cdf0e10cSrcweir
936cdf0e10cSrcweir if (xMgr.is())
937cdf0e10cSrcweir {
938cdf0e10cSrcweir try
939cdf0e10cSrcweir {
940cdf0e10cSrcweir xDesktop = uno::Reference< frame::XDesktop >(
941cdf0e10cSrcweir xMgr->createInstance( A2OU( SN_DESKTOP ) ), UNO_QUERY );
942cdf0e10cSrcweir }
943cdf0e10cSrcweir catch (uno::Exception &)
944cdf0e10cSrcweir {
945cdf0e10cSrcweir DBG_ASSERT( 0, "createInstance failed" );
946cdf0e10cSrcweir }
947cdf0e10cSrcweir }
948cdf0e10cSrcweir }
949cdf0e10cSrcweir
~AppExitListener()950cdf0e10cSrcweir AppExitListener::~AppExitListener()
951cdf0e10cSrcweir {
952cdf0e10cSrcweir }
953cdf0e10cSrcweir
954cdf0e10cSrcweir
Activate()955cdf0e10cSrcweir void AppExitListener::Activate()
956cdf0e10cSrcweir {
957cdf0e10cSrcweir if (xDesktop.is())
958cdf0e10cSrcweir xDesktop->addTerminateListener( this );
959cdf0e10cSrcweir }
960cdf0e10cSrcweir
961cdf0e10cSrcweir
Deactivate()962cdf0e10cSrcweir void AppExitListener::Deactivate()
963cdf0e10cSrcweir {
964cdf0e10cSrcweir if (xDesktop.is())
965cdf0e10cSrcweir xDesktop->removeTerminateListener( this );
966cdf0e10cSrcweir }
967cdf0e10cSrcweir
968cdf0e10cSrcweir
969cdf0e10cSrcweir void SAL_CALL
disposing(const EventObject & rEvtSource)970cdf0e10cSrcweir AppExitListener::disposing( const EventObject& rEvtSource )
971cdf0e10cSrcweir throw(RuntimeException)
972cdf0e10cSrcweir {
973cdf0e10cSrcweir MutexGuard aGuard( GetLinguMutex() );
974cdf0e10cSrcweir
975cdf0e10cSrcweir if (xDesktop.is() && rEvtSource.Source == xDesktop)
976cdf0e10cSrcweir {
977cdf0e10cSrcweir xDesktop = NULL; //! release reference to desktop
978cdf0e10cSrcweir }
979cdf0e10cSrcweir }
980cdf0e10cSrcweir
981cdf0e10cSrcweir
982cdf0e10cSrcweir void SAL_CALL
queryTermination(const EventObject &)983cdf0e10cSrcweir AppExitListener::queryTermination( const EventObject& /*rEvtSource*/ )
984cdf0e10cSrcweir throw(frame::TerminationVetoException, RuntimeException)
985cdf0e10cSrcweir {
986cdf0e10cSrcweir //MutexGuard aGuard( GetLinguMutex() );
987cdf0e10cSrcweir }
988cdf0e10cSrcweir
989cdf0e10cSrcweir
990cdf0e10cSrcweir void SAL_CALL
notifyTermination(const EventObject & rEvtSource)991cdf0e10cSrcweir AppExitListener::notifyTermination( const EventObject& rEvtSource )
992cdf0e10cSrcweir throw(RuntimeException)
993cdf0e10cSrcweir {
994cdf0e10cSrcweir MutexGuard aGuard( GetLinguMutex() );
995cdf0e10cSrcweir
996cdf0e10cSrcweir if (xDesktop.is() && rEvtSource.Source == xDesktop)
997cdf0e10cSrcweir {
998cdf0e10cSrcweir AtExit();
999cdf0e10cSrcweir }
1000cdf0e10cSrcweir }
1001cdf0e10cSrcweir
1002cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
1003cdf0e10cSrcweir
1004cdf0e10cSrcweir } // namespace linguistic
1005cdf0e10cSrcweir
1006