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 .
20 #ifndef INCLUDED_LINGUISTIC_MISC_HXX
21 #define INCLUDED_LINGUISTIC_MISC_HXX
23 #include <com/sun/star/uno/Sequence.h>
24 #include <com/sun/star/uno/Reference.h>
25 #include <com/sun/star/beans/PropertyValues.hpp>
26 #include <com/sun/star/frame/XTerminateListener.hpp>
27 #include <com/sun/star/lang/Locale.hpp>
29 #include <cppuhelper/implbase.hxx>
30 #include <i18nlangtag/lang.h>
31 #include <rtl/ustring.hxx>
32 #include <linguistic/lngdllapi.h>
36 namespace com::sun::star::beans
{ class XPropertySet
; }
37 namespace com::sun::star::frame
{ class XDesktop2
; }
38 namespace com::sun::star::linguistic2
{ class XDictionary
; }
39 namespace com::sun::star::linguistic2
{ class XDictionaryEntry
; }
40 namespace com::sun::star::linguistic2
{ class XHyphenatedWord
; }
41 namespace com::sun::star::linguistic2
{ class XLinguProperties
; }
42 namespace com::sun::star::linguistic2
{ class XSearchableDictionaryList
; }
43 namespace osl
{ class Mutex
; }
46 class LocaleDataWrapper
;
49 #define SN_GRAMMARCHECKER "com.sun.star.linguistic2.Proofreader"
50 #define SN_SPELLCHECKER "com.sun.star.linguistic2.SpellChecker"
51 #define SN_HYPHENATOR "com.sun.star.linguistic2.Hyphenator"
52 #define SN_THESAURUS "com.sun.star.linguistic2.Thesaurus"
59 // AddEntryToDic return values
60 enum class DictionaryError
62 NONE
, FULL
, READONLY
, UNKNOWN
, NOT_EXISTS
65 // values assigned to capitalization types
75 LNG_DLLPUBLIC ::osl::Mutex
& GetLinguMutex();
77 const LocaleDataWrapper
& GetLocaleDataWrapper( LanguageType nLang
);
79 sal_Int32
LevDistance( const OUString
&rTxt1
, const OUString
&rTxt2
);
81 /** Convert Locale to LanguageType for legacy handling.
82 Linguistic specific handling of an empty locale denoting LANGUAGE_NONE.
83 Does not resolve empty locale as system locale.
85 LNG_DLLPUBLIC LanguageType
LinguLocaleToLanguage( const css::lang::Locale
& rLocale
);
87 /** Convert LanguageType to Locale for legacy handling.
88 Linguistic specific handling of LANGUAGE_NONE resulting in an empty locale.
91 LNG_DLLPUBLIC
css::lang::Locale
LinguLanguageToLocale( LanguageType nLanguage
);
93 /** Checks if a LanguageType is one of the values that denote absence of
94 language or undetermined language or multiple languages, in short all
95 values used in linguistic context that do not denote a specific language.
97 LNG_DLLPUBLIC
bool LinguIsUnspecified( LanguageType nLanguage
);
99 /** The same as LinguIsUnspecified(LanguageType) but taking a BCP 47 language
100 tag string instead. */
101 LNG_DLLPUBLIC
bool LinguIsUnspecified( const OUString
& rBcp47
);
103 std::vector
< LanguageType
>
104 LocaleSeqToLangVec( css::uno::Sequence
< css::lang::Locale
> const &rLocaleSeq
);
105 css::uno::Sequence
<sal_Int16
>
106 LocaleSeqToLangSeq( css::uno::Sequence
< css::lang::Locale
> const &rLocaleSeq
);
108 // checks if file pointed to by rURL is readonly
109 // and may also check return if such a file exists or not
110 bool IsReadOnly( const OUString
&rURL
, bool *pbExist
= nullptr );
112 // checks if a file with the given URL exists
113 bool FileExists( const OUString
&rURL
);
116 OUString
GetDictionaryWriteablePath();
117 std::vector
< OUString
> GetDictionaryPaths();
119 /// @returns a URL for a new and writable dictionary rDicName.
120 /// The URL will point to the path given by 'GetDictionaryWriteablePath'
121 LNG_DLLPUBLIC OUString
GetWritableDictionaryURL( const OUString
&rDicName
);
123 LNG_DLLPUBLIC sal_Int32
GetPosInWordToCheck( const OUString
&rTxt
, sal_Int32 nPos
);
125 css::uno::Reference
< css::linguistic2::XHyphenatedWord
>
126 RebuildHyphensAndControlChars(
127 const OUString
&rOrigWord
,
128 css::uno::Reference
< css::linguistic2::XHyphenatedWord
> const &rxHyphWord
);
131 LNG_DLLPUBLIC
bool IsUpper( const OUString
&rText
, sal_Int32 nPos
, sal_Int32 nLen
, LanguageType nLanguage
);
133 inline bool IsUpper( const OUString
&rText
, LanguageType nLanguage
) { return IsUpper( rText
, 0, rText
.getLength(), nLanguage
); }
134 LNG_DLLPUBLIC CapType
capitalType(const OUString
&, CharClass
const *);
136 OUString
ToLower( const OUString
&rText
, LanguageType nLanguage
);
137 LNG_DLLPUBLIC
bool HasDigits( const OUString
&rText
);
138 LNG_DLLPUBLIC
bool IsNumeric( const OUString
&rText
);
141 LNG_DLLPUBLIC
css::uno::Reference
< css::linguistic2::XLinguProperties
> GetLinguProperties();
142 css::uno::Reference
< css::linguistic2::XSearchableDictionaryList
> GetDictionaryList();
143 css::uno::Reference
< css::linguistic2::XDictionary
> GetIgnoreAllList();
146 bool IsUseDicList( const css::beans::PropertyValues
&rProperties
,
147 const css::uno::Reference
< css::beans::XPropertySet
> &rxPropSet
);
149 bool IsIgnoreControlChars( const css::beans::PropertyValues
&rProperties
,
150 const css::uno::Reference
< css::beans::XPropertySet
> &rxPropSet
);
153 css::linguistic2::XDictionaryEntry
>
155 const css::uno::Reference
< css::linguistic2::XSearchableDictionaryList
>& rDicList
,
156 const OUString
& rWord
, LanguageType nLanguage
,
157 bool bSearchPosDics
, bool bSearchSpellEntry
);
159 LNG_DLLPUBLIC DictionaryError
AddEntryToDic(
160 css::uno::Reference
< css::linguistic2::XDictionary
> const &rxDic
,
161 const OUString
&rWord
, bool bIsNeg
,
162 const OUString
&rRplcTxt
,
163 bool bStripDot
= true );
165 LNG_DLLPUBLIC
bool SaveDictionaries( const css::uno::Reference
< css::linguistic2::XSearchableDictionaryList
> &xDicList
);
168 // virtual base class that calls it AtExit function when the application
169 // (ie the Desktop) is about to terminate
171 class AppExitListener
:
172 public cppu::WeakImplHelper
< css::frame::XTerminateListener
>
174 css::uno::Reference
< css::frame::XDesktop2
> xDesktop
;
178 virtual ~AppExitListener() override
;
180 virtual void AtExit() = 0;
186 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
188 // XTerminateListener
189 virtual void SAL_CALL
queryTermination( const css::lang::EventObject
& aEvent
) override
;
190 virtual void SAL_CALL
notifyTermination( const css::lang::EventObject
& aEvent
) override
;
193 } // namespace linguistic
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */