1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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>
32 #define DIC_MAX_ENTRIES SAL_MAX_INT32
34 sal_Int16
ReadDicVersion( SvStream
& rStream
, LanguageType
&nLng
, bool &bNeg
, OUString
&aDicName
);
37 public ::cppu::WeakImplHelper
39 css::linguistic2::XDictionary
,
44 ::comphelper::OInterfaceContainerHelper3
<css::linguistic2::XDictionaryEventListener
> aDicEvtListeners
;
45 std::vector
< css::uno::Reference
< css::linguistic2::XDictionaryEntry
> >
49 css::linguistic2::DictionaryType eDicType
;
50 LanguageType nLanguage
;
51 sal_Int16 nDicVersion
;
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);
72 bool addEntry_Impl(const css::uno::Reference
< css::linguistic2::XDictionaryEntry
>& rDicEntry
,
73 bool bIsLoadEntries
= false);
76 DictionaryNeo(OUString aName
, LanguageType nLang
,
77 css::linguistic2::DictionaryType eType
,
78 const OUString
&rMainURL
,
80 virtual ~DictionaryNeo() override
;
83 virtual OUString SAL_CALL
86 setName( const OUString
& aName
) override
;
89 virtual css::linguistic2::DictionaryType SAL_CALL
90 getDictionaryType() override
;
92 setActive( sal_Bool bActivate
) override
;
93 virtual sal_Bool SAL_CALL
95 virtual sal_Int32 SAL_CALL
97 virtual css::lang::Locale 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
114 virtual css::uno::Sequence
< css::uno::Reference
< css::linguistic2::XDictionaryEntry
> > SAL_CALL
115 getEntries() override
;
116 virtual void SAL_CALL
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
;
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
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
;
142 public cppu::WeakImplHelper
< css::linguistic2::XDictionaryEntry
>
144 OUString aDicWord
, // including hyphen positions represented by "="
145 aReplacement
; // including hyphen positions represented by "="
148 DicEntry(const DicEntry
&) = delete;
149 DicEntry
& operator = (const DicEntry
&) = delete;
151 static void splitDicFileWord(const OUString
&rDicFileWord
,
153 OUString
&rReplacement
);
156 DicEntry(const OUString
&rDicFileWord
, bool bIsNegativ
);
157 DicEntry(OUString aDicWord
, bool bIsNegativ
,
159 virtual ~DicEntry() override
;
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: */