bump product version to 6.3.0.0.beta1
[LibreOffice.git] / reportdesign / source / core / sdr / PropertyForward.cxx
blobe0837cfe37942269f349937c07ead2ac8a162b52
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 <strings.hxx>
28 namespace rptui
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::beans;
34 OPropertyMediator::OPropertyMediator(const Reference< XPropertySet>& _xSource
35 ,const Reference< XPropertySet>& _xDest
36 ,const TPropertyNamePair& _aNameMap
37 ,bool _bReverse)
38 : OPropertyForward_Base(m_aMutex)
39 ,m_aNameMap(_aNameMap)
40 ,m_xSource(_xSource)
41 ,m_xDest(_xDest)
42 ,m_bInChange(false)
44 osl_atomic_increment(&m_refCount);
45 OSL_ENSURE(m_xDest.is(),"Dest is NULL!");
46 OSL_ENSURE(m_xSource.is(),"Source is NULL!");
47 if ( m_xDest.is() && m_xSource.is() )
49 try
51 m_xDestInfo = m_xDest->getPropertySetInfo();
52 m_xSourceInfo = m_xSource->getPropertySetInfo();
53 if ( _bReverse )
55 ::comphelper::copyProperties(m_xDest,m_xSource);
56 for (const auto& [rName, rPropConv] : m_aNameMap)
58 Property aProp = m_xSourceInfo->getPropertyByName(rName);
59 if (0 == (aProp.Attributes & PropertyAttribute::READONLY))
61 Any aValue = _xDest->getPropertyValue(rPropConv.first);
62 if ( 0 != (aProp.Attributes & PropertyAttribute::MAYBEVOID) || aValue.hasValue() )
63 _xSource->setPropertyValue(rName, rPropConv.second->operator()(rPropConv.first, aValue));
67 else
69 ::comphelper::copyProperties(m_xSource,m_xDest);
70 for (const auto& [rName, rPropConv] : m_aNameMap)
71 _xDest->setPropertyValue(rPropConv.first, rPropConv.second->operator()(rPropConv.first, _xSource->getPropertyValue(rName)));
73 startListening();
75 catch(Exception&)
77 DBG_UNHANDLED_EXCEPTION("reportdesign");
80 osl_atomic_decrement(&m_refCount);
83 OPropertyMediator::~OPropertyMediator()
87 void SAL_CALL OPropertyMediator::propertyChange( const PropertyChangeEvent& evt )
89 ::osl::MutexGuard aGuard(m_aMutex);
90 if ( !m_bInChange )
92 m_bInChange = true;
93 try
95 bool bDest = (evt.Source == m_xDest);
96 Reference<XPropertySet> xProp = bDest ? m_xSource : m_xDest;
97 Reference<XPropertySetInfo> xPropInfo = bDest ? m_xSourceInfo : m_xDestInfo;
98 if ( xProp.is() && xPropInfo.is() )
100 if ( xPropInfo->hasPropertyByName(evt.PropertyName) )
101 xProp->setPropertyValue(evt.PropertyName,evt.NewValue);
102 else
104 TPropertyNamePair::const_iterator aFind = m_aNameMap.find(evt.PropertyName);
105 OUString sPropName;
106 if ( aFind != m_aNameMap.end() )
107 sPropName = aFind->second.first;
108 else
110 aFind = ::std::find_if(
111 m_aNameMap.begin(),
112 m_aNameMap.end(),
113 [&evt] (const TPropertyNamePair::value_type& namePair) {
114 return namePair.second.first == evt.PropertyName;
116 if ( aFind != m_aNameMap.end() )
117 sPropName = aFind->first;
119 if (aFind != m_aNameMap.end() && !sPropName.isEmpty() && xPropInfo->hasPropertyByName(sPropName))
120 xProp->setPropertyValue(sPropName,aFind->second.second->operator()(sPropName,evt.NewValue));
121 else if ( evt.PropertyName == PROPERTY_CHARFONTNAME
122 || evt.PropertyName == PROPERTY_CHARFONTSTYLENAME
123 || evt.PropertyName == PROPERTY_CHARSTRIKEOUT
124 || evt.PropertyName == PROPERTY_CHARWORDMODE
125 || evt.PropertyName == PROPERTY_CHARROTATION
126 || evt.PropertyName == PROPERTY_CHARSCALEWIDTH
127 || evt.PropertyName == PROPERTY_CHARFONTFAMILY
128 || evt.PropertyName == PROPERTY_CHARFONTCHARSET
129 || evt.PropertyName == PROPERTY_CHARFONTPITCH
130 || evt.PropertyName == PROPERTY_CHARHEIGHT
131 || evt.PropertyName == PROPERTY_CHARUNDERLINE
132 || evt.PropertyName == PROPERTY_CHARWEIGHT
133 || evt.PropertyName == PROPERTY_CHARPOSTURE)
135 xProp->setPropertyValue(PROPERTY_FONTDESCRIPTOR,m_xSource->getPropertyValue(PROPERTY_FONTDESCRIPTOR));
140 catch(Exception&)
142 OSL_FAIL("Exception caught!");
144 m_bInChange = false;
148 void SAL_CALL OPropertyMediator::disposing( const css::lang::EventObject& /*_rSource*/ )
150 ::osl::MutexGuard aGuard(m_aMutex);
151 disposing();
154 void SAL_CALL OPropertyMediator::disposing()
156 stopListening();
157 m_xSource.clear();
158 m_xSourceInfo.clear();
159 m_xDest.clear();
160 m_xDestInfo.clear();
163 void OPropertyMediator::stopListening()
165 if ( m_xSource.is() )
166 m_xSource->removePropertyChangeListener(OUString(), this);
167 if ( m_xDest.is() )
168 m_xDest->removePropertyChangeListener(OUString(), this);
171 void OPropertyMediator::startListening()
173 if ( m_xSource.is() )
174 m_xSource->addPropertyChangeListener(OUString(), this);
175 if ( m_xDest.is() )
176 m_xDest->addPropertyChangeListener(OUString(), this);
180 } // namespace dbaccess
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */