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>
21 #include <comphelper/property.hxx>
22 #include <tools/diagnose_ex.h>
23 #include <strings.hxx>
24 
25 namespace rptui
26 {
27 
28  using namespace ::com::sun::star::uno;
29  using namespace ::com::sun::star::beans;
30 
32  ,const Reference< XPropertySet>& _xDest
33  ,const TPropertyNamePair& _aNameMap
34  ,bool _bReverse)
36  ,m_aNameMap(_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 
81 {
82 }
83 
84 void 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);
94  Reference<XPropertySet> xProp = bDest ? m_xSource : m_xDest;
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 
145 void SAL_CALL OPropertyMediator::disposing( const css::lang::EventObject& /*_rSource*/ )
146 {
147  ::osl::MutexGuard aGuard(m_aMutex);
148  disposing();
149 }
150 
151 void 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 
160 void 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 
168 void 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: */
::cppu::WeakImplHelper< css::beans::XPropertyChangeListener > OPropertyForward_Base
osl::Mutex m_aMutex
#define PROPERTY_CHARFONTPITCH
Definition: strings.hxx:146
std::map< OUString, TPropertyConverter > TPropertyNamePair
Definition: RptDef.hxx:73
#define PROPERTY_CHARUNDERLINE
Definition: strings.hxx:148
#define PROPERTY_CHARWORDMODE
Definition: strings.hxx:151
mutable::osl::Mutex m_aMutex
#define PROPERTY_CHARFONTNAME
Definition: strings.hxx:142
#define PROPERTY_CHARSCALEWIDTH
Definition: strings.hxx:153
#define PROPERTY_CHARPOSTURE
Definition: strings.hxx:150
css::uno::Reference< css::beans::XPropertySetInfo > m_xDestInfo
#define PROPERTY_CHARWEIGHT
Definition: strings.hxx:149
virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent &evt) override
virtual ~OPropertyMediator() override
#define DBG_UNHANDLED_EXCEPTION(...)
#define PROPERTY_CHARROTATION
Definition: strings.hxx:152
#define TOOLS_WARN_EXCEPTION(area, stream)
css::uno::Reference< css::beans::XPropertySet > m_xDest
css::uno::Reference< css::beans::XPropertySetInfo > m_xSourceInfo
#define PROPERTY_CHARFONTSTYLENAME
Definition: strings.hxx:143
#define PROPERTY_CHARHEIGHT
Definition: strings.hxx:147
#define PROPERTY_CHARFONTFAMILY
Definition: strings.hxx:144
const Reference< XParameters > m_xDest
OPropertyMediator(OPropertyMediator const &)=delete
#define PROPERTY_CHARSTRIKEOUT
Definition: strings.hxx:130
#define PROPERTY_FONTDESCRIPTOR
Definition: strings.hxx:80
const Reference< XRow > m_xSource
css::uno::Reference< css::beans::XPropertySet > m_xSource
#define PROPERTY_CHARFONTCHARSET
Definition: strings.hxx:145