LCOV - code coverage report
Current view: top level - toolkit/source/controls - eventcontainer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 5 85 5.9 %
Date: 2012-08-25 Functions: 2 11 18.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 116 0.0 %

           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                 :            : #include <osl/mutex.hxx>
      30                 :            : #include <cppuhelper/queryinterface.hxx>
      31                 :            : #include <cppuhelper/weak.hxx>
      32                 :            : #include <cppuhelper/factory.hxx>
      33                 :            : #include <cppuhelper/interfacecontainer.hxx>
      34                 :            : 
      35                 :            : #include "toolkit/controls/eventcontainer.hxx"
      36                 :            : #include <com/sun/star/script/ScriptEventDescriptor.hpp>
      37                 :            : 
      38                 :            : 
      39                 :            : using namespace com::sun::star::uno;
      40                 :            : using namespace com::sun::star::lang;
      41                 :            : using namespace com::sun::star::container;
      42                 :            : using namespace com::sun::star::registry;
      43                 :            : using namespace com::sun::star::script;
      44                 :            : using namespace cppu;
      45                 :            : using namespace osl;
      46                 :            : using namespace std;
      47                 :            : 
      48                 :            : using ::rtl::OUString;
      49                 :            : 
      50                 :            : namespace toolkit
      51                 :            : {
      52                 :            : 
      53                 :            : // Methods XElementAccess
      54                 :          0 : Type NameContainer_Impl::getElementType()
      55                 :            :     throw(RuntimeException)
      56                 :            : {
      57                 :          0 :     return mType;
      58                 :            : }
      59                 :            : 
      60                 :          0 : sal_Bool NameContainer_Impl::hasElements()
      61                 :            :     throw(RuntimeException)
      62                 :            : {
      63                 :          0 :     sal_Bool bRet = (mnElementCount > 0);
      64                 :          0 :     return bRet;
      65                 :            : }
      66                 :            : 
      67                 :            : // Methods XNameAccess
      68                 :          0 : Any NameContainer_Impl::getByName( const OUString& aName )
      69                 :            :     throw(NoSuchElementException, WrappedTargetException, RuntimeException)
      70                 :            : {
      71         [ #  # ]:          0 :     NameContainerNameMap::iterator aIt = mHashMap.find( aName );
      72 [ #  # ][ #  # ]:          0 :     if( aIt == mHashMap.end() )
      73                 :            :     {
      74         [ #  # ]:          0 :         throw NoSuchElementException();
      75                 :            :     }
      76         [ #  # ]:          0 :     sal_Int32 iHashResult = (*aIt).second;
      77                 :          0 :     Any aRetAny = mValues.getConstArray()[ iHashResult ];
      78                 :          0 :     return aRetAny;
      79                 :            : }
      80                 :            : 
      81                 :          6 : Sequence< OUString > NameContainer_Impl::getElementNames()
      82                 :            :     throw(RuntimeException)
      83                 :            : {
      84                 :          6 :     return mNames;
      85                 :            : }
      86                 :            : 
      87                 :          0 : sal_Bool NameContainer_Impl::hasByName( const OUString& aName )
      88                 :            :     throw(RuntimeException)
      89                 :            : {
      90         [ #  # ]:          0 :     NameContainerNameMap::iterator aIt = mHashMap.find( aName );
      91         [ #  # ]:          0 :     sal_Bool bRet = ( aIt != mHashMap.end() );
      92                 :          0 :     return bRet;
      93                 :            : }
      94                 :            : 
      95                 :            : 
      96                 :            : // Methods XNameReplace
      97                 :          0 : void NameContainer_Impl::replaceByName( const OUString& aName, const Any& aElement )
      98                 :            :     throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
      99                 :            : {
     100                 :          0 :     Type aAnyType = aElement.getValueType();
     101         [ #  # ]:          0 :     if( mType != aAnyType )
     102         [ #  # ]:          0 :         throw IllegalArgumentException();
     103                 :            : 
     104         [ #  # ]:          0 :     NameContainerNameMap::iterator aIt = mHashMap.find( aName );
     105 [ #  # ][ #  # ]:          0 :     if( aIt == mHashMap.end() )
     106                 :            :     {
     107         [ #  # ]:          0 :         throw NoSuchElementException();
     108                 :            :     }
     109         [ #  # ]:          0 :     sal_Int32 iHashResult = (*aIt).second;
     110                 :          0 :     Any aOldElement = mValues.getConstArray()[ iHashResult ];
     111         [ #  # ]:          0 :     mValues.getArray()[ iHashResult ] = aElement;
     112                 :            : 
     113                 :            :     // Fire event
     114         [ #  # ]:          0 :     ContainerEvent aEvent;
     115 [ #  # ][ #  # ]:          0 :     aEvent.Source = *this;
     116         [ #  # ]:          0 :     aEvent.Element <<= aElement;
     117                 :          0 :     aEvent.ReplacedElement = aOldElement;
     118         [ #  # ]:          0 :     aEvent.Accessor <<= aName;
     119 [ #  # ][ #  # ]:          0 :     maContainerListeners.elementReplaced( aEvent );
     120                 :          0 : }
     121                 :            : 
     122                 :            : 
     123                 :            : // Methods XNameContainer
     124                 :          0 : void NameContainer_Impl::insertByName( const OUString& aName, const Any& aElement )
     125                 :            :     throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
     126                 :            : {
     127                 :          0 :     Type aAnyType = aElement.getValueType();
     128         [ #  # ]:          0 :     if( mType != aAnyType )
     129         [ #  # ]:          0 :         throw IllegalArgumentException();
     130                 :            : 
     131         [ #  # ]:          0 :     NameContainerNameMap::iterator aIt = mHashMap.find( aName );
     132 [ #  # ][ #  # ]:          0 :     if( aIt != mHashMap.end() )
     133                 :            :     {
     134         [ #  # ]:          0 :         throw ElementExistException();
     135                 :            :     }
     136                 :            : 
     137                 :          0 :     sal_Int32 nCount = mNames.getLength();
     138         [ #  # ]:          0 :     mNames.realloc( nCount + 1 );
     139         [ #  # ]:          0 :     mValues.realloc( nCount + 1 );
     140         [ #  # ]:          0 :     mNames.getArray()[ nCount ] = aName;
     141         [ #  # ]:          0 :     mValues.getArray()[ nCount ] = aElement;
     142         [ #  # ]:          0 :     mHashMap[ aName ] = nCount;
     143                 :            : 
     144                 :            :     // Fire event
     145         [ #  # ]:          0 :     ContainerEvent aEvent;
     146 [ #  # ][ #  # ]:          0 :     aEvent.Source = *this;
     147         [ #  # ]:          0 :     aEvent.Element <<= aElement;
     148         [ #  # ]:          0 :     aEvent.Accessor <<= aName;
     149 [ #  # ][ #  # ]:          0 :     maContainerListeners.elementInserted( aEvent );
     150                 :          0 : }
     151                 :            : 
     152                 :          0 : void NameContainer_Impl::removeByName( const OUString& Name )
     153                 :            :     throw(NoSuchElementException, WrappedTargetException, RuntimeException)
     154                 :            : {
     155         [ #  # ]:          0 :     NameContainerNameMap::iterator aIt = mHashMap.find( Name );
     156 [ #  # ][ #  # ]:          0 :     if( aIt == mHashMap.end() )
     157                 :            :     {
     158         [ #  # ]:          0 :         throw NoSuchElementException();
     159                 :            :     }
     160                 :            : 
     161         [ #  # ]:          0 :     sal_Int32 iHashResult = (*aIt).second;
     162                 :          0 :     Any aOldElement = mValues.getConstArray()[ iHashResult ];
     163                 :            : 
     164                 :            :     // Fire event
     165         [ #  # ]:          0 :     ContainerEvent aEvent;
     166 [ #  # ][ #  # ]:          0 :     aEvent.Source = *this;
     167                 :          0 :     aEvent.Element = aOldElement;
     168         [ #  # ]:          0 :     aEvent.Accessor <<= Name;
     169         [ #  # ]:          0 :     maContainerListeners.elementRemoved( aEvent );
     170                 :            : 
     171         [ #  # ]:          0 :     mHashMap.erase( aIt );
     172                 :          0 :     sal_Int32 iLast = mNames.getLength() - 1;
     173         [ #  # ]:          0 :     if( iLast != iHashResult )
     174                 :            :     {
     175         [ #  # ]:          0 :         OUString* pNames = mNames.getArray();
     176         [ #  # ]:          0 :         Any* pValues = mValues.getArray();
     177                 :          0 :         pNames[ iHashResult ] = pNames[ iLast ];
     178                 :          0 :         pValues[ iHashResult ] = pValues[ iLast ];
     179         [ #  # ]:          0 :         mHashMap[ pNames[ iHashResult ] ] = iHashResult;
     180                 :            :     }
     181         [ #  # ]:          0 :     mNames.realloc( iLast );
     182 [ #  # ][ #  # ]:          0 :     mValues.realloc( iLast );
     183                 :            : 
     184                 :          0 : }
     185                 :            : 
     186                 :            : // Methods XContainer
     187                 :          0 : void NameContainer_Impl::addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& l ) throw(::com::sun::star::uno::RuntimeException)
     188                 :            : {
     189                 :          0 :     maContainerListeners.addInterface( l );
     190                 :          0 : }
     191                 :            : 
     192                 :          0 : void NameContainer_Impl::removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& l ) throw(::com::sun::star::uno::RuntimeException)
     193                 :            : {
     194                 :          0 :     maContainerListeners.removeInterface( l );
     195                 :          0 : }
     196                 :            : 
     197                 :            : 
     198                 :            : 
     199                 :            : // Ctor
     200                 :         12 : ScriptEventContainer::ScriptEventContainer( void )
     201                 :         12 :     : NameContainer_Impl( getCppuType( (ScriptEventDescriptor*) NULL ) )
     202                 :            : {
     203                 :         12 : }
     204                 :            : 
     205                 :            : }
     206                 :            : 
     207                 :            : 
     208                 :            : 
     209                 :            : 
     210                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10