LCOV - code coverage report
Current view: top level - libreoffice/editeng/source/misc - unolingu.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 121 325 37.2 %
Date: 2012-12-27 Functions: 34 65 52.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : #include <map>
      22             : #include <vector>
      23             : #include <list>
      24             : #include <memory>
      25             : #include <editeng/unolingu.hxx>
      26             : #include <rtl/logfile.hxx>
      27             : #include <unotools/pathoptions.hxx>
      28             : #include <com/sun/star/frame/Desktop.hpp>
      29             : #include <com/sun/star/frame/XModel.hpp>
      30             : #include <com/sun/star/frame/XStorable.hpp>
      31             : #include <com/sun/star/lang/XEventListener.hpp>
      32             : #include <com/sun/star/linguistic2/XAvailableLocales.hpp>
      33             : #include <com/sun/star/linguistic2/LinguServiceManager.hpp>
      34             : #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
      35             : #include <com/sun/star/ucb/XContentAccess.hpp>
      36             : #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
      37             : #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
      38             : #include <com/sun/star/sdbc/XResultSet.hpp>
      39             : #include <com/sun/star/sdbc/XRow.hpp>
      40             : #include <com/sun/star/util/DateTime.hpp>
      41             : 
      42             : #include <comphelper/processfactory.hxx>
      43             : #include <cppuhelper/implbase1.hxx> // helper for implementations
      44             : #include <i18npool/languagetag.hxx>
      45             : #include <unotools/lingucfg.hxx>
      46             : #include <unotools/ucbhelper.hxx>
      47             : #include <unotools/localfilehelper.hxx>
      48             : #include <ucbhelper/commandenvironment.hxx>
      49             : #include <ucbhelper/content.hxx>
      50             : #include <vcl/msgbox.hxx>
      51             : #include <tools/shl.hxx>
      52             : #include <linguistic/misc.hxx>
      53             : #include <editeng/eerdll.hxx>
      54             : #include <editeng/editrids.hrc>
      55             : 
      56             : using namespace ::rtl;
      57             : using namespace ::comphelper;
      58             : using namespace ::linguistic;
      59             : using namespace ::com::sun::star;
      60             : using namespace ::com::sun::star::util;
      61             : using namespace ::com::sun::star::uno;
      62             : using namespace ::com::sun::star::lang;
      63             : using namespace ::com::sun::star::beans;
      64             : using namespace ::com::sun::star::frame;
      65             : using namespace ::com::sun::star::linguistic2;
      66             : 
      67             : #define CSS com::sun::star
      68             : 
      69           7 : static uno::Reference< XLinguServiceManager2 > GetLngSvcMgr_Impl()
      70             : {
      71           7 :     uno::Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
      72           7 :     uno::Reference< XLinguServiceManager2 > xRes = LinguServiceManager::create(xContext);
      73           7 :     return xRes;
      74             : }
      75             : 
      76             : //! Dummy implementation in order to avoid loading of lingu DLL
      77             : //! when only the XSupportedLocales interface is used.
      78             : //! The dummy accesses the real implementation (and thus loading the DLL)
      79             : //! when "real" work needs to be done only.
      80             : class ThesDummy_Impl :
      81             :     public cppu::WeakImplHelper1< XThesaurus >
      82             : {
      83             :     uno::Reference< XThesaurus >     xThes;      // the real one...
      84             :     Sequence< Locale >         *pLocaleSeq;
      85             : 
      86             :     void GetCfgLocales();
      87             : 
      88             :     void GetThes_Impl();
      89             : 
      90             : public:
      91           0 :     ThesDummy_Impl() : pLocaleSeq(0)  {}
      92             :     ~ThesDummy_Impl();
      93             : 
      94             :     // XSupportedLocales
      95             :     virtual ::com::sun::star::uno::Sequence<
      96             :             ::com::sun::star::lang::Locale > SAL_CALL
      97             :         getLocales()
      98             :             throw(::com::sun::star::uno::RuntimeException);
      99             :     virtual sal_Bool SAL_CALL
     100             :         hasLocale( const ::com::sun::star::lang::Locale& rLocale )
     101             :             throw(::com::sun::star::uno::RuntimeException);
     102             : 
     103             :     // XThesaurus
     104             :     virtual ::com::sun::star::uno::Sequence<
     105             :             ::com::sun::star::uno::Reference<
     106             :                 ::com::sun::star::linguistic2::XMeaning > > SAL_CALL
     107             :         queryMeanings( const ::rtl::OUString& rTerm,
     108             :                 const ::com::sun::star::lang::Locale& rLocale,
     109             :                 const ::com::sun::star::beans::PropertyValues& rProperties )
     110             :             throw(::com::sun::star::lang::IllegalArgumentException,
     111             :                   ::com::sun::star::uno::RuntimeException);
     112             : };
     113             : 
     114             : 
     115           0 : ThesDummy_Impl::~ThesDummy_Impl()
     116             : {
     117           0 :     delete pLocaleSeq;
     118           0 : }
     119             : 
     120             : 
     121           0 : void ThesDummy_Impl::GetCfgLocales()
     122             : {
     123           0 :     if (!pLocaleSeq)
     124             :     {
     125           0 :         SvtLinguConfig aCfg;
     126           0 :         String  aNode( A2OU( "ServiceManager/ThesaurusList" ) );
     127           0 :         Sequence < OUString > aNodeNames( aCfg.GetNodeNames( aNode ) );
     128           0 :         const OUString *pNodeNames = aNodeNames.getConstArray();
     129           0 :         sal_Int32 nLen = aNodeNames.getLength();
     130           0 :         pLocaleSeq = new Sequence< Locale >( nLen );
     131           0 :         Locale *pLocale = pLocaleSeq->getArray();
     132           0 :         for (sal_Int32 i = 0;  i < nLen;  ++i)
     133             :         {
     134           0 :             pLocale[i] = LanguageTag( pNodeNames[i] ).getLocale();
     135           0 :         }
     136             :     }
     137           0 : }
     138             : 
     139             : 
     140           0 : void ThesDummy_Impl::GetThes_Impl()
     141             : {
     142           0 :     if (!xThes.is())
     143             :     {
     144           0 :         uno::Reference< XLinguServiceManager2 > xLngSvcMgr( GetLngSvcMgr_Impl() );
     145           0 :         xThes = xLngSvcMgr->getThesaurus();
     146             : 
     147           0 :         if (xThes.is())
     148             :         {
     149             :             // no longer needed...
     150           0 :             delete pLocaleSeq;    pLocaleSeq = 0;
     151           0 :         }
     152             :     }
     153           0 : }
     154             : 
     155             : 
     156             : uno::Sequence< lang::Locale > SAL_CALL
     157           0 :         ThesDummy_Impl::getLocales()
     158             :             throw(uno::RuntimeException)
     159             : {
     160           0 :     GetThes_Impl();
     161           0 :     if (xThes.is())
     162           0 :         return xThes->getLocales();
     163           0 :     else if (!pLocaleSeq)       // if not already loaded save startup time by avoiding loading them now
     164           0 :         GetCfgLocales();
     165           0 :     return *pLocaleSeq;
     166             : }
     167             : 
     168             : 
     169             : sal_Bool SAL_CALL
     170           0 :         ThesDummy_Impl::hasLocale( const lang::Locale& rLocale )
     171             :             throw(uno::RuntimeException)
     172             : {
     173           0 :     GetThes_Impl();
     174           0 :     if (xThes.is())
     175           0 :         return xThes->hasLocale( rLocale );
     176           0 :     else if (!pLocaleSeq)       // if not already loaded save startup time by avoiding loading them now
     177           0 :         GetCfgLocales();
     178           0 :         GetCfgLocales();
     179           0 :     sal_Bool bFound = sal_False;
     180           0 :     sal_Int32 nLen = pLocaleSeq->getLength();
     181           0 :     const Locale *pLocale = pLocaleSeq->getConstArray();
     182           0 :     const Locale *pEnd = pLocale + nLen;
     183           0 :     for ( ;  pLocale < pEnd  &&  !bFound;  ++pLocale)
     184             :     {
     185           0 :         bFound = pLocale->Language == rLocale.Language  &&
     186           0 :                  pLocale->Country  == rLocale.Country   &&
     187           0 :                  pLocale->Variant  == rLocale.Variant;
     188             :     }
     189           0 :     return bFound;
     190             : }
     191             : 
     192             : 
     193             : uno::Sequence< uno::Reference< linguistic2::XMeaning > > SAL_CALL
     194           0 :         ThesDummy_Impl::queryMeanings(
     195             :                 const rtl::OUString& rTerm,
     196             :                 const lang::Locale& rLocale,
     197             :                 const beans::PropertyValues& rProperties )
     198             :             throw(lang::IllegalArgumentException,
     199             :                   uno::RuntimeException)
     200             : {
     201           0 :     GetThes_Impl();
     202           0 :     uno::Sequence< uno::Reference< linguistic2::XMeaning > > aRes;
     203             :     OSL_ENSURE( xThes.is(), "Thesaurus missing" );
     204           0 :     if (xThes.is())
     205           0 :         aRes = xThes->queryMeanings( rTerm, rLocale, rProperties );
     206           0 :     return aRes;
     207             : }
     208             : 
     209             : 
     210             : //! Dummy implementation in order to avoid loading of lingu DLL.
     211             : //! The dummy accesses the real implementation (and thus loading the DLL)
     212             : //! when it needs to be done only.
     213          19 : class SpellDummy_Impl :
     214             :     public cppu::WeakImplHelper1< XSpellChecker1 >
     215             : {
     216             :     uno::Reference< XSpellChecker1 >     xSpell;      // the real one...
     217             : 
     218             :     void    GetSpell_Impl();
     219             : 
     220             : public:
     221             : 
     222             :     // XSupportedLanguages (for XSpellChecker1)
     223             :     virtual ::com::sun::star::uno::Sequence< sal_Int16 > SAL_CALL
     224             :         getLanguages()
     225             :             throw(::com::sun::star::uno::RuntimeException);
     226             :     virtual sal_Bool SAL_CALL
     227             :         hasLanguage( sal_Int16 nLanguage )
     228             :             throw(::com::sun::star::uno::RuntimeException);
     229             : 
     230             :     // XSpellChecker1 (same as XSpellChecker but sal_Int16 for language)
     231             :     virtual sal_Bool SAL_CALL
     232             :         isValid( const ::rtl::OUString& rWord, sal_Int16 nLanguage,
     233             :                 const ::com::sun::star::beans::PropertyValues& rProperties )
     234             :             throw(::com::sun::star::lang::IllegalArgumentException,
     235             :                   ::com::sun::star::uno::RuntimeException);
     236             :     virtual ::com::sun::star::uno::Reference<
     237             :             ::com::sun::star::linguistic2::XSpellAlternatives > SAL_CALL
     238             :         spell( const ::rtl::OUString& rWord, sal_Int16 nLanguage,
     239             :                 const ::com::sun::star::beans::PropertyValues& rProperties )
     240             :             throw(::com::sun::star::lang::IllegalArgumentException,
     241             :                   ::com::sun::star::uno::RuntimeException);
     242             : };
     243             : 
     244             : 
     245         602 : void SpellDummy_Impl::GetSpell_Impl()
     246             : {
     247         602 :     if (!xSpell.is())
     248             :     {
     249           6 :         uno::Reference< XLinguServiceManager2 > xLngSvcMgr( GetLngSvcMgr_Impl() );
     250           6 :         xSpell = uno::Reference< XSpellChecker1 >( xLngSvcMgr->getSpellChecker(), UNO_QUERY );
     251             :     }
     252         602 : }
     253             : 
     254             : 
     255             : uno::Sequence< sal_Int16 > SAL_CALL
     256           0 :     SpellDummy_Impl::getLanguages()
     257             :         throw(uno::RuntimeException)
     258             : {
     259           0 :     GetSpell_Impl();
     260           0 :     if (xSpell.is())
     261           0 :         return xSpell->getLanguages();
     262             :     else
     263           0 :         return uno::Sequence< sal_Int16 >();
     264             : }
     265             : 
     266             : 
     267             : sal_Bool SAL_CALL
     268         592 :     SpellDummy_Impl::hasLanguage( sal_Int16 nLanguage )
     269             :         throw(uno::RuntimeException)
     270             : {
     271         592 :     GetSpell_Impl();
     272         592 :     sal_Bool bRes = sal_False;
     273         592 :     if (xSpell.is())
     274         592 :         bRes = xSpell->hasLanguage( nLanguage );
     275         592 :     return bRes;
     276             : }
     277             : 
     278             : 
     279             : sal_Bool SAL_CALL
     280          10 :     SpellDummy_Impl::isValid( const rtl::OUString& rWord, sal_Int16 nLanguage,
     281             :             const beans::PropertyValues& rProperties )
     282             :         throw(lang::IllegalArgumentException,
     283             :               uno::RuntimeException)
     284             : {
     285          10 :     GetSpell_Impl();
     286          10 :     sal_Bool bRes = sal_True;
     287          10 :     if (xSpell.is())
     288          10 :         bRes = xSpell->isValid( rWord, nLanguage, rProperties );
     289          10 :     return bRes;
     290             : }
     291             : 
     292             : 
     293             : uno::Reference< linguistic2::XSpellAlternatives > SAL_CALL
     294           0 :     SpellDummy_Impl::spell( const rtl::OUString& rWord, sal_Int16 nLanguage,
     295             :             const beans::PropertyValues& rProperties )
     296             :         throw(lang::IllegalArgumentException,
     297             :               uno::RuntimeException)
     298             : {
     299           0 :     GetSpell_Impl();
     300           0 :     uno::Reference< linguistic2::XSpellAlternatives > xRes;
     301           0 :     if (xSpell.is())
     302           0 :         xRes = xSpell->spell( rWord, nLanguage, rProperties );
     303           0 :     return xRes;
     304             : }
     305             : 
     306             : 
     307             : //! Dummy implementation in order to avoid loading of lingu DLL.
     308             : //! The dummy accesses the real implementation (and thus loading the DLL)
     309             : //! when it needs to be done only.
     310          22 : class HyphDummy_Impl :
     311             :     public cppu::WeakImplHelper1< XHyphenator >
     312             : {
     313             :     uno::Reference< XHyphenator >     xHyph;      // the real one...
     314             : 
     315             :     void    GetHyph_Impl();
     316             : 
     317             : public:
     318             : 
     319             :     // XSupportedLocales
     320             :     virtual ::com::sun::star::uno::Sequence<
     321             :             ::com::sun::star::lang::Locale > SAL_CALL
     322             :         getLocales()
     323             :             throw(::com::sun::star::uno::RuntimeException);
     324             :     virtual sal_Bool SAL_CALL
     325             :         hasLocale( const ::com::sun::star::lang::Locale& rLocale )
     326             :             throw(::com::sun::star::uno::RuntimeException);
     327             : 
     328             :     // XHyphenator
     329             :     virtual ::com::sun::star::uno::Reference<
     330             :             ::com::sun::star::linguistic2::XHyphenatedWord > SAL_CALL
     331             :         hyphenate( const ::rtl::OUString& rWord,
     332             :                 const ::com::sun::star::lang::Locale& rLocale,
     333             :                 sal_Int16 nMaxLeading,
     334             :                 const ::com::sun::star::beans::PropertyValues& rProperties )
     335             :             throw(::com::sun::star::lang::IllegalArgumentException,
     336             :                   ::com::sun::star::uno::RuntimeException);
     337             :     virtual ::com::sun::star::uno::Reference<
     338             :             ::com::sun::star::linguistic2::XHyphenatedWord > SAL_CALL
     339             :         queryAlternativeSpelling( const ::rtl::OUString& rWord,
     340             :                 const ::com::sun::star::lang::Locale& rLocale,
     341             :                 sal_Int16 nIndex,
     342             :                 const ::com::sun::star::beans::PropertyValues& rProperties )
     343             :             throw(::com::sun::star::lang::IllegalArgumentException,
     344             :                   ::com::sun::star::uno::RuntimeException);
     345             :     virtual ::com::sun::star::uno::Reference<
     346             :             ::com::sun::star::linguistic2::XPossibleHyphens > SAL_CALL
     347             :         createPossibleHyphens(
     348             :                 const ::rtl::OUString& rWord,
     349             :                 const ::com::sun::star::lang::Locale& rLocale,
     350             :                 const ::com::sun::star::beans::PropertyValues& rProperties )
     351             :             throw(::com::sun::star::lang::IllegalArgumentException,
     352             :                   ::com::sun::star::uno::RuntimeException);
     353             : };
     354             : 
     355             : 
     356        1804 : void HyphDummy_Impl::GetHyph_Impl()
     357             : {
     358        1804 :     if (!xHyph.is())
     359             :     {
     360           1 :         uno::Reference< XLinguServiceManager2 > xLngSvcMgr( GetLngSvcMgr_Impl() );
     361           1 :         xHyph = xLngSvcMgr->getHyphenator();
     362             :     }
     363        1804 : }
     364             : 
     365             : 
     366             : uno::Sequence< lang::Locale > SAL_CALL
     367           0 :     HyphDummy_Impl::getLocales()
     368             :         throw(uno::RuntimeException)
     369             : {
     370           0 :     GetHyph_Impl();
     371           0 :     if (xHyph.is())
     372           0 :         return xHyph->getLocales();
     373             :     else
     374           0 :         return uno::Sequence< lang::Locale >();
     375             : }
     376             : 
     377             : 
     378             : sal_Bool SAL_CALL
     379           0 :     HyphDummy_Impl::hasLocale( const lang::Locale& rLocale )
     380             :         throw(uno::RuntimeException)
     381             : {
     382           0 :     GetHyph_Impl();
     383           0 :     sal_Bool bRes = sal_False;
     384           0 :     if (xHyph.is())
     385           0 :         bRes = xHyph->hasLocale( rLocale );
     386           0 :     return bRes;
     387             : }
     388             : 
     389             : 
     390             : uno::Reference< linguistic2::XHyphenatedWord > SAL_CALL
     391        1804 :     HyphDummy_Impl::hyphenate(
     392             :             const rtl::OUString& rWord,
     393             :             const lang::Locale& rLocale,
     394             :             sal_Int16 nMaxLeading,
     395             :             const beans::PropertyValues& rProperties )
     396             :         throw(lang::IllegalArgumentException,
     397             :               uno::RuntimeException)
     398             : {
     399        1804 :     GetHyph_Impl();
     400        1804 :     uno::Reference< linguistic2::XHyphenatedWord > xRes;
     401        1804 :     if (xHyph.is())
     402        1804 :         xRes = xHyph->hyphenate( rWord, rLocale, nMaxLeading, rProperties );
     403        1804 :     return xRes;
     404             : }
     405             : 
     406             : 
     407             : uno::Reference< linguistic2::XHyphenatedWord > SAL_CALL
     408           0 :     HyphDummy_Impl::queryAlternativeSpelling(
     409             :             const rtl::OUString& rWord,
     410             :             const lang::Locale& rLocale,
     411             :             sal_Int16 nIndex,
     412             :             const PropertyValues& rProperties )
     413             :         throw(lang::IllegalArgumentException,
     414             :               uno::RuntimeException)
     415             : {
     416           0 :     GetHyph_Impl();
     417           0 :     uno::Reference< linguistic2::XHyphenatedWord > xRes;
     418           0 :     if (xHyph.is())
     419           0 :         xRes = xHyph->queryAlternativeSpelling( rWord, rLocale, nIndex, rProperties );
     420           0 :     return xRes;
     421             : }
     422             : 
     423             : 
     424             : uno::Reference< linguistic2::XPossibleHyphens > SAL_CALL
     425           0 :     HyphDummy_Impl::createPossibleHyphens(
     426             :             const rtl::OUString& rWord,
     427             :             const lang::Locale& rLocale,
     428             :             const beans::PropertyValues& rProperties )
     429             :         throw(lang::IllegalArgumentException,
     430             :               uno::RuntimeException)
     431             : {
     432           0 :     GetHyph_Impl();
     433           0 :     uno::Reference< linguistic2::XPossibleHyphens > xRes;
     434           0 :     if (xHyph.is())
     435           0 :         xRes = xHyph->createPossibleHyphens( rWord, rLocale, rProperties );
     436           0 :     return xRes;
     437             : }
     438             : 
     439             : 
     440             : typedef cppu::WeakImplHelper1 < XEventListener > LinguMgrAppExitLstnrBaseClass;
     441             : 
     442             : 
     443             : class LinguMgrAppExitLstnr : public LinguMgrAppExitLstnrBaseClass
     444             : {
     445             :     uno::Reference< XDesktop2 >        xDesktop;
     446             : 
     447             : public:
     448             :     LinguMgrAppExitLstnr();
     449             :     virtual ~LinguMgrAppExitLstnr();
     450             : 
     451             :     virtual void    AtExit() = 0;
     452             : 
     453             : 
     454             :     // lang::XEventListener
     455             :     virtual void    SAL_CALL disposing(const EventObject& rSource)
     456             :             throw( RuntimeException );
     457             : };
     458             : 
     459          14 : LinguMgrAppExitLstnr::LinguMgrAppExitLstnr()
     460             : {
     461             :     // add object to frame::Desktop EventListeners in order to properly call
     462             :     // the AtExit function at appliction exit.
     463             : 
     464          14 :     uno::Reference< XComponentContext >  xContext = getProcessComponentContext();
     465          14 :     xDesktop = Desktop::create( xContext );
     466          14 :     xDesktop->addEventListener( this );
     467          14 : }
     468             : 
     469          28 : LinguMgrAppExitLstnr::~LinguMgrAppExitLstnr()
     470             : {
     471          14 :     if (xDesktop.is())
     472             :     {
     473           0 :         xDesktop->removeEventListener( this );
     474           0 :         xDesktop = NULL;    //! release reference to desktop
     475             :     }
     476             :     OSL_ENSURE(!xDesktop.is(), "reference to desktop should be realeased");
     477          14 : }
     478             : 
     479          14 : void LinguMgrAppExitLstnr::disposing(const EventObject& rSource)
     480             :         throw( RuntimeException )
     481             : {
     482          14 :     if (xDesktop.is()  &&  rSource.Source == xDesktop)
     483             :     {
     484          14 :         xDesktop->removeEventListener( this );
     485          14 :         xDesktop = NULL;    //! release reference to desktop
     486             : 
     487          14 :         AtExit();
     488             :     }
     489          14 : }
     490             : 
     491          42 : class LinguMgrExitLstnr : public LinguMgrAppExitLstnr
     492             : {
     493             : public:
     494             :     virtual void    AtExit();
     495             : };
     496             : 
     497          14 : void LinguMgrExitLstnr::AtExit()
     498             : {
     499             :     // release references
     500          14 :     LinguMgr::xLngSvcMgr    = 0;
     501          14 :     LinguMgr::xSpell        = 0;
     502          14 :     LinguMgr::xHyph         = 0;
     503          14 :     LinguMgr::xThes         = 0;
     504          14 :     LinguMgr::xDicList      = 0;
     505          14 :     LinguMgr::xProp         = 0;
     506          14 :     LinguMgr::xIgnoreAll    = 0;
     507          14 :     LinguMgr::xChangeAll    = 0;
     508             : 
     509          14 :     LinguMgr::bExiting      = sal_True;
     510             : 
     511          14 :     LinguMgr::pExitLstnr    = 0;
     512          14 : }
     513             : 
     514             : 
     515             : LinguMgrExitLstnr *             LinguMgr::pExitLstnr    = 0;
     516             : sal_Bool                        LinguMgr::bExiting      = sal_False;
     517          24 : uno::Reference< XLinguServiceManager2 >  LinguMgr::xLngSvcMgr    = 0;
     518          24 : uno::Reference< XSpellChecker1 >    LinguMgr::xSpell        = 0;
     519          24 : uno::Reference< XHyphenator >       LinguMgr::xHyph         = 0;
     520          24 : uno::Reference< XThesaurus >        LinguMgr::xThes         = 0;
     521          24 : uno::Reference< XDictionaryList >   LinguMgr::xDicList      = 0;
     522          24 : uno::Reference< XPropertySet >      LinguMgr::xProp         = 0;
     523          24 : uno::Reference< XDictionary >       LinguMgr::xIgnoreAll    = 0;
     524          24 : uno::Reference< XDictionary >       LinguMgr::xChangeAll    = 0;
     525             : 
     526             : 
     527           0 : uno::Reference< XLinguServiceManager2 > LinguMgr::GetLngSvcMgr()
     528             : {
     529           0 :     if (bExiting)
     530           0 :         return 0;
     531             : 
     532           0 :     if (!pExitLstnr)
     533           0 :         pExitLstnr = new LinguMgrExitLstnr;
     534             : 
     535           0 :     if (!xLngSvcMgr.is())
     536           0 :         xLngSvcMgr = GetLngSvcMgr_Impl();
     537             : 
     538           0 :     return xLngSvcMgr;
     539             : }
     540             : 
     541             : 
     542         661 : uno::Reference< XSpellChecker1 > LinguMgr::GetSpellChecker()
     543             : {
     544         661 :     return xSpell.is() ? xSpell : GetSpell();
     545             : }
     546             : 
     547         404 : uno::Reference< XHyphenator > LinguMgr::GetHyphenator()
     548             : {
     549         404 :     return xHyph.is() ? xHyph : GetHyph();
     550             : }
     551             : 
     552           0 : uno::Reference< XThesaurus > LinguMgr::GetThesaurus()
     553             : {
     554           0 :     return xThes.is() ? xThes : GetThes();
     555             : }
     556             : 
     557           3 : uno::Reference< XDictionaryList > LinguMgr::GetDictionaryList()
     558             : {
     559           3 :     return xDicList.is() ? xDicList : GetDicList();
     560             : }
     561             : 
     562          12 : uno::Reference< XPropertySet > LinguMgr::GetLinguPropertySet()
     563             : {
     564          12 :     return xProp.is() ? xProp : GetProp();
     565             : }
     566             : 
     567           0 : uno::Reference< XDictionary > LinguMgr::GetStandardDic()
     568             : {
     569             :     //! don't hold reference to this
     570             :     //! (it may be removed from dictionary list and needs to be
     571             :     //! created empty if accessed again)
     572           0 :     return GetStandard();
     573             : }
     574             : 
     575           0 : uno::Reference< XDictionary > LinguMgr::GetIgnoreAllList()
     576             : {
     577           0 :     return xIgnoreAll.is() ? xIgnoreAll : GetIgnoreAll();
     578             : }
     579             : 
     580          12 : uno::Reference< XDictionary > LinguMgr::GetChangeAllList()
     581             : {
     582          12 :     return xChangeAll.is() ? xChangeAll : GetChangeAll();
     583             : }
     584             : 
     585          13 : uno::Reference< XSpellChecker1 > LinguMgr::GetSpell()
     586             : {
     587          13 :     if (bExiting)
     588           0 :         return 0;
     589             : 
     590          13 :     if (!pExitLstnr)
     591          12 :         pExitLstnr = new LinguMgrExitLstnr;
     592             : 
     593             :     //! use dummy implementation in order to avoid loading of lingu DLL
     594          13 :     xSpell = new SpellDummy_Impl;
     595          13 :     return xSpell;
     596             : }
     597             : 
     598          14 : uno::Reference< XHyphenator > LinguMgr::GetHyph()
     599             : {
     600          14 :     if (bExiting)
     601           0 :         return 0;
     602             : 
     603          14 :     if (!pExitLstnr)
     604           2 :         pExitLstnr = new LinguMgrExitLstnr;
     605             : 
     606             :     //! use dummy implementation in order to avoid loading of lingu DLL
     607          14 :     xHyph = new HyphDummy_Impl;
     608          14 :     return xHyph;
     609             : }
     610             : 
     611           0 : uno::Reference< XThesaurus > LinguMgr::GetThes()
     612             : {
     613           0 :     if (bExiting)
     614           0 :         return 0;
     615             : 
     616           0 :     if (!pExitLstnr)
     617           0 :         pExitLstnr = new LinguMgrExitLstnr;
     618             : 
     619             :     //! use dummy implementation in order to avoid loading of lingu DLL
     620             :     //! when only the XSupportedLocales interface is used.
     621             :     //! The dummy accesses the real implementation (and thus loading the DLL)
     622             :     //! when "real" work needs to be done only.
     623           0 :     xThes = new ThesDummy_Impl;
     624           0 :     return xThes;
     625             : }
     626             : 
     627           3 : uno::Reference< XDictionaryList > LinguMgr::GetDicList()
     628             : {
     629           3 :     if (bExiting)
     630           0 :         return 0;
     631             : 
     632           3 :     if (!pExitLstnr)
     633           0 :         pExitLstnr = new LinguMgrExitLstnr;
     634             : 
     635           3 :     uno::Reference< XMultiServiceFactory >  xMgr( getProcessServiceFactory() );
     636           3 :     xDicList = uno::Reference< XDictionaryList > ( xMgr->createInstance(
     637           3 :                 A2OU("com.sun.star.linguistic2.DictionaryList") ), UNO_QUERY );
     638           3 :     return xDicList;
     639             : }
     640             : 
     641           3 : uno::Reference< XPropertySet > LinguMgr::GetProp()
     642             : {
     643           3 :     if (bExiting)
     644           0 :         return 0;
     645             : 
     646           3 :     if (!pExitLstnr)
     647           0 :         pExitLstnr = new LinguMgrExitLstnr;
     648             : 
     649           3 :     uno::Reference< XMultiServiceFactory >  xMgr( getProcessServiceFactory() );
     650           3 :     xProp = uno::Reference< XPropertySet > ( xMgr->createInstance(
     651           3 :                 A2OU("com.sun.star.linguistic2.LinguProperties") ), UNO_QUERY );
     652           3 :     return xProp;
     653             : }
     654             : 
     655           0 : uno::Reference< XDictionary > LinguMgr::GetIgnoreAll()
     656             : {
     657           0 :     if (bExiting)
     658           0 :         return 0;
     659             : 
     660           0 :     if (!pExitLstnr)
     661           0 :         pExitLstnr = new LinguMgrExitLstnr;
     662             : 
     663           0 :     uno::Reference< XDictionaryList >  xTmpDicList( GetDictionaryList() );
     664           0 :     if (xTmpDicList.is())
     665             :     {
     666           0 :         xIgnoreAll = uno::Reference< XDictionary > ( xTmpDicList->getDictionaryByName(
     667           0 :                     A2OU("IgnoreAllList") ), UNO_QUERY );
     668             :     }
     669           0 :     return xIgnoreAll;
     670             : }
     671             : 
     672           3 : uno::Reference< XDictionary > LinguMgr::GetChangeAll()
     673             : {
     674           3 :     if (bExiting)
     675           0 :         return 0;
     676             : 
     677           3 :     if (!pExitLstnr)
     678           0 :         pExitLstnr = new LinguMgrExitLstnr;
     679             : 
     680           3 :     uno::Reference< XDictionaryList > _xDicList( GetDictionaryList() , UNO_QUERY );
     681           3 :     if (_xDicList.is())
     682             :     {
     683             :         xChangeAll = uno::Reference< XDictionary > (
     684           3 :                         _xDicList->createDictionary(
     685             :                             A2OU("ChangeAllList"),
     686           6 :                             LanguageTag( LANGUAGE_NONE ).getLocale(),
     687           9 :                             DictionaryType_NEGATIVE, String() ), UNO_QUERY );
     688             :     }
     689           3 :     return xChangeAll;
     690             : }
     691             : 
     692           0 : uno::Reference< XDictionary > LinguMgr::GetStandard()
     693             : {
     694             :     // Tries to return a dictionary which may hold positive entries is
     695             :     // persistent and not read-only.
     696             : 
     697           0 :     if (bExiting)
     698           0 :         return 0;
     699             : 
     700           0 :     uno::Reference< XDictionaryList >  xTmpDicList( GetDictionaryList() );
     701           0 :     if (!xTmpDicList.is())
     702           0 :         return NULL;
     703             : 
     704           0 :     const OUString aDicName( RTL_CONSTASCII_USTRINGPARAM( "standard.dic" ) );
     705           0 :     uno::Reference< XDictionary >   xDic( xTmpDicList->getDictionaryByName( aDicName ),
     706           0 :                                       UNO_QUERY );
     707           0 :     if (!xDic.is())
     708             :     {
     709             :         // try to create standard dictionary
     710           0 :         uno::Reference< XDictionary >    xTmp;
     711             :         try
     712             :         {
     713           0 :             xTmp =  xTmpDicList->createDictionary( aDicName,
     714           0 :                         LanguageTag( LANGUAGE_NONE ).getLocale(),
     715             :                         DictionaryType_POSITIVE,
     716           0 :                         linguistic::GetWritableDictionaryURL( aDicName ) );
     717             :         }
     718           0 :         catch(const com::sun::star::uno::Exception &)
     719             :         {
     720             :         }
     721             : 
     722             :         // add new dictionary to list
     723           0 :         if (xTmp.is())
     724             :         {
     725           0 :             xTmpDicList->addDictionary( xTmp );
     726           0 :             xTmp->setActive( sal_True );
     727             :         }
     728           0 :         xDic = uno::Reference< XDictionary > ( xTmp, UNO_QUERY );
     729             :     }
     730             : #if OSL_DEBUG_LEVEL > 1
     731             :     uno::Reference< XStorable >      xStor( xDic, UNO_QUERY );
     732             :     OSL_ENSURE( xDic.is() && xDic->getDictionaryType() == DictionaryType_POSITIVE,
     733             :             "wrong dictionary type");
     734             :     OSL_ENSURE( xDic.is() && LanguageTag( xDic->getLocale() ).getLanguageType() == LANGUAGE_NONE,
     735             :             "wrong dictionary language");
     736             :     OSL_ENSURE( !xStor.is() || (xStor->hasLocation() && !xStor->isReadonly()),
     737             :             "dictionary not editable" );
     738             : #endif
     739             : 
     740           0 :     return xDic;
     741             : }
     742             : 
     743           6 : uno::Reference< XSpellChecker1 >  SvxGetSpellChecker()
     744             : {
     745           6 :     return LinguMgr::GetSpellChecker();
     746             : }
     747             : 
     748           0 : uno::Reference< XHyphenator >  SvxGetHyphenator()
     749             : {
     750           0 :     return LinguMgr::GetHyphenator();
     751             : }
     752             : 
     753           0 : uno::Reference< XThesaurus >  SvxGetThesaurus()
     754             : {
     755           0 :     return LinguMgr::GetThesaurus();
     756             : }
     757             : 
     758           0 : uno::Reference< XDictionaryList >  SvxGetDictionaryList()
     759             : {
     760           0 :     return LinguMgr::GetDictionaryList();
     761             : }
     762             : 
     763          12 : uno::Reference< XPropertySet >  SvxGetLinguPropertySet()
     764             : {
     765          12 :     return LinguMgr::GetLinguPropertySet();
     766             : }
     767             : 
     768             : //TODO: remove argument or provide SvxGetIgnoreAllList with the same one
     769           0 : uno::Reference< XDictionary >  SvxGetOrCreatePosDic(
     770             :         uno::Reference< XDictionaryList >  /* xDicList */ )
     771             : {
     772           0 :     return LinguMgr::GetStandardDic();
     773             : }
     774             : 
     775           0 : uno::Reference< XDictionary >  SvxGetIgnoreAllList()
     776             : {
     777           0 :     return LinguMgr::GetIgnoreAllList();
     778             : }
     779             : 
     780          12 : uno::Reference< XDictionary >  SvxGetChangeAllList()
     781             : {
     782          12 :     return LinguMgr::GetChangeAllList();
     783             : }
     784             : 
     785             : #include <com/sun/star/linguistic2/XHyphenatedWord.hpp>
     786             : 
     787           0 : SvxAlternativeSpelling SvxGetAltSpelling(
     788             :         const ::com::sun::star::uno::Reference<
     789             :             ::com::sun::star::linguistic2::XHyphenatedWord > & rHyphWord )
     790             : {
     791           0 :     SvxAlternativeSpelling aRes;
     792           0 :     if (rHyphWord.is() && rHyphWord->isAlternativeSpelling())
     793             :     {
     794           0 :         OUString aWord( rHyphWord->getWord() ),
     795           0 :                  aAltWord( rHyphWord->getHyphenatedWord() );
     796           0 :         sal_Int16   nHyphenationPos     = rHyphWord->getHyphenationPos(),
     797           0 :                 nHyphenPos          = rHyphWord->getHyphenPos();
     798           0 :         sal_Int16   nLen    = (sal_Int16)aWord.getLength();
     799           0 :         sal_Int16   nAltLen = (sal_Int16)aAltWord.getLength();
     800           0 :         const sal_Unicode *pWord    = aWord.getStr(),
     801           0 :                           *pAltWord = aAltWord.getStr();
     802             : 
     803             :         // count number of chars from the left to the
     804             :         // hyphenation pos / hyphen pos that are equal
     805           0 :         sal_Int16 nL = 0;
     806           0 :         while (nL <= nHyphenationPos && nL <= nHyphenPos
     807           0 :                && pWord[ nL ] == pAltWord[ nL ])
     808           0 :             ++nL;
     809             :         // count number of chars from the right to the
     810             :         // hyphenation pos / hyphen pos that are equal
     811           0 :         sal_Int16 nR = 0;
     812           0 :         sal_Int32 nIdx    = nLen - 1;
     813           0 :         sal_Int32 nAltIdx = nAltLen - 1;
     814           0 :         while (nIdx > nHyphenationPos && nAltIdx > nHyphenPos
     815           0 :                && pWord[ nIdx-- ] == pAltWord[ nAltIdx-- ])
     816           0 :             ++nR;
     817             : 
     818           0 :         aRes.aReplacement       = OUString( aAltWord.copy( nL, nAltLen - nL - nR ) );
     819           0 :         aRes.nChangedPos        = (sal_Int16) nL;
     820           0 :         aRes.nChangedLength     = nLen - nL - nR;
     821           0 :         aRes.bIsAltSpelling     = sal_True;
     822           0 :         aRes.xHyphWord          = rHyphWord;
     823             :     }
     824           0 :     return aRes;
     825             : }
     826             : 
     827             : 
     828           0 : SvxDicListChgClamp::SvxDicListChgClamp( uno::Reference< XDictionaryList >  &rxDicList ) :
     829           0 :     xDicList    ( rxDicList )
     830             : {
     831           0 :     if (xDicList.is())
     832             :     {
     833           0 :         xDicList->beginCollectEvents();
     834             :     }
     835           0 : }
     836             : 
     837           0 : SvxDicListChgClamp::~SvxDicListChgClamp()
     838             : {
     839           0 :     if (xDicList.is())
     840             :     {
     841           0 :         xDicList->endCollectEvents();
     842             :     }
     843           0 : }
     844             : 
     845           0 : short SvxDicError( Window *pParent, sal_Int16 nError )
     846             : {
     847           0 :     short nRes = 0;
     848           0 :     if (DIC_ERR_NONE != nError)
     849             :     {
     850             :         int nRid;
     851           0 :         switch (nError)
     852             :         {
     853           0 :             case DIC_ERR_FULL     : nRid = RID_SVXSTR_DIC_ERR_FULL;  break;
     854           0 :             case DIC_ERR_READONLY : nRid = RID_SVXSTR_DIC_ERR_READONLY;  break;
     855             :             default:
     856           0 :                 nRid = RID_SVXSTR_DIC_ERR_UNKNOWN;
     857             :                 OSL_FAIL("unexpected case");
     858             :         }
     859           0 :         nRes = InfoBox( pParent, EE_RESSTR( nRid ) ).Execute();
     860             :     }
     861           0 :     return nRes;
     862          72 : }
     863             : 
     864             : 
     865             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10