fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svtools / source / misc / langtab.cxx
blobb83443d2754efd0e19647ab5380c378d9bb53c1f
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 .
20 #include <boost/static_assert.hpp>
22 #include <tools/shl.hxx>
24 #include <com/sun/star/i18n/DirectionProperty.hpp>
26 #include <i18nlangtag/lang.h>
27 #include <i18nlangtag/mslangid.hxx>
28 #include <i18nlangtag/languagetag.hxx>
30 #include <svtools/svtools.hrc>
31 #include <svtools/svtresid.hxx>
32 #include <svtools/langtab.hxx>
33 #include <unotools/syslocale.hxx>
36 using namespace ::com::sun::star;
38 //------------------------------------------------------------------------
40 SVT_DLLPUBLIC const String ApplyLreOrRleEmbedding( const String &rText )
42 const sal_uInt16 nLen = rText.Len();
43 if (nLen == 0)
44 return String();
46 const sal_Unicode cLRE_Embedding = 0x202A; // the start char of an LRE embedding
47 const sal_Unicode cRLE_Embedding = 0x202B; // the start char of an RLE embedding
48 const sal_Unicode cPopDirectionalFormat = 0x202C; // the unicode PDF (POP_DIRECTIONAL_FORMAT) char that terminates an LRE/RLE embedding
50 // check if there are alreay embedding characters at the strings start
51 // if so change nothing
52 const sal_Unicode cChar = rText.GetBuffer()[0];
53 if (cChar == cLRE_Embedding || cChar == cRLE_Embedding)
54 return rText;
56 // since we only call the function getCharacterDirection
57 // it does not matter which locale the CharClass is for.
58 // Thus we can readily make use of SvtSysLocale::GetCharClass()
59 // which should come at no cost...
60 SvtSysLocale aSysLocale;
61 const CharClass &rCharClass = aSysLocale.GetCharClass();
63 // we should look for the first non-neutral LTR or RTL character
64 // and use that to determine the embedding of the whole text...
65 // Thus we can avoid to check every character of the text.
66 bool bFound = false;
67 bool bIsRtlText = false;
68 for (sal_uInt16 i = 0; i < nLen && !bFound; ++i)
70 sal_Int16 nDirection = rCharClass.getCharacterDirection( rText, i );
71 switch (nDirection)
73 case i18n::DirectionProperty_LEFT_TO_RIGHT :
74 case i18n::DirectionProperty_LEFT_TO_RIGHT_EMBEDDING :
75 case i18n::DirectionProperty_LEFT_TO_RIGHT_OVERRIDE :
76 case i18n::DirectionProperty_EUROPEAN_NUMBER :
77 case i18n::DirectionProperty_ARABIC_NUMBER : // yes! arabic numbers are written from left to right
79 bIsRtlText = false;
80 bFound = true;
81 break;
84 case i18n::DirectionProperty_RIGHT_TO_LEFT :
85 case i18n::DirectionProperty_RIGHT_TO_LEFT_ARABIC :
86 case i18n::DirectionProperty_RIGHT_TO_LEFT_EMBEDDING :
87 case i18n::DirectionProperty_RIGHT_TO_LEFT_OVERRIDE :
89 bIsRtlText = true;
90 bFound = true;
91 break;
94 default:
96 // nothing to be done, character is considered to be neutral we need to look further ...
101 sal_Unicode cStart = cLRE_Embedding; // default is to use LRE embedding characters
102 if (bIsRtlText)
103 cStart = cRLE_Embedding; // then use RLE embedding
105 // add embedding start and end chars to the text if the direction could be determined
106 String aRes( rText );
107 if (bFound)
109 aRes.Insert( cStart, 0 );
110 aRes.Insert( cPopDirectionalFormat );
113 return aRes;
116 //------------------------------------------------------------------------
118 namespace {
119 BOOST_STATIC_ASSERT(
120 16642 == STR_ARR_SVT_LANGUAGE_TABLE);
121 // "The value of STR_ARR_SVT_LANGUAGE_TABLE has changed. wizards/com/sun/star/wizards/letter/LocaleCodes.java has this value hard coded, please adapt it to your change."
124 SvtLanguageTable::SvtLanguageTable() :
125 ResStringArray( SvtResId( STR_ARR_SVT_LANGUAGE_TABLE ) )
129 //------------------------------------------------------------------------
131 SvtLanguageTable::~SvtLanguageTable()
135 //------------------------------------------------------------------------
137 const OUString SvtLanguageTable::GetString( const LanguageType eType, bool bUserInterfaceSelection ) const
139 LanguageType eLang = MsLangId::getReplacementForObsoleteLanguage( eType, bUserInterfaceSelection);
140 sal_uInt32 nPos = FindIndex( eLang );
142 if ( RESARRAY_INDEX_NOTFOUND != nPos && nPos < Count() )
143 return ResStringArray::GetString( nPos );
145 //Rather than return a fairly useless "Unknown" name, return a geeky but usable-in-a-pinch lang-tag
146 OUString sLangTag(LanguageTag(eType).getBcp47());
147 SAL_WARN("svtools.misc", "Language: 0x"
148 << std::hex << eType
149 << " with unknown name, so returning lang-tag of: "
150 << sLangTag);
151 return sLangTag;
154 String SvtLanguageTable::GetLanguageString( const LanguageType eType )
156 static const SvtLanguageTable aLangTable;
157 return aLangTable.GetString( eType );
160 //------------------------------------------------------------------------
162 LanguageType SvtLanguageTable::GetType( const String& rStr ) const
164 LanguageType eType = LANGUAGE_DONTKNOW;
165 sal_uInt32 nCount = Count();
167 for ( sal_uInt32 i = 0; i < nCount; ++i )
169 if (ResStringArray::GetString( i ).equals(rStr))
171 eType = LanguageType( GetValue( i ) );
172 break;
175 return eType;
178 //------------------------------------------------------------------------
180 sal_uInt32 SvtLanguageTable::GetEntryCount() const
182 return Count();
185 //------------------------------------------------------------------------
187 LanguageType SvtLanguageTable::GetTypeAtIndex( sal_uInt32 nIndex ) const
189 LanguageType nType = LANGUAGE_DONTKNOW;
190 if (nIndex < Count())
191 nType = LanguageType( GetValue( nIndex ) );
192 return nType;
195 //------------------------------------------------------------------------
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */