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

Generated by: LCOV version 1.10