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
{ namespace sun
{ namespace star
{ namespace beans
{
40 namespace com
{ namespace sun
{ namespace star
{ namespace frame
{
44 namespace com::sun::star::linguistic2
{ class XDictionary
; }
45 namespace com::sun::star::linguistic2
{ class XDictionaryEntry
; }
46 namespace com::sun::star::linguistic2
{ class XHyphenatedWord
; }
47 namespace com::sun::star::linguistic2
{ class XLinguProperties
; }
48 namespace com::sun::star::linguistic2
{ class XSearchableDictionaryList
; }
49 namespace osl
{ class Mutex
; }
52 class LocaleDataWrapper
;
55 #define SN_GRAMMARCHECKER "com.sun.star.linguistic2.Proofreader"
56 #define SN_SPELLCHECKER "com.sun.star.linguistic2.SpellChecker"
57 #define SN_HYPHENATOR "com.sun.star.linguistic2.Hyphenator"
58 #define SN_THESAURUS "com.sun.star.linguistic2.Thesaurus"
65 // AddEntryToDic return values
66 enum class DictionaryError
68 NONE
, FULL
, READONLY
, UNKNOWN
, NOT_EXISTS
71 // values assigned to capitalization types
81 LNG_DLLPUBLIC ::osl::Mutex
& GetLinguMutex();
83 const LocaleDataWrapper
& GetLocaleDataWrapper( LanguageType nLang
);
85 sal_Int32
LevDistance( const OUString
&rTxt1
, const OUString
&rTxt2
);
87 /** Convert Locale to LanguageType for legacy handling.
88 Linguistic specific handling of an empty locale denoting LANGUAGE_NONE.
89 Does not resolve empty locale as system locale.
91 LNG_DLLPUBLIC LanguageType
LinguLocaleToLanguage( const css::lang::Locale
& rLocale
);
93 /** Convert LanguageType to Locale for legacy handling.
94 Linguistic specific handling of LANGUAGE_NONE resulting in an empty locale.
97 LNG_DLLPUBLIC
css::lang::Locale
LinguLanguageToLocale( LanguageType nLanguage
);
99 /** Checks if a LanguageType is one of the values that denote absence of
100 language or undetermined language or multiple languages, in short all
101 values used in linguistic context that do not denote a specific language.
103 LNG_DLLPUBLIC
bool LinguIsUnspecified( LanguageType nLanguage
);
105 /** The same as LinguIsUnspecified(LanguageType) but taking a BCP 47 language
106 tag string instead. */
107 LNG_DLLPUBLIC
bool LinguIsUnspecified( const OUString
& rBcp47
);
109 std::vector
< LanguageType
>
110 LocaleSeqToLangVec( css::uno::Sequence
< css::lang::Locale
> const &rLocaleSeq
);
111 css::uno::Sequence
<sal_Int16
>
112 LocaleSeqToLangSeq( css::uno::Sequence
< css::lang::Locale
> const &rLocaleSeq
);
114 // checks if file pointed to by rURL is readonly
115 // and may also check return if such a file exists or not
116 bool IsReadOnly( const OUString
&rURL
, bool *pbExist
= nullptr );
118 // checks if a file with the given URL exists
119 bool FileExists( const OUString
&rURL
);
122 OUString
GetDictionaryWriteablePath();
123 std::vector
< OUString
> GetDictionaryPaths();
125 /// @returns a URL for a new and writable dictionary rDicName.
126 /// The URL will point to the path given by 'GetDictionaryWriteablePath'
127 LNG_DLLPUBLIC OUString
GetWritableDictionaryURL( const OUString
&rDicName
);
129 LNG_DLLPUBLIC sal_Int32
GetPosInWordToCheck( const OUString
&rTxt
, sal_Int32 nPos
);
131 css::uno::Reference
< css::linguistic2::XHyphenatedWord
>
132 RebuildHyphensAndControlChars(
133 const OUString
&rOrigWord
,
134 css::uno::Reference
< css::linguistic2::XHyphenatedWord
> const &rxHyphWord
);
137 LNG_DLLPUBLIC
bool IsUpper( const OUString
&rText
, sal_Int32 nPos
, sal_Int32 nLen
, LanguageType nLanguage
);
139 inline bool IsUpper( const OUString
&rText
, LanguageType nLanguage
) { return IsUpper( rText
, 0, rText
.getLength(), nLanguage
); }
140 LNG_DLLPUBLIC CapType
capitalType(const OUString
&, CharClass
const *);
142 OUString
ToLower( const OUString
&rText
, LanguageType nLanguage
);
143 LNG_DLLPUBLIC
bool HasDigits( const OUString
&rText
);
144 LNG_DLLPUBLIC
bool IsNumeric( const OUString
&rText
);
147 LNG_DLLPUBLIC
css::uno::Reference
< css::linguistic2::XLinguProperties
> GetLinguProperties();
148 css::uno::Reference
< css::linguistic2::XSearchableDictionaryList
> GetDictionaryList();
149 css::uno::Reference
< css::linguistic2::XDictionary
> GetIgnoreAllList();
152 bool IsUseDicList( const css::beans::PropertyValues
&rProperties
,
153 const css::uno::Reference
< css::beans::XPropertySet
> &rxPropSet
);
155 bool IsIgnoreControlChars( const css::beans::PropertyValues
&rProperties
,
156 const css::uno::Reference
< css::beans::XPropertySet
> &rxPropSet
);
159 css::linguistic2::XDictionaryEntry
>
161 const css::uno::Reference
< css::linguistic2::XSearchableDictionaryList
>& rDicList
,
162 const OUString
& rWord
, LanguageType nLanguage
,
163 bool bSearchPosDics
, bool bSearchSpellEntry
);
165 LNG_DLLPUBLIC DictionaryError
AddEntryToDic(
166 css::uno::Reference
< css::linguistic2::XDictionary
> const &rxDic
,
167 const OUString
&rWord
, bool bIsNeg
,
168 const OUString
&rRplcTxt
,
169 bool bStripDot
= true );
171 LNG_DLLPUBLIC
bool SaveDictionaries( const css::uno::Reference
< css::linguistic2::XSearchableDictionaryList
> &xDicList
);
174 // virtual base class that calls it AtExit function when the application
175 // (ie the Desktop) is about to terminate
177 class AppExitListener
:
178 public cppu::WeakImplHelper
< css::frame::XTerminateListener
>
180 css::uno::Reference
< css::frame::XDesktop2
> xDesktop
;
184 virtual ~AppExitListener() override
;
186 virtual void AtExit() = 0;
192 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
194 // XTerminateListener
195 virtual void SAL_CALL
queryTermination( const css::lang::EventObject
& aEvent
) override
;
196 virtual void SAL_CALL
notifyTermination( const css::lang::EventObject
& aEvent
) override
;
199 } // namespace linguistic
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */