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 INCLUDED_UNOTOOLS_SYSLOCALE_HXX 25 #define INCLUDED_UNOTOOLS_SYSLOCALE_HXX 26 27 #include "unotools/unotoolsdllapi.h" 28 #include <unotools/localedatawrapper.hxx> 29 #include <unotools/charclass.hxx> 30 #include <sal/types.h> 31 #include <i18npool/lang.h> 32 #include <rtl/textenc.h> 33 34 class SvtSysLocale_Impl; 35 class SvtSysLocaleOptions; 36 37 namespace osl { class Mutex; } 38 class LocaleDataWrapper; 39 40 /** 41 SvtSysLocale provides a refcounted single instance of an application wide 42 <type>LocaleDataWrapper</type> and <type>CharClass</type> which always 43 follow the locale as it is currently configured by the user. You may use 44 it anywhere to access the locale data elements like decimal separator and 45 simple date formatting and so on. Contructing and destructing a 46 SvtSysLocale is not expensive as long as there is at least one instance 47 left. 48 */ 49 class UNOTOOLS_DLLPUBLIC SvtSysLocale 50 { 51 friend class SvtSysLocale_Impl; // access to mutex 52 53 static SvtSysLocale_Impl* pImpl; 54 static sal_Int32 nRefCount; 55 56 UNOTOOLS_DLLPRIVATE static ::osl::Mutex& GetMutex(); 57 58 public: 59 SvtSysLocale(); 60 ~SvtSysLocale(); 61 62 const LocaleDataWrapper& GetLocaleData() const; 63 const CharClass& GetCharClass() const; 64 65 /** It is safe to store the pointers locally and use them AS LONG AS THE 66 INSTANCE OF SvtSysLocale LIVES! 67 It is a faster access but be sure what you do! 68 */ 69 const LocaleDataWrapper* GetLocaleDataPtr() const; 70 const CharClass* GetCharClassPtr() const; 71 SvtSysLocaleOptions& GetOptions() const; 72 com::sun::star::lang::Locale GetLocale() const; 73 LanguageType GetLanguage() const; 74 com::sun::star::lang::Locale GetUILocale() const; 75 LanguageType GetUILanguage() const; 76 77 /** Get the best MIME encoding matching the system locale, or if that isn't 78 determinable one that matches the UI locale, or UTF8 if everything else 79 fails. 80 */ 81 static rtl_TextEncoding GetBestMimeEncoding(); 82 }; 83 84 #endif // INCLUDED_SVTOOLS_SYSLOCALE_HXX 85