Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / linguistic / source / dicimp.hxx
blob507e13a5aa585fe771e62d9a7ff377b68a98a092
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <com/sun/star/linguistic2/XDictionary.hpp>
23 #include <com/sun/star/frame/XStorable.hpp>
25 #include <cppuhelper/implbase.hxx>
26 #include <comphelper/interfacecontainer3.hxx>
27 #include <i18nlangtag/lang.h>
28 #include <comphelper/errcode.hxx>
30 #include "defs.hxx"
32 #define DIC_MAX_ENTRIES SAL_MAX_INT32
34 sal_Int16 ReadDicVersion( SvStream& rStream, LanguageType &nLng, bool &bNeg, OUString &aDicName );
36 class DictionaryNeo :
37 public ::cppu::WeakImplHelper
39 css::linguistic2::XDictionary,
40 css::frame::XStorable
44 ::comphelper::OInterfaceContainerHelper3<css::linguistic2::XDictionaryEventListener> aDicEvtListeners;
45 std::vector< css::uno::Reference< css::linguistic2::XDictionaryEntry > >
46 aEntries;
47 OUString aDicName;
48 OUString aMainURL;
49 css::linguistic2::DictionaryType eDicType;
50 LanguageType nLanguage;
51 sal_Int16 nDicVersion;
52 bool bNeedEntries;
53 bool bIsModified;
54 bool bIsActive;
55 bool bIsReadonly;
57 DictionaryNeo(const DictionaryNeo &) = delete;
58 DictionaryNeo & operator = (const DictionaryNeo &) = delete;
60 void launchEvent(sal_Int16 nEvent,
61 const css::uno::Reference< css::linguistic2::XDictionaryEntry >& xEntry);
63 ErrCode loadEntries(const OUString &rMainURL);
64 ErrCode saveEntries(const OUString &rMainURL);
65 static int cmpDicEntry(std::u16string_view rWord1,
66 std::u16string_view rWord2,
67 bool bSimilarOnly = false);
68 bool seekEntry(std::u16string_view rWord, sal_Int32 *pPos,
69 bool bSimilarOnly = false);
70 bool isSorted();
72 bool addEntry_Impl(const css::uno::Reference< css::linguistic2::XDictionaryEntry >& rDicEntry,
73 bool bIsLoadEntries = false);
75 public:
76 DictionaryNeo(OUString aName, LanguageType nLang,
77 css::linguistic2::DictionaryType eType,
78 const OUString &rMainURL,
79 bool bWriteable );
80 virtual ~DictionaryNeo() override;
82 // XNamed
83 virtual OUString SAL_CALL
84 getName() override;
85 virtual void SAL_CALL
86 setName( const OUString& aName ) override;
88 // XDictionary
89 virtual css::linguistic2::DictionaryType SAL_CALL
90 getDictionaryType() override;
91 virtual void SAL_CALL
92 setActive( sal_Bool bActivate ) override;
93 virtual sal_Bool SAL_CALL
94 isActive() override;
95 virtual sal_Int32 SAL_CALL
96 getCount() override;
97 virtual css::lang::Locale SAL_CALL
98 getLocale() override;
99 virtual void SAL_CALL
100 setLocale( const css::lang::Locale& aLocale ) override;
101 virtual css::uno::Reference<
102 css::linguistic2::XDictionaryEntry > SAL_CALL
103 getEntry( const OUString& aWord ) override;
104 virtual sal_Bool SAL_CALL
105 addEntry( const css::uno::Reference<
106 css::linguistic2::XDictionaryEntry >& xDicEntry ) override;
107 virtual sal_Bool SAL_CALL
108 add( const OUString& aWord, sal_Bool bIsNegative,
109 const OUString& aRplcText ) override;
110 virtual sal_Bool SAL_CALL
111 remove( const OUString& aWord ) override;
112 virtual sal_Bool SAL_CALL
113 isFull() override;
114 virtual css::uno::Sequence< css::uno::Reference< css::linguistic2::XDictionaryEntry > > SAL_CALL
115 getEntries() override;
116 virtual void SAL_CALL
117 clear() override;
118 virtual sal_Bool SAL_CALL
119 addDictionaryEventListener( const css::uno::Reference< css::linguistic2::XDictionaryEventListener >& xListener ) override;
120 virtual sal_Bool SAL_CALL
121 removeDictionaryEventListener( const css::uno::Reference< css::linguistic2::XDictionaryEventListener >& xListener ) override;
123 // XStorable
124 virtual sal_Bool SAL_CALL
125 hasLocation() override;
126 virtual OUString SAL_CALL
127 getLocation() override;
128 virtual sal_Bool SAL_CALL
129 isReadonly() override;
130 virtual void SAL_CALL
131 store() override;
132 virtual void SAL_CALL
133 storeAsURL( const OUString& aURL,
134 const css::uno::Sequence< css::beans::PropertyValue >& aArgs ) override;
135 virtual void SAL_CALL
136 storeToURL( const OUString& aURL,
137 const css::uno::Sequence< css::beans::PropertyValue >& aArgs ) override;
141 class DicEntry :
142 public cppu::WeakImplHelper< css::linguistic2::XDictionaryEntry >
144 OUString aDicWord, // including hyphen positions represented by "="
145 aReplacement; // including hyphen positions represented by "="
146 bool bIsNegativ;
148 DicEntry(const DicEntry &) = delete;
149 DicEntry & operator = (const DicEntry &) = delete;
151 static void splitDicFileWord(const OUString &rDicFileWord,
152 OUString &rDicWord,
153 OUString &rReplacement);
155 public:
156 DicEntry(const OUString &rDicFileWord, bool bIsNegativ);
157 DicEntry(OUString aDicWord, bool bIsNegativ,
158 OUString aRplcText);
159 virtual ~DicEntry() override;
161 // XDictionaryEntry
162 virtual OUString SAL_CALL
163 getDictionaryWord() override;
164 virtual sal_Bool SAL_CALL
165 isNegative() override;
166 virtual OUString SAL_CALL
167 getReplacementText() override;
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */