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