LibreOffice Module reportdesign (master) 1
PropertyForward.cxx
Go to the documentation of this file.
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/PropertyAttribute.hpp>
23#include <strings.hxx>
24
25namespace rptui
26{
27
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::beans;
30
31OPropertyMediator::OPropertyMediator(const Reference< XPropertySet>& _xSource
32 ,const Reference< XPropertySet>& _xDest
33 ,TPropertyNamePair&& _aNameMap
34 ,bool _bReverse)
36 ,m_aNameMap(std::move(_aNameMap))
37 ,m_xSource(_xSource)
38 ,m_xDest(_xDest)
39 ,m_bInChange(false)
40{
41 osl_atomic_increment(&m_refCount);
42 OSL_ENSURE(m_xDest.is(),"Dest is NULL!");
43 OSL_ENSURE(m_xSource.is(),"Source is NULL!");
44 if ( m_xDest.is() && m_xSource.is() )
45 {
46 try
47 {
48 m_xDestInfo = m_xDest->getPropertySetInfo();
49 m_xSourceInfo = m_xSource->getPropertySetInfo();
50 if ( _bReverse )
51 {
52 ::comphelper::copyProperties(m_xDest,m_xSource);
53 for (const auto& [rName, rPropConv] : m_aNameMap)
54 {
55 Property aProp = m_xSourceInfo->getPropertyByName(rName);
56 if (0 == (aProp.Attributes & PropertyAttribute::READONLY))
57 {
58 Any aValue = _xDest->getPropertyValue(rPropConv.first);
59 if ( 0 != (aProp.Attributes & PropertyAttribute::MAYBEVOID) || aValue.hasValue() )
60 _xSource->setPropertyValue(rName, rPropConv.second->operator()(rPropConv.first, aValue));
61 }
62 }
63 }
64 else
65 {
66 ::comphelper::copyProperties(m_xSource,m_xDest);
67 for (const auto& [rName, rPropConv] : m_aNameMap)
68 _xDest->setPropertyValue(rPropConv.first, rPropConv.second->operator()(rPropConv.first, _xSource->getPropertyValue(rName)));
69 }
70 startListening();
71 }
72 catch(Exception&)
73 {
74 DBG_UNHANDLED_EXCEPTION("reportdesign");
75 }
76 }
77 osl_atomic_decrement(&m_refCount);
78}
79
80OPropertyMediator::~OPropertyMediator()
81{
82}
83
84void SAL_CALL OPropertyMediator::propertyChange( const PropertyChangeEvent& evt )
85{
86 ::osl::MutexGuard aGuard(m_aMutex);
87 if ( m_bInChange )
88 return;
89
90 m_bInChange = true;
91 try
92 {
93 bool bDest = (evt.Source == m_xDest);
95 Reference<XPropertySetInfo> xPropInfo = bDest ? m_xSourceInfo : m_xDestInfo;
96 if ( xProp.is() && xPropInfo.is() )
97 {
98 if ( xPropInfo->hasPropertyByName(evt.PropertyName) )
99 xProp->setPropertyValue(evt.PropertyName,evt.NewValue);
100 else
101 {
102 TPropertyNamePair::const_iterator aFind = m_aNameMap.find(evt.PropertyName);
103 OUString sPropName;
104 if ( aFind != m_aNameMap.end() )
105 sPropName = aFind->second.first;
106 else
107 {
108 aFind = ::std::find_if(
109 m_aNameMap.begin(),
110 m_aNameMap.end(),
111 [&evt] (const TPropertyNamePair::value_type& namePair) {
112 return namePair.second.first == evt.PropertyName;
113 });
114 if ( aFind != m_aNameMap.end() )
115 sPropName = aFind->first;
116 }
117 if (aFind != m_aNameMap.end() && !sPropName.isEmpty() && xPropInfo->hasPropertyByName(sPropName))
118 xProp->setPropertyValue(sPropName,aFind->second.second->operator()(sPropName,evt.NewValue));
119 else if ( evt.PropertyName == PROPERTY_CHARFONTNAME
120 || evt.PropertyName == PROPERTY_CHARFONTSTYLENAME
121 || evt.PropertyName == PROPERTY_CHARSTRIKEOUT
122 || evt.PropertyName == PROPERTY_CHARWORDMODE
123 || evt.PropertyName == PROPERTY_CHARROTATION
124 || evt.PropertyName == PROPERTY_CHARSCALEWIDTH
125 || evt.PropertyName == PROPERTY_CHARFONTFAMILY
126 || evt.PropertyName == PROPERTY_CHARFONTCHARSET
127 || evt.PropertyName == PROPERTY_CHARFONTPITCH
128 || evt.PropertyName == PROPERTY_CHARHEIGHT
129 || evt.PropertyName == PROPERTY_CHARUNDERLINE
130 || evt.PropertyName == PROPERTY_CHARWEIGHT
131 || evt.PropertyName == PROPERTY_CHARPOSTURE)
132 {
133 xProp->setPropertyValue(PROPERTY_FONTDESCRIPTOR,m_xSource->getPropertyValue(PROPERTY_FONTDESCRIPTOR));
134 }
135 }
136 }
137 }
138 catch(Exception&)
139 {
140 TOOLS_WARN_EXCEPTION( "reportdesign", "");
141 }
142 m_bInChange = false;
143}
144
145void SAL_CALL OPropertyMediator::disposing( const css::lang::EventObject& /*_rSource*/ )
146{
147 ::osl::MutexGuard aGuard(m_aMutex);
148 disposing();
149}
150
151void SAL_CALL OPropertyMediator::disposing()
152{
153 stopListening();
154 m_xSource.clear();
155 m_xSourceInfo.clear();
156 m_xDest.clear();
157 m_xDestInfo.clear();
158}
159
160void OPropertyMediator::stopListening()
161{
162 if ( m_xSource.is() )
163 m_xSource->removePropertyChangeListener(OUString(), this);
164 if ( m_xDest.is() )
165 m_xDest->removePropertyChangeListener(OUString(), this);
166}
167
168void OPropertyMediator::startListening()
169{
170 if ( m_xSource.is() )
171 m_xSource->addPropertyChangeListener(OUString(), this);
172 if ( m_xDest.is() )
173 m_xDest->addPropertyChangeListener(OUString(), this);
174}
175
176
177} // namespace dbaccess
178
179
180/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OPropertyMediator(OPropertyMediator const &)=delete
const Reference< XParameters > m_xDest
const Reference< XRow > m_xSource
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
std::mutex m_aMutex
::cppu::WeakImplHelper< css::beans::XPropertyChangeListener > OPropertyForward_Base
std::map< OUString, TPropertyConverter > TPropertyNamePair
Definition: RptDef.hxx:73
constexpr OUStringLiteral PROPERTY_CHARUNDERLINE
Definition: strings.hxx:142
constexpr OUStringLiteral PROPERTY_FONTDESCRIPTOR
Definition: strings.hxx:80
constexpr OUStringLiteral PROPERTY_CHARFONTPITCH
Definition: strings.hxx:140
constexpr OUStringLiteral PROPERTY_CHARWEIGHT
Definition: strings.hxx:143
constexpr OUStringLiteral PROPERTY_CHARROTATION
Definition: strings.hxx:146
constexpr OUStringLiteral PROPERTY_CHARFONTFAMILY
Definition: strings.hxx:138
constexpr OUStringLiteral PROPERTY_CHARHEIGHT
Definition: strings.hxx:141
constexpr OUStringLiteral PROPERTY_CHARFONTCHARSET
Definition: strings.hxx:139
constexpr OUStringLiteral PROPERTY_CHARWORDMODE
Definition: strings.hxx:145
constexpr OUStringLiteral PROPERTY_CHARPOSTURE
Definition: strings.hxx:144
constexpr OUStringLiteral PROPERTY_CHARSCALEWIDTH
Definition: strings.hxx:147
constexpr OUStringLiteral PROPERTY_CHARFONTSTYLENAME
Definition: strings.hxx:137
constexpr OUStringLiteral PROPERTY_CHARSTRIKEOUT
Definition: strings.hxx:125
constexpr OUStringLiteral PROPERTY_CHARFONTNAME
Definition: strings.hxx:136