20#include <osl/diagnose.h>
25#include <com/sun/star/beans/PropertyAttribute.hpp>
26#include <com/sun/star/lang/DisposedException.hpp>
27#include <com/sun/star/lang/IllegalArgumentException.hpp>
43 return static_cast<OUString const*
>(arg1)->compareTo(
static_cast<Property const*
>(arg2)->Name);
53class OPropertySetHelperInfo_Impl :
public WeakImplHelper<css::beans::XPropertySetInfo>
62 virtual Property SAL_CALL getPropertyByName(
const OUString& PropertyName)
override;
63 virtual sal_Bool SAL_CALL hasPropertyByName(
const OUString& PropertyName)
override;
71 :
aInfos(rHelper_.getProperties())
83Property OPropertySetHelperInfo_Impl::getPropertyByName(
const OUString& PropertyName)
87 sizeof(Property), compare_OUString_Property_Impl));
89 throw UnknownPropertyException(PropertyName);
97sal_Bool OPropertySetHelperInfo_Impl::hasPropertyByName(
const OUString& PropertyName)
101 sizeof(Property), compare_OUString_Property_Impl));
102 return pR !=
nullptr;
105OPropertySetHelper::OPropertySetHelper() {}
108 : m_bIgnoreRuntimeExceptionsWhileFiring(bIgnoreRuntimeExceptionsWhileFiring)
120 return ::cppu::queryInterface(rType,
static_cast<XPropertySet*
>(
this),
121 static_cast<XMultiPropertySet*
>(
this),
122 static_cast<XFastPropertySet*
>(
this));
141 aEvt.Source = rSource;
152 return new OPropertySetHelperInfo_Impl(rProperties);
174 const OUString& rPropertyName)
197 if (!rPropertyName.isEmpty())
206 throw UnknownPropertyException(rPropertyName);
211 if (!(nAttributes & css::beans::PropertyAttribute::BOUND))
213 OSL_FAIL(
"add listener to an unbound property");
235 if (!rPropertyName.isEmpty())
243 throw UnknownPropertyException(rPropertyName);
264 if (!rPropertyName.isEmpty())
273 throw UnknownPropertyException(rPropertyName);
278 if (!(nAttributes & PropertyAttribute::CONSTRAINED))
280 OSL_FAIL(
"addVetoableChangeListener, and property is not constrained");
302 if (!rPropertyName.isEmpty())
311 throw UnknownPropertyException(rPropertyName);
323 const css::uno::Any& i_value)
329 throw UnknownPropertyException(OUString::number(i_handle));
335 Any aConverted, aOld;
342 OSL_ENSURE((
nAttributes & PropertyAttribute::CONSTRAINED) == 0,
343 "OPropertySetHelper::setDependentFastPropertyValue: not to be used for constrained "
351 catch (
const UnknownPropertyException&)
355 catch (
const PropertyVetoException&)
359 catch (
const IllegalArgumentException&)
363 catch (
const WrappedTargetException&)
374 WrappedTargetException aWrapped;
375 aWrapped.TargetException = ::cppu::getCaughtException();
395 sal_Int32 nHandle,
const Any& rValue)
404 throw UnknownPropertyException(OUString::number(
nHandle));
407 throw PropertyVetoException();
423 fire(rGuard, &
nHandle, &rValue, &aOldVal, 1,
true);
431 catch (
const css::beans::UnknownPropertyException&)
435 catch (
const css::beans::PropertyVetoException&)
439 catch (
const css::lang::IllegalArgumentException&)
443 catch (
const css::lang::WrappedTargetException&)
447 catch (
const css::uno::RuntimeException&)
451 catch (
const css::uno::Exception& e)
454 css::lang::WrappedTargetException aWrap;
455 aWrap.Context =
static_cast<css::beans::XPropertySet*
>(
this);
456 aWrap.TargetException <<= e;
471 throw UnknownPropertyException(OUString::number(
nHandle));
480 const Any* i_newValues,
const Any* i_oldValues,
485 fire(rGuard, i_handles, i_newValues, i_oldValues, i_count,
false);
489 const size_t additionalEvents =
m_handles.size();
491 "OPropertySetHelper::impl_fireAll: inconsistency!");
493 std::vector<sal_Int32> allHandles(additionalEvents + i_count);
495 std::copy(i_handles, i_handles + i_count, allHandles.begin() + additionalEvents);
497 std::vector<Any> allNewValues(additionalEvents + i_count);
499 std::copy(i_newValues, i_newValues + i_count, allNewValues.begin() + additionalEvents);
501 std::vector<Any> allOldValues(additionalEvents + i_count);
503 std::copy(i_oldValues, i_oldValues + i_count, allOldValues.begin() + additionalEvents);
509 fire(rGuard, allHandles.data(), allNewValues.data(), allOldValues.data(),
510 additionalEvents + i_count,
false);
514 const Any* pNewValues,
const Any* pOldValues,
524 PropertyChangeEvent* pEvts = aEvts.getArray();
527 sal_Int32 nChangesLen = 0;
529 for (i = 0;
i < nHandles;
i++)
538 if ((bVetoable && (nAttributes & PropertyAttribute::CONSTRAINED))
539 || (!bVetoable && (nAttributes & PropertyAttribute::BOUND)))
541 pEvts[nChangesLen].Source = xSource;
542 pEvts[nChangesLen].PropertyName =
aPropName;
543 pEvts[nChangesLen].PropertyHandle = pnHandles[
i];
544 pEvts[nChangesLen].OldValue = pOldValues[
i];
545 pEvts[nChangesLen].NewValue = pNewValues[
i];
553 for (i = 0;
i < nChangesLen;
i++)
572 aEvts.realloc(nChangesLen);
583 while (aIt.hasMoreElements())
585 XPropertiesChangeListener* pL = aIt.next().get();
592 pL->propertiesChange(aEvts);
594 catch (DisposedException& exc)
596 OSL_ENSURE(exc.Context.is(),
"DisposedException without Context!");
597 if (exc.Context == pL)
609 SAL_INFO(
"cppuhelper",
"caught RuntimeException while firing listeners: " << exc);
610 if (!bIgnoreRuntimeExceptionsWhileFiring)
618 std::unique_lock<std::mutex>& rGuard,
620 const css::beans::PropertyChangeEvent& rChangeEvent)
622 if (!pListeners || !pListeners->
getLength(rGuard))
629 XVetoableChangeListener* pL = aIt.
next().get();
634 pL->vetoableChange(rChangeEvent);
636 catch (DisposedException& exc)
638 OSL_ENSURE(exc.Context.is(),
"DisposedException without Context!");
639 if (exc.Context == pL)
651 SAL_INFO(
"cppuhelper",
"caught RuntimeException while firing listeners: " << exc);
660 std::unique_lock<std::mutex>& rGuard,
662 const css::beans::PropertyChangeEvent& rChangeEvent)
664 if (!pListeners || !pListeners->
getLength(rGuard))
671 XPropertyChangeListener* pL = aIt.
next().get();
676 pL->propertyChange(rChangeEvent);
678 catch (DisposedException& exc)
680 OSL_ENSURE(exc.Context.is(),
"DisposedException without Context!");
681 if (exc.Context == pL)
693 SAL_INFO(
"cppuhelper",
"caught RuntimeException while firing listeners: " << exc);
703 sal_Int32 nSeqLen, sal_Int32* pHandles,
704 const Any* pValues, sal_Int32 nHitCount)
711 std::unique_ptr<Any[]> pConvertedValues(
new Any[nHitCount]);
712 std::unique_ptr<Any[]> pOldValues(
new Any[nHitCount]);
716 for (i = 0;
i < nSeqLen;
i++)
718 if (pHandles[i] != -1)
722 if (nAttributes & PropertyAttribute::READONLY)
723 throw PropertyVetoException();
729 pHandles[
n] = pHandles[
i];
736 fire(rGuard, pHandles, pConvertedValues.get(), pOldValues.get(), n,
true);
739 for (i = 0;
i <
n;
i++)
746 impl_fireAll(rGuard, pHandles, pConvertedValues.get(), pOldValues.get(), n);
757 sal_Int32 nSeqLen = rPropertyNames.getLength();
758 if (nSeqLen != rValues.getLength())
759 throw IllegalArgumentException(
"lengths do not match",
static_cast<XPropertySet*
>(
this),
761 std::unique_ptr<sal_Int32[]> pHandles(
new sal_Int32[nSeqLen]);
765 sal_Int32 nHitCount = rPH.
fillHandles(pHandles.get(), rPropertyNames);
775 sal_Int32 nSeqLen = rPropertyNames.getLength();
776 std::unique_ptr<sal_Int32[]> pHandles(
new sal_Int32[nSeqLen]);
788 for (sal_Int32 i = 0;
i < nSeqLen;
i++)
814 sal_Int32 nLen = rPropertyNames.getLength();
815 std::unique_ptr<sal_Int32[]> pHandles(
new sal_Int32[nLen]);
818 const OUString* pNames = rPropertyNames.getConstArray();
821 sal_Int32 nFireLen = 0;
823 for (i = 0;
i < nLen;
i++)
824 if (pHandles[i] != -1)
828 PropertyChangeEvent* pChanges = aChanges.getArray();
834 sal_Int32 nFirePos = 0;
835 for (i = 0;
i < nLen;
i++)
837 if (pHandles[i] != -1)
839 pChanges[nFirePos].Source = xSource;
840 pChanges[nFirePos].PropertyName = pNames[
i];
841 pChanges[nFirePos].PropertyHandle = pHandles[
i];
843 pChanges[nFirePos].NewValue = pChanges[nFirePos].OldValue;
850 rListener->propertiesChange(aChanges);
const PropertyValue * pValues
sal_Int32 addInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
Inserts an element into the container.
sal_Int32 getLength(std::unique_lock< std::mutex > &rGuard) const
Return the number of Elements in the container.
sal_Int32 removeInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
Removes an element from the container.
This is the iterator of an OInterfaceContainerHelper4.
bool hasMoreElements() const
Return true, if there are more elements in the iterator.
css::uno::Reference< ListenerT > const & next()
Return the next element of the iterator.
void remove(::std::unique_lock<::std::mutex > &rGuard)
Removes the current element (the last one returned by next()) from the underlying container.
sal_Int32 removeInterface(::std::unique_lock<::std::mutex > &rGuard, const key &rKey, const css::uno::Reference< listener > &rListener)
Removes an element from the container with the specified key.
sal_Int32 addInterface(::std::unique_lock<::std::mutex > &rGuard, const key &rKey, const css::uno::Reference< listener > &rListener)
Inserts an element into the container with the specified key.
void disposeAndClear(std::unique_lock< std::mutex > &rGuard, const css::lang::EventObject &rEvt)
Call disposing on all references in the container, that support XEventListener.
OInterfaceContainerHelper4< listener > * getContainer(std::unique_lock< std::mutex > &rGuard, const key &rKey) const
Return the container created under this key.
std::vector< sal_Int32 > m_handles
virtual void SAL_CALL removePropertyChangeListener(const ::rtl::OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override final
Ignored if the property is not bound.
comphelper::OInterfaceContainerHelper4< css::beans::XVetoableChangeListener > maVetoableChangeListeners
Container for the XVetoableChangeListener where the listeners want to listen to all properties.
void firePropertyChangeListeners(std::unique_lock< std::mutex > &rGuard, comphelper::OInterfaceContainerHelper4< css::beans::XPropertyChangeListener > *pListeners, const css::beans::PropertyChangeEvent &rChangeEvent)
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyValues(const css::uno::Sequence<::rtl::OUString > &PropertyNames) override final
bool m_bIgnoreRuntimeExceptionsWhileFiring
std::vector< css::uno::Any > m_oldValues
virtual bool convertFastPropertyValue(std::unique_lock< std::mutex > &rGuard, css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue)=0
Converted the value rValue and return the result in rConvertedValue and the old value in rOldValue.
virtual css::uno::Any SAL_CALL getPropertyValue(const ::rtl::OUString &aPropertyName) override final
Throw UnknownPropertyException if the property with the name rPropertyName does not exist.
virtual void SAL_CALL removeVetoableChangeListener(const ::rtl::OUString &aPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override final
Ignored if the property is not constrained.
void disposing(std::unique_lock< std::mutex > &rGuard)
Send a disposing notification to the listeners.
virtual void SAL_CALL setPropertyValue(const ::rtl::OUString &rPropertyName, const css::uno::Any &aValue) override final
Throw UnknownPropertyException or PropertyVetoException if the property with the name rPropertyName d...
virtual void SAL_CALL addPropertyChangeListener(const ::rtl::OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override final
Ignored if the property is not bound.
static css::uno::Reference< css::beans::XPropertySetInfo > createPropertySetInfo(cppu::IPropertyArrayHelper &rProperties)
The property sequence is created in the call.
OMultiTypeInterfaceContainerHelperVar4< sal_Int32, css::beans::XVetoableChangeListener > aVetoableLC
Container for the XPropertyVetoableListener.
virtual css::uno::Any SAL_CALL getFastPropertyValue(sal_Int32 nHandle) override final
void impl_fireAll(std::unique_lock< std::mutex > &rGuard, sal_Int32 *i_handles, const css::uno::Any *i_newValues, const css::uno::Any *i_oldValues, sal_Int32 i_count)
notifies the given changes in property's values, plus all property changes collected during recent |s...
std::vector< css::uno::Any > m_newValues
void setFastPropertyValues(std::unique_lock< std::mutex > &rGuard, sal_Int32 nSeqLen, sal_Int32 *pHandles, const css::uno::Any *pValues, sal_Int32 nHitCount)
Set multiple properties with the handles.
virtual void SAL_CALL removePropertiesChangeListener(const css::uno::Reference< css::beans::XPropertiesChangeListener > &Listener) override final
comphelper::OInterfaceContainerHelper4< css::beans::XPropertyChangeListener > maPropertyChangeListeners
Container for the XPropertyChangedListener where the listeners want to listen to all properties.
void fireVetoableChangeListeners(std::unique_lock< std::mutex > &rGuard, comphelper::OInterfaceContainerHelper4< css::beans::XVetoableChangeListener > *pListeners, const css::beans::PropertyChangeEvent &rChangeEvent)
virtual void SAL_CALL addPropertiesChangeListener(const css::uno::Sequence<::rtl::OUString > &PropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener > &Listener) override final
virtual void setFastPropertyValueImpl(std::unique_lock< std::mutex > &rGuard, sal_Int32 nHandle, const css::uno::Any &rValue)
Override this if you need to do something special during setFastPropertyValue.
void setDependentFastPropertyValue(std::unique_lock< std::mutex > &rGuard, sal_Int32 i_handle, const css::uno::Any &i_value)
sets an dependent property's value
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Only returns a reference to XMultiPropertySet, XFastPropertySet, XPropertySet and XEventListener.
virtual css::uno::Any getPropertyValueImpl(std::unique_lock< std::mutex > &rGuard, const ::rtl::OUString &aPropertyName)
Override this if you need to do something special during getPropertyValue.
virtual void SAL_CALL firePropertiesChangeEvent(const css::uno::Sequence<::rtl::OUString > &PropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener > &Listener) override final
virtual void setFastPropertyValue_NoBroadcast(std::unique_lock< std::mutex > &rGuard, sal_Int32 nHandle, const css::uno::Any &rValue)=0
The same as setFastPropertyValue; nHandle is always valid.
virtual void SAL_CALL setPropertyValues(const css::uno::Sequence<::rtl::OUString > &PropertyNames, const css::uno::Sequence< css::uno::Any > &Values) override
virtual void SAL_CALL setFastPropertyValue(sal_Int32 nHandle, const css::uno::Any &rValue) override final
Throw UnknownPropertyException or PropertyVetoException if the property with the name rPropertyName d...
static css::uno::Sequence< css::uno::Type > getTypes()
eases implementing XTypeProvider::getTypes, returns the types of XMultiPropertySet,...
comphelper::OInterfaceContainerHelper4< css::beans::XPropertiesChangeListener > maPropertiesChangeListeners
virtual cppu::IPropertyArrayHelper & getInfoHelper()=0
This abstract method must return the name to index table.
void fire(std::unique_lock< std::mutex > &rGuard, sal_Int32 *pnHandles, const css::uno::Any *pNewValues, const css::uno::Any *pOldValues, sal_Int32 nCount, bool bVetoable)
This method fire events to all registered property listeners.
~OPropertySetHelper()
You must call disposing() before destruction.
OMultiTypeInterfaceContainerHelperVar4< sal_Int32, css::beans::XPropertyChangeListener > aBoundLC
Container for the XPropertyChangedListener.
virtual void SAL_CALL addVetoableChangeListener(const ::rtl::OUString &aPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override final
Ignored if the property is not constrained.
virtual sal_Bool SAL_CALL fillPropertyMembersByHandle(::rtl::OUString *pPropName, sal_Int16 *pAttributes, sal_Int32 nHandle)=0
virtual sal_Int32 SAL_CALL fillHandles(sal_Int32 *pHandles, const css::uno::Sequence< ::rtl::OUString > &rPropNames)=0
virtual sal_Int32 SAL_CALL getHandleByName(const ::rtl::OUString &rPropertyName)=0
OPropertySetHelper(OBroadcastHelper &rBHelper)
#define SAL_INFO(area, stream)
class SAL_NO_VTABLE XPropertySet
static int compare_OUString_Property_Impl(const void *arg1, const void *arg2) SAL_THROW_EXTERN_C()
Sequence< Property > aInfos
#define SAL_THROW_EXTERN_C()