Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / i18nlangtag / source / isolang / inwnt.cxx
blob76fe58b0491776085262fb1eeee99383e2089e53
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 #include <windef.h>
24 #include <winbase.h>
25 #include <winnls.h>
26 #include <osl/mutex.hxx>
27 #include <osl/doublecheckedlocking.h>
28 #include <i18nlangtag/mslangid.hxx>
30 static LanguageType nImplSystemLanguage = LANGUAGE_DONTKNOW;
31 static LanguageType nImplSystemUILanguage = LANGUAGE_DONTKNOW;
34 static LanguageType GetSVLang( LANGID nWinLangId )
36 // No Translation, we work with the original MS code without the SORT_ID.
37 // So we can get never LANG-ID's from MS, which are currently not defined
38 // by us.
39 return LanguageType( static_cast<sal_uInt16>(nWinLangId & 0xffff));
43 typedef LANGID (WINAPI *getLangFromEnv)();
45 static void getPlatformSystemLanguageImpl( LanguageType& rSystemLanguage,
46 getLangFromEnv pGetUserDefault, getLangFromEnv pGetSystemDefault )
48 LanguageType nLang = rSystemLanguage;
49 if ( nLang == LANGUAGE_DONTKNOW )
51 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex());
52 nLang = rSystemLanguage;
53 if ( nLang == LANGUAGE_DONTKNOW )
55 LANGID nLangId;
57 nLangId = pGetUserDefault();
58 nLang = GetSVLang( nLangId );
60 if ( nLang == LANGUAGE_DONTKNOW )
62 nLangId = pGetSystemDefault();
63 nLang = GetSVLang( nLangId );
65 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
66 rSystemLanguage = nLang;
68 else
70 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
76 LanguageType MsLangId::getPlatformSystemLanguage()
78 getPlatformSystemLanguageImpl( nImplSystemLanguage,
79 &GetUserDefaultLangID, &GetSystemDefaultLangID);
80 return nImplSystemLanguage;
84 LanguageType MsLangId::getPlatformSystemUILanguage()
86 // TODO: this could be distinguished, #if(WINVER >= 0x0500)
87 // needs _run_ time differentiation though, not at compile time.
88 getPlatformSystemLanguageImpl( nImplSystemUILanguage,
89 &GetUserDefaultUILanguage, &GetSystemDefaultUILanguage);
90 return nImplSystemUILanguage;
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */