LCOV - code coverage report
Current view: top level - libreoffice/framework/source/fwe/classes - rootactiontriggercontainer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 129 0.0 %
Date: 2012-12-17 Functions: 0 26 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 <classes/rootactiontriggercontainer.hxx>
      22             : #include <classes/actiontriggercontainer.hxx>
      23             : #include <classes/actiontriggerpropertyset.hxx>
      24             : #include <classes/actiontriggerseparatorpropertyset.hxx>
      25             : #include <framework/actiontriggerhelper.hxx>
      26             : #include <threadhelp/resetableguard.hxx>
      27             : #include <osl/mutex.hxx>
      28             : #include <vcl/svapp.hxx>
      29             : #include <cppuhelper/typeprovider.hxx>
      30             : 
      31             : 
      32             : using namespace cppu;
      33             : using namespace com::sun::star::uno;
      34             : using namespace com::sun::star::lang;
      35             : using namespace com::sun::star::container;
      36             : using namespace com::sun::star::beans;
      37             : 
      38             : 
      39             : namespace framework
      40             : {
      41             : 
      42           0 : static Sequence< sal_Int8 > impl_getStaticIdentifier()
      43             : {
      44             :     static sal_uInt8 pGUID[16] = { 0x17, 0x0F, 0xA2, 0xC9, 0xCA, 0x50, 0x4A, 0xD3, 0xA6, 0x3B, 0x39, 0x99, 0xC5, 0x96, 0x43, 0x27 };
      45           0 :     static ::com::sun::star::uno::Sequence< sal_Int8 > seqID((sal_Int8*)pGUID,16) ;
      46           0 :     return seqID ;
      47             : }
      48             : 
      49             : 
      50           0 : RootActionTriggerContainer::RootActionTriggerContainer( const Menu* pMenu, const ::rtl::OUString* pMenuIdentifier, const Reference< XMultiServiceFactory >& rServiceManager ) :
      51             :     PropertySetContainer( rServiceManager )
      52             :     ,   m_bContainerCreated( sal_False )
      53             :     ,   m_bContainerChanged( sal_False )
      54             :     ,   m_bInContainerCreation( sal_False )
      55             :     ,   m_pMenu( pMenu )
      56           0 :     ,   m_pMenuIdentifier( pMenuIdentifier )
      57             : {
      58           0 : }
      59             : 
      60           0 : RootActionTriggerContainer::~RootActionTriggerContainer()
      61             : {
      62           0 : }
      63             : 
      64             : // XInterface
      65           0 : Any SAL_CALL RootActionTriggerContainer::queryInterface( const Type& aType )
      66             : throw ( RuntimeException )
      67             : {
      68             :     Any a = ::cppu::queryInterface(
      69             :                 aType ,
      70             :                 (static_cast< XMultiServiceFactory*   >(this)),
      71             :                 (static_cast< XServiceInfo*           >(this)),
      72             :                 (static_cast< XUnoTunnel*             >(this)),
      73             :                 (static_cast< XTypeProvider*          >(this)),
      74           0 :                 (static_cast< XNamed*                 >(this)));
      75             : 
      76           0 :     if( a.hasValue() )
      77             :     {
      78           0 :         return a;
      79             :     }
      80             : 
      81           0 :     return PropertySetContainer::queryInterface( aType );
      82             : }
      83             : 
      84           0 : void SAL_CALL RootActionTriggerContainer::acquire() throw ()
      85             : {
      86           0 :     PropertySetContainer::acquire();
      87           0 : }
      88             : 
      89           0 : void SAL_CALL RootActionTriggerContainer::release() throw ()
      90             : {
      91           0 :     PropertySetContainer::release();
      92           0 : }
      93             : 
      94             : // XMultiServiceFactory
      95           0 : Reference< XInterface > SAL_CALL RootActionTriggerContainer::createInstance( const ::rtl::OUString& aServiceSpecifier )
      96             : throw ( Exception,  RuntimeException )
      97             : {
      98           0 :     if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGER ))
      99           0 :         return (OWeakObject *)( new ActionTriggerPropertySet( m_xServiceManager ));
     100           0 :     else if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGERCONTAINER ))
     101           0 :         return (OWeakObject *)( new ActionTriggerContainer( m_xServiceManager ));
     102           0 :     else if ( aServiceSpecifier.equalsAscii( SERVICENAME_ACTIONTRIGGERSEPARATOR ))
     103           0 :         return (OWeakObject *)( new ActionTriggerSeparatorPropertySet( m_xServiceManager ));
     104             :     else
     105           0 :         throw com::sun::star::uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unknown service specifier!" )), (OWeakObject *)this );
     106             : }
     107             : 
     108           0 : Reference< XInterface > SAL_CALL RootActionTriggerContainer::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const Sequence< Any >& /*Arguments*/ )
     109             : throw ( Exception, RuntimeException )
     110             : {
     111           0 :     return createInstance( ServiceSpecifier );
     112             : }
     113             : 
     114           0 : Sequence< ::rtl::OUString > SAL_CALL RootActionTriggerContainer::getAvailableServiceNames()
     115             : throw ( RuntimeException )
     116             : {
     117           0 :     Sequence< ::rtl::OUString > aSeq( 3 );
     118             : 
     119           0 :     aSeq[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGER ));
     120           0 :     aSeq[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERCONTAINER ));
     121           0 :     aSeq[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERSEPARATOR ));
     122             : 
     123           0 :     return aSeq;
     124             : }
     125             : 
     126             : 
     127             : // XIndexContainer
     128           0 : void SAL_CALL RootActionTriggerContainer::insertByIndex( sal_Int32 Index, const Any& Element )
     129             : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
     130             : {
     131           0 :     ResetableGuard aGuard( m_aLock );
     132             : 
     133           0 :     if ( !m_bContainerCreated )
     134           0 :         FillContainer();
     135             : 
     136           0 :     if ( !m_bInContainerCreation )
     137           0 :         m_bContainerChanged = sal_True;
     138           0 :     PropertySetContainer::insertByIndex( Index, Element );
     139           0 : }
     140             : 
     141           0 : void SAL_CALL RootActionTriggerContainer::removeByIndex( sal_Int32 Index )
     142             : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
     143             : {
     144           0 :     ResetableGuard aGuard( m_aLock );
     145             : 
     146           0 :     if ( !m_bContainerCreated )
     147           0 :         FillContainer();
     148             : 
     149           0 :     if ( !m_bInContainerCreation )
     150           0 :         m_bContainerChanged = sal_True;
     151           0 :     PropertySetContainer::removeByIndex( Index );
     152           0 : }
     153             : 
     154             : 
     155             : // XIndexReplace
     156           0 : void SAL_CALL RootActionTriggerContainer::replaceByIndex( sal_Int32 Index, const Any& Element )
     157             : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
     158             : {
     159           0 :     ResetableGuard aGuard( m_aLock );
     160             : 
     161           0 :     if ( !m_bContainerCreated )
     162           0 :         FillContainer();
     163             : 
     164           0 :     if ( !m_bInContainerCreation )
     165           0 :         m_bContainerChanged = sal_True;
     166           0 :     PropertySetContainer::replaceByIndex( Index, Element );
     167           0 : }
     168             : 
     169             : 
     170             : // XIndexAccess
     171           0 : sal_Int32 SAL_CALL RootActionTriggerContainer::getCount()
     172             : throw ( RuntimeException )
     173             : {
     174           0 :     ResetableGuard aGuard( m_aLock );
     175             : 
     176           0 :     if ( !m_bContainerCreated )
     177             :     {
     178           0 :         if ( m_pMenu )
     179             :         {
     180           0 :             SolarMutexGuard aSolarMutexGuard;
     181           0 :             return m_pMenu->GetItemCount();
     182             :         }
     183             :         else
     184           0 :             return 0;
     185             :     }
     186             :     else
     187             :     {
     188           0 :         return PropertySetContainer::getCount();
     189           0 :     }
     190             : }
     191             : 
     192           0 : Any SAL_CALL RootActionTriggerContainer::getByIndex( sal_Int32 Index )
     193             : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
     194             : {
     195           0 :     ResetableGuard aGuard( m_aLock );
     196             : 
     197           0 :     if ( !m_bContainerCreated )
     198           0 :         FillContainer();
     199             : 
     200           0 :     return PropertySetContainer::getByIndex( Index );
     201             : }
     202             : 
     203             : 
     204             : // XElementAccess
     205           0 : Type SAL_CALL RootActionTriggerContainer::getElementType()
     206             :     throw (::com::sun::star::uno::RuntimeException)
     207             : {
     208           0 :     return ::getCppuType(( Reference< XPropertySet >*)0);
     209             : }
     210             : 
     211           0 : sal_Bool SAL_CALL RootActionTriggerContainer::hasElements()
     212             : throw (::com::sun::star::uno::RuntimeException)
     213             : {
     214           0 :     if ( m_pMenu )
     215             :     {
     216           0 :         SolarMutexGuard aSolarMutexGuard;
     217           0 :         return ( m_pMenu->GetItemCount() > 0 );
     218             :     }
     219             : 
     220           0 :     return sal_False;
     221             : }
     222             : 
     223             : 
     224             : // XServiceInfo
     225           0 : ::rtl::OUString SAL_CALL RootActionTriggerContainer::getImplementationName()
     226             : throw ( RuntimeException )
     227             : {
     228           0 :     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATIONNAME_ROOTACTIONTRIGGERCONTAINER ));
     229             : }
     230             : 
     231           0 : sal_Bool SAL_CALL RootActionTriggerContainer::supportsService( const ::rtl::OUString& ServiceName )
     232             : throw ( RuntimeException )
     233             : {
     234           0 :     if ( ServiceName.equalsAscii( SERVICENAME_ACTIONTRIGGERCONTAINER ))
     235           0 :         return sal_True;
     236             : 
     237           0 :     return sal_False;
     238             : }
     239             : 
     240           0 : Sequence< ::rtl::OUString > SAL_CALL RootActionTriggerContainer::getSupportedServiceNames()
     241             : throw ( RuntimeException )
     242             : {
     243           0 :     Sequence< ::rtl::OUString > seqServiceNames( 1 );
     244             : 
     245           0 :     seqServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERCONTAINER ));
     246           0 :     return seqServiceNames;
     247             : }
     248             : 
     249             : // XUnoTunnel
     250           0 : sal_Int64 SAL_CALL RootActionTriggerContainer::getSomething( const Sequence< sal_Int8 >& aIdentifier ) throw ( RuntimeException )
     251             : {
     252           0 :     if ( aIdentifier == impl_getStaticIdentifier() )
     253           0 :         return reinterpret_cast< sal_Int64 >( this );
     254             :     else
     255           0 :         return 0;
     256             : }
     257             : 
     258             : // XTypeProvider
     259           0 : Sequence< Type > SAL_CALL RootActionTriggerContainer::getTypes() throw ( RuntimeException )
     260             : {
     261             :     // Optimize this method !
     262             :     // We initialize a static variable only one time. And we don't must use a mutex at every call!
     263             :     // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
     264             :     static ::cppu::OTypeCollection* pTypeCollection = NULL ;
     265             : 
     266           0 :     if ( pTypeCollection == NULL )
     267             :     {
     268             :         // Ready for multithreading; get global mutex for first call of this method only! see before
     269           0 :         osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
     270             : 
     271             :         // Control these pointer again ... it can be, that another instance will be faster then these!
     272           0 :         if ( pTypeCollection == NULL )
     273             :         {
     274             :             // Create a static typecollection ...
     275             :             static ::cppu::OTypeCollection aTypeCollection(
     276           0 :                         ::getCppuType(( const Reference< XMultiServiceFactory   >*)NULL ) ,
     277           0 :                         ::getCppuType(( const Reference< XIndexContainer        >*)NULL ) ,
     278           0 :                         ::getCppuType(( const Reference< XServiceInfo           >*)NULL ) ,
     279           0 :                         ::getCppuType(( const Reference< XTypeProvider          >*)NULL ) ,
     280           0 :                         ::getCppuType(( const Reference< XUnoTunnel             >*)NULL ) ,
     281           0 :                         ::getCppuType(( const Reference< XNamed                 >*)NULL )) ;
     282             : 
     283             :             // ... and set his address to static pointer!
     284           0 :             pTypeCollection = &aTypeCollection ;
     285           0 :         }
     286             :     }
     287             : 
     288           0 :     return pTypeCollection->getTypes() ;
     289             : }
     290             : 
     291           0 : Sequence< sal_Int8 > SAL_CALL RootActionTriggerContainer::getImplementationId() throw ( RuntimeException )
     292             : {
     293             :     // Create one Id for all instances of this class.
     294             :     // Use ethernet address to do this! (sal_True)
     295             : 
     296             :     // Optimize this method
     297             :     // We initialize a static variable only one time. And we don't must use a mutex at every call!
     298             :     // For the first call; pID is NULL - for the second call pID is different from NULL!
     299             :     static ::cppu::OImplementationId* pID = NULL ;
     300             : 
     301           0 :     if ( pID == NULL )
     302             :     {
     303             :         // Ready for multithreading; get global mutex for first call of this method only! see before
     304           0 :         osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
     305             : 
     306             :         // Control these pointer again ... it can be, that another instance will be faster then these!
     307           0 :         if ( pID == NULL )
     308             :         {
     309             :             // Create a new static ID ...
     310           0 :             static ::cppu::OImplementationId aID( sal_False ) ;
     311             :             // ... and set his address to static pointer!
     312           0 :             pID = &aID ;
     313           0 :         }
     314             :     }
     315             : 
     316           0 :     return pID->getImplementationId() ;
     317             : }
     318             : 
     319             : // private implementation helper
     320           0 : void RootActionTriggerContainer::FillContainer()
     321             : {
     322           0 :     m_bContainerCreated = sal_True;
     323           0 :     m_bInContainerCreation = sal_True;
     324           0 :     Reference<XIndexContainer> xXIndexContainer( (OWeakObject *)this, UNO_QUERY );
     325             :     ActionTriggerHelper::FillActionTriggerContainerFromMenu(
     326             :         xXIndexContainer,
     327           0 :         m_pMenu );
     328           0 :     m_bInContainerCreation = sal_False;
     329           0 : }
     330           0 : ::rtl::OUString RootActionTriggerContainer::getName() throw ( RuntimeException )
     331             : {
     332           0 :     ::rtl::OUString sRet;
     333           0 :     if( m_pMenuIdentifier )
     334           0 :         sRet = *m_pMenuIdentifier;
     335           0 :     return sRet;
     336             : }
     337             : 
     338           0 : void RootActionTriggerContainer::setName( const ::rtl::OUString& ) throw ( RuntimeException)
     339             : {
     340           0 :     throw RuntimeException();
     341             : }
     342             : }
     343             : 
     344             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10