LCOV - code coverage report
Current view: top level - svl/source/config - languageoptions.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 36 118 30.5 %
Date: 2015-06-13 12:38:46 Functions: 9 28 32.1 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <svl/languageoptions.hxx>
      22             : #include <svl/cjkoptions.hxx>
      23             : #include <svl/ctloptions.hxx>
      24             : #include <i18nlangtag/mslangid.hxx>
      25             : #include <i18nlangtag/languagetag.hxx>
      26             : #include <osl/mutex.hxx>
      27             : #include <rtl/instance.hxx>
      28             : #include <com/sun/star/i18n/ScriptType.hpp>
      29             : #include <unotools/syslocale.hxx>
      30             : 
      31             : #ifdef WNT
      32             : #include <windows.h>
      33             : #endif
      34             : 
      35             : using namespace ::com::sun::star;
      36             : // global
      37             : 
      38             : namespace { struct ALMutex : public rtl::Static< ::osl::Mutex, ALMutex > {}; }
      39             : 
      40       20201 : SvtLanguageOptions::SvtLanguageOptions( bool _bDontLoad )
      41             : {
      42             :     // Global access, must be guarded (multithreading)
      43       20201 :     ::osl::MutexGuard aGuard( ALMutex::get() );
      44             : 
      45       20201 :     m_pCJKOptions = new SvtCJKOptions( _bDontLoad );
      46       20201 :     m_pCTLOptions = new SvtCTLOptions( _bDontLoad );
      47       20201 :     m_pCTLOptions->AddListener(this);
      48       20201 :     m_pCJKOptions->AddListener(this);
      49       20201 : }
      50       40518 : SvtLanguageOptions::~SvtLanguageOptions()
      51             : {
      52             :     // Global access, must be guarded (multithreading)
      53       20201 :     ::osl::MutexGuard aGuard( ALMutex::get() );
      54             : 
      55       20201 :     m_pCTLOptions->RemoveListener(this);
      56       20201 :     m_pCJKOptions->RemoveListener(this);
      57             : 
      58       20201 :     delete m_pCJKOptions;
      59       20201 :     delete m_pCTLOptions;
      60       20317 : }
      61             : // CJK options
      62           0 : bool SvtLanguageOptions::IsCJKFontEnabled() const
      63             : {
      64           0 :     return m_pCJKOptions->IsCJKFontEnabled();
      65             : }
      66        8654 : bool SvtLanguageOptions::IsVerticalTextEnabled() const
      67             : {
      68        8654 :     return m_pCJKOptions->IsVerticalTextEnabled();
      69             : }
      70           0 : bool SvtLanguageOptions::IsAsianTypographyEnabled() const
      71             : {
      72           0 :     return m_pCJKOptions->IsAsianTypographyEnabled();
      73             : }
      74           0 : bool SvtLanguageOptions::IsJapaneseFindEnabled() const
      75             : {
      76           0 :     return m_pCJKOptions->IsJapaneseFindEnabled();
      77             : }
      78           0 : void SvtLanguageOptions::SetAll( bool _bSet )
      79             : {
      80           0 :     m_pCJKOptions->SetAll( _bSet );
      81           0 : }
      82           0 : bool SvtLanguageOptions::IsAnyEnabled() const
      83             : {
      84           0 :     return m_pCJKOptions->IsAnyEnabled();
      85             : }
      86             : // CTL options
      87           0 : void SvtLanguageOptions::SetCTLFontEnabled( bool _bEnabled )
      88             : {
      89           0 :     m_pCTLOptions->SetCTLFontEnabled( _bEnabled );
      90           0 : }
      91        8722 : bool SvtLanguageOptions::IsCTLFontEnabled() const
      92             : {
      93        8722 :     return m_pCTLOptions->IsCTLFontEnabled();
      94             : }
      95           0 : void SvtLanguageOptions::SetCTLSequenceChecking( bool _bEnabled )
      96             : {
      97           0 :     m_pCTLOptions->SetCTLSequenceChecking( _bEnabled );
      98           0 : }
      99             : 
     100           0 : void SvtLanguageOptions::SetCTLSequenceCheckingRestricted( bool _bEnable )
     101             : {
     102           0 :     m_pCTLOptions->SetCTLSequenceCheckingRestricted( _bEnable );
     103           0 : }
     104             : 
     105           0 : void SvtLanguageOptions::SetCTLSequenceCheckingTypeAndReplace( bool _bEnable )
     106             : {
     107           0 :     m_pCTLOptions->SetCTLSequenceCheckingTypeAndReplace( _bEnable );
     108           0 : }
     109             : 
     110           0 : bool SvtLanguageOptions::IsReadOnly(SvtLanguageOptions::EOption eOption) const
     111             : {
     112           0 :     bool bReadOnly = false;
     113           0 :     switch(eOption)
     114             :     {
     115             :         // cjk options
     116           0 :         case SvtLanguageOptions::E_CJKFONT          : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_CJKFONT        ); break;
     117           0 :         case SvtLanguageOptions::E_VERTICALTEXT     : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_VERTICALTEXT   ); break;
     118           0 :         case SvtLanguageOptions::E_ASIANTYPOGRAPHY  : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_ASIANTYPOGRAPHY); break;
     119           0 :         case SvtLanguageOptions::E_JAPANESEFIND     : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_JAPANESEFIND   ); break;
     120           0 :         case SvtLanguageOptions::E_RUBY             : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_RUBY           ); break;
     121           0 :         case SvtLanguageOptions::E_CHANGECASEMAP    : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_CHANGECASEMAP  ); break;
     122           0 :         case SvtLanguageOptions::E_DOUBLELINES      : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_DOUBLELINES    ); break;
     123           0 :         case SvtLanguageOptions::E_EMPHASISMARKS    : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_EMPHASISMARKS  ); break;
     124           0 :         case SvtLanguageOptions::E_VERTICALCALLOUT  : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_VERTICALCALLOUT); break;
     125           0 :         case SvtLanguageOptions::E_ALLCJK           : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_ALL            ); break;
     126             :         // ctl options
     127           0 :         case SvtLanguageOptions::E_CTLFONT              : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLFONT            ); break;
     128           0 :         case SvtLanguageOptions::E_CTLSEQUENCECHECKING  : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLSEQUENCECHECKING); break;
     129           0 :         case SvtLanguageOptions::E_CTLCURSORMOVEMENT    : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLCURSORMOVEMENT  ); break;
     130           0 :         case SvtLanguageOptions::E_CTLTEXTNUMERALS      : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLTEXTNUMERALS    ); break;
     131             :     }
     132           0 :     return bReadOnly;
     133             : }
     134             : 
     135             : // returns for a language the scripttype
     136     6817158 : SvtScriptType SvtLanguageOptions::GetScriptTypeOfLanguage( sal_uInt16 nLang )
     137             : {
     138     6817158 :     if( LANGUAGE_DONTKNOW == nLang )
     139      198408 :         nLang = LANGUAGE_ENGLISH_US;
     140     6618750 :     else if( LANGUAGE_SYSTEM == nLang  )
     141         653 :         nLang = SvtSysLocale().GetLanguageTag().getLanguageType();
     142             : 
     143     6817158 :     sal_Int16 nScriptType = MsLangId::getScriptType( nLang );
     144             :     SvtScriptType nScript;
     145     6817158 :     switch (nScriptType)
     146             :     {
     147             :         case ::com::sun::star::i18n::ScriptType::ASIAN:
     148           0 :             nScript = SvtScriptType::ASIAN;
     149           0 :             break;
     150             :         case ::com::sun::star::i18n::ScriptType::COMPLEX:
     151           0 :             nScript = SvtScriptType::COMPLEX;
     152           0 :             break;
     153             :         default:
     154     6817158 :             nScript = SvtScriptType::LATIN;
     155             :     }
     156     6817158 :     return nScript;
     157             : }
     158             : 
     159     1081534 : SvtScriptType SvtLanguageOptions::FromI18NToSvtScriptType( sal_Int16 nI18NType )
     160             : {
     161     1081534 :     switch ( nI18NType )
     162             :     {
     163     1081508 :         case i18n::ScriptType::LATIN:   return SvtScriptType::LATIN;
     164          26 :         case i18n::ScriptType::ASIAN:   return SvtScriptType::ASIAN;
     165           0 :         case i18n::ScriptType::COMPLEX: return SvtScriptType::COMPLEX;
     166           0 :         case i18n::ScriptType::WEAK:    return SvtScriptType::NONE; // no mapping
     167           0 :         default: assert(false && nI18NType && "Unknown i18n::ScriptType"); break;
     168             :     }
     169           0 :     return SvtScriptType::NONE;
     170             : }
     171             : 
     172     6048598 : sal_Int16 SvtLanguageOptions::FromSvtScriptTypeToI18N( SvtScriptType nItemType )
     173             : {
     174     6048598 :     switch ( nItemType )
     175             :     {
     176           0 :         case SvtScriptType::NONE:       return 0;
     177     6048598 :         case SvtScriptType::LATIN:      return i18n::ScriptType::LATIN;
     178           0 :         case SvtScriptType::ASIAN:      return i18n::ScriptType::ASIAN;
     179           0 :         case SvtScriptType::COMPLEX:    return i18n::ScriptType::COMPLEX;
     180           0 :         case SvtScriptType::UNKNOWN:    return 0; // no mapping
     181           0 :         default: assert(false && static_cast<int>(nItemType) && "unknown SvtScriptType"); break;
     182             :     }
     183           0 :     return 0;
     184             : }
     185             : 
     186     6047820 : sal_Int16 SvtLanguageOptions::GetI18NScriptTypeOfLanguage( sal_uInt16 nLang )
     187             : {
     188     6047820 :     return FromSvtScriptTypeToI18N( GetScriptTypeOfLanguage( nLang ) );
     189             : }
     190             : 
     191           0 : SvtSystemLanguageOptions::SvtSystemLanguageOptions() :
     192           0 :     utl::ConfigItem( "System/L10N")
     193             : {
     194           0 :     uno::Sequence< OUString > aPropertyNames(1);
     195           0 :     OUString* pNames = aPropertyNames.getArray();
     196           0 :     pNames[0] = "SystemLocale";
     197           0 :     uno::Sequence< uno::Any > aValues = GetProperties( aPropertyNames );
     198             : 
     199           0 :     if ( aValues.getLength() )
     200             :     {
     201           0 :         aValues[0]>>= m_sWin16SystemLocale;
     202           0 :     }
     203           0 : }
     204             : 
     205           0 : SvtSystemLanguageOptions::~SvtSystemLanguageOptions()
     206             : {
     207           0 : }
     208             : 
     209           0 : void    SvtSystemLanguageOptions::ImplCommit()
     210             : {
     211             :     //does nothing
     212           0 : }
     213             : 
     214           0 : void    SvtSystemLanguageOptions::Notify( const com::sun::star::uno::Sequence< OUString >& )
     215             : {
     216             :     // no listeners supported yet
     217           0 : }
     218             : 
     219           0 : LanguageType SvtSystemLanguageOptions::GetWin16SystemLanguage() const
     220             : {
     221           0 :     if( m_sWin16SystemLocale.isEmpty() )
     222           0 :         return LANGUAGE_NONE;
     223           0 :     return LanguageTag::convertToLanguageTypeWithFallback( m_sWin16SystemLocale );
     224             : }
     225             : 
     226           0 : bool SvtSystemLanguageOptions::isKeyboardLayoutTypeInstalled(sal_Int16 scriptType) const
     227             : {
     228           0 :     bool isInstalled = false;
     229             : #ifdef WNT
     230             :     int nLayouts = GetKeyboardLayoutList(0, NULL);
     231             :     if (nLayouts > 0)
     232             :     {
     233             :         HKL *lpList = (HKL*)LocalAlloc(LPTR, (nLayouts * sizeof(HKL)));
     234             :         if (lpList)
     235             :         {
     236             :             nLayouts = GetKeyboardLayoutList(nLayouts, lpList);
     237             : 
     238             :             for(int i = 0; i < nLayouts; ++i)
     239             :             {
     240             :                 LCID lang = MAKELCID((WORD)((DWORD_PTR)lpList[i] & 0xffff), SORT_DEFAULT);
     241             :                 if (MsLangId::getScriptType(lang) == scriptType)
     242             :                 {
     243             :                     isInstalled = true;
     244             :                     break;
     245             :                 }
     246             :             }
     247             : 
     248             :             LocalFree(lpList);
     249             :         }
     250             :     }
     251             : #else
     252             :     (void)scriptType;
     253             : #endif
     254           0 :     return isInstalled;
     255             : }
     256             : 
     257             : 
     258           0 : bool SvtSystemLanguageOptions::isCTLKeyboardLayoutInstalled() const
     259             : {
     260           0 :     return isKeyboardLayoutTypeInstalled(::com::sun::star::i18n::ScriptType::COMPLEX);
     261             : }
     262             : 
     263             : 
     264           0 : bool SvtSystemLanguageOptions::isCJKKeyboardLayoutInstalled() const
     265             : {
     266           0 :     return isKeyboardLayoutTypeInstalled(::com::sun::star::i18n::ScriptType::ASIAN);
     267             : }
     268             : 
     269             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11