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>
28 #include <com/sun/star/lang/XComponent.hpp>
29 #include <com/sun/star/linguistic2/XDictionaryEntry.hpp>
30 #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
31 #include <com/sun/star/linguistic2/XHyphenatedWord.hpp>
32 #include <com/sun/star/linguistic2/XLinguProperties.hpp>
34 #include <cppuhelper/implbase1.hxx>
35 #include <unotools/pathoptions.hxx>
36 #include <i18nlangtag/lang.h>
37 #include <rtl/ustring.hxx>
38 #include <unotools/charclass.hxx>
39 #include <osl/thread.h>
40 #include <osl/mutex.hxx>
41 #include <linguistic/lngdllapi.h>
43 namespace com
{ namespace sun
{ namespace star
{ namespace beans
{
45 class XFastPropertySet
;
48 namespace com
{ namespace sun
{ namespace star
{ namespace frame
{
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 asigned to capitalization types
81 LNG_DLLPUBLIC ::osl::Mutex
& GetLinguMutex();
83 LocaleDataWrapper
& GetLocaleDataWrapper( sal_Int16 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 ::com::sun::star::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 ::com::sun::star::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 ::com::sun::star::uno::Sequence
< sal_Int16
>
110 LocaleSeqToLangSeq( ::com::sun::star::uno::Sequence
<
111 ::com::sun::star::lang::Locale
> &rLocaleSeq
);
113 // checks if file pointed to by rURL is readonly
114 // and may also check return if such a file exists or not
115 bool IsReadOnly( const OUString
&rURL
, bool *pbExist
= 0 );
117 // checks if a file with the given URL exists
118 bool FileExists( const OUString
&rURL
);
121 OUString
GetDictionaryWriteablePath();
122 ::com::sun::star::uno::Sequence
< OUString
> GetDictionaryPaths();
124 /// @returns an URL for a new and writable dictionary rDicName.
125 /// The URL will point to the path given by 'GetDictionaryWriteablePath'
126 LNG_DLLPUBLIC OUString
GetWritableDictionaryURL( const OUString
&rDicName
);
128 LNG_DLLPUBLIC sal_Int32
GetPosInWordToCheck( const OUString
&rTxt
, sal_Int32 nPos
);
130 ::com::sun::star::uno::Reference
<
131 ::com::sun::star::linguistic2::XHyphenatedWord
>
132 RebuildHyphensAndControlChars( const OUString
&rOrigWord
,
133 ::com::sun::star::uno::Reference
<
134 ::com::sun::star::linguistic2::XHyphenatedWord
> &rxHyphWord
);
137 LNG_DLLPUBLIC
bool IsUpper( const OUString
&rText
, sal_Int32 nPos
, sal_Int32 nLen
, sal_Int16 nLanguage
);
139 inline bool IsUpper( const OUString
&rText
, sal_Int16 nLanguage
) { return IsUpper( rText
, 0, rText
.getLength(), nLanguage
); }
140 LNG_DLLPUBLIC CapType SAL_CALL
capitalType(const OUString
&, CharClass
*);
142 OUString
ToLower( const OUString
&rText
, sal_Int16 nLanguage
);
143 LNG_DLLPUBLIC
bool HasDigits( const OUString
&rText
);
144 LNG_DLLPUBLIC
bool IsNumeric( const OUString
&rText
);
147 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> GetOneInstanceService( const char *pServiceName
);
148 LNG_DLLPUBLIC ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XLinguProperties
> GetLinguProperties();
149 ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XSearchableDictionaryList
> GetDictionaryList();
150 ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XDictionary
> GetIgnoreAllList();
153 bool IsUseDicList( const ::com::sun::star::beans::PropertyValues
&rProperties
,
154 const ::com::sun::star::uno::Reference
<
155 ::com::sun::star::beans::XPropertySet
> &rxPropSet
);
157 bool IsIgnoreControlChars( const ::com::sun::star::beans::PropertyValues
&rProperties
,
158 const ::com::sun::star::uno::Reference
<
159 ::com::sun::star::beans::XPropertySet
> &rxPropSet
);
161 ::com::sun::star::uno::Reference
<
162 ::com::sun::star::linguistic2::XDictionaryEntry
>
164 const ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XSearchableDictionaryList
>& rDicList
,
165 const OUString
& rWord
, sal_Int16 nLanguage
,
166 bool bSearchPosDics
, bool bSearchSpellEntry
);
168 LNG_DLLPUBLIC DictionaryError
AddEntryToDic(
169 ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XDictionary
> &rxDic
,
170 const OUString
&rWord
, bool bIsNeg
,
171 const OUString
&rRplcTxt
, sal_Int16 nRplcLang
,
172 bool bStripDot
= true );
174 LNG_DLLPUBLIC
bool SaveDictionaries( const ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XSearchableDictionaryList
> &xDicList
);
177 // virtual base class that calls it AtExit function when the application
178 // (ie the Desktop) is about to terminate
180 class AppExitListener
:
181 public cppu::WeakImplHelper1
183 ::com::sun::star::frame::XTerminateListener
186 ::com::sun::star::uno::Reference
<
187 ::com::sun::star::frame::XDesktop2
> xDesktop
;
191 virtual ~AppExitListener();
193 virtual void AtExit() = 0;
199 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
201 // XTerminateListener
202 virtual void SAL_CALL
queryTermination( const ::com::sun::star::lang::EventObject
& aEvent
) throw(::com::sun::star::frame::TerminationVetoException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
203 virtual void SAL_CALL
notifyTermination( const ::com::sun::star::lang::EventObject
& aEvent
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
206 } // namespace linguistic
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */