fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / fwi / classes / propertysethelper.cxx
blob52b6972ebd4178692f1287b831ecc0b0974c91b0
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 .
20 #include <sal/config.h>
22 #include <vcl/svapp.hxx>
24 #include <classes/propertysethelper.hxx>
25 #include <threadhelp/transactionguard.hxx>
27 namespace framework{
29 PropertySetHelper::PropertySetHelper( osl::Mutex & mutex,
30 TransactionManager* pExternalTransactionManager ,
31 bool bReleaseLockOnCall )
32 : m_lSimpleChangeListener(mutex)
33 , m_lVetoChangeListener (mutex)
34 , m_bReleaseLockOnCall (bReleaseLockOnCall )
35 , m_rTransactionManager (*pExternalTransactionManager )
39 PropertySetHelper::~PropertySetHelper()
43 void PropertySetHelper::impl_setPropertyChangeBroadcaster(const css::uno::Reference< css::uno::XInterface >& xBroadcaster)
45 TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
47 SolarMutexGuard g;
48 m_xBroadcaster = xBroadcaster;
51 void SAL_CALL PropertySetHelper::impl_addPropertyInfo(const css::beans::Property& aProperty)
52 throw(css::beans::PropertyExistException,
53 css::uno::Exception )
55 TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
57 SolarMutexGuard g;
59 PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(aProperty.Name);
60 if (pIt != m_lProps.end())
61 throw css::beans::PropertyExistException();
63 m_lProps[aProperty.Name] = aProperty;
66 void SAL_CALL PropertySetHelper::impl_disablePropertySet()
68 TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
70 SolarMutexGuard g;
72 css::uno::Reference< css::uno::XInterface > xThis(static_cast< css::beans::XPropertySet* >(this), css::uno::UNO_QUERY);
73 css::lang::EventObject aEvent(xThis);
75 m_lSimpleChangeListener.disposeAndClear(aEvent);
76 m_lVetoChangeListener.disposeAndClear(aEvent);
77 m_lProps.free();
80 bool PropertySetHelper::impl_existsVeto(const css::beans::PropertyChangeEvent& aEvent)
82 /* Dont use the lock here!
83 The used helper is threadsafe and it lives for the whole lifetime of
84 our own object.
86 ::cppu::OInterfaceContainerHelper* pVetoListener = m_lVetoChangeListener.getContainer(aEvent.PropertyName);
87 if (! pVetoListener)
88 return false;
90 ::cppu::OInterfaceIteratorHelper pListener(*pVetoListener);
91 while (pListener.hasMoreElements())
93 try
95 css::uno::Reference< css::beans::XVetoableChangeListener > xListener(
96 static_cast<css::beans::XVetoableChangeListener*>(pListener.next()),
97 css::uno::UNO_QUERY_THROW);
98 xListener->vetoableChange(aEvent);
100 catch(const css::uno::RuntimeException&)
101 { pListener.remove(); }
102 catch(const css::beans::PropertyVetoException&)
103 { return true; }
106 return false;
109 void PropertySetHelper::impl_notifyChangeListener(const css::beans::PropertyChangeEvent& aEvent)
111 /* Dont use the lock here!
112 The used helper is threadsafe and it lives for the whole lifetime of
113 our own object.
115 ::cppu::OInterfaceContainerHelper* pSimpleListener = m_lSimpleChangeListener.getContainer(aEvent.PropertyName);
116 if (! pSimpleListener)
117 return;
119 ::cppu::OInterfaceIteratorHelper pListener(*pSimpleListener);
120 while (pListener.hasMoreElements())
124 css::uno::Reference< css::beans::XPropertyChangeListener > xListener(
125 static_cast<css::beans::XVetoableChangeListener*>(pListener.next()),
126 css::uno::UNO_QUERY_THROW);
127 xListener->propertyChange(aEvent);
129 catch(const css::uno::RuntimeException&)
130 { pListener.remove(); }
134 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL PropertySetHelper::getPropertySetInfo()
135 throw(css::uno::RuntimeException, std::exception)
137 TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
139 css::uno::Reference< css::beans::XPropertySetInfo > xInfo(static_cast< css::beans::XPropertySetInfo* >(this), css::uno::UNO_QUERY_THROW);
140 return xInfo;
143 void SAL_CALL PropertySetHelper::setPropertyValue(const OUString& sProperty,
144 const css::uno::Any& aValue )
145 throw(css::beans::UnknownPropertyException,
146 css::beans::PropertyVetoException ,
147 css::lang::IllegalArgumentException ,
148 css::lang::WrappedTargetException ,
149 css::uno::RuntimeException, std::exception )
151 // TODO look for e.g. readonly props and reject setProp() call!
153 TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
155 // SAFE ->
156 SolarMutexResettableGuard aWriteLock;
158 PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
159 if (pIt == m_lProps.end())
160 throw css::beans::UnknownPropertyException();
162 css::beans::Property aPropInfo = pIt->second;
164 bool bLocked = true;
165 if (m_bReleaseLockOnCall)
167 aWriteLock.clear();
168 bLocked = false;
169 // <- SAFE
172 css::uno::Any aCurrentValue = impl_getPropertyValue(aPropInfo.Name, aPropInfo.Handle);
174 if (! bLocked)
176 // SAFE ->
177 aWriteLock.reset();
180 bool bWillBeChanged = (aCurrentValue != aValue);
181 if (! bWillBeChanged)
182 return;
184 css::beans::PropertyChangeEvent aEvent;
185 aEvent.PropertyName = aPropInfo.Name;
186 aEvent.Further = sal_False;
187 aEvent.PropertyHandle = aPropInfo.Handle;
188 aEvent.OldValue = aCurrentValue;
189 aEvent.NewValue = aValue;
190 aEvent.Source = css::uno::Reference< css::uno::XInterface >(m_xBroadcaster.get(), css::uno::UNO_QUERY);
192 if (m_bReleaseLockOnCall)
194 aWriteLock.clear();
195 // <- SAFE
198 if (impl_existsVeto(aEvent))
199 throw css::beans::PropertyVetoException();
201 impl_setPropertyValue(aPropInfo.Name, aPropInfo.Handle, aValue);
203 impl_notifyChangeListener(aEvent);
206 css::uno::Any SAL_CALL PropertySetHelper::getPropertyValue(const OUString& sProperty)
207 throw(css::beans::UnknownPropertyException,
208 css::lang::WrappedTargetException ,
209 css::uno::RuntimeException, std::exception )
211 TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
213 // SAFE ->
214 SolarMutexClearableGuard aReadLock;
216 PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
217 if (pIt == m_lProps.end())
218 throw css::beans::UnknownPropertyException();
220 css::beans::Property aPropInfo = pIt->second;
222 if (m_bReleaseLockOnCall)
223 aReadLock.clear();
225 return impl_getPropertyValue(aPropInfo.Name, aPropInfo.Handle);
228 void SAL_CALL PropertySetHelper::addPropertyChangeListener(const OUString& sProperty,
229 const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener)
230 throw(css::beans::UnknownPropertyException,
231 css::lang::WrappedTargetException ,
232 css::uno::RuntimeException, std::exception )
234 TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
236 // SAFE ->
237 SolarMutexClearableGuard aReadLock;
239 PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
240 if (pIt == m_lProps.end())
241 throw css::beans::UnknownPropertyException();
243 aReadLock.clear();
244 // <- SAFE
246 m_lSimpleChangeListener.addInterface(sProperty, xListener);
249 void SAL_CALL PropertySetHelper::removePropertyChangeListener(const OUString& sProperty,
250 const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener)
251 throw(css::beans::UnknownPropertyException,
252 css::lang::WrappedTargetException ,
253 css::uno::RuntimeException, std::exception )
255 TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
257 // SAFE ->
258 SolarMutexClearableGuard aReadLock;
260 PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
261 if (pIt == m_lProps.end())
262 throw css::beans::UnknownPropertyException();
264 aReadLock.clear();
265 // <- SAFE
267 m_lSimpleChangeListener.removeInterface(sProperty, xListener);
270 void SAL_CALL PropertySetHelper::addVetoableChangeListener(const OUString& sProperty,
271 const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener)
272 throw(css::beans::UnknownPropertyException,
273 css::lang::WrappedTargetException ,
274 css::uno::RuntimeException, std::exception )
276 TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
278 // SAFE ->
279 SolarMutexClearableGuard aReadLock;
281 PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
282 if (pIt == m_lProps.end())
283 throw css::beans::UnknownPropertyException();
285 aReadLock.clear();
286 // <- SAFE
288 m_lVetoChangeListener.addInterface(sProperty, xListener);
291 void SAL_CALL PropertySetHelper::removeVetoableChangeListener(const OUString& sProperty,
292 const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener)
293 throw(css::beans::UnknownPropertyException,
294 css::lang::WrappedTargetException ,
295 css::uno::RuntimeException, std::exception )
297 TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
299 // SAFE ->
300 SolarMutexClearableGuard aReadLock;
302 PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
303 if (pIt == m_lProps.end())
304 throw css::beans::UnknownPropertyException();
306 aReadLock.clear();
307 // <- SAFE
309 m_lVetoChangeListener.removeInterface(sProperty, xListener);
312 css::uno::Sequence< css::beans::Property > SAL_CALL PropertySetHelper::getProperties()
313 throw(css::uno::RuntimeException, std::exception)
315 TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
317 SolarMutexGuard g;
319 sal_Int32 c = (sal_Int32)m_lProps.size();
320 css::uno::Sequence< css::beans::Property > lProps(c);
321 PropertySetHelper::TPropInfoHash::const_iterator pIt;
323 for ( pIt = m_lProps.begin();
324 pIt != m_lProps.end();
325 ++pIt )
327 lProps[--c] = pIt->second;
330 return lProps;
333 css::beans::Property SAL_CALL PropertySetHelper::getPropertyByName(const OUString& sName)
334 throw(css::beans::UnknownPropertyException,
335 css::uno::RuntimeException, std::exception )
337 TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
339 SolarMutexGuard g;
341 PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sName);
342 if (pIt == m_lProps.end())
343 throw css::beans::UnknownPropertyException();
345 return pIt->second;
348 sal_Bool SAL_CALL PropertySetHelper::hasPropertyByName(const OUString& sName)
349 throw(css::uno::RuntimeException, std::exception)
351 TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
353 SolarMutexGuard g;
355 PropertySetHelper::TPropInfoHash::iterator pIt = m_lProps.find(sName);
356 bool bExist = (pIt != m_lProps.end());
358 return bExist;
361 } // namespace framework
363 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */