Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / i18npool / source / isolang / inwnt.cxx
blob07661bdc1ce0c545b3a24ecb551dc41f400496ae
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <sal/config.h>
23 #define WINVER 0x0500
25 #ifdef _MSC_VER
26 #pragma warning(push,1) // disable warnings within system headers
27 #endif
28 #include <windef.h> // needed by winnls.h
29 #include <winbase.h> // needed by winnls.h
30 #include <winnls.h>
31 #ifdef _MSC_VER
32 #pragma warning(pop)
33 #endif
34 #include <rtl/instance.hxx>
35 #include "i18npool/mslangid.hxx"
37 static LanguageType nImplSystemLanguage = LANGUAGE_DONTKNOW;
38 static LanguageType nImplSystemUILanguage = LANGUAGE_DONTKNOW;
40 // =======================================================================
42 static LanguageType GetSVLang( LANGID nWinLangId )
44 // No Translation, we work with the original MS code without the SORT_ID.
45 // So we can get never LANG-ID's from MS, which are currently not defined
46 // by us.
47 return LanguageType( static_cast<sal_uInt16>(nWinLangId & 0xffff));
50 // -----------------------------------------------------------------------
52 typedef LANGID (WINAPI *getLangFromEnv)();
54 static void getPlatformSystemLanguageImpl( LanguageType& rSystemLanguage,
55 getLangFromEnv pGetUserDefault, getLangFromEnv pGetSystemDefault )
57 LanguageType nLang = rSystemLanguage;
58 if ( nLang == LANGUAGE_DONTKNOW )
60 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex());
61 nLang = rSystemLanguage;
62 if ( nLang == LANGUAGE_DONTKNOW )
64 LANGID nLangId;
66 nLangId = (pGetUserDefault)();
67 nLang = GetSVLang( nLangId );
69 if ( nLang == LANGUAGE_DONTKNOW )
71 nLangId = (pGetSystemDefault)();
72 nLang = GetSVLang( nLangId );
74 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
75 rSystemLanguage = nLang;
77 else
79 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
84 // -----------------------------------------------------------------------
86 LanguageType MsLangId::getPlatformSystemLanguage()
88 getPlatformSystemLanguageImpl( nImplSystemLanguage,
89 &GetUserDefaultLangID, &GetSystemDefaultLangID);
90 return nImplSystemLanguage;
93 // -----------------------------------------------------------------------
95 LanguageType MsLangId::getPlatformSystemUILanguage()
97 // TODO: this could be distinguished, #if(WINVER >= 0x0500)
98 // needs _run_ time differentiation though, not at compile time.
99 getPlatformSystemLanguageImpl( nImplSystemUILanguage,
100 &GetUserDefaultUILanguage, &GetSystemDefaultUILanguage);
101 return nImplSystemUILanguage;
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */