LCOV - code coverage report
Current view: top level - svl/source/config - languageoptions.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 7 99 7.1 %
Date: 2014-04-14 Functions: 1 25 4.0 %
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             : // class SvtLanguageOptions ----------------------------------------------------
      41             : 
      42           0 : SvtLanguageOptions::SvtLanguageOptions( bool _bDontLoad )
      43             : {
      44             :     // Global access, must be guarded (multithreading)
      45           0 :     ::osl::MutexGuard aGuard( ALMutex::get() );
      46             : 
      47           0 :     m_pCJKOptions = new SvtCJKOptions( _bDontLoad );
      48           0 :     m_pCTLOptions = new SvtCTLOptions( _bDontLoad );
      49           0 :     m_pCTLOptions->AddListener(this);
      50           0 :     m_pCJKOptions->AddListener(this);
      51           0 : }
      52           0 : SvtLanguageOptions::~SvtLanguageOptions()
      53             : {
      54             :     // Global access, must be guarded (multithreading)
      55           0 :     ::osl::MutexGuard aGuard( ALMutex::get() );
      56             : 
      57           0 :     m_pCTLOptions->RemoveListener(this);
      58           0 :     m_pCJKOptions->RemoveListener(this);
      59             : 
      60           0 :     delete m_pCJKOptions;
      61           0 :     delete m_pCTLOptions;
      62           0 : }
      63             : // CJK options -----------------------------------------------------------------
      64           0 : bool SvtLanguageOptions::IsCJKFontEnabled() const
      65             : {
      66           0 :     return m_pCJKOptions->IsCJKFontEnabled();
      67             : }
      68           0 : bool SvtLanguageOptions::IsVerticalTextEnabled() const
      69             : {
      70           0 :     return m_pCJKOptions->IsVerticalTextEnabled();
      71             : }
      72           0 : bool SvtLanguageOptions::IsAsianTypographyEnabled() const
      73             : {
      74           0 :     return m_pCJKOptions->IsAsianTypographyEnabled();
      75             : }
      76           0 : bool SvtLanguageOptions::IsJapaneseFindEnabled() const
      77             : {
      78           0 :     return m_pCJKOptions->IsJapaneseFindEnabled();
      79             : }
      80           0 : void SvtLanguageOptions::SetAll( bool _bSet )
      81             : {
      82           0 :     m_pCJKOptions->SetAll( _bSet );
      83           0 : }
      84           0 : bool SvtLanguageOptions::IsAnyEnabled() const
      85             : {
      86           0 :     return m_pCJKOptions->IsAnyEnabled();
      87             : }
      88             : // CTL options -----------------------------------------------------------------
      89           0 : void SvtLanguageOptions::SetCTLFontEnabled( bool _bEnabled )
      90             : {
      91           0 :     m_pCTLOptions->SetCTLFontEnabled( _bEnabled );
      92           0 : }
      93           0 : bool SvtLanguageOptions::IsCTLFontEnabled() const
      94             : {
      95           0 :     return m_pCTLOptions->IsCTLFontEnabled();
      96             : }
      97           0 : void SvtLanguageOptions::SetCTLSequenceChecking( bool _bEnabled )
      98             : {
      99           0 :     m_pCTLOptions->SetCTLSequenceChecking( _bEnabled );
     100           0 : }
     101             : 
     102           0 : void SvtLanguageOptions::SetCTLSequenceCheckingRestricted( bool _bEnable )
     103             : {
     104           0 :     m_pCTLOptions->SetCTLSequenceCheckingRestricted( _bEnable );
     105           0 : }
     106             : 
     107           0 : void SvtLanguageOptions::SetCTLSequenceCheckingTypeAndReplace( bool _bEnable )
     108             : {
     109           0 :     m_pCTLOptions->SetCTLSequenceCheckingTypeAndReplace( _bEnable );
     110           0 : }
     111             : 
     112           0 : bool SvtLanguageOptions::IsReadOnly(SvtLanguageOptions::EOption eOption) const
     113             : {
     114           0 :     bool bReadOnly = false;
     115           0 :     switch(eOption)
     116             :     {
     117             :         // cjk options
     118           0 :         case SvtLanguageOptions::E_CJKFONT          : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_CJKFONT        ); break;
     119           0 :         case SvtLanguageOptions::E_VERTICALTEXT     : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_VERTICALTEXT   ); break;
     120           0 :         case SvtLanguageOptions::E_ASIANTYPOGRAPHY  : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_ASIANTYPOGRAPHY); break;
     121           0 :         case SvtLanguageOptions::E_JAPANESEFIND     : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_JAPANESEFIND   ); break;
     122           0 :         case SvtLanguageOptions::E_RUBY             : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_RUBY           ); break;
     123           0 :         case SvtLanguageOptions::E_CHANGECASEMAP    : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_CHANGECASEMAP  ); break;
     124           0 :         case SvtLanguageOptions::E_DOUBLELINES      : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_DOUBLELINES    ); break;
     125           0 :         case SvtLanguageOptions::E_EMPHASISMARKS    : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_EMPHASISMARKS  ); break;
     126           0 :         case SvtLanguageOptions::E_VERTICALCALLOUT  : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_VERTICALCALLOUT); break;
     127           0 :         case SvtLanguageOptions::E_ALLCJK           : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_ALL            ); break;
     128             :         // ctl options
     129           0 :         case SvtLanguageOptions::E_CTLFONT              : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLFONT            ); break;
     130           0 :         case SvtLanguageOptions::E_CTLSEQUENCECHECKING  : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLSEQUENCECHECKING); break;
     131           0 :         case SvtLanguageOptions::E_CTLCURSORMOVEMENT    : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLCURSORMOVEMENT  ); break;
     132           0 :         case SvtLanguageOptions::E_CTLTEXTNUMERALS      : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLTEXTNUMERALS    ); break;
     133             :     }
     134           0 :     return bReadOnly;
     135             : }
     136             : 
     137             : // returns for a language the scripttype
     138           3 : sal_uInt16 SvtLanguageOptions::GetScriptTypeOfLanguage( sal_uInt16 nLang )
     139             : {
     140           3 :     if( LANGUAGE_DONTKNOW == nLang )
     141           0 :         nLang = LANGUAGE_ENGLISH_US;
     142           3 :     else if( LANGUAGE_SYSTEM == nLang  )
     143           0 :         nLang = SvtSysLocale().GetLanguageTag().getLanguageType();
     144             : 
     145           3 :     sal_Int16 nScriptType = MsLangId::getScriptType( nLang );
     146             :     sal_uInt16 nScript;
     147           3 :     switch (nScriptType)
     148             :     {
     149             :         case ::com::sun::star::i18n::ScriptType::ASIAN:
     150           0 :             nScript = SCRIPTTYPE_ASIAN;
     151           0 :             break;
     152             :         case ::com::sun::star::i18n::ScriptType::COMPLEX:
     153           0 :             nScript = SCRIPTTYPE_COMPLEX;
     154           0 :             break;
     155             :         default:
     156           3 :             nScript = SCRIPTTYPE_LATIN;
     157             :     }
     158           3 :     return nScript;
     159             : }
     160             : 
     161             : 
     162           0 : SvtSystemLanguageOptions::SvtSystemLanguageOptions() :
     163           0 :     utl::ConfigItem( "System/L10N")
     164             : {
     165           0 :     uno::Sequence< OUString > aPropertyNames(1);
     166           0 :     OUString* pNames = aPropertyNames.getArray();
     167           0 :     pNames[0] = "SystemLocale";
     168           0 :     uno::Sequence< uno::Any > aValues = GetProperties( aPropertyNames );
     169             : 
     170           0 :     if ( aValues.getLength() )
     171             :     {
     172           0 :         aValues[0]>>= m_sWin16SystemLocale;
     173           0 :     }
     174           0 : }
     175             : 
     176           0 : SvtSystemLanguageOptions::~SvtSystemLanguageOptions()
     177             : {
     178           0 : }
     179             : 
     180           0 : void    SvtSystemLanguageOptions::Commit()
     181             : {
     182             :     //does nothing
     183           0 : }
     184             : 
     185           0 : void    SvtSystemLanguageOptions::Notify( const com::sun::star::uno::Sequence< OUString >& )
     186             : {
     187             :     // no listeners supported yet
     188           0 : }
     189             : 
     190           0 : LanguageType SvtSystemLanguageOptions::GetWin16SystemLanguage() const
     191             : {
     192           0 :     if( m_sWin16SystemLocale.isEmpty() )
     193           0 :         return LANGUAGE_NONE;
     194           0 :     return LanguageTag::convertToLanguageTypeWithFallback( m_sWin16SystemLocale );
     195             : }
     196             : 
     197           0 : bool SvtSystemLanguageOptions::isKeyboardLayoutTypeInstalled(sal_Int16 scriptType) const
     198             : {
     199           0 :     bool isInstalled = false;
     200             : #ifdef WNT
     201             :     int nLayouts = GetKeyboardLayoutList(0, NULL);
     202             :     if (nLayouts > 0)
     203             :     {
     204             :         HKL *lpList = (HKL*)LocalAlloc(LPTR, (nLayouts * sizeof(HKL)));
     205             :         if (lpList)
     206             :         {
     207             :             nLayouts = GetKeyboardLayoutList(nLayouts, lpList);
     208             : 
     209             :             for(int i = 0; i < nLayouts; ++i)
     210             :             {
     211             :                 LCID lang = MAKELCID((WORD)((DWORD_PTR)lpList[i] & 0xffff), SORT_DEFAULT);
     212             :                 if (MsLangId::getScriptType(lang) == scriptType)
     213             :                 {
     214             :                     isInstalled = true;
     215             :                     break;
     216             :                 }
     217             :             }
     218             : 
     219             :             LocalFree(lpList);
     220             :         }
     221             :     }
     222             : #else
     223             :     (void)scriptType;
     224             : #endif
     225           0 :     return isInstalled;
     226             : }
     227             : 
     228             : 
     229           0 : bool SvtSystemLanguageOptions::isCTLKeyboardLayoutInstalled() const
     230             : {
     231           0 :     return isKeyboardLayoutTypeInstalled(::com::sun::star::i18n::ScriptType::COMPLEX);
     232             : }
     233             : 
     234             : 
     235           0 : bool SvtSystemLanguageOptions::isCJKKeyboardLayoutInstalled() const
     236             : {
     237           0 :     return isKeyboardLayoutTypeInstalled(::com::sun::star::i18n::ScriptType::ASIAN);
     238             : }
     239             : 
     240             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10