bump product version to 5.0.4.1
[LibreOffice.git] / editeng / source / misc / unolingu.cxx
blobc85eda2586df046f70603a531a04ca036e452fa7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <editeng/unolingu.hxx>
22 #include <unotools/pathoptions.hxx>
23 #include <com/sun/star/frame/Desktop.hpp>
24 #include <com/sun/star/frame/XModel.hpp>
25 #include <com/sun/star/frame/XStorable.hpp>
26 #include <com/sun/star/lang/XEventListener.hpp>
27 #include <com/sun/star/linguistic2/DictionaryList.hpp>
28 #include <com/sun/star/linguistic2/XAvailableLocales.hpp>
29 #include <com/sun/star/linguistic2/LinguServiceManager.hpp>
30 #include <com/sun/star/linguistic2/LinguProperties.hpp>
31 #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
32 #include <com/sun/star/ucb/XContentAccess.hpp>
33 #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
34 #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
35 #include <com/sun/star/sdbc/XResultSet.hpp>
36 #include <com/sun/star/sdbc/XRow.hpp>
37 #include <com/sun/star/util/DateTime.hpp>
39 #include <comphelper/processfactory.hxx>
40 #include <cppuhelper/implbase1.hxx>
41 #include <i18nlangtag/languagetag.hxx>
42 #include <unotools/lingucfg.hxx>
43 #include <unotools/ucbhelper.hxx>
44 #include <unotools/localfilehelper.hxx>
45 #include <ucbhelper/commandenvironment.hxx>
46 #include <ucbhelper/content.hxx>
47 #include <vcl/msgbox.hxx>
48 #include <vcl/svapp.hxx>
49 #include <linguistic/misc.hxx>
50 #include <editeng/eerdll.hxx>
51 #include <editeng/editrids.hrc>
53 using namespace ::comphelper;
54 using namespace ::linguistic;
55 using namespace ::com::sun::star;
56 using namespace ::com::sun::star::util;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::lang;
59 using namespace ::com::sun::star::beans;
60 using namespace ::com::sun::star::frame;
61 using namespace ::com::sun::star::linguistic2;
63 static uno::Reference< XLinguServiceManager2 > GetLngSvcMgr_Impl()
65 uno::Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
66 uno::Reference< XLinguServiceManager2 > xRes = LinguServiceManager::create(xContext);
67 return xRes;
70 //! Dummy implementation in order to avoid loading of lingu DLL
71 //! when only the XSupportedLocales interface is used.
72 //! The dummy accesses the real implementation (and thus loading the DLL)
73 //! when "real" work needs to be done only.
74 class ThesDummy_Impl :
75 public cppu::WeakImplHelper1< XThesaurus >
77 uno::Reference< XThesaurus > xThes; // the real one...
78 Sequence< lang::Locale > *pLocaleSeq;
80 void GetCfgLocales();
82 void GetThes_Impl();
84 public:
85 ThesDummy_Impl() : pLocaleSeq(0) {}
86 virtual ~ThesDummy_Impl();
88 // XSupportedLocales
89 virtual ::com::sun::star::uno::Sequence<
90 ::com::sun::star::lang::Locale > SAL_CALL
91 getLocales()
92 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
93 virtual sal_Bool SAL_CALL
94 hasLocale( const ::com::sun::star::lang::Locale& rLocale )
95 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
97 // XThesaurus
98 virtual ::com::sun::star::uno::Sequence<
99 ::com::sun::star::uno::Reference<
100 ::com::sun::star::linguistic2::XMeaning > > SAL_CALL
101 queryMeanings( const OUString& rTerm,
102 const ::com::sun::star::lang::Locale& rLocale,
103 const ::com::sun::star::beans::PropertyValues& rProperties )
104 throw(::com::sun::star::lang::IllegalArgumentException,
105 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
109 ThesDummy_Impl::~ThesDummy_Impl()
111 delete pLocaleSeq;
115 void ThesDummy_Impl::GetCfgLocales()
117 if (!pLocaleSeq)
119 SvtLinguConfig aCfg;
120 OUString aNode("ServiceManager/ThesaurusList");
121 Sequence < OUString > aNodeNames( aCfg.GetNodeNames( aNode ) );
122 const OUString *pNodeNames = aNodeNames.getConstArray();
123 sal_Int32 nLen = aNodeNames.getLength();
124 pLocaleSeq = new Sequence< lang::Locale >( nLen );
125 lang::Locale *pLocale = pLocaleSeq->getArray();
126 for (sal_Int32 i = 0; i < nLen; ++i)
128 pLocale[i] = LanguageTag::convertToLocaleWithFallback( pNodeNames[i] );
134 void ThesDummy_Impl::GetThes_Impl()
136 if (!xThes.is())
138 uno::Reference< XLinguServiceManager2 > xLngSvcMgr( GetLngSvcMgr_Impl() );
139 xThes = xLngSvcMgr->getThesaurus();
141 if (xThes.is())
143 // no longer needed...
144 delete pLocaleSeq; pLocaleSeq = 0;
150 uno::Sequence< lang::Locale > SAL_CALL
151 ThesDummy_Impl::getLocales()
152 throw(uno::RuntimeException, std::exception)
154 GetThes_Impl();
155 if (xThes.is())
156 return xThes->getLocales();
157 else if (!pLocaleSeq) // if not already loaded save startup time by avoiding loading them now
158 GetCfgLocales();
159 return *pLocaleSeq;
163 sal_Bool SAL_CALL
164 ThesDummy_Impl::hasLocale( const lang::Locale& rLocale )
165 throw(uno::RuntimeException, std::exception)
167 GetThes_Impl();
168 if (xThes.is())
169 return xThes->hasLocale( rLocale );
170 else if (!pLocaleSeq) // if not already loaded save startup time by avoiding loading them now
171 GetCfgLocales();
172 bool bFound = false;
173 sal_Int32 nLen = pLocaleSeq->getLength();
174 const lang::Locale *pLocale = pLocaleSeq->getConstArray();
175 const lang::Locale *pEnd = pLocale + nLen;
176 for ( ; pLocale < pEnd && !bFound; ++pLocale)
178 bFound = pLocale->Language == rLocale.Language &&
179 pLocale->Country == rLocale.Country &&
180 pLocale->Variant == rLocale.Variant;
182 return bFound;
186 uno::Sequence< uno::Reference< linguistic2::XMeaning > > SAL_CALL
187 ThesDummy_Impl::queryMeanings(
188 const OUString& rTerm,
189 const lang::Locale& rLocale,
190 const beans::PropertyValues& rProperties )
191 throw(lang::IllegalArgumentException,
192 uno::RuntimeException, std::exception)
194 GetThes_Impl();
195 uno::Sequence< uno::Reference< linguistic2::XMeaning > > aRes;
196 OSL_ENSURE( xThes.is(), "Thesaurus missing" );
197 if (xThes.is())
198 aRes = xThes->queryMeanings( rTerm, rLocale, rProperties );
199 return aRes;
203 //! Dummy implementation in order to avoid loading of lingu DLL.
204 //! The dummy accesses the real implementation (and thus loading the DLL)
205 //! when it needs to be done only.
206 class SpellDummy_Impl :
207 public cppu::WeakImplHelper1< XSpellChecker1 >
209 uno::Reference< XSpellChecker1 > xSpell; // the real one...
211 void GetSpell_Impl();
213 public:
215 // XSupportedLanguages (for XSpellChecker1)
216 virtual ::com::sun::star::uno::Sequence< sal_Int16 > SAL_CALL
217 getLanguages()
218 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
219 virtual sal_Bool SAL_CALL
220 hasLanguage( sal_Int16 nLanguage )
221 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
223 // XSpellChecker1 (same as XSpellChecker but sal_Int16 for language)
224 virtual sal_Bool SAL_CALL
225 isValid( const OUString& rWord, sal_Int16 nLanguage,
226 const ::com::sun::star::beans::PropertyValues& rProperties )
227 throw(::com::sun::star::lang::IllegalArgumentException,
228 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
229 virtual ::com::sun::star::uno::Reference<
230 ::com::sun::star::linguistic2::XSpellAlternatives > SAL_CALL
231 spell( const OUString& rWord, sal_Int16 nLanguage,
232 const ::com::sun::star::beans::PropertyValues& rProperties )
233 throw(::com::sun::star::lang::IllegalArgumentException,
234 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
238 void SpellDummy_Impl::GetSpell_Impl()
240 if (!xSpell.is())
242 uno::Reference< XLinguServiceManager2 > xLngSvcMgr( GetLngSvcMgr_Impl() );
243 xSpell = uno::Reference< XSpellChecker1 >( xLngSvcMgr->getSpellChecker(), UNO_QUERY );
248 uno::Sequence< sal_Int16 > SAL_CALL
249 SpellDummy_Impl::getLanguages()
250 throw(uno::RuntimeException, std::exception)
252 GetSpell_Impl();
253 if (xSpell.is())
254 return xSpell->getLanguages();
255 else
256 return uno::Sequence< sal_Int16 >();
260 sal_Bool SAL_CALL
261 SpellDummy_Impl::hasLanguage( sal_Int16 nLanguage )
262 throw(uno::RuntimeException, std::exception)
264 GetSpell_Impl();
265 bool bRes = false;
266 if (xSpell.is())
267 bRes = xSpell->hasLanguage( nLanguage );
268 return bRes;
272 sal_Bool SAL_CALL
273 SpellDummy_Impl::isValid( const OUString& rWord, sal_Int16 nLanguage,
274 const beans::PropertyValues& rProperties )
275 throw(lang::IllegalArgumentException,
276 uno::RuntimeException, std::exception)
278 GetSpell_Impl();
279 bool bRes = true;
280 if (xSpell.is())
281 bRes = xSpell->isValid( rWord, nLanguage, rProperties );
282 return bRes;
286 uno::Reference< linguistic2::XSpellAlternatives > SAL_CALL
287 SpellDummy_Impl::spell( const OUString& rWord, sal_Int16 nLanguage,
288 const beans::PropertyValues& rProperties )
289 throw(lang::IllegalArgumentException,
290 uno::RuntimeException, std::exception)
292 GetSpell_Impl();
293 uno::Reference< linguistic2::XSpellAlternatives > xRes;
294 if (xSpell.is())
295 xRes = xSpell->spell( rWord, nLanguage, rProperties );
296 return xRes;
300 //! Dummy implementation in order to avoid loading of lingu DLL.
301 //! The dummy accesses the real implementation (and thus loading the DLL)
302 //! when it needs to be done only.
303 class HyphDummy_Impl :
304 public cppu::WeakImplHelper1< XHyphenator >
306 uno::Reference< XHyphenator > xHyph; // the real one...
308 void GetHyph_Impl();
310 public:
312 // XSupportedLocales
313 virtual ::com::sun::star::uno::Sequence<
314 ::com::sun::star::lang::Locale > SAL_CALL
315 getLocales()
316 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
317 virtual sal_Bool SAL_CALL
318 hasLocale( const ::com::sun::star::lang::Locale& rLocale )
319 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
321 // XHyphenator
322 virtual ::com::sun::star::uno::Reference<
323 ::com::sun::star::linguistic2::XHyphenatedWord > SAL_CALL
324 hyphenate( const OUString& rWord,
325 const ::com::sun::star::lang::Locale& rLocale,
326 sal_Int16 nMaxLeading,
327 const ::com::sun::star::beans::PropertyValues& rProperties )
328 throw(::com::sun::star::lang::IllegalArgumentException,
329 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
330 virtual ::com::sun::star::uno::Reference<
331 ::com::sun::star::linguistic2::XHyphenatedWord > SAL_CALL
332 queryAlternativeSpelling( const OUString& rWord,
333 const ::com::sun::star::lang::Locale& rLocale,
334 sal_Int16 nIndex,
335 const ::com::sun::star::beans::PropertyValues& rProperties )
336 throw(::com::sun::star::lang::IllegalArgumentException,
337 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
338 virtual ::com::sun::star::uno::Reference<
339 ::com::sun::star::linguistic2::XPossibleHyphens > SAL_CALL
340 createPossibleHyphens(
341 const OUString& rWord,
342 const ::com::sun::star::lang::Locale& rLocale,
343 const ::com::sun::star::beans::PropertyValues& rProperties )
344 throw(::com::sun::star::lang::IllegalArgumentException,
345 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
349 void HyphDummy_Impl::GetHyph_Impl()
351 if (!xHyph.is())
353 uno::Reference< XLinguServiceManager2 > xLngSvcMgr( GetLngSvcMgr_Impl() );
354 xHyph = xLngSvcMgr->getHyphenator();
359 uno::Sequence< lang::Locale > SAL_CALL
360 HyphDummy_Impl::getLocales()
361 throw(uno::RuntimeException, std::exception)
363 GetHyph_Impl();
364 if (xHyph.is())
365 return xHyph->getLocales();
366 else
367 return uno::Sequence< lang::Locale >();
371 sal_Bool SAL_CALL
372 HyphDummy_Impl::hasLocale( const lang::Locale& rLocale )
373 throw(uno::RuntimeException, std::exception)
375 GetHyph_Impl();
376 bool bRes = false;
377 if (xHyph.is())
378 bRes = xHyph->hasLocale( rLocale );
379 return bRes;
383 uno::Reference< linguistic2::XHyphenatedWord > SAL_CALL
384 HyphDummy_Impl::hyphenate(
385 const OUString& rWord,
386 const lang::Locale& rLocale,
387 sal_Int16 nMaxLeading,
388 const beans::PropertyValues& rProperties )
389 throw(lang::IllegalArgumentException,
390 uno::RuntimeException, std::exception)
392 GetHyph_Impl();
393 uno::Reference< linguistic2::XHyphenatedWord > xRes;
394 if (xHyph.is())
395 xRes = xHyph->hyphenate( rWord, rLocale, nMaxLeading, rProperties );
396 return xRes;
400 uno::Reference< linguistic2::XHyphenatedWord > SAL_CALL
401 HyphDummy_Impl::queryAlternativeSpelling(
402 const OUString& rWord,
403 const lang::Locale& rLocale,
404 sal_Int16 nIndex,
405 const PropertyValues& rProperties )
406 throw(lang::IllegalArgumentException,
407 uno::RuntimeException, std::exception)
409 GetHyph_Impl();
410 uno::Reference< linguistic2::XHyphenatedWord > xRes;
411 if (xHyph.is())
412 xRes = xHyph->queryAlternativeSpelling( rWord, rLocale, nIndex, rProperties );
413 return xRes;
417 uno::Reference< linguistic2::XPossibleHyphens > SAL_CALL
418 HyphDummy_Impl::createPossibleHyphens(
419 const OUString& rWord,
420 const lang::Locale& rLocale,
421 const beans::PropertyValues& rProperties )
422 throw(lang::IllegalArgumentException,
423 uno::RuntimeException, std::exception)
425 GetHyph_Impl();
426 uno::Reference< linguistic2::XPossibleHyphens > xRes;
427 if (xHyph.is())
428 xRes = xHyph->createPossibleHyphens( rWord, rLocale, rProperties );
429 return xRes;
432 class LinguMgrExitLstnr : public cppu::WeakImplHelper1<XEventListener>
434 uno::Reference< XDesktop2 > xDesktop;
436 static void AtExit();
438 public:
439 LinguMgrExitLstnr();
440 virtual ~LinguMgrExitLstnr();
442 // lang::XEventListener
443 virtual void SAL_CALL disposing(const EventObject& rSource)
444 throw( RuntimeException, std::exception ) SAL_OVERRIDE;
447 LinguMgrExitLstnr::LinguMgrExitLstnr()
449 // add object to frame::Desktop EventListeners in order to properly call
450 // the AtExit function at appliction exit.
452 uno::Reference< XComponentContext > xContext = getProcessComponentContext();
453 xDesktop = Desktop::create( xContext );
454 xDesktop->addEventListener( this );
457 LinguMgrExitLstnr::~LinguMgrExitLstnr()
459 if (xDesktop.is())
461 xDesktop->removeEventListener( this );
462 xDesktop = NULL; //! release reference to desktop
464 OSL_ENSURE(!xDesktop.is(), "reference to desktop should be realeased");
467 void LinguMgrExitLstnr::disposing(const EventObject& rSource)
468 throw( RuntimeException, std::exception )
470 if (xDesktop.is() && rSource.Source == xDesktop)
472 xDesktop->removeEventListener( this );
473 xDesktop = NULL; //! release reference to desktop
475 AtExit();
479 void LinguMgrExitLstnr::AtExit()
481 SolarMutexGuard g;
483 // release references
484 LinguMgr::xLngSvcMgr = 0;
485 LinguMgr::xSpell = 0;
486 LinguMgr::xHyph = 0;
487 LinguMgr::xThes = 0;
488 LinguMgr::xDicList = 0;
489 LinguMgr::xProp = 0;
490 LinguMgr::xIgnoreAll = 0;
491 LinguMgr::xChangeAll = 0;
493 LinguMgr::bExiting = true;
495 LinguMgr::pExitLstnr = 0;
499 LinguMgrExitLstnr * LinguMgr::pExitLstnr = 0;
500 bool LinguMgr::bExiting = false;
501 uno::Reference< XLinguServiceManager2 > LinguMgr::xLngSvcMgr = 0;
502 uno::Reference< XSpellChecker1 > LinguMgr::xSpell = 0;
503 uno::Reference< XHyphenator > LinguMgr::xHyph = 0;
504 uno::Reference< XThesaurus > LinguMgr::xThes = 0;
505 uno::Reference< XSearchableDictionaryList > LinguMgr::xDicList = 0;
506 uno::Reference< XLinguProperties > LinguMgr::xProp = 0;
507 uno::Reference< XDictionary > LinguMgr::xIgnoreAll = 0;
508 uno::Reference< XDictionary > LinguMgr::xChangeAll = 0;
511 uno::Reference< XLinguServiceManager2 > LinguMgr::GetLngSvcMgr()
513 if (bExiting)
514 return 0;
516 if (!pExitLstnr)
517 pExitLstnr = new LinguMgrExitLstnr;
519 if (!xLngSvcMgr.is())
520 xLngSvcMgr = GetLngSvcMgr_Impl();
522 return xLngSvcMgr;
526 uno::Reference< XSpellChecker1 > LinguMgr::GetSpellChecker()
528 return xSpell.is() ? xSpell : GetSpell();
531 uno::Reference< XHyphenator > LinguMgr::GetHyphenator()
533 return xHyph.is() ? xHyph : GetHyph();
536 uno::Reference< XThesaurus > LinguMgr::GetThesaurus()
538 return xThes.is() ? xThes : GetThes();
541 uno::Reference< XSearchableDictionaryList > LinguMgr::GetDictionaryList()
543 return xDicList.is() ? xDicList : GetDicList();
546 uno::Reference< linguistic2::XLinguProperties > LinguMgr::GetLinguPropertySet()
548 return xProp.is() ? xProp : GetProp();
551 uno::Reference< XDictionary > LinguMgr::GetStandardDic()
553 //! don't hold reference to this
554 //! (it may be removed from dictionary list and needs to be
555 //! created empty if accessed again)
556 return GetStandard();
559 uno::Reference< XDictionary > LinguMgr::GetIgnoreAllList()
561 return xIgnoreAll.is() ? xIgnoreAll : GetIgnoreAll();
564 uno::Reference< XDictionary > LinguMgr::GetChangeAllList()
566 return xChangeAll.is() ? xChangeAll : GetChangeAll();
569 uno::Reference< XSpellChecker1 > LinguMgr::GetSpell()
571 if (bExiting)
572 return 0;
574 if (!pExitLstnr)
575 pExitLstnr = new LinguMgrExitLstnr;
577 //! use dummy implementation in order to avoid loading of lingu DLL
578 xSpell = new SpellDummy_Impl;
579 return xSpell;
582 uno::Reference< XHyphenator > LinguMgr::GetHyph()
584 if (bExiting)
585 return 0;
587 if (!pExitLstnr)
588 pExitLstnr = new LinguMgrExitLstnr;
590 //! use dummy implementation in order to avoid loading of lingu DLL
591 xHyph = new HyphDummy_Impl;
592 return xHyph;
595 uno::Reference< XThesaurus > LinguMgr::GetThes()
597 if (bExiting)
598 return 0;
600 if (!pExitLstnr)
601 pExitLstnr = new LinguMgrExitLstnr;
603 //! use dummy implementation in order to avoid loading of lingu DLL
604 //! when only the XSupportedLocales interface is used.
605 //! The dummy accesses the real implementation (and thus loading the DLL)
606 //! when "real" work needs to be done only.
607 xThes = new ThesDummy_Impl;
608 return xThes;
611 uno::Reference< XSearchableDictionaryList > LinguMgr::GetDicList()
613 if (bExiting)
614 return 0;
616 if (!pExitLstnr)
617 pExitLstnr = new LinguMgrExitLstnr;
619 xDicList = linguistic2::DictionaryList::create( getProcessComponentContext() );
620 return xDicList;
623 uno::Reference< linguistic2::XLinguProperties > LinguMgr::GetProp()
625 if (bExiting)
626 return 0;
628 if (!pExitLstnr)
629 pExitLstnr = new LinguMgrExitLstnr;
631 xProp = linguistic2::LinguProperties::create( getProcessComponentContext() );
632 return xProp;
635 uno::Reference< XDictionary > LinguMgr::GetIgnoreAll()
637 if (bExiting)
638 return 0;
640 if (!pExitLstnr)
641 pExitLstnr = new LinguMgrExitLstnr;
643 uno::Reference< XSearchableDictionaryList > xTmpDicList( GetDictionaryList() );
644 if (xTmpDicList.is())
646 xIgnoreAll = uno::Reference< XDictionary > ( xTmpDicList->getDictionaryByName(
647 "IgnoreAllList" ), UNO_QUERY );
649 return xIgnoreAll;
652 uno::Reference< XDictionary > LinguMgr::GetChangeAll()
654 if (bExiting)
655 return 0;
657 if (!pExitLstnr)
658 pExitLstnr = new LinguMgrExitLstnr;
660 uno::Reference< XSearchableDictionaryList > _xDicList( GetDictionaryList() , UNO_QUERY );
661 if (_xDicList.is())
663 xChangeAll = uno::Reference< XDictionary > (
664 _xDicList->createDictionary(
665 "ChangeAllList",
666 LanguageTag::convertToLocale( LANGUAGE_NONE ),
667 DictionaryType_NEGATIVE, OUString() ), UNO_QUERY );
669 return xChangeAll;
672 uno::Reference< XDictionary > LinguMgr::GetStandard()
674 // Tries to return a dictionary which may hold positive entries is
675 // persistent and not read-only.
677 if (bExiting)
678 return 0;
680 uno::Reference< XSearchableDictionaryList > xTmpDicList( GetDictionaryList() );
681 if (!xTmpDicList.is())
682 return NULL;
684 const OUString aDicName( "standard.dic" );
685 uno::Reference< XDictionary > xDic( xTmpDicList->getDictionaryByName( aDicName ),
686 UNO_QUERY );
687 if (!xDic.is())
689 // try to create standard dictionary
690 uno::Reference< XDictionary > xTmp;
693 xTmp = xTmpDicList->createDictionary( aDicName,
694 LanguageTag::convertToLocale( LANGUAGE_NONE ),
695 DictionaryType_POSITIVE,
696 linguistic::GetWritableDictionaryURL( aDicName ) );
698 catch(const com::sun::star::uno::Exception &)
702 // add new dictionary to list
703 if (xTmp.is())
705 xTmpDicList->addDictionary( xTmp );
706 xTmp->setActive( sal_True );
708 xDic = uno::Reference< XDictionary > ( xTmp, UNO_QUERY );
710 #if OSL_DEBUG_LEVEL > 1
711 uno::Reference< XStorable > xStor( xDic, UNO_QUERY );
712 OSL_ENSURE( xDic.is() && xDic->getDictionaryType() == DictionaryType_POSITIVE,
713 "wrong dictionary type");
714 OSL_ENSURE( xDic.is() && LanguageTag( xDic->getLocale() ).getLanguageType() == LANGUAGE_NONE,
715 "wrong dictionary language");
716 OSL_ENSURE( !xStor.is() || (xStor->hasLocation() && !xStor->isReadonly()),
717 "dictionary not editable" );
718 #endif
720 return xDic;
723 uno::Reference< XSpellChecker1 > SvxGetSpellChecker()
725 return LinguMgr::GetSpellChecker();
728 uno::Reference< XHyphenator > SvxGetHyphenator()
730 return LinguMgr::GetHyphenator();
733 uno::Reference< XThesaurus > SvxGetThesaurus()
735 return LinguMgr::GetThesaurus();
738 uno::Reference< XSearchableDictionaryList > SvxGetDictionaryList()
740 return LinguMgr::GetDictionaryList();
743 uno::Reference< XLinguProperties > SvxGetLinguPropertySet()
745 return LinguMgr::GetLinguPropertySet();
748 //TODO: remove argument or provide SvxGetIgnoreAllList with the same one
749 uno::Reference< XDictionary > SvxGetOrCreatePosDic(
750 uno::Reference< XSearchableDictionaryList > /* xDicList */ )
752 return LinguMgr::GetStandardDic();
755 uno::Reference< XDictionary > SvxGetIgnoreAllList()
757 return LinguMgr::GetIgnoreAllList();
760 uno::Reference< XDictionary > SvxGetChangeAllList()
762 return LinguMgr::GetChangeAllList();
765 #include <com/sun/star/linguistic2/XHyphenatedWord.hpp>
767 SvxAlternativeSpelling SvxGetAltSpelling(
768 const ::com::sun::star::uno::Reference<
769 ::com::sun::star::linguistic2::XHyphenatedWord > & rHyphWord )
771 SvxAlternativeSpelling aRes;
772 if (rHyphWord.is() && rHyphWord->isAlternativeSpelling())
774 OUString aWord( rHyphWord->getWord() ),
775 aAltWord( rHyphWord->getHyphenatedWord() );
776 sal_Int16 nHyphenationPos = rHyphWord->getHyphenationPos(),
777 nHyphenPos = rHyphWord->getHyphenPos();
778 sal_Int16 nLen = (sal_Int16)aWord.getLength();
779 sal_Int16 nAltLen = (sal_Int16)aAltWord.getLength();
780 const sal_Unicode *pWord = aWord.getStr(),
781 *pAltWord = aAltWord.getStr();
783 // count number of chars from the left to the
784 // hyphenation pos / hyphen pos that are equal
785 sal_Int16 nL = 0;
786 while (nL <= nHyphenationPos && nL <= nHyphenPos
787 && pWord[ nL ] == pAltWord[ nL ])
788 ++nL;
789 // count number of chars from the right to the
790 // hyphenation pos / hyphen pos that are equal
791 sal_Int16 nR = 0;
792 sal_Int32 nIdx = nLen - 1;
793 sal_Int32 nAltIdx = nAltLen - 1;
794 while (nIdx > nHyphenationPos && nAltIdx > nHyphenPos
795 && pWord[ nIdx-- ] == pAltWord[ nAltIdx-- ])
796 ++nR;
798 aRes.aReplacement = OUString( aAltWord.copy( nL, nAltLen - nL - nR ) );
799 aRes.nChangedPos = (sal_Int16) nL;
800 aRes.nChangedLength = nLen - nL - nR;
801 aRes.bIsAltSpelling = true;
802 aRes.xHyphWord = rHyphWord;
804 return aRes;
808 SvxDicListChgClamp::SvxDicListChgClamp( uno::Reference< XSearchableDictionaryList > &rxDicList ) :
809 xDicList ( rxDicList )
811 if (xDicList.is())
813 xDicList->beginCollectEvents();
817 SvxDicListChgClamp::~SvxDicListChgClamp()
819 if (xDicList.is())
821 xDicList->endCollectEvents();
825 short SvxDicError( vcl::Window *pParent, linguistic::DictionaryError nError )
827 short nRes = 0;
828 if (linguistic::DictionaryError::NONE != nError)
830 int nRid;
831 switch (nError)
833 case linguistic::DictionaryError::FULL : nRid = RID_SVXSTR_DIC_ERR_FULL; break;
834 case linguistic::DictionaryError::READONLY : nRid = RID_SVXSTR_DIC_ERR_READONLY; break;
835 default:
836 nRid = RID_SVXSTR_DIC_ERR_UNKNOWN;
837 SAL_WARN("editeng", "unexpected case");
839 nRes = ScopedVclPtr<InfoBox>::Create( pParent, EE_RESSTR( nRid ) )->Execute();
841 return nRes;
845 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */