1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
|
/*************************************************************************
*
* $RCSfile: dlistimp.cxx,v $
*
* $Revision: 1.1.1.1 $
*
* last change: $Author: hr $ $Date: 2000-11-17 12:37:34 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#include "dlistimp.hxx"
#include "dicimp.hxx"
#ifndef _FSYS_HXX
#include <tools/fsys.hxx>
#endif
#ifndef _TOOLS_INTN_HXX
#include <tools/intn.hxx>
#endif
#ifndef _STREAM_HXX
#include <tools/stream.hxx>
#endif
#ifndef _URLOBJ_HXX
#include <tools/urlobj.hxx>
#endif
#ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
#include <svtools/pathoptions.hxx>
#endif
#ifndef INCLUDED_SVTOOLS_USEROPTIONS_HXX
#include <svtools/useroptions.hxx>
#endif
#ifndef _SFXDOCFILE_HXX
#include <sfx2/docfile.hxx>
#endif
#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif
#include <cppuhelper/factory.hxx> // helper for factories
#ifndef _COM_SUN_STAR_FRAME_XSTORABLE_HPP_
#include <com/sun/star/frame/XStorable.hpp>
#endif
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/linguistic2/DictionaryEventFlags.hpp>
#include <com/sun/star/linguistic2/DictionaryListEventFlags.hpp>
#include <com/sun/star/registry/XRegistryKey.hpp>
//using namespace utl;
using namespace osl;
using namespace rtl;
using namespace com::sun::star;
using namespace com::sun::star::lang;
using namespace com::sun::star::uno;
using namespace com::sun::star::linguistic2;
using namespace linguistic;
///////////////////////////////////////////////////////////////////////////
SV_IMPL_OBJARR(ActDicArray, ActDic);
///////////////////////////////////////////////////////////////////////////
#define BUFSIZE 256
#define VERS2_NOLANGUAGE 1024
static sal_Char aBuf[ BUFSIZE ];
static const sal_Char* aDicExt = "dic";
static const sal_Char* aVerStr2 = "WBSWG2";
static const sal_Char* aVerStr5 = "WBSWG5";
// forward dedclarations
static BOOL IsVers2( const DirEntry& rPathName, USHORT& nLng, BOOL& bNeg,
sal_Char* pWordBuf);
static void AddInternal( Reference< XDictionary > &rDic,
const OUString& rNew );
static void AddUserData( const Reference< XDictionary > &rDic );
///////////////////////////////////////////////////////////////////////////
class DicEvtListenerHelper :
public cppu::WeakImplHelper1
<
XDictionaryEventListener
>
{
cppu::OInterfaceContainerHelper aDicListEvtListeners;
Sequence< DictionaryEvent > aCollectDicEvt;
Reference< XDictionaryList > xMyDicList;
INT16 nCondensedEvt;
INT16 nNumCollectEvtListeners,
nNumVerboseListeners;
public:
DicEvtListenerHelper( const Reference< XDictionaryList > &rxDicList );
virtual ~DicEvtListenerHelper();
// XEventListener
virtual void SAL_CALL
disposing( const EventObject& rSource )
throw(RuntimeException);
// XDictionaryEventListener
virtual void SAL_CALL
processDictionaryEvent( const DictionaryEvent& rDicEvent )
throw(RuntimeException);
// non-UNO functions
void DisposeAndClear( const EventObject &rEvtObj );
BOOL AddDicListEvtListener(
const Reference< XDictionaryListEventListener >& rxListener,
BOOL bReceiveVerbose );
BOOL RemoveDicListEvtListener(
const Reference< XDictionaryListEventListener >& rxListener );
INT16 BeginCollectEvents();
INT16 EndCollectEvents();
INT16 FlushEvents();
};
DicEvtListenerHelper::DicEvtListenerHelper(
const Reference< XDictionaryList > &rxDicList ) :
aDicListEvtListeners ( GetLinguMutex() ),
xMyDicList ( rxDicList )
{
nCondensedEvt = 0;
nNumCollectEvtListeners = nNumVerboseListeners = 0;
}
DicEvtListenerHelper::~DicEvtListenerHelper()
{
DBG_ASSERT(aDicListEvtListeners.getLength() == 0,
"lng : event listeners are still existing");
}
void DicEvtListenerHelper::DisposeAndClear( const EventObject &rEvtObj )
{
aDicListEvtListeners.disposeAndClear( rEvtObj );
}
void SAL_CALL DicEvtListenerHelper::disposing( const EventObject& rSource )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
Reference< XInterface > xSrc( rSource.Source );
// remove event object from EventListener list
if (xSrc.is())
aDicListEvtListeners.removeInterface( xSrc );
// if object is a dictionary then remove it from the dictionary list
// Note: this will probably happen only if someone makes a XDictionary
// implementation of his own that is also a XComponent.
Reference< XDictionary > xDic( xSrc, UNO_QUERY );
if (xDic.is())
{
xMyDicList->removeDictionary( xDic );
}
}
void SAL_CALL DicEvtListenerHelper::processDictionaryEvent(
const DictionaryEvent& rDicEvent )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
Reference< XDictionary > xDic( rDicEvent.Source, UNO_QUERY );
DBG_ASSERT(xDic.is(), "lng : missing event source");
// assert that there is a corresponding dictionary entry if one was
// added or deleted
Reference< XDictionaryEntry > xDicEntry( rDicEvent.xDictionaryEntry, UNO_QUERY );
DBG_ASSERT( !(rDicEvent.nEvent &
(DictionaryEventFlags::ADD_ENTRY | DictionaryEventFlags::DEL_ENTRY))
|| xDicEntry.is(),
"lng : missing dictionary entry" );
//
// evaluate DictionaryEvents and update data for next DictionaryListEvent
//
DictionaryType eDicType = xDic->getDictionaryType();
DBG_ASSERT(eDicType != DictionaryType_MIXED,
"lng : unexpected dictionary type");
if ((rDicEvent.nEvent & DictionaryEventFlags::ADD_ENTRY) && xDic->isActive())
nCondensedEvt |= xDicEntry->isNegative() ?
DictionaryListEventFlags::ADD_NEG_ENTRY :
DictionaryListEventFlags::ADD_POS_ENTRY;
if ((rDicEvent.nEvent & DictionaryEventFlags::DEL_ENTRY) && xDic->isActive())
nCondensedEvt |= xDicEntry->isNegative() ?
DictionaryListEventFlags::DEL_NEG_ENTRY :
DictionaryListEventFlags::DEL_POS_ENTRY;
if ((rDicEvent.nEvent & DictionaryEventFlags::ENTRIES_CLEARED) && xDic->isActive())
nCondensedEvt |= eDicType == DictionaryType_NEGATIVE ?
DictionaryListEventFlags::DEL_NEG_ENTRY :
DictionaryListEventFlags::DEL_POS_ENTRY;
if ((rDicEvent.nEvent & DictionaryEventFlags::CHG_LANGUAGE) && xDic->isActive())
nCondensedEvt |= eDicType == DictionaryType_NEGATIVE ?
DictionaryListEventFlags::DEACTIVATE_NEG_DIC
| DictionaryListEventFlags::ACTIVATE_NEG_DIC :
DictionaryListEventFlags::DEACTIVATE_POS_DIC
| DictionaryListEventFlags::ACTIVATE_POS_DIC;
if ((rDicEvent.nEvent & DictionaryEventFlags::ACTIVATE_DIC))
nCondensedEvt |= eDicType == DictionaryType_NEGATIVE ?
DictionaryListEventFlags::ACTIVATE_NEG_DIC :
DictionaryListEventFlags::ACTIVATE_POS_DIC;
if ((rDicEvent.nEvent & DictionaryEventFlags::DEACTIVATE_DIC))
nCondensedEvt |= eDicType == DictionaryType_NEGATIVE ?
DictionaryListEventFlags::DEACTIVATE_NEG_DIC :
DictionaryListEventFlags::DEACTIVATE_POS_DIC;
// update list of collected events if needs to be
if (nNumVerboseListeners > 0)
{
INT32 nColEvts = aCollectDicEvt.getLength();
aCollectDicEvt.realloc( nColEvts + 1 );
aCollectDicEvt.getArray()[ nColEvts ] = rDicEvent;
}
if (nNumCollectEvtListeners == 0 && nCondensedEvt != 0)
FlushEvents();
}
BOOL DicEvtListenerHelper::AddDicListEvtListener(
const Reference< XDictionaryListEventListener >& xListener,
BOOL bReceiveVerbose )
{
DBG_ASSERT( xListener.is(), "empty reference" );
INT32 nCount = aDicListEvtListeners.getLength();
return aDicListEvtListeners.addInterface( xListener ) != nCount;
}
BOOL DicEvtListenerHelper::RemoveDicListEvtListener(
const Reference< XDictionaryListEventListener >& xListener )
{
DBG_ASSERT( xListener.is(), "empty reference" );
INT32 nCount = aDicListEvtListeners.getLength();
return aDicListEvtListeners.removeInterface( xListener ) != nCount;
}
INT16 DicEvtListenerHelper::BeginCollectEvents()
{
return ++nNumCollectEvtListeners;
}
INT16 DicEvtListenerHelper::EndCollectEvents()
{
DBG_ASSERT(nNumCollectEvtListeners > 0, "lng: mismatched function call");
if (nNumCollectEvtListeners > 0)
{
FlushEvents();
nNumCollectEvtListeners--;
}
return nNumCollectEvtListeners;
}
INT16 DicEvtListenerHelper::FlushEvents()
{
// build DictionaryListEvent to pass on to listeners
uno::Sequence< DictionaryEvent > aDicEvents;
if (nNumVerboseListeners > 0)
aDicEvents = aCollectDicEvt;
DictionaryListEvent aEvent( xMyDicList, nCondensedEvt, aDicEvents );
// pass on event
cppu::OInterfaceIteratorHelper aIt( aDicListEvtListeners );
while (aIt.hasMoreElements())
{
Reference< XDictionaryListEventListener > xRef( aIt.next(), UNO_QUERY );
if (xRef.is())
xRef->processDictionaryListEvent( aEvent );
}
// clear "list" of events
nCondensedEvt = 0;
aCollectDicEvt.realloc( 0 );
return nNumCollectEvtListeners;
}
///////////////////////////////////////////////////////////////////////////
void DicList::MyAppExitListener::AtExit()
{
// save (modified) dictionaries
Sequence< Reference< XDictionary > > aDics( rMyDicList.getDictionaries() );
Reference< XDictionary > *pDic = aDics.getArray();
INT32 nCount = aDics.getLength();
for (INT32 i = 0; i < nCount; i++)
{
// save (modified) dictionaries
Reference< frame::XStorable > xStor( pDic[i] , UNO_QUERY );
if (xStor.is())
{
try
{
if (!xStor->isReadonly() && xStor->hasLocation())
xStor->store();
}
catch(...)
{
}
}
}
}
DicList::DicList() :
aEvtListeners ( GetLinguMutex() )
{
pDicEvtLstnrHelper = new DicEvtListenerHelper( this );
xDicEvtLstnrHelper = pDicEvtLstnrHelper;
bDisposing = FALSE;
// look for dictionaries
SvtPathOptions aPathOpt;
searchForDictionaries( aDicList, aPathOpt.GetUserDictionaryPath() );
searchForDictionaries( aDicList, aPathOpt.GetDictionaryPath() );
// create IgnoreAllList dictionary with empty URL (non persistent)
// and add it to list
OUString aDicName( A2OU( "IgnoreAllList" ) );
Reference< XDictionary > xIgnAll(
createDictionary( aDicName, CreateLocale( LANGUAGE_NONE ),
DictionaryType_POSITIVE, OUString() ) );
if (xIgnAll.is())
{
AddUserData( xIgnAll );
xIgnAll->setActive( TRUE );
addDictionary( xIgnAll );
}
pExitListener = new MyAppExitListener( *this );
xExitListener = pExitListener;
pExitListener->Activate();
// evaluate list of dictionaries to be activated from configuration
const Sequence< OUString > aActiveDics( aOpt.GetCfgActiveDictionaries() );
const OUString *pActiveDic = aActiveDics.getConstArray();
INT32 nLen = aActiveDics.getLength();
for (INT32 i = 0; i < nLen; ++i)
{
if (pActiveDic[i].getLength())
{
Reference< XDictionary > xDic( getDictionaryByName( pActiveDic[i] ) );
if (xDic.is())
xDic->setActive( TRUE );
}
}
}
DicList::~DicList()
{
pExitListener->Deactivate();
}
void DicList::searchForDictionaries( ActDicArray &rDicList,
const String &rDicDir )
{
MutexGuard aGuard( GetLinguMutex() );
// get DirEntry for dictionaries directory
DirEntry aDicDir( rDicDir );
aDicDir.ToAbs();
// Alle auf Platte stehenden Dictionary-Names einlesen
String aDirTmp( String::CreateFromAscii( "*.*" ) );
aDicDir += DirEntry( aDirTmp );
Dir aDir(aDicDir, FSYS_KIND_FILE, FSYS_SORT_END);
String aDCN( String::CreateFromAscii( "dcn" ) );
String aDCP( String::CreateFromAscii( "dcp" ) );
INetURLObject aURLObject;
aURLObject.SetSmartProtocol( INET_PROT_FILE );
for (USHORT i=0; i < aDir.Count(); ++i)
{
String aName(aDir[i].GetName());
USHORT nLang = LANGUAGE_NONE;
BOOL bNeg = FALSE;
if(!::IsVers2(aDir[i], nLang, bNeg, aBuf))
{
// Wenn kein
xub_StrLen nPos = aName.Search('.');
String aExt(aName.Copy(nPos + 1));
aExt.ToLowerAscii();
if(aExt == aDCN) // negativ
bNeg = TRUE;
else if(aExt == aDCP) // positiv
bNeg = FALSE;
else
continue; // andere Files
}
// Aufnehmen in die Liste der Dictionaries
// Wenn existent nicht aufnehmen
//
INT16 nSystemLanguage = ::GetSystemLanguage();
String aTmp1 = ToLower( aName, nSystemLanguage );
String aTmp2;
INT32 j;
INT32 nCount = rDicList.Count();
for(j = 0; j < nCount; j++)
{
aTmp2 = rDicList.GetObject( j ).xDic->getName().getStr();
aTmp2 = ToLower( aTmp2, nSystemLanguage );
if(aTmp1 == aTmp2)
break;
}
if(j >= nCount) // dictionary not yet in DicList
{
String aFileName (rDicDir);
aFileName += DirEntry::GetAccessDelimiter();
aFileName += aName;
aURLObject.SetSmartURL( aFileName );
DBG_ASSERT(!aURLObject.HasError(), "lng : invalid URL");
DictionaryType eType = bNeg ? DictionaryType_NEGATIVE : DictionaryType_POSITIVE;
Reference< XDictionary > xDic =
new DictionaryNeo( aName, nLang, eType,
aURLObject.GetMainURL() );
addDictionary( xDic );
nCount++;
}
}
}
INT32 DicList::getDicPos(const Reference< XDictionary > &xDic)
{
MutexGuard aGuard( GetLinguMutex() );
INT32 nPos = -1;
INT32 n = aDicList.Count();
for (INT32 i = 0; i < n; i++)
{
if (aDicList.GetObject(i).xDic == xDic)
return i;
}
return nPos;
}
Reference< XInterface > SAL_CALL
DicList_CreateInstance( const Reference< XMultiServiceFactory > & rSMgr )
throw(Exception)
{
Reference< XInterface > xService = (cppu::OWeakObject *) new DicList;
return xService;
}
sal_Int16 SAL_CALL DicList::getCount() throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
return aDicList.Count();
}
uno::Sequence< Reference< XDictionary > > SAL_CALL
DicList::getDictionaries()
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
uno::Sequence< Reference< XDictionary > > aDics( aDicList.Count() );
Reference< XDictionary > *pDic = aDics.getArray();
INT32 n = aDics.getLength();
for (INT32 i = 0; i < n; i++)
pDic[i] = aDicList.GetObject(i).xDic;
return aDics;
}
Reference< XDictionary > SAL_CALL
DicList::getDictionaryByName( const OUString& aDictionaryName )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
Reference< XDictionary > xDic;
INT32 nCount = aDicList.Count();
for (INT32 i = 0; i < nCount; i++)
{
const Reference< XDictionary > &rDic = aDicList.GetObject(i).xDic;
if (rDic.is() && rDic->getName() == aDictionaryName)
{
xDic = rDic;
break;
}
}
return xDic;
}
sal_Bool SAL_CALL DicList::addDictionary(
const Reference< XDictionary >& xDictionary )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
if (bDisposing)
return FALSE;
BOOL bRes = FALSE;
if (xDictionary.is())
{
aDicList.Insert( ActDic(xDictionary), aDicList.Count() );
bRes = TRUE;
// add listener helper to the dictionaries listener lists
xDictionary->addDictionaryEventListener( xDicEvtLstnrHelper );
}
return bRes;
}
sal_Bool SAL_CALL
DicList::removeDictionary( const Reference< XDictionary >& xDictionary )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
if (bDisposing)
return FALSE;
BOOL bRes = FALSE;
INT32 nPos = getDicPos( xDictionary );
if (nPos >= 0)
{
// remove dictionary list from the dictionaries listener lists
Reference< XDictionary > xDic( aDicList.GetObject( nPos ).xDic );
DBG_ASSERT(xDic.is(), "lng : empty reference");
if (xDic.is())
{
// deactivate dictionary if not already done
xDic->setActive( FALSE );
xDic->removeDictionaryEventListener( xDicEvtLstnrHelper );
}
aDicList.Remove(nPos);
bRes = TRUE;
}
return bRes;
}
sal_Bool SAL_CALL DicList::addDictionaryListEventListener(
const Reference< XDictionaryListEventListener >& xListener,
sal_Bool bReceiveVerbose )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
if (bDisposing)
return FALSE;
DBG_ASSERT(!bReceiveVerbose, "lng : not yet supported");
BOOL bRes = FALSE;
if (xListener.is()) //! don't add empty references
{
bRes = pDicEvtLstnrHelper->
AddDicListEvtListener( xListener, bReceiveVerbose );
}
return bRes;
}
sal_Bool SAL_CALL DicList::removeDictionaryListEventListener(
const Reference< XDictionaryListEventListener >& xListener )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
if (bDisposing)
return FALSE;
BOOL bRes = FALSE;
if(xListener.is())
{
bRes = pDicEvtLstnrHelper->RemoveDicListEvtListener( xListener );
}
return bRes;
}
sal_Int16 SAL_CALL DicList::beginCollectEvents() throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
return pDicEvtLstnrHelper->BeginCollectEvents();
}
sal_Int16 SAL_CALL DicList::endCollectEvents() throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
return pDicEvtLstnrHelper->EndCollectEvents();
}
sal_Int16 SAL_CALL DicList::flushEvents() throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
return pDicEvtLstnrHelper->FlushEvents();
}
Reference< XDictionary > SAL_CALL
DicList::createDictionary( const OUString& rName, const Locale& rLocale,
DictionaryType eDicType, const OUString& rURL )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
INT16 nLanguage = LocaleToLanguage( rLocale );
return new DictionaryNeo( rName, nLanguage, eDicType, rURL );
}
Reference< XDictionaryEntry > SAL_CALL
DicList::queryDictionaryEntry( const OUString& rWord, const Locale& rLocale,
sal_Bool bSearchPosDics, sal_Bool bSearchSpellEntry )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
return SearchDicList( this, rWord, LocaleToLanguage( rLocale ),
bSearchPosDics, bSearchSpellEntry );
}
void SAL_CALL
DicList::dispose()
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
if (!bDisposing)
{
bDisposing = TRUE;
EventObject aEvtObj( (XDictionaryList *) this );
aEvtListeners.disposeAndClear( aEvtObj );
if (pDicEvtLstnrHelper)
pDicEvtLstnrHelper->DisposeAndClear( aEvtObj );
INT16 nCount = aDicList.Count();
for (INT16 i = 0; i < nCount; i++)
{
Reference< XDictionary > xDic( aDicList.GetObject(i).xDic , UNO_QUERY );
// save (modified) dictionaries
Reference< frame::XStorable > xStor( xDic , UNO_QUERY );
if (xStor.is())
{
try
{
if (!xStor->isReadonly() && xStor->hasLocation())
xStor->store();
}
catch(...)
{
}
}
// release references to (members of) this object hold by
// dictionaries
if (xDic.is())
xDic->removeDictionaryEventListener( xDicEvtLstnrHelper );
}
// set list of active dictionaries in configuration
aOpt.SetCfgActiveDictionaries( Reference< XDictionaryList >( this ));
}
}
void SAL_CALL
DicList::addEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
if (!bDisposing && rxListener.is())
aEvtListeners.addInterface( rxListener );
}
void SAL_CALL
DicList::removeEventListener( const Reference< XEventListener >& rxListener )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
if (!bDisposing && rxListener.is())
aEvtListeners.removeInterface( rxListener );
}
///////////////////////////////////////////////////////////////////////////
// Service specific part
//
OUString SAL_CALL DicList::getImplementationName( ) throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
return getImplementationName_Static();
}
sal_Bool SAL_CALL DicList::supportsService( const OUString& ServiceName )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
uno::Sequence< OUString > aSNL = getSupportedServiceNames();
const OUString * pArray = aSNL.getConstArray();
for( INT32 i = 0; i < aSNL.getLength(); i++ )
if( pArray[i] == ServiceName )
return TRUE;
return FALSE;
}
uno::Sequence< OUString > SAL_CALL DicList::getSupportedServiceNames( )
throw(RuntimeException)
{
MutexGuard aGuard( GetLinguMutex() );
return getSupportedServiceNames_Static();
}
uno::Sequence< OUString > DicList::getSupportedServiceNames_Static() throw()
{
MutexGuard aGuard( GetLinguMutex() );
uno::Sequence< OUString > aSNS( 1 ); // auch mehr als 1 Service moeglich
aSNS.getArray()[0] = A2OU( SN_DICTIONARY_LIST );
return aSNS;
}
sal_Bool SAL_CALL DicList_writeInfo(
void * /*pServiceManager*/, registry::XRegistryKey * pRegistryKey )
{
try
{
String aImpl( '/' );
aImpl += DicList::getImplementationName_Static().getStr();
aImpl.AppendAscii( "/UNO/SERVICES" );
Reference< registry::XRegistryKey > xNewKey =
pRegistryKey->createKey(aImpl );
uno::Sequence< OUString > aServices =
DicList::getSupportedServiceNames_Static();
for( INT32 i = 0; i < aServices.getLength(); i++ )
xNewKey->createKey( aServices.getConstArray()[i]);
return sal_True;
}
catch(Exception &)
{
return sal_False;
}
}
void * SAL_CALL DicList_getFactory( const sal_Char * pImplName,
XMultiServiceFactory * pServiceManager, void * )
{
void * pRet = 0;
if ( !DicList::getImplementationName_Static().compareToAscii( pImplName ) )
{
Reference< XSingleServiceFactory > xFactory =
cppu::createOneInstanceFactory(
pServiceManager,
DicList::getImplementationName_Static(),
DicList_CreateInstance,
DicList::getSupportedServiceNames_Static());
// acquire, because we return an interface pointer instead of a reference
xFactory->acquire();
pRet = xFactory.get();
}
return pRet;
}
///////////////////////////////////////////////////////////////////////////
xub_StrLen lcl_GetToken( String &rToken,
const String &rText, xub_StrLen nPos, const String &rDelim )
{
xub_StrLen nRes = STRING_LEN;
if (rText.Len() == 0 || nPos >= rText.Len())
rToken = String();
else if (rDelim.Len() == 0)
{
rToken = rText;
if (rToken.Len())
nRes = rText.Len();
}
else
{
xub_StrLen i;
for (i = nPos; i < rText.Len(); ++i)
{
if (STRING_NOTFOUND != rDelim.Search( rText.GetChar(i) ))
break;
}
if (i >= rText.Len()) // delimeter not found
rToken = rText.Copy( nPos );
else
rToken = rText.Copy( nPos, (INT32) i - nPos );
nRes = i + 1; // continue after found delimeter
}
return nRes;
}
static void AddInternal(
const Reference<XDictionary> &rDic,
const OUString& rNew )
{
if (rDic.is())
{
//! TL TODO: word iterator should be used to break up the text
static const char *pDefWordDelim =
"!\"#$%&'()*+,-./:;<=>?[]\\_^`{|}~\t \n";
ByteString aDummy( pDefWordDelim );
String aDelim( aDummy , RTL_TEXTENCODING_MS_1252 );
aDelim.EraseAllChars( '.' );
String aToken;
xub_StrLen nPos = 0;
while (STRING_LEN !=
(nPos = lcl_GetToken( aToken, rNew, nPos, aDelim )))
{
if( aToken.Len() && !IsNumeric( aToken ) )
{
rDic->add( aToken, FALSE, OUString() );
}
}
}
}
static void AddUserData( const Reference< XDictionary > &rDic )
{
if (rDic.is())
{
SvtUserOptions aUserOpt;
AddInternal( rDic, aUserOpt.GetFullName() );
AddInternal( rDic, aUserOpt.GetCompany() );
AddInternal( rDic, aUserOpt.GetStreet() );
AddInternal( rDic, aUserOpt.GetCity() );
AddInternal( rDic, aUserOpt.GetTitle() );
AddInternal( rDic, aUserOpt.GetPosition() );
AddInternal( rDic, aUserOpt.GetEmail() );
}
}
///////////////////////////////////////////////////////////////////////////
#pragma optimize("ge",off)
static BOOL IsVers2( const DirEntry& rPathName, USHORT& nLng, BOOL& bNeg,
sal_Char* pWordBuf)
{
String aDIC( String::CreateFromAscii( aDicExt ) );
String aExt(rPathName.GetExtension());
aExt.ToLowerAscii();
if(aExt != aDIC)
return FALSE;
// get binary files URL
INetURLObject aURLObj;
aURLObj.SetSmartProtocol( INET_PROT_FILE );
aURLObj.SetSmartURL( rPathName.GetFull() );
String aFileURL( aURLObj.GetMainURL() );
// get stream to be used
SfxMedium aMedium( aFileURL,
STREAM_READ | STREAM_SHARE_DENYWRITE, FALSE );
aMedium.SetTransferPriority( SFX_TFPRIO_SYNCHRON );
SvStream *pStream = aMedium.GetInStream();
if (!pStream || pStream->GetError())
return FALSE;
// Header einlesen
USHORT nLen;
sal_Char nTmp;
*pStream >> nLen;
if( nLen >= BUFSIZE )
return FALSE;
pStream->Read( pWordBuf, nLen);
*( pWordBuf + nLen ) = 0;
// Version 2.0 oder Version 5.0 ?
if( !strcmp( pWordBuf, aVerStr2 ) || !strcmp( pWordBuf, aVerStr5 ) )
{
// Sprache des Dictionaries
*pStream >> nLng;
if ( VERS2_NOLANGUAGE == nLng )
nLng = LANGUAGE_NONE;
// Negativ-Flag
*pStream >> nTmp;
bNeg = (BOOL)nTmp;
return TRUE;
}
return FALSE;
}
///////////////////////////////////////////////////////////////////////////
|