Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_LINGUISTIC_MISC_HXX
21 : #define INCLUDED_LINGUISTIC_MISC_HXX
22 :
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>
33 :
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>
42 :
43 : namespace com { namespace sun { namespace star { namespace beans {
44 : class XPropertySet;
45 : class XFastPropertySet;
46 : }}}}
47 :
48 : namespace com { namespace sun { namespace star { namespace frame {
49 : class XDesktop2;
50 : }}}}
51 :
52 : class LocaleDataWrapper;
53 :
54 :
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"
59 :
60 :
61 : namespace linguistic
62 : {
63 :
64 :
65 : // AddEntryToDic return values
66 : enum class DictionaryError
67 : {
68 : NONE, FULL, READONLY, UNKNOWN, NOT_EXISTS
69 : };
70 :
71 : // values asigned to capitalization types
72 : enum class CapType
73 : {
74 : UNKNOWN,
75 : NOCAP,
76 : INITCAP,
77 : ALLCAP,
78 : MIXED
79 : };
80 :
81 : LNG_DLLPUBLIC ::osl::Mutex& GetLinguMutex();
82 :
83 : LocaleDataWrapper & GetLocaleDataWrapper( sal_Int16 nLang );
84 :
85 : sal_Int32 LevDistance( const OUString &rTxt1, const OUString &rTxt2 );
86 :
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.
90 : */
91 : LNG_DLLPUBLIC LanguageType LinguLocaleToLanguage( const ::com::sun::star::lang::Locale& rLocale );
92 :
93 : /** Convert LanguageType to Locale for legacy handling.
94 : Linguistic specific handling of LANGUAGE_NONE resulting in an empty locale.
95 : Avoid use!
96 : */
97 : LNG_DLLPUBLIC ::com::sun::star::lang::Locale LinguLanguageToLocale( LanguageType nLanguage );
98 :
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.
102 : */
103 : LNG_DLLPUBLIC bool LinguIsUnspecified( LanguageType nLanguage );
104 :
105 : /** The same as LinguIsUnspecified(LanguageType) but taking a BCP 47 language
106 : tag string instead. */
107 : LNG_DLLPUBLIC bool LinguIsUnspecified( const OUString & rBcp47 );
108 :
109 : ::com::sun::star::uno::Sequence< sal_Int16 >
110 : LocaleSeqToLangSeq( ::com::sun::star::uno::Sequence<
111 : ::com::sun::star::lang::Locale > &rLocaleSeq );
112 :
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 );
116 :
117 : // checks if a file with the given URL exists
118 : bool FileExists( const OUString &rURL );
119 :
120 :
121 : OUString GetDictionaryWriteablePath();
122 : ::com::sun::star::uno::Sequence< OUString > GetDictionaryPaths();
123 :
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 );
127 :
128 : LNG_DLLPUBLIC sal_Int32 GetPosInWordToCheck( const OUString &rTxt, sal_Int32 nPos );
129 :
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 );
135 :
136 :
137 : LNG_DLLPUBLIC bool IsUpper( const OUString &rText, sal_Int32 nPos, sal_Int32 nLen, sal_Int16 nLanguage );
138 :
139 0 : 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 *);
141 :
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 );
145 :
146 :
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();
151 :
152 :
153 : bool IsUseDicList( const ::com::sun::star::beans::PropertyValues &rProperties,
154 : const ::com::sun::star::uno::Reference<
155 : ::com::sun::star::beans::XPropertySet > &rxPropSet );
156 :
157 : bool IsIgnoreControlChars( const ::com::sun::star::beans::PropertyValues &rProperties,
158 : const ::com::sun::star::uno::Reference<
159 : ::com::sun::star::beans::XPropertySet > &rxPropSet );
160 :
161 : ::com::sun::star::uno::Reference<
162 : ::com::sun::star::linguistic2::XDictionaryEntry >
163 : SearchDicList(
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 );
167 :
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 );
173 :
174 : LNG_DLLPUBLIC bool SaveDictionaries( const ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XSearchableDictionaryList > &xDicList );
175 :
176 : // AppExitLstnr:
177 : // virtual base class that calls it AtExit function when the application
178 : // (ie the Desktop) is about to terminate
179 :
180 : class AppExitListener :
181 : public cppu::WeakImplHelper1
182 : <
183 : ::com::sun::star::frame::XTerminateListener
184 : >
185 : {
186 : ::com::sun::star::uno::Reference<
187 : ::com::sun::star::frame::XDesktop2 > xDesktop;
188 :
189 : public:
190 : AppExitListener();
191 : virtual ~AppExitListener();
192 :
193 : virtual void AtExit() = 0;
194 :
195 : void Activate();
196 : void Deactivate();
197 :
198 : // XEventListener
199 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
200 :
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;
204 : };
205 :
206 : } // namespace linguistic
207 :
208 : #endif
209 :
210 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|