LCOV - code coverage report
Current view: top level - framework/source/fwi/helper - mischelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 24 77 31.2 %
Date: 2012-08-25 Functions: 1 3 33.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 35 222 15.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      31                 :            : #include <com/sun/star/document/XDocumentLanguages.hpp>
      32                 :            : #include <com/sun/star/frame/XModuleManager.hpp>
      33                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      34                 :            : 
      35                 :            : #include <tools/debug.hxx>
      36                 :            : #include <vcl/settings.hxx>
      37                 :            : #include <vcl/svapp.hxx>
      38                 :            : #include <i18npool/mslangid.hxx>
      39                 :            : #include <svtools/langtab.hxx>
      40                 :            : #include <comphelper/processfactory.hxx>
      41                 :            : #include <helper/mischelper.hxx>
      42                 :            : #include <services.h>
      43                 :            : 
      44                 :            : 
      45                 :            : using namespace ::com::sun::star;
      46                 :            : using namespace ::com::sun::star::uno;
      47                 :            : using namespace ::com::sun::star::frame;
      48                 :            : using namespace ::com::sun::star::beans;
      49                 :            : using namespace ::com::sun::star::container;
      50                 :            : using namespace ::com::sun::star::lang;
      51                 :            : 
      52                 :            : using ::rtl::OUString;
      53                 :            : 
      54                 :            : 
      55                 :            : namespace framework
      56                 :            : {
      57                 :            : 
      58                 :          0 : uno::Reference< linguistic2::XLanguageGuessing > LanguageGuessingHelper::GetGuesser() const
      59                 :            : {
      60         [ #  # ]:          0 :     if (!m_xLanguageGuesser.is())
      61                 :            :     {
      62                 :            :         try
      63                 :            :         {
      64                 :            :             m_xLanguageGuesser = uno::Reference< linguistic2::XLanguageGuessing >(
      65         [ #  # ]:          0 :                     m_xServiceManager->createInstance(
      66                 :          0 :                         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.linguistic2.LanguageGuessing")) ),
      67 [ #  # ][ #  # ]:          0 :                         uno::UNO_QUERY );
         [ #  # ][ #  # ]
                 [ #  # ]
      68                 :            :         }
      69                 :          0 :         catch (const uno::Exception &)
      70                 :            :         {
      71                 :            :             DBG_ASSERT( 0, "failed to get language guessing component" );
      72                 :            :         }
      73                 :            :     }
      74                 :          0 :     return m_xLanguageGuesser;
      75                 :            : }
      76                 :            : 
      77                 :            : 
      78                 :      22828 : ::rtl::OUString RetrieveLabelFromCommand(
      79                 :            :     const ::rtl::OUString& aCmdURL,
      80                 :            :     const uno::Reference< lang::XMultiServiceFactory >& _xServiceFactory,
      81                 :            :     uno::Reference< container::XNameAccess >& _xUICommandLabels,
      82                 :            :     const uno::Reference< frame::XFrame >& _xFrame,
      83                 :            :     ::rtl::OUString& _rModuleIdentifier,
      84                 :            :     sal_Bool& _rIni,
      85                 :            :     const sal_Char* _pName)
      86                 :            : {
      87                 :      22828 :     ::rtl::OUString aLabel;
      88                 :            : 
      89                 :            :     // Retrieve popup menu labels
      90         [ +  + ]:      22828 :     if ( !_xUICommandLabels.is() )
      91                 :            :     {
      92                 :            :       try
      93                 :            :         {
      94         [ +  + ]:       2330 :             if ( !_rIni )
      95                 :            :             {
      96                 :       1177 :                 _rIni = sal_True;
      97 [ +  - ][ +  - ]:       1177 :                 Reference< XModuleManager > xModuleManager( _xServiceFactory->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY_THROW );
         [ +  - ][ +  - ]
                 [ #  # ]
      98                 :            : 
      99                 :            :                 try
     100                 :            :                 {
     101 [ +  - ][ +  - ]:       1177 :                     _rModuleIdentifier = xModuleManager->identify( _xFrame );
     102                 :            :                 }
     103         [ #  # ]:          0 :                 catch( const Exception& )
     104                 :            :                 {
     105                 :       1177 :                 }
     106                 :            :             }
     107                 :            : 
     108 [ +  - ][ +  - ]:       2330 :             Reference< XNameAccess > xNameAccess( _xServiceFactory->createInstance( SERVICENAME_UICOMMANDDESCRIPTION ), UNO_QUERY );
         [ +  - ][ +  - ]
     109         [ +  - ]:       2330 :             if ( xNameAccess.is() )
     110                 :            :             {
     111 [ +  - ][ +  - ]:       2330 :                 xNameAccess->getByName( _rModuleIdentifier ) >>= _xUICommandLabels;
                 [ +  - ]
     112         [ #  # ]:       2330 :             }
     113                 :            :         }
     114         [ #  # ]:          0 :         catch ( const Exception& )
     115                 :            :         {
     116                 :            :         }
     117                 :            :     }
     118                 :            : 
     119         [ +  - ]:      22828 :     if ( _xUICommandLabels.is() )
     120                 :            :     {
     121                 :            :         try
     122                 :            :         {
     123         [ +  - ]:      22828 :             if ( !aCmdURL.isEmpty() )
     124                 :            :             {
     125                 :      22828 :                 rtl::OUString aStr;
     126         [ +  - ]:      22828 :                 Sequence< PropertyValue > aPropSeq;
     127 [ +  - ][ +  - ]:      22828 :                 if( _xUICommandLabels->hasByName( aCmdURL ) )
                 [ +  + ]
     128                 :            :                 {
     129 [ +  - ][ +  - ]:      20199 :                     if ( _xUICommandLabels->getByName( aCmdURL ) >>= aPropSeq )
         [ +  - ][ +  - ]
     130                 :            :                     {
     131         [ +  - ]:      50108 :                         for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
     132                 :            :                         {
     133 [ +  - ][ +  + ]:      29909 :                             if ( aPropSeq[i].Name.equalsAscii( _pName/*"Label"*/ ))
     134                 :            :                             {
     135         [ +  - ]:      20199 :                                 aPropSeq[i].Value >>= aStr;
     136                 :      20199 :                                 break;
     137                 :            :                             }
     138                 :            :                         }
     139                 :            :                     }
     140                 :            :                 }
     141 [ +  - ][ #  # ]:      22828 :                 aLabel = aStr;
     142                 :            :             }
     143                 :            :         }
     144         [ #  # ]:          0 :         catch ( const com::sun::star::uno::Exception& )
     145                 :            :         {
     146                 :            :         }
     147                 :            :     }
     148                 :            : 
     149                 :      22828 :     return aLabel;
     150                 :            : }
     151                 :            : 
     152                 :            : 
     153                 :          0 : void FillLangItems( std::set< OUString > &rLangItems,
     154                 :            :         const SvtLanguageTable &    rLanguageTable,
     155                 :            :         const uno::Reference< frame::XFrame > & rxFrame,
     156                 :            :         const LanguageGuessingHelper & rLangGuessHelper,
     157                 :            :         sal_Int16        nScriptType,
     158                 :            :         const OUString & rCurLang,
     159                 :            :         const OUString & rKeyboardLang,
     160                 :            :         const OUString & rGuessedTextLang )
     161                 :            : {
     162                 :          0 :     rLangItems.clear();
     163                 :            : 
     164                 :            :     //1--add current language
     165 [ #  # ][ #  # ]:          0 :     if( !rCurLang.isEmpty() &&
                 [ #  # ]
     166 [ #  # ][ #  # ]:          0 :         LANGUAGE_DONTKNOW != rLanguageTable.GetType( rCurLang ))
         [ #  # ][ #  # ]
                 [ #  # ]
     167         [ #  # ]:          0 :         rLangItems.insert( rCurLang );
     168                 :            : 
     169                 :            :     //2--System
     170         [ #  # ]:          0 :     const AllSettings& rAllSettings = Application::GetSettings();
     171         [ #  # ]:          0 :     LanguageType rSystemLanguage = rAllSettings.GetLanguage();
     172         [ #  # ]:          0 :     if( rSystemLanguage != LANGUAGE_DONTKNOW )
     173                 :            :     {
     174 [ #  # ][ #  # ]:          0 :         if ( IsScriptTypeMatchingToLanguage( nScriptType, rSystemLanguage ))
     175 [ #  # ][ #  # ]:          0 :             rLangItems.insert( OUString( rLanguageTable.GetString( rSystemLanguage )) );
     176                 :            :     }
     177                 :            : 
     178                 :            :     //3--UI
     179         [ #  # ]:          0 :     LanguageType rUILanguage = rAllSettings.GetUILanguage();
     180         [ #  # ]:          0 :     if( rUILanguage != LANGUAGE_DONTKNOW )
     181                 :            :     {
     182 [ #  # ][ #  # ]:          0 :         if ( IsScriptTypeMatchingToLanguage( nScriptType, rUILanguage ))
     183 [ #  # ][ #  # ]:          0 :             rLangItems.insert( OUString( rLanguageTable.GetString( rUILanguage )) );
     184                 :            :     }
     185                 :            : 
     186                 :            :     //4--guessed language
     187         [ #  # ]:          0 :     uno::Reference< linguistic2::XLanguageGuessing > xLangGuesser( rLangGuessHelper.GetGuesser() );
     188 [ #  # ][ #  # ]:          0 :     if ( xLangGuesser.is() && !rGuessedTextLang.isEmpty())
                 [ #  # ]
     189                 :            :     {
     190 [ #  # ][ #  # ]:          0 :         ::com::sun::star::lang::Locale aLocale(xLangGuesser->guessPrimaryLanguage( rGuessedTextLang, 0, rGuessedTextLang.getLength()) );
     191         [ #  # ]:          0 :         LanguageType nLang = MsLangId::convertLocaleToLanguageWithFallback( aLocale );
     192 [ #  # ][ #  # ]:          0 :         if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_NONE && nLang != LANGUAGE_SYSTEM
         [ #  # ][ #  # ]
                 [ #  # ]
     193         [ #  # ]:          0 :             && IsScriptTypeMatchingToLanguage( nScriptType, nLang ))
     194 [ #  # ][ #  # ]:          0 :             rLangItems.insert( rLanguageTable.GetString( nLang ));
     195                 :            :     }
     196                 :            : 
     197                 :            :     //5--keyboard language
     198         [ #  # ]:          0 :     if( !rKeyboardLang.isEmpty() )
     199                 :            :     {
     200 [ #  # ][ #  # ]:          0 :         if ( IsScriptTypeMatchingToLanguage( nScriptType, rLanguageTable.GetType( rKeyboardLang )))
         [ #  # ][ #  # ]
                 [ #  # ]
     201         [ #  # ]:          0 :             rLangItems.insert( rKeyboardLang );
     202                 :            :     }
     203                 :            : 
     204                 :            :     //6--all languages used in current document
     205                 :          0 :     Reference< com::sun::star::frame::XModel > xModel;
     206         [ #  # ]:          0 :     if ( rxFrame.is() )
     207                 :            :     {
     208 [ #  # ][ #  # ]:          0 :        Reference< com::sun::star::frame::XController > xController( rxFrame->getController(), UNO_QUERY );
                 [ #  # ]
     209         [ #  # ]:          0 :        if ( xController.is() )
     210 [ #  # ][ #  # ]:          0 :            xModel = xController->getModel();
                 [ #  # ]
     211                 :            :     }
     212         [ #  # ]:          0 :     Reference< document::XDocumentLanguages > xDocumentLanguages( xModel, UNO_QUERY );
     213                 :            :     /*the description of nScriptType
     214                 :            :       LATIN :   0x001
     215                 :            :       ASIAN :   0x002
     216                 :            :       COMPLEX:  0x004
     217                 :            :     */
     218                 :          0 :     const sal_Int16 nMaxCount = 7;
     219         [ #  # ]:          0 :     if ( xDocumentLanguages.is() )
     220                 :            :     {
     221 [ #  # ][ #  # ]:          0 :         Sequence< Locale > rLocales( xDocumentLanguages->getDocumentLanguages( nScriptType, nMaxCount ));
     222         [ #  # ]:          0 :         if ( rLocales.getLength() > 0 )
     223                 :            :         {
     224         [ #  # ]:          0 :             for ( sal_uInt16 i = 0; i < rLocales.getLength(); ++i )
     225                 :            :             {
     226         [ #  # ]:          0 :                 if ( rLangItems.size() == static_cast< size_t >(nMaxCount) )
     227                 :          0 :                     break;
     228         [ #  # ]:          0 :                 const Locale& rLocale=rLocales[i];
     229 [ #  # ][ #  # ]:          0 :                 if( IsScriptTypeMatchingToLanguage( nScriptType, rLanguageTable.GetType( rLocale.Language )))
         [ #  # ][ #  # ]
                 [ #  # ]
     230         [ #  # ]:          0 :                     rLangItems.insert( OUString( rLocale.Language ) );
     231                 :            :             }
     232         [ #  # ]:          0 :         }
     233                 :          0 :     }
     234                 :          0 : }
     235                 :            : 
     236                 :            : } // namespace framework
     237                 :            : 
     238                 :            : 
     239                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10