Files
libreoffice/editeng/source/misc/unolingu.cxx

913 lines
27 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2000-09-18 16:07:07 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-09-18 16:07:07 +00:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2000-09-18 16:07:07 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 16:07:07 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 16:07:07 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-09-18 16:07:07 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-09-18 16:07:07 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-09-18 16:07:07 +00:00
*
************************************************************************/
#include <map>
#include <vector>
2011-02-05 13:34:36 +01:00
#include <list>
#include <memory>
#include <editeng/unolingu.hxx>
#include <rtl/logfile.hxx>
#include <unotools/pathoptions.hxx>
2000-09-18 16:07:07 +00:00
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/frame/XStorable.hpp>
2000-09-18 16:07:07 +00:00
#include <com/sun/star/lang/XEventListener.hpp>
#include <com/sun/star/linguistic2/XAvailableLocales.hpp>
#include <com/sun/star/linguistic2/LinguServiceManager.hpp>
#include <com/sun/star/ucb/XAnyCompareFactory.hpp>
#include <com/sun/star/ucb/XContentAccess.hpp>
#include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
#include <com/sun/star/ucb/NumberedSortingInfo.hpp>
#include <com/sun/star/sdbc/XResultSet.hpp>
#include <com/sun/star/sdbc/XRow.hpp>
#include <com/sun/star/util/DateTime.hpp>
2000-10-23 11:08:49 +00:00
#include <comphelper/processfactory.hxx>
2000-09-18 16:07:07 +00:00
#include <cppuhelper/implbase1.hxx> // helper for implementations
#include <i18npool/mslangid.hxx>
#include <unotools/lingucfg.hxx>
#include <unotools/ucbhelper.hxx>
#include <unotools/localfilehelper.hxx>
#include <ucbhelper/commandenvironment.hxx>
#include <ucbhelper/content.hxx>
2000-09-18 16:07:07 +00:00
#include <vcl/msgbox.hxx>
#include <tools/shl.hxx>
#include <linguistic/misc.hxx>
#include <editeng/eerdll.hxx>
#include <editeng/editrids.hrc>
2000-09-18 16:07:07 +00:00
using namespace ::rtl;
2000-10-23 11:08:49 +00:00
using namespace ::comphelper;
using namespace ::linguistic;
2000-09-18 16:07:07 +00:00
using namespace ::com::sun::star;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::frame;
2000-10-27 09:25:31 +00:00
using namespace ::com::sun::star::linguistic2;
2000-09-18 16:07:07 +00:00
#define CSS com::sun::star
static uno::Reference< XLinguServiceManager2 > GetLngSvcMgr_Impl()
{
uno::Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
uno::Reference< XLinguServiceManager2 > xRes = LinguServiceManager::create(xContext);
return xRes;
}
//! Dummy implementation in order to avoid loading of lingu DLL
//! when only the XSupportedLocales interface is used.
//! The dummy accesses the real implementation (and thus loading the DLL)
//! when "real" work needs to be done only.
class ThesDummy_Impl :
public cppu::WeakImplHelper1< XThesaurus >
{
uno::Reference< XThesaurus > xThes; // the real one...
Sequence< Locale > *pLocaleSeq;
void GetCfgLocales();
void GetThes_Impl();
public:
ThesDummy_Impl() : pLocaleSeq(0) {}
~ThesDummy_Impl();
// XSupportedLocales
virtual ::com::sun::star::uno::Sequence<
::com::sun::star::lang::Locale > SAL_CALL
getLocales()
throw(::com::sun::star::uno::RuntimeException);
virtual sal_Bool SAL_CALL
hasLocale( const ::com::sun::star::lang::Locale& rLocale )
throw(::com::sun::star::uno::RuntimeException);
// XThesaurus
virtual ::com::sun::star::uno::Sequence<
::com::sun::star::uno::Reference<
::com::sun::star::linguistic2::XMeaning > > SAL_CALL
queryMeanings( const ::rtl::OUString& rTerm,
const ::com::sun::star::lang::Locale& rLocale,
const ::com::sun::star::beans::PropertyValues& rProperties )
throw(::com::sun::star::lang::IllegalArgumentException,
::com::sun::star::uno::RuntimeException);
};
ThesDummy_Impl::~ThesDummy_Impl()
{
delete pLocaleSeq;
}
void ThesDummy_Impl::GetCfgLocales()
{
if (!pLocaleSeq)
{
SvtLinguConfig aCfg;
String aNode( A2OU( "ServiceManager/ThesaurusList" ) );
Sequence < OUString > aNodeNames( aCfg.GetNodeNames( aNode ) );
const OUString *pNodeNames = aNodeNames.getConstArray();
sal_Int32 nLen = aNodeNames.getLength();
pLocaleSeq = new Sequence< Locale >( nLen );
Locale *pLocale = pLocaleSeq->getArray();
for (sal_Int32 i = 0; i < nLen; ++i)
{
pLocale[i] = SvxCreateLocale(
MsLangId::convertIsoStringToLanguage( pNodeNames[i] ) );
}
}
}
void ThesDummy_Impl::GetThes_Impl()
{
if (!xThes.is())
{
uno::Reference< XLinguServiceManager2 > xLngSvcMgr( GetLngSvcMgr_Impl() );
xThes = xLngSvcMgr->getThesaurus();
if (xThes.is())
{
// no longer needed...
delete pLocaleSeq; pLocaleSeq = 0;
}
}
}
uno::Sequence< lang::Locale > SAL_CALL
ThesDummy_Impl::getLocales()
throw(uno::RuntimeException)
{
GetThes_Impl();
if (xThes.is())
return xThes->getLocales();
else if (!pLocaleSeq) // if not already loaded save startup time by avoiding loading them now
GetCfgLocales();
return *pLocaleSeq;
}
sal_Bool SAL_CALL
ThesDummy_Impl::hasLocale( const lang::Locale& rLocale )
throw(uno::RuntimeException)
{
GetThes_Impl();
if (xThes.is())
return xThes->hasLocale( rLocale );
else if (!pLocaleSeq) // if not already loaded save startup time by avoiding loading them now
GetCfgLocales();
GetCfgLocales();
sal_Bool bFound = sal_False;
sal_Int32 nLen = pLocaleSeq->getLength();
const Locale *pLocale = pLocaleSeq->getConstArray();
const Locale *pEnd = pLocale + nLen;
for ( ; pLocale < pEnd && !bFound; ++pLocale)
{
bFound = pLocale->Language == rLocale.Language &&
pLocale->Country == rLocale.Country &&
pLocale->Variant == rLocale.Variant;
}
return bFound;
}
uno::Sequence< uno::Reference< linguistic2::XMeaning > > SAL_CALL
ThesDummy_Impl::queryMeanings(
const rtl::OUString& rTerm,
const lang::Locale& rLocale,
const beans::PropertyValues& rProperties )
throw(lang::IllegalArgumentException,
uno::RuntimeException)
{
GetThes_Impl();
uno::Sequence< uno::Reference< linguistic2::XMeaning > > aRes;
2011-03-29 19:12:39 +02:00
OSL_ENSURE( xThes.is(), "Thesaurus missing" );
if (xThes.is())
aRes = xThes->queryMeanings( rTerm, rLocale, rProperties );
return aRes;
}
//! Dummy implementation in order to avoid loading of lingu DLL.
//! The dummy accesses the real implementation (and thus loading the DLL)
//! when it needs to be done only.
class SpellDummy_Impl :
public cppu::WeakImplHelper1< XSpellChecker1 >
{
uno::Reference< XSpellChecker1 > xSpell; // the real one...
void GetSpell_Impl();
public:
// XSupportedLanguages (for XSpellChecker1)
virtual ::com::sun::star::uno::Sequence< sal_Int16 > SAL_CALL
getLanguages()
throw(::com::sun::star::uno::RuntimeException);
virtual sal_Bool SAL_CALL
hasLanguage( sal_Int16 nLanguage )
throw(::com::sun::star::uno::RuntimeException);
// XSpellChecker1 (same as XSpellChecker but sal_Int16 for language)
virtual sal_Bool SAL_CALL
isValid( const ::rtl::OUString& rWord, sal_Int16 nLanguage,
const ::com::sun::star::beans::PropertyValues& rProperties )
throw(::com::sun::star::lang::IllegalArgumentException,
::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference<
::com::sun::star::linguistic2::XSpellAlternatives > SAL_CALL
spell( const ::rtl::OUString& rWord, sal_Int16 nLanguage,
const ::com::sun::star::beans::PropertyValues& rProperties )
throw(::com::sun::star::lang::IllegalArgumentException,
::com::sun::star::uno::RuntimeException);
};
void SpellDummy_Impl::GetSpell_Impl()
{
if (!xSpell.is())
{
uno::Reference< XLinguServiceManager2 > xLngSvcMgr( GetLngSvcMgr_Impl() );
xSpell = uno::Reference< XSpellChecker1 >( xLngSvcMgr->getSpellChecker(), UNO_QUERY );
}
}
uno::Sequence< sal_Int16 > SAL_CALL
SpellDummy_Impl::getLanguages()
throw(uno::RuntimeException)
{
GetSpell_Impl();
if (xSpell.is())
return xSpell->getLanguages();
else
return uno::Sequence< sal_Int16 >();
}
sal_Bool SAL_CALL
SpellDummy_Impl::hasLanguage( sal_Int16 nLanguage )
throw(uno::RuntimeException)
{
GetSpell_Impl();
sal_Bool bRes = sal_False;
if (xSpell.is())
bRes = xSpell->hasLanguage( nLanguage );
return bRes;
}
sal_Bool SAL_CALL
SpellDummy_Impl::isValid( const rtl::OUString& rWord, sal_Int16 nLanguage,
const beans::PropertyValues& rProperties )
throw(lang::IllegalArgumentException,
uno::RuntimeException)
{
GetSpell_Impl();
sal_Bool bRes = sal_True;
if (xSpell.is())
bRes = xSpell->isValid( rWord, nLanguage, rProperties );
return bRes;
}
uno::Reference< linguistic2::XSpellAlternatives > SAL_CALL
SpellDummy_Impl::spell( const rtl::OUString& rWord, sal_Int16 nLanguage,
const beans::PropertyValues& rProperties )
throw(lang::IllegalArgumentException,
uno::RuntimeException)
{
GetSpell_Impl();
uno::Reference< linguistic2::XSpellAlternatives > xRes;
if (xSpell.is())
xRes = xSpell->spell( rWord, nLanguage, rProperties );
return xRes;
}
//! Dummy implementation in order to avoid loading of lingu DLL.
//! The dummy accesses the real implementation (and thus loading the DLL)
//! when it needs to be done only.
class HyphDummy_Impl :
public cppu::WeakImplHelper1< XHyphenator >
{
uno::Reference< XHyphenator > xHyph; // the real one...
void GetHyph_Impl();
public:
// XSupportedLocales
virtual ::com::sun::star::uno::Sequence<
::com::sun::star::lang::Locale > SAL_CALL
getLocales()
throw(::com::sun::star::uno::RuntimeException);
virtual sal_Bool SAL_CALL
hasLocale( const ::com::sun::star::lang::Locale& rLocale )
throw(::com::sun::star::uno::RuntimeException);
// XHyphenator
virtual ::com::sun::star::uno::Reference<
::com::sun::star::linguistic2::XHyphenatedWord > SAL_CALL
hyphenate( const ::rtl::OUString& rWord,
const ::com::sun::star::lang::Locale& rLocale,
sal_Int16 nMaxLeading,
const ::com::sun::star::beans::PropertyValues& rProperties )
throw(::com::sun::star::lang::IllegalArgumentException,
::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference<
::com::sun::star::linguistic2::XHyphenatedWord > SAL_CALL
queryAlternativeSpelling( const ::rtl::OUString& rWord,
const ::com::sun::star::lang::Locale& rLocale,
sal_Int16 nIndex,
const ::com::sun::star::beans::PropertyValues& rProperties )
throw(::com::sun::star::lang::IllegalArgumentException,
::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference<
::com::sun::star::linguistic2::XPossibleHyphens > SAL_CALL
createPossibleHyphens(
const ::rtl::OUString& rWord,
const ::com::sun::star::lang::Locale& rLocale,
const ::com::sun::star::beans::PropertyValues& rProperties )
throw(::com::sun::star::lang::IllegalArgumentException,
::com::sun::star::uno::RuntimeException);
};
void HyphDummy_Impl::GetHyph_Impl()
{
if (!xHyph.is())
{
uno::Reference< XLinguServiceManager2 > xLngSvcMgr( GetLngSvcMgr_Impl() );
xHyph = xLngSvcMgr->getHyphenator();
}
}
uno::Sequence< lang::Locale > SAL_CALL
HyphDummy_Impl::getLocales()
throw(uno::RuntimeException)
{
GetHyph_Impl();
if (xHyph.is())
return xHyph->getLocales();
else
return uno::Sequence< lang::Locale >();
}
sal_Bool SAL_CALL
HyphDummy_Impl::hasLocale( const lang::Locale& rLocale )
throw(uno::RuntimeException)
{
GetHyph_Impl();
sal_Bool bRes = sal_False;
if (xHyph.is())
bRes = xHyph->hasLocale( rLocale );
return bRes;
}
uno::Reference< linguistic2::XHyphenatedWord > SAL_CALL
HyphDummy_Impl::hyphenate(
const rtl::OUString& rWord,
const lang::Locale& rLocale,
sal_Int16 nMaxLeading,
const beans::PropertyValues& rProperties )
throw(lang::IllegalArgumentException,
uno::RuntimeException)
{
GetHyph_Impl();
uno::Reference< linguistic2::XHyphenatedWord > xRes;
if (xHyph.is())
xRes = xHyph->hyphenate( rWord, rLocale, nMaxLeading, rProperties );
return xRes;
}
uno::Reference< linguistic2::XHyphenatedWord > SAL_CALL
HyphDummy_Impl::queryAlternativeSpelling(
const rtl::OUString& rWord,
const lang::Locale& rLocale,
sal_Int16 nIndex,
const PropertyValues& rProperties )
throw(lang::IllegalArgumentException,
uno::RuntimeException)
{
GetHyph_Impl();
uno::Reference< linguistic2::XHyphenatedWord > xRes;
if (xHyph.is())
xRes = xHyph->queryAlternativeSpelling( rWord, rLocale, nIndex, rProperties );
return xRes;
}
uno::Reference< linguistic2::XPossibleHyphens > SAL_CALL
HyphDummy_Impl::createPossibleHyphens(
const rtl::OUString& rWord,
const lang::Locale& rLocale,
const beans::PropertyValues& rProperties )
throw(lang::IllegalArgumentException,
uno::RuntimeException)
{
GetHyph_Impl();
uno::Reference< linguistic2::XPossibleHyphens > xRes;
if (xHyph.is())
xRes = xHyph->createPossibleHyphens( rWord, rLocale, rProperties );
return xRes;
}
2000-09-18 16:07:07 +00:00
typedef cppu::WeakImplHelper1 < XEventListener > LinguMgrAppExitLstnrBaseClass;
2000-09-18 16:07:07 +00:00
class LinguMgrAppExitLstnr : public LinguMgrAppExitLstnrBaseClass
{
uno::Reference< XComponent > xDesktop;
2000-09-18 16:07:07 +00:00
public:
LinguMgrAppExitLstnr();
virtual ~LinguMgrAppExitLstnr();
virtual void AtExit() = 0;
// lang::XEventListener
virtual void SAL_CALL disposing(const EventObject& rSource)
throw( RuntimeException );
};
LinguMgrAppExitLstnr::LinguMgrAppExitLstnr()
{
// add object to frame::Desktop EventListeners in order to properly call
// the AtExit function at appliction exit.
uno::Reference< XMultiServiceFactory > xMgr = getProcessServiceFactory();
2000-09-18 16:07:07 +00:00
if ( xMgr.is() )
{
xDesktop = uno::Reference< XComponent > ( xMgr->createInstance(
2000-10-24 10:38:57 +00:00
OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.frame.Desktop" ) ) ), UNO_QUERY ) ;
2000-09-18 16:07:07 +00:00
if (xDesktop.is())
xDesktop->addEventListener( this );
}
}
LinguMgrAppExitLstnr::~LinguMgrAppExitLstnr()
{
if (xDesktop.is())
{
xDesktop->removeEventListener( this );
xDesktop = NULL; //! release reference to desktop
}
2011-03-29 19:12:39 +02:00
OSL_ENSURE(!xDesktop.is(), "reference to desktop should be realeased");
2000-09-18 16:07:07 +00:00
}
void LinguMgrAppExitLstnr::disposing(const EventObject& rSource)
throw( RuntimeException )
{
if (xDesktop.is() && rSource.Source == xDesktop)
{
xDesktop->removeEventListener( this );
xDesktop = NULL; //! release reference to desktop
AtExit();
}
}
class LinguMgrExitLstnr : public LinguMgrAppExitLstnr
{
public:
virtual void AtExit();
};
void LinguMgrExitLstnr::AtExit()
{
// release references
2000-10-27 09:25:31 +00:00
LinguMgr::xLngSvcMgr = 0;
2000-09-18 16:07:07 +00:00
LinguMgr::xSpell = 0;
LinguMgr::xHyph = 0;
LinguMgr::xThes = 0;
LinguMgr::xDicList = 0;
LinguMgr::xProp = 0;
LinguMgr::xIgnoreAll = 0;
LinguMgr::xChangeAll = 0;
LinguMgr::bExiting = sal_True;
LinguMgr::pExitLstnr = 0;
}
LinguMgrExitLstnr * LinguMgr::pExitLstnr = 0;
sal_Bool LinguMgr::bExiting = sal_False;
uno::Reference< XLinguServiceManager2 > LinguMgr::xLngSvcMgr = 0;
uno::Reference< XSpellChecker1 > LinguMgr::xSpell = 0;
uno::Reference< XHyphenator > LinguMgr::xHyph = 0;
uno::Reference< XThesaurus > LinguMgr::xThes = 0;
uno::Reference< XDictionaryList > LinguMgr::xDicList = 0;
uno::Reference< XPropertySet > LinguMgr::xProp = 0;
2008-12-15 12:01:46 +00:00
uno::Reference< XDictionary > LinguMgr::xIgnoreAll = 0;
uno::Reference< XDictionary > LinguMgr::xChangeAll = 0;
2000-09-18 16:07:07 +00:00
2000-10-27 09:25:31 +00:00
uno::Reference< XLinguServiceManager2 > LinguMgr::GetLngSvcMgr()
{
if (bExiting)
return 0;
if (!pExitLstnr)
pExitLstnr = new LinguMgrExitLstnr;
if (!xLngSvcMgr.is())
xLngSvcMgr = GetLngSvcMgr_Impl();
return xLngSvcMgr;
}
uno::Reference< XSpellChecker1 > LinguMgr::GetSpellChecker()
2000-09-18 16:07:07 +00:00
{
return xSpell.is() ? xSpell : GetSpell();
}
uno::Reference< XHyphenator > LinguMgr::GetHyphenator()
2000-09-18 16:07:07 +00:00
{
return xHyph.is() ? xHyph : GetHyph();
}
uno::Reference< XThesaurus > LinguMgr::GetThesaurus()
2000-09-18 16:07:07 +00:00
{
return xThes.is() ? xThes : GetThes();
}
uno::Reference< XDictionaryList > LinguMgr::GetDictionaryList()
2000-09-18 16:07:07 +00:00
{
return xDicList.is() ? xDicList : GetDicList();
}
uno::Reference< XPropertySet > LinguMgr::GetLinguPropertySet()
2000-09-18 16:07:07 +00:00
{
return xProp.is() ? xProp : GetProp();
}
2008-12-15 12:01:46 +00:00
uno::Reference< XDictionary > LinguMgr::GetStandardDic()
2000-09-18 16:07:07 +00:00
{
//! don't hold reference to this
//! (it may be removed from dictionary list and needs to be
//! created empty if accessed again)
return GetStandard();
}
2008-12-15 12:01:46 +00:00
uno::Reference< XDictionary > LinguMgr::GetIgnoreAllList()
2000-09-18 16:07:07 +00:00
{
return xIgnoreAll.is() ? xIgnoreAll : GetIgnoreAll();
}
2008-12-15 12:01:46 +00:00
uno::Reference< XDictionary > LinguMgr::GetChangeAllList()
2000-09-18 16:07:07 +00:00
{
return xChangeAll.is() ? xChangeAll : GetChangeAll();
}
uno::Reference< XSpellChecker1 > LinguMgr::GetSpell()
2000-09-18 16:07:07 +00:00
{
if (bExiting)
return 0;
if (!pExitLstnr)
pExitLstnr = new LinguMgrExitLstnr;
//! use dummy implementation in order to avoid loading of lingu DLL
xSpell = new SpellDummy_Impl;
2000-09-18 16:07:07 +00:00
return xSpell;
}
uno::Reference< XHyphenator > LinguMgr::GetHyph()
2000-09-18 16:07:07 +00:00
{
if (bExiting)
return 0;
if (!pExitLstnr)
pExitLstnr = new LinguMgrExitLstnr;
//! use dummy implementation in order to avoid loading of lingu DLL
xHyph = new HyphDummy_Impl;
2000-09-18 16:07:07 +00:00
return xHyph;
}
uno::Reference< XThesaurus > LinguMgr::GetThes()
2000-09-18 16:07:07 +00:00
{
if (bExiting)
return 0;
if (!pExitLstnr)
pExitLstnr = new LinguMgrExitLstnr;
//! use dummy implementation in order to avoid loading of lingu DLL
//! when only the XSupportedLocales interface is used.
//! The dummy accesses the real implementation (and thus loading the DLL)
//! when "real" work needs to be done only.
xThes = new ThesDummy_Impl;
2000-09-18 16:07:07 +00:00
return xThes;
}
uno::Reference< XDictionaryList > LinguMgr::GetDicList()
2000-09-18 16:07:07 +00:00
{
if (bExiting)
return 0;
if (!pExitLstnr)
pExitLstnr = new LinguMgrExitLstnr;
uno::Reference< XMultiServiceFactory > xMgr( getProcessServiceFactory() );
2000-09-18 16:07:07 +00:00
if (xMgr.is())
{
xDicList = uno::Reference< XDictionaryList > ( xMgr->createInstance(
A2OU("com.sun.star.linguistic2.DictionaryList") ), UNO_QUERY );
2000-09-18 16:07:07 +00:00
}
return xDicList;
}
uno::Reference< XPropertySet > LinguMgr::GetProp()
2000-09-18 16:07:07 +00:00
{
if (bExiting)
return 0;
if (!pExitLstnr)
pExitLstnr = new LinguMgrExitLstnr;
uno::Reference< XMultiServiceFactory > xMgr( getProcessServiceFactory() );
2000-09-18 16:07:07 +00:00
if (xMgr.is())
{
xProp = uno::Reference< XPropertySet > ( xMgr->createInstance(
A2OU("com.sun.star.linguistic2.LinguProperties") ), UNO_QUERY );
2000-09-18 16:07:07 +00:00
}
return xProp;
}
2008-12-15 12:01:46 +00:00
uno::Reference< XDictionary > LinguMgr::GetIgnoreAll()
2000-09-18 16:07:07 +00:00
{
if (bExiting)
return 0;
if (!pExitLstnr)
pExitLstnr = new LinguMgrExitLstnr;
uno::Reference< XDictionaryList > xTmpDicList( GetDictionaryList() );
2000-09-18 16:07:07 +00:00
if (xTmpDicList.is())
{
2008-12-15 12:01:46 +00:00
xIgnoreAll = uno::Reference< XDictionary > ( xTmpDicList->getDictionaryByName(
A2OU("IgnoreAllList") ), UNO_QUERY );
2000-09-18 16:07:07 +00:00
}
return xIgnoreAll;
}
2008-12-15 12:01:46 +00:00
uno::Reference< XDictionary > LinguMgr::GetChangeAll()
2000-09-18 16:07:07 +00:00
{
if (bExiting)
return 0;
if (!pExitLstnr)
pExitLstnr = new LinguMgrExitLstnr;
uno::Reference< XDictionaryList > _xDicList( GetDictionaryList() , UNO_QUERY );
if (_xDicList.is())
2000-09-18 16:07:07 +00:00
{
2008-12-15 12:01:46 +00:00
xChangeAll = uno::Reference< XDictionary > (
_xDicList->createDictionary(
A2OU("ChangeAllList"),
2000-09-18 16:07:07 +00:00
SvxCreateLocale( LANGUAGE_NONE ),
DictionaryType_NEGATIVE, String() ), UNO_QUERY );
}
return xChangeAll;
}
2008-12-15 12:01:46 +00:00
uno::Reference< XDictionary > LinguMgr::GetStandard()
2000-09-18 16:07:07 +00:00
{
// Tries to return a dictionary which may hold positive entries is
// persistent and not read-only.
if (bExiting)
return 0;
uno::Reference< XDictionaryList > xTmpDicList( GetDictionaryList() );
2000-09-18 16:07:07 +00:00
if (!xTmpDicList.is())
return NULL;
const OUString aDicName( RTL_CONSTASCII_USTRINGPARAM( "standard.dic" ) );
2008-12-15 12:01:46 +00:00
uno::Reference< XDictionary > xDic( xTmpDicList->getDictionaryByName( aDicName ),
2000-09-18 16:07:07 +00:00
UNO_QUERY );
if (!xDic.is())
2000-09-18 16:07:07 +00:00
{
2000-10-27 09:25:31 +00:00
// try to create standard dictionary
uno::Reference< XDictionary > xTmp;
2000-10-27 09:25:31 +00:00
try
{
xTmp = xTmpDicList->createDictionary( aDicName,
SvxCreateLocale( LANGUAGE_NONE ),
DictionaryType_POSITIVE,
linguistic::GetWritableDictionaryURL( aDicName ) );
2000-10-27 09:25:31 +00:00
}
2011-12-09 02:56:30 +09:00
catch(const com::sun::star::uno::Exception &)
2000-09-18 16:07:07 +00:00
{
}
// add new dictionary to list
if (xTmp.is())
{
2000-09-18 16:07:07 +00:00
xTmpDicList->addDictionary( xTmp );
xTmp->setActive( sal_True );
}
2008-12-15 12:01:46 +00:00
xDic = uno::Reference< XDictionary > ( xTmp, UNO_QUERY );
2000-09-18 16:07:07 +00:00
}
#if OSL_DEBUG_LEVEL > 1
uno::Reference< XStorable > xStor( xDic, UNO_QUERY );
2011-03-29 19:12:39 +02:00
OSL_ENSURE( xDic.is() && xDic->getDictionaryType() == DictionaryType_POSITIVE,
"wrong dictionary type");
2011-03-29 19:12:39 +02:00
OSL_ENSURE( xDic.is() && SvxLocaleToLanguage( xDic->getLocale() ) == LANGUAGE_NONE,
"wrong dictionary language");
2011-03-29 19:12:39 +02:00
OSL_ENSURE( !xStor.is() || (xStor->hasLocation() && !xStor->isReadonly()),
"dictionary not editable" );
#endif
2000-09-18 16:07:07 +00:00
return xDic;
}
uno::Reference< XSpellChecker1 > SvxGetSpellChecker()
2000-09-18 16:07:07 +00:00
{
return LinguMgr::GetSpellChecker();
}
uno::Reference< XHyphenator > SvxGetHyphenator()
2000-09-18 16:07:07 +00:00
{
return LinguMgr::GetHyphenator();
}
uno::Reference< XThesaurus > SvxGetThesaurus()
2000-09-18 16:07:07 +00:00
{
return LinguMgr::GetThesaurus();
}
uno::Reference< XDictionaryList > SvxGetDictionaryList()
2000-09-18 16:07:07 +00:00
{
return LinguMgr::GetDictionaryList();
}
uno::Reference< XPropertySet > SvxGetLinguPropertySet()
2000-09-18 16:07:07 +00:00
{
return LinguMgr::GetLinguPropertySet();
}
2011-02-16 16:34:02 -05:00
//TODO: remove argument or provide SvxGetIgnoreAllList with the same one
2008-12-15 12:01:46 +00:00
uno::Reference< XDictionary > SvxGetOrCreatePosDic(
uno::Reference< XDictionaryList > /* xDicList */ )
2000-09-18 16:07:07 +00:00
{
return LinguMgr::GetStandardDic();
}
2008-12-15 12:01:46 +00:00
uno::Reference< XDictionary > SvxGetIgnoreAllList()
2000-09-18 16:07:07 +00:00
{
return LinguMgr::GetIgnoreAllList();
}
2008-12-15 12:01:46 +00:00
uno::Reference< XDictionary > SvxGetChangeAllList()
2000-09-18 16:07:07 +00:00
{
return LinguMgr::GetChangeAllList();
}
#include <com/sun/star/linguistic2/XHyphenatedWord.hpp>
SvxAlternativeSpelling SvxGetAltSpelling(
const ::com::sun::star::uno::Reference<
::com::sun::star::linguistic2::XHyphenatedWord > & rHyphWord )
{
SvxAlternativeSpelling aRes;
if (rHyphWord.is() && rHyphWord->isAlternativeSpelling())
{
OUString aWord( rHyphWord->getWord() ),
aAltWord( rHyphWord->getHyphenatedWord() );
sal_Int16 nHyphenationPos = rHyphWord->getHyphenationPos(),
2000-09-18 16:07:07 +00:00
nHyphenPos = rHyphWord->getHyphenPos();
sal_Int16 nLen = (sal_Int16)aWord.getLength();
sal_Int16 nAltLen = (sal_Int16)aAltWord.getLength();
2000-09-18 16:07:07 +00:00
const sal_Unicode *pWord = aWord.getStr(),
*pAltWord = aAltWord.getStr();
// count number of chars from the left to the
// hyphenation pos / hyphen pos that are equal
sal_Int16 nL = 0;
while (nL <= nHyphenationPos && nL <= nHyphenPos
&& pWord[ nL ] == pAltWord[ nL ])
++nL;
// count number of chars from the right to the
// hyphenation pos / hyphen pos that are equal
sal_Int16 nR = 0;
sal_Int32 nIdx = nLen - 1;
sal_Int32 nAltIdx = nAltLen - 1;
while (nIdx > nHyphenationPos && nAltIdx > nHyphenPos
&& pWord[ nIdx-- ] == pAltWord[ nAltIdx-- ])
++nR;
aRes.aReplacement = OUString( aAltWord.copy( nL, nAltLen - nL - nR ) );
aRes.nChangedPos = (sal_Int16) nL;
aRes.nChangedLength = nLen - nL - nR;
aRes.bIsAltSpelling = sal_True;
2000-09-18 16:07:07 +00:00
aRes.xHyphWord = rHyphWord;
}
return aRes;
}
2000-10-27 09:25:31 +00:00
2000-09-18 16:07:07 +00:00
SvxDicListChgClamp::SvxDicListChgClamp( uno::Reference< XDictionaryList > &rxDicList ) :
2000-09-18 16:07:07 +00:00
xDicList ( rxDicList )
{
if (xDicList.is())
{
xDicList->beginCollectEvents();
}
}
SvxDicListChgClamp::~SvxDicListChgClamp()
{
if (xDicList.is())
{
xDicList->endCollectEvents();
}
}
short SvxDicError( Window *pParent, sal_Int16 nError )
{
short nRes = 0;
if (DIC_ERR_NONE != nError)
{
int nRid;
switch (nError)
{
case DIC_ERR_FULL : nRid = RID_SVXSTR_DIC_ERR_FULL; break;
case DIC_ERR_READONLY : nRid = RID_SVXSTR_DIC_ERR_READONLY; break;
default:
nRid = RID_SVXSTR_DIC_ERR_UNKNOWN;
2011-03-29 19:12:39 +02:00
OSL_FAIL("unexpected case");
2000-09-18 16:07:07 +00:00
}
nRes = InfoBox( pParent, EE_RESSTR( nRid ) ).Execute();
2000-09-18 16:07:07 +00:00
}
return nRes;
}
LanguageType SvxLocaleToLanguage( const Locale& rLocale )
{
if ( rLocale.Language.isEmpty() )
2000-09-18 16:07:07 +00:00
return LANGUAGE_NONE;
return MsLangId::convertLocaleToLanguage( rLocale );
2000-09-18 16:07:07 +00:00
}
Locale& SvxLanguageToLocale( Locale& rLocale, LanguageType eLang )
{
if ( eLang != LANGUAGE_NONE )
MsLangId::convertLanguageToLocale( eLang, rLocale );
else
rLocale = Locale();
2000-09-18 16:07:07 +00:00
return rLocale;
}
Locale SvxCreateLocale( LanguageType eLang )
{
Locale aLocale;
if ( eLang != LANGUAGE_NONE )
MsLangId::convertLanguageToLocale( eLang, aLocale );
2000-09-18 16:07:07 +00:00
return aLocale;
2000-09-18 16:07:07 +00:00
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */