bump product version to 5.0.4.1
[LibreOffice.git] / reportdesign / source / core / sdr / PropertyForward.cxx
blobb3971554e4303c0bfc0b9ce74c443f8d2d5ee0f1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
30 namespace rptui
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::beans;
36 OPropertyMediator::OPropertyMediator(const Reference< XPropertySet>& _xSource
37 ,const Reference< XPropertySet>& _xDest
38 ,const TPropertyNamePair& _aNameMap
39 ,bool _bReverse)
40 : OPropertyForward_Base(m_aMutex)
41 ,m_aNameMap(_aNameMap)
42 ,m_xSource(_xSource)
43 ,m_xDest(_xDest)
44 ,m_bInChange(false)
46 osl_atomic_increment(&m_refCount);
47 OSL_ENSURE(m_xDest.is(),"Dest is NULL!");
48 OSL_ENSURE(m_xSource.is(),"Source is NULL!");
49 if ( m_xDest.is() && m_xSource.is() )
51 try
53 m_xDestInfo = m_xDest->getPropertySetInfo();
54 m_xSourceInfo = m_xSource->getPropertySetInfo();
55 if ( _bReverse )
57 ::comphelper::copyProperties(m_xDest,m_xSource);
58 TPropertyNamePair::iterator aIter = m_aNameMap.begin();
59 TPropertyNamePair::iterator aEnd = m_aNameMap.end();
60 for (; aIter != aEnd; ++aIter)
62 Property aProp = m_xSourceInfo->getPropertyByName(aIter->first);
63 if (0 == (aProp.Attributes & PropertyAttribute::READONLY))
65 Any aValue = _xDest->getPropertyValue(aIter->second.first);
66 if ( 0 != (aProp.Attributes & PropertyAttribute::MAYBEVOID) || aValue.hasValue() )
67 _xSource->setPropertyValue(aIter->first,aIter->second.second->operator()(aIter->second.first,aValue));
71 else
73 ::comphelper::copyProperties(m_xSource,m_xDest);
74 TPropertyNamePair::iterator aIter = m_aNameMap.begin();
75 TPropertyNamePair::iterator aEnd = m_aNameMap.end();
76 for (; aIter != aEnd; ++aIter)
77 _xDest->setPropertyValue(aIter->second.first,aIter->second.second->operator()(aIter->second.first,_xSource->getPropertyValue(aIter->first)));
79 startListening();
81 catch(Exception& e)
83 DBG_UNHANDLED_EXCEPTION();
84 (void)e;
87 osl_atomic_decrement(&m_refCount);
90 OPropertyMediator::~OPropertyMediator()
94 void SAL_CALL OPropertyMediator::propertyChange( const PropertyChangeEvent& evt ) throw(RuntimeException, std::exception)
96 ::osl::MutexGuard aGuard(m_aMutex);
97 if ( !m_bInChange )
99 m_bInChange = true;
102 bool bDest = (evt.Source == m_xDest);
103 Reference<XPropertySet> xProp = bDest ? m_xSource : m_xDest;
104 Reference<XPropertySetInfo> xPropInfo = bDest ? m_xSourceInfo : m_xDestInfo;
105 if ( xProp.is() )
107 if ( xPropInfo.is() )
109 if ( xPropInfo->hasPropertyByName(evt.PropertyName) )
110 xProp->setPropertyValue(evt.PropertyName,evt.NewValue);
111 else
113 TPropertyNamePair::iterator aFind = m_aNameMap.find(evt.PropertyName);
114 OUString sPropName;
115 if ( aFind != m_aNameMap.end() )
116 sPropName = aFind->second.first;
117 else
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 ::o3tl::compose1(::o3tl::select1st<TPropertyConverter>(),::o3tl::select2nd<TPropertyNamePair::value_type>())
127 if ( aFind != m_aNameMap.end() )
128 sPropName = aFind->first;
130 if (aFind != m_aNameMap.end() && !sPropName.isEmpty() && xPropInfo->hasPropertyByName(sPropName))
131 xProp->setPropertyValue(sPropName,aFind->second.second->operator()(sPropName,evt.NewValue));
132 else if ( evt.PropertyName == PROPERTY_CHARFONTNAME
133 || evt.PropertyName == PROPERTY_CHARFONTSTYLENAME
134 || evt.PropertyName == PROPERTY_CHARSTRIKEOUT
135 || evt.PropertyName == PROPERTY_CHARWORDMODE
136 || evt.PropertyName == PROPERTY_CHARROTATION
137 || evt.PropertyName == PROPERTY_CHARSCALEWIDTH
138 || evt.PropertyName == PROPERTY_CHARFONTFAMILY
139 || evt.PropertyName == PROPERTY_CHARFONTCHARSET
140 || evt.PropertyName == PROPERTY_CHARFONTPITCH
141 || evt.PropertyName == PROPERTY_CHARHEIGHT
142 || evt.PropertyName == PROPERTY_CHARUNDERLINE
143 || evt.PropertyName == PROPERTY_CHARWEIGHT
144 || evt.PropertyName == PROPERTY_CHARPOSTURE)
146 xProp->setPropertyValue(PROPERTY_FONTDESCRIPTOR,m_xSource->getPropertyValue(PROPERTY_FONTDESCRIPTOR));
152 catch(Exception&)
154 OSL_FAIL("Exception catched!");
156 m_bInChange = false;
160 void SAL_CALL OPropertyMediator::disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ ) throw (RuntimeException, std::exception)
162 ::osl::MutexGuard aGuard(m_aMutex);
163 disposing();
166 void SAL_CALL OPropertyMediator::disposing()
168 stopListening();
169 m_xSource.clear();
170 m_xSourceInfo.clear();
171 m_xDest.clear();
172 m_xDestInfo.clear();
175 void OPropertyMediator::stopListening()
177 if ( m_xSource.is() )
178 m_xSource->removePropertyChangeListener(OUString(), this);
179 if ( m_xDest.is() )
180 m_xDest->removePropertyChangeListener(OUString(), this);
183 void OPropertyMediator::startListening()
185 if ( m_xSource.is() )
186 m_xSource->addPropertyChangeListener(OUString(), this);
187 if ( m_xDest.is() )
188 m_xDest->addPropertyChangeListener(OUString(), this);
192 } // namespace dbaccess
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */