LCOV - code coverage report
Current view: top level - libreoffice/framework/source/fwi/helper - mischelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 75 0.0 %
Date: 2012-12-27 Functions: 0 3 0.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 <com/sun/star/lang/XMultiServiceFactory.hpp>
      22             : #include <com/sun/star/document/XDocumentLanguages.hpp>
      23             : #include <com/sun/star/frame/ModuleManager.hpp>
      24             : #include <com/sun/star/frame/UICommandDescription.hpp>
      25             : #include <com/sun/star/beans/PropertyValue.hpp>
      26             : 
      27             : #include <tools/debug.hxx>
      28             : #include <vcl/settings.hxx>
      29             : #include <vcl/svapp.hxx>
      30             : #include <i18npool/languagetag.hxx>
      31             : #include <svtools/langtab.hxx>
      32             : #include <comphelper/processfactory.hxx>
      33             : #include <helper/mischelper.hxx>
      34             : #include <services.h>
      35             : 
      36             : 
      37             : using namespace ::com::sun::star;
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::frame;
      40             : using namespace ::com::sun::star::beans;
      41             : using namespace ::com::sun::star::container;
      42             : using namespace ::com::sun::star::lang;
      43             : 
      44             : using ::rtl::OUString;
      45             : 
      46             : 
      47             : namespace framework
      48             : {
      49             : 
      50           0 : uno::Reference< linguistic2::XLanguageGuessing > LanguageGuessingHelper::GetGuesser() const
      51             : {
      52           0 :     if (!m_xLanguageGuesser.is())
      53             :     {
      54             :         try
      55             :         {
      56             :             m_xLanguageGuesser = uno::Reference< linguistic2::XLanguageGuessing >(
      57           0 :                     m_xServiceManager->createInstance(
      58           0 :                         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.linguistic2.LanguageGuessing")) ),
      59           0 :                         uno::UNO_QUERY );
      60             :         }
      61           0 :         catch (const uno::Exception &)
      62             :         {
      63             :             DBG_ASSERT( 0, "failed to get language guessing component" );
      64             :         }
      65             :     }
      66           0 :     return m_xLanguageGuesser;
      67             : }
      68             : 
      69             : 
      70           0 : ::rtl::OUString RetrieveLabelFromCommand(
      71             :     const ::rtl::OUString& aCmdURL,
      72             :     const uno::Reference< uno::XComponentContext >& _xContext,
      73             :     uno::Reference< container::XNameAccess >& _xUICommandLabels,
      74             :     const uno::Reference< frame::XFrame >& _xFrame,
      75             :     ::rtl::OUString& _rModuleIdentifier,
      76             :     sal_Bool& _rIni,
      77             :     const sal_Char* _pName)
      78             : {
      79           0 :     ::rtl::OUString aLabel;
      80             : 
      81             :     // Retrieve popup menu labels
      82           0 :     if ( !_xUICommandLabels.is() )
      83             :     {
      84             :       try
      85             :         {
      86           0 :             if ( !_rIni )
      87             :             {
      88           0 :                 _rIni = sal_True;
      89           0 :                 Reference< XModuleManager2 > xModuleManager = ModuleManager::create( _xContext );
      90             : 
      91             :                 try
      92             :                 {
      93           0 :                     _rModuleIdentifier = xModuleManager->identify( _xFrame );
      94             :                 }
      95           0 :                 catch( const Exception& )
      96             :                 {
      97           0 :                 }
      98             :             }
      99             : 
     100           0 :             Reference< XNameAccess > xNameAccess = frame::UICommandDescription::create( _xContext );
     101           0 :             xNameAccess->getByName( _rModuleIdentifier ) >>= _xUICommandLabels;
     102             :         }
     103           0 :         catch ( const Exception& )
     104             :         {
     105             :         }
     106             :     }
     107             : 
     108           0 :     if ( _xUICommandLabels.is() )
     109             :     {
     110             :         try
     111             :         {
     112           0 :             if ( !aCmdURL.isEmpty() )
     113             :             {
     114           0 :                 rtl::OUString aStr;
     115           0 :                 Sequence< PropertyValue > aPropSeq;
     116           0 :                 if( _xUICommandLabels->hasByName( aCmdURL ) )
     117             :                 {
     118           0 :                     if ( _xUICommandLabels->getByName( aCmdURL ) >>= aPropSeq )
     119             :                     {
     120           0 :                         for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
     121             :                         {
     122           0 :                             if ( aPropSeq[i].Name.equalsAscii( _pName/*"Label"*/ ))
     123             :                             {
     124           0 :                                 aPropSeq[i].Value >>= aStr;
     125           0 :                                 break;
     126             :                             }
     127             :                         }
     128             :                     }
     129             :                 }
     130           0 :                 aLabel = aStr;
     131             :             }
     132             :         }
     133           0 :         catch ( const com::sun::star::uno::Exception& )
     134             :         {
     135             :         }
     136             :     }
     137             : 
     138           0 :     return aLabel;
     139             : }
     140             : 
     141             : 
     142           0 : void FillLangItems( std::set< OUString > &rLangItems,
     143             :         const SvtLanguageTable &    rLanguageTable,
     144             :         const uno::Reference< frame::XFrame > & rxFrame,
     145             :         const LanguageGuessingHelper & rLangGuessHelper,
     146             :         sal_Int16        nScriptType,
     147             :         const OUString & rCurLang,
     148             :         const OUString & rKeyboardLang,
     149             :         const OUString & rGuessedTextLang )
     150             : {
     151           0 :     rLangItems.clear();
     152             : 
     153             :     //1--add current language
     154           0 :     if( !rCurLang.isEmpty() &&
     155           0 :         LANGUAGE_DONTKNOW != rLanguageTable.GetType( rCurLang ))
     156           0 :         rLangItems.insert( rCurLang );
     157             : 
     158             :     //2--System
     159           0 :     const AllSettings& rAllSettings = Application::GetSettings();
     160           0 :     LanguageType rSystemLanguage = rAllSettings.GetLanguageTag().getLanguageType();
     161           0 :     if( rSystemLanguage != LANGUAGE_DONTKNOW )
     162             :     {
     163           0 :         if ( IsScriptTypeMatchingToLanguage( nScriptType, rSystemLanguage ))
     164           0 :             rLangItems.insert( OUString( rLanguageTable.GetString( rSystemLanguage )) );
     165             :     }
     166             : 
     167             :     //3--UI
     168           0 :     LanguageType rUILanguage = rAllSettings.GetUILanguageTag().getLanguageType();
     169           0 :     if( rUILanguage != LANGUAGE_DONTKNOW )
     170             :     {
     171           0 :         if ( IsScriptTypeMatchingToLanguage( nScriptType, rUILanguage ))
     172           0 :             rLangItems.insert( OUString( rLanguageTable.GetString( rUILanguage )) );
     173             :     }
     174             : 
     175             :     //4--guessed language
     176           0 :     uno::Reference< linguistic2::XLanguageGuessing > xLangGuesser( rLangGuessHelper.GetGuesser() );
     177           0 :     if ( xLangGuesser.is() && !rGuessedTextLang.isEmpty())
     178             :     {
     179           0 :         ::com::sun::star::lang::Locale aLocale(xLangGuesser->guessPrimaryLanguage( rGuessedTextLang, 0, rGuessedTextLang.getLength()) );
     180           0 :         LanguageType nLang = LanguageTag( aLocale ).makeFallback().getLanguageType();
     181           0 :         if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_NONE && nLang != LANGUAGE_SYSTEM
     182           0 :             && IsScriptTypeMatchingToLanguage( nScriptType, nLang ))
     183           0 :             rLangItems.insert( rLanguageTable.GetString( nLang ));
     184             :     }
     185             : 
     186             :     //5--keyboard language
     187           0 :     if( !rKeyboardLang.isEmpty() )
     188             :     {
     189           0 :         if ( IsScriptTypeMatchingToLanguage( nScriptType, rLanguageTable.GetType( rKeyboardLang )))
     190           0 :             rLangItems.insert( rKeyboardLang );
     191             :     }
     192             : 
     193             :     //6--all languages used in current document
     194           0 :     Reference< com::sun::star::frame::XModel > xModel;
     195           0 :     if ( rxFrame.is() )
     196             :     {
     197           0 :        Reference< com::sun::star::frame::XController > xController( rxFrame->getController(), UNO_QUERY );
     198           0 :        if ( xController.is() )
     199           0 :            xModel = xController->getModel();
     200             :     }
     201           0 :     Reference< document::XDocumentLanguages > xDocumentLanguages( xModel, UNO_QUERY );
     202             :     /*the description of nScriptType
     203             :       LATIN :   0x001
     204             :       ASIAN :   0x002
     205             :       COMPLEX:  0x004
     206             :     */
     207           0 :     const sal_Int16 nMaxCount = 7;
     208           0 :     if ( xDocumentLanguages.is() )
     209             :     {
     210           0 :         Sequence< Locale > rLocales( xDocumentLanguages->getDocumentLanguages( nScriptType, nMaxCount ));
     211           0 :         if ( rLocales.getLength() > 0 )
     212             :         {
     213           0 :             for ( sal_uInt16 i = 0; i < rLocales.getLength(); ++i )
     214             :             {
     215           0 :                 if ( rLangItems.size() == static_cast< size_t >(nMaxCount) )
     216           0 :                     break;
     217           0 :                 const Locale& rLocale=rLocales[i];
     218           0 :                 if( IsScriptTypeMatchingToLanguage( nScriptType, rLanguageTable.GetType( rLocale.Language )))
     219           0 :                     rLangItems.insert( OUString( rLocale.Language ) );
     220             :             }
     221           0 :         }
     222           0 :     }
     223           0 : }
     224             : 
     225             : } // namespace framework
     226             : 
     227             : 
     228             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10