1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: misc.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _LINGUISTIC_MISC_HXX_
32 #define _LINGUISTIC_MISC_HXX_
35 #include <com/sun/star/uno/Sequence.h>
36 #include <com/sun/star/uno/Reference.h>
37 #include <com/sun/star/beans/PropertyValues.hpp>
38 #include <com/sun/star/frame/XTerminateListener.hpp>
39 #include <com/sun/star/lang/Locale.hpp>
40 #include <com/sun/star/lang/XComponent.hpp>
41 #include <com/sun/star/linguistic2/XDictionaryEntry.hpp>
42 #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
43 #include <com/sun/star/linguistic2/XHyphenatedWord.hpp>
45 #include <uno/lbnames.h> // CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
46 #include <cppuhelper/implbase1.hxx> // helper for implementations
47 #include <svtools/pathoptions.hxx>
48 #include <i18npool/lang.h>
49 #include <tools/string.hxx>
50 #include <unotools/charclass.hxx>
51 #include <osl/thread.h>
52 #include <osl/mutex.hxx>
53 #include <vcl/svapp.hxx>
55 namespace com
{ namespace sun
{ namespace star
{ namespace beans
{
57 class XFastPropertySet
;
60 namespace com
{ namespace sun
{ namespace star
{ namespace frame
{
64 class LocaleDataWrapper
;
66 ///////////////////////////////////////////////////////////////////////////
67 #define SN_GRAMMARCHECKER "com.sun.star.linguistic2.Proofreader"
68 #define SN_GRAMMARCHECKINGITERATOR "com.sun.star.linguistic2.ProofreadingIterator"
69 #define SN_SPELLCHECKER "com.sun.star.linguistic2.SpellChecker"
70 #define SN_HYPHENATOR "com.sun.star.linguistic2.Hyphenator"
71 #define SN_THESAURUS "com.sun.star.linguistic2.Thesaurus"
72 #define SN_LINGU_SERVCICE_MANAGER "com.sun.star.linguistic2.LinguServiceManager"
73 #define SN_LINGU_PROPERTIES "com.sun.star.linguistic2.LinguProperties"
74 #define SN_DICTIONARY_LIST "com.sun.star.linguistic2.DictionaryList"
75 #define SN_OTHER_LINGU "com.sun.star.linguistic2.OtherLingu"
76 #define SN_DESKTOP "com.sun.star.frame.Desktop"
82 // ascii to OUString conversion
83 #define A2OU(x) ::rtl::OUString::createFromAscii( x )
85 /// Flags to be used with the multi-path related functions
86 /// @see GetDictionaryPaths, GetLinguisticPaths
87 #define PATH_FLAG_INTERNAL 0x01
88 #define PATH_FLAG_USER 0x02
89 #define PATH_FLAG_WRITABLE 0x04
90 #define PATH_FLAG_ALL (PATH_FLAG_INTERNAL | PATH_FLAG_USER | PATH_FLAG_WRITABLE)
93 // AddEntryToDic return values
94 #define DIC_ERR_NONE 0
95 #define DIC_ERR_FULL 1
96 #define DIC_ERR_READONLY 2
97 #define DIC_ERR_UNKNOWN 3
98 #define DIC_ERR_NOT_EXISTS 4
100 ///////////////////////////////////////////////////////////////////////////
102 ::osl::Mutex
& GetLinguMutex();
104 LocaleDataWrapper
& GetLocaleDataWrapper( INT16 nLang
);
106 ///////////////////////////////////////////////////////////////////////////
108 rtl_TextEncoding
GetTextEncoding( INT16 nLanguage
);
110 inline ::rtl::OUString
BS2OU(const ByteString
&rText
, rtl_TextEncoding nEnc
)
112 return ::rtl::OUString( rText
.GetBuffer(), rText
.Len(), nEnc
);
115 inline ByteString
OU2BS(const ::rtl::OUString
&rText
, rtl_TextEncoding nEnc
)
117 return ByteString( rText
.getStr(), nEnc
);
120 rtl::OUString
StripTrailingChars( rtl::OUString
&rTxt
, sal_Unicode cChar
);
122 ///////////////////////////////////////////////////////////////////////////
124 sal_Int32
LevDistance( const rtl::OUString
&rTxt1
, const rtl::OUString
&rTxt2
);
126 ///////////////////////////////////////////////////////////////////////////
128 ::com::sun::star::lang::Locale
129 CreateLocale( LanguageType eLang
);
132 LocaleToLanguage( const ::com::sun::star::lang::Locale
& rLocale
);
134 ::com::sun::star::lang::Locale
&
135 LanguageToLocale( ::com::sun::star::lang::Locale
& rLocale
, LanguageType eLang
);
137 ::com::sun::star::uno::Sequence
< ::com::sun::star::lang::Locale
>
138 LangSeqToLocaleSeq( const ::com::sun::star::uno::Sequence
< INT16
> &rLangSeq
);
140 ::com::sun::star::uno::Sequence
< INT16
>
141 LocaleSeqToLangSeq( ::com::sun::star::uno::Sequence
<
142 ::com::sun::star::lang::Locale
> &rLocaleSeq
);
144 ///////////////////////////////////////////////////////////////////////////
146 // checks if file pointed to by rURL is readonly
147 // and may also check return if such a file exists or not
148 BOOL
IsReadOnly( const String
&rURL
, BOOL
*pbExist
= 0 );
150 // checks if a file with the given URL exists
151 BOOL
FileExists( const String
&rURL
);
154 // returns complete file URL for given filename that is to be searched in
155 // the specified path
156 String
GetFileURL( SvtPathOptions::Pathes ePath
, const String
&rFileName
);
158 String
GetModulePath( SvtPathOptions::Pathes ePath
, BOOL bAddAccessDelim
= TRUE
);
161 ///////////////////////////////////////////////////////////////////////////
163 ::rtl::OUString
GetDictionaryWriteablePath();
164 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> GetDictionaryPaths( sal_Int16 nPathFlags
= PATH_FLAG_ALL
);
165 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> GetLinguisticPaths( sal_Int16 nPathFlags
= PATH_FLAG_ALL
);
167 /// @returns an URL for a new and writable dictionary rDicName.
168 /// The URL will point to the path given by 'GetDictionaryWriteablePath'
169 String
GetWritableDictionaryURL( const String
&rDicName
);
171 // looks for the specified file in the list of paths.
172 // In case of multiple occurences only the first found is returned.
173 String
SearchFileInPaths( const String
&rFile
, const ::com::sun::star::uno::Sequence
< ::rtl::OUString
> &rPaths
);
176 ///////////////////////////////////////////////////////////////////////////
178 INT32
GetPosInWordToCheck( const rtl::OUString
&rTxt
, INT32 nPos
);
180 ::com::sun::star::uno::Reference
<
181 ::com::sun::star::linguistic2::XHyphenatedWord
>
182 RebuildHyphensAndControlChars( const rtl::OUString
&rOrigWord
,
183 ::com::sun::star::uno::Reference
<
184 ::com::sun::star::linguistic2::XHyphenatedWord
> &rxHyphWord
);
186 ///////////////////////////////////////////////////////////////////////////
188 BOOL
IsUpper( const String
&rText
, xub_StrLen nPos
, xub_StrLen nLen
, INT16 nLanguage
);
189 BOOL
IsLower( const String
&rText
, xub_StrLen nPos
, xub_StrLen nLen
, INT16 nLanguage
);
191 inline BOOL
IsUpper( const String
&rText
, INT16 nLanguage
) { return IsUpper( rText
, 0, rText
.Len(), nLanguage
); }
192 inline BOOL
IsLower( const String
&rText
, INT16 nLanguage
) { return IsLower( rText
, 0, rText
.Len(), nLanguage
); }
194 String
ToLower( const String
&rText
, INT16 nLanguage
);
195 String
ToUpper( const String
&rText
, INT16 nLanguage
);
196 String
ToTitle( const String
&rText
, INT16 nLanguage
);
197 sal_Unicode
ToLower( const sal_Unicode cChar
, INT16 nLanguage
);
198 sal_Unicode
ToUpper( const sal_Unicode cChar
, INT16 nLanguage
);
199 BOOL
HasDigits( const ::rtl::OUString
&rText
);
200 BOOL
IsNumeric( const String
&rText
);
202 ///////////////////////////////////////////////////////////////////////////
204 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> GetOneInstanceService( const char *pServiceName
);
205 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> GetLinguProperties();
206 ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XSearchableDictionaryList
> GetSearchableDictionaryList();
207 ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XDictionaryList
> GetDictionaryList();
208 ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XDictionary
> GetIgnoreAllList();
210 ///////////////////////////////////////////////////////////////////////////
212 BOOL
IsUseDicList( const ::com::sun::star::beans::PropertyValues
&rProperties
,
213 const ::com::sun::star::uno::Reference
<
214 ::com::sun::star::beans::XPropertySet
> &rxPropSet
);
216 BOOL
IsIgnoreControlChars( const ::com::sun::star::beans::PropertyValues
&rProperties
,
217 const ::com::sun::star::uno::Reference
<
218 ::com::sun::star::beans::XPropertySet
> &rxPropSet
);
220 ::com::sun::star::uno::Reference
<
221 ::com::sun::star::linguistic2::XDictionaryEntry
>
223 const ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XDictionaryList
>& rDicList
,
224 const ::rtl::OUString
& rWord
, INT16 nLanguage
,
225 BOOL bSearchPosDics
, BOOL bSearchSpellEntry
);
227 sal_uInt8
AddEntryToDic(
228 ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XDictionary
> &rxDic
,
229 const ::rtl::OUString
&rWord
, sal_Bool bIsNeg
,
230 const ::rtl::OUString
&rRplcTxt
, sal_Int16 nRplcLang
,
231 sal_Bool bStripDot
= sal_True
);
233 sal_Bool
SaveDictionaries( const ::com::sun::star::uno::Reference
< ::com::sun::star::linguistic2::XDictionaryList
> &xDicList
);
235 ///////////////////////////////////////////////////////////////////////////
238 // virtual base class that calls it AtExit function when the application
239 // (ie the Desktop) is about to terminate
242 class AppExitListener
:
243 public cppu::WeakImplHelper1
245 ::com::sun::star::frame::XTerminateListener
248 ::com::sun::star::uno::Reference
<
249 ::com::sun::star::frame::XDesktop
> xDesktop
;
253 virtual ~AppExitListener();
255 virtual void AtExit() = 0;
261 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw(::com::sun::star::uno::RuntimeException
);
263 // XTerminateListener
264 virtual void SAL_CALL
queryTermination( const ::com::sun::star::lang::EventObject
& aEvent
) throw(::com::sun::star::frame::TerminationVetoException
, ::com::sun::star::uno::RuntimeException
);
265 virtual void SAL_CALL
notifyTermination( const ::com::sun::star::lang::EventObject
& aEvent
) throw(::com::sun::star::uno::RuntimeException
);
268 ///////////////////////////////////////////////////////////////////////////
270 } // namespace linguistic