LCOV - code coverage report
Current view: top level - libreoffice/reportdesign/source/core/sdr - PropertyForward.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 92 0.0 %
Date: 2012-12-27 Functions: 0 8 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             : #include "PropertyForward.hxx"
      20             : #include <com/sun/star/beans/PropertyValue.hpp>
      21             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      22             : #include <comphelper/property.hxx>
      23             : #include <com/sun/star/sdbcx/XAppend.hpp>
      24             : #include <tools/debug.hxx>
      25             : #include <tools/diagnose_ex.h>
      26             : #include "corestrings.hrc"
      27             : #include <o3tl/compat_functional.hxx>
      28             : 
      29             : //........................................................................
      30             : namespace rptui
      31             : {
      32             : //........................................................................
      33             :     using namespace ::com::sun::star::uno;
      34             :     using namespace ::com::sun::star::beans;
      35             :     using namespace reportdesign;
      36             : 
      37             : DBG_NAME( rpt_OPropertyMediator )
      38           0 : OPropertyMediator::OPropertyMediator(const Reference< XPropertySet>& _xSource
      39             :                                      ,const Reference< XPropertySet>& _xDest
      40             :                                      ,const TPropertyNamePair& _aNameMap
      41             :                                      ,sal_Bool _bReverse)
      42             :                                 : OPropertyForward_Base(m_aMutex)
      43             :                                 ,m_aNameMap(_aNameMap)
      44             :                                 ,m_xSource(_xSource)
      45             :                                 ,m_xDest(_xDest)
      46           0 :                                 ,m_bInChange(sal_False)
      47             : {
      48             :     DBG_CTOR( rpt_OPropertyMediator,NULL);
      49           0 :     osl_atomic_increment(&m_refCount);
      50             :     OSL_ENSURE(m_xDest.is(),"Dest is NULL!");
      51             :     OSL_ENSURE(m_xSource.is(),"Source is NULL!");
      52           0 :     if ( m_xDest.is() && m_xSource.is() )
      53             :     {
      54             :         try
      55             :         {
      56           0 :             m_xDestInfo = m_xDest->getPropertySetInfo();
      57           0 :             m_xSourceInfo = m_xSource->getPropertySetInfo();
      58           0 :             if ( _bReverse )
      59             :             {
      60           0 :                 ::comphelper::copyProperties(m_xDest,m_xSource);
      61           0 :                 TPropertyNamePair::iterator aIter = m_aNameMap.begin();
      62           0 :                 TPropertyNamePair::iterator aEnd = m_aNameMap.end();
      63           0 :                 for (; aIter != aEnd; ++aIter)
      64             :                 {
      65           0 :                     Property aProp = m_xSourceInfo->getPropertyByName(aIter->first);
      66           0 :                     if (0 == (aProp.Attributes & PropertyAttribute::READONLY))
      67             :                     {
      68           0 :                         Any aValue = _xDest->getPropertyValue(aIter->second.first);
      69           0 :                         if ( 0 != (aProp.Attributes & PropertyAttribute::MAYBEVOID) || aValue.hasValue() )
      70           0 :                             _xSource->setPropertyValue(aIter->first,aIter->second.second->operator()(aIter->second.first,aValue));
      71             :                     }
      72           0 :                 }
      73             :             }
      74             :             else
      75             :             {
      76           0 :                 ::comphelper::copyProperties(m_xSource,m_xDest);
      77           0 :                 TPropertyNamePair::iterator aIter = m_aNameMap.begin();
      78           0 :                 TPropertyNamePair::iterator aEnd = m_aNameMap.end();
      79           0 :                 for (; aIter != aEnd; ++aIter)
      80           0 :                     _xDest->setPropertyValue(aIter->second.first,aIter->second.second->operator()(aIter->second.first,_xSource->getPropertyValue(aIter->first)));
      81             :             }
      82           0 :             startListening();
      83             :         }
      84           0 :         catch(Exception& e)
      85             :         {
      86             :             DBG_UNHANDLED_EXCEPTION();
      87             :             (void)e;
      88             :         }
      89             :     }
      90           0 :     osl_atomic_decrement(&m_refCount);
      91           0 : }
      92             : // -----------------------------------------------------------------------------
      93           0 : OPropertyMediator::~OPropertyMediator()
      94             : {
      95             :     DBG_DTOR( rpt_OPropertyMediator,NULL);
      96           0 : }
      97             : // -----------------------------------------------------------------------------
      98           0 : void SAL_CALL OPropertyMediator::propertyChange( const PropertyChangeEvent& evt ) throw(RuntimeException)
      99             : {
     100           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     101           0 :     if ( !m_bInChange )
     102             :     {
     103           0 :         m_bInChange = sal_True;
     104             :         try
     105             :         {
     106           0 :             sal_Bool bDest = (evt.Source == m_xDest);
     107           0 :             Reference<XPropertySet> xProp =  bDest ? m_xSource : m_xDest;
     108           0 :             Reference<XPropertySetInfo> xPropInfo = bDest ? m_xSourceInfo : m_xDestInfo;
     109           0 :             if ( xProp.is() )
     110             :             {
     111           0 :                 if ( xPropInfo.is() )
     112             :                 {
     113           0 :                     if ( xPropInfo->hasPropertyByName(evt.PropertyName) )
     114           0 :                         xProp->setPropertyValue(evt.PropertyName,evt.NewValue);
     115             :                     else
     116             :                     {
     117           0 :                         TPropertyNamePair::iterator aFind = m_aNameMap.find(evt.PropertyName);
     118           0 :                         ::rtl::OUString sPropName;
     119           0 :                         if ( aFind != m_aNameMap.end() )
     120           0 :                             sPropName = aFind->second.first;
     121             :                         else
     122             :                         {
     123             :                             aFind = ::std::find_if(
     124             :                                 m_aNameMap.begin(),
     125             :                                 m_aNameMap.end(),
     126             :                                 ::o3tl::compose1(
     127             :                                 ::std::bind2nd(::std::equal_to< ::rtl::OUString >(), evt.PropertyName),
     128           0 :                                     ::o3tl::compose1(::o3tl::select1st<TPropertyConverter>(),::o3tl::select2nd<TPropertyNamePair::value_type>())
     129             :                                 )
     130           0 :                             );
     131           0 :                             if ( aFind != m_aNameMap.end() )
     132           0 :                                 sPropName = aFind->first;
     133             :                         }
     134           0 :                         if ( !sPropName.isEmpty() && xPropInfo->hasPropertyByName(sPropName) )
     135           0 :                             xProp->setPropertyValue(sPropName,aFind->second.second->operator()(sPropName,evt.NewValue));
     136           0 :                         else if (   evt.PropertyName == PROPERTY_CHARFONTNAME
     137           0 :                                 ||  evt.PropertyName == PROPERTY_CHARFONTSTYLENAME
     138           0 :                                 ||  evt.PropertyName == PROPERTY_CHARSTRIKEOUT
     139           0 :                                 ||  evt.PropertyName == PROPERTY_CHARWORDMODE
     140           0 :                                 ||  evt.PropertyName == PROPERTY_CHARROTATION
     141           0 :                                 ||  evt.PropertyName == PROPERTY_CHARSCALEWIDTH
     142           0 :                                 ||  evt.PropertyName == PROPERTY_CHARFONTFAMILY
     143           0 :                                 ||  evt.PropertyName == PROPERTY_CHARFONTCHARSET
     144           0 :                                 ||  evt.PropertyName == PROPERTY_CHARFONTPITCH
     145           0 :                                 ||  evt.PropertyName == PROPERTY_CHARHEIGHT
     146           0 :                                 ||  evt.PropertyName == PROPERTY_CHARUNDERLINE
     147           0 :                                 ||  evt.PropertyName == PROPERTY_CHARWEIGHT
     148           0 :                                 ||  evt.PropertyName == PROPERTY_CHARPOSTURE)
     149             :                         {
     150           0 :                             xProp->setPropertyValue(PROPERTY_FONTDESCRIPTOR,m_xSource->getPropertyValue(PROPERTY_FONTDESCRIPTOR));
     151           0 :                         }
     152             :                     }
     153             :                 }
     154           0 :             }
     155             :         }
     156           0 :         catch(Exception&)
     157             :         {
     158             :             OSL_FAIL("Exception catched!");
     159             :         }
     160           0 :         m_bInChange = sal_False;
     161           0 :     }
     162           0 : }
     163             : // -----------------------------------------------------------------------------
     164           0 : void SAL_CALL OPropertyMediator::disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ ) throw (RuntimeException)
     165             : {
     166           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     167           0 :     disposing();
     168           0 : }
     169             : // -----------------------------------------------------------------------------
     170           0 : void SAL_CALL OPropertyMediator::disposing()
     171             : {
     172           0 :     stopListening();
     173           0 :     m_xSource.clear();
     174           0 :     m_xSourceInfo.clear();
     175           0 :     m_xDest.clear();
     176           0 :     m_xDestInfo.clear();
     177           0 : }
     178             : // -----------------------------------------------------------------------------
     179           0 : void OPropertyMediator::stopListening()
     180             : {
     181           0 :     if ( m_xSource.is() )
     182           0 :         m_xSource->removePropertyChangeListener(::rtl::OUString(), this);
     183           0 :     if ( m_xDest.is() )
     184           0 :         m_xDest->removePropertyChangeListener(::rtl::OUString(), this);
     185           0 : }
     186             : // -----------------------------------------------------------------------------
     187           0 : void OPropertyMediator::startListening()
     188             : {
     189           0 :     if ( m_xSource.is() )
     190           0 :         m_xSource->addPropertyChangeListener(::rtl::OUString(), this);
     191           0 :     if ( m_xDest.is() )
     192           0 :         m_xDest->addPropertyChangeListener(::rtl::OUString(), this);
     193           0 : }
     194             : // -----------------------------------------------------------------------------
     195             : //........................................................................
     196             : }   // namespace dbaccess
     197             : //........................................................................
     198             : 
     199             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10