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

Generated by: LCOV version 1.10