xref: /trunk/main/linguistic/inc/linguistic/misc.hxx (revision b63233d8)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _LINGUISTIC_MISC_HXX_
25 #define _LINGUISTIC_MISC_HXX_
26 
27 #include <com/sun/star/uno/Sequence.h>
28 #include <com/sun/star/uno/Reference.h>
29 #include <com/sun/star/beans/PropertyValues.hpp>
30 #include <com/sun/star/frame/XTerminateListener.hpp>
31 #include <com/sun/star/lang/Locale.hpp>
32 #include <com/sun/star/lang/XComponent.hpp>
33 #include <com/sun/star/linguistic2/XDictionaryEntry.hpp>
34 #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
35 #include <com/sun/star/linguistic2/XHyphenatedWord.hpp>
36 
37 #include <uno/lbnames.h>			// CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
38 #include <cppuhelper/implbase1.hxx>	// helper for implementations
39 #include <unotools/pathoptions.hxx>
40 #include <i18npool/lang.h>
41 #include <tools/string.hxx>
42 #include <unotools/charclass.hxx>
43 #include <osl/thread.h>
44 #include <osl/mutex.hxx>
45 #include <linguistic/lngdllapi.h>
46 
47 namespace com { namespace sun { namespace star { namespace beans {
48 	class XPropertySet;
49 	class XFastPropertySet;
50 }}}}
51 
52 namespace com { namespace sun { namespace star { namespace frame {
53 	class XDesktop;
54 }}}}
55 
56 class LocaleDataWrapper;
57 
58 ///////////////////////////////////////////////////////////////////////////
59 #define SN_GRAMMARCHECKER           "com.sun.star.linguistic2.Proofreader"
60 #define SN_GRAMMARCHECKINGITERATOR  "com.sun.star.linguistic2.ProofreadingIterator"
61 #define SN_SPELLCHECKER				"com.sun.star.linguistic2.SpellChecker"
62 #define SN_HYPHENATOR				"com.sun.star.linguistic2.Hyphenator"
63 #define SN_THESAURUS				"com.sun.star.linguistic2.Thesaurus"
64 #define SN_LINGU_SERVCICE_MANAGER	"com.sun.star.linguistic2.LinguServiceManager"
65 #define SN_LINGU_PROPERTIES			"com.sun.star.linguistic2.LinguProperties"
66 #define SN_DICTIONARY_LIST			"com.sun.star.linguistic2.DictionaryList"
67 #define SN_OTHER_LINGU				"com.sun.star.linguistic2.OtherLingu"
68 #define SN_DESKTOP					"com.sun.star.frame.Desktop"
69 
70 
71 namespace linguistic
72 {
73 
74 // ascii to OUString conversion
75 #define A2OU(x) ::rtl::OUString::createFromAscii( x )
76 
77 /// Flags to be used with the multi-path related functions
78 /// @see GetDictionaryPaths, GetLinguisticPaths
79 #define PATH_FLAG_INTERNAL  0x01
80 #define PATH_FLAG_USER      0x02
81 #define PATH_FLAG_WRITABLE  0x04
82 #define PATH_FLAG_ALL       (PATH_FLAG_INTERNAL | PATH_FLAG_USER | PATH_FLAG_WRITABLE)
83 
84 
85 // AddEntryToDic return values
86 #define DIC_ERR_NONE        0
87 #define DIC_ERR_FULL        1
88 #define DIC_ERR_READONLY    2
89 #define DIC_ERR_UNKNOWN     3
90 #define DIC_ERR_NOT_EXISTS  4
91 
92 ///////////////////////////////////////////////////////////////////////////
93 
94 LNG_DLLPUBLIC ::osl::Mutex& GetLinguMutex();
95 
96 LocaleDataWrapper & GetLocaleDataWrapper( sal_Int16 nLang );
97 
98 ///////////////////////////////////////////////////////////////////////////
99 
100 rtl_TextEncoding GetTextEncoding( sal_Int16 nLanguage );
101 
BS2OU(const ByteString & rText,rtl_TextEncoding nEnc)102 inline ::rtl::OUString BS2OU(const ByteString &rText, rtl_TextEncoding nEnc)
103 {
104     return ::rtl::OUString( rText.GetBuffer(), rText.Len(), nEnc );
105 }
106 
OU2BS(const::rtl::OUString & rText,rtl_TextEncoding nEnc)107 inline ByteString OU2BS(const ::rtl::OUString &rText, rtl_TextEncoding nEnc)
108 {
109     return ByteString( rText.getStr(), nEnc );
110 }
111 
112 rtl::OUString StripTrailingChars( rtl::OUString &rTxt, sal_Unicode cChar );
113 
114 ///////////////////////////////////////////////////////////////////////////
115 
116 sal_Int32 LevDistance( const rtl::OUString &rTxt1, const rtl::OUString &rTxt2 );
117 
118 ///////////////////////////////////////////////////////////////////////////
119 
120 ::com::sun::star::lang::Locale
121 	CreateLocale( LanguageType eLang );
122 
123 LNG_DLLPUBLIC LanguageType
124  	LocaleToLanguage( const ::com::sun::star::lang::Locale& rLocale );
125 
126 ::com::sun::star::lang::Locale&
127 	LanguageToLocale( ::com::sun::star::lang::Locale& rLocale, LanguageType eLang );
128 
129 ::com::sun::star::uno::Sequence< ::com::sun::star::lang::Locale >
130     LangSeqToLocaleSeq( const ::com::sun::star::uno::Sequence< sal_Int16 > &rLangSeq );
131 
132 ::com::sun::star::uno::Sequence< sal_Int16 >
133     LocaleSeqToLangSeq( ::com::sun::star::uno::Sequence<
134         ::com::sun::star::lang::Locale > &rLocaleSeq );
135 
136 ///////////////////////////////////////////////////////////////////////////
137 
138 // checks if file pointed to by rURL is readonly
139 // and may also check return if such a file exists or not
140 sal_Bool    IsReadOnly( const String &rURL, sal_Bool *pbExist = 0 );
141 
142 // checks if a file with the given URL exists
143 sal_Bool    FileExists( const String &rURL );
144 
145 #ifdef TL_OUTDATED
146 // returns complete file URL for given filename that is to be searched in
147 // the specified path
148 String  GetFileURL( SvtPathOptions::Pathes ePath, const String &rFileName );
149 
150 String  GetModulePath( SvtPathOptions::Pathes ePath, sal_Bool bAddAccessDelim = sal_True );
151 #endif
152 
153 ///////////////////////////////////////////////////////////////////////////
154 
155 ::rtl::OUString     GetDictionaryWriteablePath();
156 ::com::sun::star::uno::Sequence< ::rtl::OUString > GetDictionaryPaths( sal_Int16 nPathFlags = PATH_FLAG_ALL );
157 ::com::sun::star::uno::Sequence< ::rtl::OUString > GetLinguisticPaths( sal_Int16 nPathFlags = PATH_FLAG_ALL );
158 
159 /// @returns an URL for a new and writable dictionary rDicName.
160 ///     The URL will point to the path given by 'GetDictionaryWriteablePath'
161 LNG_DLLPUBLIC String  GetWritableDictionaryURL( const String &rDicName );
162 
163 // looks for the specified file in the list of paths.
164 // In case of multiple occurrences only the first found is returned.
165 String     SearchFileInPaths( const String &rFile, const ::com::sun::star::uno::Sequence< ::rtl::OUString > &rPaths );
166 
167 
168 ///////////////////////////////////////////////////////////////////////////
169 
170 LNG_DLLPUBLIC sal_Int32 GetPosInWordToCheck( const rtl::OUString &rTxt, sal_Int32 nPos );
171 
172 ::com::sun::star::uno::Reference<
173 	::com::sun::star::linguistic2::XHyphenatedWord >
174 			RebuildHyphensAndControlChars( const rtl::OUString &rOrigWord,
175 				::com::sun::star::uno::Reference<
176 					::com::sun::star::linguistic2::XHyphenatedWord > &rxHyphWord );
177 
178 ///////////////////////////////////////////////////////////////////////////
179 
180 LNG_DLLPUBLIC sal_Bool        IsUpper( const String &rText, xub_StrLen nPos, xub_StrLen nLen, sal_Int16 nLanguage );
181 LNG_DLLPUBLIC sal_Bool        IsLower( const String &rText, xub_StrLen nPos, xub_StrLen nLen, sal_Int16 nLanguage );
182 
IsUpper(const String & rText,sal_Int16 nLanguage)183 inline sal_Bool        IsUpper( const String &rText, sal_Int16 nLanguage )     { return IsUpper( rText, 0, rText.Len(), nLanguage ); }
IsLower(const String & rText,sal_Int16 nLanguage)184 inline sal_Bool        IsLower( const String &rText, sal_Int16 nLanguage )     { return IsLower( rText, 0, rText.Len(), nLanguage ); }
185 
186 String      ToLower( const String &rText, sal_Int16 nLanguage );
187 String      ToUpper( const String &rText, sal_Int16 nLanguage );
188 String      ToTitle( const String &rText, sal_Int16 nLanguage );
189 sal_Unicode	ToLower( const sal_Unicode cChar, sal_Int16 nLanguage );
190 sal_Unicode	ToUpper( const sal_Unicode cChar, sal_Int16 nLanguage );
191 LNG_DLLPUBLIC sal_Bool		HasDigits( const ::rtl::OUString &rText );
192 LNG_DLLPUBLIC sal_Bool		IsNumeric( const String &rText );
193 
194 ///////////////////////////////////////////////////////////////////////////
195 
196 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > GetOneInstanceService( const char *pServiceName );
197 LNG_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > GetLinguProperties();
198 ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XSearchableDictionaryList > GetSearchableDictionaryList();
199 ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XDictionaryList > GetDictionaryList();
200 ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XDictionary > GetIgnoreAllList();
201 
202 ///////////////////////////////////////////////////////////////////////////
203 
204 sal_Bool IsUseDicList( const ::com::sun::star::beans::PropertyValues &rProperties,
205 		const ::com::sun::star::uno::Reference<
206 			::com::sun::star::beans::XPropertySet > &rxPropSet );
207 
208 sal_Bool IsIgnoreControlChars( const ::com::sun::star::beans::PropertyValues &rProperties,
209 		const ::com::sun::star::uno::Reference<
210 			::com::sun::star::beans::XPropertySet > &rxPropSet );
211 
212 ::com::sun::star::uno::Reference<
213 	::com::sun::star::linguistic2::XDictionaryEntry >
214 		SearchDicList(
215             const ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XDictionaryList >& rDicList,
216 			const ::rtl::OUString& rWord, sal_Int16 nLanguage,
217 			sal_Bool bSearchPosDics, sal_Bool bSearchSpellEntry );
218 
219 LNG_DLLPUBLIC sal_uInt8 AddEntryToDic(
220     ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XDictionary >  &rxDic,
221     const ::rtl::OUString &rWord, sal_Bool bIsNeg,
222     const ::rtl::OUString &rRplcTxt, sal_Int16 nRplcLang,
223     sal_Bool bStripDot = sal_True );
224 
225 LNG_DLLPUBLIC sal_Bool SaveDictionaries( const ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XDictionaryList > &xDicList );
226 
227 ///////////////////////////////////////////////////////////////////////////
228 //
229 // AppExitLstnr:
230 // virtual base class that calls it AtExit function when the application
231 // (ie the Desktop) is about to terminate
232 //
233 
234 class AppExitListener :
235 	public cppu::WeakImplHelper1
236 	<
237 		::com::sun::star::frame::XTerminateListener
238 	>
239 {
240 	::com::sun::star::uno::Reference<
241 		::com::sun::star::frame::XDesktop >		xDesktop;
242 
243 public:
244 	AppExitListener();
245 	virtual ~AppExitListener();
246 
247 	virtual	void	AtExit() = 0;
248 
249 	void			Activate();
250 	void			Deactivate();
251 
252 	// XEventListener
253     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
254 
255     // XTerminateListener
256     virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& aEvent ) throw(::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException);
257     virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& aEvent ) throw(::com::sun::star::uno::RuntimeException);
258 };
259 
260 ///////////////////////////////////////////////////////////////////////////
261 
262 }	// namespace linguistic
263 
264 #endif
265 
266