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

Generated by: LCOV version 1.10