LCOV - code coverage report
Current view: top level - framework/source/uielement - uicommanddescription.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 226 300 75.3 %
Date: 2014-04-11 Functions: 30 39 76.9 %
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             : #include "uielement/uicommanddescription.hxx"
      21             : 
      22             : #include "properties.h"
      23             : 
      24             : #include "helper/mischelper.hxx"
      25             : 
      26             : #include <com/sun/star/beans/PropertyValue.hpp>
      27             : #include <com/sun/star/beans/XPropertySet.hpp>
      28             : #include <com/sun/star/frame/ModuleManager.hpp>
      29             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      30             : #include <com/sun/star/container/XNameAccess.hpp>
      31             : #include <com/sun/star/container/XNameContainer.hpp>
      32             : #include <com/sun/star/container/XContainer.hpp>
      33             : 
      34             : #include <rtl/ustrbuf.hxx>
      35             : #include <cppuhelper/implbase2.hxx>
      36             : #include <unotools/configmgr.hxx>
      37             : 
      38             : #include <vcl/mnemonic.hxx>
      39             : #include <comphelper/sequence.hxx>
      40             : #include <comphelper/string.hxx>
      41             : 
      42             : using namespace com::sun::star::uno;
      43             : using namespace com::sun::star::lang;
      44             : using namespace com::sun::star::beans;
      45             : using namespace com::sun::star::configuration;
      46             : using namespace com::sun::star::container;
      47             : using namespace ::com::sun::star::frame;
      48             : 
      49             : //  Namespace
      50             : 
      51             : struct ModuleToCommands
      52             : {
      53             :     const char* pModuleId;
      54             :     const char* pCommands;
      55             : };
      56             : 
      57             : static const char CONFIGURATION_ROOT_ACCESS[]           = "/org.openoffice.Office.UI.";
      58             : static const char CONFIGURATION_CMD_ELEMENT_ACCESS[]    = "/UserInterface/Commands";
      59             : static const char CONFIGURATION_POP_ELEMENT_ACCESS[]    = "/UserInterface/Popups";
      60             : static const char CONFIGURATION_PROPERTY_LABEL[]        = "Label";
      61             : static const char CONFIGURATION_PROPERTY_CONTEXT_LABEL[] = "ContextLabel";
      62             : 
      63             : // Property names of the resulting Property Set
      64             : static const char PROPSET_LABEL[]                       = "Label";
      65             : static const char PROPSET_NAME[]                        = "Name";
      66             : static const char PROPSET_POPUP[]                       = "Popup";
      67             : static const char PROPSET_PROPERTIES[]                  = "Properties";
      68             : 
      69             : // Special resource URLs to retrieve additional information
      70             : static const char PRIVATE_RESOURCE_URL[]                = "private:";
      71             : 
      72             : const sal_Int32   COMMAND_PROPERTY_IMAGE                = 1;
      73             : const sal_Int32   COMMAND_PROPERTY_ROTATE               = 2;
      74             : const sal_Int32   COMMAND_PROPERTY_MIRROR               = 4;
      75             : 
      76             : namespace framework
      77             : {
      78             : 
      79             : //  Configuration access class for PopupMenuControllerFactory implementation
      80             : 
      81             : class ConfigurationAccess_UICommand : // Order is necessary for right initialization!
      82             :                                         public  ::cppu::WeakImplHelper2<XNameAccess,XContainerListener>
      83             : {
      84             :     osl::Mutex m_aMutex;
      85             :     public:
      86             :                                   ConfigurationAccess_UICommand( const OUString& aModuleName, const Reference< XNameAccess >& xGenericUICommands, const Reference< XComponentContext >& rxContext );
      87             :         virtual                   ~ConfigurationAccess_UICommand();
      88             : 
      89             :         // XNameAccess
      90             :         virtual ::com::sun::star::uno::Any SAL_CALL getByName( const OUString& aName )
      91             :             throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      92             : 
      93             :         virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames()
      94             :             throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      95             : 
      96             :         virtual sal_Bool SAL_CALL hasByName( const OUString& aName )
      97             :             throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      98             : 
      99             :         // XElementAccess
     100             :         virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
     101             :             throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     102             : 
     103             :         virtual sal_Bool SAL_CALL hasElements()
     104             :             throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     105             : 
     106             :         // container.XContainerListener
     107             :         virtual void SAL_CALL     elementInserted( const ContainerEvent& aEvent ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
     108             :         virtual void SAL_CALL     elementRemoved ( const ContainerEvent& aEvent ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
     109             :         virtual void SAL_CALL     elementReplaced( const ContainerEvent& aEvent ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
     110             : 
     111             :         // lang.XEventListener
     112             :         virtual void SAL_CALL disposing( const EventObject& aEvent ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
     113             : 
     114             :     protected:
     115             :         virtual ::com::sun::star::uno::Any SAL_CALL getByNameImpl( const OUString& aName );
     116             : 
     117      200735 :         struct CmdToInfoMap
     118             :         {
     119       40147 :             CmdToInfoMap() : bPopup( false ),
     120             :                              bCommandNameCreated( false ),
     121       40147 :                              nProperties( 0 ) {}
     122             : 
     123             :             OUString       aLabel;
     124             :             OUString       aContextLabel;
     125             :             OUString       aCommandName;
     126             :             bool                bPopup : 1,
     127             :                                 bCommandNameCreated : 1;
     128             :             sal_Int32           nProperties;
     129             :         };
     130             : 
     131             :         Any                       getSequenceFromCache( const OUString& aCommandURL );
     132             :         Any                       getInfoFromCommand( const OUString& rCommandURL );
     133             :         void                      fillInfoFromResult( CmdToInfoMap& rCmdInfo, const OUString& aLabel );
     134             :         Sequence< OUString > getAllCommands();
     135             :         bool                  fillCache();
     136             :         bool                  addGenericInfoToCache();
     137             :         void                      impl_fill(const Reference< XNameAccess >& _xConfigAccess,bool _bPopup,
     138             :                                                 std::vector< OUString >& aImageCommandVector,
     139             :                                                 std::vector< OUString >& aImageRotateVector,
     140             :                                                 std::vector< OUString >& aImageMirrorVector);
     141             : 
     142             :     private:
     143             :         typedef ::boost::unordered_map< OUString,
     144             :                                  CmdToInfoMap,
     145             :                                  OUStringHash,
     146             :                                  ::std::equal_to< OUString > > CommandToInfoCache;
     147             : 
     148             :         bool initializeConfigAccess();
     149             : 
     150             :         OUString                     m_aConfigCmdAccess;
     151             :         OUString                     m_aConfigPopupAccess;
     152             :         OUString                     m_aPropUILabel;
     153             :         OUString                     m_aPropUIContextLabel;
     154             :         OUString                     m_aPropLabel;
     155             :         OUString                     m_aPropName;
     156             :         OUString                     m_aPropPopup;
     157             :         OUString                     m_aPropProperties;
     158             :         OUString                     m_aXMLFileFormatVersion;
     159             :         OUString                     m_aVersion;
     160             :         OUString                     m_aExtension;
     161             :         OUString                     m_aPrivateResourceURL;
     162             :         Reference< XNameAccess >          m_xGenericUICommands;
     163             :         Reference< XMultiServiceFactory > m_xConfigProvider;
     164             :         Reference< XNameAccess >          m_xConfigAccess;
     165             :         Reference< XContainerListener >   m_xConfigListener;
     166             :         Reference< XNameAccess >          m_xConfigAccessPopups;
     167             :         Reference< XContainerListener >   m_xConfigAccessListener;
     168             :         Sequence< OUString >         m_aCommandImageList;
     169             :         Sequence< OUString >         m_aCommandRotateImageList;
     170             :         Sequence< OUString >         m_aCommandMirrorImageList;
     171             :         CommandToInfoCache                m_aCmdInfoCache;
     172             :         bool                          m_bConfigAccessInitialized;
     173             :         bool                          m_bCacheFilled;
     174             :         bool                          m_bGenericDataRetrieved;
     175             : };
     176             : 
     177             : //  XInterface, XTypeProvider
     178             : 
     179          82 : ConfigurationAccess_UICommand::ConfigurationAccess_UICommand( const OUString& aModuleName, const Reference< XNameAccess >& rGenericUICommands, const Reference< XComponentContext>& rxContext ) :
     180             :     m_aConfigCmdAccess( CONFIGURATION_ROOT_ACCESS ),
     181             :     m_aConfigPopupAccess( CONFIGURATION_ROOT_ACCESS ),
     182             :     m_aPropUILabel( CONFIGURATION_PROPERTY_LABEL ),
     183             :     m_aPropUIContextLabel( CONFIGURATION_PROPERTY_CONTEXT_LABEL ),
     184             :     m_aPropLabel( PROPSET_LABEL ),
     185             :     m_aPropName( PROPSET_NAME ),
     186             :     m_aPropPopup( PROPSET_POPUP ),
     187             :     m_aPropProperties( PROPSET_PROPERTIES ),
     188             :     m_aPrivateResourceURL( PRIVATE_RESOURCE_URL ),
     189             :     m_xGenericUICommands( rGenericUICommands ),
     190             :     m_bConfigAccessInitialized( false ),
     191             :     m_bCacheFilled( false ),
     192          82 :     m_bGenericDataRetrieved( false )
     193             : {
     194             :     // Create configuration hierachical access name
     195          82 :     m_aConfigCmdAccess += aModuleName;
     196          82 :     m_aConfigCmdAccess += CONFIGURATION_CMD_ELEMENT_ACCESS;
     197             : 
     198          82 :     m_xConfigProvider = theDefaultProvider::get( rxContext );
     199             : 
     200          82 :     m_aConfigPopupAccess += aModuleName;
     201          82 :     m_aConfigPopupAccess += CONFIGURATION_POP_ELEMENT_ACCESS;
     202          82 : }
     203             : 
     204         246 : ConfigurationAccess_UICommand::~ConfigurationAccess_UICommand()
     205             : {
     206             :     // SAFE
     207          82 :     osl::MutexGuard g(m_aMutex);
     208         164 :     Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
     209          82 :     if ( xContainer.is() )
     210          80 :         xContainer->removeContainerListener(m_xConfigListener);
     211          82 :     xContainer = Reference< XContainer >( m_xConfigAccessPopups, UNO_QUERY );
     212          82 :     if ( xContainer.is() )
     213         162 :         xContainer->removeContainerListener(m_xConfigAccessListener);
     214         164 : }
     215             : 
     216             : // XNameAccess
     217      257350 : Any SAL_CALL ConfigurationAccess_UICommand::getByNameImpl( const OUString& rCommandURL )
     218             : {
     219             :     static sal_Int32 nRequests  = 0;
     220             : 
     221      257350 :     osl::MutexGuard g(m_aMutex);
     222      257350 :     if ( !m_bConfigAccessInitialized )
     223             :     {
     224          80 :         initializeConfigAccess();
     225          80 :         m_bConfigAccessInitialized = true;
     226          80 :         fillCache();
     227             :     }
     228             : 
     229      257350 :     if ( rCommandURL.startsWith( m_aPrivateResourceURL ) )
     230             :     {
     231             :         // special keys to retrieve information about a set of commands
     232             :         // SAFE
     233        4582 :         addGenericInfoToCache();
     234             : 
     235        4582 :         if ( rCommandURL.equalsIgnoreAsciiCase( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDIMAGELIST ))
     236         132 :             return makeAny( m_aCommandImageList );
     237        4450 :         else if ( rCommandURL.equalsIgnoreAsciiCase( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDROTATEIMAGELIST ))
     238        2225 :             return makeAny( m_aCommandRotateImageList );
     239        2225 :         else if ( rCommandURL.equalsIgnoreAsciiCase( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDMIRRORIMAGELIST ))
     240        2225 :             return makeAny( m_aCommandMirrorImageList );
     241             :         else
     242           0 :             return Any();
     243             :     }
     244             :     else
     245             :     {
     246             :         // SAFE
     247      252768 :         ++nRequests;
     248      252768 :         return getInfoFromCommand( rCommandURL );
     249      257350 :     }
     250             : }
     251             : 
     252      166222 : Any SAL_CALL ConfigurationAccess_UICommand::getByName( const OUString& rCommandURL )
     253             : throw ( NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
     254             : {
     255      166222 :     Any aRet( getByNameImpl( rCommandURL ) );
     256      166222 :     if( !aRet.hasValue() )
     257           0 :         throw NoSuchElementException();
     258             : 
     259      166222 :     return aRet;
     260             : }
     261             : 
     262           0 : Sequence< OUString > SAL_CALL ConfigurationAccess_UICommand::getElementNames()
     263             : throw ( RuntimeException, std::exception )
     264             : {
     265           0 :     return getAllCommands();
     266             : }
     267             : 
     268       91128 : sal_Bool SAL_CALL ConfigurationAccess_UICommand::hasByName( const OUString& rCommandURL )
     269             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     270             : {
     271       91128 :     return getByNameImpl( rCommandURL ).hasValue();
     272             : }
     273             : 
     274             : // XElementAccess
     275           0 : Type SAL_CALL ConfigurationAccess_UICommand::getElementType()
     276             : throw ( RuntimeException, std::exception )
     277             : {
     278           0 :     return( ::getCppuType( (const Sequence< PropertyValue >*)NULL ) );
     279             : }
     280             : 
     281           0 : sal_Bool SAL_CALL ConfigurationAccess_UICommand::hasElements()
     282             : throw ( RuntimeException, std::exception )
     283             : {
     284             :     // There must are global commands!
     285           0 :     return sal_True;
     286             : }
     287             : 
     288        2934 : void ConfigurationAccess_UICommand::fillInfoFromResult( CmdToInfoMap& rCmdInfo, const OUString& aLabel )
     289             : {
     290        2934 :     OUString aStr(aLabel.replaceAll("%PRODUCTNAME", utl::ConfigManager::getProductName()));
     291        2934 :     rCmdInfo.aLabel = aStr;
     292        2934 :     aStr = comphelper::string::stripEnd(aStr, '.'); // Remove "..." from string
     293        2934 :     rCmdInfo.aCommandName = MnemonicGenerator::EraseAllMnemonicChars(aStr);
     294        2934 :     rCmdInfo.bCommandNameCreated = true;
     295        2934 : }
     296             : 
     297      252768 : Any ConfigurationAccess_UICommand::getSequenceFromCache( const OUString& aCommandURL )
     298             : {
     299      252768 :     CommandToInfoCache::iterator pIter = m_aCmdInfoCache.find( aCommandURL );
     300      252768 :     if ( pIter != m_aCmdInfoCache.end() )
     301             :     {
     302      173230 :         if ( !pIter->second.bCommandNameCreated )
     303        2934 :             fillInfoFromResult( pIter->second, pIter->second.aLabel );
     304             : 
     305      173230 :         Sequence< PropertyValue > aPropSeq( 4 );
     306      173230 :         aPropSeq[0].Name  = m_aPropLabel;
     307      519690 :         aPropSeq[0].Value = !pIter->second.aContextLabel.isEmpty() ?
     308      346460 :                 makeAny( pIter->second.aContextLabel ): makeAny( pIter->second.aLabel );
     309      173230 :         aPropSeq[1].Name  = m_aPropName;
     310      173230 :         aPropSeq[1].Value <<= pIter->second.aCommandName;
     311      173230 :         aPropSeq[2].Name  = m_aPropPopup;
     312      173230 :         aPropSeq[2].Value <<= pIter->second.bPopup;
     313      173230 :         aPropSeq[3].Name  = m_aPropProperties;
     314      173230 :         aPropSeq[3].Value <<= pIter->second.nProperties;
     315      173230 :         return makeAny( aPropSeq );
     316             :     }
     317             : 
     318       79538 :     return Any();
     319             : }
     320         160 : void ConfigurationAccess_UICommand::impl_fill(const Reference< XNameAccess >& _xConfigAccess,bool _bPopup,
     321             :                                                 std::vector< OUString >& aImageCommandVector,
     322             :                                                 std::vector< OUString >& aImageRotateVector,
     323             :                                                 std::vector< OUString >& aImageMirrorVector)
     324             : {
     325         160 :     if ( _xConfigAccess.is() )
     326             :     {
     327         160 :         Sequence< OUString> aNameSeq = _xConfigAccess->getElementNames();
     328         160 :         const sal_Int32 nCount = aNameSeq.getLength();
     329       40307 :         for ( sal_Int32 i = 0; i < nCount; i++ )
     330             :         {
     331             :             try
     332             :             {
     333       40147 :                 Reference< XNameAccess > xNameAccess(_xConfigAccess->getByName( aNameSeq[i] ),UNO_QUERY);
     334       40147 :                 if ( xNameAccess.is() )
     335             :                 {
     336       40147 :                     CmdToInfoMap aCmdToInfo;
     337             : 
     338       40147 :                     aCmdToInfo.bPopup = _bPopup;
     339       40147 :                     xNameAccess->getByName( m_aPropUILabel )        >>= aCmdToInfo.aLabel;
     340       40147 :                     xNameAccess->getByName( m_aPropUIContextLabel ) >>= aCmdToInfo.aContextLabel;
     341       40147 :                     xNameAccess->getByName( m_aPropProperties )     >>= aCmdToInfo.nProperties;
     342             : 
     343       40147 :                     m_aCmdInfoCache.insert( CommandToInfoCache::value_type( aNameSeq[i], aCmdToInfo ));
     344             : 
     345       40147 :                     if ( aCmdToInfo.nProperties & COMMAND_PROPERTY_IMAGE )
     346       22907 :                         aImageCommandVector.push_back( aNameSeq[i] );
     347       40147 :                     if ( aCmdToInfo.nProperties & COMMAND_PROPERTY_ROTATE )
     348         782 :                         aImageRotateVector.push_back( aNameSeq[i] );
     349       40147 :                     if ( aCmdToInfo.nProperties & COMMAND_PROPERTY_MIRROR )
     350         612 :                         aImageMirrorVector.push_back( aNameSeq[i] );
     351       40147 :                 }
     352             :             }
     353           0 :             catch (const com::sun::star::lang::WrappedTargetException&)
     354             :             {
     355             :             }
     356           0 :             catch (const com::sun::star::container::NoSuchElementException&)
     357             :             {
     358             :             }
     359         160 :         }
     360             :     }
     361         160 : }
     362          80 : bool ConfigurationAccess_UICommand::fillCache()
     363             : {
     364             : 
     365          80 :     if ( m_bCacheFilled )
     366           0 :         return true;
     367             : 
     368          80 :     std::vector< OUString > aImageCommandVector;
     369         160 :     std::vector< OUString > aImageRotateVector;
     370         160 :     std::vector< OUString > aImageMirrorVector;
     371             : 
     372          80 :     impl_fill(m_xConfigAccess,false,aImageCommandVector,aImageRotateVector,aImageMirrorVector);
     373          80 :     impl_fill(m_xConfigAccessPopups,true,aImageCommandVector,aImageRotateVector,aImageMirrorVector);
     374             :     // Create cached sequences for fast retrieving
     375          80 :     m_aCommandImageList       = comphelper::containerToSequence( aImageCommandVector );
     376          80 :     m_aCommandRotateImageList = comphelper::containerToSequence( aImageRotateVector );
     377          80 :     m_aCommandMirrorImageList = comphelper::containerToSequence( aImageMirrorVector );
     378             : 
     379          80 :     m_bCacheFilled = true;
     380             : 
     381         160 :     return true;
     382             : }
     383             : 
     384        4582 : bool ConfigurationAccess_UICommand::addGenericInfoToCache()
     385             : {
     386        4582 :     if ( m_xGenericUICommands.is() && !m_bGenericDataRetrieved )
     387             :     {
     388          45 :         Sequence< OUString > aCommandNameSeq;
     389             :         try
     390             :         {
     391         135 :             if ( m_xGenericUICommands->getByName(
     392          90 :                     OUString( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDROTATEIMAGELIST )) >>= aCommandNameSeq )
     393          45 :                 m_aCommandRotateImageList = comphelper::concatSequences< OUString >( m_aCommandRotateImageList, aCommandNameSeq );
     394             :         }
     395           0 :         catch (const RuntimeException&)
     396             :         {
     397           0 :             throw;
     398             :         }
     399           0 :         catch (const Exception&)
     400             :         {
     401             :         }
     402             : 
     403             :         try
     404             :         {
     405         135 :             if ( m_xGenericUICommands->getByName(
     406          90 :                     OUString( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDMIRRORIMAGELIST )) >>= aCommandNameSeq )
     407          45 :                 m_aCommandMirrorImageList = comphelper::concatSequences< OUString >( m_aCommandMirrorImageList, aCommandNameSeq );
     408             :         }
     409           0 :         catch (const RuntimeException&)
     410             :         {
     411           0 :             throw;
     412             :         }
     413           0 :         catch (const Exception&)
     414             :         {
     415             :         }
     416             : 
     417          45 :         m_bGenericDataRetrieved = true;
     418             :     }
     419             : 
     420        4582 :     return true;
     421             : }
     422             : 
     423      252768 : Any ConfigurationAccess_UICommand::getInfoFromCommand( const OUString& rCommandURL )
     424             : {
     425      252768 :     Any a;
     426             : 
     427             :     try
     428             :     {
     429      252768 :         a = getSequenceFromCache( rCommandURL );
     430      252768 :         if ( !a.hasValue() )
     431             :         {
     432             :             // First try to ask our global commands configuration access. It also caches maybe
     433             :             // we find the entry in its cache first.
     434       79538 :             if ( m_xGenericUICommands.is() && m_xGenericUICommands->hasByName( rCommandURL ) )
     435             :             {
     436             :                 try
     437             :                 {
     438       76268 :                     return m_xGenericUICommands->getByName( rCommandURL );
     439             :                 }
     440           0 :                 catch (const com::sun::star::lang::WrappedTargetException&)
     441             :                 {
     442             :                 }
     443           0 :                 catch (const com::sun::star::container::NoSuchElementException&)
     444             :                 {
     445             :                 }
     446             :             }
     447             :         }
     448             :     }
     449           0 :     catch (const com::sun::star::container::NoSuchElementException&)
     450             :     {
     451             :     }
     452           0 :     catch (const com::sun::star::lang::WrappedTargetException&)
     453             :     {
     454             :     }
     455             : 
     456      176500 :     return a;
     457             : }
     458             : 
     459           0 : Sequence< OUString > ConfigurationAccess_UICommand::getAllCommands()
     460             : {
     461             :     // SAFE
     462           0 :     osl::MutexGuard g(m_aMutex);
     463             : 
     464           0 :     if ( !m_bConfigAccessInitialized )
     465             :     {
     466           0 :         initializeConfigAccess();
     467           0 :         m_bConfigAccessInitialized = true;
     468           0 :         fillCache();
     469             :     }
     470             : 
     471           0 :     if ( m_xConfigAccess.is() )
     472             :     {
     473           0 :         Reference< XNameAccess > xNameAccess;
     474             : 
     475             :         try
     476             :         {
     477           0 :             Sequence< OUString > aNameSeq = m_xConfigAccess->getElementNames();
     478             : 
     479           0 :             if ( m_xGenericUICommands.is() )
     480             :             {
     481             :                 // Create concat list of supported user interface commands of the module
     482           0 :                 Sequence< OUString > aGenericNameSeq = m_xGenericUICommands->getElementNames();
     483           0 :                 sal_uInt32 nCount1 = aNameSeq.getLength();
     484           0 :                 sal_uInt32 nCount2 = aGenericNameSeq.getLength();
     485             : 
     486           0 :                 aNameSeq.realloc( nCount1 + nCount2 );
     487           0 :                 OUString* pNameSeq = aNameSeq.getArray();
     488           0 :                 const OUString* pGenericSeq = aGenericNameSeq.getConstArray();
     489           0 :                 for ( sal_uInt32 i = 0; i < nCount2; i++ )
     490           0 :                     pNameSeq[nCount1+i] = pGenericSeq[i];
     491             :             }
     492             : 
     493           0 :             return aNameSeq;
     494             :         }
     495           0 :         catch (const com::sun::star::container::NoSuchElementException&)
     496             :         {
     497             :         }
     498           0 :         catch (const com::sun::star::lang::WrappedTargetException&)
     499             :         {
     500           0 :         }
     501             :     }
     502             : 
     503           0 :     return Sequence< OUString >();
     504             : }
     505             : 
     506          80 : bool ConfigurationAccess_UICommand::initializeConfigAccess()
     507             : {
     508          80 :     Sequence< Any > aArgs( 1 );
     509         160 :     PropertyValue   aPropValue;
     510             : 
     511             :     try
     512             :     {
     513          80 :         aPropValue.Name  = "nodepath";
     514          80 :         aPropValue.Value <<= m_aConfigCmdAccess;
     515          80 :         aArgs[0] <<= aPropValue;
     516             : 
     517         240 :         m_xConfigAccess = Reference< XNameAccess >( m_xConfigProvider->createInstanceWithArguments(
     518         160 :                     "com.sun.star.configuration.ConfigurationAccess", aArgs ),UNO_QUERY );
     519          80 :         if ( m_xConfigAccess.is() )
     520             :         {
     521             :             // Add as container listener
     522          80 :             Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
     523          80 :             if ( xContainer.is() )
     524             :             {
     525          80 :                 m_xConfigListener = new WeakContainerListener(this);
     526          80 :                 xContainer->addContainerListener(m_xConfigListener);
     527          80 :             }
     528             :         }
     529             : 
     530          80 :         aPropValue.Value <<= m_aConfigPopupAccess;
     531          80 :         aArgs[0] <<= aPropValue;
     532         240 :         m_xConfigAccessPopups = Reference< XNameAccess >( m_xConfigProvider->createInstanceWithArguments(
     533         160 :                     "com.sun.star.configuration.ConfigurationAccess", aArgs ),UNO_QUERY );
     534          80 :         if ( m_xConfigAccessPopups.is() )
     535             :         {
     536             :             // Add as container listener
     537          80 :             Reference< XContainer > xContainer( m_xConfigAccessPopups, UNO_QUERY );
     538          80 :             if ( xContainer.is() )
     539             :             {
     540          80 :                 m_xConfigAccessListener = new WeakContainerListener(this);
     541          80 :                 xContainer->addContainerListener(m_xConfigAccessListener);
     542          80 :             }
     543             :         }
     544             : 
     545          80 :         return true;
     546             :     }
     547           0 :     catch (const WrappedTargetException&)
     548             :     {
     549             :     }
     550           0 :     catch (const Exception&)
     551             :     {
     552             :     }
     553             : 
     554          80 :     return false;
     555             : }
     556             : 
     557             : // container.XContainerListener
     558           0 : void SAL_CALL ConfigurationAccess_UICommand::elementInserted( const ContainerEvent& ) throw(RuntimeException, std::exception)
     559             : {
     560           0 :     osl::MutexGuard g(m_aMutex);
     561           0 :     m_bCacheFilled = false;
     562           0 :     fillCache();
     563           0 : }
     564             : 
     565           0 : void SAL_CALL ConfigurationAccess_UICommand::elementRemoved( const ContainerEvent& ) throw(RuntimeException, std::exception)
     566             : {
     567           0 :     osl::MutexGuard g(m_aMutex);
     568           0 :     m_bCacheFilled = false;
     569           0 :     fillCache();
     570           0 : }
     571             : 
     572           0 : void SAL_CALL ConfigurationAccess_UICommand::elementReplaced( const ContainerEvent& ) throw(RuntimeException, std::exception)
     573             : {
     574           0 :     osl::MutexGuard g(m_aMutex);
     575           0 :     m_bCacheFilled = false;
     576           0 :     fillCache();
     577           0 : }
     578             : 
     579             : // lang.XEventListener
     580           0 : void SAL_CALL ConfigurationAccess_UICommand::disposing( const EventObject& aEvent ) throw(RuntimeException, std::exception)
     581             : {
     582             :     // SAFE
     583             :     // remove our reference to the config access
     584           0 :     osl::MutexGuard g(m_aMutex);
     585             : 
     586           0 :     Reference< XInterface > xIfac1( aEvent.Source, UNO_QUERY );
     587           0 :     Reference< XInterface > xIfac2( m_xConfigAccess, UNO_QUERY );
     588           0 :     if ( xIfac1 == xIfac2 )
     589           0 :         m_xConfigAccess.clear();
     590             :     else
     591             :     {
     592           0 :         xIfac2 = Reference< XInterface >( m_xConfigAccessPopups, UNO_QUERY );
     593           0 :         if ( xIfac1 == xIfac2 )
     594           0 :             m_xConfigAccessPopups.clear();
     595           0 :     }
     596           0 : }
     597             : 
     598          35 : UICommandDescription::UICommandDescription(const Reference< XComponentContext >& rxContext)
     599             :     : UICommandDescription_BASE(m_aMutex)
     600             :     , m_bConfigRead(false)
     601             :     , m_aPrivateResourceURL(PRIVATE_RESOURCE_URL)
     602          35 :     , m_xContext(rxContext)
     603             : {
     604          35 :     Reference< XNameAccess > xEmpty;
     605          70 :     OUString aGenericUICommand( "GenericCommands" );
     606          35 :     m_xGenericUICommands = new ConfigurationAccess_UICommand( aGenericUICommand, xEmpty, m_xContext );
     607             : 
     608          35 :     impl_fillElements("ooSetupFactoryCommandConfigRef");
     609             : 
     610             :     // insert generic commands
     611          35 :     UICommandsHashMap::iterator pIter = m_aUICommandsHashMap.find( aGenericUICommand );
     612          35 :     if ( pIter != m_aUICommandsHashMap.end() )
     613          35 :         pIter->second = m_xGenericUICommands;
     614          35 : }
     615             : 
     616           2 : UICommandDescription::UICommandDescription(const Reference< XComponentContext >& rxContext, bool)
     617             :     : UICommandDescription_BASE(m_aMutex)
     618             :     , m_bConfigRead(false)
     619           2 :     , m_xContext(rxContext)
     620             : {
     621           2 : }
     622             : 
     623         109 : UICommandDescription::~UICommandDescription()
     624             : {
     625          37 :     osl::MutexGuard g(rBHelper.rMutex);
     626          37 :     m_aModuleToCommandFileMap.clear();
     627          37 :     m_aUICommandsHashMap.clear();
     628          37 :     m_xGenericUICommands.clear();
     629          72 : }
     630          37 : void UICommandDescription::impl_fillElements(const sal_Char* _pName)
     631             : {
     632          37 :     m_xModuleManager.set( ModuleManager::create( m_xContext ) );
     633          37 :     Sequence< OUString > aElementNames = m_xModuleManager->getElementNames();
     634          74 :     Sequence< PropertyValue > aSeq;
     635          74 :     OUString                  aModuleIdentifier;
     636             : 
     637         851 :     for ( sal_Int32 i = 0; i < aElementNames.getLength(); i++ )
     638             :     {
     639         814 :         aModuleIdentifier = aElementNames[i];
     640         814 :         if ( m_xModuleManager->getByName( aModuleIdentifier ) >>= aSeq )
     641             :         {
     642         814 :             OUString aCommandStr;
     643       12254 :             for ( sal_Int32 y = 0; y < aSeq.getLength(); y++ )
     644             :             {
     645       12254 :                 if ( aSeq[y].Name.equalsAscii(_pName) )
     646             :                 {
     647         814 :                     aSeq[y].Value >>= aCommandStr;
     648         814 :                     break;
     649             :                 }
     650             :             }
     651             : 
     652             :             // Create first mapping ModuleIdentifier ==> Command File
     653         814 :             m_aModuleToCommandFileMap.insert( ModuleToCommandFileMap::value_type( aModuleIdentifier, aCommandStr ));
     654             : 
     655             :             // Create second mapping Command File ==> commands instance
     656         814 :             UICommandsHashMap::iterator pIter = m_aUICommandsHashMap.find( aCommandStr );
     657         814 :             if ( pIter == m_aUICommandsHashMap.end() )
     658         352 :                 m_aUICommandsHashMap.insert( UICommandsHashMap::value_type( aCommandStr, Reference< XNameAccess >() ));
     659             :         }
     660          37 :     } // for ( sal_Int32 i = 0; i < aElementNames.getLength(); i++ )
     661          37 : }
     662           0 : Reference< XNameAccess > UICommandDescription::impl_createConfigAccess(const OUString& _sName)
     663             : {
     664           0 :     return new ConfigurationAccess_UICommand( _sName, m_xGenericUICommands, m_xContext );
     665             : }
     666             : 
     667        4390 : Any SAL_CALL UICommandDescription::getByName( const OUString& aName )
     668             : throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     669             : {
     670        4390 :     Any a;
     671             : 
     672        8780 :     osl::MutexGuard g(rBHelper.rMutex);
     673             : 
     674        4390 :     ModuleToCommandFileMap::const_iterator pM2CIter = m_aModuleToCommandFileMap.find( aName );
     675        4390 :     if ( pM2CIter != m_aModuleToCommandFileMap.end() )
     676             :     {
     677        4356 :         OUString aCommandFile( pM2CIter->second );
     678        4356 :         UICommandsHashMap::iterator pIter = m_aUICommandsHashMap.find( aCommandFile );
     679        4356 :         if ( pIter != m_aUICommandsHashMap.end() )
     680             :         {
     681        4356 :             if ( pIter->second.is() )
     682        4309 :                 a <<= pIter->second;
     683             :             else
     684             :             {
     685          47 :                 Reference< XNameAccess > xUICommands;
     686             :                 ConfigurationAccess_UICommand* pUICommands = new ConfigurationAccess_UICommand( aCommandFile,
     687             :                                                                                                m_xGenericUICommands,
     688          47 :                                                                                                m_xContext );
     689          47 :                 xUICommands = Reference< XNameAccess >( static_cast< cppu::OWeakObject* >( pUICommands ),UNO_QUERY );
     690          47 :                 pIter->second = xUICommands;
     691          47 :                 a <<= xUICommands;
     692             :             }
     693        4356 :         }
     694             :     }
     695          34 :     else if ( !m_aPrivateResourceURL.isEmpty() && aName.startsWith( m_aPrivateResourceURL ) )
     696             :     {
     697             :         // special keys to retrieve information about a set of commands
     698          32 :         return m_xGenericUICommands->getByName( aName );
     699             :     }
     700             :     else
     701             :     {
     702           2 :         throw NoSuchElementException();
     703             :     }
     704             : 
     705        8746 :     return a;
     706             : }
     707             : 
     708           2 : Sequence< OUString > SAL_CALL UICommandDescription::getElementNames()
     709             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     710             : {
     711           2 :     osl::MutexGuard g(rBHelper.rMutex);
     712             : 
     713           2 :     Sequence< OUString > aSeq( m_aModuleToCommandFileMap.size() );
     714             : 
     715           2 :     sal_Int32 n = 0;
     716           2 :     ModuleToCommandFileMap::const_iterator pIter = m_aModuleToCommandFileMap.begin();
     717          49 :     while ( pIter != m_aModuleToCommandFileMap.end() )
     718             :     {
     719          45 :         aSeq[n++] = pIter->first;
     720          45 :         ++pIter;
     721             :     }
     722             : 
     723           2 :     return aSeq;
     724             : }
     725             : 
     726           4 : sal_Bool SAL_CALL UICommandDescription::hasByName( const OUString& aName )
     727             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     728             : {
     729           4 :     osl::MutexGuard g(rBHelper.rMutex);
     730             : 
     731           4 :     ModuleToCommandFileMap::const_iterator pIter = m_aModuleToCommandFileMap.find( aName );
     732           4 :     return ( pIter != m_aModuleToCommandFileMap.end() );
     733             : }
     734             : 
     735             : // XElementAccess
     736           2 : Type SAL_CALL UICommandDescription::getElementType()
     737             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     738             : {
     739           2 :     return( ::getCppuType( (const Reference< XNameAccess >*)NULL ) );
     740             : }
     741             : 
     742           2 : sal_Bool SAL_CALL UICommandDescription::hasElements()
     743             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     744             : {
     745             :     // generic UI commands are always available!
     746           2 :     return sal_True;
     747             : }
     748             : 
     749             : } // namespace framework
     750             : 
     751             : namespace {
     752             : 
     753          35 : struct Instance {
     754          35 :     explicit Instance(
     755             :         css::uno::Reference<css::uno::XComponentContext> const & context):
     756             :         instance(static_cast<cppu::OWeakObject *>(
     757          35 :                     new framework::UICommandDescription(context)))
     758             :     {
     759          35 :     }
     760             : 
     761             :     css::uno::Reference<css::uno::XInterface> instance;
     762             : };
     763             : 
     764             : struct Singleton:
     765             :     public rtl::StaticWithArg<
     766             :         Instance, css::uno::Reference<css::uno::XComponentContext>, Singleton>
     767             : {};
     768             : 
     769             : }
     770             : 
     771             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     772          36 : com_sun_star_comp_framework_UICommandDescription_get_implementation(
     773             :     css::uno::XComponentContext *context,
     774             :     css::uno::Sequence<css::uno::Any> const &)
     775             : {
     776             :     return cppu::acquire(static_cast<cppu::OWeakObject *>(
     777          36 :                 Singleton::get(context).instance.get()));
     778             : }
     779             : 
     780             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10