lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / reportdesign / source / core / sdr / PropertyForward.cxx
blobcca1f9825216e4ffdcd6cfc85cce52f251c03cea
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 TPropertyNamePair::const_iterator aIter = m_aNameMap.begin();
57 TPropertyNamePair::const_iterator aEnd = m_aNameMap.end();
58 for (; aIter != aEnd; ++aIter)
60 Property aProp = m_xSourceInfo->getPropertyByName(aIter->first);
61 if (0 == (aProp.Attributes & PropertyAttribute::READONLY))
63 Any aValue = _xDest->getPropertyValue(aIter->second.first);
64 if ( 0 != (aProp.Attributes & PropertyAttribute::MAYBEVOID) || aValue.hasValue() )
65 _xSource->setPropertyValue(aIter->first,aIter->second.second->operator()(aIter->second.first,aValue));
69 else
71 ::comphelper::copyProperties(m_xSource,m_xDest);
72 TPropertyNamePair::const_iterator aIter = m_aNameMap.begin();
73 TPropertyNamePair::const_iterator aEnd = m_aNameMap.end();
74 for (; aIter != aEnd; ++aIter)
75 _xDest->setPropertyValue(aIter->second.first,aIter->second.second->operator()(aIter->second.first,_xSource->getPropertyValue(aIter->first)));
77 startListening();
79 catch(Exception&)
81 DBG_UNHANDLED_EXCEPTION("reportdesign");
84 osl_atomic_decrement(&m_refCount);
87 OPropertyMediator::~OPropertyMediator()
91 void SAL_CALL OPropertyMediator::propertyChange( const PropertyChangeEvent& evt )
93 ::osl::MutexGuard aGuard(m_aMutex);
94 if ( !m_bInChange )
96 m_bInChange = true;
97 try
99 bool bDest = (evt.Source == m_xDest);
100 Reference<XPropertySet> xProp = bDest ? m_xSource : m_xDest;
101 Reference<XPropertySetInfo> xPropInfo = bDest ? m_xSourceInfo : m_xDestInfo;
102 if ( xProp.is() && xPropInfo.is() )
104 if ( xPropInfo->hasPropertyByName(evt.PropertyName) )
105 xProp->setPropertyValue(evt.PropertyName,evt.NewValue);
106 else
108 TPropertyNamePair::const_iterator aFind = m_aNameMap.find(evt.PropertyName);
109 OUString sPropName;
110 if ( aFind != m_aNameMap.end() )
111 sPropName = aFind->second.first;
112 else
114 aFind = ::std::find_if(
115 m_aNameMap.begin(),
116 m_aNameMap.end(),
117 [&evt] (const TPropertyNamePair::value_type& namePair) {
118 return namePair.second.first == evt.PropertyName;
120 if ( aFind != m_aNameMap.end() )
121 sPropName = aFind->first;
123 if (aFind != m_aNameMap.end() && !sPropName.isEmpty() && xPropInfo->hasPropertyByName(sPropName))
124 xProp->setPropertyValue(sPropName,aFind->second.second->operator()(sPropName,evt.NewValue));
125 else if ( evt.PropertyName == PROPERTY_CHARFONTNAME
126 || evt.PropertyName == PROPERTY_CHARFONTSTYLENAME
127 || evt.PropertyName == PROPERTY_CHARSTRIKEOUT
128 || evt.PropertyName == PROPERTY_CHARWORDMODE
129 || evt.PropertyName == PROPERTY_CHARROTATION
130 || evt.PropertyName == PROPERTY_CHARSCALEWIDTH
131 || evt.PropertyName == PROPERTY_CHARFONTFAMILY
132 || evt.PropertyName == PROPERTY_CHARFONTCHARSET
133 || evt.PropertyName == PROPERTY_CHARFONTPITCH
134 || evt.PropertyName == PROPERTY_CHARHEIGHT
135 || evt.PropertyName == PROPERTY_CHARUNDERLINE
136 || evt.PropertyName == PROPERTY_CHARWEIGHT
137 || evt.PropertyName == PROPERTY_CHARPOSTURE)
139 xProp->setPropertyValue(PROPERTY_FONTDESCRIPTOR,m_xSource->getPropertyValue(PROPERTY_FONTDESCRIPTOR));
144 catch(Exception&)
146 OSL_FAIL("Exception caught!");
148 m_bInChange = false;
152 void SAL_CALL OPropertyMediator::disposing( const css::lang::EventObject& /*_rSource*/ )
154 ::osl::MutexGuard aGuard(m_aMutex);
155 disposing();
158 void SAL_CALL OPropertyMediator::disposing()
160 stopListening();
161 m_xSource.clear();
162 m_xSourceInfo.clear();
163 m_xDest.clear();
164 m_xDestInfo.clear();
167 void OPropertyMediator::stopListening()
169 if ( m_xSource.is() )
170 m_xSource->removePropertyChangeListener(OUString(), this);
171 if ( m_xDest.is() )
172 m_xDest->removePropertyChangeListener(OUString(), this);
175 void OPropertyMediator::startListening()
177 if ( m_xSource.is() )
178 m_xSource->addPropertyChangeListener(OUString(), this);
179 if ( m_xDest.is() )
180 m_xDest->addPropertyChangeListener(OUString(), this);
184 } // namespace dbaccess
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */