Update ooo320-m1
[ooovba.git] / i18npool / source / isolang / inwnt.cxx
blob8fac0a922c8ffe15f83e426b790f8ae495d8de3c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: inwnt.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // no include "precompiled_i18npool.hxx" because this file is included in insys.cxx
33 #include <sal/config.h>
35 #ifdef _MSC_VER
36 #pragma warning(push,1) // disable warnings within system headers
37 #endif
38 #include <windef.h> // needed by winnls.h
39 #include <winbase.h> // needed by winnls.h
40 #include <winnls.h>
41 #ifdef _MSC_VER
42 #pragma warning(pop)
43 #endif
44 #include <rtl/instance.hxx>
45 #include "i18npool/mslangid.hxx"
47 static LanguageType nImplSystemLanguage = LANGUAGE_DONTKNOW;
48 static LanguageType nImplSystemUILanguage = LANGUAGE_DONTKNOW;
50 // =======================================================================
52 static LanguageType GetSVLang( LANGID nWinLangId )
54 // No Translation, we work with the original MS code without the SORT_ID.
55 // So we can get never LANG-ID's from MS, which are currently not defined
56 // by us.
57 return LanguageType( static_cast<sal_uInt16>(nWinLangId & 0xffff));
60 // -----------------------------------------------------------------------
62 typedef LANGID (WINAPI *getLangFromEnv)();
64 static void getPlatformSystemLanguageImpl( LanguageType& rSystemLanguage,
65 getLangFromEnv pGetUserDefault, getLangFromEnv pGetSystemDefault )
67 LanguageType nLang = rSystemLanguage;
68 if ( nLang == LANGUAGE_DONTKNOW )
70 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex());
71 nLang = rSystemLanguage;
72 if ( nLang == LANGUAGE_DONTKNOW )
74 LANGID nLangId;
76 nLangId = (pGetUserDefault)();
77 nLang = GetSVLang( nLangId );
79 if ( nLang == LANGUAGE_DONTKNOW )
81 nLangId = (pGetSystemDefault)();
82 nLang = GetSVLang( nLangId );
84 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
85 rSystemLanguage = nLang;
87 else
88 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
92 // -----------------------------------------------------------------------
94 LanguageType MsLangId::getPlatformSystemLanguage()
96 getPlatformSystemLanguageImpl( nImplSystemLanguage,
97 &GetUserDefaultLangID, &GetSystemDefaultLangID);
98 return nImplSystemLanguage;
101 // -----------------------------------------------------------------------
103 LanguageType MsLangId::getPlatformSystemUILanguage()
105 // TODO: this could be distinguished, #if(WINVER >= 0x0500)
106 // needs _run_ time differentiation though, not at compile time.
107 #if 0
108 getPlatformSystemLanguageImpl( nImplSystemUILanguage,
109 &GetUserDefaultUILanguage, &GetSystemDefaultUILanguage);
110 #endif
111 getPlatformSystemLanguageImpl( nImplSystemUILanguage,
112 &GetUserDefaultLangID, &GetSystemDefaultLangID);
113 return nImplSystemUILanguage;