23#include <com/sun/star/frame/Desktop.hpp>
24#include <com/sun/star/frame/XStorable.hpp>
25#include <com/sun/star/lang/XEventListener.hpp>
26#include <com/sun/star/linguistic2/XHyphenatedWord.hpp>
27#include <com/sun/star/linguistic2/DictionaryList.hpp>
28#include <com/sun/star/linguistic2/LinguServiceManager.hpp>
29#include <com/sun/star/linguistic2/LinguProperties.hpp>
30#include <com/sun/star/linguistic2/XSpellChecker1.hpp>
41#include <editeng/editrids.hrc>
42#include <svtools/strings.hrc>
45#include <osl/diagnose.h>
60 uno::Reference< XLinguServiceManager2 > xRes = LinguServiceManager::create(xContext);
71 public cppu::WeakImplHelper< XThesaurus >
73 uno::Reference< XThesaurus > xThes;
74 std::unique_ptr<Sequence< lang::Locale >> pLocaleSeq;
84 virtual css::uno::Sequence< css::lang::Locale > SAL_CALL
85 getLocales()
override;
87 hasLocale(
const css::lang::Locale& rLocale )
override;
90 virtual css::uno::Sequence<
91 css::uno::Reference< css::linguistic2::XMeaning > > SAL_CALL
92 queryMeanings(
const OUString& rTerm,
93 const css::lang::Locale& rLocale,
94 const css::uno::Sequence< css::beans::PropertyValue >& rProperties )
override;
99void ThesDummy_Impl::GetCfgLocales()
105 Sequence < OUString > aNodeNames( aCfg.
GetNodeNames(
"ServiceManager/ThesaurusList" ) );
106 const OUString *pNodeNames = aNodeNames.getConstArray();
107 sal_Int32 nLen = aNodeNames.getLength();
108 pLocaleSeq.reset(
new Sequence< lang::Locale >( nLen ) );
109 lang::Locale *
pLocale = pLocaleSeq->getArray();
110 for (sal_Int32 i = 0;
i < nLen; ++
i)
117void ThesDummy_Impl::GetThes_Impl()
122 xThes = xLngSvcMgr->getThesaurus();
133uno::Sequence< lang::Locale > SAL_CALL
134 ThesDummy_Impl::getLocales()
138 return xThes->getLocales();
139 else if (!pLocaleSeq)
146 ThesDummy_Impl::hasLocale(
const lang::Locale& rLocale )
150 return xThes->hasLocale( rLocale );
151 else if (!pLocaleSeq)
154 sal_Int32 nLen = pLocaleSeq->getLength();
155 const lang::Locale *
pLocale = pLocaleSeq->getConstArray();
156 const lang::Locale *pEnd =
pLocale + nLen;
159 bFound =
pLocale->Language == rLocale.Language &&
160 pLocale->Country == rLocale.Country &&
161 pLocale->Variant == rLocale.Variant;
167uno::Sequence< uno::Reference< linguistic2::XMeaning > > SAL_CALL
168 ThesDummy_Impl::queryMeanings(
169 const OUString& rTerm,
170 const lang::Locale& rLocale,
171 const css::uno::Sequence< css::beans::PropertyValue >& rProperties )
174 uno::Sequence< uno::Reference< linguistic2::XMeaning > > aRes;
175 OSL_ENSURE( xThes.is(),
"Thesaurus missing" );
177 aRes = xThes->queryMeanings( rTerm, rLocale, rProperties );
186class SpellDummy_Impl :
187 public cppu::WeakImplHelper< XSpellChecker1 >
189 uno::Reference< XSpellChecker1 > xSpell;
191 void GetSpell_Impl();
196 virtual css::uno::Sequence< sal_Int16 > SAL_CALL
197 getLanguages()
override;
199 hasLanguage( sal_Int16 nLanguage )
override;
203 isValid(
const OUString& rWord, sal_Int16 nLanguage,
204 const css::uno::Sequence< css::beans::PropertyValue >& rProperties )
override;
205 virtual css::uno::Reference< css::linguistic2::XSpellAlternatives > SAL_CALL
206 spell(
const OUString& rWord, sal_Int16 nLanguage,
207 const css::uno::Sequence< css::beans::PropertyValue >& rProperties )
override;
212void SpellDummy_Impl::GetSpell_Impl()
217 xSpell.set( xLngSvcMgr->getSpellChecker(), UNO_QUERY );
222uno::Sequence< sal_Int16 > SAL_CALL
223 SpellDummy_Impl::getLanguages()
227 return xSpell->getLanguages();
229 return uno::Sequence< sal_Int16 >();
234 SpellDummy_Impl::hasLanguage( sal_Int16 nLanguage )
239 bRes = xSpell->hasLanguage( nLanguage );
245 SpellDummy_Impl::isValid(
const OUString& rWord, sal_Int16 nLanguage,
246 const css::uno::Sequence< css::beans::PropertyValue >& rProperties )
251 bRes = xSpell->isValid( rWord, nLanguage, rProperties );
256uno::Reference< linguistic2::XSpellAlternatives > SAL_CALL
257 SpellDummy_Impl::spell(
const OUString& rWord, sal_Int16 nLanguage,
258 const css::uno::Sequence< css::beans::PropertyValue >& rProperties )
261 uno::Reference< linguistic2::XSpellAlternatives > xRes;
263 xRes = xSpell->spell( rWord, nLanguage, rProperties );
272class HyphDummy_Impl :
273 public cppu::WeakImplHelper< XHyphenator >
275 uno::Reference< XHyphenator > xHyph;
282 virtual css::uno::Sequence<
283 css::lang::Locale > SAL_CALL
284 getLocales()
override;
286 hasLocale(
const css::lang::Locale& rLocale )
override;
289 virtual css::uno::Reference<
290 css::linguistic2::XHyphenatedWord > SAL_CALL
291 hyphenate(
const OUString& rWord,
292 const css::lang::Locale& rLocale,
293 sal_Int16 nMaxLeading,
294 const css::uno::Sequence< css::beans::PropertyValue >& rProperties )
override;
295 virtual css::uno::Reference<
296 css::linguistic2::XHyphenatedWord > SAL_CALL
297 queryAlternativeSpelling(
const OUString& rWord,
298 const css::lang::Locale& rLocale,
300 const css::uno::Sequence< css::beans::PropertyValue >& rProperties )
override;
301 virtual css::uno::Reference<
302 css::linguistic2::XPossibleHyphens > SAL_CALL
303 createPossibleHyphens(
304 const OUString& rWord,
305 const css::lang::Locale& rLocale,
306 const css::uno::Sequence< css::beans::PropertyValue >& rProperties )
override;
311void HyphDummy_Impl::GetHyph_Impl()
316 xHyph = xLngSvcMgr->getHyphenator();
321uno::Sequence< lang::Locale > SAL_CALL
322 HyphDummy_Impl::getLocales()
326 return xHyph->getLocales();
328 return uno::Sequence< lang::Locale >();
333 HyphDummy_Impl::hasLocale(
const lang::Locale& rLocale )
338 bRes = xHyph->hasLocale( rLocale );
343uno::Reference< linguistic2::XHyphenatedWord > SAL_CALL
344 HyphDummy_Impl::hyphenate(
345 const OUString& rWord,
346 const lang::Locale& rLocale,
347 sal_Int16 nMaxLeading,
348 const css::uno::Sequence< css::beans::PropertyValue >& rProperties )
351 uno::Reference< linguistic2::XHyphenatedWord > xRes;
353 xRes = xHyph->hyphenate( rWord, rLocale, nMaxLeading, rProperties );
358uno::Reference< linguistic2::XHyphenatedWord > SAL_CALL
359 HyphDummy_Impl::queryAlternativeSpelling(
360 const OUString& rWord,
361 const lang::Locale& rLocale,
363 const css::uno::Sequence< css::beans::PropertyValue >& rProperties )
366 uno::Reference< linguistic2::XHyphenatedWord > xRes;
368 xRes = xHyph->queryAlternativeSpelling( rWord, rLocale, nIndex, rProperties );
373uno::Reference< linguistic2::XPossibleHyphens > SAL_CALL
374 HyphDummy_Impl::createPossibleHyphens(
375 const OUString& rWord,
376 const lang::Locale& rLocale,
377 const css::uno::Sequence< css::beans::PropertyValue >& rProperties )
380 uno::Reference< linguistic2::XPossibleHyphens > xRes;
382 xRes = xHyph->createPossibleHyphens( rWord, rLocale, rProperties );
397 virtual void SAL_CALL
disposing(
const EventObject& rSource)
override;
406 xDesktop = Desktop::create( xContext );
414 xDesktop->removeEventListener(
this );
417 OSL_ENSURE(!
xDesktop.is(),
"reference to desktop should be released");
424 xDesktop->removeEventListener(
this );
530 xSpell =
new SpellDummy_Impl;
543 xHyph =
new HyphDummy_Impl;
559 xThes =
new ThesDummy_Impl;
596 if (xTmpDicList.is())
599 xIgnoreAll = xTmpDicList->getDictionaryByName(
619 DictionaryType_NEGATIVE, OUString() );
633 if (!xTmpDicList.is())
636 static constexpr OUStringLiteral aDicName(
u"standard.dic" );
637 uno::Reference< XDictionary > xDic = xTmpDicList->getDictionaryByName( aDicName );
641 uno::Reference< XDictionary > xTmp;
644 xTmp = xTmpDicList->createDictionary( aDicName,
646 DictionaryType_POSITIVE,
649 catch(
const css::uno::Exception &)
656 xTmpDicList->addDictionary( xTmp );
657 xTmp->setActive(
true );
661#if OSL_DEBUG_LEVEL > 1
662 uno::Reference< XStorable > xStor( xDic, UNO_QUERY );
663 OSL_ENSURE( xDic.is() && xDic->getDictionaryType() == DictionaryType_POSITIVE,
664 "wrong dictionary type");
666 "wrong dictionary language");
667 OSL_ENSURE( !xStor.is() || (xStor->hasLocation() && !xStor->isReadonly()),
668 "dictionary not editable" );
675 const css::uno::Reference< css::linguistic2::XHyphenatedWord > & rHyphWord )
678 if (rHyphWord.is() && rHyphWord->isAlternativeSpelling())
680 OUString aWord( rHyphWord->getWord() ),
681 aAltWord( rHyphWord->getHyphenatedWord() );
682 sal_Int16 nHyphenationPos = rHyphWord->getHyphenationPos(),
683 nHyphenPos = rHyphWord->getHyphenPos();
684 sal_Int16 nLen =
static_cast<sal_Int16
>(aWord.getLength());
685 sal_Int16 nAltLen =
static_cast<sal_Int16
>(aAltWord.getLength());
687 *pAltWord = aAltWord.getStr();
692 while (nL <= nHyphenationPos && nL <= nHyphenPos
693 && pWord[ nL ] == pAltWord[ nL ])
698 sal_Int32 nIdx = nLen - 1;
699 sal_Int32 nAltIdx = nAltLen - 1;
700 while (nIdx > nHyphenationPos && nAltIdx > nHyphenPos
701 && pWord[ nIdx-- ] == pAltWord[ nAltIdx-- ])
704 aRes.
aReplacement = aAltWord.copy( nL, nAltLen - nL - nR );
714 xDicList (
std::move( _xDicList ))
718 xDicList->beginCollectEvents();
741 pRid = RID_SVXSTR_DIC_ERR_UNKNOWN;
742 SAL_WARN(
"editeng",
"unexpected case");
745 VclMessageType::Info, VclButtonsType::Ok,
747 nRes = xInfoBox->run();
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
LanguageType getLanguageType(bool bResolveSystem=true) const
static css::lang::Locale convertToLocaleWithFallback(const OUString &rBcp47)
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)
uno::Reference< XDesktop2 > xDesktop
virtual ~LinguMgrExitLstnr() override
virtual void SAL_CALL disposing(const EventObject &rSource) override
static css::uno::Reference< css::linguistic2::XThesaurus > GetThesaurus()
static css::uno::Reference< css::linguistic2::XDictionary > GetStandard()
static css::uno::Reference< css::linguistic2::XSearchableDictionaryList > xDicList
static css::uno::Reference< css::linguistic2::XDictionary > xIgnoreAll
static css::uno::Reference< css::linguistic2::XSpellChecker1 > xSpell
static rtl::Reference< LinguMgrExitLstnr > pExitLstnr
static css::uno::Reference< css::linguistic2::XSpellChecker1 > GetSpellChecker()
static css::uno::Reference< css::linguistic2::XHyphenator > GetHyph()
static css::uno::Reference< css::linguistic2::XLinguProperties > GetProp()
static css::uno::Reference< css::linguistic2::XDictionary > GetChangeAllList()
static css::uno::Reference< css::linguistic2::XThesaurus > GetThes()
static css::uno::Reference< css::linguistic2::XLinguServiceManager2 > GetLngSvcMgr()
static css::uno::Reference< css::linguistic2::XSearchableDictionaryList > GetDictionaryList()
static css::uno::Reference< css::linguistic2::XSearchableDictionaryList > GetDicList()
static css::uno::Reference< css::linguistic2::XLinguServiceManager2 > xLngSvcMgr
friend class LinguMgrExitLstnr
static css::uno::Reference< css::linguistic2::XHyphenator > xHyph
static css::uno::Reference< css::linguistic2::XDictionary > GetChangeAll()
static css::uno::Reference< css::linguistic2::XDictionary > GetIgnoreAllList()
static css::uno::Reference< css::linguistic2::XThesaurus > xThes
static css::uno::Reference< css::linguistic2::XHyphenator > GetHyphenator()
static css::uno::Reference< css::linguistic2::XSpellChecker1 > GetSpell()
static css::uno::Reference< css::linguistic2::XDictionary > GetStandardDic()
static css::uno::Reference< css::linguistic2::XLinguProperties > GetLinguPropertySet()
static css::uno::Reference< css::linguistic2::XLinguProperties > xProp
static css::uno::Reference< css::linguistic2::XDictionary > GetIgnoreAll()
static css::uno::Reference< css::linguistic2::XDictionary > xChangeAll
css::uno::Sequence< OUString > GetNodeNames(const OUString &rNode) const
css::uno::Reference< css::linguistic2::XSearchableDictionaryList > xDicList
SvxDicListChgClamp(const SvxDicListChgClamp &)=delete
OUString EditResId(TranslateId aId)
#define SAL_WARN(area, stream)
std::locale Create(std::string_view aPrefixName, const LanguageTag &rLocale)
OUString get(TranslateId sContextAndId, const std::locale &loc)
Reference< XComponentContext > getProcessComponentContext()
OUString GetWritableDictionaryURL(std::u16string_view rDicName)
static uno::Reference< XLinguServiceManager2 > GetLngSvcMgr_Impl()
SvxAlternativeSpelling SvxGetAltSpelling(const css::uno::Reference< css::linguistic2::XHyphenatedWord > &rHyphWord)
short SvxDicError(weld::Window *pParent, linguistic::DictionaryError nError)