LCOV - code coverage report
Current view: top level - svx/source/unodraw - shapepropertynotifier.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 35 55 63.6 %
Date: 2014-04-11 Functions: 10 14 71.4 %
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 "svx/shapepropertynotifier.hxx"
      22             : 
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : 
      25             : #include <cppuhelper/interfacecontainer.hxx>
      26             : #include <cppuhelper/weak.hxx>
      27             : #include <tools/diagnose_ex.h>
      28             : 
      29             : #include <boost/unordered_map.hpp>
      30             : 
      31             : namespace
      32             : {
      33             : 
      34             :     struct ShapePropertyHash
      35             :     {
      36      536955 :         size_t operator()( ::svx::ShapeProperty __x ) const
      37             :         {
      38      536955 :             return size_t( __x );
      39             :         }
      40             :     };
      41             : }
      42             : 
      43             : 
      44             : namespace svx
      45             : {
      46             : 
      47             : 
      48             :     using ::com::sun::star::uno::Reference;
      49             :     using ::com::sun::star::uno::XInterface;
      50             :     using ::com::sun::star::uno::UNO_QUERY;
      51             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      52             :     using ::com::sun::star::uno::UNO_SET_THROW;
      53             :     using ::com::sun::star::uno::Exception;
      54             :     using ::com::sun::star::uno::RuntimeException;
      55             :     using ::com::sun::star::uno::Any;
      56             :     using ::com::sun::star::uno::makeAny;
      57             :     using ::com::sun::star::uno::Sequence;
      58             :     using ::com::sun::star::uno::Type;
      59             :     using ::com::sun::star::beans::PropertyChangeEvent;
      60             :     using ::com::sun::star::beans::XPropertyChangeListener;
      61             :     using ::com::sun::star::lang::EventObject;
      62             :     using ::com::sun::star::beans::XPropertySet;
      63             : 
      64             :     typedef ::boost::unordered_map< ShapeProperty, PPropertyValueProvider, ShapePropertyHash  >    PropertyProviders;
      65             : 
      66             :     typedef ::cppu::OMultiTypeInterfaceContainerHelperVar   <   OUString
      67             :                                                             ,   OUStringHash
      68             :                                                             >   PropertyChangeListenerContainer;
      69             : 
      70             : 
      71             :     //= IPropertyValueProvider
      72             : 
      73      209049 :     IPropertyValueProvider::~IPropertyValueProvider()
      74             :     {
      75      209049 :     }
      76             : 
      77             : 
      78             :     //= PropertyChangeNotifier_Data
      79             : 
      80      102283 :     struct PropertyChangeNotifier_Data
      81             :     {
      82             :         ::cppu::OWeakObject&            m_rContext;
      83             :         PropertyProviders               m_aProviders;
      84             :         PropertyChangeListenerContainer m_aPropertyChangeListeners;
      85             : 
      86      104478 :         PropertyChangeNotifier_Data( ::cppu::OWeakObject& _rContext, ::osl::Mutex& _rMutex )
      87             :             :m_rContext( _rContext )
      88      104478 :             ,m_aPropertyChangeListeners( _rMutex )
      89             :         {
      90      104478 :         }
      91             :     };
      92             : 
      93             :     //= PropertyValueProvider
      94             : 
      95             : 
      96      323345 :     OUString PropertyValueProvider::getPropertyName() const
      97             :     {
      98      323345 :         return m_sPropertyName;
      99             :     }
     100             : 
     101             : 
     102           0 :     void PropertyValueProvider::getCurrentValue( Any& _out_rValue ) const
     103             :     {
     104           0 :         Reference< XPropertySet > xContextProps( const_cast< PropertyValueProvider* >( this )->m_rContext, UNO_QUERY_THROW );
     105           0 :         _out_rValue = xContextProps->getPropertyValue( getPropertyName() );
     106           0 :     }
     107             : 
     108             : 
     109             :     //= PropertyChangeNotifier
     110             : 
     111             : 
     112      104478 :     PropertyChangeNotifier::PropertyChangeNotifier( ::cppu::OWeakObject& _rOwner, ::osl::Mutex& _rMutex )
     113      104478 :         :m_pData( new PropertyChangeNotifier_Data( _rOwner, _rMutex ) )
     114             :     {
     115      104478 :     }
     116             : 
     117             : 
     118      102283 :     PropertyChangeNotifier::~PropertyChangeNotifier()
     119             :     {
     120      102283 :     }
     121             : 
     122             : 
     123      213449 :     void PropertyChangeNotifier::registerProvider( const ShapeProperty _eProperty, const PPropertyValueProvider _pProvider )
     124             :     {
     125      213449 :         ENSURE_OR_THROW( _eProperty != eInvalidShapeProperty, "Illegal ShapeProperty value!" );
     126      213449 :         ENSURE_OR_THROW( !!_pProvider, "NULL factory not allowed." );
     127             : 
     128             :         OSL_ENSURE( m_pData->m_aProviders.find( _eProperty ) == m_pData->m_aProviders.end(),
     129             :             "PropertyChangeNotifier::registerProvider: factory for this ID already present!" );
     130             : 
     131      213449 :         m_pData->m_aProviders[ _eProperty ] = _pProvider;
     132      213449 :     }
     133             : 
     134             : 
     135      323506 :     void PropertyChangeNotifier::notifyPropertyChange( const ShapeProperty _eProperty ) const
     136             :     {
     137      323506 :         ENSURE_OR_THROW( _eProperty != eInvalidShapeProperty, "Illegal ShapeProperty value!" );
     138             : 
     139      323506 :         PropertyProviders::const_iterator provPos = m_pData->m_aProviders.find( _eProperty );
     140             :         OSL_ENSURE( provPos != m_pData->m_aProviders.end(), "PropertyChangeNotifier::notifyPropertyChange: no factory!" );
     141      323506 :         if ( provPos == m_pData->m_aProviders.end() )
     142      323667 :             return;
     143             : 
     144      323345 :         OUString sPropertyName( provPos->second->getPropertyName() );
     145             : 
     146      323345 :         ::cppu::OInterfaceContainerHelper* pPropListeners = m_pData->m_aPropertyChangeListeners.getContainer( sPropertyName );
     147      323345 :         ::cppu::OInterfaceContainerHelper* pAllListeners = m_pData->m_aPropertyChangeListeners.getContainer( OUString() );
     148      323345 :         if ( !pPropListeners && !pAllListeners )
     149      323345 :             return;
     150             : 
     151             :         try
     152             :         {
     153           0 :             PropertyChangeEvent aEvent;
     154           0 :             aEvent.Source = m_pData->m_rContext;
     155             :             // Handle/OldValue not supported
     156           0 :             aEvent.PropertyName = provPos->second->getPropertyName();
     157           0 :             provPos->second->getCurrentValue( aEvent.NewValue );
     158             : 
     159           0 :             if ( pPropListeners )
     160           0 :                 pPropListeners->notifyEach( &XPropertyChangeListener::propertyChange, aEvent );
     161           0 :             if ( pAllListeners )
     162           0 :                 pAllListeners->notifyEach( &XPropertyChangeListener::propertyChange, aEvent );
     163             :         }
     164           0 :         catch( const Exception& )
     165             :         {
     166             :             DBG_UNHANDLED_EXCEPTION();
     167           0 :         }
     168             :     }
     169             : 
     170             : 
     171           0 :     void PropertyChangeNotifier::addPropertyChangeListener( const OUString& _rPropertyName, const Reference< XPropertyChangeListener >& _rxListener )
     172             :     {
     173           0 :         m_pData->m_aPropertyChangeListeners.addInterface( _rPropertyName, _rxListener );
     174           0 :     }
     175             : 
     176             : 
     177           0 :     void PropertyChangeNotifier::removePropertyChangeListener( const OUString& _rPropertyName, const Reference< XPropertyChangeListener >& _rxListener )
     178             :     {
     179           0 :         m_pData->m_aPropertyChangeListeners.removeInterface( _rPropertyName, _rxListener );
     180           0 :     }
     181             : 
     182             : 
     183         418 :     void PropertyChangeNotifier::disposing()
     184             :     {
     185         418 :         EventObject aEvent;
     186         418 :         aEvent.Source = m_pData->m_rContext;
     187         418 :         m_pData->m_aPropertyChangeListeners.disposeAndClear( aEvent );
     188         418 :     }
     189             : 
     190             : 
     191             : } // namespace svx
     192             : 
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10