LCOV - code coverage report
Current view: top level - libreoffice/svl/source/config - languageoptions.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 42 92 45.7 %
Date: 2012-12-27 Functions: 7 22 31.8 %
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 <i18npool/mslangid.hxx>
      25             : #include <i18npool/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             : using namespace ::com::sun::star;
      32             : // global ----------------------------------------------------------------------
      33             : 
      34             : namespace { struct ALMutex : public rtl::Static< ::osl::Mutex, ALMutex > {}; }
      35             : 
      36             : // class SvtLanguageOptions ----------------------------------------------------
      37             : 
      38          82 : SvtLanguageOptions::SvtLanguageOptions( sal_Bool _bDontLoad )
      39             : {
      40             :     // Global access, must be guarded (multithreading)
      41          82 :     ::osl::MutexGuard aGuard( ALMutex::get() );
      42             : 
      43          82 :     m_pCJKOptions = new SvtCJKOptions( _bDontLoad );
      44          82 :     m_pCTLOptions = new SvtCTLOptions( _bDontLoad );
      45          82 :     m_pCTLOptions->AddListener(this);
      46          82 :     m_pCJKOptions->AddListener(this);
      47          82 : }
      48             : //------------------------------------------------------------------------------
      49         164 : SvtLanguageOptions::~SvtLanguageOptions()
      50             : {
      51             :     // Global access, must be guarded (multithreading)
      52          82 :     ::osl::MutexGuard aGuard( ALMutex::get() );
      53             : 
      54          82 :     m_pCTLOptions->RemoveListener(this);
      55          82 :     m_pCJKOptions->RemoveListener(this);
      56             : 
      57          82 :     delete m_pCJKOptions;
      58          82 :     delete m_pCTLOptions;
      59          82 : }
      60             : //------------------------------------------------------------------------------
      61             : // CJK options -----------------------------------------------------------------
      62             : //------------------------------------------------------------------------------
      63           0 : sal_Bool SvtLanguageOptions::IsCJKFontEnabled() const
      64             : {
      65           0 :     return m_pCJKOptions->IsCJKFontEnabled();
      66             : }
      67             : //------------------------------------------------------------------------------
      68           0 : sal_Bool SvtLanguageOptions::IsVerticalTextEnabled() const
      69             : {
      70           0 :     return m_pCJKOptions->IsVerticalTextEnabled();
      71             : }
      72             : //------------------------------------------------------------------------------
      73           0 : sal_Bool SvtLanguageOptions::IsAsianTypographyEnabled() const
      74             : {
      75           0 :     return m_pCJKOptions->IsAsianTypographyEnabled();
      76             : }
      77             : //------------------------------------------------------------------------------
      78           0 : sal_Bool SvtLanguageOptions::IsJapaneseFindEnabled() const
      79             : {
      80           0 :     return m_pCJKOptions->IsJapaneseFindEnabled();
      81             : }
      82             : //------------------------------------------------------------------------------
      83           0 : void SvtLanguageOptions::SetAll( sal_Bool _bSet )
      84             : {
      85           0 :     m_pCJKOptions->SetAll( _bSet );
      86           0 : }
      87             : //------------------------------------------------------------------------------
      88           0 : sal_Bool SvtLanguageOptions::IsAnyEnabled() const
      89             : {
      90           0 :     return m_pCJKOptions->IsAnyEnabled();
      91             : }
      92             : //------------------------------------------------------------------------------
      93             : // CTL options -----------------------------------------------------------------
      94             : //------------------------------------------------------------------------------
      95           0 : void SvtLanguageOptions::SetCTLFontEnabled( sal_Bool _bEnabled )
      96             : {
      97           0 :     m_pCTLOptions->SetCTLFontEnabled( _bEnabled );
      98           0 : }
      99             : //------------------------------------------------------------------------------
     100          82 : sal_Bool SvtLanguageOptions::IsCTLFontEnabled() const
     101             : {
     102          82 :     return m_pCTLOptions->IsCTLFontEnabled();
     103             : }
     104             : //------------------------------------------------------------------------------
     105           0 : void SvtLanguageOptions::SetCTLSequenceChecking( sal_Bool _bEnabled )
     106             : {
     107           0 :     m_pCTLOptions->SetCTLSequenceChecking( _bEnabled );
     108           0 : }
     109             : 
     110           0 : void SvtLanguageOptions::SetCTLSequenceCheckingRestricted( sal_Bool _bEnable )
     111             : {
     112           0 :     m_pCTLOptions->SetCTLSequenceCheckingRestricted( _bEnable );
     113           0 : }
     114             : 
     115           0 : void SvtLanguageOptions::SetCTLSequenceCheckingTypeAndReplace( sal_Bool _bEnable )
     116             : {
     117           0 :     m_pCTLOptions->SetCTLSequenceCheckingTypeAndReplace( _bEnable );
     118           0 : }
     119             : 
     120             : //------------------------------------------------------------------------------
     121           0 : sal_Bool SvtLanguageOptions::IsReadOnly(SvtLanguageOptions::EOption eOption) const
     122             : {
     123           0 :     sal_Bool bReadOnly = sal_False;
     124           0 :     switch(eOption)
     125             :     {
     126             :         // cjk options
     127           0 :         case SvtLanguageOptions::E_CJKFONT          : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_CJKFONT        ); break;
     128           0 :         case SvtLanguageOptions::E_VERTICALTEXT     : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_VERTICALTEXT   ); break;
     129           0 :         case SvtLanguageOptions::E_ASIANTYPOGRAPHY  : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_ASIANTYPOGRAPHY); break;
     130           0 :         case SvtLanguageOptions::E_JAPANESEFIND     : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_JAPANESEFIND   ); break;
     131           0 :         case SvtLanguageOptions::E_RUBY             : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_RUBY           ); break;
     132           0 :         case SvtLanguageOptions::E_CHANGECASEMAP    : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_CHANGECASEMAP  ); break;
     133           0 :         case SvtLanguageOptions::E_DOUBLELINES      : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_DOUBLELINES    ); break;
     134           0 :         case SvtLanguageOptions::E_EMPHASISMARKS    : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_EMPHASISMARKS  ); break;
     135           0 :         case SvtLanguageOptions::E_VERTICALCALLOUT  : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_VERTICALCALLOUT); break;
     136           0 :         case SvtLanguageOptions::E_ALLCJK           : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_ALL            ); break;
     137             :         // ctl options
     138           0 :         case SvtLanguageOptions::E_CTLFONT              : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLFONT            ); break;
     139           0 :         case SvtLanguageOptions::E_CTLSEQUENCECHECKING  : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLSEQUENCECHECKING); break;
     140           0 :         case SvtLanguageOptions::E_CTLCURSORMOVEMENT    : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLCURSORMOVEMENT  ); break;
     141           0 :         case SvtLanguageOptions::E_CTLTEXTNUMERALS      : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLTEXTNUMERALS    ); break;
     142             :     }
     143           0 :     return bReadOnly;
     144             : }
     145             : 
     146             : // returns for a language the scripttype
     147      293420 : sal_uInt16 SvtLanguageOptions::GetScriptTypeOfLanguage( sal_uInt16 nLang )
     148             : {
     149      293420 :     if( LANGUAGE_DONTKNOW == nLang )
     150       13774 :         nLang = LANGUAGE_ENGLISH_US;
     151      279646 :     else if( LANGUAGE_SYSTEM == nLang  )
     152          18 :         nLang = SvtSysLocale().GetLanguageTag().getLanguageType();
     153             : 
     154      293420 :     sal_Int16 nScriptType = MsLangId::getScriptType( nLang );
     155             :     sal_uInt16 nScript;
     156      293420 :     switch (nScriptType)
     157             :     {
     158             :         case ::com::sun::star::i18n::ScriptType::ASIAN:
     159         707 :             nScript = SCRIPTTYPE_ASIAN;
     160         707 :             break;
     161             :         case ::com::sun::star::i18n::ScriptType::COMPLEX:
     162           0 :             nScript = SCRIPTTYPE_COMPLEX;
     163           0 :             break;
     164             :         default:
     165      292713 :             nScript = SCRIPTTYPE_LATIN;
     166             :     }
     167      293420 :     return nScript;
     168             : }
     169             : // -----------------------------------------------------------------------------
     170             : 
     171          18 : SvtSystemLanguageOptions::SvtSystemLanguageOptions() :
     172          18 :     utl::ConfigItem( "System/L10N")
     173             : {
     174          18 :     uno::Sequence< rtl::OUString > aPropertyNames(1);
     175          18 :     rtl::OUString* pNames = aPropertyNames.getArray();
     176          18 :     pNames[0] = "SystemLocale";
     177          18 :     uno::Sequence< uno::Any > aValues = GetProperties( aPropertyNames );
     178             : 
     179          18 :     if ( aValues.getLength() )
     180             :     {
     181          18 :         aValues[0]>>= m_sWin16SystemLocale;
     182          18 :     }
     183          18 : }
     184             : 
     185          18 : SvtSystemLanguageOptions::~SvtSystemLanguageOptions()
     186             : {
     187          18 : }
     188             : 
     189           0 : void    SvtSystemLanguageOptions::Commit()
     190             : {
     191             :     //does nothing
     192           0 : }
     193             : 
     194           0 : void    SvtSystemLanguageOptions::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
     195             : {
     196             :     // no listeners supported yet
     197           0 : }
     198             : 
     199             : 
     200          18 : LanguageType SvtSystemLanguageOptions::GetWin16SystemLanguage()
     201             : {
     202          18 :     if( m_sWin16SystemLocale.isEmpty() )
     203          18 :         return LANGUAGE_NONE;
     204           0 :     return LanguageTag( m_sWin16SystemLocale ).getLanguageType();
     205             : }
     206             : 
     207             : 
     208             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10