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