android: Update app-specific/MIME type icons
[LibreOffice.git] / include / linguistic / misc.hxx
blob02b3d44b3fb46e9256ac51bac16e129692fb6669
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 #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>
34 #include <vector>
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; }
45 class CharClass;
46 class LocaleDataWrapper;
49 inline constexpr OUStringLiteral SN_GRAMMARCHECKER = u"com.sun.star.linguistic2.Proofreader";
50 inline constexpr OUStringLiteral SN_SPELLCHECKER = u"com.sun.star.linguistic2.SpellChecker";
51 inline constexpr OUStringLiteral SN_HYPHENATOR = u"com.sun.star.linguistic2.Hyphenator";
52 inline constexpr OUStringLiteral SN_THESAURUS = u"com.sun.star.linguistic2.Thesaurus";
55 namespace linguistic
59 // AddEntryToDic return values
60 enum class DictionaryError
62 NONE, FULL, READONLY, UNKNOWN, NOT_EXISTS
65 // values assigned to capitalization types
66 enum class CapType
68 UNKNOWN,
69 NOCAP,
70 INITCAP,
71 ALLCAP,
72 MIXED
75 LNG_DLLPUBLIC ::osl::Mutex& GetLinguMutex();
77 const LocaleDataWrapper & GetLocaleDataWrapper( LanguageType nLang );
79 sal_Int32 LevDistance( std::u16string_view rTxt1, std::u16string_view 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.
89 Avoid use!
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( std::u16string_view 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( std::u16string_view rDicName );
123 LNG_DLLPUBLIC sal_Int32 GetPosInWordToCheck( std::u16string_view 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 LNG_DLLPUBLIC bool HasDigits( const OUString &rText );
137 LNG_DLLPUBLIC bool IsNumeric( std::u16string_view rText );
140 LNG_DLLPUBLIC css::uno::Reference< css::linguistic2::XLinguProperties > GetLinguProperties();
141 css::uno::Reference< css::linguistic2::XSearchableDictionaryList > GetDictionaryList();
142 css::uno::Reference< css::linguistic2::XDictionary > GetIgnoreAllList();
145 bool IsUseDicList( const css::beans::PropertyValues &rProperties,
146 const css::uno::Reference< css::beans::XPropertySet > &rxPropSet );
148 bool IsIgnoreControlChars( const css::beans::PropertyValues &rProperties,
149 const css::uno::Reference< css::beans::XPropertySet > &rxPropSet );
151 css::uno::Reference<
152 css::linguistic2::XDictionaryEntry >
153 SearchDicList(
154 const css::uno::Reference< css::linguistic2::XSearchableDictionaryList >& rDicList,
155 const OUString& rWord, LanguageType nLanguage,
156 bool bSearchPosDics, bool bSearchSpellEntry );
158 LNG_DLLPUBLIC DictionaryError AddEntryToDic(
159 css::uno::Reference< css::linguistic2::XDictionary > const &rxDic,
160 const OUString &rWord, bool bIsNeg,
161 const OUString &rRplcTxt,
162 bool bStripDot = true );
164 LNG_DLLPUBLIC bool SaveDictionaries( const css::uno::Reference< css::linguistic2::XSearchableDictionaryList > &xDicList );
166 // AppExitLstnr:
167 // virtual base class that calls it AtExit function when the application
168 // (ie the Desktop) is about to terminate
170 class AppExitListener :
171 public cppu::WeakImplHelper< css::frame::XTerminateListener >
173 css::uno::Reference< css::frame::XDesktop2 > xDesktop;
175 public:
176 AppExitListener();
177 virtual ~AppExitListener() override;
179 virtual void AtExit() = 0;
181 void Activate();
182 void Deactivate();
184 // XEventListener
185 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
187 // XTerminateListener
188 virtual void SAL_CALL queryTermination( const css::lang::EventObject& aEvent ) override;
189 virtual void SAL_CALL notifyTermination( const css::lang::EventObject& aEvent ) override;
192 } // namespace linguistic
194 #endif
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */