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

Generated by: LCOV version 1.10