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