LibreOffice Module i18nlangtag (master) 1
inwnt.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <sal/config.h>
22
23#include <windef.h>
24#include <winbase.h>
25#include <winnls.h>
26#include <osl/mutex.hxx>
27#include <osl/doublecheckedlocking.h>
29
32
33
34static LanguageType GetSVLang( LANGID nWinLangId )
35{
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));
40}
41
42
43typedef LANGID (WINAPI *getLangFromEnv)();
44
45static void getPlatformSystemLanguageImpl( LanguageType& rSystemLanguage,
46 getLangFromEnv pGetUserDefault, getLangFromEnv pGetSystemDefault )
47{
48 LanguageType nLang = rSystemLanguage;
49 if ( nLang == LANGUAGE_DONTKNOW )
50 {
51 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex());
52 nLang = rSystemLanguage;
53 if ( nLang == LANGUAGE_DONTKNOW )
54 {
55 LANGID nLangId;
56
57 nLangId = pGetUserDefault();
58 nLang = GetSVLang( nLangId );
59
60 if ( nLang == LANGUAGE_DONTKNOW )
61 {
62 nLangId = pGetSystemDefault();
63 nLang = GetSVLang( nLangId );
64 }
65 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
66 rSystemLanguage = nLang;
67 }
68 else
69 {
70 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
71 }
72 }
73}
74
75
77{
79 &GetUserDefaultLangID, &GetSystemDefaultLangID);
81}
82
83
85{
86 // TODO: this could be distinguished, #if(WINVER >= 0x0500)
87 // needs _run_ time differentiation though, not at compile time.
89 &GetUserDefaultUILanguage, &GetSystemDefaultUILanguage);
91}
92
93/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static LanguageType getPlatformSystemLanguage()
Definition: inunx.cxx:149
static LanguageType getPlatformSystemUILanguage()
Definition: inunx.cxx:156
static LanguageType GetSVLang(LANGID nWinLangId)
Definition: inwnt.cxx:34
LANGID(WINAPI * getLangFromEnv)()
Definition: inwnt.cxx:43
static void getPlatformSystemLanguageImpl(LanguageType &rSystemLanguage, getLangFromEnv pGetUserDefault, getLangFromEnv pGetSystemDefault)
Definition: inwnt.cxx:45
static LanguageType nImplSystemUILanguage
Definition: inwnt.cxx:31
static LanguageType nImplSystemLanguage
Definition: inwnt.cxx:30
o3tl::strong_int< sal_uInt16, struct LanguageTypeTag > LanguageType
These are MS LANGIDs, the lower 10 bits (mask 0x03ff, values below 0x0400 aren't real locale IDs) rep...
Definition: lang.h:87
#define LANGUAGE_DONTKNOW
Definition: lang.h:101