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

Generated by: LCOV version 1.10