xref: /trunk/main/linguistic/source/dicimp.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _LINGUISTIC_DICIMP_HXX_
25 #define _LINGUISTIC_DICIMP_HXX_
26 
27 #include <com/sun/star/linguistic2/XDictionary.hpp>
28 #include <com/sun/star/frame/XStorable.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 
31 #include <uno/lbnames.h>            // CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
32 #include <cppuhelper/implbase2.hxx> // helper for implementations
33 #include <cppuhelper/implbase1.hxx> // helper for implementations
34 #include <cppuhelper/interfacecontainer.h>
35 #include <tools/string.hxx>
36 #include <tools/stream.hxx>
37 
38 #include "defs.hxx"
39 #include "linguistic/misc.hxx"
40 
41 
42 ///////////////////////////////////////////////////////////////////////////
43 
44 #define DIC_MAX_ENTRIES     30000
45 
46 sal_Int16           ReadDicVersion( SvStreamPtr &rpStream, sal_uInt16 &nLng, sal_Bool &bNeg );
47 const String    GetDicExtension();
48 
49 ///////////////////////////////////////////////////////////////////////////
50 
51 class DictionaryNeo :
52     public ::cppu::WeakImplHelper2
53     <
54         ::com::sun::star::linguistic2::XDictionary,
55         ::com::sun::star::frame::XStorable
56     >
57 {
58 
59     ::cppu::OInterfaceContainerHelper                           aDicEvtListeners;
60     ::com::sun::star::uno::Sequence<
61         ::com::sun::star::uno::Reference<
62             ::com::sun::star::linguistic2::XDictionaryEntry > > aEntries;
63     ::rtl::OUString                                             aDicName;
64     ::rtl::OUString                                             aMainURL;
65     ::com::sun::star::linguistic2::DictionaryType               eDicType;
66     sal_Int16                                                       nCount;
67     sal_Int16                                                       nLanguage;
68     sal_Int16                                                       nDicVersion;
69     sal_Bool                                                        bNeedEntries;
70     sal_Bool                                                        bIsModified;
71     sal_Bool                                                        bIsActive;
72     sal_Bool                                                        bIsReadonly;
73 
74     // disallow copy-constructor and assignment-operator for now
75     DictionaryNeo(const DictionaryNeo &);
76     DictionaryNeo & operator = (const DictionaryNeo &);
77 
78     void                    launchEvent(sal_Int16 nEvent,
79         ::com::sun::star::uno::Reference<
80             ::com::sun::star::linguistic2::XDictionaryEntry > xEntry);
81 
82     sal_uLong                   loadEntries(const ::rtl::OUString &rMainURL);
83     sal_uLong                   saveEntries(const ::rtl::OUString &rMainURL);
84     int                     cmpDicEntry(const ::rtl::OUString &rWord1,
85                                         const ::rtl::OUString &rWord2,
86                                         sal_Bool bSimilarOnly = sal_False);
87     sal_Bool                    seekEntry(const ::rtl::OUString &rWord, sal_Int32 *pPos,
88                                         sal_Bool bSimilarOnly = sal_False);
89     sal_Bool                    isSorted();
90 
91     sal_Bool                    addEntry_Impl(const ::com::sun::star::uno::Reference<
92         ::com::sun::star::linguistic2::XDictionaryEntry > xDicEntry,
93                                           sal_Bool bIsLoadEntries = sal_False);
94 
95 public:
96     DictionaryNeo();
97     DictionaryNeo(const ::rtl::OUString &rName, sal_Int16 nLang,
98                     ::com::sun::star::linguistic2::DictionaryType eType,
99                     const ::rtl::OUString &rMainURL,
100                     sal_Bool bWriteable );
101     virtual ~DictionaryNeo();
102 
103     // XNamed
104     virtual ::rtl::OUString SAL_CALL
105         getName();
106     virtual void SAL_CALL
107         setName( const ::rtl::OUString& aName );
108 
109     // XDictionary
110     virtual ::com::sun::star::linguistic2::DictionaryType SAL_CALL
111         getDictionaryType();
112     virtual void SAL_CALL
113         setActive( sal_Bool bActivate );
114     virtual sal_Bool SAL_CALL
115         isActive();
116     virtual sal_Int32 SAL_CALL
117         getCount();
118     virtual ::com::sun::star::lang::Locale SAL_CALL
119         getLocale();
120     virtual void SAL_CALL
121         setLocale( const ::com::sun::star::lang::Locale& aLocale );
122     virtual ::com::sun::star::uno::Reference<
123             ::com::sun::star::linguistic2::XDictionaryEntry > SAL_CALL
124         getEntry( const ::rtl::OUString& aWord );
125     virtual sal_Bool SAL_CALL
126         addEntry( const ::com::sun::star::uno::Reference<
127                 ::com::sun::star::linguistic2::XDictionaryEntry >& xDicEntry );
128     virtual sal_Bool SAL_CALL
129         add( const ::rtl::OUString& aWord, sal_Bool bIsNegative,
130                 const ::rtl::OUString& aRplcText );
131     virtual sal_Bool SAL_CALL
132         remove( const ::rtl::OUString& aWord );
133     virtual sal_Bool SAL_CALL
134         isFull();
135     virtual ::com::sun::star::uno::Sequence<
136             ::com::sun::star::uno::Reference<
137                 ::com::sun::star::linguistic2::XDictionaryEntry > > SAL_CALL
138         getEntries();
139     virtual void SAL_CALL
140         clear();
141     virtual sal_Bool SAL_CALL
142         addDictionaryEventListener( const ::com::sun::star::uno::Reference<
143                 ::com::sun::star::linguistic2::XDictionaryEventListener >& xListener );
144     virtual sal_Bool SAL_CALL
145         removeDictionaryEventListener( const ::com::sun::star::uno::Reference<
146                 ::com::sun::star::linguistic2::XDictionaryEventListener >& xListener );
147 
148     // XStorable
149     virtual sal_Bool SAL_CALL
150         hasLocation();
151     virtual ::rtl::OUString SAL_CALL
152         getLocation();
153     virtual sal_Bool SAL_CALL
154         isReadonly();
155     virtual void SAL_CALL
156         store();
157     virtual void SAL_CALL
158         storeAsURL( const ::rtl::OUString& aURL,
159                 const ::com::sun::star::uno::Sequence<
160                     ::com::sun::star::beans::PropertyValue >& aArgs );
161     virtual void SAL_CALL
162         storeToURL( const ::rtl::OUString& aURL,
163                 const ::com::sun::star::uno::Sequence<
164                     ::com::sun::star::beans::PropertyValue >& aArgs );
165 };
166 
167 
168 ///////////////////////////////////////////////////////////////////////////
169 
170 class DicEntry :
171     public cppu::WeakImplHelper1
172     <
173         ::com::sun::star::linguistic2::XDictionaryEntry
174     >
175 {
176     ::rtl::OUString aDicWord,       // including hyphen positions represented by "="
177                     aReplacement;   // including hyphen positions represented by "="
178     sal_Bool            bIsNegativ;
179 
180     // disallow copy-constructor and assignment-operator for now
181     DicEntry(const DicEntry &);
182     DicEntry & operator = (const DicEntry &);
183 
184     void            splitDicFileWord(const ::rtl::OUString &rDicFileWord,
185                                      ::rtl::OUString &rDicWord,
186                                      ::rtl::OUString &rReplacement);
187 
188 public:
189     DicEntry();
190     DicEntry(const ::rtl::OUString &rDicFileWord, sal_Bool bIsNegativ);
191     DicEntry(const ::rtl::OUString &rDicWord, sal_Bool bIsNegativ,
192              const ::rtl::OUString &rRplcText);
193     virtual ~DicEntry();
194 
195     // XDictionaryEntry
196     virtual ::rtl::OUString SAL_CALL
197         getDictionaryWord();
198     virtual sal_Bool SAL_CALL
199         isNegative();
200     virtual ::rtl::OUString SAL_CALL
201         getReplacementText();
202 };
203 
204 
205 ///////////////////////////////////////////////////////////////////////////
206 
207 #endif
208