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