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

Generated by: LCOV version 1.10