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 #ifndef INCLUDED_LINGUISTIC_SOURCE_DICIMP_HXX 21 #define INCLUDED_LINGUISTIC_SOURCE_DICIMP_HXX 22 23 #include <com/sun/star/linguistic2/XDictionary.hpp> 24 #include <com/sun/star/frame/XStorable.hpp> 25 26 #include <cppuhelper/implbase.hxx> 27 #include <comphelper/interfacecontainer2.hxx> 28 #include <i18nlangtag/lang.h> 29 #include <vcl/errcode.hxx> 30 31 #include "defs.hxx" 32 33 #define DIC_MAX_ENTRIES 30000 34 35 sal_Int16 ReadDicVersion( SvStream& rStream, LanguageType &nLng, bool &bNeg, OUString &aDicName ); 36 37 class DictionaryNeo : 38 public ::cppu::WeakImplHelper 39 < 40 css::linguistic2::XDictionary, 41 css::frame::XStorable 42 > 43 { 44 45 ::comphelper::OInterfaceContainerHelper2 aDicEvtListeners; 46 std::vector< css::uno::Reference< css::linguistic2::XDictionaryEntry > > 47 aEntries; 48 OUString aDicName; 49 OUString aMainURL; 50 css::linguistic2::DictionaryType eDicType; 51 LanguageType nLanguage; 52 sal_Int16 nDicVersion; 53 bool bNeedEntries; 54 bool bIsModified; 55 bool bIsActive; 56 bool bIsReadonly; 57 58 DictionaryNeo(const DictionaryNeo &) = delete; 59 DictionaryNeo & operator = (const DictionaryNeo &) = delete; 60 61 void launchEvent(sal_Int16 nEvent, 62 const css::uno::Reference< css::linguistic2::XDictionaryEntry >& xEntry); 63 64 ErrCode loadEntries(const OUString &rMainURL); 65 ErrCode saveEntries(const OUString &rMainURL); 66 static int cmpDicEntry(const OUString &rWord1, 67 const OUString &rWord2, 68 bool bSimilarOnly = false); 69 bool seekEntry(const OUString &rWord, sal_Int32 *pPos, 70 bool bSimilarOnly = false); 71 bool isSorted(); 72 73 bool addEntry_Impl(const css::uno::Reference< css::linguistic2::XDictionaryEntry >& rDicEntry, 74 bool bIsLoadEntries = false); 75 76 public: 77 DictionaryNeo(const OUString &rName, LanguageType nLang, 78 css::linguistic2::DictionaryType eType, 79 const OUString &rMainURL, 80 bool bWriteable ); 81 virtual ~DictionaryNeo() override; 82 83 // XNamed 84 virtual OUString SAL_CALL 85 getName() override; 86 virtual void SAL_CALL 87 setName( const OUString& aName ) override; 88 89 // XDictionary 90 virtual css::linguistic2::DictionaryType SAL_CALL 91 getDictionaryType() override; 92 virtual void SAL_CALL 93 setActive( sal_Bool bActivate ) override; 94 virtual sal_Bool SAL_CALL 95 isActive() override; 96 virtual sal_Int32 SAL_CALL 97 getCount() override; 98 virtual css::lang::Locale SAL_CALL 99 getLocale() override; 100 virtual void SAL_CALL 101 setLocale( const css::lang::Locale& aLocale ) override; 102 virtual css::uno::Reference< 103 css::linguistic2::XDictionaryEntry > SAL_CALL 104 getEntry( const OUString& aWord ) override; 105 virtual sal_Bool SAL_CALL 106 addEntry( const css::uno::Reference< 107 css::linguistic2::XDictionaryEntry >& xDicEntry ) override; 108 virtual sal_Bool SAL_CALL 109 add( const OUString& aWord, sal_Bool bIsNegative, 110 const OUString& aRplcText ) override; 111 virtual sal_Bool SAL_CALL 112 remove( const OUString& aWord ) override; 113 virtual sal_Bool SAL_CALL 114 isFull() override; 115 virtual css::uno::Sequence< css::uno::Reference< css::linguistic2::XDictionaryEntry > > SAL_CALL 116 getEntries() override; 117 virtual void SAL_CALL 118 clear() override; 119 virtual sal_Bool SAL_CALL 120 addDictionaryEventListener( const css::uno::Reference< css::linguistic2::XDictionaryEventListener >& xListener ) override; 121 virtual sal_Bool SAL_CALL 122 removeDictionaryEventListener( const css::uno::Reference< css::linguistic2::XDictionaryEventListener >& xListener ) override; 123 124 // XStorable 125 virtual sal_Bool SAL_CALL 126 hasLocation() override; 127 virtual OUString SAL_CALL 128 getLocation() override; 129 virtual sal_Bool SAL_CALL 130 isReadonly() override; 131 virtual void SAL_CALL 132 store() override; 133 virtual void SAL_CALL 134 storeAsURL( const OUString& aURL, 135 const css::uno::Sequence< css::beans::PropertyValue >& aArgs ) override; 136 virtual void SAL_CALL 137 storeToURL( const OUString& aURL, 138 const css::uno::Sequence< css::beans::PropertyValue >& aArgs ) override; 139 }; 140 141 142 class DicEntry : 143 public cppu::WeakImplHelper< css::linguistic2::XDictionaryEntry > 144 { 145 OUString aDicWord, // including hyphen positions represented by "=" 146 aReplacement; // including hyphen positions represented by "=" 147 bool bIsNegativ; 148 149 DicEntry(const DicEntry &) = delete; 150 DicEntry & operator = (const DicEntry &) = delete; 151 152 static void splitDicFileWord(const OUString &rDicFileWord, 153 OUString &rDicWord, 154 OUString &rReplacement); 155 156 public: 157 DicEntry(const OUString &rDicFileWord, bool bIsNegativ); 158 DicEntry(const OUString &rDicWord, bool bIsNegativ, 159 const OUString &rRplcText); 160 virtual ~DicEntry() override; 161 162 // XDictionaryEntry 163 virtual OUString SAL_CALL 164 getDictionaryWord() override; 165 virtual sal_Bool SAL_CALL 166 isNegative() override; 167 virtual OUString SAL_CALL 168 getReplacementText() override; 169 }; 170 171 172 #endif 173 174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 175