1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
24 #pragma warning(push,1) // disable warnings within system headers
32 #include <rtl/instance.hxx>
33 #include "i18nlangtag/mslangid.hxx"
35 static LanguageType nImplSystemLanguage
= LANGUAGE_DONTKNOW
;
36 static LanguageType nImplSystemUILanguage
= LANGUAGE_DONTKNOW
;
38 // =======================================================================
40 static LanguageType
GetSVLang( LANGID nWinLangId
)
42 // No Translation, we work with the original MS code without the SORT_ID.
43 // So we can get never LANG-ID's from MS, which are currently not defined
45 return LanguageType( static_cast<sal_uInt16
>(nWinLangId
& 0xffff));
48 // -----------------------------------------------------------------------
50 typedef LANGID (WINAPI
*getLangFromEnv
)();
52 static void getPlatformSystemLanguageImpl( LanguageType
& rSystemLanguage
,
53 getLangFromEnv pGetUserDefault
, getLangFromEnv pGetSystemDefault
)
55 LanguageType nLang
= rSystemLanguage
;
56 if ( nLang
== LANGUAGE_DONTKNOW
)
58 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex());
59 nLang
= rSystemLanguage
;
60 if ( nLang
== LANGUAGE_DONTKNOW
)
64 nLangId
= (pGetUserDefault
)();
65 nLang
= GetSVLang( nLangId
);
67 if ( nLang
== LANGUAGE_DONTKNOW
)
69 nLangId
= (pGetSystemDefault
)();
70 nLang
= GetSVLang( nLangId
);
72 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
73 rSystemLanguage
= nLang
;
77 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
82 // -----------------------------------------------------------------------
84 LanguageType
MsLangId::getPlatformSystemLanguage()
86 getPlatformSystemLanguageImpl( nImplSystemLanguage
,
87 &GetUserDefaultLangID
, &GetSystemDefaultLangID
);
88 return nImplSystemLanguage
;
91 // -----------------------------------------------------------------------
93 LanguageType
MsLangId::getPlatformSystemUILanguage()
95 // TODO: this could be distinguished, #if(WINVER >= 0x0500)
96 // needs _run_ time differentiation though, not at compile time.
97 getPlatformSystemLanguageImpl( nImplSystemUILanguage
,
98 &GetUserDefaultUILanguage
, &GetSystemDefaultUILanguage
);
99 return nImplSystemUILanguage
;
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */