1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <sal/config.h>
35 #pragma warning(push,1) // disable warnings within system headers
37 #include <windef.h> // needed by winnls.h
38 #include <winbase.h> // needed by winnls.h
43 #include <rtl/instance.hxx>
44 #include "i18npool/mslangid.hxx"
46 static LanguageType nImplSystemLanguage
= LANGUAGE_DONTKNOW
;
47 static LanguageType nImplSystemUILanguage
= LANGUAGE_DONTKNOW
;
49 // =======================================================================
51 static LanguageType
GetSVLang( LANGID nWinLangId
)
53 // No Translation, we work with the original MS code without the SORT_ID.
54 // So we can get never LANG-ID's from MS, which are currently not defined
56 return LanguageType( static_cast<sal_uInt16
>(nWinLangId
& 0xffff));
59 // -----------------------------------------------------------------------
61 typedef LANGID (WINAPI
*getLangFromEnv
)();
63 static void getPlatformSystemLanguageImpl( LanguageType
& rSystemLanguage
,
64 getLangFromEnv pGetUserDefault
, getLangFromEnv pGetSystemDefault
)
66 LanguageType nLang
= rSystemLanguage
;
67 if ( nLang
== LANGUAGE_DONTKNOW
)
69 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex());
70 nLang
= rSystemLanguage
;
71 if ( nLang
== LANGUAGE_DONTKNOW
)
75 nLangId
= (pGetUserDefault
)();
76 nLang
= GetSVLang( nLangId
);
78 if ( nLang
== LANGUAGE_DONTKNOW
)
80 nLangId
= (pGetSystemDefault
)();
81 nLang
= GetSVLang( nLangId
);
83 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
84 rSystemLanguage
= nLang
;
88 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
93 // -----------------------------------------------------------------------
95 LanguageType
MsLangId::getPlatformSystemLanguage()
97 getPlatformSystemLanguageImpl( nImplSystemLanguage
,
98 &GetUserDefaultLangID
, &GetSystemDefaultLangID
);
99 return nImplSystemLanguage
;
102 // -----------------------------------------------------------------------
104 LanguageType
MsLangId::getPlatformSystemUILanguage()
106 // TODO: this could be distinguished, #if(WINVER >= 0x0500)
107 // needs _run_ time differentiation though, not at compile time.
108 getPlatformSystemLanguageImpl( nImplSystemUILanguage
,
109 &GetUserDefaultUILanguage
, &GetSystemDefaultUILanguage
);
110 return nImplSystemUILanguage
;
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */